0g-chain/chaincfg/mint.go

40 lines
1.4 KiB
Go
Raw Normal View History

2024-06-09 07:40:37 +00:00
package chaincfg
import (
sdk "github.com/cosmos/cosmos-sdk/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
)
2024-06-16 09:23:29 +00:00
func NextInflationRate(ctx sdk.Context, minter minttypes.Minter, params minttypes.Params, bondedRatio sdk.Dec, circulatingRatio sdk.Dec) sdk.Dec {
2024-06-09 07:40:37 +00:00
// The target annual inflation rate is recalculated for each previsions cycle. The
// inflation is also subject to a rate change (positive or negative) depending on
// the distance from the desired ratio (67%). The maximum rate change possible is
// defined to be 13% per year, however the annual inflation is capped as between
// 7% and 20%.
// (1 - bondedRatio/GoalBonded) * InflationRateChange
inflationRateChangePerYear := sdk.OneDec().
Sub(bondedRatio.Quo(params.GoalBonded)).
Mul(params.InflationRateChange)
inflationRateChange := inflationRateChangePerYear.Quo(sdk.NewDec(int64(params.BlocksPerYear)))
// adjust the new annual inflation for this next cycle
inflation := minter.Inflation.Add(inflationRateChange) // note inflationRateChange may be negative
if inflation.GT(params.InflationMax) {
inflation = params.InflationMax
}
if inflation.LT(params.InflationMin) {
inflation = params.InflationMin
}
2024-06-16 09:23:29 +00:00
ctx.Logger().Debug(
2024-06-09 07:40:37 +00:00
"calculated new annual inflation",
"bondedRatio", bondedRatio,
2024-06-16 09:23:29 +00:00
"circulatingRatio", circulatingRatio,
2024-06-09 07:40:37 +00:00
"inflation", inflation,
"params", params,
"minter", minter,
)
return inflation
}