A modular, upgradeable smart contract framework built using the EIP-2535 Diamond Standard. This template provides a clean foundation for building composable and gas-efficient smart contracts with facet-based architecture.
- βοΈ Facets: Modular smart contract logic components
- π Upgradeable: Add, replace, or remove functions at runtime
- π§ͺ Foundry test suite: Includes deployment and mutation tests
- π Loupe Functions: Introspect facet addresses and selectors
- π Role-based Access Control via
OwnableRolesFacet
- π ERC165 Interface Support
- π Automated Deploy Script
.
βββ src/
β βββ Diamond.sol # Diamond core contract
β βββ facets/ # All facets (logic modules)
β βββ initializer/ # Initializer for setting up ERC165 and others
β βββ interfaces/ # Diamond-compliant interfaces (e.g. IDiamondCut)
β βββ libraries/ # DiamondStorage, LibDiamond, etc.
β βββ scripts/DeployDiamond.s.sol # Foundry deployment script
β
βββ test/
β βββ DiamondTest.t.sol # Tests for core diamond behavior
β βββ helpers/ # Reusable test helpers and states
β
βββ foundry.toml # Foundry config
- Forge install this repo
forge install dadadave80/diamond-lib
- Import the Diamond contract and facets into your project
import {Diamond} from "@diamond/Diamond.sol";
import {DiamondCutFacet} from "@diamond/facets/DiamondCutFacet.sol";
import {DiamondLoupeFacet} from "@diamond/facets/DiamondLoupeFacet.sol";
import {OwnableRolesFacet} from "@diamond/facets/OwnableRolesFacet.sol";
- Run Tests
forge test --ffi -vvv
- Deploy Locally
forge script script/DeployDiamond.s.sol --fork-url <RPC_URL> --broadcast
Facet | Purpose |
---|---|
DiamondCutFacet | Adds/replaces/removes functions |
DiamondLoupeFacet | View functions for facets/selectors |
OwnableRolesFacet | Ownership & role-based access |
MIT Β© 2025
Built with β₯ by David Dada