feat: refactor trading API and add multi-token type support (v1.2.0)
- Bump version to 1.2.0 - Remove TradeSwapParams to simplify API structure - Add TradeTokenType enum supporting SOL/WSOL/USD1 tokens - Standardize parameter naming: sol_amount → input_token_amount, token_amount → input_token_amount - Refactor account management parameters: create_wsol_ata → create_input_token_ata etc. - Update all example code to use new API - Synchronize English and Chinese documentation BREAKING CHANGE: - Removed TradeSwapParams struct - Modified field names in TradeBuyParams and TradeSellParams - Existing code needs migration to use new parameter structure
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "sol-trade-sdk"
|
name = "sol-trade-sdk"
|
||||||
version = "1.1.1"
|
version = "1.2.0"
|
||||||
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 = "1.1.1" }
|
sol-trade-sdk = { path = "./sol-trade-sdk", version = "1.2.0" }
|
||||||
```
|
```
|
||||||
|
|
||||||
### Use crates.io
|
### Use crates.io
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
# Add to your Cargo.toml
|
# Add to your Cargo.toml
|
||||||
sol-trade-sdk = "1.1.1"
|
sol-trade-sdk = "1.2.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
## 🛠️ Usage Examples
|
## 🛠️ Usage Examples
|
||||||
@@ -144,17 +144,19 @@ For detailed information about all trading parameters, see the [Trading Paramete
|
|||||||
```rust
|
```rust
|
||||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||||
dex_type: DexType::PumpSwap,
|
dex_type: DexType::PumpSwap,
|
||||||
|
input_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: buy_sol_amount,
|
input_token_amount: buy_sol_amount,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(params.clone()),
|
extension_params: Box::new(params.clone()),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_input_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_input_token_ata: true,
|
||||||
create_mint_ata: true,
|
create_mint_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
|
durable_nonce: None,
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
+7
-5
@@ -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.1" }
|
sol-trade-sdk = { path = "./sol-trade-sdk", version = "1.2.0" }
|
||||||
```
|
```
|
||||||
|
|
||||||
### 使用 crates.io
|
### 使用 crates.io
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
# 添加到您的 Cargo.toml
|
# 添加到您的 Cargo.toml
|
||||||
sol-trade-sdk = "1.1.1"
|
sol-trade-sdk = "1.2.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
## 🛠️ 使用示例
|
## 🛠️ 使用示例
|
||||||
@@ -145,17 +145,19 @@ GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
|||||||
```rust
|
```rust
|
||||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||||
dex_type: DexType::PumpSwap,
|
dex_type: DexType::PumpSwap,
|
||||||
|
input_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: buy_sol_amount,
|
input_token_amount: buy_sol_amount,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(params.clone()),
|
extension_params: Box::new(params.clone()),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_input_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_input_token_ata: true,
|
||||||
create_mint_ata: true,
|
create_mint_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
|
durable_nonce: None,
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
+22
-62
@@ -4,61 +4,11 @@ This document provides a comprehensive reference for all trading parameters used
|
|||||||
|
|
||||||
## 📋 Table of Contents
|
## 📋 Table of Contents
|
||||||
|
|
||||||
- [TradeSwapParams](#tradeswapparams)
|
|
||||||
- [TradeBuyParams](#tradebuyparams)
|
- [TradeBuyParams](#tradebuyparams)
|
||||||
- [TradeSellParams](#tradesellparams)
|
- [TradeSellParams](#tradesellparams)
|
||||||
- [Parameter Categories](#parameter-categories)
|
- [Parameter Categories](#parameter-categories)
|
||||||
- [Important Notes](#important-notes)
|
- [Important Notes](#important-notes)
|
||||||
|
|
||||||
## TradeSwapParams
|
|
||||||
|
|
||||||
The `TradeSwapParams` struct contains all parameters required for executing swap orders across different DEX protocols. This is the most flexible trading method that supports swapping between any supported tokens.
|
|
||||||
|
|
||||||
### Basic Trading Parameters
|
|
||||||
|
|
||||||
| 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 |
|
|
||||||
| `output_token_program` | `Pubkey` | ✅ | The token program ID for the output token |
|
|
||||||
| `input_amount` | `u64` | ✅ | Amount of input token to spend (in smallest token units) |
|
|
||||||
| `slippage_basis_points` | `Option<u64>` | ❌ | Slippage tolerance in basis points (e.g., 100 = 1%, 500 = 5%) |
|
|
||||||
| `recent_blockhash` | `Option<Hash>` | ❌ | Recent blockhash for transaction validity |
|
|
||||||
| `extension_params` | `Box<dyn ProtocolParams>` | ✅ | Protocol-specific parameters (PumpFunParams, PumpSwapParams, etc.) |
|
|
||||||
|
|
||||||
### Advanced Configuration Parameters
|
|
||||||
|
|
||||||
| Parameter | Type | Required | Description |
|
|
||||||
|-----------|------|----------|-------------|
|
|
||||||
| `lookup_table_key` | `Option<Pubkey>` | ❌ | Address lookup table key for transaction optimization |
|
|
||||||
| `wait_transaction_confirmed` | `bool` | ✅ | Whether to wait for transaction confirmation |
|
|
||||||
| `create_input_mint_ata` | `bool` | ✅ | Whether to create input token Associated Token Account |
|
|
||||||
| `close_input_mint_ata` | `bool` | ✅ | Whether to close input token ATA after transaction |
|
|
||||||
| `create_output_mint_ata` | `bool` | ✅ | Whether to create output token ATA |
|
|
||||||
| `close_output_mint_ata` | `bool` | ✅ | Whether to close output token ATA after transaction |
|
|
||||||
| `open_seed_optimize` | `bool` | ✅ | Whether to use seed optimization for reduced CU consumption |
|
|
||||||
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | Durable nonce information containing nonce account and current nonce value |
|
|
||||||
| `with_tip` | `bool` | ✅ | Whether to include tip for transaction priority |
|
|
||||||
|
|
||||||
### Supported Token Pairs
|
|
||||||
|
|
||||||
The SDK currently supports swap trading between the following base tokens and other tokens:
|
|
||||||
- **SOL** (Native Solana token)
|
|
||||||
- **WSOL** (Wrapped SOL)
|
|
||||||
- **USD1** (USD1 stablecoin - currently only supported on Bonk protocol)
|
|
||||||
|
|
||||||
**Important**: At least one token in the swap pair must be a supported base token (SOL, WSOL, or USD1).
|
|
||||||
|
|
||||||
### USD1 Token Support
|
|
||||||
|
|
||||||
USD1 token support has the following limitations:
|
|
||||||
- **Protocol Restriction**: USD1 trading is currently only supported on the Bonk protocol
|
|
||||||
- **Pair Requirements**: USD1 can be swapped with other tokens, but the swap must occur on Bonk DEX
|
|
||||||
- **Token Address**: `USD1ttGY1N17NEEHLmELoaybftRBUSErhqYiQzvEmuB`
|
|
||||||
|
|
||||||
## TradeBuyParams
|
## TradeBuyParams
|
||||||
|
|
||||||
The `TradeBuyParams` struct contains all parameters required for executing buy orders across different DEX protocols.
|
The `TradeBuyParams` struct contains all parameters required for executing buy orders across different DEX protocols.
|
||||||
@@ -68,8 +18,9 @@ The `TradeBuyParams` struct contains all parameters required for executing buy o
|
|||||||
| 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) |
|
||||||
|
| `input_token_type` | `TradeTokenType` | ✅ | The type of input token to use (SOL, WSOL, USD1) |
|
||||||
| `mint` | `Pubkey` | ✅ | The public key of the token mint to purchase |
|
| `mint` | `Pubkey` | ✅ | The public key of the token mint to purchase |
|
||||||
| `sol_amount` | `u64` | ✅ | Amount of SOL to spend (in lamports) |
|
| `input_token_amount` | `u64` | ✅ | Amount of input token to spend (in smallest token units) |
|
||||||
| `slippage_basis_points` | `Option<u64>` | ❌ | Slippage tolerance in basis points (e.g., 100 = 1%, 500 = 5%) |
|
| `slippage_basis_points` | `Option<u64>` | ❌ | Slippage tolerance in basis points (e.g., 100 = 1%, 500 = 5%) |
|
||||||
| `recent_blockhash` | `Option<Hash>` | ❌ | Recent blockhash for transaction validity |
|
| `recent_blockhash` | `Option<Hash>` | ❌ | Recent blockhash for transaction validity |
|
||||||
| `extension_params` | `Box<dyn ProtocolParams>` | ✅ | Protocol-specific parameters (PumpFunParams, PumpSwapParams, etc.) |
|
| `extension_params` | `Box<dyn ProtocolParams>` | ✅ | Protocol-specific parameters (PumpFunParams, PumpSwapParams, etc.) |
|
||||||
@@ -80,8 +31,8 @@ The `TradeBuyParams` struct contains all parameters required for executing buy o
|
|||||||
|-----------|------|----------|-------------|
|
|-----------|------|----------|-------------|
|
||||||
| `lookup_table_key` | `Option<Pubkey>` | ❌ | Address lookup table key for transaction optimization |
|
| `lookup_table_key` | `Option<Pubkey>` | ❌ | Address lookup table key for transaction optimization |
|
||||||
| `wait_transaction_confirmed` | `bool` | ✅ | Whether to wait for transaction confirmation |
|
| `wait_transaction_confirmed` | `bool` | ✅ | Whether to wait for transaction confirmation |
|
||||||
| `create_wsol_ata` | `bool` | ✅ | Whether to create wSOL Associated Token Account |
|
| `create_input_token_ata` | `bool` | ✅ | Whether to create input token Associated Token Account |
|
||||||
| `close_wsol_ata` | `bool` | ✅ | Whether to close wSOL ATA after transaction |
|
| `close_input_token_ata` | `bool` | ✅ | Whether to close input token ATA after transaction |
|
||||||
| `create_mint_ata` | `bool` | ✅ | Whether to create token mint ATA |
|
| `create_mint_ata` | `bool` | ✅ | Whether to create token mint ATA |
|
||||||
| `open_seed_optimize` | `bool` | ✅ | Whether to use seed optimization for reduced CU consumption |
|
| `open_seed_optimize` | `bool` | ✅ | Whether to use seed optimization for reduced CU consumption |
|
||||||
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | Durable nonce information containing nonce account and current nonce value |
|
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | Durable nonce information containing nonce account and current nonce value |
|
||||||
@@ -96,8 +47,9 @@ The `TradeSellParams` struct contains all parameters required for executing sell
|
|||||||
| 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) |
|
||||||
|
| `output_token_type` | `TradeTokenType` | ✅ | The type of output token to receive (SOL, WSOL, USD1) |
|
||||||
| `mint` | `Pubkey` | ✅ | The public key of the token mint to sell |
|
| `mint` | `Pubkey` | ✅ | The public key of the token mint to sell |
|
||||||
| `token_amount` | `u64` | ✅ | Amount of tokens to sell (in smallest token units) |
|
| `input_token_amount` | `u64` | ✅ | Amount of tokens to sell (in smallest token units) |
|
||||||
| `slippage_basis_points` | `Option<u64>` | ❌ | Slippage tolerance in basis points (e.g., 100 = 1%, 500 = 5%) |
|
| `slippage_basis_points` | `Option<u64>` | ❌ | Slippage tolerance in basis points (e.g., 100 = 1%, 500 = 5%) |
|
||||||
| `recent_blockhash` | `Option<Hash>` | ❌ | Recent blockhash for transaction validity |
|
| `recent_blockhash` | `Option<Hash>` | ❌ | Recent blockhash for transaction validity |
|
||||||
| `with_tip` | `bool` | ✅ | Whether to include tip in the transaction |
|
| `with_tip` | `bool` | ✅ | Whether to include tip in the transaction |
|
||||||
@@ -109,8 +61,8 @@ The `TradeSellParams` struct contains all parameters required for executing sell
|
|||||||
|-----------|------|----------|-------------|
|
|-----------|------|----------|-------------|
|
||||||
| `lookup_table_key` | `Option<Pubkey>` | ❌ | Address lookup table key for transaction optimization |
|
| `lookup_table_key` | `Option<Pubkey>` | ❌ | Address lookup table key for transaction optimization |
|
||||||
| `wait_transaction_confirmed` | `bool` | ✅ | Whether to wait for transaction confirmation |
|
| `wait_transaction_confirmed` | `bool` | ✅ | Whether to wait for transaction confirmation |
|
||||||
| `create_wsol_ata` | `bool` | ✅ | Whether to create wSOL Associated Token Account |
|
| `create_output_token_ata` | `bool` | ✅ | Whether to create output token Associated Token Account |
|
||||||
| `close_wsol_ata` | `bool` | ✅ | Whether to close wSOL ATA after transaction |
|
| `close_output_token_ata` | `bool` | ✅ | Whether to close output token ATA after transaction |
|
||||||
| `open_seed_optimize` | `bool` | ✅ | Whether to use seed optimization for reduced CU consumption |
|
| `open_seed_optimize` | `bool` | ✅ | Whether to use seed optimization for reduced CU consumption |
|
||||||
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | Durable nonce information containing nonce account and current nonce value |
|
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | Durable nonce information containing nonce account and current nonce value |
|
||||||
|
|
||||||
@@ -122,8 +74,9 @@ The `TradeSellParams` struct contains all parameters required for executing sell
|
|||||||
These parameters are essential for defining the basic trading operation:
|
These parameters are essential for defining the basic trading operation:
|
||||||
|
|
||||||
- **dex_type**: Determines which protocol to use for trading
|
- **dex_type**: Determines which protocol to use for trading
|
||||||
|
- **input_token_type** (buy) / **output_token_type** (sell): Specifies the base token type (SOL, WSOL, USD1)
|
||||||
- **mint**: Specifies the token to trade
|
- **mint**: Specifies the token to trade
|
||||||
- **sol_amount** (buy) / **token_amount** (sell): Defines the trade size
|
- **input_token_amount**: Defines the trade size (for both buy and sell operations)
|
||||||
- **recent_blockhash**: Ensures transaction validity
|
- **recent_blockhash**: Ensures transaction validity
|
||||||
|
|
||||||
### ⚙️ Transaction Control Parameters
|
### ⚙️ Transaction Control Parameters
|
||||||
@@ -137,9 +90,9 @@ These parameters control how the transaction is processed:
|
|||||||
|
|
||||||
These parameters control automatic account creation and management:
|
These parameters control automatic account creation and management:
|
||||||
|
|
||||||
- **create_wsol_ata**: Automatically wrap SOL to wSOL when needed
|
- **create_input_token_ata** (buy) / **create_output_token_ata** (sell): Automatically create token accounts for input/output tokens
|
||||||
- **close_wsol_ata**: Automatically unwrap wSOL to SOL after trading
|
- **close_input_token_ata** (buy) / **close_output_token_ata** (sell): Automatically close token accounts after trading
|
||||||
- **create_mint_ata**: Automatically create token accounts
|
- **create_mint_ata**: Automatically create token accounts for the traded token
|
||||||
|
|
||||||
### 🚀 Optimization Parameters
|
### 🚀 Optimization Parameters
|
||||||
|
|
||||||
@@ -148,6 +101,13 @@ These parameters enable advanced optimizations:
|
|||||||
- **lookup_table_key**: Use address lookup tables for reduced transaction size
|
- **lookup_table_key**: Use address lookup tables for reduced transaction size
|
||||||
- **open_seed_optimize**: Use seed-based account creation for lower CU consumption
|
- **open_seed_optimize**: Use seed-based account creation for lower CU consumption
|
||||||
|
|
||||||
|
### 🔄 Token Type Parameters
|
||||||
|
|
||||||
|
The **TradeTokenType** enum supports the following base tokens:
|
||||||
|
- **SOL**: Native Solana token (typically used with PumpFun)
|
||||||
|
- **WSOL**: Wrapped SOL token (typically used with PumpSwap, Bonk, Raydium protocols)
|
||||||
|
- **USD1**: USD1 stablecoin (currently only supported on Bonk protocol)
|
||||||
|
|
||||||
### 🔄 Optional Parameters
|
### 🔄 Optional Parameters
|
||||||
|
|
||||||
When you need to use durable nonce, you need to fill in this parameter:
|
When you need to use durable nonce, you need to fill in this parameter:
|
||||||
@@ -162,9 +122,9 @@ When `open_seed_optimize: true`:
|
|||||||
- ⚠️ **Warning**: Official platform selling methods may fail
|
- ⚠️ **Warning**: Official platform selling methods may fail
|
||||||
- 📝 **Note**: Use `get_associated_token_address_with_program_id_fast_use_seed` to get ATA addresses
|
- 📝 **Note**: Use `get_associated_token_address_with_program_id_fast_use_seed` to get ATA addresses
|
||||||
|
|
||||||
### 💰 wSOL Account Management
|
### 💰 Token Account Management
|
||||||
|
|
||||||
The `create_wsol_ata` and `close_wsol_ata` parameters provide granular control:
|
The account management parameters provide granular control:
|
||||||
|
|
||||||
- **Independent Control**: Create and close operations can be controlled separately
|
- **Independent Control**: Create and close operations can be controlled separately
|
||||||
- **Batch Operations**: Create once, trade multiple times, then close
|
- **Batch Operations**: Create once, trade multiple times, then close
|
||||||
|
|||||||
@@ -4,61 +4,11 @@
|
|||||||
|
|
||||||
## 📋 目录
|
## 📋 目录
|
||||||
|
|
||||||
- [TradeSwapParams](#tradeswapparams)
|
|
||||||
- [TradeBuyParams](#tradebuyparams)
|
- [TradeBuyParams](#tradebuyparams)
|
||||||
- [TradeSellParams](#tradesellparams)
|
- [TradeSellParams](#tradesellparams)
|
||||||
- [参数分类](#参数分类)
|
- [参数分类](#参数分类)
|
||||||
- [重要说明](#重要说明)
|
- [重要说明](#重要说明)
|
||||||
|
|
||||||
## TradeSwapParams
|
|
||||||
|
|
||||||
`TradeSwapParams` 结构体包含在不同 DEX 协议上执行代币交换订单所需的所有参数。这是最灵活的交易方法,支持在任何支持的代币之间进行交换。
|
|
||||||
|
|
||||||
### 基础交易参数
|
|
||||||
|
|
||||||
| 参数 | 类型 | 必需 | 描述 |
|
|
||||||
|------|------|------|------|
|
|
||||||
| `dex_type` | `DexType` | ✅ | 要使用的交易协议 (PumpFun, PumpSwap, Bonk, RaydiumCpmm, RaydiumAmmV4) |
|
|
||||||
| `trade_type` | `TradeType` | ✅ | 要执行的交易类型 (Buy, Sell) |
|
|
||||||
| `input_mint` | `Pubkey` | ✅ | 要花费的代币公钥(输入代币) |
|
|
||||||
| `output_mint` | `Pubkey` | ✅ | 要接收的代币公钥(输出代币) |
|
|
||||||
| `input_token_program` | `Pubkey` | ✅ | 输入代币的代币程序 ID |
|
|
||||||
| `output_token_program` | `Pubkey` | ✅ | 输出代币的代币程序 ID |
|
|
||||||
| `input_amount` | `u64` | ✅ | 要花费的输入代币数量(最小代币单位) |
|
|
||||||
| `slippage_basis_points` | `Option<u64>` | ❌ | 滑点容忍度(基点单位,例如 100 = 1%, 500 = 5%) |
|
|
||||||
| `recent_blockhash` | `Option<Hash>` | ❌ | 用于交易有效性的最新区块哈希 |
|
|
||||||
| `extension_params` | `Box<dyn ProtocolParams>` | ✅ | 协议特定参数 (PumpFunParams, PumpSwapParams 等) |
|
|
||||||
|
|
||||||
### 高级配置参数
|
|
||||||
|
|
||||||
| 参数 | 类型 | 必需 | 描述 |
|
|
||||||
|------|------|------|------|
|
|
||||||
| `lookup_table_key` | `Option<Pubkey>` | ❌ | 用于交易优化的地址查找表键 |
|
|
||||||
| `wait_transaction_confirmed` | `bool` | ✅ | 是否等待交易确认 |
|
|
||||||
| `create_input_mint_ata` | `bool` | ✅ | 是否创建输入代币关联代币账户 |
|
|
||||||
| `close_input_mint_ata` | `bool` | ✅ | 交易后是否关闭输入代币 ATA |
|
|
||||||
| `create_output_mint_ata` | `bool` | ✅ | 是否创建输出代币 ATA |
|
|
||||||
| `close_output_mint_ata` | `bool` | ✅ | 交易后是否关闭输出代币 ATA |
|
|
||||||
| `open_seed_optimize` | `bool` | ✅ | 是否使用 seed 优化以减少 CU 消耗 |
|
|
||||||
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | 持久 nonce 信息,包含 nonce 账户和当前 nonce 值 |
|
|
||||||
| `with_tip` | `bool` | ✅ | 是否包含小费以提高交易优先级 |
|
|
||||||
|
|
||||||
### 支持的代币交易对
|
|
||||||
|
|
||||||
SDK 目前支持以下基础代币与其他代币之间的交换交易:
|
|
||||||
- **SOL**(Solana 原生代币)
|
|
||||||
- **WSOL**(包装 SOL)
|
|
||||||
- **USD1**(USD1 稳定币 - 目前仅在 Bonk 协议上支持)
|
|
||||||
|
|
||||||
**重要提示**:交换对中至少有一个代币必须是支持的基础代币(SOL、WSOL 或 USD1)。
|
|
||||||
|
|
||||||
### USD1 代币支持
|
|
||||||
|
|
||||||
USD1 代币支持有以下限制:
|
|
||||||
- **协议限制**:USD1 交易目前仅在 Bonk 协议上支持
|
|
||||||
- **交易对要求**:USD1 可以与其他代币交换,但必须在 Bonk DEX 上进行
|
|
||||||
- **代币地址**:`USD1ttGY1N17NEEHLmELoaybftRBUSErhqYiQzvEmuB`
|
|
||||||
|
|
||||||
## TradeBuyParams
|
## TradeBuyParams
|
||||||
|
|
||||||
`TradeBuyParams` 结构体包含在不同 DEX 协议上执行买入订单所需的所有参数。
|
`TradeBuyParams` 结构体包含在不同 DEX 协议上执行买入订单所需的所有参数。
|
||||||
@@ -68,8 +18,9 @@ USD1 代币支持有以下限制:
|
|||||||
| 参数 | 类型 | 必需 | 描述 |
|
| 参数 | 类型 | 必需 | 描述 |
|
||||||
|------|------|------|------|
|
|------|------|------|------|
|
||||||
| `dex_type` | `DexType` | ✅ | 要使用的交易协议 (PumpFun, PumpSwap, Bonk, RaydiumCpmm, RaydiumAmmV4) |
|
| `dex_type` | `DexType` | ✅ | 要使用的交易协议 (PumpFun, PumpSwap, Bonk, RaydiumCpmm, RaydiumAmmV4) |
|
||||||
|
| `input_token_type` | `TradeTokenType` | ✅ | 要使用的输入代币类型 (SOL, WSOL, USD1) |
|
||||||
| `mint` | `Pubkey` | ✅ | 要购买的代币 mint 公钥 |
|
| `mint` | `Pubkey` | ✅ | 要购买的代币 mint 公钥 |
|
||||||
| `sol_amount` | `u64` | ✅ | 要花费的 SOL 数量(以 lamports 为单位) |
|
| `input_token_amount` | `u64` | ✅ | 要花费的输入代币数量(最小代币单位) |
|
||||||
| `slippage_basis_points` | `Option<u64>` | ❌ | 滑点容忍度(基点单位,例如 100 = 1%, 500 = 5%) |
|
| `slippage_basis_points` | `Option<u64>` | ❌ | 滑点容忍度(基点单位,例如 100 = 1%, 500 = 5%) |
|
||||||
| `recent_blockhash` | `Option<Hash>` | ❌ | 用于交易有效性的最新区块哈希 |
|
| `recent_blockhash` | `Option<Hash>` | ❌ | 用于交易有效性的最新区块哈希 |
|
||||||
| `extension_params` | `Box<dyn ProtocolParams>` | ✅ | 协议特定参数 (PumpFunParams, PumpSwapParams 等) |
|
| `extension_params` | `Box<dyn ProtocolParams>` | ✅ | 协议特定参数 (PumpFunParams, PumpSwapParams 等) |
|
||||||
@@ -80,8 +31,8 @@ USD1 代币支持有以下限制:
|
|||||||
|------|------|------|------|
|
|------|------|------|------|
|
||||||
| `lookup_table_key` | `Option<Pubkey>` | ❌ | 用于交易优化的地址查找表键 |
|
| `lookup_table_key` | `Option<Pubkey>` | ❌ | 用于交易优化的地址查找表键 |
|
||||||
| `wait_transaction_confirmed` | `bool` | ✅ | 是否等待交易确认 |
|
| `wait_transaction_confirmed` | `bool` | ✅ | 是否等待交易确认 |
|
||||||
| `create_wsol_ata` | `bool` | ✅ | 是否创建 wSOL 关联代币账户 |
|
| `create_input_token_ata` | `bool` | ✅ | 是否创建输入代币关联代币账户 |
|
||||||
| `close_wsol_ata` | `bool` | ✅ | 交易后是否关闭 wSOL ATA |
|
| `close_input_token_ata` | `bool` | ✅ | 交易后是否关闭输入代币 ATA |
|
||||||
| `create_mint_ata` | `bool` | ✅ | 是否创建代币 mint ATA |
|
| `create_mint_ata` | `bool` | ✅ | 是否创建代币 mint ATA |
|
||||||
| `open_seed_optimize` | `bool` | ✅ | 是否使用 seed 优化以减少 CU 消耗 |
|
| `open_seed_optimize` | `bool` | ✅ | 是否使用 seed 优化以减少 CU 消耗 |
|
||||||
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | 持久 nonce 信息,包含 nonce 账户和当前 nonce 值 |
|
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | 持久 nonce 信息,包含 nonce 账户和当前 nonce 值 |
|
||||||
@@ -96,8 +47,9 @@ USD1 代币支持有以下限制:
|
|||||||
| 参数 | 类型 | 必需 | 描述 |
|
| 参数 | 类型 | 必需 | 描述 |
|
||||||
|------|------|------|------|
|
|------|------|------|------|
|
||||||
| `dex_type` | `DexType` | ✅ | 要使用的交易协议 (PumpFun, PumpSwap, Bonk, RaydiumCpmm, RaydiumAmmV4) |
|
| `dex_type` | `DexType` | ✅ | 要使用的交易协议 (PumpFun, PumpSwap, Bonk, RaydiumCpmm, RaydiumAmmV4) |
|
||||||
|
| `output_token_type` | `TradeTokenType` | ✅ | 要接收的输出代币类型 (SOL, WSOL, USD1) |
|
||||||
| `mint` | `Pubkey` | ✅ | 要出售的代币 mint 公钥 |
|
| `mint` | `Pubkey` | ✅ | 要出售的代币 mint 公钥 |
|
||||||
| `token_amount` | `u64` | ✅ | 要出售的代币数量(最小代币单位) |
|
| `input_token_amount` | `u64` | ✅ | 要出售的代币数量(最小代币单位) |
|
||||||
| `slippage_basis_points` | `Option<u64>` | ❌ | 滑点容忍度(基点单位,例如 100 = 1%, 500 = 5%) |
|
| `slippage_basis_points` | `Option<u64>` | ❌ | 滑点容忍度(基点单位,例如 100 = 1%, 500 = 5%) |
|
||||||
| `recent_blockhash` | `Option<Hash>` | ❌ | 用于交易有效性的最新区块哈希 |
|
| `recent_blockhash` | `Option<Hash>` | ❌ | 用于交易有效性的最新区块哈希 |
|
||||||
| `with_tip` | `bool` | ✅ | 交易中是否包含小费 |
|
| `with_tip` | `bool` | ✅ | 交易中是否包含小费 |
|
||||||
@@ -109,8 +61,8 @@ USD1 代币支持有以下限制:
|
|||||||
|------|------|------|------|
|
|------|------|------|------|
|
||||||
| `lookup_table_key` | `Option<Pubkey>` | ❌ | 用于交易优化的地址查找表键 |
|
| `lookup_table_key` | `Option<Pubkey>` | ❌ | 用于交易优化的地址查找表键 |
|
||||||
| `wait_transaction_confirmed` | `bool` | ✅ | 是否等待交易确认 |
|
| `wait_transaction_confirmed` | `bool` | ✅ | 是否等待交易确认 |
|
||||||
| `create_wsol_ata` | `bool` | ✅ | 是否创建 wSOL 关联代币账户 |
|
| `create_output_token_ata` | `bool` | ✅ | 是否创建输出代币关联代币账户 |
|
||||||
| `close_wsol_ata` | `bool` | ✅ | 交易后是否关闭 wSOL ATA |
|
| `close_output_token_ata` | `bool` | ✅ | 交易后是否关闭输出代币 ATA |
|
||||||
| `open_seed_optimize` | `bool` | ✅ | 是否使用 seed 优化以减少 CU 消耗 |
|
| `open_seed_optimize` | `bool` | ✅ | 是否使用 seed 优化以减少 CU 消耗 |
|
||||||
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | 持久 nonce 信息,包含 nonce 账户和当前 nonce 值 |
|
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | 持久 nonce 信息,包含 nonce 账户和当前 nonce 值 |
|
||||||
|
|
||||||
@@ -122,8 +74,9 @@ USD1 代币支持有以下限制:
|
|||||||
这些参数对于定义基本交易操作至关重要:
|
这些参数对于定义基本交易操作至关重要:
|
||||||
|
|
||||||
- **dex_type**: 确定用于交易的协议
|
- **dex_type**: 确定用于交易的协议
|
||||||
|
- **input_token_type** (买入) / **output_token_type** (卖出): 指定基础代币类型 (SOL, WSOL, USD1)
|
||||||
- **mint**: 指定要交易的代币
|
- **mint**: 指定要交易的代币
|
||||||
- **sol_amount** (买入) / **token_amount** (卖出): 定义交易规模
|
- **input_token_amount**: 定义交易规模(买入和卖出操作都使用此参数)
|
||||||
- **recent_blockhash**: 确保交易有效性
|
- **recent_blockhash**: 确保交易有效性
|
||||||
|
|
||||||
### ⚙️ 交易控制参数
|
### ⚙️ 交易控制参数
|
||||||
@@ -137,9 +90,9 @@ USD1 代币支持有以下限制:
|
|||||||
|
|
||||||
这些参数控制自动账户创建和管理:
|
这些参数控制自动账户创建和管理:
|
||||||
|
|
||||||
- **create_wsol_ata**: 需要时自动将 SOL 包装为 wSOL
|
- **create_input_token_ata** (买入) / **create_output_token_ata** (卖出): 自动为输入/输出代币创建代币账户
|
||||||
- **close_wsol_ata**: 交易后自动将 wSOL 解包装为 SOL
|
- **close_input_token_ata** (买入) / **close_output_token_ata** (卖出): 交易后自动关闭代币账户
|
||||||
- **create_mint_ata**: 自动创建代币账户
|
- **create_mint_ata**: 自动为交易代币创建代币账户
|
||||||
|
|
||||||
### 🚀 优化参数
|
### 🚀 优化参数
|
||||||
|
|
||||||
@@ -148,6 +101,13 @@ USD1 代币支持有以下限制:
|
|||||||
- **lookup_table_key**: 使用地址查找表减少交易大小
|
- **lookup_table_key**: 使用地址查找表减少交易大小
|
||||||
- **open_seed_optimize**: 使用基于 seed 的账户创建以降低 CU 消耗
|
- **open_seed_optimize**: 使用基于 seed 的账户创建以降低 CU 消耗
|
||||||
|
|
||||||
|
### 🔄 代币类型参数
|
||||||
|
|
||||||
|
**TradeTokenType** 枚举支持以下基础代币:
|
||||||
|
- **SOL**: Solana 原生代币(通常与 PumpFun 协议一起使用)
|
||||||
|
- **WSOL**: 包装 SOL 代币(通常与 PumpSwap、Bonk、Raydium 协议一起使用)
|
||||||
|
- **USD1**: USD1 稳定币(目前仅在 Bonk 协议上支持)
|
||||||
|
|
||||||
### 🔄 非必填参数
|
### 🔄 非必填参数
|
||||||
|
|
||||||
当你需要使用 durable nonce 时,需要填入这个参数:
|
当你需要使用 durable nonce 时,需要填入这个参数:
|
||||||
@@ -162,9 +122,9 @@ USD1 代币支持有以下限制:
|
|||||||
- ⚠️ **警告**: 官方平台的出售方法可能会失败
|
- ⚠️ **警告**: 官方平台的出售方法可能会失败
|
||||||
- 📝 **注意**: 使用 `get_associated_token_address_with_program_id_fast_use_seed` 获取 ATA 地址
|
- 📝 **注意**: 使用 `get_associated_token_address_with_program_id_fast_use_seed` 获取 ATA 地址
|
||||||
|
|
||||||
### 💰 wSOL 账户管理
|
### 💰 代币账户管理
|
||||||
|
|
||||||
`create_wsol_ata` 和 `close_wsol_ata` 参数提供精细控制:
|
账户管理参数提供精细控制:
|
||||||
|
|
||||||
- **独立控制**: 创建和关闭操作可以分别控制
|
- **独立控制**: 创建和关闭操作可以分别控制
|
||||||
- **批量操作**: 创建一次,多次交易,然后关闭
|
- **批量操作**: 创建一次,多次交易,然后关闭
|
||||||
|
|||||||
@@ -149,15 +149,16 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
|||||||
let buy_sol_amount = 100_000;
|
let buy_sol_amount = 100_000;
|
||||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||||
dex_type: DexType::PumpFun,
|
dex_type: DexType::PumpFun,
|
||||||
|
input_token_type: sol_trade_sdk::TradeTokenType::SOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: buy_sol_amount,
|
input_token_amount: buy_sol_amount,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, None)),
|
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, None)),
|
||||||
lookup_table_key: Some(lookup_table_key), // you still need to update the AddressLookupTableCache
|
lookup_table_key: Some(lookup_table_key), // you still need to update the AddressLookupTableCache
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: false,
|
create_input_token_ata: false,
|
||||||
close_wsol_ata: false,
|
close_input_token_ata: false,
|
||||||
create_mint_ata: true,
|
create_mint_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ 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, TradeType},
|
swqos::SwqosConfig,
|
||||||
trading::{core::params::BonkParams, factory::DexType},
|
trading::{core::params::BonkParams, factory::DexType},
|
||||||
SolanaTrade,
|
SolanaTrade,
|
||||||
};
|
};
|
||||||
@@ -123,35 +123,35 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
|
|||||||
|
|
||||||
let client = create_solana_trade_client().await?;
|
let client = create_solana_trade_client().await?;
|
||||||
let mint_pubkey = trade_info.base_token_mint;
|
let mint_pubkey = trade_info.base_token_mint;
|
||||||
let quote_mint_pubkey = trade_info.quote_token_mint;
|
|
||||||
let slippage_basis_points = Some(100);
|
let slippage_basis_points = Some(100);
|
||||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||||
|
|
||||||
// Buy tokens
|
// Buy tokens
|
||||||
println!("Buying tokens from Bonk...");
|
println!("Buying tokens from Bonk...");
|
||||||
|
let input_token_type =
|
||||||
|
if trade_info.quote_token_mint == sol_trade_sdk::constants::USD1_TOKEN_ACCOUNT {
|
||||||
|
sol_trade_sdk::TradeTokenType::USD1
|
||||||
|
} else {
|
||||||
|
sol_trade_sdk::TradeTokenType::SOL
|
||||||
|
};
|
||||||
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::TradeBuyParams {
|
||||||
dex_type: DexType::Bonk,
|
dex_type: DexType::Bonk,
|
||||||
trade_type: TradeType::Buy,
|
input_token_type: input_token_type.clone(),
|
||||||
input_mint: quote_mint_pubkey,
|
mint: mint_pubkey,
|
||||||
output_mint: mint_pubkey,
|
input_token_amount: buy_sol_amount,
|
||||||
input_token_program: trade_info.quote_token_program,
|
|
||||||
output_token_program: trade_info.base_token_program,
|
|
||||||
input_amount: buy_sol_amount,
|
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(BonkParams::from_trade(trade_info.clone())),
|
extension_params: Box::new(BonkParams::from_trade(trade_info.clone())),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_input_mint_ata: true,
|
create_input_token_ata: true,
|
||||||
close_input_mint_ata: false,
|
close_input_token_ata: false,
|
||||||
create_output_mint_ata: true,
|
create_mint_ata: true,
|
||||||
close_output_mint_ata: true,
|
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
with_tip: true,
|
|
||||||
};
|
};
|
||||||
client.swap(buy_params).await?;
|
client.buy(buy_params).await?;
|
||||||
|
|
||||||
// Sell tokens
|
// Sell tokens
|
||||||
println!("Selling tokens from Bonk...");
|
println!("Selling tokens from Bonk...");
|
||||||
@@ -164,14 +164,11 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
|
|||||||
let amount_token = balance.amount.parse::<u64>().unwrap();
|
let amount_token = balance.amount.parse::<u64>().unwrap();
|
||||||
|
|
||||||
println!("Selling {} tokens", amount_token);
|
println!("Selling {} tokens", amount_token);
|
||||||
let sell_params = sol_trade_sdk::TradeSwapParams {
|
let sell_params = sol_trade_sdk::TradeSellParams {
|
||||||
dex_type: DexType::Bonk,
|
dex_type: DexType::Bonk,
|
||||||
trade_type: TradeType::Sell,
|
output_token_type: input_token_type,
|
||||||
input_mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
output_mint: quote_mint_pubkey,
|
input_token_amount: amount_token,
|
||||||
input_token_program: trade_info.base_token_program,
|
|
||||||
output_token_program: trade_info.quote_token_program,
|
|
||||||
input_amount: amount_token,
|
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(BonkParams::from_trade(trade_info.clone())),
|
extension_params: Box::new(BonkParams::from_trade(trade_info.clone())),
|
||||||
@@ -180,12 +177,10 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
|
|||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
with_tip: false,
|
with_tip: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
create_input_mint_ata: false,
|
create_output_token_ata: false,
|
||||||
close_input_mint_ata: false,
|
close_output_token_ata: false,
|
||||||
create_output_mint_ata: true,
|
|
||||||
close_output_mint_ata: false,
|
|
||||||
};
|
};
|
||||||
client.swap(sell_params).await?;
|
client.sell(sell_params).await?;
|
||||||
|
|
||||||
// Exit program
|
// Exit program
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
|
|||||||
@@ -95,20 +95,28 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult<
|
|||||||
let slippage_basis_points = Some(300);
|
let slippage_basis_points = Some(300);
|
||||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||||
|
|
||||||
|
let token_type = if trade_info.quote_token_mint == sol_trade_sdk::constants::USD1_TOKEN_ACCOUNT
|
||||||
|
{
|
||||||
|
sol_trade_sdk::TradeTokenType::USD1
|
||||||
|
} else {
|
||||||
|
sol_trade_sdk::TradeTokenType::SOL
|
||||||
|
};
|
||||||
|
|
||||||
// Buy tokens
|
// Buy tokens
|
||||||
println!("Buying tokens from Bonk...");
|
println!("Buying tokens from Bonk...");
|
||||||
let buy_sol_amount = 100_000;
|
let buy_sol_amount = 100_000;
|
||||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||||
dex_type: DexType::Bonk,
|
dex_type: DexType::Bonk,
|
||||||
|
input_token_type: token_type.clone(),
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: buy_sol_amount,
|
input_token_amount: buy_sol_amount,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(BonkParams::from_dev_trade(trade_info.clone())),
|
extension_params: Box::new(BonkParams::from_dev_trade(trade_info.clone())),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_input_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_input_token_ata: true,
|
||||||
create_mint_ata: true,
|
create_mint_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
@@ -128,8 +136,9 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult<
|
|||||||
println!("Selling {} tokens", amount_token);
|
println!("Selling {} tokens", amount_token);
|
||||||
let sell_params = sol_trade_sdk::TradeSellParams {
|
let sell_params = sol_trade_sdk::TradeSellParams {
|
||||||
dex_type: DexType::Bonk,
|
dex_type: DexType::Bonk,
|
||||||
|
output_token_type: token_type,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
token_amount: amount_token,
|
input_token_amount: amount_token,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(BonkParams::immediate_sell(
|
extension_params: Box::new(BonkParams::immediate_sell(
|
||||||
@@ -141,8 +150,8 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult<
|
|||||||
)),
|
)),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_output_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_output_token_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
with_tip: false,
|
with_tip: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use sol_trade_sdk::{
|
|||||||
},
|
},
|
||||||
factory::DexType,
|
factory::DexType,
|
||||||
},
|
},
|
||||||
SolanaTrade, TradeBuyParams, TradeSellParams,
|
SolanaTrade, TradeBuyParams, TradeSellParams, TradeTokenType,
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
commitment_config::CommitmentConfig, native_token::sol_str_to_lamports, pubkey::Pubkey,
|
commitment_config::CommitmentConfig, native_token::sol_str_to_lamports, pubkey::Pubkey,
|
||||||
@@ -605,15 +605,16 @@ async fn handle_buy_pumpfun(
|
|||||||
|
|
||||||
let buy_params = TradeBuyParams {
|
let buy_params = TradeBuyParams {
|
||||||
dex_type: DexType::PumpFun,
|
dex_type: DexType::PumpFun,
|
||||||
|
input_token_type: TradeTokenType::SOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: sol_lamports,
|
input_token_amount: sol_lamports,
|
||||||
slippage_basis_points: slippage,
|
slippage_basis_points: slippage,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(param),
|
extension_params: Box::new(param),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: false,
|
create_input_token_ata: false,
|
||||||
close_wsol_ata: false,
|
close_input_token_ata: false,
|
||||||
create_mint_ata: create_mint_ata,
|
create_mint_ata: create_mint_ata,
|
||||||
open_seed_optimize: use_seed,
|
open_seed_optimize: use_seed,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
@@ -653,15 +654,16 @@ async fn handle_buy_pumpswap(
|
|||||||
|
|
||||||
let buy_params = TradeBuyParams {
|
let buy_params = TradeBuyParams {
|
||||||
dex_type: DexType::PumpSwap,
|
dex_type: DexType::PumpSwap,
|
||||||
|
input_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: sol_lamports,
|
input_token_amount: sol_lamports,
|
||||||
slippage_basis_points: slippage,
|
slippage_basis_points: slippage,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(param),
|
extension_params: Box::new(param),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_input_token_ata: true,
|
||||||
close_wsol_ata: false,
|
close_input_token_ata: false,
|
||||||
create_mint_ata: create_mint_ata,
|
create_mint_ata: create_mint_ata,
|
||||||
open_seed_optimize: use_seed,
|
open_seed_optimize: use_seed,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
@@ -700,15 +702,16 @@ async fn handle_buy_bonk(
|
|||||||
|
|
||||||
let buy_params = TradeBuyParams {
|
let buy_params = TradeBuyParams {
|
||||||
dex_type: DexType::Bonk,
|
dex_type: DexType::Bonk,
|
||||||
|
input_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: sol_lamports,
|
input_token_amount: sol_lamports,
|
||||||
slippage_basis_points: slippage,
|
slippage_basis_points: slippage,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(param),
|
extension_params: Box::new(param),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_input_token_ata: true,
|
||||||
close_wsol_ata: false,
|
close_input_token_ata: false,
|
||||||
create_mint_ata: create_mint_ata,
|
create_mint_ata: create_mint_ata,
|
||||||
open_seed_optimize: use_seed,
|
open_seed_optimize: use_seed,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
@@ -751,15 +754,16 @@ async fn handle_buy_raydium_v4(
|
|||||||
|
|
||||||
let buy_params = TradeBuyParams {
|
let buy_params = TradeBuyParams {
|
||||||
dex_type: DexType::RaydiumAmmV4,
|
dex_type: DexType::RaydiumAmmV4,
|
||||||
|
input_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: sol_lamports,
|
input_token_amount: sol_lamports,
|
||||||
slippage_basis_points: slippage,
|
slippage_basis_points: slippage,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(param),
|
extension_params: Box::new(param),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_input_token_ata: true,
|
||||||
close_wsol_ata: false,
|
close_input_token_ata: false,
|
||||||
create_mint_ata: create_mint_ata,
|
create_mint_ata: create_mint_ata,
|
||||||
open_seed_optimize: use_seed,
|
open_seed_optimize: use_seed,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
@@ -802,15 +806,16 @@ async fn handle_buy_raydium_cpmm(
|
|||||||
|
|
||||||
let buy_params = TradeBuyParams {
|
let buy_params = TradeBuyParams {
|
||||||
dex_type: DexType::RaydiumCpmm,
|
dex_type: DexType::RaydiumCpmm,
|
||||||
|
input_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: sol_lamports,
|
input_token_amount: sol_lamports,
|
||||||
slippage_basis_points: slippage,
|
slippage_basis_points: slippage,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(param),
|
extension_params: Box::new(param),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_input_token_ata: true,
|
||||||
close_wsol_ata: false,
|
close_input_token_ata: false,
|
||||||
create_mint_ata: create_mint_ata,
|
create_mint_ata: create_mint_ata,
|
||||||
open_seed_optimize: use_seed,
|
open_seed_optimize: use_seed,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
@@ -963,16 +968,17 @@ async fn handle_sell_pumpfun(
|
|||||||
|
|
||||||
let sell_params = TradeSellParams {
|
let sell_params = TradeSellParams {
|
||||||
dex_type: DexType::PumpFun,
|
dex_type: DexType::PumpFun,
|
||||||
|
output_token_type: TradeTokenType::SOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
token_amount: amount as u64,
|
input_token_amount: amount as u64,
|
||||||
slippage_basis_points: slippage,
|
slippage_basis_points: slippage,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
with_tip: false,
|
with_tip: false,
|
||||||
extension_params: Box::new(param),
|
extension_params: Box::new(param),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_output_token_ata: true,
|
||||||
close_wsol_ata: false,
|
close_output_token_ata: false,
|
||||||
open_seed_optimize: use_seed,
|
open_seed_optimize: use_seed,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
};
|
};
|
||||||
@@ -1014,16 +1020,17 @@ async fn handle_sell_pumpswap(
|
|||||||
|
|
||||||
let sell_params = TradeSellParams {
|
let sell_params = TradeSellParams {
|
||||||
dex_type: DexType::PumpSwap,
|
dex_type: DexType::PumpSwap,
|
||||||
|
output_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
token_amount: amount as u64,
|
input_token_amount: amount as u64,
|
||||||
slippage_basis_points: slippage,
|
slippage_basis_points: slippage,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
with_tip: false,
|
with_tip: false,
|
||||||
extension_params: Box::new(param),
|
extension_params: Box::new(param),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_output_token_ata: true,
|
||||||
close_wsol_ata: false,
|
close_output_token_ata: false,
|
||||||
open_seed_optimize: use_seed,
|
open_seed_optimize: use_seed,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
};
|
};
|
||||||
@@ -1064,16 +1071,17 @@ async fn handle_sell_bonk(
|
|||||||
|
|
||||||
let sell_params = TradeSellParams {
|
let sell_params = TradeSellParams {
|
||||||
dex_type: DexType::Bonk,
|
dex_type: DexType::Bonk,
|
||||||
|
output_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
token_amount: amount as u64,
|
input_token_amount: amount as u64,
|
||||||
slippage_basis_points: slippage,
|
slippage_basis_points: slippage,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
with_tip: false,
|
with_tip: false,
|
||||||
extension_params: Box::new(param),
|
extension_params: Box::new(param),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_output_token_ata: true,
|
||||||
close_wsol_ata: false,
|
close_output_token_ata: false,
|
||||||
open_seed_optimize: use_seed,
|
open_seed_optimize: use_seed,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
};
|
};
|
||||||
@@ -1117,16 +1125,17 @@ async fn handle_sell_raydium_v4(
|
|||||||
|
|
||||||
let sell_params = TradeSellParams {
|
let sell_params = TradeSellParams {
|
||||||
dex_type: DexType::RaydiumAmmV4,
|
dex_type: DexType::RaydiumAmmV4,
|
||||||
|
output_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
token_amount: amount as u64,
|
input_token_amount: amount as u64,
|
||||||
slippage_basis_points: slippage,
|
slippage_basis_points: slippage,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
with_tip: false,
|
with_tip: false,
|
||||||
extension_params: Box::new(param),
|
extension_params: Box::new(param),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_output_token_ata: true,
|
||||||
close_wsol_ata: false,
|
close_output_token_ata: false,
|
||||||
open_seed_optimize: use_seed,
|
open_seed_optimize: use_seed,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
};
|
};
|
||||||
@@ -1170,16 +1179,17 @@ async fn handle_sell_raydium_cpmm(
|
|||||||
|
|
||||||
let sell_params = TradeSellParams {
|
let sell_params = TradeSellParams {
|
||||||
dex_type: DexType::RaydiumCpmm,
|
dex_type: DexType::RaydiumCpmm,
|
||||||
|
output_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
token_amount: amount as u64,
|
input_token_amount: amount as u64,
|
||||||
slippage_basis_points: slippage,
|
slippage_basis_points: slippage,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
with_tip: false,
|
with_tip: false,
|
||||||
extension_params: Box::new(param),
|
extension_params: Box::new(param),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_output_token_ata: true,
|
||||||
close_wsol_ata: false,
|
close_output_token_ata: false,
|
||||||
open_seed_optimize: use_seed,
|
open_seed_optimize: use_seed,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use sol_trade_sdk::{
|
|||||||
core::params::PumpSwapParams, factory::DexType, middleware::builtin::LoggingMiddleware,
|
core::params::PumpSwapParams, factory::DexType, middleware::builtin::LoggingMiddleware,
|
||||||
InstructionMiddleware, MiddlewareManager,
|
InstructionMiddleware, MiddlewareManager,
|
||||||
},
|
},
|
||||||
SolanaTrade,
|
SolanaTrade, TradeTokenType,
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
commitment_config::CommitmentConfig, instruction::Instruction, pubkey::Pubkey,
|
commitment_config::CommitmentConfig, instruction::Instruction, pubkey::Pubkey,
|
||||||
@@ -86,8 +86,9 @@ async fn test_middleware() -> AnyResult<()> {
|
|||||||
|
|
||||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||||
dex_type: DexType::PumpSwap,
|
dex_type: DexType::PumpSwap,
|
||||||
|
input_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: buy_sol_cost,
|
input_token_amount: buy_sol_cost,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(
|
extension_params: Box::new(
|
||||||
@@ -95,8 +96,8 @@ async fn test_middleware() -> AnyResult<()> {
|
|||||||
),
|
),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_input_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_input_token_ata: true,
|
||||||
create_mint_ata: true,
|
create_mint_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ 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::pumpfun::PumpFunTradeEvent;
|
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::protocols::pumpfun::PumpFunTradeEvent;
|
||||||
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::{Protocol, UnifiedEvent};
|
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::{Protocol, UnifiedEvent};
|
||||||
@@ -22,6 +21,9 @@ use sol_trade_sdk::{
|
|||||||
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::{
|
||||||
|
solana_streamer_sdk::streaming::event_parser::common::filter::EventTypeFilter, TradeTokenType,
|
||||||
|
};
|
||||||
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair};
|
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair};
|
||||||
|
|
||||||
// Global static flag to ensure transaction is executed only once
|
// Global static flag to ensure transaction is executed only once
|
||||||
@@ -132,15 +134,16 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
|||||||
let buy_sol_amount = 100_000;
|
let buy_sol_amount = 100_000;
|
||||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||||
dex_type: DexType::PumpFun,
|
dex_type: DexType::PumpFun,
|
||||||
|
input_token_type: TradeTokenType::SOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: buy_sol_amount,
|
input_token_amount: buy_sol_amount,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, None)),
|
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, None)),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: false,
|
create_input_token_ata: false,
|
||||||
close_wsol_ata: false,
|
close_input_token_ata: false,
|
||||||
create_mint_ata: true,
|
create_mint_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: Some(durable_nonce),
|
durable_nonce: Some(durable_nonce),
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ 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::pumpfun::parser::PUMPFUN_PROGRAM_ID;
|
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::protocols::pumpfun::parser::PUMPFUN_PROGRAM_ID;
|
||||||
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::protocols::pumpfun::PumpFunTradeEvent;
|
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::protocols::pumpfun::PumpFunTradeEvent;
|
||||||
@@ -19,6 +18,9 @@ use sol_trade_sdk::{
|
|||||||
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::{
|
||||||
|
solana_streamer_sdk::streaming::event_parser::common::filter::EventTypeFilter, TradeTokenType,
|
||||||
|
};
|
||||||
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;
|
||||||
@@ -125,15 +127,16 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
|||||||
let buy_sol_amount = 100_000;
|
let buy_sol_amount = 100_000;
|
||||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||||
dex_type: DexType::PumpFun,
|
dex_type: DexType::PumpFun,
|
||||||
|
input_token_type: TradeTokenType::SOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: buy_sol_amount,
|
input_token_amount: buy_sol_amount,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, None)),
|
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, None)),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: false,
|
create_input_token_ata: false,
|
||||||
close_wsol_ata: false,
|
close_input_token_ata: false,
|
||||||
create_mint_ata: true,
|
create_mint_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
@@ -153,16 +156,17 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
|||||||
println!("Selling {} tokens", amount_token);
|
println!("Selling {} tokens", amount_token);
|
||||||
let sell_params = sol_trade_sdk::TradeSellParams {
|
let sell_params = sol_trade_sdk::TradeSellParams {
|
||||||
dex_type: DexType::PumpFun,
|
dex_type: DexType::PumpFun,
|
||||||
|
output_token_type: TradeTokenType::SOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
token_amount: amount_token,
|
input_token_amount: amount_token,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
with_tip: false,
|
with_tip: false,
|
||||||
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, Some(true))),
|
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, Some(true))),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: false,
|
create_output_token_ata: false,
|
||||||
close_wsol_ata: false,
|
close_output_token_ata: false,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::common::EventTy
|
|||||||
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::protocols::pumpfun::PumpFunTradeEvent;
|
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::protocols::pumpfun::PumpFunTradeEvent;
|
||||||
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::{Protocol, UnifiedEvent};
|
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::{Protocol, UnifiedEvent};
|
||||||
use sol_trade_sdk::solana_streamer_sdk::{match_event, streaming::ShredStreamGrpc};
|
use sol_trade_sdk::solana_streamer_sdk::{match_event, streaming::ShredStreamGrpc};
|
||||||
|
use sol_trade_sdk::TradeTokenType;
|
||||||
use sol_trade_sdk::{
|
use sol_trade_sdk::{
|
||||||
common::AnyResult,
|
common::AnyResult,
|
||||||
swqos::SwqosConfig,
|
swqos::SwqosConfig,
|
||||||
@@ -94,15 +95,16 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
|
|||||||
let buy_sol_amount = 100_000;
|
let buy_sol_amount = 100_000;
|
||||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||||
dex_type: DexType::PumpFun,
|
dex_type: DexType::PumpFun,
|
||||||
|
input_token_type: TradeTokenType::SOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: buy_sol_amount,
|
input_token_amount: buy_sol_amount,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(PumpFunParams::from_dev_trade(&trade_info, None)),
|
extension_params: Box::new(PumpFunParams::from_dev_trade(&trade_info, None)),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_input_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_input_token_ata: true,
|
||||||
create_mint_ata: true,
|
create_mint_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
@@ -122,16 +124,17 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
|
|||||||
println!("Selling {} tokens", amount_token);
|
println!("Selling {} tokens", amount_token);
|
||||||
let sell_params = sol_trade_sdk::TradeSellParams {
|
let sell_params = sol_trade_sdk::TradeSellParams {
|
||||||
dex_type: DexType::PumpFun,
|
dex_type: DexType::PumpFun,
|
||||||
|
output_token_type: TradeTokenType::SOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
token_amount: amount_token,
|
input_token_amount: amount_token,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
with_tip: false,
|
with_tip: false,
|
||||||
extension_params: Box::new(PumpFunParams::immediate_sell(trade_info.creator_vault, true)),
|
extension_params: Box::new(PumpFunParams::immediate_sell(trade_info.creator_vault, true)),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_output_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_output_token_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use sol_trade_sdk::{
|
|||||||
common::{AnyResult, TradeConfig},
|
common::{AnyResult, TradeConfig},
|
||||||
swqos::SwqosConfig,
|
swqos::SwqosConfig,
|
||||||
trading::{core::params::PumpSwapParams, factory::DexType},
|
trading::{core::params::PumpSwapParams, factory::DexType},
|
||||||
SolanaTrade,
|
SolanaTrade, TradeTokenType,
|
||||||
};
|
};
|
||||||
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair};
|
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair};
|
||||||
use solana_sdk::{pubkey::Pubkey, signer::Signer};
|
use solana_sdk::{pubkey::Pubkey, signer::Signer};
|
||||||
@@ -24,8 +24,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let buy_sol_amount = 100_000;
|
let buy_sol_amount = 100_000;
|
||||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||||
dex_type: DexType::PumpSwap,
|
dex_type: DexType::PumpSwap,
|
||||||
|
input_token_type: TradeTokenType::SOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: buy_sol_amount,
|
input_token_amount: buy_sol_amount,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(
|
extension_params: Box::new(
|
||||||
@@ -33,8 +34,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
),
|
),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_input_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_input_token_ata: true,
|
||||||
create_mint_ata: true,
|
create_mint_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
@@ -52,8 +53,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let amount_token = balance.amount.parse::<u64>().unwrap();
|
let amount_token = balance.amount.parse::<u64>().unwrap();
|
||||||
let sell_params = sol_trade_sdk::TradeSellParams {
|
let sell_params = sol_trade_sdk::TradeSellParams {
|
||||||
dex_type: DexType::PumpSwap,
|
dex_type: DexType::PumpSwap,
|
||||||
|
output_token_type: TradeTokenType::SOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
token_amount: amount_token,
|
input_token_amount: amount_token,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
with_tip: false,
|
with_tip: false,
|
||||||
@@ -62,8 +64,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
),
|
),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_output_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_output_token_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ use std::sync::{
|
|||||||
Arc,
|
Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::{Protocol, UnifiedEvent};
|
|
||||||
use sol_trade_sdk::solana_streamer_sdk::streaming::yellowstone_grpc::{
|
use sol_trade_sdk::solana_streamer_sdk::streaming::yellowstone_grpc::{
|
||||||
AccountFilter, TransactionFilter,
|
AccountFilter, TransactionFilter,
|
||||||
};
|
};
|
||||||
@@ -29,6 +28,10 @@ use sol_trade_sdk::{
|
|||||||
common::filter::EventTypeFilter, protocols::pumpswap::PumpSwapBuyEvent,
|
common::filter::EventTypeFilter, protocols::pumpswap::PumpSwapBuyEvent,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use sol_trade_sdk::{
|
||||||
|
solana_streamer_sdk::streaming::event_parser::{Protocol, UnifiedEvent},
|
||||||
|
TradeTokenType,
|
||||||
|
};
|
||||||
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair};
|
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair};
|
||||||
use solana_sdk::{pubkey::Pubkey, signer::Signer};
|
use solana_sdk::{pubkey::Pubkey, signer::Signer};
|
||||||
use spl_associated_token_account::get_associated_token_address_with_program_id;
|
use spl_associated_token_account::get_associated_token_address_with_program_id;
|
||||||
@@ -170,15 +173,16 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
|
|||||||
let buy_sol_amount = 100_000;
|
let buy_sol_amount = 100_000;
|
||||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||||
dex_type: DexType::PumpSwap,
|
dex_type: DexType::PumpSwap,
|
||||||
|
input_token_type: TradeTokenType::SOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: buy_sol_amount,
|
input_token_amount: buy_sol_amount,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(params.clone()),
|
extension_params: Box::new(params.clone()),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_input_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_input_token_ata: true,
|
||||||
create_mint_ata: true,
|
create_mint_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
@@ -200,16 +204,17 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
|
|||||||
let amount_token = balance.amount.parse::<u64>().unwrap();
|
let amount_token = balance.amount.parse::<u64>().unwrap();
|
||||||
let sell_params = sol_trade_sdk::TradeSellParams {
|
let sell_params = sol_trade_sdk::TradeSellParams {
|
||||||
dex_type: DexType::PumpSwap,
|
dex_type: DexType::PumpSwap,
|
||||||
|
output_token_type: TradeTokenType::SOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
token_amount: amount_token,
|
input_token_amount: amount_token,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
with_tip: false,
|
with_tip: false,
|
||||||
extension_params: Box::new(params.clone()),
|
extension_params: Box::new(params.clone()),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_output_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_output_token_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::sync::{
|
|||||||
Arc,
|
Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use sol_trade_sdk::{common::TradeConfig, instruction::utils::raydium_amm_v4::{accounts, fetch_amm_info}, solana_streamer_sdk::{match_event, streaming::event_parser::protocols::raydium_amm_v4::RaydiumAmmV4SwapEvent}, trading::common::get_multi_token_balances};
|
use sol_trade_sdk::{common::TradeConfig, instruction::utils::raydium_amm_v4::{accounts, fetch_amm_info}, solana_streamer_sdk::{match_event, streaming::event_parser::protocols::raydium_amm_v4::RaydiumAmmV4SwapEvent}, trading::common::get_multi_token_balances, TradeTokenType};
|
||||||
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::common::filter::EventTypeFilter;
|
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::raydium_amm_v4::parser::RAYDIUM_AMM_V4_PROGRAM_ID;
|
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::protocols::raydium_amm_v4::parser::RAYDIUM_AMM_V4_PROGRAM_ID;
|
||||||
@@ -138,15 +138,16 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
|
|||||||
let buy_sol_amount = 100_000;
|
let buy_sol_amount = 100_000;
|
||||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||||
dex_type: DexType::RaydiumAmmV4,
|
dex_type: DexType::RaydiumAmmV4,
|
||||||
|
input_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: buy_sol_amount,
|
input_token_amount: buy_sol_amount,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(params),
|
extension_params: Box::new(params),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_input_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_input_token_ata: true,
|
||||||
create_mint_ata: true,
|
create_mint_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
@@ -167,16 +168,17 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
|
|||||||
let params = RaydiumAmmV4Params::from_amm_address_by_rpc(&client.rpc, trade_info.amm).await?;
|
let params = RaydiumAmmV4Params::from_amm_address_by_rpc(&client.rpc, trade_info.amm).await?;
|
||||||
let sell_params = sol_trade_sdk::TradeSellParams {
|
let sell_params = sol_trade_sdk::TradeSellParams {
|
||||||
dex_type: DexType::RaydiumAmmV4,
|
dex_type: DexType::RaydiumAmmV4,
|
||||||
|
output_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
token_amount: amount_token,
|
input_token_amount: amount_token,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
with_tip: false,
|
with_tip: false,
|
||||||
extension_params: Box::new(params),
|
extension_params: Box::new(params),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_output_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_output_token_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ use std::sync::{
|
|||||||
Arc,
|
Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use sol_trade_sdk::solana_streamer_sdk::streaming::YellowstoneGrpc;
|
|
||||||
use sol_trade_sdk::solana_streamer_sdk::{
|
use sol_trade_sdk::solana_streamer_sdk::{
|
||||||
match_event, streaming::event_parser::protocols::raydium_cpmm::RaydiumCpmmSwapEvent,
|
match_event, streaming::event_parser::protocols::raydium_cpmm::RaydiumCpmmSwapEvent,
|
||||||
};
|
};
|
||||||
@@ -28,6 +27,7 @@ use sol_trade_sdk::{
|
|||||||
solana_streamer_sdk::streaming::event_parser::common::EventType,
|
solana_streamer_sdk::streaming::event_parser::common::EventType,
|
||||||
trading::core::params::RaydiumCpmmParams,
|
trading::core::params::RaydiumCpmmParams,
|
||||||
};
|
};
|
||||||
|
use sol_trade_sdk::{solana_streamer_sdk::streaming::YellowstoneGrpc, TradeTokenType};
|
||||||
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;
|
||||||
@@ -145,15 +145,16 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
|
|||||||
let buy_sol_amount = 100_000;
|
let buy_sol_amount = 100_000;
|
||||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||||
dex_type: DexType::RaydiumCpmm,
|
dex_type: DexType::RaydiumCpmm,
|
||||||
|
input_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: buy_sol_amount,
|
input_token_amount: buy_sol_amount,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(buy_params),
|
extension_params: Box::new(buy_params),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_input_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_input_token_ata: true,
|
||||||
create_mint_ata: true,
|
create_mint_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
@@ -176,16 +177,17 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
|
|||||||
println!("Selling {} tokens", amount_token);
|
println!("Selling {} tokens", amount_token);
|
||||||
let sell_params = sol_trade_sdk::TradeSellParams {
|
let sell_params = sol_trade_sdk::TradeSellParams {
|
||||||
dex_type: DexType::RaydiumCpmm,
|
dex_type: DexType::RaydiumCpmm,
|
||||||
|
output_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
token_amount: amount_token,
|
input_token_amount: amount_token,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
with_tip: false,
|
with_tip: false,
|
||||||
extension_params: Box::new(sell_params),
|
extension_params: Box::new(sell_params),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_output_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_output_token_ata: true,
|
||||||
open_seed_optimize: false,
|
open_seed_optimize: false,
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use sol_trade_sdk::{
|
|||||||
},
|
},
|
||||||
swqos::SwqosConfig,
|
swqos::SwqosConfig,
|
||||||
trading::{core::params::PumpSwapParams, factory::DexType},
|
trading::{core::params::PumpSwapParams, factory::DexType},
|
||||||
SolanaTrade,
|
SolanaTrade, TradeTokenType,
|
||||||
};
|
};
|
||||||
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair};
|
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair};
|
||||||
use solana_sdk::{pubkey::Pubkey, signer::Signer};
|
use solana_sdk::{pubkey::Pubkey, signer::Signer};
|
||||||
@@ -25,8 +25,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let buy_sol_amount = 100_000;
|
let buy_sol_amount = 100_000;
|
||||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||||
dex_type: DexType::PumpSwap,
|
dex_type: DexType::PumpSwap,
|
||||||
|
input_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
sol_amount: buy_sol_amount,
|
input_token_amount: buy_sol_amount,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
extension_params: Box::new(
|
extension_params: Box::new(
|
||||||
@@ -34,8 +35,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
),
|
),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_input_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_input_token_ata: true,
|
||||||
create_mint_ata: true,
|
create_mint_ata: true,
|
||||||
open_seed_optimize: true, // ❗️❗️❗️❗️ open seed optimize
|
open_seed_optimize: true, // ❗️❗️❗️❗️ open seed optimize
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
@@ -61,8 +62,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let amount_token = balance.amount.parse::<u64>().unwrap();
|
let amount_token = balance.amount.parse::<u64>().unwrap();
|
||||||
let sell_params = sol_trade_sdk::TradeSellParams {
|
let sell_params = sol_trade_sdk::TradeSellParams {
|
||||||
dex_type: DexType::PumpSwap,
|
dex_type: DexType::PumpSwap,
|
||||||
|
output_token_type: TradeTokenType::WSOL,
|
||||||
mint: mint_pubkey,
|
mint: mint_pubkey,
|
||||||
token_amount: amount_token,
|
input_token_amount: amount_token,
|
||||||
slippage_basis_points: slippage_basis_points,
|
slippage_basis_points: slippage_basis_points,
|
||||||
recent_blockhash: Some(recent_blockhash),
|
recent_blockhash: Some(recent_blockhash),
|
||||||
with_tip: false,
|
with_tip: false,
|
||||||
@@ -71,8 +73,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
),
|
),
|
||||||
lookup_table_key: None,
|
lookup_table_key: None,
|
||||||
wait_transaction_confirmed: true,
|
wait_transaction_confirmed: true,
|
||||||
create_wsol_ata: true,
|
create_output_token_ata: true,
|
||||||
close_wsol_ata: true,
|
close_output_token_ata: true,
|
||||||
open_seed_optimize: true, // ❗️❗️❗️❗️ open seed optimize
|
open_seed_optimize: true, // ❗️❗️❗️❗️ open seed optimize
|
||||||
durable_nonce: None,
|
durable_nonce: None,
|
||||||
};
|
};
|
||||||
|
|||||||
+53
-177
@@ -33,6 +33,14 @@ use solana_sdk::{pubkey::Pubkey, signature::Keypair, signature::Signature};
|
|||||||
pub use solana_streamer_sdk;
|
pub use solana_streamer_sdk;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
/// Type of the token to buy
|
||||||
|
#[derive(Clone, PartialEq)]
|
||||||
|
pub enum TradeTokenType {
|
||||||
|
SOL,
|
||||||
|
WSOL,
|
||||||
|
USD1,
|
||||||
|
}
|
||||||
|
|
||||||
/// Main trading client for Solana DeFi protocols
|
/// Main trading client for Solana DeFi protocols
|
||||||
///
|
///
|
||||||
/// `SolanaTrade` provides a unified interface for trading across multiple Solana DEXs
|
/// `SolanaTrade` provides a unified interface for trading across multiple Solana DEXs
|
||||||
@@ -62,54 +70,6 @@ impl Clone for SolanaTrade {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parameters for executing swap orders across different DEX protocols
|
|
||||||
///
|
|
||||||
/// Contains all necessary configuration for swapping tokens, including
|
|
||||||
/// protocol-specific settings, account management options, and transaction preferences.
|
|
||||||
#[derive(Clone)]
|
|
||||||
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
|
|
||||||
pub output_mint: Pubkey,
|
|
||||||
/// Public key of the token program to use for the input token
|
|
||||||
pub input_token_program: Pubkey,
|
|
||||||
/// Public key of the token program to use for the output token
|
|
||||||
pub output_token_program: Pubkey,
|
|
||||||
/// Amount of input token to spend (in lamports)
|
|
||||||
pub input_amount: u64,
|
|
||||||
/// Optional slippage tolerance in basis points (e.g., 100 = 1%)
|
|
||||||
pub slippage_basis_points: Option<u64>,
|
|
||||||
/// Recent blockhash for transaction validity
|
|
||||||
pub recent_blockhash: Option<Hash>,
|
|
||||||
/// Protocol-specific parameters (PumpFun, Raydium, etc.)
|
|
||||||
pub extension_params: Box<dyn ProtocolParams>,
|
|
||||||
// Extended configuration
|
|
||||||
/// Optional address lookup table for transaction size optimization
|
|
||||||
pub lookup_table_key: Option<Pubkey>,
|
|
||||||
/// Whether to wait for transaction confirmation before returning
|
|
||||||
pub wait_transaction_confirmed: bool,
|
|
||||||
/// Whether to create wrapped SOL associated token account
|
|
||||||
pub create_input_mint_ata: bool,
|
|
||||||
/// Whether to close wrapped SOL associated token account after trade
|
|
||||||
pub close_input_mint_ata: bool,
|
|
||||||
/// Whether to create token mint associated token account
|
|
||||||
pub create_output_mint_ata: bool,
|
|
||||||
/// Whether to close token mint associated token account after trade
|
|
||||||
pub close_output_mint_ata: bool,
|
|
||||||
/// Whether to enable seed-based optimization for account creation
|
|
||||||
pub open_seed_optimize: bool,
|
|
||||||
/// Durable nonce information
|
|
||||||
pub durable_nonce: Option<DurableNonceInfo>,
|
|
||||||
/// Whether to include tip for transaction priority
|
|
||||||
pub with_tip: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parameters for executing buy orders across different DEX protocols
|
/// Parameters for executing buy orders across different DEX protocols
|
||||||
///
|
///
|
||||||
/// Contains all necessary configuration for purchasing tokens, including
|
/// Contains all necessary configuration for purchasing tokens, including
|
||||||
@@ -119,10 +79,12 @@ pub struct TradeBuyParams {
|
|||||||
// 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,
|
||||||
|
/// Type of the token to buy
|
||||||
|
pub input_token_type: TradeTokenType,
|
||||||
/// Public key of the token to purchase
|
/// Public key of the token to purchase
|
||||||
pub mint: Pubkey,
|
pub mint: Pubkey,
|
||||||
/// Amount of SOL to spend (in lamports)
|
/// Amount of tokens to buy (in smallest token units)
|
||||||
pub sol_amount: u64,
|
pub input_token_amount: u64,
|
||||||
/// Optional slippage tolerance in basis points (e.g., 100 = 1%)
|
/// Optional slippage tolerance in basis points (e.g., 100 = 1%)
|
||||||
pub slippage_basis_points: Option<u64>,
|
pub slippage_basis_points: Option<u64>,
|
||||||
/// Recent blockhash for transaction validity
|
/// Recent blockhash for transaction validity
|
||||||
@@ -134,10 +96,10 @@ pub struct TradeBuyParams {
|
|||||||
pub lookup_table_key: Option<Pubkey>,
|
pub lookup_table_key: Option<Pubkey>,
|
||||||
/// Whether to wait for transaction confirmation before returning
|
/// Whether to wait for transaction confirmation before returning
|
||||||
pub wait_transaction_confirmed: bool,
|
pub wait_transaction_confirmed: bool,
|
||||||
/// Whether to create wrapped SOL associated token account
|
/// Whether to create input token associated token account
|
||||||
pub create_wsol_ata: bool,
|
pub create_input_token_ata: bool,
|
||||||
/// Whether to close wrapped SOL associated token account after trade
|
/// Whether to close input token associated token account after trade
|
||||||
pub close_wsol_ata: bool,
|
pub close_input_token_ata: bool,
|
||||||
/// Whether to create token mint associated token account
|
/// Whether to create token mint associated token account
|
||||||
pub create_mint_ata: bool,
|
pub create_mint_ata: bool,
|
||||||
/// Whether to enable seed-based optimization for account creation
|
/// Whether to enable seed-based optimization for account creation
|
||||||
@@ -155,10 +117,12 @@ pub struct TradeSellParams {
|
|||||||
// 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,
|
||||||
|
/// Type of the token to sell
|
||||||
|
pub output_token_type: TradeTokenType,
|
||||||
/// Public key of the token to sell
|
/// Public key of the token to sell
|
||||||
pub mint: Pubkey,
|
pub mint: Pubkey,
|
||||||
/// Amount of tokens to sell (in smallest token units)
|
/// Amount of tokens to sell (in smallest token units)
|
||||||
pub token_amount: u64,
|
pub input_token_amount: u64,
|
||||||
/// Optional slippage tolerance in basis points (e.g., 100 = 1%)
|
/// Optional slippage tolerance in basis points (e.g., 100 = 1%)
|
||||||
pub slippage_basis_points: Option<u64>,
|
pub slippage_basis_points: Option<u64>,
|
||||||
/// Recent blockhash for transaction validity
|
/// Recent blockhash for transaction validity
|
||||||
@@ -172,10 +136,10 @@ pub struct TradeSellParams {
|
|||||||
pub lookup_table_key: Option<Pubkey>,
|
pub lookup_table_key: Option<Pubkey>,
|
||||||
/// Whether to wait for transaction confirmation before returning
|
/// Whether to wait for transaction confirmation before returning
|
||||||
pub wait_transaction_confirmed: bool,
|
pub wait_transaction_confirmed: bool,
|
||||||
/// Whether to create wrapped SOL associated token account
|
/// Whether to create output token associated token account
|
||||||
pub create_wsol_ata: bool,
|
pub create_output_token_ata: bool,
|
||||||
/// Whether to close wrapped SOL associated token account after trade
|
/// Whether to close output token associated token account after trade
|
||||||
pub close_wsol_ata: bool,
|
pub close_output_token_ata: bool,
|
||||||
/// Whether to enable seed-based optimization for account creation
|
/// Whether to enable seed-based optimization for account creation
|
||||||
pub open_seed_optimize: bool,
|
pub open_seed_optimize: bool,
|
||||||
/// Durable nonce information
|
/// Durable nonce information
|
||||||
@@ -274,108 +238,6 @@ impl SolanaTrade {
|
|||||||
.clone()
|
.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Execute a swap order for a specified token
|
|
||||||
///
|
|
||||||
/// # Arguments
|
|
||||||
///
|
|
||||||
/// * `params` - Swap trade parameters containing all necessary trading configuration
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// Returns `Ok(Signature)` with the transaction signature if the swap order is successfully executed,
|
|
||||||
/// or an error if the transaction fails.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
///
|
|
||||||
/// This function will return an error if:
|
|
||||||
/// - Invalid protocol parameters are provided for the specified DEX type
|
|
||||||
/// - The transaction fails to execute
|
|
||||||
/// - Network or RPC errors occur
|
|
||||||
/// - Insufficient token balance for the sale
|
|
||||||
/// - Token account doesn't exist or is not properly initialized
|
|
||||||
/// - Required accounts cannot be created or accessed
|
|
||||||
pub async fn swap(&self, params: TradeSwapParams) -> Result<Signature, anyhow::Error> {
|
|
||||||
if params.slippage_basis_points.is_none() {
|
|
||||||
println!(
|
|
||||||
"slippage_basis_points is none, use default slippage basis points: {}",
|
|
||||||
DEFAULT_SLIPPAGE
|
|
||||||
);
|
|
||||||
}
|
|
||||||
let executor = TradeFactory::create_executor(params.dex_type.clone());
|
|
||||||
let protocol_params = params.extension_params;
|
|
||||||
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),
|
|
||||||
output_token_program: Some(params.output_token_program),
|
|
||||||
input_amount: Some(params.input_amount),
|
|
||||||
slippage_basis_points: params.slippage_basis_points,
|
|
||||||
lookup_table_key: params.lookup_table_key,
|
|
||||||
recent_blockhash: params.recent_blockhash,
|
|
||||||
data_size_limit: 256 * 1024,
|
|
||||||
wait_transaction_confirmed: params.wait_transaction_confirmed,
|
|
||||||
protocol_params: protocol_params.clone(),
|
|
||||||
open_seed_optimize: params.open_seed_optimize,
|
|
||||||
swqos_clients: self.swqos_clients.clone(),
|
|
||||||
middleware_manager: self.middleware_manager.clone(),
|
|
||||||
durable_nonce: params.durable_nonce,
|
|
||||||
with_tip: params.with_tip,
|
|
||||||
create_input_mint_ata: params.create_input_mint_ata,
|
|
||||||
close_input_mint_ata: params.close_input_mint_ata,
|
|
||||||
create_output_mint_ata: params.create_output_mint_ata,
|
|
||||||
close_output_mint_ata: params.close_output_mint_ata,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Validate protocol params
|
|
||||||
let is_valid_params = match params.dex_type {
|
|
||||||
DexType::PumpFun => protocol_params.as_any().downcast_ref::<PumpFunParams>().is_some(),
|
|
||||||
DexType::PumpSwap => {
|
|
||||||
protocol_params.as_any().downcast_ref::<PumpSwapParams>().is_some()
|
|
||||||
}
|
|
||||||
DexType::Bonk => protocol_params.as_any().downcast_ref::<BonkParams>().is_some(),
|
|
||||||
DexType::RaydiumCpmm => {
|
|
||||||
protocol_params.as_any().downcast_ref::<RaydiumCpmmParams>().is_some()
|
|
||||||
}
|
|
||||||
DexType::RaydiumAmmV4 => {
|
|
||||||
protocol_params.as_any().downcast_ref::<RaydiumAmmV4Params>().is_some()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if !is_valid_params {
|
|
||||||
return Err(anyhow::anyhow!("Invalid protocol params for Trade"));
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut no_support_mint = false;
|
|
||||||
|
|
||||||
// 检查是否至少有一个代币是支持的基础代币(SOL、WSOL、USD1)
|
|
||||||
let has_supported_base_token = params.input_mint == SOL_TOKEN_ACCOUNT
|
|
||||||
|| params.output_mint == SOL_TOKEN_ACCOUNT
|
|
||||||
|| params.input_mint == WSOL_TOKEN_ACCOUNT
|
|
||||||
|| params.output_mint == WSOL_TOKEN_ACCOUNT
|
|
||||||
|| params.input_mint == USD1_TOKEN_ACCOUNT
|
|
||||||
|| params.output_mint == USD1_TOKEN_ACCOUNT;
|
|
||||||
|
|
||||||
if !has_supported_base_token {
|
|
||||||
no_support_mint = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// USD1 代币暂支持在 Bonk 协议上交易
|
|
||||||
if (params.input_mint == USD1_TOKEN_ACCOUNT || params.output_mint == USD1_TOKEN_ACCOUNT)
|
|
||||||
&& params.dex_type != DexType::Bonk
|
|
||||||
{
|
|
||||||
no_support_mint = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if no_support_mint {
|
|
||||||
return Err(anyhow::anyhow!("Currently only supports swap trading between (SOL、WSOL、USD1) and other tokens. USD1 swap trading is currently only supported on the Bonk protocol."));
|
|
||||||
}
|
|
||||||
|
|
||||||
executor.swap(buy_params).await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Execute a buy order for a specified token
|
/// Execute a buy order for a specified token
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
@@ -402,22 +264,29 @@ impl SolanaTrade {
|
|||||||
DEFAULT_SLIPPAGE
|
DEFAULT_SLIPPAGE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if params.input_token_type == TradeTokenType::USD1 && params.dex_type != DexType::Bonk {
|
||||||
|
return Err(anyhow::anyhow!(
|
||||||
|
" Current version only support USD1 trading on Bonk protocols"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let input_token_mint = if params.input_token_type == TradeTokenType::SOL {
|
||||||
|
SOL_TOKEN_ACCOUNT
|
||||||
|
} else if params.input_token_type == TradeTokenType::WSOL {
|
||||||
|
WSOL_TOKEN_ACCOUNT
|
||||||
|
} else {
|
||||||
|
USD1_TOKEN_ACCOUNT
|
||||||
|
};
|
||||||
let executor = TradeFactory::create_executor(params.dex_type.clone());
|
let executor = TradeFactory::create_executor(params.dex_type.clone());
|
||||||
let protocol_params = params.extension_params;
|
let protocol_params = params.extension_params;
|
||||||
let input_mint = if params.dex_type == DexType::PumpFun {
|
|
||||||
SOL_TOKEN_ACCOUNT
|
|
||||||
} else {
|
|
||||||
WSOL_TOKEN_ACCOUNT
|
|
||||||
};
|
|
||||||
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,
|
trade_type: TradeType::Buy,
|
||||||
input_mint: input_mint,
|
input_mint: input_token_mint,
|
||||||
output_mint: params.mint,
|
output_mint: params.mint,
|
||||||
input_token_program: None,
|
input_token_program: None,
|
||||||
output_token_program: None,
|
output_token_program: None,
|
||||||
input_amount: Some(params.sol_amount),
|
input_amount: Some(params.input_token_amount),
|
||||||
slippage_basis_points: params.slippage_basis_points,
|
slippage_basis_points: params.slippage_basis_points,
|
||||||
lookup_table_key: params.lookup_table_key,
|
lookup_table_key: params.lookup_table_key,
|
||||||
recent_blockhash: params.recent_blockhash,
|
recent_blockhash: params.recent_blockhash,
|
||||||
@@ -429,8 +298,8 @@ impl SolanaTrade {
|
|||||||
middleware_manager: self.middleware_manager.clone(),
|
middleware_manager: self.middleware_manager.clone(),
|
||||||
durable_nonce: params.durable_nonce,
|
durable_nonce: params.durable_nonce,
|
||||||
with_tip: true,
|
with_tip: true,
|
||||||
create_input_mint_ata: params.create_wsol_ata,
|
create_input_mint_ata: params.create_input_token_ata,
|
||||||
close_input_mint_ata: params.close_wsol_ata,
|
close_input_mint_ata: params.close_input_token_ata,
|
||||||
create_output_mint_ata: params.create_mint_ata,
|
create_output_mint_ata: params.create_mint_ata,
|
||||||
close_output_mint_ata: false,
|
close_output_mint_ata: false,
|
||||||
};
|
};
|
||||||
@@ -484,22 +353,29 @@ impl SolanaTrade {
|
|||||||
DEFAULT_SLIPPAGE
|
DEFAULT_SLIPPAGE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if params.output_token_type == TradeTokenType::USD1 && params.dex_type != DexType::Bonk {
|
||||||
|
return Err(anyhow::anyhow!(
|
||||||
|
" Current version only support USD1 trading on Bonk protocols"
|
||||||
|
));
|
||||||
|
}
|
||||||
let executor = TradeFactory::create_executor(params.dex_type.clone());
|
let executor = TradeFactory::create_executor(params.dex_type.clone());
|
||||||
let protocol_params = params.extension_params;
|
let protocol_params = params.extension_params;
|
||||||
let output_mint = if params.dex_type == DexType::PumpFun {
|
let output_token_mint = if params.output_token_type == TradeTokenType::SOL {
|
||||||
SOL_TOKEN_ACCOUNT
|
SOL_TOKEN_ACCOUNT
|
||||||
} else {
|
} else if params.output_token_type == TradeTokenType::WSOL {
|
||||||
WSOL_TOKEN_ACCOUNT
|
WSOL_TOKEN_ACCOUNT
|
||||||
|
} else {
|
||||||
|
USD1_TOKEN_ACCOUNT
|
||||||
};
|
};
|
||||||
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,
|
trade_type: TradeType::Sell,
|
||||||
input_mint: params.mint,
|
input_mint: params.mint,
|
||||||
output_mint: output_mint,
|
output_mint: output_token_mint,
|
||||||
input_token_program: None,
|
input_token_program: None,
|
||||||
output_token_program: None,
|
output_token_program: None,
|
||||||
input_amount: Some(params.token_amount),
|
input_amount: Some(params.input_token_amount),
|
||||||
slippage_basis_points: params.slippage_basis_points,
|
slippage_basis_points: params.slippage_basis_points,
|
||||||
lookup_table_key: params.lookup_table_key,
|
lookup_table_key: params.lookup_table_key,
|
||||||
recent_blockhash: params.recent_blockhash,
|
recent_blockhash: params.recent_blockhash,
|
||||||
@@ -513,8 +389,8 @@ impl SolanaTrade {
|
|||||||
data_size_limit: 0,
|
data_size_limit: 0,
|
||||||
create_input_mint_ata: false,
|
create_input_mint_ata: false,
|
||||||
close_input_mint_ata: false,
|
close_input_mint_ata: false,
|
||||||
create_output_mint_ata: params.create_wsol_ata,
|
create_output_mint_ata: params.create_output_token_ata,
|
||||||
close_output_mint_ata: params.close_wsol_ata,
|
close_output_mint_ata: params.close_output_token_ata,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Validate protocol params
|
// Validate protocol params
|
||||||
@@ -576,7 +452,7 @@ impl SolanaTrade {
|
|||||||
return Err(anyhow::anyhow!("Percentage must be between 1 and 100"));
|
return Err(anyhow::anyhow!("Percentage must be between 1 and 100"));
|
||||||
}
|
}
|
||||||
let amount = amount_token * percent / 100;
|
let amount = amount_token * percent / 100;
|
||||||
params.token_amount = amount;
|
params.input_token_amount = amount;
|
||||||
self.sell(params).await
|
self.sell(params).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user