@metamask/bridge-status-controller 68.1.0 → 69.0.0
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.
- package/CHANGELOG.md +22 -1
- package/dist/bridge-status-controller.cjs +50 -33
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.cjs +3 -6
- package/dist/bridge-status-controller.intent.cjs.map +1 -1
- package/dist/bridge-status-controller.intent.d.cts +4 -3
- package/dist/bridge-status-controller.intent.d.cts.map +1 -1
- package/dist/bridge-status-controller.intent.d.mts +4 -3
- package/dist/bridge-status-controller.intent.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.mjs +4 -7
- package/dist/bridge-status-controller.intent.mjs.map +1 -1
- package/dist/bridge-status-controller.mjs +50 -33
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +2 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/bridge-status.cjs +2 -4
- package/dist/utils/bridge-status.cjs.map +1 -1
- package/dist/utils/bridge-status.d.cts.map +1 -1
- package/dist/utils/bridge-status.d.mts.map +1 -1
- package/dist/utils/bridge-status.mjs +2 -4
- package/dist/utils/bridge-status.mjs.map +1 -1
- package/dist/utils/gas.cjs +2 -2
- package/dist/utils/gas.cjs.map +1 -1
- package/dist/utils/gas.d.cts +1 -1
- package/dist/utils/gas.d.cts.map +1 -1
- package/dist/utils/gas.d.mts +1 -1
- package/dist/utils/gas.d.mts.map +1 -1
- package/dist/utils/gas.mjs +2 -2
- package/dist/utils/gas.mjs.map +1 -1
- package/dist/utils/intent-api.cjs +2 -2
- package/dist/utils/intent-api.cjs.map +1 -1
- package/dist/utils/intent-api.d.cts +8 -7
- package/dist/utils/intent-api.d.cts.map +1 -1
- package/dist/utils/intent-api.d.mts +8 -7
- package/dist/utils/intent-api.d.mts.map +1 -1
- package/dist/utils/intent-api.mjs +4 -4
- package/dist/utils/intent-api.mjs.map +1 -1
- package/dist/utils/transaction.cjs +23 -14
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +4 -2
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +4 -2
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +23 -14
- package/dist/utils/transaction.mjs.map +1 -1
- package/dist/utils/validators.cjs +5 -5
- package/dist/utils/validators.cjs.map +1 -1
- package/dist/utils/validators.d.cts +5 -10
- package/dist/utils/validators.d.cts.map +1 -1
- package/dist/utils/validators.d.mts +5 -10
- package/dist/utils/validators.d.mts.map +1 -1
- package/dist/utils/validators.mjs +3 -3
- package/dist/utils/validators.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge-status-controller.intent.cjs","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAA0D;AAM1D,uDAO4B;AAC5B,uDAAoE;AAOpE,MAAa,aAAa;IAUxB,YAAY,EACV,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,OAAO,EACP,MAAM,GAOP;;QArBQ,2CAA4C;QAE5C,qDAA+E;QAI/E,wDACP,IAAI,GAAG,EAAE,EAAC;QAiDZ;;;;;;;WAOG;QAEH,+BAA0B,GAAG,KAAK,EAChC,cAAsB,EACtB,WAA8B,EAC9B,QAAgB,EACqB,EAAE;YACvC,MAAM,EACJ,MAAM,EAAE,SAAS,EACjB,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,GAC9B,GAAG,WAAW,CAAC;YAChB,MAAM,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,IAAI,EAAE,CAAC;YACj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AC;gBACf,OAAO,CAAC,KAAK,CAAC,sDAAsD,EAAE;oBACpE,YAAY;oBACZ,gBAAgB,EAAE,cAAc;oBAChC,KAAK;iBACN,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC;QAEF;;;;;;WAMG;QACH,iBAAY,GAAG,KAAK,EAClB,gBAAwC,EACxC,QAAgB,EACM,EAAE;YACxB,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QACjE,CAAC,CAAC;QA9KA,uBAAA,IAAI,4BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,sCAAwB,mBAAmB,MAAA,CAAC;QAChD,IAAI,CAAC,SAAS,GAAG,IAAI,0BAAa,CAAC,sBAAsB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9E,CAAC;CA4KF;AAtMD,sCAsMC;oRA/JG,cAAsB,EACtB,KAAkB,EAClB,UAAkB,EAClB,MAAc;IAEd,MAAM,YAAY,GAAG,IAAA,+CAAkC,EACrD,KAAK,EACL,UAAU,EACV,MAAM,CAAC,QAAQ,EAAE,CAClB,CAAC;IACF,MAAM,cAAc,GAAmB;QACrC,WAAW,EAAE,KAAK,CAAC,MAAM;QACzB,YAAY;KACb,CAAC;IACF,uBAAA,IAAI,qDAAgC,CAAC,GAAG,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACzE,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["import { StatusTypes } from '@metamask/bridge-controller';\nimport type { TransactionController } from '@metamask/transaction-controller';\nimport { TransactionMeta } from '@metamask/transaction-controller';\n\nimport type { BridgeStatusControllerMessenger, FetchFunction } from './types';\nimport type { BridgeHistoryItem } from './types';\nimport {\n GetJwtFn,\n IntentApi,\n IntentApiImpl,\n IntentBridgeStatus,\n IntentSubmissionParams,\n translateIntentOrderToBridgeStatus,\n} from './utils/intent-api';\nimport { IntentOrder, IntentOrderStatus } from './utils/validators';\n\ntype IntentStatuses = {\n orderStatus: IntentOrderStatus;\n bridgeStatus: IntentBridgeStatus | null;\n};\n\nexport class IntentManager {\n readonly #messenger: BridgeStatusControllerMessenger;\n\n readonly #updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n\n readonly intentApi: IntentApi;\n\n readonly #intentStatusesByBridgeTxMetaId: Map<string, IntentStatuses> =\n new Map();\n\n constructor({\n messenger,\n updateTransactionFn,\n customBridgeApiBaseUrl,\n fetchFn,\n getJwt,\n }: {\n messenger: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n customBridgeApiBaseUrl: string;\n fetchFn: FetchFunction;\n getJwt: GetJwtFn;\n }) {\n this.#messenger = messenger;\n this.#updateTransactionFn = updateTransactionFn;\n this.intentApi = new IntentApiImpl(customBridgeApiBaseUrl, fetchFn, getJwt);\n }\n\n /**\n * Set the intent statuses for a given bridge transaction.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID (key for storage).\n * @param order - The intent order.\n * @param srcChainId - The source chain ID.\n * @param txHash - The transaction hash.\n * @returns The intent statuses.\n */\n\n #setIntentStatuses(\n bridgeTxMetaId: string,\n order: IntentOrder,\n srcChainId: number,\n txHash: string,\n ): IntentStatuses {\n const bridgeStatus = translateIntentOrderToBridgeStatus(\n order,\n srcChainId,\n txHash.toString(),\n );\n const intentStatuses: IntentStatuses = {\n orderStatus: order.status,\n bridgeStatus,\n };\n this.#intentStatusesByBridgeTxMetaId.set(bridgeTxMetaId, intentStatuses);\n return intentStatuses;\n }\n\n /**\n * Get the status of an intent order.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID.\n * @param protocol - The protocol of the intent.\n * @param clientId - The client ID.\n * @returns The intent order mapped status.\n */\n\n getIntentTransactionStatus = async (\n bridgeTxMetaId: string,\n historyItem: BridgeHistoryItem,\n clientId: string,\n ): Promise<IntentStatuses | undefined> => {\n const {\n status: statusObj,\n quote: { srcChainId, intent },\n } = historyItem;\n const txHash = statusObj?.srcChain?.txHash ?? '';\n const protocol = intent?.protocol ?? '';\n\n try {\n const orderStatus = await this.intentApi.getOrderStatus(\n bridgeTxMetaId,\n protocol,\n srcChainId.toString(),\n clientId,\n );\n\n return this.#setIntentStatuses(\n bridgeTxMetaId,\n orderStatus,\n srcChainId,\n txHash.toString(),\n );\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(\n `[Intent polling] Failed to get intent order status from API: ${error.message}`,\n );\n }\n return undefined;\n }\n };\n\n /**\n * Sync the transaction status from the intent status.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID.\n * @param historyItem - The history item.\n */\n\n syncTransactionFromIntentStatus = (\n bridgeTxMetaId: string,\n historyItem: BridgeHistoryItem,\n ): void => {\n // Update the actual transaction in TransactionController to sync with intent status\n // Use the original transaction ID (not the bridge history key)\n const originalTxId =\n historyItem.originalTransactionId ?? historyItem.txMetaId;\n if (!originalTxId) {\n return;\n }\n\n const intentStatuses =\n this.#intentStatusesByBridgeTxMetaId.get(bridgeTxMetaId);\n if (!intentStatuses) {\n return;\n }\n\n try {\n // Merge with existing TransactionMeta to avoid wiping required fields\n const { transactions } = this.#messenger.call(\n 'TransactionController:getState',\n );\n const existingTxMeta = transactions.find(\n (tx: TransactionMeta) => tx.id === originalTxId,\n );\n if (!existingTxMeta) {\n console.warn(\n '[Intent polling] Skipping update, transaction not found',\n { originalTxId, bridgeHistoryKey: bridgeTxMetaId },\n );\n return;\n }\n const { bridgeStatus, orderStatus } = intentStatuses;\n const txHash = bridgeStatus?.txHash;\n const isComplete = bridgeStatus?.status.status === StatusTypes.COMPLETE;\n const isFinalStatus =\n bridgeStatus?.status.status === StatusTypes.COMPLETE ||\n bridgeStatus?.status.status === StatusTypes.FAILED;\n const existingTxReceipt = (\n existingTxMeta as { txReceipt?: Record<string, unknown> }\n ).txReceipt;\n const txReceiptUpdate = txHash\n ? {\n txReceipt: {\n ...existingTxReceipt,\n transactionHash: txHash,\n status: (isComplete ? '0x1' : '0x0') as unknown as string,\n },\n }\n : {};\n\n const updatedTxMeta: TransactionMeta = {\n ...existingTxMeta,\n status: bridgeStatus?.transactionStatus,\n ...(txHash ? { hash: txHash } : {}),\n ...txReceiptUpdate,\n } as TransactionMeta;\n\n this.#updateTransactionFn(\n updatedTxMeta,\n `BridgeStatusController - Intent order status updated: ${orderStatus}`,\n );\n\n if (isFinalStatus) {\n this.#intentStatusesByBridgeTxMetaId.delete(bridgeTxMetaId);\n }\n } catch (error) {\n console.error('[Intent polling] Failed to update transaction status', {\n originalTxId,\n bridgeHistoryKey: bridgeTxMetaId,\n error,\n });\n }\n };\n\n /**\n * Submit an intent order.\n *\n * @param submissionParams - The submission parameters.\n * @param clientId - The client ID.\n * @returns The intent order.\n */\n submitIntent = async (\n submissionParams: IntentSubmissionParams,\n clientId: string,\n ): Promise<IntentOrder> => {\n return this.intentApi.submitIntent(submissionParams, clientId);\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bridge-status-controller.intent.cjs","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAA0E;AAM1E,uDAO4B;AAC5B,uDAA6E;AAO7E,MAAa,aAAa;IAUxB,YAAY,EACV,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,OAAO,EACP,MAAM,GAOP;;QArBQ,2CAA4C;QAE5C,qDAA+E;QAI/E,wDACP,IAAI,GAAG,EAAE,EAAC;QAiDZ;;;;;;;WAOG;QAEH,+BAA0B,GAAG,KAAK,EAChC,cAAsB,EACtB,UAAkB,EAClB,QAAgB,EAChB,QAAwB,EACxB,SAAiB,EAAE,EACkB,EAAE;YACvC,IAAI,CAAC;gBACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,cAAc,CACrD,cAAc,EACd,QAAQ,EACR,UAAU,EACV,QAAQ,CACT,CAAC;gBAEF,OAAO,uBAAA,IAAI,kEAAmB,MAAvB,IAAI,EACT,cAAc,EACd,WAAW,EACX,UAAU,EACV,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AC,CAAC;QACjE,CAAC,CAAC;QAzKA,uBAAA,IAAI,4BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,sCAAwB,mBAAmB,MAAA,CAAC;QAChD,IAAI,CAAC,SAAS,GAAG,IAAI,0BAAa,CAAC,sBAAsB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9E,CAAC;CAuKF;AAjMD,sCAiMC;oRA1JG,cAAsB,EACtB,KAA2B,EAC3B,UAAkB,EAClB,MAAc;IAEd,MAAM,YAAY,GAAG,IAAA,+CAAkC,EACrD,KAAK,EACL,UAAU,EACV,MAAM,CACP,CAAC;IACF,MAAM,cAAc,GAAmB;QACrC,WAAW,EAAE,KAAK,CAAC,MAAM;QACzB,YAAY;KACb,CAAC;IACF,uBAAA,IAAI,qDAAgC,CAAC,GAAG,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACzE,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["import { BridgeClientId, StatusTypes } from '@metamask/bridge-controller';\nimport type { TransactionController } from '@metamask/transaction-controller';\nimport { TransactionMeta } from '@metamask/transaction-controller';\n\nimport type { BridgeStatusControllerMessenger, FetchFunction } from './types';\nimport type { BridgeHistoryItem } from './types';\nimport {\n GetJwtFn,\n IntentApi,\n IntentApiImpl,\n IntentBridgeStatus,\n IntentSubmissionParams,\n translateIntentOrderToBridgeStatus,\n} from './utils/intent-api';\nimport { IntentStatusResponse, IntentOrderStatus } from './utils/validators';\n\ntype IntentStatuses = {\n orderStatus: IntentOrderStatus;\n bridgeStatus: IntentBridgeStatus | null;\n};\n\nexport class IntentManager {\n readonly #messenger: BridgeStatusControllerMessenger;\n\n readonly #updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n\n readonly intentApi: IntentApi;\n\n readonly #intentStatusesByBridgeTxMetaId: Map<string, IntentStatuses> =\n new Map();\n\n constructor({\n messenger,\n updateTransactionFn,\n customBridgeApiBaseUrl,\n fetchFn,\n getJwt,\n }: {\n messenger: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n customBridgeApiBaseUrl: string;\n fetchFn: FetchFunction;\n getJwt: GetJwtFn;\n }) {\n this.#messenger = messenger;\n this.#updateTransactionFn = updateTransactionFn;\n this.intentApi = new IntentApiImpl(customBridgeApiBaseUrl, fetchFn, getJwt);\n }\n\n /**\n * Set the intent statuses for a given bridge transaction.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID (key for storage).\n * @param order - The intent order.\n * @param srcChainId - The source chain ID.\n * @param txHash - The transaction hash.\n * @returns The intent statuses.\n */\n\n #setIntentStatuses(\n bridgeTxMetaId: string,\n order: IntentStatusResponse,\n srcChainId: number,\n txHash: string,\n ): IntentStatuses {\n const bridgeStatus = translateIntentOrderToBridgeStatus(\n order,\n srcChainId,\n txHash,\n );\n const intentStatuses: IntentStatuses = {\n orderStatus: order.status,\n bridgeStatus,\n };\n this.#intentStatusesByBridgeTxMetaId.set(bridgeTxMetaId, intentStatuses);\n return intentStatuses;\n }\n\n /**\n * Get the status of an intent order.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID.\n * @param protocol - The protocol of the intent.\n * @param clientId - The client ID.\n * @returns The intent order mapped status.\n */\n\n getIntentTransactionStatus = async (\n bridgeTxMetaId: string,\n srcChainId: number,\n protocol: string,\n clientId: BridgeClientId,\n txHash: string = '',\n ): Promise<IntentStatuses | undefined> => {\n try {\n const orderStatus = await this.intentApi.getOrderStatus(\n bridgeTxMetaId,\n protocol,\n srcChainId,\n clientId,\n );\n\n return this.#setIntentStatuses(\n bridgeTxMetaId,\n orderStatus,\n srcChainId,\n txHash.toString(),\n );\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(\n `[Intent polling] Failed to get intent order status from API: ${error.message}`,\n );\n }\n return undefined;\n }\n };\n\n /**\n * Sync the transaction status from the intent status.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID.\n * @param historyItem - The history item.\n */\n\n syncTransactionFromIntentStatus = (\n bridgeTxMetaId: string,\n historyItem: BridgeHistoryItem,\n ): void => {\n // Update the actual transaction in TransactionController to sync with intent status\n // Use the original transaction ID (not the bridge history key)\n const originalTxId =\n historyItem.originalTransactionId ?? historyItem.txMetaId;\n if (!originalTxId) {\n return;\n }\n\n const intentStatuses =\n this.#intentStatusesByBridgeTxMetaId.get(bridgeTxMetaId);\n if (!intentStatuses) {\n return;\n }\n\n try {\n // Merge with existing TransactionMeta to avoid wiping required fields\n const { transactions } = this.#messenger.call(\n 'TransactionController:getState',\n );\n const existingTxMeta = transactions.find(\n (tx: TransactionMeta) => tx.id === originalTxId,\n );\n if (!existingTxMeta) {\n console.warn(\n '[Intent polling] Skipping update, transaction not found',\n { originalTxId, bridgeHistoryKey: bridgeTxMetaId },\n );\n return;\n }\n const { bridgeStatus, orderStatus } = intentStatuses;\n const txHash = bridgeStatus?.txHash;\n const isComplete = bridgeStatus?.status.status === StatusTypes.COMPLETE;\n const isFinalStatus =\n bridgeStatus?.status.status === StatusTypes.COMPLETE ||\n bridgeStatus?.status.status === StatusTypes.FAILED;\n const existingTxReceipt = (\n existingTxMeta as { txReceipt?: Record<string, unknown> }\n ).txReceipt;\n const txReceiptUpdate = txHash\n ? {\n txReceipt: {\n ...existingTxReceipt,\n transactionHash: txHash,\n status: (isComplete ? '0x1' : '0x0') as unknown as string,\n },\n }\n : {};\n\n const updatedTxMeta: TransactionMeta = {\n ...existingTxMeta,\n status: bridgeStatus?.transactionStatus,\n ...(txHash ? { hash: txHash } : {}),\n ...txReceiptUpdate,\n } as TransactionMeta;\n\n this.#updateTransactionFn(\n updatedTxMeta,\n `BridgeStatusController - Intent order status updated: ${orderStatus}`,\n );\n\n if (isFinalStatus) {\n this.#intentStatusesByBridgeTxMetaId.delete(bridgeTxMetaId);\n }\n } catch (error) {\n console.error('[Intent polling] Failed to update transaction status', {\n originalTxId,\n bridgeHistoryKey: bridgeTxMetaId,\n error,\n });\n }\n };\n\n /**\n * Submit an intent order.\n *\n * @param submissionParams - The submission parameters.\n * @param clientId - The client ID.\n * @returns The intent order.\n */\n submitIntent = async (\n submissionParams: IntentSubmissionParams,\n clientId: BridgeClientId,\n ): Promise<IntentStatusResponse> => {\n return this.intentApi.submitIntent(submissionParams, clientId);\n };\n}\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { BridgeClientId } from "@metamask/bridge-controller";
|
|
1
2
|
import type { TransactionController } from "@metamask/transaction-controller";
|
|
2
3
|
import type { BridgeStatusControllerMessenger, FetchFunction } from "./types.cjs";
|
|
3
4
|
import type { BridgeHistoryItem } from "./types.cjs";
|
|
4
5
|
import { GetJwtFn, IntentApi, IntentBridgeStatus, IntentSubmissionParams } from "./utils/intent-api.cjs";
|
|
5
|
-
import {
|
|
6
|
+
import { IntentStatusResponse, IntentOrderStatus } from "./utils/validators.cjs";
|
|
6
7
|
type IntentStatuses = {
|
|
7
8
|
orderStatus: IntentOrderStatus;
|
|
8
9
|
bridgeStatus: IntentBridgeStatus | null;
|
|
@@ -25,7 +26,7 @@ export declare class IntentManager {
|
|
|
25
26
|
* @param clientId - The client ID.
|
|
26
27
|
* @returns The intent order mapped status.
|
|
27
28
|
*/
|
|
28
|
-
getIntentTransactionStatus: (bridgeTxMetaId: string,
|
|
29
|
+
getIntentTransactionStatus: (bridgeTxMetaId: string, srcChainId: number, protocol: string, clientId: BridgeClientId, txHash?: string) => Promise<IntentStatuses | undefined>;
|
|
29
30
|
/**
|
|
30
31
|
* Sync the transaction status from the intent status.
|
|
31
32
|
*
|
|
@@ -40,7 +41,7 @@ export declare class IntentManager {
|
|
|
40
41
|
* @param clientId - The client ID.
|
|
41
42
|
* @returns The intent order.
|
|
42
43
|
*/
|
|
43
|
-
submitIntent: (submissionParams: IntentSubmissionParams, clientId:
|
|
44
|
+
submitIntent: (submissionParams: IntentSubmissionParams, clientId: BridgeClientId) => Promise<IntentStatusResponse>;
|
|
44
45
|
}
|
|
45
46
|
export {};
|
|
46
47
|
//# sourceMappingURL=bridge-status-controller.intent.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge-status-controller.intent.d.cts","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bridge-status-controller.intent.d.cts","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAe,oCAAoC;AAC1E,OAAO,KAAK,EAAE,qBAAqB,EAAE,yCAAyC;AAG9E,OAAO,KAAK,EAAE,+BAA+B,EAAE,aAAa,EAAE,oBAAgB;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAgB;AACjD,OAAO,EACL,QAAQ,EACR,SAAS,EAET,kBAAkB,EAClB,sBAAsB,EAEvB,+BAA2B;AAC5B,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,+BAA2B;AAE7E,KAAK,cAAc,GAAG;IACpB,WAAW,EAAE,iBAAiB,CAAC;IAC/B,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACzC,CAAC;AAEF,qBAAa,aAAa;;IAKxB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAKlB,EACV,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,OAAO,EACP,MAAM,GACP,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,mBAAmB,EAAE,OAAO,qBAAqB,CAAC,SAAS,CAAC,iBAAiB,CAAC;QAC9E,sBAAsB,EAAE,MAAM,CAAC;QAC/B,OAAO,EAAE,aAAa,CAAC;QACvB,MAAM,EAAE,QAAQ,CAAC;KAClB;IAmCD;;;;;;;OAOG;IAEH,0BAA0B,mBACR,MAAM,cACV,MAAM,YACR,MAAM,YACN,cAAc,WAChB,MAAM,KACb,QAAQ,cAAc,GAAG,SAAS,CAAC,CAuBpC;IAEF;;;;;OAKG;IAEH,+BAA+B,mBACb,MAAM,eACT,iBAAiB,KAC7B,IAAI,CAuEL;IAEF;;;;;;OAMG;IACH,YAAY,qBACQ,sBAAsB,YAC9B,cAAc,KACvB,QAAQ,oBAAoB,CAAC,CAE9B;CACH"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { BridgeClientId } from "@metamask/bridge-controller";
|
|
1
2
|
import type { TransactionController } from "@metamask/transaction-controller";
|
|
2
3
|
import type { BridgeStatusControllerMessenger, FetchFunction } from "./types.mjs";
|
|
3
4
|
import type { BridgeHistoryItem } from "./types.mjs";
|
|
4
5
|
import { GetJwtFn, IntentApi, IntentBridgeStatus, IntentSubmissionParams } from "./utils/intent-api.mjs";
|
|
5
|
-
import {
|
|
6
|
+
import { IntentStatusResponse, IntentOrderStatus } from "./utils/validators.mjs";
|
|
6
7
|
type IntentStatuses = {
|
|
7
8
|
orderStatus: IntentOrderStatus;
|
|
8
9
|
bridgeStatus: IntentBridgeStatus | null;
|
|
@@ -25,7 +26,7 @@ export declare class IntentManager {
|
|
|
25
26
|
* @param clientId - The client ID.
|
|
26
27
|
* @returns The intent order mapped status.
|
|
27
28
|
*/
|
|
28
|
-
getIntentTransactionStatus: (bridgeTxMetaId: string,
|
|
29
|
+
getIntentTransactionStatus: (bridgeTxMetaId: string, srcChainId: number, protocol: string, clientId: BridgeClientId, txHash?: string) => Promise<IntentStatuses | undefined>;
|
|
29
30
|
/**
|
|
30
31
|
* Sync the transaction status from the intent status.
|
|
31
32
|
*
|
|
@@ -40,7 +41,7 @@ export declare class IntentManager {
|
|
|
40
41
|
* @param clientId - The client ID.
|
|
41
42
|
* @returns The intent order.
|
|
42
43
|
*/
|
|
43
|
-
submitIntent: (submissionParams: IntentSubmissionParams, clientId:
|
|
44
|
+
submitIntent: (submissionParams: IntentSubmissionParams, clientId: BridgeClientId) => Promise<IntentStatusResponse>;
|
|
44
45
|
}
|
|
45
46
|
export {};
|
|
46
47
|
//# sourceMappingURL=bridge-status-controller.intent.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge-status-controller.intent.d.mts","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bridge-status-controller.intent.d.mts","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAe,oCAAoC;AAC1E,OAAO,KAAK,EAAE,qBAAqB,EAAE,yCAAyC;AAG9E,OAAO,KAAK,EAAE,+BAA+B,EAAE,aAAa,EAAE,oBAAgB;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAgB;AACjD,OAAO,EACL,QAAQ,EACR,SAAS,EAET,kBAAkB,EAClB,sBAAsB,EAEvB,+BAA2B;AAC5B,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,+BAA2B;AAE7E,KAAK,cAAc,GAAG;IACpB,WAAW,EAAE,iBAAiB,CAAC;IAC/B,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACzC,CAAC;AAEF,qBAAa,aAAa;;IAKxB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAKlB,EACV,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,OAAO,EACP,MAAM,GACP,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,mBAAmB,EAAE,OAAO,qBAAqB,CAAC,SAAS,CAAC,iBAAiB,CAAC;QAC9E,sBAAsB,EAAE,MAAM,CAAC;QAC/B,OAAO,EAAE,aAAa,CAAC;QACvB,MAAM,EAAE,QAAQ,CAAC;KAClB;IAmCD;;;;;;;OAOG;IAEH,0BAA0B,mBACR,MAAM,cACV,MAAM,YACR,MAAM,YACN,cAAc,WAChB,MAAM,KACb,QAAQ,cAAc,GAAG,SAAS,CAAC,CAuBpC;IAEF;;;;;OAKG;IAEH,+BAA+B,mBACb,MAAM,eACT,iBAAiB,KAC7B,IAAI,CAuEL;IAEF;;;;;;OAMG;IACH,YAAY,qBACQ,sBAAsB,YAC9B,cAAc,KACvB,QAAQ,oBAAoB,CAAC,CAE9B;CACH"}
|
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _IntentManager_instances, _IntentManager_messenger, _IntentManager_updateTransactionFn, _IntentManager_intentStatusesByBridgeTxMetaId, _IntentManager_setIntentStatuses;
|
|
13
|
-
import { StatusTypes } from "@metamask/bridge-controller";
|
|
13
|
+
import { BridgeClientId, StatusTypes } from "@metamask/bridge-controller";
|
|
14
14
|
import { IntentApiImpl, translateIntentOrderToBridgeStatus } from "./utils/intent-api.mjs";
|
|
15
15
|
import { IntentOrderStatus } from "./utils/validators.mjs";
|
|
16
16
|
export class IntentManager {
|
|
@@ -27,12 +27,9 @@ export class IntentManager {
|
|
|
27
27
|
* @param clientId - The client ID.
|
|
28
28
|
* @returns The intent order mapped status.
|
|
29
29
|
*/
|
|
30
|
-
this.getIntentTransactionStatus = async (bridgeTxMetaId,
|
|
31
|
-
const { status: statusObj, quote: { srcChainId, intent }, } = historyItem;
|
|
32
|
-
const txHash = statusObj?.srcChain?.txHash ?? '';
|
|
33
|
-
const protocol = intent?.protocol ?? '';
|
|
30
|
+
this.getIntentTransactionStatus = async (bridgeTxMetaId, srcChainId, protocol, clientId, txHash = '') => {
|
|
34
31
|
try {
|
|
35
|
-
const orderStatus = await this.intentApi.getOrderStatus(bridgeTxMetaId, protocol, srcChainId
|
|
32
|
+
const orderStatus = await this.intentApi.getOrderStatus(bridgeTxMetaId, protocol, srcChainId, clientId);
|
|
36
33
|
return __classPrivateFieldGet(this, _IntentManager_instances, "m", _IntentManager_setIntentStatuses).call(this, bridgeTxMetaId, orderStatus, srcChainId, txHash.toString());
|
|
37
34
|
}
|
|
38
35
|
catch (error) {
|
|
@@ -117,7 +114,7 @@ export class IntentManager {
|
|
|
117
114
|
}
|
|
118
115
|
}
|
|
119
116
|
_IntentManager_messenger = new WeakMap(), _IntentManager_updateTransactionFn = new WeakMap(), _IntentManager_intentStatusesByBridgeTxMetaId = new WeakMap(), _IntentManager_instances = new WeakSet(), _IntentManager_setIntentStatuses = function _IntentManager_setIntentStatuses(bridgeTxMetaId, order, srcChainId, txHash) {
|
|
120
|
-
const bridgeStatus = translateIntentOrderToBridgeStatus(order, srcChainId, txHash
|
|
117
|
+
const bridgeStatus = translateIntentOrderToBridgeStatus(order, srcChainId, txHash);
|
|
121
118
|
const intentStatuses = {
|
|
122
119
|
orderStatus: order.status,
|
|
123
120
|
bridgeStatus,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge-status-controller.intent.mjs","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,oCAAoC;AAM1D,OAAO,EAGL,aAAa,EAGb,kCAAkC,EACnC,+BAA2B;AAC5B,OAAO,EAAe,iBAAiB,EAAE,+BAA2B;AAOpE,MAAM,OAAO,aAAa;IAUxB,YAAY,EACV,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,OAAO,EACP,MAAM,GAOP;;QArBQ,2CAA4C;QAE5C,qDAA+E;QAI/E,wDACP,IAAI,GAAG,EAAE,EAAC;QAiDZ;;;;;;;WAOG;QAEH,+BAA0B,GAAG,KAAK,EAChC,cAAsB,EACtB,WAA8B,EAC9B,QAAgB,EACqB,EAAE;YACvC,MAAM,EACJ,MAAM,EAAE,SAAS,EACjB,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,GAC9B,GAAG,WAAW,CAAC;YAChB,MAAM,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,IAAI,EAAE,CAAC;YACjD,MAAM,QAAQ,GAAG,MAAM,EAAE,QAAQ,IAAI,EAAE,CAAC;YAExC,IAAI,CAAC;gBACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC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ACL,CAAC;QACH,CAAC,CAAC;QAEF;;;;;;WAMG;QACH,iBAAY,GAAG,KAAK,EAClB,gBAAwC,EACxC,QAAgB,EACM,EAAE;YACxB,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QACjE,CAAC,CAAC;QA9KA,uBAAA,IAAI,4BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,sCAAwB,mBAAmB,MAAA,CAAC;QAChD,IAAI,CAAC,SAAS,GAAG,IAAI,aAAa,CAAC,sBAAsB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9E,CAAC;CA4KF;oRA/JG,cAAsB,EACtB,KAAkB,EAClB,UAAkB,EAClB,MAAc;IAEd,MAAM,YAAY,GAAG,kCAAkC,CACrD,KAAK,EACL,UAAU,EACV,MAAM,CAAC,QAAQ,EAAE,CAClB,CAAC;IACF,MAAM,cAAc,GAAmB;QACrC,WAAW,EAAE,KAAK,CAAC,MAAM;QACzB,YAAY;KACb,CAAC;IACF,uBAAA,IAAI,qDAAgC,CAAC,GAAG,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACzE,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["import { StatusTypes } from '@metamask/bridge-controller';\nimport type { TransactionController } from '@metamask/transaction-controller';\nimport { TransactionMeta } from '@metamask/transaction-controller';\n\nimport type { BridgeStatusControllerMessenger, FetchFunction } from './types';\nimport type { BridgeHistoryItem } from './types';\nimport {\n GetJwtFn,\n IntentApi,\n IntentApiImpl,\n IntentBridgeStatus,\n IntentSubmissionParams,\n translateIntentOrderToBridgeStatus,\n} from './utils/intent-api';\nimport { IntentOrder, IntentOrderStatus } from './utils/validators';\n\ntype IntentStatuses = {\n orderStatus: IntentOrderStatus;\n bridgeStatus: IntentBridgeStatus | null;\n};\n\nexport class IntentManager {\n readonly #messenger: BridgeStatusControllerMessenger;\n\n readonly #updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n\n readonly intentApi: IntentApi;\n\n readonly #intentStatusesByBridgeTxMetaId: Map<string, IntentStatuses> =\n new Map();\n\n constructor({\n messenger,\n updateTransactionFn,\n customBridgeApiBaseUrl,\n fetchFn,\n getJwt,\n }: {\n messenger: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n customBridgeApiBaseUrl: string;\n fetchFn: FetchFunction;\n getJwt: GetJwtFn;\n }) {\n this.#messenger = messenger;\n this.#updateTransactionFn = updateTransactionFn;\n this.intentApi = new IntentApiImpl(customBridgeApiBaseUrl, fetchFn, getJwt);\n }\n\n /**\n * Set the intent statuses for a given bridge transaction.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID (key for storage).\n * @param order - The intent order.\n * @param srcChainId - The source chain ID.\n * @param txHash - The transaction hash.\n * @returns The intent statuses.\n */\n\n #setIntentStatuses(\n bridgeTxMetaId: string,\n order: IntentOrder,\n srcChainId: number,\n txHash: string,\n ): IntentStatuses {\n const bridgeStatus = translateIntentOrderToBridgeStatus(\n order,\n srcChainId,\n txHash.toString(),\n );\n const intentStatuses: IntentStatuses = {\n orderStatus: order.status,\n bridgeStatus,\n };\n this.#intentStatusesByBridgeTxMetaId.set(bridgeTxMetaId, intentStatuses);\n return intentStatuses;\n }\n\n /**\n * Get the status of an intent order.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID.\n * @param protocol - The protocol of the intent.\n * @param clientId - The client ID.\n * @returns The intent order mapped status.\n */\n\n getIntentTransactionStatus = async (\n bridgeTxMetaId: string,\n historyItem: BridgeHistoryItem,\n clientId: string,\n ): Promise<IntentStatuses | undefined> => {\n const {\n status: statusObj,\n quote: { srcChainId, intent },\n } = historyItem;\n const txHash = statusObj?.srcChain?.txHash ?? '';\n const protocol = intent?.protocol ?? '';\n\n try {\n const orderStatus = await this.intentApi.getOrderStatus(\n bridgeTxMetaId,\n protocol,\n srcChainId.toString(),\n clientId,\n );\n\n return this.#setIntentStatuses(\n bridgeTxMetaId,\n orderStatus,\n srcChainId,\n txHash.toString(),\n );\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(\n `[Intent polling] Failed to get intent order status from API: ${error.message}`,\n );\n }\n return undefined;\n }\n };\n\n /**\n * Sync the transaction status from the intent status.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID.\n * @param historyItem - The history item.\n */\n\n syncTransactionFromIntentStatus = (\n bridgeTxMetaId: string,\n historyItem: BridgeHistoryItem,\n ): void => {\n // Update the actual transaction in TransactionController to sync with intent status\n // Use the original transaction ID (not the bridge history key)\n const originalTxId =\n historyItem.originalTransactionId ?? historyItem.txMetaId;\n if (!originalTxId) {\n return;\n }\n\n const intentStatuses =\n this.#intentStatusesByBridgeTxMetaId.get(bridgeTxMetaId);\n if (!intentStatuses) {\n return;\n }\n\n try {\n // Merge with existing TransactionMeta to avoid wiping required fields\n const { transactions } = this.#messenger.call(\n 'TransactionController:getState',\n );\n const existingTxMeta = transactions.find(\n (tx: TransactionMeta) => tx.id === originalTxId,\n );\n if (!existingTxMeta) {\n console.warn(\n '[Intent polling] Skipping update, transaction not found',\n { originalTxId, bridgeHistoryKey: bridgeTxMetaId },\n );\n return;\n }\n const { bridgeStatus, orderStatus } = intentStatuses;\n const txHash = bridgeStatus?.txHash;\n const isComplete = bridgeStatus?.status.status === StatusTypes.COMPLETE;\n const isFinalStatus =\n bridgeStatus?.status.status === StatusTypes.COMPLETE ||\n bridgeStatus?.status.status === StatusTypes.FAILED;\n const existingTxReceipt = (\n existingTxMeta as { txReceipt?: Record<string, unknown> }\n ).txReceipt;\n const txReceiptUpdate = txHash\n ? {\n txReceipt: {\n ...existingTxReceipt,\n transactionHash: txHash,\n status: (isComplete ? '0x1' : '0x0') as unknown as string,\n },\n }\n : {};\n\n const updatedTxMeta: TransactionMeta = {\n ...existingTxMeta,\n status: bridgeStatus?.transactionStatus,\n ...(txHash ? { hash: txHash } : {}),\n ...txReceiptUpdate,\n } as TransactionMeta;\n\n this.#updateTransactionFn(\n updatedTxMeta,\n `BridgeStatusController - Intent order status updated: ${orderStatus}`,\n );\n\n if (isFinalStatus) {\n this.#intentStatusesByBridgeTxMetaId.delete(bridgeTxMetaId);\n }\n } catch (error) {\n console.error('[Intent polling] Failed to update transaction status', {\n originalTxId,\n bridgeHistoryKey: bridgeTxMetaId,\n error,\n });\n }\n };\n\n /**\n * Submit an intent order.\n *\n * @param submissionParams - The submission parameters.\n * @param clientId - The client ID.\n * @returns The intent order.\n */\n submitIntent = async (\n submissionParams: IntentSubmissionParams,\n clientId: string,\n ): Promise<IntentOrder> => {\n return this.intentApi.submitIntent(submissionParams, clientId);\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bridge-status-controller.intent.mjs","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,oCAAoC;AAM1E,OAAO,EAGL,aAAa,EAGb,kCAAkC,EACnC,+BAA2B;AAC5B,OAAO,EAAwB,iBAAiB,EAAE,+BAA2B;AAO7E,MAAM,OAAO,aAAa;IAUxB,YAAY,EACV,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,OAAO,EACP,MAAM,GAOP;;QArBQ,2CAA4C;QAE5C,qDAA+E;QAI/E,wDACP,IAAI,GAAG,EAAE,EAAC;QAiDZ;;;;;;;WAOG;QAEH,+BAA0B,GAAG,KAAK,EAChC,cAAsB,EACtB,UAAkB,EAClB,QAAgB,EAChB,QAAwB,EACxB,SAAiB,EAAE,EACkB,EAAE;YACvC,IAAI,CAAC;gBACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,cAAc,CACrD,cAAc,EACd,QAAQ,EACR,UAAU,EACV,QAAQ,CACT,CAAC;gBAEF,OAAO,uBAAA,IAAI,kEAAmB,MAAvB,IAAI,EACT,cAAc,EACd,WAAW,EACX,UAAU,EACV,MAAM,CAAC,QAAQ,EAAE,CAClB,CAAC;YAC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AAI,4BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,sCAAwB,mBAAmB,MAAA,CAAC;QAChD,IAAI,CAAC,SAAS,GAAG,IAAI,aAAa,CAAC,sBAAsB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9E,CAAC;CAuKF;oRA1JG,cAAsB,EACtB,KAA2B,EAC3B,UAAkB,EAClB,MAAc;IAEd,MAAM,YAAY,GAAG,kCAAkC,CACrD,KAAK,EACL,UAAU,EACV,MAAM,CACP,CAAC;IACF,MAAM,cAAc,GAAmB;QACrC,WAAW,EAAE,KAAK,CAAC,MAAM;QACzB,YAAY;KACb,CAAC;IACF,uBAAA,IAAI,qDAAgC,CAAC,GAAG,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACzE,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["import { BridgeClientId, StatusTypes } from '@metamask/bridge-controller';\nimport type { TransactionController } from '@metamask/transaction-controller';\nimport { TransactionMeta } from '@metamask/transaction-controller';\n\nimport type { BridgeStatusControllerMessenger, FetchFunction } from './types';\nimport type { BridgeHistoryItem } from './types';\nimport {\n GetJwtFn,\n IntentApi,\n IntentApiImpl,\n IntentBridgeStatus,\n IntentSubmissionParams,\n translateIntentOrderToBridgeStatus,\n} from './utils/intent-api';\nimport { IntentStatusResponse, IntentOrderStatus } from './utils/validators';\n\ntype IntentStatuses = {\n orderStatus: IntentOrderStatus;\n bridgeStatus: IntentBridgeStatus | null;\n};\n\nexport class IntentManager {\n readonly #messenger: BridgeStatusControllerMessenger;\n\n readonly #updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n\n readonly intentApi: IntentApi;\n\n readonly #intentStatusesByBridgeTxMetaId: Map<string, IntentStatuses> =\n new Map();\n\n constructor({\n messenger,\n updateTransactionFn,\n customBridgeApiBaseUrl,\n fetchFn,\n getJwt,\n }: {\n messenger: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n customBridgeApiBaseUrl: string;\n fetchFn: FetchFunction;\n getJwt: GetJwtFn;\n }) {\n this.#messenger = messenger;\n this.#updateTransactionFn = updateTransactionFn;\n this.intentApi = new IntentApiImpl(customBridgeApiBaseUrl, fetchFn, getJwt);\n }\n\n /**\n * Set the intent statuses for a given bridge transaction.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID (key for storage).\n * @param order - The intent order.\n * @param srcChainId - The source chain ID.\n * @param txHash - The transaction hash.\n * @returns The intent statuses.\n */\n\n #setIntentStatuses(\n bridgeTxMetaId: string,\n order: IntentStatusResponse,\n srcChainId: number,\n txHash: string,\n ): IntentStatuses {\n const bridgeStatus = translateIntentOrderToBridgeStatus(\n order,\n srcChainId,\n txHash,\n );\n const intentStatuses: IntentStatuses = {\n orderStatus: order.status,\n bridgeStatus,\n };\n this.#intentStatusesByBridgeTxMetaId.set(bridgeTxMetaId, intentStatuses);\n return intentStatuses;\n }\n\n /**\n * Get the status of an intent order.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID.\n * @param protocol - The protocol of the intent.\n * @param clientId - The client ID.\n * @returns The intent order mapped status.\n */\n\n getIntentTransactionStatus = async (\n bridgeTxMetaId: string,\n srcChainId: number,\n protocol: string,\n clientId: BridgeClientId,\n txHash: string = '',\n ): Promise<IntentStatuses | undefined> => {\n try {\n const orderStatus = await this.intentApi.getOrderStatus(\n bridgeTxMetaId,\n protocol,\n srcChainId,\n clientId,\n );\n\n return this.#setIntentStatuses(\n bridgeTxMetaId,\n orderStatus,\n srcChainId,\n txHash.toString(),\n );\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(\n `[Intent polling] Failed to get intent order status from API: ${error.message}`,\n );\n }\n return undefined;\n }\n };\n\n /**\n * Sync the transaction status from the intent status.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID.\n * @param historyItem - The history item.\n */\n\n syncTransactionFromIntentStatus = (\n bridgeTxMetaId: string,\n historyItem: BridgeHistoryItem,\n ): void => {\n // Update the actual transaction in TransactionController to sync with intent status\n // Use the original transaction ID (not the bridge history key)\n const originalTxId =\n historyItem.originalTransactionId ?? historyItem.txMetaId;\n if (!originalTxId) {\n return;\n }\n\n const intentStatuses =\n this.#intentStatusesByBridgeTxMetaId.get(bridgeTxMetaId);\n if (!intentStatuses) {\n return;\n }\n\n try {\n // Merge with existing TransactionMeta to avoid wiping required fields\n const { transactions } = this.#messenger.call(\n 'TransactionController:getState',\n );\n const existingTxMeta = transactions.find(\n (tx: TransactionMeta) => tx.id === originalTxId,\n );\n if (!existingTxMeta) {\n console.warn(\n '[Intent polling] Skipping update, transaction not found',\n { originalTxId, bridgeHistoryKey: bridgeTxMetaId },\n );\n return;\n }\n const { bridgeStatus, orderStatus } = intentStatuses;\n const txHash = bridgeStatus?.txHash;\n const isComplete = bridgeStatus?.status.status === StatusTypes.COMPLETE;\n const isFinalStatus =\n bridgeStatus?.status.status === StatusTypes.COMPLETE ||\n bridgeStatus?.status.status === StatusTypes.FAILED;\n const existingTxReceipt = (\n existingTxMeta as { txReceipt?: Record<string, unknown> }\n ).txReceipt;\n const txReceiptUpdate = txHash\n ? {\n txReceipt: {\n ...existingTxReceipt,\n transactionHash: txHash,\n status: (isComplete ? '0x1' : '0x0') as unknown as string,\n },\n }\n : {};\n\n const updatedTxMeta: TransactionMeta = {\n ...existingTxMeta,\n status: bridgeStatus?.transactionStatus,\n ...(txHash ? { hash: txHash } : {}),\n ...txReceiptUpdate,\n } as TransactionMeta;\n\n this.#updateTransactionFn(\n updatedTxMeta,\n `BridgeStatusController - Intent order status updated: ${orderStatus}`,\n );\n\n if (isFinalStatus) {\n this.#intentStatusesByBridgeTxMetaId.delete(bridgeTxMetaId);\n }\n } catch (error) {\n console.error('[Intent polling] Failed to update transaction status', {\n originalTxId,\n bridgeHistoryKey: bridgeTxMetaId,\n error,\n });\n }\n };\n\n /**\n * Submit an intent order.\n *\n * @param submissionParams - The submission parameters.\n * @param clientId - The client ID.\n * @returns The intent order.\n */\n submitIntent = async (\n submissionParams: IntentSubmissionParams,\n clientId: BridgeClientId,\n ): Promise<IntentStatusResponse> => {\n return this.intentApi.submitIntent(submissionParams, clientId);\n };\n}\n"]}
|
|
@@ -243,7 +243,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
243
243
|
},
|
|
244
244
|
hasApprovalTx: Boolean(quoteResponse.approval),
|
|
245
245
|
approvalTxId,
|
|
246
|
-
isStxEnabled: isStxEnabled
|
|
246
|
+
isStxEnabled: Boolean(isStxEnabled),
|
|
247
247
|
featureId: quoteResponse.featureId,
|
|
248
248
|
location,
|
|
249
249
|
...(abTests && { abTests }),
|
|
@@ -379,9 +379,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
379
379
|
try {
|
|
380
380
|
let status;
|
|
381
381
|
let validationFailures = [];
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
const intentTxStatus = await __classPrivateFieldGet(this, _BridgeStatusController_intentManager, "f").getIntentTransactionStatus(bridgeTxMetaId, historyItem, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"));
|
|
382
|
+
if (historyItem.quote.intent) {
|
|
383
|
+
const intentTxStatus = await __classPrivateFieldGet(this, _BridgeStatusController_intentManager, "f").getIntentTransactionStatus(bridgeTxMetaId, historyItem.quote.srcChainId, historyItem.quote.intent.protocol, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"), historyItem.status.srcChain.txHash);
|
|
385
384
|
if (intentTxStatus?.bridgeStatus === null ||
|
|
386
385
|
intentTxStatus?.bridgeStatus === undefined) {
|
|
387
386
|
return;
|
|
@@ -426,7 +425,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
426
425
|
this.update((state) => {
|
|
427
426
|
state.txHistory[bridgeTxMetaId] = newBridgeHistoryItem;
|
|
428
427
|
});
|
|
429
|
-
if (
|
|
428
|
+
if (historyItem.quote.intent) {
|
|
430
429
|
__classPrivateFieldGet(this, _BridgeStatusController_intentManager, "f").syncTransactionFromIntentStatus(bridgeTxMetaId, historyItem);
|
|
431
430
|
}
|
|
432
431
|
// 5. After effects
|
|
@@ -560,7 +559,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
560
559
|
});
|
|
561
560
|
});
|
|
562
561
|
_BridgeStatusController_handleApprovalTx.set(this, async (isBridgeTx, srcChainId, approval, resetApproval, requireApproval) => {
|
|
563
|
-
if (approval) {
|
|
562
|
+
if (approval && isEvmTxData(approval)) {
|
|
564
563
|
const approveTx = async () => {
|
|
565
564
|
await __classPrivateFieldGet(this, _BridgeStatusController_handleUSDTAllowanceReset, "f").call(this, resetApproval);
|
|
566
565
|
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransaction, "f").call(this, {
|
|
@@ -647,8 +646,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
647
646
|
// Convert to hex since txFee values from the quote are decimal strings
|
|
648
647
|
if (txFee) {
|
|
649
648
|
return {
|
|
650
|
-
maxFeePerGas: toHex(txFee.maxFeePerGas
|
|
651
|
-
maxPriorityFeePerGas: toHex(txFee.maxPriorityFeePerGas
|
|
649
|
+
maxFeePerGas: toHex(txFee.maxFeePerGas),
|
|
650
|
+
maxPriorityFeePerGas: toHex(txFee.maxPriorityFeePerGas),
|
|
652
651
|
gas: gas ? toHex(gas) : undefined,
|
|
653
652
|
};
|
|
654
653
|
}
|
|
@@ -732,6 +731,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
732
731
|
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Submitted, undefined, preConfirmationProperties);
|
|
733
732
|
let txMeta;
|
|
734
733
|
let approvalTxId;
|
|
734
|
+
let isDelegatedAccount = false;
|
|
735
735
|
const startTime = Date.now();
|
|
736
736
|
const isBridgeTx = isCrossChain(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
737
737
|
const isTronTx = isTronChainId(quoteResponse.quote.srcChainId);
|
|
@@ -752,7 +752,9 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
752
752
|
return quoteResponse.approval &&
|
|
753
753
|
isTronTrade(quoteResponse.approval)
|
|
754
754
|
? await __classPrivateFieldGet(this, _BridgeStatusController_handleNonEvmTx, "f").call(this, quoteResponse.approval, quoteResponse, selectedAccount)
|
|
755
|
-
:
|
|
755
|
+
: /* c8 ignore start */
|
|
756
|
+
undefined;
|
|
757
|
+
/* c8 ignore end */
|
|
756
758
|
}
|
|
757
759
|
catch (error) {
|
|
758
760
|
!quoteResponse.featureId &&
|
|
@@ -786,7 +788,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
786
788
|
}
|
|
787
789
|
catch (error) {
|
|
788
790
|
!quoteResponse.featureId &&
|
|
789
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Failed,
|
|
791
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Failed, undefined, {
|
|
790
792
|
error_message: error?.message,
|
|
791
793
|
...preConfirmationProperties,
|
|
792
794
|
});
|
|
@@ -812,7 +814,25 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
812
814
|
if (!isEvmTxData(quoteResponse.trade)) {
|
|
813
815
|
throw new Error('Failed to submit cross-chain swap transaction: trade is not an EVM transaction');
|
|
814
816
|
}
|
|
815
|
-
if
|
|
817
|
+
// Check if the account is an EIP-7702 delegated account
|
|
818
|
+
// Delegated accounts only allow 1 in-flight tx, so approve + swap
|
|
819
|
+
// must be batched into a single transaction
|
|
820
|
+
const hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);
|
|
821
|
+
isDelegatedAccount = await (async () => {
|
|
822
|
+
try {
|
|
823
|
+
const atomicBatchSupport = await this.messenger.call('TransactionController:isAtomicBatchSupported', {
|
|
824
|
+
address: quoteResponse.trade.from,
|
|
825
|
+
chainIds: [hexChainId],
|
|
826
|
+
});
|
|
827
|
+
return atomicBatchSupport.some((entry) => entry.isSupported && entry.delegationAddress);
|
|
828
|
+
}
|
|
829
|
+
catch {
|
|
830
|
+
return false;
|
|
831
|
+
}
|
|
832
|
+
})();
|
|
833
|
+
if (isStxEnabledOnClient ||
|
|
834
|
+
quoteResponse.quote.gasIncluded7702 ||
|
|
835
|
+
isDelegatedAccount) {
|
|
816
836
|
const { tradeMeta, approvalMeta } = await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransactionBatch, "f").call(this, {
|
|
817
837
|
isBridgeTx,
|
|
818
838
|
resetApproval: quoteResponse.resetApproval,
|
|
@@ -822,6 +842,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
822
842
|
trade: quoteResponse.trade,
|
|
823
843
|
quoteResponse,
|
|
824
844
|
requireApproval,
|
|
845
|
+
isDelegatedAccount,
|
|
825
846
|
});
|
|
826
847
|
approvalTxId = approvalMeta?.id;
|
|
827
848
|
return tradeMeta;
|
|
@@ -874,7 +895,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
874
895
|
// Only add history here for non-EVM and batch EVM transactions
|
|
875
896
|
const isNonBatchEvm = !isNonEvmChainId(quoteResponse.quote.srcChainId) &&
|
|
876
897
|
!isStxEnabledOnClient &&
|
|
877
|
-
!quoteResponse.quote.gasIncluded7702
|
|
898
|
+
!quoteResponse.quote.gasIncluded7702 &&
|
|
899
|
+
!isDelegatedAccount;
|
|
878
900
|
if (!isNonBatchEvm) {
|
|
879
901
|
// Add swap or bridge tx to history
|
|
880
902
|
__classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
|
@@ -931,26 +953,21 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
931
953
|
const intent = getIntentFromQuote(quoteResponse);
|
|
932
954
|
// If backend provided an approval tx for this intent quote, submit it first (on-chain),
|
|
933
955
|
// then proceed with off-chain intent submission.
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
/* requireApproval */ false);
|
|
942
|
-
approvalTxId = approvalTxMeta?.id;
|
|
943
|
-
if (approvalTxId) {
|
|
944
|
-
await __classPrivateFieldGet(this, _BridgeStatusController_waitForTxConfirmation, "f").call(this, approvalTxId);
|
|
945
|
-
}
|
|
956
|
+
const isBridgeTx = isCrossChain(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
957
|
+
const requireApproval = isHardwareAccount && __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === BridgeClientId.MOBILE;
|
|
958
|
+
// Handle approval silently for better UX in intent flows
|
|
959
|
+
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval, quoteResponse.resetApproval, requireApproval);
|
|
960
|
+
const approvalTxId = approvalTxMeta?.id;
|
|
961
|
+
if (approvalTxId) {
|
|
962
|
+
await __classPrivateFieldGet(this, _BridgeStatusController_waitForTxConfirmation, "f").call(this, approvalTxId);
|
|
946
963
|
}
|
|
947
|
-
const { srcChainId
|
|
964
|
+
const { srcChainId, requestId } = quoteResponse.quote;
|
|
948
965
|
const signature = await this.messenger.call('KeyringController:signTypedMessage', {
|
|
949
966
|
from: accountAddress,
|
|
950
967
|
data: intent.typedData,
|
|
951
968
|
}, SignTypedDataVersion.V4);
|
|
952
969
|
const submissionParams = {
|
|
953
|
-
srcChainId
|
|
970
|
+
srcChainId,
|
|
954
971
|
quoteId: requestId,
|
|
955
972
|
signature,
|
|
956
973
|
order: intent.order,
|
|
@@ -960,16 +977,17 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
960
977
|
const intentOrder = await __classPrivateFieldGet(this, _BridgeStatusController_intentManager, "f").submitIntent(submissionParams, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"));
|
|
961
978
|
const orderUid = intentOrder.id;
|
|
962
979
|
// Determine transaction type: swap for same-chain, bridge for cross-chain
|
|
963
|
-
const
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
:
|
|
980
|
+
const transactionType = isBridgeTx
|
|
981
|
+
? /* c8 ignore start */
|
|
982
|
+
TransactionType.bridge
|
|
983
|
+
: /* c8 ignore end */
|
|
984
|
+
TransactionType.swap;
|
|
967
985
|
// Create actual transaction in Transaction Controller first
|
|
968
|
-
const networkClientId = this.messenger.call('NetworkController:findNetworkClientIdByChainId', formatChainIdToHex(
|
|
986
|
+
const networkClientId = this.messenger.call('NetworkController:findNetworkClientIdByChainId', formatChainIdToHex(srcChainId));
|
|
969
987
|
// This is a synthetic transaction whose purpose is to be able
|
|
970
988
|
// to track the order status via the history
|
|
971
989
|
const intentTransactionParams = {
|
|
972
|
-
chainId: formatChainIdToHex(
|
|
990
|
+
chainId: formatChainIdToHex(srcChainId),
|
|
973
991
|
from: accountAddress,
|
|
974
992
|
to: intent.settlementContract ??
|
|
975
993
|
'0x9008D19f58AAbd9eD0D60971565AA8510560ab41', // Default settlement contract
|
|
@@ -999,7 +1017,6 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
999
1017
|
...statusUpdatedTxMeta,
|
|
1000
1018
|
isIntentTx: true,
|
|
1001
1019
|
orderUid,
|
|
1002
|
-
intentType: isCrossChainTx ? 'bridge' : 'swap',
|
|
1003
1020
|
};
|
|
1004
1021
|
// Record in bridge history with actual transaction metadata
|
|
1005
1022
|
try {
|