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.

State Variables

MINTR

MINTRv1 public MINTR

lzEndpoint

ILayerZeroEndpoint public immutable lzEndpoint

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_);

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[]requests - 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;

_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;

lzReceive

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

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;

retryMessage

Retry a failed receive message

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

_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;

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);

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");

setSendVersion

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

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

setReceiveVersion

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

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

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");

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");

setTrustedRemoteAddress

Convenience function for setting trusted paths between EVM addresses

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

setPrecrime

Sets precrime address

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

setBridgeStatus

Activate or deactivate the bridge

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

getConfig

Gets endpoint config for this contract

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

getTrustedRemoteAddress

Get trusted remote for the given chain as an

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

isTrustedRemote

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

Events

BridgeTransferred

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

BridgeReceived

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

MessageFailed

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

RetryMessageSuccess

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

SetPrecrime

event SetPrecrime(address precrime_);

SetTrustedRemote

event SetTrustedRemote(uint16 remoteChainId_, bytes path_);

SetTrustedRemoteAddress

event SetTrustedRemoteAddress(uint16 remoteChainId_, bytes remoteAddress_);

SetMinDstGas

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

BridgeStatusSet

event BridgeStatusSet(bool isActive_);

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();