Skip to content

Commit

Permalink
Update Local to Mainnet Scripts (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs committed Jan 18, 2023
1 parent abcba0f commit 39ad5b8
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 84 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Expand Up @@ -8,9 +8,9 @@
path = deps/relayer
url = https://github.com/cosmos/relayer.git
[submodule "deps/gaia"]
# Commit: 5b47714dd5607993a1a91f2b06a6d92cbb504721
# Commit: 5db8fcc9a229730f5115bed82d0f85b6db7184b4
path = deps/gaia
url = https://github.com/Stride-Labs/gaia.git
url = https://github.com/cosmos/gaia.git
[submodule "deps/juno"]
# Commit: 955892041359443fbb5addd34c0ab8b66bd8d75c
path = deps/juno
Expand Down
6 changes: 3 additions & 3 deletions dockernet/dockerfiles/Dockerfile.gaia
@@ -1,12 +1,12 @@
FROM golang:1.17-alpine3.15 AS builder
FROM golang:1.18-alpine3.15 AS builder

WORKDIR /opt

RUN apk add --update curl make git libc-dev bash gcc linux-headers eudev-dev python3

ENV COMMIT_HASH=5b47714dd5607993a1a91f2b06a6d92cbb504721
ENV COMMIT_HASH=5db8fcc9a229730f5115bed82d0f85b6db7184b4

RUN git clone https://github.com/Stride-Labs/gaia gaia-install \
RUN git clone https://github.com/cosmos/gaia gaia-install \
&& cd gaia-install \
&& git checkout $COMMIT_HASH \
&& CGO_ENABLED=0 make install
Expand Down
13 changes: 7 additions & 6 deletions scripts/local-to-mainnet/README.md
Expand Up @@ -6,20 +6,21 @@
* Ensure you have dockernet setup properly including all submodules up to date and the `STRIDE_ADMIN_MNEMONIC` enviornment variable set
* Fund three hot wallets and set the mnemonics as environment variables (`HOT_WALLET_1_MNEMONIC`, `HOT_WALLET_2_MNEMONIC`, `HOT_WALLET_3_MNEMONIC`)
* They all must have a non-zero balance on the host
* Wallet #1 should have enough to fund each liquid stake
* Wallet #2 and Wallet #3 only need enough to relay on the host (~1 native token)
* Wallet #1 should have enough to fund each liquid stake (~5 native token per attempt)
* Wallet #2 only needs enough to create clients and connections (~0.20 native token)
* Wallet #3 only needs enough to relayer on the host (~0.50 native token)
* Update the variables at the top of `start.sh`

## Start Stride Local
* Build stride and the relayers
```bash
make build-docker build=srh{n} # where n is the new host zone that was just added
```
make build-docker build=srh
```
* Start a local stride and setup all the commands needed to test the flow
* Start a local stride instance and setup all the commands needed to test the flow
```
bash scripts/local-to-mainnet/start.sh
```

## Walk through Flow
* Step through the commands in `commands.sh` one by one and copy them into the terminal
* Step through the commands in `local-to-mainnet/commands.sh` one by one and copy them into the terminal
* In the future, we can automate this more but since this interacts with mainnet, I think it's safer to run these manually for now
79 changes: 37 additions & 42 deletions scripts/local-to-mainnet/commands.sh
Expand Up @@ -3,22 +3,23 @@
### ANY CHANGES WILL BE OVERWRITTEN. ###
############################################
#### SETUP HOT WALLET (Only needs to be run once)
echo "$HOT_WALLET_1_MNEMONIC" | build/osmosisd keys add hot --recover --keyring-backend test
echo "$HOT_WALLET_1_MNEMONIC" | build/gaiad keys add hot --recover --keyring-backend test


#### START RELAYERS
#### START RELAYER
# NOTE: CREATING CONNECTIONS WITH THE GO RELAYER IS BROKEN, USE HERMES
# Create connections and channels
docker-compose -f scripts/local-to-mainnet/docker-compose.yml run --rm relayer rly transact link stride-host
# docker-compose -f scripts/local-to-mainnet/docker-compose.yml run --rm relayer rly transact link stride-host

# (OR) If the go relayer isn't working, use hermes (you'll have to add the connections to the relayer config though in `scripts/state/relaye/config/config.yaml`)
# docker-compose -f scripts/local-to-mainnet/docker-compose.yml run --rm hermes hermes create connection --a-chain osmosis-1 --b-chain local-test-1
# docker-compose -f scripts/local-to-mainnet/docker-compose.yml run --rm hermes hermes create channel --a-chain local-test-1 --a-connection connection-0 --a-port transfer --b-port transfer
# (OR) If the go relayer isn't working, use hermes (NOTE: you'll have to add the connections to the relayer config in `scripts/state/relayer/config/config.yaml`)
docker-compose -f scripts/local-to-mainnet/docker-compose.yml run --rm hermes hermes create connection --a-chain cosmoshub-4 --b-chain local-test-1
docker-compose -f scripts/local-to-mainnet/docker-compose.yml run --rm hermes hermes create channel --a-chain local-test-1 --a-connection connection-0 --a-port transfer --b-port transfer

# Ensure Relayer Config is updated (`scripts/state/relayer/config/config.yaml`)
# Ensure Relayer Config is updated (`scripts/local-to-mainnet/state/relayer/config/config.yaml`)
# paths:
# stride-host:
# src:
# chain-id: stride-1
# chain-id: local-test-1
# client-id: 07-tendermint-0
# connection-id: connection-0
# dst:
Expand All @@ -27,81 +28,75 @@ docker-compose -f scripts/local-to-mainnet/docker-compose.yml run --rm relayer r
# connection-id: {CONNECTION-ID}

# Get channel ID created on the host
build/strided --home s q ibc channel channels
transfer_channel=$(build/strided --home s q ibc channel channels | grep channel-0 -A 4 | grep counterparty -A 1 | grep channel | awk '{print $2}') && echo $transfer_channel
build/strided --home scripts/state/stride1 q ibc channel channels
transfer_channel=$(build/strided --home scripts/state/stride1 q ibc channel channels | grep channel-0 -A 4 | grep counterparty -A 1 | grep channel | awk '{print $2}') && echo $transfer_channel

# Start Hermes Relayer
docker-compose -f scripts/local-to-mainnet/docker-compose.yml up -d hermes
docker-compose -f scripts/local-to-mainnet/docker-compose.yml logs -f hermes | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" >> scripts/logs/hermes.log 2>&1 &

# Configure the Go Relayer to only run ICQ
sed -i -E "s|rule: \"\"|rule: allowlist|g" scripts/state/relayer/config/config.yaml

# Start Go Relayer (for ICQ)
# Start Go Relayer
docker-compose -f scripts/local-to-mainnet/docker-compose.yml up -d relayer
docker-compose -f scripts/local-to-mainnet/docker-compose.yml logs -f relayer | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" >> scripts/logs/relayer.log 2>&1 &


#### REGISTER HOST
# IBC Transfer from HOST to stride (from relayer account)
build/osmosisd tx ibc-transfer transfer transfer $transfer_channel stride1u20df3trc2c2zdhm8qvh2hdjx9ewh00sv6eyy8 4000000uosmo --from hot --chain-id osmosis-1 -y --keyring-backend test --node http://osmo-fleet-direct.main.stridenet.co:26657
build/gaiad tx ibc-transfer transfer transfer $transfer_channel stride1u20df3trc2c2zdhm8qvh2hdjx9ewh00sv6eyy8 4000000uatom --from hot --chain-id cosmoshub-4 -y --keyring-backend test --node http://gaia-fleet-direct.main.stridenet.co:26657

# Confirm funds were recieved on stride and get IBC denom
build/strided --home s q bank balances stride1u20df3trc2c2zdhm8qvh2hdjx9ewh00sv6eyy8
build/strided --home scripts/state/stride1 q bank balances stride1u20df3trc2c2zdhm8qvh2hdjx9ewh00sv6eyy8

# Register host zone
IBC_DENOM=$(build/strided --home s q bank balances stride1u20df3trc2c2zdhm8qvh2hdjx9ewh00sv6eyy8 | grep ibc | awk '{print $2}' | tr -d '"') && echo $IBC_DENOM
build/strided --home s tx stakeibc register-host-zone \
connection-0 uosmo osmo $IBC_DENOM channel-0 1 \
IBC_DENOM=$(build/strided --home scripts/state/stride1 q bank balances stride1u20df3trc2c2zdhm8qvh2hdjx9ewh00sv6eyy8 | grep ibc | awk '{print $2}' | tr -d '"') && echo $IBC_DENOM
build/strided --home scripts/state/stride1 tx stakeibc register-host-zone \
connection-0 uatom cosmos $IBC_DENOM channel-0 1 \
--from admin --gas 1000000 -y

# Add validator
build/strided --home s tx stakeibc add-validator osmosis-1 imperator osmovaloper1t8qckan2yrygq7kl9apwhzfalwzgc2429p8f0s 10 5 --chain-id local-test-1 --keyring-backend test --from admin -y
build/strided --home scripts/state/stride1 tx stakeibc add-validator cosmoshub-4 imperator cosmosvaloper1vvwtk805lxehwle9l4yudmq6mn0g32px9xtkhc 10 5 --chain-id local-test-1 --keyring-backend test --from admin -y

# Confirm ICA channels were registered
build/strided --home s q stakeibc list-host-zone
build/strided --home scripts/state/stride1 q stakeibc list-host-zone


#### FLOW
## Go Through Flow
# Liquid stake (then wait and LS again)
build/strided --home s tx stakeibc liquid-stake 1000000 uosmo --keyring-backend test --from admin -y --chain-id local-test-1 -y
build/strided --home scripts/state/stride1 tx stakeibc liquid-stake 1000000 uatom --keyring-backend test --from admin -y --chain-id local-test-1 -y

# Confirm stTokens, StakedBal, and Redemption Rate
build/strided --home s q bank balances stride1u20df3trc2c2zdhm8qvh2hdjx9ewh00sv6eyy8
build/strided --home s q stakeibc list-host-zone
build/strided --home scripts/state/stride1 q bank balances stride1u20df3trc2c2zdhm8qvh2hdjx9ewh00sv6eyy8
build/strided --home scripts/state/stride1 q stakeibc list-host-zone

# Redeem
build/strided --home s tx stakeibc redeem-stake 1000 osmosis-1 osmo1c37n9aywapx2v0s6vk2yedydkkhq65zz38jfnc --from admin --keyring-backend test --chain-id local-test-1 -y
build/strided --home scripts/state/stride1 tx stakeibc redeem-stake 1000 cosmoshub-4 cosmos1c37n9aywapx2v0s6vk2yedydkkhq65zzeupe92 --from admin --keyring-backend test --chain-id local-test-1 -y

# Confirm stTokens and StakedBal
build/strided --home s q bank balances stride1u20df3trc2c2zdhm8qvh2hdjx9ewh00sv6eyy8
build/strided --home s q stakeibc list-host-zone
build/strided --home scripts/state/stride1 q bank balances stride1u20df3trc2c2zdhm8qvh2hdjx9ewh00sv6eyy8
build/strided --home scripts/state/stride1 q stakeibc list-host-zone

# Add another validator
build/strided --home s tx stakeibc add-validator osmosis-1 notional osmovaloper1083svrca4t350mphfv9x45wq9asrs60c6rv0j5 10 5 --chain-id local-test-1 --keyring-backend test --from admin -y
build/strided --home scripts/state/stride1 tx stakeibc add-validator cosmoshub-4 notional cosmosvaloper1083svrca4t350mphfv9x45wq9asrs60cdmrflj 10 5 --chain-id local-test-1 --keyring-backend test --from admin -y

# Liquid stake and confirm the stake was split 50/50 between the validators
build/strided --home s tx stakeibc liquid-stake 1000000 uosmo --keyring-backend test --from admin -y --chain-id local-test-1 -y
build/strided --home scripts/state/stride1 tx stakeibc liquid-stake 1000000 uatom --keyring-backend test --from admin -y --chain-id local-test-1 -y

# Change validator weights
build/strided --home s tx stakeibc change-validator-weight osmosis-1 osmovaloper1t8qckan2yrygq7kl9apwhzfalwzgc2429p8f0s 1 --from admin -y
build/strided --home s tx stakeibc change-validator-weight osmosis-1 osmovaloper1083svrca4t350mphfv9x45wq9asrs60c6rv0j5 49 --from admin -y
build/strided --home scripts/state/stride1 tx stakeibc change-validator-weight cosmoshub-4 cosmosvaloper1vvwtk805lxehwle9l4yudmq6mn0g32px9xtkhc 1 --from admin -y
build/strided --home scripts/state/stride1 tx stakeibc change-validator-weight cosmoshub-4 cosmosvaloper1083svrca4t350mphfv9x45wq9asrs60cdmrflj 49 --from admin -y

# LS and confirm delegation aligned with new weights
build/strided --home s tx stakeibc liquid-stake 1000000 uosmo --keyring-backend test --from admin -y --chain-id local-test-1 -y
build/strided --home scripts/state/stride1 tx stakeibc liquid-stake 1000000 uatom --keyring-backend test --from admin -y --chain-id local-test-1 -y

# Call rebalance to and confirm new delegations
build/strided --home s tx stakeibc rebalance-validators osmosis-1 5 --from admin
build/strided --home scripts/state/stride1 tx stakeibc rebalance-validators cosmoshub-4 5 --from admin

# Clear balances
fee_address=$(build/strided --home s q stakeibc show-host-zone osmosis-1 | grep feeAccount -A 1 | grep address | awk '{print $2}') && echo $fee_address
balance=$(build/osmosisd --home s q bank balances $fee_address | grep amount | awk '{print $3}' | tr -d '"') && echo $balance
build/strided --home s tx stakeibc clear-balance osmosis-1 $balance $transfer_channel --from admin
fee_address=$(build/strided --home scripts/state/stride1 q stakeibc show-host-zone osmosis-1 | grep feeAccount -A 1 | grep address | awk '{print $2}') && echo $fee_address
balance=$(build/osmosisd --home scripts/state/stride1 q bank balances $fee_address | grep amount | awk '{print $3}' | tr -d '"') && echo $balance
build/strided --home scripts/state/stride1 tx stakeibc clear-balance cosmoshub-4 $balance $transfer_channel --from admin

# Update delegations (just submit this query and confirm the ICQ callback displays in the stride logs)
# Must be submitted in ICQ window
build/strided --home s tx stakeibc update-delegation osmosis-1 osmovaloper1t8qckan2yrygq7kl9apwhzfalwzgc2429p8f0s --from admin -y
build/strided --home scripts/state/stride1 tx stakeibc update-delegation cosmoshub-4 cosmosvaloper1vvwtk805lxehwle9l4yudmq6mn0g32px9xtkhc --from admin -y

#### MISC
# If a channel closes, restore it with:
build/strided --home s tx stakeibc restore-interchain-account osmosis-1 {DELEGATION | WITHDRAWAL | FEE | REDEMPTION} --from admin
build/strided --home scripts/state/stride1 tx stakeibc restore-interchain-account cosmoshub-4 {DELEGATION | WITHDRAWAL | FEE | REDEMPTION} --from admin
28 changes: 15 additions & 13 deletions scripts/local-to-mainnet/start.sh
Expand Up @@ -3,22 +3,22 @@
set -eu
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# DO NOT USE STRIDE MAINNET CHAIN ID!
STRIDE_CHAIN_ID=local-test-1
HOST_CHAIN_ID=osmosis-1
HOST_ENDPOINT=osmo-fleet-direct.main.stridenet.co
HOST_ACCOUNT_PREFIX=osmo
HOST_DENOM=uosmo
HOST_BINARY=build/osmosisd
HOST_CHAIN_ID=cosmoshub-4
HOST_ENDPOINT=gaia-fleet-direct.main.stridenet.co
HOST_ACCOUNT_PREFIX=cosmos
HOST_DENOM=uatom
HOST_BINARY=build/gaiad
HOST_VAL_NAME_1=imperator
HOST_VAL_ADDRESS_1=osmovaloper1t8qckan2yrygq7kl9apwhzfalwzgc2429p8f0s
HOST_VAL_ADDRESS_1=cosmosvaloper1vvwtk805lxehwle9l4yudmq6mn0g32px9xtkhc
HOST_VAL_NAME_2=notional
HOST_VAL_ADDRESS_2=osmovaloper1083svrca4t350mphfv9x45wq9asrs60c6rv0j5
HOT_WALLET_ADDRESS=osmo1c37n9aywapx2v0s6vk2yedydkkhq65zz38jfnc
HOST_VAL_ADDRESS_2=cosmosvaloper1083svrca4t350mphfv9x45wq9asrs60cdmrflj
HOT_WALLET_1_ADDRESS=cosmos1c37n9aywapx2v0s6vk2yedydkkhq65zzeupe92

STATE=$SCRIPT_DIR/../state
LOGS=$SCRIPT_DIR/../logs
STRIDE_LOGS=$LOGS/stride.log
STRIDE_HOME=$STATE/stride1
DOCKER_COMPOSE="docker-compose -f $SCRIPT_DIR/docker-compose.yml"

HERMES_STRIDE_MNEMONIC="alter old invest friend relief slot swear pioneer syrup economy vendor tray focus hedgehog artist legend antenna hair almost donkey spice protect sustain increase"
Expand Down Expand Up @@ -79,13 +79,15 @@ $RELAYER_CMD keys restore host rly2 "$HOT_WALLET_3_MNEMONIC"
COMMANDS_FILE=${SCRIPT_DIR}/commands.sh
cp ${SCRIPT_DIR}/templates/commands.sh $COMMANDS_FILE
DOCKER_COMPOSE_RELATIVE="docker-compose -f scripts/local-to-mainnet/docker-compose.yml"
STATE_RELATIVE=scripts/state
LOGS_RELATIVE=scripts/logs
SCRIPTS_RELATIVE=scripts
STATE_RELATIVE=$SCRIPTS_RELATIVE/state
LOGS_RELATIVE=$SCRIPTS_RELATIVE/logs
STRIDE_HOME_RELATIVE=$SCRIPTS_RELATIVE/state/stride1
sed -i -E '1s/^/############################################\n### WARNING: THIS FILE IS AUTOGENERATED. ###\n### ANY CHANGES WILL BE OVERWRITTEN. ###\n############################################\n/' $COMMANDS_FILE
sed -i -E "s|DOCKER_COMPOSE|$DOCKER_COMPOSE_RELATIVE|g" $COMMANDS_FILE
sed -i -E "s|STATE|$STATE_RELATIVE|g" $COMMANDS_FILE
sed -i -E "s|LOGS|$LOGS_RELATIVE|g" $COMMANDS_FILE
sed -i -E "s|STRIDE_HOME|s|g" $COMMANDS_FILE
sed -i -E "s|STRIDE_HOME|$STRIDE_HOME_RELATIVE|g" $COMMANDS_FILE
sed -i -E "s|STRIDE_CHAIN_ID|$STRIDE_CHAIN_ID|g" $COMMANDS_FILE
sed -i -E "s|HOST_CHAIN_ID|$HOST_CHAIN_ID|g" $COMMANDS_FILE
sed -i -E "s|HOST_BINARY|$HOST_BINARY|g" $COMMANDS_FILE
Expand All @@ -96,7 +98,7 @@ sed -i -E "s|HOST_VAL_NAME_1|$HOST_VAL_NAME_1|g" $COMMANDS_FILE
sed -i -E "s|HOST_VAL_NAME_2|$HOST_VAL_NAME_2|g" $COMMANDS_FILE
sed -i -E "s|HOST_VAL_ADDRESS_1|$HOST_VAL_ADDRESS_1|g" $COMMANDS_FILE
sed -i -E "s|HOST_VAL_ADDRESS_2|$HOST_VAL_ADDRESS_2|g" $COMMANDS_FILE
sed -i -E "s|HOT_WALLET_ADDRESS|$HOT_WALLET_ADDRESS|g" $COMMANDS_FILE
sed -i -E "s|HOT_WALLET_ADDRESS|$HOT_WALLET_1_ADDRESS|g" $COMMANDS_FILE

rm -f $COMMANDS_FILE-E
echo "Done"
27 changes: 11 additions & 16 deletions scripts/local-to-mainnet/templates/commands.sh
Expand Up @@ -2,38 +2,32 @@
echo "$HOT_WALLET_1_MNEMONIC" | HOST_BINARY keys add hot --recover --keyring-backend test


#### START RELAYERS
#### START RELAYER
# NOTE: CREATING CONNECTIONS WITH THE GO RELAYER IS BROKEN, USE HERMES
# Create connections and channels
DOCKER_COMPOSE run --rm relayer rly transact link stride-host
# DOCKER_COMPOSE run --rm relayer rly transact link stride-host

# (OR) If the go relayer isn't working, use hermes (you'll have to add the connections to the relayer config though in `STATE/relaye/config/config.yaml`)
# DOCKER_COMPOSE run --rm hermes hermes create connection --a-chain HOST_CHAIN_ID --b-chain STRIDE_CHAIN_ID
# DOCKER_COMPOSE run --rm hermes hermes create channel --a-chain STRIDE_CHAIN_ID --a-connection connection-0 --a-port transfer --b-port transfer
# (OR) If the go relayer isn't working, use hermes (NOTE: you'll have to add the connections to the relayer config in `STATE/relayer/config/config.yaml`)
DOCKER_COMPOSE run --rm hermes hermes create connection --a-chain HOST_CHAIN_ID --b-chain STRIDE_CHAIN_ID
DOCKER_COMPOSE run --rm hermes hermes create channel --a-chain STRIDE_CHAIN_ID --a-connection connection-0 --a-port transfer --b-port transfer

# Ensure Relayer Config is updated (`STATE/relayer/config/config.yaml`)
# Ensure Relayer Config is updated (`scripts/local-to-mainnet/state/relayer/config/config.yaml`)
# paths:
# stride-host:
# src:
# chain-id: stride-1
# chain-id: STRIDE_CHAIN_ID
# client-id: 07-tendermint-0
# connection-id: connection-0
# dst:
# chain-id: cosmoshub-4
# chain-id: HOST_CHAIN_ID
# client-id: {CLIENT-ID}
# connection-id: {CONNECTION-ID}

# Get channel ID created on the host
build/strided --home STRIDE_HOME q ibc channel channels
transfer_channel=$(build/strided --home STRIDE_HOME q ibc channel channels | grep channel-0 -A 4 | grep counterparty -A 1 | grep channel | awk '{print $2}') && echo $transfer_channel

# Start Hermes Relayer
DOCKER_COMPOSE up -d hermes
DOCKER_COMPOSE logs -f hermes | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" >> LOGS/hermes.log 2>&1 &

# Configure the Go Relayer to only run ICQ
sed -i -E "s|rule: \"\"|rule: allowlist|g" STATE/relayer/config/config.yaml

# Start Go Relayer (for ICQ)
# Start Go Relayer
DOCKER_COMPOSE up -d relayer
DOCKER_COMPOSE logs -f relayer | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" >> LOGS/relayer.log 2>&1 &

Expand All @@ -57,6 +51,7 @@ build/strided --home STRIDE_HOME tx stakeibc add-validator HOST_CHAIN_ID HOST_VA
# Confirm ICA channels were registered
build/strided --home STRIDE_HOME q stakeibc list-host-zone


#### FLOW
## Go Through Flow
# Liquid stake (then wait and LS again)
Expand Down
2 changes: 1 addition & 1 deletion scripts/local-to-mainnet/templates/relayer_config.yaml
@@ -1,6 +1,6 @@
global:
api-listen-addr: :5183
timeout: 10s
timeout: 60s
memo: ""
light-cache-size: 20
chains:
Expand Down

0 comments on commit 39ad5b8

Please sign in to comment.