@metamask-previews/transaction-pay-controller 22.4.0-preview-6d2aeda → 22.4.0-preview-fe92f4bb3
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 +5 -0
- package/dist/strategy/across/across-quotes.cjs +1 -13
- package/dist/strategy/across/across-quotes.cjs.map +1 -1
- package/dist/strategy/across/across-quotes.d.cts.map +1 -1
- package/dist/strategy/across/across-quotes.d.mts.map +1 -1
- package/dist/strategy/across/across-quotes.mjs +1 -13
- package/dist/strategy/across/across-quotes.mjs.map +1 -1
- package/dist/strategy/across/across-submit.cjs +217 -18
- package/dist/strategy/across/across-submit.cjs.map +1 -1
- package/dist/strategy/across/across-submit.d.cts.map +1 -1
- package/dist/strategy/across/across-submit.d.mts.map +1 -1
- package/dist/strategy/across/across-submit.mjs +219 -20
- package/dist/strategy/across/across-submit.mjs.map +1 -1
- package/dist/strategy/across/transactions.cjs +21 -1
- package/dist/strategy/across/transactions.cjs.map +1 -1
- package/dist/strategy/across/transactions.d.cts +8 -0
- package/dist/strategy/across/transactions.d.cts.map +1 -1
- package/dist/strategy/across/transactions.d.mts +8 -0
- package/dist/strategy/across/transactions.d.mts.map +1 -1
- package/dist/strategy/across/transactions.mjs +19 -0
- package/dist/strategy/across/transactions.mjs.map +1 -1
- package/dist/utils/feature-flags.cjs +1 -1
- package/dist/utils/feature-flags.cjs.map +1 -1
- package/dist/utils/feature-flags.d.cts +1 -1
- package/dist/utils/feature-flags.d.cts.map +1 -1
- package/dist/utils/feature-flags.d.mts +1 -1
- package/dist/utils/feature-flags.d.mts.map +1 -1
- package/dist/utils/feature-flags.mjs +1 -1
- package/dist/utils/feature-flags.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -2,9 +2,11 @@ import { ORIGIN_METAMASK, successfulFetch, toHex } from "@metamask/controller-ut
|
|
|
2
2
|
import { TransactionType } from "@metamask/transaction-controller";
|
|
3
3
|
import { createModuleLogger } from "@metamask/utils";
|
|
4
4
|
import { projectLogger } from "../../logger.mjs";
|
|
5
|
+
import { accountSupports7702 } from "../../utils/7702.mjs";
|
|
5
6
|
import { getPayStrategiesConfig } from "../../utils/feature-flags.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
7
|
+
import { getGasBuffer } from "../../utils/feature-flags.mjs";
|
|
8
|
+
import { collectTransactionIds, getTransaction, updateTransaction, isPredictWithdrawTransaction, waitForTransactionConfirmed } from "../../utils/transaction.mjs";
|
|
9
|
+
import { getAcrossOrderedTransactions, getOriginalTransactionGas } from "./transactions.mjs";
|
|
8
10
|
const log = createModuleLogger(projectLogger, 'across-strategy');
|
|
9
11
|
const ACROSS_STATUS_POLL_INTERVAL = 1000;
|
|
10
12
|
/**
|
|
@@ -31,8 +33,8 @@ async function executeSingleQuote(quote, messenger, transaction) {
|
|
|
31
33
|
}, (tx) => {
|
|
32
34
|
tx.txParams.nonce = undefined;
|
|
33
35
|
});
|
|
34
|
-
const acrossDepositType = getAcrossDepositType(transaction
|
|
35
|
-
const transactionHash = await submitTransactions(quote, transaction
|
|
36
|
+
const acrossDepositType = getAcrossDepositType(transaction);
|
|
37
|
+
const transactionHash = await submitTransactions(quote, transaction, acrossDepositType, messenger);
|
|
36
38
|
updateTransaction({
|
|
37
39
|
transactionId: transaction.id,
|
|
38
40
|
messenger,
|
|
@@ -46,12 +48,12 @@ async function executeSingleQuote(quote, messenger, transaction) {
|
|
|
46
48
|
* Submit transactions for an Across quote.
|
|
47
49
|
*
|
|
48
50
|
* @param quote - Across quote.
|
|
49
|
-
* @param
|
|
51
|
+
* @param parentTransaction - Parent transaction.
|
|
50
52
|
* @param acrossDepositType - Transaction type used for the swap/deposit step.
|
|
51
53
|
* @param messenger - Controller messenger.
|
|
52
54
|
* @returns Hash of the last submitted transaction, if available.
|
|
53
55
|
*/
|
|
54
|
-
async function submitTransactions(quote,
|
|
56
|
+
async function submitTransactions(quote, parentTransaction, acrossDepositType, messenger) {
|
|
55
57
|
const { swapTx } = quote.original.quote;
|
|
56
58
|
const { gasLimits: quoteGasLimits, is7702 } = quote.original.metamask;
|
|
57
59
|
const { from } = quote.request;
|
|
@@ -60,19 +62,56 @@ async function submitTransactions(quote, parentTransactionId, acrossDepositType,
|
|
|
60
62
|
quote: quote.original.quote,
|
|
61
63
|
swapType: acrossDepositType,
|
|
62
64
|
});
|
|
65
|
+
const shouldPrependOriginalTransaction = quote.request.isPostQuote === true &&
|
|
66
|
+
parentTransaction.txParams.to !== undefined;
|
|
67
|
+
const hasPrependedOriginalGasLimit = shouldPrependOriginalTransaction &&
|
|
68
|
+
!is7702 &&
|
|
69
|
+
quoteGasLimits.length > orderedTransactions.length;
|
|
70
|
+
const gasLimitOffset = hasPrependedOriginalGasLimit ? 1 : 0;
|
|
71
|
+
const transactionCount = orderedTransactions.length + (shouldPrependOriginalTransaction ? 1 : 0);
|
|
63
72
|
const networkClientId = messenger.call('NetworkController:findNetworkClientIdByChainId', chainId);
|
|
64
|
-
const
|
|
73
|
+
const is7702Batch = is7702 && transactionCount > 1;
|
|
74
|
+
const canUseQuotedBatchGasLimit = is7702Batch &&
|
|
75
|
+
(!shouldPrependOriginalTransaction ||
|
|
76
|
+
hasOriginalTransactionGas(parentTransaction));
|
|
77
|
+
const batchGasLimit = canUseQuotedBatchGasLimit
|
|
65
78
|
? quoteGasLimits[0]?.max
|
|
66
79
|
: undefined;
|
|
67
|
-
if (
|
|
80
|
+
if (canUseQuotedBatchGasLimit && batchGasLimit === undefined) {
|
|
68
81
|
throw new Error('Missing quote gas limit for Across 7702 batch');
|
|
69
82
|
}
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
83
|
+
const quotedGasLimit7702 = batchGasLimit === undefined ? undefined : toHex(batchGasLimit);
|
|
84
|
+
const parentHasAuthorizationList = Boolean(parentTransaction.txParams.authorizationList?.length);
|
|
85
|
+
const shouldUseGasFeeToken7702Submit = shouldEstimate7702SubmitBatch(parentTransaction, quote)
|
|
86
|
+
? accountSupports7702(messenger, from)
|
|
87
|
+
: false;
|
|
88
|
+
const shouldUse7702Submit = [
|
|
89
|
+
Boolean(quotedGasLimit7702),
|
|
90
|
+
is7702Batch,
|
|
91
|
+
parentHasAuthorizationList,
|
|
92
|
+
shouldUseGasFeeToken7702Submit,
|
|
93
|
+
].some(Boolean);
|
|
94
|
+
const shouldEstimateGasLimit7702 = !quotedGasLimit7702 && shouldUse7702Submit;
|
|
95
|
+
const estimatedGasLimit7702 = shouldEstimateGasLimit7702
|
|
96
|
+
? await estimateSubmitBatchGasLimit7702({
|
|
97
|
+
chainId,
|
|
98
|
+
from,
|
|
99
|
+
messenger,
|
|
100
|
+
orderedTransactions,
|
|
101
|
+
parentTransaction,
|
|
102
|
+
shouldPrependOriginalTransaction,
|
|
103
|
+
})
|
|
104
|
+
: undefined;
|
|
105
|
+
const gasLimit7702 = quotedGasLimit7702 ?? estimatedGasLimit7702;
|
|
106
|
+
const submitAs7702 = shouldUse7702Submit || Boolean(gasLimit7702);
|
|
107
|
+
const acrossTransactions = orderedTransactions.map((transaction, index) => {
|
|
108
|
+
const gasLimit = submitAs7702
|
|
109
|
+
? undefined
|
|
110
|
+
: quoteGasLimits[index + gasLimitOffset]?.max;
|
|
111
|
+
if (gasLimit === undefined && !submitAs7702) {
|
|
112
|
+
const quoteGasIndex = index + gasLimitOffset;
|
|
74
113
|
const errorMessage = transaction.kind === 'approval'
|
|
75
|
-
? `Missing quote gas limit for Across approval transaction at index ${
|
|
114
|
+
? `Missing quote gas limit for Across approval transaction at index ${quoteGasIndex}`
|
|
76
115
|
: 'Missing quote gas limit for Across swap transaction';
|
|
77
116
|
throw new Error(errorMessage);
|
|
78
117
|
}
|
|
@@ -89,11 +128,19 @@ async function submitTransactions(quote, parentTransactionId, acrossDepositType,
|
|
|
89
128
|
type: transaction.type ?? acrossDepositType,
|
|
90
129
|
};
|
|
91
130
|
});
|
|
131
|
+
const originalTransaction = shouldPrependOriginalTransaction
|
|
132
|
+
? [
|
|
133
|
+
buildOriginalTransaction(parentTransaction, submitAs7702 || !hasPrependedOriginalGasLimit
|
|
134
|
+
? undefined
|
|
135
|
+
: quoteGasLimits[0]?.max),
|
|
136
|
+
]
|
|
137
|
+
: [];
|
|
138
|
+
const transactions = [...originalTransaction, ...acrossTransactions];
|
|
92
139
|
const transactionIds = [];
|
|
93
140
|
const { end } = collectTransactionIds(chainId, from, messenger, (transactionId) => {
|
|
94
141
|
transactionIds.push(transactionId);
|
|
95
142
|
updateTransaction({
|
|
96
|
-
transactionId:
|
|
143
|
+
transactionId: parentTransaction.id,
|
|
97
144
|
messenger,
|
|
98
145
|
note: 'Add required transaction ID from Across submission',
|
|
99
146
|
}, (tx) => {
|
|
@@ -105,9 +152,11 @@ async function submitTransactions(quote, parentTransactionId, acrossDepositType,
|
|
|
105
152
|
const gasFeeToken = quote.fees.isSourceGasFeeToken
|
|
106
153
|
? quote.request.sourceTokenAddress
|
|
107
154
|
: undefined;
|
|
155
|
+
const excludeNativeTokenForFee = gasFeeToken ? true : undefined;
|
|
108
156
|
try {
|
|
109
157
|
if (transactions.length === 1) {
|
|
110
158
|
result = await messenger.call('TransactionController:addTransaction', transactions[0].params, {
|
|
159
|
+
excludeNativeTokenForFee,
|
|
111
160
|
gasFeeToken,
|
|
112
161
|
networkClientId,
|
|
113
162
|
origin: ORIGIN_METAMASK,
|
|
@@ -121,9 +170,10 @@ async function submitTransactions(quote, parentTransactionId, acrossDepositType,
|
|
|
121
170
|
type,
|
|
122
171
|
}));
|
|
123
172
|
await messenger.call('TransactionController:addTransactionBatch', {
|
|
124
|
-
disable7702: !
|
|
125
|
-
disableHook:
|
|
126
|
-
disableSequential:
|
|
173
|
+
disable7702: !submitAs7702,
|
|
174
|
+
disableHook: submitAs7702,
|
|
175
|
+
disableSequential: submitAs7702,
|
|
176
|
+
excludeNativeTokenForFee,
|
|
127
177
|
from,
|
|
128
178
|
gasFeeToken,
|
|
129
179
|
gasLimit7702,
|
|
@@ -147,6 +197,13 @@ async function submitTransactions(quote, parentTransactionId, acrossDepositType,
|
|
|
147
197
|
: undefined;
|
|
148
198
|
return await waitForAcrossCompletion(hash, messenger);
|
|
149
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Poll Across until a submitted deposit reaches a terminal status.
|
|
202
|
+
*
|
|
203
|
+
* @param transactionHash - Source-chain deposit transaction hash.
|
|
204
|
+
* @param messenger - Controller messenger.
|
|
205
|
+
* @returns Destination/fill transaction hash when available, otherwise the source hash.
|
|
206
|
+
*/
|
|
150
207
|
async function waitForAcrossCompletion(transactionHash, messenger) {
|
|
151
208
|
if (!transactionHash) {
|
|
152
209
|
return transactionHash;
|
|
@@ -199,8 +256,124 @@ async function waitForAcrossCompletion(transactionHash, messenger) {
|
|
|
199
256
|
await new Promise((resolve) => setTimeout(resolve, ACROSS_STATUS_POLL_INTERVAL));
|
|
200
257
|
}
|
|
201
258
|
}
|
|
202
|
-
|
|
203
|
-
|
|
259
|
+
/**
|
|
260
|
+
* Check whether submit should estimate a 7702 batch gas limit.
|
|
261
|
+
*
|
|
262
|
+
* This is needed for Predict withdraw post-quote flows that pay source-chain
|
|
263
|
+
* gas with the source token, because the final submit batch can differ from the
|
|
264
|
+
* batch shape that Across quoted.
|
|
265
|
+
*
|
|
266
|
+
* @param parentTransaction - Original transaction metadata.
|
|
267
|
+
* @param quote - Across quote selected for execution.
|
|
268
|
+
* @returns Whether submit should try to estimate the final 7702 batch gas.
|
|
269
|
+
*/
|
|
270
|
+
function shouldEstimate7702SubmitBatch(parentTransaction, quote) {
|
|
271
|
+
return (isPredictWithdrawTransaction(parentTransaction) &&
|
|
272
|
+
quote.request.isPostQuote === true &&
|
|
273
|
+
quote.fees.isSourceGasFeeToken === true);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Estimate the 7702 batch gas limit for the actual submit payload.
|
|
277
|
+
*
|
|
278
|
+
* Quotes can contain a combined 7702 gas limit that only covered the Across
|
|
279
|
+
* approval/swap legs. When submit prepends the original transaction, estimate
|
|
280
|
+
* the final batch shape so the gas limit covers every submitted leg.
|
|
281
|
+
*
|
|
282
|
+
* @param args - Estimation arguments.
|
|
283
|
+
* @param args.chainId - Source chain ID.
|
|
284
|
+
* @param args.from - Sender address.
|
|
285
|
+
* @param args.messenger - Controller messenger.
|
|
286
|
+
* @param args.orderedTransactions - Across approval/swap legs in submission order.
|
|
287
|
+
* @param args.parentTransaction - Original transaction that may be prepended.
|
|
288
|
+
* @param args.shouldPrependOriginalTransaction - Whether to include the original transaction in the estimate.
|
|
289
|
+
* @returns Hex gas limit, or `undefined` when estimation is unavailable.
|
|
290
|
+
*/
|
|
291
|
+
async function estimateSubmitBatchGasLimit7702({ chainId, from, messenger, orderedTransactions, parentTransaction, shouldPrependOriginalTransaction, }) {
|
|
292
|
+
if (!accountSupports7702(messenger, from)) {
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
const originalTransaction = shouldPrependOriginalTransaction
|
|
296
|
+
? [buildOriginalTransaction(parentTransaction)]
|
|
297
|
+
: [];
|
|
298
|
+
const acrossTransactions = orderedTransactions.map((transaction) => ({
|
|
299
|
+
params: buildTransactionParams(from, {
|
|
300
|
+
chainId: transaction.chainId,
|
|
301
|
+
data: transaction.data,
|
|
302
|
+
maxFeePerGas: transaction.maxFeePerGas,
|
|
303
|
+
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
|
|
304
|
+
to: transaction.to,
|
|
305
|
+
value: transaction.value,
|
|
306
|
+
}),
|
|
307
|
+
type: transaction.type,
|
|
308
|
+
}));
|
|
309
|
+
const transactions = [...originalTransaction, ...acrossTransactions];
|
|
310
|
+
try {
|
|
311
|
+
const result = await messenger.call('TransactionController:estimateGasBatch', {
|
|
312
|
+
chainId,
|
|
313
|
+
from,
|
|
314
|
+
transactions: transactions.map(({ params }) => toBatchTransactionParams(params)),
|
|
315
|
+
});
|
|
316
|
+
if (result.gasLimits.length !== 1) {
|
|
317
|
+
return undefined;
|
|
318
|
+
}
|
|
319
|
+
const gasLimit = Math.ceil(result.gasLimits[0] * getGasBuffer(messenger, chainId));
|
|
320
|
+
return toHex(gasLimit);
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
return undefined;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Build the original parent transaction as a prepared batch leg.
|
|
328
|
+
*
|
|
329
|
+
* @param transaction - Original transaction metadata.
|
|
330
|
+
* @param gasLimit - Optional gas limit to pin on the original leg.
|
|
331
|
+
* @returns Prepared transaction params and transaction type for the original leg.
|
|
332
|
+
*/
|
|
333
|
+
function buildOriginalTransaction(transaction, gasLimit) {
|
|
334
|
+
return {
|
|
335
|
+
params: {
|
|
336
|
+
data: transaction.txParams.data,
|
|
337
|
+
from: transaction.txParams.from,
|
|
338
|
+
gas: gasLimit === undefined ? undefined : toHex(gasLimit),
|
|
339
|
+
to: transaction.txParams.to,
|
|
340
|
+
value: transaction.txParams.value,
|
|
341
|
+
},
|
|
342
|
+
type: getOriginalTransactionType(transaction),
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Get the transaction type to use for the original batch leg.
|
|
347
|
+
*
|
|
348
|
+
* @param transaction - Original transaction metadata.
|
|
349
|
+
* @returns `predictWithdraw` for Predict withdrawals; otherwise the original type.
|
|
350
|
+
*/
|
|
351
|
+
function getOriginalTransactionType(transaction) {
|
|
352
|
+
if (isPredictWithdrawTransaction(transaction)) {
|
|
353
|
+
return TransactionType.predictWithdraw;
|
|
354
|
+
}
|
|
355
|
+
return transaction.type;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Check whether the original transaction already has a usable gas limit.
|
|
359
|
+
*
|
|
360
|
+
* @param transaction - Original transaction metadata.
|
|
361
|
+
* @returns Whether the original or nested transaction gas is a positive integer.
|
|
362
|
+
*/
|
|
363
|
+
function hasOriginalTransactionGas(transaction) {
|
|
364
|
+
return getOriginalTransactionGas(transaction) !== undefined;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Get the transaction type for the Across bridge/deposit leg.
|
|
368
|
+
*
|
|
369
|
+
* @param transaction - Original parent transaction.
|
|
370
|
+
* @returns Across-specific transaction type for known flows, or the original type.
|
|
371
|
+
*/
|
|
372
|
+
function getAcrossDepositType(transaction) {
|
|
373
|
+
if (isPredictWithdrawTransaction(transaction)) {
|
|
374
|
+
return TransactionType.predictAcrossWithdraw;
|
|
375
|
+
}
|
|
376
|
+
switch (transaction.type) {
|
|
204
377
|
case TransactionType.perpsDeposit:
|
|
205
378
|
return TransactionType.perpsAcrossDeposit;
|
|
206
379
|
case TransactionType.predictDeposit:
|
|
@@ -208,9 +381,23 @@ function getAcrossDepositType(transactionType) {
|
|
|
208
381
|
case undefined:
|
|
209
382
|
return TransactionType.perpsAcrossDeposit;
|
|
210
383
|
default:
|
|
211
|
-
return
|
|
384
|
+
return transaction.type;
|
|
212
385
|
}
|
|
213
386
|
}
|
|
387
|
+
/**
|
|
388
|
+
* Build TransactionController params for an Across approval or swap leg.
|
|
389
|
+
*
|
|
390
|
+
* @param from - Sender address.
|
|
391
|
+
* @param params - Across transaction fields.
|
|
392
|
+
* @param params.chainId - Source chain ID.
|
|
393
|
+
* @param params.data - Transaction calldata.
|
|
394
|
+
* @param params.gasLimit - Optional gas limit.
|
|
395
|
+
* @param params.to - Recipient contract address.
|
|
396
|
+
* @param params.value - Optional native value.
|
|
397
|
+
* @param params.maxFeePerGas - Optional EIP-1559 max fee.
|
|
398
|
+
* @param params.maxPriorityFeePerGas - Optional EIP-1559 priority fee.
|
|
399
|
+
* @returns TransactionController params.
|
|
400
|
+
*/
|
|
214
401
|
function buildTransactionParams(from, params) {
|
|
215
402
|
const value = toHex(params.value ?? '0x0');
|
|
216
403
|
return {
|
|
@@ -223,12 +410,24 @@ function buildTransactionParams(from, params) {
|
|
|
223
410
|
value,
|
|
224
411
|
};
|
|
225
412
|
}
|
|
413
|
+
/**
|
|
414
|
+
* Normalize an optional numeric string or hex string into a hex value.
|
|
415
|
+
*
|
|
416
|
+
* @param value - Optional value to normalize.
|
|
417
|
+
* @returns Hex value, or `undefined` when no value is provided.
|
|
418
|
+
*/
|
|
226
419
|
function normalizeOptionalHex(value) {
|
|
227
420
|
if (value === undefined) {
|
|
228
421
|
return undefined;
|
|
229
422
|
}
|
|
230
423
|
return toHex(value);
|
|
231
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* Convert full TransactionController params into batch transaction params.
|
|
427
|
+
*
|
|
428
|
+
* @param params - Transaction params.
|
|
429
|
+
* @returns Batch-compatible transaction params.
|
|
430
|
+
*/
|
|
232
431
|
function toBatchTransactionParams(params) {
|
|
233
432
|
return {
|
|
234
433
|
data: params.data,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"across-submit.mjs","sourceRoot":"","sources":["../../../src/strategy/across/across-submit.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,KAAK,EACN,mCAAmC;AACpC,OAAO,EAAE,eAAe,EAAE,yCAAyC;AAOnE,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,aAAa,EAAE,yBAAqB;AAM7C,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AACnE,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,2BAA2B,EAC5B,oCAAgC;AACjC,OAAO,EAAE,4BAA4B,EAAE,2BAAuB;AAG9D,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC;AACjE,MAAM,2BAA2B,GAAG,IAAI,CAAC;AAOzC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAA+C;IAE/C,GAAG,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;IAEjC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IACnD,IAAI,eAAgC,CAAC;IA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K,CAAC,MAAM,CAAC,QAAQ,CAAC;QACvE,YAAY,EAAE,oBAAoB,CAAC,MAAM,CAAC,YAAY,CAAC;QACvD,oBAAoB,EAAE,oBAAoB,CAAC,MAAM,CAAC,oBAAoB,CAAC;QACvE,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,KAAK;KACN,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAc;IAC1C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;AACtB,CAAC;AAED,SAAS,wBAAwB,CAC/B,MAAyB;IAEzB,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAuB;QACpC,GAAG,EAAE,MAAM,CAAC,GAAsB;QAClC,YAAY,EAAE,MAAM,CAAC,YAA+B;QACpD,oBAAoB,EAAE,MAAM,CAAC,oBAAuC;QACpE,EAAE,EAAE,MAAM,CAAC,EAAqB;QAChC,KAAK,EAAE,MAAM,CAAC,KAAwB;KACvC,CAAC;AACJ,CAAC","sourcesContent":["import {\n ORIGIN_METAMASK,\n successfulFetch,\n toHex,\n} from '@metamask/controller-utils';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport type {\n BatchTransactionParams,\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../../logger';\nimport type {\n PayStrategyExecuteRequest,\n TransactionPayControllerMessenger,\n TransactionPayQuote,\n} from '../../types';\nimport { getPayStrategiesConfig } from '../../utils/feature-flags';\nimport {\n collectTransactionIds,\n getTransaction,\n updateTransaction,\n waitForTransactionConfirmed,\n} from '../../utils/transaction';\nimport { getAcrossOrderedTransactions } from './transactions';\nimport type { AcrossQuote } from './types';\n\nconst log = createModuleLogger(projectLogger, 'across-strategy');\nconst ACROSS_STATUS_POLL_INTERVAL = 1000;\n\ntype PreparedAcrossTransaction = {\n params: TransactionParams;\n type: TransactionType;\n};\n\n/**\n * Submit Across quotes.\n *\n * @param request - Request object.\n * @returns An object containing the transaction hash if available.\n */\nexport async function submitAcrossQuotes(\n request: PayStrategyExecuteRequest<AcrossQuote>,\n): Promise<{ transactionHash?: Hex }> {\n log('Executing quotes', request);\n\n const { quotes, messenger, transaction } = request;\n let transactionHash: Hex | undefined;\n\n for (const quote of quotes) {\n ({ transactionHash } = await executeSingleQuote(\n quote,\n messenger,\n transaction,\n ));\n }\n\n return { transactionHash };\n}\n\nasync function executeSingleQuote(\n quote: TransactionPayQuote<AcrossQuote>,\n messenger: TransactionPayControllerMessenger,\n transaction: TransactionMeta,\n): Promise<{ transactionHash?: Hex }> {\n log('Executing single quote', quote);\n\n updateTransaction(\n {\n transactionId: transaction.id,\n messenger,\n note: 'Remove nonce from skipped transaction',\n },\n (tx) => {\n tx.txParams.nonce = undefined;\n },\n );\n\n const acrossDepositType = getAcrossDepositType(transaction.type);\n const transactionHash = await submitTransactions(\n quote,\n transaction.id,\n acrossDepositType,\n messenger,\n );\n\n updateTransaction(\n {\n transactionId: transaction.id,\n messenger,\n note: 'Intent complete after Across submission',\n },\n (tx) => {\n tx.isIntentComplete = true;\n },\n );\n\n return { transactionHash };\n}\n\n/**\n * Submit transactions for an Across quote.\n *\n * @param quote - Across quote.\n * @param parentTransactionId - ID of the parent transaction.\n * @param acrossDepositType - Transaction type used for the swap/deposit step.\n * @param messenger - Controller messenger.\n * @returns Hash of the last submitted transaction, if available.\n */\nasync function submitTransactions(\n quote: TransactionPayQuote<AcrossQuote>,\n parentTransactionId: string,\n acrossDepositType: TransactionType,\n messenger: TransactionPayControllerMessenger,\n): Promise<Hex | undefined> {\n const { swapTx } = quote.original.quote;\n const { gasLimits: quoteGasLimits, is7702 } = quote.original.metamask;\n const { from } = quote.request;\n const chainId = toHex(swapTx.chainId);\n const orderedTransactions = getAcrossOrderedTransactions({\n quote: quote.original.quote,\n swapType: acrossDepositType,\n });\n\n const networkClientId = messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n chainId,\n );\n\n const batchGasLimit =\n is7702 && orderedTransactions.length > 1\n ? quoteGasLimits[0]?.max\n : undefined;\n\n if (is7702 && orderedTransactions.length > 1 && batchGasLimit === undefined) {\n throw new Error('Missing quote gas limit for Across 7702 batch');\n }\n\n const gasLimit7702 =\n batchGasLimit === undefined ? undefined : toHex(batchGasLimit);\n\n const transactions: PreparedAcrossTransaction[] = orderedTransactions.map(\n (transaction, index) => {\n const gasLimit = gasLimit7702 ? undefined : quoteGasLimits[index]?.max;\n\n if (gasLimit === undefined && !gasLimit7702) {\n const errorMessage =\n transaction.kind === 'approval'\n ? `Missing quote gas limit for Across approval transaction at index ${index}`\n : 'Missing quote gas limit for Across swap transaction';\n\n throw new Error(errorMessage);\n }\n\n return {\n params: buildTransactionParams(from, {\n chainId: transaction.chainId,\n data: transaction.data,\n gasLimit,\n maxFeePerGas: transaction.maxFeePerGas,\n maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,\n to: transaction.to,\n value: transaction.value,\n }),\n type: transaction.type ?? acrossDepositType,\n };\n },\n );\n\n const transactionIds: string[] = [];\n\n const { end } = collectTransactionIds(\n chainId,\n from,\n messenger,\n (transactionId) => {\n transactionIds.push(transactionId);\n\n updateTransaction(\n {\n transactionId: parentTransactionId,\n messenger,\n note: 'Add required transaction ID from Across submission',\n },\n (tx) => {\n tx.requiredTransactionIds ??= [];\n tx.requiredTransactionIds.push(transactionId);\n },\n );\n },\n );\n\n let result: { result: Promise<string> } | undefined;\n const gasFeeToken = quote.fees.isSourceGasFeeToken\n ? quote.request.sourceTokenAddress\n : undefined;\n\n try {\n if (transactions.length === 1) {\n result = await messenger.call(\n 'TransactionController:addTransaction',\n transactions[0].params,\n {\n gasFeeToken,\n networkClientId,\n origin: ORIGIN_METAMASK,\n requireApproval: false,\n type: transactions[0].type,\n },\n );\n } else {\n const batchTransactions = transactions.map(({ params, type }) => ({\n params: toBatchTransactionParams(params),\n type,\n }));\n\n await messenger.call('TransactionController:addTransactionBatch', {\n disable7702: !gasLimit7702,\n disableHook: Boolean(gasLimit7702),\n disableSequential: Boolean(gasLimit7702),\n from,\n gasFeeToken,\n gasLimit7702,\n networkClientId,\n origin: ORIGIN_METAMASK,\n requireApproval: false,\n transactions: batchTransactions,\n });\n }\n } finally {\n end();\n }\n\n if (result) {\n const txHash = await result.result;\n log('Submitted transaction', txHash);\n }\n\n await Promise.all(\n transactionIds.map((txId) => waitForTransactionConfirmed(txId, messenger)),\n );\n\n const hash = transactionIds.length\n ? getTransaction(transactionIds.slice(-1)[0], messenger)?.hash\n : undefined;\n\n return await waitForAcrossCompletion(hash as Hex | undefined, messenger);\n}\n\ntype AcrossStatusResponse = {\n depositId?: number | string;\n depositTxnRef?: Hex;\n status?: string;\n destinationTxHash?: Hex;\n fillTxnRef?: Hex;\n fillTxHash?: Hex;\n txHash?: Hex;\n};\n\nasync function waitForAcrossCompletion(\n transactionHash: Hex | undefined,\n messenger: TransactionPayControllerMessenger,\n): Promise<Hex | undefined> {\n if (!transactionHash) {\n return transactionHash;\n }\n\n const config = getPayStrategiesConfig(messenger);\n const params = new URLSearchParams({\n depositTxnRef: transactionHash,\n });\n const url = `${config.across.apiBase}/deposit/status?${params.toString()}`;\n\n let attempt = 0;\n\n while (true) {\n attempt += 1;\n let status: AcrossStatusResponse;\n\n try {\n const response = await successfulFetch(url, {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n });\n status = (await response.json()) as AcrossStatusResponse;\n } catch (error) {\n log('Across status polling request failed', {\n attempt,\n error: String(error),\n transactionHash,\n });\n\n await new Promise((resolve) =>\n setTimeout(resolve, ACROSS_STATUS_POLL_INTERVAL),\n );\n continue;\n }\n\n const normalizedStatus = status.status?.toLowerCase();\n\n log('Polled Across status', {\n attempt,\n status: normalizedStatus,\n transactionHash,\n });\n\n if (\n normalizedStatus &&\n ['completed', 'filled', 'success'].includes(normalizedStatus)\n ) {\n return (\n status.destinationTxHash ??\n status.fillTxnRef ??\n status.fillTxHash ??\n status.txHash ??\n transactionHash\n );\n }\n\n if (\n normalizedStatus &&\n ['error', 'failed', 'refund', 'refunded'].includes(normalizedStatus)\n ) {\n throw new Error(`Across request failed with status: ${normalizedStatus}`);\n }\n\n await new Promise((resolve) =>\n setTimeout(resolve, ACROSS_STATUS_POLL_INTERVAL),\n );\n }\n}\n\nfunction getAcrossDepositType(\n transactionType?: TransactionType,\n): TransactionType {\n switch (transactionType) {\n case TransactionType.perpsDeposit:\n return TransactionType.perpsAcrossDeposit;\n case TransactionType.predictDeposit:\n return TransactionType.predictAcrossDeposit;\n case undefined:\n return TransactionType.perpsAcrossDeposit;\n default:\n return transactionType;\n }\n}\n\nfunction buildTransactionParams(\n from: Hex,\n params: {\n chainId: number;\n data: Hex;\n gasLimit?: number;\n to: Hex;\n value?: Hex;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n },\n): TransactionParams {\n const value = toHex(params.value ?? '0x0');\n\n return {\n data: params.data,\n from,\n gas: params.gasLimit === undefined ? undefined : toHex(params.gasLimit),\n maxFeePerGas: normalizeOptionalHex(params.maxFeePerGas),\n maxPriorityFeePerGas: normalizeOptionalHex(params.maxPriorityFeePerGas),\n to: params.to,\n value,\n };\n}\n\nfunction normalizeOptionalHex(value?: string): Hex | undefined {\n if (value === undefined) {\n return undefined;\n }\n\n return toHex(value);\n}\n\nfunction toBatchTransactionParams(\n params: TransactionParams,\n): BatchTransactionParams {\n return {\n data: params.data as Hex | undefined,\n gas: params.gas as Hex | undefined,\n maxFeePerGas: params.maxFeePerGas as Hex | undefined,\n maxPriorityFeePerGas: params.maxPriorityFeePerGas as Hex | undefined,\n to: params.to as Hex | undefined,\n value: params.value as Hex | undefined,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"across-submit.mjs","sourceRoot":"","sources":["../../../src/strategy/across/across-submit.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,KAAK,E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AS,sBAAsB,CAC7B,IAAS,EACT,MAQC;IAED,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC;IAE3C,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,IAAI;QACJ,GAAG,EAAE,MAAM,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC;QACvE,YAAY,EAAE,oBAAoB,CAAC,MAAM,CAAC,YAAY,CAAC;QACvD,oBAAoB,EAAE,oBAAoB,CAAC,MAAM,CAAC,oBAAoB,CAAC;QACvE,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,KAAK;KACN,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,KAAc;IAC1C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;AACtB,CAAC;AAED;;;;;GAKG;AACH,SAAS,wBAAwB,CAC/B,MAAyB;IAEzB,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAuB;QACpC,GAAG,EAAE,MAAM,CAAC,GAAsB;QAClC,YAAY,EAAE,MAAM,CAAC,YAA+B;QACpD,oBAAoB,EAAE,MAAM,CAAC,oBAAuC;QACpE,EAAE,EAAE,MAAM,CAAC,EAAqB;QAChC,KAAK,EAAE,MAAM,CAAC,KAAwB;KACvC,CAAC;AACJ,CAAC","sourcesContent":["import {\n ORIGIN_METAMASK,\n successfulFetch,\n toHex,\n} from '@metamask/controller-utils';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport type {\n BatchTransactionParams,\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { projectLogger } from '../../logger';\nimport type {\n PayStrategyExecuteRequest,\n TransactionPayControllerMessenger,\n TransactionPayQuote,\n} from '../../types';\nimport { accountSupports7702 } from '../../utils/7702';\nimport { getPayStrategiesConfig } from '../../utils/feature-flags';\nimport { getGasBuffer } from '../../utils/feature-flags';\nimport {\n collectTransactionIds,\n getTransaction,\n updateTransaction,\n isPredictWithdrawTransaction,\n waitForTransactionConfirmed,\n} from '../../utils/transaction';\nimport {\n getAcrossOrderedTransactions,\n getOriginalTransactionGas,\n} from './transactions';\nimport type { AcrossQuote } from './types';\n\nconst log = createModuleLogger(projectLogger, 'across-strategy');\nconst ACROSS_STATUS_POLL_INTERVAL = 1000;\n\ntype PreparedAcrossTransaction = {\n params: TransactionParams;\n type: TransactionMeta['type'];\n};\n\n/**\n * Submit Across quotes.\n *\n * @param request - Request object.\n * @returns An object containing the transaction hash if available.\n */\nexport async function submitAcrossQuotes(\n request: PayStrategyExecuteRequest<AcrossQuote>,\n): Promise<{ transactionHash?: Hex }> {\n log('Executing quotes', request);\n\n const { quotes, messenger, transaction } = request;\n let transactionHash: Hex | undefined;\n\n for (const quote of quotes) {\n ({ transactionHash } = await executeSingleQuote(\n quote,\n messenger,\n transaction,\n ));\n }\n\n return { transactionHash };\n}\n\nasync function executeSingleQuote(\n quote: TransactionPayQuote<AcrossQuote>,\n messenger: TransactionPayControllerMessenger,\n transaction: TransactionMeta,\n): Promise<{ transactionHash?: Hex }> {\n log('Executing single quote', quote);\n\n updateTransaction(\n {\n transactionId: transaction.id,\n messenger,\n note: 'Remove nonce from skipped transaction',\n },\n (tx) => {\n tx.txParams.nonce = undefined;\n },\n );\n\n const acrossDepositType = getAcrossDepositType(transaction);\n const transactionHash = await submitTransactions(\n quote,\n transaction,\n acrossDepositType,\n messenger,\n );\n\n updateTransaction(\n {\n transactionId: transaction.id,\n messenger,\n note: 'Intent complete after Across submission',\n },\n (tx) => {\n tx.isIntentComplete = true;\n },\n );\n\n return { transactionHash };\n}\n\n/**\n * Submit transactions for an Across quote.\n *\n * @param quote - Across quote.\n * @param parentTransaction - Parent transaction.\n * @param acrossDepositType - Transaction type used for the swap/deposit step.\n * @param messenger - Controller messenger.\n * @returns Hash of the last submitted transaction, if available.\n */\nasync function submitTransactions(\n quote: TransactionPayQuote<AcrossQuote>,\n parentTransaction: TransactionMeta,\n acrossDepositType: TransactionType,\n messenger: TransactionPayControllerMessenger,\n): Promise<Hex | undefined> {\n const { swapTx } = quote.original.quote;\n const { gasLimits: quoteGasLimits, is7702 } = quote.original.metamask;\n const { from } = quote.request;\n const chainId = toHex(swapTx.chainId);\n const orderedTransactions = getAcrossOrderedTransactions({\n quote: quote.original.quote,\n swapType: acrossDepositType,\n });\n const shouldPrependOriginalTransaction =\n quote.request.isPostQuote === true &&\n parentTransaction.txParams.to !== undefined;\n const hasPrependedOriginalGasLimit =\n shouldPrependOriginalTransaction &&\n !is7702 &&\n quoteGasLimits.length > orderedTransactions.length;\n const gasLimitOffset = hasPrependedOriginalGasLimit ? 1 : 0;\n const transactionCount =\n orderedTransactions.length + (shouldPrependOriginalTransaction ? 1 : 0);\n\n const networkClientId = messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n chainId,\n );\n\n const is7702Batch = is7702 && transactionCount > 1;\n const canUseQuotedBatchGasLimit =\n is7702Batch &&\n (!shouldPrependOriginalTransaction ||\n hasOriginalTransactionGas(parentTransaction));\n const batchGasLimit = canUseQuotedBatchGasLimit\n ? quoteGasLimits[0]?.max\n : undefined;\n\n if (canUseQuotedBatchGasLimit && batchGasLimit === undefined) {\n throw new Error('Missing quote gas limit for Across 7702 batch');\n }\n\n const quotedGasLimit7702 =\n batchGasLimit === undefined ? undefined : toHex(batchGasLimit);\n const parentHasAuthorizationList = Boolean(\n parentTransaction.txParams.authorizationList?.length,\n );\n\n const shouldUseGasFeeToken7702Submit = shouldEstimate7702SubmitBatch(\n parentTransaction,\n quote,\n )\n ? accountSupports7702(messenger, from)\n : false;\n const shouldUse7702Submit = [\n Boolean(quotedGasLimit7702),\n is7702Batch,\n parentHasAuthorizationList,\n shouldUseGasFeeToken7702Submit,\n ].some(Boolean);\n\n const shouldEstimateGasLimit7702 = !quotedGasLimit7702 && shouldUse7702Submit;\n\n const estimatedGasLimit7702 = shouldEstimateGasLimit7702\n ? await estimateSubmitBatchGasLimit7702({\n chainId,\n from,\n messenger,\n orderedTransactions,\n parentTransaction,\n shouldPrependOriginalTransaction,\n })\n : undefined;\n\n const gasLimit7702 = quotedGasLimit7702 ?? estimatedGasLimit7702;\n const submitAs7702 = shouldUse7702Submit || Boolean(gasLimit7702);\n\n const acrossTransactions: PreparedAcrossTransaction[] =\n orderedTransactions.map((transaction, index) => {\n const gasLimit = submitAs7702\n ? undefined\n : quoteGasLimits[index + gasLimitOffset]?.max;\n\n if (gasLimit === undefined && !submitAs7702) {\n const quoteGasIndex = index + gasLimitOffset;\n const errorMessage =\n transaction.kind === 'approval'\n ? `Missing quote gas limit for Across approval transaction at index ${quoteGasIndex}`\n : 'Missing quote gas limit for Across swap transaction';\n\n throw new Error(errorMessage);\n }\n\n return {\n params: buildTransactionParams(from, {\n chainId: transaction.chainId,\n data: transaction.data,\n gasLimit,\n maxFeePerGas: transaction.maxFeePerGas,\n maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,\n to: transaction.to,\n value: transaction.value,\n }),\n type: transaction.type ?? acrossDepositType,\n };\n });\n const originalTransaction = shouldPrependOriginalTransaction\n ? [\n buildOriginalTransaction(\n parentTransaction,\n submitAs7702 || !hasPrependedOriginalGasLimit\n ? undefined\n : quoteGasLimits[0]?.max,\n ),\n ]\n : [];\n const transactions = [...originalTransaction, ...acrossTransactions];\n\n const transactionIds: string[] = [];\n\n const { end } = collectTransactionIds(\n chainId,\n from,\n messenger,\n (transactionId) => {\n transactionIds.push(transactionId);\n\n updateTransaction(\n {\n transactionId: parentTransaction.id,\n messenger,\n note: 'Add required transaction ID from Across submission',\n },\n (tx) => {\n tx.requiredTransactionIds ??= [];\n tx.requiredTransactionIds.push(transactionId);\n },\n );\n },\n );\n\n let result: { result: Promise<string> } | undefined;\n const gasFeeToken = quote.fees.isSourceGasFeeToken\n ? quote.request.sourceTokenAddress\n : undefined;\n const excludeNativeTokenForFee = gasFeeToken ? true : undefined;\n\n try {\n if (transactions.length === 1) {\n result = await messenger.call(\n 'TransactionController:addTransaction',\n transactions[0].params,\n {\n excludeNativeTokenForFee,\n gasFeeToken,\n networkClientId,\n origin: ORIGIN_METAMASK,\n requireApproval: false,\n type: transactions[0].type,\n },\n );\n } else {\n const batchTransactions = transactions.map(({ params, type }) => ({\n params: toBatchTransactionParams(params),\n type,\n }));\n\n await messenger.call('TransactionController:addTransactionBatch', {\n disable7702: !submitAs7702,\n disableHook: submitAs7702,\n disableSequential: submitAs7702,\n excludeNativeTokenForFee,\n from,\n gasFeeToken,\n gasLimit7702,\n networkClientId,\n origin: ORIGIN_METAMASK,\n requireApproval: false,\n transactions: batchTransactions,\n });\n }\n } finally {\n end();\n }\n\n if (result) {\n const txHash = await result.result;\n log('Submitted transaction', txHash);\n }\n\n await Promise.all(\n transactionIds.map((txId) => waitForTransactionConfirmed(txId, messenger)),\n );\n\n const hash = transactionIds.length\n ? getTransaction(transactionIds.slice(-1)[0], messenger)?.hash\n : undefined;\n\n return await waitForAcrossCompletion(hash as Hex | undefined, messenger);\n}\n\ntype AcrossStatusResponse = {\n depositId?: number | string;\n depositTxnRef?: Hex;\n status?: string;\n destinationTxHash?: Hex;\n fillTxnRef?: Hex;\n fillTxHash?: Hex;\n txHash?: Hex;\n};\n\n/**\n * Poll Across until a submitted deposit reaches a terminal status.\n *\n * @param transactionHash - Source-chain deposit transaction hash.\n * @param messenger - Controller messenger.\n * @returns Destination/fill transaction hash when available, otherwise the source hash.\n */\nasync function waitForAcrossCompletion(\n transactionHash: Hex | undefined,\n messenger: TransactionPayControllerMessenger,\n): Promise<Hex | undefined> {\n if (!transactionHash) {\n return transactionHash;\n }\n\n const config = getPayStrategiesConfig(messenger);\n const params = new URLSearchParams({\n depositTxnRef: transactionHash,\n });\n const url = `${config.across.apiBase}/deposit/status?${params.toString()}`;\n\n let attempt = 0;\n\n while (true) {\n attempt += 1;\n let status: AcrossStatusResponse;\n\n try {\n const response = await successfulFetch(url, {\n method: 'GET',\n headers: {\n Accept: 'application/json',\n },\n });\n status = (await response.json()) as AcrossStatusResponse;\n } catch (error) {\n log('Across status polling request failed', {\n attempt,\n error: String(error),\n transactionHash,\n });\n\n await new Promise((resolve) =>\n setTimeout(resolve, ACROSS_STATUS_POLL_INTERVAL),\n );\n continue;\n }\n\n const normalizedStatus = status.status?.toLowerCase();\n\n log('Polled Across status', {\n attempt,\n status: normalizedStatus,\n transactionHash,\n });\n\n if (\n normalizedStatus &&\n ['completed', 'filled', 'success'].includes(normalizedStatus)\n ) {\n return (\n status.destinationTxHash ??\n status.fillTxnRef ??\n status.fillTxHash ??\n status.txHash ??\n transactionHash\n );\n }\n\n if (\n normalizedStatus &&\n ['error', 'failed', 'refund', 'refunded'].includes(normalizedStatus)\n ) {\n throw new Error(`Across request failed with status: ${normalizedStatus}`);\n }\n\n await new Promise((resolve) =>\n setTimeout(resolve, ACROSS_STATUS_POLL_INTERVAL),\n );\n }\n}\n\n/**\n * Check whether submit should estimate a 7702 batch gas limit.\n *\n * This is needed for Predict withdraw post-quote flows that pay source-chain\n * gas with the source token, because the final submit batch can differ from the\n * batch shape that Across quoted.\n *\n * @param parentTransaction - Original transaction metadata.\n * @param quote - Across quote selected for execution.\n * @returns Whether submit should try to estimate the final 7702 batch gas.\n */\nfunction shouldEstimate7702SubmitBatch(\n parentTransaction: TransactionMeta,\n quote: TransactionPayQuote<AcrossQuote>,\n): boolean {\n return (\n isPredictWithdrawTransaction(parentTransaction) &&\n quote.request.isPostQuote === true &&\n quote.fees.isSourceGasFeeToken === true\n );\n}\n\n/**\n * Estimate the 7702 batch gas limit for the actual submit payload.\n *\n * Quotes can contain a combined 7702 gas limit that only covered the Across\n * approval/swap legs. When submit prepends the original transaction, estimate\n * the final batch shape so the gas limit covers every submitted leg.\n *\n * @param args - Estimation arguments.\n * @param args.chainId - Source chain ID.\n * @param args.from - Sender address.\n * @param args.messenger - Controller messenger.\n * @param args.orderedTransactions - Across approval/swap legs in submission order.\n * @param args.parentTransaction - Original transaction that may be prepended.\n * @param args.shouldPrependOriginalTransaction - Whether to include the original transaction in the estimate.\n * @returns Hex gas limit, or `undefined` when estimation is unavailable.\n */\nasync function estimateSubmitBatchGasLimit7702({\n chainId,\n from,\n messenger,\n orderedTransactions,\n parentTransaction,\n shouldPrependOriginalTransaction,\n}: {\n chainId: Hex;\n from: Hex;\n messenger: TransactionPayControllerMessenger;\n orderedTransactions: ReturnType<typeof getAcrossOrderedTransactions>;\n parentTransaction: TransactionMeta;\n shouldPrependOriginalTransaction: boolean;\n}): Promise<Hex | undefined> {\n if (!accountSupports7702(messenger, from)) {\n return undefined;\n }\n\n const originalTransaction = shouldPrependOriginalTransaction\n ? [buildOriginalTransaction(parentTransaction)]\n : [];\n\n const acrossTransactions = orderedTransactions.map((transaction) => ({\n params: buildTransactionParams(from, {\n chainId: transaction.chainId,\n data: transaction.data,\n maxFeePerGas: transaction.maxFeePerGas,\n maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,\n to: transaction.to,\n value: transaction.value,\n }),\n type: transaction.type,\n }));\n\n const transactions = [...originalTransaction, ...acrossTransactions];\n\n try {\n const result = await messenger.call(\n 'TransactionController:estimateGasBatch',\n {\n chainId,\n from,\n transactions: transactions.map(({ params }) =>\n toBatchTransactionParams(params),\n ),\n },\n );\n\n if (result.gasLimits.length !== 1) {\n return undefined;\n }\n\n const gasLimit = Math.ceil(\n result.gasLimits[0] * getGasBuffer(messenger, chainId),\n );\n\n return toHex(gasLimit);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Build the original parent transaction as a prepared batch leg.\n *\n * @param transaction - Original transaction metadata.\n * @param gasLimit - Optional gas limit to pin on the original leg.\n * @returns Prepared transaction params and transaction type for the original leg.\n */\nfunction buildOriginalTransaction(\n transaction: TransactionMeta,\n gasLimit?: number,\n): PreparedAcrossTransaction {\n return {\n params: {\n data: transaction.txParams.data,\n from: transaction.txParams.from,\n gas: gasLimit === undefined ? undefined : toHex(gasLimit),\n to: transaction.txParams.to,\n value: transaction.txParams.value,\n } as TransactionParams,\n type: getOriginalTransactionType(transaction),\n };\n}\n\n/**\n * Get the transaction type to use for the original batch leg.\n *\n * @param transaction - Original transaction metadata.\n * @returns `predictWithdraw` for Predict withdrawals; otherwise the original type.\n */\nfunction getOriginalTransactionType(\n transaction: TransactionMeta,\n): TransactionMeta['type'] {\n if (isPredictWithdrawTransaction(transaction)) {\n return TransactionType.predictWithdraw;\n }\n\n return transaction.type;\n}\n\n/**\n * Check whether the original transaction already has a usable gas limit.\n *\n * @param transaction - Original transaction metadata.\n * @returns Whether the original or nested transaction gas is a positive integer.\n */\nfunction hasOriginalTransactionGas(transaction: TransactionMeta): boolean {\n return getOriginalTransactionGas(transaction) !== undefined;\n}\n\n/**\n * Get the transaction type for the Across bridge/deposit leg.\n *\n * @param transaction - Original parent transaction.\n * @returns Across-specific transaction type for known flows, or the original type.\n */\nfunction getAcrossDepositType(transaction: TransactionMeta): TransactionType {\n if (isPredictWithdrawTransaction(transaction)) {\n return TransactionType.predictAcrossWithdraw;\n }\n\n switch (transaction.type) {\n case TransactionType.perpsDeposit:\n return TransactionType.perpsAcrossDeposit;\n case TransactionType.predictDeposit:\n return TransactionType.predictAcrossDeposit;\n case undefined:\n return TransactionType.perpsAcrossDeposit;\n default:\n return transaction.type as TransactionType;\n }\n}\n\n/**\n * Build TransactionController params for an Across approval or swap leg.\n *\n * @param from - Sender address.\n * @param params - Across transaction fields.\n * @param params.chainId - Source chain ID.\n * @param params.data - Transaction calldata.\n * @param params.gasLimit - Optional gas limit.\n * @param params.to - Recipient contract address.\n * @param params.value - Optional native value.\n * @param params.maxFeePerGas - Optional EIP-1559 max fee.\n * @param params.maxPriorityFeePerGas - Optional EIP-1559 priority fee.\n * @returns TransactionController params.\n */\nfunction buildTransactionParams(\n from: Hex,\n params: {\n chainId: number;\n data: Hex;\n gasLimit?: number;\n to: Hex;\n value?: Hex;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n },\n): TransactionParams {\n const value = toHex(params.value ?? '0x0');\n\n return {\n data: params.data,\n from,\n gas: params.gasLimit === undefined ? undefined : toHex(params.gasLimit),\n maxFeePerGas: normalizeOptionalHex(params.maxFeePerGas),\n maxPriorityFeePerGas: normalizeOptionalHex(params.maxPriorityFeePerGas),\n to: params.to,\n value,\n };\n}\n\n/**\n * Normalize an optional numeric string or hex string into a hex value.\n *\n * @param value - Optional value to normalize.\n * @returns Hex value, or `undefined` when no value is provided.\n */\nfunction normalizeOptionalHex(value?: string): Hex | undefined {\n if (value === undefined) {\n return undefined;\n }\n\n return toHex(value);\n}\n\n/**\n * Convert full TransactionController params into batch transaction params.\n *\n * @param params - Transaction params.\n * @returns Batch-compatible transaction params.\n */\nfunction toBatchTransactionParams(\n params: TransactionParams,\n): BatchTransactionParams {\n return {\n data: params.data as Hex | undefined,\n gas: params.gas as Hex | undefined,\n maxFeePerGas: params.maxFeePerGas as Hex | undefined,\n maxPriorityFeePerGas: params.maxPriorityFeePerGas as Hex | undefined,\n to: params.to as Hex | undefined,\n value: params.value as Hex | undefined,\n };\n}\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAcrossOrderedTransactions = void 0;
|
|
3
|
+
exports.getOriginalTransactionGas = exports.getAcrossOrderedTransactions = void 0;
|
|
4
4
|
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
5
|
+
const bignumber_js_1 = require("bignumber.js");
|
|
5
6
|
function getAcrossOrderedTransactions({ quote, swapType, }) {
|
|
6
7
|
const swapChainId = quote.swapTx.chainId;
|
|
7
8
|
const approvalTransactions = (quote.approvalTxns ?? []).map((approval) => ({
|
|
@@ -20,4 +21,23 @@ function getAcrossOrderedTransactions({ quote, swapType, }) {
|
|
|
20
21
|
];
|
|
21
22
|
}
|
|
22
23
|
exports.getAcrossOrderedTransactions = getAcrossOrderedTransactions;
|
|
24
|
+
/**
|
|
25
|
+
* Get a usable gas limit from the original or nested transaction.
|
|
26
|
+
*
|
|
27
|
+
* @param transaction - Original transaction metadata.
|
|
28
|
+
* @returns Positive integer gas limit if present, otherwise undefined.
|
|
29
|
+
*/
|
|
30
|
+
function getOriginalTransactionGas(transaction) {
|
|
31
|
+
const nestedGas = transaction.nestedTransactions?.find((tx) => tx.gas)?.gas;
|
|
32
|
+
const rawGas = nestedGas ?? transaction.txParams.gas;
|
|
33
|
+
if (rawGas === undefined) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
const gas = new bignumber_js_1.BigNumber(rawGas);
|
|
37
|
+
if (!gas.isFinite() || gas.isNaN() || !gas.isInteger() || gas.lte(0)) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return gas.toNumber();
|
|
41
|
+
}
|
|
42
|
+
exports.getOriginalTransactionGas = getOriginalTransactionGas;
|
|
23
43
|
//# sourceMappingURL=transactions.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactions.cjs","sourceRoot":"","sources":["../../../src/strategy/across/transactions.ts"],"names":[],"mappings":";;;AAAA,6EAAmE;
|
|
1
|
+
{"version":3,"file":"transactions.cjs","sourceRoot":"","sources":["../../../src/strategy/across/transactions.ts"],"names":[],"mappings":";;;AAAA,6EAAmE;AAEnE,+CAAyC;AAgBzC,SAAgB,4BAA4B,CAAC,EAC3C,KAAK,EACL,QAAQ,GAIT;IACC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC;IACzC,MAAM,oBAAoB,GAAG,CAAC,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACzE,GAAG,QAAQ;QACX,OAAO,EAAE,QAAQ,CAAC,OAAO,IAAI,WAAW;QACxC,IAAI,EAAE,UAAmB;QACzB,IAAI,EAAE,wCAAe,CAAC,kBAAkB;KACzC,CAAC,CAAC,CAAC;IAEJ,OAAO;QACL,GAAG,oBAAoB;QACvB;YACE,GAAG,KAAK,CAAC,MAAM;YACf,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,QAAQ;SACf;KACF,CAAC;AACJ,CAAC;AAvBD,oEAuBC;AAED;;;;;GAKG;AACH,SAAgB,yBAAyB,CACvC,WAA4B;IAE5B,MAAM,SAAS,GAAG,WAAW,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC;IAC5E,MAAM,MAAM,GAAG,SAAS,IAAI,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC;IAErD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,wBAAS,CAAC,MAAM,CAAC,CAAC;IAElC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACrE,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC;AAjBD,8DAiBC","sourcesContent":["import { TransactionType } from '@metamask/transaction-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport { BigNumber } from 'bignumber.js';\n\nimport type { AcrossSwapApprovalResponse } from './types';\n\nexport type AcrossOrderedTransaction = {\n chainId: number;\n data: `0x${string}`;\n gas?: string;\n kind: 'approval' | 'swap';\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n to: `0x${string}`;\n type?: TransactionType;\n value?: `0x${string}`;\n};\n\nexport function getAcrossOrderedTransactions({\n quote,\n swapType,\n}: {\n quote: AcrossSwapApprovalResponse;\n swapType?: TransactionType;\n}): AcrossOrderedTransaction[] {\n const swapChainId = quote.swapTx.chainId;\n const approvalTransactions = (quote.approvalTxns ?? []).map((approval) => ({\n ...approval,\n chainId: approval.chainId ?? swapChainId,\n kind: 'approval' as const,\n type: TransactionType.tokenMethodApprove,\n }));\n\n return [\n ...approvalTransactions,\n {\n ...quote.swapTx,\n kind: 'swap',\n type: swapType,\n },\n ];\n}\n\n/**\n * Get a usable gas limit from the original or nested transaction.\n *\n * @param transaction - Original transaction metadata.\n * @returns Positive integer gas limit if present, otherwise undefined.\n */\nexport function getOriginalTransactionGas(\n transaction: TransactionMeta,\n): number | undefined {\n const nestedGas = transaction.nestedTransactions?.find((tx) => tx.gas)?.gas;\n const rawGas = nestedGas ?? transaction.txParams.gas;\n\n if (rawGas === undefined) {\n return undefined;\n }\n\n const gas = new BigNumber(rawGas);\n\n if (!gas.isFinite() || gas.isNaN() || !gas.isInteger() || gas.lte(0)) {\n return undefined;\n }\n\n return gas.toNumber();\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TransactionType } from "@metamask/transaction-controller";
|
|
2
|
+
import type { TransactionMeta } from "@metamask/transaction-controller";
|
|
2
3
|
import type { AcrossSwapApprovalResponse } from "./types.cjs";
|
|
3
4
|
export type AcrossOrderedTransaction = {
|
|
4
5
|
chainId: number;
|
|
@@ -15,4 +16,11 @@ export declare function getAcrossOrderedTransactions({ quote, swapType, }: {
|
|
|
15
16
|
quote: AcrossSwapApprovalResponse;
|
|
16
17
|
swapType?: TransactionType;
|
|
17
18
|
}): AcrossOrderedTransaction[];
|
|
19
|
+
/**
|
|
20
|
+
* Get a usable gas limit from the original or nested transaction.
|
|
21
|
+
*
|
|
22
|
+
* @param transaction - Original transaction metadata.
|
|
23
|
+
* @returns Positive integer gas limit if present, otherwise undefined.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getOriginalTransactionGas(transaction: TransactionMeta): number | undefined;
|
|
18
26
|
//# sourceMappingURL=transactions.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactions.d.cts","sourceRoot":"","sources":["../../../src/strategy/across/transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;
|
|
1
|
+
{"version":3,"file":"transactions.d.cts","sourceRoot":"","sources":["../../../src/strategy/across/transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAGxE,OAAO,KAAK,EAAE,0BAA0B,EAAE,oBAAgB;AAE1D,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,KAAK,MAAM,EAAE,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC;IAClB,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;CACvB,CAAC;AAEF,wBAAgB,4BAA4B,CAAC,EAC3C,KAAK,EACL,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,0BAA0B,CAAC;IAClC,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B,GAAG,wBAAwB,EAAE,CAiB7B;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,eAAe,GAC3B,MAAM,GAAG,SAAS,CAepB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TransactionType } from "@metamask/transaction-controller";
|
|
2
|
+
import type { TransactionMeta } from "@metamask/transaction-controller";
|
|
2
3
|
import type { AcrossSwapApprovalResponse } from "./types.mjs";
|
|
3
4
|
export type AcrossOrderedTransaction = {
|
|
4
5
|
chainId: number;
|
|
@@ -15,4 +16,11 @@ export declare function getAcrossOrderedTransactions({ quote, swapType, }: {
|
|
|
15
16
|
quote: AcrossSwapApprovalResponse;
|
|
16
17
|
swapType?: TransactionType;
|
|
17
18
|
}): AcrossOrderedTransaction[];
|
|
19
|
+
/**
|
|
20
|
+
* Get a usable gas limit from the original or nested transaction.
|
|
21
|
+
*
|
|
22
|
+
* @param transaction - Original transaction metadata.
|
|
23
|
+
* @returns Positive integer gas limit if present, otherwise undefined.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getOriginalTransactionGas(transaction: TransactionMeta): number | undefined;
|
|
18
26
|
//# sourceMappingURL=transactions.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactions.d.mts","sourceRoot":"","sources":["../../../src/strategy/across/transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;
|
|
1
|
+
{"version":3,"file":"transactions.d.mts","sourceRoot":"","sources":["../../../src/strategy/across/transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAGxE,OAAO,KAAK,EAAE,0BAA0B,EAAE,oBAAgB;AAE1D,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,KAAK,MAAM,EAAE,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC;IAClB,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;CACvB,CAAC;AAEF,wBAAgB,4BAA4B,CAAC,EAC3C,KAAK,EACL,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,0BAA0B,CAAC;IAClC,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B,GAAG,wBAAwB,EAAE,CAiB7B;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,eAAe,GAC3B,MAAM,GAAG,SAAS,CAepB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TransactionType } from "@metamask/transaction-controller";
|
|
2
|
+
import { BigNumber } from "bignumber.js";
|
|
2
3
|
export function getAcrossOrderedTransactions({ quote, swapType, }) {
|
|
3
4
|
const swapChainId = quote.swapTx.chainId;
|
|
4
5
|
const approvalTransactions = (quote.approvalTxns ?? []).map((approval) => ({
|
|
@@ -16,4 +17,22 @@ export function getAcrossOrderedTransactions({ quote, swapType, }) {
|
|
|
16
17
|
},
|
|
17
18
|
];
|
|
18
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Get a usable gas limit from the original or nested transaction.
|
|
22
|
+
*
|
|
23
|
+
* @param transaction - Original transaction metadata.
|
|
24
|
+
* @returns Positive integer gas limit if present, otherwise undefined.
|
|
25
|
+
*/
|
|
26
|
+
export function getOriginalTransactionGas(transaction) {
|
|
27
|
+
const nestedGas = transaction.nestedTransactions?.find((tx) => tx.gas)?.gas;
|
|
28
|
+
const rawGas = nestedGas ?? transaction.txParams.gas;
|
|
29
|
+
if (rawGas === undefined) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const gas = new BigNumber(rawGas);
|
|
33
|
+
if (!gas.isFinite() || gas.isNaN() || !gas.isInteger() || gas.lte(0)) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
return gas.toNumber();
|
|
37
|
+
}
|
|
19
38
|
//# sourceMappingURL=transactions.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactions.mjs","sourceRoot":"","sources":["../../../src/strategy/across/transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;
|
|
1
|
+
{"version":3,"file":"transactions.mjs","sourceRoot":"","sources":["../../../src/strategy/across/transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;AAEnE,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAgBzC,MAAM,UAAU,4BAA4B,CAAC,EAC3C,KAAK,EACL,QAAQ,GAIT;IACC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC;IACzC,MAAM,oBAAoB,GAAG,CAAC,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACzE,GAAG,QAAQ;QACX,OAAO,EAAE,QAAQ,CAAC,OAAO,IAAI,WAAW;QACxC,IAAI,EAAE,UAAmB;QACzB,IAAI,EAAE,eAAe,CAAC,kBAAkB;KACzC,CAAC,CAAC,CAAC;IAEJ,OAAO;QACL,GAAG,oBAAoB;QACvB;YACE,GAAG,KAAK,CAAC,MAAM;YACf,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,QAAQ;SACf;KACF,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACvC,WAA4B;IAE5B,MAAM,SAAS,GAAG,WAAW,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC;IAC5E,MAAM,MAAM,GAAG,SAAS,IAAI,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC;IAErD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC;IAElC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACrE,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC","sourcesContent":["import { TransactionType } from '@metamask/transaction-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport { BigNumber } from 'bignumber.js';\n\nimport type { AcrossSwapApprovalResponse } from './types';\n\nexport type AcrossOrderedTransaction = {\n chainId: number;\n data: `0x${string}`;\n gas?: string;\n kind: 'approval' | 'swap';\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n to: `0x${string}`;\n type?: TransactionType;\n value?: `0x${string}`;\n};\n\nexport function getAcrossOrderedTransactions({\n quote,\n swapType,\n}: {\n quote: AcrossSwapApprovalResponse;\n swapType?: TransactionType;\n}): AcrossOrderedTransaction[] {\n const swapChainId = quote.swapTx.chainId;\n const approvalTransactions = (quote.approvalTxns ?? []).map((approval) => ({\n ...approval,\n chainId: approval.chainId ?? swapChainId,\n kind: 'approval' as const,\n type: TransactionType.tokenMethodApprove,\n }));\n\n return [\n ...approvalTransactions,\n {\n ...quote.swapTx,\n kind: 'swap',\n type: swapType,\n },\n ];\n}\n\n/**\n * Get a usable gas limit from the original or nested transaction.\n *\n * @param transaction - Original transaction metadata.\n * @returns Positive integer gas limit if present, otherwise undefined.\n */\nexport function getOriginalTransactionGas(\n transaction: TransactionMeta,\n): number | undefined {\n const nestedGas = transaction.nestedTransactions?.find((tx) => tx.gas)?.gas;\n const rawGas = nestedGas ?? transaction.txParams.gas;\n\n if (rawGas === undefined) {\n return undefined;\n }\n\n const gas = new BigNumber(rawGas);\n\n if (!gas.isFinite() || gas.isNaN() || !gas.isInteger() || gas.lte(0)) {\n return undefined;\n }\n\n return gas.toNumber();\n}\n"]}
|
|
@@ -244,7 +244,7 @@ exports.getPayStrategiesConfig = getPayStrategiesConfig;
|
|
|
244
244
|
function isRelayExecuteEnabled(messenger) {
|
|
245
245
|
const state = messenger.call('RemoteFeatureFlagController:getState');
|
|
246
246
|
const featureFlags = state.remoteFeatureFlags?.confirmations_pay ?? {};
|
|
247
|
-
return featureFlags.payStrategies?.relay?.
|
|
247
|
+
return featureFlags.payStrategies?.relay?.isGaslessEnabled ?? false;
|
|
248
248
|
}
|
|
249
249
|
exports.isRelayExecuteEnabled = isRelayExecuteEnabled;
|
|
250
250
|
/**
|