Skip to content

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

Open
micaelae wants to merge 6 commits into
swaps4546-v2-coercersfrom
swaps4546-v2-metadata
Open

chore: support V1 and V2 quotes when calculating swap metadata#9727
micaelae wants to merge 6 commits into
swaps4546-v2-coercersfrom
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 displayed swap amounts, fees, and price impact are derived for v2 quotes, which can affect quote sorting and user-facing numbers; scope is limited to metadata calculation with broad test updates.

Overview
calcQuoteMetadata now accepts both QuoteResponse v1 and v2. V2 inputs are detected with QuoteResponseSchemaV2, normalized via toQuoteResponseV1, and calculated with the existing v1 helpers so swap/bridge UI metadata stays on the legacy shape.

Sent amount and fees change for v2: calcSentAmount takes an isQuoteV2 flag so v2 srcTokenAmount is treated like intent quotes (total commitment, no extra feeData on top). calcRelayerFee now uses a precomputed sentAmount instead of recomputing it. minDestTokenAmount falls back to destTokenAmount when missing.

Metadata output is tighter: calcPriceImpact returns undefined when fiat/USD deltas are missing; optional fields (cost, adjustedReturn, priceImpact, etc.) are only attached when at least one value is present. sumAmounts in number-formatters can sum additional v2 fee keys (normalizedAmount, minAmountUsd, etc.).

Tests and mocks were updated (selector/calculator specs drive expectations through calcQuoteMetadata / toQuoteMetadataV1, EVM vs Solana trade shapes, renamed getMockBridgeQuotes*V1 helpers).

Reviewed by Cursor Bugbot for commit 6644859. 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
@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
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