fix alpha_in emission calculations #1918
Open
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.
Description
This fix aims to fix an issue (#1909) - while also simplifying the codebase.
old line 87 is incorrect. after the tao halving the alpha_in_i must max out at block_emission (0.5). If 1.0 alpha were emitted, the tao/alpha emission would not be even, causing a liquidity imbalance and a change in price.
modeled in a spreadsheet - at the tao halvings, an incorrect amount of alpha_in is emitted.

https://docs.google.com/spreadsheets/d/1i4tn0IYaVhvBu8xT1IjiP4U7uuFzsOdD4awjKWckH-k/edit?usp=sharing
we could have changed line 87 to
to resolve this.
but there is an error in line 105 as well
This needs to read:
or on a divide by zero, we'll add too much alpha_in into the liquidity pool.
Taking a step back - lets look at line 105 in context of subsidy.
when the subsidy is in place:
tao_in_i = price_i*block_emission
so we can rewrite line 105 (removing the safe div for the example:
alpha_in_i = (tao_in_i)/(price_i)
to:
alpha_in_i = (price_i*block_emission)/(price_i)
canceling the
price_i
alpha_in_i = block_emission
Since line 87 and line 105 both return the same value,
I added line 107 to account for both options.
alpha_in_i = tao_in_i.safe_div_or(price_i, block_emission);
With the alpha_in_i calcualted in just one place - we simplify the code.
This also resolves the issue of using alpha_emission_i instead of block_emission.
Related Issue(s)
tao_in_ratio
instead ofdefault_tao_in_i
for "price < TAO emissions" #1909Type of Change
Breaking Change
no breaking change.
Checklist
cargo fmt
andcargo clippy
to ensure my code is formatted and linted correctlyScreenshots (if applicable)
Please include any relevant screenshots or GIFs that demonstrate the changes made.
Additional Notes
Please provide any additional information or context that may be helpful for reviewers.