DiamondMod
Manages facet additions and function dispatch for diamonds
- Internal functions for facet management and call dispatch.
- Uses diamond storage pattern for centralized state.
- No external dependencies, promoting composability.
- Compatible with ERC-2535 diamond standard.
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 managing facets and dispatching calls within a diamond proxy. It enables composability by allowing facets to be added and functions to be routed to the correct implementation. Changes to facet mappings are managed internally, ensuring consistent function resolution across all interacting facets.
Storage
DiamondStorage
storage-location: erc8042:erc8109.diamond
FacetAndPosition
FacetFunctions
State Variables
| Property | Type | Description |
|---|---|---|
DIAMOND_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc8109.diamond")) |
Functions
addFacets
Adds facets and their function selectors to the diamond. Only supports adding functions during diamond deployment.
Parameters:
| Property | Type | Description |
|---|---|---|
_facets | FacetFunctions[] | - |
diamondFallback
Find facet for function that is called and execute the function if a facet is found and return any value.
getStorage
Events
Errors
Best Practices
- Call
addFacetsonly during initial diamond deployment to avoid conflicts. - Ensure that function selectors are unique across all facets before adding.
- Handle
FunctionNotFounderrors when dispatching calls that do not map to any facet.
Integration Notes
This module utilizes a dedicated storage position, DIAMOND_STORAGE_POSITION, identified by keccak256("erc8109.diamond"). The DiamondStorage struct, although empty in its definition, serves as a conceptual representation of the state managed at this position. Facets interact with this module's functions to register new facets and their associated function selectors, influencing the diamond's runtime behavior. Any updates to the facet mappings are immediately visible to all facets interacting with the diamond proxy.