Skip to content

Commit

Permalink
Add hooks concept doc with updated MDX formating (#752)
Browse files Browse the repository at this point in the history
  • Loading branch information
krisoshea-eth authored Sep 17, 2024
1 parent 03fc543 commit 190dc0a
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions docs/contracts/v4/concepts/04-hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,58 @@
title: Hooks
---

Uniswap V4 introduces Hooks, a system that allows developers to customize and extend the behavior of liquidity pools.

Hooks are external smart contracts that can be attached to individual pools. Every pool can have one hook but a hook can serve an infinite amount of pools to intercept and modify the execution flow at specific points during pool-related actions.

## Key Concepts

### Pool-Specific Hooks

- Each liquidity pool in Uniswap V4 can have its own hook contract attached to it. Hooks are optional for Uniswap V4 pools.
- The hook contract is specified when creating a new pool in the `PoolManager.initialize` function.
- Having pool-specific hooks allows for fine-grained control and customization of individual pools.

## Core Hook Functions

Uniswap V4 provides a set of core hook functions that can be implemented by developers. Developers do not have to implement every hook, you can mix&match them to whatever your liking is. You can use one or all of them!

- Hook contracts specify the permissions that determine which hook functions they implement, which is encoded in the address of the contract.
- The `PoolManager` uses these permissions to determine which hook functions to call for a given pool based on its Key.

### Initialize Hooks

- `beforeInitialize`: Called before a new pool is initialized.
- `afterInitialize`: Called after a new pool is initialized.
- These hooks allow developers to perform custom actions or validations during pool initialization, but these hooks can only be invoked once.

### Liquidity Modification Hooks

The liquidity modification hooks are extremely granular for security purposes.

- `beforeAddLiquidity`: Called before liquidity is added to a pool.
- `afterAddLiquidity`: Called after liquidity is added to a pool.
- `beforeRemoveLiquidity`: Called before liquidity is removed from a pool.
- `afterRemoveLiquidity`: Called after liquidity is removed from a pool.

### Swap Hooks

- `beforeSwap`: Called before a swap is executed in a pool.
- `afterSwap`: Called after a swap is executed in a pool.

### Donate Hooks

- `beforeDonate`: Called before a donation is made to a pool.
- `afterDonate`: Called after a donation is made to a pool.
- Donate hooks provide a way to customize the behavior of token donations to liquidity providers.

## Innovation and Potential

The introduction of hooks in Uniswap V4 opens up a world of possibilities for developers to innovate and build new DeFi protocols. Some potential use cases include:

- Customized AMMs with different pricing curves that xy = k.
- Yield farming and liquidity mining protocols that incentivize liquidity provision.
- Derivative and synthetic asset platforms built on top of Uniswap V4 liquidity.
- Lending hooks integrated with Uniswap V4 pools.

As a hook developer you can easily bootstrap the codebase of an entirely new DeFi protocol through hook designs, which subsequently drives down your audit costs and allows you to develop faster. However, it's important to note that just because you made a hook, that does not mean you will get liquidity routed to your hook from the Uniswap frontend.

0 comments on commit 190dc0a

Please sign in to comment.