2025-09-10 17:02:54 +08:00
<div align="center">
<h1>🚀 Sol Trade SDK</h1>
<h3><em>A comprehensive Rust SDK for seamless Solana DEX trading</em></h3>
</div>
2024-12-31 16:51:58 +08:00
2025-09-10 17:02:54 +08:00
<p align="center">
2026-01-05 01:24:28 +08:00
<strong>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, Meteora DAMM v2, Raydium AMM v4, and Raydium CPMM for latency-critical trading strategies.</strong>
2025-09-10 17:02:54 +08:00
</p>
2025-05-19 14:19:21 +08:00
2025-09-10 17:35:44 +08:00
<p align="center">
<a href="https://crates.io/crates/sol-trade-sdk">
<img src="https://img.shields.io/crates/v/sol-trade-sdk.svg" alt="Crates.io">
</a>
<a href="https://docs.rs/sol-trade-sdk">
<img src="https://docs.rs/sol-trade-sdk/badge.svg" alt="Documentation">
</a>
<a href="https://github.com/0xfnzero/sol-trade-sdk/blob/main/LICENSE">
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License">
</a>
<a href="https://github.com/0xfnzero/sol-trade-sdk">
<img src="https://img.shields.io/github/stars/0xfnzero/sol-trade-sdk?style=social" alt="GitHub stars">
</a>
<a href="https://github.com/0xfnzero/sol-trade-sdk/network">
<img src="https://img.shields.io/github/forks/0xfnzero/sol-trade-sdk?style=social" alt="GitHub forks">
</a>
</p>
<p align="center">
<img src="https://img.shields.io/badge/Rust-000000?style=for-the-badge&logo=rust&logoColor=white" alt="Rust">
<img src="https://img.shields.io/badge/Solana-9945FF?style=for-the-badge&logo=solana&logoColor=white" alt="Solana">
<img src="https://img.shields.io/badge/DEX-4B8BBE?style=for-the-badge&logo=bitcoin&logoColor=white" alt="DEX Trading">
</p>
2025-09-10 17:02:54 +08:00
<p align="center">
<a href="https://github.com/0xfnzero/sol-trade-sdk/blob/main/README_CN.md">中文</a> |
<a href="https://github.com/0xfnzero/sol-trade-sdk/blob/main/README.md">English</a> |
<a href="https://fnzero.dev/">Website</a> |
2025-09-13 21:09:18 +08:00
<a href="https://t.me/fnzero_group">Telegram</a> |
2025-10-08 22:57:38 +08:00
<a href="https://discord.gg/vuazbGkqQE">Discord</a>
2025-09-10 17:02:54 +08:00
</p>
## 📋 Table of Contents
- [✨ Features ](#-features )
- [📦 Installation ](#-installation )
- [🛠️ Usage Examples ](#️ -usage-examples )
2025-09-19 00:49:45 +08:00
- [📋 Example Usage ](#-example-usage )
- [⚡ Trading Parameters ](#-trading-parameters )
2025-09-10 17:02:54 +08:00
- [📊 Usage Examples Summary Table ](#-usage-examples-summary-table )
2026-02-19 01:31:50 +08:00
- [⚙️ SWQoS Service Configuration ](#️ -swqos-service-configuration )
2026-04-14 02:13:42 +08:00
- [Astralane (Binary / Plain / QUIC) ](#astralane-binary--plain--quic )
2025-09-10 17:02:54 +08:00
- [🔧 Middleware System ](#-middleware-system )
2025-09-19 00:49:45 +08:00
- [🔍 Address Lookup Tables ](#-address-lookup-tables )
- [🔍 Nonce Cache ](#-nonce-cache )
2026-02-19 01:01:21 +08:00
- [💰 Cashback Support (PumpFun / PumpSwap) ](#-cashback-support-pumpfun--pumpswap )
2025-09-10 17:02:54 +08:00
- [🛡️ MEV Protection Services ](#️ -mev-protection-services )
- [📁 Project Structure ](#-project-structure )
- [📄 License ](#-license )
- [💬 Contact ](#-contact )
- [⚠️ Important Notes ](#️ -important-notes )
---
2026-04-06 02:37:18 +08:00
## 📦 SDK Versions
This SDK is available in multiple languages:
| Language | Repository | Description |
|----------|------------|-------------|
| **Rust** | [sol-trade-sdk ](https://github.com/0xfnzero/sol-trade-sdk ) | Ultra-low latency with zero-copy optimization |
| **Node.js** | [sol-trade-sdk-nodejs ](https://github.com/0xfnzero/sol-trade-sdk-nodejs ) | TypeScript/JavaScript for Node.js |
| **Python** | [sol-trade-sdk-python ](https://github.com/0xfnzero/sol-trade-sdk-python ) | Async/await native support |
| **Go** | [sol-trade-sdk-golang ](https://github.com/0xfnzero/sol-trade-sdk-golang ) | Concurrent-safe with goroutine support |
2025-09-10 17:02:54 +08:00
## ✨ Features
2025-05-19 14:19:21 +08:00
2025-07-09 22:29:29 +08:00
1. **PumpFun Trading** : Support for `buy` and `sell` operations
2025-06-16 18:21:23 +08:00
2. **PumpSwap Trading** : Support for PumpSwap pool trading operations
2025-07-10 00:23:29 +08:00
3. **Bonk Trading** : Support for Bonk trading operations
2025-07-16 22:54:23 +08:00
4. **Raydium CPMM Trading** : Support for Raydium CPMM (Concentrated Pool Market Maker) trading operations
2025-08-19 18:07:21 +08:00
5. **Raydium AMM V4 Trading** : Support for Raydium AMM V4 (Automated Market Maker) trading operations
2025-10-05 22:27:04 +08:00
6. **Meteora DAMM V2 Trading** : Support for Meteora DAMM V2 (Dynamic AMM) trading operations
2025-09-19 00:49:45 +08:00
7. **Multiple MEV Protection** : Support for Jito, Nextblock, ZeroSlot, Temporal, Bloxroute, FlashBlock, BlockRazor, Node1, Astralane and other services
8. **Concurrent Trading** : Send transactions using multiple MEV services simultaneously; the fastest succeeds while others fail
9. **Unified Trading Interface** : Use unified trading protocol enums for trading operations
10. **Middleware System** : Support for custom instruction middleware to modify, add, or remove instructions before transaction execution
2026-02-19 01:31:50 +08:00
11. **Shared Infrastructure** : Share expensive RPC and SWQoS clients across multiple wallets for reduced resource usage
2025-05-19 14:19:21 +08:00
2025-09-10 17:02:54 +08:00
## 📦 Installation
2025-06-16 18:21:23 +08:00
2025-07-20 00:56:11 +08:00
### Direct Clone
2025-06-16 18:21:23 +08:00
Clone this project to your project directory:
```bash
cd your_project_root_directory
git clone https://github.com/0xfnzero/sol-trade-sdk
2025-05-19 14:19:21 +08:00
```
2025-06-16 18:21:23 +08:00
Add the dependency to your `Cargo.toml` :
2025-05-19 14:19:21 +08:00
```toml
2025-06-16 18:21:23 +08:00
# Add to your Cargo.toml
2026-04-12 00:55:52 +08:00
sol-trade-sdk = { path = "./sol-trade-sdk" , version = "4.0.3" }
2025-07-20 00:56:11 +08:00
```
### Use crates.io
```toml
# Add to your Cargo.toml
2026-04-12 00:55:52 +08:00
sol-trade-sdk = "4.0.3"
2025-05-19 14:19:21 +08:00
```
2025-09-10 17:02:54 +08:00
## 🛠️ Usage Examples
2025-09-19 00:49:45 +08:00
### 📋 Example Usage
2025-05-19 14:19:21 +08:00
2025-12-08 03:11:46 +08:00
#### 1. Create TradingClient Instance
2025-07-19 21:28:01 +08:00
2025-12-08 03:11:46 +08:00
You can refer to [Example: Create TradingClient Instance ](examples/trading_client/src/main.rs ).
2025-07-19 21:28:01 +08:00
2026-01-05 21:26:21 +00:00
**Method 1: Simple (single wallet)**
2025-09-19 00:49:45 +08:00
```rust
// 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 ();
2026-02-19 01:31:50 +08:00
// Multiple SWQoS services can be configured
2025-09-19 00:49:45 +08:00
let swqos_configs : Vec < SwqosConfig > = vec! [
SwqosConfig ::Default ( rpc_url . clone ()),
SwqosConfig ::Jito ( "your uuid" . to_string (), SwqosRegion ::Frankfurt , None ),
SwqosConfig ::Bloxroute ( "your api_token" . to_string (), SwqosRegion ::Frankfurt , None ),
2026-04-14 02:13:42 +08:00
// Astralane: 4th param = AstralaneTransport — Binary (default), Plain (/iris), or Quic
SwqosConfig ::Astralane ( "your_astralane_api_key" . to_string (), SwqosRegion ::Frankfurt , None , None ), // Binary HTTP /irisb
2026-03-07 10:54:35 +08:00
SwqosConfig ::Astralane (
"your_astralane_api_key" . to_string (),
SwqosRegion ::Frankfurt ,
None ,
2026-04-14 02:13:42 +08:00
Some ( AstralaneTransport ::Quic ),
2026-03-07 10:54:35 +08:00
), // QUIC
2025-09-19 00:49:45 +08:00
];
// Create TradeConfig instance
2026-04-08 02:13:37 +08:00
let trade_config = TradeConfig ::builder ( rpc_url , swqos_configs , commitment )
// .create_wsol_ata_on_startup(true) // default: true - check & create WSOL ATA on init
// .use_seed_optimize(true) // default: true - seed optimization for ATA ops
// .log_enabled(true) // default: true - SDK timing / SWQOS logs
// .check_min_tip(false) // default: false - filter SWQOS below min tip
// .swqos_cores_from_end(false) // default: false - bind SWQOS to last N CPU cores
2026-04-14 02:13:42 +08:00
// .mev_protection(false) // default: false - MEV (Astralane QUIC :9000 or HTTP mev-protect / BlockRazor)
2026-04-08 02:13:37 +08:00
. build ();
2026-02-19 01:01:21 +08:00
2025-12-08 03:11:46 +08:00
// Create TradingClient
let client = TradingClient ::new ( Arc ::new ( payer ), trade_config ). await ;
2025-09-19 00:49:45 +08:00
```
2025-09-10 00:18:31 +08:00
2026-01-05 21:26:21 +00:00
**Method 2: Shared infrastructure (multiple wallets)**
For multi-wallet scenarios, create the infrastructure once and share it across wallets.
See [Example: Shared Infrastructure ](examples/shared_infrastructure/src/main.rs ).
```rust
// 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 );
let client2 = TradingClient ::from_infrastructure ( Arc ::new ( payer2 ), infrastructure . clone (), true );
```
2025-09-19 15:46:51 +08:00
#### 2. Configure Gas Fee Strategy
For detailed information about Gas Fee Strategy, see the [Gas Fee Strategy Reference ](docs/GAS_FEE_STRATEGY.md ).
2025-10-07 23:12:37 +08:00
2025-09-19 15:46:51 +08:00
```rust
2025-10-07 23:12:37 +08:00
// Create GasFeeStrategy instance
let gas_fee_strategy = GasFeeStrategy ::new ();
// Set global strategy
2025-12-28 16:16:10 +08:00
gas_fee_strategy . set_global_fee_strategy ( 150000 , 150000 , 500000 , 500000 , 0.001 , 0.001 );
2025-09-19 15:46:51 +08:00
```
#### 3. Build Trading Parameters
2025-09-10 00:18:31 +08:00
2025-09-19 00:49:45 +08:00
For detailed information about all trading parameters, see the [Trading Parameters Reference ](docs/TRADING_PARAMETERS.md ).
2025-07-19 21:28:01 +08:00
2025-09-19 00:49:45 +08:00
```rust
2025-12-08 02:12:46 +08:00
// Import DexParamEnum for protocol-specific parameters
use sol_trade_sdk ::trading ::core ::params ::DexParamEnum ;
2025-09-19 00:49:45 +08:00
let buy_params = sol_trade_sdk ::TradeBuyParams {
dex_type : DexType ::PumpSwap ,
2025-09-22 23:18:53 +08:00
input_token_type : TradeTokenType ::WSOL ,
2025-09-19 00:49:45 +08:00
mint : mint_pubkey ,
2025-09-22 23:18:53 +08:00
input_token_amount : buy_sol_amount ,
2025-09-19 00:49:45 +08:00
slippage_basis_points : slippage_basis_points ,
2025-09-21 21:56:17 +08:00
recent_blockhash : Some ( recent_blockhash ),
2025-12-08 02:12:46 +08:00
// Use DexParamEnum for type-safe protocol parameters (zero-overhead abstraction)
extension_params : DexParamEnum ::PumpSwap ( params . clone ()),
2025-10-07 20:56:02 +08:00
address_lookup_table_account : None ,
2025-09-19 00:49:45 +08:00
wait_transaction_confirmed : true ,
2025-09-22 23:18:53 +08:00
create_input_token_ata : true ,
close_input_token_ata : true ,
2025-09-19 00:49:45 +08:00
create_mint_ata : true ,
2025-09-22 23:18:53 +08:00
durable_nonce : None ,
2025-12-08 02:12:46 +08:00
fixed_output_token_amount : None , // Optional: specify exact output amount
gas_fee_strategy : gas_fee_strategy . clone (), // Gas fee strategy configuration
simulate : false , // Set to true for simulation only
2026-01-06 11:53:09 +00:00
use_exact_sol_amount : None , // Use exact SOL input for PumpFun/PumpSwap (defaults to true)
2025-09-19 00:49:45 +08:00
};
```
2025-07-19 21:28:01 +08:00
2025-09-19 15:46:51 +08:00
#### 4. Execute Trading
2025-09-09 17:35:09 +08:00
2025-09-19 00:49:45 +08:00
```rust
client . buy ( buy_params ). await ? ;
```
2025-09-10 00:18:31 +08:00
2025-09-19 00:49:45 +08:00
### ⚡ Trading Parameters
2025-09-09 17:35:09 +08:00
2025-09-19 00:49:45 +08:00
For comprehensive information about all trading parameters including `TradeBuyParams` and `TradeSellParams` , see the dedicated [Trading Parameters Reference ](docs/TRADING_PARAMETERS.md ).
2025-09-02 09:43:53 +08:00
2025-08-25 00:21:15 +08:00
#### About ShredStream
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.
2025-09-10 17:02:54 +08:00
### 📊 Usage Examples Summary Table
2025-07-09 22:29:29 +08:00
2025-09-19 00:49:45 +08:00
| Description | Run Command | Source Code |
|-------------|-------------|-------------|
2025-12-08 03:11:46 +08:00
| Create and configure TradingClient instance | `cargo run --package trading_client` | [examples/trading_client ](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/trading_client/src/main.rs ) |
2026-01-05 21:26:21 +00:00
| Share infrastructure across multiple wallets | `cargo run --package shared_infrastructure` | [examples/shared_infrastructure ](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/shared_infrastructure/src/main.rs ) |
2025-09-19 00:49:45 +08:00
| PumpFun token sniping trading | `cargo run --package pumpfun_sniper_trading` | [examples/pumpfun_sniper_trading ](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/pumpfun_sniper_trading/src/main.rs ) |
| PumpFun token copy trading | `cargo run --package pumpfun_copy_trading` | [examples/pumpfun_copy_trading ](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/pumpfun_copy_trading/src/main.rs ) |
| PumpSwap trading operations | `cargo run --package pumpswap_trading` | [examples/pumpswap_trading ](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/pumpswap_trading/src/main.rs ) |
| Raydium CPMM trading operations | `cargo run --package raydium_cpmm_trading` | [examples/raydium_cpmm_trading ](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/raydium_cpmm_trading/src/main.rs ) |
| Raydium AMM V4 trading operations | `cargo run --package raydium_amm_v4_trading` | [examples/raydium_amm_v4_trading ](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/raydium_amm_v4_trading/src/main.rs ) |
2025-10-05 22:27:04 +08:00
| Meteora DAMM V2 trading operations | `cargo run --package meteora_damm_v2_direct_trading` | [examples/meteora_damm_v2_direct_trading ](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/meteora_damm_v2_direct_trading/src/main.rs ) |
2025-09-19 00:49:45 +08:00
| Bonk token sniping trading | `cargo run --package bonk_sniper_trading` | [examples/bonk_sniper_trading ](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/bonk_sniper_trading/src/main.rs ) |
| Bonk token copy trading | `cargo run --package bonk_copy_trading` | [examples/bonk_copy_trading ](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/bonk_copy_trading/src/main.rs ) |
| Custom instruction middleware example | `cargo run --package middleware_system` | [examples/middleware_system ](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/middleware_system/src/main.rs ) |
| Address lookup table example | `cargo run --package address_lookup` | [examples/address_lookup ](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/address_lookup/src/main.rs ) |
| Nonce example | `cargo run --package nonce_cache` | [examples/nonce_cache ](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/nonce_cache/src/main.rs ) |
| Wrap/unwrap SOL to/from WSOL example | `cargo run --package wsol_wrapper` | [examples/wsol_wrapper ](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/wsol_wrapper/src/main.rs ) |
| Seed trading example | `cargo run --package seed_trading` | [examples/seed_trading ](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/seed_trading/src/main.rs ) |
2025-09-19 15:46:51 +08:00
| Gas fee strategy example | `cargo run --package gas_fee_strategy` | [examples/gas_fee_strategy ](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/gas_fee_strategy/src/main.rs ) |
2025-06-16 18:21:23 +08:00
2026-02-19 01:31:50 +08:00
### ⚙️ SWQoS Service Configuration
2025-08-10 22:12:51 +08:00
2026-02-19 01:31:50 +08:00
When configuring SWQoS services, note the different parameter requirements for each service:
2025-08-10 22:12:51 +08:00
2025-09-10 17:02:54 +08:00
- **Jito**: The first parameter is UUID (if no UUID, pass an empty string `""` )
- **Other MEV services**: The first parameter is the API Token
2025-09-06 21:52:06 +08:00
#### Custom URL Support
2026-02-19 01:31:50 +08:00
Each SWQoS service now supports an optional custom URL parameter:
2025-09-06 21:52:06 +08:00
```rust
// 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)
2025-12-20 16:45:29 +08:00
let bloxroute_config = SwqosConfig ::Bloxroute (
2025-09-06 21:52:06 +08:00
"your_api_token" . to_string (),
SwqosRegion ::NewYork , // Will use the default endpoint for this region
None // No custom URL, uses SwqosRegion
);
```
**URL Priority Logic** :
- If a custom URL is provided (`Some(url)` ), it will be used instead of the regional endpoint
- If no custom URL is provided (`None` ), the system will use the default endpoint for the specified `SwqosRegion`
- This allows for maximum flexibility while maintaining backward compatibility
2025-08-10 22:12:51 +08:00
2025-10-07 21:20:00 +08:00
When using multiple MEV services, you need to use `Durable Nonce` . You need to use the `fetch_nonce_info` function to get the latest `nonce` value, and use it as the `durable_nonce` when trading.
2025-05-19 14:19:21 +08:00
2026-04-14 02:13:42 +08:00
#### Astralane (Binary / Plain HTTP / QUIC)
2026-03-07 10:47:31 +08:00
2026-04-14 02:13:42 +08:00
Astralane supports **Binary** HTTP (`/irisb` ), **Plain** HTTP (`/iris` ), and **QUIC** (`host:7000` , or `:9000` when global `mev_protection` is true). Pass `Some(AstralaneTransport::Plain)` , `Some(AstralaneTransport::Quic)` , or use `None` / omit for **Binary** (default). Global `mev_protection` adds `mev-protect=true` on HTTP or selects QUIC port 9000.
2026-03-07 10:47:31 +08:00
```rust
2026-04-14 02:13:42 +08:00
use sol_trade_sdk ::{ SwqosConfig , SwqosRegion , AstralaneTransport };
2026-03-07 10:47:31 +08:00
let swqos_configs : Vec < SwqosConfig > = vec! [
SwqosConfig ::Default ( rpc_url . clone ()),
SwqosConfig ::Astralane (
"your_astralane_api_key" . to_string (),
2026-04-14 02:13:42 +08:00
SwqosRegion ::Frankfurt ,
2026-03-07 10:47:31 +08:00
None ,
2026-04-14 02:13:42 +08:00
Some ( AstralaneTransport ::Quic ),
2026-03-07 10:47:31 +08:00
),
];
// Then create TradeConfig / TradingClient as usual with swqos_configs
```
2026-04-14 02:13:42 +08:00
- **Binary** (default): `None` or `Some(AstralaneTransport::Binary)` — `/irisb` , bincode body.
- **Plain**: `Some(AstralaneTransport::Plain)` — `/iris` .
- **QUIC**: `Some(AstralaneTransport::Quic)` — regional `host:7000` / `:9000` (MEV); same API key.
2026-03-07 10:47:31 +08:00
2025-09-10 17:02:54 +08:00
---
### 🔧 Middleware System
2025-07-09 22:29:29 +08:00
2025-09-03 17:47:10 +08:00
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:
2025-08-19 18:07:21 +08:00
```rust
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
```
2025-09-19 00:49:45 +08:00
### 🔍 Address Lookup Tables
2025-07-09 22:29:29 +08:00
2025-09-19 00:49:45 +08:00
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 ](docs/ADDRESS_LOOKUP_TABLE.md ).
2025-07-09 22:29:29 +08:00
2025-10-07 21:20:00 +08:00
### 🔍 Durable Nonce
2025-05-19 14:19:21 +08:00
2025-10-07 21:20:00 +08:00
Use Durable Nonce to implement transaction replay protection and optimize transaction processing. For detailed information, see the [Durable Nonce Guide ](docs/NONCE_CACHE.md ).
2025-06-16 18:21:23 +08:00
2026-02-19 01:01:21 +08:00
## 💰 Cashback Support (PumpFun / PumpSwap)
2026-02-19 01:31:50 +08:00
PumpFun and PumpSwap support **cashback** for eligible tokens: part of the trading fee can be returned to the user. The SDK **must know** whether the token has cashback enabled so that buy/sell instructions include the correct accounts (e.g. `UserVolumeAccumulator` as remaining account for cashback coins).
2026-02-19 01:01:21 +08:00
2026-02-19 01:31:50 +08:00
- **When params come from RPC**: If you use `PumpFunParams::from_mint_by_rpc` or `PumpSwapParams::from_pool_address_by_rpc` / `from_mint_by_rpc` , the SDK reads `is_cashback_coin` from chain—no extra step.
- **When params come from event/parser**: If you build params from trade events (e.g. [sol-parser-sdk ](https://github.com/0xfnzero/sol-parser-sdk )), you **must** pass the cashback flag into the SDK:
- **PumpFun**: `PumpFunParams::from_trade(..., is_cashback_coin)` and `PumpFunParams::from_dev_trade(..., is_cashback_coin)` take an `is_cashback_coin` parameter. Set it from the parsed event (e.g. CreateEvent’ s `is_cashback_enabled` or BondingCurve’ s `is_cashback_coin` ).
- **PumpSwap**: `PumpSwapParams` has a field `is_cashback_coin` . When constructing params manually (e.g. from pool/trade events), set it from the parsed pool or event data.
- The **pumpfun_copy_trading** and **pumpfun_sniper_trading** examples use sol-parser-sdk for gRPC subscription and pass `e.is_cashback_coin` when building params.
- **Claim**: Use `client.claim_cashback_pumpfun()` and `client.claim_cashback_pumpswap(...)` to claim accumulated cashback.
2026-02-19 01:01:21 +08:00
2026-03-07 11:45:33 +08:00
#### PumpFun: Creator Rewards Sharing (creator_vault)
Some PumpFun coins use **Creator Rewards Sharing** , so the on-chain `creator_vault` can differ from the default derivation. If you reuse cached params from a **buy** when **selling** , you may see program error **2006 (seeds constraint violated)** . To avoid this:
- **From gRPC/events (no RPC needed)**: You can get both `creator` and `creator_vault` from parsed transaction events:
- **sol-parser-sdk**: Before pushing events, the pipeline calls `fill_trade_accounts` , which fills `creator_vault` from the buy/sell instruction accounts (buy index 9, sell index 8). `creator` comes from the TradeEvent log. Use `PumpFunParams::from_trade(..., e.creator, e.creator_vault, ...)` or `from_dev_trade(..., e.creator, e.creator_vault, ...)` with the event `e` .
- **solana-streamer**: Instruction parsers set `creator_vault` from accounts[9] (buy) or accounts[8] (sell); `creator` comes from the merged CPI TradeEvent log. Use the same `from_trade` / `from_dev_trade` with `e.creator` and `e.creator_vault` .
- **Override after RPC**: If you get params via `PumpFunParams::from_mint_by_rpc` but later receive a newer `creator_vault` from gRPC, call `.with_creator_vault(latest_creator_vault)` on the params before selling.
The SDK does not fetch creator_vault from RPC on every sell (to avoid latency); pass the up-to-date vault from gRPC/events when available.
#### PumpSwap: coin_creator_vault from events (no RPC)
For **PumpSwap** (Pump AMM), `coin_creator_vault_ata` and `coin_creator_vault_authority` are required in buy/sell instructions. Both are available from parsed events without RPC:
- **sol-parser-sdk**: Instruction parser sets them from accounts 17 and 18; the account filler also fills them when the event comes from logs. Use `PumpSwapParams::from_trade(..., e.coin_creator_vault_ata, e.coin_creator_vault_authority, ...)` with the buy/sell event `e` .
- **solana-streamer**: Instruction parser sets them from `accounts.get(17)` and `accounts.get(18)` . Use the same `from_trade` with the event’ s `coin_creator_vault_ata` and `coin_creator_vault_authority` .
2025-09-10 17:02:54 +08:00
## 🛡️ MEV Protection Services
2025-06-16 18:21:23 +08:00
2025-09-19 00:49:45 +08:00
You can apply for a key through the official website: [Community Website ](https://fnzero.dev/swqos )
2025-06-16 18:21:23 +08:00
- **Jito**: High-performance block space
2025-07-09 22:29:29 +08:00
- **ZeroSlot**: Zero-latency transactions
- **Temporal**: Time-sensitive transactions
- **Bloxroute**: Blockchain network acceleration
2026-03-07 10:47:31 +08:00
- **FlashBlock**: High-speed transaction execution with API key authentication
- **BlockRazor**: High-speed transaction execution with API key authentication
- **Node1**: High-speed transaction execution with API key authentication
2026-04-14 02:13:42 +08:00
- **Astralane**: Blockchain network acceleration (Binary/Plain HTTP and QUIC; see [Astralane ](#astralane-binary--plain--quic ) above)
2025-07-09 22:29:29 +08:00
2025-09-10 17:02:54 +08:00
## 📁 Project Structure
2025-06-16 18:21:23 +08:00
```
src/
2025-07-09 22:29:29 +08:00
├── common/ # Common functionality and tools
├── constants/ # Constant definitions
├── instruction/ # Instruction building
2025-09-19 00:49:45 +08:00
│ └── utils/ # Instruction utilities
2025-07-09 22:29:29 +08:00
├── swqos/ # MEV service clients
├── trading/ # Unified trading engine
│ ├── common/ # Common trading tools
│ ├── core/ # Core trading engine
2025-08-19 18:07:21 +08:00
│ ├── middleware/ # Middleware system
2025-07-10 18:14:21 +08:00
│ └── factory.rs # Trading factory
2025-08-14 22:45:33 +08:00
├── utils/ # Utility functions
2025-09-19 00:49:45 +08:00
│ ├── calc/ # Amount calculation utilities
│ └── price/ # Price calculation utilities
└── lib.rs # Main library file
2025-06-16 18:21:23 +08:00
```
2025-09-10 17:02:54 +08:00
## 📄 License
2025-06-16 18:21:23 +08:00
MIT License
2025-09-10 17:02:54 +08:00
## 💬 Contact
2025-06-16 18:21:23 +08:00
2025-09-06 21:56:59 +08:00
- Official Website: https://fnzero.dev/
2025-07-09 22:29:29 +08:00
- Project Repository: https://github.com/0xfnzero/sol-trade-sdk
2025-06-16 18:21:23 +08:00
- Telegram Group: https://t.me/fnzero_group
2025-09-13 21:09:18 +08:00
- Discord: https://discord.gg/vuazbGkqQE
2025-06-16 18:21:23 +08:00
2026-02-28 20:58:12 +08:00
## ⏱️ Timing metrics (v3.5.0+)
When `log_enabled` and SDK log are on, the executor prints `[SDK] Buy/Sell timing(...)` . **Semantics changed in v3.5.0** : `submit` is now only the send to SWQOS/RPC; `confirm` is separate; `start_to_submit` (when `grpc_recv_us` is set) is **end-to-end from gRPC event to submit** , so it is larger than in-process timings. See [docs/TIMING_METRICS.md ](docs/TIMING_METRICS.md ) for definitions and how to compare with older versions.
2025-09-10 17:02:54 +08:00
## ⚠️ Important Notes
2025-06-16 18:21:23 +08:00
1. Test thoroughly before using on mainnet
2. Properly configure private keys and API tokens
3. Pay attention to slippage settings to avoid transaction failures
4. Monitor balances and transaction fees
5. Comply with relevant laws and regulations