Skip to content

Commit

Permalink
feat(scripts): Deploy platform to live network
Browse files Browse the repository at this point in the history
  • Loading branch information
desislavva authored and Lockwarr committed Oct 15, 2024
1 parent 5d0d8ab commit 4df15d5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 66 deletions.
15 changes: 3 additions & 12 deletions scripts/genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ __print_usage() {
[--currency <native_currency>]
[--accounts <accounts_spec_json>]
[--wasm-script-path <wasm_script_path>]
[--wasm-code-path <wasm_code_path>]
[--treasury-nls-u128 <init treasury amount of uNLS>
[--validator-node-urls-pubkeys <validator_node_urls_and_validator_pubkeys>]
[--validator-accounts-dir <validator_accounts_dir>]
Expand All @@ -42,7 +41,6 @@ CHAIN_ID=""
NATIVE_CURRENCY="unls"
ACCOUNTS_SPEC=""
WASM_SCRIPT_PATH=""
WASM_CODE_PATH=""
TREASURY_INIT_TOKENS_U128=""
VAL_NODE_URLS_AND_VAL_PUBKEYS=""
VAL_ACCOUNTS_DIR="val-accounts"
Expand Down Expand Up @@ -101,12 +99,6 @@ while [[ $# -gt 0 ]]; do
shift
;;

--wasm-code-path)
WASM_CODE_PATH="$2"
shift
shift
;;

--treasury-nls-u128)
TREASURY_INIT_TOKENS_U128="$2"
shift
Expand Down Expand Up @@ -203,7 +195,6 @@ 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 "$OUTPUT_FILE" "Genesis output file"
Expand All @@ -212,9 +203,9 @@ if [[ "$COMMAND" == "$COMMAND_FULL_GEN" ]]; then

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" "$GOV_VOTING_PERIOD" \
"$GOV_MAX_DEPOSIT_PERIOD" "$GOV_EXPEDITED_VOTING_PERIOD" "$STAKING_MAX_VALIDATORS" \
"$TREASURY_INIT_TOKENS_U128" "$VAL_NODE_URLS_AND_VAL_PUBKEYS" \
"$GOV_VOTING_PERIOD" "$GOV_MAX_DEPOSIT_PERIOD" \
"$GOV_EXPEDITED_VOTING_PERIOD" "$STAKING_MAX_VALIDATORS" \
"$FEEREFUNDER_ACK_FEE_MIN" "$FEEREFUNDER_TIMEOUT_FEE_MIN" \
"$DEX_ADMIN_MNEMONIC" "$STORE_CODE_PRIVILEGED_ACCOUNT_MNEMONIC" \
"$ADMINS_TOKENS")
Expand Down
17 changes: 14 additions & 3 deletions scripts/init-local-network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ DEX_ADMIN_MNEMONIC=""
HERMES_ACCOUNT_MNEMONIC=""
STORE_CODE_PRIVILEGED_ACCOUNT_MNEMONIC=""

STORE_CODE_PRIVILEGED_ACCOUNT_KEY_NAME="storeAdmin"
INSTANTIATE_PRIVILEGED_ACCOUNT_KEY_NAME="wasmAdmin"

# Hermes - Nolus chain configuration
RPC_TIMEOUT_SECS="10"
DEFAULT_GAS="1000000"
Expand Down Expand Up @@ -339,7 +342,6 @@ __config_client() {
}

verify_dir_exist "$WASM_SCRIPT_PATH" "WASM sripts path"
verify_dir_exist "$WASM_CODE_ARTIFACTS_PATH_PLATFORM" "WASM code path - platform"
verify_mandatory "$HERMES_ACCOUNT_MNEMONIC" "Hermes account mnemonic"
verify_mandatory "$DEX_ADMIN_MNEMONIC" "DEX-Admin account mnemonic"
verify_mandatory "$STORE_CODE_PRIVILEGED_ACCOUNT_MNEMONIC" "WASM store-code privileged account mnemonic"
Expand All @@ -355,8 +357,8 @@ init_setup_validator_local_sh "$INIT_LOCAL_NETWORK_SCRIPT_DIR" "$VALIDATORS_ROOT

source "$INIT_LOCAL_NETWORK_SCRIPT_DIR"/internal/init-network.sh
init_network "$VAL_ACCOUNTS_DIR" "$VALIDATORS" "$MINIMUM_GAS_PRICE" "$QUERY_GAS_LIMIT" "$CHAIN_ID" "$NATIVE_CURRENCY" \
"$VAL_TOKENS" "$VAL_STAKE" "$accounts_spec" "$WASM_SCRIPT_PATH" "$WASM_CODE_ARTIFACTS_PATH_PLATFORM" \
"$TREASURY_NLS_U128" "$GOV_VOTING_PERIOD" "$GOV_MAX_DEPOSIT_PERIOD" "$GOV_EXPEDITED_VOTING_PERIOD" "$STAKING_MAX_VALIDATORS" \
"$VAL_TOKENS" "$VAL_STAKE" "$accounts_spec" "$WASM_SCRIPT_PATH" "$TREASURY_NLS_U128" \
"$GOV_VOTING_PERIOD" "$GOV_MAX_DEPOSIT_PERIOD" "$GOV_EXPEDITED_VOTING_PERIOD" "$STAKING_MAX_VALIDATORS" \
"$FEEREFUNDER_ACK_FEE_MIN" "$FEEREFUNDER_TIMEOUT_FEE_MIN" \
"$DEX_ADMIN_MNEMONIC" "$STORE_CODE_PRIVILEGED_ACCOUNT_MNEMONIC" "$ADMINS_BALANCE"

Expand All @@ -376,3 +378,12 @@ HERMES_BINARY_DIR="$HOME"/hermes

wait_nolus_gets_ready "$USER_DIR"
wait_hermes_config_gets_healthy "$HERMES_BINARY_DIR"

source "$WASM_SCRIPT_PATH/deploy-platform.sh"
source "$INIT_LOCAL_NETWORK_SCRIPT_DIR"/internal/genesis.sh

recover_account "$USER_DIR" "$STORE_CODE_PRIVILEGED_ACCOUNT_MNEMONIC" "$STORE_CODE_PRIVILEGED_ACCOUNT_KEY_NAME"
INSTANTIATE_PRIVILEGED_ACCOUNT_ADDRESS=$(recover_account "$USER_DIR" "$DEX_ADMIN_MNEMONIC" "$INSTANTIATE_PRIVILEGED_ACCOUNT_KEY_NAME")

RPC="http://$NOLUS_NETWORK_ADDR:$NOLUS_NETWORK_RPC_PORT"
deploy_contracts "$RPC" "$CHAIN_ID" "$USER_DIR" "$WASM_CODE_ARTIFACTS_PATH_PLATFORM" "$INSTANTIATE_PRIVILEGED_ACCOUNT_ADDRESS" "$STORE_CODE_PRIVILEGED_ACCOUNT_KEY_NAME"
12 changes: 2 additions & 10 deletions scripts/init-network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ VAL_TOKENS="1000000000""$NATIVE_CURRENCY"
VAL_STAKE="1000000""$NATIVE_CURRENCY"
CHAIN_ID=""
WASM_SCRIPT_PATH=""
WASM_CODE_PATH=""
TREASURY_NLS_U128="1000000000000"
FAUCET_MNEMONIC=""
FAUCET_TOKENS="100000000000""$NATIVE_CURRENCY"
Expand Down Expand Up @@ -172,12 +171,6 @@ while [[ $# -gt 0 ]]; do
shift
;;

--wasm-code-path)
WASM_CODE_PATH="$2"
shift
shift
;;

--treasury-nls-u128)
TREASURY_NLS_U128="$2"
shift
Expand Down Expand Up @@ -261,7 +254,6 @@ done
verify_mandatory "$ARTIFACT_BIN" "Nolus binary actifact"
verify_mandatory "$ARTIFACT_SCRIPTS" "Nolus scipts actifact"
verify_mandatory "$WASM_SCRIPT_PATH" "Wasm script path"
verify_mandatory "$WASM_CODE_PATH" "Wasm code path"
verify_mandatory "$FAUCET_MNEMONIC" "Faucet mnemonic"
verify_mandatory "$CHAIN_ID" "Nolus Chain ID"
verify_mandatory "$SSH_USER" "Server ssh user"
Expand All @@ -284,8 +276,8 @@ setup_services "$VALIDATORS"

source "$SCRIPT_DIR"/internal/init-network.sh
init_network "$VAL_ACCOUNTS_DIR" "$VALIDATORS" "$MINIMUM_GAS_PRICE" "$QUERY_GAS_LIMIT" "$CHAIN_ID" "$NATIVE_CURRENCY" \
"$VAL_TOKENS" "$VAL_STAKE" "$accounts_spec" "$WASM_SCRIPT_PATH" "$WASM_CODE_PATH" \
"$TREASURY_NLS_U128" "$GOV_VOTING_PERIOD" "$GOV_MAX_DEPOSIT_PERIOD" "$GOV_EXPEDITED_VOTING_PERIOD" "$STAKING_MAX_VALIDATORS" \
"$VAL_TOKENS" "$VAL_STAKE" "$accounts_spec" "$WASM_SCRIPT_PATH" "$TREASURY_NLS_U128" \
"$GOV_VOTING_PERIOD" "$GOV_MAX_DEPOSIT_PERIOD" "$GOV_EXPEDITED_VOTING_PERIOD" "$STAKING_MAX_VALIDATORS" \
"$FEEREFUNDER_ACK_FEE_MIN" "$FEEREFUNDER_TIMEOUT_FEE_MIN" \
"$DEX_ADMIN_MNEMONIC" "$STORE_CODE_PRIVILEGED_ACCOUNT_MNEMONIC" "$ADMINS_TOKENS"

Expand Down
57 changes: 31 additions & 26 deletions scripts/internal/genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ determine_addr() {
rm_dir "$key_dir"
}

__addresses_to_string() {
local -r addresses=("${@:1}")

local addresses_to_string="["
for address in "${addresses[@]}"; do
addresses_to_string+="\"$address\","
done
addresses_to_string="${addresses_to_string%,}"
addresses_to_string+="]"

echo "$addresses_to_string"
}

generate_genesis() {
set -euo pipefail
local -r chain_id="$1"
Expand All @@ -37,19 +50,17 @@ generate_genesis() {
local -r val_accounts_dir="$5"
local -r accounts_spec_in="$6"
local -r wasm_script_path="$7"
local -r wasm_code_path="$8"
local -r treasury_init_tokens_u128="$9"
local -r node_id_and_val_pubkeys="${10}"
local -r gov_voting_period="${11}"
local -r gov_max_deposit_period="${12}"
local -r gov_expedited_voting_period="${13}"
local -r staking_max_validators="${14}"
local -r feerefunder_ack_fee_min="${15}"
local -r feerefunder_timeout_fee_min="${16}"
local -r dex_admin_mnemonic="${17}"
local -r store_code_privileged_account_mnemonic="${18}"
local -r admins_tokens="${19}"

local -r treasury_init_tokens_u128="$8"
local -r node_id_and_val_pubkeys="$9"
local -r gov_voting_period="${10}"
local -r gov_max_deposit_period="${11}"
local -r gov_expedited_voting_period="${12}"
local -r staking_max_validators="${13}"
local -r feerefunder_ack_fee_min="${14}"
local -r feerefunder_timeout_fee_min="${15}"
local -r dex_admin_mnemonic="${16}"
local -r store_code_privileged_account_mnemonic="${17}"
local -r admins_tokens="${18}"

local -r treasury_init_tokens="$treasury_init_tokens_u128$native_currency"
init_val_mngr_sh "$val_accounts_dir" "$chain_id"
Expand All @@ -74,9 +85,8 @@ generate_genesis() {
# use the below pattern to let the pipefail dump the failed command output
_=$(__generate_proto_genesis_no_wasm "$chain_id" "$native_currency" \
"$accounts_spec" "$treasury_contract_addr" "$treasury_init_tokens_u128" "$admin_contract_addr" "$gov_voting_period" \
"$gov_max_deposit_period" "$gov_expedited_voting_period" "$staking_max_validators" "$feerefunder_ack_fee_min" "$feerefunder_timeout_fee_min" "$store_code_privileged_addr")
# TODO
#_=$(add_wasm_messages "$genesis_home_dir" "$wasm_code_path" "$treasury_init_tokens" "$dex_admin_address")
"$gov_max_deposit_period" "$gov_expedited_voting_period" "$staking_max_validators" "$feerefunder_ack_fee_min" "$feerefunder_timeout_fee_min" \
"$store_code_privileged_addr")

create_validator_txs="$(__gen_val_txns "$genesis_file" "$node_id_and_val_pubkeys" "$val_stake")"
_=$(__integrate_genesis_txs "$create_validator_txs")
Expand Down Expand Up @@ -141,15 +151,15 @@ __generate_proto_genesis_no_wasm() {
local -r feerefunder_timeout_fee_min="${12}"
local -r store_code_privileged_addr="${13}"

local -a wasm_allowed_addresses=("$admin_contract_addr" "$store_code_privileged_addr")
local -a wasm_allowed_addresses_store=("$admin_contract_addr" "$store_code_privileged_addr")

run_cmd "$genesis_home_dir" init genesis_manager --chain-id "$chain_id"
run_cmd "$genesis_home_dir" config set client keyring-backend test
run_cmd "$genesis_home_dir" config set client chain-id "$chain_id"

__set_token_denominations "$genesis_file" "$native_currency"
__set_tax_recipient "$genesis_file" "$treasury_addr"
__set_wasm_permission_params "$genesis_file" "${wasm_allowed_addresses[@]}"
__set_wasm_permission_params "$genesis_file" "${wasm_allowed_addresses_store[@]}"
__set_gov_parameters "$genesis_file" "$gov_voting_period" "$gov_max_deposit_period" "$gov_expedited_voting_period"
__modify_slashing_and_staking_params "$genesis_file" "$staking_max_validators"
__modify_neutron_modules_params "$genesis_file" "$feerefunder_ack_fee_min" "$feerefunder_timeout_fee_min" "$native_currency"
Expand Down Expand Up @@ -206,20 +216,15 @@ __set_tax_recipient() {

__set_wasm_permission_params() {
local -r genesis_file="$1"
local -a allowed_addresses=("${@:2}")
local -a allowed_addresses_store=("${@:2}")

local genesis_tmp_file="$genesis_file".tmp

local addresses_to_string="["
for address in "${allowed_addresses[@]}"; do
addresses_to_string+="\"$address\","
done
addresses_to_string="${addresses_to_string%,}"
addresses_to_string+="]"
local -r allowed_addresses_store_string=$(__addresses_to_string "${allowed_addresses_store[@]}")

< "$genesis_file" \
jq '.app_state["wasm"]["params"]["code_upload_access"]["permission"]="AnyOfAddresses"' \
| jq '.app_state["wasm"]["params"]["code_upload_access"]["addresses"]='$addresses_to_string'' \
| jq '.app_state["wasm"]["params"]["code_upload_access"]["addresses"]='$allowed_addresses_store_string'' \
| jq '.app_state["wasm"]["params"]["instantiate_default_permission"]="Everybody"' > "$genesis_tmp_file"

mv "$genesis_tmp_file" "$genesis_file"
Expand Down
28 changes: 13 additions & 15 deletions scripts/internal/init-network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,25 @@ init_network() {
local -r val_stake="$8"
local genesis_accounts_spec="$9"
local -r wasm_script_path="${10}"
local -r wasm_code_path="${11}"
local -r treasury_init_tokens_u128="${12}"
local -r gov_voting_period="${13}"
local -r gov_max_deposit_period="${14}"
local -r gov_expedited_voting_period="${15}"
local -r staking_max_validators="${16}"
local -r feerefunder_ack_fee_min="${17}"
local -r feerefunder_timeout_fee_min="${18}"
local -r dex_admin_mnemonic="${19}"
local -r store_code_privileged_account_mnemonic="${20}"
local -r admins_tokens="${21}"
local -r treasury_init_tokens_u128="${11}"
local -r gov_voting_period="${12}"
local -r gov_max_deposit_period="${13}"
local -r gov_expedited_voting_period="${14}"
local -r staking_max_validators="${15}"
local -r feerefunder_ack_fee_min="${16}"
local -r feerefunder_timeout_fee_min="${17}"
local -r dex_admin_mnemonic="${18}"
local -r store_code_privileged_account_mnemonic="${19}"
local -r admins_tokens="${20}"

node_id_and_val_pubkeys="$(setup_validators "$validators" "$minimum_gas_price" "$query_gas_limit")"
local final_genesis_file;
final_genesis_file=$(generate_genesis "$chain_id" "$native_currency" \
"$val_tokens" "$val_stake" \
"$val_accounts_dir" "$genesis_accounts_spec" \
"$wasm_script_path" "$wasm_code_path" \
"$treasury_init_tokens_u128" \
"$node_id_and_val_pubkeys" \
"$gov_voting_period" "$gov_max_deposit_period" "$gov_expedited_voting_period" "$staking_max_validators" \
"$wasm_script_path" "$treasury_init_tokens_u128" \
"$node_id_and_val_pubkeys" "$gov_voting_period" \
"$gov_max_deposit_period" "$gov_expedited_voting_period" "$staking_max_validators" \
"$feerefunder_ack_fee_min" "$feerefunder_timeout_fee_min" \
"$dex_admin_mnemonic" "$store_code_privileged_account_mnemonic" "$admins_tokens")
propagate_genesis "$final_genesis_file" "$validators"
Expand Down

0 comments on commit 4df15d5

Please sign in to comment.