feat: fetch batched swap quotes#8711
Conversation
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
| srcAsset: { address: srcTokenAddress, chainId: srcChainId }, | ||
| destAsset: { address: destTokenAddress, chainId: destChainId }, | ||
| }: QuoteResponse['quote']): string => { | ||
| return `${formatAddressToAssetId(srcTokenAddress, srcChainId)}-${formatAddressToAssetId(destTokenAddress, destChainId)}`.toLowerCase(); |
There was a problem hiding this comment.
Do we need to worry that non-EVM addresses can be case sensitive here?
There was a problem hiding this comment.
Good callout! removed the lowercasing
| export type BridgeControllerState = { | ||
| quoteRequest: Partial<GenericQuoteRequest>; | ||
| quoteRequest: Partial<GenericQuoteRequest>[]; | ||
| quotes: (QuoteResponse & L1GasFees & NonEvmFees)[]; |
There was a problem hiding this comment.
Interesting, so quotes is still a single dimensional array? For batch quote requests does each request get single or multiple quotes?
There was a problem hiding this comment.
Yea the backend returns a stream of all of them, which we match up with the quoteRequest as they arrive. There can be multiple quotes for each request but the batch selector only returns the best one for each
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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 c5cc1aa. Configure here.
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |

Explanation
This PR implements quote polling for batched swap requests
Changes
updateBridgeQuoteRequestnow takes 2 extra params: the quote request’s index and the total quoteRequestCount within the batch. no changes in how we are using this handler for regular swapsselectBatchSellQuotesselector returns the recommended quote for each quoteRequest, and aggregated amounts for display purposesisValidBatchSellQuoteRequestUsage
Minimal client examples
References
Fixes https://consensyssoftware.atlassian.net/browse/SWAPS-4443
Checklist
Note
Medium Risk
This is a breaking API/state-shape change (
quoteRequestbecomes an array) that touches quote polling/streaming, analytics properties, and exchange-rate lookup logic; regressions could affect quote fetching and refresh behavior across swaps/bridges.Overview
Adds BatchSell (batched swap) quote support by changing
quoteRequeststate and polling inputs from a single request to an array, allowing callers to update a specific request via newupdateBridgeQuoteRequestParams(…, quoteRequestIndex, quoteRequestCount)parameters.Quote fetching/streaming is updated to accept multiple requests: SSE uses a new
POST /getBatchQuoteStreampath when batching, tags incoming quotes withquoteRequestIndex, traces via new Sentry trace nameBatch Sell Quotes Fetched, and adjusts polling stop/refresh logic to continue as long as any request is sufficiently funded.Selectors and rate lookup are extended for batching: adds
selectBatchSellQuotes(per-request recommended quotes plus aggregated received/fee totals), switches exchange-rate selection toselectExchangeRateByAssetId, and exportsisValidBatchSellQuoteRequest; tests/snapshots are updated and a new SSE batch test is added.Reviewed by Cursor Bugbot for commit 9e2a7fa. Bugbot is set up for automated code reviews on this repo. Configure here.