Skip to content
Lattice

CCIPGatewayAdapterLib

Git Source

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

NameTypeDescription
$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

NameTypeDescription
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

NameTypeDescription
<none>address

feeToken

function feeToken() internal view returns (address);

Returns

NameTypeDescription
<none>address

getChainSelector

function getChainSelector(uint256 chainId) internal view returns (uint64);

Parameters

NameTypeDescription
chainIduint256

Returns

NameTypeDescription
<none>uint64

getChainId

function getChainId(uint64 selector) internal view returns (uint256);

Parameters

NameTypeDescription
selectoruint64

Returns

NameTypeDescription
<none>uint256

getRemoteGateway

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

Parameters

NameTypeDescription
chainIduint256

Returns

NameTypeDescription
<none>address

getDestinationGasLimit

function getDestinationGasLimit(uint256 chainId) internal view returns (uint256);

Parameters

NameTypeDescription
chainIduint256

Returns

NameTypeDescription
<none>uint256

getAllowOutOfOrderExecution

function getAllowOutOfOrderExecution(uint256 chainId) internal view returns (bool);

Parameters

NameTypeDescription
chainIduint256

Returns

NameTypeDescription
<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

NameTypeDescription
_bytes4

Returns

NameTypeDescription
<none>bool

quoteFee

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

Parameters

NameTypeDescription
recipientbytes
payloadbytes

Returns

NameTypeDescription
<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

NameTypeDescription
sourceChainSelectoruint64

Returns

NameTypeDescription
<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

NameTypeDescription
chainIduint256

Returns

NameTypeDescription
<none>address[]
<none>address[]
<none>uint8
<none>bytes4

registerChainSelector

function registerChainSelector(uint256 chainId, uint64 selector) internal;

Parameters

NameTypeDescription
chainIduint256
selectoruint64

registerRemoteGateway

function registerRemoteGateway(uint256 chainId, address remote) internal;

Parameters

NameTypeDescription
chainIduint256
remoteaddress

configureDestination

function configureDestination(uint256 chainId, uint256 gasLimit, bool allowOutOfOrderExecution) internal;

Parameters

NameTypeDescription
chainIduint256
gasLimituint256
allowOutOfOrderExecutionbool

setFeeToken

function setFeeToken(address feeToken_) internal;

Parameters

NameTypeDescription
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

NameTypeDescription
chainIduint256
requiredCCVsaddress[]
optionalCCVsaddress[]
optionalThresholduint8
allowedFinalityConfigbytes4

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

NameTypeDescription
recipientbytes
payloadbytes
attributesbytes[]

Returns

NameTypeDescription
<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

NameTypeDescription
messageClient.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

NameTypeDescription
recipientbytes
payloadbytes

Returns

NameTypeDescription
messageClient.EVM2AnyMessage
selectoruint64