Rust SDK for low-latency Solana DEX trading bots with PumpFun, PumpSwap, Bonk, Raydium, Meteora, Jito, and SWQoS submit lanes.
Rust SDK for low-latency Solana DEX trading bots with PumpFun, PumpSwap, Bonk, Raydium, Meteora, Jito, and SWQoS submit lanes.
A high-performance Rust SDK for low-latency Solana DEX trading bots. Built for speed and efficiency, it enables seamless, high-throughput interaction with PumpFun, Pump AMM (PumpSwap), Bonk, StonkFun, Meteora DAMM v2, Raydium AMM v4, and Raydium CPMM for latency-critical trading strategies.
中文 |
English |
Website |
Telegram |
Discord
This SDK is available in multiple languages:
| Language | Repository | Description |
|---|---|---|
| Rust | sol-trade-sdk | Ultra-low latency with zero-copy optimization |
| Node.js | sol-trade-sdk-nodejs | TypeScript/JavaScript for Node.js |
| Python | sol-trade-sdk-python | Async/await native support |
| Go | sol-trade-sdk-golang | Concurrent-safe with goroutine support |
sol-trade-sdk is the Rust implementation of the FnZero Solana trading SDK family. It focuses on low-latency transaction construction and submission for Solana DEX trading bots, copy-trading systems, sniper bots, arbitrage strategies, and private trading infrastructure.
| Area | Coverage |
|---|---|
| DEX protocols | PumpFun, PumpSwap, LaunchLab, Bonk, StonkFun, Meteora DAMM v2, Raydium AMM v4, Raydium CPMM |
| Submit lanes | Default Solana RPC plus Jito, Nextblock, ZeroSlot, Temporal, Bloxroute, FlashBlock, BlockRazor, Node1, Astralane, Glaive, SpeedLanding, and other SWQoS providers |
| Trading workflows | Buy/sell, exact input/output, copy trading, sniper trading, address lookup tables, durable nonce, middleware, shared infrastructure |
| Hot-path design | Caller supplies recent blockhash or durable nonce; trade execution avoids RPC reads for blockhash, account, or balance data |
Rust crate: sol-trade-sdk = "5.0.4"
This release adds first-class shared-program trading through DexType::LaunchLab, DexParamEnum::LaunchLab, and LaunchLabParams, plus platform-specific StonkFun names through DexType::StonkFun, DexParamEnum::StonkFun, and StonkFunParams. It supports dynamic quote mints and token programs, reads current LaunchLab pool and fee configuration by RPC, and builds the current 18-account buy/sell instruction layout. The same DexType::StonkFun routes graduated pools when paired with DexParamEnum::StonkFunSwap / StonkFunSwapParams: arbitrary token pairs, mixed SPL Token/Token-2022 programs, current AmmConfig and creator fees, transfer fees, vault balances, and both swap directions are resolved from mainnet state. Buy quotes also reduce the submitted input at the curve graduation boundary, matching the official LaunchLab SDK. Existing Bonk and RaydiumCpmm names remain available for compatibility and direct underlying-protocol access.
The gated mainnet regressions use a current StonkFun reward pool and the graduated KNOTS/STONK CPMM pool. Run them without submitting a transaction:
RUN_MAINNET_TESTS=1 cargo test --lib current_stonkfun_reward_pool_decodes_and_builds_both_trade_directions -- --nocapture
RUN_MAINNET_TESTS=1 cargo test --lib current_stonkfun_graduated_pool_decodes_and_builds_both_swap_directions -- --nocapture
buy, sell, and buy_exact_quote_in flow, preferring V1 for native SOL and selecting V2 for USDC/non-native quote mints or explicit WSOL settlement| Guide | Purpose |
|---|---|
| Pre-Buy Risk Gate | Reject risky buys from a local cache before transaction construction and submission |
| Low-Latency Bot Integration | Structure event processing, state refresh, blockhash, account, and submit paths |
| Trading Parameters | Choose buy/sell amount modes, account policies, ALTs, and nonce settings |
| Gas Fee Strategy | Configure compute-unit prices, limits, relay tips, and per-lane fees |
| Address Lookup Tables | Reduce versioned transaction size with one or more ALTs |
| Durable Nonce | Build and refresh durable-nonce transaction workflows |
Clone this project to your project directory:
cd your_project_root_directory
git clone https://github.com/0xfnzero/sol-trade-sdk
Add the dependency to your Cargo.toml:
# Add to your Cargo.toml
sol-trade-sdk = { path = "./sol-trade-sdk", version = "5.0.4" }
# Add to your Cargo.toml
sol-trade-sdk = "5.0.4"
You can refer to Example: Create TradingClient Instance.
Method 1: Simple (single wallet)
…
TradeTransactionVersion::V0 is the default and preserves the existing behavior: transactions
without address lookup tables use Legacy messages, while transactions with lookup tables use V0.
Select TradeTransactionVersion::V1 explicitly to build V1 messages. V1 embeds the compute-unit
limit and total priority fee in its transaction config, does not include ComputeBudget
instructions, does not support address lookup tables, and allows transactions up to 4096 bytes.
The existing cu_price setting remains micro-lamports per compute unit and is converted to total
lamports with ceiling division. Only enable V1 on a cluster and submission provider that supports
it; individual providers may impose a smaller transport limit, and Mainnet V1 activation may lag
Devnet/Testnet.
Method 2: Shared infrastructure (multiple wallets)
For multi-wallet scenarios, create the infrastructure once and share it across wallets. See Example: Shared Infrastructure.
// Create infrastructure once (expensive)
let infra_config = InfrastructureConfig::new(rpc_url, swqos_configs, commitment);
let infrastructure = Arc::new(TradingInfrastructure::new(infra_config).await);
// Create multiple clients sharing the same infrastructure (fast)
let client1 = TradingClient::from_infrastructure(Arc::new(payer1), infrastructure.clone(), true)
.with_transaction_version(TradeTransactionVersion::V1);
let client2 = TradingClient::from_infrastructure(Arc::new(payer2), infrastructure.clone(), true);
For detailed information about Gas Fee Strategy, see the Gas Fee Strategy Reference.
// Create GasFeeStrategy instance
let gas_fee_strategy = GasFeeStrategy::new();
// Set global strategy
gas_fee_strategy.set_global_fee_strategy(150000, 150000, 500000, 500000, 0.001, 0.001);
For detailed information about all trading parameters, see the Trading Parameters Reference.
…
client.buy_simple(buy_params).await?;
Use SimpleBuyParams / SimpleSellParams for new integrations. They describe trading intent and hide low-level ATA flags. Most users only choose:
pay_with / receive_as: quote token direction. Use SOL when the wallet spends or receives native SOL. For PumpFun V2 SOL-paired pools whose quote mint is WSOL, still use SOL if you want native SOL settlement.amount: trade sizing intent. Pick one enum variant instead of combining input_token_amount, fixed_output_token_amount, and use_exact_sol_amount.account_policy: account creation behavior. Bots usually use HotPathMinimal; normal apps can keep the default Auto.| Parameter | Meaning | Recommendation |
|---|---|---|
BuyAmount::ExactInput(amount) |
Spend exactly this quote amount; slippage protects minimum output. | Normal swaps |
BuyAmount::WithMaxInput { quote_amount } |
Regular PumpFun/PumpSwap buy with slippage applied to max quote cost. | Sniping/arbitrage |
BuyAmount::ExactOutput { output_amount, max_input_amount } |
Buy an exact token amount with a max quote budget. | Exact-output workflows |
SellAmount::ExactInput(amount) |
Sell exactly this token amount. | Normal sells |
SellAmount::ExactOutput { output_amount, max_input_amount } |
Receive an exact quote amount while limiting token input, where the DEX supports it. | Exact-output sells |
AccountPolicy::Auto |
SDK creates practical ATAs when needed. | General usage |
AccountPolicy::HotPathMinimal |
Avoid ATA create/close instructions in the trade tx. | Bots, sniping, latency-sensitive flows |
AccountPolicy::CreateMissing |
Include ATA creation instructions where possible. | Convenience over transaction size |
AccountPolicy::AssumePrepared |
Caller prepared every required ATA. | Deterministic advanced flows |
Optional builder methods:
| Method | Meaning |
|---|---|
.slippage_basis_points(300) |
Set slippage. 300 means 3%. |
| `.address_lookup_table_account(a |
No open issues yet, or sync has not completed.