Skip to content

Commit c60c806

Browse files
Segfaultdjgimenok-yang
authored
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 <[email protected]> Co-authored-by: Kevin Yang <[email protected]>
1 parent 6b7a97d commit c60c806

File tree

5 files changed

+124
-4
lines changed

5 files changed

+124
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5757
- [#1816](https://github.com/NibiruChain/nibiru/pull/1816) - fix(ibc): fix ibc transaction from wasm contract
5858
- [#1823](https://github.com/NibiruChain/nibiru/pull/1823) - feat(inflation): add burn method
5959
- [#1832](https://github.com/NibiruChain/nibiru/pull/1832) - feat(tokenfactory): add burn method for native tokens
60+
- [#1820](https://github.com/NibiruChain/nibiru/pull/1820) - feat: add interchain accounts
6061

6162
#### Nibiru EVM
6263

app/keepers.go

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import (
44
"path/filepath"
55
"strings"
66

7+
ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
8+
icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
9+
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
10+
icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host"
11+
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
12+
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
13+
714
wasmdapp "github.com/CosmWasm/wasmd/app"
815
"github.com/CosmWasm/wasmd/x/wasm"
916
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
@@ -76,6 +83,7 @@ import (
7683
// ---------------------------------------------------------------
7784
// IBC imports
7885

86+
icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper"
7987
ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee"
8088
ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper"
8189
ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
@@ -151,11 +159,15 @@ type AppKeepers struct {
151159
ibcKeeper *ibckeeper.Keeper
152160
ibcFeeKeeper ibcfeekeeper.Keeper
153161
/* ibcTransferKeeper is for cross-chain fungible token transfers. */
154-
ibcTransferKeeper ibctransferkeeper.Keeper
162+
ibcTransferKeeper ibctransferkeeper.Keeper
163+
icaControllerKeeper icacontrollerkeeper.Keeper
164+
icaHostKeeper icahostkeeper.Keeper
155165

156166
// make scoped keepers public for test purposes
157-
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
158-
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
167+
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
168+
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
169+
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
170+
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
159171

160172
// make IBC modules public for test purposes
161173
// these modules are never directly routed to by the IBC Router
@@ -201,6 +213,8 @@ func initStoreKeys() (
201213
ibctransfertypes.StoreKey,
202214
ibcfeetypes.StoreKey,
203215
ibcexported.StoreKey,
216+
icahosttypes.StoreKey,
217+
icacontrollertypes.StoreKey,
204218

205219
// nibiru x/ keys
206220
oracletypes.StoreKey,
@@ -247,6 +261,8 @@ func (app *NibiruApp) InitKeepers(
247261
memKeys[capabilitytypes.MemStoreKey],
248262
)
249263
app.ScopedIBCKeeper = app.capabilityKeeper.ScopeToModule(ibcexported.ModuleName)
264+
app.ScopedICAControllerKeeper = app.capabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
265+
app.ScopedICAHostKeeper = app.capabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
250266
// scopedFeeMockKeeper := app.capabilityKeeper.ScopeToModule(MockFeePort)
251267
app.ScopedTransferKeeper = app.capabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
252268

@@ -401,6 +417,28 @@ func (app *NibiruApp) InitKeepers(
401417
app.ScopedTransferKeeper,
402418
)
403419

420+
app.icaControllerKeeper = icacontrollerkeeper.NewKeeper(
421+
appCodec, keys[icacontrollertypes.StoreKey],
422+
app.GetSubspace(icacontrollertypes.SubModuleName),
423+
app.ibcFeeKeeper,
424+
app.ibcKeeper.ChannelKeeper,
425+
&app.ibcKeeper.PortKeeper,
426+
app.ScopedICAControllerKeeper,
427+
app.MsgServiceRouter(),
428+
)
429+
430+
app.icaHostKeeper = icahostkeeper.NewKeeper(
431+
appCodec,
432+
keys[icahosttypes.StoreKey],
433+
app.GetSubspace(icahosttypes.SubModuleName),
434+
app.ibcFeeKeeper,
435+
app.ibcKeeper.ChannelKeeper,
436+
&app.ibcKeeper.PortKeeper,
437+
app.AccountKeeper,
438+
app.ScopedICAHostKeeper,
439+
app.MsgServiceRouter(),
440+
)
441+
404442
app.ScopedWasmKeeper = app.capabilityKeeper.ScopeToModule(wasmtypes.ModuleName)
405443

406444
wasmDir := filepath.Join(homePath, "data")
@@ -491,8 +529,11 @@ func (app *NibiruApp) InitKeepers(
491529
transferStack = ibctransfer.NewIBCModule(app.ibcTransferKeeper)
492530
transferStack = ibcfee.NewIBCMiddleware(transferStack, app.ibcFeeKeeper)
493531

532+
// Create the second stack for ICA
533+
icaHostIBCModule := icahost.NewIBCModule(app.icaHostKeeper)
534+
494535
// Add transfer stack to IBC Router
495-
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack)
536+
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).AddRoute(ibctransfertypes.ModuleName, transferStack)
496537

497538
// Create Mock IBC Fee module stack for testing
498539
// SendPacket, since it is originating from the application to core IBC:
@@ -579,6 +620,7 @@ func (app *NibiruApp) initAppModules(
579620
ibc.NewAppModule(app.ibcKeeper),
580621
ibctransfer.NewAppModule(app.ibcTransferKeeper),
581622
ibcfee.NewAppModule(app.ibcFeeKeeper),
623+
ica.NewAppModule(&app.icaControllerKeeper, &app.icaHostKeeper),
582624

583625
// wasm
584626
wasm.NewAppModule(
@@ -647,6 +689,7 @@ func orderedModuleNames() []string {
647689
ibctransfertypes.ModuleName,
648690
ibcexported.ModuleName,
649691
ibcfeetypes.ModuleName,
692+
icatypes.ModuleName,
650693

651694
// --------------------------------------------------------------------
652695
// CosmWasm
@@ -749,6 +792,7 @@ func ModuleBasicManager() module.BasicManager {
749792
ibc.AppModuleBasic{},
750793
ibctransfer.AppModuleBasic{},
751794
ibctm.AppModuleBasic{},
795+
ica.AppModuleBasic{},
752796
// native x/
753797
oracle.AppModuleBasic{},
754798
epochs.AppModuleBasic{},
@@ -773,6 +817,7 @@ func ModuleAccPerms() map[string][]string {
773817
oracletypes.ModuleName: {},
774818
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
775819
ibcfeetypes.ModuleName: {},
820+
icatypes.ModuleName: {},
776821

777822
epochstypes.ModuleName: {},
778823
sudotypes.ModuleName: {},
@@ -802,6 +847,8 @@ func initParamsKeeper(
802847
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
803848
paramsKeeper.Subspace(ibcexported.ModuleName)
804849
paramsKeeper.Subspace(ibcfeetypes.ModuleName)
850+
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
851+
paramsKeeper.Subspace(icahosttypes.SubModuleName)
805852
// wasm params keepers
806853
paramsKeeper.Subspace(wasmtypes.ModuleName)
807854
paramsKeeper.Subspace(devgastypes.ModuleName)

app/upgrades.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import (
88
"github.com/NibiruChain/nibiru/app/upgrades"
99
"github.com/NibiruChain/nibiru/app/upgrades/v1_1_0"
1010
"github.com/NibiruChain/nibiru/app/upgrades/v1_2_0"
11+
"github.com/NibiruChain/nibiru/app/upgrades/v1_3_0"
1112
)
1213

1314
var Upgrades = []upgrades.Upgrade{
1415
v1_1_0.Upgrade,
1516
v1_2_0.Upgrade,
17+
v1_3_0.Upgrade,
1618
}
1719

1820
func (app *NibiruApp) setupUpgrades() {

app/upgrades/v1_3_0/constants.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package v1_3_0
2+
3+
import (
4+
"github.com/cosmos/cosmos-sdk/store/types"
5+
sdk "github.com/cosmos/cosmos-sdk/types"
6+
"github.com/cosmos/cosmos-sdk/types/module"
7+
"github.com/cosmos/cosmos-sdk/x/authz"
8+
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
9+
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
10+
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
11+
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
12+
ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
13+
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
14+
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
15+
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
16+
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
17+
18+
"github.com/NibiruChain/nibiru/app/upgrades"
19+
)
20+
21+
const UpgradeName = "v1.3.0"
22+
23+
var Upgrade = upgrades.Upgrade{
24+
UpgradeName: UpgradeName,
25+
CreateUpgradeHandler: func(mm *module.Manager, cfg module.Configurator) upgradetypes.UpgradeHandler {
26+
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
27+
// set the ICS27 consensus version so InitGenesis is not run
28+
fromVM[icatypes.ModuleName] = mm.GetVersionMap()[icatypes.ModuleName]
29+
30+
// create ICS27 Controller submodule params, controller module not enabled.
31+
controllerParams := icacontrollertypes.Params{
32+
ControllerEnabled: true,
33+
}
34+
35+
// create ICS27 Host submodule params
36+
hostParams := icahosttypes.Params{
37+
HostEnabled: true,
38+
AllowMessages: []string{
39+
sdk.MsgTypeURL(&banktypes.MsgSend{}),
40+
sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}),
41+
sdk.MsgTypeURL(&stakingtypes.MsgUndelegate{}),
42+
sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}),
43+
sdk.MsgTypeURL(&distrtypes.MsgWithdrawDelegatorReward{}),
44+
sdk.MsgTypeURL(&distrtypes.MsgSetWithdrawAddress{}),
45+
sdk.MsgTypeURL(&distrtypes.MsgFundCommunityPool{}),
46+
sdk.MsgTypeURL(&authz.MsgExec{}),
47+
sdk.MsgTypeURL(&authz.MsgGrant{}),
48+
sdk.MsgTypeURL(&authz.MsgRevoke{}),
49+
sdk.MsgTypeURL(&ibctransfertypes.MsgTransfer{}),
50+
},
51+
}
52+
53+
// initialize ICS27 module
54+
icamodule, correctTypecast := mm.Modules[icatypes.ModuleName].(ica.AppModule)
55+
if !correctTypecast {
56+
panic("mm.Modules[icatypes.ModuleName] is not of type ica.AppModule")
57+
}
58+
icamodule.InitModule(ctx, controllerParams, hostParams)
59+
60+
return mm.RunMigrations(ctx, cfg, fromVM)
61+
}
62+
},
63+
StoreUpgrades: types.StoreUpgrades{
64+
Added: []string{icacontrollertypes.StoreKey, icahosttypes.StoreKey},
65+
},
66+
}

contrib/make/format.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
format:
2+
@echo "--> Formating code and ordering imports"
3+
@goimports -local github.com/NibiruChain -w .
4+
@gofmt -w .

0 commit comments

Comments
 (0)