VitaDAO / staking-contract

MIT License
0 stars 0 forks source link

Template Foundry Project

This is my go to template when I'm starting a new project.

Template Solidity Project vs Template Foundry Project

If you used Template Solidity Project before here what changed

Dependencies

Installation

  1. Follow the Foundry's installation guide

  2. forge install

Then use the command make tests to be sure everything is good to go

Folder Strucutre


.

├── deployment -> All Deployed Contracts

├── lib -> All Forge install libraries

├── script -> Deploy logic script

│ ├── config -> Config for each of your contracts

│ ├── contract -> Contract Deployment logic

│ └── utils -> Utilities used by the Template

├── src -> Your Contracts

└── test -> Your Tests

Coverage

If you want to fully use it, install

Then when you run make coverage-output, it will generate a file that Coverage Gutter will read. Go to your contract's code and use the vscode command >Coverage Gutters: Display Coverage

You will see in red the code that isn't being tested by your tests.

How to deploy

Easy way

Use ./deploy.sh. It uses foundry.toml [rpc_endpoints] and .env

Manual way

deploy :; export IS_SIMULATION=false && $(FORGE_CLEAN) && forge script $(FILEPATH) \
--rpc-url $(RPC) --sig "run()" --broadcast --verify -vvvv $(EXTRA)

IS_SIMULATION = Right now we don't have any variable to know if it's simulate-deploy, at least I didn't find it. So I use this env variable so we don't save the deployed contracts during this simulation.

SCRIPT_NAME = The script contract's name of your deployment file script. e.g: src/script/contract/HelloWorld.s.sol, the contract name is HelloWorldScript

RPC = Your RPC

NETWORK = Name of the network. This is purely for you, it doesn't need to have the same name as the actual network. It is used for your configs & naming the deployment output.

Example

make deploy SCRIPT_NAME="HelloWorldScript" /
RPC="${SEPOLIA_ARBITRUM_TESTNET}" NETWORK="arbitrumTestnet"

Note: Be sure you prepare your output file. let say you want to deploy on a network called LocalHost, you have to create the output file /deployment/LocalHost.json first

How to simulate / test a deployment

Same as the above, but with simulate-deploy

simulate-deploy :; export IS_SIMULATION=true && forge script $(SCRIPT_NAME) \
--rpc-url $(RPC) --sig "run()" -vvvv $(EXTRA)

Commands script

I'm using

MakeFile

for the commands.

e.g: make tests

e.g (with args): make tests EXTRA='-vvv --match-contract HelloWorldTest'

Recommendations

Resources

Contributions

Feel free to contribute on this template. The PR / your code needs to follow this standard

License

MIT