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

add community pool rebate feature #1135

Merged
merged 15 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/apptesting/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,21 @@ func (s *AppTestHelper) CheckICATxNotSubmitted(portId, channelId string, icaFunc
s.Require().Equal(startSequence, endSequence, "sequence number should NOT have incremented from tested function")
}

// Helper function to check if multiple ICA txs were submitted by seeing if the sequence number
// incremented by more than 1
func (s *AppTestHelper) CheckMultipleICATxSubmitted(portId, channelId string, icaFunction func() error) {
// Get the sequence before the tested funciton is run
startSequence := s.MustGetNextSequenceNumber(portId, channelId)

// Run the test function and confirm there's no error
err := icaFunction()
s.Require().NoError(err, "no error expected executing tested function")

// Check that the sequence number incremented
endSequence := s.MustGetNextSequenceNumber(portId, channelId)
s.Require().Greater(endSequence, startSequence+1, "sequence number should have incremented twice from tested function")
}

// Constructs an ICA Packet Acknowledgement compatible with ibc-go v5+
func ICAPacketAcknowledgement(t *testing.T, msgType string, msgResponses []proto.Message) channeltypes.Acknowledgement {
txMsgData := &sdk.TxMsgData{
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v15/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (s *UpgradeTestSuite) SetupQueriesBeforeUpgrade() func() {
{Id: "1", CallbackId: stakeibckeeper.ICQCallbackID_Validator},
{Id: "2", CallbackId: stakeibckeeper.ICQCallbackID_Delegation}, // deleted
{Id: "3", CallbackId: stakeibckeeper.ICQCallbackID_Delegation}, // deleted
{Id: "4", CallbackId: stakeibckeeper.ICQCallbackID_WithdrawalBalance},
{Id: "4", CallbackId: stakeibckeeper.ICQCallbackID_WithdrawalHostBalance},
}
expectedQueriesAfterUpgrade := []string{"1", "4"}

Expand Down
21 changes: 15 additions & 6 deletions app/upgrades/v20/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ import (
ccvtypes "github.com/cosmos/interchain-security/v4/x/ccv/types"

stakeibckeeper "github.com/Stride-Labs/stride/v19/x/stakeibc/keeper"
stakeibctypes "github.com/Stride-Labs/stride/v19/x/stakeibc/types"
)

const (
UpgradeName = "v20"
dydxCPTreasuryAddress = "dydx15ztc7xy42tn2ukkc0qjthkucw9ac63pgp70urn"
dydxChainId = "dydx-mainnet-1"
UpgradeName = "v20"
DydxCommunityPoolTreasuryAddress = "dydx15ztc7xy42tn2ukkc0qjthkucw9ac63pgp70urn"
DydxChainId = "dydx-mainnet-1"
)

// CreateUpgradeHandler creates an SDK upgrade handler for v20
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
consumerKeeper ccvconsumerkeeper.Keeper,
stakeIbcKeeper stakeibckeeper.Keeper,
stakeibcKeeper stakeibckeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Starting upgrade v20...")
Expand All @@ -42,19 +43,27 @@ func CreateUpgradeHandler(
MigrateICSParams(ctx, consumerKeeper)

ctx.Logger().Info("Adding DYDX Community Pool Treasury Address...")
if err := SetDydxCommunityPoolTreasuryAddress(ctx, stakeibcKeeper); err != nil {
return newVm, err
}

return newVm, nil
}
}

// Write the Community Pool Treasury Address to the DYDX host_zone struct
func SetDydxCommunityPoolTreasuryAddress(ctx sdk.Context, stakeIbcKeeper stakeibckeeper.Keeper) error {

func SetDydxCommunityPoolTreasuryAddress(ctx sdk.Context, k stakeibckeeper.Keeper) error {
// Get the dydx host_zone
hostZone, found := k.GetHostZone(ctx, DydxChainId)
if !found {
return stakeibctypes.ErrHostZoneNotFound.Wrapf("dydx host zone not found")
}

// Set the treasury address
hostZone.CommunityPoolTreasuryAddress = DydxCommunityPoolTreasuryAddress

// Save the dydx host_zone
k.SetHostZone(ctx, hostZone)

return nil
}
Expand Down
17 changes: 17 additions & 0 deletions app/upgrades/v20/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/stretchr/testify/suite"

"github.com/Stride-Labs/stride/v19/app/apptesting"
v20 "github.com/Stride-Labs/stride/v19/app/upgrades/v20"
stakeibctypes "github.com/Stride-Labs/stride/v19/x/stakeibc/types"
)

type UpgradeTestSuite struct {
Expand All @@ -21,4 +23,19 @@ func TestKeeperTestSuite(t *testing.T) {
}

func (s *UpgradeTestSuite) TestUpgrade() {
dummyUpgradeHeight := int64(5)

// Create a dydx host zone
s.App.StakeibcKeeper.SetHostZone(s.Ctx, stakeibctypes.HostZone{
ChainId: v20.DydxChainId,
})

// Run the upgrade
s.ConfirmUpgradeSucceededs("v20", dummyUpgradeHeight)

// Confirm the treasury address was added to dydx
hostZone, found := s.App.StakeibcKeeper.GetHostZone(s.Ctx, v20.DydxChainId)
s.Require().True(found, "host zone should have been found")
s.Require().Equal(v20.DydxCommunityPoolTreasuryAddress, hostZone.CommunityPoolTreasuryAddress,
"community pool treasury address")
}
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
2 changes: 1 addition & 1 deletion 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 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
Loading
Loading