Calculate output after the input fee
First calculate effective input as dx × (1 − f), where f is the fee expressed as a decimal fraction. Output dy equals y × effective input ÷ (x + effective input). The formula requires positive reserves and a fee below 100%. Its output is denominated in the output token. Reserve values should be token quantities in human-readable units, rather than monetary values or unadjusted integer balances with different decimal scales.
Trace the reserve arithmetic
Suppose a hypothetical pool holds 100 input tokens and 20,000 output tokens. A trade supplies 1 input token with a 0.30% fee. Effective input is 0.997, giving output of approximately 197.4316 tokens. At the starting reserve ratio, one input token corresponds to 200 output tokens before fees and curve movement. The modeled pool finishes with 101 input tokens and about 19,802.5684 output tokens because the full input enters reserves.
Understand what a quote would require
The calculation assumes a single constant-product curve, no other trades during the scenario, and a fee retained within the simplified reserve model. It excludes gas, routing costs, token transfer taxes, and execution differences caused by changing state. Decimal rounding in a smart contract can also affect small amounts. Zero input produces zero output. Results for very large trades approach the output reserve but do not exhaust it under this mathematical formula.