Developer Platform

BlogDocsSign In

Blog/Deep Dive

The Anatomy of a Swap

The Anatomy of a Swap
Siyu WeiSiyu Wei·March 11, 2026·6 min read

When you call the Jupiter swap API, the response comes back in under a second. A quote appears, you confirm it, and tokens move from one wallet to another. It feels instantaneous — almost trivially simple. But between your request and the final settlement, a remarkable amount of computation happens, and understanding it will make you a better integrator.

Route discovery

It starts with discovery. The moment a quote request arrives, the routing engine fans out across every liquidity source it knows about — AMMs, CLMMs, order books, and more. Each source is a pool of tokens sitting in a smart contract, and each has its own pricing curve. A constant-product pool prices things differently than a concentrated liquidity pool, which prices things differently again from an order book with discrete price levels. The engine queries all of them simultaneously, building a map of every possible path from your input token to your output token.

This is where it gets interesting. For a simple pair like SOL to USDC, there might be dozens of direct pools to choose from. But for a less common token — say, a recently launched memecoin — there might be no direct path at all. Instead, the engine discovers multi-hop routes: your token to SOL, then SOL to USDC. Or perhaps your token to USDT through one pool, then USDT to USDC through another. The number of possible paths grows combinatorially, and the engine has to evaluate all the promising ones to find the best price.

Split routing and price impact

Finding the best single path is only the beginning. The real power of the routing engine is split routing — dividing your trade across multiple paths simultaneously. Imagine you're swapping 10,000 USDC for SOL. If you push all of that through a single pool, you'll move the price against yourself significantly. The larger the trade relative to the pool's liquidity, the worse your execution price becomes. This is called price impact, and it's the enemy of large trades. Split routing fights price impact by distributing your trade. Maybe 60% goes through Raydium's concentrated liquidity pool where the liquidity is deepest, 25% through Orca's CLMM, and the remaining 15% through a smaller pool that still has favourable pricing at that size. The engine optimises this split to minimise your total price impact — a constrained optimisation problem that it solves in milliseconds.

The quote

Once the optimal route is determined, the engine returns a quote. This quote contains the expected output amount, the price impact percentage, the fees charged by each pool along the route, and the minimum output amount accounting for slippage. Slippage tolerance is your safety net — it defines the worst price you're willing to accept, and if the actual execution price falls below it, the entire transaction reverts. Setting it too tight means your transactions fail frequently; setting it too loose means you might get a worse price than expected. For most trades, 0.5% to 1% is a reasonable default, though volatile tokens might need more.

The quote also includes a serialised transaction, or more precisely, a set of instructions ready to be signed. This is a critical design choice. Rather than having the user construct the swap transaction themselves — figuring out which programs to call, in what order, with what accounts — the API hands back a ready-to-sign transaction. The integrator just needs to deserialise it, sign it with the user's wallet, and submit it to the network. This dramatically reduces integration complexity and the surface area for bugs.

Signing and submission

Signing and submission is where the client takes over. The serialised transaction gets deserialised into a versioned transaction object, signed with the user's keypair, and sent to an RPC node. From here, the transaction enters Solana's pipeline — the RPC node forwards it to the current leader validator, which includes it in a block. The swap instructions execute atomically: either all of them succeed, or none of them do. There's no state where you've sent tokens to the first pool but the second hop failed, leaving your funds stranded. Atomicity is guaranteed by the runtime.

Confirmation and finality

After the transaction lands on-chain, there's still the question of confirmation. Solana uses a probabilistic finality model — a transaction is "processed" when it's included in a block, "confirmed" when a supermajority of validators have voted on that block, and "finalised" when enough subsequent blocks have been built on top. Most applications treat "confirmed" as sufficient, since the probability of a rollback at that point is vanishingly small. But if you're building something where absolute certainty matters — say, a payment system — you might want to wait for finality.

Timing and priority fees

The entire journey, from quote request to confirmed transaction, typically takes 2-4 seconds on a healthy network. About 400 milliseconds for the quote computation, a few hundred milliseconds for client-side signing, and the rest is network propagation and block inclusion. During periods of network congestion, the transaction submission step can take longer, and this is where priority fees come in. The API lets you specify a priority fee to incentivise validators to include your transaction sooner. Think of it as a tip — optional during quiet times, but valuable when every block is full.

Exact-in vs exact-out

There's one more piece worth understanding: the difference between exact-in and exact-out quotes. An exact-in quote takes your input amount and tells you how much output you'll receive. An exact-out quote does the reverse — you specify how much output you want, and the engine calculates how much input is needed. Exact-out is less common but useful for specific use cases, like paying an invoice denominated in a particular token. The routing engine handles both, though exact-out requires iterative computation and is slightly less precise due to rounding.

All of this — the multi-source discovery, the split route optimisation, the serialised transaction construction — happens behind a single API call. That's the point of the platform: to collapse an enormously complex problem into a simple interface. But knowing what happens underneath helps you build better. You'll understand why large trades have higher price impact, why your transaction might fail during congestion, why the quote you received differs slightly from the execution price, and how to tune parameters like slippage and priority fees for your specific use case. The abstraction is there to serve you, not to hide from you.


Siyu Wei

March 11, 2026