LZUnifiedBridge
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
| Name | Type | Description |
|---|---|---|
_roles | address | Roles contract used by BaseBridge. |
_endpoint | address | LayerZero endpoint allowed to call lzCompose(). |
setBridgeContract
Sets the OFT bridge contract for an underlying token.
function setBridgeContract(address underlying, address bridgeContract) external onlyBridgeConfigurator;
Parameters
| Name | Type | Description |
|---|---|---|
underlying | address | Underlying token. |
bridgeContract | address | OFT/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
| Name | Type | Description |
|---|---|---|
underlying | address | Underlying token. |
bridgeContract | address | Executor 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
| Name | Type | Description |
|---|---|---|
_extractedAmount | uint256 | Amount extracted by the rebalancer. |
_market | address | Market address expected inside _message. |
_dstChainId | uint32 | Destination chain id (eid). |
_token | address | Underlying token (must match market.underlying()). |
_message | bytes | ABI-encoded (market, amountLD, minAmountLD, extraOptions). |
_extraData | bytes | ABI-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
| Name | Type | Description |
|---|---|---|
from | address | Expected to be the bridge contract (OFT) for the decoded underlying. |
guid | bytes32 | Unused. |
message | bytes | ABI-encoded (market). |
executor | address | Unused. |
extraData | bytes | Unused. |
processUncomposedMessages
Processes any stored/uncomposed messages for a market (via executor).
function processUncomposedMessages(address _market) external payable onlyBridgeConfigurator;
Parameters
| Name | Type | Description |
|---|---|---|
_market | address | Market 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
| Name | Type | Description |
|---|---|---|
_dstChainId | uint32 | Destination chain id (eid). |
_message | bytes | ABI-encoded (market, amountLD, minAmountLD, extraOptions). |
_extraData | bytes | Unused. |
Returns
| Name | Type | Description |
|---|---|---|
nativeFee | uint256 | Native 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
| Name | Type | Description |
|---|---|---|
underlying | address | Underlying token. |
bridgeContract | address | OFT/bridge contract used for the send. |
params | SendParam | LayerZero SendParam. |
fees | MessagingFee | LayerZero MessagingFee. |
rebalancer | address | Caller (expected rebalancer). |
refundAddress | address | Refund address for any extra native fee. |
Returns
| Name | Type | Description |
|---|---|---|
r | MessagingReceipt | MessagingReceipt 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
| Name | Type | Description |
|---|---|---|
dstEid | uint32 | Destination chain id (eid). |
_message | bytes | ABI-encoded (market, amountLD, minAmountLD, extraOptions). |
Returns
| Name | Type | Description |
|---|---|---|
fees | MessagingFee | LayerZero messaging fees. |
lzSendParams | SendParam | LayerZero 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
| Name | Type | Description |
|---|---|---|
dstChainId | uint32 | Destination chain id (eid). |
market | address | Market address encoded in compose payload. |
amountLD | uint256 | Amount sent (local decimals). |
minAmountLD | uint256 | Minimum amount expected on destination (local decimals). |
guid | bytes32 | LayerZero message GUID. |
BridgeContractSet
Emitted when a bridge contract is configured for an underlying.
event BridgeContractSet(address indexed underlying, address indexed bridgeContract);
Parameters
| Name | Type | Description |
|---|---|---|
underlying | address | Underlying token address. |
bridgeContract | address | Bridge 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
| Name | Type | Description |
|---|---|---|
underlying | address | Underlying token address. |
executor | address | Executor 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;
}