Skip to main content

ERC-20 Bridgeable Facet

Cross-chain ERC-20 token minting and burning

Key Features
  • Enables cross-chain minting and burning of ERC-20 tokens.
  • Enforces trusted-bridge role 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

Definition
struct ERC20Storage {
mapping(address owner => uint256 balance) balanceOf;
uint256 totalSupply;
}

AccessControlStorage

Definition
struct AccessControlStorage {
mapping(address account => mapping(bytes32 role => bool hasRole)) hasRole;
}

State Variables

PropertyTypeDescription
ERC20_STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc20"))
ACCESS_STORAGE_POSITIONbytes32Diamond 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.

function crosschainMint(address _account, uint256 _value) external;

Parameters:

PropertyTypeDescription
_accountaddressThe account to mint tokens to.
_valueuint256The amount to mint.

crosschainBurn

Cross-chain burn — callable only by an address having the trusted-bridge role.

function crosschainBurn(address _from, uint256 _value) external;

Parameters:

PropertyTypeDescription
_fromaddressThe account to burn tokens from.
_valueuint256The 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.

function checkTokenBridge(address _caller) external view;

Parameters:

PropertyTypeDescription
_calleraddressThe address to validate

exportSelectors

Exports the function selectors of the ERC20BridgeableFacet This function is use as a selector discovery mechanism for diamonds

function exportSelectors() external pure returns (bytes memory);

Returns:

PropertyTypeDescription
-bytesselectors The exported function selectors of the ERC20BridgeableFacet

Events

Errors

Best Practices

Best Practice
  • Ensure the trusted-bridge role is correctly assigned before calling crosschainMint or crosschainBurn.
  • Verify caller identity and permissions through the diamond proxy before executing cross-chain operations.
  • Use checkTokenBridge to confirm trusted bridge addresses when necessary.

Security Considerations

Security

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.

Was this helpful?
Last updated:

Newsletter

Get notified about releases, feature announcements, and technical deep-dives on building smart contracts with Compose.

No spam. Unsubscribe anytime.