GNSDiamondCut

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

Name
Type
Description

_init

address

The address of the contract or facet to execute _calldata

_calldata

bytes

A function call, including function selector and arguments _calldata is executed with delegatecall on _init

_diamondCut

Internal function for diamondCut()

_addFunctions

Adds the facet if it wasn't added yet, and adds its functions to the diamond

Parameters

Name
Type
Description

_facetAddress

address

address of the facet contract

_functionSelectors

bytes4[]

array of function selectors

_replaceFunctions

Updates facet contract address for given function selectors

Parameters

Name
Type
Description

_facetAddress

address

address of the facet contract

_functionSelectors

bytes4[]

array of function selectors

_removeFunctions

Removes some function selectors of a facet from diamond

Parameters

Name
Type
Description

_facetAddress

address

address of the facet contract

_functionSelectors

bytes4[]

array of function selectors

_addFacet

Adds a new facet contract address to the diamond

Parameters

Name
Type
Description

s

diamond storage pointer

_facetAddress

address

address of the new facet contract

_addFunction

Adds a new function to the diamond for a given facet contract

Parameters

Name
Type
Description

s

diamond storage pointer

_selector

bytes4

function selector

_selectorPosition

uint96

position of the function selector in the facet selectors array

_facetAddress

address

address of the facet contract

_removeFunction

Removes a function from a facet of the diamond

Parameters

Name
Type
Description

s

diamond storage pointer

_facetAddress

address

address of the facet contract

_selector

bytes4

function selector

_initializeDiamondCut

Initializes a facet after updating the diamond using delegatecall

Parameters

Name
Type
Description

_init

address

address of the contract to execute _calldata

_calldata

bytes

function call (selector and arguments)

_enforceHasContractCode

Reverts if the given address is not a contract

Parameters

Name
Type
Description

_contract

address

address to check

Last updated

Was this helpful?