@metamask/bridge-status-controller 69.0.0 → 70.0.1

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.
Files changed (130) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/dist/bridge-status-controller.cjs +115 -354
  3. package/dist/bridge-status-controller.cjs.map +1 -1
  4. package/dist/bridge-status-controller.d.cts +3 -5
  5. package/dist/bridge-status-controller.d.cts.map +1 -1
  6. package/dist/bridge-status-controller.d.mts +3 -5
  7. package/dist/bridge-status-controller.d.mts.map +1 -1
  8. package/dist/bridge-status-controller.intent.cjs +12 -25
  9. package/dist/bridge-status-controller.intent.cjs.map +1 -1
  10. package/dist/bridge-status-controller.intent.d.cts +3 -14
  11. package/dist/bridge-status-controller.intent.d.cts.map +1 -1
  12. package/dist/bridge-status-controller.intent.d.mts +3 -14
  13. package/dist/bridge-status-controller.intent.d.mts.map +1 -1
  14. package/dist/bridge-status-controller.intent.mjs +12 -25
  15. package/dist/bridge-status-controller.intent.mjs.map +1 -1
  16. package/dist/bridge-status-controller.mjs +118 -357
  17. package/dist/bridge-status-controller.mjs.map +1 -1
  18. package/dist/index.cjs +1 -3
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +0 -1
  21. package/dist/index.d.cts.map +1 -1
  22. package/dist/index.d.mts +0 -1
  23. package/dist/index.d.mts.map +1 -1
  24. package/dist/index.mjs +0 -1
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/types.cjs.map +1 -1
  27. package/dist/types.d.cts +11 -5
  28. package/dist/types.d.cts.map +1 -1
  29. package/dist/types.d.mts +11 -5
  30. package/dist/types.d.mts.map +1 -1
  31. package/dist/types.mjs.map +1 -1
  32. package/dist/utils/accounts.cjs +8 -0
  33. package/dist/utils/accounts.cjs.map +1 -0
  34. package/dist/utils/accounts.d.cts +36 -0
  35. package/dist/utils/accounts.d.cts.map +1 -0
  36. package/dist/utils/accounts.d.mts +36 -0
  37. package/dist/utils/accounts.d.mts.map +1 -0
  38. package/dist/utils/accounts.mjs +4 -0
  39. package/dist/utils/accounts.mjs.map +1 -0
  40. package/dist/utils/authentication.cjs +15 -0
  41. package/dist/utils/authentication.cjs.map +1 -0
  42. package/dist/utils/authentication.d.cts +3 -0
  43. package/dist/utils/authentication.d.cts.map +1 -0
  44. package/dist/utils/authentication.d.mts +3 -0
  45. package/dist/utils/authentication.d.mts.map +1 -0
  46. package/dist/utils/authentication.mjs +11 -0
  47. package/dist/utils/authentication.mjs.map +1 -0
  48. package/dist/utils/bridge-status.cjs +17 -1
  49. package/dist/utils/bridge-status.cjs.map +1 -1
  50. package/dist/utils/bridge-status.d.cts +8 -2
  51. package/dist/utils/bridge-status.d.cts.map +1 -1
  52. package/dist/utils/bridge-status.d.mts +8 -2
  53. package/dist/utils/bridge-status.d.mts.map +1 -1
  54. package/dist/utils/bridge-status.mjs +15 -0
  55. package/dist/utils/bridge-status.mjs.map +1 -1
  56. package/dist/utils/bridge.cjs +16 -0
  57. package/dist/utils/bridge.cjs.map +1 -0
  58. package/dist/utils/bridge.d.cts +10 -0
  59. package/dist/utils/bridge.d.cts.map +1 -0
  60. package/dist/utils/bridge.d.mts +10 -0
  61. package/dist/utils/bridge.d.mts.map +1 -0
  62. package/dist/utils/bridge.mjs +11 -0
  63. package/dist/utils/bridge.mjs.map +1 -0
  64. package/dist/utils/gas.cjs +1 -61
  65. package/dist/utils/gas.cjs.map +1 -1
  66. package/dist/utils/gas.d.cts +3 -26
  67. package/dist/utils/gas.d.cts.map +1 -1
  68. package/dist/utils/gas.d.mts +3 -26
  69. package/dist/utils/gas.d.mts.map +1 -1
  70. package/dist/utils/gas.mjs +0 -58
  71. package/dist/utils/gas.mjs.map +1 -1
  72. package/dist/utils/history.cjs +98 -0
  73. package/dist/utils/history.cjs.map +1 -0
  74. package/dist/utils/history.d.cts +22 -0
  75. package/dist/utils/history.d.cts.map +1 -0
  76. package/dist/utils/history.d.mts +22 -0
  77. package/dist/utils/history.d.mts.map +1 -0
  78. package/dist/utils/history.mjs +91 -0
  79. package/dist/utils/history.mjs.map +1 -0
  80. package/dist/utils/intent-api.cjs +41 -26
  81. package/dist/utils/intent-api.cjs.map +1 -1
  82. package/dist/utils/intent-api.d.cts +16 -3
  83. package/dist/utils/intent-api.d.cts.map +1 -1
  84. package/dist/utils/intent-api.d.mts +16 -3
  85. package/dist/utils/intent-api.d.mts.map +1 -1
  86. package/dist/utils/intent-api.mjs +38 -25
  87. package/dist/utils/intent-api.mjs.map +1 -1
  88. package/dist/utils/keyring.cjs +12 -0
  89. package/dist/utils/keyring.cjs.map +1 -0
  90. package/dist/utils/keyring.d.cts +8 -0
  91. package/dist/utils/keyring.d.cts.map +1 -0
  92. package/dist/utils/keyring.d.mts +8 -0
  93. package/dist/utils/keyring.d.mts.map +1 -0
  94. package/dist/utils/keyring.mjs +8 -0
  95. package/dist/utils/keyring.mjs.map +1 -0
  96. package/dist/utils/network.cjs +17 -0
  97. package/dist/utils/network.cjs.map +1 -0
  98. package/dist/utils/network.d.cts +5 -0
  99. package/dist/utils/network.d.cts.map +1 -0
  100. package/dist/utils/network.d.mts +5 -0
  101. package/dist/utils/network.d.mts.map +1 -0
  102. package/dist/utils/network.mjs +12 -0
  103. package/dist/utils/network.mjs.map +1 -0
  104. package/dist/utils/snaps.cjs +146 -1
  105. package/dist/utils/snaps.cjs.map +1 -1
  106. package/dist/utils/snaps.d.cts +48 -0
  107. package/dist/utils/snaps.d.cts.map +1 -1
  108. package/dist/utils/snaps.d.mts +48 -0
  109. package/dist/utils/snaps.d.mts.map +1 -1
  110. package/dist/utils/snaps.mjs +141 -0
  111. package/dist/utils/snaps.mjs.map +1 -1
  112. package/dist/utils/trace.cjs +31 -0
  113. package/dist/utils/trace.cjs.map +1 -0
  114. package/dist/utils/trace.d.cts +17 -0
  115. package/dist/utils/trace.d.cts.map +1 -0
  116. package/dist/utils/trace.d.mts +17 -0
  117. package/dist/utils/trace.d.mts.map +1 -0
  118. package/dist/utils/trace.mjs +26 -0
  119. package/dist/utils/trace.mjs.map +1 -0
  120. package/dist/utils/transaction.cjs +239 -184
  121. package/dist/utils/transaction.cjs.map +1 -1
  122. package/dist/utils/transaction.d.cts +85 -236
  123. package/dist/utils/transaction.d.cts.map +1 -1
  124. package/dist/utils/transaction.d.mts +85 -236
  125. package/dist/utils/transaction.d.mts.map +1 -1
  126. package/dist/utils/transaction.mjs +226 -176
  127. package/dist/utils/transaction.mjs.map +1 -1
  128. package/dist/utils/validators.d.cts +2 -2
  129. package/dist/utils/validators.d.mts +2 -2
  130. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"bridge-status.mjs","sourceRoot":"","sources":["../../src/utils/bridge-status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oCAAoC;AAE/D,OAAO,EAAE,WAAW,EAAE,8BAA8B;AAEpD,OAAO,EAAE,4BAA4B,EAAE,yBAAqB;AAC5D,OAAO,EAAE,mBAAmB,EAAE,yBAAqB;AASnD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,gBAAwB,EAAU,EAAE,CACrE,GAAG,gBAAgB,cAAc,CAAC;AAEpC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,aAAyC,EACvB,EAAE;IACpB,MAAM,EAAE,KAAK,EAAE,GAAG,oBAAoB,EAAE,GAAG,aAAa,CAAC;IAEzD,MAAM,6BAA6B,GAAG,MAAM,CAAC,WAAW,CACtD,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;QACzD,GAAG;QACH,KAAK,CAAC,QAAQ,EAAE;KACjB,CAAC,CAC+C,CAAC;IAEpD,MAAM,SAAS,GACb,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAEzD,OAAO;QACL,GAAG,6B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;QACrC,kBAAkB;KACnB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,KAAY,EACZ,SAAiB,EACW,EAAE;IAC9B,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACrE,OAAO;QACL,QAAQ;QACR,SAAS;QACT,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QAClB,UAAU;QACV,WAAW;QACX,KAAK;QACL,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC;KACxB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAC/C,QAAwC,EAC/B,EAAE;IACX,8DAA8D;IAC9D,2EAA2E;IAC3E,IAAI,QAAQ,EAAE,CAAC;QACb,sEAAsE;QACtE,MAAM,YAAY,GAChB,mBAAmB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;QAC1D,MAAM,oBAAoB,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC;QAEnE,IAAI,oBAAoB,GAAG,YAAY,EAAE,CAAC;YACxC,8CAA8C;YAC9C,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["import { getClientHeaders } from '@metamask/bridge-controller';\nimport type { Quote } from '@metamask/bridge-controller';\nimport { StructError } from '@metamask/superstruct';\n\nimport { validateBridgeStatusResponse } from './validators';\nimport { REFRESH_INTERVAL_MS } from '../constants';\nimport type {\n StatusResponse,\n StatusRequestWithSrcTxHash,\n StatusRequestDto,\n FetchFunction,\n BridgeHistoryItem,\n} from '../types';\n\nexport const getBridgeStatusUrl = (bridgeApiBaseUrl: string): string =>\n `${bridgeApiBaseUrl}/getTxStatus`;\n\nexport const getStatusRequestDto = (\n statusRequest: StatusRequestWithSrcTxHash,\n): StatusRequestDto => {\n const { quote, ...statusRequestNoQuote } = statusRequest;\n\n const statusRequestNoQuoteFormatted = Object.fromEntries(\n Object.entries(statusRequestNoQuote).map(([key, value]) => [\n key,\n value.toString(),\n ]),\n ) as unknown as Omit<StatusRequestDto, 'requestId'>;\n\n const requestId: { requestId: string } | Record<string, never> =\n quote?.requestId ? { requestId: quote.requestId } : {};\n\n return {\n ...statusRequestNoQuoteFormatted,\n ...requestId,\n };\n};\n\nexport const fetchBridgeTxStatus = async (\n statusRequest: StatusRequestWithSrcTxHash,\n clientId: string,\n jwt: string | undefined,\n fetchFn: FetchFunction,\n bridgeApiBaseUrl: string,\n): Promise<{ status: StatusResponse; validationFailures: string[] }> => {\n const statusRequestDto = getStatusRequestDto(statusRequest);\n const params = new URLSearchParams(statusRequestDto);\n\n // Fetch\n const url = `${getBridgeStatusUrl(bridgeApiBaseUrl)}?${params.toString()}`;\n\n const rawTxStatus: unknown = await fetchFn(url, {\n headers: getClientHeaders({ clientId, jwt }),\n });\n\n const validationFailures: string[] = [];\n\n try {\n validateBridgeStatusResponse(rawTxStatus);\n } catch (error) {\n // Build validation failure event properties\n if (error instanceof StructError) {\n error.failures().forEach(({ path }) => {\n const aggregatorId =\n (rawTxStatus as StatusResponse)?.bridge ??\n (statusRequest.bridge || statusRequest.bridgeId) ??\n ('unknown' as string);\n const pathString = path?.join('.') || 'unknown';\n validationFailures.push([aggregatorId, pathString].join('|'));\n });\n }\n }\n return {\n status: rawTxStatus as StatusResponse,\n validationFailures,\n };\n};\n\nexport const getStatusRequestWithSrcTxHash = (\n quote: Quote,\n srcTxHash: string,\n): StatusRequestWithSrcTxHash => {\n const { bridgeId, bridges, srcChainId, destChainId, refuel } = quote;\n return {\n bridgeId,\n srcTxHash,\n bridge: bridges[0],\n srcChainId,\n destChainId,\n quote,\n refuel: Boolean(refuel),\n };\n};\n\nexport const shouldSkipFetchDueToFetchFailures = (\n attempts?: BridgeHistoryItem['attempts'],\n): boolean => {\n // If there's an attempt, it means we've failed at least once,\n // so we need to check if we need to wait longer due to exponential backoff\n if (attempts) {\n // Calculate exponential backoff delay: base interval * 2^(attempts-1)\n const backoffDelay =\n REFRESH_INTERVAL_MS * Math.pow(2, attempts.counter - 1);\n const timeSinceLastAttempt = Date.now() - attempts.lastAttemptTime;\n\n if (timeSinceLastAttempt < backoffDelay) {\n // Not enough time has passed, skip this fetch\n return true;\n }\n }\n return false;\n};\n"]}
1
+ {"version":3,"file":"bridge-status.mjs","sourceRoot":"","sources":["../../src/utils/bridge-status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oCAAoC;AAE/D,OAAO,EAAE,WAAW,EAAE,8BAA8B;AAEpD,OAAO,EAAE,4BAA4B,EAAE,yBAAqB;AAC5D,OAAO,EAAE,mBAAmB,EAAE,yBAAqB;AAUnD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,gBAAwB,EAAU,EAAE,CACrE,GAAG,gBAAgB,cAAc,CAAC;AAEpC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,aAAyC,EACvB,EAAE;IACpB,MAAM,EAAE,KAAK,EAAE,GAAG,oBAAoB,EAAE,GAAG,aAAa,CAAC;IAEzD,MAAM,6BAA6B,GAAG,MAAM,CAAC,WAAW,CACtD,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;QACzD,GAAG;QACH,KAAK,CAAC,QAAQ,EAAE;KACjB,CAAC,CAC+C,CAAC;IAEpD,MAAM,SAAS,GACb,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAEzD,OAAO;QACL,GAAG,6BAA6B;QAChC,GAAG,SAAS;KACb,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC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,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { getClientHeaders } from '@metamask/bridge-controller';\nimport type { Quote, QuoteResponse } from '@metamask/bridge-controller';\nimport { StructError } from '@metamask/superstruct';\n\nimport { validateBridgeStatusResponse } from './validators';\nimport { REFRESH_INTERVAL_MS } from '../constants';\nimport type {\n StatusResponse,\n StatusRequestWithSrcTxHash,\n StatusRequestDto,\n FetchFunction,\n BridgeHistoryItem,\n StatusRequest,\n} from '../types';\n\nexport const getBridgeStatusUrl = (bridgeApiBaseUrl: string): string =>\n `${bridgeApiBaseUrl}/getTxStatus`;\n\nexport const getStatusRequestDto = (\n statusRequest: StatusRequestWithSrcTxHash,\n): StatusRequestDto => {\n const { quote, ...statusRequestNoQuote } = statusRequest;\n\n const statusRequestNoQuoteFormatted = Object.fromEntries(\n Object.entries(statusRequestNoQuote).map(([key, value]) => [\n key,\n value.toString(),\n ]),\n ) as unknown as Omit<StatusRequestDto, 'requestId'>;\n\n const requestId: { requestId: string } | Record<string, never> =\n quote?.requestId ? { requestId: quote.requestId } : {};\n\n return {\n ...statusRequestNoQuoteFormatted,\n ...requestId,\n };\n};\n\nexport const fetchBridgeTxStatus = async (\n statusRequest: StatusRequestWithSrcTxHash,\n clientId: string,\n jwt: string | undefined,\n fetchFn: FetchFunction,\n bridgeApiBaseUrl: string,\n): Promise<{ status: StatusResponse; validationFailures: string[] }> => {\n const statusRequestDto = getStatusRequestDto(statusRequest);\n const params = new URLSearchParams(statusRequestDto);\n\n // Fetch\n const url = `${getBridgeStatusUrl(bridgeApiBaseUrl)}?${params.toString()}`;\n\n const rawTxStatus: unknown = await fetchFn(url, {\n headers: getClientHeaders({ clientId, jwt }),\n });\n\n const validationFailures: string[] = [];\n\n try {\n validateBridgeStatusResponse(rawTxStatus);\n } catch (error) {\n // Build validation failure event properties\n if (error instanceof StructError) {\n error.failures().forEach(({ path }) => {\n const aggregatorId =\n (rawTxStatus as StatusResponse)?.bridge ??\n (statusRequest.bridge || statusRequest.bridgeId) ??\n ('unknown' as string);\n const pathString = path?.join('.') || 'unknown';\n validationFailures.push([aggregatorId, pathString].join('|'));\n });\n }\n }\n return {\n status: rawTxStatus as StatusResponse,\n validationFailures,\n };\n};\n\nexport const getStatusRequestWithSrcTxHash = (\n quote: Quote,\n srcTxHash: string,\n): StatusRequestWithSrcTxHash => {\n const { bridgeId, bridges, srcChainId, destChainId, refuel } = quote;\n return {\n bridgeId,\n srcTxHash,\n bridge: bridges[0],\n srcChainId,\n destChainId,\n quote,\n refuel: Boolean(refuel),\n };\n};\n\nexport const shouldSkipFetchDueToFetchFailures = (\n attempts?: BridgeHistoryItem['attempts'],\n): boolean => {\n // If there's an attempt, it means we've failed at least once,\n // so we need to check if we need to wait longer due to exponential backoff\n if (attempts) {\n // Calculate exponential backoff delay: base interval * 2^(attempts-1)\n const backoffDelay =\n REFRESH_INTERVAL_MS * Math.pow(2, attempts.counter - 1);\n const timeSinceLastAttempt = Date.now() - attempts.lastAttemptTime;\n\n if (timeSinceLastAttempt < backoffDelay) {\n // Not enough time has passed, skip this fetch\n return true;\n }\n }\n return false;\n};\n\n/**\n * @deprecated Use getStatusRequestWithSrcTxHash instead\n * @param quoteResponse - The quote response to get the status request parameters from\n * @returns The status request parameters\n */\nexport const getStatusRequestParams = (\n quoteResponse: QuoteResponse,\n): StatusRequest => {\n return {\n bridgeId: quoteResponse.quote.bridgeId,\n bridge: quoteResponse.quote.bridges[0],\n srcChainId: quoteResponse.quote.srcChainId,\n destChainId: quoteResponse.quote.destChainId,\n quote: quoteResponse.quote,\n refuel: Boolean(quoteResponse.quote.refuel),\n };\n};\n"]}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trackMetricsEvent = exports.stopPollingForQuotes = void 0;
4
+ const bridge_controller_1 = require("@metamask/bridge-controller");
5
+ const stopPollingForQuotes = (messenger, featureId, metricsContext) => {
6
+ messenger.call('BridgeController:stopPollingForQuotes', bridge_controller_1.AbortReason.TransactionSubmitted,
7
+ // If trade is submitted before all quotes are loaded, the QuotesReceived event is published
8
+ // If the trade has a featureId, it means it was submitted outside of the Unified Swap and Bridge experience, so no QuotesReceived event is published
9
+ featureId ? undefined : metricsContext);
10
+ };
11
+ exports.stopPollingForQuotes = stopPollingForQuotes;
12
+ const trackMetricsEvent = ({ messenger, eventName, properties, }) => {
13
+ messenger.call('BridgeController:trackUnifiedSwapBridgeEvent', eventName, properties);
14
+ };
15
+ exports.trackMetricsEvent = trackMetricsEvent;
16
+ //# sourceMappingURL=bridge.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.cjs","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":";;;AAAA,mEAIqC;AAK9B,MAAM,oBAAoB,GAAG,CAClC,SAA0C,EAC1C,SAAqB,EACrB,cAA0F,EACpF,EAAE;IACR,SAAS,CAAC,IAAI,CACZ,uCAAuC,EACvC,+BAAW,CAAC,oBAAoB;IAChC,4FAA4F;IAC5F,qJAAqJ;IACrJ,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,CACvC,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,oBAAoB,wBAY/B;AAEK,MAAM,iBAAiB,GAAG,CAAC,EAChC,SAAS,EACT,SAAS,EACT,UAAU,GAKX,EAAQ,EAAE;IACT,SAAS,CAAC,IAAI,CACZ,8CAA8C,EAC9C,SAAS,EACT,UAAU,CACX,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,iBAAiB,qBAc5B","sourcesContent":["import {\n AbortReason,\n FeatureId,\n UnifiedSwapBridgeEventName,\n} from '@metamask/bridge-controller';\nimport type { RequiredEventContextFromClient } from '@metamask/bridge-controller';\n\nimport { BridgeStatusControllerMessenger } from '../types';\n\nexport const stopPollingForQuotes = (\n messenger: BridgeStatusControllerMessenger,\n featureId?: FeatureId,\n metricsContext?: RequiredEventContextFromClient[UnifiedSwapBridgeEventName.QuotesReceived],\n): void => {\n messenger.call(\n 'BridgeController:stopPollingForQuotes',\n AbortReason.TransactionSubmitted,\n // If trade is submitted before all quotes are loaded, the QuotesReceived event is published\n // If the trade has a featureId, it means it was submitted outside of the Unified Swap and Bridge experience, so no QuotesReceived event is published\n featureId ? undefined : metricsContext,\n );\n};\n\nexport const trackMetricsEvent = ({\n messenger,\n eventName,\n properties,\n}: {\n messenger: BridgeStatusControllerMessenger;\n eventName: UnifiedSwapBridgeEventName;\n properties: RequiredEventContextFromClient[UnifiedSwapBridgeEventName];\n}): void => {\n messenger.call(\n 'BridgeController:trackUnifiedSwapBridgeEvent',\n eventName,\n properties,\n );\n};\n"]}
@@ -0,0 +1,10 @@
1
+ import { FeatureId, UnifiedSwapBridgeEventName } from "@metamask/bridge-controller";
2
+ import type { RequiredEventContextFromClient } from "@metamask/bridge-controller";
3
+ import { BridgeStatusControllerMessenger } from "../types.cjs";
4
+ export declare const stopPollingForQuotes: (messenger: BridgeStatusControllerMessenger, featureId?: FeatureId, metricsContext?: RequiredEventContextFromClient[UnifiedSwapBridgeEventName.QuotesReceived]) => void;
5
+ export declare const trackMetricsEvent: ({ messenger, eventName, properties, }: {
6
+ messenger: BridgeStatusControllerMessenger;
7
+ eventName: UnifiedSwapBridgeEventName;
8
+ properties: RequiredEventContextFromClient[UnifiedSwapBridgeEventName];
9
+ }) => void;
10
+ //# sourceMappingURL=bridge.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.d.cts","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EACT,0BAA0B,EAC3B,oCAAoC;AACrC,OAAO,KAAK,EAAE,8BAA8B,EAAE,oCAAoC;AAElF,OAAO,EAAE,+BAA+B,EAAE,qBAAiB;AAE3D,eAAO,MAAM,oBAAoB,2DAEnB,SAAS,mBACJ,8BAA8B,CAAC,2BAA2B,cAAc,CAAC,KACzF,IAQF,CAAC;AAEF,eAAO,MAAM,iBAAiB;;eAMjB,0BAA0B;gBACzB,8BAA8B,CAAC,0BAA0B,CAAC;MACpE,IAMH,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { FeatureId, UnifiedSwapBridgeEventName } from "@metamask/bridge-controller";
2
+ import type { RequiredEventContextFromClient } from "@metamask/bridge-controller";
3
+ import { BridgeStatusControllerMessenger } from "../types.mjs";
4
+ export declare const stopPollingForQuotes: (messenger: BridgeStatusControllerMessenger, featureId?: FeatureId, metricsContext?: RequiredEventContextFromClient[UnifiedSwapBridgeEventName.QuotesReceived]) => void;
5
+ export declare const trackMetricsEvent: ({ messenger, eventName, properties, }: {
6
+ messenger: BridgeStatusControllerMessenger;
7
+ eventName: UnifiedSwapBridgeEventName;
8
+ properties: RequiredEventContextFromClient[UnifiedSwapBridgeEventName];
9
+ }) => void;
10
+ //# sourceMappingURL=bridge.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.d.mts","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EACT,0BAA0B,EAC3B,oCAAoC;AACrC,OAAO,KAAK,EAAE,8BAA8B,EAAE,oCAAoC;AAElF,OAAO,EAAE,+BAA+B,EAAE,qBAAiB;AAE3D,eAAO,MAAM,oBAAoB,2DAEnB,SAAS,mBACJ,8BAA8B,CAAC,2BAA2B,cAAc,CAAC,KACzF,IAQF,CAAC;AAEF,eAAO,MAAM,iBAAiB;;eAMjB,0BAA0B;gBACzB,8BAA8B,CAAC,0BAA0B,CAAC;MACpE,IAMH,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { AbortReason, FeatureId, UnifiedSwapBridgeEventName } from "@metamask/bridge-controller";
2
+ export const stopPollingForQuotes = (messenger, featureId, metricsContext) => {
3
+ messenger.call('BridgeController:stopPollingForQuotes', AbortReason.TransactionSubmitted,
4
+ // If trade is submitted before all quotes are loaded, the QuotesReceived event is published
5
+ // If the trade has a featureId, it means it was submitted outside of the Unified Swap and Bridge experience, so no QuotesReceived event is published
6
+ featureId ? undefined : metricsContext);
7
+ };
8
+ export const trackMetricsEvent = ({ messenger, eventName, properties, }) => {
9
+ messenger.call('BridgeController:trackUnifiedSwapBridgeEvent', eventName, properties);
10
+ };
11
+ //# sourceMappingURL=bridge.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.mjs","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,SAAS,EACT,0BAA0B,EAC3B,oCAAoC;AAKrC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,SAA0C,EAC1C,SAAqB,EACrB,cAA0F,EACpF,EAAE;IACR,SAAS,CAAC,IAAI,CACZ,uCAAuC,EACvC,WAAW,CAAC,oBAAoB;IAChC,4FAA4F;IAC5F,qJAAqJ;IACrJ,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,CACvC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,SAAS,EACT,SAAS,EACT,UAAU,GAKX,EAAQ,EAAE;IACT,SAAS,CAAC,IAAI,CACZ,8CAA8C,EAC9C,SAAS,EACT,UAAU,CACX,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n AbortReason,\n FeatureId,\n UnifiedSwapBridgeEventName,\n} from '@metamask/bridge-controller';\nimport type { RequiredEventContextFromClient } from '@metamask/bridge-controller';\n\nimport { BridgeStatusControllerMessenger } from '../types';\n\nexport const stopPollingForQuotes = (\n messenger: BridgeStatusControllerMessenger,\n featureId?: FeatureId,\n metricsContext?: RequiredEventContextFromClient[UnifiedSwapBridgeEventName.QuotesReceived],\n): void => {\n messenger.call(\n 'BridgeController:stopPollingForQuotes',\n AbortReason.TransactionSubmitted,\n // If trade is submitted before all quotes are loaded, the QuotesReceived event is published\n // If the trade has a featureId, it means it was submitted outside of the Unified Swap and Bridge experience, so no QuotesReceived event is published\n featureId ? undefined : metricsContext,\n );\n};\n\nexport const trackMetricsEvent = ({\n messenger,\n eventName,\n properties,\n}: {\n messenger: BridgeStatusControllerMessenger;\n eventName: UnifiedSwapBridgeEventName;\n properties: RequiredEventContextFromClient[UnifiedSwapBridgeEventName];\n}): void => {\n messenger.call(\n 'BridgeController:trackUnifiedSwapBridgeEvent',\n eventName,\n properties,\n );\n};\n"]}
@@ -1,67 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calcActualGasUsed = exports.calculateGasFees = exports.getTxGasEstimates = void 0;
4
- const bridge_controller_1 = require("@metamask/bridge-controller");
5
- const controller_utils_1 = require("@metamask/controller-utils");
3
+ exports.calcActualGasUsed = void 0;
6
4
  const bignumber_js_1 = require("bignumber.js");
7
- const getTransaction1559GasFeeEstimates = (txGasFeeEstimates, estimatedBaseFee) => {
8
- const { maxFeePerGas, maxPriorityFeePerGas } = txGasFeeEstimates?.[bridge_controller_1.BRIDGE_PREFERRED_GAS_ESTIMATE] ?? {};
9
- const baseAndPriorityFeePerGas = maxPriorityFeePerGas
10
- ? new bignumber_js_1.BigNumber(estimatedBaseFee, 10)
11
- .times(10 ** 9)
12
- .plus(maxPriorityFeePerGas, 16)
13
- : undefined;
14
- return {
15
- baseAndPriorityFeePerGas,
16
- maxFeePerGas,
17
- maxPriorityFeePerGas,
18
- };
19
- };
20
- /**
21
- * Get the gas fee estimates for a transaction
22
- *
23
- * @param params - The parameters for the gas fee estimates
24
- * @param params.txGasFeeEstimates - The gas fee estimates for the transaction (TransactionController)
25
- * @param params.networkGasFeeEstimates - The gas fee estimates for the network (GasFeeController)
26
- * @returns The gas fee estimates for the transaction
27
- */
28
- const getTxGasEstimates = ({ txGasFeeEstimates, networkGasFeeEstimates, }) => {
29
- const { estimatedBaseFee = '0' } = networkGasFeeEstimates;
30
- return getTransaction1559GasFeeEstimates(txGasFeeEstimates, estimatedBaseFee);
31
- };
32
- exports.getTxGasEstimates = getTxGasEstimates;
33
- const calculateGasFees = async (skipGasFields, messenger, estimateGasFeeFn, { chainId: _, gasLimit, ...trade }, networkClientId, chainId, txFee) => {
34
- if (skipGasFields) {
35
- return {};
36
- }
37
- if (txFee) {
38
- return { ...txFee, gas: gasLimit?.toString() };
39
- }
40
- const transactionParams = {
41
- ...trade,
42
- gas: gasLimit?.toString(),
43
- data: trade.data,
44
- to: trade.to,
45
- value: trade.value,
46
- };
47
- const { gasFeeEstimates } = messenger.call('GasFeeController:getState');
48
- const { estimates: txGasFeeEstimates } = await estimateGasFeeFn({
49
- transactionParams,
50
- chainId,
51
- networkClientId,
52
- });
53
- const { maxFeePerGas, maxPriorityFeePerGas } = (0, exports.getTxGasEstimates)({
54
- networkGasFeeEstimates: gasFeeEstimates,
55
- txGasFeeEstimates,
56
- });
57
- const maxGasLimit = (0, controller_utils_1.toHex)(transactionParams.gas ?? 0);
58
- return {
59
- maxFeePerGas,
60
- maxPriorityFeePerGas,
61
- gas: maxGasLimit,
62
- };
63
- };
64
- exports.calculateGasFees = calculateGasFees;
65
5
  const calcGasInHexWei = (gasLimit, gasPrice) => {
66
6
  return gasLimit && gasPrice
67
7
  ? new bignumber_js_1.BigNumber(gasLimit, 16).times(new bignumber_js_1.BigNumber(gasPrice, 16))
@@ -1 +1 @@
1
- {"version":3,"file":"gas.cjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";;;AAAA,mEAA4E;AAE5E,iEAAmD;AAWnD,+CAAyC;AAOzC,MAAM,iCAAiC,GAAG,CACxC,iBAA2C,EAC3C,gBAAwB,EACxB,EAAE;IACF,MAAM,EAAE,YAAY,EAAE,oBAAoB,EAAE,GAC1C,iBAAiB,EAAE,CAAC,iDAA6B,CAAC,IAAI,EAAE,CAAC;IAE3D,MAAM,wBAAwB,GAAG,oBAAoB;QACnD,CAAC,CAAC,IAAI,wBAAS,CAAC,gBAAgB,EAAE,EAAE,CAAC;aAChC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;aACd,IAAI,CAAC,oB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SAC/B,QAAQ,CAAC,EAAE,CAAC,CAAC;IAEhB,OAAO,iBAAiB,IAAI,iBAAiB;QAC3C,CAAC,CAAC;YACE,MAAM,EAAE,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtC,GAAG,EACD,eAAe,EAAE,YAAY,CAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI;SACxE;QACH,CAAC,CAAC,IAAI,CAAC;AACX,CAAC,CAAC;AAjCW,QAAA,iBAAiB,qBAiC5B","sourcesContent":["import { BRIDGE_PREFERRED_GAS_ESTIMATE } from '@metamask/bridge-controller';\nimport type { TokenAmountValues, TxData } from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport type {\n GasFeeEstimates,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type {\n FeeMarketGasFeeEstimates,\n TransactionController,\n TransactionReceipt,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport type {\n BridgeHistoryItem,\n BridgeStatusControllerMessenger,\n} from '../types';\n\nconst getTransaction1559GasFeeEstimates = (\n txGasFeeEstimates: FeeMarketGasFeeEstimates,\n estimatedBaseFee: string,\n) => {\n const { maxFeePerGas, maxPriorityFeePerGas } =\n txGasFeeEstimates?.[BRIDGE_PREFERRED_GAS_ESTIMATE] ?? {};\n\n const baseAndPriorityFeePerGas = maxPriorityFeePerGas\n ? new BigNumber(estimatedBaseFee, 10)\n .times(10 ** 9)\n .plus(maxPriorityFeePerGas, 16)\n : undefined;\n\n return {\n baseAndPriorityFeePerGas,\n maxFeePerGas,\n maxPriorityFeePerGas,\n };\n};\n\n/**\n * Get the gas fee estimates for a transaction\n *\n * @param params - The parameters for the gas fee estimates\n * @param params.txGasFeeEstimates - The gas fee estimates for the transaction (TransactionController)\n * @param params.networkGasFeeEstimates - The gas fee estimates for the network (GasFeeController)\n * @returns The gas fee estimates for the transaction\n */\nexport const getTxGasEstimates = ({\n txGasFeeEstimates,\n networkGasFeeEstimates,\n}: {\n txGasFeeEstimates: Awaited<\n ReturnType<TransactionController['estimateGasFee']>\n >['estimates'];\n networkGasFeeEstimates: GasFeeState['gasFeeEstimates'];\n}) => {\n const { estimatedBaseFee = '0' } = networkGasFeeEstimates as GasFeeEstimates;\n return getTransaction1559GasFeeEstimates(\n txGasFeeEstimates as unknown as FeeMarketGasFeeEstimates,\n estimatedBaseFee,\n );\n};\n\nexport const calculateGasFees = async (\n skipGasFields: boolean,\n messenger: BridgeStatusControllerMessenger,\n estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee,\n { chainId: _, gasLimit, ...trade }: TxData,\n networkClientId: string,\n chainId: Hex,\n txFee?: { maxFeePerGas: string; maxPriorityFeePerGas: string },\n) => {\n if (skipGasFields) {\n return {};\n }\n if (txFee) {\n return { ...txFee, gas: gasLimit?.toString() };\n }\n const transactionParams = {\n ...trade,\n gas: gasLimit?.toString(),\n data: trade.data as `0x${string}`,\n to: trade.to as `0x${string}`,\n value: trade.value as `0x${string}`,\n };\n const { gasFeeEstimates } = messenger.call('GasFeeController:getState');\n const { estimates: txGasFeeEstimates } = await estimateGasFeeFn({\n transactionParams,\n chainId,\n networkClientId,\n });\n const { maxFeePerGas, maxPriorityFeePerGas } = getTxGasEstimates({\n networkGasFeeEstimates: gasFeeEstimates,\n txGasFeeEstimates,\n });\n const maxGasLimit = toHex(transactionParams.gas ?? 0);\n\n return {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas: maxGasLimit,\n };\n};\n\nconst calcGasInHexWei = (gasLimit?: string, gasPrice?: string) => {\n return gasLimit && gasPrice\n ? new BigNumber(gasLimit, 16).times(new BigNumber(gasPrice, 16))\n : null;\n};\n\n/**\n * Calculate the effective gas used for a transaction and its approval tx\n *\n * @param bridgeHistoryItem - The bridge history item\n * @param bridgeHistoryItem.pricingData - pricing data from the submitted quote\n * @param txReceipt - tx receipt from the txMeta\n * @param approvalTxReceipt - tx receipt from the approvalTxMeta\n * @returns The actual gas used for the transaction in Wei and its value in USD\n */\nexport const calcActualGasUsed = (\n { pricingData }: BridgeHistoryItem,\n txReceipt?: TransactionReceipt,\n approvalTxReceipt?: TransactionReceipt,\n): Omit<TokenAmountValues, 'valueInCurrency'> | null => {\n const usdExchangeRate =\n pricingData?.quotedGasInUsd && pricingData?.quotedGasAmount\n ? new BigNumber(pricingData?.quotedGasInUsd).div(\n pricingData.quotedGasAmount,\n )\n : null;\n\n const actualGasInHexWei = calcGasInHexWei(\n txReceipt?.gasUsed,\n txReceipt?.effectiveGasPrice,\n )?.plus(\n calcGasInHexWei(\n approvalTxReceipt?.gasUsed,\n approvalTxReceipt?.effectiveGasPrice,\n ) ?? 0,\n );\n\n const actualGasInDecEth = actualGasInHexWei\n ?.div(new BigNumber(10).pow(18))\n .toString(10);\n\n return actualGasInHexWei && actualGasInDecEth\n ? {\n amount: actualGasInHexWei.toString(10),\n usd:\n usdExchangeRate?.multipliedBy(actualGasInDecEth).toString(10) ?? null,\n }\n : null;\n};\n"]}
1
+ {"version":3,"file":"gas.cjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";;;AAGA,+CAAyC;AAIzC,MAAM,eAAe,GAAG,CAAC,QAAiB,EAAE,QAAiB,EAAE,EAAE;IAC/D,OAAO,QAAQ,IAAI,QAAQ;QACzB,CAAC,CAAC,IAAI,wBAAS,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,wBAAS,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAChE,CAAC,CAAC,IAAI,CAAC;AACX,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACI,MAAM,iBAAiB,GAAG,CAC/B,EAAE,WAAW,EAAqB,EAClC,SAA8B,EAC9B,iBAAsC,EACa,EAAE;IACrD,MAAM,eAAe,GACnB,WAAW,EAAE,cAAc,IAAI,WAAW,EAAE,eAAe;QACzD,CAAC,CAAC,IAAI,wBAAS,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,GAAG,CAC5C,WAAW,CAAC,eAAe,CAC5B;QACH,CAAC,CAAC,IAAI,CAAC;IAEX,MAAM,iBAAiB,GAAG,eAAe,CACvC,SAAS,EAAE,OAAO,EAClB,SAAS,EAAE,iBAAiB,CAC7B,EAAE,IAAI,CACL,eAAe,CACb,iBAAiB,EAAE,OAAO,EAC1B,iBAAiB,EAAE,iBAAiB,CACrC,IAAI,CAAC,CACP,CAAC;IAEF,MAAM,iBAAiB,GAAG,iBAAiB;QACzC,EAAE,GAAG,CAAC,IAAI,wBAAS,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;SAC/B,QAAQ,CAAC,EAAE,CAAC,CAAC;IAEhB,OAAO,iBAAiB,IAAI,iBAAiB;QAC3C,CAAC,CAAC;YACE,MAAM,EAAE,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtC,GAAG,EACD,eAAe,EAAE,YAAY,CAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI;SACxE;QACH,CAAC,CAAC,IAAI,CAAC;AACX,CAAC,CAAC;AAjCW,QAAA,iBAAiB,qBAiC5B","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport type { TokenAmountValues } from '@metamask/bridge-controller';\nimport type { TransactionReceipt } from '@metamask/transaction-controller';\nimport { BigNumber } from 'bignumber.js';\n\nimport type { BridgeHistoryItem } from '../types';\n\nconst calcGasInHexWei = (gasLimit?: string, gasPrice?: string) => {\n return gasLimit && gasPrice\n ? new BigNumber(gasLimit, 16).times(new BigNumber(gasPrice, 16))\n : null;\n};\n\n/**\n * Calculate the effective gas used for a transaction and its approval tx\n *\n * @param bridgeHistoryItem - The bridge history item\n * @param bridgeHistoryItem.pricingData - pricing data from the submitted quote\n * @param txReceipt - tx receipt from the txMeta\n * @param approvalTxReceipt - tx receipt from the approvalTxMeta\n * @returns The actual gas used for the transaction in Wei and its value in USD\n */\nexport const calcActualGasUsed = (\n { pricingData }: BridgeHistoryItem,\n txReceipt?: TransactionReceipt,\n approvalTxReceipt?: TransactionReceipt,\n): Omit<TokenAmountValues, 'valueInCurrency'> | null => {\n const usdExchangeRate =\n pricingData?.quotedGasInUsd && pricingData?.quotedGasAmount\n ? new BigNumber(pricingData?.quotedGasInUsd).div(\n pricingData.quotedGasAmount,\n )\n : null;\n\n const actualGasInHexWei = calcGasInHexWei(\n txReceipt?.gasUsed,\n txReceipt?.effectiveGasPrice,\n )?.plus(\n calcGasInHexWei(\n approvalTxReceipt?.gasUsed,\n approvalTxReceipt?.effectiveGasPrice,\n ) ?? 0,\n );\n\n const actualGasInDecEth = actualGasInHexWei\n ?.div(new BigNumber(10).pow(18))\n .toString(10);\n\n return actualGasInHexWei && actualGasInDecEth\n ? {\n amount: actualGasInHexWei.toString(10),\n usd:\n usdExchangeRate?.multipliedBy(actualGasInDecEth).toString(10) ?? null,\n }\n : null;\n};\n"]}
@@ -1,29 +1,6 @@
1
- import type { TokenAmountValues, TxData } from "@metamask/bridge-controller";
2
- import type { GasFeeState } from "@metamask/gas-fee-controller";
3
- import type { TransactionController, TransactionReceipt } from "@metamask/transaction-controller";
4
- import type { Hex } from "@metamask/utils";
5
- import { BigNumber } from "bignumber.js";
6
- import type { BridgeHistoryItem, BridgeStatusControllerMessenger } from "../types.cjs";
7
- /**
8
- * Get the gas fee estimates for a transaction
9
- *
10
- * @param params - The parameters for the gas fee estimates
11
- * @param params.txGasFeeEstimates - The gas fee estimates for the transaction (TransactionController)
12
- * @param params.networkGasFeeEstimates - The gas fee estimates for the network (GasFeeController)
13
- * @returns The gas fee estimates for the transaction
14
- */
15
- export declare const getTxGasEstimates: ({ txGasFeeEstimates, networkGasFeeEstimates, }: {
16
- txGasFeeEstimates: Awaited<ReturnType<TransactionController['estimateGasFee']>>['estimates'];
17
- networkGasFeeEstimates: GasFeeState['gasFeeEstimates'];
18
- }) => {
19
- baseAndPriorityFeePerGas: BigNumber | undefined;
20
- maxFeePerGas: `0x${string}`;
21
- maxPriorityFeePerGas: `0x${string}`;
22
- };
23
- export declare const calculateGasFees: (skipGasFields: boolean, messenger: BridgeStatusControllerMessenger, estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee, { chainId: _, gasLimit, ...trade }: TxData, networkClientId: string, chainId: Hex, txFee?: {
24
- maxFeePerGas: string;
25
- maxPriorityFeePerGas: string;
26
- }) => Promise<{}>;
1
+ import type { TokenAmountValues } from "@metamask/bridge-controller";
2
+ import type { TransactionReceipt } from "@metamask/transaction-controller";
3
+ import type { BridgeHistoryItem } from "../types.cjs";
27
4
  /**
28
5
  * Calculate the effective gas used for a transaction and its approval tx
29
6
  *
@@ -1 +1 @@
1
- {"version":3,"file":"gas.d.cts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,oCAAoC;AAE7E,OAAO,KAAK,EAEV,WAAW,EACZ,qCAAqC;AACtC,OAAO,KAAK,EAEV,qBAAqB,EACrB,kBAAkB,EACnB,yCAAyC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAC3C,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,OAAO,KAAK,EACV,iBAAiB,EACjB,+BAA+B,EAChC,qBAAiB;AAsBlB;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;uBAIT,QACjB,WAAW,qBAAqB,CAAC,gBAAgB,CAAC,CAAC,CACpD,CAAC,WAAW,CAAC;4BACU,WAAW,CAAC,iBAAiB,CAAC;;;;;CAOvD,CAAC;AAEF,eAAO,MAAM,gBAAgB,kBACZ,OAAO,gEAEJ,OAAO,sBAAsB,SAAS,CAAC,cAAc,sCACnC,MAAM,mBACzB,MAAM,WACd,GAAG,UACJ;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,oBAAoB,EAAE,MAAM,CAAA;CAAE,gBAgC/D,CAAC;AAQF;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,oBACX,iBAAiB,cACtB,kBAAkB,sBACV,kBAAkB,KACrC,KAAK,iBAAiB,EAAE,iBAAiB,CAAC,GAAG,IA6B/C,CAAC"}
1
+ {"version":3,"file":"gas.d.cts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,yCAAyC;AAG3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAQlD;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,oBACX,iBAAiB,cACtB,kBAAkB,sBACV,kBAAkB,KACrC,KAAK,iBAAiB,EAAE,iBAAiB,CAAC,GAAG,IA6B/C,CAAC"}
@@ -1,29 +1,6 @@
1
- import type { TokenAmountValues, TxData } from "@metamask/bridge-controller";
2
- import type { GasFeeState } from "@metamask/gas-fee-controller";
3
- import type { TransactionController, TransactionReceipt } from "@metamask/transaction-controller";
4
- import type { Hex } from "@metamask/utils";
5
- import { BigNumber } from "bignumber.js";
6
- import type { BridgeHistoryItem, BridgeStatusControllerMessenger } from "../types.mjs";
7
- /**
8
- * Get the gas fee estimates for a transaction
9
- *
10
- * @param params - The parameters for the gas fee estimates
11
- * @param params.txGasFeeEstimates - The gas fee estimates for the transaction (TransactionController)
12
- * @param params.networkGasFeeEstimates - The gas fee estimates for the network (GasFeeController)
13
- * @returns The gas fee estimates for the transaction
14
- */
15
- export declare const getTxGasEstimates: ({ txGasFeeEstimates, networkGasFeeEstimates, }: {
16
- txGasFeeEstimates: Awaited<ReturnType<TransactionController['estimateGasFee']>>['estimates'];
17
- networkGasFeeEstimates: GasFeeState['gasFeeEstimates'];
18
- }) => {
19
- baseAndPriorityFeePerGas: BigNumber | undefined;
20
- maxFeePerGas: `0x${string}`;
21
- maxPriorityFeePerGas: `0x${string}`;
22
- };
23
- export declare const calculateGasFees: (skipGasFields: boolean, messenger: BridgeStatusControllerMessenger, estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee, { chainId: _, gasLimit, ...trade }: TxData, networkClientId: string, chainId: Hex, txFee?: {
24
- maxFeePerGas: string;
25
- maxPriorityFeePerGas: string;
26
- }) => Promise<{}>;
1
+ import type { TokenAmountValues } from "@metamask/bridge-controller";
2
+ import type { TransactionReceipt } from "@metamask/transaction-controller";
3
+ import type { BridgeHistoryItem } from "../types.mjs";
27
4
  /**
28
5
  * Calculate the effective gas used for a transaction and its approval tx
29
6
  *
@@ -1 +1 @@
1
- {"version":3,"file":"gas.d.mts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,oCAAoC;AAE7E,OAAO,KAAK,EAEV,WAAW,EACZ,qCAAqC;AACtC,OAAO,KAAK,EAEV,qBAAqB,EACrB,kBAAkB,EACnB,yCAAyC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAC3C,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,OAAO,KAAK,EACV,iBAAiB,EACjB,+BAA+B,EAChC,qBAAiB;AAsBlB;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;uBAIT,QACjB,WAAW,qBAAqB,CAAC,gBAAgB,CAAC,CAAC,CACpD,CAAC,WAAW,CAAC;4BACU,WAAW,CAAC,iBAAiB,CAAC;;;;;CAOvD,CAAC;AAEF,eAAO,MAAM,gBAAgB,kBACZ,OAAO,gEAEJ,OAAO,sBAAsB,SAAS,CAAC,cAAc,sCACnC,MAAM,mBACzB,MAAM,WACd,GAAG,UACJ;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,oBAAoB,EAAE,MAAM,CAAA;CAAE,gBAgC/D,CAAC;AAQF;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,oBACX,iBAAiB,cACtB,kBAAkB,sBACV,kBAAkB,KACrC,KAAK,iBAAiB,EAAE,iBAAiB,CAAC,GAAG,IA6B/C,CAAC"}
1
+ {"version":3,"file":"gas.d.mts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,yCAAyC;AAG3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAQlD;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,oBACX,iBAAiB,cACtB,kBAAkB,sBACV,kBAAkB,KACrC,KAAK,iBAAiB,EAAE,iBAAiB,CAAC,GAAG,IA6B/C,CAAC"}
@@ -1,62 +1,4 @@
1
- import { BRIDGE_PREFERRED_GAS_ESTIMATE } from "@metamask/bridge-controller";
2
- import { toHex } from "@metamask/controller-utils";
3
1
  import { BigNumber } from "bignumber.js";
4
- const getTransaction1559GasFeeEstimates = (txGasFeeEstimates, estimatedBaseFee) => {
5
- const { maxFeePerGas, maxPriorityFeePerGas } = txGasFeeEstimates?.[BRIDGE_PREFERRED_GAS_ESTIMATE] ?? {};
6
- const baseAndPriorityFeePerGas = maxPriorityFeePerGas
7
- ? new BigNumber(estimatedBaseFee, 10)
8
- .times(10 ** 9)
9
- .plus(maxPriorityFeePerGas, 16)
10
- : undefined;
11
- return {
12
- baseAndPriorityFeePerGas,
13
- maxFeePerGas,
14
- maxPriorityFeePerGas,
15
- };
16
- };
17
- /**
18
- * Get the gas fee estimates for a transaction
19
- *
20
- * @param params - The parameters for the gas fee estimates
21
- * @param params.txGasFeeEstimates - The gas fee estimates for the transaction (TransactionController)
22
- * @param params.networkGasFeeEstimates - The gas fee estimates for the network (GasFeeController)
23
- * @returns The gas fee estimates for the transaction
24
- */
25
- export const getTxGasEstimates = ({ txGasFeeEstimates, networkGasFeeEstimates, }) => {
26
- const { estimatedBaseFee = '0' } = networkGasFeeEstimates;
27
- return getTransaction1559GasFeeEstimates(txGasFeeEstimates, estimatedBaseFee);
28
- };
29
- export const calculateGasFees = async (skipGasFields, messenger, estimateGasFeeFn, { chainId: _, gasLimit, ...trade }, networkClientId, chainId, txFee) => {
30
- if (skipGasFields) {
31
- return {};
32
- }
33
- if (txFee) {
34
- return { ...txFee, gas: gasLimit?.toString() };
35
- }
36
- const transactionParams = {
37
- ...trade,
38
- gas: gasLimit?.toString(),
39
- data: trade.data,
40
- to: trade.to,
41
- value: trade.value,
42
- };
43
- const { gasFeeEstimates } = messenger.call('GasFeeController:getState');
44
- const { estimates: txGasFeeEstimates } = await estimateGasFeeFn({
45
- transactionParams,
46
- chainId,
47
- networkClientId,
48
- });
49
- const { maxFeePerGas, maxPriorityFeePerGas } = getTxGasEstimates({
50
- networkGasFeeEstimates: gasFeeEstimates,
51
- txGasFeeEstimates,
52
- });
53
- const maxGasLimit = toHex(transactionParams.gas ?? 0);
54
- return {
55
- maxFeePerGas,
56
- maxPriorityFeePerGas,
57
- gas: maxGasLimit,
58
- };
59
- };
60
2
  const calcGasInHexWei = (gasLimit, gasPrice) => {
61
3
  return gasLimit && gasPrice
62
4
  ? new BigNumber(gasLimit, 16).times(new BigNumber(gasPrice, 16))
@@ -1 +1 @@
1
- {"version":3,"file":"gas.mjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,oCAAoC;AAE5E,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAWnD,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAOzC,MAAM,iCAAiC,GAAG,CACxC,iBAA2C,EAC3C,gBAAwB,EACxB,EAAE;IACF,MAAM,EAAE,YAAY,EAAE,oBAAoB,EAAE,GAC1C,iBAAiB,EAAE,CAAC,6BAA6B,CAAC,IAAI,EAAE,CAAC;IAE3D,MAAM,wBAAwB,GAAG,oBAAoB;QACnD,CAAC,CAAC,IAAI,SAAS,CAAC,gBAAgB,EAAE,EAAE,CAAC;aAChC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;aACd,IAAI,CAA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;IAEhB,OAAO,iBAAiB,IAAI,iBAAiB;QAC3C,CAAC,CAAC;YACE,MAAM,EAAE,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtC,GAAG,EACD,eAAe,EAAE,YAAY,CAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI;SACxE;QACH,CAAC,CAAC,IAAI,CAAC;AACX,CAAC,CAAC","sourcesContent":["import { BRIDGE_PREFERRED_GAS_ESTIMATE } from '@metamask/bridge-controller';\nimport type { TokenAmountValues, TxData } from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport type {\n GasFeeEstimates,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type {\n FeeMarketGasFeeEstimates,\n TransactionController,\n TransactionReceipt,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport type {\n BridgeHistoryItem,\n BridgeStatusControllerMessenger,\n} from '../types';\n\nconst getTransaction1559GasFeeEstimates = (\n txGasFeeEstimates: FeeMarketGasFeeEstimates,\n estimatedBaseFee: string,\n) => {\n const { maxFeePerGas, maxPriorityFeePerGas } =\n txGasFeeEstimates?.[BRIDGE_PREFERRED_GAS_ESTIMATE] ?? {};\n\n const baseAndPriorityFeePerGas = maxPriorityFeePerGas\n ? new BigNumber(estimatedBaseFee, 10)\n .times(10 ** 9)\n .plus(maxPriorityFeePerGas, 16)\n : undefined;\n\n return {\n baseAndPriorityFeePerGas,\n maxFeePerGas,\n maxPriorityFeePerGas,\n };\n};\n\n/**\n * Get the gas fee estimates for a transaction\n *\n * @param params - The parameters for the gas fee estimates\n * @param params.txGasFeeEstimates - The gas fee estimates for the transaction (TransactionController)\n * @param params.networkGasFeeEstimates - The gas fee estimates for the network (GasFeeController)\n * @returns The gas fee estimates for the transaction\n */\nexport const getTxGasEstimates = ({\n txGasFeeEstimates,\n networkGasFeeEstimates,\n}: {\n txGasFeeEstimates: Awaited<\n ReturnType<TransactionController['estimateGasFee']>\n >['estimates'];\n networkGasFeeEstimates: GasFeeState['gasFeeEstimates'];\n}) => {\n const { estimatedBaseFee = '0' } = networkGasFeeEstimates as GasFeeEstimates;\n return getTransaction1559GasFeeEstimates(\n txGasFeeEstimates as unknown as FeeMarketGasFeeEstimates,\n estimatedBaseFee,\n );\n};\n\nexport const calculateGasFees = async (\n skipGasFields: boolean,\n messenger: BridgeStatusControllerMessenger,\n estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee,\n { chainId: _, gasLimit, ...trade }: TxData,\n networkClientId: string,\n chainId: Hex,\n txFee?: { maxFeePerGas: string; maxPriorityFeePerGas: string },\n) => {\n if (skipGasFields) {\n return {};\n }\n if (txFee) {\n return { ...txFee, gas: gasLimit?.toString() };\n }\n const transactionParams = {\n ...trade,\n gas: gasLimit?.toString(),\n data: trade.data as `0x${string}`,\n to: trade.to as `0x${string}`,\n value: trade.value as `0x${string}`,\n };\n const { gasFeeEstimates } = messenger.call('GasFeeController:getState');\n const { estimates: txGasFeeEstimates } = await estimateGasFeeFn({\n transactionParams,\n chainId,\n networkClientId,\n });\n const { maxFeePerGas, maxPriorityFeePerGas } = getTxGasEstimates({\n networkGasFeeEstimates: gasFeeEstimates,\n txGasFeeEstimates,\n });\n const maxGasLimit = toHex(transactionParams.gas ?? 0);\n\n return {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas: maxGasLimit,\n };\n};\n\nconst calcGasInHexWei = (gasLimit?: string, gasPrice?: string) => {\n return gasLimit && gasPrice\n ? new BigNumber(gasLimit, 16).times(new BigNumber(gasPrice, 16))\n : null;\n};\n\n/**\n * Calculate the effective gas used for a transaction and its approval tx\n *\n * @param bridgeHistoryItem - The bridge history item\n * @param bridgeHistoryItem.pricingData - pricing data from the submitted quote\n * @param txReceipt - tx receipt from the txMeta\n * @param approvalTxReceipt - tx receipt from the approvalTxMeta\n * @returns The actual gas used for the transaction in Wei and its value in USD\n */\nexport const calcActualGasUsed = (\n { pricingData }: BridgeHistoryItem,\n txReceipt?: TransactionReceipt,\n approvalTxReceipt?: TransactionReceipt,\n): Omit<TokenAmountValues, 'valueInCurrency'> | null => {\n const usdExchangeRate =\n pricingData?.quotedGasInUsd && pricingData?.quotedGasAmount\n ? new BigNumber(pricingData?.quotedGasInUsd).div(\n pricingData.quotedGasAmount,\n )\n : null;\n\n const actualGasInHexWei = calcGasInHexWei(\n txReceipt?.gasUsed,\n txReceipt?.effectiveGasPrice,\n )?.plus(\n calcGasInHexWei(\n approvalTxReceipt?.gasUsed,\n approvalTxReceipt?.effectiveGasPrice,\n ) ?? 0,\n );\n\n const actualGasInDecEth = actualGasInHexWei\n ?.div(new BigNumber(10).pow(18))\n .toString(10);\n\n return actualGasInHexWei && actualGasInDecEth\n ? {\n amount: actualGasInHexWei.toString(10),\n usd:\n usdExchangeRate?.multipliedBy(actualGasInDecEth).toString(10) ?? null,\n }\n : null;\n};\n"]}
1
+ {"version":3,"file":"gas.mjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAIzC,MAAM,eAAe,GAAG,CAAC,QAAiB,EAAE,QAAiB,EAAE,EAAE;IAC/D,OAAO,QAAQ,IAAI,QAAQ;QACzB,CAAC,CAAC,IAAI,SAAS,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAChE,CAAC,CAAC,IAAI,CAAC;AACX,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,EAAE,WAAW,EAAqB,EAClC,SAA8B,EAC9B,iBAAsC,EACa,EAAE;IACrD,MAAM,eAAe,GACnB,WAAW,EAAE,cAAc,IAAI,WAAW,EAAE,eAAe;QACzD,CAAC,CAAC,IAAI,SAAS,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,GAAG,CAC5C,WAAW,CAAC,eAAe,CAC5B;QACH,CAAC,CAAC,IAAI,CAAC;IAEX,MAAM,iBAAiB,GAAG,eAAe,CACvC,SAAS,EAAE,OAAO,EAClB,SAAS,EAAE,iBAAiB,CAC7B,EAAE,IAAI,CACL,eAAe,CACb,iBAAiB,EAAE,OAAO,EAC1B,iBAAiB,EAAE,iBAAiB,CACrC,IAAI,CAAC,CACP,CAAC;IAEF,MAAM,iBAAiB,GAAG,iBAAiB;QACzC,EAAE,GAAG,CAAC,IAAI,SAAS,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;SAC/B,QAAQ,CAAC,EAAE,CAAC,CAAC;IAEhB,OAAO,iBAAiB,IAAI,iBAAiB;QAC3C,CAAC,CAAC;YACE,MAAM,EAAE,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtC,GAAG,EACD,eAAe,EAAE,YAAY,CAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI;SACxE;QACH,CAAC,CAAC,IAAI,CAAC;AACX,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport type { TokenAmountValues } from '@metamask/bridge-controller';\nimport type { TransactionReceipt } from '@metamask/transaction-controller';\nimport { BigNumber } from 'bignumber.js';\n\nimport type { BridgeHistoryItem } from '../types';\n\nconst calcGasInHexWei = (gasLimit?: string, gasPrice?: string) => {\n return gasLimit && gasPrice\n ? new BigNumber(gasLimit, 16).times(new BigNumber(gasPrice, 16))\n : null;\n};\n\n/**\n * Calculate the effective gas used for a transaction and its approval tx\n *\n * @param bridgeHistoryItem - The bridge history item\n * @param bridgeHistoryItem.pricingData - pricing data from the submitted quote\n * @param txReceipt - tx receipt from the txMeta\n * @param approvalTxReceipt - tx receipt from the approvalTxMeta\n * @returns The actual gas used for the transaction in Wei and its value in USD\n */\nexport const calcActualGasUsed = (\n { pricingData }: BridgeHistoryItem,\n txReceipt?: TransactionReceipt,\n approvalTxReceipt?: TransactionReceipt,\n): Omit<TokenAmountValues, 'valueInCurrency'> | null => {\n const usdExchangeRate =\n pricingData?.quotedGasInUsd && pricingData?.quotedGasAmount\n ? new BigNumber(pricingData?.quotedGasInUsd).div(\n pricingData.quotedGasAmount,\n )\n : null;\n\n const actualGasInHexWei = calcGasInHexWei(\n txReceipt?.gasUsed,\n txReceipt?.effectiveGasPrice,\n )?.plus(\n calcGasInHexWei(\n approvalTxReceipt?.gasUsed,\n approvalTxReceipt?.effectiveGasPrice,\n ) ?? 0,\n );\n\n const actualGasInDecEth = actualGasInHexWei\n ?.div(new BigNumber(10).pow(18))\n .toString(10);\n\n return actualGasInHexWei && actualGasInDecEth\n ? {\n amount: actualGasInHexWei.toString(10),\n usd:\n usdExchangeRate?.multipliedBy(actualGasInDecEth).toString(10) ?? null,\n }\n : null;\n};\n"]}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shouldPollHistoryItem = exports.getInitialHistoryItem = exports.getHistoryKey = exports.rekeyHistoryItemInState = void 0;
4
+ const bridge_controller_1 = require("@metamask/bridge-controller");
5
+ const rekeyHistoryItemInState = (state, actionId, txMeta) => {
6
+ const historyItem = state.txHistory[actionId];
7
+ if (!historyItem) {
8
+ return false;
9
+ }
10
+ state.txHistory[txMeta.id] = {
11
+ ...historyItem,
12
+ txMetaId: txMeta.id,
13
+ originalTransactionId: historyItem.originalTransactionId ?? txMeta.id,
14
+ status: {
15
+ ...historyItem.status,
16
+ srcChain: {
17
+ ...historyItem.status.srcChain,
18
+ txHash: txMeta.hash ?? historyItem.status.srcChain?.txHash,
19
+ },
20
+ },
21
+ };
22
+ delete state.txHistory[actionId];
23
+ return true;
24
+ };
25
+ exports.rekeyHistoryItemInState = rekeyHistoryItemInState;
26
+ /**
27
+ * Determines the key to use for storing a bridge history item.
28
+ * Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.
29
+ *
30
+ * @param actionId - The action ID used for pre-submission tracking
31
+ * @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta
32
+ * @param syntheticTransactionId - The transactionId of the intent's placeholder transaction
33
+ * @returns The key to use for the history item
34
+ * @throws Error if neither actionId nor bridgeTxMetaId is provided
35
+ */
36
+ function getHistoryKey(actionId, bridgeTxMetaId, syntheticTransactionId) {
37
+ const historyKey = actionId ?? bridgeTxMetaId ?? syntheticTransactionId;
38
+ if (!historyKey) {
39
+ throw new Error('Cannot add tx to history: either actionId, bridgeTxMeta.id, or syntheticTransactionId must be provided');
40
+ }
41
+ return historyKey;
42
+ }
43
+ exports.getHistoryKey = getHistoryKey;
44
+ const getInitialHistoryItem = (args) => {
45
+ const { bridgeTxMeta, quoteResponse, startTime, slippagePercentage, initialDestAssetBalance, targetContractAddress, approvalTxId, isStxEnabled, location, abTests, activeAbTests, accountAddress: selectedAddress, originalTransactionId, actionId, } = args;
46
+ // Determine the key for this history item:
47
+ // - For pre-submission (non-batch EVM): use actionId
48
+ // - For post-submission or other cases: use bridgeTxMeta.id
49
+ const historyKey = getHistoryKey(actionId, bridgeTxMeta?.id, originalTransactionId);
50
+ // Write all non-status fields to state so we can reference the quote in Activity list without the Bridge API
51
+ // We know it's in progress but not the exact status yet
52
+ const txHistoryItem = {
53
+ txMetaId: bridgeTxMeta?.id,
54
+ actionId,
55
+ originalTransactionId: originalTransactionId ?? bridgeTxMeta?.id, // Keep original for intent transactions
56
+ batchId: bridgeTxMeta?.batchId,
57
+ quote: quoteResponse.quote,
58
+ startTime,
59
+ estimatedProcessingTimeInSeconds: quoteResponse.estimatedProcessingTimeInSeconds,
60
+ slippagePercentage,
61
+ pricingData: {
62
+ amountSent: quoteResponse.sentAmount?.amount ?? '0',
63
+ amountSentInUsd: quoteResponse.sentAmount?.usd ?? undefined,
64
+ quotedGasInUsd: quoteResponse.gasFee?.effective?.usd ?? undefined,
65
+ quotedReturnInUsd: quoteResponse.toTokenAmount?.usd ?? undefined,
66
+ quotedGasAmount: quoteResponse.gasFee?.effective?.amount ?? undefined,
67
+ },
68
+ initialDestAssetBalance,
69
+ targetContractAddress,
70
+ account: selectedAddress,
71
+ status: {
72
+ // We always have a PENDING status when we start polling for a tx, don't need the Bridge API for that
73
+ // Also we know the bare minimum fields for status at this point in time
74
+ status: bridge_controller_1.StatusTypes.PENDING,
75
+ srcChain: {
76
+ chainId: quoteResponse.quote.srcChainId,
77
+ txHash: bridgeTxMeta?.hash,
78
+ },
79
+ },
80
+ hasApprovalTx: Boolean(quoteResponse.approval),
81
+ approvalTxId,
82
+ isStxEnabled: Boolean(isStxEnabled),
83
+ featureId: quoteResponse.featureId,
84
+ location,
85
+ ...(abTests && { abTests }),
86
+ ...(activeAbTests && { activeAbTests }),
87
+ };
88
+ return { historyKey, txHistoryItem };
89
+ };
90
+ exports.getInitialHistoryItem = getInitialHistoryItem;
91
+ const shouldPollHistoryItem = (historyItem) => {
92
+ const isIntent = Boolean(historyItem?.quote?.intent);
93
+ const isBridgeTx = (0, bridge_controller_1.isCrossChain)(historyItem.quote.srcChainId, historyItem.quote.destChainId);
94
+ const isTronTx = (0, bridge_controller_1.isTronChainId)(historyItem.quote.srcChainId);
95
+ return [isBridgeTx, isIntent, isTronTx].some(Boolean);
96
+ };
97
+ exports.shouldPollHistoryItem = shouldPollHistoryItem;
98
+ //# sourceMappingURL=history.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.cjs","sourceRoot":"","sources":["../../src/utils/history.ts"],"names":[],"mappings":";;;AAAA,mEAIqC;AAQ9B,MAAM,uBAAuB,GAAG,CACrC,KAAkC,EAClC,QAAgB,EAChB,MAAqC,EAC5B,EAAE;IACX,MAAM,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG;QAC3B,GAAG,WA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qBAAqB,GAAG,CACnC,WAA8B,EACrB,EAAE;IACX,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACrD,MAAM,UAAU,GAAG,IAAA,gCAAY,EAC7B,WAAW,CAAC,KAAK,CAAC,UAAU,EAC5B,WAAW,CAAC,KAAK,CAAC,WAAW,CAC9B,CAAC;IACF,MAAM,QAAQ,GAAG,IAAA,iCAAa,EAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAE7D,OAAO,CAAC,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACxD,CAAC,CAAC;AAXW,QAAA,qBAAqB,yBAWhC","sourcesContent":["import {\n StatusTypes,\n isCrossChain,\n isTronChainId,\n} from '@metamask/bridge-controller';\n\nimport type {\n BridgeHistoryItem,\n BridgeStatusControllerState,\n StartPollingForBridgeTxStatusArgsSerialized,\n} from '../types';\n\nexport const rekeyHistoryItemInState = (\n state: BridgeStatusControllerState,\n actionId: string,\n txMeta: { id: string; hash?: string },\n): boolean => {\n const historyItem = state.txHistory[actionId];\n if (!historyItem) {\n return false;\n }\n\n state.txHistory[txMeta.id] = {\n ...historyItem,\n txMetaId: txMeta.id,\n originalTransactionId: historyItem.originalTransactionId ?? txMeta.id,\n status: {\n ...historyItem.status,\n srcChain: {\n ...historyItem.status.srcChain,\n txHash: txMeta.hash ?? historyItem.status.srcChain?.txHash,\n },\n },\n };\n delete state.txHistory[actionId];\n return true;\n};\n\n/**\n * Determines the key to use for storing a bridge history item.\n * Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.\n *\n * @param actionId - The action ID used for pre-submission tracking\n * @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta\n * @param syntheticTransactionId - The transactionId of the intent's placeholder transaction\n * @returns The key to use for the history item\n * @throws Error if neither actionId nor bridgeTxMetaId is provided\n */\nexport function getHistoryKey(\n actionId: string | undefined,\n bridgeTxMetaId: string | undefined,\n syntheticTransactionId?: string,\n): string {\n const historyKey = actionId ?? bridgeTxMetaId ?? syntheticTransactionId;\n if (!historyKey) {\n throw new Error(\n 'Cannot add tx to history: either actionId, bridgeTxMeta.id, or syntheticTransactionId must be provided',\n );\n }\n return historyKey;\n}\n\nexport const getInitialHistoryItem = (\n args: StartPollingForBridgeTxStatusArgsSerialized,\n): {\n historyKey: string;\n txHistoryItem: BridgeHistoryItem;\n} => {\n const {\n bridgeTxMeta,\n quoteResponse,\n startTime,\n slippagePercentage,\n initialDestAssetBalance,\n targetContractAddress,\n approvalTxId,\n isStxEnabled,\n location,\n abTests,\n activeAbTests,\n accountAddress: selectedAddress,\n originalTransactionId,\n actionId,\n } = args;\n // Determine the key for this history item:\n // - For pre-submission (non-batch EVM): use actionId\n // - For post-submission or other cases: use bridgeTxMeta.id\n const historyKey = getHistoryKey(\n actionId,\n bridgeTxMeta?.id,\n originalTransactionId,\n );\n\n // Write all non-status fields to state so we can reference the quote in Activity list without the Bridge API\n // We know it's in progress but not the exact status yet\n const txHistoryItem = {\n txMetaId: bridgeTxMeta?.id,\n actionId,\n originalTransactionId: originalTransactionId ?? bridgeTxMeta?.id, // Keep original for intent transactions\n batchId: bridgeTxMeta?.batchId,\n quote: quoteResponse.quote,\n startTime,\n estimatedProcessingTimeInSeconds:\n quoteResponse.estimatedProcessingTimeInSeconds,\n slippagePercentage,\n pricingData: {\n amountSent: quoteResponse.sentAmount?.amount ?? '0',\n amountSentInUsd: quoteResponse.sentAmount?.usd ?? undefined,\n quotedGasInUsd: quoteResponse.gasFee?.effective?.usd ?? undefined,\n quotedReturnInUsd: quoteResponse.toTokenAmount?.usd ?? undefined,\n quotedGasAmount: quoteResponse.gasFee?.effective?.amount ?? undefined,\n },\n initialDestAssetBalance,\n targetContractAddress,\n account: selectedAddress,\n status: {\n // We always have a PENDING status when we start polling for a tx, don't need the Bridge API for that\n // Also we know the bare minimum fields for status at this point in time\n status: StatusTypes.PENDING,\n srcChain: {\n chainId: quoteResponse.quote.srcChainId,\n txHash: bridgeTxMeta?.hash,\n },\n },\n hasApprovalTx: Boolean(quoteResponse.approval),\n approvalTxId,\n isStxEnabled: Boolean(isStxEnabled),\n featureId: quoteResponse.featureId,\n location,\n ...(abTests && { abTests }),\n ...(activeAbTests && { activeAbTests }),\n };\n\n return { historyKey, txHistoryItem };\n};\n\nexport const shouldPollHistoryItem = (\n historyItem: BridgeHistoryItem,\n): boolean => {\n const isIntent = Boolean(historyItem?.quote?.intent);\n const isBridgeTx = isCrossChain(\n historyItem.quote.srcChainId,\n historyItem.quote.destChainId,\n );\n const isTronTx = isTronChainId(historyItem.quote.srcChainId);\n\n return [isBridgeTx, isIntent, isTronTx].some(Boolean);\n};\n"]}
@@ -0,0 +1,22 @@
1
+ import type { BridgeHistoryItem, BridgeStatusControllerState, StartPollingForBridgeTxStatusArgsSerialized } from "../types.cjs";
2
+ export declare const rekeyHistoryItemInState: (state: BridgeStatusControllerState, actionId: string, txMeta: {
3
+ id: string;
4
+ hash?: string;
5
+ }) => boolean;
6
+ /**
7
+ * Determines the key to use for storing a bridge history item.
8
+ * Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.
9
+ *
10
+ * @param actionId - The action ID used for pre-submission tracking
11
+ * @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta
12
+ * @param syntheticTransactionId - The transactionId of the intent's placeholder transaction
13
+ * @returns The key to use for the history item
14
+ * @throws Error if neither actionId nor bridgeTxMetaId is provided
15
+ */
16
+ export declare function getHistoryKey(actionId: string | undefined, bridgeTxMetaId: string | undefined, syntheticTransactionId?: string): string;
17
+ export declare const getInitialHistoryItem: (args: StartPollingForBridgeTxStatusArgsSerialized) => {
18
+ historyKey: string;
19
+ txHistoryItem: BridgeHistoryItem;
20
+ };
21
+ export declare const shouldPollHistoryItem: (historyItem: BridgeHistoryItem) => boolean;
22
+ //# sourceMappingURL=history.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.d.cts","sourceRoot":"","sources":["../../src/utils/history.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,2CAA2C,EAC5C,qBAAiB;AAElB,eAAO,MAAM,uBAAuB,UAC3B,2BAA2B,YACxB,MAAM,UACR;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KACpC,OAoBF,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,sBAAsB,CAAC,EAAE,MAAM,GAC9B,MAAM,CAQR;AAED,eAAO,MAAM,qBAAqB,SAC1B,2CAA2C;gBAErC,MAAM;mBACH,iBAAiB;CAoEjC,CAAC;AAEF,eAAO,MAAM,qBAAqB,gBACnB,iBAAiB,KAC7B,OASF,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { BridgeHistoryItem, BridgeStatusControllerState, StartPollingForBridgeTxStatusArgsSerialized } from "../types.mjs";
2
+ export declare const rekeyHistoryItemInState: (state: BridgeStatusControllerState, actionId: string, txMeta: {
3
+ id: string;
4
+ hash?: string;
5
+ }) => boolean;
6
+ /**
7
+ * Determines the key to use for storing a bridge history item.
8
+ * Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.
9
+ *
10
+ * @param actionId - The action ID used for pre-submission tracking
11
+ * @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta
12
+ * @param syntheticTransactionId - The transactionId of the intent's placeholder transaction
13
+ * @returns The key to use for the history item
14
+ * @throws Error if neither actionId nor bridgeTxMetaId is provided
15
+ */
16
+ export declare function getHistoryKey(actionId: string | undefined, bridgeTxMetaId: string | undefined, syntheticTransactionId?: string): string;
17
+ export declare const getInitialHistoryItem: (args: StartPollingForBridgeTxStatusArgsSerialized) => {
18
+ historyKey: string;
19
+ txHistoryItem: BridgeHistoryItem;
20
+ };
21
+ export declare const shouldPollHistoryItem: (historyItem: BridgeHistoryItem) => boolean;
22
+ //# sourceMappingURL=history.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.d.mts","sourceRoot":"","sources":["../../src/utils/history.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,2CAA2C,EAC5C,qBAAiB;AAElB,eAAO,MAAM,uBAAuB,UAC3B,2BAA2B,YACxB,MAAM,UACR;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KACpC,OAoBF,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,sBAAsB,CAAC,EAAE,MAAM,GAC9B,MAAM,CAQR;AAED,eAAO,MAAM,qBAAqB,SAC1B,2CAA2C;gBAErC,MAAM;mBACH,iBAAiB;CAoEjC,CAAC;AAEF,eAAO,MAAM,qBAAqB,gBACnB,iBAAiB,KAC7B,OASF,CAAC"}