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 7a994ee commit 0a970f4
Show file tree
Hide file tree
Showing 8 changed files with 1,081 additions and 35 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
cosmossdk.io/store v1.1.1
cosmossdk.io/tools/confix v0.1.2
cosmossdk.io/x/circuit v0.1.1
cosmossdk.io/x/evidence v0.1.1
cosmossdk.io/x/feegrant v0.1.1
cosmossdk.io/x/upgrade v0.1.4
github.com/cockroachdb/apd/v3 v3.2.1
Expand Down Expand Up @@ -64,7 +65,6 @@ require (
cloud.google.com/go/compute/metadata v0.5.0 // indirect
cloud.google.com/go/iam v1.1.9 // indirect
cloud.google.com/go/storage v1.41.0 // indirect
cosmossdk.io/x/evidence v0.1.1 // indirect
cosmossdk.io/x/tx v0.13.5 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
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,
)
}
13 changes: 12 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,17 @@ 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
cfg.RegisterMigration(types.ModuleName, 1, func(ctx sdk.Context) error {

Check failure on line 114 in x/mint/module/module.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `cfg.RegisterMigration` is not checked (errcheck)
ctx.Logger().Info(fmt.Sprintf("MIGRATING %s MODULE FROM VERSION 1 TO VERSION 2", types.ModuleName))
return nil
})
cfg.RegisterMigration(types.ModuleName, 2, func(ctx sdk.Context) error {

Check failure on line 118 in x/mint/module/module.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `cfg.RegisterMigration` is not checked (errcheck)
ctx.Logger().Info(fmt.Sprintf("MIGRATING %s MODULE FROM VERSION 2 TO VERSION 3", types.ModuleName))
return nil
})
}

// 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")
)
16 changes: 15 additions & 1 deletion x/mint/types/genesis.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package types

import "cosmossdk.io/math"
import (
"cosmossdk.io/math"
)

// NewGenesisState creates a new GenesisState object
func NewGenesisState(
params Params,
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 +28,7 @@ func DefaultGenesisState() *GenesisState {
PreviousRewardEmissionPerUnitStakedToken: DefaultPreviousRewardEmissionPerUnitStakedToken(),
PreviousBlockEmission: DefaultPreviousBlockEmission(),
EcosystemTokensMinted: DefaultEcosystemTokensMinted(),
MonthsUnlocked: math.NewInt(0),
}
}

Expand All @@ -42,5 +47,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 0a970f4

Please sign in to comment.