Skip to content

Commit

Permalink
Merge pull request #93 from hadronlabs-org/feat/deployment-docs
Browse files Browse the repository at this point in the history
feat: deployment docs DRP-137
  • Loading branch information
oldremez authored Jun 28, 2024
2 parents 46138bc + 30e152b commit 5058d52
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 43 deletions.
2 changes: 0 additions & 2 deletions scripts/.env.instantiate.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ TARGET_CHAIN_ID="test-2"
TARGET_SDK_VERSION="0.47.10"
TARGET_BASE_DENOM="uatom"
NEUTRON_SIDE_TRANSFER_CHANNEL_ID="channel-788"
# TODO: query from chain. see README.md
IBC_REGISTER_FEE="1000000"
# 21 days
UNBONDING_PERIOD=1814400
# 1 hour
Expand Down
110 changes: 78 additions & 32 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,77 @@
## Configuration
# Deployment scripts

- Cosmos SDK version
This directory contains several scripts to assist in deployment of Drop protocol, `upload.bash` and `instantiate.bash`
are those you will need to run.

**TARGET_SDK_VERSION**. In order to configure factory you need to provide cosmos sdk version of the target network. You can obtain by performing following command on the network current binary:
| Script | Purpose |
|---------------------------|---------------------------------------------------------------------------------------------------------------------|
| **upload_contracts.bash** | Stores wasm code of all Drop contracts on Neutron chain |
| **instantiate.bash** | Creates instance of Drop protocol, waits until ICA addresses are registered and sets them in protocol configuration |
| utils.bash | Universal library used across deployment scripts. You don't need to execute it by yourself |
| migrate.bash | Simple script which migrates a single contract. Useful for development |

## upload_contracts.bash

### Prerequisities

Before running upload, it is crucial to execute `make build` in root directory of the project. This action ensures
uploaded contracts will correspond to commit hash you are currently on.

### Configuration

Copy `.env.upload.example` to `.env.upload`, then configure it according to this table:

| Parameter | Suggested testnet value | Suggested mainnet value | Description |
|---------------------|--------------------------------------------|-------------------------------------------|-------------------------------------------------------------------------------------------------------|
| `NEUTRON_RPC` | `https://rpc-falcron.pion-1.ntrn.tech:443` | `https://rpc.novel.remedy.tm.p2p.org:443` | Neutron public RPCs taken from chain registry |
| `GAS_PRICES` | `0.02` | `0.01` | In case if deployment is too slow and fails on tx timeout, try increasing this value |
| `NEUTRON_CHAIN_ID` | `pion-1` | `neutron-1` | |
| `NEUTRON_HOME` | | | Set it in case if your Neutron home path is different from default one |
| `KEYRING_BACKEND` | | | Set it to `test`, `os` or whatever backend is in use |
| `DEPLOY_WALLET` | | | Set it to name of the wallet you would like to deploy protocol from and then use it as protocol admin |
| `MIN_NTRN_REQUIRED` | `10` | `10` | Scripts check if you have enough funds before doing anything. Generally, better not touch this value |
| `ARTIFACTS_DIR` | `../artifacts` | `../artifacts` | Only change it in case if you have moved somewhere either scripts dir or contracts dir |

### Execution

```bash
export $(grep -v '^#' .env.upload | xargs) && ./upload_contracts.bash
```

After script is finished, please save its output, you will need it for `instantiate.bash`.

## instantiate.bash

### Configuration

Copy `.env.instantiate.example` to `.env.instantiate`, then configure it according to this table:

