Appearance
Solidity API
LibDiamond
A library for implementing the Diamond pattern (EIP-2535)
This library provides core functionality for diamond proxies, including facet management and function selector handling
InValidFacetCutAction
solidity
error InValidFacetCutAction()Error thrown when an invalid facet cut action is provided
NotDiamondOwner
solidity
error NotDiamondOwner()Error thrown when the caller is not the diamond owner
NoSelectorsInFacet
solidity
error NoSelectorsInFacet()Error thrown when no selectors are provided for a facet
NoZeroAddress
solidity
error NoZeroAddress()Error thrown when the zero address is used
SelectorExists
solidity
error SelectorExists(bytes4 selector)Error thrown when a selector already exists
Parameters
| Name | Type | Description |
|---|---|---|
| selector | bytes4 | The existing selector |
SameSelectorReplacement
solidity
error SameSelectorReplacement(bytes4 selector)Error thrown when attempting to replace a selector with the same selector
Parameters
| Name | Type | Description |
|---|---|---|
| selector | bytes4 | The selector being replaced |
MustBeZeroAddress
solidity
error MustBeZeroAddress()Error thrown when a non-zero address is expected
NoCode
solidity
error NoCode()Error thrown when a contract has no code
NonExistentSelector
solidity
error NonExistentSelector(bytes4 selector)Error thrown when a non-existent selector is used
Parameters
| Name | Type | Description |
|---|---|---|
| selector | bytes4 | The non-existent selector |
ImmutableFunction
solidity
error ImmutableFunction(bytes4 selector)Error thrown when attempting to modify an immutable function
Parameters
| Name | Type | Description |
|---|---|---|
| selector | bytes4 | The selector of the immutable function |
NonEmptyCalldata
solidity
error NonEmptyCalldata()Error thrown when calldata is expected to be empty
EmptyCalldata
solidity
error EmptyCalldata()Error thrown when calldata is expected to be non-empty
InitCallFailed
solidity
error InitCallFailed()Error thrown when an initialization call fails
DIAMOND_STORAGE_POSITION
solidity
bytes32 DIAMOND_STORAGE_POSITIONUnique storage position for diamond storage
FacetAddressAndPosition
Struct to store facet address and function selector position
Parameters
| Name | Type | Description |
|---|
solidity
struct FacetAddressAndPosition {
address facetAddress;
uint96 functionSelectorPosition;
}FacetFunctionSelectors
Struct to store function selectors for a facet
Parameters
| Name | Type | Description |
|---|
solidity
struct FacetFunctionSelectors {
bytes4[] functionSelectors;
uint256 facetAddressPosition;
}DiamondStorage
Main storage struct for the diamond
Stores all necessary information for the diamond proxy
solidity
struct DiamondStorage {
mapping(bytes4 => struct LibDiamond.FacetAddressAndPosition) selectorToFacetAndPosition;
mapping(address => struct LibDiamond.FacetFunctionSelectors) facetFunctionSelectors;
address[] facetAddresses;
mapping(bytes4 => bool) supportedInterfaces;
mapping(string => bool) supportedFunctionInterfaces;
address contractOwner;
address diamondAddress;
}diamondStorage
solidity
function diamondStorage() internal pure returns (struct LibDiamond.DiamondStorage ds)Retrieves the diamond storage
Return Values
| Name | Type | Description |
|---|---|---|
| ds | struct LibDiamond.DiamondStorage | The DiamondStorage struct |
OwnershipTransferred
solidity
event OwnershipTransferred(address previousOwner, address newOwner)Emitted when contract ownership is transferred
Parameters
| Name | Type | Description |
|---|---|---|
| previousOwner | address | Address of the previous owner |
| newOwner | address | Address of the new owner |
setContractOwner
solidity
function setContractOwner(address _newOwner) internalSets a new contract owner
Parameters
| Name | Type | Description |
|---|---|---|
| _newOwner | address | Address of the new owner |
contractOwner
solidity
function contractOwner() internal view returns (address contractOwner_)Retrieves the current contract owner
Return Values
| Name | Type | Description |
|---|---|---|
| contractOwner_ | address | Address of the current contract owner |
enforceIsContractOwner
solidity
function enforceIsContractOwner() internal viewEnsures that the caller is the contract owner
Reverts if the caller is not the contract owner
diamondCut
solidity
function diamondCut(struct IDiamondCut.FacetCut[] _diamondCut, struct IPropsInitCall.InitCall[] _initCalls) internalInternal function to perform a diamond cut
Parameters
| Name | Type | Description |
|---|---|---|
| _diamondCut | struct IDiamondCut.FacetCut[] | Array of FacetCut structs describing the changes |
| _initCalls | struct IPropsInitCall.InitCall[] | Array of InitCall structs for initialization |
executeExternalInitCalls
solidity
function executeExternalInitCalls(address _diamond, struct IPropsInitCall.InitCall[] _externalInitCalls) internalmodifySupportedInterfaces
solidity
function modifySupportedInterfaces(bytes4[] _addInterfaceIds, bytes4[] _removeInterfaceIds) internalModifies the supported interfaces
Parameters
| Name | Type | Description |
|---|---|---|
| _addInterfaceIds | bytes4[] | Array of interface IDs to add |
| _removeInterfaceIds | bytes4[] | Array of interface IDs to remove |
modifySupportedFunctionInterfaces
solidity
function modifySupportedFunctionInterfaces(string[] _addInterfaceIds, string[] _removeInterfaceIds) internalModifies the supported function interfaces
Parameters
| Name | Type | Description |
|---|---|---|
| _addInterfaceIds | string[] | Array of function interface IDs to add |
| _removeInterfaceIds | string[] | Array of function interface IDs to remove |
addFunctions
solidity
function addFunctions(address _facetAddress, bytes4[] _functionSelectors) internalAdds new functions to a facet
Parameters
| Name | Type | Description |
|---|---|---|
| _facetAddress | address | Address of the facet |
| _functionSelectors | bytes4[] | Array of function selectors to add |
replaceFunctions
solidity
function replaceFunctions(address _facetAddress, bytes4[] _functionSelectors) internalReplaces functions in a facet
Parameters
| Name | Type | Description |
|---|---|---|
| _facetAddress | address | Address of the facet |
| _functionSelectors | bytes4[] | Array of function selectors to replace |
removeFunctions
solidity
function removeFunctions(address _facetAddress, bytes4[] _functionSelectors) internalRemoves functions from a facet
Parameters
| Name | Type | Description |
|---|---|---|
| _facetAddress | address | Address of the facet (should be zero address) |
| _functionSelectors | bytes4[] | Array of function selectors to remove |
addFacet
solidity
function addFacet(struct LibDiamond.DiamondStorage ds, address _facetAddress) internalAdds a new facet to the diamond
Parameters
| Name | Type | Description |
|---|---|---|
| ds | struct LibDiamond.DiamondStorage | DiamondStorage struct |
| _facetAddress | address | Address of the new facet |
addFunction
solidity
function addFunction(struct LibDiamond.DiamondStorage ds, bytes4 _selector, uint96 _selectorPosition, address _facetAddress) internalAdds a function to a facet
Parameters
| Name | Type | Description |
|---|---|---|
| ds | struct LibDiamond.DiamondStorage | DiamondStorage struct |
| _selector | bytes4 | Function selector to add |
| _selectorPosition | uint96 | Position of the selector in the functionSelectors array |
| _facetAddress | address | Address of the facet |
removeFunction
solidity
function removeFunction(struct LibDiamond.DiamondStorage ds, address _facetAddress, bytes4 _selector) internalRemoves a function from a facet
Parameters
| Name | Type | Description |
|---|---|---|
| ds | struct LibDiamond.DiamondStorage | DiamondStorage struct |
| _facetAddress | address | Address of the facet |
| _selector | bytes4 | Function selector to remove |
initializeDiamondCut
solidity
function initializeDiamondCut(struct IPropsInitCall.InitCall[] _initCalls) internalInitializes the diamond cut
Parameters
| Name | Type | Description |
|---|---|---|
| _initCalls | struct IPropsInitCall.InitCall[] | Array of InitCall structs for initialization |
bytesToHex
solidity
function bytesToHex(bytes data) internal pure returns (string)Converts bytes to a hexadecimal string
Parameters
| Name | Type | Description |
|---|---|---|
| data | bytes | Bytes to convert |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | string | Hexadecimal string representation of the input bytes |
enforceHasContractCode
solidity
function enforceHasContractCode(address _contract) internal viewEnsures that a contract has code
Parameters
| Name | Type | Description |
|---|---|---|
| _contract | address | Address of the contract to check |
createFunctionIdentifier
solidity
function createFunctionIdentifier(address _facetAddress, bytes4 _selector) internal pure returns (string)Creates a unique function identifier
Parameters
| Name | Type | Description |
|---|---|---|
| _facetAddress | address | Address of the facet |
| _selector | bytes4 | Function selector |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | string | Unique function identifier string |
addressToString
solidity
function addressToString(address _addr) internal pure returns (string)Converts an address to a string
Parameters
| Name | Type | Description |
|---|---|---|
| _addr | address | Address to convert |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | string | String representation of the address |
bytes4ToHexString
solidity
function bytes4ToHexString(bytes4 _bytes) internal pure returns (string)Converts bytes4 to a hexadecimal string
Parameters
| Name | Type | Description |
|---|---|---|
| _bytes | bytes4 | Bytes4 to convert |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | string | Hexadecimal string representation of the bytes4 |
toHexString
solidity
function toHexString(uint256 value, uint256 length) internal pure returns (string)Converts a uint256 value to a hexadecimal string of specified length
Parameters
| Name | Type | Description |
|---|---|---|
| value | uint256 | The uint256 value to convert |
| length | uint256 | The desired length of the output string |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | string | Hexadecimal string representation of the input value |