Spaces:
Running
Running
Commit
·
ac6bb7e
1
Parent(s):
b0550a5
add burnttensor app
Browse files- app.py +71 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import bittensor as bt
|
| 2 |
+
from substrateinterface import Keypair
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def get_incentive_percent_for_key(key, sn, incentive, substrate) -> tuple[float, int]:
|
| 8 |
+
uid = substrate.query('SubtensorModule', 'Uids', [sn, key])
|
| 9 |
+
if uid and uid.value is not None:
|
| 10 |
+
owner_incentive = int(incentive[uid.value])
|
| 11 |
+
if owner_incentive > 0:
|
| 12 |
+
return (owner_incentive / 65535) * 100, uid.value
|
| 13 |
+
return -1, -1
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def fetch_incentive_data() -> pd.DataFrame:
|
| 17 |
+
print("Starting data fetch...")
|
| 18 |
+
data = []
|
| 19 |
+
subtensor = bt.subtensor(network="finney")
|
| 20 |
+
substrate = subtensor.substrate
|
| 21 |
+
|
| 22 |
+
for sn in range(128):
|
| 23 |
+
incentive = substrate.query("SubtensorModule", "Incentive", [sn])
|
| 24 |
+
owner_ck = substrate.query('SubtensorModule', 'SubnetOwner', [sn])
|
| 25 |
+
assert incentive, "WTF"
|
| 26 |
+
assert owner_ck, "WTF"
|
| 27 |
+
sn_link = f"[{sn}](https://taostats.io/subnets/{sn})"
|
| 28 |
+
|
| 29 |
+
ck_incentive, ck_uid = get_incentive_percent_for_key(owner_ck, sn, incentive, substrate)
|
| 30 |
+
if ck_incentive > 0:
|
| 31 |
+
print(f"Found incentive for SN {sn} owner coldkey.")
|
| 32 |
+
address_link = f"[{owner_ck}](https://taostats.io/coldkey/{owner_ck})"
|
| 33 |
+
data.append([sn_link, f"{ck_incentive:.2f}%", ck_uid, "Coldkey", address_link])
|
| 34 |
+
continue
|
| 35 |
+
|
| 36 |
+
owner_hks = substrate.query("SubtensorModule", "OwnedHotkeys", [owner_ck])
|
| 37 |
+
if owner_hks and owner_hks.value:
|
| 38 |
+
for byte_array in owner_hks.value:
|
| 39 |
+
owner_hk = Keypair(public_key=bytes(byte_array[0]), ss58_format=42).ss58_address
|
| 40 |
+
hk_incentive, hk_uid = get_incentive_percent_for_key(owner_hk, sn, incentive, substrate)
|
| 41 |
+
if hk_incentive > 0:
|
| 42 |
+
print(f"Found incentive for SN {sn} owner hotkey.")
|
| 43 |
+
address_link = f"[{owner_hk}](https://taostats.io/hotkey/{owner_hk})"
|
| 44 |
+
data.append([sn_link, f"{hk_incentive:.2f}%", hk_uid, "Hotkey", address_link])
|
| 45 |
+
break
|
| 46 |
+
|
| 47 |
+
df = pd.DataFrame(data, columns=["Subnet", "Incentive", "UID", "Key Type", "Address"]) #type: ignore
|
| 48 |
+
return df
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
with gr.Blocks(title="Bittensor Subnet Incentives") as demo:
|
| 52 |
+
gr.Markdown(
|
| 53 |
+
"""
|
| 54 |
+
# Bittensor Subnet Burn Dashboard
|
| 55 |
+
This dashboard displays the burn percentage set by subnet owners for miners.
|
| 56 |
+
Click the 'Refresh' button to fetch the latest data.
|
| 57 |
+
"""
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
refresh_button = gr.Button("Refresh Data")
|
| 61 |
+
output_df = gr.DataFrame(
|
| 62 |
+
headers=["Subnet", "Burn", "UID", "Key", "Address"],
|
| 63 |
+
datatype=["markdown", "str", "number", "str", "markdown"],
|
| 64 |
+
label="Subnet Incentive Data",
|
| 65 |
+
interactive=False,
|
| 66 |
+
row_count=(60, "dynamic"),
|
| 67 |
+
col_count=(5, "fixed")
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
demo.load(fetch_incentive_data, None, output_df)
|
| 71 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
bittensor
|