Skip to main content

CrossChainBridge

Git Source

Inherits: Policy, RolesConsumer, ILayerZeroReceiver, ILayerZeroUserApplicationConfig

Message bridge for cross-chain OHM transfers.

Uses LayerZero as communication protocol.

Each chain needs to setTrustedRemoteAddress for each remote address it intends to receive from.

Constants​

lzEndpoint​

ILayerZeroEndpoint public immutable lzEndpoint;

State Variables​

MINTR​

MINTRv1 public MINTR;

ohm​

ERC20 public ohm;

bridgeActive​

Flag to determine if bridge is allowed to send messages or not

bool public bridgeActive;

failedMessages​

Storage for failed messages on receive.

chainID => source address => endpoint nonce

mapping(uint16 => mapping(bytes => mapping(uint64 => bytes32))) public failedMessages;

trustedRemoteLookup​

Trusted remote paths. Must be set by admin.

mapping(uint16 => bytes) public trustedRemoteLookup;

precrime​

LZ precrime address. Currently unused.

address public precrime;

Functions​

constructor​

constructor(Kernel kernel_, address endpoint_) Policy(kernel_);

Parameters

NameTypeDescription
kernel_Kernel
endpoint_address

configureDependencies​

Define module dependencies for this policy.

function configureDependencies() external override returns (Keycode[] memory dependencies);

Returns

NameTypeDescription
dependenciesKeycode[]- Keycode array of module dependencies.

requestPermissions​

Function called by kernel to set module function permissions.

function requestPermissions()
external
view
override
returns (Permissions[] memory permissions);

Returns

NameTypeDescription
permissionsPermissions[]- Array of keycodes and function selectors for requested permissions.

sendOhm​

Send OHM to an eligible chain

function sendOhm(uint16 dstChainId_, address to_, uint256 amount_) external payable;

Parameters

NameTypeDescription
dstChainId_uint16
to_address
amount_uint256

_receiveMessage​

Implementation of receiving an LZ message

Function must be public to be called by low-level call in lzReceive

function _receiveMessage(
uint16 srcChainId_,
bytes memory,
uint64,
bytes memory payload_
) internal;

Parameters

NameTypeDescription
srcChainId_uint16
_bytes
_uint64
payload_bytes

lzReceive​

function lzReceive(
uint16 srcChainId_,
bytes calldata srcAddress_,
uint64 nonce_,
bytes calldata payload_
) public virtual override;

Parameters

NameTypeDescription
srcChainId_uint16
srcAddress_bytes
nonce_uint64
payload_bytes

receiveMessage​

Implementation of receiving an LZ message

Function must be public to be called by low-level call in lzReceive

function receiveMessage(
uint16 srcChainId_,
bytes memory srcAddress_,
uint64 nonce_,
bytes memory payload_
) public;

Parameters

NameTypeDescription
srcChainId_uint16
srcAddress_bytes
nonce_uint64
payload_bytes

retryMessage​

Retry a failed receive message

function retryMessage(
uint16 srcChainId_,
bytes calldata srcAddress_,
uint64 nonce_,
bytes calldata payload_
) public payable virtual;

Parameters

NameTypeDescription
srcChainId_uint16
srcAddress_bytes
nonce_uint64
payload_bytes

_sendMessage​

Internal function for sending a message across chains.

Params defined in ILayerZeroEndpoint send function.

function _sendMessage(
uint16 dstChainId_,
bytes memory payload_,
address payable refundAddress_,
address zroPaymentAddress_,
bytes memory adapterParams_,
uint256 nativeFee_
) internal;

Parameters

NameTypeDescription
dstChainId_uint16
payload_bytes
refundAddress_address payable
zroPaymentAddress_address
adapterParams_bytes
nativeFee_uint256

estimateSendFee​

Function to estimate how much gas is needed to send OHM

Should be called by frontend before making sendOhm call.

function estimateSendFee(
uint16 dstChainId_,
address to_,
uint256 amount_,
bytes calldata adapterParams_
) external view returns (uint256 nativeFee, uint256 zroFee);

Parameters

NameTypeDescription
dstChainId_uint16
to_address
amount_uint256
adapterParams_bytes

Returns

NameTypeDescription
nativeFeeuint256- Native token amount to send to sendOhm
zroFeeuint256- Fee paid in ZRO token. Unused.

setConfig​

Generic config for LayerZero User Application

function setConfig(
uint16 version_,
uint16 chainId_,
uint256 configType_,
bytes calldata config_
) external override onlyRole("bridge_admin");

Parameters

NameTypeDescription
version_uint16
chainId_uint16
configType_uint256
config_bytes

setSendVersion​

Set send version of endpoint to be used by LayerZero User Application

function setSendVersion(uint16 version_) external override onlyRole("bridge_admin");

Parameters

NameTypeDescription
version_uint16

setReceiveVersion​

Set receive version of endpoint to be used by LayerZero User Application

function setReceiveVersion(uint16 version_) external override onlyRole("bridge_admin");

