/
keeper.go
87 lines (73 loc) · 2.67 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
82
83
84
85
86
87
package keeper
import (
"fmt"
"time"
"github.com/tendermint/tendermint/libs/log"
"github.com/osmosis-labs/osmosis/osmoutils"
"github.com/osmosis-labs/osmosis/v15/x/incentives/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 sdk.StoreKey
paramSpace paramtypes.Subspace
hooks types.IncentiveHooks
ak types.AccountKeeper
bk types.BankKeeper
lk types.LockupKeeper
ek types.EpochKeeper
ck types.CommunityPoolKeeper
tk types.TxFeesKeeper
clk types.ConcentratedLiquidityKeeper
pmk types.PoolManagerKeeper
pik types.PoolIncentiveKeeper
}
// NewKeeper returns a new instance of the incentive module keeper struct.
func NewKeeper(storeKey sdk.StoreKey, paramSpace paramtypes.Subspace, ak types.AccountKeeper, bk types.BankKeeper, lk types.LockupKeeper, ek types.EpochKeeper, ck types.CommunityPoolKeeper, txfk types.TxFeesKeeper, clk types.ConcentratedLiquidityKeeper, pmk types.PoolManagerKeeper, pik types.PoolIncentiveKeeper) *Keeper {
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}
return &Keeper{
storeKey: storeKey,
paramSpace: paramSpace,
ak: ak,
bk: bk,
lk: lk,
ek: ek,
ck: ck,
pik: pik,
tk: txfk,
pmk: pmk,
clk: clk,
}
}
// 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))
}
// SetLockableDurations sets which lockable durations will be incentivized.
func (k Keeper) SetLockableDurations(ctx sdk.Context, lockableDurations []time.Duration) {
store := ctx.KVStore(k.storeKey)
info := types.LockableDurationsInfo{LockableDurations: lockableDurations}
osmoutils.MustSet(store, types.LockableDurationsKey, &info)
}
// GetLockableDurations returns all incentivized lockable durations.
func (k Keeper) GetLockableDurations(ctx sdk.Context) []time.Duration {
store := ctx.KVStore(k.storeKey)
info := types.LockableDurationsInfo{}
osmoutils.MustGet(store, types.LockableDurationsKey, &info)
return info.LockableDurations
}
// SetPoolIncentivesKeeper sets pool incentives keeper
func (k *Keeper) SetPoolIncentivesKeeper(poolIncentiveKeeper types.PoolIncentiveKeeper) {
k.pik = poolIncentiveKeeper
}