allow for a flexible inflation rate determined by market demand targeting a particular bonded-stake ratio
effect a balance between market liquidity and staked supply
In order to best determine the appropriate market rate for inflation rewards, a
moving change rate is used. The moving change rate mechanism ensures that if
the % bonded is either over or under the goal %-bonded, the inflation rate will
adjust to further incentivize or disincentivize being bonded, respectively. Setting the goal
%-bonded at less than 100% encourages the network to maintain some non-staked tokens
which should help provide some liquidity.It can be broken down in the following way:
If the actual percentage of bonded tokens is below the goal %-bonded the inflation rate will
increase until a maximum value is reached
If the goal % bonded (67% in Cosmos-Hub) is maintained, then the inflation
rate will stay constant
If the actual percentage of bonded tokens is above the goal %-bonded the inflation rate will
decrease until a minimum value is reached
As of Cosmos SDK v0.53.0, developers can set a custom MintFn for the module for specialized token minting logic.The function signature that a MintFn must implement is as follows:
// MintFn defines the function that needs to be implemented in order to customize the minting process.type MintFn func(ctx sdk.Context, k *Keeper)error
This can be passed to the Keeper upon creation with an additional Option:
app.MintKeeper = mintkeeper.NewKeeper( appCodec, runtime.NewKVStoreService(keys[minttypes.StoreKey]), app.StakingKeeper, app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(), // mintkeeper.WithMintFn(CUSTOM_MINT_FN), // custom mintFn can be added here )
Below is a simple approach to creating a custom mint function with extra dependencies in DI configurations.
For this basic example, we will make the minter simply double the supply of foo coin.First, we will define a function that takes our required dependencies, and returns a MintFn.
// MyCustomMintFunction is a custom mint function that doubles the supply of `foo` coin.func MyCustomMintFunction(bank bankkeeper.BaseKeeper)mintkeeper.MintFn { return func(ctx sdk.Context, k *mintkeeper.Keeper)error { supply := bank.GetSupply(ctx, "foo") err := k.MintCoins(ctx, sdk.NewCoins(supply.Add(supply))) if err != nil { return err}return nil}}
Then, pass the function defined above into the depinject.Supply function with the required dependencies.
// NewSimApp returns a reference to an initialized SimApp.func NewSimApp( logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp),) *SimApp { var ( app = &SimApp{}appBuilder *runtime.AppBuilder appConfig = depinject.Configs( AppConfig, depinject.Supply( appOpts, logger, // our custom mint function with the necessary dependency passed in. MyCustomMintFunction(app.BankKeeper), ), ) ) // ...}
Inflation rate is calculated using an “inflation calculation function” that’s
passed to the NewAppModule function. If no function is passed, then the SDK’s
default inflation function will be used (NextInflationRate). In case a custom
inflation calculation logic is needed, this can be achieved by defining and
passing a function that matches InflationCalculationFn’s signature.
type InflationCalculationFn func(ctx sdk.Context, minter Minter, params Params, bondedRatio math.LegacyDec)math.LegacyDec
The target annual inflation rate is recalculated each block.
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%.
NextInflationRate(params Params, bondedRatio math.LegacyDec) (inflation math.LegacyDec) { inflationRateChangePerYear = (1 - bondedRatio/params.GoalBonded) * params.InflationRateChange inflationRateChange = inflationRateChangePerYear/blocksPerYr // increase the new annual inflation for this next block inflation += inflationRateChange if inflation > params.InflationMax { inflation = params.InflationMax} if inflation < params.InflationMin { inflation = params.InflationMin}return inflation}
Calculate the provisions generated for each block based on current annual provisions. The provisions are then minted by the mint module’s ModuleMinterAccount and then transferred to the auth’s FeeCollectorModuleAccount.