Skip to content
Lattice

AccessControlDiamondCutLib

Git Source

Title: AccessControlDiamondCut Library

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

Library that gates EIP-2535 diamond cuts behind EmergencyStop + DEFAULT_ADMIN_ROLE, then delegates the actual cut to DiamondLib.diamondCut. Introduces no new cut logic — all selector-collision, immutable-function, bytecode-existence, and init-delegatecall handling is diamond-lib's.

Three-layer pattern: the stateless AccessControlDiamondCut facet delegates its single external call here. DELIBERATELY STATELESS — authority lives entirely in AccessControl (+ EmergencyStop) storage, so there is no __*_init and no new ERC-7201 namespace: the host recipe's existing init (which seeds DEFAULT_ADMIN_ROLE) is the only prerequisite. Recipes wanting an on-chain upgrade registry, frozen selectors, or a guardian escape hatch should cut GovernedDiamondCut instead.

Functions

diamondCut

Guarded diamond cut: reverts if emergency-stopped, then requires the caller to hold DEFAULT_ADMIN_ROLE, then delegates to DiamondLib.diamondCut.

The stop gate runs FIRST so a guardian halt blocks upgrades in recipes that also cut EmergencyStop; in recipes without it the flag storage is default-false and the check is a no-op. Reverts AccessControlUnauthorizedAccount(caller, DEFAULT_ADMIN_ROLE) for any non-admin caller.

function diamondCut(FacetCut[] calldata _diamondCut, address _init, bytes calldata _calldata) internal;

Parameters

NameTypeDescription
_diamondCutFacetCut[]The facet addresses, cut actions, and function selectors.
_initaddressThe address delegatecalled after the cut (address(0) to skip).
_calldatabytesThe calldata passed to _init.