Skip to content

Commit

Permalink
Merge branch 'Axelar-Hook' into Axelar-Wormhole-ISMs
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasDotSol committed Dec 19, 2023
2 parents 1932675 + 7e163e9 commit 93f329d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 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,22 @@ 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 Hyperlane 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

0 comments on commit 93f329d

Please sign in to comment.