Skip to content

fix: source amount calculation ignores fee asset - #9831

Merged
micaelae merged 7 commits into
mainfrom
swaps4930-fix-src-amount-calc
Aug 12, 2026
Merged

fix: source amount calculation ignores fee asset#9831
micaelae merged 7 commits into
mainfrom
swaps4930-fix-src-amount-calc

Conversation

@micaelae

@micaelae micaelae commented Aug 12, 2026

Copy link
Copy Markdown
Member

Explanation

The initial toQuoteResponseV2 assumes that the metabridge fee is always paid in the src asset. This causes the src amount to be incorrect when the amounts are added up (srcTokenAmount + fees)

Changes

  • export assetIdsMatch util, which does a case-insensitive comparison of EVM assetIds and case-sensitive comparison for non-EVM
  • filter fees by assetId in toQuoteResponseV2 to prevent inflating src.amount

References

Fixes https://consensyssoftware.atlassian.net/browse/SWAPS-4930

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Touches quote amount coercion and sent/adjusted-return calculations shown to users; logic is localized but wrong matching would still misstate balances.

Overview
Fixes incorrect source amounts when V1 quotes are coerced to V2 by only rolling tx and metabridge fees into src.amount when the fee’s assetId matches the source asset (via new assetIdsMatch).

Adds and exports assetIdsMatch: exact match for non-EVM CAIP IDs; for EIP-155, compares case-insensitively. Replaces ad hoc .toLowerCase() comparisons in sumAmounts, calcSentAmount, calcIncludedTxFees, and calcAdjustedReturn so fee/asset alignment stays consistent across coercion and metadata math.

Reviewed by Cursor Bugbot for commit d9aa779. Bugbot is set up for automated code reviews on this repo. Configure here.

@micaelae
micaelae marked this pull request as ready for review August 12, 2026 02:21
@micaelae
micaelae requested review from a team as code owners August 12, 2026 02:21
@micaelae
micaelae enabled auto-merge August 12, 2026 02:30
@micaelae
micaelae added this pull request to the merge queue Aug 12, 2026
Merged via the queue into main with commit 62fd54e Aug 12, 2026
50 checks passed
@micaelae
micaelae deleted the swaps4930-fix-src-amount-calc branch August 12, 2026 16:12
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.

2 participants