EverclearBridge

Git Source

Inherits: BaseBridge, IBridge

Title: Everclear bridge implementation

Author: Malda Protocol

Cross-chain bridge using Everclear protocol for intent-based transfers

State Variables

everclearFeeAdapter

Everclear fee adapter contract

IFeeAdapter public everclearFeeAdapter

Functions

constructor

Initializes the Everclear bridge

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

Parameters

NameTypeDescription
_rolesaddressRoles contract address
_feeAdapteraddressEverclear fee adapter address

sendMsg

rebalance through bridge

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

Parameters

NameTypeDescription
_extractedAmountuint256extracted amount for rebalancing
_marketaddressdestination address
_dstChainIduint32destination chain id
_tokenaddressthe token to rebalance
_messagebytesoperation message data
<none>bytes

getFee

computes fee for bridge operation

function getFee(uint32, bytes calldata, bytes calldata) external pure returns (uint256);

Parameters

NameTypeDescription
<none>uint32
<none>bytes
<none>bytes

Returns

NameTypeDescription
<none>uint256fee Computed bridge fee

_decodeIntent

Decodes an intent message returned by the Everclear intents API into structured parameters.

  • The input message is the raw ABI-encoded calldata of a FeeAdapter.newIntent call.
  • The first 4 bytes are the function selector, which are skipped.
  • The remaining bytes encode the primary intent parameters followed by FeeParams.
  • Because FeeParams is a dynamic struct appended at the end, its data must be located by reading its offset and decoding separately. Layout of FeeAdapter.newIntent calldata after the selector:
destinations (uint32[])   at offset 0x00
receiver (bytes32)        at offset 0x20
inputAsset (address)      at offset 0x40
outputAsset (bytes32)     at offset 0x60
amount (uint256)          at offset 0x80
maxFee (uint24)           at offset 0xa0
ttl (uint48)              at offset 0xc0
data (bytes)              at offset 0xe0
feeParams (FeeParams)     at offset 0x100 (9th arg → pointer)

Since each static argument occupies a 32-byte slot, the pointer to feeParams lives at offset 0x100 (256 bytes) after the selector is removed.

function _decodeIntent(bytes memory message) internal pure returns (IntentParams memory);

Parameters

NameTypeDescription
messagebytesABI-encoded calldata for FeeAdapter.newIntent.

Returns

NameTypeDescription
<none>IntentParamsDecoded IntentParams struct with both core parameters and nested FeeParams.

_extractFeeParams

Extracts the nested FeeParams struct from ABI-encoded intentData.

  • FeeParams is the 9th parameter of FeeAdapter.newIntent and therefore stored as a pointer at offset 0x100.
  • The selector has already been removed, so the pointer is read at byte position 0x100 (256 bytes).
  • The pointer gives the offset to the start of the FeeParams struct relative to the start of intentData.
  • Within FeeParams, the layout is:
fee      (uint256) at +0x00
deadline (uint256) at +0x20
sig      (bytes)   at +0x40 (stored as offset → length → data)
  • The sig field is dynamic, so we read its offset (at +0x40) relative to the FeeParams base, then read the length at that offset, then slice out the actual signature bytes.
function _extractFeeParams(bytes memory intentData)
    private
    pure
    returns (uint256 fee, uint256 deadline, bytes memory sig);

Parameters

NameTypeDescription
intentDatabytesABI-encoded calldata without selector, containing intent arguments.

Returns

NameTypeDescription
feeuint256The fee value.
deadlineuint256The signature deadline.
sigbytesThe validator/relayer signature.

Events

MsgSent

Emitted when a message is sent via Everclear

event MsgSent(uint256 indexed dstChainId, address indexed market, uint256 amountLD, bytes32 id);

Parameters

NameTypeDescription
dstChainIduint256Destination chain ID
marketaddressMarket address
amountLDuint256Amount in local decimals
idbytes32Intent identifier

RebalancingReturnedToMarket

Emitted when excess rebalancing funds are returned to the market

event RebalancingReturnedToMarket(address indexed market, uint256 toReturn, uint256 extracted);

Parameters

NameTypeDescription
marketaddressMarket address
toReturnuint256Amount returned
extracteduint256Amount originally extracted

Errors

Everclear_TokenMismatch

Error thrown when provided token does not match expected asset

error Everclear_TokenMismatch();

Everclear_NotImplemented

Error thrown when a feature is not implemented

error Everclear_NotImplemented();

Everclear_MaxFeeExceeded

Error thrown when maximum fee is exceeded

error Everclear_MaxFeeExceeded();

Everclear_AddressNotValid

Error thrown when provided address is invalid

error Everclear_AddressNotValid();

Everclear_DestinationNotValid

Error thrown when provided destination is invalid

error Everclear_DestinationNotValid();

Everclear_DestinationsLengthMismatch

Error thrown when destination arrays have mismatched length

error Everclear_DestinationsLengthMismatch();

Structs

IntentParams

struct IntentParams {
    uint32[] destinations;
    bytes32 receiver;
    address inputAsset;
    bytes32 outputAsset;
    uint256 amount;
    uint24 maxFee;
    uint48 ttl;
    bytes data;
    IFeeAdapter.FeeParams feeParams;
}