Back to blog

DEX Aggregator Development Guide for 2026

Learn dex aggregator development for Solana: seven routing steps, fee math, slippage, failed swaps, and token-risk checks.

By Solana TrackerPublished 17 min read
DEX Aggregator Development Guide for 2026

In the fourth quarter of 2025, prop AMMs on Solana were approaching half of total DEX volume, The Block's research on onchain liquidity routing found. That single line should change how you think about dex aggregator development. If half the flow lives in specialized venues run by professional market makers, then the job isn't connecting more pools. The job is controlling what lands on chain.

A quote is a promise. A landed transaction is the payment. Everything between those two points, stale reserves, priority fees in lamports, a frozen token account, a blockhash that expired while the wallet prompt sat open, decides whether your users get the number they saw.

This walks through the build in the order a team ships it: the routing problem, the quote path, the fee and minimum-output math, failure classes with safe retries, and risk penalties that change a route instead of just decorating it.

Why One Pool Is the Wrong Swap

A single pool is a guess. It holds one curve, one fee tier and whatever depth its liquidity providers left behind, so it quotes the best price for a pair by coincidence at best. Traders learned this the expensive way, as volume spread across venues that all priced the same asset differently at the same moment.

The fix arrived in 2019, when 1inch's aggregator started comparing prices and liquidity across venues, calculating multi-hop routes and splitting a single order across pools, according to 1inch's account of how DEX aggregators developed. Aggregation stopped being a convenience and became the layer that decides where an order goes.

The diagram below shows the shape of the problem.

A diagram illustrating how a decentralized exchange routing engine aggregates liquidity from multiple pools for optimal trading.

Five curves, one pair

On Solana in 2026, the same SOL/token pair can be quoted by Raydium AMM v4, a Raydium CPMM pool, a Raydium CLMM band, an Orca Whirlpool, a Meteora DLMM bin and a Pump AMM curve. Each one charges different fees against different depth. The screens disagree because the math disagrees, not because one venue is lying.

Take a 50 SOL swap into a mid-cap token. One concentrated pool may show the best screen price at small ticket sizes, because its liquidity sits in a narrow band around the current tick. Push 50 SOL through it and the price walks up that band, so the fill lands worse than the poster number. A 70/30 split across that pool and a deeper constant-product pool often returns more after impact, even though the second pool looked worse at quote size.

That's the whole job. An aggregator is an execution optimizer that happens to display prices, not a price board that happens to execute.

Design rule: if your router can't lose to a single pool on some trades and win on others, it isn't routing, it's forwarding.

Why depth data belongs in the build

Concentrated liquidity makes the depth question unavoidable. The same pool can be deep at the current tick and empty two percent away, so a router that reads a single reserve number is reading fiction. Yield.ly's Uniswap V3 liquidity and yield data shows how much state one concentrated pool carries on Ethereum: active liquidity per tick range, fee tier, position-level yield. Your indexer needs equivalent fields kept fresh for Whirlpool and CLMM pools on Solana, and "fresh" is the load-bearing word. A reserve snapshot that's two slots old is already a rumor.

Depth is also only one input. A quote that wins on screen can still lose money on landing: reserves drift while the transaction waits in a wallet prompt, the priority fee in lamports needed to get it included eats the price advantage, or a token account flag kills the route entirely. Treat the displayed number as the opening bid. The route has to be chosen for what lands, and that means stale pools, fee pressure and account-level risk all move the allocation, not just the headline price.

How to Build the Quote Path

Routing is a loop that never finishes, not a function you call once. Every stage below exists because pool balances move between the moment a user types an amount and the moment a validator lands the transaction.

Seven stages from pool list to signed transaction

  1. Index each venue's state. Reserve balances, fee tier, token decimals, tick and liquidity ranges, account requirements, and program-specific constraints. A CLMM needs its initialized ticks, a DLMM needs its bins, a CPMM needs two reserves. One indexer, a different adapter per program.
  2. Normalize into one quote model. Every pool must answer the same question in the same units: given this input mint and amount, what comes back and at what cost? Once a Raydium CPMM and an Orca Whirlpool return the same shape, the search compares numbers instead of handling special cases.
  3. Build a token-pool graph. Tokens are nodes, pools are edges, and an edge only exists if the pool can accept and deliver that mint given current account state.
  4. Enumerate direct and multi-hop paths, then prune. Two-hop and three-hop routes through a small connector set (SOL, USDC, a couple of liquid majors) cover nearly everything useful. Drop any route another route already beats on output and total cost.
  5. Split the size across pools. At this step, a route stops being a line and becomes an allocation. Say you're moving 10,000 USDC into SOL. A direct Raydium SOL-USDC pool quotes one number, while a two-hop path through a deeper SOL-USDC CLMM quotes another. Split 80/20 between them only if the blended output still beats the best single venue after extra compute and account costs come off. If the second leg adds a hop and 15,000 compute units to win 3 basis points, it isn't a win.
  6. Re-quote immediately before the wallet signs. A quote that sat in a UI for eight seconds is a historical document. Refresh against current state and rebuild the transaction, not just the displayed number.
  7. Simulate the exact transaction against a recent bank state. Not a price estimate. The actual instruction list, accounts, and compute budget, run against a recent slot.

