feat: add shared infrastructure support for multi-wallet trading
Introduce TradingInfrastructure to allow multiple wallets to share the same RPC client and SWQOS clients, reducing initialization overhead and memory usage. Changes: - Add InfrastructureConfig struct for wallet-independent configuration - Add TradingInfrastructure struct to hold shared RPC/SWQOS clients - Refactor TradingClient to use Arc<TradingInfrastructure> - Add from_infrastructure() for fast client creation from shared infrastructure - Add from_infrastructure_with_wsol_setup() for async WSOL ATA setup - Maintain backwards compatibility with existing TradingClient::new() API Benefits: - First wallet: Full initialization (~200-500ms) - Subsequent wallets (same config): Fast creation (~1-2ms) - Memory: Single set of RPC/SWQOS clients shared across wallets
This commit is contained in:
+6
-6
@@ -9,12 +9,12 @@ use solana_sdk::signer::Signer;
|
||||
impl TradingClient {
|
||||
#[inline]
|
||||
pub async fn get_sol_balance(&self, payer: &Pubkey) -> Result<u64, anyhow::Error> {
|
||||
trading::common::utils::get_sol_balance(&self.rpc, payer).await
|
||||
trading::common::utils::get_sol_balance(&self.infrastructure.rpc, payer).await
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn get_payer_sol_balance(&self) -> Result<u64, anyhow::Error> {
|
||||
trading::common::utils::get_sol_balance(&self.rpc, &self.payer.pubkey()).await
|
||||
trading::common::utils::get_sol_balance(&self.infrastructure.rpc, &self.payer.pubkey()).await
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -23,12 +23,12 @@ impl TradingClient {
|
||||
payer: &Pubkey,
|
||||
mint: &Pubkey,
|
||||
) -> Result<u64, anyhow::Error> {
|
||||
trading::common::utils::get_token_balance(&self.rpc, payer, mint).await
|
||||
trading::common::utils::get_token_balance(&self.infrastructure.rpc, payer, mint).await
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn get_payer_token_balance(&self, mint: &Pubkey) -> Result<u64, anyhow::Error> {
|
||||
trading::common::utils::get_token_balance(&self.rpc, &self.payer.pubkey(), mint).await
|
||||
trading::common::utils::get_token_balance(&self.infrastructure.rpc, &self.payer.pubkey(), mint).await
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -48,11 +48,11 @@ impl TradingClient {
|
||||
receive_wallet: &Pubkey,
|
||||
amount: u64,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
trading::common::utils::transfer_sol(&self.rpc, payer, receive_wallet, amount).await
|
||||
trading::common::utils::transfer_sol(&self.infrastructure.rpc, payer, receive_wallet, amount).await
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn close_token_account(&self, mint: &Pubkey) -> Result<(), anyhow::Error> {
|
||||
trading::common::utils::close_token_account(&self.rpc, self.payer.as_ref(), mint).await
|
||||
trading::common::utils::close_token_account(&self.infrastructure.rpc, self.payer.as_ref(), mint).await
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user