Skip to content

Commit

Permalink
Merge pull request #181 from icon-project/story/update-contract-deplo…
Browse files Browse the repository at this point in the history
…y-script-#180

Story/update contract deploy script #180
  • Loading branch information
manishbista28 authored Aug 5, 2022
2 parents 8b8f807 + 083955e commit 9c82bb9
Show file tree
Hide file tree
Showing 11 changed files with 407 additions and 187 deletions.
3 changes: 3 additions & 0 deletions devnet/docker/icon-bsc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions devnet/docker/icon-bsc/README.md
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions devnet/docker/icon-bsc/docker-compose-bmr.yml
Original file line number Diff line number Diff line change
@@ -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}
Empty file modified devnet/docker/icon-bsc/iconvalidators
100644 → 100755
Empty file.
6 changes: 6 additions & 0 deletions devnet/docker/icon-bsc/scripts/bmc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion devnet/docker/icon-bsc/scripts/bts.js
Original file line number Diff line number Diff line change
@@ -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'] });
Expand All @@ -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)
}
Expand Down
47 changes: 47 additions & 0 deletions devnet/docker/icon-bsc/scripts/config.sh
Original file line number Diff line number Diff line change
@@ -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')



201 changes: 201 additions & 0 deletions devnet/docker/icon-bsc/scripts/deploysc.sh
Original file line number Diff line number Diff line change
@@ -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
37 changes: 36 additions & 1 deletion devnet/docker/icon-bsc/scripts/keystore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 </dev/urandom | head -c 64 > $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}
}
Loading

0 comments on commit 9c82bb9

Please sign in to comment.