Parameters

NameTypeDescription
version_uint16

forceResumeReceive​

Retries a received message. Used as last resort if retryPayload fails.

Unblocks queue and DESTROYS transaction forever. USE WITH CAUTION.

function forceResumeReceive(
uint16 srcChainId_,
bytes calldata srcAddress_
) external override onlyRole("bridge_admin");

Parameters

NameTypeDescription
srcChainId_uint16
srcAddress_bytes

setTrustedRemote​

Sets the trusted path for the cross-chain communication

path_ = abi.encodePacked(remoteAddress, localAddress)

function setTrustedRemote(
uint16 srcChainId_,
bytes calldata path_
) external onlyRole("bridge_admin");

Parameters

NameTypeDescription
srcChainId_uint16
path_bytes

setTrustedRemoteAddress​

Convenience function for setting trusted paths between EVM addresses

function setTrustedRemoteAddress(
uint16 remoteChainId_,
bytes calldata remoteAddress_
) external onlyRole("bridge_admin");

Parameters

NameTypeDescription
remoteChainId_uint16
remoteAddress_bytes

setPrecrime​

Sets precrime address

function setPrecrime(address precrime_) external onlyRole("bridge_admin");

Parameters

NameTypeDescription
precrime_address

setBridgeStatus​

Activate or deactivate the bridge

function setBridgeStatus(bool isActive_) external onlyRole("bridge_admin");

Parameters

NameTypeDescription
isActive_bool

getConfig​

Gets endpoint config for this contract

function getConfig(
uint16 version_,
uint16 chainId_,
address,
uint256 configType_
) external view returns (bytes memory);

Parameters

NameTypeDescription
version_uint16
chainId_uint16
_address
configType_uint256

Returns

NameTypeDescription
<none>bytes

getTrustedRemoteAddress​

Get trusted remote for the given chain as an

function getTrustedRemoteAddress(uint16 remoteChainId_) external view returns (bytes memory);

Parameters

NameTypeDescription
remoteChainId_uint16

Returns

NameTypeDescription
<none>bytes

isTrustedRemote​

function isTrustedRemote(
uint16 srcChainId_,
bytes calldata srcAddress_
) external view returns (bool);

Parameters

NameTypeDescription
srcChainId_uint16
srcAddress_bytes

Returns

NameTypeDescription
<none>bool

Events​

BridgeTransferred​

event BridgeTransferred(address indexed sender_, uint256 amount_, uint16 indexed dstChain_);

Parameters

NameTypeDescription
sender_address
amount_uint256
dstChain_uint16

BridgeReceived​

event BridgeReceived(address indexed receiver_, uint256 amount_, uint16 indexed srcChain_);

Parameters

NameTypeDescription
receiver_address
amount_uint256
srcChain_uint16

MessageFailed​

event MessageFailed(
uint16 srcChainId_,
bytes srcAddress_,
uint64 nonce_,
bytes payload_,
bytes reason_
);

Parameters

NameTypeDescription
srcChainId_uint16
srcAddress_bytes
nonce_uint64
payload_bytes
reason_bytes

RetryMessageSuccess​

event RetryMessageSuccess(
uint16 srcChainId_,
bytes srcAddress_,
uint64 nonce_,
bytes32 payloadHash_
);

Parameters

NameTypeDescription
srcChainId_uint16
srcAddress_bytes
nonce_uint64
payloadHash_bytes32

SetPrecrime​

event SetPrecrime(address precrime_);

Parameters

NameTypeDescription
precrime_address

SetTrustedRemote​

event SetTrustedRemote(uint16 remoteChainId_, bytes path_);

Parameters

NameTypeDescription
remoteChainId_uint16
path_bytes

SetTrustedRemoteAddress​

event SetTrustedRemoteAddress(uint16 remoteChainId_, bytes remoteAddress_);

Parameters

NameTypeDescription
remoteChainId_uint16
remoteAddress_bytes

SetMinDstGas​

event SetMinDstGas(uint16 dstChainId_, uint16 type_, uint256 _minDstGas);

Parameters

NameTypeDescription
dstChainId_uint16
type_uint16
_minDstGasuint256

BridgeStatusSet​

event BridgeStatusSet(bool isActive_);

Parameters

NameTypeDescription
isActive_bool

Errors​

Bridge_InsufficientAmount​

error Bridge_InsufficientAmount();

Bridge_InvalidCaller​

error Bridge_InvalidCaller();

Bridge_InvalidMessageSource​

error Bridge_InvalidMessageSource();

Bridge_NoStoredMessage​

error Bridge_NoStoredMessage();

Bridge_InvalidPayload​

error Bridge_InvalidPayload();

Bridge_DestinationNotTrusted​

error Bridge_DestinationNotTrusted();

Bridge_NoTrustedPath​

error Bridge_NoTrustedPath();

Bridge_Deactivated​

error Bridge_Deactivated();

Bridge_TrustedRemoteUninitialized​

error Bridge_TrustedRemoteUninitialized();