@@ -66,30 +66,20 @@ impl<T: Config> Pallet<T> {
6666 BlocksSinceLastStep :: < T > :: insert ( netuid, 0 ) ;
6767 LastMechansimStepBlock :: < T > :: insert ( netuid, current_block) ;
6868
69- // Get and drain the subnet pending emission.
70- let pending_alpha = PendingEmission :: < T > :: get ( netuid) ;
71- PendingEmission :: < T > :: insert ( netuid, AlphaCurrency :: ZERO ) ;
72-
73- // Get and drain the subnet pending root divs.
74- let pending_tao = PendingRootDivs :: < T > :: get ( netuid) ;
75- PendingRootDivs :: < T > :: insert ( netuid, TaoCurrency :: ZERO ) ;
76-
77- // Get this amount as alpha that was swapped for pending root divs.
78- let pending_swapped = PendingAlphaSwapped :: < T > :: get ( netuid) ;
79- PendingAlphaSwapped :: < T > :: insert ( netuid, AlphaCurrency :: ZERO ) ;
80-
81- // Get owner cut and drain.
82- let owner_cut = PendingOwnerCut :: < T > :: get ( netuid) ;
83- PendingOwnerCut :: < T > :: insert ( netuid, AlphaCurrency :: ZERO ) ;
84-
8569 // Drain pending root divs, alpha emission, and owner cut.
8670 Self :: drain_pending_emission (
8771 netuid,
88- pending_alpha ,
89- pending_tao ,
90- pending_swapped ,
91- owner_cut ,
72+ PendingEmission :: < T > :: get ( netuid ) ,
73+ PendingRootDivs :: < T > :: get ( netuid ) ,
74+ PendingAlphaSwapped :: < T > :: get ( netuid ) ,
75+ PendingOwnerCut :: < T > :: get ( netuid ) ,
9276 ) ;
77+
78+ // Drain pending values.
79+ PendingEmission :: < T > :: insert ( netuid, AlphaCurrency :: ZERO ) ;
80+ PendingRootDivs :: < T > :: insert ( netuid, TaoCurrency :: ZERO ) ;
81+ PendingAlphaSwapped :: < T > :: insert ( netuid, AlphaCurrency :: ZERO ) ;
82+ PendingOwnerCut :: < T > :: insert ( netuid, AlphaCurrency :: ZERO ) ;
9383 } else {
9484 // Increment
9585 BlocksSinceLastStep :: < T > :: mutate ( netuid, |total| * total = total. saturating_add ( 1 ) ) ;
@@ -151,6 +141,7 @@ impl<T: Config> Pallet<T> {
151141 // Adjust protocol liquidity based on new reserves
152142 T :: SwapInterface :: adjust_protocol_liquidity ( netuid, tao_in_currency, alpha_in_currency) ;
153143
144+ // If registration is not allowed, alpha out is zero. no need to distribute it.
154145 if allow_registration {
155146 Self :: split_alpha_out ( netuid, alpha_out_value, is_subsidized) ;
156147 }
@@ -160,30 +151,34 @@ impl<T: Config> Pallet<T> {
160151 Self :: update_moving_price ( netuid) ;
161152 }
162153
154+ /// Splits the alpha output for a subnet into owner cuts and root dividends.
155+ ///
156+ /// # Arguments
157+ /// * `netuid` - The subnet ID to split alpha for
158+ /// * `alpha_out_value` - The total alpha output value to split
159+ /// * `is_subsidized` - Whether the subnet is subsidized
160+ ///
161+ /// This function:
162+ /// 1. Takes a cut of alpha for the subnet owner based on owner_cut percentage
163+ /// 2. Calculates root dividends based on TAO weight and alpha issuance
164+ /// 3. Splits remaining alpha between root validators and subnet
163165 pub fn split_alpha_out ( netuid : NetUid , alpha_out_value : U96F32 , is_subsidized : bool ) {
164166 let mut alpha_out_value = alpha_out_value;
165167 let cut_percent: U96F32 = Self :: get_float_subnet_owner_cut ( ) ;
166- let mut owner_cuts: BTreeMap < NetUid , U96F32 > = BTreeMap :: new ( ) ;
167-
168- // Get alpha out.
169- let alpha_out_for_cut: U96F32 = alpha_out_value;
170- log:: debug!( "alpha_out_for_cut as {alpha_out_for_cut:?} in subnet {netuid:?}" ) ;
171168
172169 // Calculate the owner cut.
173- let owner_cut: U96F32 = alpha_out_for_cut . saturating_mul ( cut_percent) ;
170+ let owner_cut: U96F32 = alpha_out_value . saturating_mul ( cut_percent) ;
174171 log:: debug!( "owner_cut as {owner_cut:?} in subnet {netuid:?}" ) ;
175172
176- // Save owner cut.
177- * owner_cuts. entry ( netuid) . or_insert ( asfloat ! ( 0 ) ) = owner_cut;
178-
179- // Save new alpha_out.
180- alpha_out_value = alpha_out_for_cut. saturating_sub ( owner_cut) ;
181-
182173 // Accumulate the owner cut in pending.
183174 PendingOwnerCut :: < T > :: mutate ( netuid, |total| {
184175 * total = total. saturating_add ( tou64 ! ( owner_cut) . into ( ) ) ;
185176 } ) ;
186177
178+ // Update alpha_out after owner cut.
179+ alpha_out_value = alpha_out_value. saturating_sub ( owner_cut) ;
180+ log:: debug!( "alpha_out_value as {alpha_out_value:?} after owner cut in subnet {netuid:?}" ) ;
181+
187182 // Get total TAO on root.
188183 let root_tao: U96F32 = asfloat ! ( SubnetTAO :: <T >:: get( NetUid :: ROOT ) ) ;
189184 log:: debug!( "root_tao as {root_tao:?} in subnet {netuid:?}" ) ;
@@ -192,13 +187,6 @@ impl<T: Config> Pallet<T> {
192187 let tao_weight: U96F32 = root_tao. saturating_mul ( Self :: get_tao_weight ( ) ) ;
193188 log:: debug!( "tao_weight as {tao_weight:?} in subnet {netuid:?}" ) ;
194189
195- // --- 6. Seperate out root dividends in alpha and sell them into tao.
196- // Then accumulate those dividends for later.
197-
198- // Get remaining alpha out.
199- let alpha_out_remaining: U96F32 = alpha_out_value;
200- log:: debug!( "alpha_out_remaining as {alpha_out_remaining:?} in subnet {netuid:?}" ) ;
201-
202190 // Get total ALPHA on subnet.
203191 let alpha_issuance: U96F32 = asfloat ! ( Self :: get_alpha_issuance( netuid) ) ;
204192 log:: debug!( "alpha_issuance as {alpha_issuance:?} in subnet {netuid:?}" ) ;
@@ -211,12 +199,12 @@ impl<T: Config> Pallet<T> {
211199
212200 // Get root proportion of alpha_out dividends.
213201 let root_alpha: U96F32 = root_proportion
214- . saturating_mul ( alpha_out_remaining ) // Total alpha emission per block remaining.
202+ . saturating_mul ( alpha_out_value ) // Total alpha emission per block remaining.
215203 . saturating_mul ( asfloat ! ( 0.5 ) ) ; // 50% to validators.
216204 log:: debug!( "root_alpha as {root_alpha:?} in subnet {netuid:?}" ) ;
217205
218206 // Get pending alpha as original alpha_out - root_alpha.
219- let pending_alpha: U96F32 = alpha_out_remaining . saturating_sub ( root_alpha) ;
207+ let pending_alpha: U96F32 = alpha_out_value . saturating_sub ( root_alpha) ;
220208 log:: debug!( "pending_alpha as {pending_alpha:?} in subnet {netuid:?}" ) ;
221209
222210 // Sell root emission through the pool (do not pay fees)
0 commit comments