Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(x/mint): Add max supply param #19896

Merged
merged 16 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 94 additions & 17 deletions api/cosmos/mint/v1beta1/mint.pulsar.go

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

2 changes: 1 addition & 1 deletion tests/e2e/mint/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (s *E2ETestSuite) TestQueryGRPC() {
&minttypes.QueryParamsResponse{},
&minttypes.QueryParamsResponse{
Params: minttypes.NewParams("stake", math.LegacyNewDecWithPrec(13, 2), math.LegacyNewDecWithPrec(100, 2),
math.LegacyNewDec(1), math.LegacyNewDecWithPrec(67, 2), (60 * 60 * 8766 / 5)),
math.LegacyNewDec(1), math.LegacyNewDecWithPrec(67, 2), (60 * 60 * 8766 / 5), math.ZeroInt()),
},
},
{
Expand Down
2 changes: 2 additions & 0 deletions x/mint/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* [19896](https://github.com/cosmos/cosmos-sdk/pull/19896) Added a new max supply genesis param to existing params.

### Improvements

### API Breaking Changes
Expand Down
31 changes: 20 additions & 11 deletions x/mint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,21 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/mint/v1beta1/

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

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

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

## Begin-Block

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

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.

### Inflation rate calculation

Inflation rate is calculated using an "inflation calculation function" that's
Expand Down Expand Up @@ -136,15 +140,17 @@ BlockProvision(params Params) sdk.Coin {
## Parameters

The minting module contains the following parameters:
Note: `0` indicates unlimited supply for MaxSupply param

| Key | Type | Example |
|---------------------|-----------------|------------------------|
| MintDenom | string | "uatom" |
| InflationRateChange | string (dec) | "0.130000000000000000" |
| InflationMax | string (dec) | "0.200000000000000000" |
| InflationMin | string (dec) | "0.070000000000000000" |
| GoalBonded | string (dec) | "0.670000000000000000" |
| BlocksPerYear | string (uint64) | "6311520" |
| Key | Type | Example |
|---------------------|------------------|------------------------|
| MintDenom | string | "uatom" |
| InflationRateChange | string (dec) | "0.130000000000000000" |
| InflationMax | string (dec) | "0.200000000000000000" |
| InflationMin | string (dec) | "0.070000000000000000" |
| GoalBonded | string (dec) | "0.670000000000000000" |
| BlocksPerYear | string (uint64) | "6311520" |
| MaxSupply | string (math.Int)| "0" |
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved


## Events
Expand Down Expand Up @@ -232,6 +238,7 @@ inflation_max: "0.200000000000000000"
inflation_min: "0.070000000000000000"
inflation_rate_change: "0.130000000000000000"
mint_denom: stake
max_supply: "0"
```

### gRPC
Expand Down Expand Up @@ -306,7 +313,8 @@ Example Output:
"inflationMax": "200000000000000000",
"inflationMin": "70000000000000000",
"goalBonded": "670000000000000000",
"blocksPerYear": "6311520"
"blocksPerYear": "6311520",
"maxSupply": "0",
}
}
```
Expand Down Expand Up @@ -377,7 +385,8 @@ Example Output:
"inflationMax": "200000000000000000",
"inflationMin": "70000000000000000",
"goalBonded": "670000000000000000",
"blocksPerYear": "6311520"
"blocksPerYear": "6311520",
"maxSupply": "0",
}
}
```
32 changes: 28 additions & 4 deletions x/mint/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,43 @@
return err
}

// update minter's inflation and annual provisions
minter.Inflation = ic(ctx, minter, params, bondedRatio)
minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalStakingSupply)
if err = k.Minter.Set(ctx, minter); err != nil {
return err
}

// mint coins, update supply
// calculate minted coins
mintedCoin := minter.BlockProvision(params)
mintedCoins := sdk.NewCoins(mintedCoin)

err = k.MintCoins(ctx, mintedCoins)
if err != nil {
return err
maxSupply := params.MaxSupply
totalSupply := k.bankKeeper.GetSupply(ctx, params.MintDenom).Amount // fetch total supply from the bank module
Dismissed Show dismissed Hide dismissed

// if maxSupply is not infinite, check against max_supply parameter
if !maxSupply.IsZero() {
if totalSupply.Add(mintedCoins.AmountOf(params.MintDenom)).GT(maxSupply) {
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
// calculate the difference between maxSupply and totalSupply
diff := maxSupply.Sub(totalSupply)
Dismissed Show dismissed Hide dismissed
// mint the difference
diffCoin := sdk.NewCoin(params.MintDenom, diff)
Dismissed Show dismissed Hide dismissed
diffCoins := sdk.NewCoins(diffCoin)
Dismissed Show dismissed Hide dismissed

// mint coins
if err := k.MintCoins(ctx, diffCoins); err != nil {
Fixed Show fixed Hide fixed
Dismissed Show dismissed Hide dismissed
return err
}
mintedCoins = diffCoins
}
}

// mint coins if maxSupply is infinite or total staking supply is less than maxSupply
if maxSupply.IsZero() || totalSupply.Add(mintedCoins.AmountOf(params.MintDenom)).LT(maxSupply) {
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
// mint coins
if err := k.MintCoins(ctx, mintedCoins); err != nil {
Dismissed Show dismissed Hide dismissed
return err
}
}

// send the minted coins to the fee collector account
Expand Down
1 change: 1 addition & 0 deletions x/mint/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (s *GenesisTestSuite) TestImportExportGenesis() {
math.LegacyNewDecWithPrec(9, 2),
math.LegacyNewDecWithPrec(69, 2),
uint64(60*60*8766/5),
math.ZeroInt(),
)

err := s.keeper.InitGenesis(s.sdkCtx, s.accountKeeper, genesisState)
Expand Down
Loading
Loading