LZCrossChainBridge
Inherits: Owned, IVersioned, ReEnablerGracePeriod, ILZCrossChainBridge, Rescueable
Title: LZCrossChainBridge
Sends OHM to other chains using LayerZero V2.
It is a periphery contract, as it does not require any privileged access to the Olympus protocol. The user approves this contract for OHM, then calls sendOhm(). OHM is transferred to the gateway, which burns it and sends a LayerZero message.
Authorization for the lifecycle entry points splits responsibilities between the owner
and the address pinned in configurator (expected to be an
LZBridgeAndDelegateConfig instance, i.e. the timelock policy):
enable,disable,rescue, and the bootstrapsetConfiguratorcall are restricted to the owner.setGateway,setReEnabler,setGracePeriod, and the post-bootstrap rotation ofsetConfiguratorare restricted to the currentconfigurator.reEnableis restricted to the configuredreEnabler, which is set in the constructor and may be updated or cleared viasetReEnabler. A re-enable additionally requires that the grace window since the last transition has not yet elapsed.
Constants
OHM
Returns the OHM token address.
address public immutable override OHM;
Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
State Variables
gateway
Returns the LZBridgeGateway address.
address public override gateway;
Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
reEnabler
Returns the address authorized to call reEnable().
Returns address(0) when no re-enabler has been configured.
address public override reEnabler;
Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
configurator
Returns the configurator address (an LZBridgeAndDelegateConfig instance).
Returns address(0) before the owner has performed the bootstrap call.
address public override configurator;
Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
Functions
onlyConfigurator
Reverts if msg.sender is not the currently configured configurator.
The check also rejects calls while the configurator variable is unset, i.e.
before the owner has performed the bootstrap setConfigurator call.
modifier onlyConfigurator();
_requireConfigurator
Reverts if msg.sender is not the currently configured configurator.
The check also rejects calls while the configurator variable is unset, i.e.
before the owner has performed the bootstrap setConfigurator call.
function _requireConfigurator() private view;
constructor
constructor(
address ohm_,
address owner_,
address gateway_,
address reEnabler_,
uint32 grace_
) Owned(owner_) ReEnablerGracePeriod(grace_);
Parameters
| Name | Type | Description |
|---|---|---|
| ohm_ | address | |
| owner_ | address | |
| gateway_ | address | |
| reEnabler_ | address | |
| grace_ | uint32 |
VERSION
Returns the version of the contract
function VERSION() external pure override returns (uint8 major, uint8 minor);
Returns
| Name | Type | Description |
|---|---|---|
| major | uint8 | - Major version upgrade indicates breaking change to the interface. |
| minor | uint8 | - Minor version change retains backward-compatible interface. |
sendOhm
Sends OHM to a destination chain via the gateway.
Reverts if:
- The bridge is not enabled.
amount_is zero.- The user has insufficient OHM balance or approval.
- The gateway reverts (e.g. no peer configured, rate limit exceeded, gateway not enabled).
function sendOhm(
uint32 dstEid_,
address to_,
uint256 amount_
) external payable override givenEnabled;
Parameters
| Name | Type | Description |
|---|---|---|
| dstEid_ | uint32 | The LayerZero destination endpoint ID. |
| to_ | address | The recipient address on the destination chain. |
| amount_ | uint256 | The amount of OHM to send. |
setGateway
Sets the gateway address.
Reverts if:
- The caller is not the configurator.
gateway_is the zero address.
function setGateway(address gateway_) external override onlyConfigurator;
Parameters
| Name | Type | Description |
|---|---|---|
| gateway_ | address | The new gateway address. |
_authorizeRescue
Hook for subclasses to authorize the caller of rescue().
Implementations MUST revert if the caller is not authorised.
function _authorizeRescue() internal view override onlyOwner;
setReEnabler
Sets the address authorized to call reEnable().
Reverts if:
- The caller is not the configurator.
function setReEnabler(address reEnabler_) external override onlyConfigurator;
Parameters
| Name | Type | Description |
|---|---|---|
| reEnabler_ | address | The new re-enabler address, or address(0) to clear. |
setConfigurator
Sets the configurator address.
In both cases the new configurator must implement ILZBridgeAndDelegateConfig
via ERC-165 to prevent the bridge from being bricked by an incompatible address.
Reverts if:
- The bootstrap call is made by anyone other than the owner.
- A subsequent rotation is made by anyone other than the current configurator.
newConfigurator_is the zero address.newConfigurator_does not implementILZBridgeAndDelegateConfigvia ERC-165.
function setConfigurator(address newConfigurator_) external override;
Parameters
| Name | Type | Description |
|---|---|---|
| newConfigurator_ | address | The new configurator address. |
estimateSendFee
Estimates the fee for sending OHM to a destination chain.
Proxies to the gateway's estimateSendFee function with empty extra options.
function estimateSendFee(
uint32 dstEid_,
address to_,
uint256 amount_
) external view override returns (MessagingFee memory fee);
Parameters
| Name | Type | Description |
|---|---|---|
| dstEid_ | uint32 | The LayerZero destination endpoint ID. |
| to_ | address | The recipient address on the destination chain. |
| amount_ | uint256 | The amount of OHM to send. |
Returns
| Name | Type | Description |
|---|---|---|
| fee | MessagingFee | The estimated messaging fee (native + lzToken (unused)). |
sendable
Returns the current outbound capacity for a destination endpoint, with the in-flight amount decayed against the current timestamp.
Proxies to the gateway's sendable function.
function sendable(
uint32 dstEid_
) external view override returns (uint256 inFlight, uint256 available);
Parameters
| Name | Type | Description |
|---|---|---|
| dstEid_ | uint32 | The LayerZero destination endpoint ID. |
Returns
| Name | Type | Description |
|---|---|---|
| inFlight | uint256 | The decayed outbound in-flight amount at the current timestamp. |
| available | uint256 | The amount that may still be sent to the destination before the outbound rate limit is exceeded. |
receivable
Returns the current inbound capacity for a source endpoint, with the in-flight amount decayed against the current timestamp.
Proxies to the gateway's receivable function.
function receivable(
uint32 srcEid_
) external view override returns (uint256 inFlight, uint256 available);
Parameters
| Name | Type | Description |
|---|---|---|
| srcEid_ | uint32 | The LayerZero source endpoint ID. |
Returns
| Name | Type | Description |
|---|---|---|
| inFlight | uint256 | The decayed inbound in-flight amount at the current timestamp. |
| available | uint256 | The amount that may still be received from the source before the inbound rate limit is exceeded. |
supportsInterface
function supportsInterface(
bytes4 interfaceId
) public view override(ReEnablerGracePeriod, Rescueable) returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
| interfaceId | bytes4 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
_authorizeEnable
Validates that the caller is permitted to enable the contract.
Reverts if:
- The caller is not authorized to perform the enable.
The function is invoked from enable before any state mutation.
The data_ payload is forwarded unchanged so that authorization
may depend on the contents of the call.
function _authorizeEnable(bytes calldata) internal view override;
Parameters
| Name | Type | Description |
|---|---|---|
| _ | bytes | The calldata payload passed to enable. |
_authorizeDisable
Validates that the caller is permitted to disable the contract.
Reverts if:
- The caller is not authorized to perform the disable.
The function is invoked from disable before any state mutation.
The data_ payload is forwarded unchanged so that authorization
may depend on the contents of the call.
function _authorizeDisable(bytes calldata) internal view override;
Parameters
| Name | Type | Description |
|---|---|---|
| _ | bytes | The calldata payload passed to disable. |
_authorizeReEnable
The function is invoked from reEnable after the state checks pass and before
any state mutation.
Reverts if:
- The caller is not authorized to perform the re-enable.
Reverts if msg.sender is not the configured re-enabler. The check also rejects calls when no re-enabler
has been set (i.e. reEnabler == address(0)).
function _authorizeReEnable() internal view override;
_authorizeSetGracePeriod
Validates that the caller is permitted to update the grace window.
Reverts if:
- The caller is not authorized to update the grace window.
Restricts setGracePeriod to the address pinned in configurator (expected
to be the LZBridgeAndDelegateConfig timelock policy).
function _authorizeSetGracePeriod() internal view override;
validateSetGateway
Validates the payload that would be passed to setGateway.
Reverts if:
gateway_is the zero address.
function validateSetGateway(address gateway_) public pure override;
Parameters
| Name | Type | Description |
|---|---|---|
| gateway_ | address | The candidate gateway address. |
validateSetConfigurator
Validates the payload that would be passed to setConfigurator.
Reverts if:
newConfigurator_is the zero address.newConfigurator_does not implementILZBridgeAndDelegateConfigvia ERC-165.
function validateSetConfigurator(address newConfigurator_) public view override;
Parameters
| Name | Type | Description |
|---|---|---|
| newConfigurator_ | address | The candidate configurator address. |
_onlyOwner
function _onlyOwner() private view;
_setGateway
function _setGateway(address gateway_) private;
Parameters
| Name | Type | Description |
|---|---|---|
| gateway_ | address |
_setReEnabler
function _setReEnabler(address reEnabler_) private;
Parameters
| Name | Type | Description |
|---|---|---|
| reEnabler_ | address |
_requireNonzeroAddress
function _requireNonzeroAddress(address address_, string memory parameter_) private pure;
Parameters
| Name | Type | Description |
|---|---|---|
| address_ | address | |
| parameter_ | string |