Release v4.0.18
This commit is contained in:
+58
-24
@@ -195,40 +195,73 @@ gas_fee_strategy.set_global_fee_strategy(150000, 150000, 500000, 500000, 0.001,
|
||||
有关所有交易参数的详细信息,请参阅 [交易参数参考手册](docs/TRADING_PARAMETERS_CN.md)。
|
||||
|
||||
```rust
|
||||
// 导入 DexParamEnum 用于协议特定参数
|
||||
use sol_trade_sdk::trading::core::params::DexParamEnum;
|
||||
|
||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||
dex_type: DexType::PumpSwap,
|
||||
input_token_type: TradeTokenType::WSOL,
|
||||
mint: mint_pubkey,
|
||||
input_token_amount: buy_sol_amount,
|
||||
slippage_basis_points: slippage_basis_points,
|
||||
recent_blockhash: Some(recent_blockhash),
|
||||
// 使用 DexParamEnum 实现类型安全的协议参数(零开销抽象)
|
||||
extension_params: DexParamEnum::PumpSwap(params.clone()),
|
||||
address_lookup_table_account: None,
|
||||
wait_transaction_confirmed: true,
|
||||
create_input_token_ata: true,
|
||||
close_input_token_ata: true,
|
||||
create_mint_ata: true,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None, // 可选:指定精确输出数量
|
||||
gas_fee_strategy: gas_fee_strategy.clone(), // Gas 费用策略配置
|
||||
simulate: false, // 设为 true 仅进行模拟
|
||||
use_exact_sol_amount: None, // 对 PumpFun/PumpSwap 使用精确 SOL 输入(默认为 true)
|
||||
use sol_trade_sdk::{
|
||||
AccountPolicy, BuyAmount, DexType, SimpleBuyParams, TradeTokenType,
|
||||
trading::core::params::DexParamEnum,
|
||||
};
|
||||
|
||||
let buy_params = SimpleBuyParams::new(
|
||||
DexType::PumpFun,
|
||||
// 支付币种。PumpFun V2 的 SOL/WSOL quote 池,如果你想花原生 SOL,
|
||||
// 这里仍然传 SOL;SDK 内部会按 V2 账户布局处理。
|
||||
TradeTokenType::SOL,
|
||||
// 要买入的 meme/token mint。
|
||||
mint_pubkey,
|
||||
// 常规 PumpFun/PumpSwap buy。SDK 先估算能买到多少 token,
|
||||
// 再把滑点应用到最大 quote 成本上。
|
||||
BuyAmount::WithMaxInput { quote_amount: buy_sol_amount },
|
||||
// 协议状态参数,通常来自 parser/RPC 缓存,例如 PumpFunParams::from_trade(...)。
|
||||
DexParamEnum::PumpFun(pumpfun_params),
|
||||
// 传入外部缓存的 recent_blockhash;SDK 不在热路径里临时获取。
|
||||
recent_blockhash,
|
||||
gas_fee_strategy.clone(),
|
||||
)
|
||||
// 300 = 3%。
|
||||
.slippage_basis_points(300)
|
||||
// Bot/狙击推荐:假设 ATA 已提前准备好,交易内不创建/关闭 ATA,体积更小。
|
||||
.account_policy(AccountPolicy::HotPathMinimal);
|
||||
```
|
||||
|
||||
#### 4. 执行交易
|
||||
|
||||
```rust
|
||||
client.buy(buy_params).await?;
|
||||
client.buy_simple(buy_params).await?;
|
||||
```
|
||||
|
||||
### ⚡ 交易参数
|
||||
|
||||
有关所有交易参数(包括 `TradeBuyParams` 和 `TradeSellParams`)的详细信息,请参阅专门的 [交易参数参考手册](docs/TRADING_PARAMETERS_CN.md)。
|
||||
新接入建议优先使用 `SimpleBuyParams` / `SimpleSellParams`。它们描述交易意图,SDK 内部处理底层 ATA 参数。多数用户只需要选择:
|
||||
|
||||
- `pay_with` / `receive_as`:买入时用什么 quote 支付,卖出时收什么 quote。钱包实际花/收原生 SOL 就传 `SOL`。PumpFun V2 的 SOL 配对池虽然 `quote_mint` 是 WSOL,但你想用原生 SOL 结算时这里仍传 `SOL`。
|
||||
- `amount`:交易数量语义。用一个枚举表达意图,不再同时理解 `input_token_amount`、`fixed_output_token_amount`、`use_exact_sol_amount`。
|
||||
- `account_policy`:账户创建策略。Bot 通常用 `HotPathMinimal`;普通应用可以保留默认 `Auto`。
|
||||
|
||||
| 参数 | 含义 | 推荐场景 |
|
||||
|---|---|---|
|
||||
| `BuyAmount::ExactInput(amount)` | 精确花费指定 quote 数量;滑点保护最小买到数量。 | 普通买入 |
|
||||
| `BuyAmount::WithMaxInput { quote_amount }` | PumpFun/PumpSwap 常规 buy,滑点作用在最大 quote 成本上。 | 狙击、套利 |
|
||||
| `BuyAmount::ExactOutput { output_amount, max_input_amount }` | 精确买到指定 token 数量,并限制最大 quote 成本。 | 精确输出 |
|
||||
| `SellAmount::ExactInput(amount)` | 精确卖出指定 token 数量。 | 普通卖出 |
|
||||
| `SellAmount::ExactOutput { output_amount, max_input_amount }` | 精确收到指定 quote 数量,并限制最多卖出多少 token;取决于 DEX 是否支持。 | 精确输出卖出 |
|
||||
| `AccountPolicy::Auto` | SDK 按交易路径创建必要 ATA。 | 普通用户 |
|
||||
| `AccountPolicy::HotPathMinimal` | 交易内避免创建/关闭 ATA。 | Bot、狙击、低延迟 |
|
||||
| `AccountPolicy::CreateMissing` | 尽量在交易内创建缺失 ATA。 | 优先方便,不追求最小交易体积 |
|
||||
| `AccountPolicy::AssumePrepared` | 调用方保证所有 ATA 已准备好。 | 高级确定性流程 |
|
||||
|
||||
可选 builder 方法:
|
||||
|
||||
| 方法 | 含义 |
|
||||
|---|---|
|
||||
| `.slippage_basis_points(300)` | 设置滑点。`300` 表示 3%。 |
|
||||
| `.address_lookup_table_account(alt)` | 传入 ALT 以减少交易体积。PumpFun V2 交易较大时很有用。 |
|
||||
| `.wait_tx_confirmed(true)` | 等链上确认后再返回。追求最快提交时通常关闭。 |
|
||||
| `.wait_for_all_submits(true)` | fast-submit 模式下等待所有 SWQoS 通道返回,并拿到全部签名。 |
|
||||
| `.simulate(true)` | 只构建并模拟交易,不真正发送。 |
|
||||
| `.grpc_recv_us(ts)` | 传入上游收到事件的微秒时间戳,用于延迟追踪。 |
|
||||
| `SimpleBuyParams::with_durable_nonce(...)` / `SimpleSellParams::with_durable_nonce(...)` | 使用 durable nonce,不使用 `recent_blockhash`。 |
|
||||
| `SimpleSellParams::with_tip(false)` | 关闭卖出交易 relay tip。买入的 tip 使用 gas fee strategy 控制。 |
|
||||
|
||||
`TradeBuyParams` 和 `TradeSellParams` 仍保留为高级低层接口。详细说明见 [交易参数参考手册](docs/TRADING_PARAMETERS_CN.md)。
|
||||
|
||||
#### 关于shredstream
|
||||
|
||||
@@ -239,6 +272,7 @@ client.buy(buy_params).await?;
|
||||
|
||||
| 描述 | 运行命令 | 源码路径 |
|
||||
|------|---------|----------|
|
||||
| 简化买卖参数 API | `cargo run --package simple_trading` | [examples/simple_trading](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/simple_trading/src/main.rs) |
|
||||
| 创建和配置 TradingClient 实例 | `cargo run --package trading_client` | [examples/trading_client](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/trading_client/src/main.rs) |
|
||||
| 多钱包共享基础设施 | `cargo run --package shared_infrastructure` | [examples/shared_infrastructure](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/shared_infrastructure/src/main.rs) |
|
||||
| PumpFun 代币狙击交易 | `cargo run --package pumpfun_sniper_trading` | [examples/pumpfun_sniper_trading](https://github.com/0xfnzero/sol-trade-sdk/tree/main/examples/pumpfun_sniper_trading/src/main.rs) |
|
||||
|
||||
Reference in New Issue
Block a user