diff --git a/scripts/testnet/add_wasm_state_to_genesis.sh b/scripts/testnet/add_wasm_state_to_genesis.sh index cc9270b1..2235b5cc 100755 --- a/scripts/testnet/add_wasm_state_to_genesis.sh +++ b/scripts/testnet/add_wasm_state_to_genesis.sh @@ -6,26 +6,46 @@ set -euxo pipefail # Then, it adds these states to a given original genesis file. # The final genesis file is placed in the current directory as genesis.json. # -source config.sh - -# -# PRELIMINARY CHECKS -# -ORIGINAL_GENESIS=$NODE_DIR/genesis.json -if [ ! -f "$ORIGINAL_GENESIS" ]; then - echo "Original genesis file not found inside node directory." - exit 1 -fi - -TMP_HOME=./tmp -rm -rf $TMP_HOME +# download_contract_release() downloads a file from seda-chain-contracts repo. +# Argument: +# $1: Wasm contract file name +function download_contract_release() { + local repo="sedaprotocol/seda-chain-contracts" + local url="https://api.github.com" + + mkdir -p $WASM_DIR + + function gh_curl() { + curl -H "Authorization: token $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.v3.raw" \ + $@ + } + + if [ "$CONTRACTS_VERSION" = "latest" ]; then + # Github should return the latest release first. + parser=".[0].assets | map(select(.name == \"${1}\"))[0].id" + else + parser=". | map(select(.tag_name == \"$CONTRACTS_VERSION\"))[0].assets | map(select(.name == \"${1}\"))[0].id" + fi; + + asset_id=`gh_curl -s $url/repos/$repo/releases | jq "$parser"` + if [ "$asset_id" = "null" ]; then + >&2 echo "ERROR: asset not found: version $CONTRACTS_VERSION, file $1" + exit 1 + fi; + + curl -sL --header "Authorization: token $GITHUB_TOKEN" \ + --header 'Accept: application/octet-stream' \ + https://$GITHUB_TOKEN:@api.github.com/repos/$repo/releases/assets/$asset_id \ + --output-dir $WASM_DIR --output ${1} +} # store_and_instantiate() stores and instantiates a contract and returns its address -# Accept arguments: +# Arguments: # $1: Contract file name # $2: Initial state -store_and_instantiate() { +function store_and_instantiate() { local TX_OUTPUT=$($BIN tx wasm store $WASM_DIR/$1 --from $ADDR --keyring-backend test --gas auto --gas-adjustment 1.2 --home $TMP_HOME -y --output json) [[ -z "$TX_OUTPUT" ]] && { echo "failed to get tx output" ; exit 1; } local TX_HASH=$(echo $TX_OUTPUT | jq -r .txhash) @@ -46,15 +66,36 @@ store_and_instantiate() { echo $CONTRACT_ADDRESS } + +source config.sh + +# +# PRELIMINARY CHECKS AND DOWNLOADS +# +ORIGINAL_GENESIS=$NODE_DIR/genesis.json +if [ ! -f "$ORIGINAL_GENESIS" ]; then + echo "Original genesis file not found inside node directory." + exit 1 +fi + +TMP_HOME=./tmp +rm -rf $TMP_HOME + +rm -rf $WASM_DIR +download_contract_release proxy_contract.wasm +download_contract_release staking.wasm +download_contract_release data_requests.wasm + + # # SCRIPT BEGINS - START CHAIN # $BIN init new node0 --home $TMP_HOME -$BIN keys add satoshi --home $TMP_HOME --keyring-backend test -ADDR=$($BIN keys show satoshi --home $TMP_HOME --keyring-backend test -a) +$BIN keys add deployer --home $TMP_HOME --keyring-backend test +ADDR=$($BIN keys show deployer --home $TMP_HOME --keyring-backend test -a) $BIN add-genesis-account $ADDR 100000000000000000seda --home $TMP_HOME --keyring-backend test -$BIN gentx satoshi 10000000000000000seda --home $TMP_HOME --keyring-backend test +$BIN gentx deployer 10000000000000000seda --home $TMP_HOME --keyring-backend test $BIN collect-gentxs --home $TMP_HOME diff --git a/scripts/testnet/artifacts/data_requests.wasm b/scripts/testnet/artifacts/data_requests.wasm deleted file mode 100644 index 8b2af9e1..00000000 Binary files a/scripts/testnet/artifacts/data_requests.wasm and /dev/null differ diff --git a/scripts/testnet/artifacts/proxy_contract.wasm b/scripts/testnet/artifacts/proxy_contract.wasm deleted file mode 100644 index e33706c1..00000000 Binary files a/scripts/testnet/artifacts/proxy_contract.wasm and /dev/null differ diff --git a/scripts/testnet/artifacts/staking.wasm b/scripts/testnet/artifacts/staking.wasm deleted file mode 100644 index 99b27505..00000000 Binary files a/scripts/testnet/artifacts/staking.wasm and /dev/null differ diff --git a/scripts/testnet/config_example.sh b/scripts/testnet/config_example.sh index e4dac36e..4343bc85 100644 --- a/scripts/testnet/config_example.sh +++ b/scripts/testnet/config_example.sh @@ -8,11 +8,13 @@ HOME_CONFIG_DIR=$HOME_DIR/config # chain config directory BIN=$(git rev-parse --show-toplevel)/build/seda-chaind # chain binary executable on your machine LINUX_BIN=$(git rev-parse --show-toplevel)/build/seda-chaind-linux # linux version of chain binary -# CHAIN_ID=seda-testnet +CHAIN_ID=seda-testnet # GENESIS_TIME= -# Validators +####################################### +########### VALIDATOR NODES ########### +####################################### # NOTE: Assumes 26656 port for p2p communication # NOTE: Assumes user is ec2-user # NOTE: The setup node script assumes ami-0a1ab4a3fcf997a9d @@ -32,10 +34,23 @@ SELF_DELEGATION_AMOUNTS=( SSH_KEY=~/.ssh/id_rsa # key used for ssh -# Genesis acoounts addresses +####################################### +########## GENESIS ACCOUNTS ########### +####################################### +# Standard genesis accounts # NOTE: The script will create operators of the nodes defined above and # add them as genesis accounts in addition to the ones defined below. GENESIS_ADDRESSES=( "seda..." "seda..." ) + +SATOSHI=seda... # if set, creates a genesis account with 100x seda tokens compared to standard genesis account +FAUCET=seda... # if set, creates a genesis account with 10x seda tokens compared to standard genesis account + + +####################################### +############### GITHUB ################ +####################################### +GITHUB_TOKEN=ghp_... # github token for accessing seda-chain-contracts repo +CONTRACTS_VERSION=v0.0.1-rc # latest or seda-chain-contracts release version diff --git a/scripts/testnet/create_genesis.sh b/scripts/testnet/create_genesis.sh index 79494377..bbd8de6e 100755 --- a/scripts/testnet/create_genesis.sh +++ b/scripts/testnet/create_genesis.sh @@ -20,7 +20,7 @@ rm -rf $NODE_DIR # # CREATE GENESIS AND ADJUST GOV PARAMETERS # -$BIN init new node0 +$BIN init new node0 --chain-id $CHAIN_ID cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["gov"]["voting_params"]["voting_period"]="180s"' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["gov"]["params"]["voting_period"]="180s"' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json @@ -34,9 +34,17 @@ cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["gov"]["params"]["max # ADD GENESIS ACCOUNTS # for i in ${!GENESIS_ADDRESSES[@]}; do - $BIN add-genesis-account ${GENESIS_ADDRESSES[$i]} 100000000000000000seda --keyring-backend test + $BIN add-genesis-account ${GENESIS_ADDRESSES[$i]} 100000000000000000seda done +set +u +if [ ! -z "$SATOSHI" ]; then + $BIN add-genesis-account $SATOSHI 10000000000000000000seda +fi +if [ ! -z "$FAUCET" ]; then + $BIN add-genesis-account $FAUCET 1000000000000000000seda +fi +set -u # # CREATE NODE KEY, VALIDATOR KEY, AND GENTX FOR EACH NODE @@ -54,9 +62,9 @@ for i in ${!MONIKERS[@]}; do VALIDATOR_ADDRESS=$($BIN keys show ${MONIKERS[$i]} --keyring-backend test --home $INDIVIDUAL_VAL_HOME_DIR -a) # to create their gentx - $BIN add-genesis-account $VALIDATOR_ADDRESS 100000000000000000seda --home $INDIVIDUAL_VAL_HOME_DIR + $BIN add-genesis-account $VALIDATOR_ADDRESS 500000000000000000seda --home $INDIVIDUAL_VAL_HOME_DIR # to output geneis file - $BIN add-genesis-account $VALIDATOR_ADDRESS 100000000000000000seda + $BIN add-genesis-account $VALIDATOR_ADDRESS 500000000000000000seda $BIN gentx ${MONIKERS[$i]} ${SELF_DELEGATION_AMOUNTS[$i]} --moniker=${MONIKERS[$i]} --keyring-backend=test --home $INDIVIDUAL_VAL_HOME_DIR --ip=${IPS[$i]}