Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

m0-foundation/uniswap-v4-hooks

Open more actions menu

Repository files navigation

Uniswap V4 Hooks

This repository contains the Uniswap V4 hook contracts built by M0 Labs for the M0 project.

Hooks

Tick Range hook

Overview

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.

Architecture

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.

Allowlist hook

Overview

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.

Architecture

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.

Development

Installation

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

Env

Copy .env and write down the env variables needed to run this project.

cp .env.example .env

Compile

Run the following command to compile the contracts:

npm run compile

Coverage

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

Test

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

Code quality

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

CI

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:

You will need to uncomment them to activate them.

Documentation

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.

Deployment

Build

To compile the contracts for production, run:

npm run build

Deploy

Local

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

Ethereum

To deploy the Allowlist Hook and Pool to Ethereum Mainnet, run:

npm run deploy-allowlist-hook-and-pool-ethereum

Manage Uniswap Pool

Local

Run the following command to create a liquidity position:

npm run create-liquidity-position-local

Ethereum

Run the following command to create a liquidity position:

npm run create-liquidity-position-ethereum

Deployments

Network Hook Name Hook Address Pool
Ethereum Mainnet Allowlist Hook 0xAf53Cb78035A8E0acCe38441793E2648B15B88a0 wM/USDC - 0% fee
Ethereum Mainnet TickRange Hook 0xDe400595199E6Dae55a1bcb742B3Eb249AF00800 USDC/mUSD - 0% fee

About

Repository regrouping all Uniswap V4 hooks of the M0 project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  
Morty Proxy This is a proxified and sanitized view of the page, visit original site.