In a standard input-fee constant-product model, calculate the input remaining after the fee, then apply the pool curve. Use the reserve corresponding to the input asset in the denominator and the reserve corresponding to output in the numerator.
Work through the numbers
Assume hypothetical reserves of 10,000 A and 20,000 B. The trader sends 100 A. For this example, choose an input fee of 0.30%; this is a model parameter, not a live quote.
Effective input = 100 × (1 − 0.003) = 99.7 A
Output = 20,000 × 99.7 / (10,000 + 99.7)
Output ≈ 197.431607 BThe initial local reserve ratio is two B per A, which would imply 200 B for an infinitesimal-rate extrapolation. The actual modeled output is lower because of both the chosen fee and trade size.
Separate useful counterfactuals
With the same reserves and no fee, output would be approximately 198.019802 B. The difference between 200 and 198.019802 isolates the fee-free size effect in this model. The difference between 198.019802 and 197.431607 is the additional effect of the fee rule on output.
It is not necessary to subtract either difference from 197.431607 again. That number already represents the modeled receiving amount.
The Uniswap v2 reference library implements the corresponding amount-out calculation using integer arithmetic. Real token-unit rounding can slightly alter the displayed decimal result.
When this estimate is inappropriate
Do not use it directly for concentrated-liquidity balances, stable-asset invariants, dynamic fee logic or tokens with unusual transfer behavior. A multi-hop route also needs each leg's reserves rather than one combined reserve total.
The calculation is a transparent way to inspect one simple pool at one state. It does not ensure that those reserves remain unchanged until a transaction executes.
Sources & verification (1)
Source-check date is recorded in the article details. URLs are provided for manual verification. Use Copy to keep this page open.
- UniswapV2Library.sol
Reference amount-out and amount-in arithmetic; integer rounding.
https://github.com/Uniswap/v2-periphery/blob/master/contracts/libraries/UniswapV2Library.sol