-
Notifications
You must be signed in to change notification settings - Fork 77
feat: update reserves calculation for uniswap-v4/pancake-cl pools #1223
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: main
Are you sure you want to change the base?
Conversation
Test coverage changes:
|
| l.WithFields(logger.Fields{ | ||
| "error": err, | ||
| }).Error("failed to calculate reserves from ticks") | ||
| return entity.Pool{}, err |
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.
should only be a warning
| tickUpper := ticks[i+1] | ||
|
|
||
| sqrtLower, err := utils.GetSqrtRatioAtTick(tickLower.Index) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
| sqrtUpper, err := utils.GetSqrtRatioAtTick(tickUpper.Index) |
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.
can micro optimize this to reduce GetSqrtRatioAtTick calls by 2
| if sqrtPriceX96.Cmp(sqrtLower) < 0 { | ||
| numer.Mul(L, Q96).Mul(&numer, tmp.Sub(sqrtUpper, sqrtLower)) | ||
| denom.Mul(sqrtLower, sqrtUpper) | ||
|
|
||
| amount0.Div(&numer, &denom) | ||
| } else if sqrtPriceX96.Cmp(sqrtUpper) >= 0 { | ||
| numer.Mul(L, tmp.Sub(sqrtUpper, sqrtLower)) | ||
|
|
||
| amount1.Div(&numer, Q96) | ||
| } else { |
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.
can also micro-optimize this to reduce Cmp (since sqrtLower is in increasing order) (and totalAmountX.Add)
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.
this code is in quite hot path so just trying to optimize bit more
Why did we need it?
Related Issue
Release Note
How Has This Been Tested?
Screenshots (if appropriate):