@@ -6,7 +6,7 @@ use raydium_amm::state::{AmmInfo, Loadable};
66use reqwest:: Proxy ;
77use serde:: Deserialize ;
88use solana_client:: {
9- nonblocking :: rpc_client:: RpcClient ,
9+ rpc_client:: RpcClient ,
1010 rpc_filter:: { Memcmp , RpcFilterType } ,
1111} ;
1212use solana_sdk:: {
@@ -26,7 +26,6 @@ use spl_token_client::token::TokenError;
2626use std:: { str:: FromStr , sync:: Arc } ;
2727
2828use crate :: {
29- get_rpc_client_blocking,
3029 swap:: { SwapDirection , SwapInType } ,
3130 token, tx,
3231} ;
@@ -39,7 +38,6 @@ pub const AMM_PROGRAM: &str = "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8";
3938pub struct Raydium {
4039 pub client : Arc < RpcClient > ,
4140 pub keypair : Arc < Keypair > ,
42- pub client_blocking : Option < Arc < solana_client:: rpc_client:: RpcClient > > ,
4341 pub pool_id : Option < String > ,
4442}
4543
@@ -48,19 +46,10 @@ impl Raydium {
4846 Self {
4947 client,
5048 keypair,
51- client_blocking : None ,
5249 pool_id : None ,
5350 }
5451 }
5552
56- pub fn with_blocking_client (
57- & mut self ,
58- client : Arc < solana_client:: rpc_client:: RpcClient > ,
59- ) -> & mut Self {
60- self . client_blocking = Some ( client) ;
61- self
62- }
63-
6453 pub fn with_pool_id ( & mut self , pool_id : Option < String > ) -> & mut Self {
6554 self . pool_id = pool_id;
6655 self
@@ -83,12 +72,8 @@ impl Raydium {
8372 let program_id = spl_token:: ID ;
8473 let native_mint = spl_token:: native_mint:: ID ;
8574
86- let ( amm_pool_id, pool_state) = get_pool_state (
87- self . client_blocking . clone ( ) . unwrap ( ) ,
88- self . pool_id . as_deref ( ) ,
89- Some ( mint_str) ,
90- )
91- . await ?;
75+ let ( amm_pool_id, pool_state) =
76+ get_pool_state ( self . client . clone ( ) , self . pool_id . as_deref ( ) , Some ( mint_str) ) . await ?;
9277 // debug!("pool_state: {:#?}", pool_state);
9378
9479 let ( token_in, token_out, user_input_token, swap_base_in) = match (
@@ -191,9 +176,9 @@ impl Raydium {
191176
192177 let amm_program = Pubkey :: from_str ( AMM_PROGRAM ) ?;
193178 debug ! ( "amm pool id: {amm_pool_id}" ) ;
194- let client = get_rpc_client_blocking ( ) ? ;
179+
195180 let swap_info_result = amm_cli:: calculate_swap_info (
196- & client,
181+ & self . client ,
197182 amm_program,
198183 amm_pool_id,
199184 user_input_token,
@@ -223,8 +208,7 @@ impl Raydium {
223208 // get rent
224209 let rent = self
225210 . client
226- . get_minimum_balance_for_rent_exemption ( Account :: LEN )
227- . await ?;
211+ . get_minimum_balance_for_rent_exemption ( Account :: LEN ) ?;
228212 // if buy add amount_specified
229213 let total_amount = if token_in == native_mint {
230214 rent + amount_specified
@@ -306,7 +290,7 @@ impl Raydium {
306290 return Err ( anyhow ! ( "instructions is empty, no tx required" ) ) ;
307291 }
308292
309- tx:: new_signed_and_send ( & client, & self . keypair , instructions, use_jito) . await
293+ tx:: new_signed_and_send ( & self . client , & self . keypair , instructions, use_jito) . await
310294 }
311295}
312296
0 commit comments