Skip to article
Degrees of SatoshiFollow the connections.
Degrees of Satoshi/ Encyclopedia

Degrees of Satoshi · Learn with evidence

Swap Lab

Change a pool, inspect the arithmetic, and see why tolerance does not improve a quote.

Try a swap from A to B

Fictional tokens with eight decimal places. Every change recalculates locally. No wallet or transaction is involved.

Use decimal numbers with up to 18 whole digits and 8 decimal places. Pool reserves must be greater than zero.

Fee range: 0–10%, with up to 2 decimal places. Reserves must be positive; input may be zero.

Tolerance ranges from 0–100%, with up to 2 decimal places. A 100% tolerance allows a minimum of zero; it does not improve your quote.

The ordering example models one earlier A-to-B swap at the same fee. Set it to zero to compare with no earlier trade.

Edits stay in the calculator. A copied scenario link contains only the illustrative numeric settings.

Where the quote comes from

Let x and y be the reserves, a the input, f the input-fee fraction, and s the slippage tolerance. The fee stays in the pool. This is an illustrative Uniswap v2 style constant-product model, not a quote from a live exchange.

effective input = a × (1 − f)
output = floor₈[y × effective input / (x + effective input)]
new reserves = (x + a, y − output)
minimum output = floor₈[output × (1 − s)]
average execution rate = output / a
modeled retained fee = a × f
price impact = 1 − output / [effective input × y/x]

floor₈ means round down to eight decimal places. Price impact compares the received amount with the pre-trade reserve ratio after removing the input fee. The average execution rate includes the input fee. Output rounding is included; displayed percentages and ratios are rounded down too. The modeled fee can include fractions of a token unit because it describes the formula, not a separate fee transfer.

A worked example

Start with 100 A and 1,000 B, trade 10 A and charge 0.30%. Effective input is 9.97 A and the modeled retained fee is 0.03 A. Expected output is 90.66108938 B; the reserves become 110 A and 909.33891062 B. A 1% tolerance gives a minimum of 89.75447848 B. Raising tolerance changes only that minimum.

Input10 A
Output90.66108938 B

What this model leaves out

The base quote assumes no earlier trade; the ordering example adds exactly one same-direction swap. Neither includes gas charges, routes, transfer-tax tokens, rebasing tokens, hooks or external prices. All input reaches the pool; output is transferred exactly. Concentrated-liquidity pools have a different model. A real transaction may fail its minimum-output check or face ordering and contract risks.

Learn next: constant product pools · slippage and price impact · concentrated liquidity · maximal extractable value.

Inspect the model