From c60c806ad58ec1f165f7849b6ea26f3077399f9b Mon Sep 17 00:00:00 2001 From: Segfault <5221072+Segfaultd@users.noreply.github.com> Date: Tue, 23 Apr 2024 20:44:49 +0200 Subject: [PATCH] feat(ica): ICA Host / Controller integration (#1820) * ICA Host / Controller integration. Added upgrade constants. Added make format command * Fixed required message URLs * Code import fix * Fixed upgrade name * Fixed upgrade target * Changed version number * Update CHANGELOG.md --------- Co-authored-by: Jonathan Gimeno Co-authored-by: Kevin Yang <5478483+k-yang@users.noreply.github.com> --- CHANGELOG.md | 1 + app/keepers.go | 55 ++++++++++++++++++++++++-- app/upgrades.go | 2 + app/upgrades/v1_3_0/constants.go | 66 ++++++++++++++++++++++++++++++++ contrib/make/format.mk | 4 ++ 5 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 app/upgrades/v1_3_0/constants.go create mode 100644 contrib/make/format.mk diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e46f2757..4faaa4545 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#1816](https://github.com/NibiruChain/nibiru/pull/1816) - fix(ibc): fix ibc transaction from wasm contract - [#1823](https://github.com/NibiruChain/nibiru/pull/1823) - feat(inflation): add burn method - [#1832](https://github.com/NibiruChain/nibiru/pull/1832) - feat(tokenfactory): add burn method for native tokens +- [#1820](https://github.com/NibiruChain/nibiru/pull/1820) - feat: add interchain accounts #### Nibiru EVM diff --git a/app/keepers.go b/app/keepers.go index 8ea7df0da..efe942c62 100644 --- a/app/keepers.go +++ b/app/keepers.go @@ -4,6 +4,13 @@ import ( "path/filepath" "strings" + ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" + 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" + icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" + icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" + wasmdapp "github.com/CosmWasm/wasmd/app" "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" @@ -76,6 +83,7 @@ import ( // --------------------------------------------------------------- // IBC imports + icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee" ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper" ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" @@ -151,11 +159,15 @@ type AppKeepers struct { ibcKeeper *ibckeeper.Keeper ibcFeeKeeper ibcfeekeeper.Keeper /* ibcTransferKeeper is for cross-chain fungible token transfers. */ - ibcTransferKeeper ibctransferkeeper.Keeper + ibcTransferKeeper ibctransferkeeper.Keeper + icaControllerKeeper icacontrollerkeeper.Keeper + icaHostKeeper icahostkeeper.Keeper // make scoped keepers public for test purposes - ScopedIBCKeeper capabilitykeeper.ScopedKeeper - ScopedTransferKeeper capabilitykeeper.ScopedKeeper + ScopedIBCKeeper capabilitykeeper.ScopedKeeper + ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper + ScopedICAHostKeeper capabilitykeeper.ScopedKeeper + ScopedTransferKeeper capabilitykeeper.ScopedKeeper // make IBC modules public for test purposes // these modules are never directly routed to by the IBC Router @@ -201,6 +213,8 @@ func initStoreKeys() ( ibctransfertypes.StoreKey, ibcfeetypes.StoreKey, ibcexported.StoreKey, + icahosttypes.StoreKey, + icacontrollertypes.StoreKey, // nibiru x/ keys oracletypes.StoreKey, @@ -247,6 +261,8 @@ func (app *NibiruApp) InitKeepers( memKeys[capabilitytypes.MemStoreKey], ) app.ScopedIBCKeeper = app.capabilityKeeper.ScopeToModule(ibcexported.ModuleName) + app.ScopedICAControllerKeeper = app.capabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName) + app.ScopedICAHostKeeper = app.capabilityKeeper.ScopeToModule(icahosttypes.SubModuleName) // scopedFeeMockKeeper := app.capabilityKeeper.ScopeToModule(MockFeePort) app.ScopedTransferKeeper = app.capabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) @@ -401,6 +417,28 @@ func (app *NibiruApp) InitKeepers( app.ScopedTransferKeeper, ) + app.icaControllerKeeper = icacontrollerkeeper.NewKeeper( + appCodec, keys[icacontrollertypes.StoreKey], + app.GetSubspace(icacontrollertypes.SubModuleName), + app.ibcFeeKeeper, + app.ibcKeeper.ChannelKeeper, + &app.ibcKeeper.PortKeeper, + app.ScopedICAControllerKeeper, + app.MsgServiceRouter(), + ) + + app.icaHostKeeper = icahostkeeper.NewKeeper( + appCodec, + keys[icahosttypes.StoreKey], + app.GetSubspace(icahosttypes.SubModuleName), + app.ibcFeeKeeper, + app.ibcKeeper.ChannelKeeper, + &app.ibcKeeper.PortKeeper, + app.AccountKeeper, + app.ScopedICAHostKeeper, + app.MsgServiceRouter(), + ) + app.ScopedWasmKeeper = app.capabilityKeeper.ScopeToModule(wasmtypes.ModuleName) wasmDir := filepath.Join(homePath, "data") @@ -491,8 +529,11 @@ func (app *NibiruApp) InitKeepers( transferStack = ibctransfer.NewIBCModule(app.ibcTransferKeeper) transferStack = ibcfee.NewIBCMiddleware(transferStack, app.ibcFeeKeeper) + // Create the second stack for ICA + icaHostIBCModule := icahost.NewIBCModule(app.icaHostKeeper) + // Add transfer stack to IBC Router - ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack) + ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).AddRoute(ibctransfertypes.ModuleName, transferStack) // Create Mock IBC Fee module stack for testing // SendPacket, since it is originating from the application to core IBC: @@ -579,6 +620,7 @@ func (app *NibiruApp) initAppModules( ibc.NewAppModule(app.ibcKeeper), ibctransfer.NewAppModule(app.ibcTransferKeeper), ibcfee.NewAppModule(app.ibcFeeKeeper), + ica.NewAppModule(&app.icaControllerKeeper, &app.icaHostKeeper), // wasm wasm.NewAppModule( @@ -647,6 +689,7 @@ func orderedModuleNames() []string { ibctransfertypes.ModuleName, ibcexported.ModuleName, ibcfeetypes.ModuleName, + icatypes.ModuleName, // -------------------------------------------------------------------- // CosmWasm @@ -749,6 +792,7 @@ func ModuleBasicManager() module.BasicManager { ibc.AppModuleBasic{}, ibctransfer.AppModuleBasic{}, ibctm.AppModuleBasic{}, + ica.AppModuleBasic{}, // native x/ oracle.AppModuleBasic{}, epochs.AppModuleBasic{}, @@ -773,6 +817,7 @@ func ModuleAccPerms() map[string][]string { oracletypes.ModuleName: {}, ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, ibcfeetypes.ModuleName: {}, + icatypes.ModuleName: {}, epochstypes.ModuleName: {}, sudotypes.ModuleName: {}, @@ -802,6 +847,8 @@ func initParamsKeeper( paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibcexported.ModuleName) paramsKeeper.Subspace(ibcfeetypes.ModuleName) + paramsKeeper.Subspace(icacontrollertypes.SubModuleName) + paramsKeeper.Subspace(icahosttypes.SubModuleName) // wasm params keepers paramsKeeper.Subspace(wasmtypes.ModuleName) paramsKeeper.Subspace(devgastypes.ModuleName) diff --git a/app/upgrades.go b/app/upgrades.go index a5896ab0f..07bccfb09 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -8,11 +8,13 @@ import ( "github.com/NibiruChain/nibiru/app/upgrades" "github.com/NibiruChain/nibiru/app/upgrades/v1_1_0" "github.com/NibiruChain/nibiru/app/upgrades/v1_2_0" + "github.com/NibiruChain/nibiru/app/upgrades/v1_3_0" ) var Upgrades = []upgrades.Upgrade{ v1_1_0.Upgrade, v1_2_0.Upgrade, + v1_3_0.Upgrade, } func (app *NibiruApp) setupUpgrades() { diff --git a/app/upgrades/v1_3_0/constants.go b/app/upgrades/v1_3_0/constants.go new file mode 100644 index 000000000..4788dbdd6 --- /dev/null +++ b/app/upgrades/v1_3_0/constants.go @@ -0,0 +1,66 @@ +package v1_3_0 + +import ( + "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/authz" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" + icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" + icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/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/NibiruChain/nibiru/app/upgrades" +) + +const UpgradeName = "v1.3.0" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: func(mm *module.Manager, cfg module.Configurator) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + // set the ICS27 consensus version so InitGenesis is not run + fromVM[icatypes.ModuleName] = mm.GetVersionMap()[icatypes.ModuleName] + + // create ICS27 Controller submodule params, controller module not enabled. + controllerParams := icacontrollertypes.Params{ + ControllerEnabled: true, + } + + // create ICS27 Host submodule params + hostParams := icahosttypes.Params{ + HostEnabled: true, + AllowMessages: []string{ + sdk.MsgTypeURL(&banktypes.MsgSend{}), + sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}), + sdk.MsgTypeURL(&stakingtypes.MsgUndelegate{}), + sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}), + sdk.MsgTypeURL(&distrtypes.MsgWithdrawDelegatorReward{}), + sdk.MsgTypeURL(&distrtypes.MsgSetWithdrawAddress{}), + sdk.MsgTypeURL(&distrtypes.MsgFundCommunityPool{}), + sdk.MsgTypeURL(&authz.MsgExec{}), + sdk.MsgTypeURL(&authz.MsgGrant{}), + sdk.MsgTypeURL(&authz.MsgRevoke{}), + sdk.MsgTypeURL(&ibctransfertypes.MsgTransfer{}), + }, + } + + // initialize ICS27 module + icamodule, correctTypecast := mm.Modules[icatypes.ModuleName].(ica.AppModule) + if !correctTypecast { + panic("mm.Modules[icatypes.ModuleName] is not of type ica.AppModule") + } + icamodule.InitModule(ctx, controllerParams, hostParams) + + return mm.RunMigrations(ctx, cfg, fromVM) + } + }, + StoreUpgrades: types.StoreUpgrades{ + Added: []string{icacontrollertypes.StoreKey, icahosttypes.StoreKey}, + }, +} diff --git a/contrib/make/format.mk b/contrib/make/format.mk new file mode 100644 index 000000000..49c2dfa5e --- /dev/null +++ b/contrib/make/format.mk @@ -0,0 +1,4 @@ +format: + @echo "--> Formating code and ordering imports" + @goimports -local github.com/NibiruChain -w . + @gofmt -w . \ No newline at end of file