LayerZeroGatewayAdapter
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
- MUST emit a MessageSent event.
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
| Name | Type | Description |
|---|---|---|
| recipient | bytes | |
| payload | bytes | |
| attributes | bytes[] |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |
supportsAttribute
Getter to check whether an attribute is supported or not.
function supportsAttribute(bytes4 selector) external pure virtual returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| selector | bytes4 |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| origin | Origin | |
| guid | bytes32 | |
| message | bytes | |
| _ | 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
| Name | Type | Description |
|---|---|---|
| origin | Origin |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| eid | uint32 | |
| sender | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint64 |
endpoint
function endpoint() external view virtual returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
getEid
function getEid(uint256 chainId) external view virtual returns (uint32);Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint32 |
getChainId
function getChainId(uint32 eid) external view virtual returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| eid | uint32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
getPeer
function getPeer(uint256 chainId) external view virtual returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |
getDestinationGas
function getDestinationGas(uint256 chainId) external view virtual returns (uint128);Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint128 |
getDestinationMsgValue
function getDestinationMsgValue(uint256 chainId) external view virtual returns (uint128);Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| recipient | bytes | |
| payload | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
registerEid
Registers an EVM chainId ↔ LayerZero eid equivalence (both directions). Admin only.
function registerEid(uint256 chainId, uint32 eid) external virtual;Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 | |
| eid | uint32 |
registerPeer
Registers a trusted 32-byte peer (remote adapter) for a chain. Admin only.
function registerPeer(uint256 chainId, bytes32 peer) external virtual;Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 | |
| peer | bytes32 |
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
| Name | Type | Description |
|---|---|---|
| chainId | uint256 | |
| gas | uint128 | |
| msgValue | uint128 |
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
| Name | Type | Description |
|---|---|---|
| selectors | bytes |