Skip to content

Commit

Permalink
feat: integrate ICA
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Mar 30, 2023
1 parent 073468e commit 25bc7e6
Showing 1 changed file with 49 additions and 12 deletions.
61 changes: 49 additions & 12 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ import (
gravity "github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity"
gravitykeeper "github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity/keeper"
gravitytypes "github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity/types"
ica "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts"
icahost "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types"
ibctransfer "github.com/cosmos/ibc-go/v6/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v6/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
Expand Down Expand Up @@ -173,6 +178,9 @@ func init() {
nftmodule.AppModuleBasic{},
ibc.AppModuleBasic{},
ibctransfer.AppModuleBasic{},
ica.AppModuleBasic{},
// intertx.AppModuleBasic{},
// ibcfee.AppModuleBasic{},
gravity.AppModuleBasic{},
leverage.AppModuleBasic{},
oracle.AppModuleBasic{},
Expand All @@ -196,6 +204,7 @@ func init() {
nft.ModuleName: nil,

ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
icatypes.ModuleName: nil,
gravitytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
leveragetypes.ModuleName: {authtypes.Minter, authtypes.Burner},
oracletypes.ModuleName: nil,
Expand Down Expand Up @@ -245,6 +254,7 @@ type UmeeApp struct {

UIBCTransferKeeper uibctransferkeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
ICAHostKeeper icahostkeeper.Keeper
GravityKeeper gravitykeeper.Keeper
LeverageKeeper leveragekeeper.Keeper
OracleKeeper oraclekeeper.Keeper
Expand Down Expand Up @@ -359,6 +369,7 @@ func New(
// grant capabilities for the ibc and ibc-transfer modules
app.ScopedIBCKeeper = app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
app.ScopedTransferKeeper = app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)

app.initializeCustomScopedKeepers()

Expand Down Expand Up @@ -497,6 +508,12 @@ func New(
app.UpgradeKeeper,
app.ScopedIBCKeeper,
)
app.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName),
app.IBCKeeper.ChannelKeeper, // app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(),
)

var ics4Wrapper ibcporttypes.ICS4Wrapper
app.UIbcQuotaKeeper = uibcquotakeeper.NewKeeper(
Expand Down Expand Up @@ -524,10 +541,10 @@ func New(
app.UIBCTransferKeeper = uibctransferkeeper.New(ibcTransferKeeper, app.BankKeeper)

// Create Transfer Stack
// SendPacket, since it is originating from the application to core IBC:
// SendPacket, originates from the application to an IBC channel:
// transferKeeper.SendPacket -> uibcquota.SendPacket -> channel.SendPacket

// RecvPacket, message that originates from core IBC and goes down to app, the flow is the other way
// RecvPacket, message that originates from an IBC channel and goes down to app, the flow is the other way
// channel.RecvPacket -> uibcquota.OnRecvPacket -> transfer.OnRecvPacket

// transfer stack contains (from top to bottom):
Expand All @@ -541,8 +558,18 @@ func New(
ibctransfer.NewIBCModule(ibcTransferKeeper),
app.UIBCTransferKeeper,
)
// transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper)
transferStack = uibcquota.NewIBCMiddleware(transferStack, app.UIbcQuotaKeeper, appCodec)

// Create Interchain Accounts Stack
// SendPacket, since it is originating from the application to core IBC:
// icaAuthModuleKeeper.SendTx -> icaController.SendPacket -> fee.SendPacket -> channel.SendPacket

// RecvPacket, message that originates from core IBC and goes down to app, the flow is:
// channel.RecvPacket -> fee.OnRecvPacket -> icaHost.OnRecvPacket
var icaHostStack ibcporttypes.IBCModule = icahost.NewIBCModule(app.ICAHostKeeper)
// icaHostStack = ibcfee.NewIBCMiddleware(icaHostStack, app.IBCFeeKeeper)

/*
Create fee enabled wasm ibc Stack
var wasmStack ibcporttypes.IBCModule
Expand All @@ -552,14 +579,14 @@ func New(

// Create static IBC router, add app routes, then set and seal it
ibcRouter := ibcporttypes.NewRouter().
AddRoute(ibctransfertypes.ModuleName, transferStack)
AddRoute(ibctransfertypes.ModuleName, transferStack).
AddRoute(icahosttypes.SubModuleName, icaHostStack)
/*
// we will add cosmwasm IBC routing later
AddRoute(wasm.ModuleName, wasmStack).
// we don't integrate the controller now
AddRoute(intertxtypes.ModuleName, icaControllerStack).
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(icahosttypes.SubModuleName, icaHostStack)
*/
app.IBCKeeper.SetRouter(ibcRouter)

Expand Down Expand Up @@ -611,7 +638,9 @@ func New(
// must be passed by reference here.
appModules := []module.AppModule{
genutil.NewAppModule(
app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx,
app.AccountKeeper,
app.StakingKeeper,
app.DeliverTx,
encodingConfig.TxConfig,
),
auth.NewAppModule(appCodec, app.AccountKeeper, nil),
Expand All @@ -636,6 +665,8 @@ func New(
nftmodule.NewAppModule(appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),

ibctransfer.NewAppModule(ibcTransferKeeper),
// ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(nil, &app.ICAHostKeeper),
gravity.NewAppModule(app.GravityKeeper, app.BankKeeper),
leverage.NewAppModule(appCodec, app.LeverageKeeper, app.AccountKeeper, app.BankKeeper),
oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper),
Expand Down Expand Up @@ -665,7 +696,9 @@ func New(
nft.ModuleName,
group.ModuleName,
paramstypes.ModuleName, vestingtypes.ModuleName,
// icatypes.ModuleName, ibcfeetypes.ModuleName,
ibchost.ModuleName,
icatypes.ModuleName,
// ibcfeetypes.ModuleName,
leveragetypes.ModuleName,
oracletypes.ModuleName,
gravitytypes.ModuleName,
Expand All @@ -683,7 +716,8 @@ func New(
genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
feegrant.ModuleName, nft.ModuleName, group.ModuleName,
paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName,
// icatypes.ModuleName,
ibchost.ModuleName,
icatypes.ModuleName,
leveragetypes.ModuleName,
gravitytypes.ModuleName,
bech32ibctypes.ModuleName,
Expand All @@ -700,7 +734,8 @@ func New(
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName,
stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName,
crisistypes.ModuleName, ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName,
authz.ModuleName, ibctransfertypes.ModuleName, // icatypes.ModuleName,
authz.ModuleName,
ibctransfertypes.ModuleName, ibchost.ModuleName, icatypes.ModuleName, // ibcfeetypes.ModuleName
feegrant.ModuleName, nft.ModuleName, group.ModuleName,
paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName,

Expand All @@ -715,7 +750,7 @@ func New(
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName,
stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName,
crisistypes.ModuleName, ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName,
authz.ModuleName, ibctransfertypes.ModuleName, // icatypes.ModuleName,
authz.ModuleName, ibctransfertypes.ModuleName, icatypes.ModuleName, // ibcfeetypes.ModuleName
feegrant.ModuleName, nft.ModuleName, group.ModuleName,
paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName,

Expand Down Expand Up @@ -757,10 +792,12 @@ func New(

simStateModules := genmap.Pick(
app.mm.Modules,
[]string{stakingtypes.ModuleName, authtypes.ModuleName, oracletypes.ModuleName},
[]string{stakingtypes.ModuleName, authtypes.ModuleName, oracletypes.ModuleName,
ibchost.ModuleName},
)
// TODO: Ensure x/leverage implements simulator and add it here:
simTestModules := genmap.Pick(simStateModules, []string{oracletypes.ModuleName})
simTestModules := genmap.Pick(simStateModules,
[]string{oracletypes.ModuleName, ibchost.ModuleName})

app.StateSimulationManager = module.NewSimulationManagerFromAppModules(simStateModules, overrideModules)
app.sm = module.NewSimulationManagerFromAppModules(simTestModules, nil)
Expand Down Expand Up @@ -1026,7 +1063,7 @@ func initParamsKeeper(
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
// paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
// paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(gravitytypes.ModuleName)
paramsKeeper.Subspace(leveragetypes.ModuleName)
paramsKeeper.Subspace(oracletypes.ModuleName)
Expand Down

0 comments on commit 25bc7e6

Please # to comment.