Asset classes and instruments · AMM constant product
What does a trade cost in a constant-product pool?
The cost and price impact of a buy, an LP position against holding, and the extra cost to a user of a sandwiched trade, on the reserves you enter.
- k = x × y · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees400,000,000
- Spot price, y ÷ x · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees40,000.00 MDT
- Average price paid · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees40,404.04 MDT
- Average over spot · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees1.01%
- Cost of buying 10.00 tokens · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees444,444.44 MDT
- Average price paid for 10.00 tokens · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees44,444.44 MDT
- Average over spot for 10.00 tokens · Constant-product pool, x × y = k, on the entered reserves; a pool fee is charged on the quote paid in and kept outside k; impermanent loss is versus holding, excludes pool fees earned, and the model assumes no fees11.11%
- LP value ÷ hold value, 2√r ÷ (1 + r) · versus holding; excludes pool fees earned; model assumes no fees0.9428
- Impermanent loss · versus holding; excludes pool fees earned; model assumes no fees−5.72%
- LP position value · versus holding; excludes pool fees earned; model assumes no fees$14,142
- Shortfall against holding · versus holding; excludes pool fees earned; model assumes no fees$858
- Cost to the user, sandwiched · cost to the user only, at the entered front-run size, which is not solved for40,813.20 MDT
- Extra cost to the user from the sandwich · cost to the user only, at the entered front-run size, which is not solved for; the same fee treatment on both costs409.16 MDT
- User's average price over spot, sandwiched · cost to the user only, at the entered front-run size, which is not solved for2.03%
- k = x × yk = 100 × 4,000,000=400,000,000
- Spot price = y ÷ xSpot price = 4,000,000 ÷ 100=40,000.00 MDT
- Cost of the buy = (k ÷ (x − Δx) − y) ÷ (1 − φ ÷ 100)Cost of the buy = (400,000,000 ÷ (100 − 1) − 4,000,000) ÷ (1 − 0 ÷ 100)=40,404.04 MDT
- Average price paid = (k ÷ (x − Δx) − y) ÷ (1 − φ ÷ 100) ÷ ΔxAverage price paid = (400,000,000 ÷ (100 − 1) − 4,000,000) ÷ (1 − 0 ÷ 100) ÷ 1=40,404.04 MDT
- Average over spot = (A ÷ S − 1) × 100Average over spot = (40,404.0404 ÷ 40,000 − 1) × 100=1.01%
- Cost of the second buy = (k ÷ (x − Δx₂) − y) ÷ (1 − φ ÷ 100)Cost of the second buy = (400,000,000 ÷ (100 − 10) − 4,000,000) ÷ (1 − 0 ÷ 100)=444,444.44 MDT
- Average price paid, second buy = (k ÷ (x − Δx₂) − y) ÷ (1 − φ ÷ 100) ÷ Δx₂Average price paid, second buy = (400,000,000 ÷ (100 − 10) − 4,000,000) ÷ (1 − 0 ÷ 100) ÷ 10=44,444.44 MDT
- Average over spot, second buy = (A₂ ÷ S − 1) × 100Average over spot, second buy = (44,444.4444 ÷ 40,000 − 1) × 100=11.11%
- LP value ÷ hold value = 2√r ÷ (1 + r)LP value ÷ hold value = 2 × sqrt(2) ÷ (1 + 2)=0.9428
- Impermanent loss = (2√r ÷ (1 + r) − 1) × 100Impermanent loss = (2 × sqrt(2) ÷ (1 + 2) − 1) × 100=−5.72%
- LP position value = H × 2√r ÷ (1 + r)LP position value = 15,000 × 2 × sqrt(2) ÷ (1 + 2)=$14,142
- Shortfall against holding = H − H × 2√r ÷ (1 + r)Shortfall against holding = 15,000 − 15,000 × 2 × sqrt(2) ÷ (1 + 2)=$858
- Cost to the user, sandwiched = (k ÷ (x − f − Δx) − k ÷ (x − f)) ÷ (1 − φ ÷ 100)Cost to the user, sandwiched = (400,000,000 ÷ (100 − 0.5 − 1) − 400,000,000 ÷ (100 − 0.5)) ÷ (1 − 0 ÷ 100)=40,813.20 MDT
- Extra cost to the user = U − CExtra cost to the user = 40,813.2031 − 40,404.0404=409.16 MDT
- User's average over spot, sandwiched = (U ÷ Δx ÷ S − 1) × 100User's average over spot, sandwiched = (40,813.2031 ÷ 1 ÷ 40,000 − 1) × 100=2.03%
Rounded for display; the result uses full precision.
A pool of 100.00 tokens and 4,000,000.00 MDT has k = 400,000,000 and a spot price of 40,000.00 MDT. Buying 1.00 costs 40,404.04 MDT (1.01% over spot); buying 10.00 averages 44,444.44 MDT (11.11%), with a 0.00% pool fee: constant-product arithmetic on the entered reserves. At a price ratio of 2.00 the LP position is worth 0.9428 of holding: $14,142 against $15,000, a shortfall of $858 (−5.72%), versus holding; excludes pool fees earned; model assumes no fees. Cost to the user of a sandwiched trade: with 0.50 tokens bought ahead (the entered size, not solved for), the user pays 40,813.20 MDT against 40,404.04 MDT unsandwiched (the same fee treatment on both), an extra 409.16 MDT, 2.03% over spot, within the entered 3.00% tolerance. Framed only as cost to the user. Protocol risk and the total-loss row: a pool can lose its reserves to a contract failure, or a token can go to zero, and an LP position falls with it. No protocol is named or evaluated, and no fee-APR or yield figure is shown.
Educational and informational only — not investment advice, a recommendation, or an offer to buy or sell any security. Investing involves risk, including the possible loss of principal. Worked examples use fictional companies and figures.
Used in these lessons
- DeFi: financial machinery without the institutionsLesson 9 · Topic 19 · Crypto and digital assets: technology, asset and industry
- DeFi mechanics: automated market makers and lending poolsLesson 4 · Topic 51 · Crypto market structure
- MEV and transaction orderingLesson 8 · Topic 51 · Crypto market structure
When it helps
Working through price impact, impermanent loss or a sandwiched trade in a constant-product pool.
Reading the result
The pool keeps x times y constant, so each token taken out costs more quote than the last: that curve is the price impact, and the same curve leaves an LP behind simply holding when the price moves (versus holding, pool fees earned excluded). The sandwich is the cost to the user only, at a front-run size you enter. Protocol risk is not in any of these numbers.
Nothing you enter is saved or sent. Calculators earn no XP.