Swap

x·y = k curve playground

Swap simulator

A
B
28.510152
Mapping
Δx_in → Δy_out
Fee
0.3%
Price
spot 1 B/A · avg 0.712754 B/A
Price impact
28.725%

One evolution thread: V1 (primitive), V2 (composability), V3 (concentration), V4 (programmability).

Running example

Fixed case across all sections: x=200, y=200, amountIn=20 (A→B). V3/V4 rows use explicit illustrative assumptions for local depth and hook fee behavior.

VersionScenario assumptionOutput BAvg (B/A)Impact
V1full-range CPMM, 30 bps18.13220.90669.339%
V2same pricing path, pair primitive18.13220.90669.339%
V3illustrative 2× local active depth, 30 bps18.99320.94975.034%
V4same local depth, illustrative 15 bps hook fee19.02040.9514.898%

Uniswap V1

V1 proves a core idea: a pool can quote swaps directly from reserves, without an order book.

Its invariant is:

xy=kx\cdot y = k

In the running case (x=200, y=200, amountIn=20 A), V1 is the baseline execution path.

Trade path

For A input:

x=x+Δxeffx' = x + \Delta x_{eff} y=kxy' = \frac{k}{x'} Δy=yy\Delta y = y - y'

Fees are applied on input first, so effective input is smaller than raw input.

Why it mattered

  • Continuous, permissionless on-chain pricing
  • Deterministic execution from reserve state
  • Clear impact intuition: larger trades move farther on the curve

What it could not yet do

The mechanism worked, but architecture was still narrow. V2 keeps the same math and turns it into a composable pair standard.

References

Uniswap V2

V2 is the composability upgrade, not a pricing rewrite.

It keeps CPMM at pair level:

xy=kx\cdot y = k

So in the same running case, output stays close to V1—the trade path is still reserve-curve based.

What changed

  • Token-token pairs became first-class
  • Pair interface became easier to route and integrate
  • Ecosystem composability improved materially

What stayed constrained

Liquidity still spans the full theoretical range. Simple UX, but low capital efficiency.

That bottleneck leads to V3: concentrate depth where flow actually is.

References

Uniswap V3

V3 introduces concentrated liquidity: depth is allocated by tick ranges instead of spread uniformly.

Execution model

  • Inside active range: familiar local reserve-curve behavior
  • Outside active range: liquidity can become inactive

In the running case, concentrating liquidity around spot increases local depth and reduces impact.

What improved

  • Better capital efficiency
  • Better local execution when ranges are well placed

New tradeoff

LPs move from passive exposure to active range management. Tick crossing and rebalancing turn microstructure into an operational problem.

This naturally sets up V4: if range behavior can be configured, execution policy can be configured too.

References

Uniswap V4

V4 keeps V3’s concentrated-liquidity base and adds programmable execution.

Two additions define it:

  • Hooks: pool-specific logic around swap/liquidity lifecycle
  • Singleton architecture: shared pool manager for better composability/gas behavior

In the running case, realized output now depends on both curve state and policy logic (for example fee behavior in hooks).

Why this matters

Protocol teams can express differentiated behavior natively, instead of rebuilding custom layers outside the AMM.

New risk surface

Evaluation shifts from "curve only" to "curve + policy + implementation quality".

References

From V1 to V4 at a glance

VersionPool modelLP styleExtensibilityOperational complexity
V1full-range x·y=kpassive full-rangelowlow
V2pair-based x·y=kpassive full-rangemediumlow
V3concentrated by ticksactive range mgmtmediumhigh
V4concentrated + hooksactive + programmablevery highvery high

Execution quality and LP economics

Price impact is path-dependent

Execution quality is governed by order size / active liquidity, not notional size alone.

Price impact vs pool depth
probe q/L: 0.35
shallower pool impact: 25.93%
deeper pool impact: 10.45%

Model shape determines where depth exists

CPMM spreads depth across the full range; concentrated models place depth around selected ticks.

ModelLiquidity shape
CPMM (x·y=k)full-range hyperbola, uniform across prices
StableSwapnear-peg flatter zone, tails approach CPMM
CLMM (ticks)liquidity allocated by tick intervals
Pool depth by tick interval
active depth share: 88.2%
CLMM bucket count: 17
est. crossing rate: 1 / unit move

LP returns must be decomposed, not guessed from fees

Use net LP return ≈ fee income − LVR − operating costs.

LP return waterfall
net LP return: 6%

V4 hooks: power and responsibility

Hooks make behavior programmable and shift risk from pure curve math to policy logic and implementation quality.

Hook patternPrimary objectiveMain risk
dynamic_feeadapt spread to volatility regimewrong regime detection harms flow
limit_order_likeconditional execution around trigger priceexecution starvation / stale trigger logic
oracle_awarerobust parameter updates with external signalsoracle lag or manipulation surface