Skip to main content

ERC20BridgeableFacet

Cross-chain ERC-20 token minting and burning

Key Features
  • Enables cross-chain token minting and burning.
  • Restricts minting and burning to addresses with the trusted-bridge role.
  • 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

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("compose.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

Events

Errors

Best Practices

Best Practice
  • Ensure the trusted-bridge role is assigned only to authorized bridge contracts or entities.
  • Call crosschainMint and crosschainBurn through the diamond proxy to ensure correct function routing.
  • Validate that the caller possesses the trusted-bridge role before invoking minting or burning operations.

Security Considerations

Security

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.

Was this helpful?
Last updated: