From fb596d371bf2e6f4d9e0e84375ca6cb567b640b4 Mon Sep 17 00:00:00 2001 From: Tian Qin Date: Wed, 26 Jun 2024 13:06:34 -0400 Subject: [PATCH] initialize vaults on start-up in local, dev, staging --- protocol/scripts/genesis/prod_pregenesis.sh | 2 +- .../testing/containertest/containertest.sh | 2 +- protocol/testing/e2etest-local/local.sh | 2 +- protocol/testing/genesis.sh | 37 +++++++++++++++++-- protocol/testing/testnet-dev/dev.sh | 20 +++++++++- .../testing/testnet-external/pregenesis.sh | 2 +- protocol/testing/testnet-local/local.sh | 15 +++++++- protocol/testing/testnet-staging/staging.sh | 20 +++++++++- 8 files changed, 89 insertions(+), 11 deletions(-) diff --git a/protocol/scripts/genesis/prod_pregenesis.sh b/protocol/scripts/genesis/prod_pregenesis.sh index a04769cfa9..d54042179d 100755 --- a/protocol/scripts/genesis/prod_pregenesis.sh +++ b/protocol/scripts/genesis/prod_pregenesis.sh @@ -168,7 +168,7 @@ create_pregenesis_file() { echo "Copying exchange config jsons to $TMP_EXCHANGE_CONFIG_JSON_DIR" cp -R ./daemons/pricefeed/client/constants/testdata $TMP_EXCHANGE_CONFIG_JSON_DIR - edit_genesis "$VAL_CONFIG_DIR" "" "" "$TMP_EXCHANGE_CONFIG_JSON_DIR" "./testing/delaymsg_config" "STATUS_INITIALIZING" "" + edit_genesis "$VAL_CONFIG_DIR" "" "" "" "" "$TMP_EXCHANGE_CONFIG_JSON_DIR" "./testing/delaymsg_config" "STATUS_INITIALIZING" "" overwrite_genesis_production } diff --git a/protocol/testing/containertest/containertest.sh b/protocol/testing/containertest/containertest.sh index 4f1ec6c2b0..dd94d8378a 100755 --- a/protocol/testing/containertest/containertest.sh +++ b/protocol/testing/containertest/containertest.sh @@ -100,7 +100,7 @@ create_validators() { # Using "*" as a subscript results in a single arg: "dydx1... dydx1... dydx1..." # Using "@" as a subscript results in separate args: "dydx1..." "dydx1..." "dydx1..." # Note: `edit_genesis` must be called before `add-genesis-account` or `update_genesis_use_test_exchange`. - edit_genesis "$VAL_CONFIG_DIR" "${TEST_ACCOUNTS[*]}" "${FAUCET_ACCOUNTS[*]}" "" "" "" "" + edit_genesis "$VAL_CONFIG_DIR" "${TEST_ACCOUNTS[*]}" "${FAUCET_ACCOUNTS[*]}" "" "" "" "" "" "" # Configure the genesis file to only use the test exchange to compute index prices. update_genesis_use_test_exchange "$VAL_CONFIG_DIR" diff --git a/protocol/testing/e2etest-local/local.sh b/protocol/testing/e2etest-local/local.sh index 0e1f28e4c2..79b7e7d3a6 100755 --- a/protocol/testing/e2etest-local/local.sh +++ b/protocol/testing/e2etest-local/local.sh @@ -99,7 +99,7 @@ create_validators() { # Using "*" as a subscript results in a single arg: "dydx1... dydx1... dydx1..." # Using "@" as a subscript results in separate args: "dydx1..." "dydx1..." "dydx1..." # Note: `edit_genesis` must be called before `add-genesis-account`. - edit_genesis "$VAL_CONFIG_DIR" "${TEST_ACCOUNTS[*]}" "${FAUCET_ACCOUNTS[*]}" "" "" "" "" + edit_genesis "$VAL_CONFIG_DIR" "${TEST_ACCOUNTS[*]}" "${FAUCET_ACCOUNTS[*]}" "" "" "" "" "" "" update_genesis_use_test_volatile_market "$VAL_CONFIG_DIR" update_all_markets_with_fixed_price_exchange "$VAL_CONFIG_DIR" update_genesis_complete_bridge_delay "$VAL_CONFIG_DIR" "30" diff --git a/protocol/testing/genesis.sh b/protocol/testing/genesis.sh index e2167290ca..770836d4b7 100755 --- a/protocol/testing/genesis.sh +++ b/protocol/testing/genesis.sh @@ -21,6 +21,7 @@ REWARD_TOKEN="adv4tnt" NATIVE_TOKEN="adv4tnt" # public testnet token DEFAULT_SUBACCOUNT_QUOTE_BALANCE=100000000000000000 DEFAULT_SUBACCOUNT_QUOTE_BALANCE_FAUCET=900000000000000000 +DEFAULT_SUBACCOUNT_QUOTE_BALANCE_VAULT=1000000000 NATIVE_TOKEN_WHOLE_COIN="dv4tnt" COIN_NAME="dYdX V4 Testnet Token" # Each testnet validator has 1 million whole coins of native token. @@ -48,26 +49,28 @@ function edit_genesis() { # The -r flag tells the command to not treat a Backslash as an escape character. IFS=' ' read -ra INPUT_TEST_ACCOUNTS <<<"${2}" IFS=' ' read -ra INPUT_FAUCET_ACCOUNTS <<<"${3}" + IFS=' ' read -ra INPUT_VAULT_ACCOUNTS <<<"${4}" + IFS=' ' read -ra INPUT_VAULT_NUMBERS <<<"${5}" - EXCHANGE_CONFIG_JSON_DIR="$4" + EXCHANGE_CONFIG_JSON_DIR="$6" if [ -z "$EXCHANGE_CONFIG_JSON_DIR" ]; then # Default to using exchange_config folder within the current directory. EXCHANGE_CONFIG_JSON_DIR="exchange_config" fi - DELAY_MSG_JSON_DIR="$5" + DELAY_MSG_JSON_DIR="$7" if [ -z "$DELAY_MSG_JSON_DIR" ]; then # Default to using exchange_config folder within the current directory. DELAY_MSG_JSON_DIR="delaymsg_config" fi - INITIAL_CLOB_PAIR_STATUS="$6" + INITIAL_CLOB_PAIR_STATUS="$8" if [ -z "$INITIAL_CLOB_PAIR_STATUS" ]; then # Default to initialie clob pairs as active. INITIAL_CLOB_PAIR_STATUS='STATUS_ACTIVE' fi - REWARDS_VESTER_ACCOUNT_BALANCE="$7" + REWARDS_VESTER_ACCOUNT_BALANCE="$9" if [ -z "$REWARDS_VESTER_ACCOUNT_BALANCE" ]; then # Default to 200 million full coins. REWARDS_VESTER_ACCOUNT_BALANCE="200000000$EIGHTEEN_ZEROS" @@ -1058,6 +1061,12 @@ function edit_genesis() { bridge_module_account_balance=$(echo "$bridge_module_account_balance - $TESTNET_VALIDATOR_NATIVE_TOKEN_BALANCE" | bc) acct_idx=$(($acct_idx + 1)) done + # Update subaccounts module for vault accounts. + for acct in "${INPUT_VAULT_ACCOUNTS[@]}"; do + add_subaccount "$GENESIS" "$acct_idx" "$acct" "$DEFAULT_SUBACCOUNT_QUOTE_BALANCE_VAULT" + total_accounts_quote_balance=$(($total_accounts_quote_balance + $DEFAULT_SUBACCOUNT_QUOTE_BALANCE_VAULT)) + acct_idx=$(($acct_idx + 1)) + done next_bank_idx=0 if (( total_accounts_quote_balance > 0 )); then @@ -1485,6 +1494,26 @@ function edit_genesis() { update_ica_host_params # ICA Controller Params update_ica_controller_params + + # Vaults + # Set total shares and owner shares of each vault. + vault_idx=0 + if [ -z "${INPUT_TEST_ACCOUNTS[0]}" ]; then + vault_owner_address='dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4' # alice as default vault owner + else + vault_owner_address="${INPUT_TEST_ACCOUNTS[0]}" + fi + for number in "${INPUT_VAULT_NUMBERS[@]}"; do + dasel put -t json -f "$GENESIS" '.app_state.vault.vaults.[]' -v '{}' + dasel put -t string -f "$GENESIS" ".app_state.vault.vaults.[${vault_idx}].vault_id.type" -v 'VAULT_TYPE_CLOB' + dasel put -t int -f "$GENESIS" ".app_state.vault.vaults.[${vault_idx}].vault_id.number" -v "${number}" + dasel put -t string -f "$GENESIS" ".app_state.vault.vaults.[${vault_idx}].total_shares.num_shares" -v "${DEFAULT_SUBACCOUNT_QUOTE_BALANCE_VAULT}" + + dasel put -t json -f "$GENESIS" ".app_state.vault.vaults.[${vault_idx}].owner_shares.[]" -v '{}' + dasel put -t string -f "$GENESIS" ".app_state.vault.vaults.[${vault_idx}].owner_shares.[0].owner" -v "${vault_owner_address}" + dasel put -t string -f "$GENESIS" ".app_state.vault.vaults.[${vault_idx}].owner_shares.[0].shares.num_shares" -v "${DEFAULT_SUBACCOUNT_QUOTE_BALANCE_VAULT}" + vault_idx=$(($vault_idx + 1)) + done } function add_subaccount() { diff --git a/protocol/testing/testnet-dev/dev.sh b/protocol/testing/testnet-dev/dev.sh index 8b4569237d..809c543346 100755 --- a/protocol/testing/testnet-dev/dev.sh +++ b/protocol/testing/testnet-dev/dev.sh @@ -79,6 +79,24 @@ FAUCET_ACCOUNTS=( "dydx1axstmx84qtv0avhjwek46v6tcmyc8agu03nafv" # backup #2 ) +# Addresses of vaults. +# Can use ../scripts/vault/get_vault.go to generate a vault's address. +VAULT_ACCOUNTS=( + "dydx1c0m5x87llaunl5sgv3q5vd7j5uha26d2q2r2q0" # BTC vault + "dydx14rplxdyycc6wxmgl8fggppgq4774l70zt6phkw" # ETH vault + "dydx190te44zcctdgk0qmqtenve2m00g3r2dn7ntd72" # LINK vault + "dydx1a83cjn83vqh5ss2vccg6uuaeky7947xldp9r2e" # MATIC vault + "dydx1nkz8xcar6sxedw0yva6jzjplw7hfg6pp6e7h0l" # CRV vault +) +# Number of each vault above, which for CLOB vaults is the ID of the clob pair it quotes on. +VAULT_NUMBERS=( + 0 # BTC clob pair ID + 1 # ETH clob pair ID + 2 # LINK clob pair ID + 3 # MATIC clob pair ID + 4 # CRV clob pair ID +) + # Define dependencies for this script. # `jq` and `dasel` are used to manipulate json and yaml files respectively. install_prerequisites() { @@ -134,7 +152,7 @@ create_validators() { # Using "*" as a subscript results in a single arg: "dydx1... dydx1... dydx1..." # Using "@" as a subscript results in separate args: "dydx1..." "dydx1..." "dydx1..." # Note: `edit_genesis` must be called before `add-genesis-account`. - edit_genesis "$VAL_CONFIG_DIR" "${TEST_ACCOUNTS[*]}" "${FAUCET_ACCOUNTS[*]}" "" "" "" "" + edit_genesis "$VAL_CONFIG_DIR" "${TEST_ACCOUNTS[*]}" "${FAUCET_ACCOUNTS[*]}" "${VAULT_ACCOUNTS[*]}" "${VAULT_NUMBERS[*]}" "" "" "" "" update_genesis_use_test_volatile_market "$VAL_CONFIG_DIR" update_genesis_complete_bridge_delay "$VAL_CONFIG_DIR" "600" diff --git a/protocol/testing/testnet-external/pregenesis.sh b/protocol/testing/testnet-external/pregenesis.sh index d9f309b855..7411761de5 100755 --- a/protocol/testing/testnet-external/pregenesis.sh +++ b/protocol/testing/testnet-external/pregenesis.sh @@ -181,7 +181,7 @@ create_pregenesis_file() { # Using "*" as a subscript results in a single arg: "dydx1... dydx1... dydx1..." # Using "@" as a subscript results in separate args: "dydx1..." "dydx1..." "dydx1..." # Note: `edit_genesis` must be called before `add-genesis-account`. - edit_genesis "$VAL_CONFIG_DIR" "" "" "$TMP_EXCHANGE_CONFIG_JSON_DIR" "./testing/delaymsg_config" "" "" + edit_genesis "$VAL_CONFIG_DIR" "" "" "" "" "$TMP_EXCHANGE_CONFIG_JSON_DIR" "./testing/delaymsg_config" "" "" overwrite_genesis_public_testnet FAUCET_BALANCE="${FAUCET_NATIVE_TOKEN_BALANCE}$NATIVE_TOKEN" diff --git a/protocol/testing/testnet-local/local.sh b/protocol/testing/testnet-local/local.sh index b1d8ecbdff..a90bc06c0d 100755 --- a/protocol/testing/testnet-local/local.sh +++ b/protocol/testing/testnet-local/local.sh @@ -63,6 +63,18 @@ FAUCET_ACCOUNTS=( "dydx1nzuttarf5k2j0nug5yzhr6p74t9avehn9hlh8m" # main faucet ) +# Addresses of vaults. +# Can use ../scripts/vault/get_vault.go to generate a vault's address. +VAULT_ACCOUNTS=( + "dydx1c0m5x87llaunl5sgv3q5vd7j5uha26d2q2r2q0" # BTC vault + "dydx14rplxdyycc6wxmgl8fggppgq4774l70zt6phkw" # ETH vault +) +# Number of each vault, which for CLOB vaults is the ID of the clob pair it quotes on. +VAULT_NUMBERS=( + 0 # BTC clob pair ID + 1 # ETH clob pair ID +) + # Define dependencies for this script. # `jq` and `dasel` are used to manipulate json and yaml files respectively. install_prerequisites() { @@ -100,7 +112,8 @@ create_validators() { # Using "*" as a subscript results in a single arg: "dydx1... dydx1... dydx1..." # Using "@" as a subscript results in separate args: "dydx1..." "dydx1..." "dydx1..." # Note: `edit_genesis` must be called before `add-genesis-account`. - edit_genesis "$VAL_CONFIG_DIR" "${TEST_ACCOUNTS[*]}" "${FAUCET_ACCOUNTS[*]}" "" "" "" "" + # edit_genesis "$VAL_CONFIG_DIR" "${TEST_ACCOUNTS[*]}" "${FAUCET_ACCOUNTS[*]}" "${VAULT_ACCOUNTS[*]}" "${VAULT_NUMBERS[*]}" "" "" "" "" + edit_genesis "$VAL_CONFIG_DIR" "" "${FAUCET_ACCOUNTS[*]}" "${VAULT_ACCOUNTS[*]}" "${VAULT_NUMBERS[*]}" "" "" "" "" update_genesis_use_test_volatile_market "$VAL_CONFIG_DIR" update_genesis_complete_bridge_delay "$VAL_CONFIG_DIR" "30" diff --git a/protocol/testing/testnet-staging/staging.sh b/protocol/testing/testnet-staging/staging.sh index faf953084c..ebd2871f97 100755 --- a/protocol/testing/testnet-staging/staging.sh +++ b/protocol/testing/testnet-staging/staging.sh @@ -133,6 +133,24 @@ FAUCET_ACCOUNTS=( "dydx1axstmx84qtv0avhjwek46v6tcmyc8agu03nafv" # backup #2 ) +# Addresses of vaults. +# Can use ../scripts/vault/get_vault.go to generate a vault's address. +VAULT_ACCOUNTS=( + "dydx1c0m5x87llaunl5sgv3q5vd7j5uha26d2q2r2q0" # BTC vault + "dydx14rplxdyycc6wxmgl8fggppgq4774l70zt6phkw" # ETH vault + "dydx190te44zcctdgk0qmqtenve2m00g3r2dn7ntd72" # LINK vault + "dydx1a83cjn83vqh5ss2vccg6uuaeky7947xldp9r2e" # MATIC vault + "dydx1nkz8xcar6sxedw0yva6jzjplw7hfg6pp6e7h0l" # CRV vault +) +# Number of each vault above, which for CLOB vaults is the ID of the clob pair it quotes on. +VAULT_NUMBERS=( + 0 # BTC clob pair ID + 1 # ETH clob pair ID + 2 # LINK clob pair ID + 3 # MATIC clob pair ID + 4 # CRV clob pair ID +) + # Define dependencies for this script. # `jq` and `dasel` are used to manipulate json and yaml files respectively. install_prerequisites() { @@ -188,7 +206,7 @@ create_validators() { # Using "*" as a subscript results in a single arg: "dydx1... dydx1... dydx1..." # Using "@" as a subscript results in separate args: "dydx1..." "dydx1..." "dydx1..." # Note: `edit_genesis` must be called before `add-genesis-account`. - edit_genesis "$VAL_CONFIG_DIR" "${TEST_ACCOUNTS[*]}" "${FAUCET_ACCOUNTS[*]}" "" "" "" "" + edit_genesis "$VAL_CONFIG_DIR" "${TEST_ACCOUNTS[*]}" "${FAUCET_ACCOUNTS[*]}" "${VAULT_ACCOUNTS[*]}" "${VAULT_NUMBERS[*]}" "" "" "" "" update_genesis_use_test_volatile_market "$VAL_CONFIG_DIR" update_genesis_complete_bridge_delay "$VAL_CONFIG_DIR" "600"