-
Notifications
You must be signed in to change notification settings - Fork 1
/
inflation.go
78 lines (64 loc) · 2.21 KB
/
inflation.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
69
70
71
72
73
74
75
76
77
78
package keeper
import (
"github.com/AstraProtocol/astra/v2/cmd/config"
"github.com/AstraProtocol/astra/v2/x/inflation/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// MintAndAllocateInflation performs inflation minting and allocation
func (k Keeper) MintAndAllocateInflation(ctx sdk.Context, coin sdk.Coin) error {
// Mint coins for distribution
if err := k.MintCoins(ctx, coin); err != nil {
return err
}
// Allocate minted coins according to the staking module
return k.AllocateInflation(ctx, coin)
}
// MintCoins implements an alias call to the underlying supply keeper's
// MintCoins to be used in BeginBlocker.
func (k Keeper) MintCoins(ctx sdk.Context, newCoin sdk.Coin) error {
newCoins := sdk.NewCoins(newCoin)
// skip as no coins need to be minted
if newCoins.Empty() {
return nil
}
return k.bankKeeper.MintCoins(ctx, types.ModuleName, newCoins)
}
// AllocateInflation allocates coins from the inflation to external
// modules according to allocation proportions:
// - staking rewards -> sdk `auth` module fee collector
func (k Keeper) AllocateInflation(ctx sdk.Context, mintedCoin sdk.Coin) error {
// Allocate staking rewards into fee collector account
stakingRewardsAmt := sdk.NewCoins(sdk.NewCoin(
mintedCoin.Denom,
mintedCoin.Amount,
))
return k.bankKeeper.SendCoinsFromModuleToModule(
ctx,
types.ModuleName,
k.feeCollectorName,
stakingRewardsAmt,
)
}
// GetCirculatingSupply returns the bank supply.
func (k Keeper) GetCirculatingSupply(ctx sdk.Context) sdk.Dec {
circulatingSupply := k.bankKeeper.GetSupply(ctx, config.BaseDenom).Amount.ToDec()
return circulatingSupply
}
// GetInflationRate returns the inflation rate for the current period.
func (k Keeper) GetInflationRate(ctx sdk.Context) sdk.Dec {
epochMintProvision, _ := k.GetEpochMintProvision(ctx)
if epochMintProvision.IsZero() {
return sdk.ZeroDec()
}
epp := k.GetEpochsPerPeriod(ctx)
if epp == 0 {
return sdk.ZeroDec()
}
epochsPerPeriod := sdk.NewDec(epp)
circulatingSupply := k.GetCirculatingSupply(ctx)
if circulatingSupply.IsZero() {
return sdk.ZeroDec()
}
// epochMintProvision * 365 / circulatingSupply * 100
return epochMintProvision.Mul(epochsPerPeriod).Quo(circulatingSupply).Mul(sdk.NewDec(100))
}