From 9bf01cacf14930391d4a48883fbc023140b8fbbd Mon Sep 17 00:00:00 2001 From: Le Date: Thu, 21 Dec 2023 17:45:15 -0500 Subject: [PATCH] Add initial L0 Hook and test --- solidity/contracts/hooks/LayerZeroHook.sol | 44 +++++++++++++++++++ .../interfaces/hooks/IPostDispatchHook.sol | 3 +- solidity/test/hooks/LayerZeroHook.t.sol | 30 +++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 solidity/contracts/hooks/LayerZeroHook.sol create mode 100644 solidity/test/hooks/LayerZeroHook.t.sol diff --git a/solidity/contracts/hooks/LayerZeroHook.sol b/solidity/contracts/hooks/LayerZeroHook.sol new file mode 100644 index 0000000000..d6780aaa57 --- /dev/null +++ b/solidity/contracts/hooks/LayerZeroHook.sol @@ -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) {} +} diff --git a/solidity/contracts/interfaces/hooks/IPostDispatchHook.sol b/solidity/contracts/interfaces/hooks/IPostDispatchHook.sol index 69a44c7bc1..43730e6ea5 100644 --- a/solidity/contracts/interfaces/hooks/IPostDispatchHook.sol +++ b/solidity/contracts/interfaces/hooks/IPostDispatchHook.sol @@ -23,7 +23,8 @@ interface IPostDispatchHook { FALLBACK_ROUTING, ID_AUTH_ISM, PAUSABLE, - PROTOCOL_FEE + PROTOCOL_FEE, + LAYER_ZERO } /** diff --git a/solidity/test/hooks/LayerZeroHook.t.sol b/solidity/test/hooks/LayerZeroHook.t.sol new file mode 100644 index 0000000000..e7c530b3e7 --- /dev/null +++ b/solidity/test/hooks/LayerZeroHook.t.sol @@ -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)); + } +}