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 4 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
31 changes: 27 additions & 4 deletions x/mint/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,42 @@
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
// if maxSupply is not infinite, check against max_supply parameter
if !maxSupply.IsZero() {
if totalStakingSupply.Add(mintedCoins.AmountOf(params.MintDenom)).GT(maxSupply) {
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
// calculate the difference between maxSupply and totalStakingSupply
diff := maxSupply.Sub(totalStakingSupply)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also consider the burned tokens, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that we use total supply from bank, supply is updated every time right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supply doesn't track the burned tokens I guess. If it's not handled, we should track them separately?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but how do we get burned tokens ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

burned tokens are deducted from the total supply in bank, no need to handle anything here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the issue right. Let's say if the max limit is m, x tokens are already burned, the new max-tokens-limit should be m-x since x were minted some of time in the history. Otherwise burning tokens doesn't make sense in this case

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always thought of it differently. That if you reduce the token then it gives you more to mint unless you reduce the total supply. I'm not sure how we will track this otherwise and on existing chains. Is there a need for this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just have 0 address for burning tokens. That way it will not be reduced from Total supply directly but we can have tally of burned tokens. For existing chains, if they are maintaining the data of burned tokens somewhere, they can just include in the upgrade handler to mint those tokens for 0 address. We need to change the burncoins functionality to send it to this 0 address

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I tend to disagree this is an overall change. It's worth talking to users first instead of making the change blindly.

Fixed Show fixed Hide fixed
// 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
}
mintedCoin = mintedCoin.Sub(diffCoin)
Fixed Show fixed Hide fixed
mintedCoins = sdk.NewCoins(mintedCoin)
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
Fixed Show fixed Hide fixed
}
}

// mint coins if maxSupply is infinite or total staking supply is less than maxSupply
if maxSupply.IsZero() || totalStakingSupply.LT(maxSupply) {
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
// 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
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
6 changes: 6 additions & 0 deletions x/mint/proto/cosmos/mint/v1beta1/mint.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ message Params {
];
// expected blocks per year
uint64 blocks_per_year = 6;
// maximum supply for the token
string max_supply = 7 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
}
2 changes: 1 addition & 1 deletion x/mint/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func RandomizedGenState(simState *module.SimulationState) {

mintDenom := simState.BondDenom
blocksPerYear := uint64(60 * 60 * 8766 / 5)
params := types.NewParams(mintDenom, inflationRateChange, inflationMax, inflationMin, goalBonded, blocksPerYear)
params := types.NewParams(mintDenom, inflationRateChange, inflationMax, inflationMin, goalBonded, blocksPerYear, math.ZeroInt())

mintGenesis := types.NewGenesisState(types.InitialMinter(inflation), params)

Expand Down
Loading
Loading