@@ -379,6 +379,69 @@ impl<T: Config> Pallet<T> {
379
379
TotalHotkeyAlpha :: < T > :: get ( hotkey, netuid)
380
380
}
381
381
382
+ /// Retrieves the total stake (alpha) for a given coldkey on a specific sunbet.
383
+ ///
384
+ /// This function performs the following steps:
385
+ /// 1. Retrieves the list of hotkeys associated with the coldkey on the subnet.
386
+ /// 2. Iterates through the list of hotkeys and retrieves the alpha stake for each hotkey.
387
+ /// 3. Sums the alpha stakes for all hotkeys to calculate the total stake for the coldkey.
388
+ /// 4. Returns the total alpha stake for the coldkey on the subnet.
389
+ ///
390
+ /// # Arguments
391
+ /// * `coldkey` - The account ID of the coldkey.
392
+ /// * `netuid` - The unique identifier of the subnet.
393
+ ///
394
+ /// # Returns
395
+ /// * `u64` - The total alpha value for the coldkey on the specified subnet.
396
+ ///
397
+ /// # Note
398
+ /// This function returns the cumulative stake across all hotkeys associated with this coldkey on the subnet.
399
+ /// This value represents the sum of stakes from all hotkeys associated with this coldkey.
400
+ pub fn get_stake_for_coldkey_on_subnet ( coldkey : & T :: AccountId , netuid : u16 ) -> u64 {
401
+ // Retrieve the list of hotkeys associated with the coldkey on the subnet.
402
+ let hotkeys: Vec < T :: AccountId > = StakingHotkeys :: < T > :: get ( coldkey) ;
403
+
404
+ // Calculate the total alpha stake for the coldkey on the subnet.
405
+ let total_stake: u64 = hotkeys
406
+ . iter ( )
407
+ . map ( |hotkey| Self :: get_stake_for_hotkey_on_subnet ( hotkey, netuid) )
408
+ . sum ( ) ;
409
+
410
+ // Return the total alpha stake for the coldkey on the subnet.
411
+ total_stake
412
+ }
413
+
414
+ /// Retrieves the total stake (alpha) for a given coldkey across all subnets
415
+ ///
416
+ /// This function performs the following steps:
417
+ /// 1. Retrieves the list of subnets associated with the coldkey.
418
+ /// 2. Iterates through the list of subnets and retrieves the alpha stake for each subnet.
419
+ /// 3. Sums the alpha stakes for all subnets to calculate the total stake for the coldkey.
420
+ /// 4. Returns the total alpha stake for the coldkey across all subnets.
421
+ ///
422
+ /// # Arguments
423
+ /// * `coldkey` - The account ID of the coldkey.
424
+ ///
425
+ /// # Returns
426
+ /// * `u64` - The total alpha value for the coldkey across all subnets.
427
+ ///
428
+ /// # Note
429
+ /// This function returns the cumulative stake across all subnets for the coldkey.
430
+ /// This value represents the sum of stakes from all subnets associated with this coldkey.
431
+ /// This function is useful for calculating the total stake for a coldkey across all subnets.
432
+ pub fn get_stake_for_coldkey ( coldkey : & T :: AccountId ) -> u64 {
433
+ // get number of subnets
434
+ let netuids = Self :: get_all_subnet_netuids ( ) ;
435
+
436
+ // Calculate the total alpha stake for the coldkey across all subnets.
437
+ let total_stake: u64 = netuids
438
+ . iter ( )
439
+ . map ( |netuid| Self :: get_stake_for_coldkey_on_subnet ( coldkey, * netuid) )
440
+ . sum ( ) ;
441
+ // Return the total alpha stake for the coldkey across all subnets.
442
+ total_stake
443
+ }
444
+
382
445
/// Increase hotkey stake on a subnet.
383
446
///
384
447
/// The function updates share totals given current prices.
0 commit comments