Skip to content

Commit

Permalink
fix(mint): provide annual inflation rate
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Oct 7, 2022
1 parent 25316e5 commit 608af3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions pkg/mint/okp4InflationCalculationFn.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ var (
// See: https://docs.okp4.network/docs/whitepaper/tokenomics#staking-rewards
func Okp4InflationCalculationFn(ctx sdk.Context, minter minttypes.Minter, params minttypes.Params, _ sdk.Dec) sdk.Dec {
year := uint64(ctx.BlockHeight()) / params.BlocksPerYear
inflationForYear := initialInflation.Mul(params.InflationRateChange.Power(year))

return inflationForYear.QuoInt64Mut(int64(params.BlocksPerYear))
return initialInflation.Mul(params.InflationRateChange.Power(year))
}
10 changes: 5 additions & 5 deletions pkg/mint/okp4InflationCalculationFn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,39 @@ func TestOkp4InflationCalculationFn(t *testing.T) {
blockHeight: 0,
blocksPerYear: 10,
inflationRateChange: .8,
}, want: sdk.NewDecWithPrec(15, 3),
}, want: sdk.NewDecWithPrec(15, 2),
},
{
name: "Inflation for the last block of the first year",
args: args{
blockHeight: 9,
blocksPerYear: 10,
inflationRateChange: .8,
}, want: sdk.NewDecWithPrec(15, 3),
}, want: sdk.NewDecWithPrec(15, 2),
},
{
name: "Inflation for the first block of the second year",
args: args{
blockHeight: 10,
blocksPerYear: 10,
inflationRateChange: .8,
}, want: sdk.NewDecWithPrec(12, 3),
}, want: sdk.NewDecWithPrec(12, 2),
},
{
name: "Inflation for the second block of the third year",
args: args{
blockHeight: 21,
blocksPerYear: 10,
inflationRateChange: .8,
}, want: sdk.MustNewDecFromStr("0.0096"),
}, want: sdk.MustNewDecFromStr("0.096"),
},
{
name: "Inflation for a block in the 16th year",
args: args{
blockHeight: 87899401,
blocksPerYear: 5256000,
inflationRateChange: .8,
}, want: sdk.MustNewDecFromStr("0.000000000803296166"),
}, want: sdk.MustNewDecFromStr("0.004222124650659840"),
},
}

Expand Down

0 comments on commit 608af3f

Please sign in to comment.