@metamask-previews/transaction-controller 69.6.1-preview-4f4c98e → 69.6.1-preview-eb263b0ee
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 +0 -5
- package/dist/TransactionController-method-action-types.cjs +7 -0
- package/dist/TransactionController-method-action-types.cjs.map +1 -0
- package/dist/{TransactionController-method-action-types.d.ts → TransactionController-method-action-types.d.cts} +2 -2
- package/dist/TransactionController-method-action-types.d.cts.map +1 -0
- package/dist/TransactionController-method-action-types.d.mts +413 -0
- package/dist/TransactionController-method-action-types.d.mts.map +1 -0
- package/dist/{TransactionController-method-action-types.js → TransactionController-method-action-types.mjs} +1 -1
- package/dist/TransactionController-method-action-types.mjs.map +1 -0
- package/dist/TransactionController.cjs +2444 -0
- package/dist/TransactionController.cjs.map +1 -0
- package/dist/{TransactionController.d.ts → TransactionController.d.cts} +18 -18
- package/dist/TransactionController.d.cts.map +1 -0
- package/dist/TransactionController.d.mts +751 -0
- package/dist/TransactionController.d.mts.map +1 -0
- package/dist/{TransactionController.js → TransactionController.mjs} +50 -49
- package/dist/TransactionController.mjs.map +1 -0
- package/dist/api/accounts-api.cjs +57 -0
- package/dist/api/accounts-api.cjs.map +1 -0
- package/dist/api/{accounts-api.d.ts → accounts-api.d.cts} +1 -1
- package/dist/api/accounts-api.d.cts.map +1 -0
- package/dist/api/accounts-api.d.mts +44 -0
- package/dist/api/accounts-api.d.mts.map +1 -0
- package/dist/api/{accounts-api.js → accounts-api.mjs} +5 -5
- package/dist/api/accounts-api.mjs.map +1 -0
- package/dist/api/simulation-api.cjs +116 -0
- package/dist/api/simulation-api.cjs.map +1 -0
- package/dist/api/{simulation-api.d.ts → simulation-api.d.cts} +3 -3
- package/dist/api/simulation-api.d.cts.map +1 -0
- package/dist/api/simulation-api.d.mts +196 -0
- package/dist/api/simulation-api.d.mts.map +1 -0
- package/dist/api/{simulation-api.js → simulation-api.mjs} +8 -7
- package/dist/api/simulation-api.mjs.map +1 -0
- package/dist/constants.cjs +111 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/{constants.d.ts → constants.d.cts} +37 -37
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +78 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/{constants.js → constants.mjs} +1 -1
- package/dist/constants.mjs.map +1 -0
- package/dist/errors.cjs +37 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/{errors.d.ts → errors.d.cts} +2 -2
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +19 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/{errors.js → errors.mjs} +2 -2
- package/dist/errors.mjs.map +1 -0
- package/dist/gas-flows/DefaultGasFeeFlow.cjs +85 -0
- package/dist/gas-flows/{DefaultGasFeeFlow.js.map → DefaultGasFeeFlow.cjs.map} +1 -1
- package/dist/gas-flows/{DefaultGasFeeFlow.d.ts → DefaultGasFeeFlow.d.cts} +2 -2
- package/dist/gas-flows/DefaultGasFeeFlow.d.cts.map +1 -0
- package/dist/gas-flows/DefaultGasFeeFlow.d.mts +10 -0
- package/dist/gas-flows/DefaultGasFeeFlow.d.mts.map +1 -0
- package/dist/gas-flows/{DefaultGasFeeFlow.js → DefaultGasFeeFlow.mjs} +6 -6
- package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -0
- package/dist/gas-flows/LineaGasFeeFlow.cjs +111 -0
- package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -0
- package/dist/gas-flows/{LineaGasFeeFlow.d.ts → LineaGasFeeFlow.d.cts} +3 -3
- package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -0
- package/dist/gas-flows/LineaGasFeeFlow.d.mts +16 -0
- package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -0
- package/dist/gas-flows/{LineaGasFeeFlow.js → LineaGasFeeFlow.mjs} +7 -7
- package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -0
- package/dist/gas-flows/MantleLayer1GasFeeFlow.cjs +66 -0
- package/dist/gas-flows/MantleLayer1GasFeeFlow.cjs.map +1 -0
- package/dist/gas-flows/{MantleLayer1GasFeeFlow.d.ts → MantleLayer1GasFeeFlow.d.cts} +5 -5
- package/dist/gas-flows/MantleLayer1GasFeeFlow.d.cts.map +1 -0
- package/dist/gas-flows/MantleLayer1GasFeeFlow.d.mts +21 -0
- package/dist/gas-flows/MantleLayer1GasFeeFlow.d.mts.map +1 -0
- package/dist/gas-flows/{MantleLayer1GasFeeFlow.js → MantleLayer1GasFeeFlow.mjs} +6 -6
- package/dist/gas-flows/MantleLayer1GasFeeFlow.mjs.map +1 -0
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs +59 -0
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.cjs.map +1 -0
- package/dist/gas-flows/{OptimismLayer1GasFeeFlow.d.ts → OptimismLayer1GasFeeFlow.d.cts} +4 -4
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.cts.map +1 -0
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts +14 -0
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.mts.map +1 -0
- package/dist/gas-flows/{OptimismLayer1GasFeeFlow.js → OptimismLayer1GasFeeFlow.mjs} +5 -5
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs.map +1 -0
- package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs +201 -0
- package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs.map +1 -0
- package/dist/gas-flows/{OracleLayer1GasFeeFlow.d.ts → OracleLayer1GasFeeFlow.d.cts} +5 -5
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.cts.map +1 -0
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts +57 -0
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts.map +1 -0
- package/dist/gas-flows/{OracleLayer1GasFeeFlow.js → OracleLayer1GasFeeFlow.mjs} +15 -8
- package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs.map +1 -0
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.cjs +123 -0
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.cjs.map +1 -0
- package/dist/gas-flows/{RandomisedEstimationsGasFeeFlow.d.ts → RandomisedEstimationsGasFeeFlow.d.cts} +4 -4
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.cts.map +1 -0
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.mts +28 -0
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.mts.map +1 -0
- package/dist/gas-flows/{RandomisedEstimationsGasFeeFlow.js → RandomisedEstimationsGasFeeFlow.mjs} +8 -8
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.mjs.map +1 -0
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs +24 -0
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.cjs.map +1 -0
- package/dist/gas-flows/{ScrollLayer1GasFeeFlow.d.ts → ScrollLayer1GasFeeFlow.d.cts} +5 -5
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.cts.map +1 -0
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts +16 -0
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.mts.map +1 -0
- package/dist/gas-flows/{ScrollLayer1GasFeeFlow.js → ScrollLayer1GasFeeFlow.mjs} +3 -3
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.mjs.map +1 -0
- package/dist/gas-flows/TestGasFeeFlow.cjs +73 -0
- package/dist/gas-flows/TestGasFeeFlow.cjs.map +1 -0
- package/dist/gas-flows/{TestGasFeeFlow.d.ts → TestGasFeeFlow.d.cts} +2 -2
- package/dist/gas-flows/TestGasFeeFlow.d.cts.map +1 -0
- package/dist/gas-flows/TestGasFeeFlow.d.mts +12 -0
- package/dist/gas-flows/TestGasFeeFlow.d.mts.map +1 -0
- package/dist/gas-flows/{TestGasFeeFlow.js → TestGasFeeFlow.mjs} +3 -3
- package/dist/gas-flows/TestGasFeeFlow.mjs.map +1 -0
- package/dist/helpers/GasFeePoller.cjs +334 -0
- package/dist/helpers/GasFeePoller.cjs.map +1 -0
- package/dist/helpers/{GasFeePoller.d.ts → GasFeePoller.d.cts} +10 -7
- package/dist/helpers/GasFeePoller.d.cts.map +1 -0
- package/dist/helpers/GasFeePoller.d.mts +66 -0
- package/dist/helpers/GasFeePoller.d.mts.map +1 -0
- package/dist/helpers/{GasFeePoller.js → GasFeePoller.mjs} +9 -9
- package/dist/helpers/GasFeePoller.mjs.map +1 -0
- package/dist/helpers/MethodDataHelper.cjs +84 -0
- package/dist/helpers/MethodDataHelper.cjs.map +1 -0
- package/dist/helpers/{MethodDataHelper.d.ts → MethodDataHelper.d.cts} +7 -4
- package/dist/helpers/MethodDataHelper.d.cts.map +1 -0
- package/dist/helpers/MethodDataHelper.d.mts +16 -0
- package/dist/helpers/MethodDataHelper.d.mts.map +1 -0
- package/dist/helpers/{MethodDataHelper.js → MethodDataHelper.mjs} +7 -7
- package/dist/helpers/MethodDataHelper.mjs.map +1 -0
- package/dist/helpers/MultichainTrackingHelper.cjs +231 -0
- package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -0
- package/dist/helpers/{MultichainTrackingHelper.d.ts → MultichainTrackingHelper.d.cts} +5 -5
- package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -0
- package/dist/helpers/MultichainTrackingHelper.d.mts +56 -0
- package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -0
- package/dist/helpers/{MultichainTrackingHelper.js → MultichainTrackingHelper.mjs} +8 -8
- package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -0
- package/dist/helpers/PendingTransactionTracker.cjs +407 -0
- package/dist/helpers/PendingTransactionTracker.cjs.map +1 -0
- package/dist/helpers/{PendingTransactionTracker.d.ts → PendingTransactionTracker.d.cts} +8 -5
- package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -0
- package/dist/helpers/PendingTransactionTracker.d.mts +54 -0
- package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -0
- package/dist/helpers/{PendingTransactionTracker.js → PendingTransactionTracker.mjs} +15 -14
- package/dist/helpers/PendingTransactionTracker.mjs.map +1 -0
- package/dist/helpers/ResimulateHelper.cjs +274 -0
- package/dist/helpers/ResimulateHelper.cjs.map +1 -0
- package/dist/helpers/{ResimulateHelper.d.ts → ResimulateHelper.d.cts} +3 -3
- package/dist/helpers/ResimulateHelper.d.cts.map +1 -0
- package/dist/helpers/ResimulateHelper.d.mts +36 -0
- package/dist/helpers/ResimulateHelper.d.mts.map +1 -0
- package/dist/helpers/{ResimulateHelper.js → ResimulateHelper.mjs} +8 -7
- package/dist/helpers/ResimulateHelper.mjs.map +1 -0
- package/dist/helpers/TransactionPoller.cjs +175 -0
- package/dist/helpers/TransactionPoller.cjs.map +1 -0
- package/dist/helpers/{TransactionPoller.d.ts → TransactionPoller.d.cts} +5 -5
- package/dist/helpers/TransactionPoller.d.cts.map +1 -0
- package/dist/helpers/TransactionPoller.d.mts +37 -0
- package/dist/helpers/TransactionPoller.d.mts.map +1 -0
- package/dist/helpers/{TransactionPoller.js → TransactionPoller.mjs} +11 -10
- package/dist/helpers/TransactionPoller.mjs.map +1 -0
- package/dist/hooks/CollectPublishHook.cjs +94 -0
- package/dist/hooks/CollectPublishHook.cjs.map +1 -0
- package/dist/hooks/{CollectPublishHook.d.ts → CollectPublishHook.d.cts} +3 -3
- package/dist/hooks/CollectPublishHook.d.cts.map +1 -0
- package/dist/hooks/CollectPublishHook.d.mts +29 -0
- package/dist/hooks/CollectPublishHook.d.mts.map +1 -0
- package/dist/hooks/{CollectPublishHook.js → CollectPublishHook.mjs} +5 -4
- package/dist/hooks/CollectPublishHook.mjs.map +1 -0
- package/dist/hooks/ExtraTransactionsPublishHook.cjs +126 -0
- package/dist/hooks/ExtraTransactionsPublishHook.cjs.map +1 -0
- package/dist/hooks/{ExtraTransactionsPublishHook.d.ts → ExtraTransactionsPublishHook.d.cts} +3 -3
- package/dist/hooks/ExtraTransactionsPublishHook.d.cts.map +1 -0
- package/dist/hooks/ExtraTransactionsPublishHook.d.mts +19 -0
- package/dist/hooks/ExtraTransactionsPublishHook.d.mts.map +1 -0
- package/dist/hooks/{ExtraTransactionsPublishHook.js → ExtraTransactionsPublishHook.mjs} +3 -3
- package/dist/hooks/ExtraTransactionsPublishHook.mjs.map +1 -0
- package/dist/hooks/SequentialPublishBatchHook.cjs +112 -0
- package/dist/hooks/SequentialPublishBatchHook.cjs.map +1 -0
- package/dist/hooks/{SequentialPublishBatchHook.d.ts → SequentialPublishBatchHook.d.cts} +4 -4
- package/dist/hooks/SequentialPublishBatchHook.d.cts.map +1 -0
- package/dist/hooks/SequentialPublishBatchHook.d.mts +22 -0
- package/dist/hooks/SequentialPublishBatchHook.d.mts.map +1 -0
- package/dist/hooks/{SequentialPublishBatchHook.js → SequentialPublishBatchHook.mjs} +4 -4
- package/dist/hooks/SequentialPublishBatchHook.mjs.map +1 -0
- package/dist/index.cjs +40 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.ts → index.d.cts} +16 -16
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +12 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.cjs +9 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/{logger.d.ts → logger.d.cts} +3 -2
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +6 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/{logger.js → logger.mjs} +2 -2
- package/dist/logger.mjs.map +1 -0
- package/dist/types.cjs +382 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types.d.ts → types.d.cts} +8 -8
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +1887 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/{types.js → types.mjs} +1 -1
- package/dist/types.mjs.map +1 -0
- package/dist/utils/balance-changes.cjs +592 -0
- package/dist/utils/balance-changes.cjs.map +1 -0
- package/dist/utils/{balance-changes.d.ts → balance-changes.d.cts} +5 -5
- package/dist/utils/balance-changes.d.cts.map +1 -0
- package/dist/utils/balance-changes.d.mts +38 -0
- package/dist/utils/balance-changes.d.mts.map +1 -0
- package/dist/utils/{balance-changes.js → balance-changes.mjs} +20 -13
- package/dist/utils/balance-changes.mjs.map +1 -0
- package/dist/utils/balance.cjs +44 -0
- package/dist/utils/balance.cjs.map +1 -0
- package/dist/utils/{balance.d.ts → balance.d.cts} +5 -5
- package/dist/utils/balance.d.cts.map +1 -0
- package/dist/utils/balance.d.mts +26 -0
- package/dist/utils/balance.d.mts.map +1 -0
- package/dist/utils/{balance.js → balance.mjs} +3 -3
- package/dist/utils/balance.mjs.map +1 -0
- package/dist/utils/batch.cjs +712 -0
- package/dist/utils/batch.cjs.map +1 -0
- package/dist/utils/{batch.d.ts → batch.d.cts} +8 -8
- package/dist/utils/batch.d.cts.map +1 -0
- package/dist/utils/batch.d.mts +58 -0
- package/dist/utils/batch.d.mts.map +1 -0
- package/dist/utils/{batch.js → batch.mjs} +18 -18
- package/dist/utils/batch.mjs.map +1 -0
- package/dist/utils/eip7702.cjs +354 -0
- package/dist/utils/eip7702.cjs.map +1 -0
- package/dist/utils/{eip7702.d.ts → eip7702.d.cts} +5 -5
- package/dist/utils/eip7702.d.cts.map +1 -0
- package/dist/utils/eip7702.d.mts +137 -0
- package/dist/utils/eip7702.d.mts.map +1 -0
- package/dist/utils/{eip7702.js → eip7702.mjs} +12 -12
- package/dist/utils/eip7702.mjs.map +1 -0
- package/dist/utils/external-transactions.cjs +36 -0
- package/dist/utils/external-transactions.cjs.map +1 -0
- package/dist/utils/{external-transactions.d.ts → external-transactions.d.cts} +2 -2
- package/dist/utils/external-transactions.d.cts.map +1 -0
- package/dist/utils/external-transactions.d.mts +10 -0
- package/dist/utils/external-transactions.d.mts.map +1 -0
- package/dist/utils/{external-transactions.js → external-transactions.mjs} +3 -3
- package/dist/utils/external-transactions.mjs.map +1 -0
- package/dist/utils/feature-flags.cjs +255 -0
- package/dist/utils/feature-flags.cjs.map +1 -0
- package/dist/utils/{feature-flags.d.ts → feature-flags.d.cts} +3 -3
- package/dist/utils/feature-flags.d.cts.map +1 -0
- package/dist/utils/feature-flags.d.mts +313 -0
- package/dist/utils/feature-flags.d.mts.map +1 -0
- package/dist/utils/{feature-flags.js → feature-flags.mjs} +5 -5
- package/dist/utils/feature-flags.mjs.map +1 -0
- package/dist/utils/first-time-interaction.cjs +69 -0
- package/dist/utils/first-time-interaction.cjs.map +1 -0
- package/dist/utils/{first-time-interaction.d.ts → first-time-interaction.d.cts} +3 -3
- package/dist/utils/first-time-interaction.d.cts.map +1 -0
- package/dist/utils/first-time-interaction.d.mts +30 -0
- package/dist/utils/first-time-interaction.d.mts.map +1 -0
- package/dist/utils/{first-time-interaction.js → first-time-interaction.mjs} +6 -6
- package/dist/utils/first-time-interaction.mjs.map +1 -0
- package/dist/utils/gas-fee-tokens.cjs +174 -0
- package/dist/utils/gas-fee-tokens.cjs.map +1 -0
- package/dist/utils/{gas-fee-tokens.d.ts → gas-fee-tokens.d.cts} +5 -5
- package/dist/utils/gas-fee-tokens.d.cts.map +1 -0
- package/dist/utils/gas-fee-tokens.d.mts +46 -0
- package/dist/utils/gas-fee-tokens.d.mts.map +1 -0
- package/dist/utils/{gas-fee-tokens.js → gas-fee-tokens.mjs} +9 -9
- package/dist/utils/gas-fee-tokens.mjs.map +1 -0
- package/dist/utils/gas-fees.cjs +424 -0
- package/dist/utils/gas-fees.cjs.map +1 -0
- package/dist/utils/{gas-fees.d.ts → gas-fees.d.cts} +5 -5
- package/dist/utils/gas-fees.d.cts.map +1 -0
- package/dist/utils/gas-fees.d.mts +57 -0
- package/dist/utils/gas-fees.d.mts.map +1 -0
- package/dist/utils/{gas-fees.js → gas-fees.mjs} +9 -9
- package/dist/utils/gas-fees.mjs.map +1 -0
- package/dist/utils/gas-flow.cjs +81 -0
- package/dist/utils/gas-flow.cjs.map +1 -0
- package/dist/utils/{gas-flow.d.ts → gas-flow.d.cts} +6 -6
- package/dist/utils/gas-flow.d.cts.map +1 -0
- package/dist/utils/gas-flow.d.mts +29 -0
- package/dist/utils/gas-flow.d.mts.map +1 -0
- package/dist/utils/{gas-flow.js → gas-flow.mjs} +3 -3
- package/dist/utils/gas-flow.mjs.map +1 -0
- package/dist/utils/gas.cjs +545 -0
- package/dist/utils/gas.cjs.map +1 -0
- package/dist/utils/{gas.d.ts → gas.d.cts} +6 -5
- package/dist/utils/gas.d.cts.map +1 -0
- package/dist/utils/gas.d.mts +116 -0
- package/dist/utils/gas.d.mts.map +1 -0
- package/dist/utils/{gas.js → gas.mjs} +11 -11
- package/dist/utils/gas.mjs.map +1 -0
- package/dist/utils/layer1-gas-fee-flow.cjs +73 -0
- package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -0
- package/dist/utils/{layer1-gas-fee-flow.d.ts → layer1-gas-fee-flow.d.cts} +4 -4
- package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -0
- package/dist/utils/layer1-gas-fee-flow.d.mts +28 -0
- package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -0
- package/dist/utils/{layer1-gas-fee-flow.js → layer1-gas-fee-flow.mjs} +3 -3
- package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -0
- package/dist/utils/nonce.cjs +93 -0
- package/dist/utils/nonce.cjs.map +1 -0
- package/dist/utils/{nonce.d.ts → nonce.d.cts} +3 -3
- package/dist/utils/nonce.d.cts.map +1 -0
- package/dist/utils/nonce.d.mts +26 -0
- package/dist/utils/nonce.d.mts.map +1 -0
- package/dist/utils/{nonce.js → nonce.mjs} +4 -4
- package/dist/utils/nonce.mjs.map +1 -0
- package/dist/utils/prepare.cjs +97 -0
- package/dist/utils/prepare.cjs.map +1 -0
- package/dist/utils/{prepare.d.ts → prepare.d.cts} +5 -5
- package/dist/utils/prepare.d.cts.map +1 -0
- package/dist/utils/prepare.d.mts +22 -0
- package/dist/utils/prepare.d.mts.map +1 -0
- package/dist/utils/{prepare.js → prepare.mjs} +6 -5
- package/dist/utils/prepare.mjs.map +1 -0
- package/dist/utils/provider.cjs +106 -0
- package/dist/utils/provider.cjs.map +1 -0
- package/dist/utils/{provider.d.ts → provider.d.cts} +4 -4
- 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.js → provider.mjs} +3 -3
- package/dist/utils/provider.mjs.map +1 -0
- package/dist/utils/recipient.cjs +31 -0
- package/dist/utils/recipient.cjs.map +1 -0
- package/dist/utils/{recipient.d.ts → recipient.d.cts} +2 -2
- package/dist/utils/recipient.d.cts.map +1 -0
- package/dist/utils/recipient.d.mts +13 -0
- package/dist/utils/recipient.d.mts.map +1 -0
- package/dist/utils/{recipient.js → recipient.mjs} +3 -3
- package/dist/utils/recipient.mjs.map +1 -0
- package/dist/utils/retry.cjs +93 -0
- package/dist/utils/retry.cjs.map +1 -0
- package/dist/utils/{retry.d.ts → retry.d.cts} +2 -2
- package/dist/utils/retry.d.cts.map +1 -0
- package/dist/utils/retry.d.mts +11 -0
- package/dist/utils/retry.d.mts.map +1 -0
- package/dist/utils/{retry.js → retry.mjs} +3 -3
- package/dist/utils/retry.mjs.map +1 -0
- package/dist/utils/revert-reason.cjs +192 -0
- package/dist/utils/revert-reason.cjs.map +1 -0
- package/dist/utils/{revert-reason.d.ts → revert-reason.d.cts} +5 -5
- package/dist/utils/revert-reason.d.cts.map +1 -0
- package/dist/utils/revert-reason.d.mts +57 -0
- package/dist/utils/revert-reason.d.mts.map +1 -0
- package/dist/utils/{revert-reason.js → revert-reason.mjs} +4 -4
- package/dist/utils/revert-reason.mjs.map +1 -0
- package/dist/utils/signature.cjs +26 -0
- package/dist/utils/signature.cjs.map +1 -0
- package/dist/utils/{signature.d.ts → signature.d.cts} +2 -2
- package/dist/utils/signature.d.cts.map +1 -0
- package/dist/utils/signature.d.mts +11 -0
- package/dist/utils/signature.d.mts.map +1 -0
- package/dist/utils/{signature.js → signature.mjs} +3 -3
- package/dist/utils/signature.mjs.map +1 -0
- package/dist/utils/swaps.cjs +332 -0
- package/dist/utils/swaps.cjs.map +1 -0
- package/dist/utils/{swaps.d.ts → swaps.d.cts} +5 -5
- package/dist/utils/swaps.d.cts.map +1 -0
- package/dist/utils/swaps.d.mts +90 -0
- package/dist/utils/swaps.d.mts.map +1 -0
- package/dist/utils/{swaps.js → swaps.mjs} +8 -7
- package/dist/utils/swaps.mjs.map +1 -0
- package/dist/utils/transaction-type.cjs +159 -0
- package/dist/utils/transaction-type.cjs.map +1 -0
- package/dist/utils/{transaction-type.d.ts → transaction-type.d.cts} +6 -6
- package/dist/utils/transaction-type.d.cts.map +1 -0
- package/dist/utils/transaction-type.d.mts +44 -0
- package/dist/utils/transaction-type.d.mts.map +1 -0
- package/dist/utils/{transaction-type.js → transaction-type.mjs} +6 -6
- package/dist/utils/transaction-type.mjs.map +1 -0
- package/dist/utils/utils.cjs +287 -0
- package/dist/utils/utils.cjs.map +1 -0
- package/dist/utils/{utils.d.ts → utils.d.cts} +4 -4
- package/dist/utils/utils.d.cts.map +1 -0
- package/dist/utils/utils.d.mts +101 -0
- package/dist/utils/utils.d.mts.map +1 -0
- package/dist/utils/{utils.js → utils.mjs} +12 -5
- package/dist/utils/utils.mjs.map +1 -0
- package/dist/utils/validation.cjs +389 -0
- package/dist/utils/validation.cjs.map +1 -0
- package/dist/utils/{validation.d.ts → validation.d.cts} +4 -4
- package/dist/utils/validation.d.cts.map +1 -0
- package/dist/utils/validation.d.mts +66 -0
- package/dist/utils/validation.d.mts.map +1 -0
- package/dist/utils/{validation.js → validation.mjs} +8 -8
- package/dist/utils/validation.mjs.map +1 -0
- package/package.json +19 -15
- package/dist/TransactionController-method-action-types.d.ts.map +0 -1
- package/dist/TransactionController-method-action-types.js.map +0 -1
- package/dist/TransactionController.d.ts.map +0 -1
- package/dist/TransactionController.js.map +0 -1
- package/dist/api/accounts-api.d.ts.map +0 -1
- package/dist/api/accounts-api.js.map +0 -1
- package/dist/api/simulation-api.d.ts.map +0 -1
- package/dist/api/simulation-api.js.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/gas-flows/DefaultGasFeeFlow.d.ts.map +0 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.ts.map +0 -1
- package/dist/gas-flows/LineaGasFeeFlow.js.map +0 -1
- package/dist/gas-flows/MantleLayer1GasFeeFlow.d.ts.map +0 -1
- package/dist/gas-flows/MantleLayer1GasFeeFlow.js.map +0 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.d.ts.map +0 -1
- package/dist/gas-flows/OptimismLayer1GasFeeFlow.js.map +0 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.ts.map +0 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.js.map +0 -1
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.d.ts.map +0 -1
- package/dist/gas-flows/RandomisedEstimationsGasFeeFlow.js.map +0 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.d.ts.map +0 -1
- package/dist/gas-flows/ScrollLayer1GasFeeFlow.js.map +0 -1
- package/dist/gas-flows/TestGasFeeFlow.d.ts.map +0 -1
- package/dist/gas-flows/TestGasFeeFlow.js.map +0 -1
- package/dist/helpers/GasFeePoller.d.ts.map +0 -1
- package/dist/helpers/GasFeePoller.js.map +0 -1
- package/dist/helpers/MethodDataHelper.d.ts.map +0 -1
- package/dist/helpers/MethodDataHelper.js.map +0 -1
- package/dist/helpers/MultichainTrackingHelper.d.ts.map +0 -1
- package/dist/helpers/MultichainTrackingHelper.js.map +0 -1
- package/dist/helpers/PendingTransactionTracker.d.ts.map +0 -1
- package/dist/helpers/PendingTransactionTracker.js.map +0 -1
- package/dist/helpers/ResimulateHelper.d.ts.map +0 -1
- package/dist/helpers/ResimulateHelper.js.map +0 -1
- package/dist/helpers/TransactionPoller.d.ts.map +0 -1
- package/dist/helpers/TransactionPoller.js.map +0 -1
- package/dist/hooks/CollectPublishHook.d.ts.map +0 -1
- package/dist/hooks/CollectPublishHook.js.map +0 -1
- package/dist/hooks/ExtraTransactionsPublishHook.d.ts.map +0 -1
- package/dist/hooks/ExtraTransactionsPublishHook.js.map +0 -1
- package/dist/hooks/SequentialPublishBatchHook.d.ts.map +0 -1
- package/dist/hooks/SequentialPublishBatchHook.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -12
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/balance-changes.d.ts.map +0 -1
- package/dist/utils/balance-changes.js.map +0 -1
- package/dist/utils/balance.d.ts.map +0 -1
- package/dist/utils/balance.js.map +0 -1
- package/dist/utils/batch.d.ts.map +0 -1
- package/dist/utils/batch.js.map +0 -1
- package/dist/utils/eip7702.d.ts.map +0 -1
- package/dist/utils/eip7702.js.map +0 -1
- package/dist/utils/external-transactions.d.ts.map +0 -1
- package/dist/utils/external-transactions.js.map +0 -1
- package/dist/utils/feature-flags.d.ts.map +0 -1
- package/dist/utils/feature-flags.js.map +0 -1
- package/dist/utils/first-time-interaction.d.ts.map +0 -1
- package/dist/utils/first-time-interaction.js.map +0 -1
- package/dist/utils/gas-fee-tokens.d.ts.map +0 -1
- package/dist/utils/gas-fee-tokens.js.map +0 -1
- package/dist/utils/gas-fees.d.ts.map +0 -1
- package/dist/utils/gas-fees.js.map +0 -1
- package/dist/utils/gas-flow.d.ts.map +0 -1
- package/dist/utils/gas-flow.js.map +0 -1
- package/dist/utils/gas.d.ts.map +0 -1
- package/dist/utils/gas.js.map +0 -1
- package/dist/utils/layer1-gas-fee-flow.d.ts.map +0 -1
- package/dist/utils/layer1-gas-fee-flow.js.map +0 -1
- package/dist/utils/nonce.d.ts.map +0 -1
- package/dist/utils/nonce.js.map +0 -1
- package/dist/utils/prepare.d.ts.map +0 -1
- package/dist/utils/prepare.js.map +0 -1
- package/dist/utils/provider.d.ts.map +0 -1
- package/dist/utils/provider.js.map +0 -1
- package/dist/utils/recipient.d.ts.map +0 -1
- package/dist/utils/recipient.js.map +0 -1
- package/dist/utils/retry.d.ts.map +0 -1
- package/dist/utils/retry.js.map +0 -1
- package/dist/utils/revert-reason.d.ts.map +0 -1
- package/dist/utils/revert-reason.js.map +0 -1
- package/dist/utils/signature.d.ts.map +0 -1
- package/dist/utils/signature.js.map +0 -1
- package/dist/utils/swaps.d.ts.map +0 -1
- package/dist/utils/swaps.js.map +0 -1
- package/dist/utils/transaction-type.d.ts.map +0 -1
- package/dist/utils/transaction-type.js.map +0 -1
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/utils.js.map +0 -1
- package/dist/utils/validation.d.ts.map +0 -1
- package/dist/utils/validation.js.map +0 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/// <reference types="debug" />
|
|
2
|
+
import type { NetworkClientId } from "@metamask/network-controller";
|
|
3
|
+
import type { Hex } from "@metamask/utils";
|
|
4
|
+
import type { TransactionControllerMessenger } from "../TransactionController.mjs";
|
|
5
|
+
import type { BatchTransactionParams, GetSimulationConfig, IsAtomicBatchSupportedRequest, IsAtomicBatchSupportedResult, Revert, TransactionBatchSingleRequest, TransactionMeta, TransactionParams } from "../types.mjs";
|
|
6
|
+
export type UpdateGasRequest = {
|
|
7
|
+
isCustomNetwork: boolean;
|
|
8
|
+
isSimulationEnabled: boolean;
|
|
9
|
+
getSimulationConfig: GetSimulationConfig;
|
|
10
|
+
messenger: TransactionControllerMessenger;
|
|
11
|
+
txMeta: TransactionMeta;
|
|
12
|
+
};
|
|
13
|
+
export type EstimateGasBatchResult = {
|
|
14
|
+
gasLimits: number[];
|
|
15
|
+
requiresAuthorizationList?: true;
|
|
16
|
+
totalGasLimit: number;
|
|
17
|
+
};
|
|
18
|
+
export declare const log: import("debug").Debugger;
|
|
19
|
+
export declare const FIXED_GAS = "0x5208";
|
|
20
|
+
export declare const DEFAULT_GAS_MULTIPLIER = 1.5;
|
|
21
|
+
export declare const MAX_GAS_BLOCK_PERCENT = 90;
|
|
22
|
+
export declare const INTRINSIC_GAS = 21000;
|
|
23
|
+
export declare const DUMMY_AUTHORIZATION_SIGNATURE = "0x1111111111111111111111111111111111111111111111111111111111111111";
|
|
24
|
+
/**
|
|
25
|
+
* Populate the gas properties of the provided transaction meta.
|
|
26
|
+
*
|
|
27
|
+
* @param request - The request object including the necessary parameters.
|
|
28
|
+
*/
|
|
29
|
+
export declare function updateGas(request: UpdateGasRequest): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Estimate the gas for the provided transaction parameters.
|
|
32
|
+
* If the gas estimate fails, the fallback value is returned.
|
|
33
|
+
*
|
|
34
|
+
* @param options - The options object.
|
|
35
|
+
* @param options.ignoreDelegationSignatures - Ignore signature errors if submitting delegations to the DelegationManager.
|
|
36
|
+
* @param options.isSimulationEnabled - Whether the simulation is enabled.
|
|
37
|
+
* @param options.getSimulationConfig - The function to get the simulation configuration.
|
|
38
|
+
* @param options.messenger - The messenger instance for communication.
|
|
39
|
+
* @param options.networkClientId - The network client ID.
|
|
40
|
+
* @param options.txParams - The transaction parameters.
|
|
41
|
+
* @returns The estimated gas and related info.
|
|
42
|
+
*/
|
|
43
|
+
export declare function estimateGas({ ignoreDelegationSignatures, isSimulationEnabled, getSimulationConfig, messenger, networkClientId, txParams, }: {
|
|
44
|
+
ignoreDelegationSignatures?: boolean;
|
|
45
|
+
isSimulationEnabled: boolean;
|
|
46
|
+
getSimulationConfig: GetSimulationConfig;
|
|
47
|
+
messenger: TransactionControllerMessenger;
|
|
48
|
+
networkClientId: NetworkClientId;
|
|
49
|
+
txParams: TransactionParams;
|
|
50
|
+
}): Promise<{
|
|
51
|
+
blockGasLimit: string;
|
|
52
|
+
estimatedGas: string;
|
|
53
|
+
gasRevert?: Revert;
|
|
54
|
+
isUpgradeWithData: boolean;
|
|
55
|
+
simulationFails: TransactionMeta['simulationFails'];
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Sum caller-provided gas limits across a batch.
|
|
59
|
+
*
|
|
60
|
+
* If every transaction in the batch already has a `gas` value, returns the
|
|
61
|
+
* parsed per-tx limits and their sum. Otherwise returns `undefined`.
|
|
62
|
+
*
|
|
63
|
+
* Used by `estimateGasBatch`:
|
|
64
|
+
* - non-7702 path: short-circuits simulation entirely when present.
|
|
65
|
+
* - EIP-7702 path: used as a fallback when simulation fails — required for
|
|
66
|
+
* callers that submit batches whose individual sub-calls cannot be simulated
|
|
67
|
+
* standalone (e.g. predict-withdraw, where the batch's first sub-call
|
|
68
|
+
* provides source-token balance to subsequent sub-calls). When 7702
|
|
69
|
+
* simulation succeeds it is preferred since the bundled call has no per-tx
|
|
70
|
+
* intrinsic gas cost and produces a tighter estimate.
|
|
71
|
+
*
|
|
72
|
+
* @param transactions - Batch transactions to inspect.
|
|
73
|
+
* @returns Parsed gas limits and total when every transaction has gas; otherwise `undefined`.
|
|
74
|
+
*/
|
|
75
|
+
export declare function getProvidedBatchGasLimits(transactions: BatchTransactionParams[]): {
|
|
76
|
+
gasLimits: number[];
|
|
77
|
+
totalGasLimit: number;
|
|
78
|
+
} | undefined;
|
|
79
|
+
export declare function estimateGasBatch({ from, getSimulationConfig, isAtomicBatchSupported, messenger, networkClientId, transactions, }: {
|
|
80
|
+
from: Hex;
|
|
81
|
+
getSimulationConfig: GetSimulationConfig;
|
|
82
|
+
isAtomicBatchSupported: (request: IsAtomicBatchSupportedRequest) => Promise<IsAtomicBatchSupportedResult>;
|
|
83
|
+
messenger: TransactionControllerMessenger;
|
|
84
|
+
networkClientId: NetworkClientId;
|
|
85
|
+
transactions: BatchTransactionParams[];
|
|
86
|
+
}): Promise<EstimateGasBatchResult>;
|
|
87
|
+
/**
|
|
88
|
+
* Add a buffer to the provided estimated gas.
|
|
89
|
+
* The buffer is calculated based on the block gas limit and a multiplier.
|
|
90
|
+
*
|
|
91
|
+
* @param estimatedGas - The estimated gas.
|
|
92
|
+
* @param blockGasLimit - The block gas limit.
|
|
93
|
+
* @param multiplier - The multiplier to apply to the estimated gas.
|
|
94
|
+
* @returns The gas with the buffer applied.
|
|
95
|
+
*/
|
|
96
|
+
export declare function addGasBuffer(estimatedGas: string, blockGasLimit: string, multiplier: number): string;
|
|
97
|
+
/**
|
|
98
|
+
* Simulate the required gas for a batch of transactions using the simulation API.
|
|
99
|
+
*
|
|
100
|
+
* @param options - The options object.
|
|
101
|
+
* @param options.chainId - The chain ID of the transactions.
|
|
102
|
+
* @param options.from - The address of the sender.
|
|
103
|
+
* @param options.getSimulationConfig - The function to get the simulation configuration.
|
|
104
|
+
* @param options.transactions - The array of transactions within a batch request.
|
|
105
|
+
* @returns An object containing the transactions with their gas limits and the total gas limit.
|
|
106
|
+
*/
|
|
107
|
+
export declare function simulateGasBatch({ chainId, from, getSimulationConfig, transactions, }: {
|
|
108
|
+
chainId: Hex;
|
|
109
|
+
from: Hex;
|
|
110
|
+
getSimulationConfig: GetSimulationConfig;
|
|
111
|
+
transactions: TransactionBatchSingleRequest[];
|
|
112
|
+
}): Promise<{
|
|
113
|
+
totalGasLimit: Hex;
|
|
114
|
+
gasLimits: Hex[];
|
|
115
|
+
}>;
|
|
116
|
+
//# sourceMappingURL=gas.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas.d.mts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AACpE,OAAO,KAAK,EAAE,GAAG,EAAQ,wBAAwB;AAWjD,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAElF,OAAO,KAAK,EAEV,sBAAsB,EACtB,mBAAmB,EACnB,6BAA6B,EAC7B,4BAA4B,EAC5B,MAAM,EACN,6B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add0x, createModuleLogger, isStrictHexString, remove0x
|
|
3
|
-
import { BigNumber } from
|
|
4
|
-
import { simulateTransactions } from
|
|
5
|
-
import { projectLogger } from
|
|
6
|
-
import { TransactionEnvelopeType } from
|
|
7
|
-
import { DELEGATION_PREFIX, doesAccountSupportEIP7702, generateEIP7702BatchTransaction
|
|
8
|
-
import { getGasEstimateBuffer, getGasEstimateFallback
|
|
9
|
-
import { getChainId, rpcRequest } from
|
|
10
|
-
import { decodeRevert } from
|
|
1
|
+
import { BNToHex, fractionBN, hexToBN, toHex } from "@metamask/controller-utils";
|
|
2
|
+
import { add0x, createModuleLogger, isStrictHexString, remove0x } from "@metamask/utils";
|
|
3
|
+
import { BigNumber } from "bignumber.js";
|
|
4
|
+
import { simulateTransactions } from "../api/simulation-api.mjs";
|
|
5
|
+
import { projectLogger } from "../logger.mjs";
|
|
6
|
+
import { TransactionEnvelopeType } from "../types.mjs";
|
|
7
|
+
import { DELEGATION_PREFIX, doesAccountSupportEIP7702, generateEIP7702BatchTransaction } from "./eip7702.mjs";
|
|
8
|
+
import { getGasEstimateBuffer, getGasEstimateFallback } from "./feature-flags.mjs";
|
|
9
|
+
import { getChainId, rpcRequest } from "./provider.mjs";
|
|
10
|
+
import { decodeRevert } from "./revert-reason.mjs";
|
|
11
11
|
export const log = createModuleLogger(projectLogger, 'gas');
|
|
12
12
|
export const FIXED_GAS = '0x5208';
|
|
13
13
|
export const DEFAULT_GAS_MULTIPLIER = 1.5;
|
|
@@ -533,4 +533,4 @@ async function estimateGasNode(messenger, networkClientId, txParams, delegationA
|
|
|
533
533
|
params,
|
|
534
534
|
}));
|
|
535
535
|
}
|
|
536
|
-
//# sourceMappingURL=gas.
|
|
536
|
+
//# sourceMappingURL=gas.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas.mjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,UAAU,EACV,OAAO,EAC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C,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AACzD,CAAC;AAED;;;;;;;;GAQG;AACH,KAAK,UAAU,eAAe,CAC5B,SAAyC,EACzC,eAAgC,EAChC,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,CAAC,MAAM,UAAU,CAAC;QACvB,SAAS;QACT,eAAe;QACf,MAAM,EAAE,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 {\n add0x,\n createModuleLogger,\n isStrictHexString,\n remove0x,\n} from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport { simulateTransactions } from '../api/simulation-api.js';\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport { TransactionEnvelopeType } from '../types.js';\nimport type {\n AuthorizationList,\n BatchTransactionParams,\n GetSimulationConfig,\n IsAtomicBatchSupportedRequest,\n IsAtomicBatchSupportedResult,\n Revert,\n TransactionBatchSingleRequest,\n TransactionMeta,\n TransactionParams,\n} from '../types.js';\nimport {\n DELEGATION_PREFIX,\n doesAccountSupportEIP7702,\n generateEIP7702BatchTransaction,\n} from './eip7702.js';\nimport {\n getGasEstimateBuffer,\n getGasEstimateFallback,\n} from './feature-flags.js';\nimport { getChainId, rpcRequest } from './provider.js';\nimport { decodeRevert } from './revert-reason.js';\n\nexport type UpdateGasRequest = {\n isCustomNetwork: boolean;\n isSimulationEnabled: boolean;\n getSimulationConfig: GetSimulationConfig;\n messenger: TransactionControllerMessenger;\n txMeta: TransactionMeta;\n};\n\nexport type EstimateGasBatchResult = {\n gasLimits: number[];\n requiresAuthorizationList?: true;\n totalGasLimit: number;\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, gasRevert] =\n await getGas(request);\n\n txMeta.txParams.gas = gas;\n txMeta.simulationFails = simulationFails;\n txMeta.gasLimitNoBuffer = gasLimitNoBuffer;\n\n if (gasRevert) {\n txMeta.revert = { ...txMeta.revert, gas: gasRevert };\n }\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 gasRevert?: Revert;\n isUpgradeWithData: boolean;\n simulationFails: TransactionMeta['simulationFails'];\n}> {\n const request = { ...txParams };\n const { authorizationList, data, value } = 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, maxGasLimit } = getGasEstimateFallback(\n chainId,\n messenger,\n );\n\n const uncappedFallback = fixed\n ? toHex(fixed)\n : BNToHex(fractionBN(blockGasLimitBN, percentage, 100));\n\n // Clamp the fallback to the chain's per-transaction gas cap so it can never\n // exceed the gas limit the RPC will accept. Without this, a percentage of a\n // high block gas limit can overshoot the cap (e.g. 35% of Polygon's ~140M\n // block limit is ~49M, but the node caps a tx at ~33.5M and rejects it with\n // \"transaction gas limit too high\").\n const fallback =\n maxGasLimit !== undefined &&\n hexToBN(uncappedFallback).gt(hexToBN(toHex(maxGasLimit)))\n ? toHex(maxGasLimit)\n : uncappedFallback;\n\n log('Estimation fallback values', fallback);\n\n request.data = data ? add0x(data) : data;\n request.value = normalizeValue(value);\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 let gasRevert: Revert | undefined;\n\n const isUpgradeWithData =\n txParams.type === TransactionEnvelopeType.setCode &&\n Boolean(authorizationList?.length) &&\n Boolean(data) &&\n data !== '0x';\n\n try {\n if (isSimulationEnabled && isUpgradeWithData) {\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 gasRevert = decodeRevert(error, 'gas');\n\n log('Estimation failed', { ...simulationFails, fallback, gasRevert });\n }\n\n return {\n blockGasLimit,\n estimatedGas,\n gasRevert,\n isUpgradeWithData,\n simulationFails,\n };\n}\n\n/**\n * Sum caller-provided gas limits across a batch.\n *\n * If every transaction in the batch already has a `gas` value, returns the\n * parsed per-tx limits and their sum. Otherwise returns `undefined`.\n *\n * Used by `estimateGasBatch`:\n * - non-7702 path: short-circuits simulation entirely when present.\n * - EIP-7702 path: used as a fallback when simulation fails — required for\n * callers that submit batches whose individual sub-calls cannot be simulated\n * standalone (e.g. predict-withdraw, where the batch's first sub-call\n * provides source-token balance to subsequent sub-calls). When 7702\n * simulation succeeds it is preferred since the bundled call has no per-tx\n * intrinsic gas cost and produces a tighter estimate.\n *\n * @param transactions - Batch transactions to inspect.\n * @returns Parsed gas limits and total when every transaction has gas; otherwise `undefined`.\n */\nexport function getProvidedBatchGasLimits(\n transactions: BatchTransactionParams[],\n): { gasLimits: number[]; totalGasLimit: number } | undefined {\n if (!transactions.every((transaction) => transaction.gas !== undefined)) {\n return undefined;\n }\n\n const gasLimits = transactions.map((transaction) =>\n new BigNumber(transaction.gas as Hex).toNumber(),\n );\n const totalGasLimit = gasLimits.reduce((acc, gasLimit) => acc + gasLimit, 0);\n\n return { gasLimits, totalGasLimit };\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<EstimateGasBatchResult> {\n const chainId = getChainId({ messenger, networkClientId });\n\n const is7702Result = await isAtomicBatchSupported({\n address: from,\n chainIds: [chainId],\n });\n\n const accountSupports7702 = doesAccountSupportEIP7702(messenger, from);\n\n const chainResult = accountSupports7702\n ? is7702Result.find((result) => result.chainId === chainId)\n : undefined;\n\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 providedBatchGasLimits = getProvidedBatchGasLimits(transactions);\n\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 // Prefer real EIP-7702 simulation when it succeeds — the bundled call has\n // no per-tx intrinsic gas cost so the estimate is typically lower than\n // summing per-tx provided limits. Fall back to the provided sum when the\n // node-level simulation fails (e.g. predict-withdraw, where the batch's\n // first sub-call provides source-token balance to subsequent sub-calls).\n const { estimatedGas: gasLimitHex, simulationFails } = await estimateGas({\n isSimulationEnabled: true,\n getSimulationConfig,\n messenger,\n networkClientId,\n txParams: params,\n });\n\n if (simulationFails && providedBatchGasLimits) {\n log(\n 'EIP-7702 estimation failed, using batch parameter gas limits',\n providedBatchGasLimits,\n simulationFails,\n );\n return {\n gasLimits: [providedBatchGasLimits.totalGasLimit],\n ...(isUpgradeRequired ? { requiresAuthorizationList: true } : {}),\n totalGasLimit: providedBatchGasLimits.totalGasLimit,\n };\n }\n\n const totalGasLimit = new BigNumber(gasLimitHex).toNumber();\n\n log('Estimated EIP-7702 gas limit', totalGasLimit);\n\n return {\n gasLimits: [totalGasLimit],\n ...(isUpgradeRequired ? { requiresAuthorizationList: true } : {}),\n totalGasLimit,\n };\n }\n\n const providedBatchGasLimits = getProvidedBatchGasLimits(transactions);\n if (providedBatchGasLimits) {\n log('Using batch parameter gas limits', providedBatchGasLimits);\n return providedBatchGasLimits;\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?, Revert?]> {\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 gasRevert,\n isUpgradeWithData,\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, gasRevert];\n }\n\n const bufferMultiplier = getGasEstimateBuffer({\n chainId,\n isCustomRPC: isCustomNetwork,\n isUpgradeWithData,\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, gasRevert];\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 to: txParams.from,\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 * Normalize the value to a canonical hex quantity with no leading zero digits.\n * Some RPC nodes (e.g. Go's `hexutil`) reject quantities such as `0x00` or\n * `0x0de0b6b3a7640000`, failing gas estimation entirely.\n *\n * @param value - The transaction value to normalize.\n * @returns The normalized transaction value.\n */\nfunction normalizeValue(value: string | undefined): string {\n const valueOrDefault = value ?? '0x0';\n\n if (!isStrictHexString(valueOrDefault)) {\n return valueOrDefault;\n }\n\n const stripped = remove0x(valueOrDefault).replace(/^0+/u, '');\n\n return stripped.length === 0 ? '0x0' : add0x(stripped);\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"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTransactionLayer1GasFee = exports.updateTransactionLayer1GasFee = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
const logger_js_1 = require("../logger.cjs");
|
|
6
|
+
const log = (0, utils_1.createModuleLogger)(logger_js_1.projectLogger, 'layer-1-gas-fee-flow');
|
|
7
|
+
/**
|
|
8
|
+
* Updates the given transactionMeta with the layer 1 gas fee.
|
|
9
|
+
*
|
|
10
|
+
* @param request - The request to use when getting the layer 1 gas fee.
|
|
11
|
+
* @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
|
|
12
|
+
* @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.
|
|
13
|
+
* @param request.messenger - The messenger instance.
|
|
14
|
+
*/
|
|
15
|
+
async function updateTransactionLayer1GasFee(request) {
|
|
16
|
+
const layer1GasFee = await getTransactionLayer1GasFee(request);
|
|
17
|
+
if (!layer1GasFee) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const { transactionMeta } = request;
|
|
21
|
+
transactionMeta.layer1GasFee = layer1GasFee;
|
|
22
|
+
log('Updated layer 1 gas fee', layer1GasFee, transactionMeta.id);
|
|
23
|
+
}
|
|
24
|
+
exports.updateTransactionLayer1GasFee = updateTransactionLayer1GasFee;
|
|
25
|
+
/**
|
|
26
|
+
* Get the layer 1 gas fee flow for a transaction.
|
|
27
|
+
*
|
|
28
|
+
* @param transactionMeta - The transaction to get the layer 1 gas fee flow for.
|
|
29
|
+
* @param layer1GasFeeFlows - The layer 1 gas fee flows to search.
|
|
30
|
+
* @param messenger - The messenger instance.
|
|
31
|
+
* @returns The layer 1 gas fee flow for the transaction, or undefined if none match.
|
|
32
|
+
*/
|
|
33
|
+
async function getLayer1GasFeeFlow(transactionMeta, layer1GasFeeFlows, messenger) {
|
|
34
|
+
for (const layer1GasFeeFlow of layer1GasFeeFlows) {
|
|
35
|
+
const matches = await layer1GasFeeFlow.matchesTransaction({
|
|
36
|
+
transactionMeta,
|
|
37
|
+
messenger,
|
|
38
|
+
});
|
|
39
|
+
if (matches) {
|
|
40
|
+
return layer1GasFeeFlow;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get the layer 1 gas fee for a transaction.
|
|
47
|
+
*
|
|
48
|
+
* @param request - The request to use when getting the layer 1 gas fee.
|
|
49
|
+
* @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.
|
|
50
|
+
* @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
|
|
51
|
+
* @param request.messenger - The messenger instance.
|
|
52
|
+
* @returns The layer 1 gas fee.
|
|
53
|
+
*/
|
|
54
|
+
async function getTransactionLayer1GasFee({ layer1GasFeeFlows, messenger, transactionMeta, }) {
|
|
55
|
+
const layer1GasFeeFlow = await getLayer1GasFeeFlow(transactionMeta, layer1GasFeeFlows, messenger);
|
|
56
|
+
if (!layer1GasFeeFlow) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
log('Found layer 1 gas fee flow', layer1GasFeeFlow.constructor.name, transactionMeta.id);
|
|
60
|
+
try {
|
|
61
|
+
const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({
|
|
62
|
+
messenger,
|
|
63
|
+
transactionMeta,
|
|
64
|
+
});
|
|
65
|
+
return layer1Fee;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
log('Failed to get layer 1 gas fee', transactionMeta.id, error);
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.getTransactionLayer1GasFee = getTransactionLayer1GasFee;
|
|
73
|
+
//# sourceMappingURL=layer1-gas-fee-flow.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layer1-gas-fee-flow.cjs","sourceRoot":"","sources":["../../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":";;;AAAA,2CAAqD;AAGrD,6CAA6C;AAI7C,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,yBAAa,EAAE,sBAAsB,CAAC,CAAC;AAQtE;;;;;;;GAOG;AACI,KAAK,UAAU,6BAA6B,CACjD,OAAkC;IAElC,MAAM,YAAY,GAAG,MAAM,0BAA0B,CAAC,OAAO,CAAC,CAAC;IAE/D,IAAI,CAAC,YAAY,EAAE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;AACH,CAAC;AA/BD,gEA+BC","sourcesContent":["import { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type { Layer1GasFeeFlow, TransactionMeta } from '../types.js';\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 { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({\n messenger,\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,6 +1,6 @@
|
|
|
1
|
-
import type { Hex } from
|
|
2
|
-
import type { TransactionControllerMessenger } from
|
|
3
|
-
import type { Layer1GasFeeFlow, TransactionMeta } from
|
|
1
|
+
import type { Hex } from "@metamask/utils";
|
|
2
|
+
import type { TransactionControllerMessenger } from "../TransactionController.cjs";
|
|
3
|
+
import type { Layer1GasFeeFlow, TransactionMeta } from "../types.cjs";
|
|
4
4
|
export type UpdateLayer1GasFeeRequest = {
|
|
5
5
|
layer1GasFeeFlows: Layer1GasFeeFlow[];
|
|
6
6
|
messenger: TransactionControllerMessenger;
|
|
@@ -25,4 +25,4 @@ export declare function updateTransactionLayer1GasFee(request: UpdateLayer1GasFe
|
|
|
25
25
|
* @returns The layer 1 gas fee.
|
|
26
26
|
*/
|
|
27
27
|
export declare function getTransactionLayer1GasFee({ layer1GasFeeFlows, messenger, transactionMeta, }: UpdateLayer1GasFeeRequest): Promise<Hex | undefined>;
|
|
28
|
-
//# sourceMappingURL=layer1-gas-fee-flow.d.
|
|
28
|
+
//# sourceMappingURL=layer1-gas-fee-flow.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAG3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,qBAAoB;AAIrE,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,CA2BtD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Hex } from "@metamask/utils";
|
|
2
|
+
import type { TransactionControllerMessenger } from "../TransactionController.mjs";
|
|
3
|
+
import type { Layer1GasFeeFlow, TransactionMeta } from "../types.mjs";
|
|
4
|
+
export type UpdateLayer1GasFeeRequest = {
|
|
5
|
+
layer1GasFeeFlows: Layer1GasFeeFlow[];
|
|
6
|
+
messenger: TransactionControllerMessenger;
|
|
7
|
+
transactionMeta: TransactionMeta;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Updates the given transactionMeta with the layer 1 gas fee.
|
|
11
|
+
*
|
|
12
|
+
* @param request - The request to use when getting the layer 1 gas fee.
|
|
13
|
+
* @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
|
|
14
|
+
* @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.
|
|
15
|
+
* @param request.messenger - The messenger instance.
|
|
16
|
+
*/
|
|
17
|
+
export declare function updateTransactionLayer1GasFee(request: UpdateLayer1GasFeeRequest): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Get the layer 1 gas fee for a transaction.
|
|
20
|
+
*
|
|
21
|
+
* @param request - The request to use when getting the layer 1 gas fee.
|
|
22
|
+
* @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.
|
|
23
|
+
* @param request.transactionMeta - The transaction to get the layer 1 gas fee for.
|
|
24
|
+
* @param request.messenger - The messenger instance.
|
|
25
|
+
* @returns The layer 1 gas fee.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getTransactionLayer1GasFee({ layer1GasFeeFlows, messenger, transactionMeta, }: UpdateLayer1GasFeeRequest): Promise<Hex | undefined>;
|
|
28
|
+
//# sourceMappingURL=layer1-gas-fee-flow.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAG3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,qBAAoB;AAIrE,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,CA2BtD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createModuleLogger } from
|
|
2
|
-
import { projectLogger } from
|
|
1
|
+
import { createModuleLogger } from "@metamask/utils";
|
|
2
|
+
import { projectLogger } from "../logger.mjs";
|
|
3
3
|
const log = createModuleLogger(projectLogger, 'layer-1-gas-fee-flow');
|
|
4
4
|
/**
|
|
5
5
|
* Updates the given transactionMeta with the layer 1 gas fee.
|
|
@@ -65,4 +65,4 @@ export async function getTransactionLayer1GasFee({ layer1GasFeeFlows, messenger,
|
|
|
65
65
|
return undefined;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
//# sourceMappingURL=layer1-gas-fee-flow.
|
|
68
|
+
//# sourceMappingURL=layer1-gas-fee-flow.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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,aAAa,EAAE,sBAAqB;AAI7C,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,CAAC;IAED,MAAM,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IAEpC,eAAe,CAAC,YAAY,GAAG,YAAY,CAAC;IAE5C,GAAG,CAAC,yBAAyB,EAAE,YAAY,EAAE,eAAe,CAAC,EAAE,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;;GAOG;AACH,KAAK,UAAU,mBAAmB,CAChC,eAAgC,EAChC,iBAAqC,EACrC,SAAyC;IAEzC,KAAK,MAAM,gBAAgB,IAAI,iBAAiB,EAAE,CAAC;QACjD,MAAM,OAAO,GAAG,MAAM,gBAAgB,CAAC,kBAAkB,CAAC;YACxD,eAAe;YACf,SAAS;SACV,CAAC,CAAC;QAEH,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,gBAAgB,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,EAC/C,iBAAiB,EACjB,SAAS,EACT,eAAe,GACW;IAC1B,MAAM,gBAAgB,GAAG,MAAM,mBAAmB,CAChD,eAAe,EACf,iBAAiB,EACjB,SAAS,CACV,CAAC;IAEF,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,GAAG,CACD,4BAA4B,EAC5B,gBAAgB,CAAC,WAAW,CAAC,IAAI,EACjC,eAAe,CAAC,EAAE,CACnB,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,gBAAgB,CAAC,YAAY,CAAC;YACxD,SAAS;YACT,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","sourcesContent":["import { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type { Layer1GasFeeFlow, TransactionMeta } from '../types.js';\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 { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({\n messenger,\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"]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAndFormatTransactionsForNonceTracker = exports.getNextNonce = void 0;
|
|
4
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
5
|
+
const logger_js_1 = require("../logger.cjs");
|
|
6
|
+
const eip7702_js_1 = require("./eip7702.cjs");
|
|
7
|
+
const log = (0, logger_js_1.createModuleLogger)(logger_js_1.projectLogger, 'nonce');
|
|
8
|
+
/**
|
|
9
|
+
* Determine the next nonce to be used for a transaction.
|
|
10
|
+
*
|
|
11
|
+
* @param txMeta - The transaction metadata.
|
|
12
|
+
* @param getNonceLock - An anonymous function that acquires the nonce lock for an address
|
|
13
|
+
* @returns The next hexadecimal nonce to be used for the given transaction, and optionally a function to release the nonce lock.
|
|
14
|
+
*/
|
|
15
|
+
async function getNextNonce(txMeta, getNonceLock) {
|
|
16
|
+
const { customNonceValue, isExternalSign, txParams: { from, nonce: existingNonce }, } = txMeta;
|
|
17
|
+
if (isExternalSign) {
|
|
18
|
+
log('Skipping nonce as signed externally');
|
|
19
|
+
return [undefined, undefined];
|
|
20
|
+
}
|
|
21
|
+
const customNonce = customNonceValue ? (0, controller_utils_1.toHex)(customNonceValue) : undefined;
|
|
22
|
+
if (customNonce) {
|
|
23
|
+
log('Using custom nonce', customNonce);
|
|
24
|
+
return [customNonce, undefined];
|
|
25
|
+
}
|
|
26
|
+
if (existingNonce) {
|
|
27
|
+
log('Using existing nonce', existingNonce);
|
|
28
|
+
return [existingNonce, undefined];
|
|
29
|
+
}
|
|
30
|
+
const nonceLock = await getNonceLock(from);
|
|
31
|
+
const nonce = (0, controller_utils_1.toHex)(nonceLock.nextNonce);
|
|
32
|
+
const releaseLock = nonceLock.releaseLock.bind(nonceLock);
|
|
33
|
+
log('Using nonce from nonce tracker', nonce, nonceLock.nonceDetails);
|
|
34
|
+
return [nonce, releaseLock];
|
|
35
|
+
}
|
|
36
|
+
exports.getNextNonce = getNextNonce;
|
|
37
|
+
/**
|
|
38
|
+
* Filter and format transactions for the nonce tracker.
|
|
39
|
+
*
|
|
40
|
+
* Includes the outer transaction nonce when `txParams.from` matches, and EIP-7702
|
|
41
|
+
* authorization nonces only when their recovered authority matches `fromAddress`.
|
|
42
|
+
* This keeps foreign authorizations (e.g. Money Account upgrades on a same-chain
|
|
43
|
+
* pay batch) out of the payer's nonce history.
|
|
44
|
+
*
|
|
45
|
+
* @param currentChainId - Chain ID of the current network.
|
|
46
|
+
* @param fromAddress - Address of the account from which the transactions to filter from are sent.
|
|
47
|
+
* @param transactionStatuses - Status of the transactions for which to filter.
|
|
48
|
+
* @param transactions - Array of transactionMeta objects that have been prefiltered.
|
|
49
|
+
* @returns Array of transactions formatted for the nonce tracker.
|
|
50
|
+
*/
|
|
51
|
+
function getAndFormatTransactionsForNonceTracker(currentChainId, fromAddress, transactionStatuses, transactions) {
|
|
52
|
+
const normalizedFromAddress = fromAddress.toLowerCase();
|
|
53
|
+
return transactions
|
|
54
|
+
.filter(({ chainId, isTransfer, isUserOperation, status, txParams: { nonce } }) => !isTransfer &&
|
|
55
|
+
!isUserOperation &&
|
|
56
|
+
chainId === currentChainId &&
|
|
57
|
+
transactionStatuses.includes(status) &&
|
|
58
|
+
Boolean(nonce))
|
|
59
|
+
.flatMap(({ status, txParams }) => {
|
|
60
|
+
const { authorizationList, from, gas, value, nonce } = txParams;
|
|
61
|
+
// the only value we care about is the nonce
|
|
62
|
+
// but we need to return the other values to satisfy the type
|
|
63
|
+
// TODO: refactor nonceTracker to not require this
|
|
64
|
+
/* istanbul ignore next */
|
|
65
|
+
const toNonceTrackerTransaction = (currentNonce, authority) => ({
|
|
66
|
+
status,
|
|
67
|
+
history: [{}],
|
|
68
|
+
txParams: {
|
|
69
|
+
from: authority,
|
|
70
|
+
gas: gas ?? '',
|
|
71
|
+
value: value ?? '',
|
|
72
|
+
nonce: currentNonce,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
const formatted = [];
|
|
76
|
+
if (from.toLowerCase() === normalizedFromAddress && nonce) {
|
|
77
|
+
formatted.push(toNonceTrackerTransaction(nonce, from));
|
|
78
|
+
}
|
|
79
|
+
for (const authorization of authorizationList ?? []) {
|
|
80
|
+
if (authorization.nonce === undefined) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const authority = (0, eip7702_js_1.getAuthorizationAuthority)(authorization, from);
|
|
84
|
+
if (authority?.toLowerCase() !== normalizedFromAddress) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
formatted.push(toNonceTrackerTransaction(authorization.nonce, authority));
|
|
88
|
+
}
|
|
89
|
+
return formatted;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
exports.getAndFormatTransactionsForNonceTracker = getAndFormatTransactionsForNonceTracker;
|
|
93
|
+
//# sourceMappingURL=nonce.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nonce.cjs","sourceRoot":"","sources":["../../src/utils/nonce.ts"],"names":[],"mappings":";;;AAAA,iEAAmD;AAMnD,6CAAiE;AAEjE,8CAAyD;AAEzD,MAAM,GAAG,GAAG,IAAA,8BAAkB,EAAC,yBAAa,EAAE,OAAO,CAAC,CAAC;AAEvD;;;;;;GAMG;AACI,KAAK,UAAU,YAAY,CAChC,MAAuB,EACvB,YAAqD;IAErD,MAAM,EACJ,gBAAgB,EAChB,cAAc,EACd,QAAQ,EAAE,EAAE,IAAI,EAAE,KAAK,E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,SAAS,CAAC,CAC1D,CAAC;QACJ,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;AACP,CAAC;AA7DD,0FA6DC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type {\n NonceLock,\n Transaction as NonceTrackerTransaction,\n} from '@metamask/nonce-tracker';\n\nimport { createModuleLogger, projectLogger } from '../logger.js';\nimport type { TransactionMeta, TransactionStatus } from '../types.js';\nimport { getAuthorizationAuthority } from './eip7702.js';\n\nconst log = createModuleLogger(projectLogger, 'nonce');\n\n/**\n * Determine the next nonce to be used for a transaction.\n *\n * @param txMeta - The transaction metadata.\n * @param getNonceLock - An anonymous function that acquires the nonce lock for an address\n * @returns The next hexadecimal nonce to be used for the given transaction, and optionally a function to release the nonce lock.\n */\nexport async function getNextNonce(\n txMeta: TransactionMeta,\n getNonceLock: (address: string) => Promise<NonceLock>,\n): Promise<[string | undefined, (() => void) | undefined]> {\n const {\n customNonceValue,\n isExternalSign,\n txParams: { from, nonce: existingNonce },\n } = txMeta;\n\n if (isExternalSign) {\n log('Skipping nonce as signed externally');\n return [undefined, undefined];\n }\n\n const customNonce = customNonceValue ? toHex(customNonceValue) : undefined;\n\n if (customNonce) {\n log('Using custom nonce', customNonce);\n return [customNonce, undefined];\n }\n\n if (existingNonce) {\n log('Using existing nonce', existingNonce);\n return [existingNonce, undefined];\n }\n\n const nonceLock = await getNonceLock(from);\n const nonce = toHex(nonceLock.nextNonce);\n const releaseLock = nonceLock.releaseLock.bind(nonceLock);\n\n log('Using nonce from nonce tracker', nonce, nonceLock.nonceDetails);\n\n return [nonce, releaseLock];\n}\n\n/**\n * Filter and format transactions for the nonce tracker.\n *\n * Includes the outer transaction nonce when `txParams.from` matches, and EIP-7702\n * authorization nonces only when their recovered authority matches `fromAddress`.\n * This keeps foreign authorizations (e.g. Money Account upgrades on a same-chain\n * pay batch) out of the payer's nonce history.\n *\n * @param currentChainId - Chain ID of the current network.\n * @param fromAddress - Address of the account from which the transactions to filter from are sent.\n * @param transactionStatuses - Status of the transactions for which to filter.\n * @param transactions - Array of transactionMeta objects that have been prefiltered.\n * @returns Array of transactions formatted for the nonce tracker.\n */\nexport function getAndFormatTransactionsForNonceTracker(\n currentChainId: string,\n fromAddress: string,\n transactionStatuses: TransactionStatus[],\n transactions: TransactionMeta[],\n): NonceTrackerTransaction[] {\n const normalizedFromAddress = fromAddress.toLowerCase();\n\n return transactions\n .filter(\n ({ chainId, isTransfer, isUserOperation, status, txParams: { nonce } }) =>\n !isTransfer &&\n !isUserOperation &&\n chainId === currentChainId &&\n transactionStatuses.includes(status) &&\n Boolean(nonce),\n )\n .flatMap(({ status, txParams }) => {\n const { authorizationList, from, gas, value, nonce } = txParams;\n // the only value we care about is the nonce\n // but we need to return the other values to satisfy the type\n // TODO: refactor nonceTracker to not require this\n /* istanbul ignore next */\n const toNonceTrackerTransaction = (\n currentNonce: string,\n authority: string,\n ): NonceTrackerTransaction => ({\n status,\n history: [{}],\n txParams: {\n from: authority,\n gas: gas ?? '',\n value: value ?? '',\n nonce: currentNonce,\n },\n });\n\n const formatted: NonceTrackerTransaction[] = [];\n\n if (from.toLowerCase() === normalizedFromAddress && nonce) {\n formatted.push(toNonceTrackerTransaction(nonce, from));\n }\n\n for (const authorization of authorizationList ?? []) {\n if (authorization.nonce === undefined) {\n continue;\n }\n\n const authority = getAuthorizationAuthority(authorization, from);\n\n if (authority?.toLowerCase() !== normalizedFromAddress) {\n continue;\n }\n\n formatted.push(\n toNonceTrackerTransaction(authorization.nonce, authority),\n );\n }\n\n return formatted;\n });\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { NonceLock, Transaction as NonceTrackerTransaction } from
|
|
2
|
-
import type { TransactionMeta, TransactionStatus } from
|
|
1
|
+
import type { NonceLock, Transaction as NonceTrackerTransaction } from "@metamask/nonce-tracker";
|
|
2
|
+
import type { TransactionMeta, TransactionStatus } from "../types.cjs";
|
|
3
3
|
/**
|
|
4
4
|
* Determine the next nonce to be used for a transaction.
|
|
5
5
|
*
|
|
@@ -23,4 +23,4 @@ export declare function getNextNonce(txMeta: TransactionMeta, getNonceLock: (add
|
|
|
23
23
|
* @returns Array of transactions formatted for the nonce tracker.
|
|
24
24
|
*/
|
|
25
25
|
export declare function getAndFormatTransactionsForNonceTracker(currentChainId: string, fromAddress: string, transactionStatuses: TransactionStatus[], transactions: TransactionMeta[]): NonceTrackerTransaction[];
|
|
26
|
-
//# sourceMappingURL=nonce.d.
|
|
26
|
+
//# sourceMappingURL=nonce.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nonce.d.cts","sourceRoot":"","sources":["../../src/utils/nonce.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,IAAI,uBAAuB,EACvC,gCAAgC;AAGjC,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,qBAAoB;AAKtE;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,eAAe,EACvB,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,SAAS,CAAC,GACpD,OAAO,CAAC,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC,CA+BzD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uCAAuC,CACrD,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,EACnB,mBAAmB,EAAE,iBAAiB,EAAE,EACxC,YAAY,EAAE,eAAe,EAAE,GAC9B,uBAAuB,EAAE,CAwD3B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { NonceLock, Transaction as NonceTrackerTransaction } from "@metamask/nonce-tracker";
|
|
2
|
+
import type { TransactionMeta, TransactionStatus } from "../types.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Determine the next nonce to be used for a transaction.
|
|
5
|
+
*
|
|
6
|
+
* @param txMeta - The transaction metadata.
|
|
7
|
+
* @param getNonceLock - An anonymous function that acquires the nonce lock for an address
|
|
8
|
+
* @returns The next hexadecimal nonce to be used for the given transaction, and optionally a function to release the nonce lock.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getNextNonce(txMeta: TransactionMeta, getNonceLock: (address: string) => Promise<NonceLock>): Promise<[string | undefined, (() => void) | undefined]>;
|
|
11
|
+
/**
|
|
12
|
+
* Filter and format transactions for the nonce tracker.
|
|
13
|
+
*
|
|
14
|
+
* Includes the outer transaction nonce when `txParams.from` matches, and EIP-7702
|
|
15
|
+
* authorization nonces only when their recovered authority matches `fromAddress`.
|
|
16
|
+
* This keeps foreign authorizations (e.g. Money Account upgrades on a same-chain
|
|
17
|
+
* pay batch) out of the payer's nonce history.
|
|
18
|
+
*
|
|
19
|
+
* @param currentChainId - Chain ID of the current network.
|
|
20
|
+
* @param fromAddress - Address of the account from which the transactions to filter from are sent.
|
|
21
|
+
* @param transactionStatuses - Status of the transactions for which to filter.
|
|
22
|
+
* @param transactions - Array of transactionMeta objects that have been prefiltered.
|
|
23
|
+
* @returns Array of transactions formatted for the nonce tracker.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getAndFormatTransactionsForNonceTracker(currentChainId: string, fromAddress: string, transactionStatuses: TransactionStatus[], transactions: TransactionMeta[]): NonceTrackerTransaction[];
|
|
26
|
+
//# sourceMappingURL=nonce.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nonce.d.mts","sourceRoot":"","sources":["../../src/utils/nonce.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,IAAI,uBAAuB,EACvC,gCAAgC;AAGjC,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,qBAAoB;AAKtE;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,eAAe,EACvB,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,SAAS,CAAC,GACpD,OAAO,CAAC,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC,CA+BzD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uCAAuC,CACrD,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,EACnB,mBAAmB,EAAE,iBAAiB,EAAE,EACxC,YAAY,EAAE,eAAe,EAAE,GAC9B,uBAAuB,EAAE,CAwD3B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { toHex } from
|
|
2
|
-
import { createModuleLogger, projectLogger } from
|
|
3
|
-
import { getAuthorizationAuthority } from
|
|
1
|
+
import { toHex } from "@metamask/controller-utils";
|
|
2
|
+
import { createModuleLogger, projectLogger } from "../logger.mjs";
|
|
3
|
+
import { getAuthorizationAuthority } from "./eip7702.mjs";
|
|
4
4
|
const log = createModuleLogger(projectLogger, 'nonce');
|
|
5
5
|
/**
|
|
6
6
|
* Determine the next nonce to be used for a transaction.
|
|
@@ -85,4 +85,4 @@ export function getAndFormatTransactionsForNonceTracker(currentChainId, fromAddr
|
|
|
85
85
|
return formatted;
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
//# sourceMappingURL=nonce.
|
|
88
|
+
//# sourceMappingURL=nonce.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nonce.mjs","sourceRoot":"","sources":["../../src/utils/nonce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAMnD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,sBAAqB;AAEjE,OAAO,EAAE,yBAAyB,EAAE,sBAAqB;AAEzD,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAuB,EACvB,YAAqD;IAErD,MAAM,EACJ,gBAAgB,EA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AAa,CAAC,KAAK,EAAE,SAAS,CAAC,CAC1D,CAAC;QACJ,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type {\n NonceLock,\n Transaction as NonceTrackerTransaction,\n} from '@metamask/nonce-tracker';\n\nimport { createModuleLogger, projectLogger } from '../logger.js';\nimport type { TransactionMeta, TransactionStatus } from '../types.js';\nimport { getAuthorizationAuthority } from './eip7702.js';\n\nconst log = createModuleLogger(projectLogger, 'nonce');\n\n/**\n * Determine the next nonce to be used for a transaction.\n *\n * @param txMeta - The transaction metadata.\n * @param getNonceLock - An anonymous function that acquires the nonce lock for an address\n * @returns The next hexadecimal nonce to be used for the given transaction, and optionally a function to release the nonce lock.\n */\nexport async function getNextNonce(\n txMeta: TransactionMeta,\n getNonceLock: (address: string) => Promise<NonceLock>,\n): Promise<[string | undefined, (() => void) | undefined]> {\n const {\n customNonceValue,\n isExternalSign,\n txParams: { from, nonce: existingNonce },\n } = txMeta;\n\n if (isExternalSign) {\n log('Skipping nonce as signed externally');\n return [undefined, undefined];\n }\n\n const customNonce = customNonceValue ? toHex(customNonceValue) : undefined;\n\n if (customNonce) {\n log('Using custom nonce', customNonce);\n return [customNonce, undefined];\n }\n\n if (existingNonce) {\n log('Using existing nonce', existingNonce);\n return [existingNonce, undefined];\n }\n\n const nonceLock = await getNonceLock(from);\n const nonce = toHex(nonceLock.nextNonce);\n const releaseLock = nonceLock.releaseLock.bind(nonceLock);\n\n log('Using nonce from nonce tracker', nonce, nonceLock.nonceDetails);\n\n return [nonce, releaseLock];\n}\n\n/**\n * Filter and format transactions for the nonce tracker.\n *\n * Includes the outer transaction nonce when `txParams.from` matches, and EIP-7702\n * authorization nonces only when their recovered authority matches `fromAddress`.\n * This keeps foreign authorizations (e.g. Money Account upgrades on a same-chain\n * pay batch) out of the payer's nonce history.\n *\n * @param currentChainId - Chain ID of the current network.\n * @param fromAddress - Address of the account from which the transactions to filter from are sent.\n * @param transactionStatuses - Status of the transactions for which to filter.\n * @param transactions - Array of transactionMeta objects that have been prefiltered.\n * @returns Array of transactions formatted for the nonce tracker.\n */\nexport function getAndFormatTransactionsForNonceTracker(\n currentChainId: string,\n fromAddress: string,\n transactionStatuses: TransactionStatus[],\n transactions: TransactionMeta[],\n): NonceTrackerTransaction[] {\n const normalizedFromAddress = fromAddress.toLowerCase();\n\n return transactions\n .filter(\n ({ chainId, isTransfer, isUserOperation, status, txParams: { nonce } }) =>\n !isTransfer &&\n !isUserOperation &&\n chainId === currentChainId &&\n transactionStatuses.includes(status) &&\n Boolean(nonce),\n )\n .flatMap(({ status, txParams }) => {\n const { authorizationList, from, gas, value, nonce } = txParams;\n // the only value we care about is the nonce\n // but we need to return the other values to satisfy the type\n // TODO: refactor nonceTracker to not require this\n /* istanbul ignore next */\n const toNonceTrackerTransaction = (\n currentNonce: string,\n authority: string,\n ): NonceTrackerTransaction => ({\n status,\n history: [{}],\n txParams: {\n from: authority,\n gas: gas ?? '',\n value: value ?? '',\n nonce: currentNonce,\n },\n });\n\n const formatted: NonceTrackerTransaction[] = [];\n\n if (from.toLowerCase() === normalizedFromAddress && nonce) {\n formatted.push(toNonceTrackerTransaction(nonce, from));\n }\n\n for (const authorization of authorizationList ?? []) {\n if (authorization.nonce === undefined) {\n continue;\n }\n\n const authority = getAuthorizationAuthority(authorization, from);\n\n if (authority?.toLowerCase() !== normalizedFromAddress) {\n continue;\n }\n\n formatted.push(\n toNonceTrackerTransaction(authorization.nonce, authority),\n );\n }\n\n return formatted;\n });\n}\n"]}
|