ERC20CrosschainLib
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)
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
| Name | Type | Description |
|---|---|---|
| to | bytes | The full ERC-7930 interoperable address of the recipient (chain ref + address). |
| amount | uint256 | The amount to burn here and mint on the destination. |
Returns
| Name | Type | Description |
|---|---|---|
| sendId | bytes32 |
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
| Name | Type | Description |
|---|---|---|
| receiveId | bytes32 | The de-duplicated message id (replay already checked by CrosschainLink). |
| payload | bytes | The tag-stripped inbound payload abi.encode(from, toAddrBytes, amount). |