Skip to main content

Diamond Inspect Facet

Inspect diamond facets and selectors

Key Features
  • Provides functions for querying facet addresses by selector.
  • Enables retrieval of all registered facet addresses and their selectors.
  • Includes exportSelectors for mechanism discovery.
  • Operates on shared diamond storage via DIAMOND_STORAGE_POSITION.

Overview

This facet provides essential introspection capabilities for diamonds. It exposes functions to query facet addresses, their associated function selectors, and a comprehensive list of all registered facets. Developers integrate this facet to understand the diamond's internal structure and composition programmatically.

Storage

FacetNode

Definition
struct FacetNode {
address facet;
bytes4 prevFacetNodeId;
bytes4 nextFacetNodeId;
}

FacetList

Definition
struct FacetList {
bytes4 headFacetNodeId;
bytes4 tailFacetNodeId;
uint32 facetCount;
uint32 selectorCount;
}

DiamondStorage

Definition
struct DiamondStorage {
mapping(bytes4 functionSelector => FacetNode) facetNodes;
FacetList facetList;
}

Facet

Definition
struct Facet {
address facet;
bytes4[] functionSelectors;
}

State Variables

PropertyTypeDescription
DIAMOND_STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc8153.diamond"))

Functions

facetAddress

Gets the facet address that handles the given selector. If facet is not found return address(0).

function facetAddress(bytes4 _functionSelector) external view returns (address facet);

Parameters:

PropertyTypeDescription
_functionSelectorbytes4The function selector.

Returns:

PropertyTypeDescription
facetaddressThe facet address.

facetFunctionSelectors

Gets the function selectors that are handled by the given facet. If facet is not found return empty array.

function facetFunctionSelectors(address _facet) external view returns (bytes4[] memory facetSelectors);

Parameters:

PropertyTypeDescription
_facetaddressThe facet address.

Returns:

PropertyTypeDescription
facetSelectorsbytes4[]The function selectors.

facetAddresses

Gets the facet addresses used by the diamond. If no facets are registered return empty array.

function facetAddresses() external view returns (address[] memory allFacets);

Returns:

PropertyTypeDescription
allFacetsaddress[]The facet addresses.

facets

Returns the facet address and function selectors of all facets in the diamond.

function facets() external view returns (Facet[] memory facetsAndSelectors);

Returns:

PropertyTypeDescription
facetsAndSelectorsFacet[]An array of Facet structs containing each facet address and its function selectors.

exportSelectors

Exports the function selectors of the DiamondInspectFacet This function is use as a selector discovery mechanism for diamonds

function exportSelectors() external pure returns (bytes memory);

Returns:

PropertyTypeDescription
-bytesselectors The exported function selectors of the DiamondInspectFacet

Best Practices

Best Practice
  • Integrate this facet to enable external inspection of diamond facet mappings.
  • Use facetAddress to determine which facet handles a specific function selector.
  • Utilize facets and facetFunctionSelectors for comprehensive diamond structure analysis.

Security Considerations

Security

All functions in this facet are view or pure, posing no direct reentrancy or state-changing risks. Input validation for facetAddress and facetFunctionSelectors is handled by the diamond proxy's dispatch mechanism. Follow standard Solidity security practices.

Was this helpful?
Last updated:

Newsletter

Get notified about releases, feature announcements, and technical deep-dives on building smart contracts with Compose.

No spam. Unsubscribe anytime.