ERC-20 Burn Facet
Burns ERC-20 tokens from caller or allowance
- Enables burning of tokens from caller's balance via
burn. - Supports burning tokens from another account using allowance via
burnFrom. - Emits
Transferevents to the zero address upon successful burns. - Exports its selectors via
exportSelectorsfor 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
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond 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.
Parameters:
| Property | Type | Description |
|---|---|---|
_value | uint256 | The 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.
Parameters:
| Property | Type | Description |
|---|---|---|
_account | address | The address whose tokens will be burned. |
_value | uint256 | The amount of tokens to burn. |
exportSelectors
Exports the function selectors of the ERC20BurnFacet This function is use as a selector discovery mechanism for diamonds
Returns:
| Property | Type | Description |
|---|---|---|
- | bytes | selectors The exported function selectors of the ERC20BurnFacet |
Events
Errors
Best Practices
- Ensure the
ERC20BurnFacetis correctly added to the diamond with its selectors. - Verify sufficient token balances and allowances before calling
burnorburnFromrespectively. - Implement proper access control mechanisms in the diamond to restrict who can call
burnFromif necessary.
Security Considerations
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.