From 29179519a62cc82f165015f6f00cd773ead994e3 Mon Sep 17 00:00:00 2001 From: ysq Date: Wed, 13 Aug 2025 23:57:56 +0800 Subject: [PATCH] feat: upgrade to v0.3.4 with enhanced trading system --- Cargo.toml | 4 ++-- README.md | 39 ++++++++++++++++++++++++++++++++------ README_CN.md | 53 +++++++++++++++++++++++++++++++++++++++------------- src/main.rs | 24 ++++++++++++++++++------ 4 files changed, 93 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5fc6fe4..26231a4 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sol-trade-sdk" -version = "0.3.3" +version = "0.3.4" edition = "2021" authors = ["William ", "sgxiang ", "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.2.4" +solana-streamer-sdk = "0.3.1" solana-sdk = "2.3.0" solana-client = "2.3.6" solana-program = "2.3.0" diff --git a/README.md b/README.md index 8214230..d01fe14 100755 --- a/README.md +++ b/README.md @@ -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.3.3" } +sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.3.4" } ``` ### Use crates.io ```toml # Add to your Cargo.toml -sol-trade-sdk = "0.3.3" +sol-trade-sdk = "0.3.4" ``` ## Usage Examples @@ -74,11 +74,21 @@ use sol_trade_sdk::solana_streamer_sdk::{ }, Protocol, UnifiedEvent, }, + yellowstone_grpc::{AccountFilter, TransactionFilter}, YellowstoneGrpc, }, match_event, }; +use solana_streamer_sdk::streaming::event_parser::protocols::{ + bonk::parser::BONK_PROGRAM_ID, + pumpfun::parser::PUMPFUN_PROGRAM_ID, + pumpswap::parser::PUMPSWAP_PROGRAM_ID, + raydium_amm_v4::parser::RAYDIUM_AMM_V4_PROGRAM_ID, + raydium_clmm::parser::RAYDIUM_CLMM_PROGRAM_ID, + raydium_cpmm::parser::RAYDIUM_CPMM_PROGRAM_ID +}; + async fn test_grpc() -> Result<(), Box> { // Subscribe to events using GRPC client println!("Subscribing to GRPC events..."); @@ -121,6 +131,8 @@ async fn test_grpc() -> Result<(), Box> { RaydiumCpmmSwapEvent => |e: RaydiumCpmmSwapEvent| { println!("Raydium CPMM Swap event: {:?}", e); }, + // ..... + // For more events and documentation, please refer to https://github.com/0xfnzero/solana-streamer }); }; @@ -135,17 +147,30 @@ async fn test_grpc() -> Result<(), Box> { 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 + RAYDIUM_AMM_V4_PROGRAM_ID.to_string(), // Listen to raydium_amm_v4 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, + // Transaction filter for monitoring transaction data + let transaction_filter = TransactionFilter { + account_include: account_include.clone(), account_exclude, account_required, + }; + + // Account filter for monitoring account data owned by programs + let account_filter = AccountFilter { + account: vec![], + owner: account_include.clone() + }; + + grpc.subscribe_events_immediate( + protocols, + None, + transaction_filter, + account_filter, None, callback, ) @@ -199,6 +224,8 @@ async fn test_shreds() -> Result<(), Box> { RaydiumCpmmSwapEvent => |e: RaydiumCpmmSwapEvent| { println!("Raydium CPMM Swap event: {:?}", e); }, + // ..... + // For more events and documentation, please refer to https://github.com/0xfnzero/solana-streamer }); }; diff --git a/README_CN.md b/README_CN.md index a2004b1..65ea322 100755 --- a/README_CN.md +++ b/README_CN.md @@ -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.3.3" } +sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.3.4" } ``` ### 使用 crates.io ```toml # 添加到您的 Cargo.toml -sol-trade-sdk = "0.3.3" +sol-trade-sdk = "0.3.4" ``` ## 使用示例 @@ -74,11 +74,21 @@ use sol_trade_sdk::solana_streamer_sdk::{ }, Protocol, UnifiedEvent, }, + yellowstone_grpc::{AccountFilter, TransactionFilter}, YellowstoneGrpc, }, match_event, }; +use solana_streamer_sdk::streaming::event_parser::protocols::{ + bonk::parser::BONK_PROGRAM_ID, + pumpfun::parser::PUMPFUN_PROGRAM_ID, + pumpswap::parser::PUMPSWAP_PROGRAM_ID, + raydium_amm_v4::parser::RAYDIUM_AMM_V4_PROGRAM_ID, + raydium_clmm::parser::RAYDIUM_CLMM_PROGRAM_ID, + raydium_cpmm::parser::RAYDIUM_CPMM_PROGRAM_ID +}; + async fn test_grpc() -> Result<(), Box> { // 使用 GRPC 客户端订阅事件 println!("正在订阅 GRPC 事件..."); @@ -121,6 +131,8 @@ async fn test_grpc() -> Result<(), Box> { RaydiumCpmmSwapEvent => |e: RaydiumCpmmSwapEvent| { println!("Raydium CPMM Swap event: {:?}", e); }, + // ..... + // 更多的事件和说明请参考 https://github.com/0xfnzero/solana-streamer }); }; @@ -128,24 +140,37 @@ async fn test_grpc() -> Result<(), Box> { println!("开始监听事件,按 Ctrl+C 停止..."); 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 + PUMPFUN_PROGRAM_ID.to_string(), // 监听 pumpfun 程序 ID + PUMPSWAP_PROGRAM_ID.to_string(), // 监听 pumpswap 程序 ID + BONK_PROGRAM_ID.to_string(), // 监听 bonk 程序 ID + RAYDIUM_CPMM_PROGRAM_ID.to_string(), // 监听 raydium_cpmm 程序 ID + RAYDIUM_CLMM_PROGRAM_ID.to_string(), // 监听 raydium_clmm 程序 ID + RAYDIUM_AMM_V4_PROGRAM_ID.to_string(), // 监听 raydium_amm_v4 程序 ID + "xxxxxxxx".to_string(), // 监听特定账户 ]; let account_exclude = vec![]; let account_required = vec![]; - grpc.subscribe_events_v2( - protocols, - None, - account_include, + // 监听交易数据 + let transaction_filter = TransactionFilter { + account_include: account_include.clone(), account_exclude, account_required, + }; + + // 监听属于owner程序的账号数据 -> 账号事件监听 + let account_filter = AccountFilter { + account: vec![], + owner: account_include.clone() + }; + + grpc.subscribe_events_immediate( + protocols, + None, + transaction_filter, + account_filter, None, callback, ) @@ -199,6 +224,8 @@ async fn test_shreds() -> Result<(), Box> { RaydiumCpmmSwapEvent => |e: RaydiumCpmmSwapEvent| { println!("Raydium CPMM Swap event: {:?}", e); }, + // ..... + // 更多的事件和说明请参考 https://github.com/0xfnzero/solana-streamer }); }; diff --git a/src/main.rs b/src/main.rs index c6b3ead..801b0dc 100755 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +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}; +use solana_streamer_sdk::streaming::{event_parser::protocols::{bonk::parser::BONK_PROGRAM_ID, pumpfun::parser::PUMPFUN_PROGRAM_ID, pumpswap::parser::PUMPSWAP_PROGRAM_ID, raydium_amm_v4::parser::RAYDIUM_AMM_V4_PROGRAM_ID, raydium_clmm::parser::RAYDIUM_CLMM_PROGRAM_ID, raydium_cpmm::parser::RAYDIUM_CPMM_PROGRAM_ID}, yellowstone_grpc::{AccountFilter, TransactionFilter}}; #[tokio::main] async fn main() -> Result<(), Box> { @@ -431,18 +431,28 @@ async fn test_grpc() -> Result<(), Box> { 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 + RAYDIUM_AMM_V4_PROGRAM_ID.to_string(), // Listen to raydium_amm_v4 program ID "xxxxxxxx".to_string(), // Listen to xxxxx account ]; let account_exclude = vec![]; let account_required = vec![]; - println!("开始监听事件,按 Ctrl+C 停止..."); - grpc.subscribe_events_v2( - protocols, - None, - account_include, + // 监听交易数据 + let transaction_filter = TransactionFilter { + account_include: account_include.clone(), account_exclude, account_required, + }; + + // 监听属于owner程序的账号数据 -> 账号事件监听 + let account_filter = AccountFilter { account: vec![], owner: account_include.clone() }; + + println!("开始监听事件,按 Ctrl+C 停止..."); + grpc.subscribe_events_immediate( + protocols, + None, + transaction_filter, + account_filter, None, callback, ) @@ -497,6 +507,8 @@ fn create_event_callback() -> impl Fn(Box) { RaydiumCpmmSwapEvent => |e: RaydiumCpmmSwapEvent| { println!("RaydiumCpmmSwapEvent: {:?}", e); }, + // ..... + // 更多的事件和说明请参考 https://github.com/0xfnzero/solana-streamer }); } }