Skip to main content

Diamond Inspect Facet

@perfect-abstractions/compose/diamond/DiamondInspectFacet.sol

It lets you inspect the diamond’s routing table and retrieve the registered facet list.

Key Features
  • Query which facet a function selector is routed to.
  • Enumerate registered facets (and their exported selectors).
  • Read the diamond’s composition from shared diamond storage (DIAMOND_STORAGE_POSITION).

Storage

State Variables

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

Diamond Storage

Definition
/** storage-location: erc8042:erc8153.diamond */
struct DiamondStorage {
mapping(bytes4 functionSelector => FacetNode) facetNodes;
FacetList facetList;
}

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

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

Facet

Used as a return type for the facets function.

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

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 to lookup

Returns:

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

facetFunctionSelectors

Gets the function selectors exported by the given facet and returns them as bytes4[].

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

Parameters:

PropertyTypeDescription_facetaddressFacet contract address. Must implement exportSelectors()</b> (packed bytes4 selectors).

Returns:

PropertyTypeDescriptionfacetSelectorsbytes4[]Unpacked selectors returned by facet.exportSelectors(), or an empty array if the facet is not registered.

facetAddresses

Gets the facet addresses used by the diamond.

If no facets are registered, this returns an empty array.

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

Returns:

PropertyTypeDescriptionallFacetsaddress[]Facet addresses in the diamond's internal traversal order.

facets

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

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

Returns:

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

Selector Packing Notes (exportSelectors())

exportSelectors() returns a packed bytes blob where each bytes4 selector is encoded into 4 consecutive bytes (a bytes.concat(sel1, sel2, ...) style packing).

DiamondInspectFacet follows that convention:

Best Practices

Security Considerations

Most functions are view/pure and do not mutate state.

However, facetFunctionSelectors() and facets() perform external calls to IFacet(facet).exportSelectors().

If the provided address is not a valid IFacet implementation (or if exportSelectors() reverts / returns unexpected data), these calls can revert.

That being said, always make sure to provide verified and trusted facet addresses.
Last updated:

Newsletter

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

No spam. Unsubscribe anytime.