-
Notifications
You must be signed in to change notification settings - Fork 25
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 rounding of 2CLP pools #1193
base: main
Are you sure you want to change the base?
Conversation
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.
Nice, thanks @joaobrunoah !
I don't agree with the changes for computeBalance
, but otherwise makes sense!
Co-authored-by: Juan Ignacio Ubeira <[email protected]>
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.
Looks better now! I have a doubt about the invariant rounding direction. Not 100% sure it actually matters in the context of a swap though. Let's try to find out before merging.
uint256 currentInvariant = Gyro2CLPMath.calculateInvariant( | ||
balances, | ||
sqrtAlpha, | ||
sqrtBeta, | ||
kind == SwapKind.EXACT_IN ? Rounding.ROUND_DOWN : Rounding.ROUND_UP | ||
); |
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 virtual parameters are always proportional to the invariant, and we're rounding one of them up and the other one down.
Technically we should send an invariant rounded down to the virtual parameter that we round down, and an invariant rounded up to the parameter that we're rounding up.
I'm not sure it's really worth it though, as you'd need to compute two different invariants. This is only used for swaps, so rounding is not as impactful as with joins / exits.
// virtualBalanceIn is always rounded up, because: | ||
// * If swap is EXACT_IN: a bigger virtualBalanceIn leads to a lower amount out; | ||
// * If swap is EXACT_OUT: a bigger virtualBalanceIn leads to a bigger amount in; | ||
// virtualBalanceOut is always rounded down, because: | ||
// * If swap is EXACT_IN: a lower virtualBalanceOut leads to a lower amount out; | ||
// * If swap is EXACT_OUT: a lower virtualBalanceOut leads to a bigger amount in; |
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 looks correct now.
Description
Certora found some rounding issues related to some functions of 2-CLP pool:
calculateQuadratic()
, fromGyro2CLPMath.sol
, was not rounded properly.Type of change
Checklist:
main
, or there's a description of how to merge