How mudgen/diamond-3-hardhat works
Project type and purpose
• This is an Ethereum smart-contract project using Hardhat, implementing the EIP-2535 Diamond Standard (a modular, upgradeable proxy pattern).
• Its goal is to deploy a single “diamond” proxy contract on‐chain, and then add, replace, or remove logic modules (“facets”) at runtime via the diamondCut function.
File structure
• Top‐level
– hardhat.config.js, package.json: Hardhat configuration and NPM scripts
– scripts/deploy.js: deployment and upgrade orchestration
– test/*.js: unit tests for diamondCut and loupe functions
• contracts/
– Diamond.sol: the proxy entry point
– facets/
• DiamondCutFacet.sol – implements the diamondCut upgrade interface
• DiamondLoupeFacet.sol – implements standard loupe (introspection) functions
• other facet .sol files (user–customizable logic)
– interfaces/: EIP-defined ABI interfaces
– libraries/LibDiamond.sol: shared storage layout and internal diamondCut logic
– upgradeInitializers/: initialization contracts for state setup on first upgrade
Insights from the README
• The README explains the deploy sequence:
1) Deploy DiamondCutFacet
2) Deploy Diamond proxy, passing owner & cut facet address
3) Deploy DiamondInit and call its init via delegatecall
4) Deploy other facets and call diamondCut to wire them into the proxy
• Tests cover both upgrade logic and loupe functions