feat: implement QuoteResponse V1 and V2 coercers - #9725
Merged
Conversation
micaelae
marked this pull request as ready for review
August 3, 2026 22:40
micaelae
enabled auto-merge
August 3, 2026 23:53
infiniteflower
left a comment
Contributor
There was a problem hiding this comment.
https://github.com/MetaMask/core/pull/9725/changes#r3713514183, this comment applies to all toV2 functions
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ 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 c388297. Configure here.
infiniteflower
approved these changes
Aug 4, 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.

Explanation
Implement coercers between
QuoteResponsev1 and v2toQuoteResponseV2andtoQuoteResponseV1convert quote responses to required schema when neededtoQuoteMetadataV2andtoQuoteMetadataV1convert quote metadata to required schema when neededtoNormalizedAmountsconverts atomic amounts to display-ready valuesExport
sumAmountshelper util for adding up fees or token amountsReferences
Implements https://consensyssoftware.atlassian.net/browse/SWAPS-4546
Checklist
Note
Medium Risk
Changes quote shape conversion and fee/amount math used in swap/bridge UI; incorrect coercion could show wrong amounts or fees, but scope is bridge-controller with heavy test coverage and no auth/data-store changes.
Overview
Adds bidirectional coercion between bridge
QuoteResponsev1 and v2 so clients can migrate without breaking older consumers.toQuoteResponseV2maps flat v1 fields (srcTokenAmount,srcAsset,bridgeId, etc.) into nested v2src/dest, arrayfeeData, andprotocols/aggregator, including adjusting src amount when tx/metabridge fees apply (unlessintent).toQuoteResponseV1is the deprecated inverse for backwards compatibility.Metadata is bridged across shapes:
toQuoteMetadataV1/toQuoteMetadataV2extract or project legacyQuoteMetadataonto v2 partial quotes;toNormalizedAmountsfillsnormalizedAmountfields from atomic values.mergeQuoteMetadatanow branches on v1 vs v2—v1 still lodash-merges legacy fields; v2 merges normalized amounts, v2-shaped metadata, and legacy fields for client testing.Number helpers: renames
calcTokenAmount→calcNormalizedTokenAmount, addscalcAtomicTokenAmount, and exportssumAmountsfor aggregating fee/token amounts (same asset for atomic sums). New coercers, metadata helpers, andsumAmountsare exported from the package entrypoint; changelog documents the additions.Reviewed by Cursor Bugbot for commit 9e07537. Bugbot is set up for automated code reviews on this repo. Configure here.