/Diamond-Conflux

Primary LanguageSolidityMIT LicenseMIT

Diamond-3-Hardhat Implementation + Typechain Support For Conflux Hydra Network

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.

Installation

  1. Clone this repo:
git clone https://github.com/Timidan/Diamond-Conflux.git
  1. Install NPM packages:
cd diamond-3-hardhat
npm install or yarn install

Deployment

npx hardhat run scripts/deploy.ts

Upgrade a diamond

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.

Facet Information

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.

License

MIT license. See the license file. Anyone can use or modify this software for their purposes.