Crates.io | sol-trade-sdk |
lib.rs | sol-trade-sdk |
version | 1.2.2 |
created_at | 2025-07-10 10:34:25.98195+00 |
updated_at | 2025-09-25 16:08:10.004958+00 |
description | Rust SDK to interact with the dex trade Solana program. |
homepage | |
repository | https://github.com/0xfnzero/sol-trade-sdk |
max_upload_size | |
id | 1746143 |
size | 733,002 |
Integrate PumpFun, PumpSwap, Bonk, and Raydium trading functionality into your applications with powerful tools and unified interfaces.
δΈζ | English | Website | Telegram | Discord
buy
and sell
operationsClone 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 = "1.2.2" }
# Add to your Cargo.toml
sol-trade-sdk = "1.2.2"
You can refer to Example: Create SolanaTrade Instance.
// Wallet
let payer = Keypair::from_base58_string("use_your_payer_keypair_here");
// RPC URL
let rpc_url = "https://mainnet.helius-rpc.com/?api-key=xxxxxx".to_string();
let commitment = CommitmentConfig::processed();
// Multiple SWQOS services can be configured
let swqos_configs: Vec<SwqosConfig> = vec![
SwqosConfig::Default(rpc_url.clone()),
SwqosConfig::Jito("your uuid".to_string(), SwqosRegion::Frankfurt, None),
SwqosConfig::NextBlock("your api_token".to_string(), SwqosRegion::Frankfurt, None),
SwqosConfig::Bloxroute("your api_token".to_string(), SwqosRegion::Frankfurt, None),
SwqosConfig::ZeroSlot("your api_token".to_string(), SwqosRegion::Frankfurt, None),
SwqosConfig::Temporal("your api_token".to_string(), SwqosRegion::Frankfurt, None),
SwqosConfig::FlashBlock("your api_token".to_string(), SwqosRegion::Frankfurt, None),
SwqosConfig::Node1("your api_token".to_string(), SwqosRegion::Frankfurt, None),
SwqosConfig::BlockRazor("your api_token".to_string(), SwqosRegion::Frankfurt, None),
SwqosConfig::Astralane("your api_token".to_string(), SwqosRegion::Frankfurt, None),
];
// Create TradeConfig instance
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
// Create SolanaTrade client
let client = SolanaTrade::new(Arc::new(payer), trade_config).await;
For detailed information about Gas Fee Strategy, see the Gas Fee Strategy Reference.
GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
For detailed information about all trading parameters, see the Trading Parameters Reference.
let buy_params = sol_trade_sdk::TradeBuyParams {
dex_type: DexType::PumpSwap,
input_token_type: TradeTokenType::WSOL,
mint: mint_pubkey,
input_token_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(params.clone()),
lookup_table_key: None,
wait_transaction_confirmed: true,
create_input_token_ata: true,
close_input_token_ata: true,
create_mint_ata: true,
open_seed_optimize: false,
durable_nonce: None,
};
client.buy(buy_params).await?;
For comprehensive information about all trading parameters including TradeBuyParams
and TradeSellParams
, see the dedicated Trading Parameters Reference.
When using shred to subscribe to events, due to the nature of shreds, you cannot get complete information about transaction events. Please ensure that the parameters your trading logic depends on are available in shreds when using them.
Description | Run Command | Source Code |
---|---|---|
Monitor token trading events | cargo run --package event_subscription |
examples/event_subscription |
Create and configure SolanaTrade instance | cargo run --package trading_client |
examples/trading_client |
PumpFun token sniping trading | cargo run --package pumpfun_sniper_trading |
examples/pumpfun_sniper_trading |
PumpFun token copy trading | cargo run --package pumpfun_copy_trading |
examples/pumpfun_copy_trading |
PumpSwap trading operations | cargo run --package pumpswap_trading |
examples/pumpswap_trading |
Raydium CPMM trading operations | cargo run --package raydium_cpmm_trading |
examples/raydium_cpmm_trading |
Raydium AMM V4 trading operations | cargo run --package raydium_amm_v4_trading |
examples/raydium_amm_v4_trading |
Bonk token sniping trading | cargo run --package bonk_sniper_trading |
examples/bonk_sniper_trading |
Bonk token copy trading | cargo run --package bonk_copy_trading |
examples/bonk_copy_trading |
Custom instruction middleware example | cargo run --package middleware_system |
examples/middleware_system |
Address lookup table example | cargo run --package address_lookup |
examples/address_lookup |
Nonce example | cargo run --package nonce_cache |
examples/nonce_cache |
Wrap/unwrap SOL to/from WSOL example | cargo run --package wsol_wrapper |
examples/wsol_wrapper |
Seed trading example | cargo run --package seed_trading |
examples/seed_trading |
Gas fee strategy example | cargo run --package gas_fee_strategy |
examples/gas_fee_strategy |
When configuring SWQOS services, note the different parameter requirements for each service:
""
)Each SWQOS service now supports an optional custom URL parameter:
// Using custom URL (third parameter)
let jito_config = SwqosConfig::Jito(
"your_uuid".to_string(),
SwqosRegion::Frankfurt, // This parameter is still required but will be ignored
Some("https://custom-jito-endpoint.com".to_string()) // Custom URL
);
// Using default regional endpoint (third parameter is None)
let nextblock_config = SwqosConfig::NextBlock(
"your_api_token".to_string(),
SwqosRegion::NewYork, // Will use the default endpoint for this region
None // No custom URL, uses SwqosRegion
);
URL Priority Logic:
Some(url)
), it will be used instead of the regional endpointNone
), the system will use the default endpoint for the specified SwqosRegion
When using multiple MEV services, you need to use Durable Nonce
. You need to initialize a NonceCache
class (or write your own nonce management class), get the latest nonce
value, and use it as the durable_nonce
when trading.
The SDK provides a powerful middleware system that allows you to modify, add, or remove instructions before transaction execution. Middleware executes in the order they are added:
let middleware_manager = MiddlewareManager::new()
.add_middleware(Box::new(FirstMiddleware)) // Executes first
.add_middleware(Box::new(SecondMiddleware)) // Executes second
.add_middleware(Box::new(ThirdMiddleware)); // Executes last
Address Lookup Tables (ALT) allow you to optimize transaction size and reduce fees by storing frequently used addresses in a compact table format. For detailed information, see the Address Lookup Tables Guide.
Use Nonce Cache to implement transaction replay protection and optimize transaction processing. For detailed information, see the Nonce Cache Guide.
You can apply for a key through the official website: Community Website
src/
βββ common/ # Common functionality and tools
βββ constants/ # Constant definitions
βββ instruction/ # Instruction building
β βββ utils/ # Instruction utilities
βββ protos/ # gRPC protocol definitions
βββ swqos/ # MEV service clients
βββ trading/ # Unified trading engine
β βββ common/ # Common trading tools
β βββ core/ # Core trading engine
β βββ middleware/ # Middleware system
β βββ factory.rs # Trading factory
βββ utils/ # Utility functions
β βββ calc/ # Amount calculation utilities
β βββ price/ # Price calculation utilities
βββ lib.rs # Main library file
MIT License