Skip to content

Commit

Permalink
burn code added
Browse files Browse the repository at this point in the history
  • Loading branch information
cgsingh33 committed Nov 11, 2024
1 parent 0371a61 commit da02720
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 40 additions & 1 deletion app/upgrades/mainnet/v15/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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...")
Expand All @@ -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
}

0 comments on commit da02720

Please sign in to comment.