CCIPGatewayAdapterLib
Title: CCIPGatewayAdapterLib
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Chainlink CCIP (https://github.com/smartcontractkit/chainlink-ccip)
Logic + ERC-7201 storage for the Chainlink CCIP ERC-7786 gateway adapter. sendMessage builds a
CCIP EVM2AnyMessage, quotes getFee, and submits via ccipSend (native or ERC-20 fee);
ccipReceive is the router-gated delivery callback that validates the source selector + trusted
remote gateway, de-duplicates per (chainId, CCIP messageId), and delivers to the ERC-7930
recipient. EVM chains only. CCIP routes by uint64 chain selector, not EVM chainId.
Wire payload = abi.encode(senderInteropAddr, recipientInteropAddr, innerPayload); the CCIP
receiver field targets the trusted remote adapter, which forwards to the final recipient.
Functions
ccipGatewayAdapterStorage
function ccipGatewayAdapterStorage() internal pure returns (CCIPGatewayAdapterStorage storage $);Returns
| Name | Type | Description |
|---|---|---|
| $ | CCIPGatewayAdapterStorage |
__CCIPGatewayAdapter_init
Configures the router + fee token and registers the gateway-source + CCIP-receiver ERC-165 ids.
function __CCIPGatewayAdapter_init(address router_, address feeToken_) internal;Parameters
| Name | Type | Description |
|---|---|---|
| router_ | address | |
| feeToken_ | address |
registerInterface
Writes true to the ERC-165 map slots for IERC7786GatewaySource (shared, gateway source),
IAny2EVMMessageReceiver (V1, required for the router to deliver messages), and
IAny2EVMMessageReceiverV2 (CCV-enabled lanes query getCCVsAndFinalityConfig).
function registerInterface() internal;router
function router() internal view returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
feeToken
function feeToken() internal view returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
getChainSelector
function getChainSelector(uint256 chainId) internal view returns (uint64);Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint64 |
getChainId
function getChainId(uint64 selector) internal view returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| selector | uint64 |
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 |
getDestinationGasLimit
function getDestinationGasLimit(uint256 chainId) internal view returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
getAllowOutOfOrderExecution
function getAllowOutOfOrderExecution(uint256 chainId) internal view returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
supportsAttribute
No sendMessage attributes are supported by this adapter (per-dest gas is admin-configured).
function supportsAttribute(bytes4) internal pure returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| _ | bytes4 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
quoteFee
function quoteFee(bytes calldata recipient, bytes calldata payload) internal view returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| recipient | bytes | |
| payload | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
getCCVsAndFinalityConfig
CCV view the CCIP router calls for inbound messages from sourceChainSelector (V2 lanes).
An unconfigured source returns the CCIP default (no extra CCVs, bytes4(0) = require finality).
function getCCVsAndFinalityConfig(uint64 sourceChainSelector)
internal
view
returns (address[] memory, address[] memory, uint8, bytes4);Parameters
| Name | Type | Description |
|---|---|---|
| sourceChainSelector | uint64 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | address[] | |
| <none> | address[] | |
| <none> | uint8 | |
| <none> | bytes4 |
getCCVConfig
Returns the CCV config stored for chainId (admin read, by EVM chainId).
function getCCVConfig(uint256 chainId) internal view returns (address[] memory, address[] memory, uint8, bytes4);Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | address[] | |
| <none> | address[] | |
| <none> | uint8 | |
| <none> | bytes4 |
registerChainSelector
function registerChainSelector(uint256 chainId, uint64 selector) internal;Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 | |
| selector | uint64 |
registerRemoteGateway
function registerRemoteGateway(uint256 chainId, address remote) internal;Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 | |
| remote | address |
configureDestination
function configureDestination(uint256 chainId, uint256 gasLimit, bool allowOutOfOrderExecution) internal;Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 | |
| gasLimit | uint256 | |
| allowOutOfOrderExecution | bool |
setFeeToken
function setFeeToken(address feeToken_) internal;Parameters
| Name | Type | Description |
|---|---|---|
| feeToken_ | address |
configureCCV
Configures the CCV requirements + allowed finality returned to the router for inbound messages
from chainId. optionalThreshold must be ≤ optionalCCVs.length.
function configureCCV(
uint256 chainId,
address[] calldata requiredCCVs,
address[] calldata optionalCCVs,
uint8 optionalThreshold,
bytes4 allowedFinalityConfig
) internal;Parameters
| Name | Type | Description |
|---|---|---|
| chainId | uint256 | |
| requiredCCVs | address[] | |
| optionalCCVs | address[] | |
| optionalThreshold | uint8 | |
| allowedFinalityConfig | bytes4 |
sendMessage
ERC-7786 source. Quotes the CCIP fee and submits the message immediately (synchronous, no
further action required), so it returns bytes32(0) per ERC-7786. The CCIP messageId is
emitted by the router's own event. The fee is paid by msg.sender: native via msg.value
(excess refunded), or an ERC-20 fee token pulled from the caller — never from Diamond funds.
No attributes are supported — any attribute reverts UnsupportedAttribute.
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 |
ccipReceive
CCIP delivery callback: validate router + source selector + trusted remote gateway, de-dup per (chainId, messageId), then deliver to the ERC-7930 recipient encoded in the payload.
function ccipReceive(Client.Any2EVMMessage calldata message) internal;Parameters
| Name | Type | Description |
|---|---|---|
| message | Client.Any2EVMMessage |
_buildMessage
Builds the CCIP EVM2AnyMessage for recipient/payload and returns the dest chain selector.
Reverts UnknownDestinationChain if the selector/remote is unset, DestinationNotConfigured if
the delivery gas limit is unset. Wraps the final ERC-7930 recipient inside the wire payload.
function _buildMessage(bytes calldata recipient, bytes calldata payload)
private
view
returns (Client.EVM2AnyMessage memory message, uint64 selector);Parameters
| Name | Type | Description |
|---|---|---|
| recipient | bytes | |
| payload | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| message | Client.EVM2AnyMessage | |
| selector | uint64 |