Fees & trade costs

Compare swaps when the offered input amounts differ

Normalize unequal swap offers to a common output quantity and distinguish a better rate from a lower total acquisition cost.

Quotes with different input amounts cannot be ranked by output quantity alone. Decide whether the goal is to spend the same amount or receive the same amount, then request matching quotes. A per-unit rate can diagnose a difference but may not remain available at a different size.

An unequal-size example

Suppose hypothetical Offer A spends 100 stablecoins and returns 20 tokens. Offer B spends 120 stablecoins and returns 24.1 tokens. B returns more tokens, but it also spends more input.

The average input cost per output token is 5.00 for A and approximately 4.97925 for B. B has a slightly better average rate at its quoted size. That does not establish that B would offer the same rate for A's 100-unit budget.

Ask the matching question

For a fixed 100-unit budget, request both offers for 100. For an acquisition of exactly 20 tokens, request required input for 20 from each supported route. Include separate charges afterward on matching terms.

Average execution price is tied to a specific trade's sent and received quantities. Scaling an AMM quote proportionally assumes away the size effects that the comparison is supposed to measure.

Handle unsupported matching requests

If exact-output quoting is unavailable, a series of input quotes can bracket the amount required. Report the bracket and any excess output instead of pretending you obtained an exact match. Do not submit trades merely to perform this comparison.

Where one offer includes an added input fee, include it in the spending amount before computing a rate. Where output is gross before a deduction, use net received quantity. A useful comparison table lists total input spent, final output, separate charges and the fixed constraint. Those fields reveal whether an apparent advantage comes from a better offer or simply a larger transaction.

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.

  1. Pricing with the v2 SDK

    Distinction between mid price and average execution price.

    https://developers.uniswap.org/docs/sdks/v2/guides/pricing

Continue reading

Build a fair scorecard for comparing repeated swap outcomes Measure costs when only part of an intended trade completes Convert swap costs into basis points without losing the denominator