bittensor-cli 9.7.1__py3-none-any.whl → 9.8.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -531,6 +531,33 @@ class SubtensorInterface:
531
531
  res.append(record[0])
532
532
  return res
533
533
 
534
+ async def is_subnet_active(
535
+ self,
536
+ netuid: int,
537
+ block_hash: Optional[str] = None,
538
+ reuse_block: bool = False,
539
+ ) -> bool:
540
+ """Verify if subnet with provided netuid is active.
541
+
542
+ Args:
543
+ netuid (int): The unique identifier of the subnet.
544
+ block_hash (Optional[str]): The blockchain block_hash representation of block id.
545
+ reuse_block (bool): Whether to reuse the last-used block hash.
546
+
547
+ Returns:
548
+ True if subnet is active, False otherwise.
549
+
550
+ This means whether the `start_call` was initiated or not.
551
+ """
552
+ query = await self.substrate.query(
553
+ module="SubtensorModule",
554
+ storage_function="FirstEmissionBlockNumber",
555
+ block_hash=block_hash,
556
+ reuse_block_hash=reuse_block,
557
+ params=[netuid],
558
+ )
559
+ return True if query and query.value > 0 else False
560
+
534
561
  async def subnet_exists(
535
562
  self, netuid: int, block_hash: Optional[str] = None, reuse_block: bool = False
536
563
  ) -> bool:
@@ -1128,22 +1155,13 @@ class SubtensorInterface:
1128
1155
  Understanding the hyperparameters is crucial for comprehending how subnets are configured and
1129
1156
  managed, and how they interact with the network's consensus and incentive mechanisms.
