@@ -2,7 +2,6 @@ use anyhow::Result;
22use ethers:: prelude:: * ;
33use serde:: Deserialize ;
44use std:: sync:: Arc ;
5- use log:: info;
65
76// Contract interface for Bulla pool
87#[ derive( Clone , Debug ) ]
@@ -11,13 +10,14 @@ pub struct BullaPool<M> {
1110}
1211
1312#[ derive( Debug , Clone , Deserialize ) ]
14- pub struct GlobalState {
15- pub price : U256 , // uint160
16- pub tick : i32 , // int24
13+ pub struct StateOfAMM {
14+ pub sqrt_price : U256 , // uint160
15+ pub tick : i32 , // int24
1716 pub last_fee : u16 ,
1817 pub plugin_config : u8 ,
19- pub community_fee : u16 ,
20- pub unlocked : bool ,
18+ pub active_liquidity : U256 , // uint128
19+ pub next_tick : i32 , // int24
20+ pub previous_tick : i32 , // int24
2121}
2222
2323impl < M : Middleware + ' static > BullaPool < M > {
@@ -32,25 +32,26 @@ impl<M: Middleware + 'static> BullaPool<M> {
3232 Self { contract }
3333 }
3434
35- pub async fn get_global_state ( & self ) -> Result < GlobalState > {
36- let state: ( U256 , i32 , u16 , u8 , u16 , bool ) = self . contract
37- . method ( "globalState " , ( ) ) ?
35+ pub async fn get_state_of_amm ( & self ) -> Result < StateOfAMM > {
36+ let state: ( U256 , i32 , u16 , u8 , U256 , i32 , i32 ) = self . contract
37+ . method ( "safelyGetStateOfAMM " , ( ) ) ?
3838 . call ( )
3939 . await ?;
4040
41- Ok ( GlobalState {
42- price : state. 0 ,
41+ Ok ( StateOfAMM {
42+ sqrt_price : state. 0 ,
4343 tick : state. 1 ,
4444 last_fee : state. 2 ,
4545 plugin_config : state. 3 ,
46- community_fee : state. 4 ,
47- unlocked : state. 5 ,
46+ active_liquidity : state. 4 ,
47+ next_tick : state. 5 ,
48+ previous_tick : state. 6 ,
4849 } )
4950 }
5051
5152 pub async fn get_current_price ( & self ) -> Result < U256 > {
52- let state = self . get_global_state ( ) . await ?;
53- Ok ( state. price )
53+ let state = self . get_state_of_amm ( ) . await ?;
54+ Ok ( state. sqrt_price )
5455 }
5556}
5657
@@ -77,13 +78,13 @@ impl<P: JsonRpcClient + 'static> Pool<P> {
7778 pub fn set_provider ( & mut self , provider : Provider < P > ) {
7879 let contract = BullaPool :: new ( self . address , Arc :: new ( provider) ) ;
7980 self . contract = Some ( contract) ;
80- println ! ( "Provider set for pool at {}" , self . address) ;
81+ println ! ( "Provider set for pool at {:? }" , self . address) ;
8182 }
8283
8384 pub async fn get_current_price ( & self , provider : & Provider < P > ) -> Result < ( f64 , i32 ) > {
8485 if let Some ( contract) = & self . contract {
85- let state = contract. get_global_state ( ) . await ?;
86- let sqrt_price = state. price ;
86+ let state = contract. get_state_of_amm ( ) . await ?;
87+ let sqrt_price = state. sqrt_price ;
8788 // Convert sqrt price (Q96.64) to actual price
8889 let price = ( sqrt_price. as_u128 ( ) as f64 / ( 1u128 << 96 ) as f64 ) . powi ( 2 ) ;
8990 // Adjust for token decimals (18 - 6 = 12 decimals difference)
@@ -100,4 +101,8 @@ impl<P: JsonRpcClient + 'static> Pool<P> {
100101 let upper_tick = current_tick + ( half_ticks * self . tick_spacing ) ;
101102 ( lower_tick, upper_tick)
102103 }
104+
105+ pub fn address ( & self ) -> Address {
106+ self . address
107+ }
103108}
0 commit comments