refactor: Simplify nonce management by replacing global cache with direct fetch

Remove NonceCache singleton pattern and replace with fetch_nonce_info function
that directly fetches nonce information from RPC. This simplifies the API by
eliminating cache initialization and state management, making it easier for
users to manage durable nonces.
This commit is contained in:
ysq
2025-10-07 21:20:00 +08:00
parent 2d9976368b
commit e13c891cc9
7 changed files with 78 additions and 244 deletions
+11 -11
View File
@@ -1,10 +1,12 @@
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
use std::{
str::FromStr,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
};
use sol_trade_sdk::common::nonce_cache::NonceCache;
use sol_trade_sdk::common::TradeConfig;
use sol_trade_sdk::common::{nonce_cache::fetch_nonce_info, TradeConfig};
use sol_trade_sdk::TradeTokenType;
use sol_trade_sdk::{
common::AnyResult,
@@ -13,7 +15,7 @@ use sol_trade_sdk::{
SolanaTrade,
};
use solana_commitment_config::CommitmentConfig;
use solana_sdk::signature::Keypair;
use solana_sdk::{pubkey::Pubkey, signature::Keypair};
use solana_streamer_sdk::match_event;
use solana_streamer_sdk::streaming::event_parser::common::filter::EventTypeFilter;
use solana_streamer_sdk::streaming::event_parser::common::EventType;
@@ -121,10 +123,8 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
// Setup nonce cache
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 durable_nonce = NonceCache::get_durable_nonce_info();
let nonce_account_str = Pubkey::from_str("use_your_nonce_account_here")?;
let durable_nonce = fetch_nonce_info(&client.rpc, nonce_account_str).await;
// Buy tokens
println!("Buying tokens from PumpFun...");
@@ -154,7 +154,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
close_input_token_ata: false,
create_mint_ata: true,
open_seed_optimize: false,
durable_nonce: Some(durable_nonce),
durable_nonce: durable_nonce,
fixed_output_token_amount: None,
};
client.buy(buy_params).await?;