1130
1157
  """
1131
- main_result, yuma3_result, sigmoid_steepness = await asyncio.gather(
1132
- self.query_runtime_api(
1133
- runtime_api="SubnetInfoRuntimeApi",
1134
- method="get_subnet_hyperparams",
1135
- params=[netuid],
1136
- block_hash=block_hash,
1137
- ),
1138
- self.query("SubtensorModule", "Yuma3On", [netuid]),
1139
- self.query("SubtensorModule", "AlphaSigmoidSteepness", [netuid]),
1158
+ result = await self.query_runtime_api(
1159
+ runtime_api="SubnetInfoRuntimeApi",
1160
+ method="get_subnet_hyperparams_v2",
1161
+ params=[netuid],
1162
+ block_hash=block_hash,
1140
1163
  )
1141
- result = {
1142
- **main_result,
1143
- **{"yuma3_enabled": yuma3_result},
1144
- **{"alpha_sigmoid_steepness": sigmoid_steepness},
1145
- }
1146
- if not main_result:
1164
+ if not result:
1147
1165
  return []
1148
1166
 
1149
1167
  return SubnetHyperparameters.from_any(result)
@@ -1405,23 +1423,40 @@ class SubtensorInterface:
1405
1423
  return stake_info_map if stake_info_map else None
1406
1424
 
1407
1425
  async def all_subnets(self, block_hash: Optional[str] = None) -> list[DynamicInfo]:
1408
- result = await self.query_runtime_api(
1409
- "SubnetInfoRuntimeApi",
1410
- "get_all_dynamic_info",
1411
- block_hash=block_hash,
1426
+ result, prices = await asyncio.gather(
1427
+ self.query_runtime_api(
1428
+ "SubnetInfoRuntimeApi",
1429
+ "get_all_dynamic_info",
1430
+ block_hash=block_hash,
1431
+ ),
1432
+ self.get_subnet_prices(block_hash=block_hash, page_size=129),
1412
1433
  )
1413
- return DynamicInfo.list_from_any(result)
1434
+ sns: list[DynamicInfo] = DynamicInfo.list_from_any(result)
1435
+ for sn in sns:
1436
+ if sn.netuid == 0:
1437
+ sn.price = Balance.from_tao(1.0)
1438
+ else:
1439
+ try:
1440
+ sn.price = prices[sn.netuid]
1441
+ except KeyError:
1442
+ sn.price = sn.tao_in / sn.alpha_in
1443
+ return sns
1414
1444
 
1415
1445
  async def subnet(
1416
1446
  self, netuid: int, block_hash: Optional[str] = None
1417
1447
  ) -> "DynamicInfo":
1418
- result = await self.query_runtime_api(
1419
- "SubnetInfoRuntimeApi",
1420
- "get_dynamic_info",
1421
- params=[netuid],
1422
- block_hash=block_hash,
1448
+ result, price = await asyncio.gather(
1449
+ self.query_runtime_api(
1450
+ "SubnetInfoRuntimeApi",
1451
+ "get_dynamic_info",
1452
+ params=[netuid],
1453
+ block_hash=block_hash,
1454
+ ),
1455
+ self.get_subnet_price(netuid=netuid, block_hash=block_hash),
1423
1456
  )
1424
- return DynamicInfo.from_any(result)
1457
+ subnet_ = DynamicInfo.from_any(result)
1458
+ subnet_.price = price
1459
+ return subnet_
1425
1460
 
1426
1461
  async def get_owned_hotkeys(
1427
1462
  self,
@@ -1563,3 +1598,53 @@ class SubtensorInterface:
1563
1598
  )
1564
1599
 
1565
1600
  return result
1601
+
1602
+ async def get_subnet_price(
1603
+ self,
1604
+ netuid: int = None,
1605
+ block_hash: Optional[str] = None,
1606
+ ) -> Balance:
1607
+ """
1608
+ Gets the current Alpha price in TAO for a specific subnet.
1609
+
1610
+ :param netuid: The unique identifier of the subnet.
1611
+ :param block_hash: The hash of the block to retrieve the price from.
1612
+
1613
+ :return: The current Alpha price in TAO units for the specified subnet.
1614
+ """
1615
+ current_sqrt_price = await self.query(
1616
+ module="Swap",
1617
+ storage_function="AlphaSqrtPrice",
1618
+ params=[netuid],
1619
+ block_hash=block_hash,
1620
+ )
1621
+
1622
+ current_sqrt_price = fixed_to_float(current_sqrt_price)
1623
+ current_price = current_sqrt_price * current_sqrt_price
1624
+ return Balance.from_rao(int(current_price * 1e9))
1625
+
1626
+ async def get_subnet_prices(
1627
+ self, block_hash: Optional[str] = None, page_size: int = 100
1628
+ ) -> dict[int, Balance]:
1629
+ """
1630
+ Gets the current Alpha prices in TAO for all subnets.
1631
+
1632
+ :param block_hash: The hash of the block to retrieve prices from.
1633
+ :param page_size: The page size for batch queries (default: 100).
1634
+
1635
+ :return: A dictionary mapping netuid to the current Alpha price in TAO units.
1636
+ """
1637
+ query = await self.substrate.query_map(
1638
+ module="Swap",
1639
+ storage_function="AlphaSqrtPrice",
1640
+ page_size=page_size,
1641
+ block_hash=block_hash,
1642
+ )
1643
+
1644
+ map_ = {}
1645
+ async for netuid_, current_sqrt_price in query:
1646
+ current_sqrt_price_ = fixed_to_float(current_sqrt_price.value)
1647
+ current_price = current_sqrt_price_**2
1648
+ map_[netuid_] = Balance.from_rao(int(current_price * 1e9))
1649
+
1650
+ return map_
@@ -1177,6 +1177,7 @@ def prompt_for_subnet_identity(
1177
1177
  subnet_url: Optional[str],
1178
1178
  discord: Optional[str],
1179
1179
  description: Optional[str],
1180
+ logo_url: Optional[str],
1180
1181
  additional: Optional[str],
1181
1182
  ):
1182
1183
  """
@@ -1237,6 +1238,13 @@ def prompt_for_subnet_identity(
1237
1238
  lambda x: x and len(x.encode("utf-8")) > 1024,
1238
1239
  "[red]Error:[/red] Description must be <= 1024 bytes.",
1239
1240
  ),
1241
+ (
1242
+ "logo_url",
1243
+ "[blue]Logo URL [dim](optional)[/blue]",
1244
+ logo_url,
1245
+ lambda x: x and len(x.encode("utf-8")) > 1024,
1246
+ "[red]Error:[/red] Logo URL must be <= 1024 bytes.",
1247
+ ),
1240
1248
  (
1241
1249
  "additional",
1242
1250
  "[blue]Additional information [dim](optional)[/blue]",
@@ -1371,6 +1379,7 @@ def unlock_key(
1371
1379
  err_msg = f"The password used to decrypt your {unlock_type.capitalize()}key Keyfile is invalid."
1372
1380
  if print_out:
1373
1381
  err_console.print(f":cross_mark: [red]{err_msg}[/red]")
1382
+ return unlock_key(wallet, unlock_type, print_out)
1374
1383
  return UnlockStatus(False, err_msg)
1375
1384
  except KeyFileError:
1376
1385
  err_msg = f"{unlock_type.capitalize()}key Keyfile is corrupt, non-writable, or non-readable, or non-existent."
File without changes