Skip to content
Lattice

BridgeFungibleLib

Git Source

Title: BridgeFungibleLib

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Adapted for EIP-2535 from OpenZeppelin BridgeFungible v5.6.1 (https://github.com/OpenZeppelin/openzeppelin-contracts)

(https://github.com/OpenZeppelin/openzeppelin-contracts/blob/5fd1781b1454fd1ef8e722282f86f9293cacf256/contracts/crosschain/bridges/abstract/BridgeFungible.sol).

Stateless shared helpers for the fungible bridge facets: the shared ERC-165 registration, the common payload codec (interop-compatible with OZ's encoding), and USDT-safe ERC-20 transfers.

No storage of its own. The on-the-wire payload is abi.encode(fromInteropAddr, toAddrBytes, amount), prefixed by FUNGIBLE_BRIDGE_TAG so the CrosschainLink dispatcher routes it to the bridge.

Functions

registerInterface

Writes true to the ERC-165 map slot for IBridgeFungible (shared by both bridges).

function registerInterface() internal;

splitDestination

Splits a full interoperable to into its chain-only routing key and raw address bytes.

Validates the address part is exactly 20 bytes HERE (on send, before any funds move), so a malformed recipient reverts instead of locking/burning funds that the inbound 20-byte decode could never credit (send/receive symmetry).

function splitDestination(bytes memory to) internal pure returns (bytes memory chain, bytes memory addr);

Parameters

NameTypeDescription
tobytes

Returns

NameTypeDescription
chainbytes
addrbytes

buildPayload

Builds the tagged outbound payload (source-chain from interop addr, dest addr bytes, amount).

function buildPayload(address from, bytes memory toAddr, uint256 amount) internal view returns (bytes memory);

Parameters

NameTypeDescription
fromaddress
toAddrbytes
amountuint256

Returns

NameTypeDescription
<none>bytes

decodeInbound

Decodes a tag-stripped inbound payload. Reverts if the destination is not a 20-byte address.

function decodeInbound(bytes calldata payload)
        internal
        pure
        returns (bytes memory from, address to, uint256 amount);

Parameters

NameTypeDescription
payloadbytes

Returns

NameTypeDescription
frombytes
toaddress
amountuint256

safeTransfer

ERC-20 transfer that tolerates no-return-data tokens (USDT) and reverts on failure or when token has no code.

function safeTransfer(address token, address to, uint256 amount) internal;

Parameters

NameTypeDescription
tokenaddress
toaddress
amountuint256

pullExact

Pulls EXACTLY amount of token from from into this contract; reverts if the measured balance delta differs (rejects fee-on-transfer tokens, which would break the 1:1 invariant).

function pullExact(address token, address from, uint256 amount) internal;

Parameters

NameTypeDescription
tokenaddress
fromaddress
amountuint256

_call

Low-level ERC-20 call: reverts on a failed call, an explicit false return, or empty return data from an address with no code (matches OpenZeppelin SafeERC20).

function _call(address token, bytes memory data) private;

Parameters

NameTypeDescription
tokenaddress
databytes