Use a router quote to estimate execution, then enforce a separately calculated minimum output on-chain; refresh both from the same recent pool state before signing. The quote describes what the trade could return at that snapshot, while the minimum sets the least the transaction may accept when it executes.
A quote estimates output from pool state
For a V2-style constant-product pool, the quote applies the pool fee and reserve ratio to the input amount. With the common 0.30% fee, a hop’s estimate is floor(amountIn × 997 × reserveOut / (reserveIn × 1000 + amountIn × 997)); use the fee multiplier configured for the actual deployment.
For a route with multiple pools, apply that calculation hop by hop, using each hop’s estimated output as the next hop’s input. Integrators can call the router’s quote method or reproduce the library calculation, but should read reserves at one block and use the same factory, fee model, token order, and path as the swap. A quote for a pool that does not exist, has zero reserves, or uses different fee logic is not executable truth.
A quote is useful for presenting expected output and comparing routes; QuickSwap is where a user can execute a token swap against available pool liquidity. Keep those roles distinct in the integration: your displayed estimate can age while the transaction waits, so the contract call needs its own bound.
The minimum output bounds execution
For exact-input swaps, set amountOutMin from the quoted output and a slippage tolerance in basis points: floor(quoteOut × (10,000 − toleranceBps) / 10,000). At 100 bps, a quote of 500 units produces a minimum of 495; the router reverts if the actual output falls below that threshold.
The quote already reflects the trade’s price impact against the sampled reserves and the pool fee. Slippage tolerance covers the additional movement between that sample and execution; it does not cap total loss against an external market price. A loose tolerance raises the chance of execution after adverse movement, while a tight one increases reverts during volatile blocks or congested submission periods.
For exact-output swaps, the counterpart is amountInMax, derived by increasing the quoted required input by the chosen tolerance and rounding up. Do not apply the exact-input formula to this trade type: the bound is on input, not output. In either case, reject zero or nonsensical bounds rather than silently sending an effectively unprotected transaction.
Derive and submit both values as one decision
Suppose a user offers 2,000 input tokens and the selected route quotes 500 output tokens. With a 75-bps tolerance, compute a minimum of 496 tokens after integer flooring, encode that value with the exact route and recipient, then simulate the call against recent state before asking the wallet to sign.
Refresh the quote if the pool state has moved materially or the transaction has been pending long enough that the displayed estimate is misleading. A short deadline, often around 10–20 minutes in wallet flows, limits how long an old transaction remains executable, but it does not replace amountOutMin: the deadline only checks time, not price. For integrations with tighter execution needs, use a shorter deadline and refresh or cancel stale transactions where the wallet supports it.
Token behavior can invalidate a normal quote
Fee-on-transfer tokens may deliver less than the nominal input to the first pair, so a standard exact-input quote can overstate output and the ordinary router path can revert. A compatible “supporting fee-on-transfer” method measures the amount received at execution; confirm the specific router exposes it and understand that transfer taxes can change between quote and execution.
Also account for integer rounding at every hop, rebasing or otherwise non-standard token balances, and the possibility that a pool’s reserves change before inclusion. QuickSwap deployments can differ by network and router generation, so bind your ABI and fee assumptions to the deployed contracts you target instead of treating a familiar method name as proof of identical behavior.
- Read reserves and quote the exact route at a consistent block.
- Calculate amountOutMin for exact input or amountInMax for exact output.
- Simulate the encoded call, then refresh if state or submission delay makes the quote stale.