CrossChainBridge
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
| Name | Type | Description |
|---|---|---|
| kernel_ | Kernel | |
| endpoint_ | address |
configureDependencies
Define module dependencies for this policy.
function configureDependencies() external override returns (Keycode[] memory dependencies);
Returns
| Name | Type | Description |
|---|---|---|
| dependencies | Keycode[] | - 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
| Name | Type | Description |
|---|---|---|
| permissions | Permissions[] | - 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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| srcChainId_ | uint16 | |
| _ | bytes | |
| _ | uint64 | |
| payload_ | bytes |
lzReceive
function lzReceive(
uint16 srcChainId_,
bytes calldata srcAddress_,
uint64 nonce_,
bytes calldata payload_
) public virtual override;
Parameters
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| dstChainId_ | uint16 | |
| to_ | address | |
| amount_ | uint256 | |
| adapterParams_ | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| nativeFee | uint256 | - Native token amount to send to sendOhm |
| zroFee | uint256 | - 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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| remoteChainId_ | uint16 | |
| remoteAddress_ | bytes |
setPrecrime
Sets precrime address
function setPrecrime(address precrime_) external onlyRole("bridge_admin");
Parameters
| Name | Type | Description |
|---|---|---|
| precrime_ | address |
setBridgeStatus
Activate or deactivate the bridge
function setBridgeStatus(bool isActive_) external onlyRole("bridge_admin");
Parameters
| Name | Type | Description |
|---|---|---|
| isActive_ | bool |
getConfig
Gets endpoint config for this contract
function getConfig(
uint16 version_,
uint16 chainId_,
address,
uint256 configType_
) external view returns (bytes memory);
Parameters
| Name | Type | Description |
|---|---|---|
| version_ | uint16 | |
| chainId_ | uint16 | |
| _ | address | |
| configType_ | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes |
getTrustedRemoteAddress
Get trusted remote for the given chain as an
function getTrustedRemoteAddress(uint16 remoteChainId_) external view returns (bytes memory);
Parameters
| Name | Type | Description |
|---|---|---|
| remoteChainId_ | uint16 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes |
isTrustedRemote
function isTrustedRemote(
uint16 srcChainId_,
bytes calldata srcAddress_
) external view returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
| srcChainId_ | uint16 | |
| srcAddress_ | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
Events
BridgeTransferred
event BridgeTransferred(address indexed sender_, uint256 amount_, uint16 indexed dstChain_);
Parameters
| Name | Type | Description |
|---|---|---|
| sender_ | address | |
| amount_ | uint256 | |
| dstChain_ | uint16 |
BridgeReceived
event BridgeReceived(address indexed receiver_, uint256 amount_, uint16 indexed srcChain_);
Parameters
| Name | Type | Description |
|---|---|---|
| receiver_ | address | |
| amount_ | uint256 | |
| srcChain_ | uint16 |
MessageFailed
event MessageFailed(
uint16 srcChainId_,
bytes srcAddress_,
uint64 nonce_,
bytes payload_,
bytes reason_
);
Parameters
| Name | Type | Description |
|---|---|---|
| srcChainId_ | uint16 | |
| srcAddress_ | bytes | |
| nonce_ | uint64 | |
| payload_ | bytes | |
| reason_ | bytes |
RetryMessageSuccess
event RetryMessageSuccess(
uint16 srcChainId_,
bytes srcAddress_,
uint64 nonce_,
bytes32 payloadHash_
);
Parameters
| Name | Type | Description |
|---|---|---|
| srcChainId_ | uint16 | |
| srcAddress_ | bytes | |
| nonce_ | uint64 | |
| payloadHash_ | bytes32 |
SetPrecrime
event SetPrecrime(address precrime_);
Parameters
| Name | Type | Description |
|---|---|---|
| precrime_ | address |
SetTrustedRemote
event SetTrustedRemote(uint16 remoteChainId_, bytes path_);
Parameters
| Name | Type | Description |
|---|---|---|
| remoteChainId_ | uint16 | |
| path_ | bytes |
SetTrustedRemoteAddress
event SetTrustedRemoteAddress(uint16 remoteChainId_, bytes remoteAddress_);
Parameters
| Name | Type | Description |
|---|---|---|
| remoteChainId_ | uint16 | |
| remoteAddress_ | bytes |
SetMinDstGas
event SetMinDstGas(uint16 dstChainId_, uint16 type_, uint256 _minDstGas);
Parameters
| Name | Type | Description |
|---|---|---|
| dstChainId_ | uint16 | |
| type_ | uint16 | |
| _minDstGas | uint256 |
BridgeStatusSet
event BridgeStatusSet(bool isActive_);
Parameters
| Name | Type | Description |
|---|---|---|
| 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();