Skip to content

Commit

Permalink
v4 overview
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepoint committed Sep 10, 2024
1 parent 0edb8af commit d4528a3
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions docs/contracts/v4/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,56 @@ sidebar_position: 1

# Uniswap v4

Uniswap v4 uses all of the capital efficiency gains of Uniswap v3, but provides gas optimizations across the entire lifecycle
and flexibility via *hooks*.
Uniswap v4 inherits all of the capital efficiency gains of Uniswap v3, but provides flexibility via *hooks* and gas optimizations across the entire lifecycle.

For additional information, see the [Uniswap v4 whitepaper](https://github.com/Uniswap/v4-core/blob/main/docs/whitepaper/whitepaper-v4.pdf).
For additional information, see the [Uniswap v4 whitepaper](https://github.com/Uniswap/v4-core/blob/main/docs/whitepaper/whitepaper-v4.pdf)

---


## Hooks

Developers can attach solidity logic to the _swap lifecycle_ through Hooks. The logic is executed before and/or after major operations such as
pool creation, liquidity addition and removal, swapping, and donations. Hooks are deployed contracts, and are called by the Uniswap v4 PoolManager,
for permissionless execution.

The flexibility of hooks can enable:
* Limit orders
* Custom oracles
* Fee management
* Automated liquidity management

## Dynamic Fees

Uniswap v4 supports dynamic fees, allowing pools to adjust their fees up or down. While other AMMs may have hard-coded logic for dynamic fees,
v4 provides no opinionated calculation of the fee. The frequency of *liquidity fee* updates is also flexible and deteremined by the developer. Fee updates can
occur on every swap, every block, or on an arbitrary schedule (weekly, monthly, yearly, etc).

Dynamic fees open up the design space for fee optimization, value redistribution, and research.


## Singleton Design

Architecturally, all pool state and operations are managed by a single contract -- `PoolManager.sol`. The singleton design provides major gas
savings. For example, creating a pool is now a state update instead of the deployment of a new contract. Swapping through multiple pools no longer requires
transferring tokens for intermediate pools.

## Flash Accounting

By leveraging EIP-1153 Transient Storage, v4 provides an optimization referred to as *flash accounting*. Swapping, liquidity modification, and donations
incur *balance changes*, i.e. tokens to be sent in and tokens to be taken out. With *flash accounting* these balance changes are efficiently recorded in transient storage and
netted against each other. This system allows users to only pay the final balance change, without the need for resolving intermediate balance changes.

## Native ETH

Uniswap v4 supports native token assets (Ether), without the need to wrap/unwrap the native token to Wrapped Ether (WETH9).

## Custom Accounting

The flexibility of custom accounting allows developers to alter token amounts for swaps and liquidity modifications. The feature opens up the design
space for hooks to charge fees or forgo the underlying concentrated liquidity model.

Example use-cases:
* Custom curves, opt-out of the concentrated liquidity curve in favor of an entirely independent pricing mechanism
* Hook swap fees, charge and collect fees on swaps
* Liquidity withdrawal fees, penalize and/or redistribute fee revenue

0 comments on commit d4528a3

Please sign in to comment.