Skip to main content

CCIPCrossChainBridge

Git Source

Inherits: CCIPReceiver, PeripheryEnabler, Owned, ICCIPCrossChainBridge

Sends and receives OHM between chains using Chainlink CCIP It is a periphery contract, as it does not require any privileged access to the Olympus protocol. The contract is designed to be an intermediary when receiving OHM, so that failed messages can be retried.

State Variables

OHM

IERC20 public immutable OHM;

_trustedRemoteEVM

Mapping of EVM chain selectors to trusted bridge contracts

When sending, this is used to determine the initial recipient of a bridging message. When receiving, this is used to validate the sender of the message. As the zero address can be a trusted remote, the isSet flag is used to determine if the trusted remote is set.

mapping(uint64 => TrustedRemoteEVM) internal _trustedRemoteEVM;

_trustedRemoteSVM

Mapping of SVM chain selectors to trusted recipients

When sending, this is used to determine the initial recipient of a bridging message. When receiving, this is used to validate the sender of the message. As the zero address can be a trusted remote, the isSet flag is used to determine if the trusted remote is set.

mapping(uint64 => TrustedRemoteSVM) internal _trustedRemoteSVM;

_failedMessages

Mapping of message IDs to failed messages

When a message fails to receive, it is stored here to allow for retries.

mapping(bytes32 => Client.Any2EVMMessage) internal _failedMessages;

_gasLimits

Mapping of destination chain selectors to gas limits

When sending, this is used to determine the gas limit for the message.

mapping(uint64 => uint32) internal _gasLimits;

Functions

constructor

constructor(address ohm_, address ccipRouter_, address owner_) Owned(owner_) CCIPReceiver(ccipRouter_);

_buildCCIPMessage

function _buildCCIPMessage(bytes memory to_, uint256 amount_, bytes memory data_, bytes memory extraArgs_)
internal
view
returns (Client.EVM2AnyMessage memory);

_getSVMExtraArgs

function _getSVMExtraArgs(uint64 dstChainSelector_, bytes32 to_) internal view returns (bytes memory);

_getEVMExtraArgs

function _getEVMExtraArgs(uint64 dstChainSelector_) internal view returns (bytes memory);

_getEVMData

function _getEVMData(uint64 dstChainSelector_, address to_)
internal
view
returns (bytes memory recipient, bytes memory data, bytes memory extraArgs);

_getSVMData

function _getSVMData(uint64 dstChainSelector_, bytes32 to_)
internal
view
returns (bytes memory recipient, bytes memory data, bytes memory extraArgs);

getFeeSVM

Gets the fee for sending OHM to the specified destination SVM chain

This can be used to send to an address on any chain supported by CCIP

function getFeeSVM(uint64 dstChainSelector_, bytes32 to_, uint256 amount_) external view returns (uint256 fee_);

Parameters

NameTypeDescription
dstChainSelector_uint64The destination chain selector
to_bytes32The destination address
amount_uint256The amount of OHM to send

Returns

NameTypeDescription
fee_uint256The fee for sending OHM to the specified destination chain

getFeeEVM

Gets the fee for sending OHM to the specified destination EVM chain

This can be used to send to an address on any EVM chain supported by CCIP

function getFeeEVM(uint64 dstChainSelector_, address to_, uint256 amount_) external view returns (uint256 fee_);

Parameters

NameTypeDescription
dstChainSelector_uint64The destination chain selector
to_addressThe destination address
amount_uint256The amount of OHM to send

Returns

NameTypeDescription
fee_uint256The fee for sending OHM to the specified destination EVM chain

_sendOhm

function _sendOhm(
uint64 dstChainSelector_,
bytes memory to_,
uint256 amount_,
bytes memory data_,
bytes memory extraArgs_
) internal returns (bytes32);

sendToSVM

Sends OHM to the specified destination SVM chain

Unless specified for the chain through setGasLimit(), the gas limit will be 0

function sendToSVM(uint64 dstChainSelector_, bytes32 to_, uint256 amount_)
external
payable
onlyEnabled
returns (bytes32);

Parameters

NameTypeDescription
dstChainSelector_uint64The destination chain selector
to_bytes32The destination address
amount_uint256The amount of OHM to send

Returns

NameTypeDescription
<none>bytes32messageId The message ID of the sent message

sendToEVM

Sends OHM to the specified destination EVM chain

Unless specified for the chain through setGasLimit(), the gas limit will be 0

function sendToEVM(uint64 dstChainSelector_, address to_, uint256 amount_)
external
payable
onlyEnabled
returns (bytes32);

Parameters

NameTypeDescription
dstChainSelector_uint64The destination chain selector
to_addressThe destination address
amount_uint256The amount of OHM to send

Returns

NameTypeDescription
<none>bytes32messageId The message ID of the sent message

withdraw

Allows the owner to withdraw the native token from the contract

This is needed as senders may provide more native token than needed to cover fees

function withdraw(address recipient_) external onlyOwner;

Parameters

NameTypeDescription
recipient_addressThe recipient of the native token

_ccipReceive

Override this function in your implementation.

This function is designed to not revert, and instead will capture any errors in order to mark the message as failed. The message can be retried using the retryFailedMessage() function.

function _ccipReceive(Client.Any2EVMMessage memory message_) internal override;

Parameters

NameTypeDescription
message_Client.Any2EVMMessage

