Skip to content

Commit

Permalink
Add initial L0 Hook and test
Browse files Browse the repository at this point in the history
  • Loading branch information
ltyu committed Dec 21, 2023
1 parent be2edaa commit 9bf01ca
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
44 changes: 44 additions & 0 deletions solidity/contracts/hooks/LayerZeroHook.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

/*@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@ HYPERLANE @@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@*/

import {Message} from "../libs/Message.sol";
import {MailboxClient} from "../client/MailboxClient.sol";
import {Indexed} from "../libs/Indexed.sol";
import {IPostDispatchHook} from "../interfaces/hooks/IPostDispatchHook.sol";
import {AbstractPostDispatchHook} from "./libs/AbstractPostDispatchHook.sol";
import {StandardHookMetadata} from "./libs/StandardHookMetadata.sol";

contract LayerZeroHook is AbstractPostDispatchHook, MailboxClient, Indexed {
constructor(address _mailbox) MailboxClient(_mailbox) {}

// ============ External Functions ============

/// @inheritdoc IPostDispatchHook
function hookType() external pure override returns (uint8) {
return uint8(IPostDispatchHook.Types.LAYER_ZERO);
}

/// @inheritdoc AbstractPostDispatchHook
function _postDispatch(
bytes calldata metadata,
bytes calldata message
) internal virtual override {}

/// @inheritdoc AbstractPostDispatchHook
function _quoteDispatch(
bytes calldata metadata,
bytes calldata message
) internal view virtual override returns (uint256) {}
}
3 changes: 2 additions & 1 deletion solidity/contracts/interfaces/hooks/IPostDispatchHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ interface IPostDispatchHook {
FALLBACK_ROUTING,
ID_AUTH_ISM,
PAUSABLE,
PROTOCOL_FEE
PROTOCOL_FEE,
LAYER_ZERO
}

/**
Expand Down
30 changes: 30 additions & 0 deletions solidity/test/hooks/LayerZeroHook.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13;

import {LZEndpointMock} from "@layerzerolabs/solidity-examples/contracts/lzApp/mocks/LZEndpointMock.sol";
import {Test} from "forge-std/Test.sol";
import {TestMailbox} from "../../contracts/test/TestMailbox.sol";
import {LayerZeroHook} from "../../contracts/hooks/LayerZeroHook.sol";
import {IPostDispatchHook} from "../../contracts/interfaces/hooks/IPostDispatchHook.sol";

contract LayerZeroHookTest is Test {
LZEndpointMock lZEndpointMock;
TestMailbox public mailbox;
LayerZeroHook hook;

function setUp() public {
lZEndpointMock = new LZEndpointMock(uint16(block.chainid));
mailbox = new TestMailbox(0);
hook = new LayerZeroHook(address(mailbox));
}

// function testPostDispatch_emit() public {}

function testQuoteDispatch() public {
assertEq(hook.quoteDispatch("", ""), 0);
}

function testHookType() public {
assertEq(hook.hookType(), uint8(IPostDispatchHook.Types.LAYER_ZERO));
}
}

0 comments on commit 9bf01ca

Please sign in to comment.