Skip to content

Commit

Permalink
feat(mint): update mint param type (piplabs#182)
Browse files Browse the repository at this point in the history
* feat(mint): update param type

* feat(mint): make param value consistent among example and tests
  • Loading branch information
ezreal1997 authored and leeren committed Oct 10, 2024
1 parent 9b9e582 commit d3efab0
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 41 deletions.
16 changes: 10 additions & 6 deletions client/x/mint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ message Params {
// type of coin to mint
string mint_denom = 1;
// inflation amount per year
uint64 inflations_per_year = 2;
string inflations_per_year = 2 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// expected blocks per year
uint64 blocks_per_year = ;
}
Expand All @@ -58,11 +62,11 @@ type InflationCalculationFn func(ctx sdk.Context, minter Minter, params Params,

The minting module contains the following parameters:

| Key | Type | Example |
|---------------------|-----------------|------------------------------|
| MintDenom | string | "stake" |
| InflationsPerYear | string (dec) | "24625000000000000" |
| BlocksPerYear | string (uint64) | "6311520" |
| Key | Type | Example |
|---------------------|-----------------|----------------------------------------|
| MintDenom | string | "stake" |
| InflationsPerYear | string (dec) | "24625000000000000.000000000000000000" |
| BlocksPerYear | string (uint64) | "6311520" |


## Events
Expand Down
3 changes: 2 additions & 1 deletion client/x/mint/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package keeper_test
import (
"testing"

"cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -62,7 +63,7 @@ func (s *GenesisTestSuite) TestImportExportGenesis() {
genesisState := types.DefaultGenesisState()
genesisState.Params = types.NewParams(
"testDenom",
24625000_000_000_000,
math.LegacyNewDec(24625000000000000.000000000000000000),
uint64(60*60*8766/5),
)

Expand Down
2 changes: 1 addition & 1 deletion client/x/mint/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type InflationCalculationFn func(ctx context.Context, params Params, bondedRatio

// DefaultInflationCalculationFn is the default function used to calculate inflation.
func DefaultInflationCalculationFn(_ context.Context, params Params, _ math.LegacyDec) math.LegacyDec {
return math.LegacyNewDec(int64(params.InflationsPerYear)).Quo(math.LegacyNewDec(int64(params.BlocksPerYear)))
return params.InflationsPerYear.Quo(math.LegacyNewDec(int64(params.BlocksPerYear)))
}

// NewGenesisState creates a new GenesisState object.
Expand Down
80 changes: 50 additions & 30 deletions client/x/mint/types/mint.pb.go

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

8 changes: 7 additions & 1 deletion client/x/mint/types/mint.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package client.x.mint.types;
option go_package = "client/x/mint/types";

import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";

// Params defines the parameters for the x/mint module.
message Params {
Expand All @@ -12,7 +14,11 @@ message Params {
// type of coin to mint
string mint_denom = 1;
// inflation amount per year
uint64 inflations_per_year = 2;
string inflations_per_year = 2 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// expected blocks per year
uint64 blocks_per_year = 3;
}
4 changes: 2 additions & 2 deletions client/x/mint/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// NewParams returns Params instance with the given values.
func NewParams(mintDenom string, inflationsPerYear uint64, blocksPerYear uint64) Params {
func NewParams(mintDenom string, inflationsPerYear math.LegacyDec, blocksPerYear uint64) Params {
return Params{
MintDenom: mintDenom,
InflationsPerYear: inflationsPerYear,
Expand All @@ -25,7 +25,7 @@ func NewParams(mintDenom string, inflationsPerYear uint64, blocksPerYear uint64)
func DefaultParams() Params {
return Params{
MintDenom: sdk.DefaultBondDenom,
InflationsPerYear: 24625000_000_000_000,
InflationsPerYear: math.LegacyNewDec(24625000000000000.000000000000000000),
BlocksPerYear: uint64(60 * 60 * 8766 / 5), // assuming 5 second block times
}
}
Expand Down

0 comments on commit d3efab0

Please sign in to comment.