DiamondUpgradeFacet
Manage diamond upgrades and facet additions
- Manages diamond functional surface area through facet composition.
- Supports adding, replacing, and removing functions via selector mapping.
- Enables diamond upgradeability by allowing facet deployments and reconfigurations.
- Facilitates metadata updates associated with diamond state changes.
Overview
This facet provides core functionality for upgrading diamond proxies by adding, replacing, and removing facets. It allows for delegate calls and metadata updates, integrating directly with the diamond storage pattern. Developers use this facet to manage the diamond's functional surface area and upgrade its components.
Storage
OwnerStorage
FacetAndPosition
DiamondStorage
FacetFunctions
State Variables
| Property | Type | Description |
|---|---|---|
OWNER_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.owner")) |
DIAMOND_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc8109.diamond")) |
Functions
upgradeDiamond
Function Changes:
DelegateCall:
Metadata:
If _tag is non-zero or if _metadata.length > 0 then the DiamondMetadata event is emitted.
Parameters:
| Property | Type | Description |
|---|---|---|
_addFunctions | FacetFunctions[] | Selectors to add, grouped by facet. |
_replaceFunctions | FacetFunctions[] | Selectors to replace, grouped by facet. |
_removeFunctions | bytes4[] | Selectors to remove. |
_delegate | address | Optional contract to delegatecall (zero address to skip). |
_functionCall | bytes | Optional calldata to execute on _delegate. |
_tag | bytes32 | Optional arbitrary metadata, such as release version. |
_metadata | bytes | Optional arbitrary data. |
Events
Errors
Best Practices
- Initialize diamond storage ownership using the
ownerfield if applicable. - Ensure that selectors for adding or replacing functions do not conflict with immutable functions.
- Verify that facet bytecode exists at the provided address before attempting to add or replace functions.
Security Considerations
All state-modifying functions (addFunctions, replaceFunctions, removeFunctions, Metadata) must be protected by appropriate access control, typically owner-only, to prevent unauthorized modifications. The Metadata function emits an event, ensuring transparency for metadata changes. Input validation is crucial to prevent errors like NoSelectorsProvidedForFacet, NoBytecodeAtAddress, or conflicts with immutable functions.