Skip to content

Why should integrators cap BaseSwap swap slippage?

Set a minimum output from a fresh quote and pass it to the swap call; do not let a transaction accept any amount the pool returns. The minimum makes the trade revert if the pool price moves too far before execution, protecting users from unexpected execution while making the trade-off clear: a tighter limit can also cause more failed swaps.

What does a minimum output protect against?

A minimum output, often named amountOutMin in a V2-style router, is the least amount of the output token the transaction will accept. The router checks the actual result against this value during execution; if the result is lower, the whole swap reverts instead of silently completing at a worse price.

This check matters because a quote is only a snapshot of pool state. Another swap can change the reserves after your app requests a quote but before the user’s transaction executes. Integrators comparing router designs can use how BaseSwap handles swaps and pools to understand why the selected route and pool affect the quote they need to protect.

Slippage tolerance is the allowed difference between the quoted output and that minimum. It is not a fee, and it does not promise that a trade will execute at the quoted price; it defines when the user would rather have the trade fail.

How should you calculate the limit?

Calculate the minimum from the router’s quoted output, in the output token’s smallest units, using integer arithmetic. If a quote is 2,000 tokens and the user chooses an illustrative 0.5% tolerance, the minimum is 1,990 tokens. Pass that integer into the swap call; avoid rounding it up, which could make a valid trade revert.

For a V2 route, request a quote for the exact input amount and token path from the same pool state your app is using to prepare the transaction. A router or SDK quote accounts for the route’s pool fees and price impact; do not substitute a spot price or apply a fee percentage a second time. Price impact is the change caused by the trade’s own size, while slippage is the additional movement you allow between quote and execution.

Keep the tolerance a user-facing choice with a sensible default, not a hidden constant that grows when a trade fails. Deep pools and small trades can often use a tighter bound; thin pools, volatile pairs, or multi-hop routes may need more room. For example, 0.5% or 1% can illustrate choices in an interface, but neither is a universal setting for every pair.

What should the integration submit?

For an exact-input swap, the user decides how much input to spend and the minimum output they will accept. Build the transaction with the confirmed chain, router, token path, input amount, recipient, minimum output, and an expiry time. If the user has not approved the router to spend the input token, obtain the required allowance before submitting the swap.

  • Use the intended Base chain ID and a router address verified for that deployment.
  • Use token contract addresses, not symbols, to identify the path.
  • Set the minimum output from the quoted output and chosen tolerance.
  • Set a deadline that gives the user time to confirm but lets stale transactions expire.
  • Simulate or estimate gas for the assembled call before asking the wallet to sign.

The deadline and minimum output check different risks. A deadline limits how long a pending transaction remains valid; it does not cap the price movement. A transaction can execute before expiry at an unacceptable output unless the minimum is set correctly.

When can a correctly bounded swap still fail?

A swap can revert even when the displayed quote looked acceptable: a prior transaction may have moved the pool, the quote may be stale, or the route may not support the token’s transfer behaviour. Tokens that charge a transfer tax can deliver less to a pool or recipient than a standard quote predicts. Check whether the deployed router offers a fee-on-transfer-compatible method, and test against that token before claiming support.

For a real integration, imagine a portfolio app selling 1,000 units of a volatile token into a stablecoin. It should fetch a route quote, show the estimated stablecoin output and minimum, then submit the bounded exact-input call. If the market moves past the user’s limit, the app should report a slippage failure and offer a refreshed quote rather than retrying automatically with a looser bound.

BaseSwap integrations should derive limits from the current route and retain the user’s chosen tolerance through signing. My practical tip: log the quoted output, minimum output, route, and failure reason for each reverted swap; that record helps distinguish a stale quote from a poor route or an unsupported token.