Skip to content

ora-io/awesome-uniswap-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 

Repository files navigation

πŸ¦„οΈ Awesome Uniswap v4 Hooks

Check out UniswapHooks.com for more contents!

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!

πŸ“‘ Table of Contents

πŸ€” Introduction

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 in PoolManager.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 the BaseHook 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.

πŸ”„ Lifecycle

During the course of a pool action's lifecycle, a hook invokes custom logic primarily at four critical phases:

  1. Initialize: Activated when the pool is deployed.
  2. Modify Position: Used to add or remove liquidity.
  3. Swap: Engages a swap between tokens within the V4 ecosystem.
  4. 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}AddLiquidity
  • {before,after}RemoveLiquidity
  • {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.

πŸ”§ Functionalities

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

πŸ“œ Examples

A collection of hooks from Uniswap and community developers.

From Uniswap

  • 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.

From Community

  • 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 finance entities, offering custom pools with dynamic fee options and other functionalities.
  • 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 increase 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.
  • Violet Hooks: A hook that uses VioletID registry to perform identity checks. This can be used for permissioned pools for compliance.
  • Dynamic Fee Hook: A hook that adjusts the pool fee based on the realized volatility of the pair, using a Volatility Fee oracle.
  • WBTC Hook, A hook that only allows WBTC pools to be created. This is built for celebrating the Bitcoin ETF was approved on 2024-01-10.

From Hackathon

ETHGlobal London 2024

  • Apeful (source): A hook that enables user incentives on Uniswap V4 pools by automatically generating AI-based NFTs when the user does specific action with ApeCoins, everything completely onchain.
  • The Incredible Hook (source): A hook that enables user to get their transaction sponsored in exchange for a discount on swap fees for the sponsor, a win-win deal.
  • SuckerPunch (source): A dynamic fee hook, which adjusts fees based on how long you've been a holder.
  • Dynamic AMM Fees (source): A hook with impermanent loss protection using dynamic fees based on market volatility.
  • TokenTown (source): A Monopoly-inspired, onchain board game where in-game properties are purchased with a stepwise price via a custom-curve v4 pool.
  • 0xEstate (source): A marketplace that leverages v4 hooks to provide liquidity to fractional real estate. Hooks enabled constraints for purchases of onchain assets.
  • Royalty Swap (source): A hook to provide discounted swap fees for high volume traders
  • FairArbooors (source): SUAVE auctions for the right to perform top-of-block swaps, with auction proceeds being donated to LPs.

ETHGlobal Istanbul 2023

  • 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.

ETHOnline 2023

  • 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.

ETHGlobal New York 2023

  • 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 (Liquidity 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.

EthCC Paris Hookathon 2023

  • 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).

πŸ›  Tools

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.
  • Hookmate: Experimental Solidity components and utilities for Uniswap v4 Hook development. This can help developers leverage extsload and access fee info for hooks.
  • Uniswap v4 Minimal: Minimal subgraph for Uniswap v4.

πŸ“ Templates

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.
  • Gnome101's Hardhat Template: A template and playground that uses hardhat. This can be used to create and test custom hooks.

πŸ”— Supported Chains

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
  • Arbitrum Goerli

    • ChainID: 421613
    • Currency: AGOR
    • PoolManager: 0x4B8c70cF3e595D963cD4A33627d4Ba2718fD706F
  • Base Goerli Testnet

    • ChainID: 84531
    • Currency: ETH
    • PoolManager: 0x693B1C9fBb10bA64F0d97AE042Ee32aE9Eb5610D
  • Ethereum Goerli Testnet

    • ChainID: 5
    • Currency: ETH
    • PoolManager: 0x862Fa52D0c8Bca8fBCB5213C9FEbC49c87A52912
  • Polygon Mumbai Testnet

    • ChainID: 80001
    • Currency: MATIC
    • PoolManager: 0x5ff8780e4d20e75b8599a9c4528d8ac9682e5c89
  • Scroll Sepolia Testnet

    • ChainID: 534351
    • Currency: ETH
    • PoolManager: 0xA449635FaAA6b5a45a568fCe217Bb7921c992285
  • Ethereum Sepolia Testnet

    • ChainID: 11155111
    • Currency: ETH
    • PoolManager: 0x64255ed21366DB43d89736EE48928b890A84E2Cb

πŸŽ“ Tutorials

Empower your learning curve with these insightful tutorials.

πŸ’‘ Articles

Read these articles to gain a deeper understanding of Uniswap v4 hooks.

🍿 Videos

Watch these videos to learn more about Uniswap v4 hooks.

πŸ’‘ Creative Ideas

Hooks open doors to limitless innovations. Check out some of these inspiring ideas.

  • Loss Versus Rebalancing Minimization: Research funded by 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 inviting 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.
  • Tips to make pool aggregator/searcher-friendly: 6 dos and don'ts to make v4 customized pools aggregator/searcher-friendly, to attract more volume from aggregators/searchers.
  • Value accrual designs for hook developers: A simple hook fee introduces vampire/fork risk. Retaining LPs will be crucial to justifying hook fees.
  • auction-managed AMM: An auction-managed AMM that shows the design space of v4.

πŸ‘€ See Also

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.
  • The Uniswap Hook Incubator: An 8-week program to help advanced DeFi devs build hooks.

πŸ™ Thanks

Thanks to these contributors for making this list possible.