Skip to main content

ILZCrossChainBridge

Git Source

Title: ILZCrossChainBridge

Interface for the LZ Cross-Chain Bridge facilitator, the user-facing entry point for sending OHM to other chains via LayerZero V2.

It is a periphery contract, as it does not require any privileged access to the Olympus protocol. It transfers OHM from the user to the gateway, which handles burning and sending.

Functions​

sendOhm​

Sends OHM to a destination chain via the gateway.

The user must approve this contract for the OHM amount before calling. OHM is transferred from the user to the gateway, then the gateway burns and sends via LayerZero. The caller must send the native token with the call to cover the LayerZero messaging fee; excess is refunded to msg.sender. Use estimateSendFee() to determine the required fee.

function sendOhm(uint32 dstEid_, address to_, uint256 amount_) external payable;

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.

Only callable by the address pinned in configurator, which is expected to be an LZBridgeAndDelegateConfig instance (the timelock policy).

function setGateway(address gateway_) external;

Parameters

NameTypeDescription
gateway_addressThe new gateway address.

setReEnabler​

Sets the address authorized to call reEnable().

Only callable by the address pinned in configurator, which is expected to be an LZBridgeAndDelegateConfig instance (the timelock policy). The zero address is permitted and effectively disables the reEnable() entry point until a non-zero address is set.

function setReEnabler(address reEnabler_) external;

Parameters

NameTypeDescription
reEnabler_addressThe new re-enabler address, or address(0) to clear.

setConfigurator​

Sets the configurator address.

Bootstrap: when configurator is the zero address, only the owner may set the first non-zero configurator. After bootstrap, rotation is only allowed by the current configurator. The configurator is expected to be an LZBridgeAndDelegateConfig instance (the timelock policy).

In both cases the new configurator must implement ILZBridgeAndDelegateConfig via ERC-165 to prevent the bridge from being bricked by an incompatible address.

function setConfigurator(address newConfigurator_) external;

Parameters

NameTypeDescription
newConfigurator_addressThe new configurator address.

validateSetGateway​

Validates the payload that would be passed to setGateway.

Mirrors the input invariants enforced by setGateway so that callers (for instance, a timelock policy) can fail early at queue time rather than at execution time.

function validateSetGateway(address gateway_) external pure;

Parameters

NameTypeDescription
gateway_addressThe candidate gateway address.

validateSetConfigurator​

Validates the payload that would be passed to setConfigurator.

Mirrors the payload invariants enforced by setConfigurator: the zero-address check and the ERC-165 ILZBridgeAndDelegateConfig guard.

function validateSetConfigurator(address newConfigurator_) external view;

Parameters

NameTypeDescription
newConfigurator_addressThe candidate configurator address.

gateway​

Returns the LZBridgeGateway address.

function gateway() external view returns (address);

Returns

NameTypeDescription
<none>address

reEnabler​

Returns the address authorized to call reEnable().

Returns address(0) when no re-enabler has been configured.

function reEnabler() external view returns (address);

Returns

NameTypeDescription
<none>address

configurator​

Returns the configurator address (an LZBridgeAndDelegateConfig instance).

Returns address(0) before the owner has performed the bootstrap call.

function configurator() external view returns (address);

Returns

NameTypeDescription
<none>address

OHM​

Returns the OHM token address.

function OHM() external view returns (address);

Returns

NameTypeDescription
<none>address

estimateSendFee​

Estimates the fee for sending OHM to a destination chain.

function estimateSendFee(
uint32 dstEid_,
address to_,
uint256 amount_
) external view 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.

function sendable(uint32 dstEid_) external view 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.

function receivable(uint32 srcEid_) external view 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.

Events​

Bridged​

Emitted when OHM is sent to another chain.

event Bridged(
address indexed sender,
uint256 amount,
uint32 indexed dstEid,
uint256 nativeFee,
uint256 msgValue
);

Parameters

NameTypeDescription
senderaddressThe address that initiated the bridge transfer.
amountuint256The amount of OHM bridged.
dstEiduint32The LayerZero destination endpoint ID.
nativeFeeuint256The native token fee actually charged by LayerZero, read from
MessagingReceipt. May be less than msgValue when the caller overpays;
the excess is refunded to the sender by the LayerZero endpoint.
msgValueuint256The native value the caller supplied with the transaction.

GatewaySet​

Emitted when the gateway address is updated.

event GatewaySet(address indexed gateway);

Parameters

NameTypeDescription
gatewayaddressThe new gateway address.

ReEnablerSet​

Emitted when the re-enabler address is updated.

Setting the re-enabler to the zero address effectively disables the reEnable() entry point until a non-zero address is configured again.

event ReEnablerSet(address indexed reEnabler);

Parameters

NameTypeDescription
reEnableraddressThe new re-enabler address, or address(0) to clear.

ConfiguratorSet​

Emitted when the configurator address is updated.

event ConfiguratorSet(address indexed configurator);

Parameters

NameTypeDescription
configuratoraddressThe new configurator address.

Errors​

LZCrossChainBridge_InvalidAddress​

Thrown when an address argument is the zero address.

error LZCrossChainBridge_InvalidAddress(string parameter);

Parameters

NameTypeDescription
parameterstringThe name of the invalid parameter.

LZCrossChainBridge_InsufficientAmount​

Thrown when the send amount is zero.

error LZCrossChainBridge_InsufficientAmount();

LZCrossChainBridge_InvalidConfigurator​

Thrown when setConfigurator is supplied a contract that does not implement the ILZBridgeAndDelegateConfig interface via ERC-165.

error LZCrossChainBridge_InvalidConfigurator(address newConfigurator);

Parameters

NameTypeDescription
newConfiguratoraddressThe unsupported new configurator address.