Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rebate integration tests #1152

Merged
merged 11 commits into from
Mar 21, 2024
Merged
2 changes: 1 addition & 1 deletion deps/osmosis
Submodule osmosis updated 1238 files
2 changes: 2 additions & 0 deletions dockernet/config/ica_host.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
"/cosmos.distribution.v1beta1.MsgSetWithdrawAddress",
"/cosmos.distribution.v1beta1.MsgFundCommunityPool",
"/cosmos.authz.v1beta1.MsgGrant",
"/cosmos.authz.v1beta1.MsgRevoke",
"/ibc.applications.transfer.v1.MsgTransfer",
"/cosmwasm.wasm.v1.MsgExecuteContract",
"/cosmwasm.wasm.v1.MsgInstantiateContract",
Expand Down
12 changes: 12 additions & 0 deletions dockernet/scripts/community-pool-staking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,19 @@ bash dockernet/scripts/community-pool-staking/create_pool.sh
```bash
bash dockernet/scripts/community-pool-staking/add_trade_route.sh
```
* Liquid stake to create TVL
```bash
bash dockernet/scripts/community-pool-staking/stake.sh
```
* Finally, test the reinvestment flow by sending USDC to the withdrawal address. View `logs/balances.log` to watch the funds traverse the different accounts
```bash
bash dockernet/scripts/community-pool-staking/reinvest.sh
```
* To register a rebate, run the following script.
```bash
bash dockernet/scripts/community-pool-staking/rebate.sh
```
* Then trigger reinvestment again. This time, you should notice USDC goes straight from the withdrawal account to the relevant community pool account. For Gaia, this account is the standard community pool, and for dYdX, the account is the community pool treasury.
```bash
bash dockernet/scripts/community-pool-staking/reinvest.sh
```
27 changes: 24 additions & 3 deletions dockernet/scripts/community-pool-staking/add_trade_route.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ source ${SCRIPT_DIR}/../../config.sh

HOST_CHAIN=$REWARD_CONVERTER_HOST_ZONE
HOST_VAL_ADDRESS=$(${HOST_CHAIN}_ADDRESS)
HOST_CHAIN_ID=$(GET_VAR_VALUE ${HOST_CHAIN}_CHAIN_ID)
HOST_DENOM=$(GET_VAR_VALUE ${HOST_CHAIN}_DENOM)
HOST_MAIN_CMD=$(GET_VAR_VALUE ${HOST_CHAIN}_MAIN_CMD)
HOST_CHAIN_ID=$(GET_VAR_VALUE ${HOST_CHAIN}_CHAIN_ID)
HOST_VAL_PREFIX=$(GET_VAR_VALUE ${HOST_CHAIN}_VAL_PREFIX)
HOST_DENOM=$(GET_VAR_VALUE ${HOST_CHAIN}_DENOM)

GAS="--gas-prices 0.1ustrd --gas auto --gas-adjustment 1.3"

Expand All @@ -21,6 +23,10 @@ host_to_noble_client=$(GET_CLIENT_ID_FROM_CHAIN_ID $HOST_CHAIN NOBLE)
host_to_noble_connection=$(GET_CONNECTION_ID_FROM_CLIENT_ID $HOST_CHAIN $host_to_noble_client)
host_to_noble_channel=$(GET_TRANSFER_CHANNEL_ID_FROM_CONNECTION_ID $HOST_CHAIN $host_to_noble_connection)

host_to_osmo_client=$(GET_CLIENT_ID_FROM_CHAIN_ID $HOST_CHAIN OSMO)
host_to_osmo_connection=$(GET_CONNECTION_ID_FROM_CLIENT_ID $HOST_CHAIN $host_to_osmo_client)
host_to_osmo_channel=$(GET_TRANSFER_CHANNEL_ID_FROM_CONNECTION_ID $HOST_CHAIN $host_to_osmo_connection)

