LZUnifiedBridge

Git Source

Inherits: BaseBridge, IBridge

Title: LZUnifiedBridge

Author: Malda Protocol

LayerZero v2 unified bridge used by the Rebalancer to send assets cross-chain via OFT-compatible tokens.

State Variables

ENDPOINT

LayerZero endpoint contract allowed to call lzCompose().

address public immutable ENDPOINT

bridgeContracts

Maps underlying token => bridge contract (OFT). If not set, defaults to underlying itself.

mapping(address underlying => address bridgeContract) public bridgeContracts

oftExecutors

Maps underlying token => executor contract used via delegatecall for send/compose flows.

mapping(address underlying => address executor) public oftExecutors

Functions

constructor

Creates the unified LayerZero bridge.

constructor(address _roles, address _endpoint) BaseBridge(_roles);

Parameters

NameTypeDescription
_rolesaddressRoles contract used by BaseBridge.
_endpointaddressLayerZero endpoint allowed to call lzCompose().

setBridgeContract

Sets the OFT bridge contract for an underlying token.

function setBridgeContract(address underlying, address bridgeContract) external onlyBridgeConfigurator;

Parameters

NameTypeDescription
underlyingaddressUnderlying token.
bridgeContractaddressOFT/bridge contract to use for that underlying.

setOftExecutorContract

Sets the executor contract for an underlying token.

function setOftExecutorContract(address underlying, address bridgeContract) external onlyBridgeConfigurator;

Parameters

NameTypeDescription
underlyingaddressUnderlying token.
bridgeContractaddressExecutor contract (kept as name for backward-compat with existing calls/logs).

sendMsg

Sends a message + tokens via OFT, delegating to an executor per underlying.

function sendMsg(
    uint256 _extractedAmount,
    address _market,
    uint32 _dstChainId,
    address _token,
    bytes calldata _message,
    bytes calldata _extraData
) external payable onlyRebalancer;

Parameters

NameTypeDescription
_extractedAmountuint256Amount extracted by the rebalancer.
_marketaddressMarket address expected inside _message.
_dstChainIduint32Destination chain id (eid).
_tokenaddressUnderlying token (must match market.underlying()).
_messagebytesABI-encoded (market, amountLD, minAmountLD, extraOptions).
_extraDatabytesABI-encoded refund address.

lzCompose

LayerZero compose callback. Delegates compose execution to the configured executor.

function lzCompose(address from, bytes32 guid, bytes calldata message, address executor, bytes calldata extraData)
    external
    payable;

Parameters

NameTypeDescription
fromaddressExpected to be the bridge contract (OFT) for the decoded underlying.
guidbytes32Unused.
messagebytesABI-encoded (market).
executoraddressUnused.
extraDatabytesUnused.

processUncomposedMessages

Processes any stored/uncomposed messages for a market (via executor).

function processUncomposedMessages(address _market) external payable onlyBridgeConfigurator;

Parameters

NameTypeDescription
_marketaddressMarket address.

getFee

Quotes the native fee required to send the message.

function getFee(uint32 _dstChainId, bytes calldata _message, bytes calldata _extraData)
    external
    view
    returns (uint256 nativeFee);

Parameters

NameTypeDescription
_dstChainIduint32Destination chain id (eid).
_messagebytesABI-encoded (market, amountLD, minAmountLD, extraOptions).
_extraDatabytesUnused.

Returns

NameTypeDescription
nativeFeeuint256Native fee quoted by the OFT.

_delegateExecuteSend

Delegates executeSend to the configured executor and decodes the MessagingReceipt.

function _delegateExecuteSend(
    address underlying,
    address bridgeContract,
    SendParam memory params,
    MessagingFee memory fees,
    address rebalancer,
    address refundAddress
) private returns (MessagingReceipt memory r);

Parameters

NameTypeDescription
underlyingaddressUnderlying token.
bridgeContractaddressOFT/bridge contract used for the send.
paramsSendParamLayerZero SendParam.
feesMessagingFeeLayerZero MessagingFee.
rebalanceraddressCaller (expected rebalancer).
refundAddressaddressRefund address for any extra native fee.

Returns

NameTypeDescription
rMessagingReceiptMessagingReceipt returned by the executor.

_getFee

Internal helper to quote fees and build SendParam.

function _getFee(uint32 dstEid, bytes calldata _message)
    private
    view
    returns (MessagingFee memory fees, SendParam memory lzSendParams);

Parameters

NameTypeDescription
dstEiduint32Destination chain id (eid).
_messagebytesABI-encoded (market, amountLD, minAmountLD, extraOptions).

Returns

NameTypeDescription
feesMessagingFeeLayerZero messaging fees.
lzSendParamsSendParamLayerZero send parameters.

Events

MsgSent

Emitted after a message is sent via LayerZero.

event MsgSent(
    uint32 indexed dstChainId, address indexed market, uint256 amountLD, uint256 minAmountLD, bytes32 guid
);

Parameters

NameTypeDescription
dstChainIduint32Destination chain id (eid).
marketaddressMarket address encoded in compose payload.
amountLDuint256Amount sent (local decimals).
minAmountLDuint256Minimum amount expected on destination (local decimals).
guidbytes32LayerZero message GUID.

BridgeContractSet

Emitted when a bridge contract is configured for an underlying.

event BridgeContractSet(address indexed underlying, address indexed bridgeContract);

Parameters

NameTypeDescription
underlyingaddressUnderlying token address.
bridgeContractaddressBridge contract (OFT) used for that underlying.

OftExecutorSet

Emitted when an OFT executor is configured for an underlying.

event OftExecutorSet(address indexed underlying, address indexed executor);

Parameters

NameTypeDescription
underlyingaddressUnderlying token address.
executoraddressExecutor contract address.

Errors

LZBridge_NotEnoughFees

error LZBridge_NotEnoughFees();

LZBridge_ChainNotRegistered

error LZBridge_ChainNotRegistered();

LZBridge_DestinationMismatch

error LZBridge_DestinationMismatch();

LZBridge_DifferentInnerToken

error LZBridge_DifferentInnerToken();

LZBridge_NoOft

error LZBridge_NoOft();

LZBridge_TokenMismatch

error LZBridge_TokenMismatch();

LZBridge_ExecutorNotSet

error LZBridge_ExecutorNotSet();

LZBridge_ExecutorNoCode

error LZBridge_ExecutorNoCode();

LZBridge_OnlyEndpoint

error LZBridge_OnlyEndpoint();

LZBridge_BadFrom

error LZBridge_BadFrom();

LZBridge_RefunderNotValid

error LZBridge_RefunderNotValid();

LZBridge_EndpointZero

error LZBridge_EndpointZero();

Structs

SendMsgLocalVars

Local vars used to avoid stack-too-deep in sendMsg().

struct SendMsgLocalVars {
    address market;
    address underlying;
    address bridgeContract;
    MessagingFee fees;
    SendParam sendParam;
}