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

burn code added #923

Merged
merged 1 commit into from
Nov 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
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
}
Loading