DEX

Uniswap V1 notes, math-first

Uniswap V1 is the first time I saw a pricing function you can touch. Not an orderbook. Just reserves and a curve.

Uniswap V1 pool move

State

Two reserves:

x,Β yx,\ y

Constant product:

xβ‹…y=kx\cdot y = k

I keep coming back to: the price is a slope of that curve.

Quote

If you add a small amount Ξ”x\Delta x (ignore fees for a second):

xβ€²=x+Ξ”xx' = x + \Delta x yβ€²=kxβ€²y' = \frac{k}{x'} Ξ”y=yβˆ’yβ€²\Delta y = y - y'

So the output is not linear in Ξ”x\Delta x. The curve is the slippage.

Fee

V1 trade fee is 0.3%. A clean way to remember the implementation is:

Ξ”xeff=0.997 Δx\Delta x_{eff} = 0.997\,\Delta x

Then plug Ξ”xeff\Delta x_{eff} into the same constant-product math.

Price

Spot price as a local ratio:

p=dydx=βˆ’kx2p = \frac{dy}{dx} = -\frac{k}{x^2}

You can read it as: as xx grows, the curve flattens, and you pay less yy per extra unit of xx.

Notes

  • The pool is the book.
  • Liquidity is a scale factor (it stretches the curve).
  • Most surprises in UX are just the curve meeting integer math.

References

  • Uniswap V1 whitepaper
  • Uniswap V1 core contracts