From da02720113d2296a35aeda07ed8d1536efddb7e1 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Mon, 11 Nov 2024 18:39:19 +0530 Subject: [PATCH] burn code added --- app/app.go | 3 +- app/upgrades/mainnet/v15/upgrades.go | 41 +++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/app.go b/app/app.go index 8a6ed553c..0694f68a4 100644 --- a/app/app.go +++ b/app/app.go @@ -1612,7 +1612,8 @@ func (a *App) registerUpgradeHandlers(appOptions servertypes.AppOptions) { a.cdc, appOptions, *a.IbcKeeper, &a.ConsumerKeeper, - a.StakingKeeper), + a.StakingKeeper, + a.BankKeeper), ) // When a planned update height is reached, the old binary will panic // writing on disk the height and name of the update that triggered it diff --git a/app/upgrades/mainnet/v15/upgrades.go b/app/upgrades/mainnet/v15/upgrades.go index b25b433e8..d8ea69afd 100644 --- a/app/upgrades/mainnet/v15/upgrades.go +++ b/app/upgrades/mainnet/v15/upgrades.go @@ -2,12 +2,13 @@ package v15 import ( "fmt" - + collectortypes "github.com/comdex-official/comdex/x/collector/types" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -27,6 +28,7 @@ func CreateUpgradeHandler( ibcKeeper ibckeeper.Keeper, consumerKeeper *ccvconsumerkeeper.Keeper, stakingKeeper stakingkeeper.Keeper, + bankKeeper bankkeeper.Keeper, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { ctx.Logger().Info("Starting upgrade main-net v15...") @@ -53,6 +55,43 @@ func CreateUpgradeHandler( consumerKeeper.InitGenesis(ctx, &consumerGenesis) consumerKeeper.SetDistributionTransmissionChannel(ctx, "channel-37") + err = BurnTokensDuringUpgrade(ctx, bankKeeper) + if err != nil { + fmt.Println("failed to burn tokens during upgrade: ", err) + } + return fromVM, nil } } + +func BurnTokensDuringUpgrade(ctx sdk.Context, bankKeeper bankkeeper.Keeper) error { + // Define the amount to burn 12 millions + burnAmount := sdk.NewCoin("ucmdx", sdk.NewInt(12000000000000)) + + // get the address to burn tokens from + address, err := sdk.AccAddressFromBech32("comdex19g5sejtakn5g5avw8yf8x0rcelhkpfvn94n27g") + if err != nil { + panic(fmt.Sprintf("invalid address: %v", err)) + } + + // Check if the account has enough balance + balance := bankKeeper.GetBalance(ctx, address, burnAmount.Denom) + if balance.Amount.LT(burnAmount.Amount) { + return fmt.Errorf("insufficient funds: account has %s but needs %s", balance.Amount, burnAmount.Amount) + } + + // send tokens to collector module to burn + err = bankKeeper.SendCoinsFromAccountToModule(ctx, address, collectortypes.ModuleName, sdk.NewCoins(burnAmount)) + if err != nil { + return fmt.Errorf("error in transfer funds to module") + } + + // burn the tokens + err = bankKeeper.BurnCoins(ctx, collectortypes.ModuleName, sdk.NewCoins(burnAmount)) + if err != nil { + return fmt.Errorf("failed to burn tokens: %w", err) + } + + ctx.Logger().Info("Successfully burned 12 million CMDX during upgrade") + return nil +}