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

feat: Added UpgradeHandler to burn unclaimed airdrop tokens #168

Merged
merged 4 commits into from
Feb 12, 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
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
}
Loading