feat: add trade type parameter and bump version to 1.1.1

This commit is contained in:
ysq
2025-09-22 01:25:32 +08:00
parent 334e685104
commit 020187a57a
8 changed files with 19 additions and 11 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "sol-trade-sdk" name = "sol-trade-sdk"
version = "1.1.0" version = "1.1.1"
edition = "2021" edition = "2021"
authors = [ authors = [
"William <byteblock6@gmail.com>", "William <byteblock6@gmail.com>",
+2 -2
View File
@@ -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 = "1.1.0" } sol-trade-sdk = { path = "./sol-trade-sdk", version = "1.1.1" }
``` ```
### Use crates.io ### Use crates.io
```toml ```toml
# Add to your Cargo.toml # Add to your Cargo.toml
sol-trade-sdk = "1.1.0" sol-trade-sdk = "1.1.1"
``` ```
## 🛠️ Usage Examples ## 🛠️ Usage Examples
+2 -2
View File
@@ -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 = "1.1.0" } sol-trade-sdk = { path = "./sol-trade-sdk", version = "1.1.1" }
``` ```
### 使用 crates.io ### 使用 crates.io
```toml ```toml
# 添加到您的 Cargo.toml # 添加到您的 Cargo.toml
sol-trade-sdk = "1.1.0" sol-trade-sdk = "1.1.1"
``` ```
## 🛠️ 使用示例 ## 🛠️ 使用示例
+1
View File
@@ -19,6 +19,7 @@ The `TradeSwapParams` struct contains all parameters required for executing swap
| Parameter | Type | Required | Description | | Parameter | Type | Required | Description |
|-----------|------|----------|-------------| |-----------|------|----------|-------------|
| `dex_type` | `DexType` | ✅ | The trading protocol to use (PumpFun, PumpSwap, Bonk, RaydiumCpmm, RaydiumAmmV4) | | `dex_type` | `DexType` | ✅ | The trading protocol to use (PumpFun, PumpSwap, Bonk, RaydiumCpmm, RaydiumAmmV4) |
| `trade_type` | `TradeType` | ✅ | The type of trade to execute (Buy, Sell) |
| `input_mint` | `Pubkey` | ✅ | The public key of the token to spend (input token) | | `input_mint` | `Pubkey` | ✅ | The public key of the token to spend (input token) |
| `output_mint` | `Pubkey` | ✅ | The public key of the token to receive (output token) | | `output_mint` | `Pubkey` | ✅ | The public key of the token to receive (output token) |
| `input_token_program` | `Pubkey` | ✅ | The token program ID for the input token | | `input_token_program` | `Pubkey` | ✅ | The token program ID for the input token |
+1
View File
@@ -19,6 +19,7 @@
| 参数 | 类型 | 必需 | 描述 | | 参数 | 类型 | 必需 | 描述 |
|------|------|------|------| |------|------|------|------|
| `dex_type` | `DexType` | ✅ | 要使用的交易协议 (PumpFun, PumpSwap, Bonk, RaydiumCpmm, RaydiumAmmV4) | | `dex_type` | `DexType` | ✅ | 要使用的交易协议 (PumpFun, PumpSwap, Bonk, RaydiumCpmm, RaydiumAmmV4) |
| `trade_type` | `TradeType` | ✅ | 要执行的交易类型 (Buy, Sell) |
| `input_mint` | `Pubkey` | ✅ | 要花费的代币公钥(输入代币) | | `input_mint` | `Pubkey` | ✅ | 要花费的代币公钥(输入代币) |
| `output_mint` | `Pubkey` | ✅ | 要接收的代币公钥(输出代币) | | `output_mint` | `Pubkey` | ✅ | 要接收的代币公钥(输出代币) |
| `input_token_program` | `Pubkey` | ✅ | 输入代币的代币程序 ID | | `input_token_program` | `Pubkey` | ✅ | 输入代币的代币程序 ID |
+4 -5
View File
@@ -3,6 +3,7 @@ use std::sync::{
Arc, Arc,
}; };
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::common::filter::EventTypeFilter;
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::common::EventType; use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::common::EventType;
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::protocols::bonk::parser::BONK_PROGRAM_ID; use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::protocols::bonk::parser::BONK_PROGRAM_ID;
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::protocols::bonk::BonkTradeEvent; use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::protocols::bonk::BonkTradeEvent;
@@ -13,15 +14,11 @@ use sol_trade_sdk::solana_streamer_sdk::streaming::yellowstone_grpc::{
use sol_trade_sdk::solana_streamer_sdk::streaming::YellowstoneGrpc; use sol_trade_sdk::solana_streamer_sdk::streaming::YellowstoneGrpc;
use sol_trade_sdk::{ use sol_trade_sdk::{
common::AnyResult, common::AnyResult,
swqos::SwqosConfig, swqos::{SwqosConfig, TradeType},
trading::{core::params::BonkParams, factory::DexType}, trading::{core::params::BonkParams, factory::DexType},
SolanaTrade, SolanaTrade,
}; };
use sol_trade_sdk::{common::TradeConfig, solana_streamer_sdk::match_event}; use sol_trade_sdk::{common::TradeConfig, solana_streamer_sdk::match_event};
use sol_trade_sdk::{
constants::WSOL_TOKEN_ACCOUNT,
solana_streamer_sdk::streaming::event_parser::common::filter::EventTypeFilter,
};
use solana_sdk::signer::Signer; use solana_sdk::signer::Signer;
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair}; use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair};
use spl_associated_token_account::get_associated_token_address; use spl_associated_token_account::get_associated_token_address;
@@ -135,6 +132,7 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
let buy_sol_amount = 100_000; let buy_sol_amount = 100_000;
let buy_params = sol_trade_sdk::TradeSwapParams { let buy_params = sol_trade_sdk::TradeSwapParams {
dex_type: DexType::Bonk, dex_type: DexType::Bonk,
trade_type: TradeType::Buy,
input_mint: quote_mint_pubkey, input_mint: quote_mint_pubkey,
output_mint: mint_pubkey, output_mint: mint_pubkey,
input_token_program: trade_info.quote_token_program, input_token_program: trade_info.quote_token_program,
@@ -168,6 +166,7 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
println!("Selling {} tokens", amount_token); println!("Selling {} tokens", amount_token);
let sell_params = sol_trade_sdk::TradeSwapParams { let sell_params = sol_trade_sdk::TradeSwapParams {
dex_type: DexType::Bonk, dex_type: DexType::Bonk,
trade_type: TradeType::Sell,
input_mint: mint_pubkey, input_mint: mint_pubkey,
output_mint: quote_mint_pubkey, output_mint: quote_mint_pubkey,
input_token_program: trade_info.base_token_program, input_token_program: trade_info.base_token_program,
+6
View File
@@ -13,6 +13,7 @@ use crate::constants::USD1_TOKEN_ACCOUNT;
use crate::constants::WSOL_TOKEN_ACCOUNT; use crate::constants::WSOL_TOKEN_ACCOUNT;
use crate::swqos::SwqosClient; use crate::swqos::SwqosClient;
use crate::swqos::SwqosConfig; use crate::swqos::SwqosConfig;
use crate::swqos::TradeType;
use crate::trading::core::params::BonkParams; use crate::trading::core::params::BonkParams;
use crate::trading::core::params::PumpFunParams; use crate::trading::core::params::PumpFunParams;
use crate::trading::core::params::PumpSwapParams; use crate::trading::core::params::PumpSwapParams;
@@ -70,6 +71,8 @@ pub struct TradeSwapParams {
// Trading configuration // Trading configuration
/// The DEX protocol to use for the trade /// The DEX protocol to use for the trade
pub dex_type: DexType, pub dex_type: DexType,
/// The type of trade to execute
pub trade_type: TradeType,
/// Public key of the token to purchase /// Public key of the token to purchase
pub input_mint: Pubkey, pub input_mint: Pubkey,
/// Public key of the token to sell /// Public key of the token to sell
@@ -303,6 +306,7 @@ impl SolanaTrade {
let buy_params = SwapParams { let buy_params = SwapParams {
rpc: Some(self.rpc.clone()), rpc: Some(self.rpc.clone()),
payer: self.payer.clone(), payer: self.payer.clone(),
trade_type: params.trade_type,
input_mint: params.input_mint, input_mint: params.input_mint,
output_mint: params.output_mint, output_mint: params.output_mint,
input_token_program: Some(params.input_token_program), input_token_program: Some(params.input_token_program),
@@ -408,6 +412,7 @@ impl SolanaTrade {
let buy_params = SwapParams { let buy_params = SwapParams {
rpc: Some(self.rpc.clone()), rpc: Some(self.rpc.clone()),
payer: self.payer.clone(), payer: self.payer.clone(),
trade_type: TradeType::Buy,
input_mint: input_mint, input_mint: input_mint,
output_mint: params.mint, output_mint: params.mint,
input_token_program: None, input_token_program: None,
@@ -489,6 +494,7 @@ impl SolanaTrade {
let sell_params = SwapParams { let sell_params = SwapParams {
rpc: Some(self.rpc.clone()), rpc: Some(self.rpc.clone()),
payer: self.payer.clone(), payer: self.payer.clone(),
trade_type: TradeType::Sell,
input_mint: params.mint, input_mint: params.mint,
output_mint: output_mint, output_mint: output_mint,
input_token_program: None, input_token_program: None,
+2 -1
View File
@@ -4,7 +4,7 @@ use crate::common::nonce_cache::DurableNonceInfo;
use crate::common::SolanaRpcClient; use crate::common::SolanaRpcClient;
use crate::solana_streamer_sdk::streaming::event_parser::common::EventType; use crate::solana_streamer_sdk::streaming::event_parser::common::EventType;
use crate::solana_streamer_sdk::streaming::event_parser::protocols::bonk::BonkTradeEvent; use crate::solana_streamer_sdk::streaming::event_parser::protocols::bonk::BonkTradeEvent;
use crate::swqos::SwqosClient; use crate::swqos::{SwqosClient, TradeType};
use crate::trading::common::get_multi_token_balances; use crate::trading::common::get_multi_token_balances;
use crate::trading::MiddlewareManager; use crate::trading::MiddlewareManager;
use solana_hash::Hash; use solana_hash::Hash;
@@ -23,6 +23,7 @@ use std::sync::Arc;
pub struct SwapParams { pub struct SwapParams {
pub rpc: Option<Arc<SolanaRpcClient>>, pub rpc: Option<Arc<SolanaRpcClient>>,
pub payer: Arc<Keypair>, pub payer: Arc<Keypair>,
pub trade_type: TradeType,
pub input_mint: Pubkey, pub input_mint: Pubkey,
pub input_token_program: Option<Pubkey>, pub input_token_program: Option<Pubkey>,
pub output_mint: Pubkey, pub output_mint: Pubkey,