noble_to_host_client=$(GET_CLIENT_ID_FROM_CHAIN_ID NOBLE $HOST_CHAIN)
noble_to_host_connection=$(GET_CONNECTION_ID_FROM_CLIENT_ID NOBLE $noble_to_host_client)
noble_to_host_channel=$(GET_TRANSFER_CHANNEL_ID_FROM_CONNECTION_ID NOBLE $noble_to_host_connection)
Expand Down Expand Up @@ -60,11 +66,26 @@ echo " Client: $osmo_to_host_client"
echo " Connection: $osmo_to_host_connection"
echo " Transfer Channel: $osmo_to_host_channel"

echo -e "\nTransferring $USDC_DENOM to $HOST_DENOM to create ibc denom..."
echo -e "\n$HOST_CHAIN -> OSMO:"
echo " Client: $host_to_osmo_client"
echo " Connection: $host_to_osmo_connection"
echo " Transfer Channel: $host_to_osmo_channel"

echo -e "\nTransferring $USDC_DENOM to $HOST_CHAIN to create ibc denom..."
$NOBLE_MAIN_CMD tx ibc-transfer transfer transfer $noble_to_host_channel $HOST_VAL_ADDRESS 10000${USDC_DENOM} \
--from ${NOBLE_VAL_PREFIX}1 -y | TRIM_TX
sleep 15

echo -e "\nTransferring $USDC_DENOM to OSMO to create ibc denom..."
$NOBLE_MAIN_CMD tx ibc-transfer transfer transfer $noble_to_osmo_channel $(OSMO_ADDRESS) 10000${USDC_DENOM} \
--from ${NOBLE_VAL_PREFIX}1 -y | TRIM_TX
sleep 15

echo -e "\nTransferring $HOST_DENOM to OSMO to create ibc denom..."
$HOST_MAIN_CMD tx ibc-transfer transfer transfer $host_to_osmo_channel $(OSMO_ADDRESS) 10000000${HOST_DENOM} \
--from ${HOST_VAL_PREFIX}1 -y | TRIM_TX
sleep 15

echo -e "\nDetermining IBC Denoms..."
usdc_denom_on_host=$(GET_IBC_DENOM $HOST_CHAIN_ID $host_to_noble_channel $USDC_DENOM)
usdc_denom_on_osmo=$(GET_IBC_DENOM OSMO $osmo_to_noble_channel $USDC_DENOM)
Expand Down
9 changes: 9 additions & 0 deletions dockernet/scripts/community-pool-staking/rebate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -eu
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${SCRIPT_DIR}/../../config.sh

HOST_CHAIN=$REWARD_CONVERTER_HOST_ZONE
HOST_CHAIN_ID=$(GET_VAR_VALUE ${HOST_CHAIN}_CHAIN_ID)

$STRIDE_MAIN_CMD tx stakeibc set-rebate $HOST_CHAIN_ID 0.25 100000 --from admin -y
25 changes: 25 additions & 0 deletions dockernet/scripts/community-pool-staking/trade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -eu
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${SCRIPT_DIR}/../../config.sh

TRADE_AMOUNT=997500

trade_account=$($STRIDE_MAIN_CMD q stakeibc list-trade-routes | grep trade_account -A 3 | grep address | awk '{print $2}')
host_denom_on_trade=$($STRIDE_MAIN_CMD q stakeibc list-trade-routes | grep host_denom_on_trade | awk '{print $2}')
reward_denom_on_trade=$($STRIDE_MAIN_CMD q stakeibc list-trade-routes | grep reward_denom_on_trade | awk '{print $2}')

echo "Granting authz permissions..."
$STRIDE_MAIN_CMD tx stakeibc toggle-trade-controller $OSMO_CHAIN_ID grant $(OSMO_ADDRESS) --from admin -y
sleep 15

tx_file=${STATE}/${OSMO_NODE_PREFIX}1/swap_tx.json
$OSMO_MAIN_CMD tx gamm swap-exact-amount-in ${TRADE_AMOUNT}${reward_denom_on_trade} 1 \
--swap-route-pool-ids 1 --swap-route-denoms $host_denom_on_trade \
--from $trade_account --generate-only > $tx_file
sleep 5

