@metamask/bridge-status-controller 68.1.0 → 70.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 +30 -1
- package/dist/bridge-status-controller.cjs +123 -221
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +1 -4
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +1 -4
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.cjs +9 -13
- package/dist/bridge-status-controller.intent.cjs.map +1 -1
- package/dist/bridge-status-controller.intent.d.cts +6 -8
- package/dist/bridge-status-controller.intent.d.cts.map +1 -1
- package/dist/bridge-status-controller.intent.d.mts +6 -8
- package/dist/bridge-status-controller.intent.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.mjs +10 -14
- package/dist/bridge-status-controller.intent.mjs.map +1 -1
- package/dist/bridge-status-controller.mjs +125 -223
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/index.cjs +1 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.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/accounts.cjs +8 -0
- package/dist/utils/accounts.cjs.map +1 -0
- package/dist/utils/accounts.d.cts +36 -0
- package/dist/utils/accounts.d.cts.map +1 -0
- package/dist/utils/accounts.d.mts +36 -0
- package/dist/utils/accounts.d.mts.map +1 -0
- package/dist/utils/accounts.mjs +4 -0
- package/dist/utils/accounts.mjs.map +1 -0
- package/dist/utils/authentication.cjs +15 -0
- package/dist/utils/authentication.cjs.map +1 -0
- package/dist/utils/authentication.d.cts +3 -0
- package/dist/utils/authentication.d.cts.map +1 -0
- package/dist/utils/authentication.d.mts +3 -0
- package/dist/utils/authentication.d.mts.map +1 -0
- package/dist/utils/authentication.mjs +11 -0
- package/dist/utils/authentication.mjs.map +1 -0
- 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/bridge.cjs +16 -0
- package/dist/utils/bridge.cjs.map +1 -0
- package/dist/utils/bridge.d.cts +10 -0
- package/dist/utils/bridge.d.cts.map +1 -0
- package/dist/utils/bridge.d.mts +10 -0
- package/dist/utils/bridge.d.mts.map +1 -0
- package/dist/utils/bridge.mjs +11 -0
- package/dist/utils/bridge.mjs.map +1 -0
- package/dist/utils/gas.cjs +4 -7
- 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 +4 -7
- package/dist/utils/gas.mjs.map +1 -1
- package/dist/utils/history.cjs +97 -0
- package/dist/utils/history.cjs.map +1 -0
- package/dist/utils/history.d.cts +21 -0
- package/dist/utils/history.d.cts.map +1 -0
- package/dist/utils/history.d.mts +21 -0
- package/dist/utils/history.d.mts.map +1 -0
- package/dist/utils/history.mjs +90 -0
- package/dist/utils/history.mjs.map +1 -0
- package/dist/utils/intent-api.cjs +18 -3
- package/dist/utils/intent-api.cjs.map +1 -1
- package/dist/utils/intent-api.d.cts +16 -7
- package/dist/utils/intent-api.d.cts.map +1 -1
- package/dist/utils/intent-api.d.mts +16 -7
- package/dist/utils/intent-api.d.mts.map +1 -1
- package/dist/utils/intent-api.mjs +18 -4
- package/dist/utils/intent-api.mjs.map +1 -1
- package/dist/utils/keyring.cjs +12 -0
- package/dist/utils/keyring.cjs.map +1 -0
- package/dist/utils/keyring.d.cts +8 -0
- package/dist/utils/keyring.d.cts.map +1 -0
- package/dist/utils/keyring.d.mts +8 -0
- package/dist/utils/keyring.d.mts.map +1 -0
- package/dist/utils/keyring.mjs +8 -0
- package/dist/utils/keyring.mjs.map +1 -0
- package/dist/utils/network.cjs +17 -0
- package/dist/utils/network.cjs.map +1 -0
- package/dist/utils/network.d.cts +5 -0
- package/dist/utils/network.d.cts.map +1 -0
- package/dist/utils/network.d.mts +5 -0
- package/dist/utils/network.d.mts.map +1 -0
- package/dist/utils/network.mjs +12 -0
- package/dist/utils/network.mjs.map +1 -0
- package/dist/utils/snaps.cjs +146 -1
- package/dist/utils/snaps.cjs.map +1 -1
- package/dist/utils/snaps.d.cts +62 -0
- package/dist/utils/snaps.d.cts.map +1 -1
- package/dist/utils/snaps.d.mts +62 -0
- package/dist/utils/snaps.d.mts.map +1 -1
- package/dist/utils/snaps.mjs +141 -0
- package/dist/utils/snaps.mjs.map +1 -1
- package/dist/utils/trace.cjs +31 -0
- package/dist/utils/trace.cjs.map +1 -0
- package/dist/utils/trace.d.cts +17 -0
- package/dist/utils/trace.d.cts.map +1 -0
- package/dist/utils/trace.d.mts +17 -0
- package/dist/utils/trace.d.mts.map +1 -0
- package/dist/utils/trace.mjs +26 -0
- package/dist/utils/trace.mjs.map +1 -0
- package/dist/utils/transaction.cjs +31 -193
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +8 -79
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +8 -79
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +31 -187
- 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 +6 -11
- package/dist/utils/validators.d.cts.map +1 -1
- package/dist/utils/validators.d.mts +6 -11
- 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
|
@@ -10,17 +10,17 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _IntentManager_instances, _IntentManager_messenger,
|
|
13
|
+
var _IntentManager_instances, _IntentManager_messenger, _IntentManager_intentStatusesByBridgeTxMetaId, _IntentManager_setIntentStatuses;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.IntentManager = void 0;
|
|
16
16
|
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
17
|
+
const authentication_1 = require("./utils/authentication.cjs");
|
|
17
18
|
const intent_api_1 = require("./utils/intent-api.cjs");
|
|
18
19
|
const validators_1 = require("./utils/validators.cjs");
|
|
19
20
|
class IntentManager {
|
|
20
|
-
constructor({ messenger,
|
|
21
|
+
constructor({ messenger, customBridgeApiBaseUrl, fetchFn, }) {
|
|
21
22
|
_IntentManager_instances.add(this);
|
|
22
23
|
_IntentManager_messenger.set(this, void 0);
|
|
23
|
-
_IntentManager_updateTransactionFn.set(this, void 0);
|
|
24
24
|
_IntentManager_intentStatusesByBridgeTxMetaId.set(this, new Map());
|
|
25
25
|
/**
|
|
26
26
|
* Get the status of an intent order.
|
|
@@ -30,12 +30,9 @@ class IntentManager {
|
|
|
30
30
|
* @param clientId - The client ID.
|
|
31
31
|
* @returns The intent order mapped status.
|
|
32
32
|
*/
|
|
33
|
-
this.getIntentTransactionStatus = async (bridgeTxMetaId,
|
|
34
|
-
const { status: statusObj, quote: { srcChainId, intent }, } = historyItem;
|
|
35
|
-
const txHash = statusObj?.srcChain?.txHash ?? '';
|
|
36
|
-
const protocol = intent?.protocol ?? '';
|
|
33
|
+
this.getIntentTransactionStatus = async (bridgeTxMetaId, srcChainId, protocol, clientId, txHash = '') => {
|
|
37
34
|
try {
|
|
38
|
-
const orderStatus = await this.intentApi.getOrderStatus(bridgeTxMetaId, protocol, srcChainId
|
|
35
|
+
const orderStatus = await this.intentApi.getOrderStatus(bridgeTxMetaId, protocol, srcChainId, clientId);
|
|
39
36
|
return __classPrivateFieldGet(this, _IntentManager_instances, "m", _IntentManager_setIntentStatuses).call(this, bridgeTxMetaId, orderStatus, srcChainId, txHash.toString());
|
|
40
37
|
}
|
|
41
38
|
catch (error) {
|
|
@@ -91,7 +88,7 @@ class IntentManager {
|
|
|
91
88
|
...(txHash ? { hash: txHash } : {}),
|
|
92
89
|
...txReceiptUpdate,
|
|
93
90
|
};
|
|
94
|
-
__classPrivateFieldGet(this,
|
|
91
|
+
__classPrivateFieldGet(this, _IntentManager_messenger, "f").call('TransactionController:updateTransaction', updatedTxMeta, `BridgeStatusController - Intent order status updated: ${orderStatus}`);
|
|
95
92
|
if (isFinalStatus) {
|
|
96
93
|
__classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").delete(bridgeTxMetaId);
|
|
97
94
|
}
|
|
@@ -115,13 +112,12 @@ class IntentManager {
|
|
|
115
112
|
return this.intentApi.submitIntent(submissionParams, clientId);
|
|
116
113
|
};
|
|
117
114
|
__classPrivateFieldSet(this, _IntentManager_messenger, messenger, "f");
|
|
118
|
-
|
|
119
|
-
this.intentApi = new intent_api_1.IntentApiImpl(customBridgeApiBaseUrl, fetchFn, getJwt);
|
|
115
|
+
this.intentApi = new intent_api_1.IntentApiImpl(customBridgeApiBaseUrl, fetchFn, async () => await (0, authentication_1.getJwt)(messenger));
|
|
120
116
|
}
|
|
121
117
|
}
|
|
122
118
|
exports.IntentManager = IntentManager;
|
|
123
|
-
_IntentManager_messenger = new WeakMap(),
|
|
124
|
-
const bridgeStatus = (0, intent_api_1.translateIntentOrderToBridgeStatus)(order, srcChainId, txHash
|
|
119
|
+
_IntentManager_messenger = new WeakMap(), _IntentManager_intentStatusesByBridgeTxMetaId = new WeakMap(), _IntentManager_instances = new WeakSet(), _IntentManager_setIntentStatuses = function _IntentManager_setIntentStatuses(bridgeTxMetaId, order, srcChainId, txHash) {
|
|
120
|
+
const bridgeStatus = (0, intent_api_1.translateIntentOrderToBridgeStatus)(order, srcChainId, txHash);
|
|
125
121
|
const intentStatuses = {
|
|
126
122
|
orderStatus: order.status,
|
|
127
123
|
bridgeStatus,
|
|
@@ -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;YACjD,MAAM,QAAQ,GAAG,MAAM,EAAE,QAAQ,IAAI,EAAE,CAAC;YAExC,IAAI,CAAC;gBACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,cAAc,CACrD,cAAc,EACd,QAAQ,EACR,UAAU,CAAC,QAAQ,EAAE,EACrB,QAAQ,CACT,CAAC;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B,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;AAK1E,+DAAgD;AAChD,uDAM4B;AAC5B,uDAA6E;AAO7E,MAAa,aAAa;IAQxB,YAAY,EACV,SAAS,EACT,sBAAsB,EACtB,OAAO,GAKR;;QAfQ,2CAA4C;QAI5C,wDACP,IAAI,GAAG,EAAE,EAAC;QAgDZ;;;;;;;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;YACJ,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACxB,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;oBAC3B,MAAM,IAAI,KAAK,CACb,gEAAgE,KAAK,CAAC,OAAO,EAAE,CAChF,CAAC;gBACJ,CAAC;gBACD,OAAO,SAAS,CAAC;YACnB,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CAAC;CAwKF;AA/LD,sCA+LC;gOA3JG,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 { TransactionMeta } from '@metamask/transaction-controller';\n\nimport type { BridgeStatusControllerMessenger, FetchFunction } from './types';\nimport type { BridgeHistoryItem } from './types';\nimport { getJwt } from './utils/authentication';\nimport {\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 intentApi: IntentApi;\n\n readonly #intentStatusesByBridgeTxMetaId: Map<string, IntentStatuses> =\n new Map();\n\n constructor({\n messenger,\n customBridgeApiBaseUrl,\n fetchFn,\n }: {\n messenger: BridgeStatusControllerMessenger;\n customBridgeApiBaseUrl: string;\n fetchFn: FetchFunction;\n }) {\n this.#messenger = messenger;\n this.intentApi = new IntentApiImpl(\n customBridgeApiBaseUrl,\n fetchFn,\n async () => await getJwt(messenger),\n );\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.#messenger.call(\n 'TransactionController:updateTransaction',\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,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { BridgeClientId } from "@metamask/bridge-controller";
|
|
2
2
|
import type { BridgeStatusControllerMessenger, FetchFunction } from "./types.cjs";
|
|
3
3
|
import type { BridgeHistoryItem } from "./types.cjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { IntentApi, IntentBridgeStatus, IntentSubmissionParams } from "./utils/intent-api.cjs";
|
|
5
|
+
import { IntentStatusResponse, IntentOrderStatus } from "./utils/validators.cjs";
|
|
6
6
|
type IntentStatuses = {
|
|
7
7
|
orderStatus: IntentOrderStatus;
|
|
8
8
|
bridgeStatus: IntentBridgeStatus | null;
|
|
@@ -10,12 +10,10 @@ type IntentStatuses = {
|
|
|
10
10
|
export declare class IntentManager {
|
|
11
11
|
#private;
|
|
12
12
|
readonly intentApi: IntentApi;
|
|
13
|
-
constructor({ messenger,
|
|
13
|
+
constructor({ messenger, customBridgeApiBaseUrl, fetchFn, }: {
|
|
14
14
|
messenger: BridgeStatusControllerMessenger;
|
|
15
|
-
updateTransactionFn: typeof TransactionController.prototype.updateTransaction;
|
|
16
15
|
customBridgeApiBaseUrl: string;
|
|
17
16
|
fetchFn: FetchFunction;
|
|
18
|
-
getJwt: GetJwtFn;
|
|
19
17
|
});
|
|
20
18
|
/**
|
|
21
19
|
* Get the status of an intent order.
|
|
@@ -25,7 +23,7 @@ export declare class IntentManager {
|
|
|
25
23
|
* @param clientId - The client ID.
|
|
26
24
|
* @returns The intent order mapped status.
|
|
27
25
|
*/
|
|
28
|
-
getIntentTransactionStatus: (bridgeTxMetaId: string,
|
|
26
|
+
getIntentTransactionStatus: (bridgeTxMetaId: string, srcChainId: number, protocol: string, clientId: BridgeClientId, txHash?: string) => Promise<IntentStatuses | undefined>;
|
|
29
27
|
/**
|
|
30
28
|
* Sync the transaction status from the intent status.
|
|
31
29
|
*
|
|
@@ -40,7 +38,7 @@ export declare class IntentManager {
|
|
|
40
38
|
* @param clientId - The client ID.
|
|
41
39
|
* @returns The intent order.
|
|
42
40
|
*/
|
|
43
|
-
submitIntent: (submissionParams: IntentSubmissionParams, clientId:
|
|
41
|
+
submitIntent: (submissionParams: IntentSubmissionParams, clientId: BridgeClientId) => Promise<IntentStatusResponse>;
|
|
44
42
|
}
|
|
45
43
|
export {};
|
|
46
44
|
//# 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;AAG1E,OAAO,KAAK,EAAE,+BAA+B,EAAE,aAAa,EAAE,oBAAgB;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAgB;AAEjD,OAAO,EACL,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;;IAGxB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAKlB,EACV,SAAS,EACT,sBAAsB,EACtB,OAAO,GACR,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,sBAAsB,EAAE,MAAM,CAAC;QAC/B,OAAO,EAAE,aAAa,CAAC;KACxB;IAsCD;;;;;;;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,CAwEL;IAEF;;;;;;OAMG;IACH,YAAY,qBACQ,sBAAsB,YAC9B,cAAc,KACvB,QAAQ,oBAAoB,CAAC,CAE9B;CACH"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { BridgeClientId } from "@metamask/bridge-controller";
|
|
2
2
|
import type { BridgeStatusControllerMessenger, FetchFunction } from "./types.mjs";
|
|
3
3
|
import type { BridgeHistoryItem } from "./types.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { IntentApi, IntentBridgeStatus, IntentSubmissionParams } from "./utils/intent-api.mjs";
|
|
5
|
+
import { IntentStatusResponse, IntentOrderStatus } from "./utils/validators.mjs";
|
|
6
6
|
type IntentStatuses = {
|
|
7
7
|
orderStatus: IntentOrderStatus;
|
|
8
8
|
bridgeStatus: IntentBridgeStatus | null;
|
|
@@ -10,12 +10,10 @@ type IntentStatuses = {
|
|
|
10
10
|
export declare class IntentManager {
|
|
11
11
|
#private;
|
|
12
12
|
readonly intentApi: IntentApi;
|
|
13
|
-
constructor({ messenger,
|
|
13
|
+
constructor({ messenger, customBridgeApiBaseUrl, fetchFn, }: {
|
|
14
14
|
messenger: BridgeStatusControllerMessenger;
|
|
15
|
-
updateTransactionFn: typeof TransactionController.prototype.updateTransaction;
|
|
16
15
|
customBridgeApiBaseUrl: string;
|
|
17
16
|
fetchFn: FetchFunction;
|
|
18
|
-
getJwt: GetJwtFn;
|
|
19
17
|
});
|
|
20
18
|
/**
|
|
21
19
|
* Get the status of an intent order.
|
|
@@ -25,7 +23,7 @@ export declare class IntentManager {
|
|
|
25
23
|
* @param clientId - The client ID.
|
|
26
24
|
* @returns The intent order mapped status.
|
|
27
25
|
*/
|
|
28
|
-
getIntentTransactionStatus: (bridgeTxMetaId: string,
|
|
26
|
+
getIntentTransactionStatus: (bridgeTxMetaId: string, srcChainId: number, protocol: string, clientId: BridgeClientId, txHash?: string) => Promise<IntentStatuses | undefined>;
|
|
29
27
|
/**
|
|
30
28
|
* Sync the transaction status from the intent status.
|
|
31
29
|
*
|
|
@@ -40,7 +38,7 @@ export declare class IntentManager {
|
|
|
40
38
|
* @param clientId - The client ID.
|
|
41
39
|
* @returns The intent order.
|
|
42
40
|
*/
|
|
43
|
-
submitIntent: (submissionParams: IntentSubmissionParams, clientId:
|
|
41
|
+
submitIntent: (submissionParams: IntentSubmissionParams, clientId: BridgeClientId) => Promise<IntentStatusResponse>;
|
|
44
42
|
}
|
|
45
43
|
export {};
|
|
46
44
|
//# 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;AAG1E,OAAO,KAAK,EAAE,+BAA+B,EAAE,aAAa,EAAE,oBAAgB;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAgB;AAEjD,OAAO,EACL,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;;IAGxB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAKlB,EACV,SAAS,EACT,sBAAsB,EACtB,OAAO,GACR,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,sBAAsB,EAAE,MAAM,CAAC;QAC/B,OAAO,EAAE,aAAa,CAAC;KACxB;IAsCD;;;;;;;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,CAwEL;IAEF;;;;;;OAMG;IACH,YAAY,qBACQ,sBAAsB,YAC9B,cAAc,KACvB,QAAQ,oBAAoB,CAAC,CAE9B;CACH"}
|
|
@@ -9,15 +9,15 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _IntentManager_instances, _IntentManager_messenger,
|
|
13
|
-
import { StatusTypes } from "@metamask/bridge-controller";
|
|
12
|
+
var _IntentManager_instances, _IntentManager_messenger, _IntentManager_intentStatusesByBridgeTxMetaId, _IntentManager_setIntentStatuses;
|
|
13
|
+
import { BridgeClientId, StatusTypes } from "@metamask/bridge-controller";
|
|
14
|
+
import { getJwt } from "./utils/authentication.mjs";
|
|
14
15
|
import { IntentApiImpl, translateIntentOrderToBridgeStatus } from "./utils/intent-api.mjs";
|
|
15
16
|
import { IntentOrderStatus } from "./utils/validators.mjs";
|
|
16
17
|
export class IntentManager {
|
|
17
|
-
constructor({ messenger,
|
|
18
|
+
constructor({ messenger, customBridgeApiBaseUrl, fetchFn, }) {
|
|
18
19
|
_IntentManager_instances.add(this);
|
|
19
20
|
_IntentManager_messenger.set(this, void 0);
|
|
20
|
-
_IntentManager_updateTransactionFn.set(this, void 0);
|
|
21
21
|
_IntentManager_intentStatusesByBridgeTxMetaId.set(this, new Map());
|
|
22
22
|
/**
|
|
23
23
|
* Get the status of an intent order.
|
|
@@ -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) {
|
|
@@ -88,7 +85,7 @@ export class IntentManager {
|
|
|
88
85
|
...(txHash ? { hash: txHash } : {}),
|
|
89
86
|
...txReceiptUpdate,
|
|
90
87
|
};
|
|
91
|
-
__classPrivateFieldGet(this,
|
|
88
|
+
__classPrivateFieldGet(this, _IntentManager_messenger, "f").call('TransactionController:updateTransaction', updatedTxMeta, `BridgeStatusController - Intent order status updated: ${orderStatus}`);
|
|
92
89
|
if (isFinalStatus) {
|
|
93
90
|
__classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").delete(bridgeTxMetaId);
|
|
94
91
|
}
|
|
@@ -112,12 +109,11 @@ export class IntentManager {
|
|
|
112
109
|
return this.intentApi.submitIntent(submissionParams, clientId);
|
|
113
110
|
};
|
|
114
111
|
__classPrivateFieldSet(this, _IntentManager_messenger, messenger, "f");
|
|
115
|
-
|
|
116
|
-
this.intentApi = new IntentApiImpl(customBridgeApiBaseUrl, fetchFn, getJwt);
|
|
112
|
+
this.intentApi = new IntentApiImpl(customBridgeApiBaseUrl, fetchFn, async () => await getJwt(messenger));
|
|
117
113
|
}
|
|
118
114
|
}
|
|
119
|
-
_IntentManager_messenger = new WeakMap(),
|
|
120
|
-
const bridgeStatus = translateIntentOrderToBridgeStatus(order, srcChainId, txHash
|
|
115
|
+
_IntentManager_messenger = new WeakMap(), _IntentManager_intentStatusesByBridgeTxMetaId = new WeakMap(), _IntentManager_instances = new WeakSet(), _IntentManager_setIntentStatuses = function _IntentManager_setIntentStatuses(bridgeTxMetaId, order, srcChainId, txHash) {
|
|
116
|
+
const bridgeStatus = translateIntentOrderToBridgeStatus(order, srcChainId, txHash);
|
|
121
117
|
const intentStatuses = {
|
|
122
118
|
orderStatus: order.status,
|
|
123
119
|
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,SAAS,CAAC,cAAc,CACrD,cAAc,EACd,QAAQ,EACR,UAAU,CAAC,QAAQ,EAAE,EACrB,QAAQ,CACT,CAAC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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;AAK1E,OAAO,EAAE,MAAM,EAAE,mCAA+B;AAChD,OAAO,EAEL,aAAa,EAGb,kCAAkC,EACnC,+BAA2B;AAC5B,OAAO,EAAwB,iBAAiB,EAAE,+BAA2B;AAO7E,MAAM,OAAO,aAAa;IAQxB,YAAY,EACV,SAAS,EACT,sBAAsB,EACtB,OAAO,GAKR;;QAfQ,2CAA4C;QAI5C,wDACP,IAAI,GAAG,EAAE,EAAC;QAgDZ;;;;;;;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;YACJ,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACxB,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;oBAC3B,MAAM,I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B,EACtB,OAAO,EACP,KAAK,IAAI,EAAE,CAAC,MAAM,MAAM,CAAC,SAAS,CAAC,CACpC,CAAC;IACJ,CAAC;CAwKF;gOA3JG,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 { TransactionMeta } from '@metamask/transaction-controller';\n\nimport type { BridgeStatusControllerMessenger, FetchFunction } from './types';\nimport type { BridgeHistoryItem } from './types';\nimport { getJwt } from './utils/authentication';\nimport {\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 intentApi: IntentApi;\n\n readonly #intentStatusesByBridgeTxMetaId: Map<string, IntentStatuses> =\n new Map();\n\n constructor({\n messenger,\n customBridgeApiBaseUrl,\n fetchFn,\n }: {\n messenger: BridgeStatusControllerMessenger;\n customBridgeApiBaseUrl: string;\n fetchFn: FetchFunction;\n }) {\n this.#messenger = messenger;\n this.intentApi = new IntentApiImpl(\n customBridgeApiBaseUrl,\n fetchFn,\n async () => await getJwt(messenger),\n );\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.#messenger.call(\n 'TransactionController:updateTransaction',\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"]}
|