Skip to content

chore: support V1 and V2 quotes when calculating swap metadata - #9727

Merged
micaelae merged 41 commits into
mainfrom
swaps4546-v2-metadata
Aug 4, 2026
Merged

chore: support V1 and V2 quotes when calculating swap metadata#9727
micaelae merged 41 commits into
mainfrom
swaps4546-v2-metadata

Conversation

@micaelae

@micaelae micaelae commented Jul 31, 2026

Copy link
Copy Markdown
Member

Explanation

Update calcQuoteMetadata util to handle both V1 and V2 quotes. Legacy metadata calculators continue to use the V1 schema but are able to read V2 quotes

References

Implements https://consensyssoftware.atlassian.net/browse/SWAPS-4546

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
Changes how sent amounts, relayer fees, and optional metadata are derived for quotes shown in swap/bridge flows; incorrect V2 handling could misstate costs or sorting, though coverage is expanded in calculator and selector tests.

Overview
calcQuoteMetadata now accepts V1 or V2 QuoteResponse values: V2 inputs are detected and coerced through toQuoteResponseV1 before the existing calculators run, so swap/bridge UI metadata keeps using the legacy V1 shape.

V2-specific behavior is layered on top of that path. calcSentAmount takes an isQuoteV2 flag so source fees in feeData are not added on top of srcTokenAmount (same idea as intent-based quotes, avoiding double-count). calcRelayerFee now receives the precomputed sentAmount instead of recomputing it. calcPriceImpact returns undefined when fiat inputs are missing, and optional metadata fields (cost, priceImpact, etc.) are only attached when at least one value is present. sumAmounts in number-formatters can aggregate additional V2 fee fields (normalizedAmount, minAmount, and related fiat keys).

Tests and mocks were updated (factory helpers, selector expectations, EVM vs non-EVM trade shapes) to exercise V2 quotes end-to-end.

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

@micaelae micaelae changed the title chore: calcQuoteMetadata V1/V2 chore: support V1 and V2 QuoteResponse format when calculating metadata Aug 3, 2026
@micaelae micaelae changed the title chore: support V1 and V2 QuoteResponse format when calculating metadata chore: support V1 and V2 quotes when calculating swap metadata Aug 3, 2026
infiniteflower
infiniteflower previously approved these changes Aug 3, 2026
@micaelae
micaelae marked this pull request as ready for review August 3, 2026 23:50
@micaelae
micaelae requested review from a team as code owners August 3, 2026 23:50
Comment thread packages/bridge-controller/src/utils/quote-metadata/calculators.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8b8ca16. Configure here.

Comment thread packages/bridge-controller/src/utils/quote-metadata/calculators.ts
Base automatically changed from swaps4546-v2-coercers to main August 4, 2026 17:41
@micaelae
micaelae dismissed infiniteflower’s stale review August 4, 2026 17:41

The base branch was changed.

@micaelae
micaelae enabled auto-merge August 4, 2026 17:57
@micaelae
micaelae added this pull request to the merge queue Aug 4, 2026
Merged via the queue into main with commit 85fce1e Aug 4, 2026
50 checks passed
@micaelae
micaelae deleted the swaps4546-v2-metadata branch August 4, 2026 18:13
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