Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 27 additions & 34 deletions pallets/subtensor/src/coinbase/run_coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ impl<T: Config> Pallet<T> {
let total_moving_prices = acc_total_moving_prices;
log::debug!("total_moving_prices: {total_moving_prices:?}");

// --- 3. Get subnet terms (tao_in, alpha_in, and alpha_out)
// Computation is described in detail in the dtao whitepaper.
let mut tao_in: BTreeMap<NetUid, U96F32> = BTreeMap::new();
let mut alpha_in: BTreeMap<NetUid, U96F32> = BTreeMap::new();
let mut tao_in_total: TaoCurrency = 0.into();
let mut alpha_out: BTreeMap<NetUid, U96F32> = BTreeMap::new();
let mut is_subsidized: BTreeMap<NetUid, bool> = BTreeMap::new();
// Only calculate for subnets that we are emitting to.
for netuid_i in subnets_to_emit_to.iter() {
// --- 3. Get subnet terms (tao_in, alpha_in, and alpha_out)
// Computation is described in detail in the dtao whitepaper.
// Get subnet price.
let price_i = T::SwapInterface::current_alpha_price((*netuid_i).into());
log::debug!("price_i: {price_i:?}");
Expand Down Expand Up @@ -118,50 +117,44 @@ impl<T: Config> Pallet<T> {
alpha_in_i = asfloat!(0.0);
alpha_out_i = asfloat!(0.0);
}
// Insert values into maps
tao_in.insert(*netuid_i, tao_in_i);
alpha_in.insert(*netuid_i, alpha_in_i);
// Insert value into map
alpha_out.insert(*netuid_i, alpha_out_i);
}
log::debug!("tao_in: {tao_in:?}");
log::debug!("alpha_in: {alpha_in:?}");
log::debug!("alpha_out: {alpha_out:?}");

// --- 4. Injection.
// Actually perform the injection of alpha_in, alpha_out and tao_in into the subnet pool.
// This operation changes the pool liquidity each block.
for netuid_i in subnets_to_emit_to.iter() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this was made a separate loop was that injection back when we had uniswap v2 could change price, and this would disturb the balance between subnet emissions. We needed to calculate all emissions first using that prices that do not change (because emissions are proportional to prices), and then inject.

My concern here is that we are going to have a tokenomics fix that may or may not return to this behavior (i.e. change price on injection). It is safe to merge now, but will require more work for that update in the next step.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a YAGNI case? It was five minutes to join them, it will be five to split them, and only if needed. The certain benefit of having the simplest code (for all people involved) far outweighs the possible cost (for one developer) of a possible future change.

// --- 4. Injection.
// Actually perform the injection of alpha_in, alpha_out and tao_in into the subnet pool.
// This operation changes the pool liquidity each block.
// Inject Alpha in.
let alpha_in_i =
AlphaCurrency::from(tou64!(*alpha_in.get(netuid_i).unwrap_or(&asfloat!(0))));
SubnetAlphaInEmission::<T>::insert(*netuid_i, alpha_in_i);
let alpha_in_curr = AlphaCurrency::from(tou64!(alpha_in_i));
SubnetAlphaInEmission::<T>::insert(*netuid_i, alpha_in_curr);
SubnetAlphaIn::<T>::mutate(*netuid_i, |total| {
*total = total.saturating_add(alpha_in_i);
*total = total.saturating_add(alpha_in_curr);
});
// Injection Alpha out.
let alpha_out_i =
AlphaCurrency::from(tou64!(*alpha_out.get(netuid_i).unwrap_or(&asfloat!(0))));
SubnetAlphaOutEmission::<T>::insert(*netuid_i, alpha_out_i);
let alpha_out_curr = AlphaCurrency::from(tou64!(alpha_out_i));
SubnetAlphaOutEmission::<T>::insert(*netuid_i, alpha_out_curr);
SubnetAlphaOut::<T>::mutate(*netuid_i, |total| {
*total = total.saturating_add(alpha_out_i);
*total = total.saturating_add(alpha_out_curr);
});
// Inject TAO in.
let tao_in_i: TaoCurrency =
tou64!(*tao_in.get(netuid_i).unwrap_or(&asfloat!(0))).into();
SubnetTaoInEmission::<T>::insert(*netuid_i, TaoCurrency::from(tao_in_i));
let tao_in_curr: TaoCurrency = tou64!(tao_in_i).into();
SubnetTaoInEmission::<T>::insert(*netuid_i, TaoCurrency::from(tao_in_curr));
SubnetTAO::<T>::mutate(*netuid_i, |total| {
*total = total.saturating_add(tao_in_i.into());
});
TotalStake::<T>::mutate(|total| {
*total = total.saturating_add(tao_in_i.into());
});
TotalIssuance::<T>::mutate(|total| {
*total = total.saturating_add(tao_in_i.into());
*total = total.saturating_add(tao_in_curr.into());
});
tao_in_total = tao_in_total.saturating_add(tao_in_curr);
// Adjust protocol liquidity based on new reserves
T::SwapInterface::adjust_protocol_liquidity(*netuid_i, tao_in_i, alpha_in_i);
T::SwapInterface::adjust_protocol_liquidity(*netuid_i, tao_in_curr, alpha_in_curr);
}

TotalStake::<T>::mutate(|total| {
*total = total.saturating_add(tao_in_total.into());
});
TotalIssuance::<T>::mutate(|total| {
*total = total.saturating_add(tao_in_total.into());
});

log::debug!("alpha_out: {alpha_out:?}");

// --- 5. Compute owner cuts and remove them from alpha_out remaining.
// Remove owner cuts here so that we can properly seperate root dividends in the next step.
// Owner cuts are accumulated and then fed to the drain at the end of this func.
Expand Down
Loading