10
10
import scalecodec
11
11
from async_substrate_interface import AsyncSubstrateInterface
12
12
from async_substrate_interface .substrate_addons import RetryAsyncSubstrate
13
+ from async_substrate_interface .utils .storage import StorageKey
13
14
from bittensor_drand import get_encrypted_commitment
14
15
from bittensor_wallet .utils import SS58_FORMAT
15
16
from numpy .typing import NDArray
@@ -767,7 +768,8 @@ async def state_call(
767
768
block_hash = await self .determine_block_hash (block , block_hash , reuse_block )
768
769
return await self .substrate .rpc_request (
769
770
method = "state_call" ,
770
- params = [method , data , block_hash ] if block_hash else [method , data ],
771
+ params = [method , data ],
772
+ block_hash = block_hash ,
771
773
reuse_block_hash = reuse_block ,
772
774
)
773
775
@@ -2242,29 +2244,35 @@ async def get_liquidity_list(
2242
2244
block = block , block_hash = block_hash , reuse_block = reuse_block
2243
2245
)
2244
2246
2245
- query = self .substrate .query
2247
+ # Fetch global fees and current price
2248
+ fee_global_tao_query_sk = await self .substrate .create_storage_key (
2249
+ pallet = "Swap" ,
2250
+ storage_function = "FeeGlobalTao" ,
2251
+ params = [netuid ],
2252
+ block_hash = block_hash ,
2253
+ )
2254
+ fee_global_alpha_query_sk = await self .substrate .create_storage_key (
2255
+ pallet = "Swap" ,
2256
+ storage_function = "FeeGlobalAlpha" ,
2257
+ params = [netuid ],
2258
+ block_hash = block_hash ,
2259
+ )
2260
+ sqrt_price_query_sk = await self .substrate .create_storage_key (
2261
+ pallet = "Swap" ,
2262
+ storage_function = "AlphaSqrtPrice" ,
2263
+ params = [netuid ],
2264
+ block_hash = block_hash ,
2265
+ )
2246
2266
(
2247
- fee_global_tao ,
2248
- fee_global_alpha ,
2249
- sqrt_price ,
2267
+ (fee_global_tao_query , fee_global_alpha_query , sqrt_price_query ),
2250
2268
positions_response ,
2251
2269
) = await asyncio .gather (
2252
- query (
2253
- module = "Swap" ,
2254
- storage_function = "FeeGlobalTao" ,
2255
- params = [netuid ],
2256
- block_hash = block_hash ,
2257
- ),
2258
- query (
2259
- module = "Swap" ,
2260
- storage_function = "FeeGlobalAlpha" ,
2261
- params = [netuid ],
2262
- block_hash = block_hash ,
2263
- ),
2264
- query (
2265
- module = "Swap" ,
2266
- storage_function = "AlphaSqrtPrice" ,
2267
- params = [netuid ],
2270
+ self .substrate .query_multi (
2271
+ [
2272
+ fee_global_tao_query_sk ,
2273
+ fee_global_alpha_query_sk ,
2274
+ sqrt_price_query_sk ,
2275
+ ],
2268
2276
block_hash = block_hash ,
2269
2277
),
2270
2278
self .query_map (
@@ -2275,36 +2283,46 @@ async def get_liquidity_list(
2275
2283
),
2276
2284
)
2277
2285
# convert to floats
2278
- fee_global_tao = fixed_to_float (fee_global_tao )
2279
- fee_global_alpha = fixed_to_float (fee_global_alpha )
2280
- sqrt_price = fixed_to_float (sqrt_price )
2286
+ fee_global_tao = fixed_to_float (fee_global_tao_query [ 1 ] )
2287
+ fee_global_alpha = fixed_to_float (fee_global_alpha_query [ 1 ] )
2288
+ sqrt_price = fixed_to_float (sqrt_price_query [ 1 ] )
2281
2289
2282
2290
# Fetch global fees and current price
2283
2291
current_tick = price_to_tick (sqrt_price ** 2 )
2284
2292
2285
2293
# Fetch positions
2286
- positions = []
2294
+ positions_values : list [tuple [dict , int , int ]] = []
2295
+ positions_storage_keys : list [StorageKey ] = []
2287
2296
async for _ , p in positions_response :
2288
2297
position = p .value
2289
2298
2290
2299
tick_low_idx = position .get ("tick_low" )[0 ]
2291
2300
tick_high_idx = position .get ("tick_high" )[0 ]
2292
-
2293
- tick_low , tick_high = await asyncio .gather (
2294
- query (
2295
- module = "Swap" ,
2296
- storage_function = "Ticks" ,
2297
- params = [netuid , tick_low_idx ],
2298
- block_hash = block_hash ,
2299
- ),
2300
- query (
2301
- module = "Swap" ,
2302
- storage_function = "Ticks" ,
2303
- params = [netuid , tick_high_idx ],
2304
- block_hash = block_hash ,
2305
- ),
2301
+ positions_values .append ((position , tick_low_idx , tick_high_idx ))
2302
+ tick_low_sk = await self .substrate .create_storage_key (
2303
+ pallet = "Swap" ,
2304
+ storage_function = "Ticks" ,
2305
+ params = [netuid , tick_low_idx ],
2306
+ block_hash = block_hash ,
2306
2307
)
2308
+ tick_high_sk = await self .substrate .create_storage_key (
2309
+ pallet = "Swap" ,
2310
+ storage_function = "Ticks" ,
2311
+ params = [netuid , tick_high_idx ],
2312
+ block_hash = block_hash ,
2313
+ )
2314
+ positions_storage_keys .extend ([tick_low_sk , tick_high_sk ])
2307
2315
2316
+ # query all our ticks at once
2317
+ ticks_query = await self .substrate .query_multi (
2318
+ positions_storage_keys , block_hash = block_hash
2319
+ )
2320
+ # iterator with just the values
2321
+ ticks = iter ([x [1 ] for x in ticks_query ])
2322
+ positions = []
2323
+ for position , tick_low_idx , tick_high_idx in positions_values :
2324
+ tick_low = next (ticks )
2325
+ tick_high = next (ticks )
2308
2326
# Calculate fees above/below range for both tokens
2309
2327
tao_below = get_fees (
2310
2328
current_tick = current_tick ,
0 commit comments