Routing & splitting

For each swap, chop quotes both DEXs at the full size in parallel, then runs a grid search over possible 50/50 → 99/1 splits. The route with the highest output (after gas) wins.

The decision

  1. Quote DeDust and StonFi in parallel for the full amountIn. Whichever returns a higher amountOut is the single-DEX baseline.
  2. For α ∈ {1/N, 2/N, …, (N-1)/N} (default N=20), quote DeDust at α·amountIn and StonFi at (1−α)·amountIn. Keep the allocation with the largest combined output.
  3. Compare the best split to the baseline. The split wins iff:
text
splitOutput  >  bestSingleOutput  +  extraGasInOutputUnits

extraGasInOutputUnits is the additional gas a 2-leg route consumes (StonFi’s gas + DeDust’s gas − the baseline DEX’s gas) converted to the output asset using the prevailing rate. If the gain doesn’t cover gas, chop returns a single-DEX route.

Why a grid search?

The optimal allocation between two CPMM pools has a closed form, but TON pools include fees, multiple curve types (volatile vs stable), and pool depths that move between probes. A grid is robust against all of that and 20 probes complete in well under a second.

You can pass a smaller slippageBps to tighten min-out limits, but the grid resolution itself isn’t configurable from the public API.

What the data looks like

Live behavior on the TON/USDT pair, May 2026:

Order sizeDeDust soloStonFi soloBest routeSplit share
10 TON24.24 USDT24.20 USDTDeDust 1-leg
100 TON242.7 USDT242.2 USDTDeDust 1-leg
1k TON2,4152,4202,422 (split)SF 80% / DD 20%
10k TON22,90224,04024,060 (split)SF 88% / DD 12%
100k TON153,716225,293227,121 (split)SF 88% / DD 12%

Below ~100 TON, splitting’s output gain doesn’t clear the gas cost of a second leg, so chop stays single-DEX. Above that, the depth difference between pools makes a split materially better.

Wallet message limits

TON wallet v4 broadcasts at most 4 outgoing messages per external message — that’s our hard ceiling on number of split legs. Wallet v5 raises it. With two DEXs we’re always at ≤ 2 legs, so this only matters as more DEX adapters are added.