swap: handle native balance drift and low bridge amounts - #241
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
shrinathprabhu
previously approved these changes
Aug 13, 2026
shrinathprabhu
approved these changes
Aug 13, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Prevents an Exact-In native source from failing route reconstruction when its amount was previously calculated from the wallet balance minus reserved gas and the live balance changes before holdings are resolved again.
Insufficient-balance and bridge-fee errors now include human-readable token amounts and more useful source context. Bridge fees consuming the bridged amount are exposed separately as
validation/amount_too_lowso consumers can distinguish an uneconomical amount from an insufficient wallet balance.Changes
amountRaw > availableRawvalidation for native source tokens while retaining it for ERC-20 sources.ERROR_CODES.AMOUNT_TOO_LOWandErrors.amountTooLow(...)for routes whose bridge fees consume the bridged amount.validation/amount_too_lowwith formatted bridge-fee and bridged-amount values from the standard Exact-In and fast-path routes.formatTokenBalancedirectly from its domain formatting module.Testing
npm run lintnpm run typechecknpm testRisk / Impact
validation/insufficient_balancemust handle the newvalidation/amount_too_lowcode instead.ERROR_CODES.AMOUNT_TOO_LOWadditively extends the publicERROR_CODESobject andErrorCodeunion; existing codes and method signatures are unchanged.