@metamask-previews/bridge-status-controller 75.4.0-preview-ea6a28c61 → 75.4.0-preview-e12b5ece6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,99 +3,6 @@ import { TransactionStatus, TransactionType } from "@metamask/transaction-contro
3
3
  import { BigNumber } from "bignumber.js";
4
4
  import { calcActualGasUsed } from "./gas.mjs";
5
5
  import { getActualBridgeReceivedAmount, getActualSwapReceivedAmount } from "./swap-received-amount.mjs";
6
- /**
7
- * Classify a thrown value from submit (sign/broadcast) catch paths.
8
- *
9
- * @param error - The thrown value from submit.
10
- * @returns The Mixpanel `error_code`.
11
- */
12
- export const getSubmitErrorCode = (error) => {
13
- if (error === undefined || error === null) {
14
- return SwapBridgeErrorCode.MissingErrorObject;
15
- }
16
- if (error instanceof Error) {
17
- return SwapBridgeErrorCode.Unknown;
18
- }
19
- return SwapBridgeErrorCode.NonErrorRejection;
20
- };
21
- /**
22
- * @param sourceHash - Source tx hash if known at emit time.
23
- * @param destinationHash - Destination tx hash if known at emit time.
24
- * @returns Boolean hash-presence properties.
25
- */
26
- export const getHashPresenceProperties = (sourceHash, destinationHash) => {
27
- return {
28
- source_hash_present: Boolean(sourceHash),
29
- destination_hash_present: Boolean(destinationHash),
30
- };
31
- };
32
- /**
33
- * Prefer destination_execution over source_execution over poll.
34
- *
35
- * @param hashPresence - Hash presence at emit time.
36
- * @returns The Mixpanel `failure_phase` for a status/polling Failed event.
37
- */
38
- export const getStatusFailurePhase = (hashPresence) => {
39
- if (hashPresence.destination_hash_present) {
40
- return FailurePhase.DestinationExecution;
41
- }
42
- if (hashPresence.source_hash_present) {
43
- return FailurePhase.SourceExecution;
44
- }
45
- return FailurePhase.Poll;
46
- };
47
- /**
48
- * Align `failure_phase` with combined hash presence without turning a
49
- * no-hash `broadcast` failure into `poll`.
50
- *
51
- * @param phase - Phase from the emitting path.
52
- * @param hashPresence - Combined history + caller hash flags.
53
- * @returns The Mixpanel `failure_phase`.
54
- */
55
- export const promoteFailurePhase = (phase, hashPresence) => {
56
- if (hashPresence.destination_hash_present) {
57
- return FailurePhase.DestinationExecution;
58
- }
59
- if (hashPresence.source_hash_present &&
60
- (phase === FailurePhase.Broadcast ||
61
- phase === FailurePhase.Poll ||
62
- phase === FailurePhase.Unknown)) {
63
- return FailurePhase.SourceExecution;
64
- }
65
- return phase;
66
- };
67
- /**
68
- * Mixpanel properties for Failed events in the `broadcast` phase (no tx hash yet).
69
- *
70
- * @param error - The thrown value from the submit/broadcast catch.
71
- * @returns Phase, error code, and hash-presence flags.
72
- */
73
- export const getBroadcastFailureProperties = (error) => {
74
- return {
75
- failure_phase: FailurePhase.Broadcast,
76
- error_code: getSubmitErrorCode(error),
77
- source_hash_present: false,
78
- destination_hash_present: false,
79
- };
80
- };
81
- /**
82
- * Mixpanel properties for Failed events derived from history hashes.
83
- *
84
- * Used for poll Failed and TransactionController Failed once a history
85
- * item exists. Not poll-only.
86
- *
87
- * @param sourceHash - Source tx hash from history if known.
88
- * @param destinationHash - Destination tx hash from history if known.
89
- * @returns Phase, error code, and hash-presence flags.
90
- */
91
- export const getFailurePropertiesFromHistory = (sourceHash, destinationHash) => {
92
- const hashPresence = getHashPresenceProperties(sourceHash, destinationHash);
93
- return {
94
- ...hashPresence,
95
- failure_phase: getStatusFailurePhase(hashPresence),
96
- error_code: SwapBridgeErrorCode.StatusFailedWithoutReason,
97
- };
98
- };
99
6
  export const getTxStatusesFromHistory = ({ status, hasApprovalTx, approvalTxId, quote, }) => {
100
7
  const source_transaction = status.srcChain.txHash
101
8
  ? StatusTypes.COMPLETE
@@ -324,13 +231,76 @@ export const getEVMTxPropertiesFromTransactionMeta = (transactionMeta, account)
324
231
  usd_actual_gas: 0,
325
232
  action_type: MetricsActionType.SWAPBRIDGE_V1,
326
233
  ...(transactionMeta.batchId ? { batch_id: transactionMeta.batchId } : {}),
327
- ...getHashPresenceProperties(transactionMeta.hash, undefined),
328
- failure_phase: transactionMeta.hash
329
- ? FailurePhase.SourceExecution
330
- : FailurePhase.Broadcast,
331
- error_code: transactionMeta.error
332
- ? SwapBridgeErrorCode.Unknown
333
- : SwapBridgeErrorCode.MissingErrorObject,
234
+ };
235
+ };
236
+ /**
237
+ * Classify a thrown value from submit (sign/broadcast) catch paths.
238
+ *
239
+ * @param error - The thrown value from submit.
240
+ * @returns The Mixpanel `error_code`.
241
+ */
242
+ export const getSubmitErrorCode = (error) => {
243
+ if (error === undefined || error === null) {
244
+ return SwapBridgeErrorCode.MissingErrorObject;
245
+ }
246
+ if (error instanceof Error) {
247
+ return SwapBridgeErrorCode.Unknown;
248
+ }
249
+ return SwapBridgeErrorCode.NonErrorRejection;
250
+ };
251
+ /**
252
+ * @param sourceHash - Source tx hash if known at emit time.
253
+ * @param destinationHash - Destination tx hash if known at emit time.
254
+ * @returns Boolean hash-presence properties.
255
+ */
256
+ export const getHashPresenceProperties = (sourceHash, destinationHash) => {
257
+ return {
258
+ source_hash_present: Boolean(sourceHash),
259
+ destination_hash_present: Boolean(destinationHash),
260
+ };
261
+ };
262
+ /**
263
+ * Prefer destination_execution over source_execution over poll.
264
+ *
265
+ * @param hashPresence - Hash presence at emit time.
266
+ * @returns The Mixpanel `failure_phase` for a status/polling Failed event.
267
+ */
268
+ export const getStatusFailurePhase = (hashPresence) => {
269
+ if (hashPresence.destination_hash_present) {
270
+ return FailurePhase.DestinationExecution;
271
+ }
272
+ if (hashPresence.source_hash_present) {
273
+ return FailurePhase.SourceExecution;
274
+ }
275
+ return FailurePhase.Poll;
276
+ };
277
+ /**
278
+ * Telemetry for Failed events emitted from the submit catch (no tx hash yet).
279
+ *
280
+ * @param error - The thrown value from submit.
281
+ * @returns Phase, error code, and hash-presence flags.
282
+ */
283
+ export const getSubmitFailureTelemetry = (error) => {
284
+ return {
285
+ failure_phase: FailurePhase.Broadcast,
286
+ error_code: getSubmitErrorCode(error),
287
+ source_hash_present: false,
288
+ destination_hash_present: false,
289
+ };
290
+ };
291
+ /**
292
+ * Telemetry for Failed events derived from a status poll.
293
+ *
294
+ * @param sourceHash - Source tx hash if known.
295
+ * @param destinationHash - Destination tx hash if known.
296
+ * @returns Phase, error code, and hash-presence flags.
297
+ */
298
+ export const getStatusFailureTelemetry = (sourceHash, destinationHash) => {
299
+ const hashPresence = getHashPresenceProperties(sourceHash, destinationHash);
300
+ return {
301
+ ...hashPresence,
302
+ failure_phase: getStatusFailurePhase(hashPresence),
303
+ error_code: SwapBridgeErrorCode.StatusFailedWithoutReason,
334
304
  };
335
305
  };
