@@ -39,22 +39,23 @@ impl<T: Config> Pallet<T> {
3939 log:: debug!( "Subnets to emit to: {subnets_to_emit_to:?}" ) ;
4040
4141 // --- 2. Get sum of tao reserves ( in a later version we will switch to prices. )
42- let mut acc_total_moving_prices = U96F32 :: saturating_from_num ( 0.0 ) ;
4342 // Only get price EMA for subnets that we emit to.
44- for netuid_i in subnets_to_emit_to. iter ( ) {
45- // Get and update the moving price of each subnet adding the total together.
46- acc_total_moving_prices =
47- acc_total_moving_prices . saturating_add ( Self :: get_moving_alpha_price ( * netuid_i ) ) ;
48- }
49- let total_moving_prices = acc_total_moving_prices ;
43+ let total_moving_prices = subnets_to_emit_to
44+ . iter ( )
45+ . map ( |netuid| Self :: get_moving_alpha_price ( * netuid ) )
46+ . fold ( U96F32 :: saturating_from_num ( 0.0 ) , |acc , ema| {
47+ acc . saturating_add ( ema )
48+ } ) ;
5049 log:: debug!( "total_moving_prices: {total_moving_prices:?}" ) ;
5150
51+ let subsidy_mode = total_moving_prices < U96F32 :: saturating_from_num ( 1.0 ) ;
52+ log:: debug!( "subsidy_mode: {subsidy_mode:?}" ) ;
53+
5254 // --- 3. Get subnet terms (tao_in, alpha_in, and alpha_out)
5355 // Computation is described in detail in the dtao whitepaper.
5456 let mut tao_in: BTreeMap < NetUid , U96F32 > = BTreeMap :: new ( ) ;
5557 let mut alpha_in: BTreeMap < NetUid , U96F32 > = BTreeMap :: new ( ) ;
5658 let mut alpha_out: BTreeMap < NetUid , U96F32 > = BTreeMap :: new ( ) ;
57- let mut is_subsidized: BTreeMap < NetUid , bool > = BTreeMap :: new ( ) ;
5859 // Only calculate for subnets that we are emitting to.
5960 for netuid_i in subnets_to_emit_to. iter ( ) {
6061 // Get subnet price.
@@ -79,11 +80,7 @@ impl<T: Config> Pallet<T> {
7980 // Get initial alpha_in
8081 let mut alpha_in_i: U96F32 ;
8182 let mut tao_in_i: U96F32 ;
82- let tao_in_ratio: U96F32 = default_tao_in_i. safe_div_or (
83- U96F32 :: saturating_from_num ( block_emission) ,
84- U96F32 :: saturating_from_num ( 0.0 ) ,
85- ) ;
86- if price_i < tao_in_ratio {
83+ if subsidy_mode {
8784 tao_in_i = price_i. saturating_mul ( U96F32 :: saturating_from_num ( block_emission) ) ;
8885 alpha_in_i = block_emission;
8986 let difference_tao: U96F32 = default_tao_in_i. saturating_sub ( tao_in_i) ;
@@ -100,11 +97,9 @@ impl<T: Config> Pallet<T> {
10097 * total = total. saturating_sub ( bought_alpha) ;
10198 } ) ;
10299 }
103- is_subsidized. insert ( * netuid_i, true ) ;
104100 } else {
105101 tao_in_i = default_tao_in_i;
106102 alpha_in_i = tao_in_i. safe_div_or ( price_i, alpha_emission_i) ;
107- is_subsidized. insert ( * netuid_i, false ) ;
108103 }
109104 log:: debug!( "alpha_in_i: {alpha_in_i:?}" ) ;
110105
@@ -215,8 +210,7 @@ impl<T: Config> Pallet<T> {
215210 let pending_alpha: U96F32 = alpha_out_i. saturating_sub ( root_alpha) ;
216211 log:: debug!( "pending_alpha: {pending_alpha:?}" ) ;
217212 // Sell root emission through the pool (do not pay fees)
218- let subsidized: bool = * is_subsidized. get ( netuid_i) . unwrap_or ( & false ) ;
219- if !subsidized {
213+ if !subsidy_mode {
220214 let swap_result = Self :: swap_alpha_for_tao (
221215 * netuid_i,
222216 tou64 ! ( root_alpha) . into ( ) ,
0 commit comments