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

fix(mint): provide annual inflation rate #179

Merged
merged 2 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 2 additions & 3 deletions pkg/mint/okp4InflationCalculationFn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

var (
initialInflation = sdk.NewDecWithPrec(15, 2)
initialInflation = sdk.NewDecWithPrec(75, 3)
)

// Okp4InflationCalculationFn is the function used to calculate the inflation for the OKP4 network.
Expand All @@ -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(75, 3),
},
{
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(75, 3),
},
{
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(6, 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.048"),
},
{
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.002111062325329920"),
},
}

Expand Down