-
Notifications
You must be signed in to change notification settings - Fork 50
/
abci.go
68 lines (56 loc) · 1.97 KB
/
abci.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package mint
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Minting module event types
const (
EventTypeMint = "mint"
AttributeKeyBondedRatio = "bonded_ratio"
AttributeKeyInflation = "inflation"
AttributeKeyAnnualProvisions = "annual_provisions"
)
// BeginBlocker mints new tokens for the previous block.
func BeginBlocker(ctx sdk.Context, k Keeper) {
// fetch stored minter & params
minter := k.GetMinter(ctx)
params := k.GetParams(ctx)
// recalculate inflation rate
totalBondedTokens := k.StakingTokenSupply(ctx)
bondedRatio := k.BondedRatio(ctx)
minter.Inflation = minter.NextInflationRate(params, bondedRatio)
minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalBondedTokens)
k.SetMinter(ctx, minter)
// mint coins, update supply
mintedCoin := minter.BlockProvision(params)
mintedCoins := sdk.NewCoins(mintedCoin)
err := k.MintCoins(ctx, mintedCoins)
if err != nil {
panic(err)
}
communityPoolRatio := k.GetCommunityPoolRatio(ctx)
communityPoolCoins := k.GetPoolMint(ctx, communityPoolRatio, mintedCoin)
shieldStakeForShieldPoolRatio := k.GetShieldStakeForShieldPoolRatio(ctx)
SPPCoins := k.GetPoolMint(ctx, shieldStakeForShieldPoolRatio, mintedCoin)
collectedFeesCoins := mintedCoins.Sub(communityPoolCoins).Sub(SPPCoins)
// send the minted coins to the fee collector account
if err := k.AddCollectedFees(ctx, collectedFeesCoins); err != nil {
panic(err)
}
if err = k.SendToCommunityPool(ctx, communityPoolCoins); err != nil {
panic(err)
}
if err = k.SendToShieldRewards(ctx, SPPCoins); err != nil {
panic(err)
}
for _, coin := range mintedCoins {
ctx.EventManager().EmitEvent(
sdk.NewEvent(
EventTypeMint,
sdk.NewAttribute(AttributeKeyBondedRatio, bondedRatio.String()),
sdk.NewAttribute(AttributeKeyInflation, minter.Inflation.String()),
sdk.NewAttribute(AttributeKeyAnnualProvisions, minter.AnnualProvisions.String()),
sdk.NewAttribute(sdk.AttributeKeyAmount, coin.Amount.String()),
),
)
}
}