Skip to content
Lattice

BridgeERC20Lib

Git Source

Title: BridgeERC20Lib

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).

Custody bridge for legacy ERC-20s: locks tokens on send, releases them on receive. Acts as an IERC7786MessageHandler co-mounted with a CrosschainLink facet.

Functions

bridgeERC20Storage

function bridgeERC20Storage() internal pure returns (BridgeERC20Storage storage $);

Returns

NameTypeDescription
$BridgeERC20Storage

__BridgeERC20_init

Configures the bridged token and registers the IBridgeFungible ERC-165 interface.

function __BridgeERC20_init(address token_) internal;

Parameters

NameTypeDescription
token_address

token

The bridged ERC-20 token.

function token() internal view returns (address);

Returns

NameTypeDescription
<none>address

crosschainTransfer

Locks amount of the token in custody and sends a bridge message to the destination chain.

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 lock here and release on the destination.

Returns

NameTypeDescription
sendIdbytes32

processMessage

Releases custodied tokens 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).