echo "Executing swap through authz..."
$OSMO_MAIN_CMD tx authz exec $tx_file --from ${OSMO_VAL_PREFIX}1 -y | TRIM_TX
sleep 1
rm -f $tx_file
92 changes: 50 additions & 42 deletions dockernet/src/create_logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,53 +88,57 @@ while true; do
print_header "TRADE ROUTES" $state
$STRIDE_MAIN_CMD q stakeibc list-trade-routes >> $state

print_separator "STAKETIA" $state

print_header "HOST ZONE" $state
$STRIDE_MAIN_CMD q staketia host-zone >> $state
print_header "DELEGATION RECORDS" $state
$STRIDE_MAIN_CMD q staketia delegation-records >> $state
print_header "UNBONDING RECORDS" $state
$STRIDE_MAIN_CMD q staketia unbonding-records >> $state
print_header "REDEMPTION RECORDS" $state
$STRIDE_MAIN_CMD q staketia redemption-records >> $state
print_header "SLASH RECORDS" $state
$STRIDE_MAIN_CMD q staketia slash-records >> $state
host_chain="${HOST_CHAINS[0]}"
if [[ "$host_chain" == "GAIA" ]]; then
print_separator "STAKETIA" $state

print_header "HOST ZONE" $state
$STRIDE_MAIN_CMD q staketia host-zone >> $state
print_header "DELEGATION RECORDS" $state
$STRIDE_MAIN_CMD q staketia delegation-records >> $state
print_header "UNBONDING RECORDS" $state
$STRIDE_MAIN_CMD q staketia unbonding-records >> $state
print_header "REDEMPTION RECORDS" $state
$STRIDE_MAIN_CMD q staketia redemption-records >> $state
print_header "SLASH RECORDS" $state
$STRIDE_MAIN_CMD q staketia slash-records >> $state
fi

# Log stride stakeibc balances
print_separator "VALIDATORS" $balances
host_chain="${HOST_CHAINS[0]}"
host_val_address="$(${host_chain}_ADDRESS)"
host_cmd=$(GET_VAR_VALUE ${host_chain}_MAIN_CMD)
print_stride_balance $(STRIDE_ADDRESS) "STRIDE"
print_host_balance $host_chain $host_val_address $host_chain

# Log stride staketia balances
print_separator "STAKETIA STRIDE" $balances

deposit_address=$($STRIDE_MAIN_CMD keys show -a deposit)
redemption_address=$($STRIDE_MAIN_CMD keys show -a redemption)
claim_address=$($STRIDE_MAIN_CMD keys show -a claim)
fee_address=$($STRIDE_MAIN_CMD q auth module-account staketia_fee_address | grep "address:" | awk '{print $2}')

print_stride_balance $deposit_address "DEPOSIT"
print_stride_balance $redemption_address "REDEMPTION"
print_stride_balance $claim_address "CLAIM"
print_stride_balance $fee_address "FEE"

# Log staketia balance on host chain
print_separator "STAKETIA HOST" $balances
print_host_balance "$host_chain" $DELEGATION_ADDRESS "DELEGATION CONTROLLER"
print_host_balance "$host_chain" $REWARD_ADDRESS "REWARD CONTROLLER"

# Log staketia delegations/undelegations
print_separator "STAKETIA STAKING" $balances
delegation_address=$($STRIDE_MAIN_CMD q staketia host-zone | grep "delegation_address" | awk '{print $2}')

print_header "DELEGATIONS $host_chain" $balances
$host_cmd q staking delegations $delegation_address | grep -vE "pagination|total|next_key" >> $balances
print_header "UNBONDING-DELEGATIONS $host_chain" $balances
$host_cmd q staking unbonding-delegations $delegation_address | grep -vE "pagination|total|next_key" >> $balances
if [[ "$host_chain" == "GAIA" ]]; then
# Log stride staketia balances
print_separator "STAKETIA STRIDE" $balances

deposit_address=$($STRIDE_MAIN_CMD keys show -a deposit)
redemption_address=$($STRIDE_MAIN_CMD keys show -a redemption)
claim_address=$($STRIDE_MAIN_CMD keys show -a claim)
fee_address=$($STRIDE_MAIN_CMD q auth module-account staketia_fee_address | grep "address:" | awk '{print $2}')

