Skip to content
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

fix: remove A precision and clean up borked logic #1188

Merged
merged 5 commits into from
Feb 8, 2023

Conversation

matthiasmatt
Copy link
Contributor

@matthiasmatt matthiasmatt commented Feb 8, 2023

Description

Non convergence issue

The non convergence issue is annoying and sometimes extremly minor. We've seen cases where either D or stableswap calculation keep oscillating between n and n+2 for example.

This changes, which replicates the logic from the live 3pool from curve ensure that we always compute a value for both by taking the last value of the convergence.

Precision issue

After investigation, #1152 comes from using integer division in the calculation of D. This was replicated in the native python 3 model which mean that it' not coming from an issue in the implementation of the division of uint256.

This is replicating perfectly the behavior of the 3pool. It is possible though to add more precision in the calculation of D by multiplying A by 100 and dividing by this precision in a couple of places in the code.

Even setting this precision to 1 million is not enough to remove this off by one rounding issue. I've left the implementation in branch mat/stableswap_precision_issue

Based on the fact that increasing A precision does not seems to be doing anything for this particular issue, and that 3pool is already working fine with this implementation, we can just accept the current implementation.

This is also not really exploitable because of swap fees.

Purpose

Ensure we have convergence for pools that are ok.

@matthiasmatt matthiasmatt marked this pull request as ready for review February 8, 2023 14:52
@matthiasmatt matthiasmatt requested a review from a team as a code owner February 8, 2023 14:52
@k-yang k-yang merged commit 5afeb0a into master Feb 8, 2023
@k-yang k-yang deleted the mat/stableswap_improvements branch February 8, 2023 14:58
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.

2 participants