Skip to main content

LZCrossChainBridge

Git Source

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 bootstrap setConfigurator call are restricted to the owner.
  • setGateway, setReEnabler, setGracePeriod, and the post-bootstrap rotation of setConfigurator are restricted to the current configurator.
  • reEnable is restricted to the configured reEnabler, which is set in the constructor and may be updated or cleared via setReEnabler. 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

NameTypeDescription
<none>address

State Variables​

gateway​

Returns the LZBridgeGateway address.

address public override gateway;

Returns

NameTypeDescription
<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

NameTypeDescription
<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

NameTypeDescription
<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

NameTypeDescription
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

NameTypeDescription
majoruint8- Major version upgrade indicates breaking change to the interface.
minoruint8- 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

NameTypeDescription
dstEid_uint32The LayerZero destination endpoint ID.
to_addressThe recipient address on the destination chain.
amount_uint256The 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

NameTypeDescription
gateway_addressThe 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

NameTypeDescription
reEnabler_addressThe 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 implement ILZBridgeAndDelegateConfig via ERC-165.
function setConfigurator(address newConfigurator_) external override;

Parameters

NameTypeDescription
newConfigurator_addressThe 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

NameTypeDescription
dstEid_uint32The LayerZero destination endpoint ID.
to_addressThe recipient address on the destination chain.
amount_uint256The amount of OHM to send.

Returns

NameTypeDescription
feeMessagingFeeThe 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

NameTypeDescription
dstEid_uint32The LayerZero destination endpoint ID.

Returns

NameTypeDescription
inFlightuint256The decayed outbound in-flight amount at the current timestamp.
availableuint256The 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

NameTypeDescription
srcEid_uint32The LayerZero source endpoint ID.

Returns

NameTypeDescription
inFlightuint256The decayed inbound in-flight amount at the current timestamp.
availableuint256The 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

NameTypeDescription
interfaceIdbytes4

Returns

NameTypeDescription
<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

NameTypeDescription
_bytesThe 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

NameTypeDescription
_bytesThe 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

NameTypeDescription
gateway_addressThe candidate gateway address.

validateSetConfigurator​

Validates the payload that would be passed to setConfigurator.

Reverts if:

  • newConfigurator_ is the zero address.
  • newConfigurator_ does not implement ILZBridgeAndDelegateConfig via ERC-165.
function validateSetConfigurator(address newConfigurator_) public view override;

Parameters

NameTypeDescription
newConfigurator_addressThe candidate configurator address.

_onlyOwner​

function _onlyOwner() private view;

_setGateway​

function _setGateway(address gateway_) private;

Parameters

NameTypeDescription
gateway_address

_setReEnabler​

function _setReEnabler(address reEnabler_) private;

Parameters

NameTypeDescription
reEnabler_address

_requireNonzeroAddress​

function _requireNonzeroAddress(address address_, string memory parameter_) private pure;

Parameters

NameTypeDescription
address_address
parameter_string