non-fungible-apps/contracts
Felipe Mendes b8b8cb28ea
feature: conditional payment as setting (#134)
* feat: add base contract for billing

* feat: add withdraw function

* feat: add billing requirement to mint

* test: add foundry tests for minting with billing

* refactor: remove transfer billing and add access point

* test: add access point billing foundry tests

* test: add test for billing value change

* test: add hardhat test setup for billing

* test: add hardhat tests for billing

* feat: add withdrawn event and add public withdraw function

* test: add tests for withdrawing founds and access control for billing

* refactor: fix misspells and change variable names

* feat: add initialize params for billing

* feat: add gap to FleekBilling

* fix: testname misspell
2023-02-27 17:30:19 -03:00
..
.openzeppelin feat: subgraph reverse lookup (gitRepo -> NFA) (#131) 2023-02-24 16:22:18 +03:30
assets chore: change top level folder structure (#105) 2023-02-06 15:15:44 -05:00
contracts feature: conditional payment as setting (#134) 2023-02-27 17:30:19 -03:00
deployments/mumbai feat: subgraph reverse lookup (gitRepo -> NFA) (#131) 2023-02-24 16:22:18 +03:30
lib chore: change top level folder structure (#105) 2023-02-06 15:15:44 -05:00
scripts feature: conditional payment as setting (#134) 2023-02-27 17:30:19 -03:00
test feature: conditional payment as setting (#134) 2023-02-27 17:30:19 -03:00
.env.example chore: change top level folder structure (#105) 2023-02-06 15:15:44 -05:00
.gitignore chore: change top level folder structure (#105) 2023-02-06 15:15:44 -05:00
.prettierrc chore: change top level folder structure (#105) 2023-02-06 15:15:44 -05:00
README.md chore: change top level folder structure (#105) 2023-02-06 15:15:44 -05:00
foundry.toml chore: change top level folder structure (#105) 2023-02-06 15:15:44 -05:00
hardhat.config.ts chore: change top level folder structure (#105) 2023-02-06 15:15:44 -05:00
package.json test: improve foundry test with best practices (#102) 2023-02-08 17:27:39 -03:00
remappings.txt chore: change top level folder structure (#105) 2023-02-06 15:15:44 -05:00
yarn.lock chore: change top level folder structure (#105) 2023-02-06 15:15:44 -05:00

README.md

NFA - Contracts

Folder Structure

Inside contracts you are going to find:

  • contracts: all the developed contracts
  • deployments: resultant ABI and info for deployments (each network will have a nested folder)
  • lib: external modules used by Foundry
  • scripts: any utility scripts used for interacting with deployed contracts
  • 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 and it uses Node.js for running scripts and yarn 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.

  2. Install dependencies:

    $ yarn
    
  3. Compile the contracts to make sure everything is correct:

    $ yarn compile
    

    The output should looks like:

    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.

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.

  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.

In order to run them, you need to have Forge by Foundry installed on your machine (check this installation guide).

It is also required for you to have forge-std 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 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 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.

▶️ Interaction scripts

Right away, in the 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. The scripts will be using the deployment information stored in the 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:

# 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