336
306
  //# sourceMappingURL=metrics.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.mjs","sourceRoot":"","sources":["../../src/utils/metrics.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,kBAAkB,EAClB,SAAS,EACT,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,sBAAsB,EACtB,iBAAiB,EACjB,eAAe,EACf,2BAA2B,EAC3B,SAAS,EACT,0BAA0B,EAC1B,YAAY,EACZ,mBAAmB,EACpB,oCAAoC;AAerC,OAAO,EACL,iBAAiB,EACjB,eAAe,EAChB,yCAAyC;AAG1C,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAGzC,OAAO,EAAE,iBAAiB,EAAE,kBAAiB;AAC7C,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAC5B,mCAAkC;AAEnC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAc,EAAuB,EAAE;IACxE,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAC1C,OAAO,mBAAmB,CAAC,kBAAkB,CAAC;IAChD,CAAC;IACD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,mBAAmB,CAAC,OAAO,CAAC;IACrC,CAAC;IACD,OAAO,mBAAmB,CAAC,iBAAiB,CAAC;AAC/C,CAAC,CAA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\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport type { AccountsControllerState } from '@metamask/accounts-controller';\nimport {\n StatusTypes,\n getAccountHardwareType,\n formatChainIdToHex,\n isEthUsdt,\n formatChainIdToCaip,\n formatProviderLabel,\n isCustomSlippage,\n getSwapType,\n formatAddressToAssetId,\n MetricsActionType,\n MetricsSwapType,\n MetaMetricsSwapsEventSource,\n FeatureId,\n UnifiedSwapBridgeEventName,\n FailurePhase,\n SwapBridgeErrorCode,\n} from '@metamask/bridge-controller';\nimport type {\n AccountHardwareType,\n QuoteFetchData,\n QuoteMetadata,\n QuoteResponseV1,\n TxStatusData,\n RequestParams,\n TradeData,\n RequestMetadata,\n BatchSellTradesResponse,\n RequiredEventContextFromClient,\n HashPresenceProperties,\n FailureTelemetryProperties,\n} from '@metamask/bridge-controller';\nimport {\n TransactionStatus,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { CaipAssetType, Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport type { BridgeHistoryItem } from '../types.js';\nimport { calcActualGasUsed } from './gas.js';\nimport {\n getActualBridgeReceivedAmount,\n getActualSwapReceivedAmount,\n} from './swap-received-amount.js';\n\n/**\n * Classify a thrown value from submit (sign/broadcast) catch paths.\n *\n * @param error - The thrown value from submit.\n * @returns The Mixpanel `error_code`.\n */\nexport const getSubmitErrorCode = (error: unknown): SwapBridgeErrorCode => {\n if (error === undefined || error === null) {\n return SwapBridgeErrorCode.MissingErrorObject;\n }\n if (error instanceof Error) {\n return SwapBridgeErrorCode.Unknown;\n }\n return SwapBridgeErrorCode.NonErrorRejection;\n};\n\n/**\n * @param sourceHash - Source tx hash if known at emit time.\n * @param destinationHash - Destination tx hash if known at emit time.\n * @returns Boolean hash-presence properties.\n */\nexport const getHashPresenceProperties = (\n sourceHash?: string | null,\n destinationHash?: string | null,\n): HashPresenceProperties => {\n return {\n source_hash_present: Boolean(sourceHash),\n destination_hash_present: Boolean(destinationHash),\n };\n};\n\n/**\n * Prefer destination_execution over source_execution over poll.\n *\n * @param hashPresence - Hash presence at emit time.\n * @returns The Mixpanel `failure_phase` for a status/polling Failed event.\n */\nexport const getStatusFailurePhase = (\n hashPresence: HashPresenceProperties,\n): FailurePhase => {\n if (hashPresence.destination_hash_present) {\n return FailurePhase.DestinationExecution;\n }\n if (hashPresence.source_hash_present) {\n return FailurePhase.SourceExecution;\n }\n return FailurePhase.Poll;\n};\n\n/**\n * Align `failure_phase` with combined hash presence without turning a\n * no-hash `broadcast` failure into `poll`.\n *\n * @param phase - Phase from the emitting path.\n * @param hashPresence - Combined history + caller hash flags.\n * @returns The Mixpanel `failure_phase`.\n */\nexport const promoteFailurePhase = (\n phase: FailurePhase,\n hashPresence: HashPresenceProperties,\n): FailurePhase => {\n if (hashPresence.destination_hash_present) {\n return FailurePhase.DestinationExecution;\n }\n if (\n hashPresence.source_hash_present &&\n (phase === FailurePhase.Broadcast ||\n phase === FailurePhase.Poll ||\n phase === FailurePhase.Unknown)\n ) {\n return FailurePhase.SourceExecution;\n }\n return phase;\n};\n\n/**\n * Mixpanel properties for Failed events in the `broadcast` phase (no tx hash yet).\n *\n * @param error - The thrown value from the submit/broadcast catch.\n * @returns Phase, error code, and hash-presence flags.\n */\nexport const getBroadcastFailureProperties = (\n error: unknown,\n): FailureTelemetryProperties => {\n return {\n failure_phase: FailurePhase.Broadcast,\n error_code: getSubmitErrorCode(error),\n source_hash_present: false,\n destination_hash_present: false,\n };\n};\n\n/**\n * Mixpanel properties for Failed events derived from history hashes.\n *\n * Used for poll Failed and TransactionController Failed once a history\n * item exists. Not poll-only.\n *\n * @param sourceHash - Source tx hash from history if known.\n * @param destinationHash - Destination tx hash from history if known.\n * @returns Phase, error code, and hash-presence flags.\n */\nexport const getFailurePropertiesFromHistory = (\n sourceHash?: string | null,\n destinationHash?: string | null,\n): FailureTelemetryProperties => {\n const hashPresence = getHashPresenceProperties(sourceHash, destinationHash);\n return {\n ...hashPresence,\n failure_phase: getStatusFailurePhase(hashPresence),\n error_code: SwapBridgeErrorCode.StatusFailedWithoutReason,\n };\n};\n\nexport const getTxStatusesFromHistory = ({\n status,\n hasApprovalTx,\n approvalTxId,\n quote,\n}: BridgeHistoryItem): TxStatusData => {\n const source_transaction = status.srcChain.txHash\n ? StatusTypes.COMPLETE\n : StatusTypes.PENDING;\n const destination_transaction = status.destChain?.txHash\n ? status.status\n : StatusTypes.PENDING;\n\n const hexChainId = formatChainIdToHex(quote.srcChainId);\n const isEthUsdtTx = isEthUsdt(hexChainId, quote.srcAsset.address);\n const allowance_reset_transaction = status.srcChain.txHash\n ? StatusTypes.COMPLETE\n : undefined;\n const approval_transaction = status.srcChain.txHash\n ? StatusTypes.COMPLETE\n : StatusTypes.PENDING;\n\n return {\n allowance_reset_transaction: isEthUsdtTx\n ? allowance_reset_transaction\n : undefined,\n approval_transaction:\n hasApprovalTx || approvalTxId ? approval_transaction : undefined,\n source_transaction,\n destination_transaction:\n status.status === StatusTypes.FAILED\n ? StatusTypes.FAILED\n : destination_transaction,\n };\n};\n\n/**\n * Calculate the properties for a finalized transaction event based on the txHistory\n * and txMeta\n *\n * @param historyItem - The bridge history item\n * @param txMeta - The transaction meta from the TransactionController\n * @param approvalTxMeta - The approval transaction meta from the TransactionController\n * @returns The properties for the finalized transaction\n */\nexport const getFinalizedTxProperties = (\n historyItem: BridgeHistoryItem,\n txMeta?: TransactionMeta,\n approvalTxMeta?: TransactionMeta,\n) => {\n const startTime =\n approvalTxMeta?.submittedTime ??\n txMeta?.submittedTime ??\n historyItem.startTime;\n const completionTime =\n txMeta?.type === TransactionType.swap\n ? txMeta?.time\n : historyItem.completionTime;\n\n const actualGas = calcActualGasUsed(\n historyItem,\n txMeta?.txReceipt,\n approvalTxMeta?.txReceipt,\n );\n\n const actualReturn =\n txMeta?.type === TransactionType.swap\n ? getActualSwapReceivedAmount(historyItem, actualGas, txMeta)\n : getActualBridgeReceivedAmount(historyItem);\n\n const quotedVsUsedGasRatio =\n historyItem.pricingData?.quotedGasAmount && actualGas?.amount\n ? new BigNumber(historyItem.pricingData.quotedGasAmount)\n .multipliedBy(new BigNumber(10).pow(18))\n .div(actualGas.amount)\n .toNumber()\n : 0;\n\n const quoteVsExecutionRatio =\n historyItem.pricingData?.quotedReturnInUsd && actualReturn?.usd\n ? new BigNumber(historyItem.pricingData.quotedReturnInUsd)\n .div(actualReturn.usd)\n .toNumber()\n : 0;\n\n return {\n actual_time_minutes:\n completionTime && startTime ? (completionTime - startTime) / 60000 : 0,\n usd_actual_return: Number(actualReturn?.usd ?? 0),\n usd_actual_gas: actualGas?.usd ?? 0,\n quote_vs_execution_ratio: quoteVsExecutionRatio,\n quoted_vs_used_gas_ratio: quotedVsUsedGasRatio,\n };\n};\n\nexport const getRequestParamFromHistory = (\n historyItem: BridgeHistoryItem,\n): RequestParams => {\n return {\n chain_id_source: formatChainIdToCaip(historyItem.quote.srcChainId),\n token_symbol_source: historyItem.quote.srcAsset.symbol,\n token_address_source: historyItem.quote.srcAsset.assetId,\n chain_id_destination: formatChainIdToCaip(historyItem.quote.destChainId),\n token_symbol_destination: historyItem.quote.destAsset.symbol,\n token_address_destination: historyItem.quote.destAsset.assetId,\n token_security_type_destination:\n historyItem.tokenSecurityTypeDestination ?? null,\n };\n};\n\nexport const getTradeDataFromQuote = (\n quoteResponse: QuoteResponseV1 & QuoteMetadata,\n batchSellTrades?: BatchSellTradesResponse | null,\n): TradeData => {\n return {\n usd_quoted_gas: Number(quoteResponse.gasFee?.total?.usd ?? 0),\n gas_included:\n quoteResponse.quote.gasIncluded ?? batchSellTrades?.gasIncluded ?? false,\n gas_included_7702:\n quoteResponse.quote.gasIncluded7702 ??\n batchSellTrades?.gasIncluded7702 ??\n false,\n provider: formatProviderLabel(quoteResponse.quote),\n quoted_time_minutes: Number(\n quoteResponse.estimatedProcessingTimeInSeconds / 60,\n ),\n usd_quoted_return: Number(quoteResponse?.adjustedReturn?.usd ?? 0),\n };\n};\n\nexport const getPriceImpactFromQuote = (\n quote: QuoteResponseV1['quote'],\n): Pick<QuoteFetchData, 'price_impact'> => {\n return { price_impact: Number(quote.priceData?.priceImpact ?? '0') };\n};\n\n/**\n * Before the tx is confirmed, its data is not available in txHistory\n * The quote is used to populate event properties before confirmation\n *\n * @param quoteResponse - The quote response\n * @param isStxEnabled - Whether smart transactions are enabled on the client, for example the getSmartTransactionsEnabled selector value from the extension\n * @param accountHardwareType - The hardware wallet type used to submit the tx, or null if not a hardware wallet\n * @param location - The entry point from which the user initiated the swap or bridge (e.g. Main View, Token View, Trending Explore)\n * @param abTests - Legacy A/B test context for `ab_tests` (backward compatibility)\n * @param activeAbTests - New A/B test context for `active_ab_tests` (migration target)\n * @param tokenSecurityTypeDestination - The security classification of the destination token, supplied by the client (e.g. from token security/scanning data). Pass `null` when no security data is available.\n * @param batchSellTrades - The batch sell trades response\n * @param batchId - The batch ID of the transaction batch.\n * @param quotesReceivedContext - The client context captured when quotes were received.\n * @returns The properties for the pre-confirmation event\n */\nexport const getPreConfirmationPropertiesFromQuote = (\n quoteResponse: QuoteResponseV1 & QuoteMetadata,\n isStxEnabled: boolean,\n accountHardwareType: AccountHardwareType,\n location?: MetaMetricsSwapsEventSource,\n abTests?: Record<string, string>,\n activeAbTests?: { key: string; value: string }[],\n tokenSecurityTypeDestination?: string | null,\n batchSellTrades?: BatchSellTradesResponse | null,\n batchId?: Hex,\n quotesReceivedContext?: RequiredEventContextFromClient[UnifiedSwapBridgeEventName.QuotesReceived],\n) => {\n const { quote } = quoteResponse;\n return {\n ...getPriceImpactFromQuote(quote),\n ...getTradeDataFromQuote(quoteResponse, batchSellTrades),\n chain_id_source: formatChainIdToCaip(quote.srcChainId),\n token_symbol_source: quote.srcAsset.symbol,\n token_address_source: quote.srcAsset.assetId,\n chain_id_destination: formatChainIdToCaip(quote.destChainId),\n token_symbol_destination: quote.destAsset.symbol,\n token_address_destination: quote.destAsset.assetId,\n token_security_type_destination: tokenSecurityTypeDestination ?? null,\n account_hardware_type: accountHardwareType,\n is_hardware_wallet: accountHardwareType !== null,\n swap_type: getSwapType(\n quoteResponse.quote.srcChainId,\n quoteResponse.quote.destChainId,\n ),\n usd_amount_source: Number(quoteResponse?.sentAmount?.usd ?? 0),\n stx_enabled: isStxEnabled,\n action_type: MetricsActionType.SWAPBRIDGE_V1,\n slippage_limit:\n quotesReceivedContext?.slippage_limit ?? quote.slippage ?? 0,\n custom_slippage: quotesReceivedContext?.custom_slippage ?? false,\n location,\n ...(abTests &&\n Object.keys(abTests).length > 0 && {\n ab_tests: abTests,\n }),\n ...(activeAbTests &&\n activeAbTests.length > 0 && {\n active_ab_tests: activeAbTests,\n }),\n ...(batchId ? { batch_id: batchId } : {}),\n feature_id: quoteResponse.featureId ?? FeatureId.UNIFIED_SWAP_BRIDGE,\n };\n};\n\nexport const getTradeDataFromHistory = (\n historyItem: BridgeHistoryItem,\n): TradeData => {\n return {\n usd_quoted_gas: Number(historyItem.pricingData?.quotedGasInUsd ?? 0),\n gas_included: historyItem.quote.gasIncluded ?? false,\n gas_included_7702: historyItem.quote.gasIncluded7702 ?? false,\n provider: formatProviderLabel(historyItem.quote),\n quoted_time_minutes: Number(\n historyItem.estimatedProcessingTimeInSeconds / 60,\n ),\n usd_quoted_return: Number(historyItem.pricingData?.quotedReturnInUsd ?? 0),\n };\n};\n\nexport const getRequestMetadataFromHistory = (\n historyItem: BridgeHistoryItem,\n account?: AccountsControllerState['internalAccounts']['accounts'][string],\n): RequestMetadata => {\n const {\n quote,\n slippagePercentage,\n isStxEnabled,\n customSlippage,\n batchSellData,\n featureId,\n } = historyItem;\n const accountHardwareType = getAccountHardwareType(account);\n const isBatchSell =\n Boolean(batchSellData) || featureId === FeatureId.BATCH_SELL;\n const isUnifiedSwapBridge =\n featureId === undefined || featureId === FeatureId.UNIFIED_SWAP_BRIDGE;\n let inferredCustomSlippage = false;\n if (isBatchSell) {\n inferredCustomSlippage = isCustomSlippage(slippagePercentage ?? 0);\n } else if (!isUnifiedSwapBridge) {\n inferredCustomSlippage = isCustomSlippage(slippagePercentage);\n }\n\n return {\n slippage_limit: slippagePercentage ?? 0,\n custom_slippage: customSlippage ?? inferredCustomSlippage,\n usd_amount_source: Number(historyItem.pricingData?.amountSentInUsd ?? 0),\n swap_type: getSwapType(quote.srcChainId, quote.destChainId),\n account_hardware_type: accountHardwareType,\n is_hardware_wallet: accountHardwareType !== null,\n stx_enabled: isStxEnabled ?? false,\n security_warnings: [],\n };\n};\n\n/**\n * Get the properties for a swap transaction that is not in the txHistory\n *\n * @param transactionMeta - The transaction meta\n * @param account - The account that submitted the transaction\n * @returns The properties for the swap transaction\n */\nexport const getEVMTxPropertiesFromTransactionMeta = (\n transactionMeta: TransactionMeta,\n account?: AccountsControllerState['internalAccounts']['accounts'][string],\n) => {\n const accountHardwareType = getAccountHardwareType(account);\n\n return {\n source_transaction: [\n TransactionStatus.failed,\n TransactionStatus.dropped,\n TransactionStatus.rejected,\n ].includes(transactionMeta.status)\n ? StatusTypes.FAILED\n : StatusTypes.COMPLETE,\n error_message: [\n `Transaction ${transactionMeta.status}`,\n transactionMeta.error?.message,\n ]\n .filter(Boolean)\n .join('. '),\n chain_id_source: formatChainIdToCaip(transactionMeta.chainId),\n chain_id_destination: formatChainIdToCaip(transactionMeta.chainId),\n token_symbol_source: transactionMeta.sourceTokenSymbol ?? '',\n token_symbol_destination: transactionMeta.destinationTokenSymbol ?? '',\n usd_amount_source: 0,\n slippage_limit: 0,\n stx_enabled: false,\n token_address_source:\n formatAddressToAssetId(\n transactionMeta.sourceTokenAddress ?? '',\n transactionMeta.chainId,\n ) ?? ('' as CaipAssetType),\n token_address_destination:\n formatAddressToAssetId(\n transactionMeta.destinationTokenAddress ?? '',\n transactionMeta.chainId,\n ) ?? ('' as CaipAssetType),\n token_security_type_destination: null,\n custom_slippage: false,\n account_hardware_type: accountHardwareType,\n is_hardware_wallet: accountHardwareType !== null,\n swap_type:\n transactionMeta.type &&\n [TransactionType.swap, TransactionType.swapApproval].includes(\n transactionMeta.type,\n )\n ? MetricsSwapType.SINGLE\n : MetricsSwapType.CROSSCHAIN,\n security_warnings: [],\n price_impact: 0,\n usd_quoted_gas: 0,\n gas_included: false,\n gas_included_7702: false,\n quoted_time_minutes: 0,\n usd_quoted_return: 0,\n provider: '' as `${string}_${string}`,\n actual_time_minutes: 0,\n quote_vs_execution_ratio: 0,\n quoted_vs_used_gas_ratio: 0,\n usd_actual_return: 0,\n usd_actual_gas: 0,\n action_type: MetricsActionType.SWAPBRIDGE_V1,\n ...(transactionMeta.batchId ? { batch_id: transactionMeta.batchId } : {}),\n ...getHashPresenceProperties(transactionMeta.hash, undefined),\n failure_phase: transactionMeta.hash\n ? FailurePhase.SourceExecution\n : FailurePhase.Broadcast,\n error_code: transactionMeta.error\n ? SwapBridgeErrorCode.Unknown\n : SwapBridgeErrorCode.MissingErrorObject,\n };\n};\n"]}
