Skip to content
Lattice

LayerZeroGatewayAdapter

Git Source

Inherits: IERC7786GatewaySource, ILayerZeroReceiver, ILayerZeroGatewayAdapter

Title: LayerZeroGatewayAdapter

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from LayerZero v2 (https://github.com/LayerZero-Labs/LayerZero-v2)

ERC-7786 cross-chain gateway facet over the LayerZero v2 EndpointV2 (OApp). sendMessage quotes + dispatches a LayerZero message via the endpoint; lzReceive is the endpoint's delivery callback. EVM chains only.

Stateless delegator — logic/storage live in LayerZeroGatewayAdapterLib. LayerZero routes by uint32 endpoint id (the lib holds a chainId ⇄ eid map + a 32-byte trusted peer per chain); the endpoint-gated lzReceive is the inbound analogue of CCIP's ccipReceive / Wormhole's receiveWormholeMessages. Implements ILayerZeroReceiver (lzReceive / allowInitializePath / nextNonce) so the endpoint can deliver messages and query the OApp's unordered-delivery / trusted-peer policy.

Notes:

  • lattice-version: 0.1.0
  • lattice-source: LayerZero

Functions

sendMessage

If any of the attributes is not supported, this function SHOULD revert with an

UnsupportedAttribute error. Other errors SHOULD revert with errors not specified in ERC-7786.

Endpoint for creating a new message. If the message requires further (gateway specific) processing before it can be sent to the destination chain, then a non-zero sendId must be returned. Otherwise, the message MUST be sent and this function must return 0.

function sendMessage(bytes calldata recipient, bytes calldata payload, bytes[] calldata attributes)
        external
        payable
        virtual
        returns (bytes32);

Parameters

NameTypeDescription
recipientbytes
payloadbytes
attributesbytes[]

Returns

NameTypeDescription
<none>bytes32

supportsAttribute

Getter to check whether an attribute is supported or not.

function supportsAttribute(bytes4 selector) external pure virtual returns (bool);

Parameters

NameTypeDescription
selectorbytes4

Returns

NameTypeDescription
<none>bool

lzReceive

Called by the endpoint to deliver an inbound message. _executor / _extraData are supplied by the executor that triggered delivery.

function lzReceive(Origin calldata origin, bytes32 guid, bytes calldata message, address, bytes calldata)
        external
        payable
        virtual;

Parameters

NameTypeDescription
originOrigin
guidbytes32
messagebytes
_address
_bytes

allowInitializePath

Returns whether the OApp accepts initialization of the messaging path from _origin.

function allowInitializePath(Origin calldata origin) external view virtual returns (bool);

Parameters

NameTypeDescription
originOrigin

Returns

NameTypeDescription
<none>bool

nextNonce

Returns the next expected inbound nonce for (_eid, _sender) (0 ⇒ unordered / no nonce enforced).

function nextNonce(uint32 eid, bytes32 sender) external pure virtual returns (uint64);

Parameters

NameTypeDescription
eiduint32
senderbytes32

Returns

NameTypeDescription
<none>uint64

endpoint

function endpoint() external view virtual returns (address);

Returns

NameTypeDescription
<none>address

getEid

function getEid(uint256 chainId) external view virtual returns (uint32);

Parameters

NameTypeDescription
chainIduint256

Returns

NameTypeDescription
<none>uint32

getChainId

function getChainId(uint32 eid) external view virtual returns (uint256);

Parameters

NameTypeDescription
eiduint32

Returns

NameTypeDescription
<none>uint256

getPeer

function getPeer(uint256 chainId) external view virtual returns (bytes32);

Parameters

NameTypeDescription
chainIduint256

Returns

NameTypeDescription
<none>bytes32

getDestinationGas

function getDestinationGas(uint256 chainId) external view virtual returns (uint128);

Parameters

NameTypeDescription
chainIduint256

Returns

NameTypeDescription
<none>uint128

getDestinationMsgValue

function getDestinationMsgValue(uint256 chainId) external view virtual returns (uint128);

Parameters

NameTypeDescription
chainIduint256

Returns

NameTypeDescription
<none>uint128

quoteFee

Quotes the LayerZero native fee to send payload to recipient (ERC-7930).

function quoteFee(bytes calldata recipient, bytes calldata payload) external view virtual returns (uint256);

Parameters

NameTypeDescription
recipientbytes
payloadbytes

Returns

NameTypeDescription
<none>uint256

registerEid

Registers an EVM chainId ↔ LayerZero eid equivalence (both directions). Admin only.

function registerEid(uint256 chainId, uint32 eid) external virtual;

Parameters

NameTypeDescription
chainIduint256
eiduint32

registerPeer

Registers a trusted 32-byte peer (remote adapter) for a chain. Admin only.

function registerPeer(uint256 chainId, bytes32 peer) external virtual;

Parameters

NameTypeDescription
chainIduint256
peerbytes32

configureDestination

Configures a destination's executor lzReceive gas and native msg.value. Admin only.

function configureDestination(uint256 chainId, uint128 gas, uint128 msgValue) external virtual;

Parameters

NameTypeDescription
chainIduint256
gasuint128
msgValueuint128

exportSelectors

ERC-8153 selector export: this facet's cuttable selectors, tightly packed (4 bytes each).

Excludes exportSelectors() itself (0x0ef22643) - it is never cut into a diamond. Order matches forge inspect LayerZeroGatewayAdapter methodIdentifiers (alphabetical by signature); kept in exact parity by ExportSelectorsParityTest. Chunks: allowInitializePath((uint32,bytes32,uint64)) 0xff7bd03d configureDestination(uint256,uint128,uint128) 0xb3602f8d endpoint() 0x5e280f11 getChainId(uint32) 0x94f79a53 getDestinationGas(uint256) 0x73ad8334 getDestinationMsgValue(uint256) 0x8c0b3902 getEid(uint256) 0x193dc209 getPeer(uint256) 0x67ebb6b2 lzReceive((uint32,bytes32,uint64),bytes32,bytes,address,bytes) 0x13137d65 nextNonce(uint32,bytes32) 0x7d25a05e quoteFee(bytes,bytes) 0x58d14c04 registerEid(uint256,uint32) 0x5d6e12a2 registerPeer(uint256,bytes32) 0x24ac554d sendMessage(bytes,bytes,bytes[]) 0xcdfe7f5c supportsAttribute(bytes4) 0xdc680a0f

function exportSelectors() external pure virtual returns (bytes memory selectors);

Returns

NameTypeDescription
selectorsbytes