diff --git a/protocol/app/app.go b/protocol/app/app.go index 0f7cadde54..5dd2cde6e0 100644 --- a/protocol/app/app.go +++ b/protocol/app/app.go @@ -85,6 +85,8 @@ import ( "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" + ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" + icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" "github.com/gorilla/mux" "github.com/rakyll/statik/fs" "github.com/spf13/cast" @@ -166,7 +168,12 @@ import ( vestmodulekeeper "github.com/dydxprotocol/v4-chain/protocol/x/vest/keeper" vestmoduletypes "github.com/dydxprotocol/v4-chain/protocol/x/vest/types" - // IBC + icacontroller "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller" + icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper" + icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" + icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host" + icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" + icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" "github.com/cosmos/ibc-go/v7/modules/apps/transfer" ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" @@ -240,6 +247,9 @@ type App struct { TransferKeeper ibctransferkeeper.Keeper FeeGrantKeeper feegrantkeeper.Keeper ConsensusParamsKeeper consensusparamkeeper.Keeper + // ICA keepers + ICAControllerKeeper icacontrollerkeeper.Keeper + ICAHostKeeper icahostkeeper.Keeper // make scoped keepers public for test purposes ScopedIBCKeeper capabilitykeeper.ScopedKeeper @@ -356,6 +366,8 @@ func New( sendingmoduletypes.StoreKey, delaymsgmoduletypes.StoreKey, epochsmoduletypes.StoreKey, + icacontrollertypes.StoreKey, + icahosttypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys( paramstypes.TStoreKey, @@ -530,9 +542,40 @@ func New( transferModule := transfer.NewAppModule(app.TransferKeeper) transferIBCModule := transfer.NewIBCModule(app.TransferKeeper) - // Create static IBC router, add transfer route, then set and seal it + // Create the ICA controller keeper + app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper( + appCodec, + keys[icacontrollertypes.StoreKey], + app.getSubspace(icacontrollertypes.SubModuleName), + app.IBCKeeper.ChannelKeeper, + app.IBCKeeper.ChannelKeeper, + &app.IBCKeeper.PortKeeper, + app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName), + app.MsgServiceRouter(), + ) + + // Create the ICA host keeper + app.ICAHostKeeper = icahostkeeper.NewKeeper( + appCodec, + keys[icahosttypes.StoreKey], + app.getSubspace(icahosttypes.SubModuleName), + app.IBCKeeper.ChannelKeeper, + app.IBCKeeper.ChannelKeeper, + &app.IBCKeeper.PortKeeper, + app.AccountKeeper, + app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName), + app.MsgServiceRouter(), + ) + + // Create the ICA routes + icaControllerStack := icacontroller.NewIBCMiddleware(nil, app.ICAControllerKeeper) + icaHostIBCModule := icahost.NewIBCModule(app.ICAHostKeeper) + + // Create static IBC router, add transfer and ICA routes, then set and seal it ibcRouter := ibcporttypes.NewRouter() ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferIBCModule) + ibcRouter.AddRoute(icacontrollertypes.SubModuleName, icaControllerStack) + ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule) app.IBCKeeper.SetRouter(ibcRouter) // create evidence keeper with router @@ -933,6 +976,7 @@ func New( upgrade.NewAppModule(app.UpgradeKeeper), evidence.NewAppModule(app.EvidenceKeeper), ibc.NewAppModule(app.IBCKeeper), + ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper), params.NewAppModule(app.ParamsKeeper), consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper), transferModule, @@ -987,6 +1031,7 @@ func New( rewardsmoduletypes.ModuleName, sendingmoduletypes.ModuleName, delaymsgmoduletypes.ModuleName, + icatypes.ModuleName, ) app.ModuleManager.SetOrderCommiters( @@ -1023,6 +1068,7 @@ func New( rewardsmoduletypes.ModuleName, epochsmoduletypes.ModuleName, delaymsgmoduletypes.ModuleName, + icatypes.ModuleName, blocktimemoduletypes.ModuleName, // Must be last ) @@ -1062,6 +1108,7 @@ func New( rewardsmoduletypes.ModuleName, sendingmoduletypes.ModuleName, delaymsgmoduletypes.ModuleName, + icatypes.ModuleName, ) // NOTE: by default, set migration order here to be the same as init genesis order, @@ -1097,6 +1144,7 @@ func New( rewardsmoduletypes.ModuleName, sendingmoduletypes.ModuleName, delaymsgmoduletypes.ModuleName, + icatypes.ModuleName, // Auth must be migrated after staking. authtypes.ModuleName, @@ -1473,6 +1521,8 @@ func initParamsKeeper( paramsKeeper.Subspace(crisistypes.ModuleName) paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibcexported.ModuleName) + paramsKeeper.Subspace(icahosttypes.SubModuleName) + paramsKeeper.Subspace(icacontrollertypes.SubModuleName) return paramsKeeper } diff --git a/protocol/app/basic_manager/basic_manager.go b/protocol/app/basic_manager/basic_manager.go index 2bfafe027d..072aa68106 100644 --- a/protocol/app/basic_manager/basic_manager.go +++ b/protocol/app/basic_manager/basic_manager.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/upgrade" upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" + delaymsgmodule "github.com/dydxprotocol/v4-chain/protocol/x/delaymsg" custommodule "github.com/dydxprotocol/v4-chain/protocol/app/module" @@ -36,6 +37,7 @@ import ( subaccountsmodule "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts" vestmodule "github.com/dydxprotocol/v4-chain/protocol/x/vest" + ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" "github.com/cosmos/ibc-go/v7/modules/apps/transfer" ibc "github.com/cosmos/ibc-go/v7/modules/core" ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client" @@ -68,6 +70,7 @@ var ( custommodule.SlashingModuleBasic{}, feegrantmodule.AppModuleBasic{}, ibc.AppModuleBasic{}, + ica.AppModuleBasic{}, ibctm.AppModuleBasic{}, upgrade.AppModuleBasic{}, evidence.AppModuleBasic{}, diff --git a/protocol/app/module_accounts.go b/protocol/app/module_accounts.go index 0880c5e1fc..249fb38347 100644 --- a/protocol/app/module_accounts.go +++ b/protocol/app/module_accounts.go @@ -5,6 +5,7 @@ import ( distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" "github.com/dydxprotocol/v4-chain/protocol/app/config" @@ -33,6 +34,8 @@ var ( stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, govtypes.ModuleName: {authtypes.Burner}, ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + // -------- Native IBC module accounts -------- + icatypes.ModuleName: nil, // -------- dYdX custom module accounts -------- // bridge module account mints tokens for bridged funds. bridgemoduletypes.ModuleName: {authtypes.Minter},