Skip to content

Commit

Permalink
Add ics20 wrapper (in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
dawid-kruk committed Jun 24, 2024
1 parent e34bb5b commit eb80f52
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 30 deletions.
69 changes: 45 additions & 24 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
v131 "github.com/chain4energy/c4e-chain/app/upgrades/v131"
v140 "github.com/chain4energy/c4e-chain/app/upgrades/v140"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types"

porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"

Expand All @@ -35,6 +36,7 @@ import (
"os"
"path/filepath"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/chain4energy/c4e-chain/docs"
cfeclaimmodule "github.com/chain4energy/c4e-chain/x/cfeclaim"
cfedistributormodule "github.com/chain4energy/c4e-chain/x/cfedistributor"
Expand Down Expand Up @@ -83,8 +85,6 @@ import (
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distr "github.com/cosmos/cosmos-sdk/x/distribution"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/evidence"
Expand Down Expand Up @@ -119,14 +119,16 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ibchooks "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7"
ibchookskeeper "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/keeper"
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"
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"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer"
ibctransfermodule "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"
ibc "github.com/cosmos/ibc-go/v7/modules/core"
Expand Down Expand Up @@ -191,14 +193,15 @@ var (
solomachine.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
ibctransfermodule.AppModuleBasic{},
ica.AppModuleBasic{},
consensus.AppModuleBasic{},
vesting.AppModuleBasic{},
cfevestingmodule.AppModuleBasic{},
cfemintermodule.AppModuleBasic{},
cfedistributormodule.AppModuleBasic{},
cfeclaimmodule.AppModuleBasic{},
ibchooks.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

Expand Down Expand Up @@ -296,13 +299,15 @@ type App struct {
ParamsKeeper paramskeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
IBCTransferKeeper ibctransferkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
ICAControllerKeeper icacontrollerkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
GroupKeeper groupkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
WasmKeeper wasmkeeper.Keeper
IBCHooksKeeper ibchookskeeper.Keeper
Ics20WasmHooks ibchooks.WasmHooks

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -377,6 +382,7 @@ func New(
cfemintermoduletypes.StoreKey,
cfedistributormoduletypes.StoreKey,
cfeclaimmoduletypes.StoreKey,
ibchookstypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -523,21 +529,6 @@ func New(
scopedIBCKeeper,
)

// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec,
keys[ibctransfertypes.StoreKey],
app.GetSubspace(ibctransfertypes.ModuleName),
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
app.BankKeeper,
app.ScopedTransferKeeper,
)
transferModule := transfer.NewAppModule(app.TransferKeeper)
transferIBCModule := transfer.NewIBCModule(app.TransferKeeper)

app.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec, keys[icahosttypes.StoreKey],
app.GetSubspace(icahosttypes.SubModuleName),
Expand Down Expand Up @@ -601,6 +592,30 @@ func New(
// if we want to allow any custom callbacks
availableCapabilities := strings.Join(wasmd.AllCapabilities(), ",")

app.IBCHooksKeeper = ibchookskeeper.NewKeeper(
app.keys[ibchookstypes.StoreKey],
)
app.Ics20WasmHooks = ibchooks.NewWasmHooks(&app.IBCHooksKeeper, nil, AccountAddressPrefix) // The contract keeper needs to be set later
hooksICS4Wrapper := ibchooks.NewICS4Middleware(
app.IBCKeeper.ChannelKeeper,
app.Ics20WasmHooks,
)

// Create Transfer Keepers
app.IBCTransferKeeper = ibctransferkeeper.NewKeeper(
appCodec,
keys[ibctransfertypes.StoreKey],
app.GetSubspace(ibctransfertypes.ModuleName),
hooksICS4Wrapper,
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
app.BankKeeper,
app.ScopedTransferKeeper,
)
transferModule := ibctransfermodule.NewAppModule(app.IBCTransferKeeper)
transferIBCModule := ibctransfermodule.NewIBCModule(app.IBCTransferKeeper)

app.WasmKeeper = wasmkeeper.NewKeeper(
appCodec,
keys[wasmtypes.StoreKey],
Expand All @@ -612,7 +627,7 @@ func New(
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
scopedWasmKeeper,
app.TransferKeeper,
app.IBCTransferKeeper,
app.MsgServiceRouter(),
app.GRPCQueryRouter(),
wasmDir,
Expand All @@ -622,6 +637,8 @@ func New(
wasmOpts...,
)

app.Ics20WasmHooks.ContractKeeper = &app.WasmKeeper

// The gov proposal types can be individually enabled
if len(enabledProposals) != 0 {
govRouter.AddRoute(wasmtypes.RouterKey, wasmkeeper.NewWasmProposalHandler(app.WasmKeeper, enabledProposals)) //nolint:staticcheck // we still need this despite the deprecation of the gov handler
Expand Down Expand Up @@ -693,16 +710,16 @@ func New(
),
)
// this line is used by starport scaffolding # stargate/app/keeperDefinition

var wasmStack porttypes.IBCModule
wasmStack = wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper)
// Create static IBC router, add transfer route, then set and seal it

ibcRouter := ibcporttypes.NewRouter()
ibcRouter.
AddRoute(ibctransfertypes.ModuleName, transferIBCModule).
AddRoute(icacontrollertypes.SubModuleName, icaHostIBCModule).
AddRoute(wasmtypes.ModuleName, wasmStack).
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule)

// this line is used by starport scaffolding # ibc/app/router
app.IBCKeeper.SetRouter(ibcRouter)
Expand Down Expand Up @@ -741,6 +758,7 @@ func New(
ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.ParamsKeeper),
transferModule,
ibchooks.NewAppModule(app.AccountKeeper),
icaModule,
cfevestingModule,
cfeminterModule,
Expand Down Expand Up @@ -782,6 +800,7 @@ func New(
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
icatypes.ModuleName,
ibchookstypes.ModuleName,
wasmtypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
)
Expand Down Expand Up @@ -812,6 +831,7 @@ func New(
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
icatypes.ModuleName,
ibchookstypes.ModuleName,
wasmtypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/endBlockers
)
Expand Down Expand Up @@ -851,6 +871,7 @@ func New(
ibcexported.ModuleName,
icatypes.ModuleName,
crisistypes.ModuleName,
ibchookstypes.ModuleName,
wasmtypes.ModuleName,
}

Expand Down
2 changes: 2 additions & 0 deletions app/upgrades/v140/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
store "github.com/cosmos/cosmos-sdk/store/types"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types"
)

const UpgradeName = "v1.4.0"
Expand All @@ -18,6 +19,7 @@ var Upgrade = upgrades.Upgrade{
consensusparamtypes.ModuleName,
crisistypes.ModuleName,
wasmtypes.StoreKey,
ibchookstypes.StoreKey,
},
Deleted: []string{
"cfesignature",
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/cosmos/cosmos-sdk v0.47.12
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20240522065513-ed0e92f61cfa
github.com/cosmos/ibc-go/v7 v7.3.0
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.4
Expand All @@ -39,13 +40,13 @@ require (
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/storage v1.38.0 // indirect
cosmossdk.io/core v0.5.1 // indirect
cosmossdk.io/core v0.6.1 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/tools/rosetta v0.2.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
github.com/99designs/keyring v1.2.2 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect
github.com/CosmWasm/wasmvm v1.4.0 // indirect
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V
cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M=
cosmossdk.io/api v0.3.1 h1:NNiOclKRR0AOlO4KIqeaG6PS6kswOMhHD0ir0SscNXE=
cosmossdk.io/api v0.3.1/go.mod h1:DfHfMkiNA2Uhy8fj0JJlOCYOBp4eWUUJ1te5zBGNyIw=
cosmossdk.io/core v0.5.1 h1:vQVtFrIYOQJDV3f7rw4pjjVqc1id4+mE0L9hHP66pyI=
cosmossdk.io/core v0.5.1/go.mod h1:KZtwHCLjcFuo0nmDc24Xy6CRNEL9Vl/MeimQ2aC7NLE=
cosmossdk.io/core v0.6.1 h1:OBy7TI2W+/gyn2z40vVvruK3di+cAluinA6cybFbE7s=
cosmossdk.io/core v0.6.1/go.mod h1:g3MMBCBXtxbDWBURDVnJE7XML4BG5qENhs0gzkcpuFA=
cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc=
cosmossdk.io/depinject v1.0.0-alpha.4/go.mod h1:HeDk7IkR5ckZ3lMGs/o91AVUc7E596vMaOmslGFM3yU=
cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
Expand All @@ -202,8 +202,8 @@ filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
github.com/99designs/keyring v1.2.1 h1:tYLp1ULvO7i3fI5vE21ReQuj99QFSs7lGm0xWyJo87o=
github.com/99designs/keyring v1.2.1/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA=
github.com/99designs/keyring v1.2.2 h1:pZd3neh/EmUzWONb35LxQfvuY7kiSXAq3HQd97+XBn0=
github.com/99designs/keyring v1.2.2/go.mod h1:wes/FrByc8j7lFOAGLGSNEg8f/PaI3cgTBqhFkHUrPk=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
Expand Down Expand Up @@ -343,6 +343,8 @@ github.com/cosmos/gogoproto v1.4.10 h1:QH/yT8X+c0F4ZDacDv3z+xE3WU1P1Z3wQoLMBRJoK
github.com/cosmos/gogoproto v1.4.10/go.mod h1:3aAZzeRWpAwr+SS/LLkICX2/kDFyaYVzckBDzygIxek=
github.com/cosmos/iavl v0.20.1 h1:rM1kqeG3/HBT85vsZdoSNsehciqUQPWrR4BYmqE2+zg=
github.com/cosmos/iavl v0.20.1/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A=
github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20240522065513-ed0e92f61cfa h1:jUuwC6Y9sthwHMt8P6GJKhtpK3n/pge9yaxMCTLXoe4=
github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20240522065513-ed0e92f61cfa/go.mod h1:JwHFbo1oX/ht4fPpnPvmhZr+dCkYK1Vihw+vZE9umR4=
github.com/cosmos/ibc-go/v7 v7.3.0 h1:QtGeVMi/3JeLWuvEuC60sBHpAF40Oenx/y+bP8+wRRw=
github.com/cosmos/ibc-go/v7 v7.3.0/go.mod h1:mUmaHFXpXrEdcxfdXyau+utZf14pGKVUiXwYftRZZfQ=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
Expand Down

0 comments on commit eb80f52

Please sign in to comment.