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:
+10
-1
@@ -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
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user