Swap / DEX·Solana
Raydium
Solana's flagship AMM with constant-product (AMM v4 / CPMM) and concentrated-liquidity (CLMM) pools, plus farms. Routes liquidity to OpenBook for hybrid order-book + AMM execution.
- 01Solana swaps against deep AMM/CLMM liquidity
- 02creating CPMM or CLMM pools
- 03providing concentrated liquidity positions
- 04farm staking and reward harvesting
- 05memecoin and long-tail pool creation
- pnpm add @raydium-io/raydium-sdk-v2 @solana/web3.js bn.js decimal.js
| Variable | Scope | Description |
|---|---|---|
| SOLANA_RPC_URL | Server | Solana RPC endpoint (Helius, QuickNode, Triton). Public mainnet-beta is rate-limited and unreliable for Raydium SDK calls. |
Use `@raydium-io/raydium-sdk-v2`. Initialize with `Raydium.load({ connection, owner, cluster: 'mainnet', disableFeatureCheck: true })`. For swaps, fetch a pool via `raydium.api.fetchPoolById({ ids })` or compute routes with `raydium.tradeV2.getAllRoute()` then `raydium.tradeV2.computeAmountOut()` and `raydium.tradeV2.swap()`. For CLMM positions use `raydium.clmm.openPositionFromBase()` / `increaseLiquidity()` / `decreaseLiquidity()`; for CPMM use `raydium.cpmm.addLiquidity()` / `swap()`. Always pass `txVersion: TxVersion.V0` to get versioned transactions and call `.execute({ sendAndConfirm: true })` or sign and send the returned `transaction` yourself with priority fees set via `computeBudgetConfig`.
- ⚑Raydium SDK v2 returns large versioned transactions with address-lookup tables — you must use `VersionedTransaction` and a wallet adapter that supports v0 txs.
- ⚑Pass `computeBudgetConfig: { units: 600_000, microLamports }` to every CLMM/CPMM tx — defaults are too low and the tx will fail with `ComputeBudgetExceeded` under load.
- ⚑Set priority fees dynamically (Helius `getPriorityFeeEstimate` or Jito tip) — without them txs routinely time out during congestion and you pay slot-skip risk.
- ⚑CLMM positions are NFT-backed; closing requires burning the position NFT in the same tx as `closePosition` or it leaks rent.
- ⚑Pool ID lookups via `raydium.api` hit Raydium's hosted API and are cached — use `fetchPoolById` with `forceRefresh` after creating a pool, otherwise it returns stale or 404.
- ⚑Token-2022 mints with transfer hooks are only supported on CPMM (not legacy AMM v4); confirm pool type before quoting.