Trading 301 — AMM internals, MEV, and execution discipline · Lesson 1 of 5

AMM internals — beyond constant product

6 min · read

Trading 101 introduced the constant-product formula x · y = k. That's the floor of AMM math. To trade safely at 301-tier sizes you need to know what comes after it, because not every AMM you'll meet is constant product, and the differences change your loss profile.

The four families you will meet

1. Constant product (x · y = k). What the XRPL AMM uses. Simple, robust, but the curve flattens fast at the edges — large trades against a thin pool eat brutal slippage, and the pool can't be drained. Liquidity is spread uniformly across all prices from 0 to ∞.

2. Constant sum (x + y = k). Used for stablecoin-to-stablecoin pairs that should trade 1:1. No slippage… until one side is exhausted, after which the pool refuses one direction entirely. Curve is a straight line. You will rarely trade against a pure constant-sum pool — most are hybrids.

3. StableSwap (Curve.fi's invariant). A blend of constant-sum and constant-product. Behaves like constant-sum near the peg, like constant-product when stretched far from it. The math is uglier (a tunable amplification coefficient A); the trading consequence is that you get great fills on small de-peg events and harsh fills if the pair has actually broken its peg.

4. Concentrated liquidity (Uniswap v3 family). LPs place liquidity in chosen price ranges instead of across all prices. Trading inside the active range is cheap; trading outside it returns the same single-asset you put in, with no swap. From a taker's perspective: deeper liquidity than constant-product as long as price stays in the range; sudden cliffs when it doesn't.

The XRPL AMM is pure constant product. The DEX side of XRPL (the CLOB — covered next lesson) is closer to a continuous limit-order book. When you swap through Gopnik, the router decides between them based on size and depth.

The constant-product math you need to actually use

The output of a swap that adds Δx to a pool with reserves (x, y):

Δy = (y · Δx) / (x + Δx)

That denominator — x + Δx rather than just x — is the entire reason slippage exists. Two facts fall out of it:

  • Effective price = Δx / Δy = (x + Δx) / y. The bigger your Δx relative to x, the further the effective price drifts from the spot price x/y.
  • Maximum drainable output approaches y only as Δx → ∞. You can never empty a constant-product pool, but you can pay 99% slippage trying.

Memorise the rule of thumb: slippage in basis points ≈ (trade size / pool depth) × 10,000, halved by routing through deeper paths. A €10k trade against a €1M pool is ≈ 100 bps. Against a €100k pool it's ≈ 1,000 bps — 10% of your trade gone.

Why fees matter, and what they pay for

Every AMM trade pays a fee (XRPL AMM defaults to 0.5%, configurable per pool). That fee goes to liquidity providers (LPs) to compensate them for impermanent loss — the loss they take vs. just holding the two assets, when the price moves. If you ever LP into an AMM, you're being paid the fee to absorb someone else's price-move risk. DeFi 401 covers this in detail; for trading purposes today, just know that fee + slippage = your total round-trip cost, and that thin pools charge both.

The takeaway

The XRPL AMM is one curve. The DEXes you might bridge to are four curves. Before any trade above €5,000 — Gopnik's tier-3 threshold — open the pool page, eyeball the depth on each side, and ask: what fraction of this pool am I about to be? If the answer rounds up to 1%, route into smaller chunks or use a limit order. The math forgives nothing.