Skip to content

Commit

Permalink
use ibchooks
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Mar 26, 2024
1 parent 108e3f9 commit dfa8cdc
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 470 deletions.
36 changes: 24 additions & 12 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ import (

initiaapplanes "github.com/initia-labs/initia/app/lanes"
initiaappparams "github.com/initia-labs/initia/app/params"
ibchooks "github.com/initia-labs/initia/x/ibc-hooks"
ibchookskeeper "github.com/initia-labs/initia/x/ibc-hooks/keeper"
ibchookstypes "github.com/initia-labs/initia/x/ibc-hooks/types"
"github.com/initia-labs/initia/x/ibc/fetchprice"
fetchpricekeeper "github.com/initia-labs/initia/x/ibc/fetchprice/keeper"
fetchpricetypes "github.com/initia-labs/initia/x/ibc/fetchprice/types"
Expand Down Expand Up @@ -134,7 +137,7 @@ import (
// local imports
appante "github.com/initia-labs/minievm/app/ante"
apphook "github.com/initia-labs/minievm/app/hook"
evmibcmiddleware "github.com/initia-labs/minievm/app/ibc-middleware"
ibcevmhooks "github.com/initia-labs/minievm/app/ibc-hooks"
appkeepers "github.com/initia-labs/minievm/app/keepers"
applanes "github.com/initia-labs/minievm/app/lanes"

Expand Down Expand Up @@ -223,6 +226,7 @@ type MinitiaApp struct {
ICQKeeper *icqkeeper.Keeper
OracleKeeper *oraclekeeper.Keeper // x/oracle keeper used for the slinky oracle
FetchPriceKeeper *fetchpricekeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -276,7 +280,7 @@ func NewMinitiaApp(
icahosttypes.StoreKey, icacontrollertypes.StoreKey, icaauthtypes.StoreKey,
ibcfeetypes.StoreKey, evmtypes.StoreKey, opchildtypes.StoreKey,
auctiontypes.StoreKey, packetforwardtypes.StoreKey, icqtypes.StoreKey,
oracletypes.StoreKey, fetchpricetypes.StoreKey,
oracletypes.StoreKey, fetchpricetypes.StoreKey, ibchookstypes.StoreKey,
)
tkeys := storetypes.NewTransientStoreKeys()
memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -437,6 +441,13 @@ func NewMinitiaApp(
)
app.IBCFeeKeeper = &ibcFeeKeeper

app.IBCHooksKeeper = ibchookskeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[ibchookstypes.StoreKey]),
authorityAddr,
ac,
)

////////////////////////////
// Transfer configuration //
////////////////////////////
Expand All @@ -446,7 +457,6 @@ func NewMinitiaApp(
var transferStack porttypes.IBCModule
{
packetForwardKeeper := &packetforwardkeeper.Keeper{}
evmMiddleware := &evmibcmiddleware.IBCMiddleware{}

// Create Transfer Keepers
transferKeeper := ibctransferkeeper.NewKeeper(
Expand All @@ -473,8 +483,8 @@ func NewMinitiaApp(
app.IBCKeeper.ChannelKeeper,
communityPoolKeeper,
app.BankKeeper,
// ics4wrapper: transfer -> packet forward -> evm
evmMiddleware,
// ics4wrapper: transfer -> packet forward -> fee
app.IBCFeeKeeper,
authorityAddr,
)
app.PacketForwardKeeper = packetForwardKeeper
Expand All @@ -487,19 +497,21 @@ func NewMinitiaApp(
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp,
)

// create move middleware for transfer
*evmMiddleware = evmibcmiddleware.NewIBCMiddleware(
// receive: evm -> packet forward -> transfer
// create wasm middleware for transfer
hookMiddleware := ibchooks.NewIBCMiddleware(
// receive: wasm -> packet forward -> transfer
packetForwardMiddleware,
// ics4wrapper: transfer -> packet forward -> evm -> fee
app.IBCFeeKeeper,
app.EVMKeeper,
ibchooks.NewICS4Middleware(
nil, /* ics4wrapper: not used */
ibcevmhooks.NewEVMHooks(app.EVMKeeper, ac),
),
app.IBCHooksKeeper,
)

// create ibcfee middleware for transfer
transferStack = ibcfee.NewIBCMiddleware(
// receive: fee -> evm -> packet forward -> transfer
evmMiddleware,
hookMiddleware,
// ics4wrapper: transfer -> packet forward -> evm -> fee -> channel
*app.IBCFeeKeeper,
)
Expand Down
3 changes: 1 addition & 2 deletions app/ibc-hooks/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ func _createTestInput(
// ibc middleware setup

mockIBCMiddleware := mockIBCMiddleware{}
evmHooks, err := evmhooks.NewEVMHooks(evmKeeper, ac)
require.NoError(t, err)
evmHooks := evmhooks.NewEVMHooks(evmKeeper, ac)

middleware := ibchooks.NewICS4Middleware(mockIBCMiddleware, evmHooks)
ibcHookMiddleware := ibchooks.NewIBCMiddleware(mockIBCMiddleware, middleware, ibcHooksKeeper)
Expand Down
6 changes: 3 additions & 3 deletions app/ibc-hooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ type EVMHooks struct {
asyncCallbackABI *abi.ABI
}

func NewEVMHooks(evmKeeper *evmkeeper.Keeper, ac address.Codec) (*EVMHooks, error) {
func NewEVMHooks(evmKeeper *evmkeeper.Keeper, ac address.Codec) *EVMHooks {
abi, err := i_ibc_async_callback.IIbcAsyncCallbackMetaData.GetAbi()
if err != nil {
return nil, err
panic(err)
}

return &EVMHooks{
evmKeeper: evmKeeper,
ac: ac,
asyncCallbackABI: abi,
}, nil
}
}

func (h EVMHooks) OnRecvPacketOverride(im ibchooks.IBCMiddleware, ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) ibcexported.Acknowledgement {
Expand Down
118 changes: 0 additions & 118 deletions app/ibc-middleware/README.md

This file was deleted.

Loading

0 comments on commit dfa8cdc

Please sign in to comment.