ERC-20 Burn Module
Internal ERC-20 token burning functionality
- Exposes only
internalfunctions, intended for use within custom facets. - Operates on shared diamond storage using EIP-8042 semantics.
- Emits
Transferevents upon successful burning, signaling changes in token ownership. - Reverts with custom errors
ERC20InsufficientBalanceandERC20InvalidSenderfor explicit error handling.
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 burning ERC-20 tokens, reducing the total supply and an account's balance. Facets can import this module to implement burning logic, operating on shared diamond storage. Changes to token supply and balances are immediately visible to all facets interacting with the same storage.
Storage
ERC20Storage
ERC-20 storage layout using the ERC-8042 standard. storage-location: erc8042:erc20
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc20")) |
Functions
burn
Burns tokens from a specified address. Decreases both total supply and the sender's balance. This module does not perform allowance checks. Ensure proper allowance or authorization validation before calling this function.
Parameters:
| Property | Type | Description |
|---|---|---|
_account | address | The address whose tokens will be burned. |
_value | uint256 | The number of tokens to burn. |
getStorage
Returns a pointer to the ERC-20 storage struct. Uses inline assembly to bind the storage struct to the fixed storage position.
Returns:
| Property | Type | Description |
|---|---|---|
s | ERC20Storage | The ERC-20 storage struct. |
Events
Errors
Best Practices
- Ensure
_accountauthorization and allowance checks are performed before callingburnfunctions to prevent unauthorized burning. - Handle
ERC20InsufficientBalanceandERC20InvalidSendererrors to gracefully manage invalid operations. - Verify that the storage pointer is correctly initialized and points to the shared diamond storage slot designated for ERC-20 data.
Integration Notes
This module interacts with diamond storage at the STORAGE_POSITION slot, identified by keccak256("erc20"). The getStorage function returns a pointer to the ERC20Storage struct, which contains the totalSupply variable. The burn function directly modifies the totalSupply and the balance of the specified _account within this shared storage. Any facet that reads from or writes to this same storage slot will immediately observe these changes.