Advanced

AMMs Deep Dive — Lesson outline

Build a minimal x·y=k AMM.

Developer Advanced
5/8 — AMMs Deep Dive — Lesson outline

Map the routeFollow this sequence to avoid mixing intuition, math, and code prematurely.

Talk is cheap. Show me the code.
— Linus Torvalds
Steps
  1. Warm-up:Sketch the x·y=k curve and fee flow on paper.
  2. Math drill:Compute outputs for sample trades and confirm k grows with fees.
  3. Design:Define events, fee BPS, and safety checks (non-zero liquidity, min output).
  4. Implement:Write mint/burn/swap with invariant checks and cumulative price updates.
  5. Test:Simulate swaps, edge cases (tiny/large trades), and IL scenarios.
  6. Review:Add view helpers and docs for LP/trader UX.
← Previous section
Next section →