diff --git a/x/tokenomics/keeper/genesis_inflation.go b/x/tokenomics/keeper/genesis_inflation.go index 1406755c9..64a167fc8 100644 --- a/x/tokenomics/keeper/genesis_inflation.go +++ b/x/tokenomics/keeper/genesis_inflation.go @@ -1,23 +1,22 @@ package keeper import ( - "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/elys-network/elys/x/tokenomics/types" ) // SetGenesisInflation set genesisInflation in the store func (k Keeper) SetGenesisInflation(ctx sdk.Context, genesisInflation types.GenesisInflation) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.GenesisInflationKey)) + store := ctx.KVStore(k.storeKey) b := k.cdc.MustMarshal(&genesisInflation) - store.Set([]byte{0}, b) + store.Set([]byte(types.GenesisInflationKey), b) } // GetGenesisInflation returns genesisInflation func (k Keeper) GetGenesisInflation(ctx sdk.Context) (val types.GenesisInflation, found bool) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.GenesisInflationKey)) + store := ctx.KVStore(k.storeKey) - b := store.Get([]byte{0}) + b := store.Get([]byte(types.GenesisInflationKey)) if b == nil { return val, false } @@ -28,6 +27,6 @@ func (k Keeper) GetGenesisInflation(ctx sdk.Context) (val types.GenesisInflation // RemoveGenesisInflation removes genesisInflation from the store func (k Keeper) RemoveGenesisInflation(ctx sdk.Context) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.GenesisInflationKey)) - store.Delete([]byte{0}) + store := ctx.KVStore(k.storeKey) + store.Delete([]byte(types.GenesisInflationKey)) } diff --git a/x/tokenomics/migrations/new_migrator.go b/x/tokenomics/migrations/new_migrator.go new file mode 100644 index 000000000..ffd482db5 --- /dev/null +++ b/x/tokenomics/migrations/new_migrator.go @@ -0,0 +1,13 @@ +package migrations + +import ( + "github.com/elys-network/elys/x/tokenomics/keeper" +) + +type Migrator struct { + keeper keeper.Keeper +} + +func NewMigrator(keeper keeper.Keeper) Migrator { + return Migrator{keeper: keeper} +} diff --git a/x/tokenomics/migrations/v2_migration.go b/x/tokenomics/migrations/v2_migration.go new file mode 100644 index 000000000..ec36f4dca --- /dev/null +++ b/x/tokenomics/migrations/v2_migration.go @@ -0,0 +1,25 @@ +package migrations + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/elys-network/elys/x/tokenomics/types" +) + +func (m Migrator) V2Migration(ctx sdk.Context) error { + // reset genesis inflation param + inflation := types.GenesisInflation{ + Authority: "elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3", + SeedVesting: 6000000000000, + StrategicSalesVesting: 180000000000000, + Inflation: &types.InflationEntry{ + CommunityFund: 9750000000000, + IcsStakingRewards: 0, + LmRewards: 0, + StrategicReserve: 18750000000000, + TeamTokensVested: 0, + }, + } + + m.keeper.SetGenesisInflation(ctx, inflation) + return nil +} diff --git a/x/tokenomics/module.go b/x/tokenomics/module.go index 7222bceef..9e5333d99 100644 --- a/x/tokenomics/module.go +++ b/x/tokenomics/module.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/elys-network/elys/x/tokenomics/client/cli" "github.com/elys-network/elys/x/tokenomics/keeper" + "github.com/elys-network/elys/x/tokenomics/migrations" "github.com/elys-network/elys/x/tokenomics/types" ) @@ -115,6 +116,11 @@ func NewAppModule( func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + m := migrations.NewMigrator(am.keeper) + err := cfg.RegisterMigration(types.ModuleName, 1, m.V2Migration) + if err != nil { + panic(err) + } } // RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) @@ -138,7 +144,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1 -func (AppModule) ConsensusVersion() uint64 { return 1 } +func (AppModule) ConsensusVersion() uint64 { return 2 } // BeginBlock contains the logic that is automatically triggered at the beginning of each block func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}