@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
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { StatusTypes, isCrossChain, isTronChainId } from "@metamask/bridge-controller";
|
|
2
|
+
export const rekeyHistoryItemInState = (state, actionId, txMeta) => {
|
|
3
|
+
const historyItem = state.txHistory[actionId];
|
|
4
|
+
if (!historyItem) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
state.txHistory[txMeta.id] = {
|
|
8
|
+
...historyItem,
|
|
9
|
+
txMetaId: txMeta.id,
|
|
10
|
+
originalTransactionId: historyItem.originalTransactionId ?? txMeta.id,
|
|
11
|
+
status: {
|
|
12
|
+
...historyItem.status,
|
|
13
|
+
srcChain: {
|
|
14
|
+
...historyItem.status.srcChain,
|
|
15
|
+
txHash: txMeta.hash ?? historyItem.status.srcChain?.txHash,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
delete state.txHistory[actionId];
|
|
20
|
+
return true;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Determines the key to use for storing a bridge history item.
|
|
24
|
+
* Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.
|
|
25
|
+
*
|
|
26
|
+
* @param actionId - The action ID used for pre-submission tracking
|
|
27
|
+
* @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta
|
|
28
|
+
* @param syntheticTransactionId - The transactionId of the intent's placeholder transaction
|
|
29
|
+
* @returns The key to use for the history item
|
|
30
|
+
* @throws Error if neither actionId nor bridgeTxMetaId is provided
|
|
31
|
+
*/
|
|
32
|
+
export function getHistoryKey(actionId, bridgeTxMetaId, syntheticTransactionId) {
|
|
33
|
+
const historyKey = actionId ?? bridgeTxMetaId ?? syntheticTransactionId;
|
|
34
|
+
if (!historyKey) {
|
|
35
|
+
throw new Error('Cannot add tx to history: either actionId, bridgeTxMeta.id, or syntheticTransactionId must be provided');
|
|
36
|
+
}
|
|
37
|
+
return historyKey;
|
|
38
|
+
}
|
|
39
|
+
export const getInitialHistoryItem = (args) => {
|
|
40
|
+
const { bridgeTxMeta, quoteResponse, startTime, slippagePercentage, initialDestAssetBalance, targetContractAddress, approvalTxId, isStxEnabled, location, abTests, activeAbTests, accountAddress: selectedAddress, originalTransactionId, actionId, } = args;
|
|
41
|
+
// Determine the key for this history item:
|
|
42
|
+
// - For pre-submission (non-batch EVM): use actionId
|
|
43
|
+
// - For post-submission or other cases: use bridgeTxMeta.id
|
|
44
|
+
const historyKey = getHistoryKey(actionId, bridgeTxMeta?.id, originalTransactionId);
|
|
45
|
+
// Write all non-status fields to state so we can reference the quote in Activity list without the Bridge API
|
|
46
|
+
// We know it's in progress but not the exact status yet
|
|
47
|
+
const txHistoryItem = {
|
|
48
|
+
txMetaId: bridgeTxMeta?.id,
|
|
49
|
+
actionId,
|
|
50
|
+
originalTransactionId: originalTransactionId ?? bridgeTxMeta?.id, // Keep original for intent transactions
|
|
51
|
+
batchId: bridgeTxMeta?.batchId,
|
|
52
|
+
quote: quoteResponse.quote,
|
|
53
|
+
startTime,
|
|
54
|
+
estimatedProcessingTimeInSeconds: quoteResponse.estimatedProcessingTimeInSeconds,
|
|
55
|
+
slippagePercentage,
|
|
56
|
+
pricingData: {
|
|
57
|
+
amountSent: quoteResponse.sentAmount?.amount ?? '0',
|
|
58
|
+
amountSentInUsd: quoteResponse.sentAmount?.usd ?? undefined,
|
|
59
|
+
quotedGasInUsd: quoteResponse.gasFee?.effective?.usd ?? undefined,
|
|
60
|
+
quotedReturnInUsd: quoteResponse.toTokenAmount?.usd ?? undefined,
|
|
61
|
+
quotedGasAmount: quoteResponse.gasFee?.effective?.amount ?? undefined,
|
|
62
|
+
},
|
|
63
|
+
initialDestAssetBalance,
|
|
64
|
+
targetContractAddress,
|
|
65
|
+
account: selectedAddress,
|
|
66
|
+
status: {
|
|
67
|
+
// We always have a PENDING status when we start polling for a tx, don't need the Bridge API for that
|
|
68
|
+
// Also we know the bare minimum fields for status at this point in time
|
|
69
|
+
status: StatusTypes.PENDING,
|
|
70
|
+
srcChain: {
|
|
71
|
+
chainId: quoteResponse.quote.srcChainId,
|
|
72
|
+
txHash: bridgeTxMeta?.hash,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
hasApprovalTx: Boolean(quoteResponse.approval),
|
|
76
|
+
approvalTxId,
|
|
77
|
+
isStxEnabled: Boolean(isStxEnabled),
|
|
78
|
+
featureId: quoteResponse.featureId,
|
|
79
|
+
location,
|
|
80
|
+
...(abTests && { abTests }),
|
|
81
|
+
...(activeAbTests && { activeAbTests }),
|
|
82
|
+
};
|
|
83
|
+
return { historyKey, txHistoryItem };
|
|
84
|
+
};
|
|
85
|
+
export const shouldPollHistoryItem = (historyItem) => {
|
|
86
|
+
const isIntent = Boolean(historyItem?.quote?.intent);
|
|
87
|
+
const isBridgeTx = isCrossChain(historyItem.quote.srcChainId, historyItem.quote.destChainId);
|
|
88
|
+
const isTronTx = isTronChainId(historyItem.quote.srcChainId);
|
|
89
|
+
return [isBridgeTx, isIntent, isTronTx].some(Boolean);
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=history.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.mjs","sourceRoot":"","sources":["../../src/utils/history.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,aAAa,EACd,oCAAoC;AAQrC,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,KAAkC,EAClC,QAAgB,EAChB,MAAqC,EAC5B,EAAE;IACX,MAAM,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG;QAC3B,GAAG,WAAW;QACd,QAAQ,EAAE,MAAM,CAAC,EAAE;QACnB,qBAAqB,EAAE,WAAW,CAAC,q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,MAAM,UAAU,GAAG,YAAY,CAC7B,WAAW,CAAC,KAAK,CAAC,UAAU,EAC5B,WAAW,CAAC,KAAK,CAAC,WAAW,CAC9B,CAAC;IACF,MAAM,QAAQ,GAAG,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAE7D,OAAO,CAAC,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACxD,CAAC,CAAC","sourcesContent":["import {\n StatusTypes,\n isCrossChain,\n isTronChainId,\n} from '@metamask/bridge-controller';\n\nimport type {\n BridgeHistoryItem,\n BridgeStatusControllerState,\n StartPollingForBridgeTxStatusArgsSerialized,\n} from '../types';\n\nexport const rekeyHistoryItemInState = (\n state: BridgeStatusControllerState,\n actionId: string,\n txMeta: { id: string; hash?: string },\n): boolean => {\n const historyItem = state.txHistory[actionId];\n if (!historyItem) {\n return false;\n }\n\n state.txHistory[txMeta.id] = {\n ...historyItem,\n txMetaId: txMeta.id,\n originalTransactionId: historyItem.originalTransactionId ?? txMeta.id,\n status: {\n ...historyItem.status,\n srcChain: {\n ...historyItem.status.srcChain,\n txHash: txMeta.hash ?? historyItem.status.srcChain?.txHash,\n },\n },\n };\n delete state.txHistory[actionId];\n return true;\n};\n\n/**\n * Determines the key to use for storing a bridge history item.\n * Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.\n *\n * @param actionId - The action ID used for pre-submission tracking\n * @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta\n * @param syntheticTransactionId - The transactionId of the intent's placeholder transaction\n * @returns The key to use for the history item\n * @throws Error if neither actionId nor bridgeTxMetaId is provided\n */\nexport function getHistoryKey(\n actionId: string | undefined,\n bridgeTxMetaId: string | undefined,\n syntheticTransactionId?: string,\n): string {\n const historyKey = actionId ?? bridgeTxMetaId ?? syntheticTransactionId;\n if (!historyKey) {\n throw new Error(\n 'Cannot add tx to history: either actionId, bridgeTxMeta.id, or syntheticTransactionId must be provided',\n );\n }\n return historyKey;\n}\n\nexport const getInitialHistoryItem = (\n args: StartPollingForBridgeTxStatusArgsSerialized,\n): {\n historyKey: string;\n txHistoryItem: BridgeHistoryItem;\n} => {\n const {\n bridgeTxMeta,\n quoteResponse,\n startTime,\n slippagePercentage,\n initialDestAssetBalance,\n targetContractAddress,\n approvalTxId,\n isStxEnabled,\n location,\n abTests,\n activeAbTests,\n accountAddress: selectedAddress,\n originalTransactionId,\n actionId,\n } = args;\n // Determine the key for this history item:\n // - For pre-submission (non-batch EVM): use actionId\n // - For post-submission or other cases: use bridgeTxMeta.id\n const historyKey = getHistoryKey(\n actionId,\n bridgeTxMeta?.id,\n originalTransactionId,\n );\n\n // Write all non-status fields to state so we can reference the quote in Activity list without the Bridge API\n // We know it's in progress but not the exact status yet\n const txHistoryItem = {\n txMetaId: bridgeTxMeta?.id,\n actionId,\n originalTransactionId: originalTransactionId ?? bridgeTxMeta?.id, // Keep original for intent transactions\n batchId: bridgeTxMeta?.batchId,\n quote: quoteResponse.quote,\n startTime,\n estimatedProcessingTimeInSeconds:\n quoteResponse.estimatedProcessingTimeInSeconds,\n slippagePercentage,\n pricingData: {\n amountSent: quoteResponse.sentAmount?.amount ?? '0',\n amountSentInUsd: quoteResponse.sentAmount?.usd ?? undefined,\n quotedGasInUsd: quoteResponse.gasFee?.effective?.usd ?? undefined,\n quotedReturnInUsd: quoteResponse.toTokenAmount?.usd ?? undefined,\n quotedGasAmount: quoteResponse.gasFee?.effective?.amount ?? undefined,\n },\n initialDestAssetBalance,\n targetContractAddress,\n account: selectedAddress,\n status: {\n // We always have a PENDING status when we start polling for a tx, don't need the Bridge API for that\n // Also we know the bare minimum fields for status at this point in time\n status: StatusTypes.PENDING,\n srcChain: {\n chainId: quoteResponse.quote.srcChainId,\n txHash: bridgeTxMeta?.hash,\n },\n },\n hasApprovalTx: Boolean(quoteResponse.approval),\n approvalTxId,\n isStxEnabled: Boolean(isStxEnabled),\n featureId: quoteResponse.featureId,\n location,\n ...(abTests && { abTests }),\n ...(activeAbTests && { activeAbTests }),\n };\n\n return { historyKey, txHistoryItem };\n};\n\nexport const shouldPollHistoryItem = (\n historyItem: BridgeHistoryItem,\n): boolean => {\n const isIntent = Boolean(historyItem?.quote?.intent);\n const isBridgeTx = isCrossChain(\n historyItem.quote.srcChainId,\n historyItem.quote.destChainId,\n );\n const isTronTx = isTronChainId(historyItem.quote.srcChainId);\n\n return [isBridgeTx, isIntent, isTronTx].some(Boolean);\n};\n"]}
|
|
@@ -12,7 +12,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
12
12
|
};
|
|
13
13
|
var _IntentApiImpl_baseUrl, _IntentApiImpl_fetchFn, _IntentApiImpl_getJwt;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.mapIntentOrderStatusToTransactionStatus = exports.translateIntentOrderToBridgeStatus = exports.IntentApiImpl = void 0;
|
|
15
|
+
exports.postSubmitOrder = exports.getIntentFromQuote = exports.mapIntentOrderStatusToTransactionStatus = exports.translateIntentOrderToBridgeStatus = exports.IntentApiImpl = void 0;
|
|
16
16
|
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
17
17
|
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
18
18
|
const validators_1 = require("./validators.cjs");
|
|
@@ -25,30 +25,6 @@ class IntentApiImpl {
|
|
|
25
25
|
__classPrivateFieldSet(this, _IntentApiImpl_fetchFn, fetchFn, "f");
|
|
26
26
|
__classPrivateFieldSet(this, _IntentApiImpl_getJwt, getJwt, "f");
|
|
27
27
|
}
|
|
28
|
-
async submitIntent(params, clientId) {
|
|
29
|
-
const endpoint = `${__classPrivateFieldGet(this, _IntentApiImpl_baseUrl, "f")}/submitOrder`;
|
|
30
|
-
try {
|
|
31
|
-
const jwt = await __classPrivateFieldGet(this, _IntentApiImpl_getJwt, "f").call(this);
|
|
32
|
-
const response = await __classPrivateFieldGet(this, _IntentApiImpl_fetchFn, "f").call(this, endpoint, {
|
|
33
|
-
method: 'POST',
|
|
34
|
-
headers: {
|
|
35
|
-
'Content-Type': 'application/json',
|
|
36
|
-
...(0, bridge_controller_1.getClientHeaders)({ clientId, jwt }),
|
|
37
|
-
},
|
|
38
|
-
body: JSON.stringify(params),
|
|
39
|
-
});
|
|
40
|
-
if (!(0, validators_1.validateIntentStatusResponse)(response)) {
|
|
41
|
-
throw new Error('Invalid submitOrder response');
|
|
42
|
-
}
|
|
43
|
-
return response;
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
if (error instanceof Error) {
|
|
47
|
-
throw new Error(`Failed to submit intent: ${error.message}`);
|
|
48
|
-
}
|
|
49
|
-
throw new Error('Failed to submit intent');
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
28
|
async getOrderStatus(orderId, aggregatorId, srcChainId, clientId) {
|
|
53
29
|
const endpoint = `${__classPrivateFieldGet(this, _IntentApiImpl_baseUrl, "f")}/getOrderStatus?orderId=${orderId}&aggregatorId=${encodeURIComponent(aggregatorId)}&srcChainId=${srcChainId}`;
|
|
54
30
|
try {
|
|
@@ -93,7 +69,7 @@ const translateIntentOrderToBridgeStatus = (intentOrder, srcChainId, fallbackTxH
|
|
|
93
69
|
default:
|
|
94
70
|
statusType = bridge_controller_1.StatusTypes.UNKNOWN;
|
|
95
71
|
}
|
|
96
|
-
const txHash = intentOrder.txHash ?? fallbackTxHash
|
|
72
|
+
const txHash = intentOrder.txHash ?? fallbackTxHash;
|
|
97
73
|
const status = {
|
|
98
74
|
status: statusType,
|
|
99
75
|
srcChain: {
|
|
@@ -125,4 +101,43 @@ function mapIntentOrderStatusToTransactionStatus(intentStatus) {
|
|
|
125
101
|
}
|
|
126
102
|
}
|
|
127
103
|
exports.mapIntentOrderStatusToTransactionStatus = mapIntentOrderStatusToTransactionStatus;
|
|
104
|
+
/**
|
|
105
|
+
* Extracts and validates the intent data from a quote response.
|
|
106
|
+
*
|
|
107
|
+
* @param quoteResponse - The quote response that may contain intent data
|
|
108
|
+
* @returns The intent data from the quote
|
|
109
|
+
* @throws Error if the quote does not contain intent data
|
|
110
|
+
*/
|
|
111
|
+
function getIntentFromQuote(quoteResponse) {
|
|
112
|
+
const { intent } = quoteResponse.quote;
|
|
113
|
+
if (!intent) {
|
|
114
|
+
throw new Error('submitIntent: missing intent data');
|
|
115
|
+
}
|
|
116
|
+
return intent;
|
|
117
|
+
}
|
|
118
|
+
exports.getIntentFromQuote = getIntentFromQuote;
|
|
119
|
+
const postSubmitOrder = async ({ params, clientId, jwt, fetchFn, bridgeApiBaseUrl, }) => {
|
|
120
|
+
const endpoint = `${bridgeApiBaseUrl}/submitOrder`;
|
|
121
|
+
try {
|
|
122
|
+
const response = await fetchFn(endpoint, {
|
|
123
|
+
method: 'POST',
|
|
124
|
+
headers: {
|
|
125
|
+
'Content-Type': 'application/json',
|
|
126
|
+
...(0, bridge_controller_1.getClientHeaders)({ clientId, jwt }),
|
|
127
|
+
},
|
|
128
|
+
body: JSON.stringify(params),
|
|
129
|
+
});
|
|
130
|
+
if (!(0, validators_1.validateIntentStatusResponse)(response)) {
|
|
131
|
+
throw new Error('Invalid submitOrder response');
|
|
132
|
+
}
|
|
133
|
+
return response;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
if (error instanceof Error) {
|
|
137
|
+
throw new Error(`Failed to submit intent: ${error.message}`);
|
|
138
|
+
}
|
|
139
|
+
throw new Error('Failed to submit intent');
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
exports.postSubmitOrder = postSubmitOrder;
|
|
128
143
|
//# sourceMappingURL=intent-api.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent-api.cjs","sourceRoot":"","sources":["../../src/utils/intent-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"intent-api.cjs","sourceRoot":"","sources":["../../src/utils/intent-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;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CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC,CAAC;AAjCW,QAAA,eAAe,mBAiC1B","sourcesContent":["import {\n BridgeClientId,\n ChainId,\n getClientHeaders,\n Intent,\n QuoteResponse,\n StatusTypes,\n} from '@metamask/bridge-controller';\nimport { TransactionStatus } from '@metamask/transaction-controller';\n\nimport {\n IntentStatusResponse,\n IntentOrderStatus,\n validateIntentStatusResponse,\n} from './validators';\nimport type { FetchFunction, StatusResponse } from '../types';\n\nexport type IntentSubmissionParams = {\n srcChainId: ChainId;\n quoteId: string;\n signature: string;\n order: unknown;\n userAddress: string;\n aggregatorId: string;\n};\n\nexport type IntentApi = {\n getOrderStatus(\n orderId: string,\n aggregatorId: string,\n srcChainId: ChainId,\n clientId: BridgeClientId,\n ): Promise<IntentStatusResponse>;\n};\n\nexport type GetJwtFn = () => Promise<string | undefined>;\n\nexport class IntentApiImpl implements IntentApi {\n readonly #baseUrl: string;\n\n readonly #fetchFn: FetchFunction;\n\n readonly #getJwt: GetJwtFn;\n\n constructor(baseUrl: string, fetchFn: FetchFunction, getJwt: GetJwtFn) {\n this.#baseUrl = baseUrl;\n this.#fetchFn = fetchFn;\n this.#getJwt = getJwt;\n }\n\n async getOrderStatus(\n orderId: string,\n aggregatorId: string,\n srcChainId: ChainId,\n clientId: BridgeClientId,\n ): Promise<IntentStatusResponse> {\n const endpoint = `${this.#baseUrl}/getOrderStatus?orderId=${orderId}&aggregatorId=${encodeURIComponent(aggregatorId)}&srcChainId=${srcChainId}`;\n try {\n const jwt = await this.#getJwt();\n const response = await this.#fetchFn(endpoint, {\n method: 'GET',\n headers: getClientHeaders({ clientId, jwt }),\n });\n if (!validateIntentStatusResponse(response)) {\n throw new Error('Invalid getOrderStatus response');\n }\n return response;\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(`Failed to get order status: ${error.message}`);\n }\n throw new Error('Failed to get order status');\n }\n }\n}\n\nexport type IntentBridgeStatus = {\n status: StatusResponse;\n txHash?: string;\n transactionStatus: TransactionStatus;\n};\n\nexport const translateIntentOrderToBridgeStatus = (\n intentOrder: IntentStatusResponse,\n srcChainId: number,\n fallbackTxHash?: string,\n): IntentBridgeStatus => {\n let statusType: StatusTypes;\n switch (intentOrder.status) {\n case IntentOrderStatus.CONFIRMED:\n case IntentOrderStatus.COMPLETED:\n statusType = StatusTypes.COMPLETE;\n break;\n case IntentOrderStatus.FAILED:\n case IntentOrderStatus.EXPIRED:\n case IntentOrderStatus.CANCELLED:\n statusType = StatusTypes.FAILED;\n break;\n case IntentOrderStatus.PENDING:\n statusType = StatusTypes.PENDING;\n break;\n case IntentOrderStatus.SUBMITTED:\n statusType = StatusTypes.SUBMITTED;\n break;\n default:\n statusType = StatusTypes.UNKNOWN;\n }\n\n const txHash = intentOrder.txHash ?? fallbackTxHash;\n const status: StatusResponse = {\n status: statusType,\n srcChain: {\n chainId: srcChainId,\n txHash,\n },\n };\n\n return {\n status,\n txHash,\n transactionStatus: mapIntentOrderStatusToTransactionStatus(\n intentOrder.status,\n ),\n };\n};\n\nexport function mapIntentOrderStatusToTransactionStatus(\n intentStatus: IntentOrderStatus,\n): TransactionStatus {\n switch (intentStatus) {\n case IntentOrderStatus.PENDING:\n case IntentOrderStatus.SUBMITTED:\n return TransactionStatus.submitted;\n case IntentOrderStatus.CONFIRMED:\n case IntentOrderStatus.COMPLETED:\n return TransactionStatus.confirmed;\n case IntentOrderStatus.FAILED:\n case IntentOrderStatus.EXPIRED:\n case IntentOrderStatus.CANCELLED:\n return TransactionStatus.failed;\n default:\n return TransactionStatus.submitted;\n }\n}\n\n/**\n * Extracts and validates the intent data from a quote response.\n *\n * @param quoteResponse - The quote response that may contain intent data\n * @returns The intent data from the quote\n * @throws Error if the quote does not contain intent data\n */\nexport function getIntentFromQuote(quoteResponse: QuoteResponse): Intent {\n const { intent } = quoteResponse.quote;\n if (!intent) {\n throw new Error('submitIntent: missing intent data');\n }\n return intent;\n}\n\nexport const postSubmitOrder = async ({\n params,\n clientId,\n jwt,\n fetchFn,\n bridgeApiBaseUrl,\n}: {\n params: IntentSubmissionParams;\n clientId: BridgeClientId;\n jwt: string | undefined;\n fetchFn: FetchFunction;\n bridgeApiBaseUrl: string;\n}): Promise<IntentStatusResponse> => {\n const endpoint = `${bridgeApiBaseUrl}/submitOrder`;\n try {\n const response = await fetchFn(endpoint, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...getClientHeaders({ clientId, jwt }),\n },\n body: JSON.stringify(params),\n });\n if (!validateIntentStatusResponse(response)) {\n throw new Error('Invalid submitOrder response');\n }\n return response;\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(`Failed to submit intent: ${error.message}`);\n }\n throw new Error('Failed to submit intent');\n }\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BridgeClientId, ChainId } from "@metamask/bridge-controller";
|
|
1
|
+
import { BridgeClientId, ChainId, Intent, QuoteResponse } from "@metamask/bridge-controller";
|
|
2
2
|
import { TransactionStatus } from "@metamask/transaction-controller";
|
|
3
3
|
import { IntentStatusResponse, IntentOrderStatus } from "./validators.cjs";
|
|
4
4
|
import type { FetchFunction, StatusResponse } from "../types.cjs";
|
|
@@ -11,14 +11,12 @@ export type IntentSubmissionParams = {
|
|
|
11
11
|
aggregatorId: string;
|
|
12
12
|
};
|
|
13
13
|
export type IntentApi = {
|
|
14
|
-
submitIntent(params: IntentSubmissionParams, clientId: BridgeClientId): Promise<IntentStatusResponse>;
|
|
15
14
|
getOrderStatus(orderId: string, aggregatorId: string, srcChainId: ChainId, clientId: BridgeClientId): Promise<IntentStatusResponse>;
|
|
16
15
|
};
|
|
17
16
|
export type GetJwtFn = () => Promise<string | undefined>;
|
|
18
17
|
export declare class IntentApiImpl implements IntentApi {
|
|
19
18
|
#private;
|
|
20
19
|
constructor(baseUrl: string, fetchFn: FetchFunction, getJwt: GetJwtFn);
|
|
21
|
-
submitIntent(params: IntentSubmissionParams, clientId: BridgeClientId): Promise<IntentStatusResponse>;
|
|
22
20
|
getOrderStatus(orderId: string, aggregatorId: string, srcChainId: ChainId, clientId: BridgeClientId): Promise<IntentStatusResponse>;
|
|
23
21
|
}
|
|
24
22
|
export type IntentBridgeStatus = {
|
|
@@ -28,4 +26,19 @@ export type IntentBridgeStatus = {
|
|
|
28
26
|
};
|
|
29
27
|
export declare const translateIntentOrderToBridgeStatus: (intentOrder: IntentStatusResponse, srcChainId: number, fallbackTxHash?: string) => IntentBridgeStatus;
|
|
30
28
|
export declare function mapIntentOrderStatusToTransactionStatus(intentStatus: IntentOrderStatus): TransactionStatus;
|
|
29
|
+
/**
|
|
30
|
+
* Extracts and validates the intent data from a quote response.
|
|
31
|
+
*
|
|
32
|
+
* @param quoteResponse - The quote response that may contain intent data
|
|
33
|
+
* @returns The intent data from the quote
|
|
34
|
+
* @throws Error if the quote does not contain intent data
|
|
35
|
+
*/
|
|
36
|
+
export declare function getIntentFromQuote(quoteResponse: QuoteResponse): Intent;
|
|
37
|
+
export declare const postSubmitOrder: ({ params, clientId, jwt, fetchFn, bridgeApiBaseUrl, }: {
|
|
38
|
+
params: IntentSubmissionParams;
|
|
39
|
+
clientId: BridgeClientId;
|
|
40
|
+
jwt: string | undefined;
|
|
41
|
+
fetchFn: FetchFunction;
|
|
42
|
+
bridgeApiBaseUrl: string;
|
|
43
|
+
}) => Promise<IntentStatusResponse>;
|
|
31
44
|
//# sourceMappingURL=intent-api.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent-api.d.cts","sourceRoot":"","sources":["../../src/utils/intent-api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,OAAO,
|
|
1
|
+
{"version":3,"file":"intent-api.d.cts","sourceRoot":"","sources":["../../src/utils/intent-api.ts"],"names":[],"mappings":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CACrD,YAAY,EAAE,iBAAiB,GAC9B,iBAAiB,CAenB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAMvE;AAED,eAAO,MAAM,eAAe;YAOlB,sBAAsB;cACpB,cAAc;SACnB,MAAM,GAAG,SAAS;aACd,aAAa;sBACJ,MAAM;MACtB,QAAQ,oBAAoB,CAqB/B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BridgeClientId, ChainId } from "@metamask/bridge-controller";
|
|
1
|
+
import { BridgeClientId, ChainId, Intent, QuoteResponse } from "@metamask/bridge-controller";
|
|
2
2
|
import { TransactionStatus } from "@metamask/transaction-controller";
|
|
3
3
|
import { IntentStatusResponse, IntentOrderStatus } from "./validators.mjs";
|
|
4
4
|
import type { FetchFunction, StatusResponse } from "../types.mjs";
|
|
@@ -11,14 +11,12 @@ export type IntentSubmissionParams = {
|
|
|
11
11
|
aggregatorId: string;
|
|
12
12
|
};
|
|
13
13
|
export type IntentApi = {
|
|
14
|
-
submitIntent(params: IntentSubmissionParams, clientId: BridgeClientId): Promise<IntentStatusResponse>;
|
|
15
14
|
getOrderStatus(orderId: string, aggregatorId: string, srcChainId: ChainId, clientId: BridgeClientId): Promise<IntentStatusResponse>;
|
|
16
15
|
};
|
|
17
16
|
export type GetJwtFn = () => Promise<string | undefined>;
|
|
18
17
|
export declare class IntentApiImpl implements IntentApi {
|
|
19
18
|
#private;
|
|
20
19
|
constructor(baseUrl: string, fetchFn: FetchFunction, getJwt: GetJwtFn);
|
|
21
|
-
submitIntent(params: IntentSubmissionParams, clientId: BridgeClientId): Promise<IntentStatusResponse>;
|
|
22
20
|
getOrderStatus(orderId: string, aggregatorId: string, srcChainId: ChainId, clientId: BridgeClientId): Promise<IntentStatusResponse>;
|
|
23
21
|
}
|
|
24
22
|
export type IntentBridgeStatus = {
|
|
@@ -28,4 +26,19 @@ export type IntentBridgeStatus = {
|
|
|
28
26
|
};
|
|
29
27
|
export declare const translateIntentOrderToBridgeStatus: (intentOrder: IntentStatusResponse, srcChainId: number, fallbackTxHash?: string) => IntentBridgeStatus;
|
|
30
28
|
export declare function mapIntentOrderStatusToTransactionStatus(intentStatus: IntentOrderStatus): TransactionStatus;
|
|
29
|
+
/**
|
|
30
|
+
* Extracts and validates the intent data from a quote response.
|
|
31
|
+
*
|
|
32
|
+
* @param quoteResponse - The quote response that may contain intent data
|
|
33
|
+
* @returns The intent data from the quote
|
|
34
|
+
* @throws Error if the quote does not contain intent data
|
|
35
|
+
*/
|
|
36
|
+
export declare function getIntentFromQuote(quoteResponse: QuoteResponse): Intent;
|
|
37
|
+
export declare const postSubmitOrder: ({ params, clientId, jwt, fetchFn, bridgeApiBaseUrl, }: {
|
|
38
|
+
params: IntentSubmissionParams;
|
|
39
|
+
clientId: BridgeClientId;
|
|
40
|
+
jwt: string | undefined;
|
|
41
|
+
fetchFn: FetchFunction;
|
|
42
|
+
bridgeApiBaseUrl: string;
|
|
43
|
+
}) => Promise<IntentStatusResponse>;
|
|
31
44
|
//# sourceMappingURL=intent-api.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent-api.d.mts","sourceRoot":"","sources":["../../src/utils/intent-api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,OAAO,
|
|
1
|
+
{"version":3,"file":"intent-api.d.mts","sourceRoot":"","sources":["../../src/utils/intent-api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,OAAO,EAEP,MAAM,EACN,aAAa,EAEd,oCAAoC;AACrC,OAAO,EAAE,iBAAiB,EAAE,yCAAyC;AAErE,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EAElB,yBAAqB;AACtB,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,qBAAiB;AAE9D,MAAM,MAAM,sBAAsB,GAAG;IACnC,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;I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
__classPrivateFieldSet(this, _IntentApiImpl_fetchFn, fetchFn, "f");
|
|
23
23
|
__classPrivateFieldSet(this, _IntentApiImpl_getJwt, getJwt, "f");
|
|
24
24
|
}
|
|
25
|
-
async submitIntent(params, clientId) {
|
|
26
|
-
const endpoint = `${__classPrivateFieldGet(this, _IntentApiImpl_baseUrl, "f")}/submitOrder`;
|
|
27
|
-
try {
|
|
28
|
-
const jwt = await __classPrivateFieldGet(this, _IntentApiImpl_getJwt, "f").call(this);
|
|
29
|
-
const response = await __classPrivateFieldGet(this, _IntentApiImpl_fetchFn, "f").call(this, endpoint, {
|
|
30
|
-
method: 'POST',
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': 'application/json',
|
|
33
|
-
...getClientHeaders({ clientId, jwt }),
|
|
34
|
-
},
|
|
35
|
-
body: JSON.stringify(params),
|
|
36
|
-
});
|
|
37
|
-
if (!validateIntentStatusResponse(response)) {
|
|
38
|
-
throw new Error('Invalid submitOrder response');
|
|
39
|
-
}
|
|
40
|
-
return response;
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
if (error instanceof Error) {
|
|
44
|
-
throw new Error(`Failed to submit intent: ${error.message}`);
|
|
45
|
-
}
|
|
46
|
-
throw new Error('Failed to submit intent');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
25
|
async getOrderStatus(orderId, aggregatorId, srcChainId, clientId) {
|
|
50
26
|
const endpoint = `${__classPrivateFieldGet(this, _IntentApiImpl_baseUrl, "f")}/getOrderStatus?orderId=${orderId}&aggregatorId=${encodeURIComponent(aggregatorId)}&srcChainId=${srcChainId}`;
|
|
51
27
|
try {
|
|
@@ -89,7 +65,7 @@ export const translateIntentOrderToBridgeStatus = (intentOrder, srcChainId, fall
|
|
|
89
65
|
default:
|
|
90
66
|
statusType = StatusTypes.UNKNOWN;
|
|
91
67
|
}
|
|
92
|
-
const txHash = intentOrder.txHash ?? fallbackTxHash
|
|
68
|
+
const txHash = intentOrder.txHash ?? fallbackTxHash;
|
|
93
69
|
const status = {
|
|
94
70
|
status: statusType,
|
|
95
71
|
srcChain: {
|
|
@@ -119,4 +95,41 @@ export function mapIntentOrderStatusToTransactionStatus(intentStatus) {
|
|
|
119
95
|
return TransactionStatus.submitted;
|
|
120
96
|
}
|
|
121
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Extracts and validates the intent data from a quote response.
|
|
100
|
+
*
|
|
101
|
+
* @param quoteResponse - The quote response that may contain intent data
|
|
102
|
+
* @returns The intent data from the quote
|
|
103
|
+
* @throws Error if the quote does not contain intent data
|
|
104
|
+
*/
|
|
105
|
+
export function getIntentFromQuote(quoteResponse) {
|
|
106
|
+
const { intent } = quoteResponse.quote;
|
|
107
|
+
if (!intent) {
|
|
108
|
+
throw new Error('submitIntent: missing intent data');
|
|
109
|
+
}
|
|
110
|
+
return intent;
|
|
111
|
+
}
|
|
112
|
+
export const postSubmitOrder = async ({ params, clientId, jwt, fetchFn, bridgeApiBaseUrl, }) => {
|
|
113
|
+
const endpoint = `${bridgeApiBaseUrl}/submitOrder`;
|
|
114
|
+
try {
|
|
115
|
+
const response = await fetchFn(endpoint, {
|
|
116
|
+
method: 'POST',
|
|
117
|
+
headers: {
|
|
118
|
+
'Content-Type': 'application/json',
|
|
119
|
+
...getClientHeaders({ clientId, jwt }),
|
|
120
|
+
},
|
|
121
|
+
body: JSON.stringify(params),
|
|
122
|
+
});
|
|
123
|
+
if (!validateIntentStatusResponse(response)) {
|
|
124
|
+
throw new Error('Invalid submitOrder response');
|
|
125
|
+
}
|
|
126
|
+
return response;
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (error instanceof Error) {
|
|
130
|
+
throw new Error(`Failed to submit intent: ${error.message}`);
|
|
131
|
+
}
|
|
132
|
+
throw new Error('Failed to submit intent');
|
|
133
|
+
}
|
|
134
|
+
};
|
|
122
135
|
//# sourceMappingURL=intent-api.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent-api.mjs","sourceRoot":"","sources":["../../src/utils/intent-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,cAAc,EACd,OAAO,EACP,gBAAgB,
|
|
1
|
+
{"version":3,"file":"intent-api.mjs","sourceRoot":"","sources":["../../src/utils/intent-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,cAAc,EACd,OAAO,EACP,gBAAgB,EAGhB,WAAW,EACZ,oCAAoC;AACrC,OAAO,EAAE,iBAAiB,EAAE,yCAAyC;AAErE,OAAO,EAEL,iBAAiB,EACjB,4BAA4B,EAC7B,yBAAqB;AAuBtB,MAAM,OAAO,aAAa;IAOxB,YAAY,OAAe,EAAE,OAAsB,EAAE,MAAgB;QAN5D,yCAAiB;QAEjB,yCAAwB;QAExB,wCAAkB;QAGzB,uBAAA,IAAI,0BAAY,OAAO,MAAA,CAAC;QACxB,uBAAA,IAAI,0BAAY,OAAO,MAAA,CAAC;QACxB,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,OAAe,EACf,YAAoB,EACpB,UAAmB,EACnB,QAAwB;QAExB,MAAM,QAAQ,GAAG,GAAG,uBAAA,IAAI,8BAAS,2BAA2B,OAAO,iBAAiB,kBAAkB,CAAC,YAAY,CAAC,eAAe,UAAU,EAAE,CAAC;QAChJ,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,uBAAA,IAAI,6BAAQ,MAAZ,IAAI,CAAU,CAAC;YACjC,MAAM,QAAQ,GAAG,MAAM,uBAAA,IAAI,8BAAS,MAAb,IAAI,EAAU,QAAQ,EAAE;gBAC7C,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE,gBAAgB,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;aAC7C,CAAC,CAAC;YACH,IAAI,CAAC,4BAA4B,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC5C,MAAM,IAAI,KAAK,CAA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IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;SAC7B,CAAC,CAAC;QACH,IAAI,CAAC,4BAA4B,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC,CAAC","sourcesContent":["import {\n BridgeClientId,\n ChainId,\n getClientHeaders,\n Intent,\n QuoteResponse,\n StatusTypes,\n} from '@metamask/bridge-controller';\nimport { TransactionStatus } from '@metamask/transaction-controller';\n\nimport {\n IntentStatusResponse,\n IntentOrderStatus,\n validateIntentStatusResponse,\n} from './validators';\nimport type { FetchFunction, StatusResponse } from '../types';\n\nexport type IntentSubmissionParams = {\n srcChainId: ChainId;\n quoteId: string;\n signature: string;\n order: unknown;\n userAddress: string;\n aggregatorId: string;\n};\n\nexport type IntentApi = {\n getOrderStatus(\n orderId: string,\n aggregatorId: string,\n srcChainId: ChainId,\n clientId: BridgeClientId,\n ): Promise<IntentStatusResponse>;\n};\n\nexport type GetJwtFn = () => Promise<string | undefined>;\n\nexport class IntentApiImpl implements IntentApi {\n readonly #baseUrl: string;\n\n readonly #fetchFn: FetchFunction;\n\n readonly #getJwt: GetJwtFn;\n\n constructor(baseUrl: string, fetchFn: FetchFunction, getJwt: GetJwtFn) {\n this.#baseUrl = baseUrl;\n this.#fetchFn = fetchFn;\n this.#getJwt = getJwt;\n }\n\n async getOrderStatus(\n orderId: string,\n aggregatorId: string,\n srcChainId: ChainId,\n clientId: BridgeClientId,\n ): Promise<IntentStatusResponse> {\n const endpoint = `${this.#baseUrl}/getOrderStatus?orderId=${orderId}&aggregatorId=${encodeURIComponent(aggregatorId)}&srcChainId=${srcChainId}`;\n try {\n const jwt = await this.#getJwt();\n const response = await this.#fetchFn(endpoint, {\n method: 'GET',\n headers: getClientHeaders({ clientId, jwt }),\n });\n if (!validateIntentStatusResponse(response)) {\n throw new Error('Invalid getOrderStatus response');\n }\n return response;\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(`Failed to get order status: ${error.message}`);\n }\n throw new Error('Failed to get order status');\n }\n }\n}\n\nexport type IntentBridgeStatus = {\n status: StatusResponse;\n txHash?: string;\n transactionStatus: TransactionStatus;\n};\n\nexport const translateIntentOrderToBridgeStatus = (\n intentOrder: IntentStatusResponse,\n srcChainId: number,\n fallbackTxHash?: string,\n): IntentBridgeStatus => {\n let statusType: StatusTypes;\n switch (intentOrder.status) {\n case IntentOrderStatus.CONFIRMED:\n case IntentOrderStatus.COMPLETED:\n statusType = StatusTypes.COMPLETE;\n break;\n case IntentOrderStatus.FAILED:\n case IntentOrderStatus.EXPIRED:\n case IntentOrderStatus.CANCELLED:\n statusType = StatusTypes.FAILED;\n break;\n case IntentOrderStatus.PENDING:\n statusType = StatusTypes.PENDING;\n break;\n case IntentOrderStatus.SUBMITTED:\n statusType = StatusTypes.SUBMITTED;\n break;\n default:\n statusType = StatusTypes.UNKNOWN;\n }\n\n const txHash = intentOrder.txHash ?? fallbackTxHash;\n const status: StatusResponse = {\n status: statusType,\n srcChain: {\n chainId: srcChainId,\n txHash,\n },\n };\n\n return {\n status,\n txHash,\n transactionStatus: mapIntentOrderStatusToTransactionStatus(\n intentOrder.status,\n ),\n };\n};\n\nexport function mapIntentOrderStatusToTransactionStatus(\n intentStatus: IntentOrderStatus,\n): TransactionStatus {\n switch (intentStatus) {\n case IntentOrderStatus.PENDING:\n case IntentOrderStatus.SUBMITTED:\n return TransactionStatus.submitted;\n case IntentOrderStatus.CONFIRMED:\n case IntentOrderStatus.COMPLETED:\n return TransactionStatus.confirmed;\n case IntentOrderStatus.FAILED:\n case IntentOrderStatus.EXPIRED:\n case IntentOrderStatus.CANCELLED:\n return TransactionStatus.failed;\n default:\n return TransactionStatus.submitted;\n }\n}\n\n/**\n * Extracts and validates the intent data from a quote response.\n *\n * @param quoteResponse - The quote response that may contain intent data\n * @returns The intent data from the quote\n * @throws Error if the quote does not contain intent data\n */\nexport function getIntentFromQuote(quoteResponse: QuoteResponse): Intent {\n const { intent } = quoteResponse.quote;\n if (!intent) {\n throw new Error('submitIntent: missing intent data');\n }\n return intent;\n}\n\nexport const postSubmitOrder = async ({\n params,\n clientId,\n jwt,\n fetchFn,\n bridgeApiBaseUrl,\n}: {\n params: IntentSubmissionParams;\n clientId: BridgeClientId;\n jwt: string | undefined;\n fetchFn: FetchFunction;\n bridgeApiBaseUrl: string;\n}): Promise<IntentStatusResponse> => {\n const endpoint = `${bridgeApiBaseUrl}/submitOrder`;\n try {\n const response = await fetchFn(endpoint, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...getClientHeaders({ clientId, jwt }),\n },\n body: JSON.stringify(params),\n });\n if (!validateIntentStatusResponse(response)) {\n throw new Error('Invalid submitOrder response');\n }\n return response;\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(`Failed to submit intent: ${error.message}`);\n }\n throw new Error('Failed to submit intent');\n }\n};\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signTypedMessage = void 0;
|
|
4
|
+
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
5
|
+
const signTypedMessage = async ({ messenger, accountAddress, typedData, }) => {
|
|
6
|
+
return await messenger.call('KeyringController:signTypedMessage', {
|
|
7
|
+
from: accountAddress,
|
|
8
|
+
data: typedData,
|
|
9
|
+
}, keyring_controller_1.SignTypedDataVersion.V4);
|
|
10
|
+
};
|
|
11
|
+
exports.signTypedMessage = signTypedMessage;
|
|
12
|
+
//# sourceMappingURL=keyring.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring.cjs","sourceRoot":"","sources":["../../src/utils/keyring.ts"],"names":[],"mappings":";;;AACA,qEAAoE;AAI7D,MAAM,gBAAgB,GAAG,KAAK,EAAE,EACrC,SAAS,EACT,cAAc,EACd,SAAS,GAKV,EAAmB,EAAE;IACpB,OAAO,MAAM,SAAS,CAAC,IAAI,CACzB,oCAAoC,EACpC;QACE,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,SAAS;KAChB,EACD,yCAAoB,CAAC,EAAE,CACxB,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,gBAAgB,oBAiB3B","sourcesContent":["import type { Intent } from '@metamask/bridge-controller';\nimport { SignTypedDataVersion } from '@metamask/keyring-controller';\n\nimport type { BridgeStatusControllerMessenger } from '../types';\n\nexport const signTypedMessage = async ({\n messenger,\n accountAddress,\n typedData,\n}: {\n messenger: BridgeStatusControllerMessenger;\n accountAddress: string;\n typedData: Intent['typedData'];\n}): Promise<string> => {\n return await messenger.call(\n 'KeyringController:signTypedMessage',\n {\n from: accountAddress,\n data: typedData,\n },\n SignTypedDataVersion.V4,\n );\n};\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Intent } from "@metamask/bridge-controller";
|
|
2
|
+
import type { BridgeStatusControllerMessenger } from "../types.cjs";
|
|
3
|
+
export declare const signTypedMessage: ({ messenger, accountAddress, typedData, }: {
|
|
4
|
+
messenger: BridgeStatusControllerMessenger;
|
|
5
|
+
accountAddress: string;
|
|
6
|
+
typedData: Intent['typedData'];
|
|
7
|
+
}) => Promise<string>;
|
|
8
|
+
//# sourceMappingURL=keyring.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring.d.cts","sourceRoot":"","sources":["../../src/utils/keyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,oCAAoC;AAG1D,OAAO,KAAK,EAAE,+BAA+B,EAAE,qBAAiB;AAEhE,eAAO,MAAM,gBAAgB;;oBAMX,MAAM;eACX,MAAM,CAAC,WAAW,CAAC;MAC5B,QAAQ,MAAM,CASjB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Intent } from "@metamask/bridge-controller";
|
|
2
|
+
import type { BridgeStatusControllerMessenger } from "../types.mjs";
|
|
3
|
+
export declare const signTypedMessage: ({ messenger, accountAddress, typedData, }: {
|
|
4
|
+
messenger: BridgeStatusControllerMessenger;
|
|
5
|
+
accountAddress: string;
|
|
6
|
+
typedData: Intent['typedData'];
|
|
7
|
+
}) => Promise<string>;
|
|
8
|
+
//# sourceMappingURL=keyring.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring.d.mts","sourceRoot":"","sources":["../../src/utils/keyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,oCAAoC;AAG1D,OAAO,KAAK,EAAE,+BAA+B,EAAE,qBAAiB;AAEhE,eAAO,MAAM,gBAAgB;;oBAMX,MAAM;eACX,MAAM,CAAC,WAAW,CAAC;MAC5B,QAAQ,MAAM,CASjB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SignTypedDataVersion } from "@metamask/keyring-controller";
|
|
2
|
+
export const signTypedMessage = async ({ messenger, accountAddress, typedData, }) => {
|
|
3
|
+
return await messenger.call('KeyringController:signTypedMessage', {
|
|
4
|
+
from: accountAddress,
|
|
5
|
+
data: typedData,
|
|
6
|
+
}, SignTypedDataVersion.V4);
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=keyring.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring.mjs","sourceRoot":"","sources":["../../src/utils/keyring.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,qCAAqC;AAIpE,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,EACrC,SAAS,EACT,cAAc,EACd,SAAS,GAKV,EAAmB,EAAE;IACpB,OAAO,MAAM,SAAS,CAAC,IAAI,CACzB,oCAAoC,EACpC;QACE,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,SAAS;KAChB,EACD,oBAAoB,CAAC,EAAE,CACxB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { Intent } from '@metamask/bridge-controller';\nimport { SignTypedDataVersion } from '@metamask/keyring-controller';\n\nimport type { BridgeStatusControllerMessenger } from '../types';\n\nexport const signTypedMessage = async ({\n messenger,\n accountAddress,\n typedData,\n}: {\n messenger: BridgeStatusControllerMessenger;\n accountAddress: string;\n typedData: Intent['typedData'];\n}): Promise<string> => {\n return await messenger.call(\n 'KeyringController:signTypedMessage',\n {\n from: accountAddress,\n data: typedData,\n },\n SignTypedDataVersion.V4,\n );\n};\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNetworkClientIdByChainId = exports.getSelectedChainId = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
5
|
+
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
6
|
+
const getSelectedChainId = (messenger) => {
|
|
7
|
+
const { selectedNetworkClientId } = messenger.call('NetworkController:getState');
|
|
8
|
+
const networkClient = messenger.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
|
|
9
|
+
return networkClient.configuration.chainId;
|
|
10
|
+
};
|
|
11
|
+
exports.getSelectedChainId = getSelectedChainId;
|
|
12
|
+
const getNetworkClientIdByChainId = (messenger, chainId) => {
|
|
13
|
+
const hexChainId = (0, bridge_controller_1.formatChainIdToHex)(chainId);
|
|
14
|
+
return messenger.call('NetworkController:findNetworkClientIdByChainId', hexChainId);
|
|
15
|
+
};
|
|
16
|
+
exports.getNetworkClientIdByChainId = getNetworkClientIdByChainId;
|
|
17
|
+
//# sourceMappingURL=network.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.cjs","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":";;;AAAA,qEAAqE;AACrE,mEAGqC;AAI9B,MAAM,kBAAkB,GAAG,CAChC,SAA0C,EAC1C,EAAE;IACF,MAAM,EAAE,uBAAuB,EAAE,GAAG,SAAS,CAAC,IAAI,CAChD,4BAA4B,CAC7B,CAAC;IACF,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAClC,wCAAwC,EACxC,uBAAuB,CACxB,CAAC;IACF,OAAO,aAAa,CAAC,aAAa,CAAC,OAAO,CAAC;AAC7C,CAAC,CAAC;AAXW,QAAA,kBAAkB,sBAW7B;AAEK,MAAM,2BAA2B,GAAG,CACzC,SAA0C,EAC1C,OAA0C,EAC1C,EAAE;IACF,MAAM,UAAU,GAAG,IAAA,sCAAkB,EAAC,OAAO,CAAC,CAAC;IAC/C,OAAO,SAAS,CAAC,IAAI,CACnB,gDAAgD,EAChD,UAAU,CACX,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,2BAA2B,+BAStC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport {\n formatChainIdToHex,\n GenericQuoteRequest,\n} from '@metamask/bridge-controller';\n\nimport { BridgeStatusControllerMessenger } from '../types';\n\nexport const getSelectedChainId = (\n messenger: BridgeStatusControllerMessenger,\n) => {\n const { selectedNetworkClientId } = messenger.call(\n 'NetworkController:getState',\n );\n const networkClient = messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n return networkClient.configuration.chainId;\n};\n\nexport const getNetworkClientIdByChainId = (\n messenger: BridgeStatusControllerMessenger,\n chainId: GenericQuoteRequest['srcChainId'],\n) => {\n const hexChainId = formatChainIdToHex(chainId);\n return messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n hexChainId,\n );\n};\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GenericQuoteRequest } from "@metamask/bridge-controller";
|
|
2
|
+
import { BridgeStatusControllerMessenger } from "../types.cjs";
|
|
3
|
+
export declare const getSelectedChainId: (messenger: BridgeStatusControllerMessenger) => `0x${string}`;
|
|
4
|
+
export declare const getNetworkClientIdByChainId: (messenger: BridgeStatusControllerMessenger, chainId: GenericQuoteRequest['srcChainId']) => string;
|
|
5
|
+
//# sourceMappingURL=network.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.d.cts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,mBAAmB,EACpB,oCAAoC;AAErC,OAAO,EAAE,+BAA+B,EAAE,qBAAiB;AAE3D,eAAO,MAAM,kBAAkB,+DAW9B,CAAC;AAEF,eAAO,MAAM,2BAA2B,wDAE7B,mBAAmB,CAAC,YAAY,CAAC,WAO3C,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GenericQuoteRequest } from "@metamask/bridge-controller";
|
|
2
|
+
import { BridgeStatusControllerMessenger } from "../types.mjs";
|
|
3
|
+
export declare const getSelectedChainId: (messenger: BridgeStatusControllerMessenger) => `0x${string}`;
|
|
4
|
+
export declare const getNetworkClientIdByChainId: (messenger: BridgeStatusControllerMessenger, chainId: GenericQuoteRequest['srcChainId']) => string;
|
|
5
|
+
//# sourceMappingURL=network.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.d.mts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,mBAAmB,EACpB,oCAAoC;AAErC,OAAO,EAAE,+BAA+B,EAAE,qBAAiB;AAE3D,eAAO,MAAM,kBAAkB,+DAW9B,CAAC;AAEF,eAAO,MAAM,2BAA2B,wDAE7B,mBAAmB,CAAC,YAAY,CAAC,WAO3C,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
2
|
+
import { formatChainIdToHex } from "@metamask/bridge-controller";
|
|
3
|
+
export const getSelectedChainId = (messenger) => {
|
|
4
|
+
const { selectedNetworkClientId } = messenger.call('NetworkController:getState');
|
|
5
|
+
const networkClient = messenger.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
|
|
6
|
+
return networkClient.configuration.chainId;
|
|
7
|
+
};
|
|
8
|
+
export const getNetworkClientIdByChainId = (messenger, chainId) => {
|
|
9
|
+
const hexChainId = formatChainIdToHex(chainId);
|
|
10
|
+
return messenger.call('NetworkController:findNetworkClientIdByChainId', hexChainId);
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=network.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.mjs","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EACL,kBAAkB,EAEnB,oCAAoC;AAIrC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,SAA0C,EAC1C,EAAE;IACF,MAAM,EAAE,uBAAuB,EAAE,GAAG,SAAS,CAAC,IAAI,CAChD,4BAA4B,CAC7B,CAAC;IACF,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAClC,wCAAwC,EACxC,uBAAuB,CACxB,CAAC;IACF,OAAO,aAAa,CAAC,aAAa,CAAC,OAAO,CAAC;AAC7C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,SAA0C,EAC1C,OAA0C,EAC1C,EAAE;IACF,MAAM,UAAU,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC/C,OAAO,SAAS,CAAC,IAAI,CACnB,gDAAgD,EAChD,UAAU,CACX,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport {\n formatChainIdToHex,\n GenericQuoteRequest,\n} from '@metamask/bridge-controller';\n\nimport { BridgeStatusControllerMessenger } from '../types';\n\nexport const getSelectedChainId = (\n messenger: BridgeStatusControllerMessenger,\n) => {\n const { selectedNetworkClientId } = messenger.call(\n 'NetworkController:getState',\n );\n const networkClient = messenger.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n return networkClient.configuration.chainId;\n};\n\nexport const getNetworkClientIdByChainId = (\n messenger: BridgeStatusControllerMessenger,\n chainId: GenericQuoteRequest['srcChainId'],\n) => {\n const hexChainId = formatChainIdToHex(chainId);\n return messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n hexChainId,\n );\n};\n"]}
|