-
Notifications
You must be signed in to change notification settings - Fork 628
[SDK] Optimize payment methods query by removing quotes and improving balance checks #8493
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
Merged
joaquim-verges
merged 1 commit into
main
from
_SDK_Optimize_payment_methods_query_by_removing_quotes_and_improving_balance_checks
Dec 4, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The balance check calculation is fundamentally flawed: it compares USD values between tokens without accounting for fees, slippage, and price impact. Additionally, if the destination token's USD price is missing or zero, the check incorrectly marks all tokens as having sufficient balance.
View Details
Analysis
Balance check calculation doesn't account for fees and fails with missing destination token price
What fails: The
usePaymentMethodshook'shasEnoughBalancecalculation (lines 129-136) incorrectly marks tokens as having sufficient balance when destination token price is missing, and ignores fees/slippage when calculating required amount.How to reproduce:
usePaymentMethodswith any token with non-zero balance and pricehasEnoughBalance = trueeven though destination amount is unknownWhat happens:
destinationToken.prices?.["USD"]is undefined,requiredUsdValue = 0Expected behavior: When destination token price is missing, assume insufficient balance (fail-safe). Additionally, when quote data is available, use
quote.originAmount(which includes fees from the API's calculation) instead of naive USD comparison.Why this matters: Users select payment methods that appear to have enough balance but fail at transaction time, resulting in poor UX. Per Bridge Quote documentation,
originAmountis "the necessaryoriginAmountto receive the desireddestinationAmount" and includes all fees.Solution implemented:
quote.originAmountwhen available (most accurate, accounts for all fees)hasEnoughBalance = falseif destination price is missing (fail-safe)