Skip to content

A lightning-fast Foundry template for Solidity smart contract development

License

Notifications You must be signed in to change notification settings

hifi-finance/foundry-template

Repository files navigation

Foundry Template Github Actions Foundry pre-commit License: MIT

Overview

A lightning-fast Foundry template for Solidity smart contract development.

What's Inside

  • Forge: compile, test, fuzz, debug and deploy smart contracts
  • Forge Std: collection of helpful contracts and cheatcodes for testing

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:

forge init my-project --template https://github.com/hifi-finance/foundry-template
cd my-project
make

This project was built using Foundry. Refer to installation instructions here.

Features

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

For example, for Foundry, you can refer to the Foundry Book. You might be in particular interested in reading the Writing Tests guide.

Sensible Defaults

This template comes with sensible default configurations in the following files:

├── .commitlintrc.yaml
├── .gitattributes
├── .gitignore
├── .gitmodules
├── .pre-commit-config.yaml
├── foundry.toml
├── makefile
└── remappings.txt

VSCode Integration

This template is IDE agnostic, but for the best user experience, you may want to use it in VSCode with Juan Blanco'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.

Conventional Commits

This template enforces the Conventional Commits standard for git commit messages. This is a lightweight convention that creates an explicit commit history, which makes it easier to write automated tools on top of.

Writing Tests

To write a new test contract, you start by importing DSTest and inherit from it in your test contract. DSTest comes with a pre-instantiated cheatcodes environment accessible via the vm property. You can also use console.log, whose logs you can see in the terminal output by adding the -vvvv flag.

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

Commands

To make it easier to perform some tasks within the repo, a few commands are available through a makefile:

Build Commands

Command Action
make build Compile all contracts in the repo, including submodules.
make clean Delete the build artifacts and cache directories.
make fmt-check Lint the contracts.
make fmt-write Format the contracts.

Test Commands

Command Description
make coverage Get a test coverage report.
make test Run all tests located in tests/.
make gas-report Get a gas report.

Specific tests can be run using forge test conventions, specified in more detail in the Foundry Book.

Deploy Commands

Command Description
make deploy Deploy to Anvil.

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

Notes

  1. Foundry piggybacks off git submodules to manage dependencies. There's a guide about how to work with dependencies 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 mainnet fork.

Related Efforts

License

MIT © Mainframe Group Inc.