Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4 overview #742

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix with "determined"

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
Loading