feat: upgrade to v3.3.1 with enhanced error handling
Major changes: - Bump version from 3.3.0 to 3.3.1 - Update GasFeeStrategy API with min/max data size parameters - Enhance trade return values with Optional<anyhow::Error> in buy/sell/sell_percent methods - Fix PumpFun Mayhem mode fee recipient constant bug - Standardize gas fee strategy parameters across all examples - Update all examples to handle new triple return value (bool, Signature, Option<Error>)
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "sol-trade-sdk"
|
name = "sol-trade-sdk"
|
||||||
version = "3.3.0"
|
version = "3.3.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = [
|
authors = [
|
||||||
"William <byteblock6@gmail.com>",
|
"William <byteblock6@gmail.com>",
|
||||||
|
|||||||
@@ -87,14 +87,14 @@ Add the dependency to your `Cargo.toml`:
|
|||||||
|
|
||||||
```toml
|
```toml
|
||||||
# Add to your Cargo.toml
|
# Add to your Cargo.toml
|
||||||
sol-trade-sdk = { path = "./sol-trade-sdk", version = "3.3.0" }
|
sol-trade-sdk = { path = "./sol-trade-sdk", version = "3.3.1" }
|
||||||
```
|
```
|
||||||
|
|
||||||
### Use crates.io
|
### Use crates.io
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
# Add to your Cargo.toml
|
# Add to your Cargo.toml
|
||||||
sol-trade-sdk = "3.3.0"
|
sol-trade-sdk = "3.3.1"
|
||||||
```
|
```
|
||||||
|
|
||||||
## 🛠️ Usage Examples
|
## 🛠️ Usage Examples
|
||||||
@@ -146,7 +146,7 @@ For detailed information about Gas Fee Strategy, see the [Gas Fee Strategy Refer
|
|||||||
// Create GasFeeStrategy instance
|
// Create GasFeeStrategy instance
|
||||||
let gas_fee_strategy = GasFeeStrategy::new();
|
let gas_fee_strategy = GasFeeStrategy::new();
|
||||||
// Set global strategy
|
// Set global strategy
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 3. Build Trading Parameters
|
#### 3. Build Trading Parameters
|
||||||
|
|||||||
+3
-3
@@ -87,14 +87,14 @@ git clone https://github.com/0xfnzero/sol-trade-sdk
|
|||||||
|
|
||||||
```toml
|
```toml
|
||||||
# 添加到您的 Cargo.toml
|
# 添加到您的 Cargo.toml
|
||||||
sol-trade-sdk = { path = "./sol-trade-sdk", version = "3.3.0" }
|
sol-trade-sdk = { path = "./sol-trade-sdk", version = "3.3.1" }
|
||||||
```
|
```
|
||||||
|
|
||||||
### 使用 crates.io
|
### 使用 crates.io
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
# 添加到您的 Cargo.toml
|
# 添加到您的 Cargo.toml
|
||||||
sol-trade-sdk = "3.3.0"
|
sol-trade-sdk = "3.3.1"
|
||||||
```
|
```
|
||||||
|
|
||||||
## 🛠️ 使用示例
|
## 🛠️ 使用示例
|
||||||
@@ -146,7 +146,7 @@ let client = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
|||||||
// 创建 GasFeeStrategy 实例
|
// 创建 GasFeeStrategy 实例
|
||||||
let gas_fee_strategy = GasFeeStrategy::new();
|
let gas_fee_strategy = GasFeeStrategy::new();
|
||||||
// 设置全局策略
|
// 设置全局策略
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 3. 构建交易参数
|
#### 3. 构建交易参数
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
|||||||
fetch_address_lookup_table_account(&client.rpc, &lookup_table_key).await.ok();
|
fetch_address_lookup_table_account(&client.rpc, &lookup_table_key).await.ok();
|
||||||
|
|
||||||
let gas_fee_strategy = GasFeeStrategy::new();
|
let gas_fee_strategy = GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
// Buy tokens
|
// Buy tokens
|
||||||
println!("Buying tokens from PumpFun...");
|
println!("Buying tokens from PumpFun...");
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
|
|||||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||||
|
|
||||||
let gas_fee_strategy = GasFeeStrategy::new();
|
let gas_fee_strategy = GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
// Buy tokens
|
// Buy tokens
|
||||||
println!("Buying tokens from Bonk...");
|
println!("Buying tokens from Bonk...");
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult<
|
|||||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
let token_type = if trade_info.quote_token_mint == sol_trade_sdk::constants::USD1_TOKEN_ACCOUNT
|
let token_type = if trade_info.quote_token_mint == sol_trade_sdk::constants::USD1_TOKEN_ACCOUNT
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -615,7 +615,7 @@ async fn handle_buy_pumpfun(
|
|||||||
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
|
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
let buy_params = TradeBuyParams {
|
let buy_params = TradeBuyParams {
|
||||||
dex_type: DexType::PumpFun,
|
dex_type: DexType::PumpFun,
|
||||||
@@ -636,7 +636,7 @@ async fn handle_buy_pumpfun(
|
|||||||
simulate: false,
|
simulate: false,
|
||||||
};
|
};
|
||||||
match client.buy(buy_params).await {
|
match client.buy(buy_params).await {
|
||||||
Ok((_, signature)) => {
|
Ok((_, signature, _)) => {
|
||||||
println!(" ✅ Successfully bought tokens from PumpFun!");
|
println!(" ✅ Successfully bought tokens from PumpFun!");
|
||||||
println!(" ✅ Transaction Signature: {:?}", signature);
|
println!(" ✅ Transaction Signature: {:?}", signature);
|
||||||
}
|
}
|
||||||
@@ -669,7 +669,7 @@ async fn handle_buy_pumpswap(
|
|||||||
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
|
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
let buy_params = TradeBuyParams {
|
let buy_params = TradeBuyParams {
|
||||||
dex_type: DexType::PumpSwap,
|
dex_type: DexType::PumpSwap,
|
||||||
@@ -690,7 +690,7 @@ async fn handle_buy_pumpswap(
|
|||||||
simulate: false,
|
simulate: false,
|
||||||
};
|
};
|
||||||
match client.buy(buy_params).await {
|
match client.buy(buy_params).await {
|
||||||
Ok((_, signature)) => {
|
Ok((_, signature, _)) => {
|
||||||
println!(" ✅ Successfully bought tokens from PumpSwap!");
|
println!(" ✅ Successfully bought tokens from PumpSwap!");
|
||||||
println!(" ✅ Transaction Signature: {:?}", signature);
|
println!(" ✅ Transaction Signature: {:?}", signature);
|
||||||
}
|
}
|
||||||
@@ -722,7 +722,7 @@ async fn handle_buy_bonk(
|
|||||||
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
|
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
let buy_params = TradeBuyParams {
|
let buy_params = TradeBuyParams {
|
||||||
dex_type: DexType::Bonk,
|
dex_type: DexType::Bonk,
|
||||||
@@ -743,7 +743,7 @@ async fn handle_buy_bonk(
|
|||||||
simulate: false,
|
simulate: false,
|
||||||
};
|
};
|
||||||
match client.buy(buy_params).await {
|
match client.buy(buy_params).await {
|
||||||
Ok((_, signature)) => {
|
Ok((_, signature, _)) => {
|
||||||
println!(" ✅ Successfully bought tokens from Bonk!");
|
println!(" ✅ Successfully bought tokens from Bonk!");
|
||||||
println!(" ✅ Transaction Signature: {:?}", signature);
|
println!(" ✅ Transaction Signature: {:?}", signature);
|
||||||
}
|
}
|
||||||
@@ -779,7 +779,7 @@ async fn handle_buy_raydium_v4(
|
|||||||
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
|
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
let buy_params = TradeBuyParams {
|
let buy_params = TradeBuyParams {
|
||||||
dex_type: DexType::RaydiumAmmV4,
|
dex_type: DexType::RaydiumAmmV4,
|
||||||
@@ -800,7 +800,7 @@ async fn handle_buy_raydium_v4(
|
|||||||
simulate: false,
|
simulate: false,
|
||||||
};
|
};
|
||||||
match client.buy(buy_params).await {
|
match client.buy(buy_params).await {
|
||||||
Ok((_, signature)) => {
|
Ok((_, signature, _)) => {
|
||||||
println!(" ✅ Successfully bought tokens from Raydium V4!");
|
println!(" ✅ Successfully bought tokens from Raydium V4!");
|
||||||
println!(" ✅ Transaction Signature: {:?}", signature);
|
println!(" ✅ Transaction Signature: {:?}", signature);
|
||||||
}
|
}
|
||||||
@@ -836,7 +836,7 @@ async fn handle_buy_raydium_cpmm(
|
|||||||
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
|
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
let buy_params = TradeBuyParams {
|
let buy_params = TradeBuyParams {
|
||||||
dex_type: DexType::RaydiumCpmm,
|
dex_type: DexType::RaydiumCpmm,
|
||||||
@@ -857,7 +857,7 @@ async fn handle_buy_raydium_cpmm(
|
|||||||
simulate: false,
|
simulate: false,
|
||||||
};
|
};
|
||||||
match client.buy(buy_params).await {
|
match client.buy(buy_params).await {
|
||||||
Ok((_, signature)) => {
|
Ok((_, signature, _)) => {
|
||||||
println!(" ✅ Successfully bought tokens from Raydium CPMM!");
|
println!(" ✅ Successfully bought tokens from Raydium CPMM!");
|
||||||
println!(" ✅ Transaction Signature: {:?}", signature);
|
println!(" ✅ Transaction Signature: {:?}", signature);
|
||||||
}
|
}
|
||||||
@@ -1003,7 +1003,7 @@ async fn handle_sell_pumpfun(
|
|||||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
let sell_params = TradeSellParams {
|
let sell_params = TradeSellParams {
|
||||||
dex_type: DexType::PumpFun,
|
dex_type: DexType::PumpFun,
|
||||||
@@ -1026,7 +1026,7 @@ async fn handle_sell_pumpfun(
|
|||||||
};
|
};
|
||||||
|
|
||||||
match client.sell(sell_params).await {
|
match client.sell(sell_params).await {
|
||||||
Ok((_, signature)) => {
|
Ok((_, signature, _)) => {
|
||||||
println!(" ✅ Successfully sold tokens from PumpFun!");
|
println!(" ✅ Successfully sold tokens from PumpFun!");
|
||||||
println!(" ✅ Transaction Signature: {:?}", signature);
|
println!(" ✅ Transaction Signature: {:?}", signature);
|
||||||
}
|
}
|
||||||
@@ -1061,7 +1061,7 @@ async fn handle_sell_pumpswap(
|
|||||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
let sell_params = TradeSellParams {
|
let sell_params = TradeSellParams {
|
||||||
dex_type: DexType::PumpSwap,
|
dex_type: DexType::PumpSwap,
|
||||||
@@ -1083,7 +1083,7 @@ async fn handle_sell_pumpswap(
|
|||||||
simulate: false,
|
simulate: false,
|
||||||
};
|
};
|
||||||
match client.sell(sell_params).await {
|
match client.sell(sell_params).await {
|
||||||
Ok((_, signature)) => {
|
Ok((_, signature, _)) => {
|
||||||
println!(" ✅ Successfully sold tokens from PumpSwap!");
|
println!(" ✅ Successfully sold tokens from PumpSwap!");
|
||||||
println!(" ✅ Transaction Signature: {}", signature);
|
println!(" ✅ Transaction Signature: {}", signature);
|
||||||
}
|
}
|
||||||
@@ -1118,7 +1118,7 @@ async fn handle_sell_bonk(
|
|||||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
let sell_params = TradeSellParams {
|
let sell_params = TradeSellParams {
|
||||||
dex_type: DexType::Bonk,
|
dex_type: DexType::Bonk,
|
||||||
@@ -1140,7 +1140,7 @@ async fn handle_sell_bonk(
|
|||||||
simulate: false,
|
simulate: false,
|
||||||
};
|
};
|
||||||
match client.sell(sell_params).await {
|
match client.sell(sell_params).await {
|
||||||
Ok((_, signature)) => {
|
Ok((_, signature, _)) => {
|
||||||
println!(" ✅ Successfully sold tokens from Bonk!");
|
println!(" ✅ Successfully sold tokens from Bonk!");
|
||||||
println!(" ✅ Transaction Signature: {:?}", signature);
|
println!(" ✅ Transaction Signature: {:?}", signature);
|
||||||
}
|
}
|
||||||
@@ -1178,7 +1178,7 @@ async fn handle_sell_raydium_v4(
|
|||||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
let sell_params = TradeSellParams {
|
let sell_params = TradeSellParams {
|
||||||
dex_type: DexType::RaydiumAmmV4,
|
dex_type: DexType::RaydiumAmmV4,
|
||||||
@@ -1200,7 +1200,7 @@ async fn handle_sell_raydium_v4(
|
|||||||
simulate: false,
|
simulate: false,
|
||||||
};
|
};
|
||||||
match client.sell(sell_params).await {
|
match client.sell(sell_params).await {
|
||||||
Ok((_, signature)) => {
|
Ok((_, signature, _)) => {
|
||||||
println!(" ✅ Successfully sold tokens from Raydium V4!");
|
println!(" ✅ Successfully sold tokens from Raydium V4!");
|
||||||
println!(" ✅ Transaction Signature: {:?}", signature);
|
println!(" ✅ Transaction Signature: {:?}", signature);
|
||||||
}
|
}
|
||||||
@@ -1238,7 +1238,7 @@ async fn handle_sell_raydium_cpmm(
|
|||||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
let sell_params = TradeSellParams {
|
let sell_params = TradeSellParams {
|
||||||
dex_type: DexType::RaydiumCpmm,
|
dex_type: DexType::RaydiumCpmm,
|
||||||
@@ -1260,7 +1260,7 @@ async fn handle_sell_raydium_cpmm(
|
|||||||
simulate: false,
|
simulate: false,
|
||||||
};
|
};
|
||||||
match client.sell(sell_params).await {
|
match client.sell(sell_params).await {
|
||||||
Ok((_, signature)) => {
|
Ok((_, signature, _)) => {
|
||||||
println!(" ✅ Successfully sold tokens from Raydium CPMM!");
|
println!(" ✅ Successfully sold tokens from Raydium CPMM!");
|
||||||
println!(" ✅ Transaction Signature: {:?}", signature);
|
println!(" ✅ Transaction Signature: {:?}", signature);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ async fn main() {
|
|||||||
|
|
||||||
// Set global strategy
|
// Set global strategy
|
||||||
println!("1. Set global strategy");
|
println!("1. Set global strategy");
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
// Print all strategies
|
// Print all strategies
|
||||||
println!("\n2. Print all strategies");
|
println!("\n2. Print all strategies");
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let mint_pubkey = Pubkey::from_str("PRVT6TB7uss3FrUd2D9xs2zqDBsa3GbMJMwCQsgmeta").unwrap();
|
let mint_pubkey = Pubkey::from_str("PRVT6TB7uss3FrUd2D9xs2zqDBsa3GbMJMwCQsgmeta").unwrap();
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
// Buy tokens
|
// Buy tokens
|
||||||
println!("Buying tokens from Metaora Damm V2...");
|
println!("Buying tokens from Metaora Damm V2...");
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ async fn test_middleware() -> AnyResult<()> {
|
|||||||
let pool_address = Pubkey::from_str("539m4mVWt6iduB6W8rDGPMarzNCMesuqY5eUTiiYHAgR")?;
|
let pool_address = Pubkey::from_str("539m4mVWt6iduB6W8rDGPMarzNCMesuqY5eUTiiYHAgR")?;
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||||
dex_type: DexType::PumpSwap,
|
dex_type: DexType::PumpSwap,
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
|||||||
let durable_nonce = fetch_nonce_info(&client.rpc, nonce_account_str).await;
|
let durable_nonce = fetch_nonce_info(&client.rpc, nonce_account_str).await;
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
// Buy tokens
|
// Buy tokens
|
||||||
println!("Buying tokens from PumpFun...");
|
println!("Buying tokens from PumpFun...");
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
|||||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
// Buy tokens
|
// Buy tokens
|
||||||
println!("Buying tokens from PumpFun...");
|
println!("Buying tokens from PumpFun...");
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
|
|||||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
// Buy tokens
|
// Buy tokens
|
||||||
println!("Buying tokens from PumpFun...");
|
println!("Buying tokens from PumpFun...");
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let mint_pubkey = Pubkey::from_str("pumpCmXqMfrsAkQ5r49WcJnRayYRqmXz6ae8H7H9Dfn").unwrap();
|
let mint_pubkey = Pubkey::from_str("pumpCmXqMfrsAkQ5r49WcJnRayYRqmXz6ae8H7H9Dfn").unwrap();
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
// Buy tokens
|
// Buy tokens
|
||||||
println!("Buying tokens from PumpSwap...");
|
println!("Buying tokens from PumpSwap...");
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
|
|||||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
let is_sol = params.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT
|
let is_sol = params.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT
|
||||||
|| params.quote_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT;
|
|| params.quote_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT;
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
|
|||||||
);
|
);
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
// Buy tokens
|
// Buy tokens
|
||||||
println!("Buying tokens from Raydium_amm_v4...");
|
println!("Buying tokens from Raydium_amm_v4...");
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
|
|||||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
let buy_params =
|
let buy_params =
|
||||||
RaydiumCpmmParams::from_pool_address_by_rpc(&client.rpc, &trade_info.pool_state).await?;
|
RaydiumCpmmParams::from_pool_address_by_rpc(&client.rpc, &trade_info.pool_state).await?;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let mint_pubkey = Pubkey::from_str("2zMMhcVQEXDtdE6vsFS7S7D5oUodfJHE8vd1gnBouauv").unwrap();
|
let mint_pubkey = Pubkey::from_str("2zMMhcVQEXDtdE6vsFS7S7D5oUodfJHE8vd1gnBouauv").unwrap();
|
||||||
|
|
||||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0);
|
gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0);
|
||||||
|
|
||||||
// Buy tokens
|
// Buy tokens
|
||||||
println!("Buying tokens from PumpSwap...");
|
println!("Buying tokens from PumpSwap...");
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ pub mod global_constants {
|
|||||||
pubkey!("GesfTA3X2arioaHp8bbKdjG9vJtskViWACZoYvxp4twS");
|
pubkey!("GesfTA3X2arioaHp8bbKdjG9vJtskViWACZoYvxp4twS");
|
||||||
pub const MAYHEM_FEE_RECIPIENT_META: solana_sdk::instruction::AccountMeta =
|
pub const MAYHEM_FEE_RECIPIENT_META: solana_sdk::instruction::AccountMeta =
|
||||||
solana_sdk::instruction::AccountMeta {
|
solana_sdk::instruction::AccountMeta {
|
||||||
pubkey: FEE_RECIPIENT,
|
pubkey: MAYHEM_FEE_RECIPIENT,
|
||||||
is_signer: false,
|
is_signer: false,
|
||||||
is_writable: true,
|
is_writable: true,
|
||||||
};
|
};
|
||||||
|
|||||||
+3
-3
@@ -345,7 +345,7 @@ impl SolanaTrade {
|
|||||||
/// - Network or RPC errors occur
|
/// - Network or RPC errors occur
|
||||||
/// - Insufficient SOL balance for the purchase
|
/// - Insufficient SOL balance for the purchase
|
||||||
/// - Required accounts cannot be created or accessed
|
/// - Required accounts cannot be created or accessed
|
||||||
pub async fn buy(&self, params: TradeBuyParams) -> Result<(bool, Signature), anyhow::Error> {
|
pub async fn buy(&self, params: TradeBuyParams) -> Result<(bool, Signature, Option<anyhow::Error>), anyhow::Error> {
|
||||||
if params.slippage_basis_points.is_none() {
|
if params.slippage_basis_points.is_none() {
|
||||||
println!(
|
println!(
|
||||||
"slippage_basis_points is none, use default slippage basis points: {}",
|
"slippage_basis_points is none, use default slippage basis points: {}",
|
||||||
@@ -445,7 +445,7 @@ impl SolanaTrade {
|
|||||||
/// - Insufficient token balance for the sale
|
/// - Insufficient token balance for the sale
|
||||||
/// - Token account doesn't exist or is not properly initialized
|
/// - Token account doesn't exist or is not properly initialized
|
||||||
/// - Required accounts cannot be created or accessed
|
/// - Required accounts cannot be created or accessed
|
||||||
pub async fn sell(&self, params: TradeSellParams) -> Result<(bool, Signature), anyhow::Error> {
|
pub async fn sell(&self, params: TradeSellParams) -> Result<(bool, Signature, Option<anyhow::Error>), anyhow::Error> {
|
||||||
if params.slippage_basis_points.is_none() {
|
if params.slippage_basis_points.is_none() {
|
||||||
println!(
|
println!(
|
||||||
"slippage_basis_points is none, use default slippage basis points: {}",
|
"slippage_basis_points is none, use default slippage basis points: {}",
|
||||||
@@ -557,7 +557,7 @@ impl SolanaTrade {
|
|||||||
mut params: TradeSellParams,
|
mut params: TradeSellParams,
|
||||||
amount_token: u64,
|
amount_token: u64,
|
||||||
percent: u64,
|
percent: u64,
|
||||||
) -> Result<(bool, Signature), anyhow::Error> {
|
) -> Result<(bool, Signature, Option<anyhow::Error>), anyhow::Error> {
|
||||||
if percent == 0 || percent > 100 {
|
if percent == 0 || percent > 100 {
|
||||||
return Err(anyhow::anyhow!("Percentage must be between 1 and 100"));
|
return Err(anyhow::anyhow!("Percentage must be between 1 and 100"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ use crate::{
|
|||||||
struct TaskResult {
|
struct TaskResult {
|
||||||
success: bool,
|
success: bool,
|
||||||
signature: Signature,
|
signature: Signature,
|
||||||
_error: Option<anyhow::Error>,
|
error: Option<anyhow::Error>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ResultCollector {
|
struct ResultCollector {
|
||||||
@@ -54,7 +54,7 @@ impl ResultCollector {
|
|||||||
self.completed_count.fetch_add(1, Ordering::Release);
|
self.completed_count.fetch_add(1, Ordering::Release);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn wait_for_success(&self) -> Option<(bool, Signature)> {
|
async fn wait_for_success(&self) -> Option<(bool, Signature, Option<anyhow::Error>)> {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let timeout = std::time::Duration::from_secs(30);
|
let timeout = std::time::Duration::from_secs(30);
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ impl ResultCollector {
|
|||||||
if self.success_flag.load(Ordering::Acquire) {
|
if self.success_flag.load(Ordering::Acquire) {
|
||||||
while let Some(result) = self.results.pop() {
|
while let Some(result) = self.results.pop() {
|
||||||
if result.success {
|
if result.success {
|
||||||
return Some((true, result.signature));
|
return Some((true, result.signature, None));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ impl ResultCollector {
|
|||||||
let completed = self.completed_count.load(Ordering::Acquire);
|
let completed = self.completed_count.load(Ordering::Acquire);
|
||||||
if completed >= self.total_tasks {
|
if completed >= self.total_tasks {
|
||||||
while let Some(result) = self.results.pop() {
|
while let Some(result) = self.results.pop() {
|
||||||
return Some((result.success, result.signature));
|
return Some((result.success, result.signature, result.error));
|
||||||
}
|
}
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@@ -83,9 +83,9 @@ impl ResultCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_first(&self) -> Option<(bool, Signature)> {
|
fn get_first(&self) -> Option<(bool, Signature, Option<anyhow::Error>,)> {
|
||||||
if let Some(result) = self.results.pop() {
|
if let Some(result) = self.results.pop() {
|
||||||
Some((result.success, result.signature))
|
Some((result.success, result.signature, result.error))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ pub async fn execute_parallel(
|
|||||||
wait_transaction_confirmed: bool,
|
wait_transaction_confirmed: bool,
|
||||||
with_tip: bool,
|
with_tip: bool,
|
||||||
gas_fee_strategy: GasFeeStrategy,
|
gas_fee_strategy: GasFeeStrategy,
|
||||||
) -> Result<(bool, Signature)> {
|
) -> Result<(bool, Signature, Option<anyhow::Error>)> {
|
||||||
let _exec_start = Instant::now();
|
let _exec_start = Instant::now();
|
||||||
|
|
||||||
if swqos_clients.is_empty() {
|
if swqos_clients.is_empty() {
|
||||||
@@ -208,7 +208,7 @@ pub async fn execute_parallel(
|
|||||||
collector.submit(TaskResult {
|
collector.submit(TaskResult {
|
||||||
success: false,
|
success: false,
|
||||||
signature: Signature::default(),
|
signature: Signature::default(),
|
||||||
_error: Some(e),
|
error: Some(e),
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -217,6 +217,7 @@ pub async fn execute_parallel(
|
|||||||
// Transaction built
|
// Transaction built
|
||||||
|
|
||||||
let _send_start = Instant::now();
|
let _send_start = Instant::now();
|
||||||
|
let mut err = None;
|
||||||
let success = match swqos_client
|
let success = match swqos_client
|
||||||
.send_transaction(
|
.send_transaction(
|
||||||
if is_buy { TradeType::Buy } else { TradeType::Sell },
|
if is_buy { TradeType::Buy } else { TradeType::Sell },
|
||||||
@@ -225,7 +226,8 @@ pub async fn execute_parallel(
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(()) => true,
|
Ok(()) => true,
|
||||||
Err(_e) => {
|
Err(e) => {
|
||||||
|
err = Some(e);
|
||||||
// Send transaction failed
|
// Send transaction failed
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
@@ -234,7 +236,7 @@ pub async fn execute_parallel(
|
|||||||
// Transaction sent
|
// Transaction sent
|
||||||
|
|
||||||
if let Some(signature) = transaction.signatures.first() {
|
if let Some(signature) = transaction.signatures.first() {
|
||||||
collector.submit(TaskResult { success, signature: *signature, _error: None });
|
collector.submit(TaskResult { success, signature: *signature, error: err });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ impl GenericTradeExecutor {
|
|||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl TradeExecutor for GenericTradeExecutor {
|
impl TradeExecutor for GenericTradeExecutor {
|
||||||
async fn swap(&self, params: SwapParams) -> Result<(bool, Signature)> {
|
async fn swap(&self, params: SwapParams) -> Result<(bool, Signature, Option<anyhow::Error>)> {
|
||||||
let total_start = Instant::now();
|
let total_start = Instant::now();
|
||||||
|
|
||||||
// 判断买卖方向
|
// 判断买卖方向
|
||||||
@@ -201,7 +201,7 @@ async fn simulate_transaction(
|
|||||||
is_buy: bool,
|
is_buy: bool,
|
||||||
with_tip: bool,
|
with_tip: bool,
|
||||||
gas_fee_strategy: GasFeeStrategy,
|
gas_fee_strategy: GasFeeStrategy,
|
||||||
) -> Result<(bool, Signature)> {
|
) -> Result<(bool, Signature, Option<anyhow::Error>)> {
|
||||||
use crate::trading::common::build_transaction;
|
use crate::trading::common::build_transaction;
|
||||||
use solana_client::rpc_config::RpcSimulateTransactionConfig;
|
use solana_client::rpc_config::RpcSimulateTransactionConfig;
|
||||||
use solana_commitment_config::CommitmentLevel;
|
use solana_commitment_config::CommitmentLevel;
|
||||||
@@ -288,7 +288,7 @@ async fn simulate_transaction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
println!("=========================================\n");
|
println!("=========================================\n");
|
||||||
return Ok((false, signature));
|
return Ok((false, signature, Some(anyhow::anyhow!("{:?}", err))));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simulation succeeded
|
// Simulation succeeded
|
||||||
@@ -308,5 +308,5 @@ async fn simulate_transaction(
|
|||||||
|
|
||||||
println!("============================================\n");
|
println!("============================================\n");
|
||||||
|
|
||||||
Ok((true, signature))
|
Ok((true, signature, None))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use solana_sdk::{instruction::Instruction, signature::Signature};
|
|||||||
/// 交易执行器trait - 定义了所有交易协议都需要实现的核心方法
|
/// 交易执行器trait - 定义了所有交易协议都需要实现的核心方法
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
pub trait TradeExecutor: Send + Sync {
|
pub trait TradeExecutor: Send + Sync {
|
||||||
async fn swap(&self, params: SwapParams) -> Result<(bool, Signature)>;
|
async fn swap(&self, params: SwapParams) -> Result<(bool, Signature, Option<anyhow::Error>)>;
|
||||||
/// 获取协议名称
|
/// 获取协议名称
|
||||||
fn protocol_name(&self) -> &'static str;
|
fn protocol_name(&self) -> &'static str;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user