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]
name = "sol-trade-sdk"
version = "1.1.0"
version = "1.1.1"
edition = "2021"
authors = [
"William <byteblock6@gmail.com>",
+2 -2
View File
@@ -87,14 +87,14 @@ Add the dependency to your `Cargo.toml`:
```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
```toml
# Add to your Cargo.toml
sol-trade-sdk = "1.1.0"
sol-trade-sdk = "1.1.1"
```
## 🛠️ Usage Examples
+2 -2
View File
@@ -87,14 +87,14 @@ git clone https://github.com/0xfnzero/sol-trade-sdk
```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
```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 |
|-----------|------|----------|-------------|
| `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) |
| `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 |
+1
View File
@@ -19,6 +19,7 @@
| 参数 | 类型 | 必需 | 描述 |
|------|------|------|------|
| `dex_type` | `DexType` | ✅ | 要使用的交易协议 (PumpFun, PumpSwap, Bonk, RaydiumCpmm, RaydiumAmmV4) |
| `trade_type` | `TradeType` | ✅ | 要执行的交易类型 (Buy, Sell) |
| `input_mint` | `Pubkey` | ✅ | 要花费的代币公钥(输入代币) |
| `output_mint` | `Pubkey` | ✅ | 要接收的代币公钥(输出代币) |
| `input_token_program` | `Pubkey` | ✅ | 输入代币的代币程序 ID |
+4 -5
View File
@@ -3,6 +3,7 @@ use std::sync::{
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::protocols::bonk::parser::BONK_PROGRAM_ID;
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::{
common::AnyResult,
swqos::SwqosConfig,
swqos::{SwqosConfig, TradeType},
trading::{core::params::BonkParams, factory::DexType},
SolanaTrade,
};
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::{commitment_config::CommitmentConfig, signature::Keypair};
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_params = sol_trade_sdk::TradeSwapParams {
dex_type: DexType::Bonk,
trade_type: TradeType::Buy,
input_mint: quote_mint_pubkey,
output_mint: mint_pubkey,
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);
let sell_params = sol_trade_sdk::TradeSwapParams {
dex_type: DexType::Bonk,
trade_type: TradeType::Sell,
input_mint: mint_pubkey,
output_mint: quote_mint_pubkey,
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::swqos::SwqosClient;
use crate::swqos::SwqosConfig;
use crate::swqos::TradeType;
use crate::trading::core::params::BonkParams;
use crate::trading::core::params::PumpFunParams;
use crate::trading::core::params::PumpSwapParams;
@@ -70,6 +71,8 @@ pub struct TradeSwapParams {
// Trading configuration
/// The DEX protocol to use for the trade
pub dex_type: DexType,
/// The type of trade to execute
pub trade_type: TradeType,
/// Public key of the token to purchase
pub input_mint: Pubkey,
/// Public key of the token to sell
@@ -303,6 +306,7 @@ impl SolanaTrade {
let buy_params = SwapParams {
rpc: Some(self.rpc.clone()),
payer: self.payer.clone(),
trade_type: params.trade_type,
input_mint: params.input_mint,
output_mint: params.output_mint,
input_token_program: Some(params.input_token_program),
@@ -408,6 +412,7 @@ impl SolanaTrade {
let buy_params = SwapParams {
rpc: Some(self.rpc.clone()),
payer: self.payer.clone(),
trade_type: TradeType::Buy,
input_mint: input_mint,
output_mint: params.mint,
input_token_program: None,
@@ -489,6 +494,7 @@ impl SolanaTrade {
let sell_params = SwapParams {
rpc: Some(self.rpc.clone()),
payer: self.payer.clone(),
trade_type: TradeType::Sell,
input_mint: params.mint,
output_mint: output_mint,
input_token_program: None,
+2 -1
View File
@@ -4,7 +4,7 @@ use crate::common::nonce_cache::DurableNonceInfo;
use crate::common::SolanaRpcClient;
use crate::solana_streamer_sdk::streaming::event_parser::common::EventType;
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::MiddlewareManager;
use solana_hash::Hash;
@@ -23,6 +23,7 @@ use std::sync::Arc;
pub struct SwapParams {
pub rpc: Option<Arc<SolanaRpcClient>>,
pub payer: Arc<Keypair>,
pub trade_type: TradeType,
pub input_mint: Pubkey,
pub input_token_program: Option<Pubkey>,
pub output_mint: Pubkey,