Skip to content

Commit a5fc4ff

Browse files
committed
remove is_subsidized
1 parent 7601c91 commit a5fc4ff

File tree

2 files changed

+33
-37
lines changed

2 files changed

+33
-37
lines changed

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ impl<T: Config> Pallet<T> {
5454
let mut tao_in: BTreeMap<NetUid, U96F32> = BTreeMap::new();
5555
let mut alpha_in: BTreeMap<NetUid, U96F32> = BTreeMap::new();
5656
let mut alpha_out: BTreeMap<NetUid, U96F32> = BTreeMap::new();
57-
let mut is_subsidized: BTreeMap<NetUid, bool> = BTreeMap::new();
5857
let mut tao_to_stake = U96F32::saturating_from_num(0.0);
5958

6059
// Only calculate for subnets that we are emitting to.
@@ -85,8 +84,9 @@ impl<T: Config> Pallet<T> {
8584

8685
let mut alpha_in_i: U96F32;
8786
let mut tao_in_i: U96F32;
88-
if default_alpha_in_i > alpha_emission_i {
89-
alpha_in_i = alpha_emission_i;
87+
let min_alpha_emission = alpha_emission_i.min(block_emission);
88+
if default_alpha_in_i > min_alpha_emission {
89+
alpha_in_i = min_alpha_emission;
9090
tao_in_i = alpha_in_i.saturating_mul(price_i);
9191
let difference_tao: U96F32 = default_tao_in_i.saturating_sub(tao_in_i);
9292
tao_to_stake = tao_to_stake.saturating_add(difference_tao);
@@ -118,20 +118,21 @@ impl<T: Config> Pallet<T> {
118118
U96F32::saturating_from_num(0.0),
119119
);
120120

121-
for netuid_i in subnets_to_emit_to.iter() {
122-
let buy_swap_result = Self::swap_tao_for_alpha(
123-
*netuid_i,
124-
tou64!(amount_per_subnet).into(),
125-
T::SwapInterface::max_price().into(),
126-
true,
127-
);
128-
if let Ok(buy_swap_result_ok) = buy_swap_result {
129-
let bought_alpha = AlphaCurrency::from(buy_swap_result_ok.amount_paid_out);
130-
SubnetAlphaOut::<T>::mutate(*netuid_i, |total| {
131-
*total = total.saturating_sub(bought_alpha);
132-
});
121+
if amount_per_subnet > asfloat!(0.0) {
122+
for netuid_i in subnets_to_emit_to.iter() {
123+
let buy_swap_result = Self::swap_tao_for_alpha(
124+
*netuid_i,
125+
tou64!(amount_per_subnet).into(),
126+
T::SwapInterface::max_price().into(),
127+
true,
128+
);
129+
if let Ok(buy_swap_result_ok) = buy_swap_result {
130+
let bought_alpha = AlphaCurrency::from(buy_swap_result_ok.amount_paid_out);
131+
SubnetAlphaOut::<T>::mutate(*netuid_i, |total| {
132+
*total = total.saturating_sub(bought_alpha);
133+
});
134+
}
133135
}
134-
is_subsidized.insert(*netuid_i, true);
135136
}
136137

137138
log::debug!("tao_to_stake: {tao_to_stake:?}");
@@ -163,12 +164,10 @@ impl<T: Config> Pallet<T> {
163164
SubnetTaoInEmission::<T>::insert(*netuid_i, TaoCurrency::from(tao_in_i));
164165
SubnetTAO::<T>::mutate(*netuid_i, |total| {
165166
*total = total.saturating_add(tao_in_i.into());
166-
*total = total.saturating_add(tou64!(amount_per_subnet).into());
167167
});
168168

169169
TotalStake::<T>::mutate(|total| {
170170
*total = total.saturating_add(tao_in_i.into());
171-
*total = total.saturating_add(tou64!(amount_per_subnet).into());
172171
});
173172
TotalIssuance::<T>::mutate(|total| {
174173
*total = total.saturating_add(tao_in_i.into());
@@ -231,21 +230,18 @@ impl<T: Config> Pallet<T> {
231230
let pending_alpha: U96F32 = alpha_out_i.saturating_sub(root_alpha);
232231
log::debug!("pending_alpha: {pending_alpha:?}");
233232
// Sell root emission through the pool (do not pay fees)
234-
let subsidized: bool = *is_subsidized.get(netuid_i).unwrap_or(&false);
235-
if !subsidized {
236-
let swap_result = Self::swap_alpha_for_tao(
237-
*netuid_i,
238-
tou64!(root_alpha).into(),
239-
T::SwapInterface::min_price(),
240-
true,
241-
);
242-
if let Ok(ok_result) = swap_result {
243-
let root_tao = ok_result.amount_paid_out;
244-
// Accumulate root divs for subnet.
245-
PendingRootDivs::<T>::mutate(*netuid_i, |total| {
246-
*total = total.saturating_add(root_tao);
247-
});
248-
}
233+
let swap_result = Self::swap_alpha_for_tao(
234+
*netuid_i,
235+
tou64!(root_alpha).into(),
236+
T::SwapInterface::min_price().into(),
237+
true,
238+
);
239+
if let Ok(ok_result) = swap_result {
240+
let root_tao: u64 = ok_result.amount_paid_out;
241+
// Accumulate root divs for subnet.
242+
PendingRootDivs::<T>::mutate(*netuid_i, |total| {
243+
*total = total.saturating_add(root_tao.into());
244+
});
249245
}
250246
// Accumulate alpha emission in pending.
251247
PendingAlphaSwapped::<T>::mutate(*netuid_i, |total| {

pallets/subtensor/src/tests/coinbase.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fn test_coinbase_tao_issuance_different_prices() {
153153
new_test_ext(1).execute_with(|| {
154154
let netuid1 = NetUid::from(1);
155155
let netuid2 = NetUid::from(2);
156-
let emission = 100_000_000;
156+
let emission = 1_000_000_000;
157157
add_network(netuid1, 1, 0);
158158
add_network(netuid2, 1, 0);
159159

@@ -198,17 +198,17 @@ fn test_coinbase_tao_issuance_different_prices() {
198198
// Assert tao emission is split evenly.
199199
assert_abs_diff_eq!(
200200
SubnetTAO::<Test>::get(netuid1),
201-
TaoCurrency::from(initial_tao + emission / 3),
201+
TaoCurrency::from(initial_tao + 45 * emission / 100),
202202
epsilon = 1.into(),
203203
);
204204
assert_abs_diff_eq!(
205205
SubnetTAO::<Test>::get(netuid2),
206-
TaoCurrency::from(initial_tao + 2 * emission / 3),
206+
TaoCurrency::from(initial_tao + 55 * emission / 100),
207207
epsilon = 1.into(),
208208
);
209209

210210
// Prices are low => we limit tao issued (buy alpha with it)
211-
let tao_issued = TaoCurrency::from(((0.1 + 0.2) * emission as f64) as u64);
211+
let tao_issued = TaoCurrency::from((emission as f64) as u64);
212212
assert_abs_diff_eq!(
213213
TotalIssuance::<Test>::get(),
214214
tao_issued,

0 commit comments

Comments
 (0)