mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-27 00:35:18 +00:00
custom inflation calculation function
This commit is contained in:
parent
58e6e470b6
commit
8849e52f6e
@ -839,7 +839,7 @@ func NewApp(
|
|||||||
// earn.NewAppModule(app.earnKeeper, app.accountKeeper, app.bankKeeper),
|
// earn.NewAppModule(app.earnKeeper, app.accountKeeper, app.bankKeeper),
|
||||||
// router.NewAppModule(app.routerKeeper),
|
// router.NewAppModule(app.routerKeeper),
|
||||||
// nil InflationCalculationFn, use SDK's default inflation function
|
// nil InflationCalculationFn, use SDK's default inflation function
|
||||||
mint.NewAppModule(appCodec, app.mintKeeper, app.accountKeeper, nil, mintSubspace),
|
mint.NewAppModule(appCodec, app.mintKeeper, app.accountKeeper, chaincfg.CustomInflationCalculateFn, mintSubspace),
|
||||||
// community.NewAppModule(app.communityKeeper, app.accountKeeper),
|
// community.NewAppModule(app.communityKeeper, app.accountKeeper),
|
||||||
metrics.NewAppModule(options.TelemetryOptions),
|
metrics.NewAppModule(options.TelemetryOptions),
|
||||||
|
|
||||||
|
48
chaincfg/mint.go
Normal file
48
chaincfg/mint.go
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package chaincfg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/cometbft/cometbft/libs/log"
|
||||||
|
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CustomInflationCalculateFn(ctx sdk.Context, minter minttypes.Minter, params minttypes.Params, bondedRatio sdk.Dec, _ sdk.Dec) sdk.Dec {
|
||||||
|
logger := ctx.Logger()
|
||||||
|
if logger == nil {
|
||||||
|
panic("logger is nil")
|
||||||
|
}
|
||||||
|
return customInflationCalculateFn(logger, minter, params, bondedRatio)
|
||||||
|
}
|
||||||
|
|
||||||
|
func customInflationCalculateFn(logger log.Logger, minter minttypes.Minter, params minttypes.Params, bondedRatio sdk.Dec) sdk.Dec {
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Info(
|
||||||
|
"calculated new annual inflation",
|
||||||
|
"bondedRatio", bondedRatio,
|
||||||
|
"inflation", inflation,
|
||||||
|
"params", params,
|
||||||
|
"minter", minter,
|
||||||
|
)
|
||||||
|
return inflation
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user