BridgeFungibleLib
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)
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
| Name | Type | Description |
|---|---|---|
| to | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| chain | bytes | |
| addr | bytes |
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
| Name | Type | Description |
|---|---|---|
| from | address | |
| toAddr | bytes | |
| amount | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| payload | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| from | bytes | |
| to | address | |
| amount | uint256 |
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
| Name | Type | Description |
|---|---|---|
| token | address | |
| to | address | |
| amount | uint256 |
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
| Name | Type | Description |
|---|---|---|
| token | address | |
| from | address | |
| amount | uint256 |
_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
| Name | Type | Description |
|---|---|---|
| token | address | |
| data | bytes |