-
Notifications
You must be signed in to change notification settings - Fork 61
Feat: Add Abstract Diamond Lib #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Introduced remappings for compose-related directories in foundry.toml to improve import path management and organization.
Introduces the Diamond contract, an abstract implementation of the ERC-2535 Diamond proxy pattern. Provides mechanisms for dynamic addition, replacement, and removal of facets, including storage management, error handling, and fallback delegation logic.
MinimalDiamond now inherits from the Diamond contract and is initialized via its constructor, simplifying deployment and initialization. Imports have been updated to use the @compose package.
Updated imports to use @compose package for Diamond and DiamondLoupeFacet. Refactored diamond initialization to pass facet cuts and initialization arguments directly to MinimalDiamond constructor, simplifying setup in BaseBenchmark.
Introduces initializable storage and logic to the Diamond contract, including new errors and events for initialization. Replaces the constructor with an external initialize function, updates function parameter types to calldata for efficiency, and adds a receive function for handling plain ether transfers.
Updated import paths in Base.t.sol to use @compose-benchmark namespace. Refactored MinimalDiamond to remove constructor and use an initialize method instead, simplifying contract deployment in tests.
Abstract diamond lib
👷 Deploy request for compose-diamonds pending review.Visit the deploys page to approve it
|
Coverage Report
Last updated: Tue, 25 Nov 2025 14:07:13 GMT for commit |
Gas ReportComparing gas usage between Summary
Details
ℹ️ About this reportThis report compares gas usage between the base branch and this PR using
To run this locally: # Generate snapshot for current branch
forge snapshot
# Compare with another branch
git checkout main
forge snapshot --diff .gas-snapshotLast updated: Tue, 25 Nov 2025 14:07:54 GMT for commit |
Since there is another storage within the same contract
|
@dadadave80 I will review this. Thanks for this! |
|
@dadadave80 I like this approach, but have you explored a diamond contract implementation where the facet functions are added to the diamond in the constructor function of the diamond contract? And storage variable and any other initialization is done in the constructor function of the diamond contract? I am currently exploring that approach, which you can see here: https://github.com/Perfect-Abstractions/Compose/blob/main/src/diamond/deployment/ExampleDiamond.sol |
|
@dadadave80 Do you prefer the initializer approach over the constructor approach? If so, why? |
Initializing the diamond with a constructor loads Loading large arrays of structs into memory tends to explode gas usage. Additionally, the removal of |
Yes, this is true. It would be very interested and very useful to see some gas benchmark comparisons between using a constructor version that uses
The idea with Also, they can import the I don't know why people would need replace/remove functions when constructing a diamond. If you have ideas about that, I am interested to know. |
|
Alright, use what you feel is best for the library |
Yes, of course. This discussion with you is very good for me and what you have submitted is helpful in this phase of development. I really appreciate it and hope to keep working and discussing things with you. |
Summary
Unify and enhance the Diamond proxy implementation with improved import management and initialization logic.
Changes Made
Removed specific EVM version to default to the latest mainnet version.
Added remappings in
foundry.tomlfor better import path management.Introduced an abstract Diamond contract implementing the ERC-2535 Diamond proxy pattern.
Refactored MinimalDiamond to inherit from the abstract Diamond contract, simplifying its deployment.
Updated imports and initialization logic in BaseBenchmark to use the new structure.
Checklist
Before submitting this PR, please ensure:
Code follows the Solidity feature ban - No inheritance, constructors, modifiers, public/private variables, external library functions,
using fordirectives, orselfdestructCode follows Design Principles - Readable, uses diamond storage, favors composition over inheritance
Code matches the codebase style - Consistent formatting, documentation, and patterns (e.g. ERC20Facet.sol)
Code is formatted with
forge fmtExisting tests pass - Run tests to be sure existing tests pass.
New tests are optional - If you don't provide tests for new functionality or changes then please create a new issue so this can be assigned to someone.
All tests pass - Run
forge testand ensure everything worksDocumentation updated - If applicable, update relevant documentation
Make sure to follow the contributing guidelines.
Additional Notes
No additional notes at this time.