How the Uniswap v4 singleton architecture works
mainUniswap v4 uses a singleton-style architecture where all pool state is managed within a single contract: PoolManager.sol.
Instead of interacting with individual pool contracts, integrators interact with the PoolManager using an unlock mechanism. To perform actions, an integrator must:
- Call
unlockon thePoolManager. - Implement the
IUnlockCallbackinterface to receive theunlockCallbackcall. - Execute pool actions (like
swap,modifyLiquidity, etc.) within that callback.
Key Constraints:
- Delta Accounting: The
PoolManagertracks net balances (thedeltafield) during an unlock. All accumulated deltas must reach 0 by the time the unlock is released. - Hooks: Pools can be initialized with a hook contract that executes
{before,after}callbacks for lifecycle events likeInitialize,AddLiquidity,RemoveLiquidity,Swap, andDonate. The set of callbacks executed for a pool is fixed after initialization.