@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,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasTransactionType = exports.decodeTransactionData = exports.determineTransactionType = exports.ESTIMATE_GAS_ERROR = void 0;
|
|
4
|
+
const abi_1 = require("@ethersproject/abi");
|
|
5
|
+
const metamask_eth_abis_1 = require("@metamask/metamask-eth-abis");
|
|
6
|
+
const types_js_1 = require("../types.cjs");
|
|
7
|
+
const eip7702_js_1 = require("./eip7702.cjs");
|
|
8
|
+
const provider_js_1 = require("./provider.cjs");
|
|
9
|
+
exports.ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';
|
|
10
|
+
const ERC20Interface = new abi_1.Interface(metamask_eth_abis_1.abiERC20);
|
|
11
|
+
const ERC721Interface = new abi_1.Interface(metamask_eth_abis_1.abiERC721);
|
|
12
|
+
const ERC1155Interface = new abi_1.Interface(metamask_eth_abis_1.abiERC1155);
|
|
13
|
+
const USDCInterface = new abi_1.Interface(metamask_eth_abis_1.abiFiatTokenV2);
|
|
14
|
+
/**
|
|
15
|
+
* Determines the type of the transaction by analyzing the txParams.
|
|
16
|
+
* It will never return TRANSACTION_TYPE_CANCEL or TRANSACTION_TYPE_RETRY as these
|
|
17
|
+
* represent specific events that we specify manually at transaction creation.
|
|
18
|
+
*
|
|
19
|
+
* @param txParams - Parameters for the transaction.
|
|
20
|
+
* @param options - Optional messenger and network client ID to query the network.
|
|
21
|
+
* @param options.messenger - The TransactionController messenger.
|
|
22
|
+
* @param options.networkClientId - The network client ID to use.
|
|
23
|
+
* @returns A object with the transaction type and the contract code response in Hex.
|
|
24
|
+
*/
|
|
25
|
+
async function determineTransactionType(txParams, options) {
|
|
26
|
+
const { data, to } = txParams;
|
|
27
|
+
const hasRealBytecode = Boolean(data && data !== '0x' && data.length > 2);
|
|
28
|
+
if (hasRealBytecode && !to) {
|
|
29
|
+
return { type: types_js_1.TransactionType.deployContract, getCodeResponse: undefined };
|
|
30
|
+
}
|
|
31
|
+
let getCodeResponse;
|
|
32
|
+
let isContractAddress = Boolean(data?.length);
|
|
33
|
+
if (options) {
|
|
34
|
+
const { messenger, networkClientId } = options;
|
|
35
|
+
const response = await readAddressAsContract(messenger, networkClientId, to);
|
|
36
|
+
getCodeResponse = response.contractCode;
|
|
37
|
+
isContractAddress = response.isContractAddress;
|
|
38
|
+
}
|
|
39
|
+
if (!isContractAddress) {
|
|
40
|
+
return { type: types_js_1.TransactionType.simpleSend, getCodeResponse };
|
|
41
|
+
}
|
|
42
|
+
const hasValue = Number(txParams.value ?? '0') !== 0;
|
|
43
|
+
const contractInteractionResult = {
|
|
44
|
+
type: types_js_1.TransactionType.contractInteraction,
|
|
45
|
+
getCodeResponse,
|
|
46
|
+
};
|
|
47
|
+
if (!data || hasValue) {
|
|
48
|
+
return contractInteractionResult;
|
|
49
|
+
}
|
|
50
|
+
const name = getMethodName(data);
|
|
51
|
+
if (!name) {
|
|
52
|
+
return contractInteractionResult;
|
|
53
|
+
}
|
|
54
|
+
const tokenMethodName = [
|
|
55
|
+
types_js_1.TransactionType.tokenMethodApprove,
|
|
56
|
+
types_js_1.TransactionType.tokenMethodSetApprovalForAll,
|
|
57
|
+
types_js_1.TransactionType.tokenMethodTransfer,
|
|
58
|
+
types_js_1.TransactionType.tokenMethodTransferFrom,
|
|
59
|
+
types_js_1.TransactionType.tokenMethodSafeTransferFrom,
|
|
60
|
+
types_js_1.TransactionType.tokenMethodIncreaseAllowance,
|
|
61
|
+
].find((methodName) => methodName.toLowerCase() === name.toLowerCase());
|
|
62
|
+
if (tokenMethodName) {
|
|
63
|
+
return { type: tokenMethodName, getCodeResponse };
|
|
64
|
+
}
|
|
65
|
+
return contractInteractionResult;
|
|
66
|
+
}
|
|
67
|
+
exports.determineTransactionType = determineTransactionType;
|
|
68
|
+
/**
|
|
69
|
+
* Parses transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155 and USDC.
|
|
70
|
+
* The data will decode correctly if the transaction is an interaction with a contract that matches one of these
|
|
71
|
+
* contract standards
|
|
72
|
+
*
|
|
73
|
+
* @param data - Encoded transaction data.
|
|
74
|
+
* @param options - Options bag.
|
|
75
|
+
* @param options.getMethodName - Whether to get the method name.
|
|
76
|
+
* @returns A representation of an ethereum contract call.
|
|
77
|
+
*/
|
|
78
|
+
function decodeTransactionData(data, options) {
|
|
79
|
+
if (!data || data.length < 10) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
const fourByte = data.substring(0, 10).toLowerCase();
|
|
83
|
+
for (const iface of [
|
|
84
|
+
ERC20Interface,
|
|
85
|
+
ERC721Interface,
|
|
86
|
+
ERC1155Interface,
|
|
87
|
+
USDCInterface,
|
|
88
|
+
]) {
|
|
89
|
+
try {
|
|
90
|
+
if (options?.getMethodName) {
|
|
91
|
+
return iface.getFunction(fourByte)?.name;
|
|
92
|
+
}
|
|
93
|
+
return iface.parseTransaction({ data });
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// Intentionally empty
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
exports.decodeTransactionData = decodeTransactionData;
|
|
102
|
+
/**
|
|
103
|
+
* Attempts to get the method name from the given transaction data.
|
|
104
|
+
*
|
|
105
|
+
* @param data - Encoded transaction data.
|
|
106
|
+
* @returns The method name.
|
|
107
|
+
*/
|
|
108
|
+
function getMethodName(data) {
|
|
109
|
+
return decodeTransactionData(data, {
|
|
110
|
+
getMethodName: true,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Reads an Ethereum address and determines if it is a contract address.
|
|
115
|
+
*
|
|
116
|
+
* @param messenger - The TransactionController messenger.
|
|
117
|
+
* @param networkClientId - The network client ID to use.
|
|
118
|
+
* @param address - The Ethereum address.
|
|
119
|
+
* @returns An object containing the contract code and a boolean indicating if it is a contract address.
|
|
120
|
+
*/
|
|
121
|
+
async function readAddressAsContract(messenger, networkClientId, address) {
|
|
122
|
+
let contractCode;
|
|
123
|
+
try {
|
|
124
|
+
contractCode = (await (0, provider_js_1.rpcRequest)({
|
|
125
|
+
messenger,
|
|
126
|
+
networkClientId,
|
|
127
|
+
method: 'eth_getCode',
|
|
128
|
+
params: [address, 'latest'],
|
|
129
|
+
}));
|
|
130
|
+
// Not used
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
contractCode = null;
|
|
135
|
+
}
|
|
136
|
+
const isContractAddress = contractCode
|
|
137
|
+
? contractCode !== '0x' &&
|
|
138
|
+
contractCode !== '0x0' &&
|
|
139
|
+
!contractCode.startsWith(eip7702_js_1.DELEGATION_PREFIX)
|
|
140
|
+
: false;
|
|
141
|
+
return { contractCode, isContractAddress };
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Check whether a transaction (or any of its nested transactions) has one of
|
|
145
|
+
* the given types.
|
|
146
|
+
*
|
|
147
|
+
* @param transactionMeta - Transaction metadata.
|
|
148
|
+
* @param types - Transaction types to match against.
|
|
149
|
+
* @returns `true` when the transaction or a nested transaction has one of the given types.
|
|
150
|
+
*/
|
|
151
|
+
function hasTransactionType(transactionMeta, types) {
|
|
152
|
+
const { nestedTransactions, type } = transactionMeta ?? {};
|
|
153
|
+
if (types.includes(type)) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
return (nestedTransactions?.some((tx) => types.includes(tx.type)) ?? false);
|
|
157
|
+
}
|
|
158
|
+
exports.hasTransactionType = hasTransactionType;
|
|
159
|
+
//# sourceMappingURL=transaction-type.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-type.cjs","sourceRoot":"","sources":["../../src/utils/transaction-type.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAE/C,mEAKqC;AASrC,2CAA8C;AAC9C,8CAAiD;AACjD,gDAA2C;AAE9B,QAAA,kBAAkB,GAAG,kCAAkC,CAAC;AAErE,MAAM,cAAc,GAAG,IAAI,eAAS,CAAC,4BAAQ,CAAC,CAAC;AAC/C,MAAM,eAAe,GAAG,IAAI,eAAS,CAAC,6BAAS,CAAC,CAAC;AACjD,MAAM,gBAAgB,GAAG,IAAI,eAAS,CAAC,8BAAU,CAAC,CAAC;AACnD,MAAM,aAAa,GAAG,IAAI,eAAS,CAAC,kCAAc,CAAC,CAAC;AAEpD;;;;;;;;;;GAUG;AACI,KAAK,UAAU,wBAAwB,CAC5C,QAA2B,EAC3B,OAGC;IAED,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,QAAQ,CAAC;IAE9B,MAAM,eAAe,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1E,IAAI,eAAe,IAAI,CAAC,EAAE,EAAE,CAAC;QAC3B,OAAO,EAAE,IAAI,EAAE,0BAAe,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AE,aAAa;YACrB,MAAM,EAAE,CAAC,OAAiB,EAAE,QAAQ,CAAC;SACtC,CAAC,CAAW,CAAC;QACd,WAAW;QACX,6DAA6D;IAC/D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,YAAY,GAAG,IAAI,CAAC;IACtB,CAAC;IAED,MAAM,iBAAiB,GAAG,YAAY;QACpC,CAAC,CAAC,YAAY,KAAK,IAAI;YACrB,YAAY,KAAK,KAAK;YACtB,CAAC,YAAY,CAAC,UAAU,CAAC,8BAAiB,CAAC;QAC7C,CAAC,CAAC,KAAK,CAAC;IACV,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAC7C,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAChC,eAA4C,EAC5C,KAAiC;IAEjC,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,GAAG,eAAe,IAAI,EAAE,CAAC;IAE3D,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAuB,CAAC,EAAE,CAAC;QAC5C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CACL,kBAAkB,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAC9B,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAuB,CAAC,CAC3C,IAAI,KAAK,CACX,CAAC;AACJ,CAAC;AAfD,gDAeC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport type { TransactionDescription } from '@ethersproject/abi';\nimport {\n abiERC721,\n abiERC20,\n abiERC1155,\n abiFiatTokenV2,\n} from '@metamask/metamask-eth-abis';\nimport type { NetworkClientId } from '@metamask/network-controller';\n\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n InferTransactionTypeResult,\n TransactionMeta,\n TransactionParams,\n} from '../types.js';\nimport { TransactionType } from '../types.js';\nimport { DELEGATION_PREFIX } from './eip7702.js';\nimport { rpcRequest } from './provider.js';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\nconst ERC20Interface = new Interface(abiERC20);\nconst ERC721Interface = new Interface(abiERC721);\nconst ERC1155Interface = new Interface(abiERC1155);\nconst USDCInterface = new Interface(abiFiatTokenV2);\n\n/**\n * Determines the type of the transaction by analyzing the txParams.\n * It will never return TRANSACTION_TYPE_CANCEL or TRANSACTION_TYPE_RETRY as these\n * represent specific events that we specify manually at transaction creation.\n *\n * @param txParams - Parameters for the transaction.\n * @param options - Optional messenger and network client ID to query the network.\n * @param options.messenger - The TransactionController messenger.\n * @param options.networkClientId - The network client ID to use.\n * @returns A object with the transaction type and the contract code response in Hex.\n */\nexport async function determineTransactionType(\n txParams: TransactionParams,\n options?: {\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n },\n): Promise<InferTransactionTypeResult> {\n const { data, to } = txParams;\n\n const hasRealBytecode = Boolean(data && data !== '0x' && data.length > 2);\n\n if (hasRealBytecode && !to) {\n return { type: TransactionType.deployContract, getCodeResponse: undefined };\n }\n\n let getCodeResponse;\n let isContractAddress = Boolean(data?.length);\n\n if (options) {\n const { messenger, networkClientId } = options;\n const response = await readAddressAsContract(\n messenger,\n networkClientId,\n to,\n );\n\n getCodeResponse = response.contractCode;\n isContractAddress = response.isContractAddress;\n }\n\n if (!isContractAddress) {\n return { type: TransactionType.simpleSend, getCodeResponse };\n }\n\n const hasValue = Number(txParams.value ?? '0') !== 0;\n\n const contractInteractionResult = {\n type: TransactionType.contractInteraction,\n getCodeResponse,\n };\n\n if (!data || hasValue) {\n return contractInteractionResult;\n }\n\n const name = getMethodName(data);\n\n if (!name) {\n return contractInteractionResult;\n }\n\n const tokenMethodName = [\n TransactionType.tokenMethodApprove,\n TransactionType.tokenMethodSetApprovalForAll,\n TransactionType.tokenMethodTransfer,\n TransactionType.tokenMethodTransferFrom,\n TransactionType.tokenMethodSafeTransferFrom,\n TransactionType.tokenMethodIncreaseAllowance,\n ].find((methodName) => methodName.toLowerCase() === name.toLowerCase());\n\n if (tokenMethodName) {\n return { type: tokenMethodName, getCodeResponse };\n }\n\n return contractInteractionResult;\n}\n\n/**\n * Parses transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155 and USDC.\n * The data will decode correctly if the transaction is an interaction with a contract that matches one of these\n * contract standards\n *\n * @param data - Encoded transaction data.\n * @param options - Options bag.\n * @param options.getMethodName - Whether to get the method name.\n * @returns A representation of an ethereum contract call.\n */\nexport function decodeTransactionData(\n data: string,\n options?: {\n getMethodName?: boolean;\n },\n): undefined | TransactionDescription | string {\n if (!data || data.length < 10) {\n return undefined;\n }\n\n const fourByte = data.substring(0, 10).toLowerCase();\n\n for (const iface of [\n ERC20Interface,\n ERC721Interface,\n ERC1155Interface,\n USDCInterface,\n ]) {\n try {\n if (options?.getMethodName) {\n return iface.getFunction(fourByte)?.name;\n }\n return iface.parseTransaction({ data });\n } catch {\n // Intentionally empty\n }\n }\n\n return undefined;\n}\n\n/**\n * Attempts to get the method name from the given transaction data.\n *\n * @param data - Encoded transaction data.\n * @returns The method name.\n */\nfunction getMethodName(data?: string): string | undefined {\n return decodeTransactionData(data as string, {\n getMethodName: true,\n }) as string | undefined;\n}\n\n/**\n * Reads an Ethereum address and determines if it is a contract address.\n *\n * @param messenger - The TransactionController messenger.\n * @param networkClientId - The network client ID to use.\n * @param address - The Ethereum address.\n * @returns An object containing the contract code and a boolean indicating if it is a contract address.\n */\nasync function readAddressAsContract(\n messenger: TransactionControllerMessenger,\n networkClientId: NetworkClientId,\n address?: string,\n): Promise<{\n contractCode: string | null;\n isContractAddress: boolean;\n}> {\n let contractCode;\n try {\n contractCode = (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_getCode',\n params: [address as string, 'latest'],\n })) as string;\n // Not used\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (error) {\n contractCode = null;\n }\n\n const isContractAddress = contractCode\n ? contractCode !== '0x' &&\n contractCode !== '0x0' &&\n !contractCode.startsWith(DELEGATION_PREFIX)\n : false;\n return { contractCode, isContractAddress };\n}\n\n/**\n * Check whether a transaction (or any of its nested transactions) has one of\n * the given types.\n *\n * @param transactionMeta - Transaction metadata.\n * @param types - Transaction types to match against.\n * @returns `true` when the transaction or a nested transaction has one of the given types.\n */\nexport function hasTransactionType(\n transactionMeta: TransactionMeta | undefined,\n types: readonly TransactionType[],\n): boolean {\n const { nestedTransactions, type } = transactionMeta ?? {};\n\n if (types.includes(type as TransactionType)) {\n return true;\n }\n\n return (\n nestedTransactions?.some((tx) =>\n types.includes(tx.type as TransactionType),\n ) ?? false\n );\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { TransactionDescription } from
|
|
2
|
-
import type { NetworkClientId } from
|
|
3
|
-
import type { TransactionControllerMessenger } from
|
|
4
|
-
import type { InferTransactionTypeResult, TransactionMeta, TransactionParams } from
|
|
5
|
-
import { TransactionType } from
|
|
1
|
+
import type { TransactionDescription } from "@ethersproject/abi";
|
|
2
|
+
import type { NetworkClientId } from "@metamask/network-controller";
|
|
3
|
+
import type { TransactionControllerMessenger } from "../TransactionController.cjs";
|
|
4
|
+
import type { InferTransactionTypeResult, TransactionMeta, TransactionParams } from "../types.cjs";
|
|
5
|
+
import { TransactionType } from "../types.cjs";
|
|
6
6
|
export declare const ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
|
|
7
7
|
/**
|
|
8
8
|
* Determines the type of the transaction by analyzing the txParams.
|
|
@@ -41,4 +41,4 @@ export declare function decodeTransactionData(data: string, options?: {
|
|
|
41
41
|
* @returns `true` when the transaction or a nested transaction has one of the given types.
|
|
42
42
|
*/
|
|
43
43
|
export declare function hasTransactionType(transactionMeta: TransactionMeta | undefined, types: readonly TransactionType[]): boolean;
|
|
44
|
-
//# sourceMappingURL=transaction-type.d.
|
|
44
|
+
//# sourceMappingURL=transaction-type.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-type.d.cts","sourceRoot":"","sources":["../../src/utils/transaction-type.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AAOjE,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AAEpE,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EACV,0BAA0B,EAC1B,eAAe,EACf,iBAAiB,EAClB,qBAAoB;AACrB,OAAO,EAAE,eAAe,EAAE,qBAAoB;AAI9C,eAAO,MAAM,kBAAkB,qCAAqC,CAAC;AAOrE;;;;;;;;;;GAUG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,CAAC,EAAE;IACR,SAAS,EAAE,8BAA8B,CAAC;IAC1C,eAAe,EAAE,eAAe,CAAC;CAClC,GACA,OAAO,CAAC,0BAA0B,CAAC,CA2DrC;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IACR,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,GACA,SAAS,GAAG,sBAAsB,GAAG,MAAM,CAwB7C;AAoDD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,eAAe,EAAE,eAAe,GAAG,SAAS,EAC5C,KAAK,EAAE,SAAS,eAAe,EAAE,GAChC,OAAO,CAYT"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { TransactionDescription } from "@ethersproject/abi";
|
|
2
|
+
import type { NetworkClientId } from "@metamask/network-controller";
|
|
3
|
+
import type { TransactionControllerMessenger } from "../TransactionController.mjs";
|
|
4
|
+
import type { InferTransactionTypeResult, TransactionMeta, TransactionParams } from "../types.mjs";
|
|
5
|
+
import { TransactionType } from "../types.mjs";
|
|
6
|
+
export declare const ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
|
|
7
|
+
/**
|
|
8
|
+
* Determines the type of the transaction by analyzing the txParams.
|
|
9
|
+
* It will never return TRANSACTION_TYPE_CANCEL or TRANSACTION_TYPE_RETRY as these
|
|
10
|
+
* represent specific events that we specify manually at transaction creation.
|
|
11
|
+
*
|
|
12
|
+
* @param txParams - Parameters for the transaction.
|
|
13
|
+
* @param options - Optional messenger and network client ID to query the network.
|
|
14
|
+
* @param options.messenger - The TransactionController messenger.
|
|
15
|
+
* @param options.networkClientId - The network client ID to use.
|
|
16
|
+
* @returns A object with the transaction type and the contract code response in Hex.
|
|
17
|
+
*/
|
|
18
|
+
export declare function determineTransactionType(txParams: TransactionParams, options?: {
|
|
19
|
+
messenger: TransactionControllerMessenger;
|
|
20
|
+
networkClientId: NetworkClientId;
|
|
21
|
+
}): Promise<InferTransactionTypeResult>;
|
|
22
|
+
/**
|
|
23
|
+
* Parses transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155 and USDC.
|
|
24
|
+
* The data will decode correctly if the transaction is an interaction with a contract that matches one of these
|
|
25
|
+
* contract standards
|
|
26
|
+
*
|
|
27
|
+
* @param data - Encoded transaction data.
|
|
28
|
+
* @param options - Options bag.
|
|
29
|
+
* @param options.getMethodName - Whether to get the method name.
|
|
30
|
+
* @returns A representation of an ethereum contract call.
|
|
31
|
+
*/
|
|
32
|
+
export declare function decodeTransactionData(data: string, options?: {
|
|
33
|
+
getMethodName?: boolean;
|
|
34
|
+
}): undefined | TransactionDescription | string;
|
|
35
|
+
/**
|
|
36
|
+
* Check whether a transaction (or any of its nested transactions) has one of
|
|
37
|
+
* the given types.
|
|
38
|
+
*
|
|
39
|
+
* @param transactionMeta - Transaction metadata.
|
|
40
|
+
* @param types - Transaction types to match against.
|
|
41
|
+
* @returns `true` when the transaction or a nested transaction has one of the given types.
|
|
42
|
+
*/
|
|
43
|
+
export declare function hasTransactionType(transactionMeta: TransactionMeta | undefined, types: readonly TransactionType[]): boolean;
|
|
44
|
+
//# sourceMappingURL=transaction-type.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-type.d.mts","sourceRoot":"","sources":["../../src/utils/transaction-type.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AAOjE,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AAEpE,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAoC;AAClF,OAAO,KAAK,EACV,0BAA0B,EAC1B,eAAe,EACf,iBAAiB,EAClB,qBAAoB;AACrB,OAAO,EAAE,eAAe,EAAE,qBAAoB;AAI9C,eAAO,MAAM,kBAAkB,qCAAqC,CAAC;AAOrE;;;;;;;;;;GAUG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,CAAC,EAAE;IACR,SAAS,EAAE,8BAA8B,CAAC;IAC1C,eAAe,EAAE,eAAe,CAAC;CAClC,GACA,OAAO,CAAC,0BAA0B,CAAC,CA2DrC;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IACR,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,GACA,SAAS,GAAG,sBAAsB,GAAG,MAAM,CAwB7C;AAoDD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,eAAe,EAAE,eAAe,GAAG,SAAS,EAC5C,KAAK,EAAE,SAAS,eAAe,EAAE,GAChC,OAAO,CAYT"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Interface } from
|
|
2
|
-
import { abiERC721, abiERC20, abiERC1155, abiFiatTokenV2
|
|
3
|
-
import { TransactionType } from
|
|
4
|
-
import { DELEGATION_PREFIX } from
|
|
5
|
-
import { rpcRequest } from
|
|
1
|
+
import { Interface } from "@ethersproject/abi";
|
|
2
|
+
import { abiERC721, abiERC20, abiERC1155, abiFiatTokenV2 } from "@metamask/metamask-eth-abis";
|
|
3
|
+
import { TransactionType } from "../types.mjs";
|
|
4
|
+
import { DELEGATION_PREFIX } from "./eip7702.mjs";
|
|
5
|
+
import { rpcRequest } from "./provider.mjs";
|
|
6
6
|
export const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';
|
|
7
7
|
const ERC20Interface = new Interface(abiERC20);
|
|
8
8
|
const ERC721Interface = new Interface(abiERC721);
|
|
@@ -150,4 +150,4 @@ export function hasTransactionType(transactionMeta, types) {
|
|
|
150
150
|
}
|
|
151
151
|
return (nestedTransactions?.some((tx) => types.includes(tx.type)) ?? false);
|
|
152
152
|
}
|
|
153
|
-
//# sourceMappingURL=transaction-type.
|
|
153
|
+
//# sourceMappingURL=transaction-type.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-type.mjs","sourceRoot":"","sources":["../../src/utils/transaction-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,2BAA2B;AAE/C,OAAO,EACL,SAAS,EACT,QAAQ,EACR,UAAU,EACV,cAAc,EACf,oCAAoC;AASrC,OAAO,EAAE,eAAe,EAAE,qBAAoB;AAC9C,OAAO,EAAE,iBAAiB,EAAE,sBAAqB;AACjD,OAAO,EAAE,UAAU,EAAE,uBAAsB;AAE3C,MAAM,CAAC,MAAM,kBAAkB,GAAG,kCAAkC,CAAC;AAErE,MAAM,cAAc,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,CAAC;AAC/C,MAAM,eAAe,GAAG,IAAI,SAAS,CAAC,SAAS,CAAC,CAAC;AACjD,MAAM,gBAAgB,GAAG,IAAI,SAAS,CAAC,UAAU,CAAC,CAAC;AACnD,MAAM,aAAa,GAAG,IAAI,SAAS,CAAC,cAAc,CAAC,CAAC;AAEpD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,QAA2B,EAC3B,OAGC;IAED,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,QAAQ,CAAC;IAE9B,MAAM,eAAe,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1E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;YAC/B,SAAS;YACT,eAAe;YACf,MAAM,EAAE,aAAa;YACrB,MAAM,EAAE,CAAC,OAAiB,EAAE,QAAQ,CAAC;SACtC,CAAC,CAAW,CAAC;QACd,WAAW;QACX,6DAA6D;IAC/D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,YAAY,GAAG,IAAI,CAAC;IACtB,CAAC;IAED,MAAM,iBAAiB,GAAG,YAAY;QACpC,CAAC,CAAC,YAAY,KAAK,IAAI;YACrB,YAAY,KAAK,KAAK;YACtB,CAAC,YAAY,CAAC,UAAU,CAAC,iBAAiB,CAAC;QAC7C,CAAC,CAAC,KAAK,CAAC;IACV,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAC7C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,eAA4C,EAC5C,KAAiC;IAEjC,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,GAAG,eAAe,IAAI,EAAE,CAAC;IAE3D,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAuB,CAAC,EAAE,CAAC;QAC5C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CACL,kBAAkB,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAC9B,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAuB,CAAC,CAC3C,IAAI,KAAK,CACX,CAAC;AACJ,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport type { TransactionDescription } from '@ethersproject/abi';\nimport {\n abiERC721,\n abiERC20,\n abiERC1155,\n abiFiatTokenV2,\n} from '@metamask/metamask-eth-abis';\nimport type { NetworkClientId } from '@metamask/network-controller';\n\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n InferTransactionTypeResult,\n TransactionMeta,\n TransactionParams,\n} from '../types.js';\nimport { TransactionType } from '../types.js';\nimport { DELEGATION_PREFIX } from './eip7702.js';\nimport { rpcRequest } from './provider.js';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\nconst ERC20Interface = new Interface(abiERC20);\nconst ERC721Interface = new Interface(abiERC721);\nconst ERC1155Interface = new Interface(abiERC1155);\nconst USDCInterface = new Interface(abiFiatTokenV2);\n\n/**\n * Determines the type of the transaction by analyzing the txParams.\n * It will never return TRANSACTION_TYPE_CANCEL or TRANSACTION_TYPE_RETRY as these\n * represent specific events that we specify manually at transaction creation.\n *\n * @param txParams - Parameters for the transaction.\n * @param options - Optional messenger and network client ID to query the network.\n * @param options.messenger - The TransactionController messenger.\n * @param options.networkClientId - The network client ID to use.\n * @returns A object with the transaction type and the contract code response in Hex.\n */\nexport async function determineTransactionType(\n txParams: TransactionParams,\n options?: {\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n },\n): Promise<InferTransactionTypeResult> {\n const { data, to } = txParams;\n\n const hasRealBytecode = Boolean(data && data !== '0x' && data.length > 2);\n\n if (hasRealBytecode && !to) {\n return { type: TransactionType.deployContract, getCodeResponse: undefined };\n }\n\n let getCodeResponse;\n let isContractAddress = Boolean(data?.length);\n\n if (options) {\n const { messenger, networkClientId } = options;\n const response = await readAddressAsContract(\n messenger,\n networkClientId,\n to,\n );\n\n getCodeResponse = response.contractCode;\n isContractAddress = response.isContractAddress;\n }\n\n if (!isContractAddress) {\n return { type: TransactionType.simpleSend, getCodeResponse };\n }\n\n const hasValue = Number(txParams.value ?? '0') !== 0;\n\n const contractInteractionResult = {\n type: TransactionType.contractInteraction,\n getCodeResponse,\n };\n\n if (!data || hasValue) {\n return contractInteractionResult;\n }\n\n const name = getMethodName(data);\n\n if (!name) {\n return contractInteractionResult;\n }\n\n const tokenMethodName = [\n TransactionType.tokenMethodApprove,\n TransactionType.tokenMethodSetApprovalForAll,\n TransactionType.tokenMethodTransfer,\n TransactionType.tokenMethodTransferFrom,\n TransactionType.tokenMethodSafeTransferFrom,\n TransactionType.tokenMethodIncreaseAllowance,\n ].find((methodName) => methodName.toLowerCase() === name.toLowerCase());\n\n if (tokenMethodName) {\n return { type: tokenMethodName, getCodeResponse };\n }\n\n return contractInteractionResult;\n}\n\n/**\n * Parses transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155 and USDC.\n * The data will decode correctly if the transaction is an interaction with a contract that matches one of these\n * contract standards\n *\n * @param data - Encoded transaction data.\n * @param options - Options bag.\n * @param options.getMethodName - Whether to get the method name.\n * @returns A representation of an ethereum contract call.\n */\nexport function decodeTransactionData(\n data: string,\n options?: {\n getMethodName?: boolean;\n },\n): undefined | TransactionDescription | string {\n if (!data || data.length < 10) {\n return undefined;\n }\n\n const fourByte = data.substring(0, 10).toLowerCase();\n\n for (const iface of [\n ERC20Interface,\n ERC721Interface,\n ERC1155Interface,\n USDCInterface,\n ]) {\n try {\n if (options?.getMethodName) {\n return iface.getFunction(fourByte)?.name;\n }\n return iface.parseTransaction({ data });\n } catch {\n // Intentionally empty\n }\n }\n\n return undefined;\n}\n\n/**\n * Attempts to get the method name from the given transaction data.\n *\n * @param data - Encoded transaction data.\n * @returns The method name.\n */\nfunction getMethodName(data?: string): string | undefined {\n return decodeTransactionData(data as string, {\n getMethodName: true,\n }) as string | undefined;\n}\n\n/**\n * Reads an Ethereum address and determines if it is a contract address.\n *\n * @param messenger - The TransactionController messenger.\n * @param networkClientId - The network client ID to use.\n * @param address - The Ethereum address.\n * @returns An object containing the contract code and a boolean indicating if it is a contract address.\n */\nasync function readAddressAsContract(\n messenger: TransactionControllerMessenger,\n networkClientId: NetworkClientId,\n address?: string,\n): Promise<{\n contractCode: string | null;\n isContractAddress: boolean;\n}> {\n let contractCode;\n try {\n contractCode = (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_getCode',\n params: [address as string, 'latest'],\n })) as string;\n // Not used\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (error) {\n contractCode = null;\n }\n\n const isContractAddress = contractCode\n ? contractCode !== '0x' &&\n contractCode !== '0x0' &&\n !contractCode.startsWith(DELEGATION_PREFIX)\n : false;\n return { contractCode, isContractAddress };\n}\n\n/**\n * Check whether a transaction (or any of its nested transactions) has one of\n * the given types.\n *\n * @param transactionMeta - Transaction metadata.\n * @param types - Transaction types to match against.\n * @returns `true` when the transaction or a nested transaction has one of the given types.\n */\nexport function hasTransactionType(\n transactionMeta: TransactionMeta | undefined,\n types: readonly TransactionType[],\n): boolean {\n const { nestedTransactions, type } = transactionMeta ?? {};\n\n if (types.includes(type as TransactionType)) {\n return true;\n }\n\n return (\n nestedTransactions?.some((tx) =>\n types.includes(tx.type as TransactionType),\n ) ?? false\n );\n}\n"]}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.caip2ToHex = exports.setEnvelopeType = exports.getPercentageChange = exports.toBN = exports.bnFromHex = exports.padHexToEvenLength = exports.normalizeGasFeeValues = exports.normalizeTxError = exports.validateIfTransactionUnapprovedOrSubmitted = exports.validateIfTransactionUnapproved = exports.validateGasValues = exports.isEIP1559Transaction = exports.normalizeTransactionParams = exports.ESTIMATE_GAS_ERROR = void 0;
|
|
7
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
8
|
+
const utils_1 = require("@metamask/utils");
|
|
9
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
10
|
+
const types_js_1 = require("../types.cjs");
|
|
11
|
+
exports.ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';
|
|
12
|
+
// TODO: Replace `any` with type
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
const NORMALIZERS = {
|
|
15
|
+
accessList: (accessList) => accessList,
|
|
16
|
+
authorizationList: (authorizationList) => authorizationList,
|
|
17
|
+
data: (data) => (0, utils_1.add0x)(padHexToEvenLength(data)),
|
|
18
|
+
from: (from) => (0, utils_1.add0x)(from).toLowerCase(),
|
|
19
|
+
gas: (gas) => (0, utils_1.add0x)(gas),
|
|
20
|
+
gasLimit: (gas) => (0, utils_1.add0x)(gas),
|
|
21
|
+
gasPrice: (gasPrice) => (0, utils_1.add0x)(gasPrice),
|
|
22
|
+
nonce: (nonce) => (0, utils_1.add0x)(nonce),
|
|
23
|
+
to: (to) => (0, utils_1.add0x)(to).toLowerCase(),
|
|
24
|
+
value: (value) => (0, utils_1.add0x)(value),
|
|
25
|
+
maxFeePerGas: (maxFeePerGas) => (0, utils_1.add0x)(maxFeePerGas),
|
|
26
|
+
maxPriorityFeePerGas: (maxPriorityFeePerGas) => (0, utils_1.add0x)(maxPriorityFeePerGas),
|
|
27
|
+
estimatedBaseFee: (maxPriorityFeePerGas) => (0, utils_1.add0x)(maxPriorityFeePerGas),
|
|
28
|
+
type: (type) => (0, utils_1.add0x)(type),
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Normalizes properties on transaction params.
|
|
32
|
+
*
|
|
33
|
+
* @param txParams - The transaction params to normalize.
|
|
34
|
+
* @returns Normalized transaction params.
|
|
35
|
+
*/
|
|
36
|
+
function normalizeTransactionParams(txParams) {
|
|
37
|
+
const normalizedTxParams = { from: '' };
|
|
38
|
+
for (const key of (0, utils_1.getKnownPropertyNames)(NORMALIZERS)) {
|
|
39
|
+
if (txParams[key]) {
|
|
40
|
+
normalizedTxParams[key] = NORMALIZERS[key](txParams[key]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
normalizedTxParams.value ?? (normalizedTxParams.value = '0x0');
|
|
44
|
+
if (normalizedTxParams.gasLimit && !normalizedTxParams.gas) {
|
|
45
|
+
normalizedTxParams.gas = normalizedTxParams.gasLimit;
|
|
46
|
+
}
|
|
47
|
+
return normalizedTxParams;
|
|
48
|
+
}
|
|
49
|
+
exports.normalizeTransactionParams = normalizeTransactionParams;
|
|
50
|
+
/**
|
|
51
|
+
* Checks if a transaction is EIP-1559 by checking for the existence of
|
|
52
|
+
* maxFeePerGas and maxPriorityFeePerGas within its parameters.
|
|
53
|
+
*
|
|
54
|
+
* @param txParams - Transaction params object to add.
|
|
55
|
+
* @returns Boolean that is true if the transaction is EIP-1559 (has maxFeePerGas and maxPriorityFeePerGas), otherwise returns false.
|
|
56
|
+
*/
|
|
57
|
+
function isEIP1559Transaction(txParams) {
|
|
58
|
+
const hasOwnProp = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
59
|
+
return (hasOwnProp(txParams, 'maxFeePerGas') &&
|
|
60
|
+
hasOwnProp(txParams, 'maxPriorityFeePerGas'));
|
|
61
|
+
}
|
|
62
|
+
exports.isEIP1559Transaction = isEIP1559Transaction;
|
|
63
|
+
const validateGasValues = (gasValues) => {
|
|
64
|
+
Object.keys(gasValues).forEach((key) => {
|
|
65
|
+
// TODO: Replace `any` with type
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
+
const value = gasValues[key];
|
|
68
|
+
if (typeof value !== 'string' || !(0, utils_1.isStrictHexString)(value)) {
|
|
69
|
+
throw new TypeError(`expected hex string for ${key} but received: ${value}`);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
exports.validateGasValues = validateGasValues;
|
|
74
|
+
/**
|
|
75
|
+
* Validates that a transaction is unapproved.
|
|
76
|
+
* Throws if the transaction is not unapproved.
|
|
77
|
+
*
|
|
78
|
+
* @param transactionMeta - The transaction metadata to check.
|
|
79
|
+
* @param fnName - The name of the function calling this helper.
|
|
80
|
+
*/
|
|
81
|
+
function validateIfTransactionUnapproved(transactionMeta, fnName) {
|
|
82
|
+
if (transactionMeta?.status !== types_js_1.TransactionStatus.unapproved) {
|
|
83
|
+
throw new Error(`TransactionsController: Can only call ${fnName} on an unapproved transaction.\n Current tx status: ${transactionMeta?.status}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.validateIfTransactionUnapproved = validateIfTransactionUnapproved;
|
|
87
|
+
/**
|
|
88
|
+
* Validates that a transaction is unapproved or submitted.
|
|
89
|
+
* Throws if the transaction is not unapproved or submitted.
|
|
90
|
+
*
|
|
91
|
+
* @param transactionMeta - The transaction metadata to check.
|
|
92
|
+
* @param fnName - The name of the function calling this helper.
|
|
93
|
+
*/
|
|
94
|
+
function validateIfTransactionUnapprovedOrSubmitted(transactionMeta, fnName) {
|
|
95
|
+
const allowedStatuses = [
|
|
96
|
+
types_js_1.TransactionStatus.unapproved,
|
|
97
|
+
types_js_1.TransactionStatus.submitted,
|
|
98
|
+
];
|
|
99
|
+
if (!transactionMeta || !allowedStatuses.includes(transactionMeta.status)) {
|
|
100
|
+
throw new Error(`TransactionsController: Can only call ${fnName} on an unapproved or submitted transaction.\n Current tx status: ${transactionMeta?.status}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.validateIfTransactionUnapprovedOrSubmitted = validateIfTransactionUnapprovedOrSubmitted;
|
|
104
|
+
/**
|
|
105
|
+
* Normalizes properties on transaction params.
|
|
106
|
+
*
|
|
107
|
+
* @param error - The error to be normalize.
|
|
108
|
+
* @returns Normalized transaction error.
|
|
109
|
+
*/
|
|
110
|
+
function normalizeTxError(error) {
|
|
111
|
+
return {
|
|
112
|
+
name: error.name,
|
|
113
|
+
message: error.message,
|
|
114
|
+
stack: error.stack,
|
|
115
|
+
code: error.code,
|
|
116
|
+
rpc: isJsonCompatible(error.value) ? error.value : undefined,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
exports.normalizeTxError = normalizeTxError;
|
|
120
|
+
/**
|
|
121
|
+
* Normalize an object containing gas fee values.
|
|
122
|
+
*
|
|
123
|
+
* @param gasFeeValues - An object containing gas fee values.
|
|
124
|
+
* @returns An object containing normalized gas fee values.
|
|
125
|
+
*/
|
|
126
|
+
function normalizeGasFeeValues(gasFeeValues) {
|
|
127
|
+
// TODO: Replace `any` with type
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
129
|
+
const normalize = (value) => typeof value === 'string' ? (0, utils_1.add0x)(value) : value;
|
|
130
|
+
if ('gasPrice' in gasFeeValues) {
|
|
131
|
+
return {
|
|
132
|
+
gasPrice: normalize(gasFeeValues.gasPrice),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
maxFeePerGas: normalize(gasFeeValues.maxFeePerGas),
|
|
137
|
+
maxPriorityFeePerGas: normalize(gasFeeValues.maxPriorityFeePerGas),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
exports.normalizeGasFeeValues = normalizeGasFeeValues;
|
|
141
|
+
/**
|
|
142
|
+
* Determines whether the given value can be encoded as JSON.
|
|
143
|
+
*
|
|
144
|
+
* @param value - The value.
|
|
145
|
+
* @returns True if the value is JSON-encodable, false if not.
|
|
146
|
+
*/
|
|
147
|
+
function isJsonCompatible(value) {
|
|
148
|
+
try {
|
|
149
|
+
JSON.parse(JSON.stringify(value));
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Ensure a hex string is of even length by adding a leading 0 if necessary.
|
|
158
|
+
* Any existing `0x` prefix is preserved but is not added if missing.
|
|
159
|
+
*
|
|
160
|
+
* @param hexValue - The hex string to ensure is even.
|
|
161
|
+
* @returns The hex string with an even length.
|
|
162
|
+
*/
|
|
163
|
+
function padHexToEvenLength(hexValue) {
|
|
164
|
+
const prefix = hexValue.toLowerCase().startsWith('0x')
|
|
165
|
+
? hexValue.slice(0, 2)
|
|
166
|
+
: '';
|
|
167
|
+
const data = prefix ? hexValue.slice(2) : hexValue;
|
|
168
|
+
const evenData = data.length % 2 === 0 ? data : `0${data}`;
|
|
169
|
+
return prefix + evenData;
|
|
170
|
+
}
|
|
171
|
+
exports.padHexToEvenLength = padHexToEvenLength;
|
|
172
|
+
/**
|
|
173
|
+
* Create a BN from a hex string, accepting an optional 0x prefix.
|
|
174
|
+
*
|
|
175
|
+
* @param hexValue - Hex string with or without 0x prefix.
|
|
176
|
+
* @returns BN parsed as base-16.
|
|
177
|
+
*/
|
|
178
|
+
function bnFromHex(hexValue) {
|
|
179
|
+
const str = typeof hexValue === 'string' ? hexValue : hexValue;
|
|
180
|
+
const withoutPrefix = str.startsWith('0x') || str.startsWith('0X') ? str.slice(2) : str;
|
|
181
|
+
if (withoutPrefix.length === 0) {
|
|
182
|
+
return new bn_js_1.default(0);
|
|
183
|
+
}
|
|
184
|
+
return new bn_js_1.default(withoutPrefix, 16);
|
|
185
|
+
}
|
|
186
|
+
exports.bnFromHex = bnFromHex;
|
|
187
|
+
/**
|
|
188
|
+
* Convert various numeric-like values to a BN instance.
|
|
189
|
+
* Accepts BN, ethers BigNumber, hex string, bigint, or number.
|
|
190
|
+
*
|
|
191
|
+
* @param value - The value to convert.
|
|
192
|
+
* @returns BN representation of the input value.
|
|
193
|
+
*/
|
|
194
|
+
function toBN(value) {
|
|
195
|
+
if (value instanceof bn_js_1.default) {
|
|
196
|
+
return value;
|
|
197
|
+
}
|
|
198
|
+
if (typeof bn_js_1.default.isBN ===
|
|
199
|
+
'function' &&
|
|
200
|
+
bn_js_1.default.isBN(value)) {
|
|
201
|
+
return value;
|
|
202
|
+
}
|
|
203
|
+
if (value !== null &&
|
|
204
|
+
typeof value === 'object' &&
|
|
205
|
+
typeof value.toHexString === 'function') {
|
|
206
|
+
return bnFromHex(value.toHexString());
|
|
207
|
+
}
|
|
208
|
+
if (value !== null &&
|
|
209
|
+
typeof value === 'object' &&
|
|
210
|
+
typeof value._hex === 'string') {
|
|
211
|
+
return bnFromHex(value._hex);
|
|
212
|
+
}
|
|
213
|
+
if (typeof value === 'string') {
|
|
214
|
+
return bnFromHex(value);
|
|
215
|
+
}
|
|
216
|
+
if (typeof value === 'bigint') {
|
|
217
|
+
return new bn_js_1.default(value.toString());
|
|
218
|
+
}
|
|
219
|
+
if (typeof value === 'number') {
|
|
220
|
+
return new bn_js_1.default(value);
|
|
221
|
+
}
|
|
222
|
+
throw new Error('Unexpected value returned from oracle contract');
|
|
223
|
+
}
|
|
224
|
+
exports.toBN = toBN;
|
|
225
|
+
/**
|
|
226
|
+
* Calculate the absolute percentage change between two values.
|
|
227
|
+
*
|
|
228
|
+
* @param originalValue - The first value.
|
|
229
|
+
* @param newValue - The second value.
|
|
230
|
+
* @returns The percentage change from the first value to the second value.
|
|
231
|
+
* If the original value is zero and the new value is not, returns 100.
|
|
232
|
+
*/
|
|
233
|
+
function getPercentageChange(originalValue, newValue) {
|
|
234
|
+
const precisionFactor = new bn_js_1.default(10).pow(new bn_js_1.default(18));
|
|
235
|
+
const originalValuePrecision = originalValue.mul(precisionFactor);
|
|
236
|
+
const newValuePrecision = newValue.mul(precisionFactor);
|
|
237
|
+
const difference = newValuePrecision.sub(originalValuePrecision);
|
|
238
|
+
if (difference.isZero()) {
|
|
239
|
+
return 0;
|
|
240
|
+
}
|
|
241
|
+
if (originalValuePrecision.isZero() && !newValuePrecision.isZero()) {
|
|
242
|
+
return 100;
|
|
243
|
+
}
|
|
244
|
+
return difference.muln(100).div(originalValuePrecision).abs().toNumber();
|
|
245
|
+
}
|
|
246
|
+
exports.getPercentageChange = getPercentageChange;
|
|
247
|
+
/**
|
|
248
|
+
* Sets the envelope type for the given transaction parameters based on the
|
|
249
|
+
* current network's EIP-1559 compatibility and the transaction parameters.
|
|
250
|
+
*
|
|
251
|
+
* @param txParams - The transaction parameters to set the envelope type for.
|
|
252
|
+
* @param isEIP1559Compatible - Indicates if the current network supports EIP-1559.
|
|
253
|
+
*/
|
|
254
|
+
function setEnvelopeType(txParams, isEIP1559Compatible) {
|
|
255
|
+
if (txParams.accessList) {
|
|
256
|
+
txParams.type = types_js_1.TransactionEnvelopeType.accessList;
|
|
257
|
+
}
|
|
258
|
+
else if (txParams.authorizationList) {
|
|
259
|
+
txParams.type = types_js_1.TransactionEnvelopeType.setCode;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
txParams.type = isEIP1559Compatible
|
|
263
|
+
? types_js_1.TransactionEnvelopeType.feeMarket
|
|
264
|
+
: types_js_1.TransactionEnvelopeType.legacy;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
exports.setEnvelopeType = setEnvelopeType;
|
|
268
|
+
/**
|
|
269
|
+
* Convert CAIP-2 chain ID to hex format.
|
|
270
|
+
*
|
|
271
|
+
* @param caip2ChainId - Chain ID in CAIP-2 format (e.g., 'eip155:1')
|
|
272
|
+
* @returns Hex chain ID (e.g., '0x1') or undefined if invalid format
|
|
273
|
+
*/
|
|
274
|
+
function caip2ToHex(caip2ChainId) {
|
|
275
|
+
if (!(0, utils_1.isCaipChainId)(caip2ChainId)) {
|
|
276
|
+
return undefined;
|
|
277
|
+
}
|
|
278
|
+
try {
|
|
279
|
+
const { reference } = (0, utils_1.parseCaipChainId)(caip2ChainId);
|
|
280
|
+
return (0, controller_utils_1.toHex)(reference);
|
|
281
|
+
}
|
|
282
|
+
catch {
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
exports.caip2ToHex = caip2ToHex;
|
|
287
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":";;;;;;AACA,iEAAmD;AAEnD,2CAMyB;AACzB,kDAAuB;AASvB,2CAAyE;AAE5D,QAAA,kBAAkB,GAAG,kCAAkC,CAAC;AAErE,gCAAgC;AAChC,8DAA8D;AAC9D,MAAM,WAAW,GAAgD;IAC/D,UAAU,EAAE,CAAC,UAAuB,EAAE,EAAE,CAAC,UAAU;IACnD,iBAAiB,EAAE,CAAC,iBAAqC,EAAE,EAAE,CAC3D,iBAAiB;IACnB,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAA,aAAK,EAAC,kBAAkB,CAAC,IAAI,CAA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G,mBAAmB;YACjC,CAAC,CAAC,kCAAuB,CAAC,SAAS;YACnC,CAAC,CAAC,kCAAuB,CAAC,MAAM,CAAC;IACrC,CAAC;AACH,CAAC;AAbD,0CAaC;AAED;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,YAAoB;IAC7C,IAAI,CAAC,IAAA,qBAAa,EAAC,YAAY,CAAC,EAAE,CAAC;QACjC,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,CAAC;QACH,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,YAAY,CAAC,CAAC;QACrD,OAAO,IAAA,wBAAK,EAAC,SAAS,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAVD,gCAUC","sourcesContent":["import type { AccessList, AuthorizationList } from '@ethereumjs/common';\nimport { toHex } from '@metamask/controller-utils';\nimport type { Hex, Json } from '@metamask/utils';\nimport {\n add0x,\n getKnownPropertyNames,\n isCaipChainId,\n isStrictHexString,\n parseCaipChainId,\n} from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport type {\n FeeMarketEIP1559Values,\n GasPriceValue,\n TransactionError,\n TransactionMeta,\n TransactionParams,\n} from '../types.js';\nimport { TransactionEnvelopeType, TransactionStatus } from '../types.js';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\n// TODO: Replace `any` with type\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst NORMALIZERS: { [param in keyof TransactionParams]: any } = {\n accessList: (accessList?: AccessList) => accessList,\n authorizationList: (authorizationList?: AuthorizationList) =>\n authorizationList,\n data: (data: string) => add0x(padHexToEvenLength(data)),\n from: (from: string) => add0x(from).toLowerCase(),\n gas: (gas: string) => add0x(gas),\n gasLimit: (gas: string) => add0x(gas),\n gasPrice: (gasPrice: string) => add0x(gasPrice),\n nonce: (nonce: string) => add0x(nonce),\n to: (to: string) => add0x(to).toLowerCase(),\n value: (value: string) => add0x(value),\n maxFeePerGas: (maxFeePerGas: string) => add0x(maxFeePerGas),\n maxPriorityFeePerGas: (maxPriorityFeePerGas: string) =>\n add0x(maxPriorityFeePerGas),\n estimatedBaseFee: (maxPriorityFeePerGas: string) =>\n add0x(maxPriorityFeePerGas),\n type: (type: string) => add0x(type),\n};\n\n/**\n * Normalizes properties on transaction params.\n *\n * @param txParams - The transaction params to normalize.\n * @returns Normalized transaction params.\n */\nexport function normalizeTransactionParams(\n txParams: TransactionParams,\n): TransactionParams {\n const normalizedTxParams: TransactionParams = { from: '' };\n\n for (const key of getKnownPropertyNames(NORMALIZERS)) {\n if (txParams[key]) {\n normalizedTxParams[key] = NORMALIZERS[key](txParams[key]);\n }\n }\n\n normalizedTxParams.value ??= '0x0';\n\n if (normalizedTxParams.gasLimit && !normalizedTxParams.gas) {\n normalizedTxParams.gas = normalizedTxParams.gasLimit;\n }\n\n return normalizedTxParams;\n}\n\n/**\n * Checks if a transaction is EIP-1559 by checking for the existence of\n * maxFeePerGas and maxPriorityFeePerGas within its parameters.\n *\n * @param txParams - Transaction params object to add.\n * @returns Boolean that is true if the transaction is EIP-1559 (has maxFeePerGas and maxPriorityFeePerGas), otherwise returns false.\n */\nexport function isEIP1559Transaction(txParams: TransactionParams): boolean {\n const hasOwnProp = (obj: TransactionParams, key: string): boolean =>\n Object.prototype.hasOwnProperty.call(obj, key);\n return (\n hasOwnProp(txParams, 'maxFeePerGas') &&\n hasOwnProp(txParams, 'maxPriorityFeePerGas')\n );\n}\n\nexport const validateGasValues = (\n gasValues: GasPriceValue | FeeMarketEIP1559Values,\n): void => {\n Object.keys(gasValues).forEach((key) => {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const value = (gasValues as any)[key];\n if (typeof value !== 'string' || !isStrictHexString(value)) {\n throw new TypeError(\n `expected hex string for ${key} but received: ${value}`,\n );\n }\n });\n};\n\n/**\n * Validates that a transaction is unapproved.\n * Throws if the transaction is not unapproved.\n *\n * @param transactionMeta - The transaction metadata to check.\n * @param fnName - The name of the function calling this helper.\n */\nexport function validateIfTransactionUnapproved(\n transactionMeta: TransactionMeta | undefined,\n fnName: string,\n): void {\n if (transactionMeta?.status !== TransactionStatus.unapproved) {\n throw new Error(\n `TransactionsController: Can only call ${fnName} on an unapproved transaction.\\n Current tx status: ${transactionMeta?.status}`,\n );\n }\n}\n\n/**\n * Validates that a transaction is unapproved or submitted.\n * Throws if the transaction is not unapproved or submitted.\n *\n * @param transactionMeta - The transaction metadata to check.\n * @param fnName - The name of the function calling this helper.\n */\nexport function validateIfTransactionUnapprovedOrSubmitted(\n transactionMeta: TransactionMeta | undefined,\n fnName: string,\n): void {\n const allowedStatuses = [\n TransactionStatus.unapproved,\n TransactionStatus.submitted,\n ];\n if (!transactionMeta || !allowedStatuses.includes(transactionMeta.status)) {\n throw new Error(\n `TransactionsController: Can only call ${fnName} on an unapproved or submitted transaction.\\n Current tx status: ${transactionMeta?.status}`,\n );\n }\n}\n\n/**\n * Normalizes properties on transaction params.\n *\n * @param error - The error to be normalize.\n * @returns Normalized transaction error.\n */\nexport function normalizeTxError(\n error: Error & { code?: string; value?: unknown },\n): TransactionError {\n return {\n name: error.name,\n message: error.message,\n stack: error.stack,\n code: error.code,\n rpc: isJsonCompatible(error.value) ? error.value : undefined,\n };\n}\n\n/**\n * Normalize an object containing gas fee values.\n *\n * @param gasFeeValues - An object containing gas fee values.\n * @returns An object containing normalized gas fee values.\n */\nexport function normalizeGasFeeValues(\n gasFeeValues: GasPriceValue | FeeMarketEIP1559Values,\n): GasPriceValue | FeeMarketEIP1559Values {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const normalize = (value: any): string =>\n typeof value === 'string' ? add0x(value) : value;\n\n if ('gasPrice' in gasFeeValues) {\n return {\n gasPrice: normalize(gasFeeValues.gasPrice),\n };\n }\n\n return {\n maxFeePerGas: normalize(gasFeeValues.maxFeePerGas),\n maxPriorityFeePerGas: normalize(gasFeeValues.maxPriorityFeePerGas),\n };\n}\n\n/**\n * Determines whether the given value can be encoded as JSON.\n *\n * @param value - The value.\n * @returns True if the value is JSON-encodable, false if not.\n */\nfunction isJsonCompatible(value: unknown): value is Json {\n try {\n JSON.parse(JSON.stringify(value));\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Ensure a hex string is of even length by adding a leading 0 if necessary.\n * Any existing `0x` prefix is preserved but is not added if missing.\n *\n * @param hexValue - The hex string to ensure is even.\n * @returns The hex string with an even length.\n */\nexport function padHexToEvenLength(hexValue: string): string {\n const prefix = hexValue.toLowerCase().startsWith('0x')\n ? hexValue.slice(0, 2)\n : '';\n const data = prefix ? hexValue.slice(2) : hexValue;\n const evenData = data.length % 2 === 0 ? data : `0${data}`;\n\n return prefix + evenData;\n}\n\n/**\n * Create a BN from a hex string, accepting an optional 0x prefix.\n *\n * @param hexValue - Hex string with or without 0x prefix.\n * @returns BN parsed as base-16.\n */\nexport function bnFromHex(hexValue: string | Hex): BN {\n const str = typeof hexValue === 'string' ? hexValue : (hexValue as string);\n const withoutPrefix =\n str.startsWith('0x') || str.startsWith('0X') ? str.slice(2) : str;\n if (withoutPrefix.length === 0) {\n return new BN(0);\n }\n return new BN(withoutPrefix, 16);\n}\n\n/**\n * Convert various numeric-like values to a BN instance.\n * Accepts BN, ethers BigNumber, hex string, bigint, or number.\n *\n * @param value - The value to convert.\n * @returns BN representation of the input value.\n */\nexport function toBN(value: unknown): BN {\n if (value instanceof BN) {\n return value;\n }\n if (\n typeof (BN as unknown as { isBN?: (v: unknown) => boolean }).isBN ===\n 'function' &&\n (BN as unknown as { isBN: (v: unknown) => boolean }).isBN(value)\n ) {\n return value as BN;\n }\n if (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as { toHexString?: () => string }).toHexString === 'function'\n ) {\n return bnFromHex((value as { toHexString: () => string }).toHexString());\n }\n if (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as { _hex?: string })._hex === 'string'\n ) {\n return bnFromHex((value as { _hex: string })._hex);\n }\n if (typeof value === 'string') {\n return bnFromHex(value);\n }\n if (typeof value === 'bigint') {\n return new BN(value.toString());\n }\n if (typeof value === 'number') {\n return new BN(value);\n }\n throw new Error('Unexpected value returned from oracle contract');\n}\n\n/**\n * Calculate the absolute percentage change between two values.\n *\n * @param originalValue - The first value.\n * @param newValue - The second value.\n * @returns The percentage change from the first value to the second value.\n * If the original value is zero and the new value is not, returns 100.\n */\nexport function getPercentageChange(originalValue: BN, newValue: BN): number {\n const precisionFactor = new BN(10).pow(new BN(18));\n const originalValuePrecision = originalValue.mul(precisionFactor);\n const newValuePrecision = newValue.mul(precisionFactor);\n\n const difference = newValuePrecision.sub(originalValuePrecision);\n\n if (difference.isZero()) {\n return 0;\n }\n\n if (originalValuePrecision.isZero() && !newValuePrecision.isZero()) {\n return 100;\n }\n\n return difference.muln(100).div(originalValuePrecision).abs().toNumber();\n}\n\n/**\n * Sets the envelope type for the given transaction parameters based on the\n * current network's EIP-1559 compatibility and the transaction parameters.\n *\n * @param txParams - The transaction parameters to set the envelope type for.\n * @param isEIP1559Compatible - Indicates if the current network supports EIP-1559.\n */\nexport function setEnvelopeType(\n txParams: TransactionParams,\n isEIP1559Compatible: boolean,\n): void {\n if (txParams.accessList) {\n txParams.type = TransactionEnvelopeType.accessList;\n } else if (txParams.authorizationList) {\n txParams.type = TransactionEnvelopeType.setCode;\n } else {\n txParams.type = isEIP1559Compatible\n ? TransactionEnvelopeType.feeMarket\n : TransactionEnvelopeType.legacy;\n }\n}\n\n/**\n * Convert CAIP-2 chain ID to hex format.\n *\n * @param caip2ChainId - Chain ID in CAIP-2 format (e.g., 'eip155:1')\n * @returns Hex chain ID (e.g., '0x1') or undefined if invalid format\n */\nexport function caip2ToHex(caip2ChainId: string): Hex | undefined {\n if (!isCaipChainId(caip2ChainId)) {\n return undefined;\n }\n try {\n const { reference } = parseCaipChainId(caip2ChainId);\n return toHex(reference);\n } catch {\n return undefined;\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Hex } from
|
|
2
|
-
import BN from
|
|
3
|
-
import type { FeeMarketEIP1559Values, GasPriceValue, TransactionError, TransactionMeta, TransactionParams } from
|
|
1
|
+
import type { Hex } from "@metamask/utils";
|
|
2
|
+
import BN from "bn.js";
|
|
3
|
+
import type { FeeMarketEIP1559Values, GasPriceValue, TransactionError, TransactionMeta, TransactionParams } from "../types.cjs";
|
|
4
4
|
export declare const ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
|
|
5
5
|
/**
|
|
6
6
|
* Normalizes properties on transaction params.
|
|
@@ -98,4 +98,4 @@ export declare function setEnvelopeType(txParams: TransactionParams, isEIP1559Co
|
|
|
98
98
|
* @returns Hex chain ID (e.g., '0x1') or undefined if invalid format
|
|
99
99
|
*/
|
|
100
100
|
export declare function caip2ToHex(caip2ChainId: string): Hex | undefined;
|
|
101
|
-
//# sourceMappingURL=utils.d.
|
|
101
|
+
//# sourceMappingURL=utils.d.cts.map
|