The cost of a stale reserve

Breadth without refresh is the classic failure, and it's been measured. An empirical audit of 2.98 million Ethereum swaps found an average realized routing shortfall of 2.02 basis points, equivalent to about $24 million in aggregate, with failure to activate additional pools identified as the dominant inefficiency. Read that as an engineering statement rather than a market statistic: the routers had venues available and didn't use them, because their view of liquidity was wrong or incomplete.

The dataset is Ethereum. The lesson ports to Solana unchanged. Seven pools with stale reserves route worse than three pools refreshed every slot.

A router that quotes from a five-second-old snapshot isn't optimizing. It's remembering.

Score the router on landed output

Measure at fixed trade sizes, on realized fills, and report these separately for liquid pairs and volatile ones:

  • Median shortfall: quoted output against landed output in basis points. Sub-5 basis points is a reasonable target for liquid pairs.
  • Tail shortfall: the 95th and 99th percentile, because that's where users get hurt.
  • Fill success: the share of submitted transactions that confirm.
  • Latency: quote time at p50 and p99, not one lucky request.
  • Compute and fees: units consumed and lamports paid per landed swap.

Volatile pairs deserve their own line in the report. Route quality degrades when state moves between quote and landing, and a blended average hides precisely that.

Set Fees and Minimum Output

Two numbers get confused constantly: what the network charges to include your transaction, and what the swap is allowed to return. One is a cost, the other is a floor. Mixing them produces either overpaid swaps or reverts you could have avoided.

Fee math for one landed swap

Every Solana transaction pays a base fee of 5,000 lamports per signature, split evenly with 50% burned and 50% paid to the validator. On top sits an optional prioritization fee, paid 100% to the validator and calculated as ceil(compute_unit_price × compute_unit_limit ÷ 1,000,000) lamports, per the Solana fee structure documentation.

Work the example. A routed swap simulates at a 200,000 CU limit and you set the price at 100 micro-lamports per CU. The priority fee is ceil(100 × 200,000 ÷ 1,000,000) = 20,000 lamports. Add the base fee for one signature and the network cost is 25,000 lamports before any price impact.

Component Formula or split Example
Base fee 5,000 lamports per signature; 50% burned, 50% to the validator 5,000 lamports
Priority fee ceil(price × CU limit ÷ 1,000,000) lamports; 100% to the validator 20,000 lamports (100 micro-lamports × 200,000 CU)
Total network fee Base plus priority for one signature, before price impact 25,000 lamports

Size the CU limit from simulation, never from a hardcoded ceiling. A single-hop Raydium swap and a three-hop split that creates two token accounts are different transactions, and paying for 1.4 million units you don't use is a donation to the validator. Raise the micro-lamport price when the landing slot is congested, not on a fixed schedule.

Setting minimum out from a fresh quote

Slippage is price protection, and it belongs downstream of the quote. If the quote returns 12.40 SOL, a 50 basis point tolerance sets minimum-out at about 12.338 SOL. That's the number written into the instruction, and it decides whether the swap reverts.

Don't ship one default across every pair. A liquid SOL-USDC route can sit at 10 to 30 basis points. A newly launched memecoin with one thin pool may need 100 to 300 basis points, or ordinary pool movement reverts it before any bot gets involved.

Slippage isn't only a revert trigger. On a public swap it's the ceiling on what a sandwich attacker can extract. Tight on a liquid pair is a defense, and loose on the same pair is an invitation.

Show both numbers on the confirm screen

Users compare fees and ignore floors, so place them side by side: priority fee in SOL, minimum tokens out in the output mint. Someone who sees 0.00002 SOL of priority cost next to a minimum-out sitting 4% under the quote understands that the cheap transaction may fill worse. Someone who only sees the fee doesn't. A cheaper fee can cost the fill, and the screen should say so before signing.

Retry Only Recoverable Swap Failures

Every retry costs the signer a fee, so the first question after a failure is whether resubmitting can fix it. Some errors clear on a fresh quote, others never clear at all, and telling them apart is the whole job.

A diagram illustrating a paper plane bouncing off a threshold with an automatic retry mechanism for transactions.

Solana carries a high share of failed transactions, and much of that failure is arbitrage spam: bots fire the same trade at the same slot until one version lands. QuickNode's guide to MEV on Solana describes how priority fees and bidding decide which competing transactions get in. Those network-wide counts cover every transaction type, from memecoin snipes to wallet transfers, so treat them as a stress envelope. They show how badly a pipeline can fail during congestion, and a well-built aggregator should land far above the chain average.

Classify before you retry

Retrying blindly is how a wallet pays three fees for zero fills. Read the error class first, then apply exactly one response. Each failure type is also information about the route: a slippage revert means the pool moved, and a state error means the quote went stale between simulation and landing.

Failure Usual cause Safe next move
Slippage revert Pool moved past minimum-out Re-quote and rebuild minimum-out, never resend the same transaction
Account or state change Pool or token account changed between quote and landing Rebuild instructions from fresh state
Compute exhaustion CU limit below simulated need Raise the limit and simulate again
Blockhash expiry Quote sat too long New blockhash only, then resubmit
Insufficient priority fee Congested slot Raise micro-lamports per CU and resubmit
Permanent simulation error Frozen token account or invalid state Stop and show the reason to the user

