refactor: simplify trading parameters API and nonce handling

- Change recent_blockhash from required to optional parameter
- Replace separate nonce_account and current_nonce with unified durable_nonce
- Update all examples and documentation to reflect API changes
- Improve nonce cache usage pattern for better developer experience

BREAKING CHANGE: TradeBuyParams and TradeSellParams API has changed
- recent_blockhash is now Option<Hash> instead of Hash
- nonce_account and current_nonce fields replaced with durable_nonce: Option<DurableNonceInfo>
This commit is contained in:
ysq
2025-09-21 21:56:17 +08:00
parent b4769749f5
commit f8891f3147
21 changed files with 89 additions and 136 deletions
+2 -2
View File
@@ -147,7 +147,7 @@ let buy_params = sol_trade_sdk::TradeBuyParams {
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(params.clone()),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -225,7 +225,7 @@ let nextblock_config = SwqosConfig::NextBlock(
- If no custom URL is provided (`None`), the system will use the default endpoint for the specified `SwqosRegion`
- This allows for maximum flexibility while maintaining backward compatibility
When using multiple MEV services, you need to use `Durable Nonce`. You need to initialize a `NonceCache` class (or write your own nonce management class), get the latest `nonce` value, and use it as the `nonce_account` and `current_nonce` when trading.
When using multiple MEV services, you need to use `Durable Nonce`. You need to initialize a `NonceCache` class (or write your own nonce management class), get the latest `nonce` value, and use it as the `durable_nonce` when trading.
---
+2 -2
View File
@@ -148,7 +148,7 @@ let buy_params = sol_trade_sdk::TradeBuyParams {
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(params.clone()),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -226,7 +226,7 @@ let nextblock_config = SwqosConfig::NextBlock(
- 如果没有提供自定义 URL`None`),系统将使用指定 `SwqosRegion` 的默认端点
- 这提供了最大的灵活性,同时保持向后兼容性
当使用多个MEV服务时,需要使用`Durable Nonce`。你需要初始化`NonceCache`类(或者自行写一个管理nonce的类),获取最新的`nonce`值,并在交易的时候将`nonce_account``current_nonce`填入交易参数。
当使用多个MEV服务时,需要使用`Durable Nonce`。你需要初始化`NonceCache`类(或者自行写一个管理nonce的类),获取最新的`nonce`值,并在交易的时候将`durable_nonce`填入交易参数。
---
+1 -1
View File
@@ -52,7 +52,7 @@ let buy_params = sol_trade_sdk::TradeBuyParams {
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: Some(100),
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, None)),
lookup_table_key: Some(lookup_table_key), // Include lookup table
wait_transaction_confirmed: true,
+1 -1
View File
@@ -52,7 +52,7 @@ let buy_params = sol_trade_sdk::TradeBuyParams {
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: Some(100),
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, None)),
lookup_table_key: Some(lookup_table_key), // 包含查找表
wait_transaction_confirmed: true,
+4 -8
View File
@@ -42,15 +42,12 @@ Get the latest nonce information from RPC:
NonceCache::get_instance().fetch_nonce_info_use_rpc(&client.rpc).await?;
// Or manually manage nonce
// NonceCache::get_instance().update_nonce_info_partial(nonce_account, current_nonce, used);
let nonce_info = NonceCache::get_instance().get_nonce_info();
let current_nonce = nonce_info.current_nonce;
let nonce_account = nonce_info.nonce_account;
println!("Current nonce: {}", current_nonce);
let durable_nonce = NonceCache::get_durable_nonce_info();
```
### 3. Use Nonce in Transactions
Set nonce parameters: nonce_account and current_nonce
Set nonce parameters: durable_nonce
```rust
let buy_params = sol_trade_sdk::TradeBuyParams {
@@ -58,7 +55,7 @@ let buy_params = sol_trade_sdk::TradeBuyParams {
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: Some(100),
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, None)),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -66,8 +63,7 @@ let buy_params = sol_trade_sdk::TradeBuyParams {
close_wsol_ata: false,
create_mint_ata: true,
open_seed_optimize: false,
nonce_account: nonce_account, // Set nonce account
current_nonce: Some(current_nonce), // Set nonce value
durable_nonce: Some(durable_nonce), // Set durable nonce
};
// Execute transaction
+4 -8
View File
@@ -42,15 +42,12 @@ NonceCache::get_instance().init(Some(nonce_account_str.to_string()));
NonceCache::get_instance().fetch_nonce_info_use_rpc(&client.rpc).await?;
// 或者手动管理nonce
// NonceCache::get_instance().update_nonce_info_partial(nonce_account, current_nonce, used);
let nonce_info = NonceCache::get_instance().get_nonce_info();
let current_nonce = nonce_info.current_nonce;
let nonce_account = nonce_info.nonce_account;
println!("Current nonce: {}", current_nonce);
let durable_nonce = NonceCache::get_durable_nonce_info();
```
### 3. 在交易中使用 Nonce
设置 nonce 参数:nonce_account 和 recent_nonce
设置 nonce 参数:durable_nonce
```rust
let buy_params = sol_trade_sdk::TradeBuyParams {
@@ -58,7 +55,7 @@ let buy_params = sol_trade_sdk::TradeBuyParams {
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: Some(100),
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, None)),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -66,8 +63,7 @@ let buy_params = sol_trade_sdk::TradeBuyParams {
close_wsol_ata: false,
create_mint_ata: true,
open_seed_optimize: false,
nonce_account: nonce_account, // 设置 nonce 账户
current_nonce: Some(current_nonce), // 设置 nonce 值
durable_nonce: Some(durable_nonce), // 设置 durable nonce
};
// 执行交易
+6 -9
View File
@@ -21,7 +21,7 @@ The `TradeBuyParams` struct contains all parameters required for executing buy o
| `mint` | `Pubkey` | ✅ | The public key of the token mint to purchase |
| `sol_amount` | `u64` | ✅ | Amount of SOL to spend (in lamports) |
| `slippage_basis_points` | `Option<u64>` | ❌ | Slippage tolerance in basis points (e.g., 100 = 1%, 500 = 5%) |
| `recent_blockhash` | `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.) |
### Advanced Configuration Parameters
@@ -34,8 +34,7 @@ The `TradeBuyParams` struct contains all parameters required for executing buy o
| `close_wsol_ata` | `bool` | ✅ | Whether to close wSOL ATA after transaction |
| `create_mint_ata` | `bool` | ✅ | Whether to create token mint ATA |
| `open_seed_optimize` | `bool` | ✅ | Whether to use seed optimization for reduced CU consumption |
| `nonce_account` | `Option<Pubkey>` | ❌ | nonce account |
| `current_nonce` | `Option<u64>` | ❌ | nonce value |
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | Durable nonce information containing nonce account and current nonce value |
## TradeSellParams
@@ -50,7 +49,7 @@ The `TradeSellParams` struct contains all parameters required for executing sell
| `mint` | `Pubkey` | ✅ | The public key of the token mint to sell |
| `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%) |
| `recent_blockhash` | `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 |
| `extension_params` | `Box<dyn ProtocolParams>` | ✅ | Protocol-specific parameters (PumpFunParams, PumpSwapParams, etc.) |
@@ -63,8 +62,7 @@ The `TradeSellParams` struct contains all parameters required for executing sell
| `create_wsol_ata` | `bool` | ✅ | Whether to create wSOL Associated Token Account |
| `close_wsol_ata` | `bool` | ✅ | Whether to close wSOL ATA after transaction |
| `open_seed_optimize` | `bool` | ✅ | Whether to use seed optimization for reduced CU consumption |
| `nonce_account` | `Option<Pubkey>` | ❌ | nonce account |
| `current_nonce` | `Option<u64>` | ❌ | nonce value |
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | Durable nonce information containing nonce account and current nonce value |
## Parameter Categories
@@ -102,9 +100,8 @@ These parameters enable advanced optimizations:
### 🔄 Optional Parameters
When you need to use durable nonce, you need to fill in these two parameters:
- **nonce_account**: nonce account
- **current_nonce**: nonce value
When you need to use durable nonce, you need to fill in this parameter:
- **durable_nonce**: Durable nonce information containing nonce account and current nonce value
## Important Notes
+6 -9
View File
@@ -21,7 +21,7 @@
| `mint` | `Pubkey` | ✅ | 要购买的代币 mint 公钥 |
| `sol_amount` | `u64` | ✅ | 要花费的 SOL 数量(以 lamports 为单位) |
| `slippage_basis_points` | `Option<u64>` | ❌ | 滑点容忍度(基点单位,例如 100 = 1%, 500 = 5% |
| `recent_blockhash` | `Hash` | | 用于交易有效性的最新区块哈希 |
| `recent_blockhash` | `Option<Hash>` | | 用于交易有效性的最新区块哈希 |
| `extension_params` | `Box<dyn ProtocolParams>` | ✅ | 协议特定参数 (PumpFunParams, PumpSwapParams 等) |
### 高级配置参数
@@ -34,8 +34,7 @@
| `close_wsol_ata` | `bool` | ✅ | 交易后是否关闭 wSOL ATA |
| `create_mint_ata` | `bool` | ✅ | 是否创建代币 mint ATA |
| `open_seed_optimize` | `bool` | ✅ | 是否使用 seed 优化以减少 CU 消耗 |
| `nonce_account` | `Option<Pubkey>` | ❌ | nonce 账户 |
| `current_nonce` | `Option<u64>` | ❌ | nonce 值 |
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | 持久 nonce 信息,包含 nonce 账户和当前 nonce 值 |
## TradeSellParams
@@ -50,7 +49,7 @@
| `mint` | `Pubkey` | ✅ | 要出售的代币 mint 公钥 |
| `token_amount` | `u64` | ✅ | 要出售的代币数量(最小代币单位) |
| `slippage_basis_points` | `Option<u64>` | ❌ | 滑点容忍度(基点单位,例如 100 = 1%, 500 = 5% |
| `recent_blockhash` | `Hash` | | 用于交易有效性的最新区块哈希 |
| `recent_blockhash` | `Option<Hash>` | | 用于交易有效性的最新区块哈希 |
| `with_tip` | `bool` | ✅ | 交易中是否包含小费 |
| `extension_params` | `Box<dyn ProtocolParams>` | ✅ | 协议特定参数 (PumpFunParams, PumpSwapParams 等) |
@@ -63,8 +62,7 @@
| `create_wsol_ata` | `bool` | ✅ | 是否创建 wSOL 关联代币账户 |
| `close_wsol_ata` | `bool` | ✅ | 交易后是否关闭 wSOL ATA |
| `open_seed_optimize` | `bool` | ✅ | 是否使用 seed 优化以减少 CU 消耗 |
| `nonce_account` | `Option<Pubkey>` | ❌ | nonce 账户 |
| `current_nonce` | `Option<u64>` | ❌ | nonce 值 |
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | 持久 nonce 信息,包含 nonce 账户和当前 nonce 值 |
## 参数分类
@@ -102,9 +100,8 @@
### 🔄 非必填参数
当你需要使用 durable nonce 时,需要填入这个参数:
- **nonce_account**: nonce 账户
- **current_nonce**: nonce 值
当你需要使用 durable nonce 时,需要填入这个参数:
- **durable_nonce**: 持久 nonce 信息,包含 nonce 账户和当前 nonce 值
## 重要说明
+2 -3
View File
@@ -152,7 +152,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, None)),
lookup_table_key: Some(lookup_table_key), // you still need to update the AddressLookupTableCache
wait_transaction_confirmed: true,
@@ -160,8 +160,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
close_wsol_ata: false,
create_mint_ata: true,
open_seed_optimize: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.buy(buy_params).await?;
+4 -6
View File
@@ -140,7 +140,7 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(BonkParams::from_trade(trade_info.clone())),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -148,8 +148,7 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
close_wsol_ata: true,
create_mint_ata: true,
open_seed_optimize: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.buy(buy_params).await?;
@@ -169,7 +168,7 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
mint: mint_pubkey,
token_amount: amount_token,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(BonkParams::from_trade(trade_info.clone())),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -177,8 +176,7 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
close_wsol_ata: true,
open_seed_optimize: false,
with_tip: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.sell(sell_params).await?;
+4 -6
View File
@@ -103,7 +103,7 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult<
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(BonkParams::from_dev_trade(trade_info.clone())),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -111,8 +111,7 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult<
close_wsol_ata: true,
create_mint_ata: true,
open_seed_optimize: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.buy(buy_params).await?;
@@ -132,7 +131,7 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult<
mint: mint_pubkey,
token_amount: amount_token,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(BonkParams::immediate_sell(
trade_info.base_token_program,
trade_info.platform_config,
@@ -145,8 +144,7 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult<
close_wsol_ata: true,
open_seed_optimize: false,
with_tip: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.sell(sell_params).await?;
+20 -30
View File
@@ -608,7 +608,7 @@ async fn handle_buy_pumpfun(
mint: mint_pubkey,
sol_amount: sol_lamports,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(param),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -616,8 +616,7 @@ async fn handle_buy_pumpfun(
close_wsol_ata: false,
create_mint_ata: create_mint_ata,
open_seed_optimize: use_seed,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
match client.buy(buy_params).await {
Ok(signature) => {
@@ -657,7 +656,7 @@ async fn handle_buy_pumpswap(
mint: mint_pubkey,
sol_amount: sol_lamports,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(param),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -665,8 +664,7 @@ async fn handle_buy_pumpswap(
close_wsol_ata: false,
create_mint_ata: create_mint_ata,
open_seed_optimize: use_seed,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
match client.buy(buy_params).await {
Ok(signature) => {
@@ -705,7 +703,7 @@ async fn handle_buy_bonk(
mint: mint_pubkey,
sol_amount: sol_lamports,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(param),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -713,8 +711,7 @@ async fn handle_buy_bonk(
close_wsol_ata: false,
create_mint_ata: create_mint_ata,
open_seed_optimize: use_seed,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
match client.buy(buy_params).await {
Ok(signature) => {
@@ -757,7 +754,7 @@ async fn handle_buy_raydium_v4(
mint: mint_pubkey,
sol_amount: sol_lamports,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(param),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -765,8 +762,7 @@ async fn handle_buy_raydium_v4(
close_wsol_ata: false,
create_mint_ata: create_mint_ata,
open_seed_optimize: use_seed,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
match client.buy(buy_params).await {
Ok(signature) => {
@@ -809,7 +805,7 @@ async fn handle_buy_raydium_cpmm(
mint: mint_pubkey,
sol_amount: sol_lamports,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(param),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -817,8 +813,7 @@ async fn handle_buy_raydium_cpmm(
close_wsol_ata: false,
create_mint_ata: create_mint_ata,
open_seed_optimize: use_seed,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
match client.buy(buy_params).await {
Ok(signature) => {
@@ -971,7 +966,7 @@ async fn handle_sell_pumpfun(
mint: mint_pubkey,
token_amount: amount as u64,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
with_tip: false,
extension_params: Box::new(param),
lookup_table_key: None,
@@ -979,8 +974,7 @@ async fn handle_sell_pumpfun(
create_wsol_ata: true,
close_wsol_ata: false,
open_seed_optimize: use_seed,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
match client.sell(sell_params).await {
@@ -1023,7 +1017,7 @@ async fn handle_sell_pumpswap(
mint: mint_pubkey,
token_amount: amount as u64,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
with_tip: false,
extension_params: Box::new(param),
lookup_table_key: None,
@@ -1031,8 +1025,7 @@ async fn handle_sell_pumpswap(
create_wsol_ata: true,
close_wsol_ata: false,
open_seed_optimize: use_seed,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
match client.sell(sell_params).await {
Ok(signature) => {
@@ -1074,7 +1067,7 @@ async fn handle_sell_bonk(
mint: mint_pubkey,
token_amount: amount as u64,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
with_tip: false,
extension_params: Box::new(param),
lookup_table_key: None,
@@ -1082,8 +1075,7 @@ async fn handle_sell_bonk(
create_wsol_ata: true,
close_wsol_ata: false,
open_seed_optimize: use_seed,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
match client.sell(sell_params).await {
Ok(signature) => {
@@ -1128,7 +1120,7 @@ async fn handle_sell_raydium_v4(
mint: mint_pubkey,
token_amount: amount as u64,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
with_tip: false,
extension_params: Box::new(param),
lookup_table_key: None,
@@ -1136,8 +1128,7 @@ async fn handle_sell_raydium_v4(
create_wsol_ata: true,
close_wsol_ata: false,
open_seed_optimize: use_seed,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
match client.sell(sell_params).await {
Ok(signature) => {
@@ -1182,7 +1173,7 @@ async fn handle_sell_raydium_cpmm(
mint: mint_pubkey,
token_amount: amount as u64,
slippage_basis_points: slippage,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
with_tip: false,
extension_params: Box::new(param),
lookup_table_key: None,
@@ -1190,8 +1181,7 @@ async fn handle_sell_raydium_cpmm(
create_wsol_ata: true,
close_wsol_ata: false,
open_seed_optimize: use_seed,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
match client.sell(sell_params).await {
Ok(signature) => {
+2 -3
View File
@@ -89,7 +89,7 @@ async fn test_middleware() -> AnyResult<()> {
mint: mint_pubkey,
sol_amount: buy_sol_cost,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(
PumpSwapParams::from_pool_address_by_rpc(&client.rpc, &pool_address).await?,
),
@@ -99,8 +99,7 @@ async fn test_middleware() -> AnyResult<()> {
close_wsol_ata: true,
create_mint_ata: true,
open_seed_optimize: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.buy(buy_params).await?;
println!("tip: This transaction will not succeed because we're using a test account. You can modify the code to initialize the payer with your own private key");
+3 -6
View File
@@ -125,9 +125,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
let nonce_account_str = "use_your_nonce_account_here";
NonceCache::get_instance().init(Some(nonce_account_str.to_string()));
NonceCache::get_instance().fetch_nonce_info_use_rpc(&client.rpc).await?;
let current_nonce = NonceCache::get_instance().get_nonce_info().current_nonce;
let nonce_account = NonceCache::get_instance().get_nonce_info().nonce_account;
println!("current_nonce: {}", current_nonce);
let durable_nonce = NonceCache::get_durable_nonce_info();
// Buy tokens
println!("Buying tokens from PumpFun...");
@@ -137,7 +135,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, None)),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -145,8 +143,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
close_wsol_ata: false,
create_mint_ata: true,
open_seed_optimize: false,
nonce_account: nonce_account,
current_nonce: Some(current_nonce),
durable_nonce: Some(durable_nonce),
};
client.buy(buy_params).await?;
+4 -6
View File
@@ -128,7 +128,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, None)),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -136,8 +136,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
close_wsol_ata: false,
create_mint_ata: true,
open_seed_optimize: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.buy(buy_params).await?;
@@ -157,7 +156,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
mint: mint_pubkey,
token_amount: amount_token,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
with_tip: false,
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, Some(true))),
lookup_table_key: None,
@@ -165,8 +164,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
create_wsol_ata: false,
close_wsol_ata: false,
open_seed_optimize: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.sell(sell_params).await?;
+4 -6
View File
@@ -97,7 +97,7 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(PumpFunParams::from_dev_trade(&trade_info, None)),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -105,8 +105,7 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
close_wsol_ata: true,
create_mint_ata: true,
open_seed_optimize: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.buy(buy_params).await?;
@@ -126,7 +125,7 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
mint: mint_pubkey,
token_amount: amount_token,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
with_tip: false,
extension_params: Box::new(PumpFunParams::immediate_sell(trade_info.creator_vault, true)),
lookup_table_key: None,
@@ -134,8 +133,7 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
create_wsol_ata: true,
close_wsol_ata: true,
open_seed_optimize: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.sell(sell_params).await?;
+4 -6
View File
@@ -27,7 +27,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(
PumpSwapParams::from_pool_address_by_rpc(&client.rpc, &pool).await?,
),
@@ -37,8 +37,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
close_wsol_ata: true,
create_mint_ata: true,
open_seed_optimize: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.buy(buy_params).await?;
@@ -56,7 +55,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
mint: mint_pubkey,
token_amount: amount_token,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
with_tip: false,
extension_params: Box::new(
PumpSwapParams::from_pool_address_by_rpc(&client.rpc, &pool).await?,
@@ -66,8 +65,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
create_wsol_ata: true,
close_wsol_ata: true,
open_seed_optimize: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.sell(sell_params).await?;
+4 -6
View File
@@ -173,7 +173,7 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(params.clone()),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -181,8 +181,7 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
close_wsol_ata: true,
create_mint_ata: true,
open_seed_optimize: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.buy(buy_params).await?;
@@ -204,7 +203,7 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
mint: mint_pubkey,
token_amount: amount_token,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
with_tip: false,
extension_params: Box::new(params.clone()),
lookup_table_key: None,
@@ -212,8 +211,7 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
create_wsol_ata: true,
close_wsol_ata: true,
open_seed_optimize: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.sell(sell_params).await?;
+4 -6
View File
@@ -141,7 +141,7 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(params),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -149,8 +149,7 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
close_wsol_ata: true,
create_mint_ata: true,
open_seed_optimize: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.buy(buy_params).await?;
@@ -171,7 +170,7 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
mint: mint_pubkey,
token_amount: amount_token,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
with_tip: false,
extension_params: Box::new(params),
lookup_table_key: None,
@@ -179,8 +178,7 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
create_wsol_ata: true,
close_wsol_ata: true,
open_seed_optimize: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.sell(sell_params).await?;
+4 -6
View File
@@ -157,7 +157,7 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(buy_params),
lookup_table_key: None,
wait_transaction_confirmed: true,
@@ -165,8 +165,7 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
close_wsol_ata: true,
create_mint_ata: true,
open_seed_optimize: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.buy(buy_params).await?;
@@ -189,7 +188,7 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
mint: mint_pubkey,
token_amount: amount_token,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
with_tip: false,
extension_params: Box::new(sell_params),
lookup_table_key: None,
@@ -197,8 +196,7 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
create_wsol_ata: true,
close_wsol_ata: true,
open_seed_optimize: false,
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.sell(sell_params).await?;
+4 -6
View File
@@ -28,7 +28,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
extension_params: Box::new(
PumpSwapParams::from_pool_address_by_rpc(&client.rpc, &pool).await?,
),
@@ -38,8 +38,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
close_wsol_ata: true,
create_mint_ata: true,
open_seed_optimize: true, // ❗️❗️❗️❗️ open seed optimize
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.buy(buy_params).await?;
@@ -65,7 +64,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
mint: mint_pubkey,
token_amount: amount_token,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
recent_blockhash: Some(recent_blockhash),
with_tip: false,
extension_params: Box::new(
PumpSwapParams::from_pool_address_by_rpc(&client.rpc, &pool).await?,
@@ -75,8 +74,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
create_wsol_ata: true,
close_wsol_ata: true,
open_seed_optimize: true, // ❗️❗️❗️❗️ open seed optimize
nonce_account: None,
current_nonce: None,
durable_nonce: None,
};
client.sell(sell_params).await?;