The main component of Uniswap V4 is swap; it manages precise input/output swaps, optimizes gas through flash accounting, and moves price through liquidity ticks. Three main points:
- Each swap moves through initialized liquidity ranges, crossing ticks when it is depleted. The price fluctuates tick by tick.
- Multihop efficiency: By avoiding middlemen, flash accounting settles net balances just once.
- Dynamic fee support: Hooks have the ability to modify fees in real time according to market conditions.
Compared to their predecessors, V4 swaps are therefore both gas-optimized and capital-efficient. lets discuss further about swap and Flash Accounting & Locking.
How swap works on Uniswap v4
Uniswap v4 design flow

- User uses a periphery contract (SwapRouter, for example) to initiate a swap
- Periphery contract
unlock
s the PoolManager
, triggering the manager to call unlockCallback
on the periphery
- Inside the callback function, the periphery executes
swap
on the manager
- The manager makes sure the pool is valid and has been initialized
- The manager checks the hook address attached to the pool (if one does) and checks if it needs to run
beforeSwap
- If yes,
beforeSwap
is called on the hook contract. If no, skip to next step.
- After
beforeSwap
is run, the actual swap is conducted inside the manager contract
- The manager then charges protocol fees, if any, and emits the
Swap
event.
- It again checks the hook address to see if
afterSwap
needs to run
- If yes, call
afterSwap
, else skip to next step
- Finally, the manager has an overall delta change of balances from the swap. This delta represents which token (and how much) is owed to the user, and which token (and how much) is owed to the manager