ERC-20 Mint Module
Internal functions for minting ERC-20 tokens
- Provides
internalfunctions for facet composition. - Utilizes the diamond storage pattern (EIP-8042) for shared state.
- No external dependencies or
usingdirectives. - Minimal gas overhead due to direct storage manipulation.
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 minting ERC-20 tokens. Facets can import this module to manage token creation using shared diamond storage. Changes to total supply and recipient balances are immediately reflected across all facets accessing the same storage.
Storage
ERC20Storage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc20")) |
Functions
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. |
mint
Mints new tokens to a specified address. Increases both total supply and the recipient's balance.
Parameters:
| Property | Type | Description |
|---|---|---|
_account | address | The address receiving the newly minted tokens. |
_value | uint256 | The number of tokens to mint. |
Events
Errors
Best Practices
- Ensure that access control for minting is enforced by the calling facet.
- Verify storage layout compatibility when upgrading or adding facets to avoid storage collisions.
- Handle the
ERC20InvalidReceivererror if the minting logic were to incorporate checks for valid recipients.
Integration Notes
This module interacts with diamond storage at a fixed position identified by keccak256(\"erc20\"). It reads and writes to the ERC20Storage struct, specifically modifying totalSupply. All state changes made by mint are immediately visible to any other facet that reads from the same storage position within the diamond.