Skip to content

Commit

Permalink
[TRA-451] initialize vaults on start-up in local, dev, staging (#1782)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqin7 committed Jul 11, 2024
1 parent 23e4b62 commit 9512db1
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 11 deletions.
2 changes: 1 addition & 1 deletion protocol/scripts/genesis/prod_pregenesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion protocol/testing/containertest/containertest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion protocol/testing/e2etest-local/local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
37 changes: 33 additions & 4 deletions protocol/testing/genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
20 changes: 19 additions & 1 deletion protocol/testing/testnet-dev/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion protocol/testing/testnet-external/pregenesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 14 additions & 1 deletion protocol/testing/testnet-local/local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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"

Expand Down
20 changes: 19 additions & 1 deletion protocol/testing/testnet-staging/staging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit 9512db1

Please sign in to comment.