Skip to content

Conversation

dougsillars
Copy link

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.
image
https://docs.google.com/spreadsheets/d/1i4tn0IYaVhvBu8xT1IjiP4U7uuFzsOdD4awjKWckH-k/edit?usp=sharing

we could have changed line 87 to

alpha_in_i = block_emission;

to resolve this.

but there is an error in line 105 as well

alpha_in_i = tao_in_i.safe_div_or(price_i, alpha_emission_i);

This needs to read:

alpha_in_i = tao_in_i.safe_div_or(price_i, block_emission);

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)

Type of Change

  • [ x] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Breaking Change

no breaking change.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run cargo fmt and cargo clippy to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Screenshots (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.

@mcjkula
Copy link

mcjkula commented Aug 4, 2025

This also resolves the issue of using alpha_emission_i instead of block_emission.

Why is that an issue? We should use alpha_emission_i for this. I don't understand the fix you are applying.

The reason for the subsidy is, that when the price is lower than TAO emissions then the alpha_in becomes larger than allowed, and without the limitation to alpha_emission_i it could become "infinitely" large.

Let's say my ALPHA price is 0.2 and my TAO emissions are 0.4, then I would need to inject 2 ALPHA into the pool to keep the price stable. To resolve this issue the subsidy is clipping the alpha_in_i to alpha_emission_i this means more TAO per ALPHA, so that the price increases back towards it's TAO emissions and the pool can continue to inject in balance.

With V3 the change was done to fix this mechanism, where it would downscale tao_in_i to price_i * block_emission and use the difference_tao to swap TAO for ALPHA. This means it's the same process of bringing the price back towards it's TAO emissions.

The problem with the fix, was that it compares the price towards tao_in_ratio which is not supposed to be used for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect use of tao_in_ratio instead of default_tao_in_i for "price < TAO emissions"
2 participants