Skip to content

Commit 7045dec

Browse files
committed
Add diamond manager
1 parent 99740f8 commit 7045dec

379 files changed

Lines changed: 193609 additions & 4 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

GUIDE.MD

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Setup guide
2+
## Installing NPM
3+
Recommended for easier use: install NVM (Node Version Manager), this will allow you to install and switch between Node versions, installation is different for each OS.
4+
5+
## Setup
6+
* Navigate to `/diamond-contracts` directory
7+
* Run `nvm use` , this will read the `.nvmrc` file in the folder and install the appropriate Node version
8+
* Once Node is installed run `npm i` to install all necessary packages.
9+
* Rename `sample.env` file to `.env` in the folder, fill all values (RPC endpoints, API keys, Private Key for the deployer account)
10+
* To test the smart contracts use the command `npm run test`, this will compile all contracts and make sure the environment values are working correctly
11+
12+
## Configuring chains
13+
* All configurations are in the `/diamond-contracts/hardhat.config.js` file
14+
* To add a new blockchain you must add the RPC and Block explorer data of the chain
15+
* The RPC information must be added in the networks field of the config, identify the chain with the chain's 0x identifier (`0x1` for Eth mainnet and so on), this is important for the deployment process.
16+
* You can specify a private key for each chain, but there's a reusable object that you can destructure
17+
* The block explorer data includes the API key of the chain explorer, this is important for the verification of the source code. It must be added on the `etherscan.apiKey` field of the config
18+
* Run `npx hardhat verify --list-networks` to see all supported chains, if the new chain does not appear you must add it manually to the `etherscan.customChains` field, you will need to provide the name, numerical id, api endpoint and browser url of the chain
19+
20+
## Deployments
21+
* The deployment process reads the files in `/diamond-contracts/deploy`, it will read the files in alphabetical order, which is why the `1.Facets.js` file is named like that
22+
* It will go through each of the names in Facets and use the a helper to deploy and verify each of the facets
23+
* Once all facets are deployed it will move on to the ERC20Exchange, Factory, Marketplace, ERC20 and FacetSource contracts respectively.
24+
* Hardhat will be able to tell if a contract has already been deployed, so if the process is interrupted for any reason it will not redeploy everything again on the second run, as long as the contract's source code hasn't changed
25+
* It will only try to verify the contract if the deployment happened on the current run, so to verify an already deployed contract you will need to tweak the code a bit
26+
* To ignore the checking, deploying and verification of each facet and contract in the list you can also modify the code, be it with return statements on each .js files or just commenting out the names of the facets.
27+
* There are separate commands to deploy on each blockchain, to see all available commands use the npm run command
28+
* Deployment scripts on testnets are called deploy-{blockchain} i.e. `deploy-sepolia`
29+
* Deployment scripts for testnets are called PAYABLE-deploy-{blockchain} i.e `PAYABLE-deploy-ethereum`, it makes it easier to identify and harder to call by accident
30+
* You will have to add additional commands when a blockchain is added, the underlying command will be "npx hardhat --network {chain hash} deploy" i.e. `npx hardhat --network 0xaa36a7 deploy`
31+
* The process is automatic, you will be able to see the resulting 0x address of the contract and the status of the verification and a link to the block explorer's source code page
32+
![Deployment example](/assets/images/deploymentexample.png)
33+
* The deployment of the DiamondCut facet is priority when deploying on a new blockchain, as it will be used to deploying the main contracts of the Factory, Marketplace and FacetSource
34+
* On the deployment of the ERC20 you must add the address of the contract's owner and the amount of tokens to be minted on deploy
35+
* The resulting ABIs will be generated on the `/diamond-contracts/deployments/` directory, the folder will have the same identifier as the hardhat config (which should be the 0x identifier of the chain)
36+
37+
## Connecting facets
38+
For ease of use the `diamond-manager` folder has a basic React frontend to manage diamond facets
39+
40+
* Copy the deployments directory from `diamond-contracts` to `diamond-manager`
41+
* Run `npm i` to install all components
42+
* Run `npm start` to deploy a local frontend
43+
* Use the dropdown menu to select a diamond contract, the frontend will display all of it's related facets
44+
* Each of the functions from the facet will be displayed, you must select them all (by clicking on them) and pressing the 'Add' button
45+
* Selected functions are colored green
46+
* Functions connected to the diamond will have a blue border
47+
* Functions that exist in name in the diamond but are not coming from the current facet will have a green border
48+
* Functions that are not connected will have a red border
49+
![Manager Example](/assets/images/manager.png)
50+
* The Add functionality will fail if one of the functions already exists in the diamond, use the Replace button for these functions, you can also Remove functions
51+
* Always add the functions from the Loupe facet first, that is how we can query the diamond and tell which functions are available
52+
* There are 7 functions used by the AccessControl standard: getRoleAdmin, getRoleMember, getRoleMemberCount, grantRole, hasRole, renounceRole, revokeRole, these functions are available directly on the main diamond contract so they are not necessary to add, this can save gas at the time of connecting the facets.
53+
* `rair-front` will need the combined ABI from each contract, use the Combine ABI button at the bottom of the page to generate the file, then move it to the appropriate folder.
189 KB
Loading

assets/images/manager.png

174 KB
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1116

0 commit comments

Comments
 (0)