Skip to content

Commit

Permalink
feat: Added UpgradeHandler to burn unclaimed airdrop tokens (envadiv#168
Browse files Browse the repository at this point in the history
)

* feat: Added UpgradeHandler to burn coins for a specific address

* chore: made review changes

* chore : updated go docs

* chore: made review changes
  • Loading branch information
vishal-kanna committed Feb 12, 2024
1 parent 0c3181c commit 0bcafb0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
appparams "github.com/envadiv/Passage3D/app/params"
"github.com/envadiv/Passage3D/app/upgrades"
"github.com/envadiv/Passage3D/app/upgrades/v2.2.0"

v3 "github.com/envadiv/Passage3D/app/upgrades/v2.4.0"
"github.com/envadiv/Passage3D/x/claim"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -189,7 +189,7 @@ var (
wasm.ModuleName: {authtypes.Burner},
}

Upgrades = []upgrades.Upgrade{v2.Upgrade}
Upgrades = []upgrades.Upgrade{v2.Upgrade, v3.Upgrade}
)

var (
Expand Down
62 changes: 62 additions & 0 deletions app/upgrades/v2.4.0/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package v2

import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bank "github.com/cosmos/cosmos-sdk/x/bank/keeper"
distribution "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/envadiv/Passage3D/app/upgrades"
claim "github.com/envadiv/Passage3D/x/claim/keeper"
claimtypes "github.com/envadiv/Passage3D/x/claim/types"
)

const Name = "v2.4.0"

var Upgrade = upgrades.Upgrade{
UpgradeName: Name,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: storetypes.StoreUpgrades{},
}

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
_ distribution.Keeper,
bk bank.Keeper,
ak auth.AccountKeeper,
_ claim.Keeper,
) upgradetypes.UpgradeHandler {

return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
if err := ExecuteProposal(ctx, ak, bk); err != nil {
return nil, err
}

return fromVM, nil
}
}

func ExecuteProposal(ctx sdk.Context, ak auth.AccountKeeper, bk bank.Keeper) error {
// get airdrop claim module account
addr := ak.GetModuleAddress(claimtypes.ModuleName)

// get all balances of airdrop claim module account
balances := bk.GetAllBalances(ctx, addr)

// claim module account do not have the burner permissions
// so we are sending it to the another module account and burning the tokens
if err := bk.SendCoinsFromModuleToModule(ctx, claimtypes.ModuleName, govtypes.ModuleName, balances); err != nil {
return err
}

// burn the coins from the module account
err := bk.BurnCoins(ctx, govtypes.ModuleName, balances)
if err != nil {
return err
}
return nil
}

0 comments on commit 0bcafb0

Please sign in to comment.