@@ -69,19 +69,21 @@ impl<T: Config> Pallet<T> {
6969 if price_i < tao_in_ratio {
7070 tao_in_i = price_i. saturating_mul ( U96F32 :: saturating_from_num ( block_emission) ) ;
7171 alpha_in_i = block_emission;
72- let difference_tao: U96F32 = default_tao_in_i. saturating_sub ( tao_in_i) ;
72+ let difference_tao: TaoCurrency =
73+ tou64 ! ( default_tao_in_i. saturating_sub( tao_in_i) ) . into ( ) ;
74+ TotalIssuance :: < T > :: mutate ( |total| {
75+ * total = total. saturating_add ( difference_tao) ;
76+ } ) ;
7377 // Difference becomes buy.
7478 let buy_swap_result = Self :: swap_tao_for_alpha (
7579 * netuid_i,
76- tou64 ! ( difference_tao) . into ( ) ,
80+ difference_tao,
7781 T :: SwapInterface :: max_price ( ) ,
7882 true ,
7983 ) ;
8084 if let Ok ( buy_swap_result_ok) = buy_swap_result {
8185 let bought_alpha = AlphaCurrency :: from ( buy_swap_result_ok. amount_paid_out ) ;
82- SubnetAlphaOut :: < T > :: mutate ( * netuid_i, |total| {
83- * total = total. saturating_sub ( bought_alpha) ;
84- } ) ;
86+ Self :: recycle_subnet_alpha ( * netuid_i, bought_alpha) ;
8587 }
8688 is_subsidized. insert ( * netuid_i, true ) ;
8789 } else {
@@ -106,6 +108,7 @@ impl<T: Config> Pallet<T> {
106108 alpha_in. insert ( * netuid_i, alpha_in_i) ;
107109 alpha_out. insert ( * netuid_i, alpha_out_i) ;
108110 }
111+ log:: debug!( "is_subsidized: {is_subsidized:?}" ) ;
109112 log:: debug!( "tao_in: {tao_in:?}" ) ;
110113 log:: debug!( "alpha_in: {alpha_in:?}" ) ;
111114 log:: debug!( "alpha_out: {alpha_out:?}" ) ;
@@ -189,21 +192,23 @@ impl<T: Config> Pallet<T> {
189192 . unwrap_or ( asfloat ! ( 0.0 ) ) ;
190193 log:: debug!( "root_proportion: {root_proportion:?}" ) ;
191194 // Get root proportion of alpha_out dividends.
192- let root_alpha: U96F32 = root_proportion
193- . saturating_mul ( alpha_out_i) // Total alpha emission per block remaining.
194- . saturating_mul ( asfloat ! ( 0.5 ) ) ; // 50% to validators.
195- // Remove root alpha from alpha_out.
196- log:: debug!( "root_alpha: {root_alpha:?}" ) ;
197- // Get pending alpha as original alpha_out - root_alpha.
198- let pending_alpha: U96F32 = alpha_out_i. saturating_sub ( root_alpha) ;
199- log:: debug!( "pending_alpha: {pending_alpha:?}" ) ;
200-
195+ let mut root_alpha: U96F32 = asfloat ! ( 0.0 ) ;
201196 let subsidized: bool = * is_subsidized. get ( netuid_i) . unwrap_or ( & false ) ;
202197 if !subsidized {
198+ // Only give root alpha if not being subsidized.
199+ root_alpha = root_proportion
200+ . saturating_mul ( alpha_out_i) // Total alpha emission per block remaining.
201+ . saturating_mul ( asfloat ! ( 0.5 ) ) ; // 50% to validators.
203202 PendingRootAlphaDivs :: < T > :: mutate ( * netuid_i, |total| {
204203 * total = total. saturating_add ( tou64 ! ( root_alpha) . into ( ) ) ;
205204 } ) ;
206205 }
206+ // Remove root alpha from alpha_out.
207+ log:: debug!( "root_alpha: {root_alpha:?}" ) ;
208+
209+ // Get pending alpha as original alpha_out - root_alpha.
210+ let pending_alpha: U96F32 = alpha_out_i. saturating_sub ( root_alpha) ;
211+ log:: debug!( "pending_alpha: {pending_alpha:?}" ) ;
207212
208213 // Accumulate alpha emission in pending.
209214 PendingEmission :: < T > :: mutate ( * netuid_i, |total| {
@@ -246,7 +251,13 @@ impl<T: Config> Pallet<T> {
246251 PendingOwnerCut :: < T > :: insert ( netuid, AlphaCurrency :: ZERO ) ;
247252
248253 // Drain pending root alpha divs, alpha emission, and owner cut.
249- Self :: drain_pending_emission ( netuid, pending_alpha, pending_root_alpha, owner_cut) ;
254+ Self :: drain_pending_emission (
255+ netuid,
256+ pending_alpha,
257+ pending_root_alpha,
258+ pending_alpha. saturating_add ( pending_root_alpha) ,
259+ owner_cut,
260+ ) ;
250261 } else {
251262 // Increment
252263 BlocksSinceLastStep :: < T > :: mutate ( netuid, |total| * total = total. saturating_add ( 1 ) ) ;
@@ -482,6 +493,7 @@ impl<T: Config> Pallet<T> {
482493 let destination = maybe_dest. clone ( ) . unwrap_or ( hotkey. clone ( ) ) ;
483494
484495 if let Some ( dest) = maybe_dest {
496+ log:: debug!( "incentives: auto staking {incentive:?} to {dest:?}" ) ;
485497 Self :: deposit_event ( Event :: < T > :: AutoStakeAdded {
486498 netuid,
487499 destination : dest,
@@ -490,6 +502,9 @@ impl<T: Config> Pallet<T> {
490502 incentive,
491503 } ) ;
492504 }
505+ log:: debug!(
506+ "incentives: increasing stake for {hotkey:?} to {incentive:?} with owner {owner:?}"
507+ ) ;
493508 Self :: increase_stake_for_hotkey_and_coldkey_on_subnet (
494509 & destination,
495510 & owner,
@@ -604,6 +619,7 @@ impl<T: Config> Pallet<T> {
604619 netuid : NetUid ,
605620 pending_alpha : AlphaCurrency ,
606621 pending_root_alpha : AlphaCurrency ,
622+ total_alpha : AlphaCurrency ,
607623 owner_cut : AlphaCurrency ,
608624 ) {
609625 log:: debug!(
@@ -614,7 +630,7 @@ impl<T: Config> Pallet<T> {
614630
615631 // Run the epoch.
616632 let hotkey_emission: Vec < ( T :: AccountId , AlphaCurrency , AlphaCurrency ) > =
617- Self :: epoch_with_mechanisms ( netuid, pending_alpha . saturating_add ( pending_root_alpha ) ) ;
633+ Self :: epoch_with_mechanisms ( netuid, total_alpha ) ;
618634 log:: debug!( "hotkey_emission: {hotkey_emission:?}" ) ;
619635
620636 // Compute the pending validator alpha.
@@ -630,8 +646,7 @@ impl<T: Config> Pallet<T> {
630646 log:: debug!( "incentive_sum: {incentive_sum:?}" ) ;
631647
632648 let pending_validator_alpha = if !incentive_sum. is_zero ( ) {
633- pending_alpha
634- . saturating_add ( pending_root_alpha)
649+ total_alpha
635650 . saturating_div ( 2 . into ( ) )
636651 . saturating_sub ( pending_root_alpha)
637652 } else {
0 commit comments