File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,39 @@ impl<T: Config> Pallet<T> {
86
86
finalized_stake
87
87
}
88
88
89
+ /// Calculates the total stake for a hotkey across all subnets.
90
+ ///
91
+ /// This function iterates through all subnets and accumulates the stake
92
+ /// for the given hotkey on each subnet.
93
+ ///
94
+ /// # Arguments
95
+ ///
96
+ /// * `hotkey` - The AccountId of the hotkey to calculate the total stake for.
97
+ ///
98
+ /// # Returns
99
+ ///
100
+ /// * `u64` - The total stake for the hotkey across all subnets.
101
+ ///
102
+
103
+ pub fn get_total_stake_for_hotkey_on_subnets ( hotkey : & T :: AccountId ) -> u64 {
104
+ // Get the list of all subnets
105
+ let subnet_list: Vec < u16 > = Self :: get_all_subnet_netuids ( ) ;
106
+
107
+ // Initialize the total stake
108
+ let mut total_stake: u64 = 0 ;
109
+
110
+ // Iterate through all subnets and accumulate the stake
111
+ for netuid in subnet_list {
112
+ // Get the stake for the hotkey on this subnet
113
+ let subnet_stake: u64 = Self :: get_stake_for_hotkey_on_subnet ( hotkey, netuid) ;
114
+
115
+ // Add the subnet stake to the total stake using saturating addition
116
+ total_stake = total_stake. saturating_add ( subnet_stake) ;
117
+ }
118
+
119
+ // Return the total stake
120
+ total_stake
121
+ }
89
122
/// Calculates reward consensus and returns the emissions for uids/hotkeys in a given `netuid`.
90
123
/// (Dense version used only for testing purposes.)
91
124
#[ allow( clippy:: indexing_slicing) ]
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ impl<T: Config> Pallet<T> {
60
60
let owner = Self :: get_owning_coldkey_for_hotkey ( & delegate. clone ( ) ) ;
61
61
let take: Compact < u16 > = <Delegates < T > >:: get ( delegate. clone ( ) ) . into ( ) ;
62
62
63
- let total_stake: U64F64 = Self :: get_total_stake_for_hotkey ( & delegate. clone ( ) ) . into ( ) ;
63
+ let total_stake: U64F64 = Self :: get_total_stake_for_hotkey_on_subnets ( & delegate. clone ( ) ) . into ( ) ;
64
64
65
65
let return_per_1000: U64F64 = if total_stake > U64F64 :: from_num ( 0 ) {
66
66
emissions_per_day
You can’t perform that action at this time.
0 commit comments