Welcome to the Diamond Foundry project! This repository introduces a robust system that simplifies smart contract management using the EIP2535 Diamond Proxy Standard, a specification for an upgradable smart contract on Ethereum blockchain.
The primary goal is to build a versatile and reusable library of smart contract facets and an automated Diamond Factory. This system offers a solution to common challenges associated with smart contract development and deployment, such as complexity and the requirement for skilled engineers and auditors.
Please note that the project is still a work in progress. While we strive for accuracy, the software is provided "as is", and users are urged to use it with discretion as it's not yet stable for production environments.
- Facet Registry and Diamond Factory.
- Linting, Build, Test & Slither in CI. Deployment of artifacts to be added.
- Multi address delegate call and Facets containing built-in initializers.
DiamondCutFacet
andDiamondLoupeFacet
implementation.- Simple
OwnableFacet
andOwnable2StepFacet
with pending owner functionality. NFTOwnershipFacet
, where ownership is attributed to a NFT.AccessControlFacet
, optimized access control with 256 roles.
This is a project fully built with foundry. If you are new to foundry, please check the installation instructions.
Also, pnpm
is used as a default package manager, so please follow these instructions
for installation.
For guidance on how to integrate a Foundry project in VSCode, please refer to this guide.
git clone https://github.com/Forgenie/diamond-foundry.git
cd diamond-foundry
pnpm install
This is a list of the most frequently needed commands.
Note: You need to have foundry
installed in order to work with the contracts.
Compile the contracts:
$ forge build
Delete the build artifacts and cache directories:
$ forge clean
Get a test coverage report:
$ forge coverage
Get a gas report:
$ forge test --gas-report
Lint the contracts:
$ pnpm lint
Run the tests:
$ forge test
We invite community members to contribute to the project by reviewing code, detecting bugs, developing new Facets, and extending functionality.
Open up and review a PR, discussion or issue, and provide feedback by clearly explaining the changes and the motivation behind.
- Adding facets
- Use diamond storage
Layout
pattern for storing variables in file named<FacetName>Storage
. - Define internal behavior, interact with storage in the
<FacetName>Base
abstract contract. - Compose initializer and protect external calls in
<FacetName>Facet
contract. I<FacetName>
for interface of external functions, andI<FacetName>Base
for errors, structs, enums, and events.
- Testing
- Build helper contract named
<FacetName>Helper
for getting facet's selectors, initalizer and supported interfaces. - Attach facet interface to a diamond's address in the
setUp
of anabstract <FacetName>FacetTest
contract. OverridediamondInitParams()
to initialize diamond with tested facet or others if needed. - Reuse
I<Facet>Base
interface for accessing internal structs, errors, events or enums. - Test facets by attaching their
interface
to a diamond address. - There is one
Test
contract per each function within a Facet. It's naming should follow the<Contract>_<method>
rule, so that we can isolate it with--match-contract <REGEX>
.
MIT License (c) 2023 Forgenie Labs
Nick Mudge @mudgen diamond-hardhat
Paul Razvan Berg @PaulRBerg
foundry-template
OpenZeppelin @OpenZeppelin
openzeppelin-contracts