Skip to content

Commit

Permalink
Merge pull request #179 from okp4/fix/mint-inflation
Browse files Browse the repository at this point in the history
fix(mint): provide annual inflation rate
  • Loading branch information
amimart authored Oct 7, 2022
2 parents 25316e5 + 7bbd048 commit 5cf87f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
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

0 comments on commit 5cf87f4

Please sign in to comment.