-
Notifications
You must be signed in to change notification settings - Fork 607
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: improve dust handling in EstimateTradeBasedOnPriceImpact #6769
fix: improve dust handling in EstimateTradeBasedOnPriceImpact #6769
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.
Thanks for the PR! Good catch.
I think there are two components of this PR.
- Err checking if err returned from calculation is ErrInvalidMathApprox, if so graceful returning zero instead of treating this as error
- Refactoring functions in router.go with wrapper functions that create response (e.g
ZeroEstimateTradeBasedOnPriceImpactResponseOnErrInvalidMathApprox
,ZeroEstimateTradeBasedOnPriceImpactResponseFromRequest
)
I am very much in favor of part 1, but I think the new methods introduced with wrapper functions that calls another function to create response struct can be overly confusing compared to directly creating and returning response struct in router.go. Please take a look at let me know what you think! :)
@mattverse I removed the confusing helper functions sir |
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.
Awesome! LGTM
Note to other reviewers: This change is state breaking due to us having estimate query for stargate query
@mattverse is this pending another approval or can it be merged? |
@migueldingli1997 Just waiting to see if any other folks are willing to review this. Planning to merge this by EOW if not |
What is the purpose of the change
We've noticed that the
EstimateTradeBasedOnPriceImpact
introduced in #6167 can error when we're estimating a dust trade against a balancer pool. This happens especially if the weights of the base and quote assets are equal, meaning that for a small enough input, the pool might only be able to give out <1 tokens, which is rounded to zero and triggers anErrInvalidMathApprox
.This PR adds logic to look out for
ErrInvalidMathApprox
in the case of balancer pools, in which case this error is tolerated and a zero output is returned instead of the error. Some refactoring to reduce code duplication was also applied.Testing and Verifying
This change added tests and can be verified as follows:
Documentation and Release Note
Unreleased
section ofCHANGELOG.md
?Where is the change documented?
x/{module}/README.md
)Osmosis documentation siteN/A