diff --git a/Cargo.toml b/Cargo.toml index 80f6233..2557007 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sol-trade-sdk" -version = "1.1.0" +version = "1.1.1" edition = "2021" authors = [ "William ", diff --git a/README.md b/README.md index 2d21da9..f53e6a1 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/README_CN.md b/README_CN.md index ce7ed8c..6a06fa9 100755 --- a/README_CN.md +++ b/README_CN.md @@ -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" ``` ## 🛠️ 使用示例 diff --git a/docs/TRADING_PARAMETERS.md b/docs/TRADING_PARAMETERS.md index e7a302f..d61431f 100644 --- a/docs/TRADING_PARAMETERS.md +++ b/docs/TRADING_PARAMETERS.md @@ -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 | diff --git a/docs/TRADING_PARAMETERS_CN.md b/docs/TRADING_PARAMETERS_CN.md index 897e214..e345baf 100644 --- a/docs/TRADING_PARAMETERS_CN.md +++ b/docs/TRADING_PARAMETERS_CN.md @@ -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 | diff --git a/examples/bonk_copy_trading/src/main.rs b/examples/bonk_copy_trading/src/main.rs index e591dc6..bbbcc1b 100644 --- a/examples/bonk_copy_trading/src/main.rs +++ b/examples/bonk_copy_trading/src/main.rs @@ -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, diff --git a/src/lib.rs b/src/lib.rs index cdb095d..f95b853 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, diff --git a/src/trading/core/params.rs b/src/trading/core/params.rs index a2000fb..d28dea1 100755 --- a/src/trading/core/params.rs +++ b/src/trading/core/params.rs @@ -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>, pub payer: Arc, + pub trade_type: TradeType, pub input_mint: Pubkey, pub input_token_program: Option, pub output_mint: Pubkey,