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.
State
Two reserves:
x,Β y
Constant product:
xβ
y=k
I keep coming back to: the price is a slope of that curve.
Quote
If you add a small amount Ξx (ignore fees for a second):
xβ²=x+Ξx
yβ²=xβ²kβ
Ξy=yβyβ²
So the output is not linear in Ξ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
Then plug Ξxeffβ into the same constant-product math.
Price
Spot price as a local ratio:
p=dxdyβ=βx2kβ
You can read it as: as x grows, the curve flattens, and you pay less y per extra unit of x.
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