9
9
from async_substrate_interface .substrate_addons import RetrySyncSubstrate
10
10
from async_substrate_interface .sync_substrate import SubstrateInterface
11
11
from async_substrate_interface .types import ScaleObj
12
+ from async_substrate_interface .utils .storage import StorageKey
12
13
from bittensor_drand import get_encrypted_commitment
13
14
from numpy .typing import NDArray
14
15
@@ -429,7 +430,8 @@ def state_call(
429
430
block_hash = self .determine_block_hash (block )
430
431
return self .substrate .rpc_request (
431
432
method = "state_call" ,
432
- params = [method , data , block_hash ] if block_hash else [method , data ],
433
+ params = [method , data ],
434
+ block_hash = block_hash
433
435
)
434
436
435
437
# Common subtensor calls ===========================================================================================
@@ -484,20 +486,26 @@ def blocks_since_last_step(
484
486
)
485
487
return query .value if query is not None and hasattr (query , "value" ) else query
486
488
487
- def blocks_since_last_update (self , netuid : int , uid : int ) -> Optional [int ]:
489
+ def blocks_since_last_update (self , netuid : int , uid : int , block : Optional [ int ] = None ) -> Optional [int ]:
488
490
"""
489
491
Returns the number of blocks since the last update for a specific UID in the subnetwork.
490
492
491
493
Arguments:
492
494
netuid (int): The unique identifier of the subnetwork.
493
495
uid (int): The unique identifier of the neuron.
496
+ block (int): The block number for this query.
494
497
495
498
Returns:
496
499
Optional[int]: The number of blocks since the last update, or ``None`` if the subnetwork or UID does not
497
500
exist.
498
501
"""
499
- call = self .get_hyperparameter (param_name = "LastUpdate" , netuid = netuid )
500
- return None if not call else (self .get_current_block () - int (call [uid ]))
502
+ call = self .get_hyperparameter (param_name = "LastUpdate" , netuid = netuid , block = block )
503
+ if not call :
504
+ return None
505
+ elif block is not None :
506
+ return block - int (call [uid ])
507
+ else :
508
+ return self .get_current_block () - int (call [uid ])
501
509
502
510
def bonds (
503
511
self , netuid : int , block : Optional [int ] = None
@@ -1492,31 +1500,25 @@ def get_liquidity_list(
1492
1500
logging .debug (f"Subnet { netuid } is not active." )
1493
1501
return None
1494
1502
1495
- query = self .substrate .query
1496
1503
block_hash = self .determine_block_hash (block )
1497
1504
1498
1505
# Fetch global fees and current price
1499
- fee_global_tao_query = query (
1500
- module = "Swap" ,
1501
- storage_function = "FeeGlobalTao" ,
1502
- params = [netuid ],
1503
- block_hash = block_hash ,
1506
+ fee_global_tao_query_sk = self .substrate .create_storage_key (
1507
+ pallet = "Swap" , storage_function = "FeeGlobalTao" , params = [netuid ], block_hash = block_hash
1504
1508
)
1505
- fee_global_alpha_query = query (
1506
- module = "Swap" ,
1507
- storage_function = "FeeGlobalAlpha" ,
1508
- params = [netuid ],
1509
- block_hash = block_hash ,
1509
+ fee_global_alpha_query_sk = self .substrate .create_storage_key (
1510
+ pallet = "Swap" , storage_function = "FeeGlobalAlpha" , params = [netuid ], block_hash = block_hash
1510
1511
)
1511
- sqrt_price_query = query (
1512
- module = "Swap" ,
1513
- storage_function = "AlphaSqrtPrice" ,
1514
- params = [netuid ],
1515
- block_hash = block_hash ,
1512
+ sqrt_price_query_sk = self .substrate .create_storage_key (
1513
+ pallet = "Swap" , storage_function = "AlphaSqrtPrice" , params = [netuid ], block_hash = block_hash
1516
1514
)
1517
- fee_global_tao = fixed_to_float (fee_global_tao_query )
1518
- fee_global_alpha = fixed_to_float (fee_global_alpha_query )
1519
- sqrt_price = fixed_to_float (sqrt_price_query )
1515
+ fee_global_tao_query , fee_global_alpha_query , sqrt_price_query = self .substrate .query_multi (
1516
+ [fee_global_tao_query_sk , fee_global_alpha_query_sk , sqrt_price_query_sk ],
1517
+ block_hash = block_hash )
1518
+
1519
+ fee_global_tao = fixed_to_float (fee_global_tao_query [1 ])
1520
+ fee_global_alpha = fixed_to_float (fee_global_alpha_query [1 ])
1521
+ sqrt_price = fixed_to_float (sqrt_price_query [1 ])
1520
1522
current_tick = price_to_tick (sqrt_price ** 2 )
1521
1523
1522
1524
# Fetch positions
@@ -1526,26 +1528,36 @@ def get_liquidity_list(
1526
1528
block = block ,
1527
1529
params = [netuid , wallet .coldkeypub .ss58_address ],
1528
1530
)
1529
-
1530
- positions = []
1531
+ positions_values : list [ tuple [ dict , int , int ]] = []
1532
+ positions_storage_keys : list [ StorageKey ] = []
1531
1533
for _ , p in positions_response :
1532
1534
position = p .value
1533
1535
1534
1536
tick_low_idx = position ["tick_low" ][0 ]
1535
1537
tick_high_idx = position ["tick_high" ][0 ]
1536
1538
1537
- tick_low = query (
1538
- module = "Swap" ,
1539
+ tick_low_sk = self . substrate . create_storage_key (
1540
+ pallet = "Swap" ,
1539
1541
storage_function = "Ticks" ,
1540
1542
params = [netuid , tick_low_idx ],
1541
1543
block_hash = block_hash ,
1542
1544
)
1543
- tick_high = query (
1544
- module = "Swap" ,
1545
+ tick_high_sk = self . substrate . create_storage_key (
1546
+ pallet = "Swap" ,
1545
1547
storage_function = "Ticks" ,
1546
1548
params = [netuid , tick_high_idx ],
1547
- block_hash = block_hash ,
1549
+ block_hash = block_hash
1548
1550
)
1551
+ positions_values .append ((position , tick_low_idx , tick_high_idx ))
1552
+ positions_storage_keys .extend ([tick_low_sk , tick_high_sk ])
1553
+ # query all our ticks at once
1554
+ ticks_query = self .substrate .query_multi (positions_storage_keys , block_hash = block_hash )
1555
+ # iterator with just the values
1556
+ ticks = iter ([x [1 ] for x in ticks_query ])
1557
+ positions = []
1558
+ for position , tick_low_idx , tick_high_idx in positions_values :
1559
+ tick_low = next (ticks )
1560
+ tick_high = next (ticks )
1549
1561
1550
1562
# Calculate fees above/below range for both tokens
1551
1563
tao_below = get_fees (
0 commit comments