@@ -3,123 +3,109 @@ package app
33import (
44 "fmt"
55
6- storetypes "github.com/cosmos/cosmos-sdk/store/types"
76 sdk "github.com/cosmos/cosmos-sdk/types"
87 "github.com/cosmos/cosmos-sdk/types/module"
9- "github.com/cosmos/cosmos-sdk/x/group"
10- stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
8+ authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
9+ vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
10+ minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
1111 upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
12- ica "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts"
13- icacontrollertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types"
14- icahosttypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/types"
15- icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types"
16- ibcfeetypes "github.com/cosmos/ibc-go/v5/modules/apps/29-fee/types"
17- icaauthmoduletypes "github.com/crypto-org-chain/chain-main/v4/x/icaauth/types"
18- nfttransfertypes "github.com/crypto-org-chain/chain-main/v4/x/nft-transfer/types"
12+
13+ "github.com/crypto-org-chain/chain-main/v4/config"
1914)
2015
21- func (app * ChainApp ) RegisterUpgradeHandlers () {
22- planName := "v4.2.0"
23- app .UpgradeKeeper .SetUpgradeHandler (planName , func (ctx sdk.Context , _ upgradetypes.Plan , fromVM module.VersionMap ) (module.VersionMap , error ) {
24- // the minimal commission rate of 5% (0.05)
25- // (default is needed to be set because of SDK store migrations that set the param)
26- stakingtypes .DefaultMinCommissionRate = sdk .NewDecWithPrec (5 , 2 )
16+ type VestingAccountSpec struct {
17+ Account string
18+ Periods int
19+ PeriodDuration int64
20+ }
2721
28- app .StakingKeeper .IterateValidators (ctx , func (index int64 , val stakingtypes.ValidatorI ) (stop bool ) {
29- if val .GetCommission ().LT (stakingtypes .DefaultMinCommissionRate ) {
30- validator , found := app .StakingKeeper .GetValidator (ctx , val .GetOperator ())
31- if ! found {
32- ctx .Logger ().Error ("validator not found" , val )
33- return true
34- }
35- ctx .Logger ().Info ("update validator's commission rate to a minimal one" , val )
36- validator .Commission .Rate = stakingtypes .DefaultMinCommissionRate
37- if validator .Commission .MaxRate .LT (stakingtypes .DefaultMinCommissionRate ) {
38- validator .Commission .MaxRate = stakingtypes .DefaultMinCommissionRate
39- }
40- app .StakingKeeper .SetValidator (ctx , validator )
41- }
42- return false
43- })
22+ var (
23+ MintAmount = sdk .NewInt (7000000000000000000 )
24+ VestingSpec = map [string ]VestingAccountSpec {
25+ "chaintest" : {
26+ Account : "cro1jgt29q28ehyc6p0fd5wqhwswfxv59lhppz3v65" ,
27+ Periods : 60 ,
28+ PeriodDuration : 60 ,
29+ },
30+ "testnet-croeseid-4" : {
31+ Account : "tcro1t7y7hzl3spx8pdqfzsmw5u5n3y2fwg2nh9rngm" ,
32+ Periods : 60 ,
33+ PeriodDuration : 600 ,
34+ },
35+ "crypto-org-chain-mainnet-dryrun-1" : {
36+ Account : "cro1jgt29q28ehyc6p0fd5wqhwswfxv59lhppz3v65" ,
37+ Periods : 60 ,
38+ PeriodDuration : 600 ,
39+ },
40+ "crypto-org-chain-mainnet-1" : {
41+ Account : "cro198pra975lcj526974r80fflr6retphnl3l7f4h" ,
42+ Periods : 60 ,
43+ PeriodDuration : 2628000 , // 1 month
44+ },
45+ }
46+ )
4447
45- icaModule := app .mm .Modules [icatypes .ModuleName ].(ica.AppModule )
48+ func (app * ChainApp ) RegisterUpgradeHandlers () {
49+ planName := "v5.0.0"
50+ app .UpgradeKeeper .SetUpgradeHandler (planName , func (ctx sdk.Context , _ upgradetypes.Plan , fromVM module.VersionMap ) (module.VersionMap , error ) {
51+ vestingSpec , ok := VestingSpec [ctx .ChainID ()]
52+ if ! ok {
53+ return nil , fmt .Errorf ("vesting spec not found for chainID %s" , ctx .ChainID ())
54+ }
4655
47- // set the ICS27 consensus version so InitGenesis is not run
48- fromVM [icatypes .ModuleName ] = icaModule .ConsensusVersion ()
56+ params := app .MintKeeper .GetParams (ctx )
57+ params .InflationMax = sdk .NewDecWithPrec (1 , 2 ) // 1%
58+ params .InflationMin = sdk .NewDecWithPrec (85 , 4 ) // 0.85%
59+ app .MintKeeper .SetParams (ctx , params )
4960
50- // create ICS27 Controller submodule params
51- controllerParams := icacontrollertypes.Params {
52- ControllerEnabled : false ,
61+ // Mint 70B CRO
62+ totalAmount := sdk .NewCoins (sdk .NewCoin (config .BaseCoinUnit , MintAmount ))
63+ if err := app .BankKeeper .MintCoins (ctx , minttypes .ModuleName , totalAmount ); err != nil {
64+ return nil , fmt .Errorf ("failed to mint coins: %w" , err )
5365 }
5466
55- // create ICS27 Host submodule params
56- hostParams := icahosttypes.Params {
57- HostEnabled : false ,
58- AllowMessages : []string {
59- "/cosmos.authz.v1beta1.MsgExec" ,
60- "/cosmos.authz.v1beta1.MsgGrant" ,
61- "/cosmos.authz.v1beta1.MsgRevoke" ,
62- "/cosmos.bank.v1beta1.MsgSend" ,
63- "/cosmos.bank.v1beta1.MsgMultiSend" ,
64- "/cosmos.distribution.v1beta1.MsgSetWithdrawAddress" ,
65- "/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission" ,
66- "/cosmos.distribution.v1beta1.MsgFundCommunityPool" ,
67- "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward" ,
68- "/cosmos.gov.v1beta1.MsgVoteWeighted" ,
69- "/cosmos.gov.v1beta1.MsgSubmitProposal" ,
70- "/cosmos.gov.v1beta1.MsgDeposit" ,
71- "/cosmos.gov.v1beta1.MsgVote" ,
72- "/cosmos.staking.v1beta1.MsgCreateValidator" ,
73- "/cosmos.staking.v1beta1.MsgEditValidator" ,
74- "/cosmos.staking.v1beta1.MsgDelegate" ,
75- "/cosmos.staking.v1beta1.MsgUndelegate" ,
76- "/cosmos.staking.v1beta1.MsgBeginRedelegate" ,
77- "/cosmos.staking.v1beta1.MsgCancelUnbondingDelegation" ,
78- "/cosmos.slashing.v1beta1.MsgUnjail" ,
79- "/ibc.applications.transfer.v1.MsgTransfer" ,
80- "/chainmain.nft_transfer.v1.MsgTransfer" ,
81- "/chainmain.nft.v1.MsgBurnNFT" ,
82- "/chainmain.nft.v1.MsgEditNFT" ,
83- "/chainmain.nft.v1.MsgIssueDenom" ,
84- "/chainmain.nft.v1.MsgMintNFT" ,
85- "/chainmain.nft.v1.MsgTransferNFT" ,
86- },
67+ vestingAddr , err := sdk .AccAddressFromBech32 (vestingSpec .Account )
68+ if err != nil {
69+ return nil , fmt .Errorf ("failed to parse vesting address: %w" , err )
8770 }
8871
89- ctx .Logger ().Info ("start to init interchain account module..." )
72+ // Create vesting periods (60 periods)
73+ startTime := ctx .BlockTime ()
9074
91- // initialize ICS27 module
92- icaModule .InitModule (ctx , controllerParams , hostParams )
75+ amountPerPeriod := MintAmount .QuoRaw (int64 (vestingSpec .Periods ))
76+ // the last period keep the remainder
77+ amountLastPeriod := MintAmount .Sub (amountPerPeriod .MulRaw (int64 (vestingSpec .Periods - 1 )))
9378
94- ctx .Logger ().Info ("start to run module migrations..." )
79+ periods := make ([]vesting.Period , vestingSpec .Periods )
80+ for i := 0 ; i < vestingSpec .Periods - 1 ; i ++ {
81+ periods [i ] = vesting.Period {
82+ Length : vestingSpec .PeriodDuration ,
83+ Amount : sdk .NewCoins (sdk .NewCoin (config .BaseCoinUnit , amountPerPeriod )),
84+ }
85+ }
86+ periods [vestingSpec .Periods - 1 ] = vesting.Period {
87+ Length : vestingSpec .PeriodDuration ,
88+ Amount : sdk .NewCoins (sdk .NewCoin (config .BaseCoinUnit , amountLastPeriod )),
89+ }
9590
96- return app .mm .RunMigrations (ctx , app .configurator , fromVM )
97- })
91+ baseAcc := authtypes .NewBaseAccount (vestingAddr , nil , 0 , 0 )
92+ vestingAcc := vesting .NewPeriodicVestingAccount (
93+ baseAcc ,
94+ totalAmount ,
95+ startTime .Unix (),
96+ periods ,
97+ )
98+ app .AccountKeeper .SetAccount (ctx , vestingAcc )
99+
100+ if err := app .BankKeeper .SendCoinsFromModuleToAccount (
101+ ctx ,
102+ minttypes .ModuleName ,
103+ vestingAddr ,
104+ totalAmount ,
105+ ); err != nil {
106+ return nil , fmt .Errorf ("failed to send coins to vesting account: %w" , err )
107+ }
98108
99- // testnets need to do a coordinated upgrade to keep in sync with current mainnet version
100- testnetPlanName := "v4.2.7-testnet"
101- app .UpgradeKeeper .SetUpgradeHandler (testnetPlanName , func (ctx sdk.Context , _ upgradetypes.Plan , fromVM module.VersionMap ) (module.VersionMap , error ) {
102109 return app .mm .RunMigrations (ctx , app .configurator , fromVM )
103110 })
104-
105- upgradeInfo , err := app .UpgradeKeeper .ReadUpgradeInfoFromDisk ()
106- if err != nil {
107- panic (fmt .Sprintf ("failed to read upgrade info from disk %s" , err ))
108- }
109-
110- if upgradeInfo .Name == planName && ! app .UpgradeKeeper .IsSkipHeight (upgradeInfo .Height ) {
111- storeUpgrades := storetypes.StoreUpgrades {
112- Added : []string {
113- group .ModuleName ,
114- icacontrollertypes .StoreKey ,
115- icahosttypes .StoreKey ,
116- icaauthmoduletypes .StoreKey ,
117- ibcfeetypes .StoreKey ,
118- nfttransfertypes .StoreKey ,
119- },
120- }
121-
122- // configure store loader that checks if version == upgradeHeight and applies store upgrades
123- app .SetStoreLoader (upgradetypes .UpgradeStoreLoader (upgradeInfo .Height , & storeUpgrades ))
124- }
125111}
0 commit comments