5
5
use crate :: {
6
6
bindings:: {
7
7
ephemeralgetpopulatedticksinrange:: {
8
+ EphemeralGetPopulatedTicksInRange ,
8
9
EphemeralGetPopulatedTicksInRange :: {
9
10
getPopulatedTicksInRangeCall, getPopulatedTicksInRangeReturn,
10
- EphemeralGetPopulatedTicksInRangeInstance ,
11
11
} ,
12
12
PoolUtils :: PopulatedTick ,
13
13
} ,
14
- ephemeralpoolpositions:: {
15
- EphemeralPoolPositions :: EphemeralPoolPositionsInstance , PoolUtils :: PositionKey ,
16
- } ,
14
+ ephemeralpoolpositions:: { EphemeralPoolPositions , PoolUtils :: PositionKey } ,
17
15
ephemeralpoolslots:: {
18
- EphemeralPoolSlots :: { getSlotsCall, getSlotsReturn, EphemeralPoolSlotsInstance } ,
16
+ EphemeralPoolSlots ,
17
+ EphemeralPoolSlots :: { getSlotsCall, getSlotsReturn} ,
19
18
PoolUtils :: Slot ,
20
19
} ,
21
- ephemeralpooltickbitmap:: EphemeralPoolTickBitmap :: EphemeralPoolTickBitmapInstance ,
22
- ephemeralpoolticks:: EphemeralPoolTicks :: EphemeralPoolTicksInstance ,
20
+ ephemeralpooltickbitmap:: EphemeralPoolTickBitmap ,
21
+ ephemeralpoolticks:: EphemeralPoolTicks ,
23
22
} ,
24
23
call_ephemeral_contract,
24
+ error:: Error ,
25
25
} ;
26
26
use alloc:: vec:: Vec ;
27
27
use alloy:: {
28
- contract:: Error ,
28
+ contract:: Error as ContractError ,
29
29
eips:: BlockId ,
30
- primitives:: { aliases:: I24 , Address , Bytes } ,
30
+ primitives:: { aliases:: I24 , Address } ,
31
31
providers:: Provider ,
32
32
sol_types:: SolCall ,
33
33
transports:: { Transport , TransportError } ,
@@ -54,14 +54,13 @@ pub async fn get_populated_ticks_in_range<T, P>(
54
54
tick_upper : I24 ,
55
55
provider : P ,
56
56
block_id : Option < BlockId > ,
57
- ) -> Result < ( Vec < PopulatedTick > , I24 ) >
57
+ ) -> Result < ( Vec < PopulatedTick > , I24 ) , Error >
58
58
where
59
59
T : Transport + Clone ,
60
60
P : Provider < T > ,
61
61
{
62
- let deploy_builder = EphemeralGetPopulatedTicksInRangeInstance :: deploy_builder (
63
- provider, pool, tick_lower, tick_upper,
64
- ) ;
62
+ let deploy_builder =
63
+ EphemeralGetPopulatedTicksInRange :: deploy_builder ( provider, pool, tick_lower, tick_upper) ;
65
64
match call_ephemeral_contract ! ( deploy_builder, getPopulatedTicksInRangeCall, block_id) {
66
65
Ok ( getPopulatedTicksInRangeReturn {
67
66
populatedTicks,
73
72
. collect ( ) ,
74
73
tickSpacing,
75
74
) ) ,
76
- Err ( err) => Err ( err. into ( ) ) ,
75
+ Err ( err) => Err ( err) ,
77
76
}
78
77
}
79
78
@@ -103,15 +102,12 @@ pub async fn get_static_slots<T, P>(
103
102
pool : Address ,
104
103
provider : P ,
105
104
block_id : Option < BlockId > ,
106
- ) -> Result < Vec < Slot > >
105
+ ) -> Result < Vec < Slot > , Error >
107
106
where
108
107
T : Transport + Clone ,
109
108
P : Provider < T > ,
110
109
{
111
- get_pool_storage ! (
112
- EphemeralPoolSlotsInstance :: deploy_builder( provider, pool) ,
113
- block_id
114
- )
110
+ get_pool_storage ! ( EphemeralPoolSlots :: deploy_builder( provider, pool) , block_id)
115
111
}
116
112
117
113
/// Get the storage slots in the `ticks` mapping between `tick_lower` and `tick_upper`.
@@ -134,13 +130,13 @@ pub async fn get_ticks_slots<T, P>(
134
130
tick_upper : I24 ,
135
131
provider : P ,
136
132
block_id : Option < BlockId > ,
137
- ) -> Result < Vec < Slot > >
133
+ ) -> Result < Vec < Slot > , Error >
138
134
where
139
135
T : Transport + Clone ,
140
136
P : Provider < T > ,
141
137
{
142
138
get_pool_storage ! (
143
- EphemeralPoolTicksInstance :: deploy_builder( provider, pool, tick_lower, tick_upper) ,
139
+ EphemeralPoolTicks :: deploy_builder( provider, pool, tick_lower, tick_upper) ,
144
140
block_id
145
141
)
146
142
}
@@ -160,13 +156,13 @@ pub async fn get_tick_bitmap_slots<T, P>(
160
156
pool : Address ,
161
157
provider : P ,
162
158
block_id : Option < BlockId > ,
163
- ) -> Result < Vec < Slot > >
159
+ ) -> Result < Vec < Slot > , Error >
164
160
where
165
161
T : Transport + Clone ,
166
162
P : Provider < T > ,
167
163
{
168
164
get_pool_storage ! (
169
- EphemeralPoolTickBitmapInstance :: deploy_builder( provider, pool) ,
165
+ EphemeralPoolTickBitmap :: deploy_builder( provider, pool) ,
170
166
block_id
171
167
)
172
168
}
@@ -188,13 +184,13 @@ pub async fn get_positions_slots<T, P>(
188
184
positions : Vec < PositionKey > ,
189
185
provider : P ,
190
186
block_id : Option < BlockId > ,
191
- ) -> Result < Vec < Slot > >
187
+ ) -> Result < Vec < Slot > , Error >
192
188
where
193
189
T : Transport + Clone ,
194
190
P : Provider < T > ,
195
191
{
196
192
get_pool_storage ! (
197
- EphemeralPoolPositionsInstance :: deploy_builder( provider, pool, positions) ,
193
+ EphemeralPoolPositions :: deploy_builder( provider, pool, positions) ,
198
194
block_id
199
195
)
200
196
}
@@ -203,28 +199,35 @@ where
203
199
mod tests {
204
200
use super :: * ;
205
201
use crate :: {
206
- bindings:: iuniswapv3pool:: IUniswapV3Pool :: { IUniswapV3PoolInstance , Mint } ,
202
+ bindings:: iuniswapv3pool:: { IUniswapV3Pool , IUniswapV3Pool :: Mint } ,
207
203
tests:: * ,
208
204
} ;
209
205
use alloy:: { primitives:: address, rpc:: types:: Filter , sol_types:: SolEvent } ;
210
- use anyhow:: Result ;
211
206
use futures:: future:: join_all;
212
207
213
208
const POOL_ADDRESS : Address = address ! ( "88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640" ) ;
209
+
214
210
#[ tokio:: test]
215
- async fn test_get_populated_ticks_in_range ( ) -> Result < ( ) > {
211
+ async fn test_get_populated_ticks_in_range ( ) {
216
212
let provider = PROVIDER . clone ( ) ;
217
- let pool = IUniswapV3PoolInstance :: new ( POOL_ADDRESS , provider. clone ( ) ) ;
218
- let tick_current = pool. slot0 ( ) . block ( BLOCK_NUMBER ) . call ( ) . await ?. tick ;
219
- let tick_spacing = pool. tickSpacing ( ) . block ( BLOCK_NUMBER ) . call ( ) . await ?. _0 ;
213
+ let pool = IUniswapV3Pool :: new ( POOL_ADDRESS , provider. clone ( ) ) ;
214
+ let tick_current = pool. slot0 ( ) . block ( BLOCK_NUMBER ) . call ( ) . await . unwrap ( ) . tick ;
215
+ let tick_spacing = pool
216
+ . tickSpacing ( )
217
+ . block ( BLOCK_NUMBER )
218
+ . call ( )
219
+ . await
220
+ . unwrap ( )
221
+ . _0 ;
220
222
let ( ticks, _) = get_populated_ticks_in_range (
221
223
POOL_ADDRESS ,
222
224
tick_current,
223
225
tick_current + ( tick_spacing << 8 ) ,
224
226
provider,
225
227
Some ( BLOCK_NUMBER ) ,
226
228
)
227
- . await ?;
229
+ . await
230
+ . unwrap ( ) ;
228
231
assert ! ( !ticks. is_empty( ) ) ;
229
232
// let mut multicall = Multicall::new(client.clone(), None).await?;
230
233
// multicall.add_calls(
@@ -254,7 +257,6 @@ mod tests {
254
257
// assert_eq!(liquidity_gross, _liquidity_gross);
255
258
// assert_eq!(liquidity_net, _liquidity_net);
256
259
// }
257
- Ok ( ( ) )
258
260
}
259
261
260
262
async fn verify_slots < T , P > ( slots : Vec < Slot > , provider : P )
@@ -287,7 +289,7 @@ mod tests {
287
289
#[ tokio:: test]
288
290
async fn test_get_ticks_slots ( ) {
289
291
let provider = PROVIDER . clone ( ) ;
290
- let pool = IUniswapV3PoolInstance :: new ( POOL_ADDRESS , provider. clone ( ) ) ;
292
+ let pool = IUniswapV3Pool :: new ( POOL_ADDRESS , provider. clone ( ) ) ;
291
293
let tick_current = pool. slot0 ( ) . block ( BLOCK_NUMBER ) . call ( ) . await . unwrap ( ) . tick ;
292
294
let slots = get_ticks_slots (
293
295
POOL_ADDRESS ,
@@ -311,14 +313,14 @@ mod tests {
311
313
}
312
314
313
315
#[ tokio:: test]
314
- async fn test_get_positions_slots ( ) -> Result < ( ) > {
316
+ async fn test_get_positions_slots ( ) {
315
317
let provider = PROVIDER . clone ( ) ;
316
318
// create a filter to get the mint events
317
319
let filter = Filter :: new ( )
318
320
. from_block ( BLOCK_NUMBER . as_u64 ( ) . unwrap ( ) - 10000 )
319
321
. to_block ( BLOCK_NUMBER . as_u64 ( ) . unwrap ( ) )
320
322
. event_signature ( <Mint as SolEvent >:: SIGNATURE_HASH ) ;
321
- let logs = provider. get_logs ( & filter) . await ? ;
323
+ let logs = provider. get_logs ( & filter) . await . unwrap ( ) ;
322
324
// decode the logs into position keys
323
325
let positions: Vec < _ > = logs
324
326
. iter ( )
@@ -343,8 +345,8 @@ mod tests {
343
345
provider. clone ( ) ,
344
346
Some ( BLOCK_NUMBER ) ,
345
347
)
346
- . await ?;
348
+ . await
349
+ . unwrap ( ) ;
347
350
verify_slots ( slots, provider) . await ;
348
- Ok ( ( ) )
349
351
}
350
352
}
0 commit comments