print_stride_balance $deposit_address "DEPOSIT"
print_stride_balance $redemption_address "REDEMPTION"
print_stride_balance $claim_address "CLAIM"
print_stride_balance $fee_address "FEE"

# Log staketia balance on host chain
print_separator "STAKETIA HOST" $balances
print_host_balance "$host_chain" $DELEGATION_ADDRESS "DELEGATION CONTROLLER"
print_host_balance "$host_chain" $REWARD_ADDRESS "REWARD CONTROLLER"

# Log staketia delegations/undelegations
print_separator "STAKETIA STAKING" $balances
delegation_address=$($STRIDE_MAIN_CMD q staketia host-zone | grep "delegation_address" | awk '{print $2}')

print_header "DELEGATIONS $host_chain" $balances
$host_cmd q staking delegations $delegation_address | grep -vE "pagination|total|next_key" >> $balances
print_header "UNBONDING-DELEGATIONS $host_chain" $balances
$host_cmd q staking unbonding-delegations $delegation_address | grep -vE "pagination|total|next_key" >> $balances
fi

# Log stride channels
print_separator "STRIDE" $channels
Expand Down Expand Up @@ -184,21 +188,25 @@ while true; do
print_stride_balance $community_pool_stake_address "COMMUNITY POOL STAKE HOLDING ACCT BALANCE"
print_stride_balance $community_pool_redeem_address "COMMUNITY POOL REDEEM HOLDING ACCT BALANCE"

community_pool_treasury=$($STRIDE_MAIN_CMD q stakeibc show-host-zone $HOST_CHAIN_ID | grep community_pool_treasury | awk '{print $2}' | tr -d '"')
if [[ "$community_pool_treasury" != "" ]]; then
print_host_balance $chain $community_pool_treasury "COMMUNITY POOL TREASURY ADDRESS"
fi

# Log host channels
print_separator "$chain" $channels
$HOST_MAIN_CMD q ibc channel channels | grep -E "channel_id|port|state" >> $channels || true
done


TRADE_ICA_ADDR=$($STRIDE_MAIN_CMD q stakeibc list-trade-routes | grep trade_account -A 2 | grep address | awk '{print $2}')
if [[ "$TRADE_ICA_ADDR" == "$OSMO_ADDRESS_PREFIX"* ]]; then
print_header "TRADE ACCT BALANCE" >> $balances
print_header "TRADE ACCT BALANCE" $balances
$OSMO_MAIN_CMD q bank balances $TRADE_ICA_ADDR >> $balances
fi

for chain in ${ACCESSORY_CHAINS[@]:-}; do
ACCESSORY_MAIN_CMD=$(GET_VAR_VALUE ${chain}_MAIN_CMD)
print_header "========================== $chain =============================" >> $channels
print_header "========================== $chain =============================" $channels
$ACCESSORY_MAIN_CMD q ibc channel channels | grep -E "channel_id|port|state" >> $channels || true
done

Expand Down
4 changes: 2 additions & 2 deletions dockernet/src/init_chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ if [[ "$CHAIN" != "STRIDE" && "$CHAIN" != "HOST" ]]; then
fi

# wipe out the persistent peers for the main node (these are incorrectly autogenerated for each validator during collect-gentxs)
sed -i -E "s|persistent_peers = .*|persistent_peers = \"\"|g" $MAIN_CONFIG
sed -i -E "s|^persistent_peers = .*|persistent_peers = \"\"|g" $MAIN_CONFIG

# update chain-specific genesis settings
if [ "$CHAIN" == "STRIDE" ]; then
Expand All @@ -362,7 +362,7 @@ for (( i=2; i <= $NUM_NODES; i++ )); do
genesis_json="${STATE}/${node_name}/config/genesis.json"

# add the main node as a persistent peer
sed -i -E "s|persistent_peers = .*|persistent_peers = \"${MAIN_NODE_ID}\"|g" $config_toml
sed -i -E "s|^persistent_peers = .*|persistent_peers = \"${MAIN_NODE_ID}\"|g" $config_toml
# copy the main node's genesis to the peer nodes to ensure they all have the same genesis
cp $MAIN_GENESIS $genesis_json

