Documentation Index
Fetch the complete documentation index at: https://docs.raydium.io/llms.txt
Use this file to discover all available pages before exploring further.
The router does no math
The routing program does not implement any pricing logic. It is a pure orchestrator: it accepts a route, passes accounts to child programs, and chains token flows. Each hop prices off its own pool program’s curve:- AMM v4 hops: use the constant-product formula (
x · y = k) with OpenBook hybrid pricing. Seeproducts/amm-v4/math. - CPMM hops: use the constant-product formula with configurable fee tiers. See
products/cpmm/math. - CLMM hops: use concentrated-liquidity tick math. See
algorithms/clmm-math. - Stable hops: use the stable-swap curve for like-kind assets. See
products/stable/math.
- Calling each pool’s swap instruction via CPI.
- Collecting the output amount.
- Passing it as the input amount to the next hop.
- Checking the final output against the caller’s slippage limit.
Slippage compounding
On a multi-hop route, slippage at each hop compounds. A small slippage on hop 1 becomes a larger slippage on hop 2 because the volume into hop 2 is already reduced. Example:minimum_amount_out, the router checks your final output against this global limit. Each hop also checks its own swap against its local fee structure, but the router does not re-quote mid-route—you must pre-compute the route and bake in enough slippage tolerance.
CLMM hops and limit_prices
For each hop into a CLMM pool, the router checks that the pool’s currentsqrt_price_x64 is within a specified bound. The bounds are passed as a VecDeque<u128> called limit_prices:
- One
sqrt_price_x64per CLMM hop in the route. sqrt_price_x64is the tick-based price representation used by CLMM. Seealgorithms/clmm-mathfor the definition.- The router enforces:
Instruction variants and limit_prices
-
SwapBaseInWithUserAccount,SwapBaseOutWithUserAccount(Legacy, tags 0 and 1): thelimit_pricesVecDeque is required. An empty deque is rejected with an error if any hop is a CLMM pool. You must provide one price per CLMM hop, in order. -
SwapBaseIn,SwapBaseOut(Current, tags 8 and 9): thelimit_pricesVecDeque is optional. An empty deque is silently ignored; no price check is performed. New code should use these.
Building limit_prices
For a route with M CLMM hops, the deque should contain exactly M entries. Order them by hop:When to check limit_prices
Thesqrt_price_x64 is a snapshot of the pool’s current price. It changes continuously as swaps execute. You should:
- Fetch the pool’s current state from on-chain.
- Compute acceptable bounds (e.g., ±0.5% of the current price).
- Encode those bounds into
limit_prices. - Include the bounds in your router instruction.
Fee handling
Each pool charges its own fee according to its configuration:- AMM v4: 0.25% (fixed) split between LP, protocol, and fund.
- CPMM: configurable per
AmmConfig(default 0.25%, split varies by tier). - CLMM: configurable per pool, taken off the input amount.
- Stable: like AMM v4, 0.25% split.
products/amm-v4/feesproducts/cpmm/feesproducts/clmm/fees(if available)products/stable/fees(if available)
Multi-hop accounting example
Suppose you route USDC → SOL → STEP across two constant-product pools, each with a 0.25% fee:Precision considerations
Like all Solana programs, the router uses integer arithmetic:- All amounts are
u64(lamports or token smallest units). - Curve calculations use
u128intermediates where needed to avoid overflow. - Rounding conventions depend on the child program. The router does not re-round.
Where to go next
products/amm-v4/math— constant-product math.products/cpmm/math— CPMM constant-product with Token-2022.algorithms/clmm-math— concentrated liquidity pricing.products/stable/math— stable-swap curve.products/routing/code-demos— examples of quoting before routing.


