Skip to content

A curated list of awesome Uniswap v4 hooks resources.

Notifications You must be signed in to change notification settings

KB0xD3D/awesome-uniswap-hooks

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 

Repository files navigation

🦄️ Awesome Uniswap v4 Hooks

A curated list of awesome Uniswap v4 hooks resources.

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

🔄 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}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.

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

From the 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.
  • Trading Hours: Allows trading to only occur between defined trading hours. This can be used to prevent trading during certain times of day, such as when the market is illiquid or when there is a high risk of price volatility.
  • 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.
  • Hedging Mechanism: Allows users to hedge their positions against market volatility. This can be done by using a variety of techniques, such as buying options or futures contracts.
  • 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.
  • Impermanent Loss Hedge (Makemake): Another hook to automatically hedge impermanent loss with options.
  • Median Price Oracle: Provides a more accurate price feed. This can be done by using a variety of techniques, such as aggregating prices from multiple sources or using a median price calculation.
  • 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.

🛠 Tools

Utilize these tools to boost your development process.

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

📐 Templates

These are templates for writing Uniswap V4 Hooks.

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

🎓 Tutorials

Empower your learning curve with these insightful tutorials.

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

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

👀 See Also

Check out these related resources.

🙏 Thanks

Thanks to these contributors for making this list possible.

About

A curated list of awesome Uniswap v4 hooks resources.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published