Skip to content

Commit fb079df

Browse files
authored
feat: add feature_id and batch_id to Unified SwapBridge events (MetaMask#8964)
## Explanation ### Metrics changes - Add new `Unified SwapBridge` event properties - `feature_id` (all events) - `batch_sell` (Submitted, Completed, Failed for BatchSell) - Publish Submitted/Completed/Failed events for quickBuy and batchSell features ### fetchQuotes changes - Make `featureId` a required param of `fetchQuotes` to identify callers - Update transaction-pay-controller's `fetchQuotes` call ### batch-sell submission changes - Pre-generate batchId and append it to batch-sell events - Pass batchId to transaction-controller to propagate it to the tx meta Client-side updates - run `yarn lint:tsc` to see where `feature_id` needs to be added, then fix the type errors - search for `fetchQuotes` usages and add FeatureId <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> Fixes https://consensyssoftware.atlassian.net/browse/SWAPS-4468 ## 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](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Breaking changes to `fetchQuotes` and required `feature_id` on all clients and internal callers; transaction submission and metrics behavior changed for batch sell and feature-gated status events. > > **Overview** > Standardizes **Unified SwapBridge** analytics with a required **`feature_id`** on every event and renames/expands **`FeatureId`** values to Segment-style strings (e.g. `unified_swap_bridge`, `quick_buy_follow_trading`, `batch_sell`). > > **Breaking API changes in `bridge-controller`:** callers must pass **`feature_id`** in quote/metrics context and supply a **`FeatureId`** when calling **`fetchQuotes`** (no longer optional). Quote streaming and validation-failure tracking thread **`feature_id`** through fetch/SSE paths and onto quote objects. > > **`bridge-status-controller`:** pre-generates **`batch_id`** for batch sell via **`generateBatchId`**, passes it into transaction batches and includes it on **Submitted / Completed / Failed** events. Status metrics are emitted for **`ALLOWED_FEATURE_IDS_FOR_STATUS_EVENTS`** (unified swap/bridge, quick buy variants, batch sell) instead of broadly suppressing events when a feature id is set (e.g. perps). > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 83d02b0. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 569e061 commit fb079df

35 files changed

Lines changed: 678 additions & 304 deletions

packages/bridge-controller/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `QUICK_BUY_FOLLOW_TRADING`, `QUICK_BUY_TOKEN_DETAILS`, `BATCH_SELL` and `UNIFIED_SWAP_BRIDGE` to FeatureId enum ([#8964](https://github.com/MetaMask/core/pull/8964))
13+
- Update metrics schema with `batch_id` property ([#8964](https://github.com/MetaMask/core/pull/8964))
14+
1015
### Changed
1116

17+
- **BREAKING**: require all events to have the `feature_id` property ([#8964](https://github.com/MetaMask/core/pull/8964))
18+
- **BREAKING**: require FeatureId argument when calling `BridgeController:fetchQuotes` ([#8964](https://github.com/MetaMask/core/pull/8964))
19+
- Rename FeatureIds to match segment property conventions ([#8964](https://github.com/MetaMask/core/pull/8964))
20+
- `quickBuy` to `quick_buy_follow_trading` and `quick_buy_token_details`
21+
- `dappSwap` to `dapp_swap`
1222
- Bump `@metamask/accounts-controller` from `^39.0.0` to `^39.0.1` ([#9058](https://github.com/MetaMask/core/pull/9058))
1323
- Bump `@metamask/assets-controller` from `^8.3.2` to `^8.3.3` ([#9058](https://github.com/MetaMask/core/pull/9058))
1424
- Bump `@metamask/assets-controllers` from `^108.5.0` to `^108.6.0` ([#9058](https://github.com/MetaMask/core/pull/9058))

packages/bridge-controller/src/__snapshots__/bridge-controller.sse.batch.test.ts.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes s
6666
"Unified SwapBridge Input Changed",
6767
{
6868
"action_type": "swapbridge-v1",
69+
"feature_id": "batch_sell",
6970
"input": "chain_source",
7071
"input_value": "eip155:10",
7172
"location": "Main View",
@@ -75,6 +76,7 @@ exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes s
7576
"Unified SwapBridge Input Changed",
7677
{
7778
"action_type": "swapbridge-v1",
79+
"feature_id": "batch_sell",
7880
"input": "chain_destination",
7981
"input_value": "eip155:137",
8082
"location": "Main View",
@@ -84,6 +86,7 @@ exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes s
8486
"Unified SwapBridge Input Changed",
8587
{
8688
"action_type": "swapbridge-v1",
89+
"feature_id": "batch_sell",
8790
"input": "token_destination",
8891
"input_value": "eip155:137/erc20:0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
8992
"location": "Main View",
@@ -93,6 +96,7 @@ exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes s
9396
"Unified SwapBridge Input Changed",
9497
{
9598
"action_type": "swapbridge-v1",
99+
"feature_id": "batch_sell",
96100
"input": "slippage",
97101
"input_value": 0.5,
98102
"location": "Main View",
@@ -106,6 +110,7 @@ exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes s
106110
"chain_id_destination": "eip155:137",
107111
"chain_id_source": "eip155:10",
108112
"custom_slippage": true,
113+
"feature_id": "batch_sell",
109114
"has_sufficient_funds": true,
110115
"is_hardware_wallet": false,
111116
"location": "Main View",

packages/bridge-controller/src/__snapshots__/bridge-controller.sse.test.ts.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ exports[`BridgeController SSE should publish validation failures 4`] = `
2020
"lifi|trade.inputsToSign",
2121
"lifi|trade.raw_data_hex",
2222
],
23+
"feature_id": "unified_swap_bridge",
2324
"location": "Main View",
2425
"refresh_count": 1,
2526
"token_address_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:123d1",
@@ -36,6 +37,7 @@ exports[`BridgeController SSE should publish validation failures 4`] = `
3637
"failures": [
3738
"unknown|unknown",
3839
],
40+
"feature_id": "unified_swap_bridge",
3941
"location": "Main View",
4042
"refresh_count": 1,
4143
"token_address_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:123d1",
@@ -52,6 +54,7 @@ exports[`BridgeController SSE should publish validation failures 4`] = `
5254
"failures": [
5355
"unknown|quote",
5456
],
57+
"feature_id": "unified_swap_bridge",
5558
"location": "Main View",
5659
"refresh_count": 1,
5760
"token_address_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:123d1",
@@ -71,6 +74,7 @@ exports[`BridgeController SSE should replace all stale quotes after a refresh an
7174
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
7275
"chain_id_source": "eip155:1",
7376
"custom_slippage": true,
77+
"feature_id": "unified_swap_bridge",
7478
"has_sufficient_funds": true,
7579
"is_hardware_wallet": false,
7680
"location": "Main View",
@@ -99,6 +103,7 @@ exports[`BridgeController SSE should reset and refetch quotes after quote reques
99103
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
100104
"chain_id_source": "eip155:1",
101105
"custom_slippage": true,
106+
"feature_id": "unified_swap_bridge",
102107
"has_sufficient_funds": false,
103108
"is_hardware_wallet": false,
104109
"location": "Main View",
@@ -127,6 +132,7 @@ exports[`BridgeController SSE should reset quotes list if quote refresh fails 2`
127132
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
128133
"chain_id_source": "eip155:1",
129134
"custom_slippage": true,
135+
"feature_id": "unified_swap_bridge",
130136
"has_sufficient_funds": true,
131137
"is_hardware_wallet": false,
132138
"location": "Main View",
@@ -152,6 +158,7 @@ exports[`BridgeController SSE should reset quotes list if quote refresh fails 2`
152158
"chain_id_source": "eip155:1",
153159
"custom_slippage": true,
154160
"error_message": "Network error",
161+
"feature_id": "unified_swap_bridge",
155162
"has_sufficient_funds": true,
156163
"is_hardware_wallet": false,
157164
"location": "Main View",
@@ -213,6 +220,7 @@ exports[`BridgeController SSE should rethrow error from server 3`] = `
213220
"Unified SwapBridge Input Changed",
214221
{
215222
"action_type": "swapbridge-v1",
223+
"feature_id": "unified_swap_bridge",
216224
"input": "chain_source",
217225
"input_value": "eip155:1",
218226
"location": "Main View",
@@ -222,6 +230,7 @@ exports[`BridgeController SSE should rethrow error from server 3`] = `
222230
"Unified SwapBridge Input Changed",
223231
{
224232
"action_type": "swapbridge-v1",
233+
"feature_id": "unified_swap_bridge",
225234
"input": "chain_destination",
226235
"input_value": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
227236
"location": "Main View",
@@ -231,6 +240,7 @@ exports[`BridgeController SSE should rethrow error from server 3`] = `
231240
"Unified SwapBridge Input Changed",
232241
{
233242
"action_type": "swapbridge-v1",
243+
"feature_id": "unified_swap_bridge",
234244
"input": "token_destination",
235245
"input_value": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:123d1",
236246
"location": "Main View",
@@ -240,6 +250,7 @@ exports[`BridgeController SSE should rethrow error from server 3`] = `
240250
"Unified SwapBridge Input Changed",
241251
{
242252
"action_type": "swapbridge-v1",
253+
"feature_id": "unified_swap_bridge",
243254
"input": "slippage",
244255
"input_value": 0.5,
245256
"location": "Main View",
@@ -253,6 +264,7 @@ exports[`BridgeController SSE should rethrow error from server 3`] = `
253264
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
254265
"chain_id_source": "eip155:1",
255266
"custom_slippage": true,
267+
"feature_id": "unified_swap_bridge",
256268
"has_sufficient_funds": true,
257269
"is_hardware_wallet": false,
258270
"location": "Main View",
@@ -278,6 +290,7 @@ exports[`BridgeController SSE should rethrow error from server 3`] = `
278290
"chain_id_source": "eip155:1",
279291
"custom_slippage": true,
280292
"error_message": "Bridge-api error: timeout from server",
293+
"feature_id": "unified_swap_bridge",
281294
"has_sufficient_funds": true,
282295
"is_hardware_wallet": false,
283296
"location": "Main View",
@@ -339,6 +352,7 @@ exports[`BridgeController SSE should trigger quote polling if request is valid 2
339352
"Unified SwapBridge Input Changed",
340353
{
341354
"action_type": "swapbridge-v1",
355+
"feature_id": "unified_swap_bridge",
342356
"input": "chain_source",
343357
"input_value": "eip155:1",
344358
"location": "Main View",
@@ -348,6 +362,7 @@ exports[`BridgeController SSE should trigger quote polling if request is valid 2
348362
"Unified SwapBridge Input Changed",
349363
{
350364
"action_type": "swapbridge-v1",
365+
"feature_id": "unified_swap_bridge",
351366
"input": "chain_destination",
352367
"input_value": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
353368
"location": "Main View",
@@ -357,6 +372,7 @@ exports[`BridgeController SSE should trigger quote polling if request is valid 2
357372
"Unified SwapBridge Input Changed",
358373
{
359374
"action_type": "swapbridge-v1",
375+
"feature_id": "unified_swap_bridge",
360376
"input": "token_destination",
361377
"input_value": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:123d1",
362378
"location": "Main View",
@@ -366,6 +382,7 @@ exports[`BridgeController SSE should trigger quote polling if request is valid 2
366382
"Unified SwapBridge Input Changed",
367383
{
368384
"action_type": "swapbridge-v1",
385+
"feature_id": "unified_swap_bridge",
369386
"input": "slippage",
370387
"input_value": 0.5,
371388
"location": "Main View",
@@ -379,6 +396,7 @@ exports[`BridgeController SSE should trigger quote polling if request is valid 2
379396
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
380397
"chain_id_source": "eip155:1",
381398
"custom_slippage": true,
399+
"feature_id": "unified_swap_bridge",
382400
"has_sufficient_funds": true,
383401
"is_hardware_wallet": false,
384402
"location": "Main View",

0 commit comments

Comments
 (0)