feat: Upgrade to SDK version 0.2.6

- Upgrade solana-streamer-sdk dependency from 0.1.4 to 0.1.5
- Enhance sell function with with_tip parameter to control tip feature
- Improve event subscription using subscribe_events_v2 API with account filtering
- Update documentation and example code for new API
This commit is contained in:
ysq
2025-07-26 17:54:59 +08:00
parent 92bc7aecfa
commit 5cd6c6197d
5 changed files with 102 additions and 12 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
[package]
name = "sol-trade-sdk"
version = "0.2.5"
version = "0.2.6"
edition = "2021"
authors = ["William <byteblock6@gmail.com>", "sgxiang <sgxiang@gmail.com>", "wei <1415121722@qq.com>"]
repository = "https://github.com/0xfnzero/sol-trade-sdk"
@@ -13,7 +13,7 @@ readme = "README.md"
crate-type = ["cdylib", "rlib"]
[dependencies]
solana-streamer-sdk = "0.1.4"
solana-streamer-sdk = "0.1.5"
solana-sdk = "2.1.16"
solana-client = "2.1.16"
solana-program = "2.1.16"
+31 -4
View File
@@ -31,14 +31,14 @@ Add the dependency to your `Cargo.toml`:
```toml
# Add to your Cargo.toml
sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.2.5" }
sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.2.6" }
```
### Use crates.io
```toml
# Add to your Cargo.toml
sol-trade-sdk = "0.2.5"
sol-trade-sdk = "0.2.6"
```
## Usage Examples
@@ -127,8 +127,29 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
// Subscribe to events from multiple protocols
println!("Starting to listen for events, press Ctrl+C to stop...");
let protocols = vec![Protocol::PumpFun, Protocol::PumpSwap, Protocol::Bonk, Protocol::RaydiumCpmm];
grpc.subscribe_events(protocols, None, None, None, None, None, callback)
.await?;
// Filter accounts
let account_include = vec![
PUMPFUN_PROGRAM_ID.to_string(), // Listen to pumpfun program ID
PUMPSWAP_PROGRAM_ID.to_string(), // Listen to pumpswap program ID
BONK_PROGRAM_ID.to_string(), // Listen to bonk program ID
RAYDIUM_CPMM_PROGRAM_ID.to_string(), // Listen to raydium_cpmm program ID
RAYDIUM_CLMM_PROGRAM_ID.to_string(), // Listen to raydium_clmm program ID
"xxxxxxxx".to_string(), // Listen to xxxxx account
];
let account_exclude = vec![];
let account_required = vec![];
grpc.subscribe_events_v2(
protocols,
None,
account_include,
account_exclude,
account_required,
None,
callback,
)
.await?;
Ok(())
}
@@ -339,6 +360,7 @@ async fn test_pumpfun_sell() -> AnyResult<()> {
slippage_basis_points,
recent_blockhash,
None,
false,
None,
)
.await?;
@@ -390,6 +412,7 @@ async fn test_pumpswap() -> AnyResult<()> {
slippage_basis_points,
recent_blockhash,
None,
false,
Some(Box::new(PumpSwapParams {
pool: Some(pool_address),
auto_handle_wsol: true,
@@ -458,6 +481,7 @@ async fn test_raydium_cpmm() -> Result<(), Box<dyn std::error::Error>> {
slippage_basis_points,
recent_blockhash,
None,
false,
Some(Box::new(RaydiumCpmmParams {
pool_state: Some(pool_state), // If not provided, will auto-calculate
mint_token_program: Some(spl_token::ID), // Support spl_token or spl_token_2022::ID
@@ -513,6 +537,7 @@ async fn test_bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyRe
slippage_basis_points,
recent_blockhash,
None,
false,
None,
).await?;
@@ -553,6 +578,7 @@ async fn test_bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult
slippage_basis_points,
recent_blockhash,
None,
false,
None,
).await?;
@@ -595,6 +621,7 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
slippage_basis_points,
recent_blockhash,
None,
false,
None,
)
.await?;
+30 -4
View File
@@ -31,14 +31,14 @@ git clone https://github.com/0xfnzero/sol-trade-sdk
```toml
# 添加到您的 Cargo.toml
sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.2.5" }
sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.2.6" }
```
### 使用 crates.io
```toml
# 添加到您的 Cargo.toml
sol-trade-sdk = "0.2.5"
sol-trade-sdk = "0.2.6"
```
## 使用示例
@@ -127,8 +127,29 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
// 订阅多个协议的事件
println!("开始监听事件,按 Ctrl+C 停止...");
let protocols = vec![Protocol::PumpFun, Protocol::PumpSwap, Protocol::Bonk, Protocol::RaydiumCpmm];
grpc.subscribe_events(protocols, None, None, None, None, None, callback)
.await?;
// Filter accounts
let account_include = vec![
PUMPFUN_PROGRAM_ID.to_string(), // Listen to pumpfun program ID
PUMPSWAP_PROGRAM_ID.to_string(), // Listen to pumpswap program ID
BONK_PROGRAM_ID.to_string(), // Listen to bonk program ID
RAYDIUM_CPMM_PROGRAM_ID.to_string(), // Listen to raydium_cpmm program ID
RAYDIUM_CLMM_PROGRAM_ID.to_string(), // Listen to raydium_clmm program ID
"xxxxxxxx".to_string(), // Listen to xxxxx account
];
let account_exclude = vec![];
let account_required = vec![];
grpc.subscribe_events_v2(
protocols,
None,
account_include,
account_exclude,
account_required,
None,
callback,
)
.await?;
Ok(())
}
@@ -388,6 +409,7 @@ async fn test_pumpswap() -> AnyResult<()> {
slippage_basis_points,
recent_blockhash,
None,
false,
Some(Box::new(PumpSwapParams {
pool: Some(pool_address),
auto_handle_wsol: true,
@@ -456,6 +478,7 @@ async fn test_raydium_cpmm() -> Result<(), Box<dyn std::error::Error>> {
slippage_basis_points,
recent_blockhash,
None,
false,
Some(Box::new(RaydiumCpmmParams {
pool_state: Some(pool_state), // 如果不传,会自动计算
mint_token_program: Some(spl_token::ID), // 支持 spl_token 或 spl_token_2022::ID
@@ -511,6 +534,7 @@ async fn test_bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyRe
slippage_basis_points,
recent_blockhash,
None,
false,
None,
).await?;
@@ -551,6 +575,7 @@ async fn test_bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult
slippage_basis_points,
recent_blockhash,
None,
false,
None,
).await?;
@@ -593,6 +618,7 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
slippage_basis_points,
recent_blockhash,
None,
false,
None,
)
.await?;
+10 -1
View File
@@ -250,6 +250,7 @@ impl SolanaTrade {
/// * `slippage_basis_points` - Optional slippage tolerance in basis points (e.g., 100 = 1%)
/// * `recent_blockhash` - Recent blockhash for transaction validity
/// * `custom_buy_tip_fee` - Optional custom tip fee for priority processing (in SOL)
/// * `with_tip` - Optional boolean to indicate if the transaction should be sent with tip
/// * `extension_params` - Optional protocol-specific parameters (uses defaults if None)
///
/// # Returns
@@ -285,6 +286,7 @@ impl SolanaTrade {
/// slippage,
/// recent_blockhash,
/// None,
/// false,
/// None,
/// ).await?;
/// ```
@@ -297,6 +299,7 @@ impl SolanaTrade {
slippage_basis_points: Option<u64>,
recent_blockhash: Hash,
custom_buy_tip_fee: Option<f64>,
with_tip: bool,
extension_params: Option<Box<dyn ProtocolParams>>,
) -> Result<(), anyhow::Error> {
let executor = TradeFactory::create_executor(dex_type.clone());
@@ -360,7 +363,11 @@ impl SolanaTrade {
}
// Execute sell based on tip preference
executor.sell_with_tip(sell_with_tip_params).await
if with_tip {
executor.sell_with_tip(sell_with_tip_params).await
} else {
executor.sell(sell_params).await
}
}
/// Execute a sell order for a percentage of the specified token amount
@@ -430,6 +437,7 @@ impl SolanaTrade {
slippage_basis_points: Option<u64>,
recent_blockhash: Hash,
custom_buy_tip_fee: Option<f64>,
with_tip: bool,
extension_params: Option<Box<dyn ProtocolParams>>,
) -> Result<(), anyhow::Error> {
if percent == 0 || percent > 100 {
@@ -444,6 +452,7 @@ impl SolanaTrade {
slippage_basis_points,
recent_blockhash,
custom_buy_tip_fee,
with_tip,
extension_params,
)
.await
+29 -1
View File
@@ -24,6 +24,7 @@ use sol_trade_sdk::solana_streamer_sdk::{
},
};
use solana_sdk::{commitment_config::CommitmentConfig, pubkey::Pubkey, signature::Keypair};
use solana_streamer_sdk::streaming::event_parser::protocols::{bonk::parser::BONK_PROGRAM_ID, pumpfun::parser::PUMPFUN_PROGRAM_ID, pumpswap::parser::PUMPSWAP_PROGRAM_ID, raydium_clmm::parser::RAYDIUM_CLMM_PROGRAM_ID, raydium_cpmm::parser::RAYDIUM_CPMM_PROGRAM_ID};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -110,6 +111,7 @@ async fn test_pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> Any
slippage_basis_points,
recent_blockhash,
None,
false,
None,
).await?;
@@ -163,6 +165,7 @@ async fn test_pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) ->
slippage_basis_points,
recent_blockhash,
None,
false,
None,
).await?;
@@ -207,6 +210,7 @@ async fn test_pumpswap() -> AnyResult<()> {
slippage_basis_points,
recent_blockhash,
None,
false,
Some(Box::new(PumpSwapParams {
pool: Some(pool_address),
auto_handle_wsol: true,
@@ -251,6 +255,7 @@ async fn test_bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult
slippage_basis_points,
recent_blockhash,
None,
false,
None,
).await?;
@@ -294,6 +299,7 @@ async fn test_bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyRe
slippage_basis_points,
recent_blockhash,
None,
false,
None,
).await?;
@@ -334,6 +340,7 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
slippage_basis_points,
recent_blockhash,
None,
false,
None,
).await?;
@@ -382,6 +389,7 @@ async fn test_raydium_cpmm() -> Result<(), Box<dyn std::error::Error>> {
slippage_basis_points,
recent_blockhash,
None,
false,
Some(Box::new(RaydiumCpmmParams {
pool_state: Some(pool_state), // 如果不传,会自动计算
mint_token_program: Some(spl_token::ID), // spl_token_2022::ID
@@ -404,9 +412,29 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
let callback = create_event_callback();
let protocols = vec![Protocol::PumpFun, Protocol::PumpSwap, Protocol::Bonk, Protocol::RaydiumCpmm];
// Filter accounts
let account_include = vec![
PUMPFUN_PROGRAM_ID.to_string(), // Listen to pumpfun program ID
PUMPSWAP_PROGRAM_ID.to_string(), // Listen to pumpswap program ID
BONK_PROGRAM_ID.to_string(), // Listen to bonk program ID
RAYDIUM_CPMM_PROGRAM_ID.to_string(), // Listen to raydium_cpmm program ID
RAYDIUM_CLMM_PROGRAM_ID.to_string(), // Listen to raydium_clmm program ID
"xxxxxxxx".to_string(), // Listen to xxxxx account
];
let account_exclude = vec![];
let account_required = vec![];
println!("开始监听事件,按 Ctrl+C 停止...");
grpc.subscribe_events(protocols, None, None, None, None, None, callback).await?;
grpc.subscribe_events_v2(
protocols,
None,
account_include,
account_exclude,
account_required,
None,
callback,
)
.await?;
Ok(())
}