| Parameter | Suggested testnet value | Suggested mainnet value | Description |
|------------------------------------|--------------------------------------------|-------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
| `NEUTRON_RPC` | `https://rpc-falcron.pion-1.ntrn.tech:443` | `https://rpc.novel.remedy.tm.p2p.org:443` | Neutron public RPCs taken from chain registry |
| `GAS_PRICES` | `0.02` | `0.01` | In case if deployment is too slow and fails on tx timeout, try increasing this value |
| `NEUTRON_CHAIN_ID` | `pion-1` | `neutron-1` | |
| `NEUTRON_HOME` | | | Set it in case if your Neutron home path is different from default one |
| `TARGET_CHAIN_ID` | | | Chain ID of target network, could be obtained from chain registry |
| `KEYRING_BACKEND` | | | Set it to `test`, `os` or whatever backend is in use |
| `DEPLOY_WALLET` | | | Set it to name of the wallet you would like to deploy protocol from and then use it as protocol admin |
| `MIN_NTRN_REQUIRED` | `10` | `10` | Scripts check if you have enough funds before doing anything. Generally, better not touch this value |
| `TARGET_SDK_VERSION` | | | Cosmos SDK version of target chain, could be obtained from chain registry or from chain itself (refer to documentation below) |
| `TARGET_BASE_DENOM` | | | Denom to be staked with Drop protocol, e.g. "uatom" |
| `NEUTRON_SIDE_TRANSFER_CHANNEL_ID` | | | Neutron side channel ID associated with transfer port which is used for IBC transfer of target denom to and from Neutron |
| `UNBONDING_PERIOD` | | | Can be queried from target chain using `targetd query staking params`, it will be returned as `unbonding_time` |
| `UNBONDING_SAFE_PERIOD` | `3600` | `3600` | Time period before unbonding ends during which we don't initiate any operations just to be safe. One hour is a good default |
| `UNBOND_BATCH_SWITCH_TIME` | | | Divide `UNBONDING_PERIOD` by 7 |
| `PUPPETEER_TIMEOUT` | `1209600` | `1209600` | 14 days is a good default |
| `STAKER_TIMEOUT` | `1209600` | `1209600` | 14 days is a good default |
| `ARTIFACTS_DIR` | `../artifacts` | `../artifacts` | Only change it in case if you have moved somewhere either scripts dir or contracts dir |
| `INITIAL_VALIDATORS` | | | Set it to validators to stake to, format is as follows: `[{"valoper_address":"cosmosvaloper1...","weight":"10"},...]` |
| `*_code_id` | | | Set it to code ID taken from output of upload.bash |

#### Cosmos SDK version

**TARGET_SDK_VERSION**. In order to configure factory you need to provide cosmos sdk version of the target network. You
can obtain by performing following command on the network current binary:

```
$ gaiad version --long | grep "cosmos_sdk_version"
Expand All @@ -18,37 +87,14 @@ curl -s -X 'GET' \
-H 'accept: application/json' | jq -r '.application_version.cosmos_sdk_version'
```
- Interchain account registration fee

**IBC_REGISTER_FEE**. Can be queried from `interhaintxs` parameters, using latest binary:

```
$ neutrond query interchaintxs params --node https://rpc-falcron.pion-1.ntrn.tech:443 -o json | jq '.params.register_fee'
[
{
"denom": "untrn",
"amount": "100000"
}
]
```

or using REST service
### Execution

