Skip to main content

DiamondInspectFacet

Inspects diamond facets and storage mappings

Key Features
  • Provides external view functions for diamond inspection.
  • Accesses diamond storage via inline assembly for direct state retrieval.
  • Returns facet addresses and function-to-facet mappings.
  • Follows EIP-2535 diamond standard conventions.

Overview

This facet provides read-only access to the diamond's facet mappings and storage structure. It exposes functions to retrieve facet addresses by function selector and to list all function-to-facet pairings. Developers integrate this facet to inspect diamond functionality and understand its on-chain configuration.


Storage

FacetAndPosition

Definition
struct FacetAndPosition {
address facet;
uint32 position;
}

DiamondStorage

Definition
struct DiamondStorage {
mapping(bytes4 functionSelector => FacetAndPosition) facetAndPosition;
/**
* Array of all function selectors that can be called in the diamond.
*/
bytes4[] selectors;
}

FunctionFacetPair

Definition
struct FunctionFacetPair {
bytes4 selector;
address facet;
}

State Variables

PropertyTypeDescription
DIAMOND_STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc8109.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.

functionFacetPairs

Returns an array of all function selectors and their corresponding facet addresses. Iterates through the diamond's stored selectors and pairs each with its facet.

function functionFacetPairs() external view returns (FunctionFacetPair[] memory pairs);

Returns:

PropertyTypeDescription
pairsFunctionFacetPair[]An array of FunctionFacetPair structs, each containing a selector and its facet address.

Best Practices

Best Practice
  • Ensure this facet is added to the diamond during initialization.
  • Call facetAddress to determine which facet handles a specific function selector.
  • Use functionFacetPairs to get a comprehensive view of the diamond's function dispatch.

Security Considerations

Security

This facet contains only view functions and does not modify state. Standard Solidity security practices apply. Input validation is handled by the underlying diamond proxy and facet dispatch mechanism.

Was this helpful?
Last updated: