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

BPT_IN_FOR_EXACT_TOKENS_OUT accuracy issue #2541

Closed
sparrowDom opened this issue Aug 4, 2023 · 1 comment
Closed

BPT_IN_FOR_EXACT_TOKENS_OUT accuracy issue #2541

sparrowDom opened this issue Aug 4, 2023 · 1 comment

Comments

@sparrowDom
Copy link

Problem:
When exiting the pool using BPT_IN_FOR_EXACT_TOKENS_OUT I've encountered accuracy issues that seem like a rounding error.

Reproduction
See these 2 tenderly transactions where 1st one succeeds and 2nd one fails.

Both are exiting rETH/WETH pool in BPT_IN_FOR_EXACT_TOKENS_OUT mode with the same minAmountsOut in the exitPoolRequest as well amountsOut encoded in the user encoded data of the BPT_IN_FOR_EXACT_TOKENS_OUT mode. (format: [BPT_IN_FOR_EXACT_TOKENS_OUT, amountsOut, maxBPTAmountIn] )

First one succeeds because it is withdrawing 1.0 rETH and the second one fails because it is withdrawing 0.8123 rETH. Both have been given sufficient BPT in the encoded request so that is not the issue. This require in the code is the one that triggers the exception. Using Tenderly Evaluate to see the value of variables in the execution:
Screenshot 2023-08-04 at 22 00 38
Screenshot 2023-08-04 at 22 01 15

from the above debugger it is evident that the actual change is off by 1 WEI from the limit number that has been passed in the request. And because it is smaller than the minAmountsOut the transaction fails.

@jubeira
Copy link
Contributor

jubeira commented Oct 27, 2023

Hi @sparrowDom, thanks for looking into this.

Rounding in pool's favor is on purpose; at some point the math inside the pools is not perfectly accurate (e.g. when upscaling and downscaling), and that means that the calculated amounts might be off with respect to a scenario with no precision loss.

To prevent the txs from failing, I'd suggest being more permissive with the minimum amounts in or out in general. Some wei won't make any economic difference in practice, but will help the txs go through when the rounding happens. You can query the swaps before executing them too.

@jubeira jubeira closed this as completed Oct 27, 2023
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

No branches or pull requests

2 participants