/
keeper.go
81 lines (68 loc) · 2.03 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
79
80
81
package keeper
import (
"fmt"
"github.com/cometbft/cometbft/libs/log"
"github.com/duality-labs/duality/x/incentives/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
// Keeper provides a way to manage incentives module storage.
type Keeper struct {
storeKey storetypes.StoreKey
paramSpace paramtypes.Subspace
hooks types.IncentiveHooks
ak types.AccountKeeper
bk types.BankKeeper
ek types.EpochKeeper
dk types.DexKeeper
distributor Distributor
authority string
}
// NewKeeper returns a new instance of the incentive module keeper struct.
func NewKeeper(
storeKey storetypes.StoreKey,
paramSpace paramtypes.Subspace,
ak types.AccountKeeper,
bk types.BankKeeper,
ek types.EpochKeeper,
dk types.DexKeeper,
authority string,
) *Keeper {
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}
keeper := &Keeper{
storeKey: storeKey,
paramSpace: paramSpace,
ak: ak,
bk: bk,
ek: ek,
dk: dk,
authority: authority,
}
keeper.distributor = NewDistributor(keeper)
return keeper
}
// SetHooks sets the incentives hooks.
func (k *Keeper) SetHooks(ih types.IncentiveHooks) *Keeper {
if k.hooks != nil {
panic("cannot set incentive hooks twice")
}
k.hooks = ih
return k
}
// Logger returns a logger instance for the incentives module.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
// GetModuleBalance returns full balance of the module.
func (k Keeper) GetModuleBalance(ctx sdk.Context) sdk.Coins {
acc := k.ak.GetModuleAccount(ctx, types.ModuleName)
return k.bk.GetAllBalances(ctx, acc.GetAddress())
}
// GetModuleStakedCoins Returns staked balance of the module.
func (k Keeper) GetModuleStakedCoins(ctx sdk.Context) sdk.Coins {
// all not unstaking + not finished unstaking
return k.GetStakes(ctx).GetCoins()
}