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

feat: solvers - consume full swap amount #10

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

parketh
Copy link
Contributor

@parketh parketh commented Oct 4, 2024

Summary

This PR updates the swap amount calculation logic in swap_lib to better handle rounding errors when calculating swap amounts.

Description

As part of the reintegration of Solvers with AVNU, their team identified that in some exact in swaps, the amount actually consumed is lower than the amount requested even though liquidity is enough to fill the swap.

This happens because we calculate the net swap amount based on available liquidity, and add back fees using the net_to_fee util function. This leads to rounding errors in some cases, where the actual amount consumed deviates +/- 1 from the requested swap amount.

This PR adds a fix to consume the full swap amount for exact in swaps that that are fully filled over non-zero liquidity.

Testing

snforge test --max-n-steps 4294967295

@parketh parketh changed the title feat: consume full swap amount feat: solvers - consume full swap amount Oct 4, 2024
@parketh parketh merged commit 3606796 into main Oct 4, 2024
1 check passed
@parketh parketh deleted the feat/consume-full-swap-amount branch October 4, 2024 14:02
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.

1 participant