Skip to content
Lattice

ERC20CrosschainLib

Git Source

Title: ERC20CrosschainLib

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

(https://github.com/OpenZeppelin/openzeppelin-contracts/blob/5fd1781b1454fd1ef8e722282f86f9293cacf256/contracts/token/ERC20/extensions/ERC20Crosschain.sol).

Self-bridging ERC-20: the token embeds the BridgeFungible logic, burning its OWN supply on send and minting it on receive — no separate bridge contract or custodied/external token.

Acts as an IERC7786MessageHandler co-mounted with CrosschainLink + ERC20; registers under the shared FUNGIBLE_BRIDGE_TAG and reuses IBridgeFungible for ERC-165. No own storage (reuses the ERC20 balances). No role is needed: crosschainTransfer burns the CALLER's own tokens, and the inbound mint is gated by CrosschainLink's gateway/counterpart auth + the address(this) handler guard. The burn and mint call ERC20Lib directly: an ERC-20 movement-replacing extension (ERC20Pausable, ERC20Votes) does not see them, so the two are mutually exclusive (D25, #234).

Functions

__ERC20Crosschain_init

Registers the IBridgeFungible ERC-165 interface. Must be called in a pre/postInitializer block.

function __ERC20Crosschain_init() internal;

crosschainTransfer

Burns amount of the caller's own supply and sends a bridge message to the destination.

function crosschainTransfer(bytes calldata to, uint256 amount) internal returns (bytes32 sendId);

Parameters

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

Returns

NameTypeDescription
sendIdbytes32

processMessage

Mints amount of own supply to the inbound recipient. Callable only via the Diamond's own authenticated receiveMessage dispatch (msg.sender == address(this)).

function processMessage(bytes32 receiveId, bytes calldata payload) internal;

Parameters

NameTypeDescription
receiveIdbytes32The de-duplicated message id (replay already checked by CrosschainLink).
payloadbytesThe tag-stripped inbound payload abi.encode(from, toAddrBytes, amount).