Diamond Module
Internal functions and storage for diamond proxy functionality.
- Exposes internal functions for diamond proxy operations.
- Manages diamond storage using a dedicated storage slot (
DIAMOND_STORAGE_POSITION). - Supports facet registration and retrieval through internal mechanisms.
- No external dependencies, ensuring minimal on-chain footprint.
This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.
Overview
This module provides core internal functions and storage management for diamond proxies. It enables facets to interact with shared diamond storage and manage facet registrations. Changes made through this module are immediately visible to all facets utilizing the diamond storage pattern.
Storage
DiamondStorage
storage-location: erc8042:erc8153.diamond
FacetList
FacetNode
State Variables
| Property | Type | Description |
|---|---|---|
DIAMOND_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc8153.diamond")) |
Functions
addFacets
Parameters:
| Property | Type | Description |
|---|---|---|
_facets | address[] | - |
at
Parameters:
| Property | Type | Description |
|---|---|---|
selectors | bytes | - |
index | uint256 | - |
diamondFallback
Find facet for function that is called and execute the function if a facet is found and return any value.
getDiamondStorage
importSelectors
Parameters:
| Property | Type | Description |
|---|---|---|
_facet | address | - |
Events
Errors
Best Practices
- Ensure that facet registration functions (like
addFacetsandimportSelectors) are called only during diamond initialization or controlled upgrade processes. - Verify that the
DiamondStoragestruct is correctly defined and that any new fields are added at the end to maintain storage compatibility. - Handle custom errors such as
CannotAddFunctionToDiamondThatAlreadyExistsandNoSelectorsForFacetto ensure robust error management.
Integration Notes
This module interacts directly with the diamond's shared storage at the DIAMOND_STORAGE_POSITION, which is identified by keccak256("erc8153.diamond"). The DiamondStorage struct, which includes a FacetList field, resides here. All functions within this module read from and write to this shared storage. Changes to the facetList or other storage elements are immediately visible to any facet that accesses the same storage slot.