Skip to content

Commit

Permalink
refactor(scripts): Network setup process update
Browse files Browse the repository at this point in the history
  • Loading branch information
desislavva committed Jan 8, 2024
1 parent 2d40af1 commit 8816673
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 348 deletions.
90 changes: 17 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,126 +29,70 @@ Install [golang](https://golang.org/), [tomlq](https://tomlq.readthedocs.io/en/l

The command will compile and install nolusd locally on your machine.

#### Initialize, set up the DEX parameters and run
#### Initialize, set up and run

`init-local-network.sh` generates a network setup, including setting up the initial DEX. The Hermes relayer is used to connect to the DEXes, and its configuration is also handled by the script.
`init-local-network.sh` generates a network setup, including the deployment of platform contracts (only) and initial Hermes setup (Nolus chain configuration).

First, generate the mnemonic you will use for Hermes:

```sh
nolusd keys mnemonic
```

Then recover it on the DEX (the network binary is required) and use a faucet to obtain some amount:

Example for the Osmosis DEX ([Osmo-test-5 faucet](https://faucet.osmotest5.osmosis.zone/)):

```sh
osmosisd keys add hermes_key --recover
```

Initialize and start (run `./scripts/init-local-network.sh --help` for additional configuration options):

```sh
./scripts/init-local-network.sh --reserve-tokens <reserve_account_init_tokens> --hermes-mnemonic <the_mnemonic_generated_by_the_previous_steps> --dex-network-addr-rpc-host <dex_network_addr_rpc_host_part> --dex-network-addr-grpc-host <dex_network_addr_grpc_host_part> --dex-admin-mnemonic <mnemonic_phrase> --store-code-privileged-account-mnemonic <mnemonic_phrase>
./scripts/init-local-network.sh --reserve-tokens <reserve_account_init_tokens> --hermes-mnemonic <the_mnemonic_generated_by_the_previous_steps> --dex-admin-mnemonic <mnemonic_phrase> --store-code-privileged-account-mnemonic <mnemonic_phrase>
```

Set up the DEX parameters: [Set up the DEX parameters manually](#set-up-the-dex-parameters-manually)

*Notes:

* Make sure the `nolus-money-market` repository is checked out as a sibling to this one.

* !!! Before running the `./scripts/init-local-network.sh` again, make sure the `nolusd` and `hermes` processes are killed.

* The `hermes` and `nolusd` logs are stored in `~/hermes` and `~/.nolus` respectively.
* The nolusd logs are stored in `~/.nolus`.

### Run an already configured single-node

```sh
nolusd start --home "networks/nolus/local-validator-1"
```

## Set up the DEX parameters manually

The goal is to let smart contracts know the details of the connectivity to the selected DEX. Herebelow is a sample request for setting up the DEX.
This should be done via sudo gov proposal. You can generate the proposal file with `nolusd tx gov submit-proposal draft-proposal`.
Here's an example .json file for sudo-contract proposal:

```json
{
"messages": [
{
"@type": "/cosmwasm.wasm.v1.MsgSudoContract",
"authority": "nolus10d07y265gmmuvt4z0w9aw880jnsr700jvjr65k",
"contract": "nolus1wn625s4jcmvk0szpl85rj5azkfc6suyvf75q6vrddscjdphtve8s5gg42f",
"msg": {"setup_dex": {"connection_id": "connection-0", "transfer_channel": {"local_endpoint": "channel-0", "remote_endpoint": "channel-1499"}}}
}
],
"deposit": "10000000unls",
"title": "Set up the DEX parameter",
"summary": "Thе proposal aims to set the DEX parameters in the Leaser contract"
}
```

```sh
nolusd tx gov submit-proposal filename.json --fees 900unls --gas auto --gas-adjustment 1.1 --from wallet
```

Check if the transaction has passed:

```sh
nolusd q wasm contract-state smart nolus1wn625s4jcmvk0szpl85rj5azkfc6suyvf75q6vrddscjdphtve8s5gg42f '{"config":{}}'
```

*Notes:
## Set up a new DEX

* `*nolus1wn625s4jcmvk0szpl85rj5azkfc6suyvf75q6vrddscjdphtve8s5gg42f*` is the Leaser contract instance associated with the first DEX already configured on the network at genesis time /by default this is Osmosis/. Each DEX is associated with a separate instance.
On a live network, a new DEX can be deployed using the following steps.

* `*connection-0*` is the connection to the first DEX already configured on the network /by default this is Osmosis/. Should be replaced with the connection to the selected DEX.
### Manual step - Prerequisites

* `*channel-0*` refers to the first DEX already configured on the network /by default this is Osmosis/. Should be replaced with the channel to the selected DEX.
* provide a certain amount for the Hermes account (DEX side)

* `*channel-1499*` should be replaced, so you can get the actual channel ID of the remote endpoint with:
Recover your Hermes wallet on the DEX network and use a faucet to obtain some amount.

```sh
nolusd q ibc channel connections <connection> --output json | jq '.channels[0].counterparty.channel_id' | tr -d '"'
```
Example for the Osmosis DEX ([Osmo-test-5 faucet](https://faucet.osmotest5.osmosis.zone/)):

## Set up a new DEX
```sh
osmosisd keys add hermes_key --recover
```

On a live network, a new DEX can be deployed using the following steps.
* start hermes

### Аutomated step

```sh
./scripts/add-new-dex.sh --dex-admin-key <dex_admin_key> --store-code-privileged-user-key <store_code_privileged_user_key> --dex-name <dex_name> --dex-chain-id <new_dex_chain_id> --wasm-artifacts-path <wasm_artifacts_dir_path> --dex-ip-addr-rpc-host <new_dex_ip_addr_rpc_host_part> --dex-ip-addr-grpc-host <new_dex_ip_addr_grpc_host_part> --dex-account-prefix <new_dex_account_prefix> --dex-price-denom <new_dex_price_denom> --dex-trusting-period-secs <new_dex_trusting_period_in_seconds> --protocol-currency <new_protocol_currency> --protocol-swap-tree <new_protocol_swap_tree>
./scripts/add-new-dex.sh --dex-admin-key <dex_admin_key> --store-code-privileged-user-key <store_code_privileged_user_key> --wasm-artifacts-path <wasm_artifacts_dir_path> --dex-name <dex_name> --dex-chain-id <new_dex_chain_id> --dex-ip-addr-rpc-host <new_dex_ip_addr_rpc_host_part> --dex-ip-addr-grpc-host <new_dex_ip_addr_grpc_host_part> --dex-account-prefix <new_dex_account_prefix> --dex-price-denom <new_dex_price_denom> --dex-trusting-period-secs <new_dex_trusting_period_in_seconds> --dex-if-interchain-security <if_interchain_security_true/false> --protocol-currency <new_protocol_currency> --protocol-swap-tree <new_protocol_swap_tree>
```

The script takes care of setting up Hermes to work with the new DEX and deploying DEX-specific contracts (More about deploying contracts on a live network can be found [here](https://github.com/nolus-protocol/nolus-money-market)).
The script takes care of setting up Hermes to work with the new DEX and, for now, deploying DEX-specific contracts (More about deploying contracts on a live network can be found [here](https://github.com/nolus-protocol/nolus-money-market)).

*Notes:

* Execute `./scripts/add-new-dex.sh --help` for additional configuration options)
* Execute `./scripts/add-new-dex.sh --help` for additional configuration options

* The `protocol-swap-tree` must be passed in single quotes (for example: **--protocol-swap-tree '{"value":[0,"USDC"],"children":[{"value":[5,"OSMO"],"children":[{"value":[12,"ATOM"]}]}]}'**)

* The script will locate the Hermes account from the Hermes configuration directory and link it to the new DEX

* !!! Prerequisites: Before running, the address should have a certain amount on the DEX network in order to be used by Hermes. This can be accomplished by using the DEX network binary and a public faucet, as demonstrated for Osmosis [here](#initialize-set-up-the-dex-parameters-and-run)

### Manual step

Get the new DEX-specific Leaser address: (TO DO: update)

```sh
nolusd q wasm cs all <admin_contract_address>
```

Configure it with the new DEX-specific connection:

Follow the instructions [here](#set-up-the-dex-parameters-manually) bearing in mind the `Notes`.

## Build a statically linked binary

By default, `make build` generates a dynamically linked binary. In case someone would like to reproduce the way the binary is built in the pipeline then the command to achieve it locally is:
Expand Down
34 changes: 25 additions & 9 deletions scripts/add-new-dex.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ WASM_ARTIFACTS_PATH=""

HERMES_CONFIG_DIR_PATH="$HOME/.hermes"
HERMES_BINARY_DIR_PATH="$HOME/hermes"
DEX_NETWORK=""
DEX_NAME=""
CHAIN_ID=""
CHAIN_IP_ADDR_RPC=""
Expand All @@ -28,9 +29,9 @@ CHAIN_TRUSTING_PERIOD=""
IF_INTERCHAIN_SECURITY="true"

PROTOCOL_CURRENCY=""
ADMIN_CONTRACT_ADDRESS="nolus1gurgpv8savnfw66lckwzn4zk7fp394lpe667dhu7aw48u40lj6jsqxf8nd"
TRASURY_CONTRACT_ADDRESS="nolus14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s0k0puz"
TIMEALARMS_CONTRACT_ADDRESS="nolus1zwv6feuzhy6a9wekh96cd57lsarmqlwxdypdsplw6zhfncqw6ftqmx7chl"
ADMIN_CONTRACT_ADDRESS="nolus1ghd753shjuwexxywmgs4xz7x2q732vcnkm6h2pyv9s6ah3hylvrq8welhp"
TREASURY_CONTRACT_ADDRESS="nolus14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s0k0puz"
TIMEALARMS_CONTRACT_ADDRESS="nolus1nc5tatafv6eyq7llkr2gv50ff9e22mnf70qgjlv737ktmt4eswrqrr2r7y"
SWAP_TREE=""

while [[ $# -gt 0 ]]; do
Expand All @@ -49,6 +50,7 @@ while [[ $# -gt 0 ]]; do
[--wasm-artifacts-path <wasm_artifacts_path>]
[--hermes-config-dir-path <config.toml_and_hermes.seed_dir_path>]
[--hermes-binary-dir-path <hermes_binary_dir_path>]
[--dex-network <dex_network>]
[--dex-name <dex_name>]
[--dex-chain-id <new_dex_chain_id>]
[--dex-ip-addr-rpc-host <new_dex_chain_ip_addr_rpc_fully_host>]
Expand Down Expand Up @@ -114,6 +116,12 @@ while [[ $# -gt 0 ]]; do
shift
;;

--dex-network)
DEX_NETWORK="$2"
shift
shift
;;

--dex-name)
DEX_NAME="$2"
shift
Expand Down Expand Up @@ -175,7 +183,7 @@ while [[ $# -gt 0 ]]; do
;;

--treasury-contract-address)
TRASURY_CONTRACT_ADDRESS="$2"
TREASURY_CONTRACT_ADDRESS="$2"
shift
shift
;;
Expand All @@ -202,18 +210,19 @@ done

NOLUS_CHAIN_ID=$(grep -oP 'chain-id = "\K[^"]+' "$NOLUS_HOME_DIR"/config/client.toml)

verify_dir_exist "$NOLUS_MONEY_MARKET_DIR" "The NOLUS_MONEY_MARKET_DIR dir does not exist"
verify_dir_exist "$NOLUS_MONEY_MARKET_DIR" "The NOLUS_MONEY_MARKET dir does not exist"
DEPLOY_CONTRACTS_SCRIPT="$NOLUS_MONEY_MARKET_DIR/scripts/deploy-contracts-live.sh"

verify_dir_exist "$WASM_ARTIFACTS_PATH" "The WASM_ARTIFACTS_PATH dir does not exist"
verify_mandatory "$DEX_NAME" "new DEX name"
verify_mandatory "$DEX_ADMIN_KEY" "dex-admin key name"
verify_mandatory "$STORE_CODE_PRIVILEGED_USER_KEY" "sotre-code privileged user key"
verify_mandatory "$DEX_NETWORK" "new DEX network"
verify_mandatory "$CHAIN_ID" "new DEX chain_id"
verify_mandatory "$CHAIN_IP_ADDR_RPC" "new DEX RPC addr - fully host part"
verify_mandatory "$CHAIN_IP_ADDR_GRPC" "new DEX gRPC addr - fully host part"
verify_mandatory "$CHAIN_ACCOUNT_PREFIX" "new DEX account prefix"
verify_mandatory "$CHAIN_PRICE_DENOM" "new DEX price denom"
verify_mandatory "$CHAIN_PRICE_DENOM" "new DEX price denom"
verify_mandatory "$CHAIN_TRUSTING_PERIOD" "new DEX trusting period"
verify_mandatory "$PROTOCOL_CURRENCY" "new protocol currency"
verify_mandatory "$SWAP_TREE" "new protocol swap_tree"
Expand All @@ -235,11 +244,18 @@ dex_account_setup "$HERMES_BINARY_DIR_PATH" "$CHAIN_ID" "$HERMES_CONFIG_DIR_PATH

NOLUS_HERMES_ADDRESS=$(get_hermes_address "$HERMES_BINARY_DIR_PATH" "$NOLUS_CHAIN_ID")

# Open a connection
# Open a connection (exports CONNECTION_ID)
open_connection "$NOLUS_NET" "$NOLUS_HOME_DIR" "$ACCOUNT_KEY_TO_FEED_HERMES_ADDRESS" "$HERMES_BINARY_DIR_PATH" \
"$NOLUS_HERMES_ADDRESS" "$NOLUS_CHAIN_ID" "$CHAIN_ID"

DEX_CONNECTION_ID="$CONNECTION_ID"

CONNECTION_INFO=$(get_connection_info "$NOLUS_HOME_DIR" "$DEX_CONNECTION_ID")
DEX_CHANNEL_LOCAL=$(echo "$CONNECTION_INFO" | jq -r '.channels[0].channel_id')
DEX_CHANNEL_REMOTE=$(echo "$CONNECTION_INFO" | jq -r '.channels[0].counterparty.channel_id')

# TO DO - Remove and run manually
# Deploy contracts
_=$(deploy_contracts "$NOLUS_NET" "$NOLUS_CHAIN_ID" "$NOLUS_HOME_DIR" "$DEX_ADMIN_KEY" "$STORE_CODE_PRIVILEGED_USER_KEY" \
"$ADMIN_CONTRACT_ADDRESS" "$WASM_ARTIFACTS_PATH/$DEX_NAME" "$DEX_NAME" "$PROTOCOL_CURRENCY" \
"$TRASURY_CONTRACT_ADDRESS" "$TIMEALARMS_CONTRACT_ADDRESS" "$SWAP_TREE")
"$ADMIN_CONTRACT_ADDRESS" "$WASM_ARTIFACTS_PATH/$DEX_NAME" "$DEX_NETWORK" "$DEX_NAME" "$DEX_CONNECTION_ID" "$DEX_CHANNEL_LOCAL" "$DEX_CHANNEL_REMOTE" "$PROTOCOL_CURRENCY" \
"$TREASURY_CONTRACT_ADDRESS" "$TIMEALARMS_CONTRACT_ADDRESS" "$SWAP_TREE")
33 changes: 3 additions & 30 deletions scripts/genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@ __print_usage() {
[--validator-accounts-dir <validator_accounts_dir>]
[--validator-tokens <validators_initial_tokens>]
[--validator-stake <tokens_validator_stakes>]
[--lpp-native <lpp_native>]
[--gov-voting-period <voting_period>]
[--feerefunder-ack-fee-min <feerefunder_ack_fee_min_amount>]
[--feerefunder-timeout-fee-min <feerefunder_timeout_fee_min_amount>]
[--dex-admin-mnemonic <dex_admin_account_mnemonic>]
[--store-code-privileged-account-mnemonic <store_code_privileged_account_mnemonic>]
[--dex-name <dex_name>]
[--dex-swap-tree <dex_specific_swap_tree]
[-o|--output <genesis_file_path>]" \
"$1"
}
Expand All @@ -49,14 +46,11 @@ VAL_ACCOUNTS_DIR="val-accounts"
VAL_TOKENS="1000000000""$NATIVE_CURRENCY"
VAL_STAKE="1000000""$NATIVE_CURRENCY"
OUTPUT_FILE=""
LPP_NATIVE="USDC"
CONTRACTS_INFO_FILE="contracts-info.json"
GOV_VOTING_PERIOD="43200s"
FEEREFUNDER_ACK_FEE_MIN="1"
FEEREFUNDER_TIMEOUT_FEE_MIN="1"
DEX_ADMIN_MNEMONIC=""
STORE_CODE_PRIVILEGED_ACCOUNT_MNEMONIC=""
DEX_NAME="osmosis"
ADMINS_TOKENS="10000000""$NATIVE_CURRENCY"

if [[ $# -lt 1 ]]; then
Expand Down Expand Up @@ -137,12 +131,6 @@ while [[ $# -gt 0 ]]; do
shift
;;

--lpp-native)
LPP_NATIVE="$2"
shift
shift
;;

--gov-voting-period)
GOV_VOTING_PERIOD="$2"
shift
Expand Down Expand Up @@ -173,18 +161,6 @@ while [[ $# -gt 0 ]]; do
shift
;;

--dex-name)
DEX_NAME="$2"
shift
shift
;;

--dex-swap-tree)
DEX_SWAP_TREE="$2"
shift
shift
;;

-o | --output)
OUTPUT_FILE="$2"
shift
Expand All @@ -199,27 +175,24 @@ while [[ $# -gt 0 ]]; do
esac
done

DEX_SWAP_TREE='{"value":[0,"'"$LPP_NATIVE"'"],"children":[{"value":[5,"OSMO"],"children":[{"value":[12,"ATOM"]}]}]}'

if [[ "$COMMAND" == "$COMMAND_FULL_GEN" ]]; then
verify_mandatory "$CHAIN_ID" "Nolus chain identifier"
verify_mandatory "$ACCOUNTS_SPEC" "Nolus genesis accounts spec"
verify_mandatory "$WASM_SCRIPT_PATH" "Wasm script path"
verify_mandatory "$WASM_CODE_PATH" "Wasm code path"
verify_mandatory "$TREASURY_INIT_TOKENS_U128" "Treasury init tokens"
verify_mandatory "$VAL_NODE_URLS_AND_VAL_PUBKEYS" "Validator URLs and validator public keys spec"
verify_mandatory "$LPP_NATIVE" "Lpp native currency symbol"
verify_mandatory "$OUTPUT_FILE" "Genesis output file"
verify_mandatory "$DEX_ADMIN_MNEMONIC" "DEX-admin account mnemonic"
verify_mandatory "$STORE_CODE_PRIVILEGED_ACCOUNT_MNEMONIC" "WASM store-code privileged account mnemonic"

genesis_file=$(generate_genesis "$CHAIN_ID" "$NATIVE_CURRENCY" "$VAL_TOKENS" "$VAL_STAKE" \
"$VAL_ACCOUNTS_DIR" "$ACCOUNTS_SPEC" "$WASM_SCRIPT_PATH" \
"$WASM_CODE_PATH" "$TREASURY_INIT_TOKENS_U128" \
"$VAL_NODE_URLS_AND_VAL_PUBKEYS" "$LPP_NATIVE" \
"$CONTRACTS_INFO_FILE" "$GOV_VOTING_PERIOD" \
"$VAL_NODE_URLS_AND_VAL_PUBKEYS" "$GOV_VOTING_PERIOD" \
"$FEEREFUNDER_ACK_FEE_MIN" "$FEEREFUNDER_TIMEOUT_FEE_MIN" \
"$DEX_ADMIN_MNEMONIC" "$STORE_CODE_PRIVILEGED_ACCOUNT_MNEMONIC" "$ADMINS_TOKENS" "$DEX_NAME" "$DEX_SWAP_TREE")
"$DEX_ADMIN_MNEMONIC" "$STORE_CODE_PRIVILEGED_ACCOUNT_MNEMONIC" \
"$ADMINS_TOKENS")
mv "$genesis_file" "$OUTPUT_FILE"
# elif [[ "$COMMAND" == "$COMMAND_SETUP" ]]; then
#
Expand Down
Loading

0 comments on commit 8816673

Please sign in to comment.