AgentSkillsCN

solana-arb

Solana套利工程——Jupiter集成、MEV防护与利润优化。

SKILL.md
--- frontmatter
name: solana-arb
description: Solana arbitrage engineering — Jupiter integration, MEV protection, and profit optimization

What I do

  • Guide Jupiter v6 API integration for quoting, routing, and swap execution
  • Document arbitrage opportunity detection and profit calculation with failure economics
  • Define MEV protection strategies with Jito bundles and anti-sandwich patterns
  • Provide bot architecture patterns, monitoring, and honest testing strategies

When to use me

Use this skill when building trading bots or arbitrage systems on Solana. Pair with solana-core for transaction construction and RPC patterns, rust-pro for Rust engineering, and perf-rust for hot-path optimization.

Jupiter v6 Integration

  • Quote API: GET /quote with inputMint, outputMint, amount, slippageBps
  • Swap API: POST /swap with quoteResponse and userPublicKey
  • Route selection: ExactIn vs ExactOut. Use maxAccounts to constrain tx size. onlyDirectRoutes is faster but may miss better multi-hop routes.
  • Direct AMM integration: interact directly with Raydium/Orca/Phoenix pool programs for lower latency (skip Jupiter API round-trip)
  • Concurrent quoting: tokio::task::JoinSet to quote multiple routes simultaneously

Arbitrage Opportunity Detection

PatternDescriptionComplexity
Triangular arbA->B->C->A on a single DEXMedium
Two-leg arbBuy DEX1, sell DEX2Low
Cross-pool divergenceSame pair, different poolsLow

Decision tree: Is an opportunity real?

code
Price discrepancy detected
  -> Is quote < 2 slots old? NO -> discard (stale)
  -> Does simulated profit > all-in costs? NO -> skip
  -> Is the route still valid? NO -> re-quote
  -> Execute

Latency matters: the first bot to land the transaction captures the opportunity.

Latency Budget Framework

PhaseBudgetTypicalOptimization
Detection<50ms100msGeyser stream vs polling
Quoting<30ms80msLocal route calc vs Jupiter API
Simulation<20ms50msCached simulation, skip when confident
Submission<50ms100msJito bundle vs direct RPC
Confirmation<400ms800msStake-weighted confirmation
TOTAL<550ms1130msTarget: sub-second end-to-end

Methodology: measure each phase with std::time::Instant, log p50/p95/p99, optimize the widest phase first (same principle as perf-core).

Profit Calculation

Cost ComponentHow to CalculateTypical Range
Base fee5000 lamports/signatureFixed
Priority feecompute_units x unit_price1K-1M lamports
Slippagequote_amount - actual_received0.1-2%
Token account rentIf creating new ATAs0.002 SOL
Failed tx costbase_fee + priority_fee (lost)Full cost, zero revenue
RPC costPer-request pricingProvider-dependent

Failed Transaction Economics

Solana arb failure rate: ~30-40% of transactions fail (dropped, expired, front-run). Model this as a first-class business metric.

  • Expected profit = (gross_profit x success_rate) - (tx_cost x total_attempts)
  • A bot with 60% success rate and 0.001 SOL/tx cost needs >0.0017 SOL gross profit per trade to break even
  • Track failed tx cost as a first-class P&L metric

Atomic Execution & Jito Bundles

  • Atomic execution: all swap instructions in a single transaction -- all succeed or all revert. Order: compute_budget_ix -> swap_ix_1 -> swap_ix_2
  • Jito bundles: submit transactions as an atomic bundle to the Jito block engine. Use when gross_profit > tip_amount AND trade is sandwichable.
  • Tips: check Jito tip floor for minimum viable tip. Use Jito's published tip account addresses. Competitive tips for high-value trades.
  • Searcher API: gRPC connection to Jito block engine for bundle submission

Risk Management

RiskDetectionMitigation
Stale quoteTimestamp > 2 slots oldMax quote age, re-quote before execute
Sandwich attackUnusual slippage on landed txJito bundles, tight slippage limits
Failed transactionSimulation returns errorPre-simulate every transaction
Inventory riskToken balance drifts from targetAuto-rebalance at threshold
Network congestionSlot skip rate > 5%Dynamic priority fees, pause trading
Smart contract riskPool program upgradeMonitor program upgrade authority

MEV Defense Checklist

  • Use Jito bundles for all trades above minimum profit threshold
  • Set per-route slippage limits (not a global default)
  • Never broadcast swap intent via public mempool
  • Verify tip amount covers bundle inclusion probability
  • Monitor for unusual slippage patterns indicating adversarial activity
  • Implement circuit breaker: stop trading after N consecutive losses
  • Use separate fee-payer keypair from main trading keypair

Bot Architecture

Async event loop: stream(account_updates) -> filter(price_divergence > threshold) -> quote(jupiter OR direct_amm) -> simulate -> execute(jito OR direct_send)

  • Concurrent quoting: tokio::task::JoinSet for multiple routes simultaneously
  • State management: track in-flight transactions (avoid double-execution), cooldown per pool pair
  • Graceful shutdown: drain in-flight transactions, log final P&L, do not open new positions

Testing Strategies

EnvironmentWhat It ValidatesWhat It DOESN'T Validate
localnet (solana-test-validator + cloned state)Tx construction, instruction ordering, error handlingReal latency, competition, actual liquidity
DevnetBasic API integration, account creationArb profitability (no real liquidity or competition)
Mainnet paper tradingReal prices, latency, competitionExecution (observe but don't trade)
Mainnet live (small size)EverythingScale (start with minimum viable trade size)

The Devnet Lie: devnet pools have no real liquidity and no competing bots. A strategy profitable on devnet tells you nothing about mainnet viability. Start with localnet for correctness, skip to mainnet paper trading for strategy.

Monitoring & Observability

MetricWhyAlert Threshold
P&L per hourCore business metricNegative for >10 min
Transaction success rateExecution quality<80%
Quote-to-land latency p95Speed competitiveness>500ms
Failed tx cost per hourWasted spend>X SOL (user-defined)
Opportunity detection ratePipeline health0 for >5 min
Jito bundle inclusion rateBundle competitiveness<50%

Anti-Patterns

Anti-PatternMeasurable Impact
Trusting quotes without simulationFailed txs waste base + priority fees with zero revenue
Fixed slippage tolerance (e.g., 1% global)Too loose on stable pairs (leaks value), too tight on volatile (misses trades)
No circuit breakerCompounds losses during adverse conditions
Ignoring failed tx costs in P&LOverstates profitability by 30-40% on typical Solana arb
Hardcoded priority feesUnderpays during congestion (dropped), overpays during calm (eats profits)
Single RPC endpoint with no failoverOne provider outage halts all trading
Not accounting for ATA rent in profit calc0.002 SOL per new token account adds up
Submitting without JitoExposes profitable trades to sandwich attacks in public mempool

Companion Skills

DomainSkillCoverage
Solana fundamentalssolana-coreTransactions, RPC, accounts, real-time data
Rust engineeringrust-proOwnership, error handling, async patterns
Performance optimizationperf-rustProfiling, benchmarking, allocation analysis
Performance methodologyperf-coreMeasure-profile-identify-optimize-verify loop