-
Notifications
You must be signed in to change notification settings - Fork 578
/
keepers.go
806 lines (729 loc) · 32.7 KB
/
keepers.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
package keepers
import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
"github.com/cosmos/cosmos-sdk/x/distribution"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/params"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
icq "github.com/cosmos/ibc-apps/modules/async-icq/v4"
icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v4/types"
"github.com/osmosis-labs/osmosis/v20/x/cosmwasmpool"
cosmwasmpooltypes "github.com/osmosis-labs/osmosis/v20/x/cosmwasmpool/types"
downtimedetector "github.com/osmosis-labs/osmosis/v20/x/downtime-detector"
downtimetypes "github.com/osmosis-labs/osmosis/v20/x/downtime-detector/types"
"github.com/osmosis-labs/osmosis/v20/x/gamm"
ibcratelimit "github.com/osmosis-labs/osmosis/v20/x/ibc-rate-limit"
ibcratelimittypes "github.com/osmosis-labs/osmosis/v20/x/ibc-rate-limit/types"
"github.com/osmosis-labs/osmosis/v20/x/poolmanager"
poolmanagertypes "github.com/osmosis-labs/osmosis/v20/x/poolmanager/types"
"github.com/osmosis-labs/osmosis/v20/x/protorev"
ibchooks "github.com/osmosis-labs/osmosis/x/ibc-hooks"
ibchookskeeper "github.com/osmosis-labs/osmosis/x/ibc-hooks/keeper"
ibchookstypes "github.com/osmosis-labs/osmosis/x/ibc-hooks/types"
icqkeeper "github.com/cosmos/ibc-apps/modules/async-icq/v4/keeper"
icahost "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/types"
ibctransferkeeper "github.com/cosmos/ibc-go/v4/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
ibcclient "github.com/cosmos/ibc-go/v4/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types"
porttypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"
packetforward "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router"
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/keeper"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/types"
// IBC Transfer: Defines the "transfer" IBC port
transfer "github.com/cosmos/ibc-go/v4/modules/apps/transfer"
_ "github.com/osmosis-labs/osmosis/v20/client/docs/statik"
owasm "github.com/osmosis-labs/osmosis/v20/wasmbinding"
concentratedliquidity "github.com/osmosis-labs/osmosis/v20/x/concentrated-liquidity"
concentratedliquiditytypes "github.com/osmosis-labs/osmosis/v20/x/concentrated-liquidity/types"
gammkeeper "github.com/osmosis-labs/osmosis/v20/x/gamm/keeper"
gammtypes "github.com/osmosis-labs/osmosis/v20/x/gamm/types"
incentiveskeeper "github.com/osmosis-labs/osmosis/v20/x/incentives/keeper"
incentivestypes "github.com/osmosis-labs/osmosis/v20/x/incentives/types"
lockupkeeper "github.com/osmosis-labs/osmosis/v20/x/lockup/keeper"
lockuptypes "github.com/osmosis-labs/osmosis/v20/x/lockup/types"
mintkeeper "github.com/osmosis-labs/osmosis/v20/x/mint/keeper"
minttypes "github.com/osmosis-labs/osmosis/v20/x/mint/types"
poolincentives "github.com/osmosis-labs/osmosis/v20/x/pool-incentives"
poolincentiveskeeper "github.com/osmosis-labs/osmosis/v20/x/pool-incentives/keeper"
poolincentivestypes "github.com/osmosis-labs/osmosis/v20/x/pool-incentives/types"
protorevkeeper "github.com/osmosis-labs/osmosis/v20/x/protorev/keeper"
protorevtypes "github.com/osmosis-labs/osmosis/v20/x/protorev/types"
"github.com/osmosis-labs/osmosis/v20/x/superfluid"
superfluidkeeper "github.com/osmosis-labs/osmosis/v20/x/superfluid/keeper"
superfluidtypes "github.com/osmosis-labs/osmosis/v20/x/superfluid/types"
tokenfactorykeeper "github.com/osmosis-labs/osmosis/v20/x/tokenfactory/keeper"
tokenfactorytypes "github.com/osmosis-labs/osmosis/v20/x/tokenfactory/types"
"github.com/osmosis-labs/osmosis/v20/x/twap"
twaptypes "github.com/osmosis-labs/osmosis/v20/x/twap/types"
"github.com/osmosis-labs/osmosis/v20/x/txfees"
txfeeskeeper "github.com/osmosis-labs/osmosis/v20/x/txfees/keeper"
txfeestypes "github.com/osmosis-labs/osmosis/v20/x/txfees/types"
valsetpref "github.com/osmosis-labs/osmosis/v20/x/valset-pref"
valsetpreftypes "github.com/osmosis-labs/osmosis/v20/x/valset-pref/types"
epochskeeper "github.com/osmosis-labs/osmosis/x/epochs/keeper"
epochstypes "github.com/osmosis-labs/osmosis/x/epochs/types"
)
type AppKeepers struct {
// keepers, by order of initialization
// "Special" keepers
ParamsKeeper *paramskeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
CrisisKeeper *crisiskeeper.Keeper
UpgradeKeeper *upgradekeeper.Keeper
// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper
ScopedICQKeeper capabilitykeeper.ScopedKeeper
// "Normal" keepers
AccountKeeper *authkeeper.AccountKeeper
BankKeeper *bankkeeper.BaseKeeper
AuthzKeeper *authzkeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
DistrKeeper *distrkeeper.Keeper
DowntimeKeeper *downtimedetector.Keeper
SlashingKeeper *slashingkeeper.Keeper
IBCKeeper *ibckeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
ICAHostKeeper *icahostkeeper.Keeper
ICQKeeper *icqkeeper.Keeper
TransferKeeper *ibctransferkeeper.Keeper
EvidenceKeeper *evidencekeeper.Keeper
GAMMKeeper *gammkeeper.Keeper
TwapKeeper *twap.Keeper
LockupKeeper *lockupkeeper.Keeper
EpochsKeeper *epochskeeper.Keeper
IncentivesKeeper *incentiveskeeper.Keeper
ProtoRevKeeper *protorevkeeper.Keeper
MintKeeper *mintkeeper.Keeper
PoolIncentivesKeeper *poolincentiveskeeper.Keeper
TxFeesKeeper *txfeeskeeper.Keeper
SuperfluidKeeper *superfluidkeeper.Keeper
GovKeeper *govkeeper.Keeper
WasmKeeper *wasm.Keeper
ContractKeeper *wasmkeeper.PermissionedKeeper
TokenFactoryKeeper *tokenfactorykeeper.Keeper
PoolManagerKeeper *poolmanager.Keeper
ValidatorSetPreferenceKeeper *valsetpref.Keeper
ConcentratedLiquidityKeeper *concentratedliquidity.Keeper
CosmwasmPoolKeeper *cosmwasmpool.Keeper
// IBC modules
// transfer module
RawIcs20TransferAppModule transfer.AppModule
RateLimitingICS4Wrapper *ibcratelimit.ICS4Wrapper
TransferStack *ibchooks.IBCMiddleware
Ics20WasmHooks *ibchooks.WasmHooks
HooksICS4Wrapper ibchooks.ICS4Middleware
PacketForwardKeeper *packetforwardkeeper.Keeper
// keys to access the substores
keys map[string]*sdk.KVStoreKey
tkeys map[string]*sdk.TransientStoreKey
memKeys map[string]*sdk.MemoryStoreKey
}
// InitNormalKeepers initializes all 'normal' keepers (account, app, bank, auth, staking, distribution, slashing, transfer, gamm, IBC router, pool incentives, governance, mint, txfees keepers).
func (appKeepers *AppKeepers) InitNormalKeepers(
appCodec codec.Codec,
bApp *baseapp.BaseApp,
maccPerms map[string][]string,
wasmDir string,
wasmConfig wasm.Config,
wasmEnabledProposals []wasm.ProposalType,
wasmOpts []wasm.Option,
blockedAddress map[string]bool,
) {
// Add 'normal' keepers
accountKeeper := authkeeper.NewAccountKeeper(
appCodec,
appKeepers.keys[authtypes.StoreKey],
appKeepers.GetSubspace(authtypes.ModuleName),
authtypes.ProtoBaseAccount,
maccPerms,
)
appKeepers.AccountKeeper = &accountKeeper
bankKeeper := bankkeeper.NewBaseKeeper(
appCodec,
appKeepers.keys[banktypes.StoreKey],
appKeepers.AccountKeeper,
appKeepers.GetSubspace(banktypes.ModuleName),
blockedAddress,
)
appKeepers.BankKeeper = &bankKeeper
authzKeeper := authzkeeper.NewKeeper(
appKeepers.keys[authzkeeper.StoreKey],
appCodec,
bApp.MsgServiceRouter(),
)
appKeepers.AuthzKeeper = &authzKeeper
stakingKeeper := stakingkeeper.NewKeeper(
appCodec,
appKeepers.keys[stakingtypes.StoreKey],
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.GetSubspace(stakingtypes.ModuleName),
)
appKeepers.StakingKeeper = &stakingKeeper
distrKeeper := distrkeeper.NewKeeper(
appCodec, appKeepers.keys[distrtypes.StoreKey],
appKeepers.GetSubspace(distrtypes.ModuleName),
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.StakingKeeper,
authtypes.FeeCollectorName,
blockedAddress,
)
appKeepers.DistrKeeper = &distrKeeper
appKeepers.DowntimeKeeper = downtimedetector.NewKeeper(
appKeepers.keys[downtimetypes.StoreKey],
)
slashingKeeper := slashingkeeper.NewKeeper(
appCodec,
appKeepers.keys[slashingtypes.StoreKey],
appKeepers.StakingKeeper,
appKeepers.GetSubspace(slashingtypes.ModuleName),
)
appKeepers.SlashingKeeper = &slashingKeeper
// Create IBC Keeper
appKeepers.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
appKeepers.keys[ibchost.StoreKey],
appKeepers.GetSubspace(ibchost.ModuleName),
appKeepers.StakingKeeper,
appKeepers.UpgradeKeeper,
appKeepers.ScopedIBCKeeper,
)
// Configure the hooks keeper
hooksKeeper := ibchookskeeper.NewKeeper(
appKeepers.keys[ibchookstypes.StoreKey],
appKeepers.GetSubspace(ibchookstypes.ModuleName),
appKeepers.IBCKeeper.ChannelKeeper,
nil,
)
appKeepers.IBCHooksKeeper = hooksKeeper
appKeepers.WireICS20PreWasmKeeper(appCodec, bApp, appKeepers.IBCHooksKeeper)
icaHostKeeper := icahostkeeper.NewKeeper(
appCodec, appKeepers.keys[icahosttypes.StoreKey],
appKeepers.GetSubspace(icahosttypes.SubModuleName),
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.AccountKeeper,
appKeepers.ScopedICAHostKeeper,
bApp.MsgServiceRouter(),
)
appKeepers.ICAHostKeeper = &icaHostKeeper
icaHostIBCModule := icahost.NewIBCModule(*appKeepers.ICAHostKeeper)
// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
// The transferIBC module is replaced by rateLimitingTransferModule
AddRoute(ibctransfertypes.ModuleName, appKeepers.TransferStack)
// Note: the sealing is done after creating wasmd and wiring that up
// ICQ Keeper
icqKeeper := icqkeeper.NewKeeper(
appCodec,
appKeepers.keys[icqtypes.StoreKey],
appKeepers.GetSubspace(icqtypes.ModuleName),
appKeepers.IBCKeeper.ChannelKeeper, // may be replaced with middleware
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.ScopedICQKeeper,
bApp.GRPCQueryRouter(),
)
appKeepers.ICQKeeper = &icqKeeper
// Create Async ICQ module
icqModule := icq.NewIBCModule(*appKeepers.ICQKeeper)
// Add icq modules to IBC router
ibcRouter.AddRoute(icqtypes.ModuleName, icqModule)
// Note: the sealing is done after creating wasmd and wiring that up
// create evidence keeper with router
// If evidence needs to be handled for the app, set routes in router here and seal
appKeepers.EvidenceKeeper = evidencekeeper.NewKeeper(
appCodec,
appKeepers.keys[evidencetypes.StoreKey],
appKeepers.StakingKeeper,
appKeepers.SlashingKeeper,
)
appKeepers.LockupKeeper = lockupkeeper.NewKeeper(
appKeepers.keys[lockuptypes.StoreKey],
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.DistrKeeper, appKeepers.GetSubspace(lockuptypes.ModuleName))
appKeepers.ConcentratedLiquidityKeeper = concentratedliquidity.NewKeeper(
appCodec,
appKeepers.keys[concentratedliquiditytypes.StoreKey],
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.GAMMKeeper,
appKeepers.PoolIncentivesKeeper,
appKeepers.IncentivesKeeper,
appKeepers.LockupKeeper,
appKeepers.DistrKeeper,
appKeepers.GetSubspace(concentratedliquiditytypes.ModuleName),
)
gammKeeper := gammkeeper.NewKeeper(
appCodec, appKeepers.keys[gammtypes.StoreKey],
appKeepers.GetSubspace(gammtypes.ModuleName),
appKeepers.AccountKeeper,
// TODO: Add a mintcoins restriction
appKeepers.BankKeeper, appKeepers.DistrKeeper,
appKeepers.ConcentratedLiquidityKeeper,
appKeepers.PoolIncentivesKeeper,
appKeepers.IncentivesKeeper)
appKeepers.GAMMKeeper = &gammKeeper
appKeepers.ConcentratedLiquidityKeeper.SetGammKeeper(appKeepers.GAMMKeeper)
appKeepers.CosmwasmPoolKeeper = cosmwasmpool.NewKeeper(appCodec, appKeepers.keys[cosmwasmpooltypes.StoreKey], appKeepers.GetSubspace(cosmwasmpooltypes.ModuleName), appKeepers.AccountKeeper, appKeepers.BankKeeper)
appKeepers.PoolManagerKeeper = poolmanager.NewKeeper(
appKeepers.keys[poolmanagertypes.StoreKey],
appKeepers.GetSubspace(poolmanagertypes.ModuleName),
appKeepers.GAMMKeeper,
appKeepers.ConcentratedLiquidityKeeper,
appKeepers.CosmwasmPoolKeeper,
appKeepers.BankKeeper,
appKeepers.AccountKeeper,
appKeepers.DistrKeeper,
appKeepers.StakingKeeper,
appKeepers.ProtoRevKeeper,
)
appKeepers.PoolManagerKeeper.SetStakingKeeper(appKeepers.StakingKeeper)
appKeepers.GAMMKeeper.SetPoolManager(appKeepers.PoolManagerKeeper)
appKeepers.ConcentratedLiquidityKeeper.SetPoolManagerKeeper(appKeepers.PoolManagerKeeper)
appKeepers.CosmwasmPoolKeeper.SetPoolManagerKeeper(appKeepers.PoolManagerKeeper)
appKeepers.TwapKeeper = twap.NewKeeper(
appKeepers.keys[twaptypes.StoreKey],
appKeepers.tkeys[twaptypes.TransientStoreKey],
appKeepers.GetSubspace(twaptypes.ModuleName),
appKeepers.PoolManagerKeeper)
appKeepers.EpochsKeeper = epochskeeper.NewKeeper(appKeepers.keys[epochstypes.StoreKey])
protorevKeeper := protorevkeeper.NewKeeper(
appCodec, appKeepers.keys[protorevtypes.StoreKey],
appKeepers.GetSubspace(protorevtypes.ModuleName),
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.GAMMKeeper,
appKeepers.EpochsKeeper,
appKeepers.PoolManagerKeeper,
appKeepers.ConcentratedLiquidityKeeper,
)
appKeepers.ProtoRevKeeper = &protorevKeeper
appKeepers.PoolManagerKeeper.SetProtorevKeeper(appKeepers.ProtoRevKeeper)
txFeesKeeper := txfeeskeeper.NewKeeper(
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.keys[txfeestypes.StoreKey],
appKeepers.PoolManagerKeeper,
appKeepers.GAMMKeeper,
appKeepers.ProtoRevKeeper,
appKeepers.DistrKeeper,
)
appKeepers.TxFeesKeeper = &txFeesKeeper
appKeepers.IncentivesKeeper = incentiveskeeper.NewKeeper(
appKeepers.keys[incentivestypes.StoreKey],
appKeepers.GetSubspace(incentivestypes.ModuleName),
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.LockupKeeper,
appKeepers.EpochsKeeper,
appKeepers.DistrKeeper,
appKeepers.TxFeesKeeper,
appKeepers.ConcentratedLiquidityKeeper,
appKeepers.PoolManagerKeeper,
appKeepers.PoolIncentivesKeeper,
)
appKeepers.ConcentratedLiquidityKeeper.SetIncentivesKeeper(appKeepers.IncentivesKeeper)
appKeepers.GAMMKeeper.SetIncentivesKeeper(appKeepers.IncentivesKeeper)
mintKeeper := mintkeeper.NewKeeper(
appKeepers.keys[minttypes.StoreKey],
appKeepers.GetSubspace(minttypes.ModuleName),
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.DistrKeeper,
appKeepers.EpochsKeeper,
authtypes.FeeCollectorName,
)
appKeepers.MintKeeper = &mintKeeper
poolIncentivesKeeper := poolincentiveskeeper.NewKeeper(
appKeepers.keys[poolincentivestypes.StoreKey],
appKeepers.GetSubspace(poolincentivestypes.ModuleName),
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.IncentivesKeeper,
appKeepers.DistrKeeper,
appKeepers.PoolManagerKeeper,
appKeepers.EpochsKeeper,
appKeepers.GAMMKeeper,
)
appKeepers.PoolIncentivesKeeper = &poolIncentivesKeeper
appKeepers.PoolManagerKeeper.SetPoolIncentivesKeeper(appKeepers.PoolIncentivesKeeper)
appKeepers.IncentivesKeeper.SetPoolIncentivesKeeper(appKeepers.PoolIncentivesKeeper)
appKeepers.ConcentratedLiquidityKeeper.SetPoolIncentivesKeeper(appKeepers.PoolIncentivesKeeper)
appKeepers.GAMMKeeper.SetPoolIncentivesKeeper(appKeepers.PoolIncentivesKeeper)
tokenFactoryKeeper := tokenfactorykeeper.NewKeeper(
appKeepers.keys[tokenfactorytypes.StoreKey],
appKeepers.GetSubspace(tokenfactorytypes.ModuleName),
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.DistrKeeper,
)
appKeepers.TokenFactoryKeeper = &tokenFactoryKeeper
validatorSetPreferenceKeeper := valsetpref.NewKeeper(
appKeepers.keys[valsetpreftypes.StoreKey],
appKeepers.GetSubspace(valsetpreftypes.ModuleName),
appKeepers.StakingKeeper,
appKeepers.DistrKeeper,
appKeepers.LockupKeeper,
)
appKeepers.ValidatorSetPreferenceKeeper = &validatorSetPreferenceKeeper
appKeepers.SuperfluidKeeper = superfluidkeeper.NewKeeper(
appKeepers.keys[superfluidtypes.StoreKey], appKeepers.GetSubspace(superfluidtypes.ModuleName),
*appKeepers.AccountKeeper, appKeepers.BankKeeper, appKeepers.StakingKeeper, appKeepers.DistrKeeper, appKeepers.EpochsKeeper, appKeepers.LockupKeeper, appKeepers.GAMMKeeper, appKeepers.IncentivesKeeper,
lockupkeeper.NewMsgServerImpl(appKeepers.LockupKeeper), appKeepers.ConcentratedLiquidityKeeper, appKeepers.PoolManagerKeeper, appKeepers.ValidatorSetPreferenceKeeper)
// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
supportedFeatures := "iterator,staking,stargate,osmosis,cosmwasm_1_1,cosmwasm_1_2"
wasmOpts = append(owasm.RegisterCustomPlugins(appKeepers.BankKeeper, appKeepers.TokenFactoryKeeper), wasmOpts...)
wasmOpts = append(owasm.RegisterStargateQueries(*bApp.GRPCQueryRouter(), appCodec), wasmOpts...)
wasmKeeper := wasm.NewKeeper(
appCodec,
appKeepers.keys[wasm.StoreKey],
appKeepers.GetSubspace(wasm.ModuleName),
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.StakingKeeper,
appKeepers.DistrKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.ScopedWasmKeeper,
appKeepers.TransferKeeper,
bApp.MsgServiceRouter(),
bApp.GRPCQueryRouter(),
wasmDir,
wasmConfig,
supportedFeatures,
wasmOpts...,
)
appKeepers.WasmKeeper = &wasmKeeper
appKeepers.CosmwasmPoolKeeper.SetWasmKeeper(appKeepers.WasmKeeper)
// Pass the contract keeper to all the structs (generally ICS4Wrappers for ibc middlewares) that need it
appKeepers.ContractKeeper = wasmkeeper.NewDefaultPermissionKeeper(appKeepers.WasmKeeper)
appKeepers.RateLimitingICS4Wrapper.ContractKeeper = appKeepers.ContractKeeper
appKeepers.Ics20WasmHooks.ContractKeeper = appKeepers.ContractKeeper
appKeepers.CosmwasmPoolKeeper.SetContractKeeper(appKeepers.ContractKeeper)
appKeepers.IBCHooksKeeper.ContractKeeper = appKeepers.ContractKeeper
// set token factory contract keeper
appKeepers.TokenFactoryKeeper.SetContractKeeper(appKeepers.ContractKeeper)
// wire up x/wasm to IBC
ibcRouter.AddRoute(wasm.ModuleName, wasm.NewIBCHandler(appKeepers.WasmKeeper, appKeepers.IBCKeeper.ChannelKeeper, appKeepers.IBCKeeper.ChannelKeeper))
// Seal the router
appKeepers.IBCKeeper.SetRouter(ibcRouter)
// register the proposal types
govRouter := govtypes.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(*appKeepers.ParamsKeeper)).
AddRoute(distrtypes.RouterKey, distribution.NewCommunityPoolSpendProposalHandler(*appKeepers.DistrKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(*appKeepers.UpgradeKeeper)).
AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper)).
AddRoute(poolincentivestypes.RouterKey, poolincentives.NewPoolIncentivesProposalHandler(*appKeepers.PoolIncentivesKeeper)).
AddRoute(txfeestypes.RouterKey, txfees.NewUpdateFeeTokenProposalHandler(*appKeepers.TxFeesKeeper)).
AddRoute(superfluidtypes.RouterKey, superfluid.NewSuperfluidProposalHandler(*appKeepers.SuperfluidKeeper, *appKeepers.EpochsKeeper, *appKeepers.GAMMKeeper)).
AddRoute(protorevtypes.RouterKey, protorev.NewProtoRevProposalHandler(*appKeepers.ProtoRevKeeper)).
AddRoute(gammtypes.RouterKey, gamm.NewGammProposalHandler(*appKeepers.GAMMKeeper)).
AddRoute(concentratedliquiditytypes.RouterKey, concentratedliquidity.NewConcentratedLiquidityProposalHandler(*appKeepers.ConcentratedLiquidityKeeper)).
AddRoute(cosmwasmpooltypes.RouterKey, cosmwasmpool.NewCosmWasmPoolProposalHandler(*appKeepers.CosmwasmPoolKeeper)).
AddRoute(poolmanagertypes.RouterKey, poolmanager.NewPoolManagerProposalHandler(*appKeepers.PoolManagerKeeper)).
AddRoute(incentivestypes.RouterKey, incentiveskeeper.NewIncentivesProposalHandler(*appKeepers.IncentivesKeeper))
// The gov proposal types can be individually enabled
if len(wasmEnabledProposals) != 0 {
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(appKeepers.WasmKeeper, wasmEnabledProposals))
}
govKeeper := govkeeper.NewKeeper(
appCodec, appKeepers.keys[govtypes.StoreKey],
appKeepers.GetSubspace(govtypes.ModuleName), appKeepers.AccountKeeper, appKeepers.BankKeeper,
appKeepers.SuperfluidKeeper, govRouter)
appKeepers.GovKeeper = &govKeeper
}
// WireICS20PreWasmKeeper Create the IBC Transfer Stack from bottom to top:
//
// * SendPacket. Originates from the transferKeeper and goes up the stack:
// transferKeeper.SendPacket -> ibc_rate_limit.SendPacket -> ibc_hooks.SendPacket -> channel.SendPacket
// * RecvPacket, message that originates from core IBC and goes down to app, the flow is the other way
// channel.RecvPacket -> ibc_hooks.OnRecvPacket -> ibc_rate_limit.OnRecvPacket -> forward.OnRecvPacket -> transfer.OnRecvPacket
//
// Note that the forward middleware is only integrated on the "reveive" direction. It can be safely skipped when sending.
// Note also that the forward middleware is called "router", but we are using the name "forward" for clarity
// This may later be renamed upstream: https://github.com/ibc-apps/middleware/packet-forward-middleware/issues/10
//
// After this, the wasm keeper is required to be set on both
// appkeepers.WasmHooks AND appKeepers.RateLimitingICS4Wrapper
func (appKeepers *AppKeepers) WireICS20PreWasmKeeper(
appCodec codec.Codec,
bApp *baseapp.BaseApp,
hooksKeeper *ibchookskeeper.Keeper,
) {
// Setup the ICS4Wrapper used by the hooks middleware
osmoPrefix := sdk.GetConfig().GetBech32AccountAddrPrefix()
wasmHooks := ibchooks.NewWasmHooks(hooksKeeper, nil, osmoPrefix) // The contract keeper needs to be set later
appKeepers.Ics20WasmHooks = &wasmHooks
appKeepers.HooksICS4Wrapper = ibchooks.NewICS4Middleware(
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.Ics20WasmHooks,
)
// ChannelKeeper wrapper for rate limiting SendPacket(). The wasmKeeper needs to be added after it's created
rateLimitingICS4Wrapper := ibcratelimit.NewICS4Middleware(
appKeepers.HooksICS4Wrapper,
appKeepers.AccountKeeper,
// wasm keeper we set later.
nil,
appKeepers.BankKeeper,
appKeepers.GetSubspace(ibcratelimittypes.ModuleName),
)
appKeepers.RateLimitingICS4Wrapper = &rateLimitingICS4Wrapper
// Create Transfer Keepers
transferKeeper := ibctransferkeeper.NewKeeper(
appCodec,
appKeepers.keys[ibctransfertypes.StoreKey],
appKeepers.GetSubspace(ibctransfertypes.ModuleName),
// The ICS4Wrapper is replaced by the rateLimitingICS4Wrapper instead of the channel
appKeepers.RateLimitingICS4Wrapper,
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.ScopedTransferKeeper,
)
appKeepers.TransferKeeper = &transferKeeper
appKeepers.RawIcs20TransferAppModule = transfer.NewAppModule(*appKeepers.TransferKeeper)
// Packet Forward Middleware
// Initialize packet forward middleware router
appKeepers.PacketForwardKeeper = packetforwardkeeper.NewKeeper(
appCodec,
appKeepers.keys[packetforwardtypes.StoreKey],
appKeepers.GetSubspace(packetforwardtypes.ModuleName),
appKeepers.TransferKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.DistrKeeper,
appKeepers.BankKeeper,
// The ICS4Wrapper is replaced by the HooksICS4Wrapper instead of the channel so that sending can be overridden by the middleware
appKeepers.HooksICS4Wrapper,
)
packetForwardMiddleware := packetforward.NewIBCMiddleware(
transfer.NewIBCModule(*appKeepers.TransferKeeper),
appKeepers.PacketForwardKeeper,
0,
packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp,
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp,
)
// RateLimiting IBC Middleware
rateLimitingTransferModule := ibcratelimit.NewIBCModule(packetForwardMiddleware, appKeepers.RateLimitingICS4Wrapper)
// Hooks Middleware
hooksTransferModule := ibchooks.NewIBCMiddleware(&rateLimitingTransferModule, &appKeepers.HooksICS4Wrapper)
appKeepers.TransferStack = &hooksTransferModule
}
// InitSpecialKeepers initiates special keepers (crisis appkeeper, upgradekeeper, params keeper)
func (appKeepers *AppKeepers) InitSpecialKeepers(
appCodec codec.Codec,
bApp *baseapp.BaseApp,
wasmDir string,
cdc *codec.LegacyAmino,
invCheckPeriod uint,
skipUpgradeHeights map[int64]bool,
homePath string,
) {
appKeepers.GenerateKeys()
paramsKeeper := appKeepers.initParamsKeeper(appCodec, cdc, appKeepers.keys[paramstypes.StoreKey], appKeepers.tkeys[paramstypes.TStoreKey])
appKeepers.ParamsKeeper = ¶msKeeper
// set the BaseApp's parameter store
bApp.SetParamStore(appKeepers.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable()))
// add capability keeper and ScopeToModule for ibc module
appKeepers.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, appKeepers.keys[capabilitytypes.StoreKey], appKeepers.memKeys[capabilitytypes.MemStoreKey])
appKeepers.ScopedIBCKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
appKeepers.ScopedICAHostKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
appKeepers.ScopedTransferKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
appKeepers.ScopedWasmKeeper = appKeepers.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
appKeepers.ScopedICQKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icqtypes.ModuleName)
appKeepers.CapabilityKeeper.Seal()
// TODO: Make a SetInvCheckPeriod fn on CrisisKeeper.
// IMO, its bad design atm that it requires this in state machine initialization
crisisKeeper := crisiskeeper.NewKeeper(
appKeepers.GetSubspace(crisistypes.ModuleName), invCheckPeriod, appKeepers.BankKeeper, authtypes.FeeCollectorName,
)
appKeepers.CrisisKeeper = &crisisKeeper
upgradeKeeper := upgradekeeper.NewKeeper(
skipUpgradeHeights,
appKeepers.keys[upgradetypes.StoreKey],
appCodec,
homePath,
bApp,
)
appKeepers.UpgradeKeeper = &upgradeKeeper
}
// initParamsKeeper init params keeper and its subspaces.
func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)
paramsKeeper.Subspace(authtypes.ModuleName)
paramsKeeper.Subspace(banktypes.ModuleName)
paramsKeeper.Subspace(stakingtypes.ModuleName)
paramsKeeper.Subspace(minttypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(incentivestypes.ModuleName)
paramsKeeper.Subspace(lockuptypes.ModuleName)
paramsKeeper.Subspace(poolincentivestypes.ModuleName)
paramsKeeper.Subspace(protorevtypes.ModuleName)
paramsKeeper.Subspace(superfluidtypes.ModuleName)
paramsKeeper.Subspace(poolmanagertypes.ModuleName)
paramsKeeper.Subspace(gammtypes.ModuleName)
paramsKeeper.Subspace(wasm.ModuleName)
paramsKeeper.Subspace(tokenfactorytypes.ModuleName)
paramsKeeper.Subspace(twaptypes.ModuleName)
paramsKeeper.Subspace(ibcratelimittypes.ModuleName)
paramsKeeper.Subspace(concentratedliquiditytypes.ModuleName)
paramsKeeper.Subspace(icqtypes.ModuleName)
paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())
paramsKeeper.Subspace(cosmwasmpooltypes.ModuleName)
paramsKeeper.Subspace(ibchookstypes.ModuleName)
return paramsKeeper
}
// SetupHooks sets up hooks for modules.
func (appKeepers *AppKeepers) SetupHooks() {
// For every module that has hooks set on it,
// you must check InitNormalKeepers to ensure that its not passed by de-reference
// e.g. *app.StakingKeeper doesn't appear
// Recall that SetHooks is a mutative call.
appKeepers.BankKeeper.SetHooks(
banktypes.NewMultiBankHooks(
appKeepers.TokenFactoryKeeper.Hooks(),
),
)
appKeepers.StakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(
appKeepers.DistrKeeper.Hooks(),
appKeepers.SlashingKeeper.Hooks(),
appKeepers.SuperfluidKeeper.Hooks(),
),
)
appKeepers.GAMMKeeper.SetHooks(
gammtypes.NewMultiGammHooks(
// insert gamm hooks receivers here
appKeepers.PoolIncentivesKeeper.Hooks(),
appKeepers.TwapKeeper.GammHooks(),
appKeepers.ProtoRevKeeper.Hooks(),
),
)
appKeepers.ConcentratedLiquidityKeeper.SetListeners(
concentratedliquiditytypes.NewConcentratedLiquidityListeners(
appKeepers.TwapKeeper.ConcentratedLiquidityListener(),
appKeepers.PoolIncentivesKeeper.Hooks(),
appKeepers.ProtoRevKeeper.Hooks(),
),
)
appKeepers.LockupKeeper.SetHooks(
lockuptypes.NewMultiLockupHooks(
// insert lockup hooks receivers here
appKeepers.SuperfluidKeeper.Hooks(),
),
)
appKeepers.IncentivesKeeper.SetHooks(
incentivestypes.NewMultiIncentiveHooks(
// insert incentive hooks receivers here
),
)
appKeepers.MintKeeper.SetHooks(
minttypes.NewMultiMintHooks(
// insert mint hooks receivers here
appKeepers.PoolIncentivesKeeper.Hooks(),
),
)
appKeepers.EpochsKeeper.SetHooks(
epochstypes.NewMultiEpochHooks(
// insert epoch hooks receivers here
appKeepers.TxFeesKeeper.Hooks(),
appKeepers.TwapKeeper.EpochHooks(),
appKeepers.SuperfluidKeeper.Hooks(),
appKeepers.IncentivesKeeper.Hooks(),
appKeepers.MintKeeper.Hooks(),
appKeepers.ProtoRevKeeper.EpochHooks(),
),
)
appKeepers.GovKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// insert governance hooks receivers here
),
)
}
// TODO: We need to automate this, by bundling with a module struct...
func KVStoreKeys() []string {
return []string{
authtypes.StoreKey,
banktypes.StoreKey,
stakingtypes.StoreKey,
minttypes.StoreKey,
distrtypes.StoreKey,
downtimetypes.StoreKey,
slashingtypes.StoreKey,
govtypes.StoreKey,
paramstypes.StoreKey,
ibchost.StoreKey,
icahosttypes.StoreKey,
upgradetypes.StoreKey,
evidencetypes.StoreKey,
ibctransfertypes.StoreKey,
capabilitytypes.StoreKey,
gammtypes.StoreKey,
twaptypes.StoreKey,
lockuptypes.StoreKey,
incentivestypes.StoreKey,
epochstypes.StoreKey,
poolincentivestypes.StoreKey,
concentratedliquiditytypes.StoreKey,
poolmanagertypes.StoreKey,
authzkeeper.StoreKey,
txfeestypes.StoreKey,
superfluidtypes.StoreKey,
wasm.StoreKey,
tokenfactorytypes.StoreKey,
valsetpreftypes.StoreKey,
protorevtypes.StoreKey,
ibchookstypes.StoreKey,
icqtypes.StoreKey,
packetforwardtypes.StoreKey,
cosmwasmpooltypes.StoreKey,
}
}