-
Notifications
You must be signed in to change notification settings - Fork 52
/
keeper.go
78 lines (69 loc) · 2.96 KB
/
keeper.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/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/shentufoundation/shentu/v2/x/mint/types"
)
type Keeper struct {
mintkeeper.Keeper
dk types.DistributionKeeper
accountKeeper types.AccountKeeper
stakingKeeper types.StakingKeeper
shieldKeeper types.ShieldKeeper
}
// NewKeeper implements the wrapper newkeeper on top of the original newkeeper with distribution, supply and staking keeper.
func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
sk types.StakingKeeper, ak types.AccountKeeper, bk types.BankKeeper, distributionKeeper types.DistributionKeeper, shieldKeeper types.ShieldKeeper,
feeCollectorName string) Keeper {
return Keeper{
Keeper: mintkeeper.NewKeeper(cdc, key, paramSpace, sk, ak, bk, feeCollectorName),
dk: distributionKeeper,
accountKeeper: ak,
stakingKeeper: sk,
shieldKeeper: shieldKeeper,
}
}
// SendToCommunityPool sends coins to the community pool using FundCommunityPool.
func (k Keeper) SendToCommunityPool(ctx sdk.Context, amount sdk.Coins) error {
if amount.AmountOf(k.stakingKeeper.BondDenom(ctx)).Equal(sdk.ZeroInt()) {
return nil
}
mintAddress := k.accountKeeper.GetModuleAddress(minttypes.ModuleName)
return k.dk.FundCommunityPool(ctx, amount, mintAddress)
}
// SendToShieldRewards sends coins to the shield rewards using FundShieldBlockRewards.
func (k Keeper) SendToShieldRewards(ctx sdk.Context, amount sdk.Coins) error {
if amount.AmountOf(k.stakingKeeper.BondDenom(ctx)).Equal(sdk.ZeroInt()) {
return nil
}
mintAddress := k.accountKeeper.GetModuleAddress(minttypes.ModuleName)
return k.shieldKeeper.FundShieldBlockRewards(ctx, amount, mintAddress)
}
// GetCommunityPoolRatio returns the current ratio of the community pool compared to the total supply.
func (k Keeper) GetCommunityPoolRatio(ctx sdk.Context) sdk.Dec {
communityPool := k.dk.GetFeePool(ctx).CommunityPool
for _, coin := range communityPool {
totalBondedTokensDec := sdk.NewDecFromInt(k.StakingTokenSupply(ctx))
if coin.Denom == k.stakingKeeper.BondDenom(ctx) {
ratio := coin.Amount.Quo(totalBondedTokensDec)
return ratio
}
}
return sdk.NewDec(0)
}
// GetShieldRatio returns the current ratio of
// shield staking pool compared to the total supply.
func (k Keeper) GetShieldRatio(ctx sdk.Context) sdk.Dec {
return k.shieldKeeper.GetShieldBlockRewardRatio(ctx)
}
// GetPoolMint returns Coins that are about to be minted towards the community pool.
func (k Keeper) GetPoolMint(ctx sdk.Context, ratio sdk.Dec, mintedCoin sdk.Coin) sdk.Coin {
communityPoolMintDec := ratio.MulInt(mintedCoin.Amount)
amount := communityPoolMintDec.TruncateInt()
return sdk.NewCoin(k.stakingKeeper.BondDenom(ctx), amount)
}