Skip to content
Lattice

WormholeGatewayAdapterLib

Git Source

Title: WormholeGatewayAdapterLib

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Adapted for EIP-2535 from OpenZeppelin community-contracts WormholeGatewayAdapter (https://github.com/OpenZeppelin/openzeppelin-community-contracts, commit f7e5f08).

Dual-mode ERC-7786 gateway over the Wormhole relayer. Two-phase send (pending → requestRelay, or immediate via a requestRelay attribute); inbound receiveWormholeMessages validates the relayer + trusted source gateway, de-duplicates per (chainId, sendId), and delivers. EVM only.

Functions

wormholeGatewayAdapterStorage

function wormholeGatewayAdapterStorage() internal pure returns (WormholeGatewayAdapterStorage storage $);

Returns

NameTypeDescription
$WormholeGatewayAdapterStorage

__WormholeGatewayAdapter_init

Configures the relayer + this chain's Wormhole id and registers the gateway-source ERC-165 id.

function __WormholeGatewayAdapter_init(address relayer_, uint16 wormholeChainId_) internal;

Parameters

NameTypeDescription
relayer_address
wormholeChainId_uint16

registerInterface

Writes true to the SHARED IERC7786GatewaySource ERC-165 map slot (0x11967553 → ...). Same slot the Axelar/OpenBridge adapters register; a Diamond mounts at most one gateway.

function registerInterface() internal;

relayer

function relayer() internal view returns (address);

Returns

NameTypeDescription
<none>address

wormholeChainId

function wormholeChainId() internal view returns (uint16);

Returns

NameTypeDescription
<none>uint16

getWormholeChain

function getWormholeChain(uint256 chainId) internal view returns (uint16);

Parameters

NameTypeDescription
chainIduint256

Returns

NameTypeDescription
<none>uint16

getChainId

function getChainId(uint16 wormhole) internal view returns (uint256);

Parameters

NameTypeDescription
wormholeuint16

Returns

NameTypeDescription
<none>uint256

getRemoteGateway

function getRemoteGateway(uint256 chainId) internal view returns (address);

Parameters

NameTypeDescription
chainIduint256

Returns

NameTypeDescription
<none>address

supportsAttribute

function supportsAttribute(bytes4 selector) internal pure returns (bool);

Parameters

NameTypeDescription
selectorbytes4

Returns

NameTypeDescription
<none>bool

quoteRelay

function quoteRelay(bytes calldata recipient, uint256 gasLimit) internal view returns (uint256 price);

Parameters

NameTypeDescription
recipientbytes
gasLimituint256

Returns

NameTypeDescription
priceuint256

registerChainEquivalence

function registerChainEquivalence(uint256 chainId, uint16 wormhole) internal;

Parameters

NameTypeDescription
chainIduint256
wormholeuint16

registerRemoteGateway

function registerRemoteGateway(uint256 chainId, address remote) internal;

Parameters

NameTypeDescription
chainIduint256
remoteaddress

sendMessage

ERC-7786 source. No attribute → store pending (return non-zero sendId); one requestRelay attribute → dispatch immediately (return 0); more → revert.

function sendMessage(bytes calldata recipient, bytes calldata payload, bytes[] calldata attributes)
        internal
        returns (bytes32);

Parameters

NameTypeDescription
recipientbytes
payloadbytes
attributesbytes[]

Returns

NameTypeDescription
<none>bytes32

_sendPending

No-attribute path: hold the message (and any value) until requestRelay. Split out for stack.

function _sendPending(bytes32 sendId, bytes calldata recipient, bytes calldata payload) private returns (bytes32);

Parameters

NameTypeDescription
sendIdbytes32
recipientbytes
payloadbytes

Returns

NameTypeDescription
<none>bytes32

_sendImmediate

Single-requestRelay-attribute path: dispatch immediately. Split out for stack.

function _sendImmediate(
        bytes32 sendId,
        bytes calldata recipient,
        bytes calldata payload,
        bytes[] calldata attributes
    ) private;

Parameters

NameTypeDescription
sendIdbytes32
recipientbytes
payloadbytes
attributesbytes[]

requestRelay

Dispatches a previously-stored pending message via the Wormhole relayer.

function requestRelay(bytes32 sendId, uint256 gasLimit, address refundRecipient) internal;

Parameters

NameTypeDescription
sendIdbytes32
gasLimituint256
refundRecipientaddress

receiveWormholeMessages

Wormhole delivery callback: validate relayer + source gateway, de-dup, deliver.

function receiveWormholeMessages(
        bytes calldata payload,
        bytes32 sourceAddress,
        uint16 sourceChain,
        bytes32 deliveryHash
    ) internal;

Parameters

NameTypeDescription
payloadbytes
sourceAddressbytes32
sourceChainuint16
deliveryHashbytes32

_relay

Encodes the wire payload and dispatches to the trusted remote gateway via the relayer.

function _relay(Relay memory p) private;

Parameters

NameTypeDescription
pRelay

_decodeRequestRelay

Decodes a requestRelay attribute. Returns ok=false if the selector/length doesn't match.

function _decodeRequestRelay(bytes calldata attr)
        private
        pure
        returns (bool ok, uint256 value, uint256 gasLimit, address refundRecipient);

Parameters

NameTypeDescription
attrbytes

Returns

NameTypeDescription
okbool
valueuint256
gasLimituint256
refundRecipientaddress

Structs

Relay

Relay parameters (passed as a memory struct to keep callers under the stack limit).

struct Relay {
        bytes32 id;
        address sender;
        uint256 receiverValue;
        uint256 gasLimit;
        address refundRecipient;
        uint256 totalValue;
        bytes recipient;
        bytes payload;
    }

Properties

NameTypeDescription
idbytes32
senderaddress
receiverValueuint256
gasLimituint256
refundRecipientaddress
totalValueuint256
recipientbytes
payloadbytes