ERC20BridgeableFacet
Cross-chain ERC-20 token minting and burning
- Enables cross-chain token minting and burning.
- Restricts minting and burning to addresses with the
trusted-bridgerole. - Integrates with the diamond storage pattern for token state management.
- Follows Compose's convention of explicit function calls.
Overview
This facet enables cross-chain ERC-20 token minting and burning operations within a diamond. It exposes functions that are callable only by addresses with the trusted-bridge role, ensuring secure and controlled token movements across different chains. Integrate this facet to manage bridged token supply.
Storage
ERC20Storage
AccessControlStorage
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
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 |
Events
Errors
Best Practices
- Ensure the
trusted-bridgerole is assigned only to authorized bridge contracts or entities. - Call
crosschainMintandcrosschainBurnthrough the diamond proxy to ensure correct function routing. - Validate that the caller possesses the
trusted-bridgerole before invoking minting or burning operations.
Security Considerations
The crosschainMint and crosschainBurn functions are protected by access control, requiring the caller to have the trusted-bridge role. The checkTokenBridge internal function enforces this role check. Input validation for _account, _from, and _value is crucial to prevent unexpected behavior. Follow standard Solidity security practices for handling token transfers and state updates.