Skip to content

Commit

Permalink
hook fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasDotSol committed Dec 16, 2023
1 parent ceeebfa commit 5805e92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 13 additions & 4 deletions solidity/contracts/hooks/wormhole/WormholeHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pragma solidity >=0.8.0;

// ============ Internal Imports ============
import {IPostDispatchHook} from "../../interfaces/hooks/IPostDispatchHook.sol";
import {Message} from "../../libs/Message.sol";
import {MailboxClient} from "../../client/MailboxClient.sol";

// TODO: figure out whether it is possible to import this using Hardhat:
// https://github.com/wormhole-foundation/wormhole/blob/main/ethereum/contracts/interfaces/IWormhole.sol
Expand All @@ -14,10 +16,12 @@ interface IWormhole {
) external payable returns (uint64 sequence);
}

contract WormholeHook is IPostDispatchHook {
contract WormholeHook is IPostDispatchHook, MailboxClient {
using Message for bytes;

IWormhole public wormhole;

constructor(address _wormhole) {
constructor(address _wormhole, address _mailbox) MailboxClient(_mailbox) {
wormhole = IWormhole(_wormhole);
}

Expand All @@ -26,14 +30,19 @@ contract WormholeHook is IPostDispatchHook {
}

function supportsMetadata(bytes calldata) external pure returns (bool) {
return false;
return true;
}

function postDispatch(
bytes calldata,
bytes calldata message
) external payable {
wormhole.publishMessage{value: msg.value}(0, message, 200);
// ensure hook only dispatches messages that are dispatched by the mailbox
bytes32 id = message.id();
require(_isLatestDispatched(id), "message not dispatched by mailbox");
// use 0 nonce, _isLatestDispatched is sufficient check.
// 201 consistency level iis safest as it ensures finality is reached before bridging.
wormhole.publishMessage{value: msg.value}(0, abi.encodePacked(id), 201);
}

function quoteDispatch(
Expand Down
4 changes: 3 additions & 1 deletion solidity/contracts/interfaces/IInterchainSecurityModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ interface IInterchainSecurityModule {
MERKLE_ROOT_MULTISIG,
MESSAGE_ID_MULTISIG,
NULL, // used with relayer carrying no metadata
CCIP_READ
CCIP_READ,
AXELAR,
WORMHOLE
}

/**
Expand Down

0 comments on commit 5805e92

Please sign in to comment.