@@ -78,7 +78,7 @@ class DynamicInfo:
78
78
## Viewing subnets
79
79
Subnets evolve substantially in Dynamic TAO! Each subnet has its own currency, known as its alpha token, and an internal economy comprising a currency reserve of TAO, a reserve of its own alpha token, and a ledger of staked balances, to keep track of all of its stakers&mdash ; those who have put TAO into its reserve in exchange for alpha.
80
80
81
- ### ` all_subnets `
81
+ #### ` all_subnets `
82
82
``` python
83
83
all_subnets(
84
84
block_number: Optional[int ] = None
@@ -90,7 +90,7 @@ Description: Fetches information about all subnets at a certain block height (or
90
90
91
91
Returns: A list of DynamicInfo objects (detailed below).
92
92
93
- ### ` get_netuids `
93
+ #### ` get_netuids `
94
94
``` python
95
95
get_netuids(self , block: Optional[int ] = None ) -> list[int ]
96
96
@@ -104,7 +104,7 @@ Returns:
104
104
- ` list ` [ int] : A list of network UIDs representing each active subnet.
105
105
106
106
107
- ### ` subnet `
107
+ #### ` subnet `
108
108
``` python
109
109
subnet(
110
110
netuid: int ,
@@ -117,7 +117,7 @@ Fetches information about a single subnet identified by netuid.
117
117
Returns a DynamicInfo object describing the subnet’s current state.
118
118
119
119
120
- ### ` metagraph `
120
+ #### ` metagraph `
121
121
``` python
122
122
metagraph(
123
123
netuid: int ,
@@ -128,15 +128,15 @@ metagraph(
128
128
129
129
Returns the metagraph for a specified subnet netuid. The metagraph includes detailed data on the neurons in the subnet.
130
130
131
- ## Calculating exchange rates
131
+ ## Exchange rates
132
132
You can query the DynamicInfo object for the exchange rates between TAO and alpha tokens.
133
133
You can use ` all_subnets ` or ` subnet ` to get the DynamicInfo object.
134
134
135
135
``` python
136
136
subnet = sub.subnet(netuid = 1 )
137
137
```
138
-
139
- ### ` tao_to_alpha `
138
+ ### Calculate exhange rates
139
+ #### ` tao_to_alpha `
140
140
141
141
``` python
142
142
tao_to_alpha(self , tao: Union[Balance, float , int ]) -> Balance:
@@ -146,15 +146,15 @@ Description: Returns an 'ideal' estimate of how much Alpha a staker would receiv
146
146
Parameters:
147
147
` tao ` : Amount of TAO to stake.
148
148
149
- ### ` alpha_to_tao `
149
+ #### ` alpha_to_tao `
150
150
``` python
151
151
alpha_to_tao(self , alpha: Union[Balance, float , int ]) -> Balance:
152
152
```
153
153
Description: Returns an 'ideal' estimate of how much TAO would be yielded by unstaking at the current price, * ignoring slippage* .
154
154
Parameters:
155
155
` alpha ` : Amount of Alpha to unstake.
156
156
157
- ### ` tao_to_alpha_with_slippage `
157
+ #### ` tao_to_alpha_with_slippage `
158
158
``` python
159
159
tao_to_alpha_with_slippage(tao: Union[Balance, float , int ], percentage: bool = False ) -> Union[tuple[Balance, Balance], float ]:
160
160
```
@@ -171,7 +171,7 @@ Returns:
171
171
OR
172
172
Percentage of the slippage as a float
173
173
174
- ### ` alpha_to_tao_with_slippage `
174
+ #### ` alpha_to_tao_with_slippage `
175
175
``` python
176
176
alpha_to_tao_with_slippage(alpha: Union[Balance, float , int ], percentage: bool = False ) -> Union[tuple[Balance, Balance], float ]:
177
177
```
@@ -188,7 +188,7 @@ Returns:
188
188
OR
189
189
Percentage of the slippage as a float
190
190
191
- ### Example: Viewing exchange rates
191
+ ### Display current exchange rates
192
192
193
193
The following script displays exchange rates for a subnet alpha token, with and without slippage.
194
194
@@ -210,7 +210,7 @@ print("alpha_to_tao", subnet.alpha_to_tao(100))
210
210
211
211
## Managing stake
212
212
213
- ### ` get_stake `
213
+ #### ` get_stake `
214
214
``` python
215
215
get_stake(
216
216
hotkey_ss58: str ,
@@ -228,7 +228,7 @@ Parameters:
228
228
229
229
230
230
231
- ### ` add_stake `
231
+ #### ` add_stake `
232
232
233
233
``` python
234
234
async add_stake(
@@ -246,7 +246,7 @@ Parameters:
246
246
- netuid: Unique ID of the subnet on which you want to stake.
247
247
- tao_amount: Amount to stake, can be a float, integer, or bittensor.Balance object.
248
248
249
- ### ` unstake `
249
+ #### ` unstake `
250
250
``` python
251
251
unstake(
252
252
wallet,
@@ -266,7 +266,7 @@ Parameters:
266
266
- amount: Amount to unstake.
267
267
268
268
269
- ### ` get_balance `
269
+ #### ` get_balance `
270
270
``` python
271
271
get_balance(
272
272
address: str ,
@@ -282,13 +282,13 @@ Parameters:
282
282
- block: Optional block number at which to fetch the balance. Uses the latest block if None.
283
283
284
284
285
- ### ` get_current_block `
285
+ #### ` get_current_block `
286
286
``` python
287
287
get_current_block() -> int
288
288
289
289
```
290
290
Description: Returns the current chain block number.
291
- ### ` wait_for_block `
291
+ #### ` wait_for_block `
292
292
``` python
293
293
wait_for_block(
294
294
block: Optional[int ] = None
@@ -302,9 +302,8 @@ Update: we have added proper nonce protection allowing you to run gather operati
302
302
scatter_stake = await asyncio.gather(* [ sub.add_stake( hotkey, coldkey, netuid, amount ) for netuid in range (64 ) ] )
303
303
```
304
304
305
- ### Example: staking and unstaking
306
305
307
- #### Staking
306
+ ### Staking
308
307
The following script incrementally stakes 3 TAO into several subnets over many blocks:
309
308
310
309
``` python
@@ -360,7 +359,7 @@ netuid 5 price τ0.001784484 stake ε11.208213619
360
359
...
361
360
362
361
```
363
- #### Unstaking
362
+ ### Unstaking
364
363
365
364
The below script will reverse the effects of the above, by incrementally unstaking alpha tokens from the list of subnets to yield TAO.
366
365
@@ -418,11 +417,13 @@ netuid 5 price τ0.001785179 stake ε33.619312896
418
417
419
418
```
420
419
421
- ## Register on a subnet
420
+ ## Subnet registration
421
+
422
+ ### Register
422
423
423
424
You can register your hotkey on a subnet using the ` burned_register ` method. This is necessary for staking, mining or validating.
424
425
425
- ### ` burned_register `
426
+ #### ` burned_register `
426
427
``` python
427
428
burned_register(
428
429
wallet,
@@ -454,9 +455,9 @@ reg = sub.burned_register(wallet=wallet, netuid=3)
454
455
```
455
456
456
457
457
- ## View your registered subnets
458
+ ### View registered subnets
458
459
459
- ### ` get_netuids_for_hotkey `
460
+ #### ` get_netuids_for_hotkey `
460
461
``` python
461
462
get_netuids_for_hotkey(
462
463
hotkey: str ,
@@ -482,7 +483,7 @@ netuids = sub.get_netuids_for_hotkey(wallet.hotkey.ss58_address)
482
483
print (netuids)
483
484
```
484
485
485
- ### ` btcli wallet overview `
486
+ #### ` btcli wallet overview `
486
487
You can also use the ` btcli ` to check subnet registrations using ` btcli wallet overview ` .
487
488
This displays the registrations to subnets by hotkeys controlled by the wallet:
488
489
@@ -517,3 +518,65 @@ Subnet: 119: vidac Ⲃ
517
518
1 268.38 Ⲃ 0.0094 1.0000 0.0093 0.0094 0.0000 ρ3470929 0.0000
518
519
519
520
` ` `
521
+
522
+
523
+ # # View a hotkey's emissions
524
+
525
+ This script displays the last day' s emissions for a specified hotkey on all subnets on which the hotkey is registered.
526
+
527
+ This could be useful for a miner to see how much they' ve been extracting from the different subnets, if they' ve been mining on several.
528
+
529
+ Be aware that daily emissions can fluctuate widely. See [Emissions](../emissions.md).
530
+
531
+ ```python
532
+ from bittensor.core.async_subtensor import AsyncSubtensor
533
+ import sys
534
+ import asyncio
535
+
536
+ # This is the validator HK for Opentensor Foundation, substitute with the hotkey of the miner/validator you wish to inspect
537
+ HOTKEY = "5F4tQyWrhfGVcNhoqeiNsR6KjD4wMZ2kfhLj4oHYuyHbZAc3"
538
+
539
+ # Speicfy which subnets you wish to inspect, by UID
540
+ NETUIDS = range(0,64)
541
+ BLOCKTIME = 12
542
+
543
+ subtensor_address = "finney" # or "test" or locally with "ws://127.0.0.1:9944"
544
+
545
+ async def main():
546
+ async with AsyncSubtensor(f"{subtensor_address}") as subtensor:
547
+ all_sn_dynamic_info_list = await subtensor.all_subnets()
548
+
549
+ all_sn_dynamic_info = {info.netuid: info for info in all_sn_dynamic_info_list}
550
+ daily_blocks = (60 * 60 * 24) / BLOCKTIME # Number of blocks per day
551
+
552
+
553
+ print(f"Hotkey: {HOTKEY}")
554
+
555
+ subnets = await asyncio.gather(*[subtensor.subnet_exists(netuid) for netuid in range(1, 8)])
556
+ metagraphs = await asyncio.gather(*[ subtensor.metagraph(netuid=id) for id in NETUIDS])
557
+ for id in NETUIDS:
558
+ print(f"UID: {id}")
559
+
560
+ metagraph = metagraphs[id]
561
+ tempo_multiplier = daily_blocks / metagraph.tempo
562
+
563
+ subnet_info = all_sn_dynamic_info.get(id)
564
+
565
+ uid = metagraph.hotkeys.index(HOTKEY) if HOTKEY in metagraph.hotkeys else None
566
+
567
+ if uid is None:
568
+ print(f"Hotkey {HOTKEY} not found in the metagraph")
569
+ else:
570
+ daily_rewards_alpha = float(metagraph.emission[uid] * tempo_multiplier)
571
+ daily_rewards_tao = float(daily_rewards_alpha * subnet_info.price.tao)
572
+ alpha_to_tao_with_slippage, slippage = subnet_info.alpha_to_tao_with_slippage(
573
+ alpha=daily_rewards_alpha
574
+ )
575
+
576
+ print(f"Daily Rewards Alpha: {daily_rewards_alpha}")
577
+ print(f"Daily Rewards Tao: {daily_rewards_tao}")
578
+ print(f"Alpha to Tao with Slippage: {alpha_to_tao_with_slippage}")
579
+
580
+ asyncio.run(main())
581
+
582
+ ```
0 commit comments