P11-L02 · P11 · P11-M01
Compute an illustrative swap with fees and reserves
Prerequisites: P11-L01
Learning objectives
- Compute an illustrative swap with fees and reserves
- Calculate fee-adjusted constant-product output.
- Separate curve impact, fee effect and later slippage.
EN source master · P11-L02 · 30 minutes estimated · needs_review
Offline formative study. No wallet connection, real funds, private keys, signatures, live trade or personal portfolio inputs. Visuals are specifications; this is neither runtime content nor certification.
Why this matters
An output estimate is ambiguous unless it states whether fees, curve movement and subsequent state changes are included.
Explanation
Put the fee in the right place
The v2 model adjusts input for the swap fee when testing the invariant [V2]. In our toy model, fee f=0.003 and effective input Δx_eff=Δx(1−f). Output= y×Δx_eff/(x+Δx_eff). Actual x reserve receives the full input; the retained fee means the unadjusted reserve product increases. It is not correct to remove the fee from reserves and then claim k remains identical.
Declare impact convention
For this lesson, curve impact=1−(no-fee average output/input)/(initial marginal ratio). Fee-inclusive execution shortfall uses the fee-adjusted output/input instead. These two percentages differ; either must be named. Slippage here means additional change between the modeled quote and execution caused by a changed state, not the curve impact already modeled.
Recompute size sensitivity
A larger supplied input travels farther along the curve and worsens average output per input. TVL is aggregate marked value, not the output available at a chosen size. Other pools, routes or hooks are absent; this is not an aggregator quote.
State exclusions
Calculations retain precision and round display only; real onchain integer rounding, gas, fee-on-transfer behavior, MEV and intervening swaps are not simulated. Correct arithmetic provides a conditional estimate, not a guaranteed minimum or safe transaction. LAB03 association in the catalog is downstream and non-gating; this offline lesson does not require deploying a lab.
Key terms
- Effective input: input after stipulated swap fee adjustment.
- Curve impact: finite no-fee average deviation from initial ratio, under stated convention.
- Fee-inclusive shortfall: comparison including fee.
- Slippage: additional quote/execution change under this lesson's convention.
Historical example
ILLUSTRATIVE x100 X,y1000 Y,input 10 X,fee 0.3%. Effective 9.97 X. Compare no-fee 10 X and fee-adjusted10 X. Separate larger-input case20 X; no gas or integer contract rounding.
Visual specifications
Liquidity-depth chart specification using exact formula; mark10/20 inputs, effective input, average output and fee retention. Different lanes for curve impact, fee-inclusive shortfall and unmodeled slippage.
What the evidence proves
Conditional outputs and named execution-shortfall comparisons in the fixture.
What the evidence does not prove
A guaranteed onchain quote, actual gas/MEV, safe minimum output or complete exit liquidity.
Evidence classifications
- OBSERVED: FIX-P11-L02 stipulates fee 0.003 and reserves 100/1000.
- INFERRED: output 1000×9.97/109.97 under the toy model.
- UNKNOWN: state at any actual execution.
- INSUFFICIENT EVIDENCE: the modeled output guarantees a real fill.
Common mistakes
- Using effective input as actual ending reserve.
- Calling fee effect and slippage the same thing.
- Reporting impact without denominator convention.
Practical exercise
Compute fee-adjusted output, ending actual reserves and product. Compute no-fee curve impact and fee-inclusive shortfall for 10 X. Calculate output for 20 X and compare average execution.
Deliver calculations or annotations, claim/source table and limitations. Suggested allocation: study 12 minutes, exercise 8, correction/quiz 10; estimate subject to calibration.
Show worked correction
Δx_eff9.97; output=9970/109.97=90.661089 Y; actual x'=110,y'=909.338911. Product≈100027.28017 XY, above 100000 because the fee stays. No-fee output 90.909091 gives curve impact1−9.090909/10=9.090909%. Fee-inclusive shortfall1−9.066109/10=9.338911%. For20 X, effective 19.94; output 19940/119.94=166.2497916 Y, average 8.3124896 Y/X, lower than9.0661089. Unmodeled state-change slippage remains UNKNOWN.
Formative rubric (5 points): reproducible inputs, correct method, correct result, claim-specific evidence scope, explicit limitations. Invented observation, advisory output or unsupported safety claim requires correction regardless of score.
Checklist
- Declare fee and impact convention.
- Keep full input in actual reserve.
- Round only display.
- Separate modeled curve and later execution.
Summary
Fee-adjusted reserve math is reproducible when balances and comparison conventions are explicit; execution still depends on missing state and costs.
Summary
- Calculate fee-adjusted constant-product output.
- Separate curve impact, fee effect and later slippage.
Next lesson
P11-L03 after correction review.
Tools
NONE in the authoritative catalog. The supplied offline fixture/package is sufficient; no paid feature or unverified Production capability is required. Lab/certification metadata denotes downstream associations, not access gates or live awards.
Sources & claim boundaries
- [V2] Uniswap v2 core whitepaper (March 2020) — Reserve ratio, constant-product mechanics and input-fee invariant; version-specific, not a live deployment snapshot. Checked 2026-10-01; locator turn14view0.
Visual specifications
P11-L02-V01
Compute an illustrative swap with fees and reserves
ILLUSTRATIVE — fictional inputs; no signal or safety guarantee.
Liquidity-depth chart specification using exact formula; mark10/20 inputs, effective input, average output and fee retention. Different lanes for curve impact, fee-inclusive shortfall and unmodeled slippage.
Liquidity-depth chart specification using exact formula; mark10/20 inputs, effective input, average output and fee retention. Different lanes for curve impact, fee-inclusive shortfall and unmodeled slippage.
At 390px stack chart/table, assumptions, correction and source panel; provide complete text equivalent. Rendering pending.
RTL explanatory prose; numeric values, IDs and chronological axes stay LTR; preserve dependency directions.
FIX-P11-L02
Sources & claim boundaries
V2 · PRIMARY_DOCUMENTATION
Uniswap v2 core whitepaper (March 2020)
- Supported claim
- Reserve ratio, constant-product mechanics and input-fee invariant; version-specific, not a live deployment snapshot.
- Verification boundary
- Documentation supports mechanism only; fixture values are original stipulated inputs. Historical publications remain attributed.
- Checked at
- 2026-10-01
https://app.uniswap.org/whitepaper.pdf
Dataset provenance
id: FIX-P11-L02
dataStatus: ILLUSTRATIVE
observedAt: null
timeBasis: T/SIM markers are fictional order, not timestamps.
source: Author-created fixture embedded in this lesson.
scope: No market observation, usable address, secret, signature or personal financial data.