This is a simple example implementation for EIP-2535 Diamond Standard. To learn about other implementations go here: https://github.com/mudgen/diamond
The standard loupe functions have been gas-optimized in this implementation and can be called in on-chain transactions. However keep in mind that a diamond can have any number of functions and facets so it is still possible to get out-of-gas errors when calling loupe functions. Except for the facetAddress
loupe function which has a fixed gas cost.
- Clone this repo:
git clone https://github.com/Timidan/Diamond-Conflux.git
- Install NPM packages:
cd diamond-3-hardhat
npm install or yarn install
npx hardhat run scripts/deploy.ts
Check the scripts/deploy.ts
and or the test/diamondTest.ts
file for examples of upgrades.
Note that upgrade functionality is optional. It is possible to deploy a diamond that can't be upgraded, which is a 'Single Cut Diamond'. It is also possible to deploy an upgradeable diamond and at a later date remove its diamondCut
function so it can't be upgraded any more.
Note that any number of functions from any number of facets can be added/replaced/removed on a diamond in a single transaction.
The contracts/Diamond.sol
file shows an example of implementing a diamond.
The contracts/facets/DiamondCutFacet.sol
file shows how to implement the diamondCut
external function.
The contracts/facets/DiamondLoupeFacet.sol
file shows how to implement the four standard loupe functions.
The contracts/libraries/LibDiamond.sol
file shows how to implement Diamond Storage and a diamondCut
internal function.
The scripts/deploy.ts
file shows how to deploy a diamond.
MIT license. See the license file. Anyone can use or modify this software for their purposes.