Skip to content

Commit

Permalink
feat(ica): ICA Host / Controller integration (#1820)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Apr 23, 2024
1 parent 6b7a97d commit c60c806
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
55 changes: 51 additions & 4 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -201,6 +213,8 @@ func initStoreKeys() (
ibctransfertypes.StoreKey,
ibcfeetypes.StoreKey,
ibcexported.StoreKey,
icahosttypes.StoreKey,
icacontrollertypes.StoreKey,

// nibiru x/ keys
oracletypes.StoreKey,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -647,6 +689,7 @@ func orderedModuleNames() []string {
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,

// --------------------------------------------------------------------
// CosmWasm
Expand Down Expand Up @@ -749,6 +792,7 @@ func ModuleBasicManager() module.BasicManager {
ibc.AppModuleBasic{},
ibctransfer.AppModuleBasic{},
ibctm.AppModuleBasic{},
ica.AppModuleBasic{},
// native x/
oracle.AppModuleBasic{},
epochs.AppModuleBasic{},
Expand All @@ -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: {},
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
66 changes: 66 additions & 0 deletions app/upgrades/v1_3_0/constants.go
Original file line number Diff line number Diff line change
@@ -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},
},
}
4 changes: 4 additions & 0 deletions contrib/make/format.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
format:
@echo "--> Formating code and ordering imports"
@goimports -local github.com/NibiruChain -w .
@gofmt -w .

0 comments on commit c60c806

Please sign in to comment.