A DEX aggregator is a blockchain-based routing service that monitors prices and available liquidity across multiple decentralized exchanges and determines how a trade should be executed in order to obtain the best possible outcome. In particular, an aggregator may split a single order across several AMMs rather than route the full order to a single pool. This is often advantageous because the price impact of a trade depends on pool depth, so distributing the trade across multiple venues can improve the effective execution price.
To illustrate this mechanism, consider the following simplified problem. Suppose that a trader wants to sell a total amount T of token X across two different constant-product pools in order to receive as much token Y as possible. For j∈{1,2}, let
xj,yj
denote the reserves of tokens X and Y in pool j, respectively, and let
ϕj∈[0,1)
be the trading fee of pool j. Define, for convenience,
λj:=1−ϕj.
Suppose that the trader sends an amount u∈[0,T] of token X to pool 1 and the remaining amount T−u to pool 2. Then, by the fee-adjusted constant-product formula, the amount of token Y received from pool 1 is
Applying the quadratic formula, the roots of g are
u1≈−86881.3085,u2≈884.4477.
Since the leading coefficient of g is negative, it follows that g(u) is positive on the interval (u1,u2) and negative on (−∞,u1)∪(u2,∞). Because u2∈[0,1500], we conclude that F is strictly increasing on [0,u2] and strictly decreasing on [u2,1500]. Hence, the unique maximizer on [0,1500] is
u⋆≈884.4477.
Therefore, the optimal routing is:
send
884.4477 CTN
to pool 1,
send
1500−884.4477=615.5523 CTN
to pool 2.
The corresponding outputs are
Δy1(u⋆)≈2,740,995.2719 USDC,
and
Δy2(u⋆)≈1,809,765.8129 USDC.
Thus, the maximum total output is
F(u⋆)≈4,550,761.0848 USDC.
For comparison, if the entire trade were executed only in pool 1, the trader would receive
F(1500)≈4,312,842.0929 USDC,
whereas if the entire trade were executed only in pool 2, the trader would receive
F(0)≈4,039,581.2491 USDC.
Hence, splitting the order optimally across both pools yields a substantially better execution than routing the whole trade to either single pool.
This example makes clear why DEX aggregators are valuable. In order to identify the optimal split, one must know the current state of each pool and perform a nontrivial optimization. Aggregators automate this entire procedure and thereby allow users to obtain better prices without carrying out these computations manually.