Skip to content

Commit

Permalink
mint module GenesisState, proto, and v3 no-op migration
Browse files Browse the repository at this point in the history
  • Loading branch information
relyt29 committed Dec 4, 2024
1 parent 7c2b41b commit b54896e
Show file tree
Hide file tree
Showing 8 changed files with 1,084 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#668](https://github.com/allora-network/allora-chain/pull/668) Add stake nil amount validation + added tests + fixed other tests
* [#687](https://github.com/allora-network/allora-chain/pull/687) Fix reputer nonce submission boundaries
* [#690](https://github.com/allora-network/allora-chain/pull/690) Make investor token unlock amounts strictly monotonically increasing
* [#695](https://github.com/allora-network/allora-chain/pull/695) Mint module GenesisState, proto, and v3 no-op migration (follow-on PR to 690)

### Security

Expand Down
915 changes: 915 additions & 0 deletions x/mint/api/mint/v4/genesis.pulsar.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions x/mint/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (k Keeper) InitGenesis(ctx context.Context, ak types.AccountKeeper, data *t
panic(err)
}

if err := k.SetMonthsAlreadyUnlocked(ctx, data.MonthsUnlocked); err != nil {
panic(err)
}

ak.GetModuleAccount(ctx, types.ModuleName)
}

Expand All @@ -54,10 +58,13 @@ func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState {
panic(err)
}

monthsUnlocked := k.GetMonthsAlreadyUnlocked(ctx)

return types.NewGenesisState(
params,
previousRewardEmissionPerUnitStakedToken,
previousBlockEmission,
ecosystemTokensMinted,
monthsUnlocked,
)
}
19 changes: 18 additions & 1 deletion x/mint/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

// ConsensusVersion defines the current x/mint module consensus version.
const ConsensusVersion = 2
const ConsensusVersion = 3

var (
_ module.AppModuleBasic = AppModule{} //nolint:exhaustruct
Expand Down Expand Up @@ -108,6 +108,23 @@ func (am AppModule) IsAppModule() {}
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServiceServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServiceServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper))

// we don't have any data to migrate, so the migration itself is a no-op,
// but it's good to print that we're doing a migration
err := cfg.RegisterMigration(types.ModuleName, 1, func(ctx sdk.Context) error {
ctx.Logger().Info(fmt.Sprintf("MIGRATING %s MODULE FROM VERSION 1 TO VERSION 2", types.ModuleName))
return nil
})
if err != nil {
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err))
}
err = cfg.RegisterMigration(types.ModuleName, 2, func(ctx sdk.Context) error {
ctx.Logger().Info(fmt.Sprintf("MIGRATING %s MODULE FROM VERSION 2 TO VERSION 3", types.ModuleName))
return nil
})
if err != nil {
panic(fmt.Sprintf("failed to migrate x/%s from version 2 to 3: %v", types.ModuleName, err))
}
}

// InitGenesis performs genesis initialization for the mint module. It returns
Expand Down
49 changes: 49 additions & 0 deletions x/mint/proto/mint/v4/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
syntax = "proto3";
package mint.v4;

import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "mint/v1beta1/types.proto";

option go_package = "github.com/allora-network/allora-chain/x/mint/types";

// GenesisState defines the mint module's genesis state.
message GenesisState {
// params defines all the parameters of the module.
mint.v1beta1.Params params = 1 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];

// previous target emission rewards per unit staked token
string previous_reward_emission_per_unit_staked_token = 2 [
(cosmos_proto.scalar) = "cosmos.LegacyDec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];

string previous_block_emission = 3 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];

// number of tokens minted into the ecosystem treasury
string ecosystem_tokens_minted = 4 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];

// number of months already unlocked for investor token vesting purposes
string months_unlocked = 5 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
}
1 change: 1 addition & 0 deletions x/mint/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ var (
ErrNegativeCirculatingSupply = errors.Register(ModuleName, 6, "circulating supply cannot be negative")
ErrNotFound = errors.Register(ModuleName, 7, "not found")
ErrUnauthorized = errors.Register(ModuleName, 8, "unauthorized message signer")
ErrInvalidMonthsUnlocked = errors.Register(ModuleName, 9, "invalid months unlocked")
)
12 changes: 12 additions & 0 deletions x/mint/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ func NewGenesisState(
previousRewardEmissionPerUnitStakedToken math.LegacyDec,
previousBlockEmission math.Int,
ecosystemTokensMinted math.Int,
monthsUnlocked math.Int,
) *GenesisState {
return &GenesisState{
Params: params,
PreviousRewardEmissionPerUnitStakedToken: previousRewardEmissionPerUnitStakedToken,
PreviousBlockEmission: previousBlockEmission,
EcosystemTokensMinted: ecosystemTokensMinted,
MonthsUnlocked: monthsUnlocked,
}
}

Expand All @@ -24,6 +26,7 @@ func DefaultGenesisState() *GenesisState {
PreviousRewardEmissionPerUnitStakedToken: DefaultPreviousRewardEmissionPerUnitStakedToken(),
PreviousBlockEmission: DefaultPreviousBlockEmission(),
EcosystemTokensMinted: DefaultEcosystemTokensMinted(),
MonthsUnlocked: math.NewInt(0),
}
}

Expand All @@ -42,5 +45,14 @@ func ValidateGenesis(data GenesisState) error {
return ErrInvalidEcosystemTokensMinted
}

if data.MonthsUnlocked.IsNegative() {
return ErrInvalidMonthsUnlocked
}

thirtySix := math.NewInt(36)
if data.MonthsUnlocked.GT(thirtySix) {
return ErrInvalidMonthsUnlocked
}

return nil
}
113 changes: 81 additions & 32 deletions x/mint/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b54896e

Please sign in to comment.