-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #924 from comdex-official/feature/dev
ics upgrade
- Loading branch information
Showing
5 changed files
with
240 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package v15 | ||
|
||
const ( | ||
UpgradeName = "v15.2.0" | ||
UpgradeHeight = "" | ||
UpgradeInfo = `'{ | ||
"binaries": { | ||
"darwin/arm64":"", | ||
"darwin/x86_64":"", | ||
"linux/arm64":"", | ||
"linux/x86_64":"", | ||
"windows/x86_64":"" | ||
} | ||
}'` | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
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" | ||
ibcconnectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" | ||
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" | ||
ccvconsumerkeeper "github.com/cosmos/interchain-security/v4/x/ccv/consumer/keeper" | ||
consumertypes "github.com/cosmos/interchain-security/v4/x/ccv/consumer/types" | ||
"github.com/spf13/cast" | ||
) | ||
|
||
// CreateUpgradeHandler creates an SDK upgrade handler for v15 | ||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
cdc codec.Codec, | ||
appOpts servertypes.AppOptions, | ||
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...") | ||
ibcKeeper.ConnectionKeeper.SetParams(ctx, ibcconnectiontypes.DefaultParams()) | ||
|
||
fromVM := make(map[string]uint64) | ||
|
||
nodeHome := cast.ToString(appOpts.Get(flags.FlagHome)) | ||
consumerUpgradeGenFile := nodeHome + "/config/ccv.json" | ||
appState, _, err := genutiltypes.GenesisStateFromGenFile(consumerUpgradeGenFile) | ||
if err != nil { | ||
return fromVM, fmt.Errorf("failed to unmarshal genesis state: %w", err) | ||
} | ||
|
||
var consumerGenesis = consumertypes.GenesisState{} | ||
cdc.MustUnmarshalJSON(appState[consumertypes.ModuleName], &consumerGenesis) | ||
|
||
consumerGenesis.PreCCV = true | ||
consumerGenesis.Params.SoftOptOutThreshold = "0.05" | ||
consumerGenesis.Params.RewardDenoms = []string{"ucmdx"} | ||
consumerGenesis.Params.Enabled = true | ||
consumerGenesis.Params.ProviderFeePoolAddrStr = "cosmos1ap0mh6xzfn8943urr84q6ae7zfnar48am2erhd" | ||
consumerGenesis.Params.ConsumerRedistributionFraction = "0.70" | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.