@@ -14,6 +14,9 @@ import (
1414 feegrantkeeper "cosmossdk.io/x/feegrant/keeper"
1515 upgradekeeper "cosmossdk.io/x/upgrade/keeper"
1616 upgradetypes "cosmossdk.io/x/upgrade/types"
17+ "github.com/CosmWasm/wasmd/x/wasm"
18+ wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
19+ wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
1720 "github.com/cosmos/cosmos-sdk/baseapp"
1821 "github.com/cosmos/cosmos-sdk/codec"
1922 addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
@@ -45,23 +48,29 @@ import (
4548 slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
4649 stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
4750 stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
51+ icacontroller "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller"
52+ icacontrollerkeeper "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller/keeper"
4853 icacontrollertypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller/types"
54+ icahostkeeper "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/host/keeper"
4955 icahosttypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/host/types"
56+ ibccallbacks "github.com/cosmos/ibc-go/v10/modules/apps/callbacks"
5057 "github.com/cosmos/ibc-go/v10/modules/apps/transfer"
5158 ibctransferkeeper "github.com/cosmos/ibc-go/v10/modules/apps/transfer/keeper"
5259 ibctransfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
60+ transferv2 "github.com/cosmos/ibc-go/v10/modules/apps/transfer/v2"
5361 ibcclienttypes "github.com/cosmos/ibc-go/v10/modules/core/02-client/types"
5462 ibcconnectiontypes "github.com/cosmos/ibc-go/v10/modules/core/03-connection/types"
5563 porttypes "github.com/cosmos/ibc-go/v10/modules/core/05-port/types"
64+ ibcapi "github.com/cosmos/ibc-go/v10/modules/core/api"
5665 ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported"
5766 ibckeeper "github.com/cosmos/ibc-go/v10/modules/core/keeper"
5867 ibctm "github.com/cosmos/ibc-go/v10/modules/light-clients/07-tendermint"
59- emodule "pkg.akt.dev/go/node/escrow/module"
6068
6169 atypes "pkg.akt.dev/go/node/audit/v1"
6270 ctypes "pkg.akt.dev/go/node/cert/v1"
6371 dtypes "pkg.akt.dev/go/node/deployment/v1"
6472 dv1beta "pkg.akt.dev/go/node/deployment/v1beta3"
73+ emodule "pkg.akt.dev/go/node/escrow/module"
6574 agovtypes "pkg.akt.dev/go/node/gov/v1beta3"
6675 mtypes "pkg.akt.dev/go/node/market/v1beta4"
6776 ptypes "pkg.akt.dev/go/node/provider/v1beta4"
@@ -103,6 +112,8 @@ type AppKeepers struct {
103112 IBC * ibckeeper.Keeper
104113 Evidence * evidencekeeper.Keeper
105114 Transfer ibctransferkeeper.Keeper
115+ ICAController icacontrollerkeeper.Keeper
116+ ICAHost icahostkeeper.Keeper
106117 }
107118
108119 Akash struct {
@@ -115,6 +126,10 @@ type AppKeepers struct {
115126 Cert ckeeper.Keeper
116127 }
117128
129+ External struct {
130+ Wasm * wasmkeeper.Keeper
131+ }
132+
118133 Modules struct {
119134 TMLight ibctm.LightClientModule
120135 }
@@ -238,6 +253,9 @@ func (app *App) InitNormalKeepers(
238253 encodingConfig sdkutil.EncodingConfig ,
239254 bApp * baseapp.BaseApp ,
240255 maccPerms map [string ][]string ,
256+ wasmDir string ,
257+ wasmConfig wasmtypes.NodeConfig ,
258+ wasmOpts []wasmkeeper.Option ,
241259 blockedAddresses map [string ]bool ,
242260 invCheckPeriod uint ,
243261) {
@@ -386,14 +404,6 @@ func (app *App) InitNormalKeepers(
386404 authtypes .NewModuleAddress (govtypes .ModuleName ).String (),
387405 )
388406
389- transferIBCModule := transfer .NewIBCModule (app .Keepers .Cosmos .Transfer )
390-
391- // Create static IBC router, add transfer route, then set and seal it
392- ibcRouter := porttypes .NewRouter ()
393- ibcRouter .AddRoute (ibctransfertypes .ModuleName , transferIBCModule )
394-
395- app .Keepers .Cosmos .IBC .SetRouter (ibcRouter )
396-
397407 /// Light client modules
398408 clientKeeper := app .Keepers .Cosmos .IBC .ClientKeeper
399409 storeProvider := app .Keepers .Cosmos .IBC .ClientKeeper .GetStoreProvider ()
@@ -444,6 +454,70 @@ func (app *App) InitNormalKeepers(
444454 cdc ,
445455 app .keys [ctypes .StoreKey ],
446456 )
457+
458+ // The last arguments can contain custom message handlers, and custom query handlers,
459+ // if we want to allow any custom callbacks
460+ // The last arguments can contain custom message handlers, and custom query handlers,
461+ // if we want to allow any custom callbacks
462+ wasmCapabilities := wasmkeeper .BuiltInCapabilities ()
463+ wasmCapabilities = append (wasmCapabilities , "akash" )
464+
465+ wasmKeeper := wasmkeeper .NewKeeper (
466+ cdc ,
467+ runtime .NewKVStoreService (app .keys [wasmtypes .StoreKey ]),
468+ app .Keepers .Cosmos .Acct ,
469+ app .Keepers .Cosmos .Bank ,
470+ * app .Keepers .Cosmos .Staking ,
471+ distrkeeper .NewQuerier (app .Keepers .Cosmos .Distr ),
472+ app .Keepers .Cosmos .IBC .ChannelKeeper ,
473+ app .Keepers .Cosmos .IBC .ChannelKeeper ,
474+ app .Keepers .Cosmos .IBC .ChannelKeeperV2 ,
475+ app .Keepers .Cosmos .Transfer ,
476+ bApp .MsgServiceRouter (),
477+ bApp .GRPCQueryRouter (),
478+ wasmDir ,
479+ wasmConfig ,
480+ wasmtypes.VMConfig {},
481+ wasmCapabilities ,
482+ authtypes .NewModuleAddress (govtypes .ModuleName ).String (),
483+ wasmOpts ... ,
484+ )
485+ app .Keepers .External .Wasm = & wasmKeeper
486+
487+ // Create fee enabled wasm ibc Stack
488+ wasmStackIBCHandler := wasm .NewIBCHandler (app .Keepers .External .Wasm , app .Keepers .Cosmos .IBC .ChannelKeeper , app .Keepers .Cosmos .Transfer , app .Keepers .Cosmos .IBC .ChannelKeeper )
489+
490+ // Create Interchain Accounts Stack
491+ // SendPacket, since it is originating from the application to core IBC:
492+ // icaAuthModuleKeeper.SendTx -> icaController.SendPacket -> fee.SendPacket -> channel.SendPacket
493+ var icaControllerStack porttypes.IBCModule
494+ // integration point for custom authentication modules
495+ // sees https://medium.com/the-interchain-foundation/ibc-go-v6-changes-to-interchain-accounts-and-how-it-impacts-your-chain-806c185300d7
496+ var noAuthzModule porttypes.IBCModule
497+ icaControllerStack = icacontroller .NewIBCMiddlewareWithAuth (noAuthzModule , app .Keepers .Cosmos .ICAController )
498+ // app.ICAAuthModule = icaControllerStack.(ibcmock.IBCModule)
499+ icaControllerStack = icacontroller .NewIBCMiddlewareWithAuth (icaControllerStack , app .Keepers .Cosmos .ICAController )
500+ icaControllerStack = ibccallbacks .NewIBCMiddleware (icaControllerStack , app .Keepers .Cosmos .IBC .ChannelKeeper , wasmStackIBCHandler , wasm .DefaultMaxIBCCallbackGas )
501+ icaICS4Wrapper := icaControllerStack .(porttypes.ICS4Wrapper )
502+ // Since the callback middleware itself is an ics4wrapper, it needs to be passed to the ica controller keeper
503+ app .Keepers .Cosmos .ICAController .WithICS4Wrapper (icaICS4Wrapper )
504+
505+ transferIBCModule := transfer .NewIBCModule (app .Keepers .Cosmos .Transfer )
506+
507+ // Create static IBC router, add transfer route, then set and seal it
508+ ibcRouter := porttypes .NewRouter ()
509+ ibcRouter .AddRoute (ibctransfertypes .ModuleName , transferIBCModule )
510+ ibcRouter .AddRoute (wasmtypes .ModuleName , wasmStackIBCHandler )
511+
512+ app .Keepers .Cosmos .IBC .SetRouter (ibcRouter )
513+
514+ ibcRouterV2 := ibcapi .NewRouter ()
515+ ibcRouterV2 = ibcRouterV2 .
516+ AddRoute (ibctransfertypes .PortID , transferv2 .NewIBCModule (app .Keepers .Cosmos .Transfer )).
517+ AddPrefixRoute (wasmkeeper .PortIDPrefixV2 , wasmkeeper .NewIBC2Handler (app .Keepers .External .Wasm ))
518+
519+ app .Keepers .Cosmos .IBC .SetRouterV2 (ibcRouterV2 )
520+
447521}
448522
449523func (app * App ) SetupHooks () {
@@ -517,6 +591,8 @@ func kvStoreKeys() []string {
517591 upgradetypes .StoreKey ,
518592 evidencetypes .StoreKey ,
519593 ibctransfertypes .StoreKey ,
594+ // wasm after ibc transfer
595+ wasmtypes .ModuleName ,
520596 }
521597
522598 keys = append (keys , akashKVStoreKeys ()... )
0 commit comments