@metamask/transaction-controller 63.3.1 → 64.1.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 +31 -1
- package/dist/TransactionController.cjs +85 -103
- package/dist/TransactionController.cjs.map +1 -1
- package/dist/TransactionController.d.cts.map +1 -1
- package/dist/TransactionController.d.mts.map +1 -1
- package/dist/TransactionController.mjs +86 -108
- package/dist/TransactionController.mjs.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.cjs +22 -11
- package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.mjs +23 -12
- package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -1
- package/dist/helpers/AccountsApiRemoteTransactionSource.cjs +2 -2
- package/dist/helpers/AccountsApiRemoteTransactionSource.cjs.map +1 -1
- package/dist/helpers/AccountsApiRemoteTransactionSource.d.cts.map +1 -1
- package/dist/helpers/AccountsApiRemoteTransactionSource.d.mts.map +1 -1
- package/dist/helpers/AccountsApiRemoteTransactionSource.mjs +1 -1
- package/dist/helpers/AccountsApiRemoteTransactionSource.mjs.map +1 -1
- package/dist/helpers/GasFeePoller.cjs +5 -19
- package/dist/helpers/GasFeePoller.cjs.map +1 -1
- package/dist/helpers/GasFeePoller.d.cts +1 -6
- package/dist/helpers/GasFeePoller.d.cts.map +1 -1
- package/dist/helpers/GasFeePoller.d.mts +1 -6
- package/dist/helpers/GasFeePoller.d.mts.map +1 -1
- package/dist/helpers/GasFeePoller.mjs +5 -26
- package/dist/helpers/GasFeePoller.mjs.map +1 -1
- package/dist/helpers/MethodDataHelper.cjs +10 -6
- package/dist/helpers/MethodDataHelper.cjs.map +1 -1
- package/dist/helpers/MethodDataHelper.d.cts +4 -4
- package/dist/helpers/MethodDataHelper.d.cts.map +1 -1
- package/dist/helpers/MethodDataHelper.d.mts +4 -4
- package/dist/helpers/MethodDataHelper.d.mts.map +1 -1
- package/dist/helpers/MethodDataHelper.mjs +10 -6
- package/dist/helpers/MethodDataHelper.mjs.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.cjs +0 -2
- package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.d.cts +0 -2
- package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.d.mts +0 -2
- package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.mjs +0 -2
- package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -1
- package/dist/helpers/PendingTransactionTracker.cjs +38 -24
- package/dist/helpers/PendingTransactionTracker.cjs.map +1 -1
- package/dist/helpers/PendingTransactionTracker.d.cts +3 -7
- package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -1
- package/dist/helpers/PendingTransactionTracker.d.mts +3 -7
- package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -1
- package/dist/helpers/PendingTransactionTracker.mjs +38 -24
- package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
- package/dist/hooks/SequentialPublishBatchHook.cjs +4 -6
- package/dist/hooks/SequentialPublishBatchHook.cjs.map +1 -1
- package/dist/hooks/SequentialPublishBatchHook.d.cts +2 -4
- package/dist/hooks/SequentialPublishBatchHook.d.cts.map +1 -1
- package/dist/hooks/SequentialPublishBatchHook.d.mts +2 -4
- package/dist/hooks/SequentialPublishBatchHook.d.mts.map +1 -1
- package/dist/hooks/SequentialPublishBatchHook.mjs +4 -6
- package/dist/hooks/SequentialPublishBatchHook.mjs.map +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +14 -3
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +14 -3
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/balance-changes.cjs +2 -2
- package/dist/utils/balance-changes.cjs.map +1 -1
- package/dist/utils/balance-changes.d.cts +4 -2
- package/dist/utils/balance-changes.d.cts.map +1 -1
- package/dist/utils/balance-changes.d.mts +4 -2
- package/dist/utils/balance-changes.d.mts.map +1 -1
- package/dist/utils/balance-changes.mjs +2 -2
- package/dist/utils/balance-changes.mjs.map +1 -1
- package/dist/utils/balance.cjs +14 -10
- package/dist/utils/balance.cjs.map +1 -1
- package/dist/utils/balance.d.cts +8 -5
- package/dist/utils/balance.d.cts.map +1 -1
- package/dist/utils/balance.d.mts +8 -5
- package/dist/utils/balance.d.mts.map +1 -1
- package/dist/utils/balance.mjs +14 -10
- package/dist/utils/balance.mjs.map +1 -1
- package/dist/utils/batch.cjs +19 -19
- package/dist/utils/batch.cjs.map +1 -1
- package/dist/utils/batch.d.cts +1 -5
- package/dist/utils/batch.d.cts.map +1 -1
- package/dist/utils/batch.d.mts +1 -5
- package/dist/utils/batch.d.mts.map +1 -1
- package/dist/utils/batch.mjs +20 -20
- package/dist/utils/batch.mjs.map +1 -1
- package/dist/utils/eip7702.cjs +13 -6
- package/dist/utils/eip7702.cjs.map +1 -1
- package/dist/utils/eip7702.d.cts +6 -5
- package/dist/utils/eip7702.d.cts.map +1 -1
- package/dist/utils/eip7702.d.mts +6 -5
- package/dist/utils/eip7702.d.mts.map +1 -1
- package/dist/utils/eip7702.mjs +14 -7
- package/dist/utils/eip7702.mjs.map +1 -1
- package/dist/utils/gas-fee-tokens.cjs +4 -3
- package/dist/utils/gas-fee-tokens.cjs.map +1 -1
- package/dist/utils/gas-fee-tokens.d.cts +6 -4
- package/dist/utils/gas-fee-tokens.d.cts.map +1 -1
- package/dist/utils/gas-fee-tokens.d.mts +6 -4
- package/dist/utils/gas-fee-tokens.d.mts.map +1 -1
- package/dist/utils/gas-fee-tokens.mjs +4 -3
- package/dist/utils/gas-fee-tokens.mjs.map +1 -1
- package/dist/utils/gas-fees.cjs +8 -6
- package/dist/utils/gas-fees.cjs.map +1 -1
- package/dist/utils/gas-fees.d.cts +0 -2
- package/dist/utils/gas-fees.d.cts.map +1 -1
- package/dist/utils/gas-fees.d.mts +0 -2
- package/dist/utils/gas-fees.d.mts.map +1 -1
- package/dist/utils/gas-fees.mjs +9 -7
- package/dist/utils/gas-fees.mjs.map +1 -1
- package/dist/utils/gas.cjs +60 -34
- package/dist/utils/gas.cjs.map +1 -1
- package/dist/utils/gas.d.cts +6 -11
- package/dist/utils/gas.d.cts.map +1 -1
- package/dist/utils/gas.d.mts +6 -11
- package/dist/utils/gas.d.mts.map +1 -1
- package/dist/utils/gas.mjs +61 -35
- package/dist/utils/gas.mjs.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.cjs +7 -3
- package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.d.cts +2 -5
- package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.d.mts +2 -5
- package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -1
- package/dist/utils/layer1-gas-fee-flow.mjs +7 -3
- package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -1
- package/dist/utils/provider.cjs +74 -0
- package/dist/utils/provider.cjs.map +1 -0
- package/dist/utils/provider.d.cts +65 -0
- package/dist/utils/provider.d.cts.map +1 -0
- package/dist/utils/provider.d.mts +65 -0
- package/dist/utils/provider.d.mts.map +1 -0
- package/dist/utils/provider.mjs +67 -0
- package/dist/utils/provider.mjs.map +1 -0
- package/dist/utils/swaps.cjs +11 -7
- package/dist/utils/swaps.cjs.map +1 -1
- package/dist/utils/swaps.d.cts +6 -4
- package/dist/utils/swaps.d.cts.map +1 -1
- package/dist/utils/swaps.d.mts +6 -4
- package/dist/utils/swaps.d.mts.map +1 -1
- package/dist/utils/swaps.mjs +11 -7
- package/dist/utils/swaps.mjs.map +1 -1
- package/dist/utils/transaction-type.cjs +17 -8
- package/dist/utils/transaction-type.cjs.map +1 -1
- package/dist/utils/transaction-type.d.cts +9 -3
- package/dist/utils/transaction-type.d.cts.map +1 -1
- package/dist/utils/transaction-type.d.mts +9 -3
- package/dist/utils/transaction-type.d.mts.map +1 -1
- package/dist/utils/transaction-type.mjs +17 -8
- package/dist/utils/transaction-type.mjs.map +1 -1
- package/package.json +7 -6
package/dist/utils/gas.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { BNToHex, fractionBN, hexToBN,
|
|
1
|
+
import { BNToHex, fractionBN, hexToBN, toHex } from "@metamask/controller-utils";
|
|
2
2
|
import { add0x, createModuleLogger, remove0x } from "@metamask/utils";
|
|
3
3
|
import { BigNumber } from "bignumber.js";
|
|
4
4
|
import { DELEGATION_PREFIX, generateEIP7702BatchTransaction } from "./eip7702.mjs";
|
|
5
5
|
import { getGasEstimateBuffer, getGasEstimateFallback } from "./feature-flags.mjs";
|
|
6
|
+
import { getChainId, rpcRequest } from "./provider.mjs";
|
|
6
7
|
import { simulateTransactions } from "../api/simulation-api.mjs";
|
|
7
8
|
import { projectLogger } from "../logger.mjs";
|
|
8
9
|
import { TransactionEnvelopeType } from "../types.mjs";
|
|
@@ -35,22 +36,22 @@ export async function updateGas(request) {
|
|
|
35
36
|
* If the gas estimate fails, the fallback value is returned.
|
|
36
37
|
*
|
|
37
38
|
* @param options - The options object.
|
|
38
|
-
* @param options.chainId - The chain ID of the transaction.
|
|
39
|
-
* @param options.ethQuery - The EthQuery instance to interact with the network.
|
|
40
39
|
* @param options.ignoreDelegationSignatures - Ignore signature errors if submitting delegations to the DelegationManager.
|
|
41
40
|
* @param options.isSimulationEnabled - Whether the simulation is enabled.
|
|
42
41
|
* @param options.getSimulationConfig - The function to get the simulation configuration.
|
|
43
42
|
* @param options.messenger - The messenger instance for communication.
|
|
43
|
+
* @param options.networkClientId - The network client ID.
|
|
44
44
|
* @param options.txParams - The transaction parameters.
|
|
45
45
|
* @returns The estimated gas and related info.
|
|
46
46
|
*/
|
|
47
|
-
export async function estimateGas({
|
|
47
|
+
export async function estimateGas({ ignoreDelegationSignatures, isSimulationEnabled, getSimulationConfig, messenger, networkClientId, txParams, }) {
|
|
48
48
|
const request = { ...txParams };
|
|
49
49
|
const { authorizationList, data, from, value, to } = request;
|
|
50
|
+
const chainId = getChainId({ messenger, networkClientId });
|
|
50
51
|
if (ignoreDelegationSignatures && !isSimulationEnabled) {
|
|
51
52
|
throw new Error('Gas estimation with ignored delegation signatures is not supported as simulation disabled');
|
|
52
53
|
}
|
|
53
|
-
const { gasLimit: blockGasLimit, number: blockNumber } = await getLatestBlock(
|
|
54
|
+
const { gasLimit: blockGasLimit, number: blockNumber } = await getLatestBlock(messenger, networkClientId);
|
|
54
55
|
const blockGasLimitBN = hexToBN(blockGasLimit);
|
|
55
56
|
const { percentage, fixed } = getGasEstimateFallback(chainId, messenger);
|
|
56
57
|
const fallback = fixed
|
|
@@ -72,7 +73,7 @@ export async function estimateGas({ chainId, ethQuery, ignoreDelegationSignature
|
|
|
72
73
|
from?.toLowerCase() === to?.toLowerCase();
|
|
73
74
|
try {
|
|
74
75
|
if (isSimulationEnabled && isUpgradeWithDataToSelf) {
|
|
75
|
-
estimatedGas = await estimateGasUpgradeWithDataToSelf(request,
|
|
76
|
+
estimatedGas = await estimateGasUpgradeWithDataToSelf(request, messenger, networkClientId, chainId, getSimulationConfig);
|
|
76
77
|
}
|
|
77
78
|
else if (ignoreDelegationSignatures && isSimulationEnabled) {
|
|
78
79
|
estimatedGas = await simulateGas({
|
|
@@ -82,7 +83,7 @@ export async function estimateGas({ chainId, ethQuery, ignoreDelegationSignature
|
|
|
82
83
|
});
|
|
83
84
|
}
|
|
84
85
|
else {
|
|
85
|
-
estimatedGas = await estimateGasNode(
|
|
86
|
+
estimatedGas = await estimateGasNode(messenger, networkClientId, request);
|
|
86
87
|
}
|
|
87
88
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
89
|
}
|
|
@@ -104,7 +105,8 @@ export async function estimateGas({ chainId, ethQuery, ignoreDelegationSignature
|
|
|
104
105
|
simulationFails,
|
|
105
106
|
};
|
|
106
107
|
}
|
|
107
|
-
export async function estimateGasBatch({
|
|
108
|
+
export async function estimateGasBatch({ from, getSimulationConfig, isAtomicBatchSupported, messenger, networkClientId, transactions, }) {
|
|
109
|
+
const chainId = getChainId({ messenger, networkClientId });
|
|
108
110
|
const is7702Result = await isAtomicBatchSupported({
|
|
109
111
|
address: from,
|
|
110
112
|
chainIds: [chainId],
|
|
@@ -128,11 +130,10 @@ export async function estimateGasBatch({ chainId, ethQuery, from, getSimulationC
|
|
|
128
130
|
type,
|
|
129
131
|
};
|
|
130
132
|
const { estimatedGas: gasLimitHex } = await estimateGas({
|
|
131
|
-
chainId,
|
|
132
|
-
ethQuery,
|
|
133
133
|
isSimulationEnabled: true,
|
|
134
134
|
getSimulationConfig,
|
|
135
135
|
messenger,
|
|
136
|
+
networkClientId,
|
|
136
137
|
txParams: params,
|
|
137
138
|
});
|
|
138
139
|
const totalGasLimit = new BigNumber(gasLimitHex).toNumber();
|
|
@@ -235,7 +236,9 @@ export async function simulateGasBatch({ chainId, from, getSimulationConfig, tra
|
|
|
235
236
|
* @returns The final gas value and the estimate used.
|
|
236
237
|
*/
|
|
237
238
|
async function getGas(request) {
|
|
238
|
-
const {
|
|
239
|
+
const { isCustomNetwork, isSimulationEnabled, getSimulationConfig, messenger, txMeta, } = request;
|
|
240
|
+
const { networkClientId } = txMeta;
|
|
241
|
+
const chainId = getChainId({ messenger, networkClientId });
|
|
239
242
|
const { disableGasBuffer } = txMeta;
|
|
240
243
|
if (txMeta.txParams.gas) {
|
|
241
244
|
log('Using value from request', txMeta.txParams.gas);
|
|
@@ -246,11 +249,10 @@ async function getGas(request) {
|
|
|
246
249
|
return [FIXED_GAS, undefined, FIXED_GAS];
|
|
247
250
|
}
|
|
248
251
|
const { blockGasLimit, estimatedGas, isUpgradeWithDataToSelf, simulationFails, } = await estimateGas({
|
|
249
|
-
chainId,
|
|
250
|
-
ethQuery: request.ethQuery,
|
|
251
252
|
isSimulationEnabled,
|
|
252
253
|
getSimulationConfig,
|
|
253
254
|
messenger,
|
|
255
|
+
networkClientId,
|
|
254
256
|
txParams: txMeta.txParams,
|
|
255
257
|
});
|
|
256
258
|
log('Original estimated gas', estimatedGas);
|
|
@@ -278,57 +280,75 @@ async function getGas(request) {
|
|
|
278
280
|
* Determine if the gas for the provided request should be fixed.
|
|
279
281
|
*
|
|
280
282
|
* @param options - The options object.
|
|
281
|
-
* @param options.
|
|
283
|
+
* @param options.messenger - The messenger instance for communication.
|
|
282
284
|
* @param options.txMeta - The transaction meta object.
|
|
283
285
|
* @param options.isCustomNetwork - Whether the network is a custom network.
|
|
284
286
|
* @returns Whether the gas should be fixed.
|
|
285
287
|
*/
|
|
286
|
-
async function requiresFixedGas({
|
|
287
|
-
const { txParams: { to, data, type }, } = txMeta;
|
|
288
|
+
async function requiresFixedGas({ messenger, txMeta, isCustomNetwork, }) {
|
|
289
|
+
const { networkClientId, txParams: { to, data, type }, } = txMeta;
|
|
288
290
|
if (isCustomNetwork ||
|
|
289
291
|
!to ||
|
|
290
292
|
data ||
|
|
291
293
|
type === TransactionEnvelopeType.setCode) {
|
|
292
294
|
return false;
|
|
293
295
|
}
|
|
294
|
-
const code = await getCode(
|
|
296
|
+
const code = await getCode(messenger, networkClientId, to);
|
|
295
297
|
return !code || code === '0x';
|
|
296
298
|
}
|
|
297
299
|
/**
|
|
298
300
|
* Get the contract code for the provided address.
|
|
299
301
|
*
|
|
300
|
-
* @param
|
|
302
|
+
* @param messenger - The messenger instance for communication.
|
|
303
|
+
* @param networkClientId - The network client ID.
|
|
301
304
|
* @param address - The address to get the code for.
|
|
302
305
|
* @returns The contract code.
|
|
303
306
|
*/
|
|
304
|
-
async function getCode(
|
|
305
|
-
return await
|
|
307
|
+
async function getCode(messenger, networkClientId, address) {
|
|
308
|
+
return (await rpcRequest({
|
|
309
|
+
messenger,
|
|
310
|
+
networkClientId,
|
|
311
|
+
method: 'eth_getCode',
|
|
312
|
+
params: [address, 'latest'],
|
|
313
|
+
}));
|
|
306
314
|
}
|
|
307
315
|
/**
|
|
308
316
|
* Get the latest block from the network.
|
|
309
317
|
*
|
|
310
|
-
* @param
|
|
318
|
+
* @param messenger - The messenger instance for communication.
|
|
319
|
+
* @param networkClientId - The network client ID.
|
|
311
320
|
* @returns The latest block number.
|
|
312
321
|
*/
|
|
313
|
-
async function getLatestBlock(
|
|
314
|
-
return await
|
|
322
|
+
async function getLatestBlock(messenger, networkClientId) {
|
|
323
|
+
return (await rpcRequest({
|
|
324
|
+
messenger,
|
|
325
|
+
networkClientId,
|
|
326
|
+
method: 'eth_getBlockByNumber',
|
|
327
|
+
params: ['latest', false],
|
|
328
|
+
}));
|
|
315
329
|
}
|
|
316
330
|
/**
|
|
317
331
|
* Estimate the gas for a type 4 transaction.
|
|
318
332
|
*
|
|
319
333
|
* @param txParams - The transaction parameters.
|
|
320
|
-
* @param
|
|
334
|
+
* @param messenger - The messenger instance for communication.
|
|
335
|
+
* @param networkClientId - The network client ID.
|
|
321
336
|
* @param chainId - The chain ID of the transaction.
|
|
322
337
|
* @param getSimulationConfig - The function to get the simulation configuration.
|
|
323
338
|
* @returns The estimated gas.
|
|
324
339
|
*/
|
|
325
|
-
async function estimateGasUpgradeWithDataToSelf(txParams,
|
|
326
|
-
const upgradeGas = await
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
340
|
+
async function estimateGasUpgradeWithDataToSelf(txParams, messenger, networkClientId, chainId, getSimulationConfig) {
|
|
341
|
+
const upgradeGas = (await rpcRequest({
|
|
342
|
+
messenger,
|
|
343
|
+
networkClientId,
|
|
344
|
+
method: 'eth_estimateGas',
|
|
345
|
+
params: [
|
|
346
|
+
{
|
|
347
|
+
...txParams,
|
|
348
|
+
data: '0x',
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
}));
|
|
332
352
|
log('Upgrade only gas', upgradeGas);
|
|
333
353
|
const delegationAddress = txParams.authorizationList?.[0].address;
|
|
334
354
|
let executeGas;
|
|
@@ -345,7 +365,7 @@ async function estimateGasUpgradeWithDataToSelf(txParams, ethQuery, chainId, get
|
|
|
345
365
|
}
|
|
346
366
|
if (executeGas === undefined) {
|
|
347
367
|
try {
|
|
348
|
-
executeGas = await estimateGasNode(
|
|
368
|
+
executeGas = await estimateGasNode(messenger, networkClientId, { ...txParams, authorizationList: undefined, type: undefined }, delegationAddress);
|
|
349
369
|
}
|
|
350
370
|
catch (error) {
|
|
351
371
|
log('Error while estimating data portion of upgrade', error);
|
|
@@ -412,12 +432,13 @@ function normalizeAuthorizationList(authorizationList, chainId) {
|
|
|
412
432
|
/**
|
|
413
433
|
* Estimate the gas for a transaction using the `eth_estimateGas` method.
|
|
414
434
|
*
|
|
415
|
-
* @param
|
|
435
|
+
* @param messenger - The messenger instance for communication.
|
|
436
|
+
* @param networkClientId - The network client ID.
|
|
416
437
|
* @param txParams - The transaction parameters.
|
|
417
438
|
* @param delegationAddress - The delegation address of the sender to mock.
|
|
418
439
|
* @returns The estimated gas as a hex string.
|
|
419
440
|
*/
|
|
420
|
-
function estimateGasNode(
|
|
441
|
+
async function estimateGasNode(messenger, networkClientId, txParams, delegationAddress) {
|
|
421
442
|
const { from } = txParams;
|
|
422
443
|
const params = [txParams];
|
|
423
444
|
if (delegationAddress) {
|
|
@@ -428,6 +449,11 @@ function estimateGasNode(ethQuery, txParams, delegationAddress) {
|
|
|
428
449
|
},
|
|
429
450
|
});
|
|
430
451
|
}
|
|
431
|
-
return
|
|
452
|
+
return (await rpcRequest({
|
|
453
|
+
messenger,
|
|
454
|
+
networkClientId,
|
|
455
|
+
method: 'eth_estimateGas',
|
|
456
|
+
params,
|
|
457
|
+
}));
|
|
432
458
|
}
|
|
433
459
|
//# sourceMappingURL=gas.mjs.map
|
package/dist/utils/gas.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas.mjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,UAAU,EACV,OAAO,EACP,KAAK,EACL,KAAK,EACN,mCAAmC;AAGpC,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,wBAAwB;AACtE,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,OAAO,EAAE,iBAAiB,EAAE,+BAA+B,EAAE,sBAAkB;AAC/E,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,4BAAwB;AAC/E,OAAO,EAAE,oBAAoB,EAAE,kCAA8B;AAC7D,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAE1C,OAAO,EAAE,uBAAuB,EAAE,qBAAiB;AAsBnD,MAAM,CAAC,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;AAE5D,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAAC;AAClC,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAC1C,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACxC,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC;AAEnC,MAAM,CAAC,MAAM,6BAA6B,GACxC,oEAAoE,CAAC;AAEvE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,OAAyB;IACvD,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,aAAa,GAAG,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAE7C,MAAM,CAAC,GAAG,EAAE,eAAe,EAAE,gBAAgB,CAAC,GAAG,MAAM,MAAM,CAAC,OAA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,OAAO,iBAAiB,EAAE,GAAG,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;QAChD,GAAG,aAAa;QAChB,OAAO,EAAE,aAAa,CAAC,OAAO,IAAI,OAAO;QACzC,KAAK,EAAE,aAAa,CAAC,KAAK,IAAI,KAAK;QACnC,CAAC,EAAE,aAAa,CAAC,CAAC,IAAI,6BAA6B;QACnD,CAAC,EAAE,aAAa,CAAC,CAAC,IAAI,6BAA6B;QACnD,OAAO,EAAE,aAAa,CAAC,OAAO,IAAI,KAAK;KACxC,CAAC,CAAC,CAAC;AACN,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,eAAe,CACtB,QAAkB,EAClB,QAA2B,EAC3B,iBAAuB;IAEvB,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC;IAC1B,MAAM,MAAM,GAAG,CAAC,QAAQ,CAAW,CAAC;IAEpC,IAAI,iBAAiB,EAAE,CAAC;QACtB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEtB,MAAM,CAAC,IAAI,CAAC;YACV,CAAC,IAAI,CAAC,EAAE;gBACN,IAAI,EAAE,iBAAiB,GAAG,QAAQ,CAAC,iBAAiB,CAAC;aACtD;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,KAAK,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import {\n BNToHex,\n fractionBN,\n hexToBN,\n query,\n toHex,\n} from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport type { Hex, Json } from '@metamask/utils';\nimport { add0x, createModuleLogger, remove0x } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport { DELEGATION_PREFIX, generateEIP7702BatchTransaction } from './eip7702';\nimport { getGasEstimateBuffer, getGasEstimateFallback } from './feature-flags';\nimport { simulateTransactions } from '../api/simulation-api';\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport { TransactionEnvelopeType } from '../types';\nimport type {\n AuthorizationList,\n BatchTransactionParams,\n GetSimulationConfig,\n IsAtomicBatchSupportedRequest,\n IsAtomicBatchSupportedResult,\n TransactionBatchSingleRequest,\n TransactionMeta,\n TransactionParams,\n} from '../types';\n\nexport type UpdateGasRequest = {\n chainId: Hex;\n ethQuery: EthQuery;\n isCustomNetwork: boolean;\n isSimulationEnabled: boolean;\n getSimulationConfig: GetSimulationConfig;\n messenger: TransactionControllerMessenger;\n txMeta: TransactionMeta;\n};\n\nexport const log = createModuleLogger(projectLogger, 'gas');\n\nexport const FIXED_GAS = '0x5208';\nexport const DEFAULT_GAS_MULTIPLIER = 1.5;\nexport const MAX_GAS_BLOCK_PERCENT = 90;\nexport const INTRINSIC_GAS = 21000;\n\nexport const DUMMY_AUTHORIZATION_SIGNATURE =\n '0x1111111111111111111111111111111111111111111111111111111111111111';\n\n/**\n * Populate the gas properties of the provided transaction meta.\n *\n * @param request - The request object including the necessary parameters.\n */\nexport async function updateGas(request: UpdateGasRequest): Promise<void> {\n const { txMeta } = request;\n const initialParams = { ...txMeta.txParams };\n\n const [gas, simulationFails, gasLimitNoBuffer] = await getGas(request);\n\n txMeta.txParams.gas = gas;\n txMeta.simulationFails = simulationFails;\n txMeta.gasLimitNoBuffer = gasLimitNoBuffer;\n\n if (!initialParams.gas) {\n txMeta.originalGasEstimate = txMeta.txParams.gas;\n }\n\n txMeta.defaultGasEstimates ??= {};\n txMeta.defaultGasEstimates.gas = txMeta.txParams.gas;\n}\n\n/**\n * Estimate the gas for the provided transaction parameters.\n * If the gas estimate fails, the fallback value is returned.\n *\n * @param options - The options object.\n * @param options.chainId - The chain ID of the transaction.\n * @param options.ethQuery - The EthQuery instance to interact with the network.\n * @param options.ignoreDelegationSignatures - Ignore signature errors if submitting delegations to the DelegationManager.\n * @param options.isSimulationEnabled - Whether the simulation is enabled.\n * @param options.getSimulationConfig - The function to get the simulation configuration.\n * @param options.messenger - The messenger instance for communication.\n * @param options.txParams - The transaction parameters.\n * @returns The estimated gas and related info.\n */\nexport async function estimateGas({\n chainId,\n ethQuery,\n ignoreDelegationSignatures,\n isSimulationEnabled,\n getSimulationConfig,\n messenger,\n txParams,\n}: {\n chainId: Hex;\n ethQuery: EthQuery;\n ignoreDelegationSignatures?: boolean;\n isSimulationEnabled: boolean;\n getSimulationConfig: GetSimulationConfig;\n messenger: TransactionControllerMessenger;\n txParams: TransactionParams;\n}): Promise<{\n blockGasLimit: string;\n estimatedGas: string;\n isUpgradeWithDataToSelf: boolean;\n simulationFails: TransactionMeta['simulationFails'];\n}> {\n const request = { ...txParams };\n const { authorizationList, data, from, value, to } = request;\n\n if (ignoreDelegationSignatures && !isSimulationEnabled) {\n throw new Error(\n 'Gas estimation with ignored delegation signatures is not supported as simulation disabled',\n );\n }\n\n const { gasLimit: blockGasLimit, number: blockNumber } =\n await getLatestBlock(ethQuery);\n\n const blockGasLimitBN = hexToBN(blockGasLimit);\n const { percentage, fixed } = getGasEstimateFallback(chainId, messenger);\n\n const fallback = fixed\n ? toHex(fixed)\n : BNToHex(fractionBN(blockGasLimitBN, percentage, 100));\n\n log('Estimation fallback values', fallback);\n\n request.data = data ? add0x(data) : data;\n request.value = value ?? '0x0';\n\n request.authorizationList = normalizeAuthorizationList(\n request.authorizationList,\n chainId,\n );\n\n delete request.gasPrice;\n delete request.maxFeePerGas;\n delete request.maxPriorityFeePerGas;\n\n let estimatedGas = fallback;\n let simulationFails: TransactionMeta['simulationFails'];\n\n const isUpgradeWithDataToSelf =\n txParams.type === TransactionEnvelopeType.setCode &&\n Boolean(authorizationList?.length) &&\n Boolean(data) &&\n data !== '0x' &&\n from?.toLowerCase() === to?.toLowerCase();\n\n try {\n if (isSimulationEnabled && isUpgradeWithDataToSelf) {\n estimatedGas = await estimateGasUpgradeWithDataToSelf(\n request,\n ethQuery,\n chainId,\n getSimulationConfig,\n );\n } else if (ignoreDelegationSignatures && isSimulationEnabled) {\n estimatedGas = await simulateGas({\n chainId,\n getSimulationConfig,\n transaction: request,\n });\n } else {\n estimatedGas = await estimateGasNode(ethQuery, request);\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n simulationFails = {\n reason: error.message,\n errorKey: error.errorKey,\n debug: {\n blockNumber,\n blockGasLimit,\n },\n };\n\n log('Estimation failed', { ...simulationFails, fallback });\n }\n\n return {\n blockGasLimit,\n estimatedGas,\n isUpgradeWithDataToSelf,\n simulationFails,\n };\n}\n\nexport async function estimateGasBatch({\n chainId,\n ethQuery,\n from,\n getSimulationConfig,\n isAtomicBatchSupported,\n messenger,\n transactions,\n}: {\n chainId: Hex;\n ethQuery: EthQuery;\n from: Hex;\n getSimulationConfig: GetSimulationConfig;\n isAtomicBatchSupported: (\n request: IsAtomicBatchSupportedRequest,\n ) => Promise<IsAtomicBatchSupportedResult>;\n messenger: TransactionControllerMessenger;\n transactions: BatchTransactionParams[];\n}): Promise<{ totalGasLimit: number; gasLimits: number[] }> {\n const is7702Result = await isAtomicBatchSupported({\n address: from,\n chainIds: [chainId],\n });\n\n const chainResult = is7702Result.find((result) => result.chainId === chainId);\n const isUpgradeRequired = Boolean(chainResult && !chainResult.isSupported);\n\n if (isUpgradeRequired && !chainResult?.upgradeContractAddress) {\n throw new Error('Upgrade contract address not found');\n }\n\n if (chainResult) {\n const authorizationList = isUpgradeRequired\n ? [{ address: chainResult.upgradeContractAddress as Hex }]\n : undefined;\n\n const type = isUpgradeRequired\n ? TransactionEnvelopeType.setCode\n : undefined;\n\n const params: TransactionParams = {\n ...generateEIP7702BatchTransaction(from, transactions),\n authorizationList,\n from,\n type,\n };\n\n const { estimatedGas: gasLimitHex } = await estimateGas({\n chainId,\n ethQuery,\n isSimulationEnabled: true,\n getSimulationConfig,\n messenger,\n txParams: params,\n });\n\n const totalGasLimit = new BigNumber(gasLimitHex).toNumber();\n\n log('Estimated EIP-7702 gas limit', totalGasLimit);\n\n return { totalGasLimit, gasLimits: [totalGasLimit] };\n }\n\n const allTransactionsHaveGas = transactions.every(\n (transaction) => transaction.gas !== undefined,\n );\n\n if (allTransactionsHaveGas) {\n const gasLimits = transactions.map((transaction) =>\n new BigNumber(transaction.gas as Hex).toNumber(),\n );\n\n const total = gasLimits.reduce((acc, gasLimit) => acc + gasLimit, 0);\n\n log('Using batch parameter gas limits', { gasLimits, total });\n\n return { totalGasLimit: total, gasLimits };\n }\n\n const { gasLimits: gasLimitsHex } = await simulateGasBatch({\n chainId,\n from,\n getSimulationConfig,\n transactions: transactions.map((transaction) => ({\n params: transaction,\n })),\n });\n\n const gasLimits = transactions.map((transaction, index) =>\n transaction.gas\n ? new BigNumber(transaction.gas).toNumber()\n : new BigNumber(gasLimitsHex[index]).toNumber(),\n );\n\n const totalGasLimit = gasLimits.reduce((acc, gasLimit) => acc + gasLimit, 0);\n\n log('Simulated batch gas limits', { totalGasLimit, gasLimits });\n\n return { totalGasLimit, gasLimits };\n}\n\n/**\n * Add a buffer to the provided estimated gas.\n * The buffer is calculated based on the block gas limit and a multiplier.\n *\n * @param estimatedGas - The estimated gas.\n * @param blockGasLimit - The block gas limit.\n * @param multiplier - The multiplier to apply to the estimated gas.\n * @returns The gas with the buffer applied.\n */\nexport function addGasBuffer(\n estimatedGas: string,\n blockGasLimit: string,\n multiplier: number,\n): string {\n const estimatedGasBN = hexToBN(estimatedGas);\n\n const maxGasBN = fractionBN(\n hexToBN(blockGasLimit),\n MAX_GAS_BLOCK_PERCENT,\n 100,\n );\n\n const paddedGasBN = fractionBN(estimatedGasBN, multiplier * 100, 100);\n\n if (estimatedGasBN.gt(maxGasBN)) {\n const estimatedGasHex = add0x(estimatedGas);\n log('Using estimated value', estimatedGasHex);\n return estimatedGasHex;\n }\n\n if (paddedGasBN.lt(maxGasBN)) {\n const paddedHex = add0x(BNToHex(paddedGasBN));\n log('Using padded estimate', paddedHex, multiplier);\n return paddedHex;\n }\n\n const maxHex = add0x(BNToHex(maxGasBN));\n log('Using 90% of block gas limit', maxHex);\n return maxHex;\n}\n\n/**\n * Simulate the required gas for a batch of transactions using the simulation API.\n *\n * @param options - The options object.\n * @param options.chainId - The chain ID of the transactions.\n * @param options.from - The address of the sender.\n * @param options.getSimulationConfig - The function to get the simulation configuration.\n * @param options.transactions - The array of transactions within a batch request.\n * @returns An object containing the transactions with their gas limits and the total gas limit.\n */\nexport async function simulateGasBatch({\n chainId,\n from,\n getSimulationConfig,\n transactions,\n}: {\n chainId: Hex;\n from: Hex;\n getSimulationConfig: GetSimulationConfig;\n transactions: TransactionBatchSingleRequest[];\n}): Promise<{ totalGasLimit: Hex; gasLimits: Hex[] }> {\n try {\n const response = await simulateTransactions(chainId, {\n getSimulationConfig,\n transactions: transactions.map((transaction) => ({\n ...transaction.params,\n from,\n })),\n });\n\n if (response?.transactions?.length !== transactions.length) {\n throw new Error('Simulation response does not match transaction count');\n }\n\n return response.transactions.reduce<{\n totalGasLimit: Hex;\n gasLimits: Hex[];\n }>(\n (acc, transaction) => {\n const gasLimit = transaction?.gasLimit;\n\n if (!gasLimit) {\n throw new Error(\n 'No simulated gas returned for one of the transactions',\n );\n }\n\n acc.gasLimits.push(gasLimit);\n\n acc.totalGasLimit = BNToHex(\n hexToBN(acc.totalGasLimit).add(hexToBN(gasLimit)),\n );\n\n return acc;\n },\n {\n totalGasLimit: '0x0',\n gasLimits: [],\n },\n );\n } catch (error: unknown) {\n log('Error while simulating gas batch', error);\n throw new Error(\n 'Cannot estimate transaction batch total gas as simulation failed',\n );\n }\n}\n\n/**\n * Determine the gas for the provided request.\n *\n * @param request - The request object including the necessary parameters.\n * @returns The final gas value and the estimate used.\n */\nasync function getGas(\n request: UpdateGasRequest,\n): Promise<[string, TransactionMeta['simulationFails']?, string?]> {\n const {\n chainId,\n isCustomNetwork,\n isSimulationEnabled,\n getSimulationConfig,\n messenger,\n txMeta,\n } = request;\n const { disableGasBuffer } = txMeta;\n\n if (txMeta.txParams.gas) {\n log('Using value from request', txMeta.txParams.gas);\n return [txMeta.txParams.gas, undefined, txMeta.txParams.gas];\n }\n\n if (await requiresFixedGas(request)) {\n log('Using fixed value', FIXED_GAS);\n return [FIXED_GAS, undefined, FIXED_GAS];\n }\n\n const {\n blockGasLimit,\n estimatedGas,\n isUpgradeWithDataToSelf,\n simulationFails,\n } = await estimateGas({\n chainId,\n ethQuery: request.ethQuery,\n isSimulationEnabled,\n getSimulationConfig,\n messenger,\n txParams: txMeta.txParams,\n });\n\n log('Original estimated gas', estimatedGas);\n\n if (simulationFails) {\n log('Using original fallback estimate as simulation failed');\n }\n\n if (disableGasBuffer) {\n log('Gas buffer disabled');\n }\n\n if (simulationFails || disableGasBuffer) {\n return [estimatedGas, simulationFails, estimatedGas];\n }\n\n const bufferMultiplier = getGasEstimateBuffer({\n chainId,\n isCustomRPC: isCustomNetwork,\n isUpgradeWithDataToSelf,\n messenger,\n });\n\n log('Buffer', bufferMultiplier);\n\n const bufferedGas = addGasBuffer(\n estimatedGas,\n blockGasLimit,\n bufferMultiplier,\n );\n\n log('Buffered gas', bufferedGas);\n\n return [bufferedGas, simulationFails, estimatedGas];\n}\n\n/**\n * Determine if the gas for the provided request should be fixed.\n *\n * @param options - The options object.\n * @param options.ethQuery - The EthQuery instance to interact with the network.\n * @param options.txMeta - The transaction meta object.\n * @param options.isCustomNetwork - Whether the network is a custom network.\n * @returns Whether the gas should be fixed.\n */\nasync function requiresFixedGas({\n ethQuery,\n txMeta,\n isCustomNetwork,\n}: UpdateGasRequest): Promise<boolean> {\n const {\n txParams: { to, data, type },\n } = txMeta;\n\n if (\n isCustomNetwork ||\n !to ||\n data ||\n type === TransactionEnvelopeType.setCode\n ) {\n return false;\n }\n\n const code = await getCode(ethQuery, to);\n\n return !code || code === '0x';\n}\n\n/**\n * Get the contract code for the provided address.\n *\n * @param ethQuery - The EthQuery instance to interact with the network.\n * @param address - The address to get the code for.\n * @returns The contract code.\n */\nasync function getCode(\n ethQuery: EthQuery,\n address: string,\n): Promise<string | undefined> {\n return await query(ethQuery, 'getCode', [address]);\n}\n\n/**\n * Get the latest block from the network.\n *\n * @param ethQuery - The EthQuery instance to interact with the network.\n * @returns The latest block number.\n */\nasync function getLatestBlock(\n ethQuery: EthQuery,\n): Promise<{ gasLimit: string; number: string }> {\n return await query(ethQuery, 'getBlockByNumber', ['latest', false]);\n}\n\n/**\n * Estimate the gas for a type 4 transaction.\n *\n * @param txParams - The transaction parameters.\n * @param ethQuery - The EthQuery instance to interact with the network.\n * @param chainId - The chain ID of the transaction.\n * @param getSimulationConfig - The function to get the simulation configuration.\n * @returns The estimated gas.\n */\nasync function estimateGasUpgradeWithDataToSelf(\n txParams: TransactionParams,\n ethQuery: EthQuery,\n chainId: Hex,\n getSimulationConfig: GetSimulationConfig,\n): Promise<Hex> {\n const upgradeGas = await query(ethQuery, 'estimateGas', [\n {\n ...txParams,\n data: '0x',\n },\n ]);\n\n log('Upgrade only gas', upgradeGas);\n\n const delegationAddress = txParams.authorizationList?.[0].address as Hex;\n\n let executeGas: Hex | undefined;\n\n try {\n executeGas = await simulateGas({\n chainId,\n delegationAddress,\n getSimulationConfig,\n transaction: txParams,\n });\n } catch (error: unknown) {\n log('Error while simulating data portion of upgrade', error);\n }\n\n if (executeGas === undefined) {\n try {\n executeGas = await estimateGasNode(\n ethQuery,\n { ...txParams, authorizationList: undefined, type: undefined },\n delegationAddress,\n );\n } catch (error: unknown) {\n log('Error while estimating data portion of upgrade', error);\n throw error;\n }\n\n log('Success estimating data portion of upgrade', executeGas);\n }\n\n log('Execute gas', executeGas);\n\n const total = BNToHex(\n hexToBN(upgradeGas).add(hexToBN(executeGas)).subn(INTRINSIC_GAS),\n );\n\n log('Total type 4 gas', total);\n\n return total;\n}\n\n/**\n * Simulate the required gas using the simulation API.\n *\n * @param options - The options object.\n * @param options.chainId - The chain ID of the transaction.\n * @param options.delegationAddress - The delegation address of the sender to mock.\n * @param options.getSimulationConfig - The function to get the simulation configuration.\n * @param options.transaction - The transaction parameters.\n * @returns The simulated gas.\n */\nasync function simulateGas({\n chainId,\n delegationAddress,\n getSimulationConfig,\n transaction,\n}: {\n chainId: Hex;\n delegationAddress?: Hex;\n getSimulationConfig: GetSimulationConfig;\n transaction: TransactionParams;\n}): Promise<Hex> {\n const response = await simulateTransactions(chainId, {\n getSimulationConfig,\n transactions: [\n {\n to: transaction.to as Hex,\n from: transaction.from as Hex,\n data: transaction.data as Hex,\n value: transaction.value as Hex,\n },\n ],\n overrides: {\n [transaction.from]: {\n code:\n delegationAddress &&\n ((DELEGATION_PREFIX + remove0x(delegationAddress)) as Hex),\n },\n },\n });\n\n const gasLimit = response?.transactions?.[0].gasLimit;\n\n if (!gasLimit) {\n throw new Error('No simulated gas returned');\n }\n\n return gasLimit;\n}\n\n/**\n * Populate the authorization list with dummy values.\n *\n * @param authorizationList - The authorization list to prepare.\n * @param chainId - The chain ID to use.\n * @returns The authorization list with dummy values.\n */\nfunction normalizeAuthorizationList(\n authorizationList: AuthorizationList | undefined,\n chainId: Hex,\n): AuthorizationList | undefined {\n return authorizationList?.map((authorization) => ({\n ...authorization,\n chainId: authorization.chainId ?? chainId,\n nonce: authorization.nonce ?? '0x1',\n r: authorization.r ?? DUMMY_AUTHORIZATION_SIGNATURE,\n s: authorization.s ?? DUMMY_AUTHORIZATION_SIGNATURE,\n yParity: authorization.yParity ?? '0x1',\n }));\n}\n\n/**\n * Estimate the gas for a transaction using the `eth_estimateGas` method.\n *\n * @param ethQuery - The EthQuery instance to interact with the network.\n * @param txParams - The transaction parameters.\n * @param delegationAddress - The delegation address of the sender to mock.\n * @returns The estimated gas as a hex string.\n */\nfunction estimateGasNode(\n ethQuery: EthQuery,\n txParams: TransactionParams,\n delegationAddress?: Hex,\n): Promise<Hex> {\n const { from } = txParams;\n const params = [txParams] as Json[];\n\n if (delegationAddress) {\n params.push('latest');\n\n params.push({\n [from]: {\n code: DELEGATION_PREFIX + remove0x(delegationAddress),\n },\n });\n }\n\n return query(ethQuery, 'estimateGas', params);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"gas.mjs","sourceRoot":"","sources":["../../src/utils/gas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iBAAiB;QACzB,MAAM;KACP,CAAC,CAAQ,CAAC;AACb,CAAC","sourcesContent":["import {\n BNToHex,\n fractionBN,\n hexToBN,\n toHex,\n} from '@metamask/controller-utils';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport type { Hex, Json } from '@metamask/utils';\nimport { add0x, createModuleLogger, remove0x } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport { DELEGATION_PREFIX, generateEIP7702BatchTransaction } from './eip7702';\nimport { getGasEstimateBuffer, getGasEstimateFallback } from './feature-flags';\nimport { getChainId, rpcRequest } from './provider';\nimport { simulateTransactions } from '../api/simulation-api';\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport { TransactionEnvelopeType } from '../types';\nimport type {\n AuthorizationList,\n BatchTransactionParams,\n GetSimulationConfig,\n IsAtomicBatchSupportedRequest,\n IsAtomicBatchSupportedResult,\n TransactionBatchSingleRequest,\n TransactionMeta,\n TransactionParams,\n} from '../types';\n\nexport type UpdateGasRequest = {\n isCustomNetwork: boolean;\n isSimulationEnabled: boolean;\n getSimulationConfig: GetSimulationConfig;\n messenger: TransactionControllerMessenger;\n txMeta: TransactionMeta;\n};\n\nexport const log = createModuleLogger(projectLogger, 'gas');\n\nexport const FIXED_GAS = '0x5208';\nexport const DEFAULT_GAS_MULTIPLIER = 1.5;\nexport const MAX_GAS_BLOCK_PERCENT = 90;\nexport const INTRINSIC_GAS = 21000;\n\nexport const DUMMY_AUTHORIZATION_SIGNATURE =\n '0x1111111111111111111111111111111111111111111111111111111111111111';\n\n/**\n * Populate the gas properties of the provided transaction meta.\n *\n * @param request - The request object including the necessary parameters.\n */\nexport async function updateGas(request: UpdateGasRequest): Promise<void> {\n const { txMeta } = request;\n const initialParams = { ...txMeta.txParams };\n\n const [gas, simulationFails, gasLimitNoBuffer] = await getGas(request);\n\n txMeta.txParams.gas = gas;\n txMeta.simulationFails = simulationFails;\n txMeta.gasLimitNoBuffer = gasLimitNoBuffer;\n\n if (!initialParams.gas) {\n txMeta.originalGasEstimate = txMeta.txParams.gas;\n }\n\n txMeta.defaultGasEstimates ??= {};\n txMeta.defaultGasEstimates.gas = txMeta.txParams.gas;\n}\n\n/**\n * Estimate the gas for the provided transaction parameters.\n * If the gas estimate fails, the fallback value is returned.\n *\n * @param options - The options object.\n * @param options.ignoreDelegationSignatures - Ignore signature errors if submitting delegations to the DelegationManager.\n * @param options.isSimulationEnabled - Whether the simulation is enabled.\n * @param options.getSimulationConfig - The function to get the simulation configuration.\n * @param options.messenger - The messenger instance for communication.\n * @param options.networkClientId - The network client ID.\n * @param options.txParams - The transaction parameters.\n * @returns The estimated gas and related info.\n */\nexport async function estimateGas({\n ignoreDelegationSignatures,\n isSimulationEnabled,\n getSimulationConfig,\n messenger,\n networkClientId,\n txParams,\n}: {\n ignoreDelegationSignatures?: boolean;\n isSimulationEnabled: boolean;\n getSimulationConfig: GetSimulationConfig;\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n txParams: TransactionParams;\n}): Promise<{\n blockGasLimit: string;\n estimatedGas: string;\n isUpgradeWithDataToSelf: boolean;\n simulationFails: TransactionMeta['simulationFails'];\n}> {\n const request = { ...txParams };\n const { authorizationList, data, from, value, to } = request;\n const chainId = getChainId({ messenger, networkClientId });\n\n if (ignoreDelegationSignatures && !isSimulationEnabled) {\n throw new Error(\n 'Gas estimation with ignored delegation signatures is not supported as simulation disabled',\n );\n }\n\n const { gasLimit: blockGasLimit, number: blockNumber } = await getLatestBlock(\n messenger,\n networkClientId,\n );\n\n const blockGasLimitBN = hexToBN(blockGasLimit);\n const { percentage, fixed } = getGasEstimateFallback(chainId, messenger);\n\n const fallback = fixed\n ? toHex(fixed)\n : BNToHex(fractionBN(blockGasLimitBN, percentage, 100));\n\n log('Estimation fallback values', fallback);\n\n request.data = data ? add0x(data) : data;\n request.value = value ?? '0x0';\n\n request.authorizationList = normalizeAuthorizationList(\n request.authorizationList,\n chainId,\n );\n\n delete request.gasPrice;\n delete request.maxFeePerGas;\n delete request.maxPriorityFeePerGas;\n\n let estimatedGas = fallback;\n let simulationFails: TransactionMeta['simulationFails'];\n\n const isUpgradeWithDataToSelf =\n txParams.type === TransactionEnvelopeType.setCode &&\n Boolean(authorizationList?.length) &&\n Boolean(data) &&\n data !== '0x' &&\n from?.toLowerCase() === to?.toLowerCase();\n\n try {\n if (isSimulationEnabled && isUpgradeWithDataToSelf) {\n estimatedGas = await estimateGasUpgradeWithDataToSelf(\n request,\n messenger,\n networkClientId,\n chainId,\n getSimulationConfig,\n );\n } else if (ignoreDelegationSignatures && isSimulationEnabled) {\n estimatedGas = await simulateGas({\n chainId,\n getSimulationConfig,\n transaction: request,\n });\n } else {\n estimatedGas = await estimateGasNode(messenger, networkClientId, request);\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n simulationFails = {\n reason: error.message,\n errorKey: error.errorKey,\n debug: {\n blockNumber,\n blockGasLimit,\n },\n };\n\n log('Estimation failed', { ...simulationFails, fallback });\n }\n\n return {\n blockGasLimit,\n estimatedGas,\n isUpgradeWithDataToSelf,\n simulationFails,\n };\n}\n\nexport async function estimateGasBatch({\n from,\n getSimulationConfig,\n isAtomicBatchSupported,\n messenger,\n networkClientId,\n transactions,\n}: {\n from: Hex;\n getSimulationConfig: GetSimulationConfig;\n isAtomicBatchSupported: (\n request: IsAtomicBatchSupportedRequest,\n ) => Promise<IsAtomicBatchSupportedResult>;\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n transactions: BatchTransactionParams[];\n}): Promise<{ totalGasLimit: number; gasLimits: number[] }> {\n const chainId = getChainId({ messenger, networkClientId });\n\n const is7702Result = await isAtomicBatchSupported({\n address: from,\n chainIds: [chainId],\n });\n\n const chainResult = is7702Result.find((result) => result.chainId === chainId);\n const isUpgradeRequired = Boolean(chainResult && !chainResult.isSupported);\n\n if (isUpgradeRequired && !chainResult?.upgradeContractAddress) {\n throw new Error('Upgrade contract address not found');\n }\n\n if (chainResult) {\n const authorizationList = isUpgradeRequired\n ? [{ address: chainResult.upgradeContractAddress as Hex }]\n : undefined;\n\n const type = isUpgradeRequired\n ? TransactionEnvelopeType.setCode\n : undefined;\n\n const params: TransactionParams = {\n ...generateEIP7702BatchTransaction(from, transactions),\n authorizationList,\n from,\n type,\n };\n\n const { estimatedGas: gasLimitHex } = await estimateGas({\n isSimulationEnabled: true,\n getSimulationConfig,\n messenger,\n networkClientId,\n txParams: params,\n });\n\n const totalGasLimit = new BigNumber(gasLimitHex).toNumber();\n\n log('Estimated EIP-7702 gas limit', totalGasLimit);\n\n return { totalGasLimit, gasLimits: [totalGasLimit] };\n }\n\n const allTransactionsHaveGas = transactions.every(\n (transaction) => transaction.gas !== undefined,\n );\n\n if (allTransactionsHaveGas) {\n const gasLimits = transactions.map((transaction) =>\n new BigNumber(transaction.gas as Hex).toNumber(),\n );\n\n const total = gasLimits.reduce((acc, gasLimit) => acc + gasLimit, 0);\n\n log('Using batch parameter gas limits', { gasLimits, total });\n\n return { totalGasLimit: total, gasLimits };\n }\n\n const { gasLimits: gasLimitsHex } = await simulateGasBatch({\n chainId,\n from,\n getSimulationConfig,\n transactions: transactions.map((transaction) => ({\n params: transaction,\n })),\n });\n\n const gasLimits = transactions.map((transaction, index) =>\n transaction.gas\n ? new BigNumber(transaction.gas).toNumber()\n : new BigNumber(gasLimitsHex[index]).toNumber(),\n );\n\n const totalGasLimit = gasLimits.reduce((acc, gasLimit) => acc + gasLimit, 0);\n\n log('Simulated batch gas limits', { totalGasLimit, gasLimits });\n\n return { totalGasLimit, gasLimits };\n}\n\n/**\n * Add a buffer to the provided estimated gas.\n * The buffer is calculated based on the block gas limit and a multiplier.\n *\n * @param estimatedGas - The estimated gas.\n * @param blockGasLimit - The block gas limit.\n * @param multiplier - The multiplier to apply to the estimated gas.\n * @returns The gas with the buffer applied.\n */\nexport function addGasBuffer(\n estimatedGas: string,\n blockGasLimit: string,\n multiplier: number,\n): string {\n const estimatedGasBN = hexToBN(estimatedGas);\n\n const maxGasBN = fractionBN(\n hexToBN(blockGasLimit),\n MAX_GAS_BLOCK_PERCENT,\n 100,\n );\n\n const paddedGasBN = fractionBN(estimatedGasBN, multiplier * 100, 100);\n\n if (estimatedGasBN.gt(maxGasBN)) {\n const estimatedGasHex = add0x(estimatedGas);\n log('Using estimated value', estimatedGasHex);\n return estimatedGasHex;\n }\n\n if (paddedGasBN.lt(maxGasBN)) {\n const paddedHex = add0x(BNToHex(paddedGasBN));\n log('Using padded estimate', paddedHex, multiplier);\n return paddedHex;\n }\n\n const maxHex = add0x(BNToHex(maxGasBN));\n log('Using 90% of block gas limit', maxHex);\n return maxHex;\n}\n\n/**\n * Simulate the required gas for a batch of transactions using the simulation API.\n *\n * @param options - The options object.\n * @param options.chainId - The chain ID of the transactions.\n * @param options.from - The address of the sender.\n * @param options.getSimulationConfig - The function to get the simulation configuration.\n * @param options.transactions - The array of transactions within a batch request.\n * @returns An object containing the transactions with their gas limits and the total gas limit.\n */\nexport async function simulateGasBatch({\n chainId,\n from,\n getSimulationConfig,\n transactions,\n}: {\n chainId: Hex;\n from: Hex;\n getSimulationConfig: GetSimulationConfig;\n transactions: TransactionBatchSingleRequest[];\n}): Promise<{ totalGasLimit: Hex; gasLimits: Hex[] }> {\n try {\n const response = await simulateTransactions(chainId, {\n getSimulationConfig,\n transactions: transactions.map((transaction) => ({\n ...transaction.params,\n from,\n })),\n });\n\n if (response?.transactions?.length !== transactions.length) {\n throw new Error('Simulation response does not match transaction count');\n }\n\n return response.transactions.reduce<{\n totalGasLimit: Hex;\n gasLimits: Hex[];\n }>(\n (acc, transaction) => {\n const gasLimit = transaction?.gasLimit;\n\n if (!gasLimit) {\n throw new Error(\n 'No simulated gas returned for one of the transactions',\n );\n }\n\n acc.gasLimits.push(gasLimit);\n\n acc.totalGasLimit = BNToHex(\n hexToBN(acc.totalGasLimit).add(hexToBN(gasLimit)),\n );\n\n return acc;\n },\n {\n totalGasLimit: '0x0',\n gasLimits: [],\n },\n );\n } catch (error: unknown) {\n log('Error while simulating gas batch', error);\n throw new Error(\n 'Cannot estimate transaction batch total gas as simulation failed',\n );\n }\n}\n\n/**\n * Determine the gas for the provided request.\n *\n * @param request - The request object including the necessary parameters.\n * @returns The final gas value and the estimate used.\n */\nasync function getGas(\n request: UpdateGasRequest,\n): Promise<[string, TransactionMeta['simulationFails']?, string?]> {\n const {\n isCustomNetwork,\n isSimulationEnabled,\n getSimulationConfig,\n messenger,\n txMeta,\n } = request;\n const { networkClientId } = txMeta;\n const chainId = getChainId({ messenger, networkClientId });\n const { disableGasBuffer } = txMeta;\n\n if (txMeta.txParams.gas) {\n log('Using value from request', txMeta.txParams.gas);\n return [txMeta.txParams.gas, undefined, txMeta.txParams.gas];\n }\n\n if (await requiresFixedGas(request)) {\n log('Using fixed value', FIXED_GAS);\n return [FIXED_GAS, undefined, FIXED_GAS];\n }\n\n const {\n blockGasLimit,\n estimatedGas,\n isUpgradeWithDataToSelf,\n simulationFails,\n } = await estimateGas({\n isSimulationEnabled,\n getSimulationConfig,\n messenger,\n networkClientId,\n txParams: txMeta.txParams,\n });\n\n log('Original estimated gas', estimatedGas);\n\n if (simulationFails) {\n log('Using original fallback estimate as simulation failed');\n }\n\n if (disableGasBuffer) {\n log('Gas buffer disabled');\n }\n\n if (simulationFails || disableGasBuffer) {\n return [estimatedGas, simulationFails, estimatedGas];\n }\n\n const bufferMultiplier = getGasEstimateBuffer({\n chainId,\n isCustomRPC: isCustomNetwork,\n isUpgradeWithDataToSelf,\n messenger,\n });\n\n log('Buffer', bufferMultiplier);\n\n const bufferedGas = addGasBuffer(\n estimatedGas,\n blockGasLimit,\n bufferMultiplier,\n );\n\n log('Buffered gas', bufferedGas);\n\n return [bufferedGas, simulationFails, estimatedGas];\n}\n\n/**\n * Determine if the gas for the provided request should be fixed.\n *\n * @param options - The options object.\n * @param options.messenger - The messenger instance for communication.\n * @param options.txMeta - The transaction meta object.\n * @param options.isCustomNetwork - Whether the network is a custom network.\n * @returns Whether the gas should be fixed.\n */\nasync function requiresFixedGas({\n messenger,\n txMeta,\n isCustomNetwork,\n}: UpdateGasRequest): Promise<boolean> {\n const {\n networkClientId,\n txParams: { to, data, type },\n } = txMeta;\n\n if (\n isCustomNetwork ||\n !to ||\n data ||\n type === TransactionEnvelopeType.setCode\n ) {\n return false;\n }\n\n const code = await getCode(messenger, networkClientId, to);\n\n return !code || code === '0x';\n}\n\n/**\n * Get the contract code for the provided address.\n *\n * @param messenger - The messenger instance for communication.\n * @param networkClientId - The network client ID.\n * @param address - The address to get the code for.\n * @returns The contract code.\n */\nasync function getCode(\n messenger: TransactionControllerMessenger,\n networkClientId: NetworkClientId,\n address: string,\n): Promise<string | undefined> {\n return (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_getCode',\n params: [address, 'latest'],\n })) as string | undefined;\n}\n\n/**\n * Get the latest block from the network.\n *\n * @param messenger - The messenger instance for communication.\n * @param networkClientId - The network client ID.\n * @returns The latest block number.\n */\nasync function getLatestBlock(\n messenger: TransactionControllerMessenger,\n networkClientId: NetworkClientId,\n): Promise<{ gasLimit: string; number: string }> {\n return (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_getBlockByNumber',\n params: ['latest', false],\n })) as { gasLimit: string; number: string };\n}\n\n/**\n * Estimate the gas for a type 4 transaction.\n *\n * @param txParams - The transaction parameters.\n * @param messenger - The messenger instance for communication.\n * @param networkClientId - The network client ID.\n * @param chainId - The chain ID of the transaction.\n * @param getSimulationConfig - The function to get the simulation configuration.\n * @returns The estimated gas.\n */\nasync function estimateGasUpgradeWithDataToSelf(\n txParams: TransactionParams,\n messenger: TransactionControllerMessenger,\n networkClientId: NetworkClientId,\n chainId: Hex,\n getSimulationConfig: GetSimulationConfig,\n): Promise<Hex> {\n const upgradeGas = (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_estimateGas',\n params: [\n {\n ...txParams,\n data: '0x',\n },\n ],\n })) as Hex;\n\n log('Upgrade only gas', upgradeGas);\n\n const delegationAddress = txParams.authorizationList?.[0].address as Hex;\n\n let executeGas: Hex | undefined;\n\n try {\n executeGas = await simulateGas({\n chainId,\n delegationAddress,\n getSimulationConfig,\n transaction: txParams,\n });\n } catch (error: unknown) {\n log('Error while simulating data portion of upgrade', error);\n }\n\n if (executeGas === undefined) {\n try {\n executeGas = await estimateGasNode(\n messenger,\n networkClientId,\n { ...txParams, authorizationList: undefined, type: undefined },\n delegationAddress,\n );\n } catch (error: unknown) {\n log('Error while estimating data portion of upgrade', error);\n throw error;\n }\n\n log('Success estimating data portion of upgrade', executeGas);\n }\n\n log('Execute gas', executeGas);\n\n const total = BNToHex(\n hexToBN(upgradeGas).add(hexToBN(executeGas)).subn(INTRINSIC_GAS),\n );\n\n log('Total type 4 gas', total);\n\n return total;\n}\n\n/**\n * Simulate the required gas using the simulation API.\n *\n * @param options - The options object.\n * @param options.chainId - The chain ID of the transaction.\n * @param options.delegationAddress - The delegation address of the sender to mock.\n * @param options.getSimulationConfig - The function to get the simulation configuration.\n * @param options.transaction - The transaction parameters.\n * @returns The simulated gas.\n */\nasync function simulateGas({\n chainId,\n delegationAddress,\n getSimulationConfig,\n transaction,\n}: {\n chainId: Hex;\n delegationAddress?: Hex;\n getSimulationConfig: GetSimulationConfig;\n transaction: TransactionParams;\n}): Promise<Hex> {\n const response = await simulateTransactions(chainId, {\n getSimulationConfig,\n transactions: [\n {\n to: transaction.to as Hex,\n from: transaction.from as Hex,\n data: transaction.data as Hex,\n value: transaction.value as Hex,\n },\n ],\n overrides: {\n [transaction.from]: {\n code:\n delegationAddress &&\n ((DELEGATION_PREFIX + remove0x(delegationAddress)) as Hex),\n },\n },\n });\n\n const gasLimit = response?.transactions?.[0].gasLimit;\n\n if (!gasLimit) {\n throw new Error('No simulated gas returned');\n }\n\n return gasLimit;\n}\n\n/**\n * Populate the authorization list with dummy values.\n *\n * @param authorizationList - The authorization list to prepare.\n * @param chainId - The chain ID to use.\n * @returns The authorization list with dummy values.\n */\nfunction normalizeAuthorizationList(\n authorizationList: AuthorizationList | undefined,\n chainId: Hex,\n): AuthorizationList | undefined {\n return authorizationList?.map((authorization) => ({\n ...authorization,\n chainId: authorization.chainId ?? chainId,\n nonce: authorization.nonce ?? '0x1',\n r: authorization.r ?? DUMMY_AUTHORIZATION_SIGNATURE,\n s: authorization.s ?? DUMMY_AUTHORIZATION_SIGNATURE,\n yParity: authorization.yParity ?? '0x1',\n }));\n}\n\n/**\n * Estimate the gas for a transaction using the `eth_estimateGas` method.\n *\n * @param messenger - The messenger instance for communication.\n * @param networkClientId - The network client ID.\n * @param txParams - The transaction parameters.\n * @param delegationAddress - The delegation address of the sender to mock.\n * @returns The estimated gas as a hex string.\n */\nasync function estimateGasNode(\n messenger: TransactionControllerMessenger,\n networkClientId: NetworkClientId,\n txParams: TransactionParams,\n delegationAddress?: Hex,\n): Promise<Hex> {\n const { from } = txParams;\n const params = [txParams] as Json[];\n\n if (delegationAddress) {\n params.push('latest');\n\n params.push({\n [from]: {\n code: DELEGATION_PREFIX + remove0x(delegationAddress),\n },\n });\n }\n\n return (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_estimateGas',\n params,\n })) as Hex;\n}\n"]}
|
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTransactionLayer1GasFee = exports.updateTransactionLayer1GasFee = void 0;
|
|
4
4
|
const utils_1 = require("@metamask/utils");
|
|
5
|
+
const provider_1 = require("./provider.cjs");
|
|
5
6
|
const logger_1 = require("../logger.cjs");
|
|
6
7
|
const log = (0, utils_1.createModuleLogger)(logger_1.projectLogger, 'layer-1-gas-fee-flow');
|
|
7
8
|
/**
|
|
8
9
|
* Updates the given transactionMeta with the layer 1 gas fee.
|
|
9
10
|
*
|
|
10
11
|
* @param request - The request to use when getting the layer 1 gas fee.
|
|
11
|
-
* @param request.provider - Provider used to create a new underlying EthQuery instance
|
|
12
12
|
* @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
|
|
13
13
|
* @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.
|
|
14
|
+
* @param request.messenger - The messenger instance.
|
|
14
15
|
*/
|
|
15
16
|
async function updateTransactionLayer1GasFee(request) {
|
|
16
17
|
const layer1GasFee = await getTransactionLayer1GasFee(request);
|
|
@@ -47,18 +48,21 @@ async function getLayer1GasFeeFlow(transactionMeta, layer1GasFeeFlows, messenger
|
|
|
47
48
|
*
|
|
48
49
|
* @param request - The request to use when getting the layer 1 gas fee.
|
|
49
50
|
* @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.
|
|
50
|
-
* @param request.provider - The provider to use to get the layer 1 gas fee.
|
|
51
51
|
* @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
|
|
52
52
|
* @param request.messenger - The messenger instance.
|
|
53
53
|
* @returns The layer 1 gas fee.
|
|
54
54
|
*/
|
|
55
|
-
async function getTransactionLayer1GasFee({ layer1GasFeeFlows, messenger,
|
|
55
|
+
async function getTransactionLayer1GasFee({ layer1GasFeeFlows, messenger, transactionMeta, }) {
|
|
56
56
|
const layer1GasFeeFlow = await getLayer1GasFeeFlow(transactionMeta, layer1GasFeeFlows, messenger);
|
|
57
57
|
if (!layer1GasFeeFlow) {
|
|
58
58
|
return undefined;
|
|
59
59
|
}
|
|
60
60
|
log('Found layer 1 gas fee flow', layer1GasFeeFlow.constructor.name, transactionMeta.id);
|
|
61
61
|
try {
|
|
62
|
+
const provider = (0, provider_1.getProvider)({
|
|
63
|
+
messenger,
|
|
64
|
+
networkClientId: transactionMeta.networkClientId,
|
|
65
|
+
});
|
|
62
66
|
const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({
|
|
63
67
|
provider,
|
|
64
68
|
transactionMeta,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layer1-gas-fee-flow.cjs","sourceRoot":"","sources":["../../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"layer1-gas-fee-flow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IAAI,EACjC,eAAe,CAAC,EAAE,CACnB,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,IAAA,sBAAW,EAAC;YAC3B,SAAS;YACT,eAAe,EAAE,eAAe,CAAC,eAAe;SACjD,CAAC,CAAC;QAEH,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,gBAAgB,CAAC,YAAY,CAAC;YACxD,QAAQ;YACR,eAAe;SAChB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,+BAA+B,EAAE,eAAe,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QAChE,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AApCD,gEAoCC","sourcesContent":["import { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { getProvider } from './provider';\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type { Layer1GasFeeFlow, TransactionMeta } from '../types';\n\nconst log = createModuleLogger(projectLogger, 'layer-1-gas-fee-flow');\n\nexport type UpdateLayer1GasFeeRequest = {\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n messenger: TransactionControllerMessenger;\n transactionMeta: TransactionMeta;\n};\n\n/**\n * Updates the given transactionMeta with the layer 1 gas fee.\n *\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @param request.messenger - The messenger instance.\n */\nexport async function updateTransactionLayer1GasFee(\n request: UpdateLayer1GasFeeRequest,\n): Promise<void> {\n const layer1GasFee = await getTransactionLayer1GasFee(request);\n\n if (!layer1GasFee) {\n return;\n }\n\n const { transactionMeta } = request;\n\n transactionMeta.layer1GasFee = layer1GasFee;\n\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n}\n\n/**\n * Get the layer 1 gas fee flow for a transaction.\n *\n * @param transactionMeta - The transaction to get the layer 1 gas fee flow for.\n * @param layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @param messenger - The messenger instance.\n * @returns The layer 1 gas fee flow for the transaction, or undefined if none match.\n */\nasync function getLayer1GasFeeFlow(\n transactionMeta: TransactionMeta,\n layer1GasFeeFlows: Layer1GasFeeFlow[],\n messenger: TransactionControllerMessenger,\n): Promise<Layer1GasFeeFlow | undefined> {\n for (const layer1GasFeeFlow of layer1GasFeeFlows) {\n const matches = await layer1GasFeeFlow.matchesTransaction({\n transactionMeta,\n messenger,\n });\n\n if (matches) {\n return layer1GasFeeFlow;\n }\n }\n\n return undefined;\n}\n\n/**\n * Get the layer 1 gas fee for a transaction.\n *\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n * @param request.messenger - The messenger instance.\n * @returns The layer 1 gas fee.\n */\nexport async function getTransactionLayer1GasFee({\n layer1GasFeeFlows,\n messenger,\n transactionMeta,\n}: UpdateLayer1GasFeeRequest): Promise<Hex | undefined> {\n const layer1GasFeeFlow = await getLayer1GasFeeFlow(\n transactionMeta,\n layer1GasFeeFlows,\n messenger,\n );\n\n if (!layer1GasFeeFlow) {\n return undefined;\n }\n\n log(\n 'Found layer 1 gas fee flow',\n layer1GasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n\n try {\n const provider = getProvider({\n messenger,\n networkClientId: transactionMeta.networkClientId,\n });\n\n const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({\n provider,\n transactionMeta,\n });\n return layer1Fee;\n } catch (error) {\n log('Failed to get layer 1 gas fee', transactionMeta.id, error);\n return undefined;\n }\n}\n"]}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import type { Provider } from "@metamask/network-controller";
|
|
2
1
|
import type { Hex } from "@metamask/utils";
|
|
3
2
|
import type { TransactionControllerMessenger } from "../TransactionController.cjs";
|
|
4
3
|
import type { Layer1GasFeeFlow, TransactionMeta } from "../types.cjs";
|
|
5
4
|
export type UpdateLayer1GasFeeRequest = {
|
|
6
5
|
layer1GasFeeFlows: Layer1GasFeeFlow[];
|
|
7
6
|
messenger: TransactionControllerMessenger;
|
|
8
|
-
provider: Provider;
|
|
9
7
|
transactionMeta: TransactionMeta;
|
|
10
8
|
};
|
|
11
9
|
/**
|
|
12
10
|
* Updates the given transactionMeta with the layer 1 gas fee.
|
|
13
11
|
*
|
|
14
12
|
* @param request - The request to use when getting the layer 1 gas fee.
|
|
15
|
-
* @param request.provider - Provider used to create a new underlying EthQuery instance
|
|
16
13
|
* @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
|
|
17
14
|
* @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.
|
|
15
|
+
* @param request.messenger - The messenger instance.
|
|
18
16
|
*/
|
|
19
17
|
export declare function updateTransactionLayer1GasFee(request: UpdateLayer1GasFeeRequest): Promise<void>;
|
|
20
18
|
/**
|
|
@@ -22,10 +20,9 @@ export declare function updateTransactionLayer1GasFee(request: UpdateLayer1GasFe
|
|
|
22
20
|
*
|
|
23
21
|
* @param request - The request to use when getting the layer 1 gas fee.
|
|
24
22
|
* @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.
|
|
25
|
-
* @param request.provider - The provider to use to get the layer 1 gas fee.
|
|
26
23
|
* @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
|
|
27
24
|
* @param request.messenger - The messenger instance.
|
|
28
25
|
* @returns The layer 1 gas fee.
|
|
29
26
|
*/
|
|
30
|
-
export declare function getTransactionLayer1GasFee({ layer1GasFeeFlows, messenger,
|
|
27
|
+
export declare function getTransactionLayer1GasFee({ layer1GasFeeFlows, messenger, transactionMeta, }: UpdateLayer1GasFeeRequest): Promise<Hex | undefined>;
|
|
31
28
|
//# sourceMappingURL=layer1-gas-fee-flow.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layer1-gas-fee-flow.d.cts","sourceRoot":"","sources":["../../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"layer1-gas-fee-flow.d.cts","sourceRoot":"","sources":["../../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,qBAAiB;AAIlE,MAAM,MAAM,yBAAyB,GAAG;IACtC,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IACtC,SAAS,EAAE,8BAA8B,CAAC;IAC1C,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,IAAI,CAAC,CAYf;AA6BD;;;;;;;;GAQG;AACH,wBAAsB,0BAA0B,CAAC,EAC/C,iBAAiB,EACjB,SAAS,EACT,eAAe,GAChB,EAAE,yBAAyB,GAAG,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,CAgCtD"}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import type { Provider } from "@metamask/network-controller";
|
|
2
1
|
import type { Hex } from "@metamask/utils";
|
|
3
2
|
import type { TransactionControllerMessenger } from "../TransactionController.mjs";
|
|
4
3
|
import type { Layer1GasFeeFlow, TransactionMeta } from "../types.mjs";
|
|
5
4
|
export type UpdateLayer1GasFeeRequest = {
|
|
6
5
|
layer1GasFeeFlows: Layer1GasFeeFlow[];
|
|
7
6
|
messenger: TransactionControllerMessenger;
|
|
8
|
-
provider: Provider;
|
|
9
7
|
transactionMeta: TransactionMeta;
|
|
10
8
|
};
|
|
11
9
|
/**
|
|
12
10
|
* Updates the given transactionMeta with the layer 1 gas fee.
|
|
13
11
|
*
|
|
14
12
|
* @param request - The request to use when getting the layer 1 gas fee.
|
|
15
|
-
* @param request.provider - Provider used to create a new underlying EthQuery instance
|
|
16
13
|
* @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
|
|
17
14
|
* @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.
|
|
15
|
+
* @param request.messenger - The messenger instance.
|
|
18
16
|
*/
|
|
19
17
|
export declare function updateTransactionLayer1GasFee(request: UpdateLayer1GasFeeRequest): Promise<void>;
|
|
20
18
|
/**
|
|
@@ -22,10 +20,9 @@ export declare function updateTransactionLayer1GasFee(request: UpdateLayer1GasFe
|
|
|
22
20
|
*
|
|
23
21
|
* @param request - The request to use when getting the layer 1 gas fee.
|
|
24
22
|
* @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.
|
|
25
|
-
* @param request.provider - The provider to use to get the layer 1 gas fee.
|
|
26
23
|
* @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
|
|
27
24
|
* @param request.messenger - The messenger instance.
|
|
28
25
|
* @returns The layer 1 gas fee.
|
|
29
26
|
*/
|
|
30
|
-
export declare function getTransactionLayer1GasFee({ layer1GasFeeFlows, messenger,
|
|
27
|
+
export declare function getTransactionLayer1GasFee({ layer1GasFeeFlows, messenger, transactionMeta, }: UpdateLayer1GasFeeRequest): Promise<Hex | undefined>;
|
|
31
28
|
//# sourceMappingURL=layer1-gas-fee-flow.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layer1-gas-fee-flow.d.mts","sourceRoot":"","sources":["../../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"layer1-gas-fee-flow.d.mts","sourceRoot":"","sources":["../../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,qBAAiB;AAIlE,MAAM,MAAM,yBAAyB,GAAG;IACtC,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IACtC,SAAS,EAAE,8BAA8B,CAAC;IAC1C,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,IAAI,CAAC,CAYf;AA6BD;;;;;;;;GAQG;AACH,wBAAsB,0BAA0B,CAAC,EAC/C,iBAAiB,EACjB,SAAS,EACT,eAAe,GAChB,EAAE,yBAAyB,GAAG,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,CAgCtD"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { createModuleLogger } from "@metamask/utils";
|
|
2
|
+
import { getProvider } from "./provider.mjs";
|
|
2
3
|
import { projectLogger } from "../logger.mjs";
|
|
3
4
|
const log = createModuleLogger(projectLogger, 'layer-1-gas-fee-flow');
|
|
4
5
|
/**
|
|
5
6
|
* Updates the given transactionMeta with the layer 1 gas fee.
|
|
6
7
|
*
|
|
7
8
|
* @param request - The request to use when getting the layer 1 gas fee.
|
|
8
|
-
* @param request.provider - Provider used to create a new underlying EthQuery instance
|
|
9
9
|
* @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
|
|
10
10
|
* @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.
|
|
11
|
+
* @param request.messenger - The messenger instance.
|
|
11
12
|
*/
|
|
12
13
|
export async function updateTransactionLayer1GasFee(request) {
|
|
13
14
|
const layer1GasFee = await getTransactionLayer1GasFee(request);
|
|
@@ -43,18 +44,21 @@ async function getLayer1GasFeeFlow(transactionMeta, layer1GasFeeFlows, messenger
|
|
|
43
44
|
*
|
|
44
45
|
* @param request - The request to use when getting the layer 1 gas fee.
|
|
45
46
|
* @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.
|
|
46
|
-
* @param request.provider - The provider to use to get the layer 1 gas fee.
|
|
47
47
|
* @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
|
|
48
48
|
* @param request.messenger - The messenger instance.
|
|
49
49
|
* @returns The layer 1 gas fee.
|
|
50
50
|
*/
|
|
51
|
-
export async function getTransactionLayer1GasFee({ layer1GasFeeFlows, messenger,
|
|
51
|
+
export async function getTransactionLayer1GasFee({ layer1GasFeeFlows, messenger, transactionMeta, }) {
|
|
52
52
|
const layer1GasFeeFlow = await getLayer1GasFeeFlow(transactionMeta, layer1GasFeeFlows, messenger);
|
|
53
53
|
if (!layer1GasFeeFlow) {
|
|
54
54
|
return undefined;
|
|
55
55
|
}
|
|
56
56
|
log('Found layer 1 gas fee flow', layer1GasFeeFlow.constructor.name, transactionMeta.id);
|
|
57
57
|
try {
|
|
58
|
+
const provider = getProvider({
|
|
59
|
+
messenger,
|
|
60
|
+
networkClientId: transactionMeta.networkClientId,
|
|
61
|
+
});
|
|
58
62
|
const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({
|
|
59
63
|
provider,
|
|
60
64
|
transactionMeta,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layer1-gas-fee-flow.mjs","sourceRoot":"","sources":["../../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"layer1-gas-fee-flow.mjs","sourceRoot":"","sources":["../../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAGrD,OAAO,EAAE,WAAW,EAAE,uBAAmB;AACzC,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAI1C,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,sBAAsB,CAAC,CAAC;AAQtE;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,OAAkC;IAElC,MAAM,YAAY,GAAG,MAAM,0BAA0B,CAAC,OAAO,CAAC,CAAC;IAE/D,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO;IACT,C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,eAAe,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QAChE,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { getProvider } from './provider';\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type { Layer1GasFeeFlow, TransactionMeta } from '../types';\n\nconst log = createModuleLogger(projectLogger, 'layer-1-gas-fee-flow');\n\nexport type UpdateLayer1GasFeeRequest = {\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n messenger: TransactionControllerMessenger;\n transactionMeta: TransactionMeta;\n};\n\n/**\n * Updates the given transactionMeta with the layer 1 gas fee.\n *\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @param request.messenger - The messenger instance.\n */\nexport async function updateTransactionLayer1GasFee(\n request: UpdateLayer1GasFeeRequest,\n): Promise<void> {\n const layer1GasFee = await getTransactionLayer1GasFee(request);\n\n if (!layer1GasFee) {\n return;\n }\n\n const { transactionMeta } = request;\n\n transactionMeta.layer1GasFee = layer1GasFee;\n\n log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);\n}\n\n/**\n * Get the layer 1 gas fee flow for a transaction.\n *\n * @param transactionMeta - The transaction to get the layer 1 gas fee flow for.\n * @param layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @param messenger - The messenger instance.\n * @returns The layer 1 gas fee flow for the transaction, or undefined if none match.\n */\nasync function getLayer1GasFeeFlow(\n transactionMeta: TransactionMeta,\n layer1GasFeeFlows: Layer1GasFeeFlow[],\n messenger: TransactionControllerMessenger,\n): Promise<Layer1GasFeeFlow | undefined> {\n for (const layer1GasFeeFlow of layer1GasFeeFlows) {\n const matches = await layer1GasFeeFlow.matchesTransaction({\n transactionMeta,\n messenger,\n });\n\n if (matches) {\n return layer1GasFeeFlow;\n }\n }\n\n return undefined;\n}\n\n/**\n * Get the layer 1 gas fee for a transaction.\n *\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n * @param request.messenger - The messenger instance.\n * @returns The layer 1 gas fee.\n */\nexport async function getTransactionLayer1GasFee({\n layer1GasFeeFlows,\n messenger,\n transactionMeta,\n}: UpdateLayer1GasFeeRequest): Promise<Hex | undefined> {\n const layer1GasFeeFlow = await getLayer1GasFeeFlow(\n transactionMeta,\n layer1GasFeeFlows,\n messenger,\n );\n\n if (!layer1GasFeeFlow) {\n return undefined;\n }\n\n log(\n 'Found layer 1 gas fee flow',\n layer1GasFeeFlow.constructor.name,\n transactionMeta.id,\n );\n\n try {\n const provider = getProvider({\n messenger,\n networkClientId: transactionMeta.networkClientId,\n });\n\n const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({\n provider,\n transactionMeta,\n });\n return layer1Fee;\n } catch (error) {\n log('Failed to get layer 1 gas fee', transactionMeta.id, error);\n return undefined;\n }\n}\n"]}
|