<title id="banner-title">diamond-lib β ERC-2535 Multi-Facet Proxy Library</title>A banner for the diamond-lib repository, depicting a faceted diamond representing the multi-facet proxy standard EIP-2535, with floating function selectors connected to facets.<style>.mono{font-family:ui-monospace,"SF Mono",Menlo,Consolas,"Courier New",monospace}.sans{font-family:system-ui,-apple-system,"Segoe UI","Helvetica Neue",Arial,sans-serif}.tag{font-size:17px;fill:#a8b5ca;font-weight:400}.dim,.meta{font-size:10px;letter-spacing:.22em}.meta{fill:#7ddbc0;font-weight:600}.dim,.sel,.seldim{fill:#5a6a85;font-weight:500}.sel,.seldim{font-size:11px;fill:#7ddbc0}.seldim{fill:#7a8aa5}.chip{font-size:10px;letter-spacing:.18em;fill:#a8b5ca;font-weight:600}</style>EIP / 2535STANDARD Β· FINALβ STATUS: STABLEMIT Β· Β© 2026 D.DADA0x1f931c1cβ diamondCut0xf2fde38bβ transferOwnership0x7a0ed627β facetsERC-2535 Β· MULTI-FACET PROXY STANDARDdiamond-libA modular, upgradeable smart contract framework.Add Β· replace Β· remove functions at runtime β one immutable address.SOLIDITYFOUNDRYERC-165ERC-1733 FACETS Β· LOUPE$forge install dadadave80/diamond-lib
Warning
Pending Security Audits This library is currently under active development and security review. Do not use in production until formal security audits are completed. Breaking changes may occur as we prepare for audit release.
A production-grade, modular smart contract framework built on the EIP-2535 Diamond Standard. This library provides a battle-tested foundation for building composable, upgradeable, and gas-efficient smart contracts using facet-based architecture.
| Document | Purpose |
|---|---|
| SPECIFICATION.md | Complete architecture, storage layout, and design decisions |
| DEVELOPER_GUIDE.md | Practical examples for common tasks and patterns |
| GLOSSARY.md | Terminology reference and core concepts |
| SECURITY.md | Security policies and vulnerability reporting |
| CONTRIBUTING.md | Guidelines for contributing to the project |
The Diamond pattern enables upgradeable smart contracts through facetsβmodular contracts that share storage while maintaining independent logic and upgradeable implementations.
- βοΈ Modular Facets: Organize functionality into focused, independent modules
- π Runtime Upgrades: Add, replace, or remove functions without contract migration
- π Introspection: Built-in loupe functions to query Diamond composition
- π Ownership Control: EIP-173 compatible single-owner access control
- π ERC165 Support: Standardized interface detection
- π§ͺ Comprehensive Tests: Foundry-based test suite with mutation testing
- π Deployment Scripts: Ready-to-use initialization and deployment tooling
src/
βββ Diamond.sol # Core Diamond proxy contract
βββ facets/
β βββ DiamondCutFacet.sol # Modify Diamond structure
β βββ DiamondLoupeFacet.sol # Introspect Diamond composition
β βββ OwnableFacet.sol # Ownership management
β βββ ERC165Facet.sol # Interface registration
βββ initializer/
β βββ DiamondInit.sol # Initial setup contract
β βββ MultiInit.sol # Multi-step initialization
βββ interfaces/
β βββ IDiamondCut.sol # Diamond cut standard
β βββ IDiamondLoupe.sol # Loupe functions standard
β βββ IERC165.sol # Interface detection
βββ libraries/
β βββ DiamondLib.sol # Core Diamond logic
β βββ OwnableLib.sol # Ownership primitives
β βββ InitializableLib.sol # Initialization guards
β βββ ERC165Lib.sol # Interface registration
βββ script/
βββ DeployDiamond.s.sol # Foundry deployment script
test/
βββ DiamondTest.t.sol # Core Diamond tests
βββ helpers/ # Reusable test fixtures
forge install dadadave80/diamond-libimport {Diamond} from "@diamond/Diamond.sol";
import {DiamondCutFacet} from "@diamond/facets/DiamondCutFacet.sol";
import {DiamondLoupeFacet} from "@diamond/facets/DiamondLoupeFacet.sol";
import {OwnableFacet} from "@diamond/facets/OwnableFacet.sol";
import {DiamondInit} from "@diamond/initializer/DiamondInit.sol";forge script script/DeployDiamond.s.sol:DeployDiamond \
--rpc-url <RPC_URL> \
--private-key <PRIVATE_KEY> \
--broadcastforge test -vSee DEVELOPER_GUIDE.md for detailed instructions.
See DEVELOPER_GUIDE.md for complete example.
Use the built-in loupe functions:
IDiamondLoupe loupe = IDiamondLoupe(diamond);
Facet[] memory facets = loupe.facets();
address facetAddr = loupe.facetAddress(selector);See GLOSSARY.md for more on introspection.
| Facet | Purpose | Reference |
|---|---|---|
| DiamondCutFacet | Execute diamond cuts (add/replace/remove functions) | Spec |
| DiamondLoupeFacet | Query Diamond composition | Spec |
| OwnableFacet | Manage Diamond ownership (EIP-173) | Spec |
| ERC165Facet | Register supported interfaces | Spec |
The library uses ERC-7201 namespaced storage to prevent collisions between facets:
// Each component gets isolated storage
bytes32 constant STORAGE_LOCATION =
uint256(keccak256(abi.encode(uint256(keccak256("namespace")) - 1)))
& ~bytes32(uint256(0xff));Learn more:
- SPECIFICATION.md β Storage architecture
- DEVELOPER_GUIDE.md β Using storage in custom facets
- Design new facet or changes
- Test on local fork:
forge test --fork-url <RPC_URL> - Deploy new facet:
forge create --rpc-url <RPC_URL> ... - Cut facet into Diamond: Call
diamondCut()with cuts array - Verify with loupe functions
- Monitor DiamondCut event for audit trail
See DEVELOPER_GUIDE.md for practical examples.
This library implements and supports:
- EIP-2535 β Diamond Standard
- ERC-7201 β Namespaced Storage Layout
- EIP-165 β Interface Detection
- EIP-173 β Ownership Standard
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Please report security vulnerabilities privately. See SECURITY.md for details.
- New to Diamond? Start with GLOSSARY.md
- Building a facet? See DEVELOPER_GUIDE.md
- Deep dive? Read SPECIFICATION.md
- Official EIP: EIP-2535 Diamond Standard
- Community: Nick Mudge's Awesome Diamonds
MIT Β© 2025
Built with β₯ by David Dada