From 943137b883c4e873604483e99d2400d0864dfc06 Mon Sep 17 00:00:00 2001 From: artemijspavlovs <19916123+artemijspavlovs@users.noreply.github.com> Date: Sun, 7 Apr 2024 11:59:26 +0300 Subject: [PATCH 1/8] docs: add advanced setup README docs: update the README with relevant values for remote hub setup --- README.md | 32 ++++- README.with-advanced-features.md | 201 +++++++++++++++++++++++++++++++ 2 files changed, 228 insertions(+), 5 deletions(-) create mode 100644 README.with-advanced-features.md diff --git a/README.md b/README.md index eacddd3..d97c890 100644 --- a/README.md +++ b/README.md @@ -38,14 +38,18 @@ export the following variables: ```shell export ROLLAPP_CHAIN_ID="rollappwasm_1234-1" export KEY_NAME_ROLLAPP="rol-user" -export DENOM="urax" +export BASE_DENOM="awsm" +export DENOM=$(echo "$BASE_DENOM" | sed 's/^.//') export MONIKER="$ROLLAPP_CHAIN_ID-sequencer" + +export ROLLAPP_HOME_DIR="$HOME/.rollapp" +export ROLLAPP_SETTLEMENT_INIT_DIR_PATH="${ROLLAPP_HOME_DIR}/init" ``` if you want to change the max wasm size: ```shell -export MAX_WASM_SIZE=YOUR_MAX_WASM_SIZE +export MAX_WASM_SIZE=WASM_SIZE_IN_BYTES # 2560000 ``` And initialize the rollapp: @@ -76,6 +80,17 @@ You should have a running local rollapp! Follow the instructions on [Dymension Hub docs](https://docs.dymension.xyz/develop/get-started/run-base-layers) to run local dymension hub node +all scripts are adjusted to use local hub node that's hosted on the default port `localhost:36657`. + +configuration with a remote hub node is also supported, the following variables must be set: + +```shell +export HUB_RPC_ENDPOINT="http://localhost" +export HUB_RPC_PORT="36657" # default: 36657 +export HUB_RPC_URL="http://3.71.160.88:36657" +export HUB_CHAIN_ID="dymension_100-1" +``` + ### Create sequencer keys create sequencer key using `dymd` @@ -88,7 +103,13 @@ SEQUENCER_ADDR=`dymd keys show sequencer --address --keyring-backend test --keyr fund the sequencer account ```shell -dymd tx bank send local-user $SEQUENCER_ADDR 10000000000000000000000adym --keyring-backend test --broadcast-mode block --fees 20000000000000adym -y +# this will retrieve the min bond amount from the hub +# if you're using an new address for registering a sequencer, +# you have to account for gas fees so it should the final value should be increased +BOND_AMOUNT="$(dymd q sequencer params -o json --node ${HUB_RPC_URL} | jq -r '.params.min_bond.amount')$(dymd q sequencer params -o json --node ${HUB_RPC_URL} | jq -r '.params.min_bond.denom')" +echo $BOND_AMOUNT + +dymd tx bank send local-user dym1978q3tcxwg0ldzgv7ynfr3mzytr9qfsuwjt7tl 100000000000000000000000adym --keyring-backend test --broadcast-mode block --fees 20000000000000adym -y ``` ### Register rollapp on settlement @@ -109,8 +130,9 @@ Modify `dymint.toml` in the chain directory (`~/.rollapp/config`) set: ```shell -settlement_layer = "dymension" -gas_prices = "0.025adym" +sed -i 's/settlement_layer.*/settlement_layer = "dymension"/' ${ROLLAPP_HOME_DIR}/config/dymint.toml +sed -i '/node_address =/c\node_address = '\"$HUB_RPC_URL\" "${ROLLAPP_HOME_DIR}/config/dymint.toml" +sed -i '/rollapp_id =/c\rollapp_id = '\"$ROLLAPP_CHAIN_ID\" "${ROLLAPP_HOME_DIR}/config/dymint.toml" ``` ### Run rollapp locally diff --git a/README.with-advanced-features.md b/README.with-advanced-features.md new file mode 100644 index 0000000..151ddfd --- /dev/null +++ b/README.with-advanced-features.md @@ -0,0 +1,201 @@ +# Dymension WASM Rollapp + +## rollappd - A template WASM RollApp chain + +This repository hosts `rollappd`, a template implementation of a dymension rollapp with `WASM` execution layer. + +`rollappd` is an example of a working RollApp using `dymension-RDK` and `dymint`. + +It uses Cosmos-SDK's [simapp](https://github.com/cosmos/cosmos-sdk/tree/main/simapp) as a reference, but with the following changes: + +- minimal app setup +- wired with EVM and ERC20 modules by [Evmos](https://github.com/evmos/evmos) +- wired IBC for [ICS 20 Fungible Token Transfers](https://github.com/cosmos/ibc/tree/main/spec/app/ics-020-fungible-token-transfer) +- Uses `dymint` for block sequencing and replacing `tendermint` +- Uses modules from `dymension-RDK` to sync with `dymint` and provide RollApp custom logic + +## Overview + +**Note**: Requires [Go 1.20](https://go.dev/) + +## Quick guide + +Get started with [building RollApps](https://docs.dymension.xyz/develop/get-started/setup) + +## Installing / Getting started + +Build and install the ```rollappd``` binary: + +```shell +make install +``` + +### Initial configuration + +export the following variables: + +```shell +export ROLLAPP_CHAIN_ID="rollappwasm_1234-1" +export KEY_NAME_ROLLAPP="rol-user" +export BASE_DENOM="awsm" +export DENOM=$(echo "$BASE_DENOM" | sed 's/^.//') +export MONIKER="$ROLLAPP_CHAIN_ID-sequencer" + +export ROLLAPP_HOME_DIR="$HOME/.rollapp" +export ROLLAPP_SETTLEMENT_INIT_DIR_PATH="${ROLLAPP_HOME_DIR}/init" +``` + +if you want to change the max wasm size: + +```shell +export MAX_WASM_SIZE=WASM_SIZE_IN_BYTES +``` + +And initialize the rollapp: + +```shell +sh scripts/init.sh +``` + +### Download cw20-ics20 smartcontract + +Download cw20-ics20 smartcontract with a specific version: + +```shell +sh scripts/download_release.sh v1.0.0 +``` + +### Run rollapp + +```shell +rollappd start +``` + +You should have a running local rollapp! + +## Run a rollapp with a settlement node + +### Run local dymension hub node + +Follow the instructions on [Dymension Hub docs](https://docs.dymension.xyz/develop/get-started/run-base-layers) to run local dymension hub node + +all scripts are adjusted to use local hub node that's hosted on the default port `localhost:36657`. + +configuration with a remote hub node is also supported, the following variables must be set: + +```shell +export HUB_RPC_ENDPOINT="http://localhost" +export HUB_RPC_PORT="36657" # default: 36657 +export HUB_RPC_URL="http://${HUB_RPC_ENDPOINT}:${HUB_RPC_PORT}" +export HUB_CHAIN_ID="dymension_100-1" +``` + +### Create sequencer keys + +create sequencer key using `dymd` + +```shell +dymd keys add sequencer --keyring-dir ~/.rollapp_evm/sequencer_keys --keyring-backend test +SEQUENCER_ADDR=`dymd keys show sequencer --address --keyring-backend test --keyring-dir ~/.rollapp_evm/sequencer_keys` +``` + +fund the sequencer account (if you're using a remote hub node, you must fund the sequencer account or you must have an account with enough funds in your keyring) + +```shell +# this will retrieve the min bond amount from the hub +# if you're using an new address for registering a sequencer, +# you have to account for gas fees so it should the final value should be increased +BOND_AMOUNT="$(dymd q sequencer params -o json --node ${HUB_RPC_URL} | jq -r '.params.min_bond.amount')$(dymd q sequencer params -o json --node ${HUB_RPC_URL} | jq -r '.params.min_bond.denom')" + +dymd tx bank send local-user $SEQUENCER_ADDR ${BOND_AMOUNT} --keyring-backend test --broadcast-mode block --fees 1dym -y --node ${HUB_RPC_URL} +``` + +### Generate denommetadata + +```shell + +sh scripts/settlement/generate_denom_metadata.sh +``` + +### Add genesis accounts + + +```shell +sh scripts/settlement/add_genesis_accounts.sh +``` + +### Register rollapp on settlement + +```shell +# for permissioned deployment setup, you must have access to an account whitelisted for rollapp +# registration, assuming you want to import an existing account, you can do: +dymd keys add local-user --recover +# input mnemonic from the account that has the permission to register rollapp + +sh scripts/settlement/register_rollapp_to_hub.sh +``` + +### Register sequencer for rollapp on settlement + +```shell +sh scripts/settlement/register_sequencer_to_hub.sh +``` + +### Configure the rollapp + +Modify `dymint.toml` in the chain directory (`~/.rollapp_evm/config`) +set: + +```shell +sed -i 's/settlement_layer.*/settlement_layer = "dymension"/' ${ROLLAPP_HOME_DIR}/config/dymint.toml +sed -i '/node_address =/c\node_address = '\"$HUB_RPC_URL\" "${ROLLAPP_HOME_DIR}/config/dymint.toml" +sed -i '/rollapp_id =/c\rollapp_id = '\"$ROLLAPP_CHAIN_ID\" "${ROLLAPP_HOME_DIR}/config/dymint.toml" +``` + +### Update the Genesis file to include the denommetadata, genesis accounts, module account and elevated accounts + +```shell +sh scripts/update_genesis_file.sh +``` + +### Update the Genesis file to include the denommetadata, genesis accounts, module account and elevated accounts + +```shell +# this script automatically adds 2 vesting accounts, adjust the timestampts to your liking or skip this step +sh scripts/add_vesting_accounts_to_genesis_file.sh +``` + +### Run rollapp locally + +```shell +rollappd start +``` + +## Setup IBC between rollapp and local dymension hub node + +### Install dymension relayer + +```shell +git clone https://github.com/dymensionxyz/go-relayer.git --branch v0.2.0-v2.3.1-relayer +cd go-relayer && make install +``` + +### Establish IBC channel + +while the rollapp and the local dymension hub node running, run: + +```shell +sh scripts/ibc/setup_ibc.sh +``` + +After successful run, the new established channels will be shown + +### run the relayer + +```shell +rly start hub-rollapp +``` + +## Developers guide + +TODO From d9906a68a534654921a4f9f47673e6f23c7834c4 Mon Sep 17 00:00:00 2001 From: artemijspavlovs <19916123+artemijspavlovs@users.noreply.github.com> Date: Sun, 7 Apr 2024 12:00:49 +0300 Subject: [PATCH 2/8] chore: update init scripts to support remote hub and permissioned setup --- scripts/init.sh | 18 ++++++++---------- scripts/settlement/register_rollapp_to_hub.sh | 15 +++++++++++---- .../settlement/register_sequencer_to_hub.sh | 15 ++++++++++----- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/scripts/init.sh b/scripts/init.sh index 6d1ea51..ecc5a14 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -6,17 +6,16 @@ ROLLAPP_CHAIN_DIR="$HOME/.rollapp" set_denom() { denom=$1 - jq --arg denom $denom '.app_state.mint.params.mint_denom = $denom' "$GENESIS_FILE" > "$tmp" && mv "$tmp" "$GENESIS_FILE" - jq --arg denom $denom '.app_state.staking.params.bond_denom = $denom' "$GENESIS_FILE" > "$tmp" && mv "$tmp" "$GENESIS_FILE" - jq --arg denom $denom '.app_state.gov.deposit_params.min_deposit[0].denom = $denom' "$GENESIS_FILE" > "$tmp" && mv "$tmp" "$GENESIS_FILE" + jq --arg denom $denom '.app_state.mint.params.mint_denom = $denom' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + jq --arg denom $denom '.app_state.staking.params.bond_denom = $denom' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + jq --arg denom $denom '.app_state.gov.deposit_params.min_deposit[0].denom = $denom' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" } # ---------------------------- initial parameters ---------------------------- # # Assuming 1,000,000 tokens #half is staked -TOKEN_AMOUNT="1000000000000000000000000$DENOM" -STAKING_AMOUNT="500000000000000000000000$DENOM" - +TOKEN_AMOUNT="1000000000000000000000000$BASE_DENOM" +STAKING_AMOUNT="500000000000000000000000$BASE_DENOM" CONFIG_DIRECTORY="$ROLLAPP_CHAIN_DIR/config" GENESIS_FILE="$CONFIG_DIRECTORY/genesis.json" @@ -56,8 +55,8 @@ $EXECUTABLE config keyring-backend test $EXECUTABLE config chain-id "$ROLLAPP_CHAIN_ID" # -------------------------------- app config -------------------------------- # -sed -i'' -e "s/^minimum-gas-prices *= .*/minimum-gas-prices = \"0$DENOM\"/" "$APP_CONFIG_FILE" -set_denom "$DENOM" +sed -i'' -e "s/^minimum-gas-prices *= .*/minimum-gas-prices = \"0$BASE_DENOM\"/" "$APP_CONFIG_FILE" +set_denom "$BASE_DENOM" # --------------------- adding keys and genesis accounts --------------------- # #local genesis account @@ -67,10 +66,9 @@ $EXECUTABLE gentx_seq --pubkey "$($EXECUTABLE dymint show-sequencer)" --from "$K echo "Do you want to include staker on genesis? (Y/n) " read -r answer -if [ ! "$answer" != "${answer#[Nn]}" ] ;then +if [ ! "$answer" != "${answer#[Nn]}" ]; then $EXECUTABLE gentx "$KEY_NAME_ROLLAPP" "$STAKING_AMOUNT" --chain-id "$ROLLAPP_CHAIN_ID" --keyring-backend test --home "$ROLLAPP_CHAIN_DIR" $EXECUTABLE collect-gentxs --home "$ROLLAPP_CHAIN_DIR" fi - $EXECUTABLE validate-genesis diff --git a/scripts/settlement/register_rollapp_to_hub.sh b/scripts/settlement/register_rollapp_to_hub.sh index 364d778..9849117 100644 --- a/scripts/settlement/register_rollapp_to_hub.sh +++ b/scripts/settlement/register_rollapp_to_hub.sh @@ -1,14 +1,21 @@ #!/bin/bash KEYRING_PATH="$HOME/.rollapp/sequencer_keys" -KEY_NAME_SEQUENCER="sequencer" MAX_SEQUENCERS=5 -#Register rollapp +# this account must be whitelisted on the hub for permissioned deployment setup +DEPLOYER="local-user" + +#Register rollapp +set -x dymd tx rollapp create-rollapp "$ROLLAPP_CHAIN_ID" "$MAX_SEQUENCERS" '{"Addresses":[]}' \ - --from "$KEY_NAME_SEQUENCER" \ + "$DENOM_METADATA_PATH" \ + --from "$DEPLOYER" \ --keyring-backend test \ --keyring-dir "$KEYRING_PATH" \ --broadcast-mode block \ - --fees 20000000000000adym \ + --fees 1dym \ + --node ${HUB_RPC_URL} \ + --chain-id ${HUB_CHAIN_ID} \ -y +set +x diff --git a/scripts/settlement/register_sequencer_to_hub.sh b/scripts/settlement/register_sequencer_to_hub.sh index 3f2bb5d..74e747c 100644 --- a/scripts/settlement/register_sequencer_to_hub.sh +++ b/scripts/settlement/register_sequencer_to_hub.sh @@ -4,15 +4,20 @@ EXECUTABLE="rollappd" KEYRING_PATH="$HOME/.rollapp/sequencer_keys" KEY_NAME_SEQUENCER="sequencer" - #Register Sequencer -DESCRIPTION="{\"Moniker\":\"myrollapp-sequencer\",\"Identity\":\"\",\"Website\":\"\",\"SecurityContact\":\"\",\"Details\":\"\"}"; +DESCRIPTION="{\"Moniker\":\"${ROLLAPP_CHAIN_ID}-sequencer\",\"Identity\":\"\",\"Website\":\"\",\"SecurityContact\":\"\",\"Details\":\"\"}" SEQ_PUB_KEY="$($EXECUTABLE dymint show-sequencer)" +BOND_AMOUNT="$(dymd q sequencer params -o json --node ${HUB_RPC_URL} | jq -r '.params.min_bond.amount')$(dymd q sequencer params -o json --node ${HUB_RPC_URL} | jq -r '.params.min_bond.denom')" -dymd tx sequencer create-sequencer "$SEQ_PUB_KEY" "$ROLLAPP_CHAIN_ID" "$DESCRIPTION" 20000000000000adym\ +set -x +dymd tx sequencer create-sequencer "$SEQ_PUB_KEY" "$ROLLAPP_CHAIN_ID" "$DESCRIPTION" "$BOND_AMOUNT" \ --from "$KEY_NAME_SEQUENCER" \ --keyring-dir "$KEYRING_PATH" \ --keyring-backend test \ --broadcast-mode block \ - --fees 20000000000000adym \ - -y \ No newline at end of file + --fees 1dym \ + --node "$HUB_RPC_URL" \ + --chain-id ${HUB_CHAIN_ID} \ + -y + +set +x From 77ae185ddc6ad3842c8179709bb8d9573e5cec60 Mon Sep 17 00:00:00 2001 From: artemijspavlovs <19916123+artemijspavlovs@users.noreply.github.com> Date: Sun, 7 Apr 2024 12:01:05 +0300 Subject: [PATCH 3/8] chore: add scripts for advanced setup --- .../add_vesting_accounts_to_genesis_file.sh | 12 +++ scripts/settlement/add_genesis_accounts.sh | 24 ++++++ scripts/settlement/generate_denom_metadata.sh | 36 +++++++++ scripts/update_genesis_file.sh | 74 +++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 scripts/add_vesting_accounts_to_genesis_file.sh create mode 100644 scripts/settlement/add_genesis_accounts.sh create mode 100644 scripts/settlement/generate_denom_metadata.sh create mode 100644 scripts/update_genesis_file.sh diff --git a/scripts/add_vesting_accounts_to_genesis_file.sh b/scripts/add_vesting_accounts_to_genesis_file.sh new file mode 100644 index 0000000..b9de0bd --- /dev/null +++ b/scripts/add_vesting_accounts_to_genesis_file.sh @@ -0,0 +1,12 @@ +#!/bin/bash +rollapp_evm keys add three-year-vester --keyring-backend test +rollapp_evm add-genesis-account three-year-vester \ + 10000000000000000000000${BASE_DENOM} --keyring-backend test \ + --vesting-amount 10000000000000000000000${BASE_DENOM} \ + --vesting-end-time 1805902584 + +rollapp_evm keys add two-year-vester-after-1-week --keyring-backend test +rollapp_evm add-genesis-account two-year-vester-after-1-week \ + 10000000000000000000000${BASE_DENOM} --keyring-backend test \ + --vesting-amount 10000000000000000000000${BASE_DENOM} \ + --vesting-end-time 1774366584 --vesting-start-time 1711985835 diff --git a/scripts/settlement/add_genesis_accounts.sh b/scripts/settlement/add_genesis_accounts.sh new file mode 100644 index 0000000..fb6d289 --- /dev/null +++ b/scripts/settlement/add_genesis_accounts.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +if [ ! -d "$ROLLAPP_SETTLEMENT_INIT_DIR_PATH" ]; then + mkdir -p "$ROLLAPP_SETTLEMENT_INIT_DIR_PATH" + echo "Creating the ROLLAPP_SETTLEMENT_INIT_DIR_PATH: $ROLLAPP_SETTLEMENT_INIT_DIR_PATH" +else + echo "ROLLAPP_SETTLEMENT_INIT_DIR_PATH already exists: $ROLLAPP_SETTLEMENT_INIT_DIR_PATH" +fi + +dymd keys add alice-genesis --keyring-backend test +dymd keys add bob-genesis --keyring-backend test + +tee "$ROLLAPP_SETTLEMENT_INIT_DIR_PATH/genesis_accounts.json" >/dev/null </dev/null <"$tmp" && mv "$tmp" "$GENESIS_FILE" +jq '.consensus_params["block"]["max_bytes"] = "5242880"' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + +jq '.app_state.gov.voting_params.voting_period = "300s"' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + +# this is a static module account for the hubgenesis module +# retrieved using 'rollapp-evm q auth module-accounts' command +module_account_address="ethm1748tamme3jj3v9wq95fc3pmglxtqscljdy7483" + +# Construct the JSON object with the obtained address +module_account=$(jq -n \ + --arg address "$module_account_address" \ + '[{ + "@type": "/cosmos.auth.v1beta1.ModuleAccount", + "base_account": { + "account_number": "0", + "address": $address, + "pub_key": null, + "sequence": "0" + }, + "name": "hubgenesis", + "permissions": [] + }]') + +jq --argjson module_account "$module_account" '.app_state.auth.accounts += $module_account' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + +module_account_balance=$( + jq -n \ + --arg address "$module_account_address" \ + --arg denom "$BASE_DENOM" \ + '[{ + "address": $address, + "coins": [ + { + "denom": $denom, + "amount": "60000000000000000000000" + } + ] + }]' +) + +jq '.app_state.bank.balances[0].coins[0].amount = "2000000000000000000000000000"' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" +jq --argjson module_account_balance "$module_account_balance" '.app_state.bank.balances += $module_account_balance' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + +jq '.app_state.bank.supply[0].amount = "2000060000000000000000000000"' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + +# ---------------------------- add elevated account ---------------------------- # +elevated_address=$(${EXECUTABLE} keys show ${KEY_NAME_ROLLAPP} --keyring-backend test --output json | jq -r .address) +elevated_address_json=$(jq -n \ + --arg address "$elevated_address" \ + '[{ + "address": $address + }]') +jq --argjson elevated_address_json "$elevated_address_json" '.app_state.hubgenesis.params.genesis_triggerer_whitelist += $elevated_address_json' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" +jq --arg hub_chain_id "$HUB_CHAIN_ID" '.app_state.hubgenesis.hub.hub_id = $hub_chain_id' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + +# ---------------------------- add denom metadata ---------------------------- # +denom_metadata=$(cat $ROLLAPP_SETTLEMENT_INIT_DIR_PATH/denommetadata.json) +jq --argjson denom_metadata "$denom_metadata" '.app_state.bank.denom_metadata = $denom_metadata' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" +jq --arg elevated_address "$elevated_address" '.app_state.denommetadata.params.allowed_addresses += [$elevated_address]' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" From 1f1758368655f0c3836e61214746764991bcb38c Mon Sep 17 00:00:00 2001 From: artemijspavlovs <19916123+artemijspavlovs@users.noreply.github.com> Date: Sun, 7 Apr 2024 12:18:53 +0300 Subject: [PATCH 4/8] chore: fix init script, add operator address to the genesis file --- scripts/init.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/init.sh b/scripts/init.sh index ecc5a14..f6fc45d 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -64,11 +64,17 @@ $EXECUTABLE keys add "$KEY_NAME_ROLLAPP" --keyring-backend test $EXECUTABLE add-genesis-account "$KEY_NAME_ROLLAPP" "$TOKEN_AMOUNT" --keyring-backend test $EXECUTABLE gentx_seq --pubkey "$($EXECUTABLE dymint show-sequencer)" --from "$KEY_NAME_ROLLAPP" --keyring-backend test +# set sequencer's operator address +operator_address=$($EXECUTABLE keys show "$KEY_NAME_ROLLAPP" -a --keyring-backend test --bech val) +jq --arg addr $operator_address '.app_state["sequencers"]["genesis_operator_address"] = $addr' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" + echo "Do you want to include staker on genesis? (Y/n) " read -r answer if [ ! "$answer" != "${answer#[Nn]}" ]; then + set -x $EXECUTABLE gentx "$KEY_NAME_ROLLAPP" "$STAKING_AMOUNT" --chain-id "$ROLLAPP_CHAIN_ID" --keyring-backend test --home "$ROLLAPP_CHAIN_DIR" $EXECUTABLE collect-gentxs --home "$ROLLAPP_CHAIN_DIR" + set +x fi $EXECUTABLE validate-genesis From f8f373c67d179e0ba8916fafe6ca9ef0b6255e4a Mon Sep 17 00:00:00 2001 From: artemijspavlovs <19916123+artemijspavlovs@users.noreply.github.com> Date: Sun, 7 Apr 2024 15:54:03 +0300 Subject: [PATCH 5/8] docs: update local dymd configuraiton during rollapp initialization --- README.md | 7 +++++-- README.with-advanced-features.md | 17 ++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d97c890..abc4c68 100644 --- a/README.md +++ b/README.md @@ -87,8 +87,11 @@ configuration with a remote hub node is also supported, the following variables ```shell export HUB_RPC_ENDPOINT="http://localhost" export HUB_RPC_PORT="36657" # default: 36657 -export HUB_RPC_URL="http://3.71.160.88:36657" +export HUB_RPC_URL="http://${HUB_RPC_ENDPOINT}:${HUB_RPC_PORT}" export HUB_CHAIN_ID="dymension_100-1" + +dymd config chain-id ${HUB_CHAIN_ID} +dymd config node ${HUB_RPC_URL} ``` ### Create sequencer keys @@ -106,7 +109,7 @@ fund the sequencer account # this will retrieve the min bond amount from the hub # if you're using an new address for registering a sequencer, # you have to account for gas fees so it should the final value should be increased -BOND_AMOUNT="$(dymd q sequencer params -o json --node ${HUB_RPC_URL} | jq -r '.params.min_bond.amount')$(dymd q sequencer params -o json --node ${HUB_RPC_URL} | jq -r '.params.min_bond.denom')" +BOND_AMOUNT="$(dymd q sequencer params -o json | jq -r '.params.min_bond.amount')$(dymd q sequencer params -o jsono | jq -r '.params.min_bond.denom')" echo $BOND_AMOUNT dymd tx bank send local-user dym1978q3tcxwg0ldzgv7ynfr3mzytr9qfsuwjt7tl 100000000000000000000000adym --keyring-backend test --broadcast-mode block --fees 20000000000000adym -y diff --git a/README.with-advanced-features.md b/README.with-advanced-features.md index 151ddfd..59a24b7 100644 --- a/README.with-advanced-features.md +++ b/README.with-advanced-features.md @@ -9,7 +9,6 @@ This repository hosts `rollappd`, a template implementation of a dymension rolla It uses Cosmos-SDK's [simapp](https://github.com/cosmos/cosmos-sdk/tree/main/simapp) as a reference, but with the following changes: - minimal app setup -- wired with EVM and ERC20 modules by [Evmos](https://github.com/evmos/evmos) - wired IBC for [ICS 20 Fungible Token Transfers](https://github.com/cosmos/ibc/tree/main/spec/app/ics-020-fungible-token-transfer) - Uses `dymint` for block sequencing and replacing `tendermint` - Uses modules from `dymension-RDK` to sync with `dymint` and provide RollApp custom logic @@ -62,7 +61,7 @@ sh scripts/init.sh Download cw20-ics20 smartcontract with a specific version: ```shell -sh scripts/download_release.sh v1.0.0 +bash scripts/download_release.sh v1.0.0 ``` ### Run rollapp @@ -88,6 +87,9 @@ export HUB_RPC_ENDPOINT="http://localhost" export HUB_RPC_PORT="36657" # default: 36657 export HUB_RPC_URL="http://${HUB_RPC_ENDPOINT}:${HUB_RPC_PORT}" export HUB_CHAIN_ID="dymension_100-1" + +dymd config chain-id ${HUB_CHAIN_ID} +dymd config node ${HUB_RPC_URL} ``` ### Create sequencer keys @@ -95,8 +97,8 @@ export HUB_CHAIN_ID="dymension_100-1" create sequencer key using `dymd` ```shell -dymd keys add sequencer --keyring-dir ~/.rollapp_evm/sequencer_keys --keyring-backend test -SEQUENCER_ADDR=`dymd keys show sequencer --address --keyring-backend test --keyring-dir ~/.rollapp_evm/sequencer_keys` +dymd keys add sequencer --keyring-dir ${ROLLAPP_HOME_DIR}/sequencer_keys --keyring-backend test +SEQUENCER_ADDR=`dymd keys show sequencer --address --keyring-backend test --keyring-dir ${ROLLAPP_HOME_DIR}/sequencer_keys` ``` fund the sequencer account (if you're using a remote hub node, you must fund the sequencer account or you must have an account with enough funds in your keyring) @@ -105,9 +107,9 @@ fund the sequencer account (if you're using a remote hub node, you must fund the # this will retrieve the min bond amount from the hub # if you're using an new address for registering a sequencer, # you have to account for gas fees so it should the final value should be increased -BOND_AMOUNT="$(dymd q sequencer params -o json --node ${HUB_RPC_URL} | jq -r '.params.min_bond.amount')$(dymd q sequencer params -o json --node ${HUB_RPC_URL} | jq -r '.params.min_bond.denom')" +BOND_AMOUNT="$(dymd q sequencer params -o json | jq -r '.params.min_bond.amount')$(dymd q sequencer params -o json | jq -r '.params.min_bond.denom')" -dymd tx bank send local-user $SEQUENCER_ADDR ${BOND_AMOUNT} --keyring-backend test --broadcast-mode block --fees 1dym -y --node ${HUB_RPC_URL} +dymd tx bank send local-user $SEQUENCER_ADDR ${BOND_AMOUNT} --keyring-backend test --broadcast-mode block --fees 1dym -y ``` ### Generate denommetadata @@ -143,7 +145,8 @@ sh scripts/settlement/register_sequencer_to_hub.sh ### Configure the rollapp -Modify `dymint.toml` in the chain directory (`~/.rollapp_evm/config`) +Modify `dymint.toml` in the chain directory (`${ROLLAPP_HOME_DIR}/config`) + set: ```shell From fbf4e8bf246fe8ea280d42d5482056837a400bdc Mon Sep 17 00:00:00 2001 From: artemijspavlovs <19916123+artemijspavlovs@users.noreply.github.com> Date: Sun, 7 Apr 2024 15:54:59 +0300 Subject: [PATCH 6/8] chore: ibc setup - retrieve the hub and chain metadata from local config chore: add empty block time time change for faster ibc setup --- scripts/ibc/setup_ibc.sh | 48 +++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/scripts/ibc/setup_ibc.sh b/scripts/ibc/setup_ibc.sh index 17f2a28..7e164f7 100644 --- a/scripts/ibc/setup_ibc.sh +++ b/scripts/ibc/setup_ibc.sh @@ -9,20 +9,20 @@ RELAYER_EXECUTABLE="rly" # settlement config SETTLEMENT_EXECUTABLE="dymd" -SETTLEMENT_CHAIN_ID="dymension_100-1" +SETTLEMENT_CHAIN_ID=$($SETTLEMENT_EXECUTABLE config | jq -r '."chain-id"') +SETTLEMENT_RPC_FOR_RELAYER=$($SETTLEMENT_EXECUTABLE config | jq -r '."node"') SETTLEMENT_KEY_NAME_GENESIS="local-user" +SETTLEMENT_BASE_DENOM="adym" +# rollapp config EXECUTABLE="rollappd" -ROLLAPP_CHAIN_ID="rollappwasm_1234-1" +ROLLAPP_CHAIN_ID=$($EXECUTABLE config | jq -r '."chain-id"') +ROLLAPP_RPC_FOR_RELAYER=$($EXECUTABLE config | jq -r '."node"') ROLLAPP_KEY_NAME_GENESIS="rol-user" -DENOM="urax" RELAYER_KEY_FOR_ROLLAP="relayer-rollapp-key" RELAYER_KEY_FOR_HUB="relayer-hub-key" RELAYER_PATH="hub-rollapp" -ROLLAPP_RPC_FOR_RELAYER="http://127.0.0.1:26657" -SETTLEMENT_RPC_FOR_RELAYER="http://127.0.0.1:36657" - if ! command -v $RELAYER_EXECUTABLE >/dev/null; then echo "$RELAYER_EXECUTABLE does not exist" @@ -30,6 +30,10 @@ if ! command -v $RELAYER_EXECUTABLE >/dev/null; then exit 1 fi +# --------------------------------- change block time to easily create ibc channels --------------------------------- # +sed -i 's/empty_blocks_max_time =.*/empty_blocks_max_time = "3s"/' ${ROLLAPP_HOME_DIR}/config/dymint.toml +sudo systemctl restart rollapp + # --------------------------------- rly init --------------------------------- # RLY_PATH="$HOME/.relayer" RLY_CONFIG_FILE="$RLY_PATH/config/config.yaml" @@ -52,14 +56,14 @@ rly config init echo '# ------------------------- adding chains to rly config ------------------------- #' tmp=$(mktemp) -jq --arg key "$RELAYER_KEY_FOR_ROLLAP" '.value.key = $key' $ROLLAPP_IBC_CONF_FILE > "$tmp" && mv "$tmp" $ROLLAPP_IBC_CONF_FILE -jq --arg chain "$ROLLAPP_CHAIN_ID" '.value."chain-id" = $chain' $ROLLAPP_IBC_CONF_FILE > "$tmp" && mv "$tmp" $ROLLAPP_IBC_CONF_FILE -jq --arg rpc "$ROLLAPP_RPC_FOR_RELAYER" '.value."rpc-addr" = $rpc' $ROLLAPP_IBC_CONF_FILE > "$tmp" && mv "$tmp" $ROLLAPP_IBC_CONF_FILE -jq --arg denom "0.0$DENOM" '.value."gas-prices" = $denom' $ROLLAPP_IBC_CONF_FILE > "$tmp" && mv "$tmp" $ROLLAPP_IBC_CONF_FILE +jq --arg key "$RELAYER_KEY_FOR_ROLLAP" '.value.key = $key' $ROLLAPP_IBC_CONF_FILE >"$tmp" && mv "$tmp" $ROLLAPP_IBC_CONF_FILE +jq --arg chain "$ROLLAPP_CHAIN_ID" '.value."chain-id" = $chain' $ROLLAPP_IBC_CONF_FILE >"$tmp" && mv "$tmp" $ROLLAPP_IBC_CONF_FILE +jq --arg rpc "$ROLLAPP_RPC_FOR_RELAYER" '.value."rpc-addr" = $rpc' $ROLLAPP_IBC_CONF_FILE >"$tmp" && mv "$tmp" $ROLLAPP_IBC_CONF_FILE +jq --arg denom "0.0$BASE_DENOM" '.value."gas-prices" = $denom' $ROLLAPP_IBC_CONF_FILE >"$tmp" && mv "$tmp" $ROLLAPP_IBC_CONF_FILE -jq --arg key "$RELAYER_KEY_FOR_HUB" '.value.key = $key' $HUB_IBC_CONF_FILE > "$tmp" && mv "$tmp" $HUB_IBC_CONF_FILE -jq --arg chain "$SETTLEMENT_CHAIN_ID" '.value."chain-id" = $chain' $HUB_IBC_CONF_FILE > "$tmp" && mv "$tmp" $HUB_IBC_CONF_FILE -jq --arg rpc "$SETTLEMENT_RPC_FOR_RELAYER" '.value."rpc-addr" = $rpc' $HUB_IBC_CONF_FILE > "$tmp" && mv "$tmp" $HUB_IBC_CONF_FILE +jq --arg key "$RELAYER_KEY_FOR_HUB" '.value.key = $key' $HUB_IBC_CONF_FILE >"$tmp" && mv "$tmp" $HUB_IBC_CONF_FILE +jq --arg chain "$SETTLEMENT_CHAIN_ID" '.value."chain-id" = $chain' $HUB_IBC_CONF_FILE >"$tmp" && mv "$tmp" $HUB_IBC_CONF_FILE +jq --arg rpc "$SETTLEMENT_RPC_FOR_RELAYER" '.value."rpc-addr" = $rpc' $HUB_IBC_CONF_FILE >"$tmp" && mv "$tmp" $HUB_IBC_CONF_FILE rly chains add --file "$ROLLAPP_IBC_CONF_FILE" "$ROLLAPP_CHAIN_ID" rly chains add --file "$HUB_IBC_CONF_FILE" "$SETTLEMENT_CHAIN_ID" @@ -72,16 +76,16 @@ RLY_HUB_ADDR=$(rly keys show "$SETTLEMENT_CHAIN_ID") RLY_ROLLAPP_ADDR=$(rly keys show "$ROLLAPP_CHAIN_ID") echo '# -------------------------------- funding for rly account ------------------------------- #' -$SETTLEMENT_EXECUTABLE tx bank send $SETTLEMENT_KEY_NAME_GENESIS "$(rly keys show "$SETTLEMENT_CHAIN_ID")" 1000000000000000000000adym --keyring-backend test --broadcast-mode block --fees 20000000000000adym -y --node "$SETTLEMENT_RPC_FOR_RELAYER" -$EXECUTABLE tx bank send $ROLLAPP_KEY_NAME_GENESIS "$(rly keys show "$ROLLAPP_CHAIN_ID")" 1000000000000000000000$DENOM --keyring-backend test --broadcast-mode block -y --node "$ROLLAPP_RPC_FOR_RELAYER" +$SETTLEMENT_EXECUTABLE tx bank send $SETTLEMENT_KEY_NAME_GENESIS "$(rly keys show "$SETTLEMENT_CHAIN_ID")" 1000000000000000000000${SETTLEMENT_BASE_DENOM} --keyring-backend test --broadcast-mode block --fees 20000000000000${SETTLEMENT_BASE_DENOM} -y +$EXECUTABLE tx bank send $ROLLAPP_KEY_NAME_GENESIS "$(rly keys show "$ROLLAPP_CHAIN_ID")" 1000000000000000000000$BASE_DENOM --keyring-backend test --broadcast-mode block -y --node "$ROLLAPP_RPC_FOR_RELAYER" echo "# ------------------------------- balance of rly account on hub [$RLY_HUB_ADDR]------------------------------ #" -$SETTLEMENT_EXECUTABLE q bank balances "$(rly keys show "$SETTLEMENT_CHAIN_ID")" --node "$SETTLEMENT_RPC_FOR_RELAYER" -echo "From within the hub node: \"$SETTLEMENT_EXECUTABLE tx bank send $SETTLEMENT_KEY_NAME_GENESIS $RLY_HUB_ADDR 100000000000000000000udym --keyring-backend test --broadcast-mode block\"" +$SETTLEMENT_EXECUTABLE q bank balances "$(rly keys show "$SETTLEMENT_CHAIN_ID")" +echo "From within the hub node: \n\"$SETTLEMENT_EXECUTABLE tx bank send $SETTLEMENT_KEY_NAME_GENESIS $RLY_HUB_ADDR 100000000000000000000${SETTLEMENT_BASE_DENOM} --keyring-backend test --broadcast-mode block\"" echo "# ------------------------------- balance of rly account on rollapp [$RLY_ROLLAPP_ADDR] ------------------------------ #" $EXECUTABLE q bank balances "$(rly keys show "$ROLLAPP_CHAIN_ID")" --node "$ROLLAPP_RPC_FOR_RELAYER" -echo "From within the rollapp node: \"$EXECUTABLE tx bank send $KEY_NAME_ROLLAPP $RLY_ROLLAPP_ADDR 100000000$DENOM --keyring-backend test --broadcast-mode block\"" +echo "From within the rollapp node: \n\"$EXECUTABLE tx bank send $KEY_NAME_ROLLAPP $RLY_ROLLAPP_ADDR 100000000$BASE_DENOM --keyring-backend test --broadcast-mode block\"" echo '# -------------------------------- creating IBC link ------------------------------- #' @@ -94,5 +98,9 @@ rly tx link "$RELAYER_PATH" --src-port "$IBC_PORT" --dst-port "$IBC_PORT" --vers sleep 5 echo '# -------------------------------- IBC channel established ------------------------------- #' -echo "ROLLAPP_CHANNEL: $(rly q channels "$ROLLAPP_CHAIN_ID")" -echo "HUB_CHANNEL: $(rly q channels "$SETTLEMENT_CHAIN_ID")" +echo "Channel Information:" +echo $(rly q channels "$ROLLAPP_CHAIN_ID" | jq '{ "rollapp-channel": .channel_id, "hub-channel": .counterparty.channel_id }') + +# --------------------------------- revert empty block time to 1h --------------------------------- # +sed -i 's/empty_blocks_max_time =.*/empty_blocks_max_time = "3600s"/' ${ROLLAPP_HOME_DIR}/config/dymint.toml +sudo systemctl restart rollapp From 21f3b316c386003417eceaaf765e8277be6742e8 Mon Sep 17 00:00:00 2001 From: artemijspavlovs <19916123+artemijspavlovs@users.noreply.github.com> Date: Sun, 7 Apr 2024 15:56:42 +0300 Subject: [PATCH 7/8] refactor: levarage variables in rollapp init scripts --- .../add_vesting_accounts_to_genesis_file.sh | 10 ++++---- scripts/settlement/generate_denom_metadata.sh | 5 ++-- scripts/settlement/register_rollapp_to_hub.sh | 3 +-- .../settlement/register_sequencer_to_hub.sh | 4 +--- scripts/update_genesis_file.sh | 23 +++++++++---------- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/scripts/add_vesting_accounts_to_genesis_file.sh b/scripts/add_vesting_accounts_to_genesis_file.sh index b9de0bd..a343615 100644 --- a/scripts/add_vesting_accounts_to_genesis_file.sh +++ b/scripts/add_vesting_accounts_to_genesis_file.sh @@ -1,12 +1,14 @@ #!/bin/bash -rollapp_evm keys add three-year-vester --keyring-backend test -rollapp_evm add-genesis-account three-year-vester \ +BINARY="rollappd" + +$BINARY keys add three-year-vester --keyring-backend test +$BINARY add-genesis-account three-year-vester \ 10000000000000000000000${BASE_DENOM} --keyring-backend test \ --vesting-amount 10000000000000000000000${BASE_DENOM} \ --vesting-end-time 1805902584 -rollapp_evm keys add two-year-vester-after-1-week --keyring-backend test -rollapp_evm add-genesis-account two-year-vester-after-1-week \ +$BINARY keys add two-year-vester-after-1-week --keyring-backend test +$BINARY add-genesis-account two-year-vester-after-1-week \ 10000000000000000000000${BASE_DENOM} --keyring-backend test \ --vesting-amount 10000000000000000000000${BASE_DENOM} \ --vesting-end-time 1774366584 --vesting-start-time 1711985835 diff --git a/scripts/settlement/generate_denom_metadata.sh b/scripts/settlement/generate_denom_metadata.sh index 663ea55..fc4b19a 100644 --- a/scripts/settlement/generate_denom_metadata.sh +++ b/scripts/settlement/generate_denom_metadata.sh @@ -1,8 +1,8 @@ #!/bin/bash if [ -z "$ROLLAPP_SETTLEMENT_INIT_DIR_PATH" ]; then - echo "ROLLAPP_SETTLEMENT_INIT_DIR_PATH is not set, using '$HOME/.rollapp_evm/init'" - ROLLAPP_SETTLEMENT_INIT_DIR_PATH="$HOME/.rollapp_evm/init" + echo "ROLLAPP_SETTLEMENT_INIT_DIR_PATH is not set, using '${ROLLAPP_HOME_DIR}/init'" + ROLLAPP_SETTLEMENT_INIT_DIR_PATH="${ROLLAPP_HOME_DIR}/init" fi if [ ! -d "$ROLLAPP_SETTLEMENT_INIT_DIR_PATH" ]; then @@ -33,4 +33,3 @@ tee "$ROLLAPP_SETTLEMENT_INIT_DIR_PATH/denommetadata.json" >/dev/null <"$tmp" jq '.app_state.gov.voting_params.voting_period = "300s"' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" # this is a static module account for the hubgenesis module -# retrieved using 'rollapp-evm q auth module-accounts' command +# retrieved using 'rollappd q auth module-accounts' command module_account_address="ethm1748tamme3jj3v9wq95fc3pmglxtqscljdy7483" # Construct the JSON object with the obtained address module_account=$(jq -n \ - --arg address "$module_account_address" \ - '[{ + --arg address "$module_account_address" \ + '[{ "@type": "/cosmos.auth.v1beta1.ModuleAccount", "base_account": { "account_number": "0", @@ -39,10 +38,10 @@ module_account=$(jq -n \ jq --argjson module_account "$module_account" '.app_state.auth.accounts += $module_account' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" module_account_balance=$( - jq -n \ - --arg address "$module_account_address" \ - --arg denom "$BASE_DENOM" \ - '[{ + jq -n \ + --arg address "$module_account_address" \ + --arg denom "$BASE_DENOM" \ + '[{ "address": $address, "coins": [ { @@ -61,8 +60,8 @@ jq '.app_state.bank.supply[0].amount = "2000060000000000000000000000"' "$GENESIS # ---------------------------- add elevated account ---------------------------- # elevated_address=$(${EXECUTABLE} keys show ${KEY_NAME_ROLLAPP} --keyring-backend test --output json | jq -r .address) elevated_address_json=$(jq -n \ - --arg address "$elevated_address" \ - '[{ + --arg address "$elevated_address" \ + '[{ "address": $address }]') jq --argjson elevated_address_json "$elevated_address_json" '.app_state.hubgenesis.params.genesis_triggerer_whitelist += $elevated_address_json' "$GENESIS_FILE" >"$tmp" && mv "$tmp" "$GENESIS_FILE" From 6bad7b8e77c8dd7ea204a2cc678a773bca174b51 Mon Sep 17 00:00:00 2001 From: artemijspavlovs <19916123+artemijspavlovs@users.noreply.github.com> Date: Sun, 7 Apr 2024 15:58:59 +0300 Subject: [PATCH 8/8] docs: run as systemd service --- README.with-advanced-features.md | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/README.with-advanced-features.md b/README.with-advanced-features.md index 59a24b7..f663565 100644 --- a/README.with-advanced-features.md +++ b/README.with-advanced-features.md @@ -174,6 +174,26 @@ sh scripts/add_vesting_accounts_to_genesis_file.sh rollappd start ``` +or as a systemd service: + +```shell +sudo tee /etc/systemd/system/rollapp.service > /dev/null < /dev/null <