Skip to content

Commit 6d65d4b

Browse files
committed
fix: use correct coldkey stake helper
1 parent 3de9c3d commit 6d65d4b

File tree

2 files changed

+2
-65
lines changed

2 files changed

+2
-65
lines changed

pallets/subtensor/src/staking/stake_utils.rs

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -379,69 +379,6 @@ impl<T: Config> Pallet<T> {
379379
TotalHotkeyAlpha::<T>::get(hotkey, netuid)
380380
}
381381

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-
445382
/// Increase hotkey stake on a subnet.
446383
///
447384
/// The function updates share totals given current prices.

runtime/src/precompiles/staking.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ impl StakingPrecompile {
122122
let coldkey: AccountId32 = Self::parse_pub_key(data)?.into();
123123

124124
// get total stake of coldkey
125-
// TODO: is using the function that was written for this purpose in the pallet the right way to go about this?
126-
let total_stake = pallet_subtensor::Pallet::<Runtime>::get_stake_for_coldkey(&coldkey);
125+
let total_stake =
126+
pallet_subtensor::Pallet::<Runtime>::get_total_stake_for_coldkey(&coldkey);
127127
// Convert to EVM decimals
128128
let stake_u256 = U256::from(total_stake);
129129
let stake_eth =

0 commit comments

Comments
 (0)