|
| 1 | +use bittensor_rs::metagraph::sync_metagraph; |
| 2 | +use bittensor_rs::BittensorClient; |
| 3 | + |
| 4 | +#[tokio::main] |
| 5 | +async fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 6 | + println!("Connecting to Bittensor finney..."); |
| 7 | + |
| 8 | + let client = BittensorClient::new("wss://entrypoint-finney.opentensor.ai:443").await?; |
| 9 | + |
| 10 | + println!("Querying subnet 100 metagraph...\n"); |
| 11 | + |
| 12 | + let metagraph = sync_metagraph(&client, 100).await?; |
| 13 | + |
| 14 | + println!("Total neurons: {}", metagraph.n); |
| 15 | + println!("\nTop 30 by effective stake (alpha + root):"); |
| 16 | + println!("{:-<90}", ""); |
| 17 | + |
| 18 | + // Collect stakes |
| 19 | + let mut stakes: Vec<(u16, String, u128, u128, u128)> = metagraph.neurons |
| 20 | + .iter() |
| 21 | + .map(|(uid, neuron)| { |
| 22 | + let alpha = neuron.stake; |
| 23 | + let root = neuron.root_stake; |
| 24 | + let total = alpha.saturating_add(root); |
| 25 | + let hotkey_str = format!("{}", neuron.hotkey); |
| 26 | + (*uid as u16, hotkey_str, alpha, root, total) |
| 27 | + }) |
| 28 | + .filter(|(_, _, _, _, total)| *total > 0) |
| 29 | + .collect(); |
| 30 | + |
| 31 | + // Sort by total stake descending |
| 32 | + stakes.sort_by(|a, b| b.4.cmp(&a.4)); |
| 33 | + |
| 34 | + println!("{:<6} {:<50} {:>12} {:>12} {:>12}", "UID", "Hotkey", "Alpha", "Root", "Total TAO"); |
| 35 | + println!("{:-<90}", ""); |
| 36 | + |
| 37 | + for (uid, hotkey, alpha, root, total) in stakes.iter().take(30) { |
| 38 | + let alpha_tao = *alpha as f64 / 1_000_000_000.0; |
| 39 | + let root_tao = *root as f64 / 1_000_000_000.0; |
| 40 | + let total_tao = *total as f64 / 1_000_000_000.0; |
| 41 | + println!("{:<6} {:<50} {:>12.2} {:>12.2} {:>12.2}", |
| 42 | + uid, hotkey, alpha_tao, root_tao, total_tao); |
| 43 | + } |
| 44 | + |
| 45 | + let gte_1000 = stakes.iter().filter(|(_, _, _, _, t)| *t as f64 / 1e9 >= 1000.0).count(); |
| 46 | + let gte_100 = stakes.iter().filter(|(_, _, _, _, t)| *t as f64 / 1e9 >= 100.0).count(); |
| 47 | + let gte_10 = stakes.iter().filter(|(_, _, _, _, t)| *t as f64 / 1e9 >= 10.0).count(); |
| 48 | + let gt_0 = stakes.len(); |
| 49 | + |
| 50 | + println!("\n{:-<90}", ""); |
| 51 | + println!("Validators with >= 1000 TAO: {}", gte_1000); |
| 52 | + println!("Validators with >= 100 TAO: {}", gte_100); |
| 53 | + println!("Validators with >= 10 TAO: {}", gte_10); |
| 54 | + println!("Validators with > 0 TAO: {}", gt_0); |
| 55 | + |
| 56 | + Ok(()) |
| 57 | +} |
0 commit comments