Curriculum·Junior·J302
Swap Execution: AMMs, MEV, and DEX Architectures
Uniswap v3, 12 March 2025. A swap of 220,764 USDC for USDT, submitted outside Uniswap's own interface and so without its MEV protection and default slippage settings, returned about $5,271, a loss of roughly 98 percent, per Cointelegraph.
Lesson 1 opens on
bZx, February 2020
bZx took its prices from Kyber, and Kyber routed to on-chain pools. On 15 February (UTC) an attacker took a flash loan of 10,000 ETH from dYdX and put 1,300 ETH of it into a five times leveraged short of ETH against wBTC at bZx. bZx converted 5,637 ETH into 51 wBTC through a Kyber order that was routed to Uniswap, at around three times the market price, and a logic error in bZx's contract skipped the collateral check that should have reverted the position.
The lessons
- J302-01Constant product mathDerive an AMM's price from its reserves and compute the effect of a trade of any sizeabout 41 min · opens on bZx, February 2020
- J302-02Price impact and slippageSeparate pool price, price impact and slippage, which are three different costsabout 43 min · opens on The Curve stETH pool, June 2022
- J302-03The transaction lifecycleTrace a transaction from signing to finality and name what can change at each stageabout 33 min · opens on The seven block reorganization, 25 May 2022
- J302-04MEVName the parties in the ordering supply chain and what each one is trusted withabout 33 min · opens on The mev-boost relay exploit, 3 April 2023
- J302-05Execution discipline on-chainRun the pre-swap checklist that the preceding four lessons produceabout 31 min · opens on Six swaps, one setting, one day
- J302-06The four architecturesClassify any venue by where price is formed and where matching happensabout 33 min · opens on Four architectures, four failure shapes
- J302-07AMM generations, properlyName each market maker generation and the capability it addedabout 34 min · opens on Balancer and the deflationary token, 28 June 2020
- J302-08On-chain order books and app-chainsExplain why an order book is expensive to run on a shared chainabout 32 min · opens on The account that stopped a market, 14 September 2021
- J302-09Aggregators and routingExplain what an aggregator does and why it requires a token approval to do itabout 31 min · opens on LI.FI and Jumper, 16 July 2024
- J302-10Intents and solversDistinguish stating a route from stating an outcome, and what each exposesabout 32 min · opens on The CoW Swap solver exploit, 7 February 2023
- J302-11Perp DEXsName the components a perpetual venue adds beyond a spot exchangeabout 33 min · opens on Hyperliquid and JELLY, March 2025
- J302-12Launch venues and bonding curvesExplain how a bonding curve prices without a counterparty or any liquidityabout 33 min · opens on The completion rate on a launch venue
Labs
J302-L
One swap routed five ways: through an AMM directly, an aggregator, a protected RPC, an intent-based DEX and an on-chain order book. Attribute the cost of each from quoted and realized price, fee and gas, derive the AMM's impact from its reserves, price the tolerance, and compute the sandwich threshold.
