Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
23 changes: 13 additions & 10 deletions x/mint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,15 @@ BlockProvision(params Params) sdk.Coin {

The minting module contains the following parameters:

| 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" |


## Events
Expand Down Expand Up @@ -306,7 +307,8 @@ Example Output:
"inflationMax": "200000000000000000",
"inflationMin": "70000000000000000",
"goalBonded": "670000000000000000",
"blocksPerYear": "6311520"
"blocksPerYear": "6311520",
"maxSupply": "0",
}
}
```
Expand Down Expand Up @@ -377,7 +379,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 @@ -37,19 +37,43 @@ func (k Keeper) BeginBlocker(ctx context.Context, ic types.InflationCalculationF
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

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

path flow from Begin/EndBlock to a panic call path flow from Begin/EndBlock to a panic call path flow from Begin/EndBlock to a panic call path flow from Begin/EndBlock to a panic call path flow from Begin/EndBlock to a panic call

// if maxSupply is not infinite, check against max_supply parameter
if !maxSupply.IsZero() {
if totalSupply.Add(mintedCoins.AmountOf(params.MintDenom)).GT(maxSupply) {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

path flow from Begin/EndBlock to a panic call

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

path flow from Begin/EndBlock to a panic call
// calculate the difference between maxSupply and totalSupply
diff := maxSupply.Sub(totalSupply)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

path flow from Begin/EndBlock to a panic call
// mint the difference
diffCoin := sdk.NewCoin(params.MintDenom, diff)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

path flow from Begin/EndBlock to a panic call
diffCoins := sdk.NewCoins(diffCoin)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

path flow from Begin/EndBlock to a panic call

// mint coins
if err := k.MintCoins(ctx, diffCoins); err != nil {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

path flow from Begin/EndBlock to a panic call path flow from Begin/EndBlock to a panic call path flow from Begin/EndBlock to a panic call path flow from Begin/EndBlock to a panic call path flow from Begin/EndBlock to a panic call
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) {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

path flow from Begin/EndBlock to a panic call

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

path flow from Begin/EndBlock to a panic call
// mint coins
if err := k.MintCoins(ctx, mintedCoins); err != nil {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

path flow from Begin/EndBlock to a panic call path flow from Begin/EndBlock to a panic call path flow from Begin/EndBlock to a panic call path flow from Begin/EndBlock to a panic call path flow from Begin/EndBlock to a panic call
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
26 changes: 25 additions & 1 deletion x/mint/keeper/migrator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package keeper

import "context"
import (
"context"

"cosmossdk.io/math"
)

// Migrator is a struct for handling in-place state migrations.
type Migrator struct {
Expand All @@ -21,3 +25,23 @@ func NewMigrator(k Keeper) Migrator {
func (m Migrator) Migrate1to2(ctx context.Context) error {
return nil
}

// Migrate2to3 migrates the x/mint module state from the consensus version 2 to
// version 3.
func (m Migrator) Migrate2to3(ctx context.Context) error {
params, err := m.keeper.Params.Get(ctx)
if err != nil {
return err
}

// Initialize the new MaxSupply parameter with the default value
params.MaxSupply = math.ZeroInt()

// Set the updated params
err = m.keeper.Params.Set(ctx, params)
if err != nil {
return err
}

return nil
}
1 change: 1 addition & 0 deletions x/mint/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (s *IntegrationTestSuite) TestUpdateParams() {
InflationMin: sdkmath.LegacyNewDecWithPrec(2, 2),
GoalBonded: sdkmath.LegacyNewDecWithPrec(37, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
MaxSupply: sdkmath.ZeroInt(), // infinite supply
},
},
expectErr: false,
Expand Down
Loading