Skip to main content

Routing and Quotes

A robust router evaluates executable routes rather than choosing a pool by TVL alone. The largest pool is not always the best price, and the best quoted price is not always executable.

Candidate discovery

  1. Fetch live pools and exclude unsupported or inactive factories.
  2. Keep pools containing the input token, output token or an approved connector asset.
  3. Model tokens as graph vertices and pools as edges.
  4. Support parallel edges, because the same pair can have stable, volatile and multiple concentrated pools.
  5. Search direct and bounded multi-hop paths; a maximum of three pool hops is a common practical limit.

Quote evaluation

For each candidate path:

  • call the compatible quoter with the exact input;
  • discard reverting or zero-output quotes;
  • estimate gas where practical;
  • validate token behaviour;
  • compare final output after fees and estimated execution cost;
  • select the route that best matches the application's objective.

The pool with the most liquidity can produce a worse quote than a smaller pool with a more appropriate curve, active range or fee setting.

Mixed routes

A mixed route can traverse basic and concentrated pools. Its encoded path must preserve logical token direction even when that direction is opposite to a pool's internal token0/token1 order.

Never copy route-type constants from another deployment without checking Raphael's router and quoter implementation.

Execution

Once a route is selected:

  1. derive the minimum output from the user's slippage tolerance;
  2. request only the required token approval;
  3. set a short, reasonable deadline;
  4. simulate the exact call;
  5. submit through the correct Raphael router;
  6. confirm the receipt and actual output.

Refresh stale quotes. A quote is not a reservation of pool state; it is a snapshot of one block that the next block may contradict.