Skip to main content

ERC20BridgeableMod

Manages cross-chain token transfers with role-based access control

Key Features
  • Internal functions for cross-chain minting and burning.
  • Enforces trusted-bridge role for cross-chain operations.
  • Utilizes diamond storage for bridge access control configuration.
  • Compatible with ERC-2535 diamonds.
Module Usage

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

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

ERC20Storage

ERC-8042 compliant storage struct for ERC20 token data. storage-location: erc8042:compose.erc20

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

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

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) view;

Parameters:

PropertyTypeDescription
_calleraddressThe address to validate

crosschainBurn

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

function crosschainBurn(address _from, uint256 _value) ;

Parameters:

PropertyTypeDescription
_fromaddressThe account to burn tokens from.
_valueuint256The amount to burn.

crosschainMint

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

function crosschainMint(address _account, uint256 _value) ;

Parameters:

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

getAccessControlStorage

helper to return AccessControlStorage at its diamond slot

function getAccessControlStorage() pure returns (AccessControlStorage storage s);

getERC20Storage

Returns the ERC20 storage struct from the predefined diamond storage slot. Uses inline assembly to set the storage slot reference.

function getERC20Storage() pure returns (ERC20Storage storage s);

Returns:

PropertyTypeDescription
sERC20StorageThe ERC20 storage struct reference.

Events

Errors

Best Practices

Best Practice
  • Ensure the calling facet possesses the trusted-bridge role before invoking crosschain functions.
  • Verify that _caller is a valid, non-zero address when checking bridge trust.
  • Handle potential reverts from checkTokenBridge before executing cross-chain operations.

Integration Notes

Shared Storage

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.

Was this helpful?
Last updated: