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: proportional slippage #424

Merged
merged 9 commits into from
Jan 15, 2025
Merged

fix: proportional slippage #424

merged 9 commits into from
Jan 15, 2025

Conversation

agualis
Copy link
Collaborator

@agualis agualis commented Jan 9, 2025

@gosuto.eth We finally merged the fix.
Recap: pools containing Erc4626 tokens (no matter if they are boosted or not) require a default 0.01 slippage in proportional mode cause the related SDK queries are not 100% accurate in that case (due to SC limitations). That small slippage + the already existing SDK rounding should avoid the error (some dust is the price to pay in this scenario).

Fixes slippage bug reported by Gosuto:
balancer/b-sdk#552

Before:
Using slippage 0% by default causes a tx simulation error due addLiquidityBoosted queries not being 100% precise

Screenshot 2025-01-09 at 19 38 31

Also real slippage was not properly displayed in the quote.

After:

Using 0.01 % slippage by default fixes the issue.

success

Also real slippage is now properly displayed.

There are other proportional scenarios where the SDK queries are more precise so we could use 0% or 0.0001% instead or 0.01% but I think it is not worthy the complexity.

Copy link

vercel bot commented Jan 9, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mono-beets-test-v3 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 15, 2025 3:58pm
mono-beets-v3 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 15, 2025 3:58pm
mono-frontend-v3 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 15, 2025 3:58pm
mono-test-v3 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 15, 2025 3:58pm

For example, addLiquidityBoosted queries with tokens with 6 decimals would always fail if we used 0% slippage by default.
This 0.01% is big enough to prevent tx simulation errors in all types of proportional adds while keeping the dust amount small.
*/
export const defaultProportionalSlippagePercentage = '0.01'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I thought the SDK rounded down? The only reason the SDK calcs should fail with 0% slippage is if the pool balances move.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole reason we are using 0% slippage is to help the user avoid dust.

Copy link
Collaborator Author

@agualis agualis Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are cases where rounding down is not enough due to SDK query not being 100% precise as the comment explains. @brunoguerios has more context but it's an SC limitation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the problem lies in the AddLiquidityBoosted queries not matching the actual transaction 100%. It's an SC limitation.
The error is ~1000 wei, which is negligible on 18 decimal tokens, but not as much on 6 decimals tokens 😕
If you'd like to get even more context, we'd have to get SC team involved in the discussion.
For all other queries that are an exact match, rounding down should be enough.

@agualis agualis merged commit 3b59129 into main Jan 15, 2025
13 checks passed
@agualis agualis deleted the fix/proportionalSlippage branch January 15, 2025 16:07
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.

Boosted add slippage issue
3 participants