Skip to content

Commit

Permalink
added airdrop safety checks (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs authored Mar 25, 2023
1 parent d16d7f2 commit a7ebe87
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
22 changes: 22 additions & 0 deletions app/upgrades/v8/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/Stride-Labs/stride/v8/utils"
autopilotkeeper "github.com/Stride-Labs/stride/v8/x/autopilot/keeper"
autopilottypes "github.com/Stride-Labs/stride/v8/x/autopilot/types"
claimkeeper "github.com/Stride-Labs/stride/v8/x/claim/keeper"
"github.com/Stride-Labs/stride/v8/x/claim/types"
claimtypes "github.com/Stride-Labs/stride/v8/x/claim/types"
)

Expand Down Expand Up @@ -46,6 +48,26 @@ func CreateUpgradeHandler(
}
}

// Delete all unofficial airdrops from the store so they don't conflict with the evmos addition
claimParams, err := claimKeeper.GetParams(ctx)
if err != nil {
return vm, errorsmod.Wrapf(err, "unable to get claim parameters")
}

updatedAirdropList := []*types.Airdrop{}
for _, existingAirdrop := range claimParams.Airdrops {
if utils.ContainsString(ResetAirdropIdentifiers, existingAirdrop.AirdropIdentifier) {
updatedAirdropList = append(updatedAirdropList, existingAirdrop)
}
}
updatedClaimsParams := claimtypes.Params{
Airdrops: updatedAirdropList,
}

if err := claimKeeper.SetParams(ctx, updatedClaimsParams); err != nil {
return vm, errorsmod.Wrapf(err, "unable to remove unofficial airdrops")
}

// Add the evmos airdrop
ctx.Logger().Info("Adding evmos airdrop...")
duration := uint64(AirdropDuration.Seconds())
Expand Down
17 changes: 11 additions & 6 deletions app/upgrades/v8/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import (
)

var (
ustrd = "ustrd"
dummyUpgradeHeight = int64(5)
osmoAirdropId = "osmosis"
addresses = []string{
ustrd = "ustrd"
dummyUpgradeHeight = int64(5)
osmoAirdropId = "osmosis"
unofficialAirdropId = "unofficial-airdrop"
addresses = []string{
"stride12a06af3mm5j653446xr4dguacuxfkj293ey2vh",
"stride1udf2vyj5wyjckl7nzqn5a2vh8fpmmcffey92y8",
"stride1uc8ccxy5s2hw55fn8963ukfdycaamq95jqcfnr",
Expand Down Expand Up @@ -60,6 +61,10 @@ func (s *UpgradeTestSuite) SetupStoreBeforeUpgrade() {
AirdropIdentifier: osmoAirdropId,
ClaimedSoFar: sdkmath.NewInt(1000000),
},
{
AirdropIdentifier: unofficialAirdropId, // this should be removed
ClaimedSoFar: sdkmath.NewInt(1000000),
},
},
}
err := s.App.ClaimKeeper.SetParams(s.Ctx, params)
Expand Down Expand Up @@ -97,10 +102,10 @@ func (s *UpgradeTestSuite) SetupStoreBeforeUpgrade() {
func (s *UpgradeTestSuite) CheckStoreAfterUpgrade() {
afterCtx := s.Ctx.WithBlockHeight(dummyUpgradeHeight)

// Check that the evmos airdrop was added
// Check that the evmos airdrop was added and the unofficial airdrop was removed
claimParams, err := s.App.ClaimKeeper.GetParams(s.Ctx)
s.Require().NoError(err, "no error expected when getting params")
s.Require().Len(claimParams.Airdrops, 2, "there should be two airdrops (evmos and osmo)")
s.Require().Len(claimParams.Airdrops, 2, "there should be only two airdrops (evmos and osmo)")
osmoAirdrop := claimParams.Airdrops[0]
evmosAirdrop := claimParams.Airdrops[1]

Expand Down
3 changes: 0 additions & 3 deletions x/claim/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
case *types.MsgClaimFreeAmount:
res, err := msgServer.ClaimFreeAmount(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgCreateAirdrop:
res, err := msgServer.CreateAirdrop(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgDeleteAirdrop:
res, err := msgServer.DeleteAirdrop(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
Expand Down

0 comments on commit a7ebe87

Please sign in to comment.