Merged
Conversation
Chore/updates and fixes
Chore/rename and refactor libs
Remove underscore prefix from all internal library functions,
_guardInitializeOwner indirection, and use inline
`assembly("memory-safe")` annotations. Update DiamondCutFacet and
OwnableRolesFacet call sites.
Replace constructor-based initialization with an external `initialize()` function guarded by InitializableLib. Simplify MultiInit to use inline delegatecall with explicit error handling. Remove _beforeDelegate hook and _diamondCut wrapper from Diamond base contract.
Split DiamondInit into standalone OwnableInit and ERC165Init initializers for granular use via MultiInit. Update deploy script to use MultiInit with the separate initializers.
postReinitializer was storing the raw version without shifting left by 1, breaking the packed slot layout (bit 0 = initializing, bits 1..64 = version). This caused getInitializedVersion() to return incorrect values and the Initialized event to emit wrong versions after reinitialization.
Test initialization, re-initialization prevention, version tracking, sequential reinitializations, disableInitializers, and MultiInit composition through the Diamond.initialize() entrypoint.
Add initializable Diamond pattern
Replace vm.readFile artifact parsing with forge inspect FFI call to fetch only methodIdentifiers, eliminating full artifact JSON dumps in test and script traces.
Add 81 new tests across 3 test files covering diamond cut operations (add/replace/remove), all error conditions, ownership transfer and handover ceremonies, role management, MultiInit error paths, ETH handling, and ERC-165 compliance edge cases.
Remove duplicate addFunctions, replaceFunctions, removeFunctions, diamondCut, and initializeDiamondCut memory variants. Rename calldata variants to be the canonical functions.
Chore/updates and fixes
…th-ownable Refactor and enhance Diamond library with initializable pattern
- Inline storage access to eliminate redundant view helper calls - Optimize addFunction to use single struct assignment - Optimize replaceSelectors to avoid costly delete + recreate - Extract _removeSelectorFromOldFacet for reuse in replace and remove - Reorganize internal sections for clarity
Replace storage-based interface checks with an assembly switch-case in ERC165Lib that returns true for ERC-165, ERC-173, IDiamondCut, and IDiamondLoupe without touching storage. This eliminates the need for ERC165Init and its storage writes during initialization.
Move supportsInterface from DiamondLoupeFacet into a new ERC165Facet for cleaner separation of concerns. Update deploy script, test state, and all test files to register and reference the new facet.
Feat/erc165 lib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OwnableInitandERC165InitOwnableRoleswith simplerOwnablelib and facetsupportsInterfaceinto dedicatedERC165Facet_removeSelectorFromOldFacetaddFacetTest plan
forge test)