Foundry-based template for developing Solidity smart contracts used by Vac
Go to file
Ricardo Guilherme Schmidt 96e97ba0e2 chore: add preparation commit command `pnpm adorno` 2024-03-01 10:35:39 +01:00
.github chore: add preparation commit command `pnpm adorno` 2024-03-01 10:35:39 +01:00
.vscode chore: mark "lib" as vendored code 2023-04-07 22:08:31 +03:00
certora feat: add certora CI integration (#10) 2023-11-23 08:52:05 +01:00
lib chore: first template adjustments 2023-08-09 10:14:12 +02:00
script refactor: move deployer assignment to the top (#9) 2023-09-26 16:35:42 +02:00
src build: bump "prb-test" 2023-03-04 12:37:52 +02:00
test feat: add `DeploymentConfig` for network specifc deployments (#5) 2023-09-07 10:21:11 +02:00
.editorconfig chore: fix indenting for *.sol in .editorconfig 2022-09-15 00:57:35 +02:00
.env.example feat: add FOUNDRY_PROFILE env var 2023-07-07 12:32:52 +03:00
.gas-report chore: add gas-report (#18) 2024-02-26 14:09:11 +01:00
.gas-snapshot chore: first template adjustments 2023-08-09 10:14:12 +02:00
.gitattributes chore(.gitattributes): add eol settings to enforce `lf` 2024-02-29 15:36:26 +01:00
.gitignore feat: add certora CI integration (#10) 2023-11-23 08:52:05 +01:00
.gitmodules chore: first template adjustments 2023-08-09 10:14:12 +02:00
.prettierignore Revert "chore: don't prettier ignore slither config" 2023-09-09 13:25:14 +02:00
.prettierrc.yml chore: remove Prettier overrides for "*.sol" 2023-03-13 17:58:43 +02:00
.solhint.json build: upgrade to Solidity v0.8.19 2023-02-25 12:40:42 +02:00
CHANGELOG.md feat: add `release` command to cut releases 2024-02-28 08:02:51 +01:00
LICENSE.md chore: update copyright year in license 2023-01-01 13:26:12 +02:00
PROPERTIES.md chore: add PROPERTIES.md (#2) 2023-08-09 11:38:21 +02:00
README.md docs: add missing docs about fixing linting errors (#7) 2023-09-08 21:42:27 +02:00
codecov.yml build: add codecov task to CI actions (#6) 2023-09-08 18:15:36 +02:00
foundry.toml fix(config): replace `arbitrum_one` -> `arbitrum` (#11) 2023-12-21 08:59:43 +01:00
package.json chore: add preparation commit command `pnpm adorno` 2024-03-01 10:35:39 +01:00
pnpm-lock.yaml feat: add `release` command to cut releases 2024-02-28 08:02:51 +01:00
remappings.txt chore: first template adjustments 2023-08-09 10:14:12 +02:00
slither.config.json chore: add slither config (#4) 2023-09-07 10:25:03 +02:00

README.md

Foundry Template Github Actions Foundry License: MIT

A Foundry-based template for developing Solidity smart contracts, with sensible defaults.

This is a fork of PaulRBerg's template and adjusted to Vac's smart contracts unit's needs. See Upstream differences to learn more about how this template differs from Paul's.

What's Inside

  • Forge: compile, test, fuzz, format, and deploy smart contracts
  • Forge Std: collection of helpful contracts and cheatcodes for testing
  • Solhint Community: linter for Solidity code

Getting Started

Click the Use this template button at the top of the page to create a new repository with this repo as the initial state.

Or, if you prefer to install the template manually:

$ mkdir my-project
$ cd my-project
$ forge init --template vacp2p/foundry-template
$ pnpm install # install Solhint, Prettier, and other Node.js deps

If this is your first time with Foundry, check out the installation instructions.

Features

This template builds upon the frameworks and libraries mentioned above, so for details about their specific features, please consult their respective documentation.

For example, if you're interested in exploring Foundry in more detail, you should look at the Foundry Book. In particular, you may be interested in reading the Writing Tests tutorial.

Upstream differences

As mentioned above, this template is a fork with adjustments specific to the needs of Vac's smart contract service unit. These differences are:

  • Removal of PRBTest - In an attempt to keep dependence on third-party code low, we've decided to remove this library as a standard dependency of every project within Vac. If we do see a need for it, we might bring it back in the future.
  • PROPERTIES.md - For invariant testing and formal verification, we've introduced a PROPERTIES.md to document all protocol properties that must hold true.

Sensible Defaults

This template comes with a set of sensible default configurations for you to use. These defaults can be found in the following files:

├── .editorconfig
├── .gitignore
├── .prettierignore
├── .prettierrc.yml
├── .solhint.json
├── foundry.toml
├── remappings.txt
└── slither.config.json

VSCode Integration

This template is IDE agnostic, but for the best user experience, you may want to use it in VSCode alongside Nomic Foundation's Solidity extension.

For guidance on how to integrate a Foundry project in VSCode, please refer to this guide.

GitHub Actions

This template comes with GitHub Actions pre-configured. Your contracts will be linted and tested on every push and pull request made to the main branch.

You can edit the CI script in .github/workflows/ci.yml.

Writing Tests

If you would like to view the logs in the terminal output you can add the -vvv flag and use console.log.

This template comes with an example test contract Foo.t.sol

Usage

This is a list of the most frequently needed commands.

Build

Build the contracts:

$ forge build

Clean

Delete the build artifacts and cache directories:

$ forge clean

Compile

Compile the contracts:

$ forge build

Coverage

Get a test coverage report:

$ forge coverage

Deploy

Deploy to Anvil:

$ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545

For this script to work, you need to have a MNEMONIC environment variable set to a valid BIP39 mnemonic.

For instructions on how to deploy to a testnet or mainnet, check out the Solidity Scripting tutorial.

Format

Format the contracts:

$ forge fmt

Gas Usage

Get a gas report:

$ forge test --gas-report

Lint

Lint the contracts:

$ pnpm lint

Fixing linting issues

For any errors in solidity files, run forge fmt. For errors in any other file type, run pnpm prettier:write.

Test

Run the tests:

$ forge test

Notes

  1. Foundry uses git submodules to manage dependencies. For detailed instructions on working with dependencies, please refer to the guide in the book
  2. You don't have to create a .env file, but filling in the environment variables may be useful when debugging and testing against a fork.

License

This project is licensed under MIT.