feat: add seed optimization and mint ATA creation control
- Add open_seed_optimize parameter for transaction CU optimization using createAccountWithSeed - Add create_mint_ata parameter to control automatic mint token account creation - Update all examples to include new create_mint_ata parameter (set to true) - Enhance documentation with detailed explanations of seed optimization features - Add warnings about compatibility requirements when using seed optimization - Support conditional mint ATA creation across all trading protocols (PumpFun, PumpSwap, Bonk, Raydium) BREAKING CHANGE: All buy functions now require create_mint_ata parameter
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "sol-trade-sdk"
|
||||
version = "0.6.1"
|
||||
version = "0.6.2"
|
||||
edition = "2021"
|
||||
authors = [
|
||||
"William <byteblock6@gmail.com>",
|
||||
|
||||
@@ -33,23 +33,30 @@ Add the dependency to your `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
# Add to your Cargo.toml
|
||||
sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.6.1" }
|
||||
sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.6.2" }
|
||||
```
|
||||
|
||||
### Use crates.io
|
||||
|
||||
```toml
|
||||
# Add to your Cargo.toml
|
||||
sol-trade-sdk = "0.6.1"
|
||||
sol-trade-sdk = "0.6.2"
|
||||
```
|
||||
|
||||
## Usage Examples
|
||||
|
||||
### Important Parameter Description
|
||||
#### open_seed_optimize Parameter
|
||||
|
||||
#### create_wsol_ata and close_wsol_ata Parameters
|
||||
`open_seed_optimize` is used to specify whether to use seed optimization to reduce transaction CU consumption.
|
||||
|
||||
In PumpSwap, Bonk, and Raydium trading, the `create_wsol_ata` and `close_wsol_ata` parameters provide fine-grained control over wSOL (Wrapped SOL) account management:
|
||||
- **Purpose**: When `open_seed_optimize: true`, the SDK uses createAccountWithSeed optimization to create token ata accounts during transactions.
|
||||
- **Note**: Transactions created with `open_seed_optimize` enabled must be sold through this SDK. Using official methods to sell may fail.
|
||||
- **Note**: After enabling `open_seed_optimize`, you need to use the `get_associated_token_address_with_program_id_fast_use_seed` method to get the token ata address.
|
||||
|
||||
#### create_wsol_ata and close_wsol_ata、 create_mint_ata Parameters
|
||||
|
||||
In PumpSwap, Bonk, and Raydium trading, the `create_wsol_ata` and `close_wsol_ata`、 `create_mint_ata` parameters provide fine-grained control over wSOL (Wrapped SOL) account management:
|
||||
|
||||
- **create_wsol_ata**:
|
||||
- When `create_wsol_ata: true`, the SDK automatically creates and wraps SOL to wSOL before trading
|
||||
@@ -59,6 +66,9 @@ In PumpSwap, Bonk, and Raydium trading, the `create_wsol_ata` and `close_wsol_at
|
||||
- When `close_wsol_ata: true`, the SDK automatically closes the wSOL account and unwraps to SOL after trading
|
||||
- When selling: automatically unwraps the received wSOL to SOL and reclaims rent
|
||||
|
||||
- **create_mint_ata**:
|
||||
- When `create_mint_ata: true`, the SDK automatically creates the token ata account before trading
|
||||
|
||||
- **Benefits of Separate Parameters**:
|
||||
- Allows independent control of wSOL account creation and closure
|
||||
- Useful for batch operations where you want to create once and close after multiple transactions
|
||||
@@ -114,6 +124,7 @@ Please ensure that the parameters your trading logic depends on are available in
|
||||
| Address Lookup | `address_lookup` | Address lookup table example | `cargo run --package address_lookup` | [examples/address_lookup](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/address_lookup/src/main.rs) |
|
||||
| Nonce | `nonce_cache` | Nonce example | `cargo run --package nonce_cache` | [examples/nonce_cache](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/nonce_cache/src/main.rs) |
|
||||
| WSOL Wrapper | `wsol_wrapper` | Wrap/unwrap SOL to/from WSOL example | `cargo run --package wsol_wrapper` | [examples/wsol_wrapper](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/wsol_wrapper/src/main.rs) |
|
||||
| Seed Trading | `seed_trading` | Seed trading example | `cargo run --package seed_trading` | [examples/seed_trading](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/seed_trading/src/main.rs) |
|
||||
|
||||
### SWQOS Service Configuration
|
||||
|
||||
|
||||
+16
-4
@@ -33,23 +33,31 @@ git clone https://github.com/0xfnzero/sol-trade-sdk
|
||||
|
||||
```toml
|
||||
# 添加到您的 Cargo.toml
|
||||
sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.6.1" }
|
||||
sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.6.2" }
|
||||
```
|
||||
|
||||
### 使用 crates.io
|
||||
|
||||
```toml
|
||||
# 添加到您的 Cargo.toml
|
||||
sol-trade-sdk = "0.6.1"
|
||||
sol-trade-sdk = "0.6.2"
|
||||
```
|
||||
|
||||
## 使用示例
|
||||
|
||||
### 重要说明
|
||||
|
||||
#### create_wsol_ata 和 close_wsol_ata 参数
|
||||
#### open_seed_optimize 参数
|
||||
|
||||
在 PumpSwap、Bonk、Raydium 交易中,`create_wsol_ata` 和 `close_wsol_ata` 参数提供对 wSOL(Wrapped SOL)账户管理的精细控制:
|
||||
`open_seed_optimize` ,用于指定是否使用 seed 优化交易 CU 消耗。
|
||||
|
||||
- **用途**:当 `open_seed_optimize: true` 时,SDK 会在交易时使用 createAccountWithSeed 优化来创建代币 ata 账户。
|
||||
- **注意**:开启 `open_seed_optimize` 后创建的交易,需要通过该 SDK 卖出,使用官网提供的方法卖出可能会失败。
|
||||
- **注意**:开启 `open_seed_optimize` 后,获取代币 ata 地址需要通过 `get_associated_token_address_with_program_id_fast_use_seed` 方法获取。
|
||||
|
||||
#### create_wsol_ata 和 close_wsol_ata、 create_mint_ata 参数
|
||||
|
||||
在 PumpSwap、Bonk、Raydium 交易中,`create_wsol_ata` 和 `close_wsol_ata`、 `create_mint_ata` 参数提供对 wSOL(Wrapped SOL)账户管理的精细控制:
|
||||
|
||||
- **create_wsol_ata**:
|
||||
- 当 `create_wsol_ata: true` 时,SDK 会在交易前自动创建并将 SOL 包装为 wSOL
|
||||
@@ -59,6 +67,9 @@ sol-trade-sdk = "0.6.1"
|
||||
- 当 `close_wsol_ata: true` 时,SDK 会在交易后自动关闭 wSOL 账户并解包装为 SOL
|
||||
- 卖出时:自动将获得的 wSOL 解包装为 SOL 并回收租金
|
||||
|
||||
- **create_mint_ata**:
|
||||
- 当 `create_mint_ata: true` 时,SDK 会在交易时创建代币ata账户
|
||||
|
||||
- **分离参数的优势**:
|
||||
- 允许独立控制 wSOL 账户的创建和关闭
|
||||
- 适用于批量操作,可以创建一次,在多次交易后再关闭
|
||||
@@ -114,6 +125,7 @@ sol-trade-sdk = "0.6.1"
|
||||
| 地址查找表 | `address_lookup` | 地址查找表示例 | `cargo run --package address_lookup` | [examples/address_lookup](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/address_lookup/src/main.rs) |
|
||||
| Nonce | `nonce_cache` | Nonce示例 | `cargo run --package nonce_cache` | [examples/nonce_cache](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/nonce_cache/src/main.rs) |
|
||||
| WSOL 包装器 | `wsol_wrapper` | SOL与WSOL相互转换示例 | `cargo run --package wsol_wrapper` | [examples/wsol_wrapper](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/wsol_wrapper/src/main.rs) |
|
||||
| Seed 优化 | `seed_trading` | Seed 优化交易示例 | `cargo run --package seed_trading` | [examples/seed_trading](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/seed_trading/src/main.rs) |
|
||||
|
||||
### SWQOS 服务配置说明
|
||||
|
||||
|
||||
@@ -171,6 +171,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -153,6 +153,7 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -122,6 +122,7 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult<
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -104,6 +104,7 @@ async fn test_middleware() -> AnyResult<()> {
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -154,6 +154,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -147,6 +147,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -115,6 +115,7 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -35,6 +35,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -189,6 +189,7 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -160,6 +160,7 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -164,6 +164,7 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -37,6 +37,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true, // ❗️❗️❗️❗️ open seed optimize
|
||||
)
|
||||
.await?;
|
||||
|
||||
+11
-9
@@ -96,15 +96,17 @@ impl InstructionBuilder for BonkInstructionBuilder {
|
||||
.extend(crate::trading::common::handle_wsol(¶ms.payer.pubkey(), amount_in));
|
||||
}
|
||||
|
||||
instructions.extend(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&protocol_params.mint_token_program,
|
||||
params.open_seed_optimize,
|
||||
),
|
||||
);
|
||||
if params.create_mint_ata {
|
||||
instructions.extend(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&protocol_params.mint_token_program,
|
||||
params.open_seed_optimize,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
let mut data = [0u8; 32];
|
||||
data[..8].copy_from_slice(&BUY_EXECT_IN_DISCRIMINATOR);
|
||||
|
||||
@@ -93,15 +93,17 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
|
||||
let mut instructions = Vec::with_capacity(2);
|
||||
|
||||
// Create associated token account
|
||||
instructions.extend(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
params.open_seed_optimize,
|
||||
),
|
||||
);
|
||||
if params.create_mint_ata {
|
||||
instructions.extend(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
params.open_seed_optimize,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
let mut buy_data = [0u8; 24];
|
||||
buy_data[..8].copy_from_slice(&[102, 6, 61, 18, 1, 218, 235, 234]); // Method ID
|
||||
|
||||
@@ -124,15 +124,17 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
.extend(crate::trading::common::handle_wsol(¶ms.payer.pubkey(), sol_amount));
|
||||
}
|
||||
|
||||
instructions.extend(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
if quote_mint_is_wsol { &base_mint } else { "e_mint },
|
||||
if quote_mint_is_wsol { &base_token_program } else { "e_token_program },
|
||||
params.open_seed_optimize,
|
||||
),
|
||||
);
|
||||
if params.create_mint_ata {
|
||||
instructions.extend(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
if quote_mint_is_wsol { &base_mint } else { "e_mint },
|
||||
if quote_mint_is_wsol { &base_token_program } else { "e_token_program },
|
||||
params.open_seed_optimize,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Create buy instruction
|
||||
let mut accounts = Vec::with_capacity(23);
|
||||
|
||||
@@ -70,15 +70,17 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
.extend(crate::trading::common::handle_wsol(¶ms.payer.pubkey(), amount_in));
|
||||
}
|
||||
|
||||
instructions.extend(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
params.open_seed_optimize,
|
||||
),
|
||||
);
|
||||
if params.create_mint_ata {
|
||||
instructions.extend(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
params.open_seed_optimize,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Create buy instruction
|
||||
let accounts: [AccountMeta; 17] = [
|
||||
|
||||
@@ -105,15 +105,17 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
.extend(crate::trading::common::handle_wsol(¶ms.payer.pubkey(), amount_in));
|
||||
}
|
||||
|
||||
instructions.extend(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&mint_token_program,
|
||||
params.open_seed_optimize,
|
||||
),
|
||||
);
|
||||
if params.create_mint_ata {
|
||||
instructions.extend(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&mint_token_program,
|
||||
params.open_seed_optimize,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Create buy instruction
|
||||
let accounts: [AccountMeta; 13] = [
|
||||
|
||||
@@ -161,6 +161,7 @@ impl SolanaTrade {
|
||||
wait_transaction_confirmed: bool,
|
||||
create_wsol_ata: bool,
|
||||
close_wsol_ata: bool,
|
||||
create_mint_ata: bool,
|
||||
open_seed_optimize: bool,
|
||||
) -> Result<Signature, anyhow::Error> {
|
||||
if slippage_basis_points.is_none() {
|
||||
@@ -187,6 +188,7 @@ impl SolanaTrade {
|
||||
open_seed_optimize,
|
||||
create_wsol_ata,
|
||||
close_wsol_ata,
|
||||
create_mint_ata,
|
||||
swqos_clients: self.swqos_clients.clone(),
|
||||
middleware_manager: self.middleware_manager.clone(),
|
||||
};
|
||||
|
||||
@@ -34,6 +34,7 @@ pub struct BuyParams {
|
||||
pub middleware_manager: Option<Arc<MiddlewareManager>>,
|
||||
pub create_wsol_ata: bool,
|
||||
pub close_wsol_ata: bool,
|
||||
pub create_mint_ata: bool,
|
||||
}
|
||||
|
||||
/// Sell parameters
|
||||
|
||||
Reference in New Issue
Block a user