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
- Quote DeDust and StonFi in parallel for the full
amountIn. Whichever returns a higheramountOutis the single-DEX baseline. - 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. - Compare the best split to the baseline. The split wins iff:
splitOutput > bestSingleOutput + extraGasInOutputUnitsextraGasInOutputUnits 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 size | DeDust solo | StonFi solo | Best route | Split share |
|---|---|---|---|---|
10 TON | 24.24 USDT | 24.20 USDT | DeDust 1-leg | — |
100 TON | 242.7 USDT | 242.2 USDT | DeDust 1-leg | — |
1k TON | 2,415 | 2,420 | 2,422 (split) | SF 80% / DD 20% |
10k TON | 22,902 | 24,040 | 24,060 (split) | SF 88% / DD 12% |
100k TON | 153,716 | 225,293 | 227,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.