chore: change top level folder structure (#105)

* folder restructure init - WIP

* Update husky for folder change

* Properly ignore local zeppelin file

* change folder strucutre: update readme and contribution files

* remove chakra from readme list of key dependencies

* run contract workflow steps in contract dir

* Cleanup readmes, split contract into it's own

* Apply some suggestions from code review

Co-authored-by: Shredder <110225819+EmperorOrokuSaki@users.noreply.github.com>
Co-authored-by: Felipe Mendes <zo.fmendes@gmail.com>

* Move .env.example to contracts folder, and use consistent format for directory references in docs

* More readme dir ref fixes

* Update poc note in readme, and removed deploy folder from readme

* Prettier refactor

* Revert "Prettier refactor"

This reverts commit 82249e32aaf6a6e9a4d432c4f89ca365c18972f8.

* Clean up package.json and add prettier ignore

---------

Co-authored-by: Shredder <110225819+EmperorOrokuSaki@users.noreply.github.com>
Co-authored-by: Felipe Mendes <zo.fmendes@gmail.com>
This commit is contained in:
Janison Sivarajah 2023-02-06 15:15:44 -05:00 committed by GitHub
parent f37fcbc315
commit 6a827263b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
66 changed files with 7140 additions and 5863 deletions

View File

@ -10,6 +10,10 @@ jobs:
test-contracts:
runs-on: ubuntu-latest
defaults:
run:
working-directory: contracts
strategy:
matrix:
node-version: [18.x]

21
.gitignore vendored
View File

@ -1,24 +1,3 @@
node_modules
.env
# hardhat
cache
artifacts
deployments/hardhat
# NPM
package-lock.json
# Foundry
out
forge-cache
# OpenZeppelin
.openzeppelin/unknown-*.json
# Subgraph
*.wasm
subgraph/build
subgraph/generated
subgraph/abis
subgraph/examples/query/.graphclient

2
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
path = contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std

View File

@ -1,4 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
cd contracts
yarn test

12
.prettierignore Normal file
View File

@ -0,0 +1,12 @@
contracts/.openzeppelin/**/*
contracts/artifacts/**/*
contracts/cache/**/*
contracts/deployments/**/*
contracts/forge-cache/**/*
contracts/lib/**/*
contracts/out/**/*
subgraph/abis/**/*
subgraph/build/**/*
subgraph/generated/**/*
subgraph/examples/query/.graphclient/**/*

View File

@ -45,7 +45,7 @@ Please ensure your code is clear and readable and provide as much information as
## Testing
This project has test suites both in Solidity and JavaScript. We use [Hardhat](https://hardhat.org/) and [Foundry](https://book.getfoundry.sh/) frameworks. It is mandatory for all tests to be well described to make the code consistent and secure. To get more information about this topic, check the [Testing section on our wiki](https://github.com/fleekxyz/non-fungible-apps/wiki/%F0%9F%93%98-Getting-Started#testing). You can also treat existing test suites as your inspiration. They are located at the [test folder](/test).
This is a mono repo so testing will be dependent on the specific folder you are in. Please refer to the readme, test folder, and package.json commands for the testing specifics in the directory you are working in. Reegarding contract, this project has test suites both in Solidity and JavaScript. We use [Hardhat](https://hardhat.org/) and [Foundry](https://book.getfoundry.sh/) frameworks. It is mandatory for all tests to be well described to make the code consistent and secure. To get more information about this topic, check the [Testing section on our wiki](https://github.com/fleekxyz/non-fungible-apps/wiki/%F0%9F%93%98-Getting-Started#testing). You can also treat existing test suites as your inspiration. They are located at the [test folder](/contracts/test).
## Getting help

198
README.md
View File

@ -21,197 +21,24 @@ You can find the wiki [here](https://github.com/fleekxyz/non-fungible-apps/wiki)
### 📁 Project Structure
Inside the root folder you are going to find:
- [contracts](./contracts): all the developed contracts
- [subgraph](./subgraph): The Graph project related code
- [ui](./ui): a web application to interact with deployed contracts
- [/contracts](/contracts): all the developed contracts
- [/deploy](/deploy): scripts used for deployment on different networks
- [/deployments](/deployments): resultant ABI and info for deployments (each network will have a nested folder)
- [/lib](/lib): external modules used by Foundry
- [/scripts](/scripts): any utility scripts used for interacting with deployed contracts
- [/test](/test): tests suits to validate contracts
- [/ui](/ui): a web application to interact with deployed contracts
You can see breakdowns of other folders in the README within those folders.
And after running it locally some folders may be generated:
### Contracts
- `/artifacts`: ABIs and build info generated by Hardhat
- `/cache`: cache info used by Hardhat
- `/forge-cache`: cache info used by Foundry
- `/node_modules`: all dependencies for the Node.js environment
- `/out`: resultant ABIs for all contracts that has interactions
Within the project is the contracts folder which houses the contracts, utils, tests and deployment scripts associated with the Solidity smart contracts. Check the [contracts readme](./contracts/README.md) for more info.
### 📄 Contracts
The contracts present in this project are based in [Solidity](https://github.com/ethereum/solidity) and it uses [Node.js](https://nodejs.org/) for running scripts and [yarn](https://yarnpkg.com/) to keep dependencies management.
> ⚠️ Before starting developing make sure you Solidity, Node.js and yarn correctly installed in your environment
Follow the steps:
1. Clone the repo, [check out how here](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository).
2. Install the dependencies:
```bash
$ yarn
```
3. Compile the contracts to make sure everything is correct:
```bash
$ yarn compile
```
The output should looks like:
```bash
yarn run v1.22.19
$ hardhat compile
Compiled 14 Solidity files successfully.
Done in 0.98s.
```
4. Now you are able to make your code changes in the project. To help with Solidity, check [the language references](https://docs.soliditylang.org/).
### ✅ Testing Contracts
The project is covered with test suits (Foundry & Hardhat) that must pass to guarantee code integrity.
**HardHat tests**
All HardHat tests are located at [this directory](../test/).
1. Make sure that you have the dependencies installed:
```
$ yarn
```
2. Run:
```
$ yarn test:hardhat
```
The output should finish looking like:
```
...
33 passing (1s)
Done in 2.11s.
```
**Foundry tests**
All Forge tests are located at [this directory](../test/foundry/).
In order to run them, you need to have Forge by Foundry installed on your machine (check [this](https://book.getfoundry.sh/getting-started/installation.html) installation guide).
It is also required for you to have [forge-std](https://github.com/foundry-rs/forge-std/tree/cd7d533f9a0ee0ec02ad81e0a8f262bc4203c653) in your `./lib/` directory. In case you don't have it yet, you can run:
```
$ git submodule update --init --recursive
```
After installing Foundry and its components, you can simply run in the root directory:
```
$ yarn test:foundry
```
It is going to execute all test cases that are described in the [/test/foundry](test/foundry/) directory. Your output should looks like:
```
Test result: ok. 36 passed; 0 failed; finished in 4.06ms
Done in 0.58s.
```
### Running Both Test Environments
Alternatively, you can run both test environments by executing:
```
$ yarn test
```
> ⚠️ Please make sure to update tests as appropriate before pushing code
### 🚀 Deployment
This guide contains instructions to deploy the contract on three networks. If the execution is successful, you will see the contract address on your screen at the end of the instructions.
#### **Hardhat Local Network**
HardHat offers a local testnet environment that allows users and testers to deploy and interact with contracts without the need to contact external APIs and endpoints.
To start your local HardHat network, you need to run a node first. It is important to not terminate the command before proceeding with the instructions:
```
$ yarn node:hardhat
```
To deploy the contract on the HardHat network, execute:
```
$ yarn deploy:hardhat
```
If the execution is successful, you will see the contract address on your screen.
#### **Polygon Mumbai Testnet**
To deploy the contract on the testnet, you have to first export your wallet's private key and update the `.env.example` file at the root directory of this repository.
The [.env.example](./.env.example) file needs to be renamed to `.env` before continuing. Make sure you are using your private API URL, if you have one.
After updating the `.env` file, you can run:
```
$ yarn deploy:mumbai
```
to deploy the contract on the testnet. Please note that your wallet needs to hold enough Mumbai MATIC for the deployment to be successful. To reach more in-depth information about how to deploy contract checkout [this guide](https://wiki.polygon.technology/docs/develop/alchemy).
<!-- TODO: add this section after the mainnet setup is done and tested
**Polygon main-net**
To deploy the contract on the testnet, you have to first export your wallet's private key and update the `.env.example` file at the root directory of this repository.
The [.env.example](./.env.example) file needs to be renamed to `.env` before continuing. Make sure you are using your private API URL, if you have one.
After updating the `.env` file, you can run:
```
yarn deploy:mainnet
```
to deploy the contract on the testnet. Please note that your wallet needs to hold enough Mumbai MATIC for the deployment to be successful.
-->
### ▶️ Interaction scripts
Right away, in the [/scripts](/scripts/) folder you are able to see some scripts that will help you to interact with deployed contracts. By default you are able to select `localhost`, `hardhat` or `mumbai` network name predefined on [hardhat.config.ts](/hardhat.config.ts). The scripts will be using the deployment information stored in the [/deployments](/deployments/) folder. You should have a nested folder for each of the networks you have deployed it. The scripts needs be run using the Hardhat environment following the pattern:
```bash
# Replace <script_name> with the selected script
# Replace <network_name> with the selected network
$ npx hardhat run scripts/<script_name>.js --network <network_name>
```
> 💡You are able to see and change the arguments for each script at the top of each file
<!-- TODO: add the commands here when they are done
### Admin commands
The project should provide a way for interacting with the contract as owner with CLI.
> 🛠️ Work in progress...
-->
### 🖥️ User Interface
Within the project is included a [React](https://reactjs.org/) web application to expose and test the interaction with deployed scripts. Check the [UI readme](/ui/README.md) for more info
Within the project is included a [React](https://reactjs.org/) web application to expose and test the interaction with deployed scripts. Check the [UI readme](./ui/README.md) for more info.
### Subgraph
In order to index data offchain, we use TheGraph and this section is the code required for our subgraph. Check the [subgraph readme](./subgraph/README.md) for more info.
### 💅 Code Styling
@ -235,13 +62,12 @@ Later on, when the initiative prove its value, a service will be added to Fleek'
## 💡 Proof of concept
The proof of concept is being a work in progress and you can reach more information [here](https://github.com/fleekxyz/non-fungible-apps/wiki/%F0%9F%92%A1-Proof-of-Concept).
The proof of concept was concluded last year and you can reach more information [here](https://github.com/fleekxyz/non-fungible-apps/wiki/%F0%9F%92%A1-Proof-of-Concept).
## 📚 Dependency Highlights
We use the following libraries to develop Fleek Non Fungible Apps
- [Chakra](https://chakra-ui.com/)
- [Eslint](https://eslint.org/) + [Prettier](https://prettier.io/)
- [Ethers](https://docs.ethers.io/v5/)
- [Foundry](https://book.getfoundry.sh/)

11
contracts/.gitignore vendored Normal file
View File

@ -0,0 +1,11 @@
# hardhat
cache
artifacts
deployments/hardhat
# Foundry
out
forge-cache
# OpenZeppelin
.openzeppelin/unknown-*.json

18
contracts/.prettierrc Normal file
View File

@ -0,0 +1,18 @@
{
"semi": true,
"useTabs": false,
"tabWidth": 2,
"singleQuote": true,
"endOfLine": "lf",
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 120,
"tabWidth": 4,
"singleQuote": false,
"bracketSpacing": false
}
}
]
}

191
contracts/README.md Normal file
View File

@ -0,0 +1,191 @@
# NFA - Contracts
## Folder Structure
Inside contracts you are going to find:
- [contracts](./contracts): all the developed contracts
- [deployments](./deployments): resultant ABI and info for deployments (each network will have a nested folder)
- [lib](./lib): external modules used by Foundry
- [scripts](./scripts): any utility scripts used for interacting with deployed contracts
- [test](./test): tests suits to validate contracts
And after running it locally some folders may be generated:
- `artifacts`: ABIs and build info generated by Hardhat
- `cache`: cache info used by Hardhat
- `forge-cache`: cache info used by Foundry
- `node_modules`: all dependencies for the Node.js environment
- `out`: resultant ABIs for all contracts that has interactions
## Building
The contracts present in this project are based in [Solidity](https://github.com/ethereum/solidity) and it uses [Node.js](https://nodejs.org/) for running scripts and [yarn](https://yarnpkg.com/) to keep dependencies management.
> ⚠️ Before starting developing make sure you Solidity, Node.js and yarn correctly installed in your environment
Also, make sure you run `yarn` at the root directory to get some required tools. The rest of these steps assume you are in the [contracts folder](./).
Follow the steps:
1. Clone the repo, [check out how here](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository).
2. Install dependencies:
```bash
$ yarn
```
3. Compile the contracts to make sure everything is correct:
```bash
$ yarn compile
```
The output should looks like:
```bash
yarn run v1.22.19
$ hardhat compile
Compiled 14 Solidity files successfully.
Done in 0.98s.
```
4. Now you are able to make your code changes in the project. To help with Solidity, check [the language references](https://docs.soliditylang.org/).
## ✅ Testing
The project is covered with test suits (Foundry & Hardhat) that must pass to guarantee code integrity.
### HardHat Tests
All HardHat tests are located at [this directory](./test).
1. Make sure that you have the dependencies installed:
```
$ yarn
```
2. Run:
```
$ yarn test:hardhat
```
The output should finish looking like:
```
...
33 passing (1s)
Done in 2.11s.
```
### Foundry tests
All Forge tests are located at [this directory](./test/foundry).
In order to run them, you need to have Forge by Foundry installed on your machine (check [this](https://book.getfoundry.sh/getting-started/installation.html) installation guide).
It is also required for you to have [forge-std](https://github.com/foundry-rs/forge-std/tree/cd7d533f9a0ee0ec02ad81e0a8f262bc4203c653) in your `./lib/` directory. In case you don't have it yet, you can run:
```
$ git submodule update --init --recursive
```
After installing Foundry and its components, you can simply run in the root directory:
```
$ yarn test:foundry
```
It is going to execute all test cases that are described in the [test/foundry](./test/foundry/) directory. Your output should looks like:
```
Test result: ok. 36 passed; 0 failed; finished in 4.06ms
Done in 0.58s.
```
## Running Both Test Environments
Alternatively, you can run both test environments by executing:
```
$ yarn test
```
> ⚠️ Please make sure to update tests as appropriate before pushing code
## 🚀 Deployment
This guide contains instructions to deploy the contract on three networks. If the execution is successful, you will see the contract address on your screen at the end of the instructions.
### **Hardhat Local Network**
HardHat offers a local testnet environment that allows users and testers to deploy and interact with contracts without the need to contact external APIs and endpoints.
To start your local HardHat network, you need to run a node first. It is important to not terminate the command before proceeding with the instructions:
```
$ yarn node:hardhat
```
To deploy the contract on the HardHat network, execute:
```
$ yarn deploy:hardhat
```
If the execution is successful, you will see the contract address on your screen.
### **Polygon Mumbai Testnet**
To deploy the contract on the testnet, you have to first export your wallet's private key and update the `.env.example` file at the root directory of this repository.
The [.env.example](./.env.example) file needs to be renamed to `.env` before continuing. Make sure you are using your private API URL, if you have one.
After updating the `.env` file, you can run:
```
$ yarn deploy:mumbai
```
to deploy the contract on the testnet. Please note that your wallet needs to hold enough Mumbai MATIC for the deployment to be successful. To reach more in-depth information about how to deploy contract checkout [this guide](https://wiki.polygon.technology/docs/develop/alchemy).
<!-- TODO: add this section after the mainnet setup is done and tested
**Polygon main-net**
To deploy the contract on the testnet, you have to first export your wallet's private key and update the `.env.example` file at the root directory of this repository.
The [.env.example](./.env.example) file needs to be renamed to `.env` before continuing. Make sure you are using your private API URL, if you have one.
After updating the `.env` file, you can run:
```
yarn deploy:mainnet
```
to deploy the contract on the testnet. Please note that your wallet needs to hold enough Mumbai MATIC for the deployment to be successful.
-->
## ▶️ Interaction scripts
Right away, in the [scripts](./scripts/) folder you are able to see some scripts that will help you to interact with deployed contracts. By default you are able to select `localhost`, `hardhat` or `mumbai` network name predefined on [hardhat.config.ts](./hardhat.config.ts). The scripts will be using the deployment information stored in the [deployments](./deployments/) folder. You should have a nested folder for each of the networks you have deployed it. The scripts needs be run using the Hardhat environment following the pattern:
```bash
# Replace <script_name> with the selected script
# Replace <network_name> with the selected network
$ npx hardhat run scripts/<script_name>.js --network <network_name>
```
> 💡You are able to see and change the arguments for each script at the top of each file
<!-- TODO: add the commands here when they are done
### Admin commands
The project should provide a way for interacting with the contract as owner with CLI.
> 🛠️ Work in progress...
-->

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

Before

Width:  |  Height:  |  Size: 480 B

After

Width:  |  Height:  |  Size: 480 B

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Before

Width:  |  Height:  |  Size: 362 KiB

After

Width:  |  Height:  |  Size: 362 KiB

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

54
contracts/package.json Normal file
View File

@ -0,0 +1,54 @@
{
"name": "@fleekxyz/nfa-contracts",
"version": "0.0.1",
"description": "",
"private": "false",
"scripts": {
"test": "hardhat test && forge test --via-ir",
"test:foundry": "forge test --via-ir",
"test:hardhat": "hardhat test",
"format": "prettier --write \"./**/*.{js,json,sol,ts}\"",
"node:hardhat": "hardhat node",
"deploy:hardhat": "hardhat run scripts/deploy.js --network hardhat",
"deploy:mumbai": "hardhat run scripts/deploy.js --network mumbai",
"compile": "hardhat compile",
"verify:mumbai": "npx hardhat run ./scripts/verify-polyscan.js --network mumbai"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fleekxyz/non-fungible-apps.git"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/fleekxyz/non-fungible-apps/issues"
},
"homepage": "https://github.com/fleekxyz/non-fungible-apps#readme",
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^1.0.5",
"@nomicfoundation/hardhat-network-helpers": "^1.0.7",
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
"@nomiclabs/hardhat-ethers": "^2.2.1",
"@nomiclabs/hardhat-etherscan": "^3.1.0",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@openzeppelin/contracts": "^4.7.3",
"@openzeppelin/contracts-upgradeable": "^4.8.0",
"@openzeppelin/hardhat-upgrades": "^1.22.0",
"@types/mocha": "^10.0.1",
"chai": "^4.3.6",
"colorthief": "^2.3.2",
"dotenv": "^16.0.2",
"ethers": "^5.7.2",
"hardhat": "^2.11.2",
"hardhat-contract-sizer": "^2.6.1",
"hardhat-gas-reporter": "^1.0.9",
"lint-staged": "^13.0.4",
"prettier": "^2.7.1",
"prettier-plugin-solidity": "^1.0.0",
"sharp": "^0.31.3",
"solidity-coverage": "^0.8.2",
"ts-node": "^10.9.1",
"typescript": "^4.9.3",
"web3": "^1.8.1"
}
}

6644
contracts/yarn.lock Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4,18 +4,10 @@
"description": "",
"private": "false",
"scripts": {
"test": "hardhat test && forge test --via-ir",
"test:foundry": "forge test --via-ir",
"test:hardhat": "hardhat test",
"format": "prettier --write \"./**/*.{js,json,sol,ts}\"",
"node:hardhat": "hardhat node",
"deploy:hardhat": "hardhat run scripts/deploy.js --network hardhat",
"deploy:mumbai": "hardhat run scripts/deploy.js --network mumbai",
"compile": "hardhat compile",
"postinstall": "husky install",
"prepack": "pinst --disable",
"postpack": "pinst --enable",
"verify:mumbai": "npx hardhat run ./scripts/verify-polyscan.js --network mumbai"
"postpack": "pinst --enable"
},
"repository": {
"type": "git",
@ -29,32 +21,9 @@
"homepage": "https://github.com/fleekxyz/non-fungible-apps#readme",
"devDependencies": {
"@graphql-codegen/cli": "^2.16.4",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.5",
"@nomicfoundation/hardhat-network-helpers": "^1.0.7",
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
"@nomiclabs/hardhat-ethers": "^2.2.1",
"@nomiclabs/hardhat-etherscan": "^3.1.0",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@openzeppelin/contracts": "^4.7.3",
"@openzeppelin/contracts-upgradeable": "^4.8.0",
"@openzeppelin/hardhat-upgrades": "^1.22.0",
"@types/mocha": "^10.0.1",
"chai": "^4.3.6",
"colorthief": "^2.3.2",
"dotenv": "^16.0.2",
"ethers": "^5.7.2",
"hardhat": "^2.11.2",
"hardhat-contract-sizer": "^2.6.1",
"hardhat-gas-reporter": "^1.0.9",
"husky": "^8.0.2",
"lint-staged": "^13.0.4",
"pinst": "^3.0.0",
"prettier": "^2.7.1",
"prettier-plugin-solidity": "^1.0.0",
"sharp": "^0.31.3",
"solidity-coverage": "^0.8.2",
"ts-node": "^10.9.1",
"typescript": "^4.9.3",
"web3": "^1.8.1"
"prettier-plugin-solidity": "^1.0.0"
}
}

5
subgraph/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
*.wasm
build
generated
abis
examples/query/.graphclient

5805
yarn.lock

File diff suppressed because it is too large Load Diff