Skip to main content
Based on EIP-2535: Diamonds (https://eips.ethereum.org/EIPS/eip-2535) Follows diamond-3 implementation (https://github.com/mudgen/diamond-3-hardhat/) Manages all actions (calls, updates and initializations) related to the diamond and its facets.

fallback

fallback() external payable
Forwards call to the right facet using msg.sig using delegatecall. Reverts if signature is not known.

receive

receive() external payable
Allows the contract to receive ether

diamondCut

function diamondCut(struct IDiamondStorage.FacetCut[] _faceCut, address _init, bytes _calldata) external
Add/replace/remove any number of functions and optionally execute a function with delegatecall

Parameters

NameTypeDescription
_faceCutIDiamondStorage.FacetCut[]
_initaddressThe address of the contract or facet to execute _calldata
_calldatabytesA function call, including function selector and arguments _calldata is executed with delegatecall on _init

_diamondCut

function _diamondCut(struct IDiamondStorage.FacetCut[] _facetCut, address _init, bytes _calldata) internal
Internal function for diamondCut()

_addFunctions

function _addFunctions(address _facetAddress, bytes4[] _functionSelectors) internal
Adds the facet if it wasn’t added yet, and adds its functions to the diamond

Parameters

NameTypeDescription
_facetAddressaddressaddress of the facet contract
_functionSelectorsbytes4[]array of function selectors

_replaceFunctions

function _replaceFunctions(address _facetAddress, bytes4[] _functionSelectors) internal
Updates facet contract address for given function selectors

Parameters

NameTypeDescription
_facetAddressaddressaddress of the facet contract
_functionSelectorsbytes4[]array of function selectors

_removeFunctions

function _removeFunctions(address _facetAddress, bytes4[] _functionSelectors) internal
Removes some function selectors of a facet from diamond

Parameters

NameTypeDescription
_facetAddressaddressaddress of the facet contract
_functionSelectorsbytes4[]array of function selectors

_addFacet

function _addFacet(struct IDiamondStorage.DiamondStorage s, address _facetAddress) internal
Adds a new facet contract address to the diamond

Parameters

NameTypeDescription
sIDiamondStorage.DiamondStoragediamond storage pointer
_facetAddressaddressaddress of the new facet contract

_addFunction

function _addFunction(struct IDiamondStorage.DiamondStorage s, bytes4 _selector, uint96 _selectorPosition, address _facetAddress) internal
Adds a new function to the diamond for a given facet contract

Parameters

NameTypeDescription
sIDiamondStorage.DiamondStoragediamond storage pointer
_selectorbytes4function selector
_selectorPositionuint96position of the function selector in the facet selectors array
_facetAddressaddressaddress of the facet contract

_removeFunction

function _removeFunction(struct IDiamondStorage.DiamondStorage s, address _facetAddress, bytes4 _selector) internal
Removes a function from a facet of the diamond

Parameters

NameTypeDescription
sIDiamondStorage.DiamondStoragediamond storage pointer
_facetAddressaddressaddress of the facet contract
_selectorbytes4function selector

_initializeDiamondCut

function _initializeDiamondCut(address _init, bytes _calldata) internal
Initializes a facet after updating the diamond using delegatecall

Parameters

NameTypeDescription
_initaddressaddress of the contract to execute _calldata
_calldatabytesfunction call (selector and arguments)

_enforceHasContractCode

function _enforceHasContractCode(address _contract) internal view
Reverts if the given address is not a contract

Parameters

NameTypeDescription
_contractaddressaddress to check