WormholeGatewayAdapterLib
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
| Name | Type | Description |
|---|---|---|
| $ | 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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| <none> | address |
wormholeChainId
function wormholeChainId() internal view returns (uint16);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint16 |
getWormholeChain
function getWormholeChain(uint256 chainId) internal view returns (uint16);Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint16 |
getChainId
function getChainId(uint16 wormhole) internal view returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| wormhole | uint16 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
getRemoteGateway
function getRemoteGateway(uint256 chainId) internal view returns (address);Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
supportsAttribute
function supportsAttribute(bytes4 selector) internal pure returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| selector | bytes4 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
quoteRelay
function quoteRelay(bytes calldata recipient, uint256 gasLimit) internal view returns (uint256 price);Parameters
| Name | Type | Description |
|---|---|---|
| recipient | bytes | |
| gasLimit | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| price | uint256 |
registerChainEquivalence
function registerChainEquivalence(uint256 chainId, uint16 wormhole) internal;Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 | |
| wormhole | uint16 |
registerRemoteGateway
function registerRemoteGateway(uint256 chainId, address remote) internal;Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 | |
| remote | address |
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
| Name | Type | Description |
|---|---|---|
| recipient | bytes | |
| payload | bytes | |
| attributes | bytes[] |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| sendId | bytes32 | |
| recipient | bytes | |
| payload | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| sendId | bytes32 | |
| recipient | bytes | |
| payload | bytes | |
| attributes | bytes[] |
requestRelay
Dispatches a previously-stored pending message via the Wormhole relayer.
function requestRelay(bytes32 sendId, uint256 gasLimit, address refundRecipient) internal;Parameters
| Name | Type | Description |
|---|---|---|
| sendId | bytes32 | |
| gasLimit | uint256 | |
| refundRecipient | address |
receiveWormholeMessages
Wormhole delivery callback: validate relayer + source gateway, de-dup, deliver.
function receiveWormholeMessages(
bytes calldata payload,
bytes32 sourceAddress,
uint16 sourceChain,
bytes32 deliveryHash
) internal;Parameters
| Name | Type | Description |
|---|---|---|
| payload | bytes | |
| sourceAddress | bytes32 | |
| sourceChain | uint16 | |
| deliveryHash | bytes32 |
_relay
Encodes the wire payload and dispatches to the trusted remote gateway via the relayer.
function _relay(Relay memory p) private;Parameters
| Name | Type | Description |
|---|---|---|
| p | Relay |
_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
| Name | Type | Description |
|---|---|---|
| attr | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| ok | bool | |
| value | uint256 | |
| gasLimit | uint256 | |
| refundRecipient | address |
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
| Name | Type | Description |
|---|---|---|
| id | bytes32 | |
| sender | address | |
| receiverValue | uint256 | |
| gasLimit | uint256 | |
| refundRecipient | address | |
| totalValue | uint256 | |
| recipient | bytes | |
| payload | bytes |