From 18b3e3e8f7535029266d354f514eb7d2cae659e5 Mon Sep 17 00:00:00 2001 From: Riley Edmunds Date: Tue, 28 Mar 2023 11:28:41 -0400 Subject: [PATCH 1/3] airdrop testing --- dockernet/scripts/airdrop/airdrop3.sh | 63 ++++++++++----------------- dockernet/scripts/airdrop/airdrop4.sh | 1 + 2 files changed, 25 insertions(+), 39 deletions(-) diff --git a/dockernet/scripts/airdrop/airdrop3.sh b/dockernet/scripts/airdrop/airdrop3.sh index 15d12bf953..3e3e2336b5 100644 --- a/dockernet/scripts/airdrop/airdrop3.sh +++ b/dockernet/scripts/airdrop/airdrop3.sh @@ -27,8 +27,11 @@ echo "Funding accounts..." # Transfer uatom from gaia to stride, so that we can liquid stake later $GAIA_MAIN_CMD tx ibc-transfer transfer transfer channel-0 stride1nf6v2paty9m22l3ecm7dpakq2c92ueyununayr 1000000uatom --from ${GAIA_VAL_PREFIX}1 -y | TRIM_TX sleep 5 -# Fund the distributor account -$STRIDE_MAIN_CMD tx bank send val1 stride12lw3587g97lgrwr2fjtr8gg5q6sku33e5yq9wl 600000ustrd --from val1 -y | TRIM_TX +# query the distribution-test3 account +echo "query the distribution-test3 account" +$STRIDE_MAIN_CMD q bank balances stride12lw3587g97lgrwr2fjtr8gg5q6sku33e5yq9wl +# Fund the distributor-test3 account +$STRIDE_MAIN_CMD tx bank send val1 stride12lw3587g97lgrwr2fjtr8gg5q6sku33e5yq9wl 100ustrd --from val1 -y | TRIM_TX sleep 5 # Fund the airdrop account $STRIDE_MAIN_CMD tx bank send val1 stride1nf6v2paty9m22l3ecm7dpakq2c92ueyununayr 1000000000ustrd --from val1 -y | TRIM_TX @@ -44,7 +47,7 @@ sleep 5 # Create the airdrop, so that the airdrop account can claim tokens echo ">>> Testing multiple airdrop reset and claims flow..." -$STRIDE_MAIN_CMD tx claim create-airdrop stride2 $(date +%s) 30 ustrd --from distributor-test3 -y | TRIM_TX +$STRIDE_MAIN_CMD tx claim create-airdrop stride2 $(date +%s) 180 ustrd --from distributor-test3 -y | TRIM_TX sleep 5 # # Set airdrop allocations $STRIDE_MAIN_CMD tx claim set-airdrop-allocations stride2 stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z 1 --from distributor-test3 -y | TRIM_TX @@ -54,60 +57,42 @@ sleep 5 # # 3. Check eligibility and claim the airdrop echo "> Checking claim record elibility" $STRIDE_MAIN_CMD q claim claim-record stride stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z +$STRIDE_MAIN_CMD q bank balances stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z echo "> Claiming airdrop" $STRIDE_MAIN_CMD tx claim claim-free-amount --from stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z -y | TRIM_TX sleep 5 # # 5. Query to check airdrop vesting account was created (w/ correct amount) echo "Verifying funds are vesting, should be 1." -$STRIDE_MAIN_CMD q claim user-vestings stride1jrmtt5c6z8h5yrrwml488qnm7p3vxrrml2kgvl +$STRIDE_MAIN_CMD q claim user-vestings stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z +$STRIDE_MAIN_CMD q bank balances stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z # BATCH 2 - # 6. Wait 30 seconds -echo "> Waiting 30 seconds for next batch..." -sleep 30 + # 6. Wait 60 seconds +echo "> Waiting 60 seconds for next batch..." +sleep 60 +$STRIDE_MAIN_CMD q claim user-vestings stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z +$STRIDE_MAIN_CMD q bank balances stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z # 7. Claim the airdrop $STRIDE_MAIN_CMD tx claim claim-free-amount --from stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z -y | TRIM_TX # # 8. Query to check airdrop vesting account was created (w/ correct amount) echo "> Verifying more funds are vesting, should be 2." -$STRIDE_MAIN_CMD q claim user-vestings stride1jrmtt5c6z8h5yrrwml488qnm7p3vxrrml2kgvl +$STRIDE_MAIN_CMD q claim user-vestings stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z +$STRIDE_MAIN_CMD q bank balances stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z # # BATCH 3 -# # 10. Wait 30 seconds -echo "> Waiting 30 seconds for next batch..." -sleep 30 +# # 10. Wait 60 seconds +echo "> Waiting 60 seconds for next batch..." +sleep 60 +$STRIDE_MAIN_CMD q claim user-vestings stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z +$STRIDE_MAIN_CMD q bank balances stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z # # 11. Claim the airdrop $STRIDE_MAIN_CMD tx claim claim-free-amount --from stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z -y | TRIM_TX # # 12. Query to check airdrop vesting account was created (w/ correct amount) echo "> Verifying more funds are vesting, should be 3." -$STRIDE_MAIN_CMD q claim user-vestings stride1jrmtt5c6z8h5yrrwml488qnm7p3vxrrml2kgvl - - - - -# ### Test staggered airdrops - -# # create airdrop 1 with a 60 day start window, 60 sec reset, claim, sleep 35 -# # $STRIDE_MAIN_CMD tx claim create-airdrop airdrop1 $(date +%s) 60 ustrd --from distributor-test3 -y -# # sleep 5 -# # $STRIDE_MAIN_CMD tx claim set-airdrop-allocations airdrop1 stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z 1 --from distributor-test3 -y -# # sleep 5 -# # $STRIDE_MAIN_CMD tx claim claim-free-amount --from stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z -# # sleep 35 - -# # # create airdrop 2 with a 60 day start window, 60 sec reset, claim, sleep 35 -# # $STRIDE_MAIN_CMD tx claim create-airdrop airdrop1 $(date +%s) 60 stuatom --from distributor-test3 -y -# # sleep 5 -# # $STRIDE_MAIN_CMD tx claim set-airdrop-allocations airdrop1 stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z 1 --from distributor-test3 -y -# # sleep 5 -# # $STRIDE_MAIN_CMD tx claim claim-free-amount --from stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z -# # sleep 35 - -# # # airdrop 1 resets -# # $STRIDE_MAIN_CMD q bank balances stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z -# # $STRIDE_MAIN_CMD tx claim claim-free-amount --from stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z -# # $STRIDE_MAIN_CMD q bank balances stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z - +# $STRIDE_MAIN_CMD q claim user-vestings stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z +$STRIDE_MAIN_CMD q claim user-vestings stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z +$STRIDE_MAIN_CMD q bank balances stride1kwll0uet4mkj867s4q8dgskp03txgjnswc2u4z diff --git a/dockernet/scripts/airdrop/airdrop4.sh b/dockernet/scripts/airdrop/airdrop4.sh index e15484cbca..672b56cd1a 100644 --- a/dockernet/scripts/airdrop/airdrop4.sh +++ b/dockernet/scripts/airdrop/airdrop4.sh @@ -2,6 +2,7 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source ${SCRIPT_DIR}/../../config.sh +echo $STRIDE_MAIN_CMD # CLEANUP if running tests twice, clear out and re-fund accounts $STRIDE_MAIN_CMD keys delete distributor-test3 -y &> /dev/null || true $STRIDE_MAIN_CMD keys delete distributor-test4 -y &> /dev/null || true From cc27a2026439a05eb0fce76d4a283a8749a765b7 Mon Sep 17 00:00:00 2001 From: Riley Edmunds Date: Wed, 20 Mar 2024 14:15:51 -0400 Subject: [PATCH 2/3] v20 scaffold --- app/upgrades.go | 12 +++++++ app/upgrades/v20/upgrades.go | 57 +++++++++++++++++++++++++++++++ app/upgrades/v20/upgrades_test.go | 24 +++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 app/upgrades/v20/upgrades.go create mode 100644 app/upgrades/v20/upgrades_test.go diff --git a/app/upgrades.go b/app/upgrades.go index afa0dc974f..1391619c1b 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -28,6 +28,7 @@ import ( v18 "github.com/Stride-Labs/stride/v19/app/upgrades/v18" v19 "github.com/Stride-Labs/stride/v19/app/upgrades/v19" v2 "github.com/Stride-Labs/stride/v19/app/upgrades/v2" + v20 "github.com/Stride-Labs/stride/v19/app/upgrades/v20" v3 "github.com/Stride-Labs/stride/v19/app/upgrades/v3" v4 "github.com/Stride-Labs/stride/v19/app/upgrades/v4" v5 "github.com/Stride-Labs/stride/v19/app/upgrades/v5" @@ -263,6 +264,17 @@ func (app *StrideApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) { ), ) + // v20 upgrade handler + app.UpgradeKeeper.SetUpgradeHandler( + v20.UpgradeName, + v20.CreateUpgradeHandler( + app.mm, + app.configurator, + app.appCodec, + app.StakeibcKeeper, + ), + ) + upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() if err != nil { panic(fmt.Errorf("Failed to read upgrade info from disk: %w", err)) diff --git a/app/upgrades/v20/upgrades.go b/app/upgrades/v20/upgrades.go new file mode 100644 index 0000000000..2d12e6cc05 --- /dev/null +++ b/app/upgrades/v20/upgrades.go @@ -0,0 +1,57 @@ +package v20 + +import ( + errorsmod "cosmossdk.io/errors" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + stakeibckeeper "github.com/Stride-Labs/stride/v19/x/stakeibc/keeper" + "github.com/Stride-Labs/stride/v19/x/stakeibc/types" +) + +const ( + UpgradeName = "v20" + dydxCPTreasuryAddress = "dydx15ztc7xy42tn2ukkc0qjthkucw9ac63pgp70urn" + dydxChainId = "dydx-mainnet-1" +) + +// CreateUpgradeHandler creates an SDK upgrade handler for v20 +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + cdc codec.Codec, + stakeIbcKeeper stakeibckeeper.Keeper, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + ctx.Logger().Info("Starting upgrade v20...") + + ctx.Logger().Info("Adding DYDX Community Pool Treasury Address...") + if err := SetDydxCommunityPoolTreasuryAddress(ctx, stakeIbcKeeper); err != nil { + return nil, errorsmod.Wrapf(err, "unable to set dydx community pool treasury address") + } + + return nil, nil + } +} + +// Write the Community Pool Treasury Address to the DYDX host_zone struct +func SetDydxCommunityPoolTreasuryAddress(ctx sdk.Context, stakeIbcKeeper stakeibckeeper.Keeper) error { + + // Get the dydx host_zone + hostZone, found := stakeIbcKeeper.GetHostZone(ctx, dydxChainId) + if !found { + return errorsmod.Wrapf(types.ErrHostZoneNotFound, "user redemption record not found") + } + + // Set the treasury address + // TODO replace with writing to store (types don't work with v19/20) + hostZone.communityPoolTreasuryAddress = dydxCPTreasuryAddress + + // Save the dydx host_zone + stakeIbcKeeper.SetHostZone(ctx, hostZone) + + return nil +} diff --git a/app/upgrades/v20/upgrades_test.go b/app/upgrades/v20/upgrades_test.go new file mode 100644 index 0000000000..bedaf5e8d3 --- /dev/null +++ b/app/upgrades/v20/upgrades_test.go @@ -0,0 +1,24 @@ +package v20_test + +import ( + "testing" + + "github.com/stretchr/testify/suite" + + "github.com/Stride-Labs/stride/v19/app/apptesting" +) + +type UpgradeTestSuite struct { + apptesting.AppTestHelper +} + +func (s *UpgradeTestSuite) SetupTest() { + s.Setup() +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(UpgradeTestSuite)) +} + +func (s *UpgradeTestSuite) TestUpgrade() { +} From 049084f4429e071c2e11f013a9d3c58e1ddcc2f8 Mon Sep 17 00:00:00 2001 From: Riley Edmunds Date: Wed, 20 Mar 2024 14:38:19 -0400 Subject: [PATCH 3/3] sam pr comments --- app/upgrades.go | 1 - app/upgrades/v20/upgrades.go | 17 +---------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/app/upgrades.go b/app/upgrades.go index 1391619c1b..cc1b858fac 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -270,7 +270,6 @@ func (app *StrideApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) { v20.CreateUpgradeHandler( app.mm, app.configurator, - app.appCodec, app.StakeibcKeeper, ), ) diff --git a/app/upgrades/v20/upgrades.go b/app/upgrades/v20/upgrades.go index 2d12e6cc05..7e30049e1d 100644 --- a/app/upgrades/v20/upgrades.go +++ b/app/upgrades/v20/upgrades.go @@ -1,15 +1,11 @@ package v20 import ( - errorsmod "cosmossdk.io/errors" - - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" stakeibckeeper "github.com/Stride-Labs/stride/v19/x/stakeibc/keeper" - "github.com/Stride-Labs/stride/v19/x/stakeibc/types" ) const ( @@ -22,18 +18,14 @@ const ( func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, - cdc codec.Codec, stakeIbcKeeper stakeibckeeper.Keeper, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { ctx.Logger().Info("Starting upgrade v20...") ctx.Logger().Info("Adding DYDX Community Pool Treasury Address...") - if err := SetDydxCommunityPoolTreasuryAddress(ctx, stakeIbcKeeper); err != nil { - return nil, errorsmod.Wrapf(err, "unable to set dydx community pool treasury address") - } - return nil, nil + return mm.RunMigrations(ctx, configurator, vm) } } @@ -41,17 +33,10 @@ func CreateUpgradeHandler( func SetDydxCommunityPoolTreasuryAddress(ctx sdk.Context, stakeIbcKeeper stakeibckeeper.Keeper) error { // Get the dydx host_zone - hostZone, found := stakeIbcKeeper.GetHostZone(ctx, dydxChainId) - if !found { - return errorsmod.Wrapf(types.ErrHostZoneNotFound, "user redemption record not found") - } // Set the treasury address - // TODO replace with writing to store (types don't work with v19/20) - hostZone.communityPoolTreasuryAddress = dydxCPTreasuryAddress // Save the dydx host_zone - stakeIbcKeeper.SetHostZone(ctx, hostZone) return nil }