Skip to content

Commit bd764c7

Browse files
likhita-809tac0turtle
authored andcommitted
feat(x/mint): Add max supply param (#19895)
Co-authored-by: Marko <[email protected]>
1 parent c586ff2 commit bd764c7

File tree

16 files changed

+310
-65
lines changed

16 files changed

+310
-65
lines changed

api/cosmos/mint/v1beta1/mint.pulsar.go

Lines changed: 94 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/cosmos/mint/v1beta1/mint.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,10 @@ message Params {
5959
];
6060
// expected blocks per year
6161
uint64 blocks_per_year = 6;
62+
// maximum supply for the token
63+
string max_supply = 7 [
64+
(cosmos_proto.scalar) = "cosmos.Int",
65+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
66+
(gogoproto.nullable) = false
67+
];
6268
}

tests/e2e/mint/grpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (s *E2ETestSuite) TestQueryGRPC() {
2929
&minttypes.QueryParamsResponse{},
3030
&minttypes.QueryParamsResponse{
3131
Params: minttypes.NewParams("stake", math.LegacyNewDecWithPrec(13, 2), math.LegacyNewDecWithPrec(100, 2),
32-
math.LegacyNewDec(1), math.LegacyNewDecWithPrec(67, 2), (60 * 60 * 8766 / 5)),
32+
math.LegacyNewDec(1), math.LegacyNewDecWithPrec(67, 2), (60 * 60 * 8766 / 5), math.ZeroInt()),
3333
},
3434
},
3535
{

tools/benchmark/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ Ref: https://keepachangelog.com/en/1.0.0/
2828
## [v0.2.0-rc.1](https://github.com/cosmos/cosmos-sdk/releases/tag/tools/benchmark/v0.2.0-rc.1) - 2024-12-18
2929

3030
* [#22778](https://github.com/cosmos/cosmos-sdk/pull/22778) - Initial commit
31+
* [19896](https://github.com/cosmos/cosmos-sdk/pull/19896) Added a new max supply genesis param to existing params.
32+

x/mint/README.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,21 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/mint/v1beta1/
140140

141141
The mint module stores its params in state with the prefix of `0x01`,
142142
it can be updated with governance or the address with authority.
143+
**Note:** With the latest update, the addition of the `MaxSupply` parameter allows controlling the maximum supply of tokens minted by the module.
144+
A value of `0` indicates an unlimited supply.
143145

144146
* Params: `mint/params -> legacy_amino(params)`
145147

146148
```protobuf reference
147-
https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/mint/v1beta1/mint.proto#L26-L59
149+
https://github.com/cosmos/cosmos-sdk/blob/7068d0da52d954430054768b2c56aff44666933b/x/mint/proto/cosmos/mint/v1beta1/mint.proto#L26-L68
148150
```
149151

150152
## Begin-Block
151153

152154
Minting parameters are recalculated and inflation paid at the beginning of each block.
153155

156+
The minting logic in the `BeginBlocker` function provides an optional feature for controlling token minting based on the maximum allowable supply (MaxSupply). This feature allows users to adjust the minting process according to their specific requirements and use cases. However, it's important to note that the MaxSupply parameter is independent of the minting process and assumes that any adjustments to the total supply, including burning tokens, are handled by external modules.
157+
154158
### Inflation rate calculation
155159

156160
Inflation rate is calculated using an "inflation calculation function" that's
@@ -213,15 +217,17 @@ BlockProvision(params Params) sdk.Coin {
213217
## Parameters
214218
215219
The minting module contains the following parameters:
220+
Note: `0` indicates unlimited supply for MaxSupply param
216221
217-
| Key | Type | Example |
218-
|---------------------|-----------------|------------------------|
219-
| MintDenom | string | "uatom" |
220-
| InflationRateChange | string (dec) | "0.130000000000000000" |
221-
| InflationMax | string (dec) | "0.200000000000000000" |
222-
| InflationMin | string (dec) | "0.070000000000000000" |
223-
| GoalBonded | string (dec) | "0.670000000000000000" |
224-
| BlocksPerYear | string (uint64) | "6311520" |
222+
| Key | Type | Example |
223+
|---------------------|------------------|------------------------|
224+
| MintDenom | string | "uatom" |
225+
| InflationRateChange | string (dec) | "0.130000000000000000" |
226+
| InflationMax | string (dec) | "0.200000000000000000" |
227+
| InflationMin | string (dec) | "0.070000000000000000" |
228+
| GoalBonded | string (dec) | "0.670000000000000000" |
229+
| BlocksPerYear | string (uint64) | "6311520" |
230+
| MaxSupply | string (math.Int)| "0" |
225231
226232
227233
## Events
@@ -309,6 +315,7 @@ inflation_max: "0.200000000000000000"
309315
inflation_min: "0.070000000000000000"
310316
inflation_rate_change: "0.130000000000000000"
311317
mint_denom: stake
318+
max_supply: "0"
312319
```
313320
314321
### gRPC
@@ -383,7 +390,8 @@ Example Output:
383390
"inflationMax": "200000000000000000",
384391
"inflationMin": "70000000000000000",
385392
"goalBonded": "670000000000000000",
386-
"blocksPerYear": "6311520"
393+
"blocksPerYear": "6311520",
394+
"maxSupply": "0",
387395
}
388396
}
389397
```
@@ -454,7 +462,8 @@ Example Output:
454462
"inflationMax": "200000000000000000",
455463
"inflationMin": "70000000000000000",
456464
"goalBonded": "670000000000000000",
457-
"blocksPerYear": "6311520"
465+
"blocksPerYear": "6311520",
466+
"maxSupply": "0",
458467
}
459468
}
460469
```

x/mint/keeper/abci.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package mint
2+
3+
import (
4+
"context"
5+
6+
"github.com/cosmos/cosmos-sdk/telemetry"
7+
sdk "github.com/cosmos/cosmos-sdk/types"
8+
"github.com/cosmos/cosmos-sdk/x/mint/keeper"
9+
"github.com/cosmos/cosmos-sdk/x/mint/types"
10+
)
11+
12+
// BeginBlocker mints new tokens for the previous block.
13+
func BeginBlocker(ctx context.Context, k keeper.Keeper) error {
14+
defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker)
15+
16+
sdkCtx := sdk.UnwrapSDKContext(ctx)
17+
return k.MintFn(sdkCtx)
18+
}

x/mint/keeper/genesis_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func (s *GenesisTestSuite) TestImportExportGenesis() {
6969
math.LegacyNewDecWithPrec(9, 2),
7070
math.LegacyNewDecWithPrec(69, 2),
7171
uint64(60*60*8766/5),
72+
math.ZeroInt(),
7273
)
7374

7475
s.keeper.InitGenesis(s.sdkCtx, s.accountKeeper, genesisState)

x/mint/keeper/migrator.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package keeper
22

33
import (
4+
"context"
5+
46
sdk "github.com/cosmos/cosmos-sdk/types"
57
"github.com/cosmos/cosmos-sdk/x/mint/exported"
68
v2 "github.com/cosmos/cosmos-sdk/x/mint/migrations/v2"
9+
"github.com/cosmos/cosmos-sdk/x/mint/types"
710
)
811

912
// Migrator is a struct for handling in-place state migrations.
@@ -27,3 +30,24 @@ func NewMigrator(k Keeper, ss exported.Subspace) Migrator {
2730
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
2831
return v2.Migrate(ctx, m.keeper.storeService.OpenKVStore(ctx), m.legacySubspace, m.keeper.cdc)
2932
}
33+
34+
// Migrate2to3 migrates the x/mint module state from the consensus version 2 to
35+
// version 3.
36+
func (m Migrator) Migrate2to3(ctx context.Context) error {
37+
params, err := m.keeper.Params.Get(ctx)
38+
if err != nil {
39+
return err
40+
}
41+
42+
// Initialize the new MaxSupply parameter with the default value
43+
defaultParams := types.DefaultParams()
44+
params.MaxSupply = defaultParams.MaxSupply
45+
46+
// Set the updated params
47+
err = m.keeper.Params.Set(ctx, params)
48+
if err != nil {
49+
return err
50+
}
51+
52+
return nil
53+
}

0 commit comments

Comments
 (0)