-
Notifications
You must be signed in to change notification settings - Fork 2
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/swap exact out #28
Conversation
What does that mean? In what sense "protocol is at loss"? Where does this 1 token go (and who's paying it)? |
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.
I can see the logic being changed but none of the tests needed adjustments? I remember some tests where the output differed from the reference Curve implementations.
Before the change proposed in this PR:
After this PR:
|
Curve and RefFi do not implement any equivalent method to our |
OK, got it. So I think wording of protocol loss is incorrect. Protocol (in this case the tokens in the pool) are not unnecessarily spent. It's the trader to has to pay more. |
Because of rounding down when converting "rated_amount" to "token_amount", the method
rated_swap_from(...)
calculatesamount_in
smaller than needed inrated_swap_to(...)
to produce the sameamount_out
. This behavior makes a rather insignificant loss to the protocol (1
smallest unit of "token_in") but still, these methods should be consistent.Fix: Instead of adjusting the "rated_amount" by adding
1
, adjust the "token_amount".EDIT:
When the precision of "token_in" is larger than the precision of "token_out", the protocol loss is greater than
1
, reaching thetoken_in_precision
/token_out_precision
. E.g. when swapping dai(18 dec) to usdt(6 dec), the loss can reach 0.000001 dai