@metamask/bridge-status-controller 69.0.0 → 70.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -1
- package/dist/bridge-status-controller.cjs +115 -354
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +3 -5
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +3 -5
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.cjs +12 -25
- package/dist/bridge-status-controller.intent.cjs.map +1 -1
- package/dist/bridge-status-controller.intent.d.cts +3 -14
- package/dist/bridge-status-controller.intent.d.cts.map +1 -1
- package/dist/bridge-status-controller.intent.d.mts +3 -14
- package/dist/bridge-status-controller.intent.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.mjs +12 -25
- package/dist/bridge-status-controller.intent.mjs.map +1 -1
- package/dist/bridge-status-controller.mjs +118 -357
- 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 +11 -5
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +11 -5
- 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 +17 -1
- package/dist/utils/bridge-status.cjs.map +1 -1
- package/dist/utils/bridge-status.d.cts +8 -2
- package/dist/utils/bridge-status.d.cts.map +1 -1
- package/dist/utils/bridge-status.d.mts +8 -2
- package/dist/utils/bridge-status.d.mts.map +1 -1
- package/dist/utils/bridge-status.mjs +15 -0
- 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 +1 -61
- package/dist/utils/gas.cjs.map +1 -1
- package/dist/utils/gas.d.cts +3 -26
- package/dist/utils/gas.d.cts.map +1 -1
- package/dist/utils/gas.d.mts +3 -26
- package/dist/utils/gas.d.mts.map +1 -1
- package/dist/utils/gas.mjs +0 -58
- package/dist/utils/gas.mjs.map +1 -1
- package/dist/utils/history.cjs +98 -0
- package/dist/utils/history.cjs.map +1 -0
- package/dist/utils/history.d.cts +22 -0
- package/dist/utils/history.d.cts.map +1 -0
- package/dist/utils/history.d.mts +22 -0
- package/dist/utils/history.d.mts.map +1 -0
- package/dist/utils/history.mjs +91 -0
- package/dist/utils/history.mjs.map +1 -0
- package/dist/utils/intent-api.cjs +41 -26
- package/dist/utils/intent-api.cjs.map +1 -1
- package/dist/utils/intent-api.d.cts +16 -3
- package/dist/utils/intent-api.d.cts.map +1 -1
- package/dist/utils/intent-api.d.mts +16 -3
- package/dist/utils/intent-api.d.mts.map +1 -1
- package/dist/utils/intent-api.mjs +38 -25
- 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 +48 -0
- package/dist/utils/snaps.d.cts.map +1 -1
- package/dist/utils/snaps.d.mts +48 -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 +239 -184
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +85 -236
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +85 -236
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +226 -176
- package/dist/utils/transaction.mjs.map +1 -1
- package/dist/utils/validators.d.cts +2 -2
- package/dist/utils/validators.d.mts +2 -2
- package/package.json +3 -3
|
@@ -10,17 +10,18 @@ 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");
|
|
19
|
+
const transaction_1 = require("./utils/transaction.cjs");
|
|
18
20
|
const validators_1 = require("./utils/validators.cjs");
|
|
19
21
|
class IntentManager {
|
|
20
|
-
constructor({ messenger,
|
|
22
|
+
constructor({ messenger, customBridgeApiBaseUrl, fetchFn, }) {
|
|
21
23
|
_IntentManager_instances.add(this);
|
|
22
24
|
_IntentManager_messenger.set(this, void 0);
|
|
23
|
-
_IntentManager_updateTransactionFn.set(this, void 0);
|
|
24
25
|
_IntentManager_intentStatusesByBridgeTxMetaId.set(this, new Map());
|
|
25
26
|
/**
|
|
26
27
|
* Get the status of an intent order.
|
|
@@ -30,10 +31,10 @@ class IntentManager {
|
|
|
30
31
|
* @param clientId - The client ID.
|
|
31
32
|
* @returns The intent order mapped status.
|
|
32
33
|
*/
|
|
33
|
-
this.getIntentTransactionStatus = async (bridgeTxMetaId, srcChainId, protocol, clientId, txHash
|
|
34
|
+
this.getIntentTransactionStatus = async (bridgeTxMetaId, srcChainId, protocol, clientId, txHash) => {
|
|
34
35
|
try {
|
|
35
36
|
const orderStatus = await this.intentApi.getOrderStatus(bridgeTxMetaId, protocol, srcChainId, clientId);
|
|
36
|
-
return __classPrivateFieldGet(this, _IntentManager_instances, "m", _IntentManager_setIntentStatuses).call(this, bridgeTxMetaId, orderStatus, srcChainId, txHash
|
|
37
|
+
return __classPrivateFieldGet(this, _IntentManager_instances, "m", _IntentManager_setIntentStatuses).call(this, bridgeTxMetaId, orderStatus, srcChainId, txHash);
|
|
37
38
|
}
|
|
38
39
|
catch (error) {
|
|
39
40
|
if (error instanceof Error) {
|
|
@@ -61,8 +62,7 @@ class IntentManager {
|
|
|
61
62
|
}
|
|
62
63
|
try {
|
|
63
64
|
// Merge with existing TransactionMeta to avoid wiping required fields
|
|
64
|
-
const
|
|
65
|
-
const existingTxMeta = transactions.find((tx) => tx.id === originalTxId);
|
|
65
|
+
const existingTxMeta = (0, transaction_1.getTransactionMetaById)(__classPrivateFieldGet(this, _IntentManager_messenger, "f"), originalTxId);
|
|
66
66
|
if (!existingTxMeta) {
|
|
67
67
|
console.warn('[Intent polling] Skipping update, transaction not found', { originalTxId, bridgeHistoryKey: bridgeTxMetaId });
|
|
68
68
|
return;
|
|
@@ -78,17 +78,15 @@ class IntentManager {
|
|
|
78
78
|
txReceipt: {
|
|
79
79
|
...existingTxReceipt,
|
|
80
80
|
transactionHash: txHash,
|
|
81
|
-
status:
|
|
81
|
+
status: isComplete ? '0x1' : '0x0',
|
|
82
82
|
},
|
|
83
83
|
}
|
|
84
84
|
: {};
|
|
85
|
-
|
|
86
|
-
...existingTxMeta,
|
|
85
|
+
(0, transaction_1.updateTransaction)(__classPrivateFieldGet(this, _IntentManager_messenger, "f"), existingTxMeta, {
|
|
87
86
|
status: bridgeStatus?.transactionStatus,
|
|
88
87
|
...(txHash ? { hash: txHash } : {}),
|
|
89
88
|
...txReceiptUpdate,
|
|
90
|
-
};
|
|
91
|
-
__classPrivateFieldGet(this, _IntentManager_updateTransactionFn, "f").call(this, updatedTxMeta, `BridgeStatusController - Intent order status updated: ${orderStatus}`);
|
|
89
|
+
}, `BridgeStatusController - Intent order status updated: ${orderStatus}`);
|
|
92
90
|
if (isFinalStatus) {
|
|
93
91
|
__classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").delete(bridgeTxMetaId);
|
|
94
92
|
}
|
|
@@ -101,23 +99,12 @@ class IntentManager {
|
|
|
101
99
|
});
|
|
102
100
|
}
|
|
103
101
|
};
|
|
104
|
-
/**
|
|
105
|
-
* Submit an intent order.
|
|
106
|
-
*
|
|
107
|
-
* @param submissionParams - The submission parameters.
|
|
108
|
-
* @param clientId - The client ID.
|
|
109
|
-
* @returns The intent order.
|
|
110
|
-
*/
|
|
111
|
-
this.submitIntent = async (submissionParams, clientId) => {
|
|
112
|
-
return this.intentApi.submitIntent(submissionParams, clientId);
|
|
113
|
-
};
|
|
114
102
|
__classPrivateFieldSet(this, _IntentManager_messenger, messenger, "f");
|
|
115
|
-
|
|
116
|
-
this.intentApi = new intent_api_1.IntentApiImpl(customBridgeApiBaseUrl, fetchFn, getJwt);
|
|
103
|
+
this.intentApi = new intent_api_1.IntentApiImpl(customBridgeApiBaseUrl, fetchFn, async () => await (0, authentication_1.getJwt)(messenger));
|
|
117
104
|
}
|
|
118
105
|
}
|
|
119
106
|
exports.IntentManager = IntentManager;
|
|
120
|
-
_IntentManager_messenger = new WeakMap(),
|
|
107
|
+
_IntentManager_messenger = new WeakMap(), _IntentManager_intentStatusesByBridgeTxMetaId = new WeakMap(), _IntentManager_instances = new WeakSet(), _IntentManager_setIntentStatuses = function _IntentManager_setIntentStatuses(bridgeTxMetaId, order, srcChainId, txHash) {
|
|
121
108
|
const bridgeStatus = (0, intent_api_1.translateIntentOrderToBridgeStatus)(order, srcChainId, txHash);
|
|
122
109
|
const intentStatuses = {
|
|
123
110
|
orderStatus: order.status,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge-status-controller.intent.cjs","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAA0E;
|
|
1
|
+
{"version":3,"file":"bridge-status-controller.intent.cjs","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAA0E;AAI1E,+DAAgD;AAChD,uDAK4B;AAC5B,yDAAgF;AAChF,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,MAAe,EACsB,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,CACP,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,CAAC;QACH,CAAC,CAAC;QAEF;;;;;WAKG;QAEH,oCAA+B,GAAG,CAChC,cAAsB,EACtB,WAA8B,EACxB,EAAE;YACR,oFAAoF;YACpF,+DAA+D;YAC/D,MAAM,YAAY,GAChB,WAAW,CAAC,qBAAqB,IAAI,WAAW,CAAC,QAAQ,CAAC;YAC5D,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO;YACT,CAAC;YAED,MAAM,cAAc,GAClB,uBAAA,IAAI,qDAA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,eAAe;iBACnB,EACD,yDAAyD,WAAW,EAAE,CACvE,CAAC;gBAEF,IAAI,aAAa,EAAE,CAAC;oBAClB,uBAAA,IAAI,qDAAgC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;gBAC9D,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,sDAAsD,EAAE;oBACpE,YAAY;oBACZ,gBAAgB,EAAE,cAAc;oBAChC,KAAK;iBACN,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC;QA5JA,uBAAA,IAAI,4BAAc,SAAS,MAAA,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,IAAI,0BAAa,CAChC,sBAAsB,EACtB,OAAO,EACP,KAAK,IAAI,EAAE,CAAC,MAAM,IAAA,uBAAM,EAAC,SAAS,CAAC,CACpC,CAAC;IACJ,CAAC;CAuJF;AA9KD,sCA8KC;gOA1IG,cAAsB,EACtB,KAA2B,EAC3B,UAAkB,EAClB,MAAe;IAEf,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';\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 translateIntentOrderToBridgeStatus,\n} from './utils/intent-api';\nimport { getTransactionMetaById, updateTransaction } from './utils/transaction';\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,\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 existingTxMeta = getTransactionMetaById(\n this.#messenger,\n 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\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 as `0x${string}` | undefined,\n status: isComplete ? '0x1' : '0x0',\n },\n }\n : {};\n\n updateTransaction(\n this.#messenger,\n existingTxMeta,\n {\n status: bridgeStatus?.transactionStatus,\n ...(txHash ? { hash: txHash } : {}),\n ...txReceiptUpdate,\n },\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"]}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { BridgeClientId } from "@metamask/bridge-controller";
|
|
2
|
-
import type { TransactionController } from "@metamask/transaction-controller";
|
|
3
2
|
import type { BridgeStatusControllerMessenger, FetchFunction } from "./types.cjs";
|
|
4
3
|
import type { BridgeHistoryItem } from "./types.cjs";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { IntentApi, IntentBridgeStatus } from "./utils/intent-api.cjs";
|
|
5
|
+
import { IntentOrderStatus } from "./utils/validators.cjs";
|
|
7
6
|
type IntentStatuses = {
|
|
8
7
|
orderStatus: IntentOrderStatus;
|
|
9
8
|
bridgeStatus: IntentBridgeStatus | null;
|
|
@@ -11,12 +10,10 @@ type IntentStatuses = {
|
|
|
11
10
|
export declare class IntentManager {
|
|
12
11
|
#private;
|
|
13
12
|
readonly intentApi: IntentApi;
|
|
14
|
-
constructor({ messenger,
|
|
13
|
+
constructor({ messenger, customBridgeApiBaseUrl, fetchFn, }: {
|
|
15
14
|
messenger: BridgeStatusControllerMessenger;
|
|
16
|
-
updateTransactionFn: typeof TransactionController.prototype.updateTransaction;
|
|
17
15
|
customBridgeApiBaseUrl: string;
|
|
18
16
|
fetchFn: FetchFunction;
|
|
19
|
-
getJwt: GetJwtFn;
|
|
20
17
|
});
|
|
21
18
|
/**
|
|
22
19
|
* Get the status of an intent order.
|
|
@@ -34,14 +31,6 @@ export declare class IntentManager {
|
|
|
34
31
|
* @param historyItem - The history item.
|
|
35
32
|
*/
|
|
36
33
|
syncTransactionFromIntentStatus: (bridgeTxMetaId: string, historyItem: BridgeHistoryItem) => void;
|
|
37
|
-
/**
|
|
38
|
-
* Submit an intent order.
|
|
39
|
-
*
|
|
40
|
-
* @param submissionParams - The submission parameters.
|
|
41
|
-
* @param clientId - The client ID.
|
|
42
|
-
* @returns The intent order.
|
|
43
|
-
*/
|
|
44
|
-
submitIntent: (submissionParams: IntentSubmissionParams, clientId: BridgeClientId) => Promise<IntentStatusResponse>;
|
|
45
34
|
}
|
|
46
35
|
export {};
|
|
47
36
|
//# 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":"AAAA,OAAO,EAAE,cAAc,EAAe,oCAAoC;
|
|
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;AAE1E,OAAO,KAAK,EAAE,+BAA+B,EAAE,aAAa,EAAE,oBAAgB;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAgB;AAEjD,OAAO,EACL,SAAS,EAET,kBAAkB,EAEnB,+BAA2B;AAE5B,OAAO,EAAwB,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,WACf,MAAM,KACd,QAAQ,cAAc,GAAG,SAAS,CAAC,CAuBpC;IAEF;;;;;OAKG;IAEH,+BAA+B,mBACb,MAAM,eACT,iBAAiB,KAC7B,IAAI,CAqEL;CACH"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { BridgeClientId } from "@metamask/bridge-controller";
|
|
2
|
-
import type { TransactionController } from "@metamask/transaction-controller";
|
|
3
2
|
import type { BridgeStatusControllerMessenger, FetchFunction } from "./types.mjs";
|
|
4
3
|
import type { BridgeHistoryItem } from "./types.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { IntentApi, IntentBridgeStatus } from "./utils/intent-api.mjs";
|
|
5
|
+
import { IntentOrderStatus } from "./utils/validators.mjs";
|
|
7
6
|
type IntentStatuses = {
|
|
8
7
|
orderStatus: IntentOrderStatus;
|
|
9
8
|
bridgeStatus: IntentBridgeStatus | null;
|
|
@@ -11,12 +10,10 @@ type IntentStatuses = {
|
|
|
11
10
|
export declare class IntentManager {
|
|
12
11
|
#private;
|
|
13
12
|
readonly intentApi: IntentApi;
|
|
14
|
-
constructor({ messenger,
|
|
13
|
+
constructor({ messenger, customBridgeApiBaseUrl, fetchFn, }: {
|
|
15
14
|
messenger: BridgeStatusControllerMessenger;
|
|
16
|
-
updateTransactionFn: typeof TransactionController.prototype.updateTransaction;
|
|
17
15
|
customBridgeApiBaseUrl: string;
|
|
18
16
|
fetchFn: FetchFunction;
|
|
19
|
-
getJwt: GetJwtFn;
|
|
20
17
|
});
|
|
21
18
|
/**
|
|
22
19
|
* Get the status of an intent order.
|
|
@@ -34,14 +31,6 @@ export declare class IntentManager {
|
|
|
34
31
|
* @param historyItem - The history item.
|
|
35
32
|
*/
|
|
36
33
|
syncTransactionFromIntentStatus: (bridgeTxMetaId: string, historyItem: BridgeHistoryItem) => void;
|
|
37
|
-
/**
|
|
38
|
-
* Submit an intent order.
|
|
39
|
-
*
|
|
40
|
-
* @param submissionParams - The submission parameters.
|
|
41
|
-
* @param clientId - The client ID.
|
|
42
|
-
* @returns The intent order.
|
|
43
|
-
*/
|
|
44
|
-
submitIntent: (submissionParams: IntentSubmissionParams, clientId: BridgeClientId) => Promise<IntentStatusResponse>;
|
|
45
34
|
}
|
|
46
35
|
export {};
|
|
47
36
|
//# 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":"AAAA,OAAO,EAAE,cAAc,EAAe,oCAAoC;
|
|
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;AAE1E,OAAO,KAAK,EAAE,+BAA+B,EAAE,aAAa,EAAE,oBAAgB;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAgB;AAEjD,OAAO,EACL,SAAS,EAET,kBAAkB,EAEnB,+BAA2B;AAE5B,OAAO,EAAwB,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,WACf,MAAM,KACd,QAAQ,cAAc,GAAG,SAAS,CAAC,CAuBpC;IAEF;;;;;OAKG;IAEH,+BAA+B,mBACb,MAAM,eACT,iBAAiB,KAC7B,IAAI,CAqEL;CACH"}
|
|
@@ -9,15 +9,16 @@ 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,
|
|
12
|
+
var _IntentManager_instances, _IntentManager_messenger, _IntentManager_intentStatusesByBridgeTxMetaId, _IntentManager_setIntentStatuses;
|
|
13
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";
|
|
16
|
+
import { getTransactionMetaById, updateTransaction } from "./utils/transaction.mjs";
|
|
15
17
|
import { IntentOrderStatus } from "./utils/validators.mjs";
|
|
16
18
|
export class IntentManager {
|
|
17
|
-
constructor({ messenger,
|
|
19
|
+
constructor({ messenger, customBridgeApiBaseUrl, fetchFn, }) {
|
|
18
20
|
_IntentManager_instances.add(this);
|
|
19
21
|
_IntentManager_messenger.set(this, void 0);
|
|
20
|
-
_IntentManager_updateTransactionFn.set(this, void 0);
|
|
21
22
|
_IntentManager_intentStatusesByBridgeTxMetaId.set(this, new Map());
|
|
22
23
|
/**
|
|
23
24
|
* Get the status of an intent order.
|
|
@@ -27,10 +28,10 @@ export class IntentManager {
|
|
|
27
28
|
* @param clientId - The client ID.
|
|
28
29
|
* @returns The intent order mapped status.
|
|
29
30
|
*/
|
|
30
|
-
this.getIntentTransactionStatus = async (bridgeTxMetaId, srcChainId, protocol, clientId, txHash
|
|
31
|
+
this.getIntentTransactionStatus = async (bridgeTxMetaId, srcChainId, protocol, clientId, txHash) => {
|
|
31
32
|
try {
|
|
32
33
|
const orderStatus = await this.intentApi.getOrderStatus(bridgeTxMetaId, protocol, srcChainId, clientId);
|
|
33
|
-
return __classPrivateFieldGet(this, _IntentManager_instances, "m", _IntentManager_setIntentStatuses).call(this, bridgeTxMetaId, orderStatus, srcChainId, txHash
|
|
34
|
+
return __classPrivateFieldGet(this, _IntentManager_instances, "m", _IntentManager_setIntentStatuses).call(this, bridgeTxMetaId, orderStatus, srcChainId, txHash);
|
|
34
35
|
}
|
|
35
36
|
catch (error) {
|
|
36
37
|
if (error instanceof Error) {
|
|
@@ -58,8 +59,7 @@ export class IntentManager {
|
|
|
58
59
|
}
|
|
59
60
|
try {
|
|
60
61
|
// Merge with existing TransactionMeta to avoid wiping required fields
|
|
61
|
-
const
|
|
62
|
-
const existingTxMeta = transactions.find((tx) => tx.id === originalTxId);
|
|
62
|
+
const existingTxMeta = getTransactionMetaById(__classPrivateFieldGet(this, _IntentManager_messenger, "f"), originalTxId);
|
|
63
63
|
if (!existingTxMeta) {
|
|
64
64
|
console.warn('[Intent polling] Skipping update, transaction not found', { originalTxId, bridgeHistoryKey: bridgeTxMetaId });
|
|
65
65
|
return;
|
|
@@ -75,17 +75,15 @@ export class IntentManager {
|
|
|
75
75
|
txReceipt: {
|
|
76
76
|
...existingTxReceipt,
|
|
77
77
|
transactionHash: txHash,
|
|
78
|
-
status:
|
|
78
|
+
status: isComplete ? '0x1' : '0x0',
|
|
79
79
|
},
|
|
80
80
|
}
|
|
81
81
|
: {};
|
|
82
|
-
|
|
83
|
-
...existingTxMeta,
|
|
82
|
+
updateTransaction(__classPrivateFieldGet(this, _IntentManager_messenger, "f"), existingTxMeta, {
|
|
84
83
|
status: bridgeStatus?.transactionStatus,
|
|
85
84
|
...(txHash ? { hash: txHash } : {}),
|
|
86
85
|
...txReceiptUpdate,
|
|
87
|
-
};
|
|
88
|
-
__classPrivateFieldGet(this, _IntentManager_updateTransactionFn, "f").call(this, updatedTxMeta, `BridgeStatusController - Intent order status updated: ${orderStatus}`);
|
|
86
|
+
}, `BridgeStatusController - Intent order status updated: ${orderStatus}`);
|
|
89
87
|
if (isFinalStatus) {
|
|
90
88
|
__classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").delete(bridgeTxMetaId);
|
|
91
89
|
}
|
|
@@ -98,22 +96,11 @@ export class IntentManager {
|
|
|
98
96
|
});
|
|
99
97
|
}
|
|
100
98
|
};
|
|
101
|
-
/**
|
|
102
|
-
* Submit an intent order.
|
|
103
|
-
*
|
|
104
|
-
* @param submissionParams - The submission parameters.
|
|
105
|
-
* @param clientId - The client ID.
|
|
106
|
-
* @returns The intent order.
|
|
107
|
-
*/
|
|
108
|
-
this.submitIntent = async (submissionParams, clientId) => {
|
|
109
|
-
return this.intentApi.submitIntent(submissionParams, clientId);
|
|
110
|
-
};
|
|
111
99
|
__classPrivateFieldSet(this, _IntentManager_messenger, messenger, "f");
|
|
112
|
-
|
|
113
|
-
this.intentApi = new IntentApiImpl(customBridgeApiBaseUrl, fetchFn, getJwt);
|
|
100
|
+
this.intentApi = new IntentApiImpl(customBridgeApiBaseUrl, fetchFn, async () => await getJwt(messenger));
|
|
114
101
|
}
|
|
115
102
|
}
|
|
116
|
-
_IntentManager_messenger = new WeakMap(),
|
|
103
|
+
_IntentManager_messenger = new WeakMap(), _IntentManager_intentStatusesByBridgeTxMetaId = new WeakMap(), _IntentManager_instances = new WeakSet(), _IntentManager_setIntentStatuses = function _IntentManager_setIntentStatuses(bridgeTxMetaId, order, srcChainId, txHash) {
|
|
117
104
|
const bridgeStatus = translateIntentOrderToBridgeStatus(order, srcChainId, txHash);
|
|
118
105
|
const intentStatuses = {
|
|
119
106
|
orderStatus: order.status,
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAI1E,OAAO,EAAE,MAAM,EAAE,mCAA+B;AAChD,OAAO,E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I,qDAAgC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;gBAC9D,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,sDAAsD,EAAE;oBACpE,YAAY;oBACZ,gBAAgB,EAAE,cAAc;oBAChC,KAAK;iBACN,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC;QA5JA,uBAAA,IAAI,4BAAc,SAAS,MAAA,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,IAAI,aAAa,CAChC,sBAAsB,EACtB,OAAO,EACP,KAAK,IAAI,EAAE,CAAC,MAAM,MAAM,CAAC,SAAS,CAAC,CACpC,CAAC;IACJ,CAAC;CAuJF;gOA1IG,cAAsB,EACtB,KAA2B,EAC3B,UAAkB,EAClB,MAAe;IAEf,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';\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 translateIntentOrderToBridgeStatus,\n} from './utils/intent-api';\nimport { getTransactionMetaById, updateTransaction } from './utils/transaction';\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,\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 existingTxMeta = getTransactionMetaById(\n this.#messenger,\n 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\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 as `0x${string}` | undefined,\n status: isComplete ? '0x1' : '0x0',\n },\n }\n : {};\n\n updateTransaction(\n this.#messenger,\n existingTxMeta,\n {\n status: bridgeStatus?.transactionStatus,\n ...(txHash ? { hash: txHash } : {}),\n ...txReceiptUpdate,\n },\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"]}
|