DeFi Integrations Best Practices
A condensed summary of the 25 most important DeFi integration practices drawn from every page in this section.
Search across all documentation pages
A condensed summary of the 25 most important DeFi integration practices drawn from every page in this section.
Allowlist mint pubkeys: Never trust ticker strings - hard-code mainnet mints in config (DeFi Basics).
Re-quote before send: Jupiter quotes expire in seconds - fetch fresh quote immediately before swap (Swaps with Jupiter).
Set explicit slippage: Default 50 bps for liquid pairs; raise for thin pools - log chosen slippageBps per tx.
Simulate every mainnet tx: Use RPC simulateTransaction or Surfpool 0.12.0 fork before spending SOL.
Use dynamic compute limits: Multi-hop swaps exceed 200k CU - enable Jupiter dynamicComputeUnitLimit or set budget ix.
Handle wSOL explicitly: Enable wrapAndUnwrapSol or manage wSOL ATA lifecycle manually.
Validate pool program IDs: Direct AMM CPIs must check pool owner matches Raydium/Orca/Meteora program (AMMs).
Read reserves at execution: Client previews use stale state - simulate or read on-chain reserves in same slot.
Check oracle staleness: Lending and perps must fail closed when Pyth/Switchboard age exceeds threshold (Oracles).
Separate LTV and liquidation: Display max borrow LTV and liquidation threshold with safety buffer (Lending).
Track LST exchange rates: Never assume 1 LST = 1 SOL - read stake pool rate (Liquid Staking).
Allowlist LST mints: Reject unknown stake pool tokens - scams mimic jitoSOL tickers.
Bundle under contention: Large swaps on mainnet use Jito bundles or private RPC (Jito & MEV).
Cap price impact: Abort swaps when priceImpactPct exceeds product policy.
Use versioned transactions: DeFi routes need ALTs - legacy tx formats hit account limits.
Priority fees on mainnet: Set prioritizationFeeLamports from fee oracle during congestion.
Test on mainnet fork: Devnet liquidity is thin - Surfpool 0.12.0 for realistic Jupiter routes.
Log route plans: Persist routePlan JSON for incident debugging and user support.
Isolate leverage loops: Borrow-swap-deposit chains fail atomically - model end-state health before submit.
Perp oracle marks: Liquidations use oracle price, not last trade (Perps).
Tick/lot integers only: CLOB prices are ticks - no JavaScript float math in production paths.
Monitor receipt token balances: Lending deposits may return cTokens - track correct mint for withdrawals.
Rate-limit quote API: Backoff on HTTP 429 from Jupiter; cache quotes < 5s only.
Fail closed on CPI errors: Propagate program errors - never swallow failed DeFi CPI in your program.
Document venue risk: Disclose smart contract, oracle, and depeg risks per integrated protocol in UX copy.
50 bps is a common default; tighten for size-dependent impact checks using priceImpactPct.
Optional for large trades; priority fees alone may suffice for small swaps.
Surfpool fork with cloned user ATAs and pool state - not bare devnet for routing tests.
Stale quotes and missing slippage checks - causes failed txs or bad fills.
Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.
Reviewed by Chris St. John·Last updated Jul 16, 2026