-
Notifications
You must be signed in to change notification settings - Fork 244
Global subsidies based on ema prices #2140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devnet-ready
Are you sure you want to change the base?
Changes from all commits
6067577
bf2c2c4
8ec2ecd
95e1af9
07e3f1e
162ad20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,12 +35,25 @@ impl<T: Config> Pallet<T> { | |
let subnet_emissions = Self::get_subnet_block_emissions(&subnets, block_emission); | ||
let subnets_to_emit_to: Vec<NetUid> = subnet_emissions.keys().copied().collect(); | ||
|
||
// Get sum of tao reserves ( in a later version we will switch to prices. ) | ||
// Only get price EMA for subnets that we emit to. | ||
let total_moving_prices = subnets_to_emit_to | ||
.iter() | ||
.map(|netuid| Self::get_moving_alpha_price(*netuid)) | ||
.fold(U96F32::saturating_from_num(0.0), |acc, ema| { | ||
acc.saturating_add(ema) | ||
}); | ||
log::debug!("total_moving_prices: {total_moving_prices:?}"); | ||
|
||
let subsidy_mode = total_moving_prices < U96F32::saturating_from_num(1.0); | ||
log::debug!("subsidy_mode: {subsidy_mode:?}"); | ||
|
||
// --- 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 tao_issued: BTreeMap<NetUid, U96F32> = BTreeMap::new(); | ||
let mut alpha_in: BTreeMap<NetUid, U96F32> = BTreeMap::new(); | ||
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() { | ||
// Get subnet price. | ||
|
@@ -62,11 +75,7 @@ impl<T: Config> Pallet<T> { | |
// Get initial alpha_in | ||
let mut alpha_in_i: U96F32; | ||
let mut tao_in_i: U96F32; | ||
let tao_in_ratio: U96F32 = default_tao_in_i.safe_div_or( | ||
U96F32::saturating_from_num(block_emission), | ||
U96F32::saturating_from_num(0.0), | ||
); | ||
if price_i < tao_in_ratio { | ||
if subsidy_mode { | ||
tao_in_i = price_i.saturating_mul(U96F32::saturating_from_num(block_emission)); | ||
alpha_in_i = block_emission; | ||
let difference_tao: U96F32 = default_tao_in_i.saturating_sub(tao_in_i); | ||
|
@@ -83,11 +92,9 @@ impl<T: Config> Pallet<T> { | |
*total = total.saturating_sub(bought_alpha); | ||
}); | ||
} | ||
is_subsidized.insert(*netuid_i, true); | ||
} else { | ||
tao_in_i = default_tao_in_i; | ||
alpha_in_i = tao_in_i.safe_div_or(price_i, alpha_emission_i); | ||
is_subsidized.insert(*netuid_i, false); | ||
} | ||
log::debug!("alpha_in_i: {alpha_in_i:?}"); | ||
|
||
|
@@ -103,6 +110,7 @@ impl<T: Config> Pallet<T> { | |
} | ||
// Insert values into maps | ||
tao_in.insert(*netuid_i, tao_in_i); | ||
tao_issued.insert(*netuid_i, default_tao_in_i); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As commented above that wouldn't be true, when ALPHA price > TAO emissions, with the global subsidy, because the |
||
alpha_in.insert(*netuid_i, alpha_in_i); | ||
alpha_out.insert(*netuid_i, alpha_out_i); | ||
} | ||
|
@@ -138,10 +146,13 @@ impl<T: Config> Pallet<T> { | |
TotalStake::<T>::mutate(|total| { | ||
*total = total.saturating_add(tao_in_i.into()); | ||
}); | ||
// TAO issued | ||
let tao_issued_i: TaoCurrency = | ||
tou64!(*tao_issued.get(netuid_i).unwrap_or(&asfloat!(0))).into(); | ||
TotalIssuance::<T>::mutate(|total| { | ||
*total = total.saturating_add(tao_in_i.into()); | ||
*total = total.saturating_add(tao_issued_i.into()); | ||
}); | ||
// Adjust protocol liquidity based on new reserves | ||
// Adjust protocol liquidity based on added reserves | ||
T::SwapInterface::adjust_protocol_liquidity(*netuid_i, tao_in_i, alpha_in_i); | ||
} | ||
|
||
|
@@ -198,8 +209,7 @@ impl<T: Config> Pallet<T> { | |
let pending_alpha: U96F32 = alpha_out_i.saturating_sub(root_alpha); | ||
log::debug!("pending_alpha: {pending_alpha:?}"); | ||
// Sell root emission through the pool (do not pay fees) | ||
let subsidized: bool = *is_subsidized.get(netuid_i).unwrap_or(&false); | ||
if !subsidized { | ||
if !subsidy_mode { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That could technically stay so that the root proportion on "overpriced" subnets (ALPHA price > TAO emissions) is not countering the SoS to increase at/above 1 |
||
let swap_result = Self::swap_alpha_for_tao( | ||
*netuid_i, | ||
tou64!(root_alpha).into(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
tao_in_i
should only be changed for subnets where ALPHA price < TAO emissions (EMA / sum of EMAs), otherwise it would inject more TAO, and would result in more than 1 TAO/block being emitted. The only reason to change thetao_in_i
according to theALPHA price * Block Emission
is so that one can calculate how much TAO should be used to swap for ALPHA (to bring the ALPHA price back up).Here a scenario:
If one were to use ALPHA prices only as commented at line 38 I think this wouldn't happen, because then there is no discrepancy between ALPHA price and EMA price, as only ALPHA price is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason to downscale TAO is if ALPHA needs to be downscaled, so that the injections can maintain the price, while the
difference_tao_in
is used to swap for ALPHA (increasing the ALPHA price towards TAO emissions), which it doesn't when ALPHA price > TAO emissions