-
Notifications
You must be signed in to change notification settings - Fork 255
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6067577
Global subsidies based on ema prices
gztensor bf2c2c4
Fix tests for global subsidies
gztensor 8ec2ecd
Fix subsidized issuance
gztensor 95e1af9
Fix comment
gztensor 07e3f1e
Merge branch 'devnet-ready' into feat/global-subsidies
gztensor 162ad20
Merge devnet-ready in
gztensor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,22 +39,23 @@ impl<T: Config> Pallet<T> { | |
| log::debug!("Subnets to emit to: {subnets_to_emit_to:?}"); | ||
|
|
||
| // --- 2. Get sum of tao reserves ( in a later version we will switch to prices. ) | ||
| let mut acc_total_moving_prices = U96F32::saturating_from_num(0.0); | ||
| // Only get price EMA for subnets that we emit to. | ||
| for netuid_i in subnets_to_emit_to.iter() { | ||
| // Get and update the moving price of each subnet adding the total together. | ||
| acc_total_moving_prices = | ||
| acc_total_moving_prices.saturating_add(Self::get_moving_alpha_price(*netuid_i)); | ||
| } | ||
| let total_moving_prices = acc_total_moving_prices; | ||
| 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 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. | ||
|
|
@@ -79,11 +80,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); | ||
|
|
@@ -100,11 +97,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:?}"); | ||
|
|
||
|
|
@@ -215,8 +210,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(), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_ishould 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_iaccording to theALPHA price * Block Emissionis 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_inis used to swap for ALPHA (increasing the ALPHA price towards TAO emissions), which it doesn't when ALPHA price > TAO emissions