-
Notifications
You must be signed in to change notification settings - Fork 560
/
keeper.go
119 lines (98 loc) · 3.79 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package poolmanager
import (
sdk "github.com/cosmos/cosmos-sdk/types"
gogotypes "github.com/gogo/protobuf/types"
"github.com/osmosis-labs/osmosis/osmoutils"
"github.com/osmosis-labs/osmosis/v19/x/poolmanager/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
type Keeper struct {
storeKey sdk.StoreKey
gammKeeper types.PoolModuleI
concentratedKeeper types.PoolModuleI
cosmwasmpoolKeeper types.PoolModuleI
poolIncentivesKeeper types.PoolIncentivesKeeperI
bankKeeper types.BankI
accountKeeper types.AccountI
communityPoolKeeper types.CommunityPoolI
// routes is a map to get the pool module by id.
routes map[types.PoolType]types.PoolModuleI
// poolModules is a list of all pool modules.
// It is used when an operation has to be applied to all pool
// modules. Since map iterations are non-deterministic, we
// use this list to ensure deterministic iteration.
poolModules []types.PoolModuleI
paramSpace paramtypes.Subspace
}
func NewKeeper(storeKey sdk.StoreKey, paramSpace paramtypes.Subspace, gammKeeper types.PoolModuleI, concentratedKeeper types.PoolModuleI, cosmwasmpoolKeeper types.PoolModuleI, bankKeeper types.BankI, accountKeeper types.AccountI, communityPoolKeeper types.CommunityPoolI) *Keeper {
// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}
routesMap := map[types.PoolType]types.PoolModuleI{
types.Balancer: gammKeeper,
types.Stableswap: gammKeeper,
types.Concentrated: concentratedKeeper,
types.CosmWasm: cosmwasmpoolKeeper,
}
routesList := []types.PoolModuleI{
gammKeeper, concentratedKeeper, cosmwasmpoolKeeper,
}
return &Keeper{
storeKey: storeKey,
paramSpace: paramSpace,
gammKeeper: gammKeeper,
concentratedKeeper: concentratedKeeper,
cosmwasmpoolKeeper: cosmwasmpoolKeeper,
bankKeeper: bankKeeper,
accountKeeper: accountKeeper,
communityPoolKeeper: communityPoolKeeper,
routes: routesMap,
poolModules: routesList,
}
}
// GetParams returns the total set of poolmanager parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
k.paramSpace.GetParamSet(ctx, ¶ms)
return params
}
// SetParams sets the total set of poolmanager parameters.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, ¶ms)
}
// InitGenesis initializes the poolmanager module's state from a provided genesis
// state.
func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) {
k.SetNextPoolId(ctx, genState.NextPoolId)
if err := genState.Validate(); err != nil {
panic(err)
}
k.SetParams(ctx, genState.Params)
for _, poolRoute := range genState.PoolRoutes {
k.SetPoolRoute(ctx, poolRoute.PoolId, poolRoute.PoolType)
}
}
// ExportGenesis returns the poolmanager module's exported genesis.
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
return &types.GenesisState{
Params: k.GetParams(ctx),
NextPoolId: k.GetNextPoolId(ctx),
PoolRoutes: k.getAllPoolRoutes(ctx),
}
}
// GetNextPoolId returns the next pool id.
func (k Keeper) GetNextPoolId(ctx sdk.Context) uint64 {
store := ctx.KVStore(k.storeKey)
nextPoolId := gogotypes.UInt64Value{}
osmoutils.MustGet(store, types.KeyNextGlobalPoolId, &nextPoolId)
return nextPoolId.Value
}
// SetNextPoolId sets next pool Id.
func (k Keeper) SetNextPoolId(ctx sdk.Context, poolId uint64) {
store := ctx.KVStore(k.storeKey)
osmoutils.MustSet(store, types.KeyNextGlobalPoolId, &gogotypes.UInt64Value{Value: poolId})
}
// SetPoolIncentivesKeeper sets pool incentives keeper
func (k *Keeper) SetPoolIncentivesKeeper(poolIncentivesKeeper types.PoolIncentivesKeeperI) {
k.poolIncentivesKeeper = poolIncentivesKeeper
}