@@ -13,32 +13,26 @@ pub struct Pool<P> {
1313 token_b_decimals : u8 ,
1414 tick_spacing : i32 ,
1515 contract : Option < BullaPool < Arc < Provider < P > > > > ,
16- provider : Option < Arc < Provider < P > > > ,
1716}
1817
1918impl < P : JsonRpcClient + ' static > Pool < P > {
20- pub async fn new ( address : Address , token_a : Address , token_b : Address , tick_spacing : i32 , provider : Arc < Provider < P > > ) -> Result < Self > {
19+ pub async fn new ( address : Address , provider : Arc < Provider < P > > , token_a : Address , token_b : Address , tick_spacing : i32 ) -> Result < Self > {
2120 let token_a_decimals = Self :: get_decimals ( provider. clone ( ) , token_a) . await ?;
2221 let token_b_decimals = Self :: get_decimals ( provider. clone ( ) , token_b) . await ?;
22+ let contract = BullaPool :: new ( address, provider. clone ( ) ) ;
23+ println ! ( "Provider set for pool at {:?}" , address) ;
2324 Ok ( Self {
2425 address,
2526 token_a,
2627 token_b,
2728 token_a_decimals,
2829 token_b_decimals,
2930 tick_spacing,
30- contract : None ,
31- provider : Some ( provider) ,
31+ contract : Some ( contract) ,
3232 } )
3333 }
3434
35- pub fn set_provider ( & mut self , provider : Provider < P > ) {
36- let contract = BullaPool :: new ( self . address , Arc :: new ( provider) ) ;
37- self . contract = Some ( contract) ;
38- println ! ( "Provider set for pool at {:?}" , self . address) ;
39- }
40-
41- pub async fn get_adjusted_current_price_and_tick ( & self , provider : & Provider < P > ) -> Result < ( f64 , i32 ) > {
35+ pub async fn get_adjusted_current_price_and_tick ( & self ) -> Result < ( f64 , i32 ) > {
4236 if let Some ( contract) = & self . contract {
4337 let state = contract. get_state_of_amm ( ) . await ?;
4438 let sqrt_price = state. sqrt_price ;
@@ -48,7 +42,7 @@ impl<P: JsonRpcClient + 'static> Pool<P> {
4842 let adjusted_price = price * ( 10.0_f64 . powi ( self . token_a_decimals as i32 - self . token_b_decimals as i32 ) ) ;
4943 Ok ( ( adjusted_price, state. tick ) )
5044 } else {
51- anyhow:: bail!( "Provider not set for pool" )
45+ anyhow:: bail!( "Contract not set for pool" )
5246 }
5347 }
5448
0 commit comments