1
+ {"version":3,"file":"metrics.mjs","sourceRoot":"","sources":["../../src/utils/metrics.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,kBAAkB,EAClB,SAAS,EACT,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,sBAAsB,EACtB,iBAAiB,EACjB,eAAe,EACf,2BAA2B,EAC3B,SAAS,EACT,0BAA0B,EAC1B,YAAY,EACZ,mBAAmB,EACpB,oCAAoC;AAerC,OAAO,EACL,iBAAiB,EACjB,eAAe,EAChB,yCAAyC;AAG1C,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAGzC,OAAO,EAAE,iBAAiB,EAAE,kBAAiB;AAC7C,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAC5B,mCAAkC;AAEnC,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,EACvC,MAAM,EACN,aAAa,EACb,YAAY,EACZ,KAAK,GACa,EAAgB,EAAE;IACpC,MAAM,kBAAkB,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM;QAC/C,CA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O,YAAY,CAAC,IAAI,CAAC;AAC3B,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,KAAc,EACc,EAAE;IAC9B,OAAO;QACL,aAAa,EAAE,YAAY,CAAC,SAAS;QACrC,UAAU,EAAE,kBAAkB,CAAC,KAAK,CAAC;QACrC,mBAAmB,EAAE,KAAK;QAC1B,wBAAwB,EAAE,KAAK;KAChC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,UAA0B,EAC1B,eAA+B,EACH,EAAE;IAC9B,MAAM,YAAY,GAAG,yBAAyB,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;IAC5E,OAAO;QACL,GAAG,YAAY;QACf,aAAa,EAAE,qBAAqB,CAAC,YAAY,CAAC;QAClD,UAAU,EAAE,mBAAmB,CAAC,yBAAyB;KAC1D,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable camelcase */\n/* eslint-disable @typescript-eslint/naming-convention */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport type { AccountsControllerState } from '@metamask/accounts-controller';\nimport {\n StatusTypes,\n getAccountHardwareType,\n formatChainIdToHex,\n isEthUsdt,\n formatChainIdToCaip,\n formatProviderLabel,\n isCustomSlippage,\n getSwapType,\n formatAddressToAssetId,\n MetricsActionType,\n MetricsSwapType,\n MetaMetricsSwapsEventSource,\n FeatureId,\n UnifiedSwapBridgeEventName,\n FailurePhase,\n SwapBridgeErrorCode,\n} from '@metamask/bridge-controller';\nimport type {\n AccountHardwareType,\n QuoteFetchData,\n QuoteMetadata,\n QuoteResponseV1,\n TxStatusData,\n RequestParams,\n TradeData,\n RequestMetadata,\n BatchSellTradesResponse,\n RequiredEventContextFromClient,\n HashPresenceProperties,\n FailureTelemetryProperties,\n} from '@metamask/bridge-controller';\nimport {\n TransactionStatus,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { CaipAssetType, Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport type { BridgeHistoryItem } from '../types.js';\nimport { calcActualGasUsed } from './gas.js';\nimport {\n getActualBridgeReceivedAmount,\n getActualSwapReceivedAmount,\n} from './swap-received-amount.js';\n\nexport const getTxStatusesFromHistory = ({\n status,\n hasApprovalTx,\n approvalTxId,\n quote,\n}: BridgeHistoryItem): TxStatusData => {\n const source_transaction = status.srcChain.txHash\n ? StatusTypes.COMPLETE\n : StatusTypes.PENDING;\n const destination_transaction = status.destChain?.txHash\n ? status.status\n : StatusTypes.PENDING;\n\n const hexChainId = formatChainIdToHex(quote.srcChainId);\n const isEthUsdtTx = isEthUsdt(hexChainId, quote.srcAsset.address);\n const allowance_reset_transaction = status.srcChain.txHash\n ? StatusTypes.COMPLETE\n : undefined;\n const approval_transaction = status.srcChain.txHash\n ? StatusTypes.COMPLETE\n : StatusTypes.PENDING;\n\n return {\n allowance_reset_transaction: isEthUsdtTx\n ? allowance_reset_transaction\n : undefined,\n approval_transaction:\n hasApprovalTx || approvalTxId ? approval_transaction : undefined,\n source_transaction,\n destination_transaction:\n status.status === StatusTypes.FAILED\n ? StatusTypes.FAILED\n : destination_transaction,\n };\n};\n\n/**\n * Calculate the properties for a finalized transaction event based on the txHistory\n * and txMeta\n *\n * @param historyItem - The bridge history item\n * @param txMeta - The transaction meta from the TransactionController\n * @param approvalTxMeta - The approval transaction meta from the TransactionController\n * @returns The properties for the finalized transaction\n */\nexport const getFinalizedTxProperties = (\n historyItem: BridgeHistoryItem,\n txMeta?: TransactionMeta,\n approvalTxMeta?: TransactionMeta,\n) => {\n const startTime =\n approvalTxMeta?.submittedTime ??\n txMeta?.submittedTime ??\n historyItem.startTime;\n const completionTime =\n txMeta?.type === TransactionType.swap\n ? txMeta?.time\n : historyItem.completionTime;\n\n const actualGas = calcActualGasUsed(\n historyItem,\n txMeta?.txReceipt,\n approvalTxMeta?.txReceipt,\n );\n\n const actualReturn =\n txMeta?.type === TransactionType.swap\n ? getActualSwapReceivedAmount(historyItem, actualGas, txMeta)\n : getActualBridgeReceivedAmount(historyItem);\n\n const quotedVsUsedGasRatio =\n historyItem.pricingData?.quotedGasAmount && actualGas?.amount\n ? new BigNumber(historyItem.pricingData.quotedGasAmount)\n .multipliedBy(new BigNumber(10).pow(18))\n .div(actualGas.amount)\n .toNumber()\n : 0;\n\n const quoteVsExecutionRatio =\n historyItem.pricingData?.quotedReturnInUsd && actualReturn?.usd\n ? new BigNumber(historyItem.pricingData.quotedReturnInUsd)\n .div(actualReturn.usd)\n .toNumber()\n : 0;\n\n return {\n actual_time_minutes:\n completionTime && startTime ? (completionTime - startTime) / 60000 : 0,\n usd_actual_return: Number(actualReturn?.usd ?? 0),\n usd_actual_gas: actualGas?.usd ?? 0,\n quote_vs_execution_ratio: quoteVsExecutionRatio,\n quoted_vs_used_gas_ratio: quotedVsUsedGasRatio,\n };\n};\n\nexport const getRequestParamFromHistory = (\n historyItem: BridgeHistoryItem,\n): RequestParams => {\n return {\n chain_id_source: formatChainIdToCaip(historyItem.quote.srcChainId),\n token_symbol_source: historyItem.quote.srcAsset.symbol,\n token_address_source: historyItem.quote.srcAsset.assetId,\n chain_id_destination: formatChainIdToCaip(historyItem.quote.destChainId),\n token_symbol_destination: historyItem.quote.destAsset.symbol,\n token_address_destination: historyItem.quote.destAsset.assetId,\n token_security_type_destination:\n historyItem.tokenSecurityTypeDestination ?? null,\n };\n};\n\nexport const getTradeDataFromQuote = (\n quoteResponse: QuoteResponseV1 & QuoteMetadata,\n batchSellTrades?: BatchSellTradesResponse | null,\n): TradeData => {\n return {\n usd_quoted_gas: Number(quoteResponse.gasFee?.total?.usd ?? 0),\n gas_included:\n quoteResponse.quote.gasIncluded ?? batchSellTrades?.gasIncluded ?? false,\n gas_included_7702:\n quoteResponse.quote.gasIncluded7702 ??\n batchSellTrades?.gasIncluded7702 ??\n false,\n provider: formatProviderLabel(quoteResponse.quote),\n quoted_time_minutes: Number(\n quoteResponse.estimatedProcessingTimeInSeconds / 60,\n ),\n usd_quoted_return: Number(quoteResponse?.adjustedReturn?.usd ?? 0),\n };\n};\n\nexport const getPriceImpactFromQuote = (\n quote: QuoteResponseV1['quote'],\n): Pick<QuoteFetchData, 'price_impact'> => {\n return { price_impact: Number(quote.priceData?.priceImpact ?? '0') };\n};\n\n/**\n * Before the tx is confirmed, its data is not available in txHistory\n * The quote is used to populate event properties before confirmation\n *\n * @param quoteResponse - The quote response\n * @param isStxEnabled - Whether smart transactions are enabled on the client, for example the getSmartTransactionsEnabled selector value from the extension\n * @param accountHardwareType - The hardware wallet type used to submit the tx, or null if not a hardware wallet\n * @param location - The entry point from which the user initiated the swap or bridge (e.g. Main View, Token View, Trending Explore)\n * @param abTests - Legacy A/B test context for `ab_tests` (backward compatibility)\n * @param activeAbTests - New A/B test context for `active_ab_tests` (migration target)\n * @param tokenSecurityTypeDestination - The security classification of the destination token, supplied by the client (e.g. from token security/scanning data). Pass `null` when no security data is available.\n * @param batchSellTrades - The batch sell trades response\n * @param batchId - The batch ID of the transaction batch.\n * @param quotesReceivedContext - The client context captured when quotes were received.\n * @returns The properties for the pre-confirmation event\n */\nexport const getPreConfirmationPropertiesFromQuote = (\n quoteResponse: QuoteResponseV1 & QuoteMetadata,\n isStxEnabled: boolean,\n accountHardwareType: AccountHardwareType,\n location?: MetaMetricsSwapsEventSource,\n abTests?: Record<string, string>,\n activeAbTests?: { key: string; value: string }[],\n tokenSecurityTypeDestination?: string | null,\n batchSellTrades?: BatchSellTradesResponse | null,\n batchId?: Hex,\n quotesReceivedContext?: RequiredEventContextFromClient[UnifiedSwapBridgeEventName.QuotesReceived],\n) => {\n const { quote } = quoteResponse;\n return {\n ...getPriceImpactFromQuote(quote),\n ...getTradeDataFromQuote(quoteResponse, batchSellTrades),\n chain_id_source: formatChainIdToCaip(quote.srcChainId),\n token_symbol_source: quote.srcAsset.symbol,\n token_address_source: quote.srcAsset.assetId,\n chain_id_destination: formatChainIdToCaip(quote.destChainId),\n token_symbol_destination: quote.destAsset.symbol,\n token_address_destination: quote.destAsset.assetId,\n token_security_type_destination: tokenSecurityTypeDestination ?? null,\n account_hardware_type: accountHardwareType,\n is_hardware_wallet: accountHardwareType !== null,\n swap_type: getSwapType(\n quoteResponse.quote.srcChainId,\n quoteResponse.quote.destChainId,\n ),\n usd_amount_source: Number(quoteResponse?.sentAmount?.usd ?? 0),\n stx_enabled: isStxEnabled,\n action_type: MetricsActionType.SWAPBRIDGE_V1,\n slippage_limit:\n quotesReceivedContext?.slippage_limit ?? quote.slippage ?? 0,\n custom_slippage: quotesReceivedContext?.custom_slippage ?? false,\n location,\n ...(abTests &&\n Object.keys(abTests).length > 0 && {\n ab_tests: abTests,\n }),\n ...(activeAbTests &&\n activeAbTests.length > 0 && {\n active_ab_tests: activeAbTests,\n }),\n ...(batchId ? { batch_id: batchId } : {}),\n feature_id: quoteResponse.featureId ?? FeatureId.UNIFIED_SWAP_BRIDGE,\n };\n};\n\nexport const getTradeDataFromHistory = (\n historyItem: BridgeHistoryItem,\n): TradeData => {\n return {\n usd_quoted_gas: Number(historyItem.pricingData?.quotedGasInUsd ?? 0),\n gas_included: historyItem.quote.gasIncluded ?? false,\n gas_included_7702: historyItem.quote.gasIncluded7702 ?? false,\n provider: formatProviderLabel(historyItem.quote),\n quoted_time_minutes: Number(\n historyItem.estimatedProcessingTimeInSeconds / 60,\n ),\n usd_quoted_return: Number(historyItem.pricingData?.quotedReturnInUsd ?? 0),\n };\n};\n\nexport const getRequestMetadataFromHistory = (\n historyItem: BridgeHistoryItem,\n account?: AccountsControllerState['internalAccounts']['accounts'][string],\n): RequestMetadata => {\n const {\n quote,\n slippagePercentage,\n isStxEnabled,\n customSlippage,\n batchSellData,\n featureId,\n } = historyItem;\n const accountHardwareType = getAccountHardwareType(account);\n const isBatchSell =\n Boolean(batchSellData) || featureId === FeatureId.BATCH_SELL;\n const isUnifiedSwapBridge =\n featureId === undefined || featureId === FeatureId.UNIFIED_SWAP_BRIDGE;\n let inferredCustomSlippage = false;\n if (isBatchSell) {\n inferredCustomSlippage = isCustomSlippage(slippagePercentage ?? 0);\n } else if (!isUnifiedSwapBridge) {\n inferredCustomSlippage = isCustomSlippage(slippagePercentage);\n }\n\n return {\n slippage_limit: slippagePercentage ?? 0,\n custom_slippage: customSlippage ?? inferredCustomSlippage,\n usd_amount_source: Number(historyItem.pricingData?.amountSentInUsd ?? 0),\n swap_type: getSwapType(quote.srcChainId, quote.destChainId),\n account_hardware_type: accountHardwareType,\n is_hardware_wallet: accountHardwareType !== null,\n stx_enabled: isStxEnabled ?? false,\n security_warnings: [],\n };\n};\n\n/**\n * Get the properties for a swap transaction that is not in the txHistory\n *\n * @param transactionMeta - The transaction meta\n * @param account - The account that submitted the transaction\n * @returns The properties for the swap transaction\n */\nexport const getEVMTxPropertiesFromTransactionMeta = (\n transactionMeta: TransactionMeta,\n account?: AccountsControllerState['internalAccounts']['accounts'][string],\n) => {\n const accountHardwareType = getAccountHardwareType(account);\n\n return {\n source_transaction: [\n TransactionStatus.failed,\n TransactionStatus.dropped,\n TransactionStatus.rejected,\n ].includes(transactionMeta.status)\n ? StatusTypes.FAILED\n : StatusTypes.COMPLETE,\n error_message: [\n `Transaction ${transactionMeta.status}`,\n transactionMeta.error?.message,\n ]\n .filter(Boolean)\n .join('. '),\n chain_id_source: formatChainIdToCaip(transactionMeta.chainId),\n chain_id_destination: formatChainIdToCaip(transactionMeta.chainId),\n token_symbol_source: transactionMeta.sourceTokenSymbol ?? '',\n token_symbol_destination: transactionMeta.destinationTokenSymbol ?? '',\n usd_amount_source: 0,\n slippage_limit: 0,\n stx_enabled: false,\n token_address_source:\n formatAddressToAssetId(\n transactionMeta.sourceTokenAddress ?? '',\n transactionMeta.chainId,\n ) ?? ('' as CaipAssetType),\n token_address_destination:\n formatAddressToAssetId(\n transactionMeta.destinationTokenAddress ?? '',\n transactionMeta.chainId,\n ) ?? ('' as CaipAssetType),\n token_security_type_destination: null,\n custom_slippage: false,\n account_hardware_type: accountHardwareType,\n is_hardware_wallet: accountHardwareType !== null,\n swap_type:\n transactionMeta.type &&\n [TransactionType.swap, TransactionType.swapApproval].includes(\n transactionMeta.type,\n )\n ? MetricsSwapType.SINGLE\n : MetricsSwapType.CROSSCHAIN,\n security_warnings: [],\n price_impact: 0,\n usd_quoted_gas: 0,\n gas_included: false,\n gas_included_7702: false,\n quoted_time_minutes: 0,\n usd_quoted_return: 0,\n provider: '' as `${string}_${string}`,\n actual_time_minutes: 0,\n quote_vs_execution_ratio: 0,\n quoted_vs_used_gas_ratio: 0,\n usd_actual_return: 0,\n usd_actual_gas: 0,\n action_type: MetricsActionType.SWAPBRIDGE_V1,\n ...(transactionMeta.batchId ? { batch_id: transactionMeta.batchId } : {}),\n };\n};\n\n/**\n * Classify a thrown value from submit (sign/broadcast) catch paths.\n *\n * @param error - The thrown value from submit.\n * @returns The Mixpanel `error_code`.\n */\nexport const getSubmitErrorCode = (error: unknown): SwapBridgeErrorCode => {\n if (error === undefined || error === null) {\n return SwapBridgeErrorCode.MissingErrorObject;\n }\n if (error instanceof Error) {\n return SwapBridgeErrorCode.Unknown;\n }\n return SwapBridgeErrorCode.NonErrorRejection;\n};\n\n/**\n * @param sourceHash - Source tx hash if known at emit time.\n * @param destinationHash - Destination tx hash if known at emit time.\n * @returns Boolean hash-presence properties.\n */\nexport const getHashPresenceProperties = (\n sourceHash?: string | null,\n destinationHash?: string | null,\n): HashPresenceProperties => {\n return {\n source_hash_present: Boolean(sourceHash),\n destination_hash_present: Boolean(destinationHash),\n };\n};\n\n/**\n * Prefer destination_execution over source_execution over poll.\n *\n * @param hashPresence - Hash presence at emit time.\n * @returns The Mixpanel `failure_phase` for a status/polling Failed event.\n */\nexport const getStatusFailurePhase = (\n hashPresence: HashPresenceProperties,\n): FailurePhase => {\n if (hashPresence.destination_hash_present) {\n return FailurePhase.DestinationExecution;\n }\n if (hashPresence.source_hash_present) {\n return FailurePhase.SourceExecution;\n }\n return FailurePhase.Poll;\n};\n\n/**\n * Telemetry for Failed events emitted from the submit catch (no tx hash yet).\n *\n * @param error - The thrown value from submit.\n * @returns Phase, error code, and hash-presence flags.\n */\nexport const getSubmitFailureTelemetry = (\n error: unknown,\n): FailureTelemetryProperties => {\n return {\n failure_phase: FailurePhase.Broadcast,\n error_code: getSubmitErrorCode(error),\n source_hash_present: false,\n destination_hash_present: false,\n };\n};\n\n/**\n * Telemetry for Failed events derived from a status poll.\n *\n * @param sourceHash - Source tx hash if known.\n * @param destinationHash - Destination tx hash if known.\n * @returns Phase, error code, and hash-presence flags.\n */\nexport const getStatusFailureTelemetry = (\n sourceHash?: string | null,\n destinationHash?: string | null,\n): FailureTelemetryProperties => {\n const hashPresence = getHashPresenceProperties(sourceHash, destinationHash);\n return {\n ...hashPresence,\n failure_phase: getStatusFailurePhase(hashPresence),\n error_code: SwapBridgeErrorCode.StatusFailedWithoutReason,\n };\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/bridge-status-controller",
3
- "version": "75.4.0-preview-ea6a28c61",
3
+ "version": "75.4.0-preview-e12b5ece6",
4
4
  "description": "Manages bridge-related status fetching functionality for MetaMask",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -66,8 +66,8 @@
66
66
  "@metamask/profile-sync-controller": "^29.0.0",
67
67
  "@metamask/snaps-controllers": "^19.0.0",
68
68
  "@metamask/superstruct": "^3.4.1",
69
- "@metamask/transaction-controller": "^69.7.0",
70
- "@metamask/utils": "^11.11.0",
69
+ "@metamask/transaction-controller": "^69.8.0",
70
+ "@metamask/utils": "^11.12.0",
71
71
  "bignumber.js": "^9.1.2",
72
72
  "uuid": "^8.3.2"
73
73
  },