Explore a detailed technical breakdown of Uniswap v4, innovative uniswap v4 hooks, architecture and impact on decentralized finance.
Uniswap has redefined decentralized trading by replacing traditional order books with Automated Market Makers (AMMs), enabling swaps without intermediaries. At the core of this model are liquidity pools with token reserves, funded by liquidity providers who earn fees in return for their contributions. Over the years, Uniswap has refined this design to enhance capital efficiency and user experience. With the release of Uniswap V4, the protocol introduces:
Enabling developers to build highly flexible pools while reducing gas costs and fragmentation. These innovations mark a major step forward in both technical design and ecosystem composability.
Introduced AMMs using the constant product formula x * y = k
. Enabled ETH ↔ ERC20 swaps and permissionless liquidity, but ERC20 ↔ ERC20 swaps required routing through ETH, increasing costs.
Added ERC20 ↔ ERC20 pools, multi-hop routing, flash swaps, and a TWAP oracle. However, LPs still had to provide liquidity across the entire price curve, leading to inefficiency and higher impermanent loss.
Brought concentrated liquidity, letting LPs choose specific price ranges. This improved capital efficiency, boosted fee earnings, and reduced impermanent loss by narrowing exposure. Yet, it introduced complexity for LPs and liquidity fragmentation across chains, while forks diluted network effects.
Introduces a singleton architecture, customizable hooks, and flash accounting for major gas savings. With native ETH support and EIP-1153 transient storage, V4 reduces costs and enables developers to experiment with new AMM designs—including mechanisms that could further address impermanent loss.
Impermanent loss (IL) occurs when the value of assets you provide as liquidity grows differently compared to simply holding them. It’s called impermanent because it only becomes permanent once you withdraw your funds from the pool.
Example:
You deposit 1 ETH (worth $2,000) and 2,000 USDC into a pool. Later, ETH’s price doubles to $4,000.
The $344 difference is your impermanent loss.
Liquidity providers accept this risk because they earn trading fees that can offset or exceed the IL over time.
Providing liquidity in Uniswap V4 is orchestrated through the PoolManager contract via the modifyLiquidity flow. Unlike V2/V3, where each pool was its own contract, V4 consolidates all pools under a singleton PoolManager, with pool logic implemented as libraries. This design allows for more efficient liquidity operations, unified accounting, and hook extensibility.
Adding or removing liquidity follows a clear execution path:
PositionManager
).PoolManager
, which triggers unlockCallback
.modifyLiquidity
on the manager.beforeModifyLiquidity
.ModifyLiquidity
event is emitted.afterModifyLiquidity
.(amount0, amount1)
Delta is returned to the periphery.This architecture preserves atomicity while giving hooks the ability to extend liquidity behavior.
When a new pool is created on Uniswap, the very first liquidity provider (LP) has a special responsibility: they must set the starting price and deposit tokens into the pool. Unlike traditional pools, Uniswap uses a concentrated liquidity model, where LPs choose a price range in which their funds will be active.
Example: ETH/USDC Pool
This means the LP’s funds will only be used for trades while ETH stays within that range.
Depending on the current market price and your chosen range, you might need to deposit:
Uniswap’s math ensures that the right amounts are required, keeping balances accurate and preventing errors.
Want to dive deeper into the mechanics of liquidity provision and the math that powers it?
Check out our detailed handbook on Uniswap v4’s liquidity design: Liquidity Mechanics in Uniswap V4 Core
In Uniswap v3, each pool was a standalone contract, with its own state and fees. Multi-hop swaps and liquidity changes were costly due to interactions with multiple contracts.
In Uniswap v4, pools are library-backed states inside a singleton PoolManager , reducing deployment and multi-hop costs:
1// PoolManager
2using Pools for *;
3mapping (PoolId id => Pool.State) internal pools;
4
5function swap(PoolId id, ...) {
6 pools[id].swap(...); // Library call
7}
All liquidity modifications now funnel through PoolManager.modifyLiquidity , which combines hook composability, efficient tick math, and centralized accounting into a single unified system.
Swaps are the core of Uniswap V4, executing token exchanges across initialized liquidity ranges and adjusting prices tick-by-tick as liquidity is consumed. Leveraging flash accounting, balances are settled only once per transaction, reducing gas costs, while hooks enable dynamic fee adjustments for greater flexibility. Let’s dive deeper into swaps, flash accounting, and locking.
Uniswap v4 swaps follow a precise sequence, optimized for gas efficiency and customizability:
SwapRouter
), which unlocks the PoolManager
.PoolManager
invokes unlockCallback
on the periphery, where the actual swap
is triggered.beforeSwap
executes before the swap logic.Swap
event is emitted.afterSwap
runs after execution.BalanceDelta
(net token0/token1 changes) and returns it to the periphery.BalanceDelta
?BalanceDelta
is a signed pair (amount0, amount1)
that tracks net balance changes from the user’s perspective:
In Uniswap V4, settlement is delayed until execution completes. This enables flash accounting, where multi-hop swaps require only an initial input and final output transfer. All intermediate transfers are internally netted, reducing gas costs and boosting efficiency.
This mechanism builds on EIP-6909’s token accounting model, standardizing how balance changes are represented and making v4 swaps both more efficient and extensible.
Want to dive deeper into the mechanics of token swaps and the math that drives them?
Check out our detailed handbook on Uniswap v4’s swap design: Swap Mechanics in Uniswap v4 core
Ensure your Uniswap v4 swaps and smart contracts are safe and efficient. Take the next step toward secure DeFi transactions.
In V2/V3, multi-hop swaps required intermediate token transfers between pool contracts, incurring high gas overhead. V4’s singleton PoolManager enables flash accounting:
PoolManager
once.For example, an ETH → USDC → DAI route:
ETH
sent → pool → USDC
transferred → pool → DAI
transferred → user.ETH
deposited once → intermediate steps computed in-memory → only final DAI
transferred out.This reduces external token transfers from O(hops) to O(1), cutting gas costs drastically while maintaining invariant correctness.
One of the most powerful innovations in Uniswap v4 is hooks, custom smart contracts that let developers modify pool behavior at key points, such as before or after swaps and liquidity changes. This flexibility opens up a wide range of possibilities, including:
Hooks effectively turn Uniswap into a developer platform for AMM experimentation, enabling new financial primitives without requiring a protocol fork.
Want to dive deeper into hooks? Check out our detailed blog post here:
Uniswap v4 hooks enable protocols to extend and customize AMM functionality, powering innovations such as dynamic fees, automated liquidity management, and MEV protection. This flexibility has quickly made hooks a core building block for new DeFi applications.
The ecosystem has already produced 3,200+ live hook implementations, created by the broader community, the Uniswap core team, and protocol builders. A comprehensive directory is available at HookRank. Below are some of the leading projects already building with hooks:
Uniswap v4 sets a new benchmark for AMM efficiency through concentrated liquidity, extensible hooks, and flash accounting, cutting multi-hop gas costs by up to 99% while enabling highly customizable strategies. By resolving fragmentation and strengthening security, v4 reinforces Uniswap’s leadership in DeFi, delivering superior capital efficiency and operational flexibility for both LPs and traders.
Contents
Get updates on our community, partners, events, and everything happening across the ecosystem — delivered straight to your inbox.
Subscribe Now!
Office 104/105 Level 1, Emaar Square, Building 4 Sheikh Mohammed Bin Rashid Boulevard Downtown Dubai, United Arab Emirates P.O box: 416654
Privacy PolicyAll Rights Reserved. © 2025. QuillAudits - LLC
Office 104/105 Level 1, Emaar Square, Building 4 Sheikh Mohammed Bin Rashid Boulevard Downtown Dubai, United Arab Emirates P.O box: 416654
audits@quillaudits.comAll Rights Reserved. © 2025. QuillAudits - LLC
Privacy Policy