diff --git a/devnet/docker/icon-bsc/Makefile b/devnet/docker/icon-bsc/Makefile index 2ce952863..88c4ab7f7 100644 --- a/devnet/docker/icon-bsc/Makefile +++ b/devnet/docker/icon-bsc/Makefile @@ -12,6 +12,9 @@ clean: docker-compose down -v --remove-orphans rm -rf local/artifacts +buildsc: + make -C ../../../ dist-javascore dist-sol + build: make -C ../../../ dist-javascore dist-sol iconbridge-image mkdir -p ./data/bsc/node1 diff --git a/devnet/docker/icon-bsc/README.md b/devnet/docker/icon-bsc/README.md new file mode 100644 index 000000000..a5a163ace --- /dev/null +++ b/devnet/docker/icon-bsc/README.md @@ -0,0 +1,19 @@ +Run bsc node with +cd icon-bridge/devnet/docker/bsc-node +docker run -d -p 8545:8545 -p 8546:8546 bsc-node + +Run goloop node using "icon" docker image from +icon-bridge/devnet/docker/icon-hmny/src/docker-compose.nodes.yml + +To build javascore +make buildsc + +Provide parameters in scripts/config.sh + +Deploy smart contract with +cd ./scripts/ +./deploysc.sh + +Run relay with +export bmr_config_json=$(cat ./_ixh/bmr.config.json) +docker-compose -f docker-compose-bmr.yml up -d diff --git a/devnet/docker/icon-bsc/docker-compose-bmr.yml b/devnet/docker/icon-bsc/docker-compose-bmr.yml new file mode 100644 index 000000000..1a9af02f9 --- /dev/null +++ b/devnet/docker/icon-bsc/docker-compose-bmr.yml @@ -0,0 +1,18 @@ +version: '3.3' +services: + + bmr: + image: localnets:5000/bmr:latest + container_name: bmr + network_mode: host + restart: unless-stopped + # ports: + # - 6060:6060 # golang pprof + entrypoint: ["/bin/bash", "-c"] + command: + - | + echo '$bmr_config_json' >/config.json + /bin/iconbridge -config /config.json + environment: + AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID} + AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY} diff --git a/devnet/docker/icon-bsc/iconvalidators b/devnet/docker/icon-bsc/iconvalidators old mode 100644 new mode 100755 diff --git a/devnet/docker/icon-bsc/scripts/bmc.js b/devnet/docker/icon-bsc/scripts/bmc.js index cf4b09ccc..bbcbdeec2 100644 --- a/devnet/docker/icon-bsc/scripts/bmc.js +++ b/devnet/docker/icon-bsc/scripts/bmc.js @@ -31,6 +31,12 @@ module.exports = async function (callback) { //console.log(await bmcManagement.getRelays(argv.link)) console.log(tx) break; + case "addOwner": + console.log("Add bmc owner ", argv.addr) + tx = await bmcManagement.addOwner(argv.addr) + //console.log(await bmcManagement.getRelays(argv.link)) + console.log(tx) + break; case "addService": console.log("Add Service ", argv.name) tx = await bmcManagement.addService(argv.name, argv.addr) diff --git a/devnet/docker/icon-bsc/scripts/bts.js b/devnet/docker/icon-bsc/scripts/bts.js index 16e7142de..1a17f10c4 100644 --- a/devnet/docker/icon-bsc/scripts/bts.js +++ b/devnet/docker/icon-bsc/scripts/bts.js @@ -1,5 +1,4 @@ const BTSCore = artifacts.require("BTSCore"); -const address = require('./addresses.json'); module.exports = async function (callback) { try { var argv = require('minimist')(process.argv.slice(2), { string: ['addr'] }); @@ -17,6 +16,12 @@ module.exports = async function (callback) { tx = await btsCore.coinId(argv.coinName); console.log(tx); break; + case "addOwner": + console.log("Add bts owner ", argv.addr) + tx = await btsCore.addOwner(argv.addr) + //console.log(await bmcManagement.getRelays(argv.link)) + console.log(tx) + break; default: console.error("Bad input for method, ", argv) } diff --git a/devnet/docker/icon-bsc/scripts/config.sh b/devnet/docker/icon-bsc/scripts/config.sh new file mode 100644 index 000000000..9be2ede96 --- /dev/null +++ b/devnet/docker/icon-bsc/scripts/config.sh @@ -0,0 +1,47 @@ +#!/bin/sh +BUILD_DIR=$(echo "$(cd "$(dirname "../../../../../")"; pwd)"/build) +BASE_DIR=$(echo "$(cd "$(dirname "../../")"; pwd)") + +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}} + +################################################################################### + +export ICON_ENDPOINT='http://localhost:9080/api/v3/default' +#'https://lisbon.net.solidwallet.io/api/v3/icon_dex' +export ICON_KEY_STORE=$ICONBRIDGE_CONFIG_DIR/keystore/icon.god.wallet.json +export ICON_SECRET=$ICONBRIDGE_CONFIG_DIR/keystore/icon.god.wallet.secret +export ICON_NATIVE_COIN=('ICX') +export ICON_NATIVE_TOKEN=('TICX' 'ETH') +export ICON_WRAPPED_COIN=('TBNB' 'BNB') + +export GOLOOP_RPC_STEP_LIMIT=5000000000 +export GOLOOP_RPC_NID='0x5b9a77' +#'0x2' +GOLOOPCHAIN=${GOLOOPCHAIN:-'goloop'} +export GOLOOP_RPC_URI=$ICON_ENDPOINT +export GOLOOP_RPC_KEY_STORE=$ICON_KEY_STORE +export GOLOOP_RPC_KEY_SECRET=$ICON_SECRET + +################################################################################### + +export BSC_ENDPOINT='http://localhost:8545' +#'https://data-seed-prebsc-1-s1.binance.org:8545' +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 +export BSC_NID=${BSC_NID:-'97'} +export BSC_BMC_NET=${BSC_BMC_NET:-'0x61.bsc'} + +export BSC_NATIVE_COIN=('BNB') +export BSC_NATIVE_TOKEN=('TBNB' 'ETH') +export BSC_WRAPPED_COIN=('ICX' 'TICX') + + + diff --git a/devnet/docker/icon-bsc/scripts/deploysc.sh b/devnet/docker/icon-bsc/scripts/deploysc.sh new file mode 100755 index 000000000..dc807d42a --- /dev/null +++ b/devnet/docker/icon-bsc/scripts/deploysc.sh @@ -0,0 +1,201 @@ +#!/bin/bash +set -e + +# Parts of this code is adapted from https://github.com/icon-project/btp/blob/goloop2moonbeam/testnet/goloop2moonbeam/scripts +source config.sh +source keystore.sh +source rpc.sh + + +deploysc() { + + echo "start..." + echo "check god keys..." + if [ ! -f "${ICON_KEY_STORE}" ]; then + ensure_key_store $ICON_KEY_STORE $ICON_SECRET + echo "Fund newly created wallet " $ICON_KEY_STORE + exit 0 + fi + if [ ! -f "${BSC_KEY_STORE}" ]; then + ensure_bsc_key_store $BSC_KEY_STORE $BSC_SECRET + echo "Fund newly created wallet " $BSC_KEY_STORE + exit 0 + fi + export PRIVATE_KEY="[\""$(cat $BSC_KEY_STORE.priv)"\"]" + # add owners + echo "List/Create user accounts" + ensure_key_store $CONFIG_DIR/keystore/icon.bts.wallet.json $CONFIG_DIR/keystore/icon.bts.wallet.secret + ensure_key_store $CONFIG_DIR/keystore/icon.bmc.wallet.json $CONFIG_DIR/keystore/icon.bmc.wallet.secret + ensure_key_store $CONFIG_DIR/keystore/icon.bmr.wallet.json $CONFIG_DIR/keystore/icon.bmr.wallet.secret + ensure_key_store $CONFIG_DIR/keystore/icon.fa.wallet.json $CONFIG_DIR/keystore/icon.fa.wallet.secret + + ensure_bsc_key_store $CONFIG_DIR/keystore/bsc.bts.wallet.json $CONFIG_DIR/keystore/bsc.bts.wallet.secret + ensure_bsc_key_store $CONFIG_DIR/keystore/bsc.bmc.wallet.json $CONFIG_DIR/keystore/bsc.bmc.wallet.secret + ensure_bsc_key_store $CONFIG_DIR/keystore/bsc.bmr.wallet.json $CONFIG_DIR/keystore/bsc.bmr.wallet.secret + + echo "$GOLOOP_RPC_NID.icon" >$CONFIG_DIR/net.btp.icon #0x240fa7.icon + mkdir -p $CONFIG_DIR/tx + + source token.javascore.sh + source token.solidity.sh + + echo "Deploy Javascore" + sleep 2 + #deploy icon + deploy_javascore_bmc + deploy_javascore_bts + for v in "${ICON_NATIVE_TOKEN[@]}" + do + deploy_javascore_irc2 $v $v + done + + + #deploy bsc + deploy_solidity_bmc + deploy_solidity_bts + for v in "${BSC_NATIVE_TOKEN[@]}" + do + deploy_solidity_token $v $v + done + + generate_addresses_json >$CONFIG_DIR/addresses.json + + #configure icon + echo "CONFIGURE ICON" + configure_javascore_add_bmc_owner + configure_javascore_bmc_setFeeAggregator + configure_javascore_add_bts + configure_javascore_add_bts_owner + configure_javascore_bts_setICXFee + #configure bsc + echo "CONFIGURE BSC" + configure_solidity_add_bmc_owner + configure_solidity_add_bts_service + configure_solidity_set_fee_ratio + configure_solidity_add_bts_owner + + + #Link icon + echo "LINK ICON" + configure_javascore_addLink + configure_bmc_javascore_addRelay + echo "Register ICON Tokens" + for v in "${ICON_NATIVE_TOKEN[@]}" + do + configure_javascore_register_native_token $v $v + get_btp_icon_coinId $v + done + for v in "${ICON_WRAPPED_COIN[@]}" + do + configure_javascore_register_wrapped_coin $v $v + get_btp_icon_coinId $v + done + + + #Link bsc + echo "LINK BSC" + add_icon_link + set_link_height + add_icon_relay + echo "Register BSC Tokens" + for v in "${BSC_NATIVE_TOKEN[@]}" + do + bsc_register_native_token $v $v + get_coinID $v + done + for v in "${BSC_WRAPPED_COIN[@]}" + do + bsc_register_wrapped_coin $v $v + get_coinID $v + done + + generate_relay_config >$CONFIG_DIR/bmr.config.json + wait_for_file $CONFIG_DIR/bmr.config.json + echo "Done deploying" +} + +wait_for_file() { + FILE_NAME=$1 + timeout=10 + while [ ! -f "$FILE_NAME" ]; do + if [ "$timeout" == 0 ]; then + echo "ERROR: Timeout while waiting for the file $FILE_NAME." + exit 1 + fi + sleep 1 + timeout=$(expr $timeout - 1) + + echo "waiting for the output file: $FILE_NAME" + done +} + + + +generate_relay_config() { + jq -n ' + .base_dir = $base_dir | + .log_level = "debug" | + .console_level = "trace" | + .log_writer.filename = $log_writer_filename | + .relays = [ $b2i_relay, $i2b_relay ]' \ + --arg base_dir "bmr" \ + --arg log_writer_filename "bmr/bmr.log" \ + --argjson b2i_relay "$( + jq -n ' + .name = "b2i" | + .src.address = $src_address | + .src.endpoint = [ $src_endpoint ] | + .src.options = $src_options | + .src.offset = $src_offset | + .dst.address = $dst_address | + .dst.endpoint = [ $dst_endpoint ] | + .dst.options = $dst_options | + .dst.key_store = $dst_key_store | + .dst.key_store.coinType = $dst_key_store_cointype | + .dst.key_password = $dst_key_password ' \ + --arg src_address "$(cat $CONFIG_DIR/btp.bsc.btp.address)" \ + --arg src_endpoint "$BSC_ENDPOINT" \ + --argjson src_offset "$(cat $CONFIG_DIR/btp.bsc.block.height)" \ + --argjson src_options "$( + jq -n {} + )" \ + --arg dst_address "$(cat $CONFIG_DIR/btp.icon.btp.address)" \ + --arg dst_endpoint "$ICON_ENDPOINT" \ + --argfile dst_key_store "$CONFIG_DIR/keystore/icon.bmr.wallet.json" \ + --arg dst_key_store_cointype "icx" \ + --arg dst_key_password "$(cat $CONFIG_DIR/keystore/icon.bmr.wallet.secret)" \ + --argjson dst_options '{"step_limit":13610920010, "tx_data_size_limit":8192}' + )" \ + --argjson i2b_relay "$( + jq -n ' + .name = "i2b" | + .src.address = $src_address | + .src.endpoint = [ $src_endpoint ] | + .src.offset = $src_offset | + .src.options.verifier.blockHeight = $src_options_verifier_blockHeight | + .src.options.verifier.validatorsHash = $src_options_verifier_validatorsHash | + .dst.address = $dst_address | + .dst.endpoint = [ $dst_endpoint ] | + .dst.options = $dst_options | + .dst.tx_data_size_limit = $dst_tx_data_size_limit | + .dst.key_store = $dst_key_store | + .dst.key_store.coinType = $dst_key_store_cointype | + .dst.key_password = $dst_key_password ' \ + --arg src_address "$(cat $CONFIG_DIR/btp.icon.btp.address)" \ + --arg src_endpoint "$ICON_ENDPOINT" \ + --argjson src_offset "$(cat $CONFIG_DIR/btp.icon.block.height)" \ + --argjson src_options_verifier_blockHeight "$(cat $CONFIG_DIR/btp.icon.block.height)" \ + --arg src_options_verifier_validatorsHash "$(cat $CONFIG_DIR/btp.icon.validators.hash)" \ + --arg dst_address "$(cat $CONFIG_DIR/btp.bsc.btp.address)" \ + --arg dst_endpoint "$BSC_ENDPOINT" \ + --argfile dst_key_store "$CONFIG_DIR/keystore/bsc.bmr.wallet.json" \ + --arg dst_key_store_cointype "evm" \ + --arg dst_key_password "$(cat $CONFIG_DIR/keystore/bsc.bmr.wallet.secret)" \ + --argjson dst_tx_data_size_limit 8192 \ + --argjson dst_options '{"gas_limit":8000000}' + )" +} + +#wait-for-it.sh $GOLOOP_RPC_ADMIN_URI +# run provisioning +deploysc diff --git a/devnet/docker/icon-bsc/scripts/keystore.sh b/devnet/docker/icon-bsc/scripts/keystore.sh index 6f405cce6..04735a6c8 100644 --- a/devnet/docker/icon-bsc/scripts/keystore.sh +++ b/devnet/docker/icon-bsc/scripts/keystore.sh @@ -21,7 +21,42 @@ ensure_key_store() { local KEY_STORE=$1 local KEY_SECRET=$(ensure_key_secret $2) if [ ! -f "${KEY_STORE}" ]; then - goloop ks gen --out $KEY_STORE -p $(cat ${KEY_SECRET}) > /dev/null 2>&1 + goloop ks gen --out ${KEY_STORE}tmp -p $(cat ${KEY_SECRET}) > /dev/null 2>&1 + cat ${KEY_STORE}tmp | jq -r . > ${KEY_STORE} + rm ${KEY_STORE}tmp + fi echo ${KEY_STORE} +} + +ensure_bsc_key_store() { + if [ $# -lt 2 ] ; then + echo "Usage: ensure_key_store KEYSTORE_PATH SECRET_PATH" + return 1 + fi + + local KEY_STORE_PATH=$1 + local KEY_SECRET_PATH=$(ensure_key_secret $2) + if [ ! -f "${KEY_STORE_PATH}" ]; then + mkdir -p $ICONBRIDGE_CONFIG_DIR/keystore + tr -dc A-Fa-f0-9 $ICONBRIDGE_CONFIG_DIR/keystore/$(basename ${KEY_STORE_PATH}).priv + tmpPath=$(geth account import --datadir $ICONBRIDGE_CONFIG_DIR --password $KEY_SECRET_PATH $ICONBRIDGE_CONFIG_DIR/keystore/$(basename ${KEY_STORE_PATH}).priv | sed -e "s/^Address: {//" -e "s/}//") + fileMatch=$(find $ICONBRIDGE_CONFIG_DIR/keystore -type f -name '*'$tmpPath) + cat $fileMatch | jq -r . > $KEY_STORE_PATH + rm $fileMatch + fi + echo ${KEY_STORE_PATH} +} + +ensure_empty_key_secret() { + if [ $# -lt 1 ] ; then + echo "Usage: ensure_key_secret SECRET_PATH" + return 1 + fi + local KEY_SECRET=$1 + if [ ! -f "${KEY_SECRET}" ]; then + mkdir -p $(dirname ${KEY_SECRET}) + echo -n '' > ${KEY_SECRET} + fi + echo ${KEY_SECRET} } \ No newline at end of file diff --git a/devnet/docker/icon-bsc/scripts/token.javascore.sh b/devnet/docker/icon-bsc/scripts/token.javascore.sh index e844699f1..fea3db052 100644 --- a/devnet/docker/icon-bsc/scripts/token.javascore.sh +++ b/devnet/docker/icon-bsc/scripts/token.javascore.sh @@ -14,7 +14,7 @@ deploy_javascore_bmc() { goloop rpc sendtx deploy $CONTRACTS_DIR/javascore/bmc.jar \ --content_type application/java \ --param _net=$(cat net.btp.icon) | jq -r . >tx.icon.bmc - sleep 2 + sleep 3 extract_scoreAddress tx.icon.bmc btp.icon.bmc echo "btp://$(cat net.btp.icon)/$(cat btp.icon.bmc)" >btp.icon.btp.address btp_icon_block_height=$(goloop_lastblock | jq -r .height) @@ -22,14 +22,6 @@ deploy_javascore_bmc() { echo $(URI=$ICON_ENDPOINT HEIGHT=$(decimal2Hex $(($btp_icon_block_height - 1))) $ICONBRIDGE_BIN_DIR/iconvalidators | jq -r .hash) > btp.icon.validators.hash } -deploy_javascore_bsr() { - echo "deploying javascore bsr" - cd $CONFIG_DIR - goloop rpc sendtx deploy $CONTRACTS_DIR/javascore/bsr.jar \ - --content_type application/java | jq -r . >tx.icon.bsr - extract_scoreAddress tx.icon.bsr btp.icon.bsr -} - deploy_javascore_bts() { echo "deploying javascore bts" cd $CONFIG_DIR @@ -37,38 +29,30 @@ deploy_javascore_bts() { --content_type application/java \ --param _name="ICX" \ --param _bmc=$(cat btp.icon.bmc) \ + --param _decimals="0x12" \ --param _serializedIrc2=$(xxd -p $CONTRACTS_DIR/javascore/irc2Tradeable.jar | tr -d '\n') | jq -r . > tx.icon.bts - sleep 2 + sleep 3 extract_scoreAddress tx.icon.bts btp.icon.bts } deploy_javascore_irc2() { - echo "deploying javascore IRC2Token TICX" - cd $CONFIG_DIR - goloop rpc sendtx deploy $CONTRACTS_DIR/javascore/irc2.jar \ - --content_type application/java \ - --param _name="TICX" \ - --param _symbol="TICX" \ - --param _initialSupply="0x186a0" \ - --param _decimals="0x12" | jq -r . >tx.icon.ticx - extract_scoreAddress tx.icon.ticx btp.icon.ticx -} - -deploy_javascore_eth() { - echo "deploying javascore IRC2Token ETH" + echo "deploying javascore IRC2Token " $1 cd $CONFIG_DIR goloop rpc sendtx deploy $CONTRACTS_DIR/javascore/irc2.jar \ --content_type application/java \ - --param _name="ETH" \ - --param _symbol="ETH" \ + --param _name=$1 \ + --param _symbol=$2 \ --param _initialSupply="0x186a0" \ - --param _decimals="0x12" | jq -r . >tx.icon.eth - extract_scoreAddress tx.icon.eth btp.icon.eth + --param _decimals="0x12" | jq -r . >tx.icon.$1 + sleep 10 + extract_scoreAddress tx.icon.$1 btp.icon.$1 } + configure_javascore_add_bmc_owner() { echo "bmc Add Owner" - local btp_icon_bmc_owner=$(cat $GOLOOP_RPC_KEY_STORE | jq -r .address) + echo $CONFIG_DIR/keystore/icon.bmc.wallet.json + local btp_icon_bmc_owner=$(cat $CONFIG_DIR/keystore/icon.bmc.wallet.json | jq -r .address) cd $CONFIG_DIR local is_owner=$(goloop rpc call \ --to $(cat btp.icon.bmc) \ @@ -77,24 +61,26 @@ configure_javascore_add_bmc_owner() { if [ "$is_owner" == "0x0" ]; then goloop rpc sendtx call --to $(cat btp.icon.bmc) \ --method addOwner \ - --param _addr=$btp_icon_bmc_owner > tx/addbmcowner.icon - ensure_txresult tx/addbmcowner.icon + --param _addr=$btp_icon_bmc_owner | jq -r . > tx/addbmcowner.icon + sleep 2 + ensure_txresult tx/addbmcowner.icon fi } configure_javascore_bmc_setFeeAggregator() { echo "bmc setFeeAggregator" cd $CONFIG_DIR - ensure_key_store fa.ks.json fa.secret - FA=$(cat fa.ks.json | jq -r .address) + FA=$(cat $CONFIG_DIR/keystore/icon.fa.wallet.json | jq -r .address) goloop rpc sendtx call --to $(cat btp.icon.bmc) \ --method setFeeAggregator \ --param _addr=${FA} | jq -r . >tx/setFeeAggregator.icon + sleep 2 ensure_txresult tx/setFeeAggregator.icon goloop rpc sendtx call --to $(cat btp.icon.bmc) \ --method setFeeGatheringTerm \ --param _value=1000 | jq -r . >tx/setFeeGatheringTerm.icon + sleep 2 ensure_txresult tx/setFeeGatheringTerm.icon } @@ -105,13 +91,14 @@ configure_javascore_add_bts() { --method addService \ --value 0 \ --param _addr=$(cat btp.icon.bts) \ - --param _svc=$SVC_NAME | jq -r . >tx/addService.icon + --param _svc="bts" | jq -r . >tx/addService.icon + sleep 2 ensure_txresult tx/addService.icon } configure_javascore_add_bts_owner() { echo "Add bts Owner" - local btp_icon_bts_owner=$(cat $GOLOOP_RPC_KEY_STORE | jq -r .address) + local btp_icon_bts_owner=$(cat $CONFIG_DIR/keystore/icon.bts.wallet.json | jq -r .address) cd $CONFIG_DIR local is_owner=$(goloop rpc call \ --to $(cat btp.icon.bts) \ @@ -121,19 +108,11 @@ configure_javascore_add_bts_owner() { goloop rpc sendtx call --to $(cat btp.icon.bts) \ --method addOwner \ --param _addr=$btp_icon_bts_owner | jq -r . >tx/addBtsOwner.icon + sleep 2 ensure_txresult tx/addBtsOwner.icon fi } -configure_javascore_set_bsr() { - echo "bts set bsr" - cd $CONFIG_DIR - goloop rpc sendtx call --to $(cat btp.icon.bts) \ - --method addRestrictor \ - --param _address=$(cat btp.icon.bsr) | jq -r . >tx/addRestrictor.icon - ensure_txresult tx/addRestrictor.icon -} - configure_javascore_bts_setICXFee() { echo "bts set ICX fee" @@ -145,6 +124,7 @@ configure_javascore_bts_setICXFee() { --param _name="ICX" \ --param _feeNumerator=$(decimal2Hex $btp_bts_fee_numerator) \ --param _fixedFee=$(decimal2Hex $btp_bts_fixed_fee) | jq -r . >tx/setICXFee.icon + sleep 2 ensure_txresult tx/setICXFee.icon } @@ -154,105 +134,72 @@ configure_javascore_addLink() { goloop rpc sendtx call --to $(cat btp.icon.bmc) \ --method addLink \ --param _link=$(cat btp.bsc.btp.address) | jq -r . >tx/addLink.icon + sleep 2 ensure_txresult tx/addLink.icon goloop rpc sendtx call --to $(cat btp.icon.bmc) \ --method setLinkRxHeight \ --param _link=$(cat btp.bsc.btp.address) \ --param _height=$(cat btp.bsc.block.height)| jq -r . >tx/setLinkRxHeight.icon + sleep 2 ensure_txresult tx/setLinkRxHeight.icon } configure_bmc_javascore_addRelay() { echo "Adding bsc Relay" - local btp_icon_bmr_owner=$(cat $GOLOOP_RPC_KEY_STORE | jq -r .address) + local btp_icon_bmr_owner=$(cat $CONFIG_DIR/keystore/icon.bmr.wallet.json | jq -r .address) cd $CONFIG_DIR goloop rpc sendtx call --to $(cat btp.icon.bmc) \ --method addRelay \ --param _link=$(cat btp.bsc.btp.address) \ --param _addr=${btp_icon_bmr_owner} | jq -r . >tx/addRelay.icon + sleep 2 ensure_txresult tx/addRelay.icon } -configure_javascore_register_bnb() { - echo "Register BNB" - cd $CONFIG_DIR - local btp_bts_fee_numerator=100 - local btp_bts_fixed_fee=5000 - goloop rpc sendtx call --to $(cat btp.icon.bts) \ - --method register \ - --param _name="BNB" \ - --param _symbol="BNB" \ - --param _decimals="0x12" \ - --param _feeNumerator=$(decimal2Hex $btp_bts_fee_numerator) \ - --param _fixedFee=$(decimal2Hex $btp_bts_fixed_fee) | jq -r . >tx/register.coin.bnb - ensure_txresult tx/register.coin.bnb -} - -get_btp_icon_bnb() { - echo "Get BTP Icon BNB Addr" - cd $CONFIG_DIR - goloop rpc sendtx call --to $(cat btp.icon.bts) \ - --method "coinId" \ - --param _coinName="BNB" | jq -r . >tx/bnb.coin.icon - ensure_txresult tx/bnb.coin.icon -} - -configure_javascore_register_ticx() { - echo "Register TICX" - cd $CONFIG_DIR - local btp_bts_fee_numerator=100 - local btp_bts_fixed_fee=5000 - goloop rpc sendtx call --to $(cat btp.icon.bts) \ - --method register \ - --param _name=TICX \ - --param _symbol=TICX \ - --param _decimals=0x12 \ - --param _addr=$(cat btp.icon.ticx) \ - --param _feeNumerator=$(decimal2Hex $btp_bts_fee_numerator) \ - --param _fixedFee=$(decimal2Hex $btp_bts_fixed_fee) | jq -r . >tx/register.coin.ticx - ensure_txresult tx/register.coin.ticx -} -configure_javascore_register_eth() { - echo "Register ETH" +configure_javascore_register_native_token() { + echo "Register Native Token " $1 cd $CONFIG_DIR local btp_bts_fee_numerator=100 local btp_bts_fixed_fee=5000 goloop rpc sendtx call --to $(cat btp.icon.bts) \ --method register \ - --param _name=ETH \ - --param _symbol=ETH \ + --param _name=$1 \ + --param _symbol=$2 \ --param _decimals=0x12 \ - --param _addr=$(cat btp.icon.eth) \ + --param _addr=$(cat btp.icon.$1) \ --param _feeNumerator=$(decimal2Hex $btp_bts_fee_numerator) \ - --param _fixedFee=$(decimal2Hex $btp_bts_fixed_fee) | jq -r . >tx/register.coin.eth - ensure_txresult tx/register.coin.eth + --param _fixedFee=$(decimal2Hex $btp_bts_fixed_fee) | jq -r . >tx/register.coin.$1 + sleep 10 + ensure_txresult tx/register.coin.$1 } -configure_javascore_register_tbnb() { - echo "Register TBNB" +configure_javascore_register_wrapped_coin() { + echo "Register Wrapped Coin " $1 cd $CONFIG_DIR local btp_bts_fee_numerator=100 local btp_bts_fixed_fee=5000 goloop rpc sendtx call --to $(cat btp.icon.bts) \ --method register \ - --param _name=TBNB \ - --param _symbol=TBNB \ + --param _name=$1 \ + --param _symbol=$2 \ --param _decimals=0x12 \ --param _feeNumerator=$(decimal2Hex $btp_bts_fee_numerator) \ - --param _fixedFee=$(decimal2Hex $btp_bts_fixed_fee) | jq -r . >tx/register.coin.tbnb - ensure_txresult tx/register.coin.tbnb + --param _fixedFee=$(decimal2Hex $btp_bts_fixed_fee) | jq -r . >tx/register.coin.$1 + sleep 10 + ensure_txresult tx/register.coin.$1 } -get_btp_icon_tbnb() { - echo "Get BTP Icon TBNB Addr" +get_btp_icon_coinId() { + echo "Get BTP Icon Addr " $1 cd $CONFIG_DIR goloop rpc sendtx call --to $(cat btp.icon.bts) \ --method coinId \ - --param _coinName=TBNB | jq -r . >tx/tbnb.coin.icon - ensure_txresult tx/tbnb.coin.icon + --param _coinName=$1 | jq -r . >tx/icon.coinId.$1 + sleep 10 + ensure_txresult tx/icon.coinId.$1 } bsh_javascore_balance() { diff --git a/devnet/docker/icon-bsc/scripts/token.solidity.sh b/devnet/docker/icon-bsc/scripts/token.solidity.sh index 82809923e..1d77edb75 100644 --- a/devnet/docker/icon-bsc/scripts/token.solidity.sh +++ b/devnet/docker/icon-bsc/scripts/token.solidity.sh @@ -12,32 +12,29 @@ deploy_solidity_bmc() { cd $CONTRACTS_DIR/solidity/bmc cp $ICONBRIDGE_BASE_DIR/bin/env ./.env rm -rf contracts/test build .openzeppelin + truffle compile --all BMC_BTP_NET=$BSC_BMC_NET \ truffle migrate --network bsc --compile-all eth_blocknumber > $CONFIG_DIR/btp.bsc.block.height generate_metadata "BMC" } - - deploy_solidity_bts() { echo "deploying solidity bts" cd $CONTRACTS_DIR/solidity/bts cp $ICONBRIDGE_BASE_DIR/bin/env ./.env rm -rf contracts/test build .openzeppelin - + truffle compile --all BSH_COIN_NAME="BNB" \ BSH_COIN_FEE=100 \ BSH_FIXED_FEE=5000 \ BMC_PERIPHERY_ADDRESS="$(cat $CONFIG_DIR/btp.bsc.bmc.periphery)" \ - BSH_SERVICE=$SVC_NAME \ truffle migrate --compile-all --network bsc --f 1 --to 1 generate_metadata "BTS" } deploy_solidity_token() { - echo "deploying solidity token " - echo $1 + echo "deploying solidity token " $1 cd $CONTRACTS_DIR/solidity/bts cp $ICONBRIDGE_BASE_DIR/bin/env ./.env export BSH_COIN_NAME=$1 @@ -50,14 +47,31 @@ deploy_solidity_token() { } configure_solidity_add_bts_service() { - echo "adding ${SVC_NAME} service into BMC" + echo "adding bts service into BMC" cd $CONTRACTS_DIR/solidity/bmc tx=$(truffle exec --network bsc "$SCRIPTS_DIR"/bmc.js \ - --method addService --name $SVC_NAME --addr $(cat $CONFIG_DIR/btp.bsc.bts.periphery)) + --method addService --name "bts" --addr $(cat $CONFIG_DIR/btp.bsc.bts.periphery)) echo "$tx" >$CONFIG_DIR/tx/addService.bsc } +configure_solidity_add_bmc_owner() { + echo "adding bmc owner" + BSC_BMC_USER=$(cat $CONFIG_DIR/keystore/bsc.bmc.wallet.json | jq -r .address) + cd $CONTRACTS_DIR/solidity/bmc + tx=$(truffle exec --network bsc "$SCRIPTS_DIR"/bmc.js \ + --method addOwner --addr "0x${BSC_BMC_USER}") + echo "$tx" >$CONFIG_DIR/tx/addBmcUser.bsc +} + configure_solidity_add_bts_owner() { + echo "adding bts owner" + BSC_BTS_USER=$(cat $CONFIG_DIR/keystore/bsc.bts.wallet.json | jq -r .address) + cd $CONTRACTS_DIR/solidity/bts + tx=$(truffle exec --network bsc "$SCRIPTS_DIR"/bts.js \ + --method addOwner --addr "0x${BSC_BTS_USER}") + echo "$tx" >$CONFIG_DIR/tx/addBtsUser.bsc +} + configure_solidity_set_fee_ratio() { echo "SetFee Ratio" cd $CONTRACTS_DIR/solidity/bts @@ -84,7 +98,7 @@ set_link_height() { add_icon_relay() { echo "adding icon link" - BSC_RELAY_USER=$(cat $BSC_KEY_STORE | jq -r .address) + BSC_RELAY_USER=$(cat $CONFIG_DIR/keystore/bsc.bmr.wallet.json | jq -r .address) cd $CONTRACTS_DIR/solidity/bmc tx=$(truffle exec --network bsc "$SCRIPTS_DIR"/bmc.js \ --method addRelay --link $(cat $CONFIG_DIR/btp.icon.btp.address) --addr "0x${BSC_RELAY_USER}") @@ -92,46 +106,10 @@ add_icon_relay() { } -# bsc_register_icx() { -# echo "bts: Register ICX: " -# local btp_bts_fee_numerator=100 -# local btp_bts_fixed_fee=5000 -# echo "Registering ICX" -# cd $CONTRACTS_DIR/solidity/bts -# tx=$(truffle exec --network bsc "$SCRIPTS_DIR"/bts.js \ -# --method register --name "ICX" --symbol "ICX" --decimals 18 --addr "0x0000000000000000000000000000000000000000" --feeNumerator ${btp_bts_fee_numerator} --fixedFee ${btp_bts_fixed_fee}) -# echo "$tx" >$CONFIG_DIR/tx/register.icx.bsc -# } - -# get_coinID_icx() { -# echo "getCoinID ICX" -# cd $CONTRACTS_DIR/solidity/bts -# tx=$(truffle exec --network bsc "$SCRIPTS_DIR"/bts.js \ -# --method coinId --coinName "ICX") -# echo "$tx" >$CONFIG_DIR/tx/coinID.icx -# } -# bsc_register_ticx() { -# local btp_bts_fee_numerator=100 -# local btp_bts_fixed_fee=5000 -# echo "Registering TICX" -# cd $CONTRACTS_DIR/solidity/bts -# tx=$(truffle exec --network bsc "$SCRIPTS_DIR"/bts.js \ -# --method register --name "TICX" --symbol "TICX" --decimals 18 --addr "0x0000000000000000000000000000000000000000" --feeNumerator ${btp_bts_fee_numerator} --fixedFee ${btp_bts_fixed_fee}) -# echo "$tx" >$CONFIG_DIR/tx/register.ticx.bsc -# } - -# get_coinID_ticx() { -# echo "getCoinID TICX" -# cd $CONTRACTS_DIR/solidity/bts -# tx=$(truffle exec --network bsc "$SCRIPTS_DIR"/bts.js \ -# --method coinId --coinName "TICX") -# echo "$tx" >$CONFIG_DIR/tx/coinID.ticx -# } - bsc_register_wrapped_coin() { + echo "bts: Register " $1 local btp_bts_fee_numerator=100 local btp_bts_fixed_fee=5000 - echo "Registering " $1 cd $CONTRACTS_DIR/solidity/bts tx=$(truffle exec --network bsc "$SCRIPTS_DIR"/bts.js \ --method register --name "$1" --symbol "$2" --decimals 18 --addr "0x0000000000000000000000000000000000000000" --feeNumerator ${btp_bts_fee_numerator} --fixedFee ${btp_bts_fixed_fee}) @@ -157,45 +135,6 @@ get_coinID() { echo "$tx" >$CONFIG_DIR/tx/coinID.$1 } -# bsc_register_tbnb() { -# echo "bts: Register TBNB: " -# local btp_bts_fee_numerator=100 -# local btp_bts_fixed_fee=5000 -# local addr=$(cat $CONFIG_DIR/btp.bsc.tbnb) -# cd $CONTRACTS_DIR/solidity/bts -# tx=$(truffle exec --network bsc "$SCRIPTS_DIR"/bts.js \ -# --method register --name "TBNB" --symbol "TBNB" --decimals 18 --addr $addr --feeNumerator $btp_bts_fee_numerator --fixedFee ${btp_bts_fixed_fee}) -# echo "$tx" >$CONFIG_DIR/tx/register.tbnb.bsc -# } - -# get_coinID_tbnb() { -# echo "getCoinID TBNB" -# cd $CONTRACTS_DIR/solidity/bts -# tx=$(truffle exec --network bsc "$SCRIPTS_DIR"/bts.js \ -# --method coinId --coinName "TBNB") -# echo "$tx" >$CONFIG_DIR/tx/coinID.tbnb -# } - -# bsc_register_eth() { -# echo "bts: Register ETH: " -# local btp_bts_fee_numerator=100 -# local btp_bts_fixed_fee=5000 -# local addr=$(cat $CONFIG_DIR/btp.bsc.eth) -# cd $CONTRACTS_DIR/solidity/bts -# tx=$(truffle exec --network bsc "$SCRIPTS_DIR"/bts.js \ -# --method register --name "ETH" --symbol "ETH" --decimals 18 --addr $addr --feeNumerator $btp_bts_fee_numerator --fixedFee ${btp_bts_fixed_fee}) -# echo "$tx" >$CONFIG_DIR/tx/register.eth.bsc -# } - -# get_coinID_eth() { -# echo "getCoinID ETH" -# cd $CONTRACTS_DIR/solidity/bts -# tx=$(truffle exec --network bsc "$SCRIPTS_DIR"/bts.js \ -# --method coinId --coinName "ETH") -# echo "$tx" >$CONFIG_DIR/tx/coinID.eth -# } - - bsc_updateRxSeq() { cd $CONTRACTS_DIR/solidity/bmc