ERC20BridgeableMod
Manages cross-chain token transfers with role-based access control
- Internal functions for cross-chain minting and burning.
- Enforces
trusted-bridgerole for cross-chain operations. - Utilizes diamond storage for bridge access control configuration.
- Compatible with ERC-2535 diamonds.
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 token minting and burning, secured by role-based access control. Facets can import this module to integrate trusted bridge functionality, ensuring only authorized addresses can perform cross-chain operations. Changes to token bridges are managed via diamond storage, visible to all integrated facets.
Storage
AccessControlStorage
ERC20Storage
ERC-8042 compliant storage struct for ERC20 token data. storage-location: erc8042:compose.erc20
State Variables
| Property | Type | Description |
|---|---|---|
ERC20_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.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 calling facet possesses the
trusted-bridgerole before invoking crosschain functions. - Verify that
_calleris a valid, non-zero address when checking bridge trust. - Handle potential reverts from
checkTokenBridgebefore executing cross-chain operations.
Integration Notes
This module interacts with diamond storage using the ERC20_STORAGE_POSITION key, which is defined as keccak256("compose.erc20"). Functions like checkTokenBridge read from and functions like crosschainMint and crosschainBurn modify state related to trusted bridges. All state changes are immediately visible to other facets accessing the same diamond storage.