The permanent class is where builders err in both directions. A frozen token account will never succeed no matter how many times you resubmit, and hammering it burns fees while telling the user nothing. Name the reason in plain words and let the signer decide whether the trade is still worth attempting.

Treating every simulation failure as permanent loses recoverable fills. Treating none of them as permanent burns fees on trades that can't land.

Instrument the pipeline

Track quote-to-confirmation success by route, token, fee tier, congestion regime and wallet type. Submit through more than one RPC path so a single provider's bad slot doesn't look like a routing bug. A practical check separates the two causes: if three liquid SOL-USDC swaps fail in a quiet period, the defect sits in your transaction builder. Congestion explains a cluster of failures at 3 a.m. during a launch. It doesn't explain three failures at noon on a Tuesday.

Penalize Mint and Freeze Risk

A best price can still be a bad trade. A router can compute a mathematically optimal quote and still walk a user into a token that can't be sold tomorrow, which means token-level risk has to reach the route decision itself.

Read the authorities before you route

A Solana token mint can retain a mint authority and a freeze authority. The mint authority can create additional units and expand supply, while the freeze authority can freeze token accounts so holders can't transfer or burn what they own, as Solana's guide to creating a mint explains. Neither flag proves fraud. Both are concrete entry-risk signals, and a router that ignores them is quoting only half the trade.

Freeze risk is the sharper of the two. Only a mint that still holds freeze authority can freeze accounts, the FreezeAccount instruction moves an account from initialized to frozen, and a frozen account keeps its owner, mint and balance while being unable to receive, transfer or burn, per Solana's guide to setting authority. Authorities can be revoked permanently by setting them to None, and the current authority must sign that change. So an aggregator can distinguish two very different tokens instead of treating them as equivalent.

Two tokens, same price, different risk

Say Token A and Token B both quote roughly 1,000,000 units per 1 SOL.

Token Authority state Route treatment Quote
Token A Mint authority active; freeze authority active Kept with a warning and score penalty; downgrade reason shown About 1,000,000 units per 1 SOL
Token B Both authorities revoked Routed normally; wins over Token A only when the user asks for safer routing About 1,000,000 units per 1 SOL

Token A stays in the results. Deleting it looks like censorship and hides the reason from the person who needs it most. Show the route, print the downgrade reason (active mint, active freeze, or both), and let safer routing win when the user asks for it.

The quieter penalties

Two more signals belong in the same layer. Liquidity that can vanish: a pool holding a few thousand dollars of depth will move violently on your own order and may be drained right after it. Holder concentration: a cluster of wallets created in the same block owning most of the supply is a distribution profile, not a community.

Run mints through a scorer such as Rugcheck rather than hand-rolling the first version, and keep the score separate from the price. Solana processed about $364 billion in DEX volume during Q4 2025, according to Galaxy Research's Q4 2025 review, and that aggregate tells you nothing about whether one long-tail pool has durable liquidity.

Back-test your penalties against legitimate mints that keep an authority for a real reason, like a vesting schedule or a controlled burn. A false positive that hides a good token is as expensive as a missed rug, and it's easier to prove after the fact.

Quote One Pair Before You Scale

Do not index every Solana program in week one. Ship a thin path, measure it, then replace pieces only where the measurements say you're losing.

Start with a hosted router and one indexed data source. Our Raptor Swap API is a free hosted swap API across 71 Solana DEXes with JIT routing, and an optional self-hostable binary is available if the routing has to sit inside your own infrastructure. Pair it with our Data API, which exposes 70+ endpoints for tokens, wallets, trades, prices and risk scores, indexed and served in milliseconds, so token context and quotes come from the same system. Check current docs, rate limits and terms before you depend on any provider, ours included.

The two-swap go-live check

Venue count is not a launch criterion. Two swaps are.

  • Swap one, the liquid pair. Trade a fixed size of SOL into USDC and log quoted output, landed output, priority fee paid and the confirmation slot. If median shortfall misses the target you set for liquid pairs, fix the pipeline before adding anything.
  • Swap two, the risky pair. Quote a newly launched mint and confirm the mint and freeze warning appears next to the price. The token should still be quotable, with the reason for the downgrade visible.

Only after both pass should you add your own split logic and a second RPC path, and only for the routes where the hosted path misses fills or prices. Keep every replacement behind the same trade log, so the hosted route and the in-house route are compared on the same trades before traffic moves.

Build the scoreboard before the router. Teams that add venues without a landed-output log can't tell an improvement from a coincidence.


Solana Tracker gives you both halves of that build in one place: the Raptor Swap API for cross-DEX routing and transaction building, and the Data API for the token, pool, price and risk context a router needs before it commits to a route. Both are documented, keyed and ready to test against your own pair of go-live swaps this week. Visit Solana Tracker to pull a quote on a liquid pair and a newly launched mint, then compare what you were quoted with what landed on-chain.

More articles