Skip to content

Commit bd96c8e

Browse files
author
likhita-809
committed
wip
1 parent c7c5b8b commit bd96c8e

File tree

6 files changed

+50
-7
lines changed

6 files changed

+50
-7
lines changed

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
{

x/mint/keeper/abci.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,42 @@ func (k Keeper) BeginBlocker(ctx context.Context, ic types.InflationCalculationF
3737
return err
3838
}
3939

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

46-
// mint coins, update supply
47+
// calculate minted coins
4748
mintedCoin := minter.BlockProvision(params)
4849
mintedCoins := sdk.NewCoins(mintedCoin)
4950

50-
err = k.MintCoins(ctx, mintedCoins)
51-
if err != nil {
52-
return err
51+
maxSupply := params.MaxSupply
52+
// if maxSupply is not infinite, check against max_supply parameter
53+
if !maxSupply.IsZero() {
54+
if totalStakingSupply.Add(mintedCoins.AmountOf(params.MintDenom)).GT(maxSupply) {
55+
// calculate the difference between maxSupply and totalStakingSupply
56+
diff := maxSupply.Sub(totalStakingSupply)
57+
// mint the difference
58+
diffCoin := sdk.NewCoin(params.MintDenom, diff)
59+
diffCoins := sdk.NewCoins(diffCoin)
60+
61+
// mint coins
62+
if err := k.MintCoins(ctx, diffCoins); err != nil {
63+
return err
64+
}
65+
mintedCoin = mintedCoin.Sub(diffCoin)
66+
mintedCoins = sdk.NewCoins(mintedCoin)
67+
}
68+
}
69+
70+
// mint coins if maxSupply is infinite or total staking supply is less than maxSupply
71+
if maxSupply.IsZero() || totalStakingSupply.LT(maxSupply) {
72+
// mint coins
73+
if err := k.MintCoins(ctx, mintedCoins); err != nil {
74+
return err
75+
}
5376
}
5477

5578
// send the minted coins to the fee collector account

x/mint/keeper/genesis_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func (s *GenesisTestSuite) TestImportExportGenesis() {
7171
math.LegacyNewDecWithPrec(9, 2),
7272
math.LegacyNewDecWithPrec(69, 2),
7373
uint64(60*60*8766/5),
74+
math.ZeroInt(),
7475
)
7576

7677
err := s.keeper.InitGenesis(s.sdkCtx, s.accountKeeper, genesisState)

x/mint/keeper/msg_server_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (s *IntegrationTestSuite) TestUpdateParams() {
5353
InflationMin: sdkmath.LegacyNewDecWithPrec(2, 2),
5454
GoalBonded: sdkmath.LegacyNewDecWithPrec(37, 2),
5555
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
56+
MaxSupply: sdkmath.ZeroInt(), // infinite supply
5657
},
5758
},
5859
expectErr: false,

x/mint/simulation/genesis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func RandomizedGenState(simState *module.SimulationState) {
6666

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

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

x/mint/types/params.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import (
1111
)
1212

1313
// NewParams returns Params instance with the given values.
14-
func NewParams(mintDenom string, inflationRateChange, inflationMax, inflationMin, goalBonded math.LegacyDec, blocksPerYear uint64) Params {
14+
func NewParams(mintDenom string, inflationRateChange, inflationMax, inflationMin, goalBonded math.LegacyDec, blocksPerYear uint64, maxSupply math.Int) Params {
1515
return Params{
1616
MintDenom: mintDenom,
1717
InflationRateChange: inflationRateChange,
1818
InflationMax: inflationMax,
1919
InflationMin: inflationMin,
2020
GoalBonded: goalBonded,
2121
BlocksPerYear: blocksPerYear,
22+
MaxSupply: maxSupply,
2223
}
2324
}
2425

@@ -31,6 +32,7 @@ func DefaultParams() Params {
3132
InflationMin: math.LegacyNewDecWithPrec(7, 2),
3233
GoalBonded: math.LegacyNewDecWithPrec(67, 2),
3334
BlocksPerYear: uint64(60 * 60 * 8766 / 5), // assuming 5 second block times
35+
MaxSupply: math.ZeroInt(), // assuming zero is infinite
3436
}
3537
}
3638

@@ -54,6 +56,9 @@ func (p Params) Validate() error {
5456
if err := validateBlocksPerYear(p.BlocksPerYear); err != nil {
5557
return err
5658
}
59+
if err := validateMaxSupply(p.MaxSupply); err != nil {
60+
return err
61+
}
5762
if p.InflationMax.LT(p.InflationMin) {
5863
return fmt.Errorf(
5964
"max inflation (%s) must be greater than or equal to min inflation (%s)",
@@ -168,3 +173,16 @@ func validateBlocksPerYear(i interface{}) error {
168173

169174
return nil
170175
}
176+
177+
func validateMaxSupply(i interface{}) error {
178+
v, ok := i.(math.Int)
179+
if !ok {
180+
return fmt.Errorf("invalid parameter type: %T", i)
181+
}
182+
183+
if v.IsNegative() {
184+
return fmt.Errorf("max supply must be positive: %d", v)
185+
}
186+
187+
return nil
188+
}

0 commit comments

Comments
 (0)