Workspace / Research tools
Liquidity pools

Constant Product Swap Calculator

A constant-product pool changes its exchange rate as a trade consumes one reserve and adds to the other. This calculator estimates output for a single hypothetical swap using input-token reserve x, output-token reserve y, trade input, and a percentage fee. It is useful for seeing why doubling trade size need not double received tokens. All reserves and trade amounts come from your browser-local entries. The model represents one pool with ordinary token transfers; it does not search routes, request quotes, or submit a swap.

Enable JavaScript to edit assumptions, calculate and compare a baseline locally. The formula and methodology below remain available without JavaScript.

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.

Primary documentation

Your research workspace

Save selected inputs and research notes explicitly in this browser. Compare assumptions and restore a saved setup without submitting a trade. JavaScript enables the controls.

Find a tool or research page