/
reward_pool.go
36 lines (29 loc) · 1.54 KB
/
reward_pool.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
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/public-awesome/stargaze/x/curating/types"
)
// GetRewardPool returns the reward pool account.
func (k Keeper) GetRewardPool(ctx sdk.Context) (rewardPool authtypes.ModuleAccountI) {
return k.accountKeeper.GetModuleAccount(ctx, types.RewardPoolName)
}
// GetRewardPoolBalance returns the reward pool balance
func (k Keeper) GetRewardPoolBalance(ctx sdk.Context) sdk.Coin {
return k.bankKeeper.GetBalance(ctx, k.GetRewardPool(ctx).GetAddress(), k.GetParams(ctx).StakeDenom)
}
// InflateRewardPool process the designated inflation to the reward pool
func (k Keeper) InflateRewardPool(ctx sdk.Context) error {
blockInflationAddr := k.accountKeeper.GetModuleAccount(ctx, authtypes.FeeCollectorName).GetAddress()
blockInflation := k.bankKeeper.GetBalance(ctx, blockInflationAddr, k.GetParams(ctx).StakeDenom)
rewardPoolAllocation := k.GetParams(ctx).RewardPoolAllocation
blockInflationDec := sdk.NewDecFromInt(blockInflation.Amount)
rewardAmount := blockInflationDec.Mul(rewardPoolAllocation)
rewardCoin := sdk.NewCoin(k.GetParams(ctx).StakeDenom, rewardAmount.TruncateInt())
return k.bankKeeper.SendCoinsFromModuleToModule(
ctx, authtypes.FeeCollectorName, types.RewardPoolName, sdk.NewCoins(rewardCoin))
}
// InitializeRewardPool sets up the reward pool from genesis
func (k Keeper) InitializeRewardPool(ctx sdk.Context, funds sdk.Coin) error {
return k.bankKeeper.MintCoins(ctx, types.RewardPoolName, sdk.NewCoins(funds))
}