ERC-20 Bridgeable Module
Internal functions for cross-chain ERC20 token operations
- Internal functions for cross-chain token operations.
- Leverages diamond storage for access control roles (
trusted-bridge). - Emits
CrosschainBurnandCrosschainMintevents for off-chain monitoring. - Does not use
usingdirectives or external dependencies.
This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.
Overview
This module provides internal functions for cross-chain ERC20 token transfers, specifically for burning and minting tokens across different chains. It relies on diamond storage for managing access control roles, ensuring that only trusted bridges can execute these sensitive operations. Changes to token balances are immediately visible to all facets interacting with the same diamond storage.
Storage
AccessControlStorage
storage struct for the AccessControl. storage-location: erc8042:compose.accesscontrol
ERC20Storage
ERC-8042 compliant storage struct for ERC20 token data. storage-location: erc8042:erc20
State Variables
| Property | Type | Description |
|---|---|---|
ERC20_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc20")) |
ACCESS_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.accesscontrol")) |
Functions
checkTokenBridge
Internal check to check if the bridge (caller) is trusted. Reverts if caller is zero or not in the AccessControl trusted-bridge role.
Parameters:
| Property | Type | Description |
|---|---|---|
_caller | address | The address to validate |
crosschainBurn
Cross-chain burn — callable only by an address having the trusted-bridge role.
Parameters:
| Property | Type | Description |
|---|---|---|
_from | address | The account to burn tokens from. |
_value | uint256 | The amount to burn. |
crosschainMint
Cross-chain mint — callable only by an address having the trusted-bridge role.
Parameters:
| Property | Type | Description |
|---|---|---|
_account | address | The account to mint tokens to. |
_value | uint256 | The amount to mint. |
getAccessControlStorage
helper to return AccessControlStorage at its diamond slot
getERC20Storage
Returns the ERC20 storage struct from the predefined diamond storage slot. Uses inline assembly to set the storage slot reference.
Returns:
| Property | Type | Description |
|---|---|---|
s | ERC20Storage | The ERC20 storage struct reference. |
Events
Errors
Best Practices
- Ensure the caller has the
trusted-bridgerole before invokingcrosschainBurnorcrosschainMint. - Verify that the diamond storage layout remains compatible when upgrading facets to prevent storage collisions.
- Handle potential reverts from
ERC20InsufficientBalance,ERC20InvalidBridgeAccount,ERC20InvalidCallerAddress,ERC20InvalidReceiver, orERC20InvalidSender.
Integration Notes
This module utilizes the diamond storage pattern, with its state stored at the ERC20_STORAGE_POSITION slot, identified by keccak256("erc20"). Functions like crosschainBurn and crosschainMint directly read from and write to the shared diamond storage. The AccessControlStorage struct, though empty in the provided definition, is conceptually used for role management. Any changes made to token balances via this module are immediately reflected for all other facets accessing the same storage.