ERC-20 Bridgeable Facet
Cross-chain ERC-20 token minting and burning
- Enables cross-chain minting and burning of ERC-20 tokens.
- Enforces
trusted-bridgerole for authorized operations via access control. - Functions are callable via the diamond proxy, adhering to ERC-2535.
- Exports its own selectors for discovery by the diamond.
Overview
This facet exposes cross-chain mint and burn functionalities for ERC-20 tokens within a diamond. It enforces access control via the trusted-bridge role, ensuring only authorized entities can perform these operations. Calls are routed through the diamond proxy, leveraging shared diamond storage for state management.
Storage
ERC20Storage
AccessControlStorage
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
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. |
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. |
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 |
exportSelectors
Exports the function selectors of the ERC20BridgeableFacet This function is use as a selector discovery mechanism for diamonds
Returns:
| Property | Type | Description |
|---|---|---|
- | bytes | selectors The exported function selectors of the ERC20BridgeableFacet |
Events
Errors
Best Practices
- Ensure the
trusted-bridgerole is correctly assigned before callingcrosschainMintorcrosschainBurn. - Verify caller identity and permissions through the diamond proxy before executing cross-chain operations.
- Use
checkTokenBridgeto confirm trusted bridge addresses when necessary.
Security Considerations
State-changing functions crosschainMint and crosschainBurn are protected by the trusted-bridge role, enforced by internal checks. The checkTokenBridge function reverts if the caller is not a trusted bridge address or is the zero address. Input validation for _account, _from, and _value is crucial and should be handled by the caller or prior facets. Follow standard Solidity security practices for external calls and state updates.