A curated list of awesome Uniswap v4 hooks resources.
Special thanks to Uniswap Foundation for including this resource in the official doc and mentioning this work in the blog!
Uniswap v4 Hooks -- also known simply as hooks -- are specially designed contracts that run at distinct points throughout a pool action's lifecycle. They serve as plugins allowing developers to tailor how pools, swaps, fees, and LP positions interact. This enables innovation atop Uniswap v4's core features, thereby supporting the development of custom AMM pools.
These resources will help you get started with Uniswap v4 hooks.
- Uniswap's v4 Announcement: Official announcement article from Uniswap detailing their vision for v4, including the introduction of hooks.
- Uniswap v4 Developer Documents: Official V4 Developer Documents from Uniswap Foundation, covering topics including how developer would begin to start building out hooks on local testnets in order to start testing out hook designs.
- Core smart contracts of Uniswap v4: The core smart contracts of Uniswap v4, highlighting
v4-core
's singleton-style architecture, the management of all pool state inPoolManager.sol
, and use of hook contracts to implement callbacks in the lifecycle of pool actions. - Peripheral smart contracts for interacting with Uniswap v4:
v4-periphery
hosts the logic that builds on top of the core pool logic like hook contracts, position managers, and even possibly libraries needed for integrations. It is still under development and is being updated as the v4 ecosystem matures. Includes theBaseHook
contract that can be used as a base for creating custom hooks. - Draft Technical Whitepaper for Uniswap v4 Core: Covers an introduction to Uniswap v4, hooks, singleton and flash accounting, native ETH, and other notable features.
During the course of a pool action's lifecycle, a hook invokes custom logic primarily at four critical phases:
- Initialize: Activated when the pool is deployed.
- Modify Position: Used to add or remove liquidity.
- Swap: Engages a swap between tokens within the V4 ecosystem.
- Donate: Facilitates the donation of liquidity to a V4 pool. Upon initialization, a pool can be associated with a hook contract. Such a contract has the ability to execute any of the callback functions during the pool action's lifecycle:
{before,after}Initialize
{before,after}ModifyPosition
{before,after}Swap
{before,after}Donate
Moreover, hooks can determine fees on swaps and liquidity withdrawals through callback functions. The flexibility lies in updating the fee values or callback logic based on the hook's design. Nevertheless, the callbacks activated on a pool, including the fee type, remain constant post pool initialization.
Hooks foster creativity. Here are some interesting functionalities that could be implemented with hooks.
- Onchain limit orders that fill at tick prices
- Dynamic fees rooted in volatility or other determinants
- Channeling out-of-range liquidity into lending platforms
- Autocompounding LP fees reintegrated into the LP positions
- MEV profits being internally distributed back to liquidity providers
- A time-weighted average market maker TWAMM to execute large orders over time
- Creation of bespoke onchain oracles (i.e., median, truncated), like geomean oracles
A collection of hooks from Uniswap and community developers.
- Full Range: A hook that allows a Uniswap pool to provide liquidity for a range of prices. This can be used to create a market maker for a volatile asset or to provide more liquidity for a thin market.
- Geomean Oracle: A unique hook making a Uniswap pool function as an oracle. The geomean price is calculated using the prices of the assets in the pool. This can be used to get a more accurate price for an asset than a single oracle.
- Limit Order: A hook that allows users to place limit orders. This means that they can specify the price at which they are willing to buy or sell an asset. If the market price reaches the limit price, the order will be executed.
- TWAMM: A TWAMM (Time Weighted Average Market Maker) is a type of market maker that uses time-weighted averages to calculate the prices of assets. This can be used to reduce the volatility of the market and to provide more accurate prices for assets. See also Uniswap's research blog post on TWAMM.
- Volatility Oracle: A volatility oracle is a contract that provides information about the volatility of an asset. This information can be used to price options and other derivatives.
- Truncated Oracle: A truncated oracle is an onchain price oracle that records the price of an asset in a Uniswap liquidity pool using the geometric mean formula. See also Uniswap's research blog post on truncated oracles.
- Multi-Sig: Requires multiple signatures for certain pool actions, such as adding or removing liquidity. This can be used to add an extra layer of security to a pool.
- Whitelist: Restricts pool participation to a whitelist of approved addresses. This can be used to prevent certain people from participating in a pool, such as people who have been banned from the platform or people who are considered to be high-risk traders.
- Old Account: Allows only old accounts to use the pool. Old is subjective; it's the hook owner's job to define "old".
- KYC: Allows for Know Your Customer (KYC) checks to be performed on users before they are allowed to trade on a pool. This can be used to prevent fraud and ensure that only legitimate users are able to trade.
- New York Trading Hours: Reverts when markets are closed in New York. This can be used to prevent trading during certain times of the day, such as when the New York Stock Exchange is closed.
- Impermanent Loss Hedge (Antonio Furtado): A hook to hedge against impermanent loss. This can be used to protect liquidity providers from losing money due to price fluctuations.
- Stop Loss Order: Allows users to place stop loss orders on their positions. This means that the position will be automatically closed if the price reaches a certain level.
- Liquidity Provider Fee Rebate: Allows liquidity providers (LPs) to receive a rebate on the fees they pay when swapping tokens on a pool. This can be used to incentivize LPs to provide liquidity to the pool.
- On-Chain Take Profit Order: Allows users to place automatically executing on-chain "take-profit" orders. This means that the position will be automatically closed if the price reaches a certain level.
- Hyperlane LPTs: Automates LPTs on destination chains using Hyperlane in hooks. This can be used to provide liquidity to new tokens on new chains in a more efficient and secure way.
- Torres Token Sale: A Solidity ERC20 token using hooks to create a compliant token sale system following judge Torres ruling in the XRP case. This can be used to ensure that token sales are conducted in a fair and transparent way.
- NFT Owners Only: Disallows a swap if sender doesn't own an ERC721 NFT. This can be used to prevent people from selling tokens that they don't own.
- Curve Style Voting Escrow - veLP: A Curve-style voting escrow (ve) hook. This can be used to create a more democratic and efficient way to vote on changes to a liquidity pool.
- Huff Hooks: Allows developers to add custom functionality to pools. This can be used to create a variety of new features, such as limit orders or margin trading.
- Magna Carta: A hook for enforcing a verifiable sequencing rule. This can be used to prevent front-running and other types of manipulation.
- Uni LBP: A capital-efficient Uniswap v4 liquidity bootstrapping pool (LBP) hooks contract. This can be used to allow tokens to be sold at a linearly decreasing price.
- UniKits Hooks: A series of hooks and tools to enhance the functionality of Uniswap v4 Hooks. These can be used to provide v4 pools with basic functions such as auth to swap, and swap to share.
- Automated Buyback: A hook that enables protocols to implement automated token buybacks from their treasury when price drops below a target threshold in a Uniswap Pool. This enables automated price support during declines and volatility.
- Privacy Enhancing Hook: A hook for Uniswap v4 that combines the privacy features of Tornado Cash with the efficiency and verifiability of Merkle trees/ZK Snarks. This can enhance the privacy and security of Uniswap v4 pools by breaking the on-chain link between depositors and withdrawal addresses, while also providing a verifiable proof of inclusion.
- Minimize LVR Hook: A hook for implementing the POC of research idea on loss-versus-rebalancing. This can reduce LVR and increase LP returns.
- Bungi: An experimental Liquidity Position Manager for Uniswap v4. This can be an advanced LP router with more features than the baseline PoolModifyPositionTest.
- Captain Hooks: A series of Uniswap v4 custom hooks built with Scaffold ETH 2. This can be used for targeting traditional fiannce entities, offering custom pools with dynamic fee options and other functionnalities.
- Anti-KYC: A hook that bans KYC-ed users. This can be used to provide alternative liquidity pools for users who do not want to go through KYC.
- WID KYC: A hook that uses World ID to perform KYC checks. This can be used to provide specific liquidity pools for users who have registered on the World ID of World Coin.
- Volatility Fee Hook: A dynamic fee hook based on volatility to mitigate large impermanent losses on high volatility assets. This can be used to increases liquidity, which also benefits users.
- Ref Fee Hook: A hook that takes referral fees for swaps and liquidity adds (if specified). This can be used to incentivize users to refer others to the pool.
- Identity with Civic: A hook that allows traders with a Civic Pass. This can be used for KYC, compliance, sybil resistance and more.
- Locking Liquidity Hook: A hook that gives pool deployers a way to ensure consistent liquidity levels. This can let pool deployers create advanced features that are possible through locking liquidity. See also its design choices.
- Attestation Hook: A hook that allows for the querying of attestations from various attestation protocols. Check returned responses against preset criteria in any of the hook functions.
- Constant-sum Swap: A hook that implements constant-sum swaps (x + y = k), allowing for an exact 1:1 swap everytime.
- SUClave (source): A hook that controls initial swap access. This democratizes MEV and ensures equitable swap opportunities in liquidity pools.
- Toxic Fl-no (source): A dynamic fee hook, rewarding valuable participants in the ecosystem by adjusting Uniswap pool fees based on user behavior within a Suave contract, promoting equitability.
- Aggeragator Hook (source): A hook enables LPs in other DEXes to optimize their Uniswap V4 positions, streamlining liquidity management. It facilitates JIT activation for profitable ranges.
- Perks (source): A mobile app that redefines brand loyalty. Users earn rewards across various brands while token pools are shielded from market dumps via a Uniswap hook.
- Delegated Liquidity (source): Empowers token delegates to vote on governance proposals without missing out on providing liquidity.
- HOOK Finance (source) : A hook that enables perpetual trading as a Uniswap V4 Hook! An innovative way to introduce perpetual markets to V4.
- Protecc (source): Allows developers and builders to create liquidity pools that automatically leverage Spark Protocol's sDAI and SparkLend.
- Orderbook Hook (source): A Uniswap v4 hook blending the immediacy of AMM systems with the detail-oriented nature of orderbooks.
- MEVictim Rebate (source): Allows you to identify MEV victims using historical onchain data which then airdrops the victim a token to use in a Uniswap v4 gated pool on where they can get a rebate when providing liquidity.
- Fair Trade (source): A Uniswap v4 pool that launches tokens with safety guarantees for future token holders and traders. Designed to be a hook to be added to pools to protect against shit-coin ruggings.
- NFT Pool Party (source): Enables you to launch your NFT collection on Uniswap & earn ongoing income streams from royalties (again). Used v4 Hooks to create NFT IDOs and gave the power back to the creators to control their royalties.
- ReCentFi (source): An AI-powered platform to reward eco-friendly action. Users pick up trash, upload videos for verification, and gain exclusive access to βcleanβ Uniswap pools with verification gated hooks added to them.
- 0xY (source): Borrowing protocol offering put-protected term loans that protect against price liquidation. A Uniswap V4 pool implements custom hooks that lends to the protocol whenever the price moves out of range for a user's LP.
- Axiom LP Mgmt (source): A Uniswap v4 hook and position manager to enable trustless LP modification with Axiom. Modifies positions on Uniswap pools automatically so that LPs can passively make better returns.
- UniV4 CCLP Hook (source): Uses Uniswap V4 to create a hook that seamlessly transfers the user's LP to another chain, without them having to worry about bridging or anything else.
- TimeConcentrate (source): Concentrates liquidity along price, and now time, with Uni v4 hooks to mitigate the times MEV bots attack. Hook that modifies positions based on time of MEV attacks.
- Arb Controller (source): A Uniswap v4 hook that sets dynamic fee for a pool based on the price movements. The dynamic fee partially discriminates informed order flow from arbitrageurs.
- NYCV4Hermit (source): Three libraries of tooling developed for Liquidity Sniping (Liqiudity Snipping Blocking Hook), V4 Math, and a V4 Quoter Library.
- Lime (source): An active Uniswap V4 hook manager which allows fillers or market makers to set price and fill Intent / RFQ based swap requests.
- Median Price Oracle: An initial exploration of a median price oracle that is more resistant to manipulation than TWAP. It includes an approximation algorithm where a running median can provide substantial gas efficiency on both read and write.
- Impermanent Loss Hedge (Makemake): A hook to explore ways to hedge impermanent loss for LPs by buying out of the money call options on the underlying asset. When liquidity is added to the pool, the hook is called & executes a purchase of the req. amount of calls in Lyra options protocol.
- Hedge: Risk management strategies using hooks. The project showcases how hedging mechanisms can mitigate price volatility risks in a trader's portfolio.
- Trading Hours: Traditional market opening/closing hours to a Uniswap v4 pool using a beforeSwap hook. Users are only able to trade between 8am and 4pm.
- Dynamic Fee: Adjusts with the goal of cutting LP losses to arbitrageurs, and an implementation of a shared fungible liquidity position (similar to a vault).
Utilize these tools to boost your development process.
- Scaffold Hook: Uniswap v4 Hook development stack, complete with testnet deployment and UI. This tool can help builder develop and test Uniswap v4 Hooks with minimal interfaces for the swap lifecycle (pool creation, liquidity provision, and swapping).
- Hook Mine And Sinker: Mine addresses for UniswapV4 Hooks. This tool can be used to generate random addresses that are eligible to become hooks. This can be useful for testing or for deploying your own Hooks.
- Hook Deployer: Hook create2 deployer. This tool can be used to deploy hooks to Ethereum.
- Uniswap v4 Tests: A test suite for working with Uniswap v4 hooks. This test suite can be used to verify that your hooks are working correctly.
- Uniswap v4 Hook Test Framework: A fuzz testing framework for Uniswap V4 Hooks, built during ETHGlobal 2023. This framework can be used to test the security of your hooks.
These are templates for writing Uniswap V4 Hooks.
- Uniswap Foundation's Template: This template repository provides a starting point for writing Uniswap V4 hooks. It includes the necessary files and contracts to get started. This template can be used to create a custom hook that can be used to execute arbitrary code on every swap. Previously built by saucepoint.
- SolidityLabs' Template: Foundry-based template for developing custom pool in Uniswap v4 with hooks.
- Arrakis' Playground: This playground is a web-based application that allows you to interact with hooks. You can use this playground to test your own hooks or to learn more about how hooks work. This playground can be used to test the functionality of your hooks by simulating swaps.
- Lucas Martin Calderon's Template: This repository contains a template for a hook that was created for the ETHGlobal Hackathon. This template can be used to create a custom hook that can be used to provide liquidity to a particular pool.
- Nick Addison's Template: This repository contains a template for a hook that includes a factory to mine addresses and trace diagrams. This template can be used to create a custom hook that can be used to mine addresses and generate trace diagrams.
- Quantum3 Labs's Scaffold: A boilerplate to use Uniswap v4 hooks with scaffold eth.
A list of chains with their respective chainId
values and an example poolAddress
where Uniswap v4 liquidity pools can be found.
-
Conduit Testnet
- ChainID:
111
- Currency:
ETH
- PoolManager:
0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9
- ChainID:
-
Arbitrum Goerli
- ChainID:
421613
- Currency:
AGOR
- PoolManager:
0x4B8c70cF3e595D963cD4A33627d4Ba2718fD706F
- ChainID:
-
Base Goerli Testnet
- ChainID:
84531
- Currency:
ETH
- PoolManager:
0x693B1C9fBb10bA64F0d97AE042Ee32aE9Eb5610D
- ChainID:
-
Ethereum Goerli Testnet
- ChainID:
5
- Currency:
ETH
- PoolManager:
0x862Fa52D0c8Bca8fBCB5213C9FEbC49c87A52912
- ChainID:
-
Polygon Mumbai Testnet
- ChainID:
80001
- Currency:
MATIC
- PoolManager:
0x5ff8780e4d20e75b8599a9c4528d8ac9682e5c89
- ChainID:
-
Scroll Sepolia Testnet
- ChainID:
534351
- Currency:
ETH
- PoolManager:
0xA449635FaAA6b5a45a568fCe217Bb7921c992285
- ChainID:
Empower your learning curve with these insightful tutorials.
- Uniswap Foundation: v4 by Example: This website shows Solidity snippets for integrating and using Uniswap v4. This is an introduction to integrating and using Uniswap v4 through simple examples.
- LearnWeb3: On-chain "take-profit" orders hook: This tutorial from LearnWeb3 delves into the intricacies of Uniswap v4 hooks. The lesson guides users through building a hook for placing 'take-profit' positions, exemplified by the scenario where a user in an ETH/DAI pool can set an automatic order to sell all their ETH when the price reaches a determined price.
- Solidity Developer: Integrate Uniswap v4 and create a custom hook: This tutorial provides a deep dive, showcasing the nuanced mechanisms for executing fees, the importance of the Ethereum address prefix for the hooks contract, and use of the CREATE2 opcode to deploy contracts with deterministic addresses. A tangible example of using hooks to enable limit orders is presented.
- James Bachini: Introduction to Hooks: This tutorial showcases using the "beforeSwap" hook function to introduce custom actions during a swap.
- Saucepoint: Getting Started with the
v4-template
: This tutorial provides a step-by-step guide to using thev4-template
to create a custom hook, with testing and trouble-shooting tips. - Captain Hook: Uniswap Hooks Tutorial: This tutorial contains 3 different proofs of concept hooks, accompanied by a tutorial blog post.
- Umbrella Research: A Deep Dive With Captain Hook (I): This tutorial shows how developers can implement role-based features within the Uniswap v4 protocol.
Read these articles to gain a deeper understanding of Uniswap v4 hooks.
- A Saga of Hooks, Bidding Farewell to Fork Swap: The v4 innovation, introduction to hooks, action hooks, and enabling custom oracle and distribution of internalized MEV to LPs.
- Threat modeling for secure integration: Learn what to watch out for and what to take care of when integrating with Uniswap v4. Section 4.4.1 reviews potential issues with hooks, including upgradeable hooks, denial of service attacks, sandwich attacks, and access control.
- SharkTeam's Best Security Practices for UniswapV4 Hooks: Covers differences between v4 and v3 with examples of best security practices for hooks.
- Community Contributions to Uniswap v4: Talks about the community contributions to Uniswap v4, including ideas, implementations, commits, and so on.
- Uniswap V4: Exploring Hooks, KYC, and Enhanced Features: Explores the buzz around Uniswap V4, and the reason why this development is intriguing.
- Thorns in the Rose: Exploring Security Risks in Uniswap v4's Novel Hook Mechanism: Explores the threat models of Uniswap v4 hook, and discovers that 36% of the hooks in this repository in one specific commit hash may be vulnerable to attacks.
- Lethal Integration: Vulnerabilities in Hooks Due to Risky Interactions: Scrutinizes secure hook interaction logic from flawed access control and improper input validation perspectives.
- Threats for UniswapV4 hooks: Focuses on the potential threats, risks and vulnerabilities associated with bad hooks in Uniswap v4.
- Uniswap V4: Re-Initialization Leading to Funds Locked: Presents present implementations of "Bad hooks" of "Re-Initialization Leading to Funds Locked".
Watch these videos to learn more about Uniswap v4 hooks.
- Hayden Adams announcing the release of Uniswap V4 (Bankless): 90-minute video covering the release of Uniswap v4, including the hook centric roadmap at 43:29.
- Hayden Adams on what makes v4 special (Unchained Podcast): 80-minute video highlighting v4 including an explanation of hooks, their most common uses, and security concerns starting at 21:05.
- Uniswap V4 Deep Dive with Head of Protocols Sara Reynolds (The Defiant): 75-minute video discussing v4 including an overview of hooks and attack vectors starting at 4:30.
- Uniswap v4: Hooks, Singletons and Controversy (Blockcast): 22-minute video exploring v4 including a discussion of hooks starting at 1:21.
Hooks open doors to limitless innovations. Check out some of these inspiring ideas.
- Loss Versus Rebalancing Minimization: Research funded from the Uniswap Foundation Grants Program regarding cross-domain MEV sources within the DEX ecosystem, specifically on loss-versus-rebalancing (LVR).
- Oracleless Lending Protocol: Creating a new lending protocol offering features like flexible liquidation thresholds, oracle-free operations, and enhanced earnings for liquidity providers.
- Torando Cash on Hooks: A Tornado-like system, utilizing all of Uniswap's liquidity as its pool.
- Hook Safety as a Service: Insuring safety of a hook up to a certain amount.
- Gasless Swaps: Incentivizing traders via a non-toxic MEV executer with gasless swaps.
- Hook to Facilitate Keeper Activity: An intuition on using v4 hooks to facilitate keeper activity.
- What bad hooks look like: An RFP by Uniswap Foundation inviteing for proposals from academic researchers and/or solidity auditors to explore the "malicious design space" of hooks in solidity, especially how they can compromise systems and create safety failures.
- UniBrain Hook: The UniBrain hook is designed to automatically trigger onchain actions using an automated Dutch Auction via a Uniswap V4 Pool. It can turn Uniswap v4 into a hub for triggering onchain function calls.
Check out these related resources.
- Uniswap v4: A New Era For Defi: Article from Uniswap discussing their excitement for the developing of the ecosystem -- highlighting hooks' ability to attract liquidity, design new interfaces, and bridge DeFi into the mainstream.
- Contribution Guidelines for Uniswap v4 Core: Uniswap has released the draft code so that v4 can be built in public with community contribution. You may contribute by opening an issue, resolving an issue, and reviewing open PRs.
Thanks to these contributors for making this list possible.