_receiveMessage

Actual handler for receiving CCIP messages

Does NOT support receiving messages from SVM, since they will not go through this contract

function _receiveMessage(Client.Any2EVMMessage memory message_) internal;

receiveMessage

Receives a message from the CCIP router

This function can only be called by the contract

function receiveMessage(Client.Any2EVMMessage calldata message_) external;

retryFailedMessage

Retries a failed message

*This function will revert if:

  • The message is not in the failedMessages mapping
  • The message sender is not a trusted remote
  • The message tokens array is not of length 1
  • The message token is not OHM
  • The message data is not a valid EVM address*
function retryFailedMessage(bytes32 messageId_) external;

Parameters

NameTypeDescription
messageId_bytes32The message ID

getFailedMessage

Gets the failed message for the specified message ID

This function re-creates the Client.Any2EVMMessage struct in order to return the correct type. This is done to avoid requiring the caller to import the Client library.

function getFailedMessage(bytes32 messageId_) external view returns (ICCIPClient.Any2EVMMessage memory);

Parameters

NameTypeDescription
messageId_bytes32The message ID

Returns

NameTypeDescription
<none>ICCIPClient.Any2EVMMessagemessage_ The failed message

setTrustedRemoteEVM

Sets the trusted remote for the specified destination EVM chain

This is needed to send/receive messages to/from the specified destination EVM chain

function setTrustedRemoteEVM(uint64 dstChainSelector_, address to_) external onlyOwner;

Parameters

NameTypeDescription
dstChainSelector_uint64The destination chain selector
to_addressThe destination address

unsetTrustedRemoteEVM

Unsets the trusted remote for the specified destination EVM chain

This is needed to stop sending/receiving messages to/from the specified destination EVM chain

function unsetTrustedRemoteEVM(uint64 dstChainSelector_) external onlyOwner;

Parameters

NameTypeDescription
dstChainSelector_uint64The destination chain selector

getTrustedRemoteEVM

Gets the trusted remote for the specified destination EVM chain

This function will revert if the trusted remote is not set

function getTrustedRemoteEVM(uint64 dstChainSelector_) external view returns (TrustedRemoteEVM memory);

Parameters

NameTypeDescription
dstChainSelector_uint64The destination chain selector

Returns

NameTypeDescription
<none>TrustedRemoteEVMto_ The destination address

setTrustedRemoteSVM

Sets the trusted remote for the specified destination SVM chain

This is needed to send/receive messages to/from the specified destination SVM chain

function setTrustedRemoteSVM(uint64 dstChainSelector_, bytes32 to_) external onlyOwner;

Parameters

NameTypeDescription
dstChainSelector_uint64The destination chain selector
to_bytes32The destination address

unsetTrustedRemoteSVM

Unsets the trusted remote for the specified destination SVM chain

This is needed to stop sending/receiving messages to/from the specified destination SVM chain

function unsetTrustedRemoteSVM(uint64 dstChainSelector_) external onlyOwner;

Parameters

NameTypeDescription
dstChainSelector_uint64The destination chain selector

getTrustedRemoteSVM

Gets the trusted remote for the specified destination SVM chain

This function will revert if the trusted remote is not set

function getTrustedRemoteSVM(uint64 dstChainSelector_) external view returns (TrustedRemoteSVM memory);

Parameters

NameTypeDescription
dstChainSelector_uint64The destination chain selector

Returns

NameTypeDescription
<none>TrustedRemoteSVMto_ The destination address

setGasLimit

Sets the gas limit for the specified destination chain

function setGasLimit(uint64 dstChainSelector_, uint32 gasLimit_) external onlyOwner;

Parameters

NameTypeDescription
dstChainSelector_uint64The destination chain selector
gasLimit_uint32The gas limit

getGasLimit

Gets the gas limit for the specified destination chain

function getGasLimit(uint64 dstChainSelector_) external view returns (uint32);

Parameters

NameTypeDescription
dstChainSelector_uint64The destination chain selector

Returns

NameTypeDescription
<none>uint32gasLimit_ The gas limit, or 0 if not set

getCCIPRouter

Gets the CCIP router address

function getCCIPRouter() external view returns (address);

Returns

NameTypeDescription
<none>addressccipRouter_ The CCIP router address

supportsInterface

function supportsInterface(bytes4 interfaceId_)
public
view
virtual
override(CCIPReceiver, PeripheryEnabler)
returns (bool);

_enable

Implementation-specific enable function

*This function is called by the enable() function The implementing contract can override this function and perform the following:

  1. Validate any parameters (if needed) or revert
  2. Validate state (if needed) or revert
  3. Perform any necessary actions, apart from modifying the isEnabled state variable*
function _enable(bytes calldata) internal override;

Parameters

NameTypeDescription
<none>bytes

_disable

Implementation-specific disable function

*This function is called by the disable() function The implementing contract can override this function and perform the following:

  1. Validate any parameters (if needed) or revert
  2. Validate state (if needed) or revert
  3. Perform any necessary actions, apart from modifying the isEnabled state variable*
function _disable(bytes calldata) internal override;

Parameters

NameTypeDescription
<none>bytes

_onlyOwner

Implementation-specific validation of ownership

Implementing contracts should override this function to perform the appropriate validation and revert if the caller is not permitted to enable/disable the contract.

function _onlyOwner() internal view override;