Some checks failed
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
Build & Push SDK Proto Builder / build (push) Has been cancelled
80 lines
2.1 KiB
Go
80 lines
2.1 KiB
Go
package keeper
|
|
|
|
import (
|
|
"github.com/cosmos/cosmos-sdk/telemetry"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/x/mint/types"
|
|
)
|
|
|
|
// 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
|
|
|
|
// MintFn runs the mintFn of the keeper.
|
|
func (k *Keeper) MintFn(ctx sdk.Context) error {
|
|
return k.mintFn(ctx, k)
|
|
}
|
|
|
|
// DefaultMintFn returns a default mint function.
|
|
// The default MintFn has a requirement on staking as it uses bond to calculate inflation.
|
|
func DefaultMintFn(ic types.InflationCalculationFn) MintFn {
|
|
return func(ctx sdk.Context, k *Keeper) error {
|
|
// fetch stored minter & params
|
|
minter, err := k.Minter.Get(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
params, err := k.Params.Get(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// recalculate inflation rate
|
|
totalStakingSupply, err := k.StakingTokenSupply(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
bondedRatio, err := k.BondedRatio(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
minter.Inflation = ic(ctx, minter, params, bondedRatio)
|
|
minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalStakingSupply)
|
|
if err = k.Minter.Set(ctx, minter); err != nil {
|
|
return err
|
|
}
|
|
|
|
// mint coins, update supply
|
|
mintedCoin := minter.BlockProvision(params)
|
|
mintedCoins := sdk.NewCoins(mintedCoin)
|
|
|
|
err = k.MintCoins(ctx, mintedCoins)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// send the minted coins to the fee collector account
|
|
err = k.AddCollectedFees(ctx, mintedCoins)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if mintedCoin.Amount.IsInt64() {
|
|
defer telemetry.ModuleSetGauge(types.ModuleName, float32(mintedCoin.Amount.Int64()), "minted_tokens")
|
|
}
|
|
|
|
ctx.EventManager().EmitEvent(
|
|
sdk.NewEvent(
|
|
types.EventTypeMint,
|
|
sdk.NewAttribute(types.AttributeKeyBondedRatio, bondedRatio.String()),
|
|
sdk.NewAttribute(types.AttributeKeyInflation, minter.Inflation.String()),
|
|
sdk.NewAttribute(types.AttributeKeyAnnualProvisions, minter.AnnualProvisions.String()),
|
|
sdk.NewAttribute(sdk.AttributeKeyAmount, mintedCoin.Amount.String()),
|
|
),
|
|
)
|
|
|
|
return nil
|
|
}
|
|
}
|