Skip to content

Commit 3d50278

Browse files
committed
Improved DiamondExample
1 parent 4e6340c commit 3d50278

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/diamond/DiamondLoupeFacet.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,14 @@ contract DiamondLoupeFacet {
223223
/// - This design is optimized for diamonds with many facets and many selectors,
224224
/// where the original O(n²) nested loop approach becomes prohibitively expensive.
225225
///
226-
/// @return facetsAndSelectors Array of Facet structs, each containing a facet address.
226+
/// @return facetsAndSelectors Array of Facet structs, each containing a facet address and function selectors.
227227
function facets() external view returns (Facet[] memory facetsAndSelectors) {
228228
DiamondStorage storage s = getStorage();
229229
bytes4[] memory selectors = s.selectors;
230230
uint256 selectorsCount = selectors.length;
231231
bytes4 selector;
232232

233-
// Reuse the selectors array to hold pointers to Facet structs in memory.
233+
// Reuse the selectors memory array to hold pointers to Facet structs in memory.
234234
// Each pointer is a memory address to a Facet struct in memory.
235235
// As we loop through the selectors, we overwrite earlier slots with pointers.
236236
// The selectors array and the facetPointers array point to the same
@@ -250,6 +250,7 @@ contract DiamondLoupeFacet {
250250
// Each entry is a dynamically sized array of uint256 pointers.
251251
// Using only the last byte of the address (256 possible values) provides a simple
252252
// bucketing mechanism to reduce linear search costs across unique facets.
253+
// Each entry in the map is called a "bucket".
253254
uint256[][256] memory map;
254255

255256
// The last byte of a facet address, used as an index key into `map`.

src/diamond/deployment/ExampleDiamond.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ contract ExampleDiamond is ComposeDiamond {
1414
/// address facetAddress;
1515
/// FacetCutAction action; // Add=0, Replace=1, Remove=2
1616
/// bytes4[] functionSelectors;
17-
/// }
17+
///}
18+
1819
/// @notice Initializes the diamond contract with facets, owner and other data.
1920
/// @dev Adds all provided facets to the diamond's function selector mapping and sets the contract owner.
2021
/// Each facet in the array will have its function selectors registered to enable delegatecall routing.
2122
/// @param _facets Array of facet addresses and their corresponding function selectors to add to the diamond.
2223
/// @param _diamondOwner Address that will be set as the owner of the diamond contract.
23-
constructor(FacetCut[] memory _facets, address _diamondOwner) {
24-
addFacets(_facets);
24+
constructor(ComposeDiamond.FacetCut[] memory _facets, address _diamondOwner) {
25+
ComposeDiamond.addFacets(_facets);
2526

2627
// Initialize storage variables
2728
//////////////////////////////////////////////////////

0 commit comments

Comments
 (0)