Skip to content

Commit

Permalink
Tokenomics genesis inflation store update (#334)
Browse files Browse the repository at this point in the history
tokenomics genesis inflation store update
  • Loading branch information
jelysn authored Jan 11, 2024
1 parent b3794af commit ef75e4b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
13 changes: 6 additions & 7 deletions x/tokenomics/keeper/genesis_inflation.go
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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))
}
13 changes: 13 additions & 0 deletions x/tokenomics/migrations/new_migrator.go
Original file line number Diff line number Diff line change
@@ -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}
}
25 changes: 25 additions & 0 deletions x/tokenomics/migrations/v2_migration.go
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 7 additions & 1 deletion x/tokenomics/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand All @@ -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) {}
Expand Down

0 comments on commit ef75e4b

Please sign in to comment.