burntensor / app.py
pawkanarek's picture
add burnttensor app
ac6bb7e
raw
history blame
2.87 kB
import bittensor as bt
from substrateinterface import Keypair
import gradio as gr
import pandas as pd
def get_incentive_percent_for_key(key, sn, incentive, substrate) -> tuple[float, int]:
uid = substrate.query('SubtensorModule', 'Uids', [sn, key])
if uid and uid.value is not None:
owner_incentive = int(incentive[uid.value])
if owner_incentive > 0:
return (owner_incentive / 65535) * 100, uid.value
return -1, -1
def fetch_incentive_data() -> pd.DataFrame:
print("Starting data fetch...")
data = []
subtensor = bt.subtensor(network="finney")
substrate = subtensor.substrate
for sn in range(128):
incentive = substrate.query("SubtensorModule", "Incentive", [sn])
owner_ck = substrate.query('SubtensorModule', 'SubnetOwner', [sn])
assert incentive, "WTF"
assert owner_ck, "WTF"
sn_link = f"[{sn}](https://taostats.io/subnets/{sn})"
ck_incentive, ck_uid = get_incentive_percent_for_key(owner_ck, sn, incentive, substrate)
if ck_incentive > 0:
print(f"Found incentive for SN {sn} owner coldkey.")
address_link = f"[{owner_ck}](https://taostats.io/coldkey/{owner_ck})"
data.append([sn_link, f"{ck_incentive:.2f}%", ck_uid, "Coldkey", address_link])
continue
owner_hks = substrate.query("SubtensorModule", "OwnedHotkeys", [owner_ck])
if owner_hks and owner_hks.value:
for byte_array in owner_hks.value:
owner_hk = Keypair(public_key=bytes(byte_array[0]), ss58_format=42).ss58_address
hk_incentive, hk_uid = get_incentive_percent_for_key(owner_hk, sn, incentive, substrate)
if hk_incentive > 0:
print(f"Found incentive for SN {sn} owner hotkey.")
address_link = f"[{owner_hk}](https://taostats.io/hotkey/{owner_hk})"
data.append([sn_link, f"{hk_incentive:.2f}%", hk_uid, "Hotkey", address_link])
break
df = pd.DataFrame(data, columns=["Subnet", "Incentive", "UID", "Key Type", "Address"]) #type: ignore
return df
with gr.Blocks(title="Bittensor Subnet Incentives") as demo:
gr.Markdown(
"""
# Bittensor Subnet Burn Dashboard
This dashboard displays the burn percentage set by subnet owners for miners.
Click the 'Refresh' button to fetch the latest data.
"""
)
refresh_button = gr.Button("Refresh Data")
output_df = gr.DataFrame(
headers=["Subnet", "Burn", "UID", "Key", "Address"],
datatype=["markdown", "str", "number", "str", "markdown"],
label="Subnet Incentive Data",
interactive=False,
row_count=(60, "dynamic"),
col_count=(5, "fixed")
)
demo.load(fetch_incentive_data, None, output_df)
demo.launch()