Skip to content
Lattice

DiamondIntrospectionInit

Git Source

Title: DiamondIntrospectionInit

Author: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80)

One-shot ERC-165 flag registration for a recipe's introspection/upgrade surface, appended to a recipe's init chain via MultiInit. Both variants register IERC165 (0x01ffc9a7) — every recipe cuts ERC165Facet, and ERC-165 requires supportsInterface(0x01ffc9a7) to be true. TWO truthful variants for the rest — a flag is registered iff the facet is actually cut:

  • initUpgradeable: the recipe cuts BOTH DiamondLoupeFacet AND a diamondCut-carrying facet — registers IDiamondLoupe (0x48e2b093) and IDiamondCut (0x1f931c1c).
  • initImmutable: the recipe cuts ONLY DiamondLoupeFacet (immutable-by-design diamonds) — registers IDiamondLoupe alone, so supportsInterface(0x1f931c1c) stays false and tooling can SEE the diamond is not upgradeable.

Delegatecalled by Diamond.initialize inside the initializing window (stock diamond-lib DiamondInit is NOT usable here: it unconditionally registers both flags AND initializes an Ownable owner). Stateless; safe to share one deployed instance across recipes.

Functions

initUpgradeable

Registers the IERC165 + IDiamondCut + IDiamondLoupe ERC-165 flags (cut facet + loupe both cut).

function initUpgradeable() external;

initImmutable

Registers the IERC165 + IDiamondLoupe ERC-165 flags only (loupe cut, deliberately no cut facet).

ERC165_MAP_ILOUPE_SLOT is diamond-lib's precomputed map slot for IDiamondLoupe: keccak256(abi.encode(bytes4(0x48e2b093), 0x9ca7f3e2e2bfb15fdf072b85dde92837cddacee6cf2f6b38cd06c9457c1c4200)) = 0x8b4e92bdfe8926212c580d8c12b81d3807ee1d50462b0f735541a0bd64c0003c (single sstore, per the repo's registerInterface standard; the read path recomputes the keccak, so the guard tests' supportsInterface(0x48e2b093) asserts verify the constant).

function initImmutable() external;