Skip to content

Commit dd58577

Browse files
committed
Subsidy mode based on ema prices total
1 parent e846eba commit dd58577

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ impl<T: Config> Pallet<T> {
3434
// 2. Get subnets to emit to and emissions
3535
let subnet_emissions = Self::get_subnet_block_emissions(&subnets, block_emission);
3636
let subnets_to_emit_to: Vec<NetUid> = subnet_emissions.keys().copied().collect();
37+
let total_ema_price: U96F32 = subnets_to_emit_to
38+
.iter()
39+
.map(|netuid| Self::get_moving_alpha_price(*netuid))
40+
.sum();
3741

3842
// --- 3. Get subnet terms (tao_in, alpha_in, and alpha_out)
3943
// Computation is described in detail in the dtao whitepaper.
4044
let mut tao_in: BTreeMap<NetUid, U96F32> = BTreeMap::new();
4145
let mut alpha_in: BTreeMap<NetUid, U96F32> = BTreeMap::new();
4246
let mut alpha_out: BTreeMap<NetUid, U96F32> = BTreeMap::new();
43-
let mut is_subsidized: BTreeMap<NetUid, bool> = BTreeMap::new();
47+
let subsidy_mode = total_ema_price <= U96F32::saturating_from_num(1);
4448
// Only calculate for subnets that we are emitting to.
4549
for netuid_i in subnets_to_emit_to.iter() {
4650
// Get subnet price.
@@ -79,15 +83,11 @@ impl<T: Config> Pallet<T> {
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
}
86-
is_subsidized.insert(*netuid_i, true);
8788
} else {
8889
tao_in_i = default_tao_in_i;
8990
alpha_in_i = tao_in_i.safe_div_or(price_i, alpha_emission_i);
90-
is_subsidized.insert(*netuid_i, false);
9191
}
9292
log::debug!("alpha_in_i: {alpha_in_i:?}");
9393

@@ -198,8 +198,7 @@ impl<T: Config> Pallet<T> {
198198
let pending_alpha: U96F32 = alpha_out_i.saturating_sub(root_alpha);
199199
log::debug!("pending_alpha: {pending_alpha:?}");
200200

201-
let subsidized: bool = *is_subsidized.get(netuid_i).unwrap_or(&false);
202-
if !subsidized {
201+
if !subsidy_mode {
203202
PendingRootAlphaDivs::<T>::mutate(*netuid_i, |total| {
204203
*total = total.saturating_add(tou64!(root_alpha).into());
205204
});

0 commit comments

Comments
 (0)