@metamask/bridge-status-controller 69.0.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 +9 -1
- package/dist/bridge-status-controller.cjs +77 -192
- 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 +6 -7
- package/dist/bridge-status-controller.intent.cjs.map +1 -1
- package/dist/bridge-status-controller.intent.d.cts +2 -5
- package/dist/bridge-status-controller.intent.d.cts.map +1 -1
- package/dist/bridge-status-controller.intent.d.mts +2 -5
- package/dist/bridge-status-controller.intent.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.mjs +6 -7
- package/dist/bridge-status-controller.intent.mjs.map +1 -1
- package/dist/bridge-status-controller.mjs +79 -194
- 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.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 +3 -6
- 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 +3 -6
- 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 +16 -1
- package/dist/utils/intent-api.cjs.map +1 -1
- package/dist/utils/intent-api.d.cts +9 -1
- package/dist/utils/intent-api.d.cts.map +1 -1
- package/dist/utils/intent-api.d.mts +9 -1
- package/dist/utils/intent-api.d.mts.map +1 -1
- package/dist/utils/intent-api.mjs +14 -0
- 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 +12 -183
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +5 -78
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +5 -78
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +12 -177
- 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 +1 -1
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Intent, QuoteMetadata, QuoteResponse, Trade, TxData } from "@metamask/bridge-controller";
|
|
1
|
+
import type { QuoteMetadata, QuoteResponse, TxData } from "@metamask/bridge-controller";
|
|
3
2
|
import { TransactionType } from "@metamask/transaction-controller";
|
|
4
|
-
import type { BatchTransactionParams,
|
|
5
|
-
import type { BridgeStatusControllerMessenger
|
|
6
|
-
import type { BridgeStatusControllerState } from "../types.mjs";
|
|
3
|
+
import type { BatchTransactionParams, TransactionMeta } from "@metamask/transaction-controller";
|
|
4
|
+
import type { BridgeStatusControllerMessenger } from "../types.mjs";
|
|
7
5
|
export declare const generateActionId: () => string;
|
|
8
6
|
export declare const getStatusRequestParams: (quoteResponse: QuoteResponse) => {
|
|
9
7
|
bridgeId: string;
|
|
@@ -173,24 +171,6 @@ export declare const getStatusRequestParams: (quoteResponse: QuoteResponse) => {
|
|
|
173
171
|
};
|
|
174
172
|
refuel: boolean;
|
|
175
173
|
};
|
|
176
|
-
export declare const getTxMetaFields: (quoteResponse: Omit<QuoteResponse<Trade, Trade>, 'approval' | 'trade'> & QuoteMetadata, approvalTxId?: string) => Omit<TransactionMeta, 'networkClientId' | 'status' | 'time' | 'txParams' | 'id' | 'chainId'>;
|
|
177
|
-
/**
|
|
178
|
-
* Handles the response from non-EVM transaction submission
|
|
179
|
-
* Works with the new unified ClientRequest:signAndSendTransaction interface
|
|
180
|
-
* Supports Solana, Bitcoin, and other non-EVM chains
|
|
181
|
-
*
|
|
182
|
-
* @param snapResponse - The response from the snap after transaction submission
|
|
183
|
-
* @param quoteResponse - The quote response containing trade details and metadata
|
|
184
|
-
* @param selectedAccount - The selected account information
|
|
185
|
-
* @returns The transaction metadata including non-EVM specific fields
|
|
186
|
-
*/
|
|
187
|
-
export declare const handleNonEvmTxResponse: (snapResponse: string | {
|
|
188
|
-
transactionId: string;
|
|
189
|
-
} | {
|
|
190
|
-
result: Record<string, string>;
|
|
191
|
-
} | {
|
|
192
|
-
signature: string;
|
|
193
|
-
}, quoteResponse: Omit<QuoteResponse<Trade>, 'approval'> & QuoteMetadata, selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string]) => TransactionMeta & SolanaTransactionMeta;
|
|
194
174
|
export declare const handleApprovalDelay: (srcChainId: QuoteResponse['quote']['srcChainId']) => Promise<void>;
|
|
195
175
|
/**
|
|
196
176
|
* Adds a delay for hardware wallet transactions on mobile to fix an issue
|
|
@@ -200,50 +180,20 @@ export declare const handleApprovalDelay: (srcChainId: QuoteResponse['quote']['s
|
|
|
200
180
|
* @param requireApproval - Whether the delay should be applied
|
|
201
181
|
*/
|
|
202
182
|
export declare const handleMobileHardwareWalletDelay: (requireApproval: boolean) => Promise<void>;
|
|
203
|
-
/**
|
|
204
|
-
* Creates a request to sign and send a transaction for non-EVM chains
|
|
205
|
-
* Uses the new unified ClientRequest:signAndSendTransaction interface
|
|
206
|
-
*
|
|
207
|
-
* @param trade - The trade data
|
|
208
|
-
* @param srcChainId - The source chain ID
|
|
209
|
-
* @param selectedAccount - The selected account information
|
|
210
|
-
* @returns The snap request object for signing and sending transaction
|
|
211
|
-
*/
|
|
212
|
-
export declare const getClientRequest: (trade: Trade, srcChainId: number, selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string]) => {
|
|
213
|
-
snapId: never;
|
|
214
|
-
origin: string;
|
|
215
|
-
handler: never;
|
|
216
|
-
request: {
|
|
217
|
-
id: string;
|
|
218
|
-
jsonrpc: string;
|
|
219
|
-
method: string;
|
|
220
|
-
params: {
|
|
221
|
-
options?: Record<string, unknown> | undefined;
|
|
222
|
-
transaction: string;
|
|
223
|
-
scope: `${string}:${string}`;
|
|
224
|
-
accountId: string;
|
|
225
|
-
};
|
|
226
|
-
};
|
|
227
|
-
};
|
|
228
183
|
export declare const waitForTxConfirmation: (messenger: BridgeStatusControllerMessenger, txId: string, { timeoutMs, pollMs, }?: {
|
|
229
184
|
timeoutMs?: number | undefined;
|
|
230
185
|
pollMs?: number | undefined;
|
|
231
186
|
}) => Promise<TransactionMeta>;
|
|
232
|
-
export declare const rekeyHistoryItemInState: (state: BridgeStatusControllerState, actionId: string, txMeta: {
|
|
233
|
-
id: string;
|
|
234
|
-
hash?: string;
|
|
235
|
-
}) => boolean;
|
|
236
187
|
export declare const toBatchTxParams: (skipGasFields: boolean, { chainId, gasLimit, ...trade }: TxData, { maxFeePerGas, maxPriorityFeePerGas, gas, }: {
|
|
237
188
|
maxFeePerGas?: string | undefined;
|
|
238
189
|
maxPriorityFeePerGas?: string | undefined;
|
|
239
190
|
gas?: string | undefined;
|
|
240
191
|
}) => BatchTransactionParams;
|
|
241
|
-
export declare const getAddTransactionBatchParams: ({ messenger, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, gasSponsored, }, sentAmount, toTokenAmount, }, requireApproval, isDelegatedAccount,
|
|
192
|
+
export declare const getAddTransactionBatchParams: ({ messenger, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, gasSponsored, }, sentAmount, toTokenAmount, }, requireApproval, isDelegatedAccount, }: {
|
|
242
193
|
messenger: BridgeStatusControllerMessenger;
|
|
243
194
|
isBridgeTx: boolean;
|
|
244
195
|
trade: TxData;
|
|
245
196
|
quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> & Partial<QuoteMetadata>;
|
|
246
|
-
estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee;
|
|
247
197
|
approval?: {
|
|
248
198
|
chainId: number;
|
|
249
199
|
from: string;
|
|
@@ -265,9 +215,8 @@ export declare const getAddTransactionBatchParams: ({ messenger, isBridgeTx, app
|
|
|
265
215
|
requireApproval?: boolean | undefined;
|
|
266
216
|
isDelegatedAccount?: boolean | undefined;
|
|
267
217
|
}) => Promise<import("@metamask/transaction-controller").TransactionBatchRequest>;
|
|
268
|
-
export declare const findAndUpdateTransactionsInBatch: ({ messenger,
|
|
218
|
+
export declare const findAndUpdateTransactionsInBatch: ({ messenger, batchId, txDataByType, }: {
|
|
269
219
|
messenger: BridgeStatusControllerMessenger;
|
|
270
|
-
updateTransactionFn: typeof TransactionController.prototype.updateTransaction;
|
|
271
220
|
batchId: string;
|
|
272
221
|
txDataByType: {
|
|
273
222
|
batch?: string | undefined;
|
|
@@ -321,26 +270,4 @@ export declare const findAndUpdateTransactionsInBatch: ({ messenger, updateTrans
|
|
|
321
270
|
approvalMeta?: TransactionMeta | undefined;
|
|
322
271
|
tradeMeta?: TransactionMeta | undefined;
|
|
323
272
|
};
|
|
324
|
-
/**
|
|
325
|
-
* Determines the key to use for storing a bridge history item.
|
|
326
|
-
* Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.
|
|
327
|
-
*
|
|
328
|
-
* @param actionId - The action ID used for pre-submission tracking
|
|
329
|
-
* @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta
|
|
330
|
-
* @returns The key to use for the history item
|
|
331
|
-
* @throws Error if neither actionId nor bridgeTxMetaId is provided
|
|
332
|
-
*/
|
|
333
|
-
export declare function getHistoryKey(actionId: string | undefined, bridgeTxMetaId: string | undefined): string;
|
|
334
|
-
/**
|
|
335
|
-
* Extracts and validates the intent data from a quote response.
|
|
336
|
-
*
|
|
337
|
-
* @param quoteResponse - The quote response that may contain intent data
|
|
338
|
-
* @returns The intent data from the quote
|
|
339
|
-
* @throws Error if the quote does not contain intent data
|
|
340
|
-
*/
|
|
341
|
-
export declare function getIntentFromQuote(quoteResponse: QuoteResponse & {
|
|
342
|
-
quote: {
|
|
343
|
-
intent?: Intent;
|
|
344
|
-
};
|
|
345
|
-
}): Intent;
|
|
346
273
|
//# sourceMappingURL=transaction.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.mts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transaction.d.mts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,MAAM,EACP,oCAAoC;AAErC,OAAO,EAEL,eAAe,EAChB,yCAAyC;AAC1C,OAAO,KAAK,EACV,sBAAsB,EAEtB,eAAe,EAChB,yCAAyC;AAQ1C,OAAO,KAAK,EAAE,+BAA+B,EAAE,qBAAiB;AAEhE,eAAO,MAAM,gBAAgB,cAAgD,CAAC;AAE9E,eAAO,MAAM,sBAAsB,kBAAmB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CASlE,CAAC;AAEF,eAAO,MAAM,mBAAmB,eAClB,aAAa,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,kBAYjD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,+BAA+B,oBACzB,OAAO,kBAQzB,CAAC;AAEF,eAAO,MAAM,qBAAqB,qDAE1B,MAAM;;;MAKX,QAAQ,eAAe,CAyBzB,CAAC;AAEF,eAAO,MAAM,eAAe,kBACX,OAAO,mCACW,MAAM;;;;MAMtC,sBAiBF,CAAC;AAEF,eAAO,MAAM,4BAA4B;;gBAoB3B,OAAO;WACZ,MAAM;mBACE,KAAK,aAAa,EAAE,UAAU,GAAG,OAAO,CAAC,GACtD,QAAQ,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;iFAqFzB,CAAC;AAEF,eAAO,MAAM,gCAAgC;;aAMlC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2EhB,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
2
|
+
import { ChainId, formatChainIdToHex } from "@metamask/bridge-controller";
|
|
2
3
|
import { toHex } from "@metamask/controller-utils";
|
|
3
4
|
import { TransactionStatus, TransactionType } from "@metamask/transaction-controller";
|
|
4
5
|
import { createProjectLogger } from "@metamask/utils";
|
|
5
|
-
import {
|
|
6
|
+
import { getAccountByAddress } from "./accounts.mjs";
|
|
6
7
|
import { calculateGasFees } from "./gas.mjs";
|
|
7
|
-
import {
|
|
8
|
+
import { getNetworkClientIdByChainId } from "./network.mjs";
|
|
8
9
|
import { APPROVAL_DELAY_MS } from "../constants.mjs";
|
|
9
10
|
export const generateActionId = () => (Date.now() + Math.random()).toString();
|
|
10
11
|
export const getStatusRequestParams = (quoteResponse) => {
|
|
@@ -17,100 +18,6 @@ export const getStatusRequestParams = (quoteResponse) => {
|
|
|
17
18
|
refuel: Boolean(quoteResponse.quote.refuel),
|
|
18
19
|
};
|
|
19
20
|
};
|
|
20
|
-
export const getTxMetaFields = (quoteResponse, approvalTxId) => {
|
|
21
|
-
// Handle destination chain ID - should always be convertible for EVM destinations
|
|
22
|
-
let destinationChainId;
|
|
23
|
-
try {
|
|
24
|
-
destinationChainId = formatChainIdToHex(quoteResponse.quote.destChainId);
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
// Fallback for non-EVM destination (shouldn't happen for BTC->EVM)
|
|
28
|
-
destinationChainId = '0x1'; // Default to mainnet
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
destinationChainId,
|
|
32
|
-
sourceTokenAmount: quoteResponse.quote.srcTokenAmount,
|
|
33
|
-
sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,
|
|
34
|
-
sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,
|
|
35
|
-
sourceTokenAddress: quoteResponse.quote.srcAsset.address,
|
|
36
|
-
destinationTokenAmount: quoteResponse.quote.destTokenAmount,
|
|
37
|
-
destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,
|
|
38
|
-
destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,
|
|
39
|
-
destinationTokenAddress: quoteResponse.quote.destAsset.address,
|
|
40
|
-
// chainId is now excluded from this function and handled by the caller
|
|
41
|
-
approvalTxId,
|
|
42
|
-
// this is the decimal (non atomic) amount (not USD value) of source token to swap
|
|
43
|
-
swapTokenValue: quoteResponse.sentAmount.amount,
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Handles the response from non-EVM transaction submission
|
|
48
|
-
* Works with the new unified ClientRequest:signAndSendTransaction interface
|
|
49
|
-
* Supports Solana, Bitcoin, and other non-EVM chains
|
|
50
|
-
*
|
|
51
|
-
* @param snapResponse - The response from the snap after transaction submission
|
|
52
|
-
* @param quoteResponse - The quote response containing trade details and metadata
|
|
53
|
-
* @param selectedAccount - The selected account information
|
|
54
|
-
* @returns The transaction metadata including non-EVM specific fields
|
|
55
|
-
*/
|
|
56
|
-
export const handleNonEvmTxResponse = (snapResponse, quoteResponse, selectedAccount) => {
|
|
57
|
-
const selectedAccountAddress = selectedAccount.address;
|
|
58
|
-
const snapId = selectedAccount.metadata.snap?.id;
|
|
59
|
-
let hash;
|
|
60
|
-
// Handle different response formats
|
|
61
|
-
if (typeof snapResponse === 'string') {
|
|
62
|
-
hash = snapResponse;
|
|
63
|
-
}
|
|
64
|
-
else if (snapResponse && typeof snapResponse === 'object') {
|
|
65
|
-
// Check for new unified interface response format first
|
|
66
|
-
if ('transactionId' in snapResponse && snapResponse.transactionId) {
|
|
67
|
-
hash = snapResponse.transactionId;
|
|
68
|
-
}
|
|
69
|
-
else if ('result' in snapResponse &&
|
|
70
|
-
snapResponse.result &&
|
|
71
|
-
typeof snapResponse.result === 'object') {
|
|
72
|
-
// Try to extract signature from common locations in response object
|
|
73
|
-
hash =
|
|
74
|
-
snapResponse.result.signature ||
|
|
75
|
-
snapResponse.result.txid ||
|
|
76
|
-
snapResponse.result.hash ||
|
|
77
|
-
snapResponse.result.txHash;
|
|
78
|
-
}
|
|
79
|
-
else if ('signature' in snapResponse &&
|
|
80
|
-
snapResponse.signature &&
|
|
81
|
-
typeof snapResponse.signature === 'string') {
|
|
82
|
-
hash = snapResponse.signature;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const isBridgeTx = isCrossChain(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
86
|
-
let hexChainId;
|
|
87
|
-
try {
|
|
88
|
-
hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);
|
|
89
|
-
}
|
|
90
|
-
catch {
|
|
91
|
-
// TODO: Fix chain ID activity list handling for Bitcoin
|
|
92
|
-
// Fallback to Ethereum mainnet for now
|
|
93
|
-
hexChainId = '0x1';
|
|
94
|
-
}
|
|
95
|
-
// Extract the transaction data for storage
|
|
96
|
-
const tradeData = extractTradeData(quoteResponse.trade);
|
|
97
|
-
// Create a transaction meta object with bridge-specific fields
|
|
98
|
-
return {
|
|
99
|
-
...getTxMetaFields(quoteResponse),
|
|
100
|
-
time: Date.now(),
|
|
101
|
-
id: hash ?? uuid(),
|
|
102
|
-
chainId: hexChainId,
|
|
103
|
-
networkClientId: snapId ?? hexChainId,
|
|
104
|
-
txParams: { from: selectedAccountAddress, data: tradeData },
|
|
105
|
-
type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,
|
|
106
|
-
status: TransactionStatus.submitted,
|
|
107
|
-
hash, // Add the transaction signature as hash
|
|
108
|
-
origin: snapId,
|
|
109
|
-
// Add an explicit flag to mark this as a non-EVM transaction
|
|
110
|
-
isSolana: true, // TODO deprecate this and use chainId to detect non-EVM chains
|
|
111
|
-
isBridgeTx,
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
21
|
export const handleApprovalDelay = async (srcChainId) => {
|
|
115
22
|
if ([ChainId.LINEA, ChainId.BASE].includes(srcChainId)) {
|
|
116
23
|
const debugLog = createProjectLogger('bridge');
|
|
@@ -132,28 +39,6 @@ export const handleMobileHardwareWalletDelay = async (requireApproval) => {
|
|
|
132
39
|
await mobileHardwareWalletDelay;
|
|
133
40
|
}
|
|
134
41
|
};
|
|
135
|
-
/**
|
|
136
|
-
* Creates a request to sign and send a transaction for non-EVM chains
|
|
137
|
-
* Uses the new unified ClientRequest:signAndSendTransaction interface
|
|
138
|
-
*
|
|
139
|
-
* @param trade - The trade data
|
|
140
|
-
* @param srcChainId - The source chain ID
|
|
141
|
-
* @param selectedAccount - The selected account information
|
|
142
|
-
* @returns The snap request object for signing and sending transaction
|
|
143
|
-
*/
|
|
144
|
-
export const getClientRequest = (trade, srcChainId, selectedAccount) => {
|
|
145
|
-
const scope = formatChainIdToCaip(srcChainId);
|
|
146
|
-
const transactionData = extractTradeData(trade);
|
|
147
|
-
// Tron trades need the visible flag and contract type to be included in the request options
|
|
148
|
-
const options = isTronTrade(trade)
|
|
149
|
-
? {
|
|
150
|
-
visible: trade.visible,
|
|
151
|
-
type: trade.raw_data?.contract?.[0]?.type,
|
|
152
|
-
}
|
|
153
|
-
: undefined;
|
|
154
|
-
// Use the new unified interface
|
|
155
|
-
return createClientTransactionRequest(selectedAccount.metadata.snap?.id, transactionData, scope, selectedAccount.id, options);
|
|
156
|
-
};
|
|
157
42
|
export const waitForTxConfirmation = async (messenger, txId, { timeoutMs = 5 * 60000, pollMs = 3000, } = {}) => {
|
|
158
43
|
const start = Date.now();
|
|
159
44
|
while (true) {
|
|
@@ -175,26 +60,6 @@ export const waitForTxConfirmation = async (messenger, txId, { timeoutMs = 5 * 6
|
|
|
175
60
|
await new Promise((resolve) => setTimeout(resolve, pollMs));
|
|
176
61
|
}
|
|
177
62
|
};
|
|
178
|
-
export const rekeyHistoryItemInState = (state, actionId, txMeta) => {
|
|
179
|
-
const historyItem = state.txHistory[actionId];
|
|
180
|
-
if (!historyItem) {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
state.txHistory[txMeta.id] = {
|
|
184
|
-
...historyItem,
|
|
185
|
-
txMetaId: txMeta.id,
|
|
186
|
-
originalTransactionId: historyItem.originalTransactionId ?? txMeta.id,
|
|
187
|
-
status: {
|
|
188
|
-
...historyItem.status,
|
|
189
|
-
srcChain: {
|
|
190
|
-
...historyItem.status.srcChain,
|
|
191
|
-
txHash: txMeta.hash ?? historyItem.status.srcChain?.txHash,
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
delete state.txHistory[actionId];
|
|
196
|
-
return true;
|
|
197
|
-
};
|
|
198
63
|
export const toBatchTxParams = (skipGasFields, { chainId, gasLimit, ...trade }, { maxFeePerGas, maxPriorityFeePerGas, gas, }) => {
|
|
199
64
|
const params = {
|
|
200
65
|
...trade,
|
|
@@ -212,14 +77,14 @@ export const toBatchTxParams = (skipGasFields, { chainId, gasLimit, ...trade },
|
|
|
212
77
|
maxPriorityFeePerGas: toHex(maxPriorityFeePerGas ?? 0),
|
|
213
78
|
};
|
|
214
79
|
};
|
|
215
|
-
export const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, gasSponsored, }, sentAmount, toTokenAmount, }, requireApproval = false, isDelegatedAccount = false,
|
|
80
|
+
export const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, gasSponsored, }, sentAmount, toTokenAmount, }, requireApproval = false, isDelegatedAccount = false, }) => {
|
|
216
81
|
const isGasless = gasIncluded || gasIncluded7702;
|
|
217
|
-
const selectedAccount = messenger
|
|
82
|
+
const selectedAccount = getAccountByAddress(messenger, trade.from);
|
|
218
83
|
if (!selectedAccount) {
|
|
219
84
|
throw new Error('Failed to submit cross-chain swap batch transaction: unknown account in trade data');
|
|
220
85
|
}
|
|
221
86
|
const hexChainId = formatChainIdToHex(trade.chainId);
|
|
222
|
-
const networkClientId = messenger
|
|
87
|
+
const networkClientId = getNetworkClientIdByChainId(messenger, hexChainId);
|
|
223
88
|
// Gas fields should be omitted only when gas is sponsored via 7702
|
|
224
89
|
const skipGasFields = gasIncluded7702 === true;
|
|
225
90
|
// Enable 7702 batching when the quote includes gasless 7702 support,
|
|
@@ -228,7 +93,7 @@ export const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, appr
|
|
|
228
93
|
const disable7702 = !skipGasFields && !isDelegatedAccount;
|
|
229
94
|
const transactions = [];
|
|
230
95
|
if (resetApproval) {
|
|
231
|
-
const gasFees = await calculateGasFees(skipGasFields, messenger,
|
|
96
|
+
const gasFees = await calculateGasFees(skipGasFields, messenger, resetApproval, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
232
97
|
transactions.push({
|
|
233
98
|
type: isBridgeTx
|
|
234
99
|
? TransactionType.bridgeApproval
|
|
@@ -237,7 +102,7 @@ export const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, appr
|
|
|
237
102
|
});
|
|
238
103
|
}
|
|
239
104
|
if (approval) {
|
|
240
|
-
const gasFees = await calculateGasFees(skipGasFields, messenger,
|
|
105
|
+
const gasFees = await calculateGasFees(skipGasFields, messenger, approval, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
241
106
|
transactions.push({
|
|
242
107
|
type: isBridgeTx
|
|
243
108
|
? TransactionType.bridgeApproval
|
|
@@ -245,7 +110,7 @@ export const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, appr
|
|
|
245
110
|
params: toBatchTxParams(skipGasFields, approval, gasFees),
|
|
246
111
|
});
|
|
247
112
|
}
|
|
248
|
-
const gasFees = await calculateGasFees(skipGasFields, messenger,
|
|
113
|
+
const gasFees = await calculateGasFees(skipGasFields, messenger, trade, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
249
114
|
transactions.push({
|
|
250
115
|
type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,
|
|
251
116
|
params: toBatchTxParams(skipGasFields, trade, gasFees),
|
|
@@ -266,7 +131,7 @@ export const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, appr
|
|
|
266
131
|
};
|
|
267
132
|
return transactionParams;
|
|
268
133
|
};
|
|
269
|
-
export const findAndUpdateTransactionsInBatch = ({ messenger,
|
|
134
|
+
export const findAndUpdateTransactionsInBatch = ({ messenger, batchId, txDataByType, }) => {
|
|
270
135
|
const txs = messenger.call('TransactionController:getState').transactions;
|
|
271
136
|
const txBatch = {
|
|
272
137
|
approvalMeta: undefined,
|
|
@@ -309,7 +174,7 @@ export const findAndUpdateTransactionsInBatch = ({ messenger, updateTransactionF
|
|
|
309
174
|
});
|
|
310
175
|
if (txMeta) {
|
|
311
176
|
const updatedTx = { ...txMeta, type: txType };
|
|
312
|
-
|
|
177
|
+
messenger.call('TransactionController:updateTransaction', updatedTx, `Update tx type to ${txType}`);
|
|
313
178
|
txBatch[[TransactionType.bridgeApproval, TransactionType.swapApproval].includes(txType)
|
|
314
179
|
? 'approvalMeta'
|
|
315
180
|
: 'tradeMeta'] = updatedTx;
|
|
@@ -317,34 +182,4 @@ export const findAndUpdateTransactionsInBatch = ({ messenger, updateTransactionF
|
|
|
317
182
|
});
|
|
318
183
|
return txBatch;
|
|
319
184
|
};
|
|
320
|
-
/**
|
|
321
|
-
* Determines the key to use for storing a bridge history item.
|
|
322
|
-
* Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.
|
|
323
|
-
*
|
|
324
|
-
* @param actionId - The action ID used for pre-submission tracking
|
|
325
|
-
* @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta
|
|
326
|
-
* @returns The key to use for the history item
|
|
327
|
-
* @throws Error if neither actionId nor bridgeTxMetaId is provided
|
|
328
|
-
*/
|
|
329
|
-
export function getHistoryKey(actionId, bridgeTxMetaId) {
|
|
330
|
-
const historyKey = actionId ?? bridgeTxMetaId;
|
|
331
|
-
if (!historyKey) {
|
|
332
|
-
throw new Error('Cannot add tx to history: either actionId or bridgeTxMeta.id must be provided');
|
|
333
|
-
}
|
|
334
|
-
return historyKey;
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Extracts and validates the intent data from a quote response.
|
|
338
|
-
*
|
|
339
|
-
* @param quoteResponse - The quote response that may contain intent data
|
|
340
|
-
* @returns The intent data from the quote
|
|
341
|
-
* @throws Error if the quote does not contain intent data
|
|
342
|
-
*/
|
|
343
|
-
export function getIntentFromQuote(quoteResponse) {
|
|
344
|
-
const { intent } = quoteResponse.quote;
|
|
345
|
-
if (!intent) {
|
|
346
|
-
throw new Error('submitIntent: missing intent data');
|
|
347
|
-
}
|
|
348
|
-
return intent;
|
|
349
|
-
}
|
|
350
185
|
//# sourceMappingURL=transaction.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.mjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACb,oCAAoC;AAQrC,OAAO,EAAE,KAAK,EAAE,mCAAmC;AACnD,OAAO,EACL,iBAAiB,EACjB,eAAe,EAChB,yCAAyC;AAM1C,OAAO,EAAE,mBAAmB,EAAE,wBAAwB;AACtD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAElC,OAAO,EAAE,gBAAgB,EAAE,kBAAc;AACzC,OAAO,EAAE,8BAA8B,EAAE,oBAAgB;AAEzD,OAAO,EAAE,iBAAiB,EAAE,yBAAqB;AAOjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;AAE9E,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,aAA4B,EAAE,EAAE;IACrE,OAAO;QACL,QAAQ,EAAE,aAAa,CAAC,KAAK,CAAC,QAAQ;QACtC,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QACtC,UAAU,EAAE,aAAa,CAAC,KAAK,CAAC,UAAU;QAC1C,WAAW,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW;QAC5C,KAAK,EAAE,aAAa,CAAC,KAAK;QAC1B,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC;KAC5C,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM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CAAC,QAAQ,CACrE,MAAyB,CAC1B;gBACC,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,WAAW,CAChB,GAAG,SAAS,CAAC;QAChB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAC3B,QAA4B,EAC5B,cAAkC;IAElC,MAAM,UAAU,GAAG,QAAQ,IAAI,cAAc,CAAC;IAC9C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CACb,+EAA+E,CAChF,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,aAA6D;IAE7D,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC;IACvC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { AccountsControllerState } from '@metamask/accounts-controller';\nimport {\n ChainId,\n extractTradeData,\n isTronTrade,\n formatChainIdToCaip,\n formatChainIdToHex,\n isCrossChain,\n} from '@metamask/bridge-controller';\nimport type {\n Intent,\n QuoteMetadata,\n QuoteResponse,\n Trade,\n TxData,\n} from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport {\n TransactionStatus,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport type {\n BatchTransactionParams,\n TransactionController,\n TransactionMeta,\n} from '@metamask/transaction-controller';\nimport { createProjectLogger } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport { calculateGasFees } from './gas';\nimport { createClientTransactionRequest } from './snaps';\nimport type { TransactionBatchSingleRequest } from '../../../transaction-controller/src/types';\nimport { APPROVAL_DELAY_MS } from '../constants';\nimport type {\n BridgeStatusControllerMessenger,\n SolanaTransactionMeta,\n} from '../types';\nimport type { BridgeStatusControllerState } from '../types';\n\nexport const generateActionId = () => (Date.now() + Math.random()).toString();\n\nexport const getStatusRequestParams = (quoteResponse: QuoteResponse) => {\n return {\n bridgeId: quoteResponse.quote.bridgeId,\n bridge: quoteResponse.quote.bridges[0],\n srcChainId: quoteResponse.quote.srcChainId,\n destChainId: quoteResponse.quote.destChainId,\n quote: quoteResponse.quote,\n refuel: Boolean(quoteResponse.quote.refuel),\n };\n};\n\nexport const getTxMetaFields = (\n quoteResponse: Omit<QuoteResponse<Trade, Trade>, 'approval' | 'trade'> &\n QuoteMetadata,\n approvalTxId?: string,\n): Omit<\n TransactionMeta,\n 'networkClientId' | 'status' | 'time' | 'txParams' | 'id' | 'chainId'\n> => {\n // Handle destination chain ID - should always be convertible for EVM destinations\n let destinationChainId;\n try {\n destinationChainId = formatChainIdToHex(quoteResponse.quote.destChainId);\n } catch {\n // Fallback for non-EVM destination (shouldn't happen for BTC->EVM)\n destinationChainId = '0x1' as `0x${string}`; // Default to mainnet\n }\n\n return {\n destinationChainId,\n sourceTokenAmount: quoteResponse.quote.srcTokenAmount,\n sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,\n sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,\n sourceTokenAddress: quoteResponse.quote.srcAsset.address,\n\n destinationTokenAmount: quoteResponse.quote.destTokenAmount,\n destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,\n destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,\n destinationTokenAddress: quoteResponse.quote.destAsset.address,\n\n // chainId is now excluded from this function and handled by the caller\n approvalTxId,\n // this is the decimal (non atomic) amount (not USD value) of source token to swap\n swapTokenValue: quoteResponse.sentAmount.amount,\n };\n};\n\n/**\n * Handles the response from non-EVM transaction submission\n * Works with the new unified ClientRequest:signAndSendTransaction interface\n * Supports Solana, Bitcoin, and other non-EVM chains\n *\n * @param snapResponse - The response from the snap after transaction submission\n * @param quoteResponse - The quote response containing trade details and metadata\n * @param selectedAccount - The selected account information\n * @returns The transaction metadata including non-EVM specific fields\n */\nexport const handleNonEvmTxResponse = (\n snapResponse:\n | string\n | { transactionId: string } // New unified interface response\n | { result: Record<string, string> }\n | { signature: string },\n quoteResponse: Omit<QuoteResponse<Trade>, 'approval'> & QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n): TransactionMeta & SolanaTransactionMeta => {\n const selectedAccountAddress = selectedAccount.address;\n const snapId = selectedAccount.metadata.snap?.id;\n let hash;\n // Handle different response formats\n if (typeof snapResponse === 'string') {\n hash = snapResponse;\n } else if (snapResponse && typeof snapResponse === 'object') {\n // Check for new unified interface response format first\n if ('transactionId' in snapResponse && snapResponse.transactionId) {\n hash = snapResponse.transactionId;\n } else if (\n 'result' in snapResponse &&\n snapResponse.result &&\n typeof snapResponse.result === 'object'\n ) {\n // Try to extract signature from common locations in response object\n hash =\n snapResponse.result.signature ||\n snapResponse.result.txid ||\n snapResponse.result.hash ||\n snapResponse.result.txHash;\n } else if (\n 'signature' in snapResponse &&\n snapResponse.signature &&\n typeof snapResponse.signature === 'string'\n ) {\n hash = snapResponse.signature;\n }\n }\n\n const isBridgeTx = isCrossChain(\n quoteResponse.quote.srcChainId,\n quoteResponse.quote.destChainId,\n );\n\n let hexChainId;\n try {\n hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n } catch {\n // TODO: Fix chain ID activity list handling for Bitcoin\n // Fallback to Ethereum mainnet for now\n hexChainId = '0x1' as `0x${string}`;\n }\n\n // Extract the transaction data for storage\n const tradeData = extractTradeData(quoteResponse.trade);\n\n // Create a transaction meta object with bridge-specific fields\n return {\n ...getTxMetaFields(quoteResponse),\n time: Date.now(),\n id: hash ?? uuid(),\n chainId: hexChainId,\n networkClientId: snapId ?? hexChainId,\n txParams: { from: selectedAccountAddress, data: tradeData },\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n status: TransactionStatus.submitted,\n hash, // Add the transaction signature as hash\n origin: snapId,\n // Add an explicit flag to mark this as a non-EVM transaction\n isSolana: true, // TODO deprecate this and use chainId to detect non-EVM chains\n isBridgeTx,\n };\n};\n\nexport const handleApprovalDelay = async (\n srcChainId: QuoteResponse['quote']['srcChainId'],\n) => {\n if ([ChainId.LINEA, ChainId.BASE].includes(srcChainId)) {\n const debugLog = createProjectLogger('bridge');\n debugLog(\n 'Delaying submitting bridge tx to make Linea and Base confirmation more likely',\n );\n const waitPromise = new Promise((resolve) =>\n setTimeout(resolve, APPROVAL_DELAY_MS),\n );\n await waitPromise;\n }\n};\n\n/**\n * Adds a delay for hardware wallet transactions on mobile to fix an issue\n * where the Ledger does not get prompted for the 2nd approval.\n * Extension does not have this issue.\n *\n * @param requireApproval - Whether the delay should be applied\n */\nexport const handleMobileHardwareWalletDelay = async (\n requireApproval: boolean,\n) => {\n if (requireApproval) {\n const mobileHardwareWalletDelay = new Promise((resolve) =>\n setTimeout(resolve, 1000),\n );\n await mobileHardwareWalletDelay;\n }\n};\n\n/**\n * Creates a request to sign and send a transaction for non-EVM chains\n * Uses the new unified ClientRequest:signAndSendTransaction interface\n *\n * @param trade - The trade data\n * @param srcChainId - The source chain ID\n * @param selectedAccount - The selected account information\n * @returns The snap request object for signing and sending transaction\n */\nexport const getClientRequest = (\n trade: Trade,\n srcChainId: number,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n) => {\n const scope = formatChainIdToCaip(srcChainId);\n\n const transactionData = extractTradeData(trade);\n\n // Tron trades need the visible flag and contract type to be included in the request options\n const options = isTronTrade(trade)\n ? {\n visible: trade.visible,\n type: trade.raw_data?.contract?.[0]?.type,\n }\n : undefined;\n\n // Use the new unified interface\n return createClientTransactionRequest(\n selectedAccount.metadata.snap?.id as string,\n transactionData,\n scope,\n selectedAccount.id,\n options,\n );\n};\n\nexport const waitForTxConfirmation = async (\n messenger: BridgeStatusControllerMessenger,\n txId: string,\n {\n timeoutMs = 5 * 60_000,\n pollMs = 3_000,\n }: { timeoutMs?: number; pollMs?: number } = {},\n): Promise<TransactionMeta> => {\n const start = Date.now();\n while (true) {\n const { transactions } = messenger.call('TransactionController:getState');\n const meta = transactions.find((tx: TransactionMeta) => tx.id === txId);\n\n if (meta) {\n if (meta.status === TransactionStatus.confirmed) {\n return meta;\n }\n if (\n meta.status === TransactionStatus.failed ||\n meta.status === TransactionStatus.dropped ||\n meta.status === TransactionStatus.rejected\n ) {\n throw new Error('Approval transaction did not confirm');\n }\n }\n\n if (Date.now() - start > timeoutMs) {\n throw new Error('Timed out waiting for approval confirmation');\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollMs));\n }\n};\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\nexport const toBatchTxParams = (\n skipGasFields: boolean,\n { chainId, gasLimit, ...trade }: TxData,\n {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas,\n }: { maxFeePerGas?: string; maxPriorityFeePerGas?: string; gas?: string },\n): BatchTransactionParams => {\n const params = {\n ...trade,\n data: trade.data as `0x${string}`,\n to: trade.to as `0x${string}`,\n value: trade.value as `0x${string}`,\n };\n if (skipGasFields) {\n return params;\n }\n\n return {\n ...params,\n gas: toHex(gas ?? 0),\n maxFeePerGas: toHex(maxFeePerGas ?? 0),\n maxPriorityFeePerGas: toHex(maxPriorityFeePerGas ?? 0),\n };\n};\n\nexport const getAddTransactionBatchParams = async ({\n messenger,\n isBridgeTx,\n approval,\n resetApproval,\n trade,\n quoteResponse: {\n quote: {\n feeData: { txFee },\n gasIncluded,\n gasIncluded7702,\n gasSponsored,\n },\n sentAmount,\n toTokenAmount,\n },\n requireApproval = false,\n isDelegatedAccount = false,\n estimateGasFeeFn,\n}: {\n messenger: BridgeStatusControllerMessenger;\n isBridgeTx: boolean;\n trade: TxData;\n quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> &\n Partial<QuoteMetadata>;\n estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee;\n approval?: TxData;\n resetApproval?: TxData;\n requireApproval?: boolean;\n isDelegatedAccount?: boolean;\n}) => {\n const isGasless = gasIncluded || gasIncluded7702;\n const selectedAccount = messenger.call(\n 'AccountsController:getAccountByAddress',\n trade.from,\n );\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap batch transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n hexChainId,\n );\n\n // Gas fields should be omitted only when gas is sponsored via 7702\n const skipGasFields = gasIncluded7702 === true;\n // Enable 7702 batching when the quote includes gasless 7702 support,\n // or when the account is already delegated (to avoid the in-flight\n // transaction limit for delegated accounts)\n const disable7702 = !skipGasFields && !isDelegatedAccount;\n const transactions: TransactionBatchSingleRequest[] = [];\n if (resetApproval) {\n const gasFees = await calculateGasFees(\n skipGasFields,\n messenger,\n estimateGasFeeFn,\n resetApproval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(skipGasFields, resetApproval, gasFees),\n });\n }\n if (approval) {\n const gasFees = await calculateGasFees(\n skipGasFields,\n messenger,\n estimateGasFeeFn,\n approval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(skipGasFields, approval, gasFees),\n });\n }\n const gasFees = await calculateGasFees(\n skipGasFields,\n messenger,\n estimateGasFeeFn,\n trade,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n params: toBatchTxParams(skipGasFields, trade, gasFees),\n assetsFiatValues: {\n sending: sentAmount?.valueInCurrency?.toString(),\n receiving: toTokenAmount?.valueInCurrency?.toString(),\n },\n });\n const transactionParams: Parameters<\n TransactionController['addTransactionBatch']\n >[0] = {\n disable7702,\n isGasFeeIncluded: Boolean(gasIncluded7702),\n isGasFeeSponsored: Boolean(gasSponsored),\n networkClientId,\n requireApproval,\n origin: 'metamask',\n from: trade.from as `0x${string}`,\n transactions,\n };\n\n return transactionParams;\n};\n\nexport const findAndUpdateTransactionsInBatch = ({\n messenger,\n updateTransactionFn,\n batchId,\n txDataByType,\n}: {\n messenger: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n batchId: string;\n txDataByType: { [key in TransactionType]?: string };\n}) => {\n const txs = messenger.call('TransactionController:getState').transactions;\n const txBatch: {\n approvalMeta?: TransactionMeta;\n tradeMeta?: TransactionMeta;\n } = {\n approvalMeta: undefined,\n tradeMeta: undefined,\n };\n\n // This is a workaround to update the tx type after the tx is signed\n // TODO: remove this once the tx type for batch txs is preserved in the tx controller\n Object.entries(txDataByType).forEach(([txType, txData]) => {\n // Skip types not present in the batch (e.g. swap entry is undefined for bridge txs)\n if (txData === undefined) {\n return;\n }\n\n // Find transaction by batchId and either matching data or delegation characteristics\n const txMeta = txs.find((tx) => {\n if (tx.batchId !== batchId) {\n return false;\n }\n\n // For 7702 delegated transactions, check for delegation-specific fields\n // These transactions might have authorizationList or delegationAddress\n const is7702Transaction =\n (Array.isArray(tx.txParams.authorizationList) &&\n tx.txParams.authorizationList.length > 0) ||\n Boolean(tx.delegationAddress);\n\n if (is7702Transaction) {\n // For 7702 transactions, we need to match based on transaction type\n // since the data field might be different (batch execute call)\n if (\n (txType === TransactionType.swap ||\n txType === TransactionType.bridge) &&\n tx.type === TransactionType.batch\n ) {\n return true;\n }\n // Also check if it's an approval transaction for 7702\n if (\n (txType === TransactionType.swapApproval ||\n txType === TransactionType.bridgeApproval) &&\n tx.txParams.data === txData\n ) {\n return true;\n }\n }\n\n // Default matching logic for non-7702 transactions\n return tx.txParams.data === txData;\n });\n\n if (txMeta) {\n const updatedTx = { ...txMeta, type: txType as TransactionType };\n updateTransactionFn(updatedTx, `Update tx type to ${txType}`);\n txBatch[\n [TransactionType.bridgeApproval, TransactionType.swapApproval].includes(\n txType as TransactionType,\n )\n ? 'approvalMeta'\n : 'tradeMeta'\n ] = updatedTx;\n }\n });\n\n return txBatch;\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 * @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): string {\n const historyKey = actionId ?? bridgeTxMetaId;\n if (!historyKey) {\n throw new Error(\n 'Cannot add tx to history: either actionId or bridgeTxMeta.id must be provided',\n );\n }\n return historyKey;\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(\n quoteResponse: QuoteResponse & { quote: { intent?: Intent } },\n): Intent {\n const { intent } = quoteResponse.quote;\n if (!intent) {\n throw new Error('submitIntent: missing intent data');\n }\n return intent;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"transaction.mjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,oCAAoC;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AAM,EAAE,IAAI,EAAE,MAAyB,EAAE,CAAC;YACjE,SAAS,CAAC,IAAI,CACZ,yCAAyC,EACzC,SAAS,EACT,qBAAqB,MAAM,EAAE,CAC9B,CAAC;YACF,OAAO,CACL,CAAC,eAAe,CAAC,cAAc,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC,QAAQ,CACrE,MAAyB,CAC1B;gBACC,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,WAAW,CAChB,GAAG,SAAS,CAAC;QAChB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport { ChainId, formatChainIdToHex } from '@metamask/bridge-controller';\nimport type {\n QuoteMetadata,\n QuoteResponse,\n TxData,\n} from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport {\n TransactionStatus,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport type {\n BatchTransactionParams,\n TransactionController,\n TransactionMeta,\n} from '@metamask/transaction-controller';\nimport type { TransactionBatchSingleRequest } from '@metamask/transaction-controller';\nimport { createProjectLogger } from '@metamask/utils';\n\nimport { getAccountByAddress } from './accounts';\nimport { calculateGasFees } from './gas';\nimport { getNetworkClientIdByChainId } from './network';\nimport { APPROVAL_DELAY_MS } from '../constants';\nimport type { BridgeStatusControllerMessenger } from '../types';\n\nexport const generateActionId = () => (Date.now() + Math.random()).toString();\n\nexport const getStatusRequestParams = (quoteResponse: QuoteResponse) => {\n return {\n bridgeId: quoteResponse.quote.bridgeId,\n bridge: quoteResponse.quote.bridges[0],\n srcChainId: quoteResponse.quote.srcChainId,\n destChainId: quoteResponse.quote.destChainId,\n quote: quoteResponse.quote,\n refuel: Boolean(quoteResponse.quote.refuel),\n };\n};\n\nexport const handleApprovalDelay = async (\n srcChainId: QuoteResponse['quote']['srcChainId'],\n) => {\n if ([ChainId.LINEA, ChainId.BASE].includes(srcChainId)) {\n const debugLog = createProjectLogger('bridge');\n debugLog(\n 'Delaying submitting bridge tx to make Linea and Base confirmation more likely',\n );\n const waitPromise = new Promise((resolve) =>\n setTimeout(resolve, APPROVAL_DELAY_MS),\n );\n await waitPromise;\n }\n};\n\n/**\n * Adds a delay for hardware wallet transactions on mobile to fix an issue\n * where the Ledger does not get prompted for the 2nd approval.\n * Extension does not have this issue.\n *\n * @param requireApproval - Whether the delay should be applied\n */\nexport const handleMobileHardwareWalletDelay = async (\n requireApproval: boolean,\n) => {\n if (requireApproval) {\n const mobileHardwareWalletDelay = new Promise((resolve) =>\n setTimeout(resolve, 1000),\n );\n await mobileHardwareWalletDelay;\n }\n};\n\nexport const waitForTxConfirmation = async (\n messenger: BridgeStatusControllerMessenger,\n txId: string,\n {\n timeoutMs = 5 * 60_000,\n pollMs = 3_000,\n }: { timeoutMs?: number; pollMs?: number } = {},\n): Promise<TransactionMeta> => {\n const start = Date.now();\n while (true) {\n const { transactions } = messenger.call('TransactionController:getState');\n const meta = transactions.find((tx: TransactionMeta) => tx.id === txId);\n\n if (meta) {\n if (meta.status === TransactionStatus.confirmed) {\n return meta;\n }\n if (\n meta.status === TransactionStatus.failed ||\n meta.status === TransactionStatus.dropped ||\n meta.status === TransactionStatus.rejected\n ) {\n throw new Error('Approval transaction did not confirm');\n }\n }\n\n if (Date.now() - start > timeoutMs) {\n throw new Error('Timed out waiting for approval confirmation');\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollMs));\n }\n};\n\nexport const toBatchTxParams = (\n skipGasFields: boolean,\n { chainId, gasLimit, ...trade }: TxData,\n {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas,\n }: { maxFeePerGas?: string; maxPriorityFeePerGas?: string; gas?: string },\n): BatchTransactionParams => {\n const params = {\n ...trade,\n data: trade.data as `0x${string}`,\n to: trade.to as `0x${string}`,\n value: trade.value as `0x${string}`,\n };\n if (skipGasFields) {\n return params;\n }\n\n return {\n ...params,\n gas: toHex(gas ?? 0),\n maxFeePerGas: toHex(maxFeePerGas ?? 0),\n maxPriorityFeePerGas: toHex(maxPriorityFeePerGas ?? 0),\n };\n};\n\nexport const getAddTransactionBatchParams = async ({\n messenger,\n isBridgeTx,\n approval,\n resetApproval,\n trade,\n quoteResponse: {\n quote: {\n feeData: { txFee },\n gasIncluded,\n gasIncluded7702,\n gasSponsored,\n },\n sentAmount,\n toTokenAmount,\n },\n requireApproval = false,\n isDelegatedAccount = false,\n}: {\n messenger: BridgeStatusControllerMessenger;\n isBridgeTx: boolean;\n trade: TxData;\n quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> &\n Partial<QuoteMetadata>;\n approval?: TxData;\n resetApproval?: TxData;\n requireApproval?: boolean;\n isDelegatedAccount?: boolean;\n}) => {\n const isGasless = gasIncluded || gasIncluded7702;\n const selectedAccount = getAccountByAddress(messenger, trade.from);\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap batch transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = getNetworkClientIdByChainId(messenger, hexChainId);\n\n // Gas fields should be omitted only when gas is sponsored via 7702\n const skipGasFields = gasIncluded7702 === true;\n // Enable 7702 batching when the quote includes gasless 7702 support,\n // or when the account is already delegated (to avoid the in-flight\n // transaction limit for delegated accounts)\n const disable7702 = !skipGasFields && !isDelegatedAccount;\n const transactions: TransactionBatchSingleRequest[] = [];\n if (resetApproval) {\n const gasFees = await calculateGasFees(\n skipGasFields,\n messenger,\n resetApproval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(skipGasFields, resetApproval, gasFees),\n });\n }\n if (approval) {\n const gasFees = await calculateGasFees(\n skipGasFields,\n messenger,\n approval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(skipGasFields, approval, gasFees),\n });\n }\n const gasFees = await calculateGasFees(\n skipGasFields,\n messenger,\n trade,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n params: toBatchTxParams(skipGasFields, trade, gasFees),\n assetsFiatValues: {\n sending: sentAmount?.valueInCurrency?.toString(),\n receiving: toTokenAmount?.valueInCurrency?.toString(),\n },\n });\n const transactionParams: Parameters<\n TransactionController['addTransactionBatch']\n >[0] = {\n disable7702,\n isGasFeeIncluded: Boolean(gasIncluded7702),\n isGasFeeSponsored: Boolean(gasSponsored),\n networkClientId,\n requireApproval,\n origin: 'metamask',\n from: trade.from as `0x${string}`,\n transactions,\n };\n\n return transactionParams;\n};\n\nexport const findAndUpdateTransactionsInBatch = ({\n messenger,\n batchId,\n txDataByType,\n}: {\n messenger: BridgeStatusControllerMessenger;\n batchId: string;\n txDataByType: { [key in TransactionType]?: string };\n}) => {\n const txs = messenger.call('TransactionController:getState').transactions;\n const txBatch: {\n approvalMeta?: TransactionMeta;\n tradeMeta?: TransactionMeta;\n } = {\n approvalMeta: undefined,\n tradeMeta: undefined,\n };\n\n // This is a workaround to update the tx type after the tx is signed\n // TODO: remove this once the tx type for batch txs is preserved in the tx controller\n Object.entries(txDataByType).forEach(([txType, txData]) => {\n // Skip types not present in the batch (e.g. swap entry is undefined for bridge txs)\n if (txData === undefined) {\n return;\n }\n\n // Find transaction by batchId and either matching data or delegation characteristics\n const txMeta = txs.find((tx: TransactionMeta) => {\n if (tx.batchId !== batchId) {\n return false;\n }\n\n // For 7702 delegated transactions, check for delegation-specific fields\n // These transactions might have authorizationList or delegationAddress\n const is7702Transaction =\n (Array.isArray(tx.txParams.authorizationList) &&\n tx.txParams.authorizationList.length > 0) ||\n Boolean(tx.delegationAddress);\n\n if (is7702Transaction) {\n // For 7702 transactions, we need to match based on transaction type\n // since the data field might be different (batch execute call)\n if (\n (txType === TransactionType.swap ||\n txType === TransactionType.bridge) &&\n tx.type === TransactionType.batch\n ) {\n return true;\n }\n // Also check if it's an approval transaction for 7702\n if (\n (txType === TransactionType.swapApproval ||\n txType === TransactionType.bridgeApproval) &&\n tx.txParams.data === txData\n ) {\n return true;\n }\n }\n\n // Default matching logic for non-7702 transactions\n return tx.txParams.data === txData;\n });\n\n if (txMeta) {\n const updatedTx = { ...txMeta, type: txType as TransactionType };\n messenger.call(\n 'TransactionController:updateTransaction',\n updatedTx,\n `Update tx type to ${txType}`,\n );\n txBatch[\n [TransactionType.bridgeApproval, TransactionType.swapApproval].includes(\n txType as TransactionType,\n )\n ? 'approvalMeta'\n : 'tradeMeta'\n ] = updatedTx;\n }\n });\n\n return txBatch;\n};\n"]}
|
|
@@ -164,8 +164,8 @@ export declare enum IntentOrderStatus {
|
|
|
164
164
|
EXPIRED = "expired"
|
|
165
165
|
}
|
|
166
166
|
declare const IntentStatusResponseSchema: import("@metamask/superstruct").Struct<{
|
|
167
|
-
status: IntentOrderStatus;
|
|
168
167
|
id: string;
|
|
168
|
+
status: IntentOrderStatus;
|
|
169
169
|
metadata: {
|
|
170
170
|
txHashes?: string | string[] | undefined;
|
|
171
171
|
};
|
|
@@ -190,8 +190,8 @@ declare const IntentStatusResponseSchema: import("@metamask/superstruct").Struct
|
|
|
190
190
|
}>;
|
|
191
191
|
export type IntentStatusResponse = Infer<typeof IntentStatusResponseSchema>;
|
|
192
192
|
export declare const validateIntentStatusResponse: (data: unknown) => data is {
|
|
193
|
-
status: IntentOrderStatus;
|
|
194
193
|
id: string;
|
|
194
|
+
status: IntentOrderStatus;
|
|
195
195
|
metadata: {
|
|
196
196
|
txHashes?: string | string[] | undefined;
|
|
197
197
|
};
|
|
@@ -164,8 +164,8 @@ export declare enum IntentOrderStatus {
|
|
|
164
164
|
EXPIRED = "expired"
|
|
165
165
|
}
|
|
166
166
|
declare const IntentStatusResponseSchema: import("@metamask/superstruct").Struct<{
|
|
167
|
-
status: IntentOrderStatus;
|
|
168
167
|
id: string;
|
|
168
|
+
status: IntentOrderStatus;
|
|
169
169
|
metadata: {
|
|
170
170
|
txHashes?: string | string[] | undefined;
|
|
171
171
|
};
|
|
@@ -190,8 +190,8 @@ declare const IntentStatusResponseSchema: import("@metamask/superstruct").Struct
|
|
|
190
190
|
}>;
|
|
191
191
|
export type IntentStatusResponse = Infer<typeof IntentStatusResponseSchema>;
|
|
192
192
|
export declare const validateIntentStatusResponse: (data: unknown) => data is {
|
|
193
|
-
status: IntentOrderStatus;
|
|
194
193
|
id: string;
|
|
194
|
+
status: IntentOrderStatus;
|
|
195
195
|
metadata: {
|
|
196
196
|
txHashes?: string | string[] | undefined;
|
|
197
197
|
};
|