Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 9 additions & 50 deletions bittensor_cli/src/commands/subnets/subnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,10 @@ async def subnets_list(

async def fetch_subnet_data():
block_hash = await subtensor.substrate.get_chain_head()
subnets_, mechanisms, block_number_, ema_flows = await asyncio.gather(
subnets_, mechanisms, block_number_ = await asyncio.gather(
subtensor.all_subnets(block_hash=block_hash),
subtensor.get_all_subnet_mechanisms(block_hash=block_hash),
subtensor.substrate.get_block_number(block_hash=block_hash),
subtensor.get_all_subnet_ema_tao_inflow(block_hash=block_hash),
)

# Sort subnets by market cap, keeping the root subnet in the first position
Expand All @@ -238,7 +237,7 @@ async def fetch_subnet_data():
reverse=True,
)
sorted_subnets = [root_subnet] + other_subnets
return sorted_subnets, block_number_, mechanisms, ema_flows
return sorted_subnets, block_number_, mechanisms

def calculate_emission_stats(
subnets_: list, block_number_: int
Expand Down Expand Up @@ -335,11 +334,6 @@ def define_table(
justify="left",
footer=f"τ {total_emissions}",
)
defined_table.add_column(
f"[bold white]Net Inflow EMA ({Balance.get_unit(0)})",
style=COLOR_PALETTE["POOLS"]["ALPHA_OUT"],
justify="left",
)
defined_table.add_column(
f"[bold white]P ({Balance.get_unit(0)}_in, {Balance.get_unit(1)}_in)",
style=COLOR_PALETTE["STAKE"]["TAO"],
Expand Down Expand Up @@ -371,7 +365,7 @@ def define_table(
return defined_table

# Non-live mode
def _create_table(subnets_, block_number_, mechanisms, ema_flows):
def _create_table(subnets_, block_number_, mechanisms):
rows = []
_, percentage_string = calculate_emission_stats(subnets_, block_number_)

Expand Down Expand Up @@ -438,18 +432,6 @@ def _create_table(subnets_, block_number_, mechanisms, ema_flows):
)
emission_cell = f"τ {emission_tao:,.4f}"

# TAO Inflow EMA cell
if netuid in ema_flows:
_, _ema_value = ema_flows[netuid]
ema_value = _ema_value.tao
ema_color, ema_sign = format_ema_flow_cell(ema_value)
ema_formatted = format_ema_tao_value(ema_value, verbose)
ema_flow_cell = (
f"[{ema_color}]{ema_sign}τ {ema_formatted}[/{ema_color}]"
)
else:
ema_flow_cell = "-"

price_cell = f"{price_value} τ/{symbol}"
alpha_out_cell = (
f"{alpha_out_value} {symbol}"
Expand All @@ -473,7 +455,6 @@ def _create_table(subnets_, block_number_, mechanisms, ema_flows):
price_cell, # Rate τ_in/α_in
market_cap_cell, # Market Cap
emission_cell, # Emission (τ)
ema_flow_cell, # TAO Flow EMA
liquidity_cell, # Liquidity (t_in, a_in)
alpha_out_cell, # Stake α_out
supply_cell, # Supply
Expand All @@ -500,7 +481,7 @@ def _create_table(subnets_, block_number_, mechanisms, ema_flows):
defined_table.add_row(*row)
return defined_table

def dict_table(subnets_, block_number_, mechanisms, ema_flows) -> dict:
def dict_table(subnets_, block_number_, mechanisms) -> dict:
subnet_rows = {}
total_tao_emitted, _ = calculate_emission_stats(subnets_, block_number_)
total_emissions = 0.0
Expand Down Expand Up @@ -530,18 +511,12 @@ def dict_table(subnets_, block_number_, mechanisms, ema_flows) -> dict:
),
"sn_tempo": (subnet.tempo if netuid != 0 else None),
}
tao_flow_ema = None
if netuid in ema_flows:
_, ema_value = ema_flows[netuid]
tao_flow_ema = ema_value.tao

subnet_rows[netuid] = {
"netuid": netuid,
"subnet_name": subnet_name,
"price": price_value,
"market_cap": market_cap,
"emission": emission_tao,
"tao_flow_ema": tao_flow_ema,
"liquidity": {"tao_in": tao_in, "alpha_in": alpha_in},
"alpha_out": alpha_out,
"supply": supply,
Expand All @@ -559,9 +534,7 @@ def dict_table(subnets_, block_number_, mechanisms, ema_flows) -> dict:
return output

# Live mode
def create_table_live(
subnets_, previous_data_, block_number_, mechanisms, ema_flows
):
def create_table_live(subnets_, previous_data_, block_number_, mechanisms):
def format_cell(
value, previous_value, unit="", unit_first=False, precision=4, millify=False
):
Expand Down Expand Up @@ -679,16 +652,10 @@ def format_liquidity_cell(
market_cap = (subnet.alpha_in.tao + subnet.alpha_out.tao) * subnet.price.tao
supply = subnet.alpha_in.tao + subnet.alpha_out.tao

ema_value = 0
if netuid in ema_flows:
_, ema_value = ema_flows[netuid]
ema_value = ema_value.tao

# Store current values for comparison
current_data[netuid] = {
"market_cap": market_cap,
"emission_tao": emission_tao,
"tao_flow_ema": ema_value,
"alpha_out": subnet.alpha_out.tao,
"tao_in": subnet.tao_in.tao,
"alpha_in": subnet.alpha_in.tao,
Expand Down Expand Up @@ -717,12 +684,6 @@ def format_liquidity_cell(
precision=4,
)

ema_flow_cell = format_cell(
ema_value,
prev.get("tao_flow_ema"),
unit="τ",
precision=6,
)
price_cell = format_cell(
subnet.price.tao,
prev.get("price"),
Expand Down Expand Up @@ -806,7 +767,6 @@ def format_liquidity_cell(
price_cell, # Rate τ_in/α_in
market_cap_cell, # Market Cap
emission_cell, # Emission (τ)
ema_flow_cell, # TAO Flow EMA
liquidity_cell, # Liquidity (t_in, a_in)
alpha_out_cell, # Stake α_out
supply_cell, # Supply
Expand Down Expand Up @@ -862,7 +822,6 @@ def format_liquidity_cell(
subnets,
block_number,
mechanisms,
ema_flows,
) = await fetch_subnet_data()

# Update block numbers
Expand All @@ -875,7 +834,7 @@ def format_liquidity_cell(
)

table, current_data = create_table_live(
subnets, previous_data, block_number, mechanisms, ema_flows
subnets, previous_data, block_number, mechanisms
)
previous_data = current_data
progress.reset(progress_task)
Expand All @@ -901,13 +860,13 @@ def format_liquidity_cell(
pass # Ctrl + C
else:
# Non-live mode
subnets, block_number, mechanisms, ema_flows = await fetch_subnet_data()
subnets, block_number, mechanisms = await fetch_subnet_data()
if json_output:
json_console.print(
json.dumps(dict_table(subnets, block_number, mechanisms, ema_flows))
json.dumps(dict_table(subnets, block_number, mechanisms))
)
else:
table = _create_table(subnets, block_number, mechanisms, ema_flows)
table = _create_table(subnets, block_number, mechanisms)
console.print(table)

return
Expand Down
Loading