Skip to main content

ERC-20 Burn Facet

Burns ERC-20 tokens from caller or allowance

Key Features
  • Enables burning of tokens from caller's balance via burn.
  • Supports burning tokens from another account using allowance via burnFrom.
  • Emits Transfer events to the zero address upon successful burns.
  • Exports its selectors via exportSelectors for diamond discovery.

Overview

This facet implements ERC-20 token burning functionality within a diamond. It exposes external functions for callers to burn their own tokens or burn tokens from another account using their allowance. Calls are routed through the diamond proxy, and storage is accessed via the diamond's shared storage pattern.

Storage

ERC20Storage

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

State Variables

PropertyTypeDescription
STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc20"))

Functions

burn

Burns (destroys) a specific amount of tokens from the caller's balance. Emits a Transfer event to the zero address.

function burn(uint256 _value) external;

Parameters:

PropertyTypeDescription
_valueuint256The amount of tokens to burn.

burnFrom

Burns tokens from another account, deducting from the caller's allowance. Emits a Transfer event to the zero address.

function burnFrom(address _account, uint256 _value) external;

Parameters:

PropertyTypeDescription
_accountaddressThe address whose tokens will be burned.
_valueuint256The amount of tokens to burn.

exportSelectors

Exports the function selectors of the ERC20BurnFacet 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 ERC20BurnFacet

Events

Errors

Best Practices

Best Practice
  • Ensure the ERC20BurnFacet is correctly added to the diamond with its selectors.
  • Verify sufficient token balances and allowances before calling burn or burnFrom respectively.
  • Implement proper access control mechanisms in the diamond to restrict who can call burnFrom if necessary.

Security Considerations

Security

The burn function requires the caller to have sufficient token balance. The burnFrom function requires the caller to have sufficient allowance for the specified account. Both functions emit Transfer events to the zero address, signaling token destruction. Developers should ensure that the underlying ERC-20 token logic correctly handles balance and allowance checks. Reentrancy is not a direct concern as these functions do not perform external calls that could re-enter the facet, but standard checks-effects-interactions patterns should be followed by the diamond's storage access.

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.