Skip to content
Lattice

BridgeERC20

Git Source

Inherits: IBridgeFungible, IERC7786MessageHandler

Title: BridgeERC20

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

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

Custody bridge facet for legacy ERC-20 tokens: locks tokens on crosschainTransfer, releases them on an inbound message. Registered as a handler on a co-mounted CrosschainLink facet.

Stateless delegator — logic/storage live in BridgeERC20Lib. processMessage is callable only via the Diamond's own authenticated receiveMessage dispatch (it enforces msg.sender == address(this)). CUSTODY: locked tokens sit in the diamond's balance with no per-module ledger. A co-cut module that counts the diamond's whole balance of the same token (ERC-4626 totalAssets, VestingWallet release) treats the escrow as its own. One custodian per asset per diamond (issue #240).

Notes:

  • lattice-version: 0.1.0
  • lattice-source: OpenZeppelin

Functions

crosschainTransfer

Bridge amount of the configured token to a crosschain recipient.

function crosschainTransfer(bytes calldata to, uint256 amount) external virtual override returns (bytes32 sendId);

Parameters

NameTypeDescription
tobytesThe full ERC-7930 interoperable address of the recipient (chain ref + address).
amountuint256The amount to lock/burn here and release/mint on the destination chain.

Returns

NameTypeDescription
sendIdbytes32The ERC-7786 gateway-assigned send id.

processMessage

Process a validated, de-duplicated cross-chain message.

function processMessage(
        bytes32 receiveId,
        bytes calldata,
        /*sender*/
        bytes calldata payload
    )
        external
        virtual
        override;

Parameters

NameTypeDescription
receiveIdbytes32The gateway-assigned unique message id (already checked for replay by the facet).
_bytesThe ERC-7930 interoperable address of the source (includes the source chain).
payloadbytesThe message payload with the leading 4-byte handler tag stripped.

token

The bridged ERC-20 token.

function token() external view virtual returns (address);

Returns

NameTypeDescription
<none>address

exportSelectors

ERC-8153 selector export: this facet's cuttable selectors, tightly packed (4 bytes each).

Excludes exportSelectors() itself (0x0ef22643) - it is never cut into a diamond. Order matches forge inspect BridgeERC20 methodIdentifiers (alphabetical by signature); kept in exact parity by ExportSelectorsParityTest. Chunks: crosschainTransfer(bytes,uint256) 0x28dcc8d8 processMessage(bytes32,bytes,bytes) 0x902d5027 token() 0xfc0c546a

function exportSelectors() external pure virtual returns (bytes memory selectors);

Returns

NameTypeDescription
selectorsbytes