From 4329aa62cc128cd9a3e71e5dde3078d684d44dae Mon Sep 17 00:00:00 2001 From: Manuel <6245917+manu0466@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:04:35 +0200 Subject: [PATCH] build: improve localnet scripts and containers (#127) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Overview This PR updates the Dockerfiles and scripts to run a localnet with all the contracts required for the liquid staking protocol. These updates account for the fact that the liquid staking contract now uses a single oracle contract and the newer version of the treasury contract. closes: #XXXX ## What changes have been made in this PR? - Refactored the scripts to use a set of shared params defined in the `params.sh` file - Added a script to dowload all the required binaries - Refactored the `init-stake-contract.sh` script to use only a single oracle contract - Updated the Dockerfiles to used the new scripts ## Checklist - [ ] Appropriate labels applied - [ ] Targeted PR against correct branch - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Wrote unit and integration - [ ] Updated relevant documentation --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- scripts/deploy/init_stake_contract_testnet.sh | 28 ---- scripts/deploy/tia-osmo-pool.sh | 14 -- scripts/testnet/.dockerignore | 1 + scripts/testnet/Dockerfile | 92 ++++++------- scripts/testnet/Dockerfile.fast | 81 +++++------ scripts/testnet/Local-Testnet.md | 49 ++++--- scripts/testnet/bins/.gitignore | 3 + scripts/testnet/bins/celestia-appd | 20 +++ scripts/testnet/bins/download.sh | 77 +++++++++++ scripts/testnet/bins/hermes | 20 +++ scripts/testnet/bins/osmosisd | 20 +++ scripts/testnet/bins/wrapper.sh | 20 +++ scripts/testnet/check-node-running.sh | 0 scripts/testnet/fund-accounts.sh | 73 ++++++++++ scripts/testnet/hermes-config.toml | 2 + scripts/testnet/init-stake-contract.sh | 107 +++++++++++++++ scripts/testnet/init_ica_oracle.sh | 16 --- scripts/testnet/init_stake_contract.sh | 49 ------- scripts/testnet/local-account.sh | 14 -- .../local-celestia-testnet-multi-continue.sh | 14 +- .../local-celestia-testnet-multi-new.sh | 127 ++++++++++-------- scripts/testnet/local-hermes-clear-packets.sh | 15 ++- scripts/testnet/local-hermes-continue.sh | 8 +- scripts/testnet/local-hermes-new.sh | 23 +++- .../testnet/local-osmosis-testnet-continue.sh | 7 +- scripts/testnet/local-osmosis-testnet-new.sh | 32 +++-- scripts/testnet/migrate_stake_contract.sh | 9 -- scripts/testnet/params.sh | 30 +++++ scripts/testnet/tia-osmo-pool.sh | 35 +++-- scripts/testnet/utils/configure-localnet.sh | 21 +++ scripts/testnet/utils/import-accounts-keys.sh | 13 ++ scripts/testnet/utils/tx.sh | 62 +++++++++ 32 files changed, 737 insertions(+), 345 deletions(-) delete mode 100644 scripts/deploy/init_stake_contract_testnet.sh delete mode 100644 scripts/deploy/tia-osmo-pool.sh create mode 100644 scripts/testnet/.dockerignore create mode 100644 scripts/testnet/bins/.gitignore create mode 100755 scripts/testnet/bins/celestia-appd create mode 100755 scripts/testnet/bins/download.sh create mode 100755 scripts/testnet/bins/hermes create mode 100755 scripts/testnet/bins/osmosisd create mode 100755 scripts/testnet/bins/wrapper.sh mode change 100644 => 100755 scripts/testnet/check-node-running.sh create mode 100755 scripts/testnet/fund-accounts.sh create mode 100755 scripts/testnet/init-stake-contract.sh delete mode 100644 scripts/testnet/init_ica_oracle.sh delete mode 100644 scripts/testnet/init_stake_contract.sh delete mode 100644 scripts/testnet/local-account.sh mode change 100644 => 100755 scripts/testnet/local-hermes-clear-packets.sh mode change 100644 => 100755 scripts/testnet/local-hermes-continue.sh mode change 100644 => 100755 scripts/testnet/local-hermes-new.sh delete mode 100644 scripts/testnet/migrate_stake_contract.sh create mode 100644 scripts/testnet/params.sh mode change 100644 => 100755 scripts/testnet/tia-osmo-pool.sh create mode 100755 scripts/testnet/utils/configure-localnet.sh create mode 100755 scripts/testnet/utils/import-accounts-keys.sh create mode 100755 scripts/testnet/utils/tx.sh diff --git a/scripts/deploy/init_stake_contract_testnet.sh b/scripts/deploy/init_stake_contract_testnet.sh deleted file mode 100644 index caca0584..00000000 --- a/scripts/deploy/init_stake_contract_testnet.sh +++ /dev/null @@ -1,28 +0,0 @@ -RES=$(osmosisd tx wasm store ./artifacts/staking-aarch64.wasm --from test_master --output json --node https://rpc.testnet.osmosis.zone:443 -y -b block --gas-prices 0.025uosmo --gas-adjustment 1.7 --gas auto --chain-id osmo-test-5) -CODE_ID=$(echo $RES | jq -r '.raw_log | fromjson | .[0].events[] | select(.type == "store_code") | .attributes[] | select(.key == "code_id") | .value') -ADMIN_OSMOSIS=osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge -ADMIN_CELESTIA=celestia1sfhy3emrgp26wnzuu64p06kpkxd9phel74e0yx - -CHANNEL_CELESTIA=channel-25 -CHANNEL=channel-4370 - -# token depends on channel it was send over -# find the token by sending it to you and then reading it -celestia-appd tx ibc-transfer transfer transfer $CHANNEL_CELESTIA --from test_master --node https://rpc.celestia-mocha.com:443 --chain-id mocha-4 osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge 1utia --fees 21000utia -y -osmosisd query bank balances osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge --node https://rpc.testnet.osmosis.zone:443 - -NATIVE_TOKEN_DENOM="ibc/0E22FFB61DB307FE01D3D0DFF4A8EBEB6CC4997DCF9E901AE0751A2FFF4B90DD" -CELESTIA_VALIDATOR_1=$(celestia-appd query staking validators --node https://rpc.celestia-mocha.com:443 --output json | jq -r '.validators | map(.operator_address) | join(",")' | cut -d',' -f1 | bech32 --decode | bech32 --prefix celestiavaloper) -CELESTIA_VALIDATOR_2=$(celestia-appd query staking validators --node https://rpc.celestia-mocha.com:443 --output json | jq -r '.validators | map(.operator_address) | join(",")' | cut -d',' -f2 | bech32 --decode | bech32 --prefix celestiavaloper) -CELESTIA_VALIDATOR_3=$(celestia-appd query staking validators --node https://rpc.celestia-mocha.com:443 --output json | jq -r '.validators | map(.operator_address) | join(",")' | cut -d',' -f3 | bech32 --decode | bech32 --prefix celestiavaloper) -INIT={\"native_token_denom\":\"$NATIVE_TOKEN_DENOM\",\"liquid_stake_token_denom\":\"stTIA\",\"treasury_address\":\"$ADMIN_OSMOSIS\",\"monitors\":[\"$ADMIN_OSMOSIS\"],\"validators\":[\"$CELESTIA_VALIDATOR_1\",\"$CELESTIA_VALIDATOR_2\",\"$CELESTIA_VALIDATOR_3\"],\"batch_period\":86400,\"unbonding_period\":1209600,\"protocol_fee_config\":{\"dao_treasury_fee\":\"10\"},\"multisig_address_config\":{\"staker_address\":\"$ADMIN_CELESTIA\",\"reward_collector_address\":\"$ADMIN_CELESTIA\"},\"minimum_liquid_stake_amount\":\"100\",\"ibc_channel_id\":\"$CHANNEL\"} -RES=$(osmosisd tx wasm instantiate $CODE_ID $INIT \ - --from test_master --label "milkyway test" -y \ - --admin "$ADMIN_OSMOSIS" --node https://rpc.testnet.osmosis.zone:443 -y -b block \ - --gas-prices 0.025uosmo --gas-adjustment 1.7 --gas auto \ - --chain-id osmo-test-5 --output json) -CONTRACT=$(echo $RES | jq -r '.raw_log | fromjson | .[0].events[] | select(.type == "instantiate") | .attributes[] | select(.key == "_contract_address") | .value') -echo $CONTRACT - -# current deployment -# osmo1tcmdquceeen0wzye5y5mmctye70gx7mkr6027drzg4xdaphf98ps9rlrw0 \ No newline at end of file diff --git a/scripts/deploy/tia-osmo-pool.sh b/scripts/deploy/tia-osmo-pool.sh deleted file mode 100644 index bc7b6889..00000000 --- a/scripts/deploy/tia-osmo-pool.sh +++ /dev/null @@ -1,14 +0,0 @@ -# this create a tia osmo pool on osmosis testnet - -# send tia -celestia-appd tx ibc-transfer transfer transfer channel-0 --from test_master --keyring-backend test --node http://localhost:26661 --chain-id celestia-dev-1 --fees 21000utia --output json -y osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge 10000000utia --broadcast-mode block | jq -r '.raw_log' - -# get tia ibc token name -osmosisd query bank balances osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge -NATIVE_TOKEN_DENOM="ibc/0E22FFB61DB307FE01D3D0DFF4A8EBEB6CC4997DCF9E901AE0751A2FFF4B90DD" - -osmosisd tx gamm create-pool --pool-file ./pool.json \ - --from test_master --keyring-backend test -y \ - --node https://rpc.testnet.osmosis.zone:443 -b block \ - --gas-prices 0.025uosmo --gas-adjustment 1.7 --gas auto \ - --chain-id osmo-test-5 --output json \ No newline at end of file diff --git a/scripts/testnet/.dockerignore b/scripts/testnet/.dockerignore new file mode 100644 index 00000000..42155f03 --- /dev/null +++ b/scripts/testnet/.dockerignore @@ -0,0 +1 @@ +bins/bins diff --git a/scripts/testnet/Dockerfile b/scripts/testnet/Dockerfile index f150f391..39c40a09 100644 --- a/scripts/testnet/Dockerfile +++ b/scripts/testnet/Dockerfile @@ -1,52 +1,38 @@ FROM ubuntu:latest -RUN apt-get update -RUN apt-get install -y tmux -RUN apt-get install -y git -RUN apt-get install -y make -RUN apt-get install -y golang-go -RUN apt-get install -y wget -RUN apt install unzip -RUN wget https://github.com/osmosis-labs/osmosis/releases/download/v20.1.1/osmosisd-20.1.1-linux-amd64 -RUN mv osmosisd-20.1.1-linux-amd64 /usr/local/bin/osmosisd -RUN chmod +x /usr/local/bin/osmosisd - -RUN ARCH=$(arch | sed s/aarch64/arm64/) && \ - wget https://github.com/celestiaorg/celestia-app/releases/download/v1.3.0/celestia-app_Linux_$ARCH.tar.gz && \ - tar -xvf celestia-app_Linux_$ARCH.tar.gz -RUN mv celestia-appd /usr/local/bin -RUN chmod +x /usr/local/bin/celestia-appd - -RUN ARCH=$(arch) && \ - wget https://github.com/informalsystems/hermes/releases/download/v1.7.0/hermes-v1.7.0-$ARCH-unknown-linux-gnu.zip && \ - unzip hermes-v1.7.0-$ARCH-unknown-linux-gnu.zip -RUN mv hermes /usr/local/bin -RUN chmod +x /usr/local/bin/hermes - -RUN apt-get install -y psmisc -RUN apt-get install -y jq - - -COPY ./check-node-running.sh ./check-node-running.sh -COPY ./local-osmosis-testnet-new.sh ./local-osmosis-testnet-new.sh -RUN sh ./local-osmosis-testnet-new.sh -COPY ./local-celestia-testnet-multi-new.sh ./local-celestia-testnet-multi-new.sh -RUN sh ./local-celestia-testnet-multi-new.sh - -COPY ./local-osmosis-testnet-continue.sh ./local-osmosis-testnet-continue.sh -COPY ./local-celestia-testnet-multi-continue.sh ./local-celestia-testnet-multi-continue.sh -COPY ./local-hermes-continue.sh ./local-hermes-continue.sh -COPY ./local-hermes-new.sh ./local-hermes-new.sh -COPY ./local-account.sh ./local-account.sh -COPY ./hermes-config.toml ./hermes-config.toml -COPY ./local-hermes-clear-packets.sh ./local-hermes-clear-packets.sh -RUN sh ./local-celestia-testnet-multi-continue.sh && \ - sh ./local-osmosis-testnet-continue.sh && \ - sh ./check-node-running.sh osmosis1 && \ - sh ./check-node-running.sh celestia1 && \ - sh ./local-hermes-new.sh && \ - sh ./local-account.sh +RUN apt-get update && \ + apt-get install -y tmux git make golang-go wget unzip psmisc jq + +# Binaries versions +# Remember to update the hermes compatibility mode when bumping the versions +# https://hermes.informal.systems/documentation/configuration/comet-compat-mode.html +ENV OSMOSISD_VERSION="25.0.0" \ + CELESTIA_APP_VERSION="1.11.0" \ + HERMES_VERSION="1.9.0" + +# Prepare the container environment +RUN mkdir /milkiway +COPY ./* /milkiway/ +COPY ./bins /milkiway/bins +COPY ./utils /milkiway/utils +WORKDIR /milkiway + +# Install binaries +RUN bash -c "source /milkiway/bins/download.sh && \ + ensure_installed osmosisd && \ + ensure_installed celestia-appd && \ + ensure_installed hermes" + +RUN ./local-osmosis-testnet-new.sh +RUN ./local-celestia-testnet-multi-new.sh +RUN ./local-celestia-testnet-multi-continue.sh && \ + ./local-osmosis-testnet-continue.sh && \ + ./check-node-running.sh osmosis1 && \ + ./check-node-running.sh celestia1 && \ + ./fund-accounts.sh && \ + ./local-hermes-new.sh && \ + ./tia-osmo-pool.sh EXPOSE 26661 EXPOSE 26657 @@ -55,10 +41,10 @@ EXPOSE 1314 EXPOSE 9090 # last command needs to be persistant to keep container running -CMD sh ./local-celestia-testnet-multi-continue.sh && \ - sh ./local-osmosis-testnet-continue.sh && \ - sh ./check-node-running.sh osmosis1 && \ - sh ./check-node-running.sh celestia1 && \ - sh ./local-hermes-clear-packets.sh && \ - sh ./local-hermes-continue.sh && \ - tail -f /dev/null \ No newline at end of file +CMD ./local-celestia-testnet-multi-continue.sh && \ + ./local-osmosis-testnet-continue.sh && \ + ./check-node-running.sh osmosis1 && \ + ./check-node-running.sh celestia1 && \ + ./local-hermes-clear-packets.sh && \ + ./local-hermes-continue.sh && \ + tail -f /dev/null diff --git a/scripts/testnet/Dockerfile.fast b/scripts/testnet/Dockerfile.fast index 32d6e924..c474ff87 100644 --- a/scripts/testnet/Dockerfile.fast +++ b/scripts/testnet/Dockerfile.fast @@ -1,48 +1,31 @@ FROM ubuntu:latest -RUN apt-get update -RUN apt-get install -y tmux -RUN apt-get install -y git -RUN apt-get install -y make -RUN apt-get install -y golang-go -RUN apt-get install -y wget -RUN apt install unzip - -RUN wget https://github.com/osmosis-labs/osmosis/releases/download/v20.1.1/osmosisd-20.1.1-linux-amd64 -RUN mv osmosisd-20.1.1-linux-amd64 /usr/local/bin/osmosisd -RUN chmod +x /usr/local/bin/osmosisd - -RUN ARCH=$(arch | sed s/aarch64/arm64/) && \ - wget https://github.com/celestiaorg/celestia-app/releases/download/v1.3.0/celestia-app_Linux_$ARCH.tar.gz && \ - tar -xvf celestia-app_Linux_$ARCH.tar.gz -RUN mv celestia-appd /usr/local/bin -RUN chmod +x /usr/local/bin/celestia-appd - -RUN ARCH=$(arch) && \ - wget https://github.com/informalsystems/hermes/releases/download/v1.7.0/hermes-v1.7.0-$ARCH-unknown-linux-gnu.zip && \ - unzip hermes-v1.7.0-$ARCH-unknown-linux-gnu.zip -RUN mv hermes /usr/local/bin -RUN chmod +x /usr/local/bin/hermes - -RUN apt-get install -y psmisc -RUN apt-get install -y jq - - -COPY ./check-node-running.sh ./check-node-running.sh -COPY ./local-osmosis-testnet-new.sh ./local-osmosis-testnet-new.sh -RUN sh ./local-osmosis-testnet-new.sh - -COPY ./local-celestia-testnet-multi-new.sh ./local-celestia-testnet-multi-new.sh +RUN apt-get update && \ + apt-get install -y tmux git make golang-go wget unzip psmisc jq + +# Binaries versions +# Remember to update the hermes compatibility mode when bumping the versions +# https://hermes.informal.systems/documentation/configuration/comet-compat-mode.html +ENV OSMOSISD_VERSION="25.0.0" \ + CELESTIA_APP_VERSION="1.11.0" \ + HERMES_VERSION="1.9.0" + +# Prepare the container environment +RUN mkdir /milkiway +COPY ./* /milkiway/ +COPY ./bins /milkiway/bins +COPY ./utils /milkiway/utils +WORKDIR /milkiway + +# Install binaries +RUN bash -c "source /milkiway/bins/download.sh && \ + ensure_installed osmosisd && \ + ensure_installed celestia-appd && \ + ensure_installed hermes" + +RUN ./local-osmosis-testnet-new.sh # Reduce unbonding time to 6 minutes -RUN UNBONDING_TIME=360s sh ./local-celestia-testnet-multi-new.sh - -COPY ./local-osmosis-testnet-continue.sh ./local-osmosis-testnet-continue.sh -COPY ./local-celestia-testnet-multi-continue.sh ./local-celestia-testnet-multi-continue.sh -COPY ./local-hermes-continue.sh ./local-hermes-continue.sh -COPY ./local-hermes-new.sh ./local-hermes-new.sh -COPY ./local-account.sh ./local-account.sh -COPY ./hermes-config.toml ./hermes-config.toml -COPY ./local-hermes-clear-packets.sh ./local-hermes-clear-packets.sh +RUN UNBONDING_TIME=360s ./local-celestia-testnet-multi-new.sh # Reduce the trust threshold according to the fast unbonding time RUN sed -i -E 's|14d|300s|g' ./hermes-config.toml @@ -55,10 +38,10 @@ EXPOSE 9090 # As the relayer times out very fast, we do create a bridge on start of the docker. # Continues runs will though create new bridges so you need to reset the docker every time. -CMD sh ./local-celestia-testnet-multi-continue.sh && \ - sh ./local-osmosis-testnet-continue.sh && \ - sh ./check-node-running.sh osmosis1 && \ - sh ./check-node-running.sh celestia1 && \ - sh ./local-hermes-new.sh && \ - sh ./local-account.sh && \ - tail -f /dev/null \ No newline at end of file +CMD ./local-celestia-testnet-multi-continue.sh && \ + ./local-osmosis-testnet-continue.sh && \ + ./check-node-running.sh osmosis1 && \ + ./check-node-running.sh celestia1 && \ + ./local-hermes-new.sh && \ + ./local-account.sh && \ + tail -f /dev/null diff --git a/scripts/testnet/Local-Testnet.md b/scripts/testnet/Local-Testnet.md index 44e10752..7c370f4e 100644 --- a/scripts/testnet/Local-Testnet.md +++ b/scripts/testnet/Local-Testnet.md @@ -14,33 +14,50 @@ Now you can always boot into the clean config docker run --name mw-testnet -d -p 26661:26661/udp -p 26657:26657/udp -p 26661:26661/tcp -p 26657:26657/tcp -p 1317:1317 -p 1314:1314 -p 9090:9090 docker.io/library/mw-testnet ``` -Test accounts are funded, check out `./local-accounts.sh` -But you need to import the mnemonic: +Upon creation, the following accounts will be funded: +- `osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge`: Osmosis account used to deploy the contracts on the chain. +- `osmo1lh0u9sug6qh922gjpal3frwtacaums4s7lkyl9`: Osmosis trader account used to swap the fee collected by the treasury contract. +- `celestia1sfhy3emrgp26wnzuu64p06kpkxd9phel74e0yx`: Celestia account that stakes the TIA on the Celestia chain (staker). +- `celestia1lh0u9sug6qh922gjpal3frwtacaums4s8w5yn6`: Celestia account that operates the staker account through the `x/authz` module (grantee). +- `celestia12rzczckgh8fqq533t0xqhqrrzdk76du3dxrx9q`: Celestia account where the staking reward will be withdrawn. -``` -MNEMONIC="boy view flame close solar robust crunch slot govern false jungle dirt blade minor shield bounce rent expand anxiety busy pull inject grace require" +NOTE: The `grantee` account will have all the on chain permissions to control the staker account. -echo $MNEMONIC | osmosisd keys add test_master --recover -echo $MNEMONIC | celestia-appd keys add test_master --recover -``` +Those accounts can be imported into a test keyring through the `utils/import-accounts-keys.sh` script. -Now you can deploy the contract: +After the network is ready, you can configure the clients by using the `utils/configure-localnet.sh` script. -You will need the bech32 dep to parse validator addresses: +## Deploy Contracts -``` -cargo install --git https://github.com/cmoog/bech32 -``` +Before deploying the contracts, you need to: +1. Import the accounts using the `utils/import-accounts-keys.sh` script. +2. Compile the contracts by navigating to the project root directory and running the `make optimize` command. +3. Download the oracle contract from [here](https://github.com/milkyway-labs/milkyway-oracle/releases) and store it in the `artifacts/` folder. + +After completing the above steps, you can deploy the contracts by running: + +```sh +./init_stake_contract.sh ``` -sh ./init_stake_contract.sh -``` -After this you can liquid stake (currently you need to wait a couple of seconds after ibc transfer TIA to Osmosis): +This script will initialize all the contracts and print out their addresses. + +Next, you can IBC transfer some TIA using the following command: +```sh +celestia-appd tx ibc-transfer transfer transfer channel-0 osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge 1000000utia \ + --from staker --fees 21000utia -b block -y ``` -sh ./liquid_stake.sh + +Upon reception, you can liquid stake the received tokens using the following command: + +```sh +osmosisd tx wasm execute osmo1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrsll0sqv '{"liquid_stake":{}}' \ + --amount 1000000ibc/C3E53D20BC7A4CC993B17C7971F8ECD06A433C10B6A96F4C4C3714F0624C56DA \ + --from test_master ``` +NOTE: All the application binaries are available in the `bins` folder and will be lazily downloaded on first use. ### Fast testnet to test unbonding diff --git a/scripts/testnet/bins/.gitignore b/scripts/testnet/bins/.gitignore new file mode 100644 index 00000000..66f30247 --- /dev/null +++ b/scripts/testnet/bins/.gitignore @@ -0,0 +1,3 @@ +# Ignore downloaded binaries +bins/ + diff --git a/scripts/testnet/bins/celestia-appd b/scripts/testnet/bins/celestia-appd new file mode 100755 index 00000000..840e4b19 --- /dev/null +++ b/scripts/testnet/bins/celestia-appd @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# This script serves as a wrapper for various applications +# needed to run a testnet for testing our smart contracts. +# The application to run is determined by the name of this file, +# allowing the creation of links to this script with the actual application names. +# This way, other software depending on these applications +# will think they are using the actual application. + +set -e + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +BINS_DIR="$SCRIPT_DIR/bins" +source "$SCRIPT_DIR/download.sh" +SCRIPT_NAME="$(basename "$0")" + +# Ensure that we have the proper a application installed +ensure_installed "$SCRIPT_NAME" +# Run the application passing the arguments to it +"$BINS_DIR/$SCRIPT_NAME" "$@" diff --git a/scripts/testnet/bins/download.sh b/scripts/testnet/bins/download.sh new file mode 100755 index 00000000..46f421b0 --- /dev/null +++ b/scripts/testnet/bins/download.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash + +set -e + +DEFAULT_OSMOSISD_VERSION="25.0.0" +DEFAULT_CELESTIA_VERSION="1.11.0" +DEFAULT_HERMES_VERSION="1.9.0" + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +BINS_DIR="$SCRIPT_DIR/bins" + + +function download_osmosisd() { + local download_version="$DEFAULT_OSMOSISD_VERSION" + if [[ -n "$OSMOSISD_VERSION" ]]; then + download_version="$OSMOSISD_VERSION" + fi + + local download_url="https://github.com/osmosis-labs/osmosis/releases/download/v${download_version}/osmosisd-${download_version}-linux-amd64" + echo "Downloading osmosisd v${download_version}" + wget -q -O "$BINS_DIR/osmosisd" "$download_url" || { + echo "Failed to download osmosisd." + return 1 + } + chmod +x "$BINS_DIR/osmosisd" +} + +function download_celestia-appd() { + local download_version="$DEFAULT_CELESTIA_VERSION" + if [[ -n "$CELESTIA_APP_VERSION" ]]; then + download_version="$CELESTIA_APP_VERSION" + fi + + local download_url="https://github.com/celestiaorg/celestia-app/releases/download/v${download_version}/celestia-app_Linux_x86_64.tar.gz" + echo "Downloading celestia-appd v${download_version}" + wget -q -O "$BINS_DIR/celestia.tar.gz" "$download_url" || { + echo "Failed to download celestia-appd." + return 1 + } + + + tar --extract --file "$BINS_DIR/celestia.tar.gz" celestia-appd + rm -f "$BINS_DIR/celestia.tar.gz" + mv celestia-appd "$BINS_DIR" + chmod +x "$BINS_DIR/celestia-appd" +} + +function download_hermes() { + local download_version=$DEFAULT_HERMES_VERSION + if [[ -n "$HERMES_VERSION" ]]; then + download_version="$HERMES_VERSION" + fi + + local download_url="https://github.com/informalsystems/hermes/releases/download/v${download_version}/hermes-v${download_version}-x86_64-unknown-linux-gnu.zip" + echo "Downloading hermes v${download_version}" + wget -q -O "$BINS_DIR/hermes.zip" "$download_url" || { + echo "Failed to download hermes." + return 1 + } + + + unzip -j "$BINS_DIR/hermes.zip" "hermes" -d "$BINS_DIR" + chmod +x "$BINS_DIR/hermes" + rm -f "$BINS_DIR/hermes.zip" +} + +function ensure_installed() { + mkdir -p "$BINS_DIR" + + local application=$1 + if [[ ! -f "$BINS_DIR/$application" ]]; then + download_"$application" || { + echo "Failed to download $application" + exit 1 + } + fi +} diff --git a/scripts/testnet/bins/hermes b/scripts/testnet/bins/hermes new file mode 100755 index 00000000..840e4b19 --- /dev/null +++ b/scripts/testnet/bins/hermes @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# This script serves as a wrapper for various applications +# needed to run a testnet for testing our smart contracts. +# The application to run is determined by the name of this file, +# allowing the creation of links to this script with the actual application names. +# This way, other software depending on these applications +# will think they are using the actual application. + +set -e + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +BINS_DIR="$SCRIPT_DIR/bins" +source "$SCRIPT_DIR/download.sh" +SCRIPT_NAME="$(basename "$0")" + +# Ensure that we have the proper a application installed +ensure_installed "$SCRIPT_NAME" +# Run the application passing the arguments to it +"$BINS_DIR/$SCRIPT_NAME" "$@" diff --git a/scripts/testnet/bins/osmosisd b/scripts/testnet/bins/osmosisd new file mode 100755 index 00000000..840e4b19 --- /dev/null +++ b/scripts/testnet/bins/osmosisd @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# This script serves as a wrapper for various applications +# needed to run a testnet for testing our smart contracts. +# The application to run is determined by the name of this file, +# allowing the creation of links to this script with the actual application names. +# This way, other software depending on these applications +# will think they are using the actual application. + +set -e + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +BINS_DIR="$SCRIPT_DIR/bins" +source "$SCRIPT_DIR/download.sh" +SCRIPT_NAME="$(basename "$0")" + +# Ensure that we have the proper a application installed +ensure_installed "$SCRIPT_NAME" +# Run the application passing the arguments to it +"$BINS_DIR/$SCRIPT_NAME" "$@" diff --git a/scripts/testnet/bins/wrapper.sh b/scripts/testnet/bins/wrapper.sh new file mode 100755 index 00000000..840e4b19 --- /dev/null +++ b/scripts/testnet/bins/wrapper.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# This script serves as a wrapper for various applications +# needed to run a testnet for testing our smart contracts. +# The application to run is determined by the name of this file, +# allowing the creation of links to this script with the actual application names. +# This way, other software depending on these applications +# will think they are using the actual application. + +set -e + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +BINS_DIR="$SCRIPT_DIR/bins" +source "$SCRIPT_DIR/download.sh" +SCRIPT_NAME="$(basename "$0")" + +# Ensure that we have the proper a application installed +ensure_installed "$SCRIPT_NAME" +# Run the application passing the arguments to it +"$BINS_DIR/$SCRIPT_NAME" "$@" diff --git a/scripts/testnet/check-node-running.sh b/scripts/testnet/check-node-running.sh old mode 100644 new mode 100755 diff --git a/scripts/testnet/fund-accounts.sh b/scripts/testnet/fund-accounts.sh new file mode 100755 index 00000000..ffcc3b3c --- /dev/null +++ b/scripts/testnet/fund-accounts.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +# Add bins to the path +BINS_DIR="$SCRIPT_DIR/bins" +PATH=$BINS_DIR:$PATH + +source "$SCRIPT_DIR/params.sh" +source "$SCRIPT_DIR/utils/tx.sh" + +echo "Funding $OSMOSIS_ACCOUNT" +wait_tx osmosisd tx bank send validator1 "$OSMOSIS_ACCOUNT" 50000000stake \ + "$OSMOSIS_TX_PARAMS" \ + --home="$HOME/.osmosisd/validator1" -y +wait_tx osmosisd tx bank send validator1 "$OSMOSIS_ACCOUNT" 50000000uosmo \ + "$OSMOSIS_TX_PARAMS" \ + --home="$HOME"/.osmosisd/validator1 -y + +echo "Funding $OSMOSIS_TRADER (trader)" +wait_tx osmosisd tx bank send validator1 "$OSMOSIS_TRADER" 50000000stake \ + "$OSMOSIS_TX_PARAMS" \ + --home="$HOME"/.osmosisd/validator1 -y +wait_tx osmosisd tx bank send validator1 "$OSMOSIS_TRADER" 50000000uosmo \ + "$OSMOSIS_TX_PARAMS" \ + --home="$HOME"/.osmosisd/validator1 -y + +# Funds Celestia accounts +echo "Funding $CELESTIA_STAKER (staker)" +wait_tx celestia-appd tx bank send validator1 $CELESTIA_STAKER 500000000utia \ + "$CELESTIA_TX_PARAMS" \ + --home="$HOME"/.celestia-app/validator1 -y +echo "Funding $CELESTIA_GRANTEE (grantee)" +wait_tx celestia-appd tx bank send validator1 $CELESTIA_GRANTEE 10000000utia \ + "$CELESTIA_TX_PARAMS" \ + --home="$HOME"/.celestia-app/validator1 -y +echo "Funding $CELESTIA_REWARDS_COLLECTOR (rewards_collector)" +wait_tx celestia-appd tx bank send validator1 $CELESTIA_REWARDS_COLLECTOR 1000000utia \ + "$CELESTIA_TX_PARAMS" \ + --home="$HOME"/.celestia-app/validator1 -y + +# Init Celestia accounts +echo "Adding accounts keys to Celestia" +echo "$TESTNET_MNEMONIC" | celestia-appd keys add staker --account $CELESTIA_STAKER_ACCOUNT_INDEX --recover +echo "$TESTNET_MNEMONIC" | celestia-appd keys add grantee --account $CELESTIA_GRANTEE_ACCOUNT_INDEX --recover +echo "$TESTNET_MNEMONIC" | celestia-appd keys add rewards_collector --account $CELESTIA_REWARDS_COLLECTOR_ACCOUNT_INDEX --recover + +# Set rewards collector address +echo "Setting rewards collector address" +wait_tx celestia-appd tx distribution set-withdraw-addr $CELESTIA_REWARDS_COLLECTOR --from staker \ + "$CELESTIA_TX_PARAMS" + +# Grant grants to the grantee +echo "Granting grants from staker to grantee" +wait_tx celestia-appd tx authz grant $CELESTIA_GRANTEE generic --msg-type=/cosmos.staking.v1beta1.MsgDelegate --from staker \ + "$CELESTIA_TX_PARAMS" +wait_tx celestia-appd tx authz grant $CELESTIA_GRANTEE generic --msg-type=/cosmos.staking.v1beta1.MsgUndelegate --from staker \ + "$CELESTIA_TX_PARAMS" +wait_tx celestia-appd tx authz grant $CELESTIA_GRANTEE generic --msg-type=/cosmos.staking.v1beta1.MsgBeginRedelegate --from staker \ + "$CELESTIA_TX_PARAMS" +wait_tx celestia-appd tx authz grant $CELESTIA_GRANTEE generic --msg-type=/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward --from staker \ + "$CELESTIA_TX_PARAMS" +wait_tx celestia-appd tx authz grant $CELESTIA_GRANTEE generic --msg-type=/ibc.applications.transfer.v1.MsgTransfer --from staker \ + "$CELESTIA_TX_PARAMS" +wait_tx celestia-appd tx authz grant $CELESTIA_GRANTEE generic --msg-type=/ibc.applications.transfer.v1.MsgTransfer --from rewards_collector \ + "$CELESTIA_TX_PARAMS" + +# Grant fee grant +echo "Granting fee grant from staker to grantee" +wait_tx celestia-appd tx feegrant grant $CELESTIA_STAKER $CELESTIA_GRANTEE \ + --period 120 --period-limit 500000utia \ + --allowed-messages "/cosmos.authz.v1beta1.MsgExec,/ibc.applications.transfer.v1.MsgTransfer" \ + "$CELESTIA_TX_PARAMS" + diff --git a/scripts/testnet/hermes-config.toml b/scripts/testnet/hermes-config.toml index fd00647b..d4535af0 100644 --- a/scripts/testnet/hermes-config.toml +++ b/scripts/testnet/hermes-config.toml @@ -45,6 +45,7 @@ clock_drift = '5s' max_block_time = '30s' trusting_period = '14d' trust_threshold = { numerator = '2', denominator = '3' } +compat_mode = '0.34' [chains.packet_filter] policy = 'allow' @@ -72,6 +73,7 @@ clock_drift = '5s' max_block_time = '30s' trusting_period = '14d' trust_threshold = { numerator = '2', denominator = '3' } +compat_mode = '0.37' [chains.packet_filter] policy = 'allow' diff --git a/scripts/testnet/init-stake-contract.sh b/scripts/testnet/init-stake-contract.sh new file mode 100755 index 00000000..bb22ccc9 --- /dev/null +++ b/scripts/testnet/init-stake-contract.sh @@ -0,0 +1,107 @@ +#!/bin/bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +ARTIFACTS_DIR="${SCRIPT_DIR}/../../artifacts" +BINS_DIR="${SCRIPT_DIR}/bins" + +# extend PATH to include the bin dirs. +PATH="${BINS_DIR}:${PATH}" + +# Include testenet params +source "${SCRIPT_DIR}/params.sh" +# Include tx utils +source "${SCRIPT_DIR}/utils/tx.sh" + +set -e + +function store_contract() { + local contract_file=$1 + if [ ! -f "$contract_file" ]; then + echo "Contract file not found: $contract_file" + exit 1 + fi + + wait_tx osmosisd tx wasm store "$1" --from test_master --keyring-backend test "$OSMOSIS_TX_PARAMS" + osmosisd query wasm list-code --node $OSMOSIS_NODE --output json | jq -r '.code_infos[-1].code_id' +} + +function init_contract() { + local contract_code=$1 + local init_message=$2 + local label=$3 + + wait_tx osmosisd tx wasm instantiate "$contract_code" "$init_message" \ + --label "$label" --admin "$OSMOSIS_ACCOUNT" \ + --from test_master --keyring-backend test \ + "$OSMOSIS_TX_PARAMS" + + osmosisd query wasm list-contract-by-code "$contract_code" --node $OSMOSIS_NODE --output json | jq -r '.contracts[-1]' +} + +# token depends on channel it was send over +# find the token by sending it to you and then reading it +# celestia-appd tx ibc-transfer transfer transfer channel-0 --from test_master --node http://localhost:26661 --chain-id celestia-dev-1 --fees 21000utia --output json -y osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge 10000000utia --broadcast-mode block | jq -r '.raw_log' +# osmosisd query bank balances osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge +NATIVE_TOKEN_DENOM="ibc/C3E53D20BC7A4CC993B17C7971F8ECD06A433C10B6A96F4C4C3714F0624C56DA" +#VALIDATORS=$(osmosisd query staking validators --output json | jq -r '.validators | map(.operator_address) | join(",")') +CELESTIA_VALIDATOR_1=$(celestia-appd query staking validators --node http://localhost:26661 --output json | jq -r '.validators[] | select(.description.moniker == "validator1") | .operator_address') +#CELESTIA_VALIDATOR_2=$(celestia-appd query staking validators --node http://localhost:26661 --output json | jq -r '.validators[] | select(.description.moniker == "validator2") | .operator_address') +#CELESTIA_VALIDATOR_3=$(celestia-appd query staking validators --node http://localhost:26661 --output json | jq -r '.validators[] | select(.description.moniker == "validator3") | .operator_address') +UNBONDING_PERIOD=$(celestia-appd query staking params --node http://localhost:26661 --output json | jq -r '.unbonding_time | .[:-1]') +BATCH_PERIOD=$(echo "scale=2; ($UNBONDING_PERIOD + 6) / 7" | bc) +BATCH_PERIOD=${BATCH_PERIOD%.*} + +# Contracts paths. +STAKING_CONTRACT_PATH="${ARTIFACTS_DIR}/staking.wasm" +ORACLE_CONTRACT_PATH="${ARTIFACTS_DIR}/oracle.wasm" +TREASURY_CONTRACT_PATH="${ARTIFACTS_DIR}/treasury.wasm" + +# Store the staking contract +echo "Storing staking contract..." +STAKING_CONTRACT_CODE_ID=$(store_contract "$STAKING_CONTRACT_PATH") +echo "Store MilkyWay oracle contract" +ORACLE_CODE_ID=$(store_contract "$ORACLE_CONTRACT_PATH") +echo "Store MilkyWay treasury contract" +TREASURY_CODE_ID=$(store_contract "$TREASURY_CONTRACT_PATH") + +echo "" +echo "All contracts stored!" +echo "Staking contract code: $STAKING_CONTRACT_CODE_ID" +echo "Oracle contract code: $ORACLE_CODE_ID" +echo "Treasury contract code: $TREASURY_CODE_ID" +echo "" + +# Contracts initialization + +echo "Init treasury contract" +INIT="{\"trader\":\"$OSMOSIS_TRADER\",\"allowed_swap_routes\":[[{\"pool_id\":1,\"token_in_denom\":\"$NATIVE_TOKEN_DENOM\",\"token_out_denom\":\"uosmo\"}]]}" \ +TREASURY_CONTRACT=$(init_contract "$TREASURY_CODE_ID" "$INIT" "Treasury") + +echo "Init staking contract" +INIT="{\"native_token_denom\":\"$NATIVE_TOKEN_DENOM\",\"liquid_stake_token_denom\":\"milkTIA\",\"treasury_address\":\"$TREASURY_CONTRACT\",\"monitors\":[\"$OSMOSIS_ACCOUNT\"],\"validators\":[\"$CELESTIA_VALIDATOR_1\"],\"batch_period\":60,\"unbonding_period\":$UNBONDING_PERIOD,\"protocol_fee_config\":{\"dao_treasury_fee\":\"800\"},\"multisig_address_config\":{\"staker_address\":\"$CELESTIA_STAKER\",\"reward_collector_address\":\"$CELESTIA_REWARDS_COLLECTOR\"},\"minimum_liquid_stake_amount\":\"100\",\"ibc_channel_id\":\"channel-0\",\"send_fees_to_treasury\":true}" +STAKE_CONTRACT=$(init_contract "$STAKING_CONTRACT_CODE_ID" "$INIT" "Staking") +#VALIDATORS=$(osmosisd query staking validators --output json | jq -r '.validators | map(.operator_address) | join(",")') + +# Init our oracle contract +echo "Init oracle contract" +INIT="{\"admin_address\":\"$STAKE_CONTRACT\"}" +ORACLE_CONTRACT=$(init_contract "$ORACLE_CODE_ID" "$INIT" "Oracle") + +# Start the staking contract +echo "Starting the staking contract..." +INIT="{\"update_config\":{\"oracle_address\":\"$ORACLE_CONTRACT\"}}" +wait_tx osmosisd tx wasm execute "$STAKE_CONTRACT" "$INIT" \ + --from test_master --keyring-backend test \ + "$OSMOSIS_TX_PARAMS" + +wait_tx osmosisd tx wasm execute "$STAKE_CONTRACT" '{"resume_contract":{"total_native_token":"0","total_liquid_stake_token":"0","total_reward_amount":"0"}}' \ + --from test_master --keyring-backend test \ + "$OSMOSIS_TX_PARAMS" + +echo "" +echo "Contracts initialized!" +echo "Staking contract address: $STAKE_CONTRACT" +echo "Oracle contract address: $ORACLE_CONTRACT" +echo "Treasury contract address: $TREASURY_CONTRACT" +echo "" + diff --git a/scripts/testnet/init_ica_oracle.sh b/scripts/testnet/init_ica_oracle.sh deleted file mode 100644 index 3fb0da73..00000000 --- a/scripts/testnet/init_ica_oracle.sh +++ /dev/null @@ -1,16 +0,0 @@ -# init in stride folder - -RES=$(osmosisd tx wasm store ./artifacts/ica_oracle.wasm --from test_master --keyring-backend test --output json --node http://localhost:26657 -y -b block --gas-prices 0.025stake --gas-adjustment 1.7 --gas auto --chain-id osmosis-dev-1) -CODE_ID=$(osmosisd query wasm list-code --output json | jq -r '.code_infos[-1].code_id') - -STAKE_CONTRACT=osmo1lnfn4f9gpz8fmvquarmuph62wmss3qwh92j98z4y4q4x566stkmsnfuffg -ADMIN_OSMOSIS=osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge - -INIT={\"admin_address\":\"$STAKE_CONTRACT\"} -osmosisd tx wasm instantiate $CODE_ID $INIT \ - --from test_master --keyring-backend test --label "milkyway test" -y \ - --admin "$ADMIN_OSMOSIS" --node http://localhost:26657 -y -b block \ - --gas-prices 0.025stake --gas-adjustment 1.7 --gas auto \ - --chain-id osmosis-dev-1 -CONTRACT=$(osmosisd query wasm list-contract-by-code $CODE_ID --node http://localhost:26657 --output json | jq -r '.contracts[-1]') -echo $CONTRACT \ No newline at end of file diff --git a/scripts/testnet/init_stake_contract.sh b/scripts/testnet/init_stake_contract.sh deleted file mode 100644 index 37dc461c..00000000 --- a/scripts/testnet/init_stake_contract.sh +++ /dev/null @@ -1,49 +0,0 @@ -# cargo install --git https://github.com/cmoog/bech32 - -TXHASH=$(osmosisd tx wasm store ./artifacts/staking-aarch64.wasm --from test_master --keyring-backend test --output json --node http://localhost:26657 -y -b sync --gas-prices 0.025stake --gas-adjustment 1.7 --gas auto --chain-id osmosis-dev-1 | jq -r '.txhash') -# wait - -CODE_ID=$(osmosisd query wasm list-code --output json | jq -r '.code_infos[-1].code_id') -ADMIN_OSMOSIS=osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge -ADMIN_CELESTIA=celestia1sfhy3emrgp26wnzuu64p06kpkxd9phel74e0yx -# token depends on channel it was send over -# find the token by sending it to you and then reading it -# celestia-appd tx ibc-transfer transfer transfer channel-0 --from test_master --node http://localhost:26661 --chain-id celestia-dev-1 --fees 21000utia --output json -y osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge 10000000utia --broadcast-mode block | jq -r '.raw_log' -# osmosisd query bank balances osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge -NATIVE_TOKEN_DENOM="ibc/C3E53D20BC7A4CC993B17C7971F8ECD06A433C10B6A96F4C4C3714F0624C56DA" -VALIDATORS=$(osmosisd query staking validators --output json | jq -r '.validators | map(.operator_address) | join(",")') -OSMOSIS_VALIDATOR_1=$(echo $VALIDATORS | cut -d',' -f1 | bech32 --decode | bech32 --prefix osmo) -CELESTIA_VALIDATOR_1=$(celestia-appd query staking validators --node http://localhost:26661 --output json | jq -r '.validators[] | select(.description.moniker == "validator1") | .operator_address') -CELESTIA_VALIDATOR_2=$(celestia-appd query staking validators --node http://localhost:26661 --output json | jq -r '.validators[] | select(.description.moniker == "validator2") | .operator_address') -CELESTIA_VALIDATOR_3=$(celestia-appd query staking validators --node http://localhost:26661 --output json | jq -r '.validators[] | select(.description.moniker == "validator3") | .operator_address') -UNBONDING_PERIOD=$(celestia-appd query staking params --node http://localhost:26661 --output json | jq -r '.unbonding_time | .[:-1]') -BATCH_PERIOD=$(echo "scale=2; ($UNBONDING_PERIOD + 6) / 7" | bc) -BATCH_PERIOD=${BATCH_PERIOD%.*} -INIT={\"native_token_denom\":\"$NATIVE_TOKEN_DENOM\",\"liquid_stake_token_denom\":\"milkTIA\",\"treasury_address\":\"$ADMIN_OSMOSIS\",\"monitors\":[\"$ADMIN_OSMOSIS\"],\"validators\":[\"$CELESTIA_VALIDATOR_1\",\"$CELESTIA_VALIDATOR_2\",\"$CELESTIA_VALIDATOR_3\"],\"batch_period\":86400,\"unbonding_period\":$UNBONDING_PERIOD,\"protocol_fee_config\":{\"dao_treasury_fee\":\"10\"},\"multisig_address_config\":{\"staker_address\":\"$ADMIN_CELESTIA\",\"reward_collector_address\":\"$ADMIN_CELESTIA\"},\"minimum_liquid_stake_amount\":\"100\",\"ibc_channel_id\":\"channel-0\"} -osmosisd tx wasm instantiate $CODE_ID $INIT \ - --from test_master --keyring-backend test --label "milkyway test" -y \ - --admin "$ADMIN_OSMOSIS" --node http://localhost:26657 -y -b sync \ - --gas-prices 0.025stake --gas-adjustment 1.7 --gas auto \ - --chain-id osmosis-dev-1 - -# wait - -STAKE_CONTRACT=$(osmosisd query wasm list-contract-by-code $CODE_ID --node http://localhost:26657 --output json | jq -r '.contracts[-1]') -echo $STAKE_CONTRACT - -# deploy oracle contract - -# ORACLE_CONTRACT=osmo1nc5tatafv6eyq7llkr2gv50ff9e22mnf70qgjlv737ktmt4eswrqvlx82r -osmosisd tx wasm execute $STAKE_CONTRACT '{"update_config":{"oracle_contract_address":"'$ORACLE_CONTRACT'"}}' \ - --from test_master --keyring-backend test \ - -y -b sync \ - --gas-prices 0.025stake --gas-adjustment 1.7 --gas auto \ - --chain-id osmosis-dev-1 - -# wait - -osmosisd tx wasm execute $STAKE_CONTRACT '{"resume_contract":{"total_native_token":"0","total_liquid_stake_token":"0","total_reward_amount":"0"}}' \ - --from test_master --keyring-backend test -y \ - --node http://localhost:26657 -y -b sync \ - --gas-prices 0.025stake --gas-adjustment 1.7 --gas auto \ - --chain-id osmosis-dev-1 diff --git a/scripts/testnet/local-account.sh b/scripts/testnet/local-account.sh deleted file mode 100644 index 7f770234..00000000 --- a/scripts/testnet/local-account.sh +++ /dev/null @@ -1,14 +0,0 @@ -# test mnemonic, so in tests you have a funded account -# MNEMONIC="boy view flame close solar robust crunch slot govern false jungle dirt blade minor shield bounce rent expand anxiety busy pull inject grace require addresses" -# celestia1sfhy3emrgp26wnzuu64p06kpkxd9phel74e0yx -# osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge - -OSMOSIS_ADDR=osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge -osmosisd tx bank send validator1 $OSMOSIS_ADDR 50000000stake --keyring-backend=test --home=$HOME/.osmosisd/validator1 --chain-id osmosis-dev-1 --fees 875stake -y --broadcast-mode block -osmosisd tx bank send validator1 $OSMOSIS_ADDR 50000000uosmo --keyring-backend=test --home=$HOME/.osmosisd/validator1 --chain-id osmosis-dev-1 --fees 875stake -y --broadcast-mode block - -CELESTIA_ADDR=celestia1sfhy3emrgp26wnzuu64p06kpkxd9phel74e0yx -celestia-appd tx bank send validator1 $CELESTIA_ADDR 500000000utia --keyring-backend=test --home=$HOME/.celestia-app/validator1 --node http://0.0.0.0:26661 --chain-id celestia-dev-1 --fees 21000utia -y --broadcast-mode block - -# echo $MNEMONIC | osmosisd keys add test_master --recover -# echo $MNEMONIC | celestia-appd keys add test_master --recover \ No newline at end of file diff --git a/scripts/testnet/local-celestia-testnet-multi-continue.sh b/scripts/testnet/local-celestia-testnet-multi-continue.sh index eacfc9dc..f5204f9e 100755 --- a/scripts/testnet/local-celestia-testnet-multi-continue.sh +++ b/scripts/testnet/local-celestia-testnet-multi-continue.sh @@ -1,4 +1,8 @@ -#!/bin/sh +#!/bin/bash + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +BINS_DIR=$SCRIPT_DIR/bins +PATH=$BINS_DIR:$PATH # Stop script execution if an error is encountered set -o errexit @@ -9,12 +13,12 @@ killall celestia-appd || true # Start celestia-app echo "Starting celestia-app..." -tmux new -s celestia2 -d celestia-appd start --home=$HOME/.celestia-app/validator2 -tmux new -s celestia3 -d celestia-appd start --home=$HOME/.celestia-app/validator3 -tmux new -s celestia1 -d celestia-appd start --home=$HOME/.celestia-app/validator1 \ +tmux new -s celestia2 -d celestia-appd start --home="$HOME"/.celestia-app/validator2 +tmux new -s celestia3 -d celestia-appd start --home="$HOME"/.celestia-app/validator3 +tmux new -s celestia1 -d celestia-appd start --home="$HOME"/.celestia-app/validator1 \ --api.enable \ --grpc.enable \ --grpc-web.enable \ --api.address tcp://0.0.0.0:1314 \ --grpc.address 0.0.0.0:9084 \ - --grpc-web.address 0.0.0.0:9085 \ No newline at end of file + --grpc-web.address 0.0.0.0:9085 diff --git a/scripts/testnet/local-celestia-testnet-multi-new.sh b/scripts/testnet/local-celestia-testnet-multi-new.sh index eaf437a5..dfbb52f0 100755 --- a/scripts/testnet/local-celestia-testnet-multi-new.sh +++ b/scripts/testnet/local-celestia-testnet-multi-new.sh @@ -1,41 +1,48 @@ #!/bin/bash + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +BINS_DIR=$SCRIPT_DIR/bins +PATH=$BINS_DIR:$PATH + set -e +# Include the utils function +source "$SCRIPT_DIR"/utils/tx.sh + # always returns true so set -e doesn't exit if it is not running. killall celestia-appd || true # make four celestia directories -mkdir -p $HOME/.celestia-app -mkdir $HOME/.celestia-app/validator1 -mkdir $HOME/.celestia-app/validator2 -mkdir $HOME/.celestia-app/validator3 +mkdir -p "$HOME"/.celestia-app +mkdir "$HOME"/.celestia-app/validator1 +mkdir "$HOME"/.celestia-app/validator2 +mkdir "$HOME"/.celestia-app/validator3 # init all three validators -celestia-appd init --chain-id=celestia-dev-1 validator1 --home=$HOME/.celestia-app/validator1 -celestia-appd init --chain-id=celestia-dev-1 validator2 --home=$HOME/.celestia-app/validator2 -celestia-appd init --chain-id=celestia-dev-1 validator3 --home=$HOME/.celestia-app/validator3 +celestia-appd init --chain-id=celestia-dev-1 validator1 --home="$HOME"/.celestia-app/validator1 +celestia-appd init --chain-id=celestia-dev-1 validator2 --home="$HOME"/.celestia-app/validator2 +celestia-appd init --chain-id=celestia-dev-1 validator3 --home="$HOME"/.celestia-app/validator3 # create keys for all three validators -celestia-appd keys add validator1 --keyring-backend=test --home=$HOME/.celestia-app/validator1 -celestia-appd keys add validator2 --keyring-backend=test --home=$HOME/.celestia-app/validator2 -celestia-appd keys add validator3 --keyring-backend=test --home=$HOME/.celestia-app/validator3 +celestia-appd keys add validator1 --keyring-backend=test --home="$HOME"/.celestia-app/validator1 +celestia-appd keys add validator2 --keyring-backend=test --home="$HOME"/.celestia-app/validator2 +celestia-appd keys add validator3 --keyring-backend=test --home="$HOME"/.celestia-app/validator3 -update_genesis () { - cat $HOME/.celestia-app/validator1/config/genesis.json | jq "$1" > $HOME/.celestia-app/validator1/config/tmp_genesis.json && mv $HOME/.celestia-app/validator1/config/tmp_genesis.json $HOME/.celestia-app/validator1/config/genesis.json +update_genesis() { + cat "$HOME"/.celestia-app/validator1/config/genesis.json | jq "$1" >"$HOME"/.celestia-app/validator1/config/tmp_genesis.json && mv "$HOME"/.celestia-app/validator1/config/tmp_genesis.json "$HOME"/.celestia-app/validator1/config/genesis.json } # change unbonding time to 1 hour if env variable is set -if [ -z "$UNBONDING_TIME" ] -then - echo "UNBONDING_TIME is unset, using default value of 21 days" +if [ -z "$UNBONDING_TIME" ]; then + echo "UNBONDING_TIME is unset, using default value of 21 days" else - echo "UNBONDING_TIME is set to '$UNBONDING_TIME', using this value" - update_genesis '.app_state["staking"]["params"]["unbonding_time"]'="\"$UNBONDING_TIME\"" + echo "UNBONDING_TIME is set to '$UNBONDING_TIME', using this value" + update_genesis '.app_state["staking"]["params"]["unbonding_time"]'="\"$UNBONDING_TIME\"" fi # create validator node with tokens to transfer to the three other nodes -celestia-appd add-genesis-account $(celestia-appd keys show validator1 -a --keyring-backend=test --home=$HOME/.celestia-app/validator1) 10000000000utia --home=$HOME/.celestia-app/validator1 -celestia-appd gentx validator1 600000000utia --keyring-backend=test --home=$HOME/.celestia-app/validator1 --chain-id=celestia-dev-1 -celestia-appd collect-gentxs --home=$HOME/.celestia-app/validator1 +celestia-appd add-genesis-account "$(celestia-appd keys show validator1 -a --keyring-backend=test --home="$HOME"/.celestia-app/validator1)" 1000000000000000utia --home="$HOME"/.celestia-app/validator1 +celestia-appd gentx validator1 600000000utia --keyring-backend=test --home="$HOME"/.celestia-app/validator1 --chain-id=celestia-dev-1 +celestia-appd collect-gentxs --home="$HOME"/.celestia-app/validator1 # port key (osmosis uses default ports) # validator1 1314, 9084, 9085, 26661, 26661, 26660, 6060 @@ -48,49 +55,63 @@ VALIDATOR2_CONFIG=$HOME/.celestia-app/validator2/config/config.toml VALIDATOR3_CONFIG=$HOME/.celestia-app/validator3/config/config.toml # validator1 -sed -i -E 's|tcp://127.0.0.1:26658|tcp://0.0.0.0:26662|g' $VALIDATOR1_CONFIG -sed -i -E 's|tcp://127.0.0.1:26657|tcp://0.0.0.0:26661|g' $VALIDATOR1_CONFIG -sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26660|g' $VALIDATOR1_CONFIG -sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR1_CONFIG -sed -i -E 's#"null"#"kv"#g' $VALIDATOR1_CONFIG -sed -i -E 's|discard_abci_responses = true|discard_abci_responses = false|g' $VALIDATOR1_CONFIG +sed -i -E 's|tcp://127.0.0.1:26658|tcp://0.0.0.0:26662|g' "$VALIDATOR1_CONFIG" +sed -i -E 's|tcp://127.0.0.1:26657|tcp://0.0.0.0:26661|g' "$VALIDATOR1_CONFIG" +sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26660|g' "$VALIDATOR1_CONFIG" +sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' "$VALIDATOR1_CONFIG" +sed -i -E 's#"null"#"kv"#g' "$VALIDATOR1_CONFIG" +sed -i -E 's|discard_abci_responses = true|discard_abci_responses = false|g' "$VALIDATOR1_CONFIG" # validator2 -sed -i -E 's|tcp://127.0.0.1:26658|tcp://0.0.0.0:26655|g' $VALIDATOR2_CONFIG -sed -i -E 's|tcp://127.0.0.1:26657|tcp://0.0.0.0:26654|g' $VALIDATOR2_CONFIG -sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26653|g' $VALIDATOR2_CONFIG -sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR2_CONFIG +sed -i -E 's|tcp://127.0.0.1:26658|tcp://0.0.0.0:26655|g' "$VALIDATOR2_CONFIG" +sed -i -E 's|tcp://127.0.0.1:26657|tcp://0.0.0.0:26654|g' "$VALIDATOR2_CONFIG" +sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26653|g' "$VALIDATOR2_CONFIG" +sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' "$VALIDATOR2_CONFIG" # validator3 -sed -i -E 's|tcp://127.0.0.1:26658|tcp://0.0.0.0:26652|g' $VALIDATOR3_CONFIG -sed -i -E 's|tcp://127.0.0.1:26657|tcp://0.0.0.0:26651|g' $VALIDATOR3_CONFIG -sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26650|g' $VALIDATOR3_CONFIG -sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR3_CONFIG - +sed -i -E 's|tcp://127.0.0.1:26658|tcp://0.0.0.0:26652|g' "$VALIDATOR3_CONFIG" +sed -i -E 's|tcp://127.0.0.1:26657|tcp://0.0.0.0:26651|g' "$VALIDATOR3_CONFIG" +sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26650|g' "$VALIDATOR3_CONFIG" +sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' "$VALIDATOR3_CONFIG" # copy validator1 genesis file to validator2-3 -cp $HOME/.celestia-app/validator1/config/genesis.json $HOME/.celestia-app/validator2/config/genesis.json -cp $HOME/.celestia-app/validator1/config/genesis.json $HOME/.celestia-app/validator3/config/genesis.json - +cp "$HOME"/.celestia-app/validator1/config/genesis.json "$HOME"/.celestia-app/validator2/config/genesis.json +# VALIDATORS=$(osmosisd query staking validators --output json | jq -r '.validators | map(.operator_address) | join(",")') +cp "$HOME"/.celestia-app/validator1/config/genesis.json "$HOME"/.celestia-app/validator3/config/genesis.json # copy tendermint node id of validator1 to persistent peers of validator2-3 -sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$(celestia-appd tendermint show-node-id --home=$HOME/.celestia-app/validator1)@localhost:26660\"|g" $HOME/.celestia-app/validator2/config/config.toml -sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$(celestia-appd tendermint show-node-id --home=$HOME/.celestia-app/validator1)@localhost:26660\"|g" $HOME/.celestia-app/validator3/config/config.toml +sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$(celestia-appd tendermint show-node-id --home="$HOME"/.celestia-app/validator1)@localhost:26660\"|g" "$HOME"/.celestia-app/validator2/config/config.toml +sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$(celestia-appd tendermint show-node-id --home="$HOME"/.celestia-app/validator1)@localhost:26660\"|g" "$HOME"/.celestia-app/validator3/config/config.toml # start all three validators -tmux new -s celestia1 -d celestia-appd start --home=$HOME/.celestia-app/validator1 -tmux new -s celestia2 -d celestia-appd start --home=$HOME/.celestia-app/validator2 -tmux new -s celestia3 -d celestia-appd start --home=$HOME/.celestia-app/validator3 - +tmux new -s celestia1 -d celestia-appd start --home="$HOME"/.celestia-app/validator1 +tmux new -s celestia2 -d celestia-appd start --home="$HOME"/.celestia-app/validator2 +tmux new -s celestia3 -d celestia-appd start --home="$HOME"/.celestia-app/validator3 # send utia from first validator to second validator echo "Waiting to send funds to validators 2 and 3..." -sh ./check-node-running.sh celestia1 -sh ./check-node-running.sh celestia2 -sh ./check-node-running.sh celestia3 -celestia-appd tx bank send validator1 $(celestia-appd keys show validator2 -a --keyring-backend=test --home=$HOME/.celestia-app/validator2) 510000000utia --keyring-backend=test --home=$HOME/.celestia-app/validator1 --chain-id=celestia-dev-1 --broadcast-mode block --node http://localhost:26661 --yes --fees 21000utia -celestia-appd tx bank send validator1 $(celestia-appd keys show validator3 -a --keyring-backend=test --home=$HOME/.celestia-app/validator3) 410000000utia --keyring-backend=test --home=$HOME/.celestia-app/validator1 --chain-id=celestia-dev-1 --broadcast-mode block --node http://localhost:26661 --yes --fees 21000utia +./check-node-running.sh celestia1 +./check-node-running.sh celestia2 +./check-node-running.sh celestia3 + +VALIDATOR2_ADDRESS=$(celestia-appd keys show validator2 -a --keyring-backend=test --home="$HOME"/.celestia-app/validator2) +VALIDATOR2_PUBKEY=$(celestia-appd tendermint show-validator --home="$HOME"/.celestia-app/validator2) +VALIDATOR3_ADDRESS=$(celestia-appd keys show validator3 -a --keyring-backend=test --home="$HOME"/.celestia-app/validator3) +VALIDATOR3_PUBKEY=$(celestia-appd tendermint show-validator --home="$HOME"/.celestia-app/validator3) + +wait_tx celestia-appd tx bank send validator1 "$VALIDATOR2_ADDRESS" 510000000utia \ + --keyring-backend=test --home="$HOME"/.celestia-app/validator1 --chain-id=celestia-dev-1 \ + --node http://localhost:26661 --yes --fees 21000utia +wait_tx celestia-appd tx bank send validator1 "$VALIDATOR3_ADDRESS" 410000000utia \ + --keyring-backend=test --home="$HOME"/.celestia-app/validator1 --chain-id=celestia-dev-1 \ + --node http://localhost:26661 --yes --fees 21000utia # create second & third validator -celestia-appd tx staking create-validator --amount=500000000utia --from=validator2 --pubkey=$(celestia-appd tendermint show-validator --home=$HOME/.celestia-app/validator2) --moniker="validator2" --chain-id="celestia-dev-1" --commission-rate="0.1" --commission-max-rate="0.2" --commission-max-change-rate="0.05" --min-self-delegation="500000000" --keyring-backend=test --home=$HOME/.celestia-app/validator2 --broadcast-mode block --node http://localhost:26661 --yes --fees 21000utia -celestia-appd tx staking create-validator --amount=400000000utia --from=validator3 --pubkey=$(celestia-appd tendermint show-validator --home=$HOME/.celestia-app/validator3) --moniker="validator3" --chain-id="celestia-dev-1" --commission-rate="0.1" --commission-max-rate="0.2" --commission-max-change-rate="0.05" --min-self-delegation="400000000" --keyring-backend=test --home=$HOME/.celestia-app/validator3 --broadcast-mode block --node http://localhost:26661 --yes --fees 21000utia - -echo "All 3 Validators are up and running!" \ No newline at end of file +wait_tx celestia-appd tx staking create-validator --amount=500000000utia --from=validator2 --pubkey="$VALIDATOR2_PUBKEY" --moniker="validator2" \ + --commission-rate="0.1" --commission-max-rate="0.2" \ + --commission-max-change-rate="0.05" --min-self-delegation="500000000" \ + --chain-id="celestia-dev-1" --keyring-backend=test --home="$HOME"/.celestia-app/validator2 --node http://localhost:26661 --yes --fees 21000utia +wait_tx celestia-appd tx staking create-validator --amount=400000000utia --from=validator3 --pubkey="$VALIDATOR3_PUBKEY" --moniker="validator3" \ + --commission-rate="0.1" --commission-max-rate="0.2" \ + --commission-max-change-rate="0.05" --min-self-delegation="400000000" \ + --chain-id="celestia-dev-1" --keyring-backend=test --home="$HOME"/.celestia-app/validator3 --node http://localhost:26661 --yes --fees 21000utia + +echo "All 3 Validators are up and running!" diff --git a/scripts/testnet/local-hermes-clear-packets.sh b/scripts/testnet/local-hermes-clear-packets.sh old mode 100644 new mode 100755 index 83a9787b..19837168 --- a/scripts/testnet/local-hermes-clear-packets.sh +++ b/scripts/testnet/local-hermes-clear-packets.sh @@ -1,8 +1,13 @@ +#!/bin/bash + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +BINS_DIR=$SCRIPT_DIR/bins +PATH=$BINS_DIR:$PATH + # clears the packages in the channel as they frequently get stuck -while true -do - hermes clear packets --chain osmosis-dev-1 --port transfer --channel channel-0 - hermes clear packets --chain celestia-dev-1 --port transfer --channel channel-0 - sleep 1 +while true; do + hermes clear packets --chain osmosis-dev-1 --port transfer --channel channel-0 + hermes clear packets --chain celestia-dev-1 --port transfer --channel channel-0 + sleep 1 done diff --git a/scripts/testnet/local-hermes-continue.sh b/scripts/testnet/local-hermes-continue.sh old mode 100644 new mode 100755 index 543d97cc..00d7fe52 --- a/scripts/testnet/local-hermes-continue.sh +++ b/scripts/testnet/local-hermes-continue.sh @@ -1 +1,7 @@ -tmux new -s hermes -d hermes start \ No newline at end of file +#!/bin/bash + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +BINS_DIR=$SCRIPT_DIR/bins +PATH=$BINS_DIR:$PATH + +tmux new -s hermes -d hermes start diff --git a/scripts/testnet/local-hermes-new.sh b/scripts/testnet/local-hermes-new.sh old mode 100644 new mode 100755 index 0e7c0a17..8edda397 --- a/scripts/testnet/local-hermes-new.sh +++ b/scripts/testnet/local-hermes-new.sh @@ -1,4 +1,11 @@ -#!/bin/sh +#!/bin/bash + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +BINS_DIR=$SCRIPT_DIR/bins +PATH=$BINS_DIR:$PATH + +# Include the utils function +source "$SCRIPT_DIR"/utils/tx.sh # Stop script execution if an error is encountered set -o errexit @@ -10,15 +17,19 @@ killall hermes || true mkdir -p ~/.hermes cp ./hermes-config.toml ~/.hermes/config.toml -celestia-appd keys add relayer --output=json --keyring-backend test 2> ./celestia-relayer-key.json -osmosisd keys add relayer --output=json --keyring-backend test 2> ./osmosis-relayer-key.json +celestia-appd keys add relayer --output=json --keyring-backend test 2>./celestia-relayer-key.json +osmosisd keys add relayer --output=json --keyring-backend test 2>./osmosis-relayer-key.json hermes keys add --chain osmosis-dev-1 --key-file './osmosis-relayer-key.json' hermes keys add --chain celestia-dev-1 --key-file './celestia-relayer-key.json' OSMOSIS_ADDR=$(jq -r '.address' ./osmosis-relayer-key.json) -osmosisd tx bank send validator1 $OSMOSIS_ADDR 50000000stake --keyring-backend=test --home=$HOME/.osmosisd/validator1 --chain-id osmosis-dev-1 --fees 875stake -y -b block +wait_tx osmosisd tx bank send validator1 "$OSMOSIS_ADDR" 50000000stake \ + --keyring-backend=test --home="$HOME"/.osmosisd/validator1 \ + --chain-id osmosis-dev-1 --fees 875stake -y CELESTIA_ADDR=$(jq -r '.address' ./celestia-relayer-key.json) -celestia-appd tx bank send validator1 $CELESTIA_ADDR 5000000000utia --keyring-backend=test --home=$HOME/.celestia-app/validator1 --chain-id celestia-dev-1 --fees 21000utia -y -b block --node http://0.0.0.0:26661 +wait_tx celestia-appd tx bank send validator1 "$CELESTIA_ADDR" 5000000000utia \ + --keyring-backend=test --home="$HOME"/.celestia-app/validator1 \ + --chain-id celestia-dev-1 --fees 21000utia -y --node http://0.0.0.0:26661 hermes create client --host-chain celestia-dev-1 --reference-chain osmosis-dev-1 hermes create client --host-chain osmosis-dev-1 --reference-chain celestia-dev-1 @@ -32,4 +43,4 @@ echo "--- HERMES READY ---" tmux new -s hermes -d hermes start # start a loop to clear packets -tmux new -s hermes-clear-lopp -d sh ./local-hermes-clear-packets.sh \ No newline at end of file +tmux new -s hermes-clear-lopp -d sh ./local-hermes-clear-packets.sh diff --git a/scripts/testnet/local-osmosis-testnet-continue.sh b/scripts/testnet/local-osmosis-testnet-continue.sh index efa40b0f..a36a16e1 100755 --- a/scripts/testnet/local-osmosis-testnet-continue.sh +++ b/scripts/testnet/local-osmosis-testnet-continue.sh @@ -1,8 +1,13 @@ #!/bin/bash + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +BINS_DIR=$SCRIPT_DIR/bins +PATH=$BINS_DIR:$PATH + set -e # always returns true so set -e doesn't exit if it is not running. killall osmosisd || true # start all three validators -tmux new -s osmosis1 -d osmosisd start --home=$HOME/.osmosisd/validator1 --rpc.laddr tcp://0.0.0.0:26657 \ No newline at end of file +tmux new -s osmosis1 -d osmosisd start --home="$HOME"/.osmosisd/validator1 --rpc.laddr tcp://0.0.0.0:26657 diff --git a/scripts/testnet/local-osmosis-testnet-new.sh b/scripts/testnet/local-osmosis-testnet-new.sh index 4d1ae7b9..dc11b7aa 100755 --- a/scripts/testnet/local-osmosis-testnet-new.sh +++ b/scripts/testnet/local-osmosis-testnet-new.sh @@ -1,35 +1,41 @@ #!/bin/bash + set -e +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +BINS_DIR=$SCRIPT_DIR/bins +PATH=$BINS_DIR:$PATH + # always returns true so set -e doesn't exit if it is not running. killall osmosisd || true # make four osmosis directories -mkdir -p $HOME/.osmosisd -mkdir $HOME/.osmosisd/validator1 +mkdir -p "$HOME"/.osmosisd +mkdir "$HOME"/.osmosisd/validator1 # init validator -osmosisd init --chain-id=osmosis-dev-1 validator1 --home=$HOME/.osmosisd/validator1 -osmosisd keys add validator1 --keyring-backend=test --home=$HOME/.osmosisd/validator1 +osmosisd init --chain-id=osmosis-dev-1 validator1 --home="$HOME"/.osmosisd/validator1 +osmosisd keys add validator1 --keyring-backend=test --home="$HOME"/.osmosisd/validator1 -update_genesis () { - cat $HOME/.osmosisd/validator1/config/genesis.json | jq "$1" > $HOME/.osmosisd/validator1/config/tmp_genesis.json && mv $HOME/.osmosisd/validator1/config/tmp_genesis.json $HOME/.osmosisd/validator1/config/genesis.json +update_genesis() { + cat "$HOME"/.osmosisd/validator1/config/genesis.json | jq "$1" >"$HOME"/.osmosisd/validator1/config/tmp_genesis.json && mv "$HOME"/.osmosisd/validator1/config/tmp_genesis.json "$HOME"/.osmosisd/validator1/config/genesis.json } # change staking denom to uosmo update_genesis '.app_state["staking"]["params"]["bond_denom"]="uosmo"' -sed -i -E 's|tcp://127.0.0.1:26657|tcp://0.0.0.0:26657|g' $HOME/.osmosisd/validator1/config/config.toml +sed -i -E 's|tcp://127.0.0.1:26657|tcp://0.0.0.0:26657|g' "$HOME"/.osmosisd/validator1/config/config.toml # create validator node with tokens -osmosisd add-genesis-account $(osmosisd keys show validator1 -a --keyring-backend=test --home=$HOME/.osmosisd/validator1) 100000000000uosmo,100000000000stake --home=$HOME/.osmosisd/validator1 -osmosisd gentx validator1 500000000uosmo --keyring-backend=test --home=$HOME/.osmosisd/validator1 --chain-id=osmosis-dev-1 -osmosisd collect-gentxs --home=$HOME/.osmosisd/validator1 +osmosisd add-genesis-account "$(osmosisd keys show validator1 -a --keyring-backend=test --home="$HOME"/.osmosisd/validator1)" \ + 100000000000000uosmo,100000000000000stake --home="$HOME"/.osmosisd/validator1 +osmosisd gentx validator1 500000000uosmo --keyring-backend=test --home="$HOME"/.osmosisd/validator1 --chain-id=osmosis-dev-1 +osmosisd collect-gentxs --home="$HOME"/.osmosisd/validator1 # change config.toml values -sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $HOME/.osmosisd/validator1/config/config.toml +sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' "$HOME"/.osmosisd/validator1/config/config.toml -tmux new -s osmosis1 -d osmosisd start --home=$HOME/.osmosisd/validator1 +tmux new -s osmosis1 -d osmosisd start --home="$HOME"/.osmosisd/validator1 sh ./check-node-running.sh osmosis1 -echo "Osmosis validator is up and running!" \ No newline at end of file +echo "Osmosis validator is up and running!" diff --git a/scripts/testnet/migrate_stake_contract.sh b/scripts/testnet/migrate_stake_contract.sh deleted file mode 100644 index 5986deac..00000000 --- a/scripts/testnet/migrate_stake_contract.sh +++ /dev/null @@ -1,9 +0,0 @@ -CODE_ID=$(osmosisd query wasm list-code --output json | jq -r '.code_infos[-1].code_id') -CONTRACT=$(osmosisd query wasm list-contract-by-code $CODE_ID --output json | jq -r '.contracts[-1]') -RES=$(osmosisd tx wasm store ./artifacts/staking-aarch64.wasm --from test_master --keyring-backend test --output json -y -b block --gas-prices 0.025stake --gas-adjustment 1.7 --gas auto --chain-id osmosis-dev-1) -CODE_ID=$(echo $RES | jq -r '.logs[0].events[-1].attributes[-1].value') -osmosisd tx wasm migrate $CONTRACT $CODE_ID '{}' \ - --from test_master -y \ - -b block --keyring-backend test \ - --gas-prices 0.025stake --gas-adjustment 1.7 --gas auto \ - --chain-id osmosis-dev-1 diff --git a/scripts/testnet/params.sh b/scripts/testnet/params.sh new file mode 100644 index 00000000..4662f867 --- /dev/null +++ b/scripts/testnet/params.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# Osmosis config +OSMOSIS_NODE="http://localhost:26657" +OSMOSIS_CHAIN_ID="osmosis-dev-1" +OSMOSIS_GAS_PRICE="0.025stake" +OSMOSIS_GAS_ADJUSTMENT="1.7" +OSMOSIS_TX_PARAMS="--keyring-backend test --node $OSMOSIS_NODE --chain-id $OSMOSIS_CHAIN_ID --gas-prices $OSMOSIS_GAS_PRICE --gas-adjustment $OSMOSIS_GAS_ADJUSTMENT --gas auto -y" + +# Celestia config +CELESTIA_NODE="http://localhost:26661" +CELESTIA_CHAIN_ID="celestia-dev-1" +CELESTIA_TX_PARAMS="--keyring-backend test --node $CELESTIA_NODE --chain-id $CELESTIA_CHAIN_ID --fees 21000utia -y" + +# Accounts info +# Mnemonic used to generate accounts +TESTNET_MNEMONIC="boy view flame close solar robust crunch slot govern false jungle dirt blade minor shield bounce rent expand anxiety busy pull inject grace require" + +# Osmosis accounts +OSMOSIS_ACCOUNT="osmo1sfhy3emrgp26wnzuu64p06kpkxd9phel8ym0ge" +OSMOSIS_TRADER="osmo1lh0u9sug6qh922gjpal3frwtacaums4s7lkyl9" +OSMOSIS_TRADER_ACCOUNT_INDEX=1 + +# Celestia accounts +CELESTIA_STAKER="celestia1sfhy3emrgp26wnzuu64p06kpkxd9phel74e0yx" +CELESTIA_STAKER_ACCOUNT_INDEX=0 +CELESTIA_GRANTEE="celestia1lh0u9sug6qh922gjpal3frwtacaums4s8w5yn6" +CELESTIA_GRANTEE_ACCOUNT_INDEX=1 +CELESTIA_REWARDS_COLLECTOR="celestia12rzczckgh8fqq533t0xqhqrrzdk76du3dxrx9q" +CELESTIA_REWARDS_COLLECTOR_ACCOUNT_INDEX=2 diff --git a/scripts/testnet/tia-osmo-pool.sh b/scripts/testnet/tia-osmo-pool.sh old mode 100644 new mode 100755 index 1a9e7a7c..d065dbd9 --- a/scripts/testnet/tia-osmo-pool.sh +++ b/scripts/testnet/tia-osmo-pool.sh @@ -1,31 +1,40 @@ +#!/bin/bash + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +BINS_DIR="$SCRIPT_DIR/bins" +PATH="$BINS_DIR:$PATH" + +source "$SCRIPT_DIR/params.sh" +source "$SCRIPT_DIR/utils/tx.sh" + # this create a tia osmo pool on osmosis testnet # send tia -OSMOSIS_VALIDATOR_1_ADDR=$(osmosisd keys show validator1 --address --keyring-backend=test --home=$HOME/.osmosisd/validator1) -celestia-appd tx ibc-transfer transfer transfer channel-0 --from validator1 --node http://localhost:26661 --chain-id celestia-dev-1 --fees 21000utia --output json -y $OSMOSIS_VALIDATOR_1_ADDR 10000000utia --broadcast-mode block --keyring-backend=test --home=$HOME/.celestia-app/validator1 +OSMOSIS_VALIDATOR_1_ADDR=$(osmosisd keys show validator1 --address --keyring-backend=test --home="$HOME/.osmosisd/validator1") +wait_tx celestia-appd tx ibc-transfer transfer transfer channel-0 "$OSMOSIS_VALIDATOR_1_ADDR" 10000000000000utia \ + --from validator1 --keyring-backend=test --home="$HOME"/.celestia-app/validator1 \ + "$CELESTIA_TX_PARAMS" # get tia ibc token name echo "waiting for tia to arrive" NATIVE_TOKEN_DENOM="" while [ -z "$NATIVE_TOKEN_DENOM" ]; do - BALANCES=$(osmosisd query bank balances $OSMOSIS_VALIDATOR_1_ADDR --output json) - echo $BALANCES - NATIVE_TOKEN_DENOM=$(echo $BALANCES | jq -r '.balances[].denom | select(. | contains("ibc/"))') - sleep 3 -done; + BALANCES=$(osmosisd query bank balances "$OSMOSIS_VALIDATOR_1_ADDR" --output json) + echo "$BALANCES" + NATIVE_TOKEN_DENOM=$(echo "$BALANCES" | jq -r '.balances[].denom | select(. | contains("ibc/"))') + sleep 3 +done echo '{ - "initial-deposit": "1000000uosmo,1000000ibc/C3E53D20BC7A4CC993B17C7971F8ECD06A433C10B6A96F4C4C3714F0624C56DA", + "initial-deposit": "10000000000000uosmo,10000000000000ibc/C3E53D20BC7A4CC993B17C7971F8ECD06A433C10B6A96F4C4C3714F0624C56DA", "swap-fee": "0.01", "exit-fee": "0", "weights": "10uosmo,1ibc/C3E53D20BC7A4CC993B17C7971F8ECD06A433C10B6A96F4C4C3714F0624C56DA" }' > pool.json -osmosisd tx gamm create-pool --pool-file ./pool.json \ - --from validator1 --keyring-backend=test --home=$HOME/.osmosisd/validator1 \ - -y -b block \ - --gas-prices 0.025stake --gas-adjustment 1.7 --gas auto \ - --chain-id osmosis-dev-1 +wait_tx osmosisd tx gamm create-pool --pool-file ./pool.json \ + --from validator1 --keyring-backend=test --home="$HOME"/.osmosisd/validator1 \ + "$OSMOSIS_TX_PARAMS" # add liquidity # osmosisd tx gamm join-pool --pool-id 1 --max-amounts-in 1000000$NATIVE_TOKEN_DENOM,1000000uosmo --share-amount-out 1000 --from test_master --keyring-backend test -y \ diff --git a/scripts/testnet/utils/configure-localnet.sh b/scripts/testnet/utils/configure-localnet.sh new file mode 100755 index 00000000..85c3bb96 --- /dev/null +++ b/scripts/testnet/utils/configure-localnet.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +# Include the binaries +PATH=$SCRIPT_DIR/../bins:$PATH +# Include the params +source "$SCRIPT_DIR/../params.sh" + +echo "Configuring osmosisd" +osmosisd config chain-id $OSMOSIS_CHAIN_ID +osmosisd config gas auto +osmosisd config gas-adjustment $OSMOSIS_GAS_ADJUSTMENT +osmosisd config gas-prices $OSMOSIS_GAS_PRICE +osmosisd config 'keyring-backend' test + +echo "Configuring celestia-appd" +celestia-appd config chain-id $CELESTIA_CHAIN_ID +celestia-appd config 'keyring-backend' test +celestia-appd config node $CELESTIA_NODE + +echo "Clients configured" diff --git a/scripts/testnet/utils/import-accounts-keys.sh b/scripts/testnet/utils/import-accounts-keys.sh new file mode 100755 index 00000000..f5f1b680 --- /dev/null +++ b/scripts/testnet/utils/import-accounts-keys.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +PATH=$SCRIPT_DIR/../bins:$PATH +source "$SCRIPT_DIR/../params.sh" + +echo "Adding accounts to test kyering" +echo "$TESTNET_MNEMONIC" +echo "$TESTNET_MNEMONIC" | osmosisd keys add test_master --recover --keyring-backend test +echo "$TESTNET_MNEMONIC" | osmosisd keys add trader --account $OSMOSIS_TRADER_ACCOUNT_INDEX --recover --keyring-backend test +echo "$TESTNET_MNEMONIC" | celestia-appd keys add staker --account $CELESTIA_STAKER_ACCOUNT_INDEX --recover --keyring-backend test +echo "$TESTNET_MNEMONIC" | celestia-appd keys add grantee --account $CELESTIA_GRANTEE_ACCOUNT_INDEX --recover --keyring-backend test +echo "$TESTNET_MNEMONIC" | celestia-appd keys add rewards_collector --account $CELESTIA_REWARDS_COLLECTOR_ACCOUNT_INDEX --recover --keyring-backend test diff --git a/scripts/testnet/utils/tx.sh b/scripts/testnet/utils/tx.sh new file mode 100755 index 00000000..6c37ff10 --- /dev/null +++ b/scripts/testnet/utils/tx.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +source "$SCRIPT_DIR/../params.sh" + +function wait_tx_included() { + # Get function parameters + local binary=$1 + local tx_hash=$2 + local node=$3 + + local count=0 + while [ $count -lt 30 ]; do + local output + output=$($binary q tx "$tx_hash" --node "$node" --output json 2>/dev/null || echo "failed") + if [ "$output" == "failed" ]; then + count=$((count+1)) + sleep 1 + else + local code= + code=$(echo "$output" | jq -r '.code') + if [ "$code" == "0" ]; then + break + else + echo "Tx $tx_hash failed" + echo "$output" | jq '.raw_log' + echo "" + echo "$output" + exit 1 + fi + fi + done +} + +function wait_osmossis_tx() { + local tx_hash=$1 + wait_tx_included osmosisd "$tx_hash" $OSMOSIS_NODE +} + +function wait_celestia_tx() { + local tx_hash=$1 + wait_tx_included celestia-appd "$tx_hash" $CELESTIA_NODE +} + +function wait_tx() { + local command=$* + # Extract the binary name + local bin="$1" + # Get the transaction hash + # of the command that has been provided + local tx_hash + tx_hash=$($command --output json | jq -r '.txhash') + + if [ "$bin" == "osmosisd" ]; then + wait_osmossis_tx "$tx_hash" + elif [ "$bin" == "celestia-appd" ]; then + wait_celestia_tx "$tx_hash" + else + echo "Can wait tx of $bin" + exit 1 + fi +}