diff --git a/EIPS/eip-2535.md b/EIPS/eip-2535.md index 1283bd6c..a92d0e47 100644 --- a/EIPS/eip-2535.md +++ b/EIPS/eip-2535.md @@ -107,16 +107,13 @@ A diamond can be upgraded if it has a diamondCut external function or other func A facet defines external functions and can define or use internal functions, libraries, and state variables. -A facet can declare and use state variables but it does it in a way that is safer, easier and more flexible for diamonds. - -Facet state variables are declared in structs. Each struct is given a specific position in contract storage. This technique is called **Diamond Storage**. +A facet can declare state variables in structs. Each struct is given a specific position in contract storage. This technique is called **Diamond Storage**. Here is a simple example that shows diamond storage and its use in a facet: ```Solidity // A contract that implements diamond storage. -// This contract is inherited and used by facets. -contract DiamondStorageContract { +library LibA { // This struct contains state variables we care about. struct DiamondStorage { @@ -128,23 +125,23 @@ contract DiamondStorageContract { // ds is short for DiamondStorage function diamondStorage() internal pure returns(DiamondStorage storage ds) { // Specifies a random position from a hash of a string - bytes32 storagePosition = keccak256("diamond.storage") + bytes32 storagePosition = keccak256("diamond.storage.LibA") // Set the position of our struct in contract storage assembly {ds.slot := storagePosition} } } -// Our facet inherits and uses the diamond storage defined above. -contract FacetA is DiamondStorageContract { +// Our facet uses the diamond storage defined above. +contract FacetA { function setDataA(bytes32 _dataA) external { - DiamondStorage storage ds = diamondStorage(); + LibA.DiamondStorage storage ds = LibA.diamondStorage(); require(ds.owner == msg.sender, "Must be owner."); ds.dataA = _dataA } function getDataA() external view returns (bytes32) { - return diamondStorage().dataA + return LibDiamond.diamondStorage().dataA } } ``` @@ -155,8 +152,6 @@ By using diamond storage facets can declare their own state variables that do no By using diamond storage facets can be developed independently, without connection or concern for other facets. -Solidity libraries can also use diamond storage. - ## Diamonds Can Use Other Contract Storage Strategies Diamonds and facets don't have to use diamond storage. They can use other contract storage strategies such as contract inheritance.