```bash
export $(grep -v '^#' .env.instantiate | xargs) && ./instantiate.bash
```
$ curl -s -X 'GET' \
'https://rest-falcron.pion-1.ntrn.tech/neutron/interchaintxs/params' \
-H 'accept: application/json' | jq '.params.register_fee'
[
{
"denom": "untrn",
"amount": "1000000"
}
]
```

## Running

Export required variables and run script `export $(grep -v '^#' .env.upload.example | xargs) && ./upload_contracts.bash`
During execution the script will print hermes commands. In case if it gets stuck, you will have to execute these hermes
commands manually until ICA account is registered.

After script is finished, write down its output, you will need it to configure frontend, monitoring and hermes.
2 changes: 1 addition & 1 deletion scripts/instantiate.bash
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ MIN_NTRN_REQUIRED="${MIN_NTRN_REQUIRED:-10}"
TARGET_SDK_VERSION="${TARGET_SDK_VERSION:-0.47.10}"
TARGET_BASE_DENOM="${TARGET_BASE_DENOM:-uatom}"
NEUTRON_SIDE_TRANSFER_CHANNEL_ID="${NEUTRON_SIDE_TRANSFER_CHANNEL_ID:-channel-788}"
IBC_REGISTER_FEE="${IBC_REGISTER_FEE:-1000000}"
INITIAL_VALIDATORS="${INITIAL_VALIDATORS:-[]}"
UNBONDING_PERIOD="${UNBONDING_PERIOD:-1814400}"
UNBONDING_SAFE_PERIOD="${UNBONDING_SAFE_PERIOD:-3600}"
Expand All @@ -24,6 +23,7 @@ source ./utils.bash

echo "DEPLOY_WALLET: $DEPLOY_WALLET"
echo "NEUTRON_RPC: $NEUTRON_RPC"
echo "NEUTRON_HOME: $NEUTRON_HOME"


main() {
Expand Down
1 change: 1 addition & 0 deletions scripts/upload_contracts.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ source ./utils.bash

echo "DEPLOY_WALLET: $DEPLOY_WALLET"
echo "NEUTRON_RPC: $NEUTRON_RPC"
echo "NEUTRON_HOME: $NEUTRON_HOME"


main() {
Expand Down
20 changes: 12 additions & 8 deletions scripts/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ deploy_factory() {
"base_denom":"'"$uatom_on_neutron_denom"'",
"core_params":{
"idle_min_interval":60,
"unbond_batch_switch_time":'$UNBOND_BATCH_SWITCH_TIME',
"unbonding_safe_period":'$UNBONDING_SAFE_PERIOD',
"unbonding_period":'$UNBONDING_PERIOD',
"unbond_batch_switch_time":'"$UNBOND_BATCH_SWITCH_TIME"',
"unbonding_safe_period":'"$UNBONDING_SAFE_PERIOD"',
"unbonding_period":'"$UNBONDING_PERIOD"',
"lsm_redeem_threshold":2,
"lsm_min_bond_amount":"1",
"lsm_redeem_max_interval":60000,
Expand All @@ -179,10 +179,10 @@ deploy_factory() {
"staker_params":{
"min_stake_amount":"10000",
"min_ibc_transfer":"10000",
"timeout":'$STAKER_TIMEOUT'
"timeout":'"$STAKER_TIMEOUT"'
},
"puppeteer_params":{
"timeout":'$PUPPETEER_TIMEOUT'
"timeout":'"$PUPPETEER_TIMEOUT"'
}
}'
factory_address="$(neutrond tx wasm instantiate "$factory_code_id" "$msg" \
Expand All @@ -202,25 +202,29 @@ deploy_factory() {
echo "[OK] Withdrawal manager contract: $withdrawal_manager_address"
}

get_ibc_register_fee() {
neutrond query interchaintxs params "${nq[@]}" | jq -r '.params.register_fee[] | select(.denom=="untrn") | .amount'
}

register_staker_ica() {
register_ica_result="$(neutrond tx wasm execute "$staker_address" '{"register_i_c_a":{}}' \
--amount "${IBC_REGISTER_FEE}untrn" --from "$DEPLOY_WALLET" "${ntx[@]}" | wait_ntx)"
--amount "$(get_ibc_register_fee)untrn" --from "$DEPLOY_WALLET" "${ntx[@]}" | wait_ntx)"
staker_ica_port="$(echo "$register_ica_result" | jq -r "$(select_attr "channel_open_init" "port_id")")"
staker_ica_channel="$(echo "$register_ica_result" | jq -r "$(select_attr "channel_open_init" "channel_id")")"
echo "[OK] Staker ICA configuration: $staker_ica_port/$staker_ica_channel"
}

register_puppeteer_ica() {
register_ica_result="$(neutrond tx wasm execute "$puppeteer_address" '{"register_i_c_a":{}}' \
--amount "${IBC_REGISTER_FEE}untrn" --from "$DEPLOY_WALLET" "${ntx[@]}" | wait_ntx)"
--amount "$(get_ibc_register_fee)untrn" --from "$DEPLOY_WALLET" "${ntx[@]}" | wait_ntx)"
puppeteer_ica_port="$(echo "$register_ica_result" | jq -r "$(select_attr "channel_open_init" "port_id")")"
puppeteer_ica_channel="$(echo "$register_ica_result" | jq -r "$(select_attr "channel_open_init" "channel_id")")"
echo "[OK] Puppeteer ICA configuration: $puppeteer_ica_port/$puppeteer_ica_channel"
}

register_pump_ica() {
register_ica_result="$(neutrond tx wasm execute "$pump_address" '{"register_i_c_a":{}}' \
--amount "${IBC_REGISTER_FEE}untrn" --from "$DEPLOY_WALLET" "${ntx[@]}" | wait_ntx)"
--amount "$(get_ibc_register_fee)untrn" --from "$DEPLOY_WALLET" "${ntx[@]}" | wait_ntx)"
pump_ica_port="$(echo "$register_ica_result" | jq -r "$(select_attr "channel_open_init" "port_id")")"
pump_ica_channel="$(echo "$register_ica_result" | jq -r "$(select_attr "channel_open_init" "channel_id")")"
echo "[OK] Pump ICA configuration: $pump_ica_port/$pump_ica_channel"
Expand Down

0 comments on commit 5058d52

Please sign in to comment.