Routing & execution

Thinking about DEX liquidity as a routing graph

Model tokens as nodes and executable markets as directed connections to understand routes, parallel venues and capacity limits.

A routing graph represents assets as nodes and executable exchanges as connections. It helps explain how a router finds direct and indirect paths, but a usable swap needs more than a connected line: each connection has amount-dependent terms.

Build a small hypothetical network

Suppose markets connect A/B, A/C and C/B. There is a direct A-to-B option and an indirect A-to-C-to-B option. If two independent A/B pools exist, they are parallel market connections between the same assets.

Direction matters. A-to-B and B-to-A use different input and output reserves and can produce different finite-size behavior. The graph should therefore preserve the direction of the proposed trade.

Research on efficient CFMM routing treats markets as parts of a network whose trades combine into a net asset result. The graph here is a simplified conceptual representation of that broader optimization problem.

Edges do not have fixed travel distances

Unlike a road map with a fixed distance, a pool connection changes its effective rate with the amount flowing through it. A path that looks favorable for one unit can lose to another at a larger amount.

Paths can also interact. If two branches use the same pool, their flows are coupled through that pool's state. They cannot both claim independent access to the original reserves.

Constraints remove possibilities

A hop limit excludes paths that are too long. A source filter removes particular venues. An intermediary-token restriction removes certain connecting nodes. After those changes, a route can disappear even though the unrestricted graph remains connected.

For native-asset wrapping and cross-chain delivery, the graph needs operations with different semantics from ordinary pool swaps. A convenient diagram should not erase those distinctions.

The graph model is most useful for explaining route structure and restrictions. To evaluate the result, attach the actual size-dependent output, fee rules and execution conditions to each selected operation. Connectivity answers whether a path exists; quoting answers whether that path can deliver the required trade.

Sources & verification (3)

Source-check date is recorded in the article details. URLs are provided for manual verification. Use Copy to keep this page open.

  1. An Efficient Algorithm for Optimal Routing Through Constant Function Market Makers

    Network routing, utility objectives and optimization under CFMM constraints.

    https://arxiv.org/html/2302.04938v1
  2. Multi-hop Swapping

    Sequential token paths and reverse requirements for exact-output swaps.

    https://developers.uniswap.org/docs/protocols/v3/guides/swapping/multi-hop-swapping
  3. Uniswap smart-order-router: alpha-router.ts

    Candidate-pool selection and configurable hop and split limits.

    https://github.com/Uniswap/smart-order-router/blob/main/src/routers/alpha-router/alpha-router.ts

Continue reading

Why the best route changes with trade size Why split routers compare marginal output What does best mean to a swap router?