diff --git a/devnet/docker/icon-bsc/Makefile b/devnet/docker/icon-bsc/Makefile index df0196af8..a903c4b81 100644 --- a/devnet/docker/icon-bsc/Makefile +++ b/devnet/docker/icon-bsc/Makefile @@ -54,7 +54,7 @@ stoprelayimg: ./build.sh stoprelayimg buildimglocal: - ./build.sh buildimg + ./build.sh buildimglocal runimglocal: ./build.sh runimglocal diff --git a/devnet/docker/icon-bsc/build.sh b/devnet/docker/icon-bsc/build.sh index 560ace7a8..a296de23c 100755 --- a/devnet/docker/icon-bsc/build.sh +++ b/devnet/docker/icon-bsc/build.sh @@ -214,7 +214,7 @@ deploy_smart_contracts_on_localnet() { cd scripts if [ ! -f config_testnet.sh ]; then cp config.sh config_testnet.sh - cp config_local.sh config.sh + cp config/icon-bsc.config.localnet.sh config.sh fi ./deploysc.sh if [ -f config_testnet.sh ]; then diff --git a/devnet/docker/icon-bsc/scripts/bmc.js b/devnet/docker/icon-bsc/scripts/bmc.js index 585a5145b..7e07e724d 100644 --- a/devnet/docker/icon-bsc/scripts/bmc.js +++ b/devnet/docker/icon-bsc/scripts/bmc.js @@ -26,11 +26,22 @@ module.exports = async function (callback) { break case "addRelay": console.log("Add relay ", argv.link) - let relays = [argv.addr] + let relays=argv.addr.split(',').map(item => item.trim()); tx = await bmcManagement.addRelay(argv.link, relays) //console.log(await bmcManagement.getRelays(argv.link)) console.log(tx) break; + case "removeRelay": + console.log("Remove relay ", argv.link) + let relay = argv.addr + tx = await bmcManagement.removeRelay(argv.link, relay) + // console.log(await bmcManagement.getRelays(argv.link)) + console.log(tx) + break; + case "getRelays": + console.log("Relays for link ", argv.link) + console.log(await bmcManagement.getRelays(argv.link)) + break; case "addOwner": console.log("Add bmc owner ", argv.addr) tx = await bmcManagement.addOwner(argv.addr) @@ -65,4 +76,4 @@ module.exports = async function (callback) { console.log(error) } callback() -} \ No newline at end of file +} diff --git a/devnet/docker/icon-bsc/scripts/config/icon-bsc.config.localnet.sh b/devnet/docker/icon-bsc/scripts/config/icon-bsc.config.localnet.sh new file mode 100644 index 000000000..c94cbddca --- /dev/null +++ b/devnet/docker/icon-bsc/scripts/config/icon-bsc.config.localnet.sh @@ -0,0 +1,85 @@ +#!/bin/bash +#BUILD_DIR=$(echo "$(cd "$(dirname "../../../../../")"; pwd)"/build) +BASE_DIR=$(echo "$(cd "$(dirname "../../")"; pwd)") +BUILD_DIR=$BASE_DIR/build +export ICONBRIDGE_CONFIG_DIR=$BASE_DIR/_ixh +export ICONBRIDGE_CONTRACTS_DIR=$BUILD_DIR/contracts +export ICONBRIDGE_SCRIPTS_DIR=$BASE_DIR/scripts +export ICONBRIDGE_BIN_DIR=$BASE_DIR + +export CONFIG_DIR=${CONFIG_DIR:-${ICONBRIDGE_CONFIG_DIR}} +export CONTRACTS_DIR=${CONTRACTS_DIR:-${ICONBRIDGE_CONTRACTS_DIR}} +export SCRIPTS_DIR=${SCRIPTS_DIR:-${ICONBRIDGE_SCRIPTS_DIR}} + +################################################################################### + +# localnet: begin +export TAG="ICON BSC LOCALNET" +export BSC_BMC_NET="0x61.bsc" +export GOLOOP_RPC_NID=$(cat $CONFIG_DIR/nid.icon) +export ICON_BMC_NET="$GOLOOP_RPC_NID.icon" +export BSC_NID="97" + +export ICON_ENDPOINT="http://localhost:9080/api/v3/icon" +export ICON_NATIVE_COIN_SYM=("ICX") +export ICON_NATIVE_COIN_NAME=("btp-$ICON_BMC_NET-ICX") +export ICON_NATIVE_TOKEN_SYM=("sICX" "bnUSD") +export ICON_NATIVE_TOKEN_NAME=("btp-$ICON_BMC_NET-sICX" "btp-$ICON_BMC_NET-bnUSD") +export ICON_WRAPPED_COIN_SYM=("BNB" "BUSD" "USDT" "USDC" "BTCB" "ETH") +export ICON_WRAPPED_COIN_NAME=("btp-$BSC_BMC_NET-BNB" "btp-$BSC_BMC_NET-BUSD" "btp-$BSC_BMC_NET-USDT" "btp-$BSC_BMC_NET-USDC" "btp-$BSC_BMC_NET-BTCB" "btp-$BSC_BMC_NET-ETH") +export FEE_GATHERING_INTERVAL=1000 + + +export ICON_NATIVE_COIN_FIXED_FEE=(4300000000000000000) +export ICON_NATIVE_COIN_FEE_NUMERATOR=(100) +export ICON_NATIVE_COIN_DECIMALS=(18) +export ICON_NATIVE_TOKEN_FIXED_FEE=(3900000000000000000 1500000000000000000) +export ICON_NATIVE_TOKEN_FEE_NUMERATOR=(100 100) +export ICON_NATIVE_TOKEN_DECIMALS=(18 18) +export ICON_WRAPPED_COIN_FIXED_FEE=(5000000000000000 1500000000000000000 1500000000000000000 1500000000000000000 62500000000000 750000000000000) +export ICON_WRAPPED_COIN_FEE_NUMERATOR=(100 100 100 100 100 100) +export ICON_WRAPPED_COIN_DECIMALS=(18 18 18 18 18 18) + +export BSC_ENDPOINT="http://localhost:8545" +export BSC_NATIVE_COIN_SYM=("BNB") +export BSC_NATIVE_COIN_NAME=("btp-$BSC_BMC_NET-BNB") +export BSC_NATIVE_TOKEN_SYM=("BUSD" "USDT" "USDC" "BTCB" "ETH") +export BSC_NATIVE_TOKEN_NAME=("btp-$BSC_BMC_NET-BUSD" "btp-$BSC_BMC_NET-USDT" "btp-$BSC_BMC_NET-USDC" "btp-$BSC_BMC_NET-BTCB" "btp-$BSC_BMC_NET-ETH") +export BSC_WRAPPED_COIN_SYM=("ICX" "sICX" "bnUSD") +export BSC_WRAPPED_COIN_NAME=("btp-$ICON_BMC_NET-ICX" "btp-$ICON_BMC_NET-sICX" "btp-$ICON_BMC_NET-bnUSD") + +export BSC_NATIVE_COIN_FIXED_FEE=(5000000000000000) +export BSC_NATIVE_COIN_FEE_NUMERATOR=(100) +export BSC_NATIVE_COIN_DECIMALS=(18) +export BSC_NATIVE_TOKEN_FIXED_FEE=(1500000000000000000 1500000000000000000 1500000000000000000 62500000000000 750000000000000) +export BSC_NATIVE_TOKEN_FEE_NUMERATOR=(100 100 100 100 100) +export BSC_NATIVE_TOKEN_DECIMALS=(18 18 18 18 18) +export BSC_WRAPPED_COIN_FIXED_FEE=(4300000000000000000 3900000000000000000 1500000000000000000) +export BSC_WRAPPED_COIN_FEE_NUMERATOR=(100 100 100) +export BSC_WRAPPED_COIN_DECIMALS=(18 18 18) + +# localnet: end + + +GOLOOPCHAIN=${GOLOOPCHAIN:-"goloop"} +export GOLOOP_RPC_STEP_LIMIT=5000000000 +export ICON_KEY_STORE=$ICONBRIDGE_CONFIG_DIR/keystore/icon.god.wallet.json +export ICON_SECRET=$ICONBRIDGE_CONFIG_DIR/keystore/icon.god.wallet.secret +export GOLOOP_RPC_URI=$ICON_ENDPOINT +export GOLOOP_RPC_KEY_STORE=$ICON_KEY_STORE +export GOLOOP_RPC_KEY_SECRET=$ICON_SECRET + +export BSC_RPC_URI=$BSC_ENDPOINT +export BSC_KEY_STORE=$ICONBRIDGE_CONFIG_DIR/keystore/bsc.god.wallet.json +export BSC_SECRET=$ICONBRIDGE_CONFIG_DIR/keystore/bsc.god.wallet.secret + +#use god keys for relay txns +if [ ! -f $CONFIG_DIR/keystore/icon.bmr.wallet.json ]; then + cp $CONFIG_DIR/keystore/icon.god.wallet.json $CONFIG_DIR/keystore/icon.bmr.wallet.json + cp $CONFIG_DIR/keystore/icon.god.wallet.secret $CONFIG_DIR/keystore/icon.bmr.wallet.secret +fi + +if [ ! -f $CONFIG_DIR/keystore/bsc.bmr.wallet.json ]; then + cp $CONFIG_DIR/keystore/bsc.god.wallet.json $CONFIG_DIR/keystore/bsc.bmr.wallet.json + cp $CONFIG_DIR/keystore/bsc.god.wallet.secret $CONFIG_DIR/keystore/bsc.bmr.wallet.secret +fi diff --git a/devnet/docker/icon-bsc/scripts/relayOwner.javascore.sh b/devnet/docker/icon-bsc/scripts/relayOwner.javascore.sh new file mode 100755 index 000000000..5668bf65d --- /dev/null +++ b/devnet/docker/icon-bsc/scripts/relayOwner.javascore.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +set -e +source config.sh # config file +source rpc.sh +source keystore.sh + +function bmcExists() { + if [ ! -f icon.addr.bmc ]; then + echo "icon.addr.bmc does not exist" + exit 0 + fi +} + +function addRelayIcon() { + cd $CONFIG_DIR + bmcExists + getRelaysIcon + goloop rpc sendtx call --to $(cat icon.addr.bmc) \ + --method addRelay \ + --param _link=$(cat bsc.addr.bmcbtp)\ + --param _addr=${1} | jq -r . >tx/addRelay.icon + sleep 3 + ensure_txresult tx/addRelay.icon + + getRelaysIcon + echo "Relay added to BMC javascore!" +} + +function getRelaysIcon() { + cd $CONFIG_DIR + echo + echo "Existing relays" + goloop rpc call --to $(cat icon.addr.bmc) \ + --method getRelays \ + --param _link=$(cat bsc.addr.bmcbtp) + echo +} + +function removeRelayIcon() { + cd $CONFIG_DIR + + bmcExists + getRelaysIcon + + goloop rpc sendtx call --to $(cat icon.addr.bmc) \ + --method removeRelay \ + --param _link=$(cat bsc.addr.bmcbtp) \ + --param _addr=${1} | jq -r . >tx/removeRelay.icon + sleep 3 + ensure_txresult tx/addRelay.icon + + getRelaysIcon + echo "Relay removed from BMC javascore!" +} + +if [ $# -eq 0 ]; then + echo "No arguments supplied: Pass --help or -h" +elif [ $1 == "--remove" ]; then + echo "Removing relay " $2 + removeRelayIcon $2 +elif [ $1 == "--add" ]; then + echo "Adding relay " $2 + addRelayIcon $2 +elif [ $1 == "--get" ]; then + getRelaysIcon +else + echo "Invalid argument " + echo "Ensure config.sh is for relevant configuration" + echo + echo "Usage: " + echo " --add addr : Add Relayer" + echo " --remove addr : Remove Relayer" + echo " --get : Get Relayers" +fi diff --git a/devnet/docker/icon-bsc/scripts/relayOwner.solidity.sh b/devnet/docker/icon-bsc/scripts/relayOwner.solidity.sh new file mode 100755 index 000000000..efa0d282e --- /dev/null +++ b/devnet/docker/icon-bsc/scripts/relayOwner.solidity.sh @@ -0,0 +1,85 @@ +#!/bin/bash +set -e +source config.sh +source rpc.sh + +export PRIVATE_KEY="[\""$(cat $BSC_KEY_STORE.priv)"\"]" + +function bmcExists() { + if [ ! -f bsc.addr.bmcmanagement ]; then + echo "bsc.addr.bmcmanagement does not exist" + exit 0 + fi +} + +function getRelaysSolidity() { + cd $CONFIG_DIR + bmcExists + + cd $CONTRACTS_DIR/solidity/bmc + truffle exec --network bsc "$SCRIPTS_DIR"/bmc.js \ + --method "getRelays" --link "$(cat $CONFIG_DIR/icon.addr.bmcbtp)" +} + +function removeRelaySolidity() { + cd $CONFIG_DIR + + getRelaysSolidity + echo + cd $CONTRACTS_DIR/solidity/bmc + tx=$(truffle exec --network bsc "$SCRIPTS_DIR"/bmc.js \ + --method removeRelay --link "$(cat $CONFIG_DIR/icon.addr.bmcbtp)" --addr "${1}") + echo "$tx" >$CONFIG_DIR/tx/removeRelay.bmc.bsc + echo + getRelaysSolidity +} + +function addRelaySolidity() { + # USAGE + # For single relay + # addRelaySolidity 0x4300148436d51f7f270cb6e76cbc82fa0ce1b359 + # For multiple relays + # addRelaySolidity 0x4300148436d51f7f270cb6e76cbc82fa0ce1b359,0x70e789d2f5d469ea30e0525dbfdd5515d6ead30d + # + cd $CONFIG_DIR + + getRelaysSolidity + echo + echo + + echo "Adding relay to BMC Management" + echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" + echo -e "\033[0;31m DANGER:: This method removes all existing previous relays, and adds $1 as new relay addresses \033[0m" + echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" + sleep 1 + read -p "Are you sure you want to proceed [y/N]: " proceed + if [[ $proceed == "y" ]]; then + + cd $CONTRACTS_DIR/solidity/bmc + tx=$(truffle exec --network bsc "$SCRIPTS_DIR"/bmc.js \ + --method addRelay --link "$(cat $CONFIG_DIR/icon.addr.bmcbtp)" --addr "${1}") + echo "$tx" >$CONFIG_DIR/tx/addRelay.bmc.bsc + getRelaysSolidity + fi + +} + +if [ $# -eq 0 ]; then + echo "No arguments supplied: Pass --help or -h" +elif [ $1 == "--remove" ]; then + echo "Removing relay " $2 + removeRelaySolidity $2 +elif [ $1 == "--add" ]; then + echo "Adding relay " $2 + addRelaySolidity $2 +elif [ $1 == "--get" ]; then + getRelaysSolidity +else + echo "Invalid argument " + echo "Ensure config.sh is for relevant configuration" + echo + echo "Usage: " + echo " --add addr : Add Relayer" + echo " --remove addr : Remove Relayer" + echo " --get : Get Relayers" +fi