-
Notifications
You must be signed in to change notification settings - Fork 208
/
inflation_calculation.go
39 lines (31 loc) · 1.01 KB
/
inflation_calculation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// CalculateEpochMintProvision returns mint provision per epoch
func CalculateEpochMintProvision(
params Params,
period uint64,
) sdk.Dec {
if params.EpochsPerPeriod == 0 || !params.InflationEnabled || period >= params.MaxPeriod {
return sdk.ZeroDec()
}
// truncating to the nearest integer
x := period
// Calculate the value of the polynomial at x
polynomialValue := polynomial(params.PolynomialFactors, sdk.NewDec(int64(x)))
if polynomialValue.IsNegative() {
// Just to make sure nothing weird occur
return sdk.ZeroDec()
}
return polynomialValue.Quo(sdk.NewDec(int64(params.EpochsPerPeriod)))
}
// Compute the value of x given the polynomial factors
func polynomial(factors []sdk.Dec, x sdk.Dec) sdk.Dec {
result := sdk.ZeroDec()
for i, factor := range factors {
result = result.Add(factor.Mul(x.Power(uint64(len(factors) - i - 1))))
}
// Multiply by 1 million to get the value in unibi
return result.Mul(sdk.NewDec(1_000_000))
}