Expand Down
7 changes: 6 additions & 1 deletion dockernet/src/register_host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ if [[ "$CHAIN" == "GAIA" ]]; then
LSM_ENABLED="true"
fi

COMMUNITY_POOL_TREASURY_ADDRESS=""
if [[ "$CHAIN" == "DYDX" ]]; then
COMMUNITY_POOL_TREASURY_ADDRESS="--community-pool-treasury-address dydx15ztc7xy42tn2ukkc0qjthkucw9ac63pgp70urn"
fi

echo "$CHAIN - Registering host zone..."
$STRIDE_MAIN_CMD tx stakeibc register-host-zone \
$CONNECTION $HOST_DENOM $ADDRESS_PREFIX $IBC_DENOM $CHANNEL 1 $LSM_ENABLED \
$CONNECTION $HOST_DENOM $ADDRESS_PREFIX $IBC_DENOM $CHANNEL 1 $LSM_ENABLED $COMMUNITY_POOL_TREASURY_ADDRESS \
--gas 1000000 --from $STRIDE_ADMIN_ACCT --home $DOCKERNET_HOME/state/stride1 -y | TRIM_TX
sleep 10

Expand Down
2 changes: 2 additions & 0 deletions dockernet/start_network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ done


# Start each chain, create the transfer channels and start the relayers
# For dydx, sleep before and after the relayers are setup to get it some time to startup
# since it's a computationally expensive chain
bash $SRC/start_chain.sh
bash $SRC/start_relayers.sh

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func WithdrawalRewardBalanceCallback(k Keeper, ctx sdk.Context, args []byte, que

// If there's a rebate portion, fund the community pool with that amount
if rebateAmount.GT(sdkmath.ZeroInt()) {
rebateToken := sdk.NewCoin(tradeRouteCallback.RewardDenom, rebateAmount)
rebateToken := sdk.NewCoin(tradeRoute.RewardDenomOnHostZone, rebateAmount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are actually the same thing if you look at how it sets RewardDenom before the call

if err := k.FundCommunityPool(ctx, hostZone, rebateToken, types.ICAAccountType_WITHDRAWAL); err != nil {
return errorsmod.Wrapf(err, "unable to submit fund community pool ICA")
}
Expand Down
12 changes: 5 additions & 7 deletions x/stakeibc/keeper/reward_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ func (k Keeper) BuildTradeAuthzMsg(
switch permissionChange {
case types.AuthzPermissionChange_GRANT:
authorization := authz.NewGenericAuthorization(swapMsgTypeUrl)
grant, err := authz.NewGrant(ctx.BlockTime(), authorization, nil)
expiration := ctx.BlockTime().Add(time.Hour * 24 * 365 * 100) // 100 years

grant, err := authz.NewGrant(ctx.BlockTime(), authorization, &expiration)
if err != nil {
return nil, errorsmod.Wrapf(err, "unable to build grant struct")
}
Expand All @@ -206,12 +208,14 @@ func (k Keeper) BuildTradeAuthzMsg(
Grantee: grantee,
Grant: grant,
}}

case types.AuthzPermissionChange_REVOKE:
authzMsg = []proto.Message{&authz.MsgRevoke{
Granter: tradeRoute.TradeAccount.Address,
Grantee: grantee,
MsgTypeUrl: swapMsgTypeUrl,
}}

default:
return nil, errors.New("invalid permission change")
}
Expand Down Expand Up @@ -296,12 +300,6 @@ func (k Keeper) TransferRewardTokensHostToTrade(ctx sdk.Context, amount sdkmath.
return nil
}

// Similarly, if there's no price on the trade route yet, don't initiate the transfer because
// we know the swap will not be submitted
if route.TradeConfig.SwapPrice.IsZero() {
return nil
}

// Build the PFM transfer message from host to trade zone
msg, err := k.BuildHostToTradeTransferMsg(ctx, amount, route)
if err != nil {
Expand Down