Uniswap v4 custom pool template for Foundry based on foundry-template.
Full blog post with more details about Uniswap 4 and hooks available at https://soliditydeveloper.com/uniswap4.
An example for the flow of hooks is shown below:
![image](https://private-user-images.githubusercontent.com/659390/250261674-bdce944f-f085-4dc9-b8df-c1cd1811d795.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwNDk3MDQsIm5iZiI6MTcyNDA0OTQwNCwicGF0aCI6Ii82NTkzOTAvMjUwMjYxNjc0LWJkY2U5NDRmLWYwODUtNGRjOS1iOGRmLWMxY2QxODExZDc5NS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODE5JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgxOVQwNjM2NDRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT05MDlkNjQ0ZGY1ZDgwNTM4MTI1OTBhODI1MWEwZTI4ZTdjNTE0ODViMzQyMWM0MzZmZTM2YWY2YjJiYzRmOTcwJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.BlwWSgrnvzoG-o_WbUzO8nov7RIrrkaRYOPe1KAHwjs)
The flags for which hooks will be executed depends the leading bits on the Hooks address:
- Uniswap v4: Examples showing how to create custom hooks for Uniswap v4
- Foundry-Template: Foundry-based template for developing Solidity smart contracts by Paul Berg
- Forge: compile, test, fuzz, format, and deploy smart contracts
- Forge Std: collection of helpful contracts and cheat codes for testing
- PRBTest: modern collection of testing assertions and logging utilities
- Prettier: code formatter for non-Solidity files
- Solhint Community: linter for Solidity code
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/soliditylabs/uniswap-v4-custom-pool
cd my-project
pnpm install # install Solhint, Prettier, and other Node.js deps
If this is your first time with Foundry, check out the installation instructions.
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.
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
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.
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.
To write a new test contract, you start by importing PRBTest and inherit from
it in your test contract. PRBTest comes with a pre-instantiated cheatcodes
environment accessible via the vm
property. 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
This is a list of the most frequently needed commands.
Build the contracts:
$ forge build
Delete the build artifacts and cache directories:
$ forge clean
Compile the contracts:
$ forge build
Get a test coverage report:
$ forge coverage
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 the contracts:
$ forge fmt
Get a gas report:
$ forge test --gas-report
Lint the contracts:
$ pnpm lint
Run the tests:
$ forge test
- Foundry uses git submodules to manage dependencies. For detailed instructions on working with dependencies, please refer to the guide in the book
- 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.
- abigger87/femplate
- cleanunicorn/ethereum-smartcontract-template
- foundry-rs/forge-template
- FrankieIsLost/forge-template
This project is licensed under MIT.