2018-10-19 11:36:00 -07:00
|
|
|
package mint
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
2019-05-16 08:25:32 -07:00
|
|
|
// mint new tokens for the previous block
|
2019-04-05 13:20:58 -07:00
|
|
|
func BeginBlocker(ctx sdk.Context, k Keeper) {
|
2018-10-19 11:36:00 -07:00
|
|
|
|
2018-12-04 10:17:02 -08:00
|
|
|
// fetch stored minter & params
|
2019-04-05 13:20:58 -07:00
|
|
|
minter := k.GetMinter(ctx)
|
|
|
|
params := k.GetParams(ctx)
|
2018-11-26 04:13:47 -08:00
|
|
|
|
2018-12-04 10:17:02 -08:00
|
|
|
// recalculate inflation rate
|
2019-02-15 07:55:21 -08:00
|
|
|
totalSupply := k.sk.TotalTokens(ctx)
|
2018-10-19 11:36:00 -07:00
|
|
|
bondedRatio := k.sk.BondedRatio(ctx)
|
2018-11-26 04:13:47 -08:00
|
|
|
minter.Inflation = minter.NextInflationRate(params, bondedRatio)
|
|
|
|
minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalSupply)
|
2018-10-19 11:36:00 -07:00
|
|
|
k.SetMinter(ctx, minter)
|
2018-12-04 10:17:02 -08:00
|
|
|
|
|
|
|
// mint coins, add to collected fees, update supply
|
|
|
|
mintedCoin := minter.BlockProvision(params)
|
|
|
|
k.fck.AddCollectedFees(ctx, sdk.Coins{mintedCoin})
|
2019-01-02 12:29:47 -08:00
|
|
|
k.sk.InflateSupply(ctx, mintedCoin.Amount)
|
2018-12-04 10:17:02 -08:00
|
|
|
|
2018-10-19 11:36:00 -07:00
|
|
|
}
|