Two pools begin with the same balances. One swap uses Uniswap v2's constant-product rule; the other uses Curve's original StableSwap invariant. Calculate both outputs, add transaction costs, and see why the better quote can change with trade size.
Intermediate calculation lab · reviewed 24 October 2026. This is a reproducible model comparison using invented pool balances and cost assumptions. It is not a live quote, an executed trade or a ranking of today's Uniswap and Curve apps. Read How DEXs Work first if pools and swaps are new to you.
One question, with the conditions held still
Mina wants to swap token X for token Y. Both are fictional stablecoins assumed to be worth $1 for the base case. She already holds X on the same network as each model pool. We compare a direct, single-pool spot swap—not a derivative, an aggregator or a cross-chain route.
| Input | Uniswap v2 model | Original StableSwap model |
|---|---|---|
| Starting reserves | 1,000,000 X + 1,000,000 Y | 1,000,000 X + 1,000,000 Y |
| First trade | 1,000 X for Y | 1,000 X for Y |
| Swap fee | 0.30% of input | Assumed 0.04% of pre-fee output |
| Pricing rule | Constant product | Two-coin invariant, A = 100 in the original paper's notation |
| Extra execution cost | Assumed $2 | Assumed $7 |
Uniswap's fee documentation gives v2 a 0.30% swap fee. Curve's 0.04% here is an author-selected assumption, not a universal Curve fee. Equal starting reserves isolate pricing behavior; the deliberately different extra costs test whether a quote advantage survives execution. Existing approvals are assumed sufficient. No bridge, interface fee, transfer-tax token or competing transaction is included.
Follow the 1,000-token swap
1. Uniswap v2: account for the fee and the curve
The pricing input after the 0.30% fee is 1,000 × 0.997 = 997 X. With initial reserves RX and RY, the continuous-arithmetic output is R_Y × 997 / (R_X + 997). Substituting the reserves gives 996.006981 Y. The full 1,000 X enters the pool; 997 is the amount used for fee-adjusted pricing.
This follows the v2 pricing model. The output already reflects the swap fee and the curve's effect. Subtracting another $3 from this output would count the fee twice.
2. StableSwap: preserve its invariant, then deduct the fee
Curve's original design keeps the exchange curve flatter near balanced, similarly valued assets. Applying its two-coin invariant to the same starting balances gives approximately 999.995025 Y before the assumed fee. After multiplying by 0.9996, the output is 999.595027 Y. The optional calculation below exposes the equation and every input.
The original StableSwap paper supplies the invariant. The legacy plain-pool documentation shows a fee deduction from calculated output. This model uses continuous arithmetic; deployed contracts use token decimals, normalization and integer rounding.
3. Compare what remains after the extra costs
| Measure | Uniswap v2 model | StableSwap model |
|---|---|---|
| Output after swap fee | 996.006981 Y | 999.595027 Y |
| Output valued at $1/Y | $996.006981 | $999.595027 |
| Less assumed extra cost | $2 | $7 |
| Economic net value | $994.006981 | $992.595027 |
Conclusion under these assumptions: StableSwap produces about 3.588046 more Y, but its extra cost is $5 higher. The v2 model therefore leaves Mina about $1.411954 better off. The output-token transfer is still 996.006981 or 999.595027 Y; “economic net” values the separately paid cost rather than changing that transfer.
The break-even question is useful beyond this example: how much extra execution cost can the larger output absorb? Here the answer is about $3.588046. If extra costs were equal, StableSwap would lead in this model. Neither result establishes which live app offers the best route.
Go deeper: reproduce the calculation
For two coins, the original paper's invariant becomes 4A(x + y) + D = 4AD + D³/(4xy). Initially x = y = 1,000,000, so D = 2,000,000. After adding input to x, hold D fixed and solve for y. A = 100 here uses the paper's notation; do not paste it into a deployed pool's parameter field without checking that implementation's scaling convention.
from decimal import Decimal as N, getcontext
getcontext().prec = 50
reserve = N(1000000)
invariant = 2 * reserve
amp = N(100) # A in the original paper
def compare(amount):
amount = N(amount)
effective = amount * N("0.997")
uni = reserve * effective / (reserve + effective)
x = reserve + amount
b = x + invariant / (4 * amp) - invariant
c = invariant ** 3 / (16 * amp * x)
y = (-b + (b * b + 4 * c).sqrt()) / 2
stable = (reserve - y) * N("0.9996")
return uni, stable
for size in (1000, 10000):
uni, stable = compare(size)
print(size, round(uni, 6), round(stable, 6))
print("net:", round(uni - 2, 6), round(stable - 7, 6))
This small calculation is an educational model, not a production quote library. Each call starts again from the original balanced reserves. It does not simulate successive swaps, changing amplification, rate-bearing tokens, dynamic fees, routing or transaction ordering.
Change one variable: 10,000 X instead
Reset both pools to their original balances, then increase only the input amount. Keep the same fee assumptions and extra costs.
| Measure | Uniswap v2 model | StableSwap model |
|---|---|---|
| Output after swap fee | 9,871.580344 Y | 9,995.502662 Y |
| Economic net value | $9,869.580344 | $9,988.502662 |
Now the output advantage is about $123.922318, enough to cover the $5 difference in extra costs. StableSwap leads by about $118.922318. A route that loses for a small order can win for a larger order. This comparison changes trade size; it does not prove that either protocol has more real liquidity.
Where the model stops matching a real quote
Uniswap v3/v4 introduce other liquidity and fee arrangements. Curve has multiple pool designs, including StableSwap-NG. The Curve design overview distinguishes these implementations. Our original-invariant model does not represent every Curve pool, just as v2 does not represent every Uniswap route.
Also distinguish price impact, caused by the order's interaction with liquidity, from slippage, a change between expected and realized execution. A tolerance is a permitted boundary, not an additional fixed fee. See Uniswap's price-impact explanation.
Before comparing two live quotes: record these fields
- The same chain, input/output token contracts, decimals, input amount and observation time or block.
- The protocol version, exact pool or multi-pool route, and whether the displayed output already includes pool and service fees.
- Approval costs, network costs and any bridge cost, expressed in a common valuation currency.
- Minimum received, expiry and what happens if the transaction fails.
- The source used to value each token. A stablecoin ticker is not proof of a $1 redemption value.
A live comparison must obtain actual quotes and pool conditions. No such observation is claimed in this lab. The purpose of the model is to make a later quote comparison interpretable.
Check your understanding
Keep the first example's modeled outputs fixed, but value Y at $0.98 instead of $1. Is receiving almost 1,000 Y equivalent to recovering almost $1,000?
Show the answer
No. Before the extra execution costs, 996.006981 Y is worth about $976.09, and 999.595027 Y is worth about $979.60. This is a valuation stress test, not a simulated live depeg: real arbitrage and pool imbalance would also change the quote. A flatter exchange curve does not guarantee the underlying token's value.
Continue learning: Return to DEX mechanics · Try a stablecoin exit-cost calculation.
Revision history and scope
Revised 19 October 2026. Removed fixed fee, slippage, leverage and best-price guarantees. Added an example of total execution cost.
24 October 2026: Moved the earlier correction note below the lesson and added a reader-focused introduction. This is a presentation edit; the earlier factual review date is unchanged.
24 October 2026 — substantive update: Replaced the seven-brand checklist with a reproducible comparison of Uniswap v2 and the original StableSwap invariant. All reserves, Curve fee and execution-cost inputs are declared assumptions. Calculations were checked locally; no live quotes or trades are claimed.
