This repository contains the Uniswap V4 hook contracts built by M0 Labs for the M0 project.
This hook restricts both liquidity provision and token swaps to a specific tick range, bounded by lower and upper tick values.
This feature is particularly useful for stable pairs that want to prevent their pool's liquidity from becoming unbalanced.
BaseTickRangeHook is an abstract contract that other hooks can inherit from to restrict swaps and liquidity provision.
It inherits from OpenZeppelin’s AccessControl and allows an admin to manage one role:
- manager role - address that manages the hook and sets the different parameters
The deployer sets the tick range during deployment, and the hook manager can modify it at any time.
Liquidity providers can only add liquidity between the lower and upper tick values.
Liquidity providers may be unable to add liquidity to their positions if the tick range has been updated since they first created their position. They are able to remove their liquidity at any time, even if not inside the current tick range.
The contract maintains two separate allowlists—one for swappers and one for liquidity providers—to restrict which addresses can interact with the pool.
It also inherits from the Tick Range hook contract to restrict liquidity provision within a specific tick range.
Predicate is used to perform ongoing compliance checks for addresses on the swappers allowlist.
Inherits from the BaseTickRangeHook abstract contract and its functionalities.
Inherits from the PredicateClient to perform Predicate checks when swapping.
Both allowlists and the Predicate check are enabled by default upon deployment and can be disabled later by the hook manager.
You may have to install the following tools to use this repository:
- Foundry to compile and test contracts
- lcov to generate the code coverage report
- slither to static analyze contracts
Install dependencies:
npm i
Copy .env
and write down the env variables needed to run this project.
cp .env.example .env
Run the following command to compile the contracts:
npm run compile
Forge is used for coverage, run it with:
npm run coverage
You can then consult the report by opening coverage/index.html
:
open coverage/index.html
To run all tests:
npm test
Run test that matches a test contract:
forge test --mc <test-contract-name>
Test a specific test case:
forge test --mt <test-case-name>
To run slither:
npm run slither
Husky is used to run lint-staged and tests when committing.
Prettier is used to format code. Use it by running:
npm run prettier
Solhint is used to lint Solidity files. Run it with:
npm run solhint
To fix solhint errors, run:
npm run solhint-fix
The following Github Actions workflow are setup to run on push and pull requests:
It will build the contracts and run the test coverage, as well as a gas report.
The coverage report will be displayed in the PR by github-actions-report-lcov and the gas report by foundry-gas-diff.
For the workflows to work, you will need to setup the MNEMONIC_FOR_TESTS
and MAINNET_RPC_URL
repository secrets in the settings of your Github repository.
Some additional workflows are available if you wish to add fuzz, integration and invariant tests:
- .github/workflows/test-fuzz.yml
- .github/workflows/test-integration.yml
- .github/workflows/test-invariant.yml
You will need to uncomment them to activate them.
The documentation can be generated by running:
npm run doc
It will run a server on port 4000, you can then access the documentation by opening http://localhost:4000.
To compile the contracts for production, run:
npm run build
Open a new terminal window and run anvil to start a local chain:
anvil --fork-url <MAINNET_RPC_URL> --chain-id 31337
Use one of the following commands to deploy the different hooks and pools to the local chain:
npm run deploy-allowlist-hook-local
npm run deploy-allowlist-hook-and-pool-local
npm run deploy-tick-range-hook-local
npm run deploy-tick-range-hook-and-pool-local
To deploy the Allowlist Hook and Pool to Ethereum Mainnet, run:
npm run deploy-allowlist-hook-and-pool-ethereum
Run the following command to create a liquidity position:
npm run create-liquidity-position-local
Run the following command to create a liquidity position:
npm run create-liquidity-position-ethereum
Network | Hook Name | Hook Address | Pool |
---|---|---|---|
Ethereum Mainnet | Allowlist Hook | 0xAf53Cb78035A8E0acCe38441793E2648B15B88a0 | wM/USDC - 0% fee |
Ethereum Mainnet | TickRange Hook | 0xDe400595199E6Dae55a1bcb742B3Eb249AF00800 | USDC/mUSD - 0% fee |