@metamask-previews/transaction-controller 25.2.0-preview-59bf6d5d → 25.3.0-preview-07ab424

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.
Files changed (107) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/dist/TransactionController.js +14 -13
  3. package/dist/TransactionController.mjs +13 -12
  4. package/dist/{chunk-PF3UOCRW.js → chunk-2AYEGKAN.js} +7 -7
  5. package/dist/{chunk-5IHLDAOF.js → chunk-2JERLB6M.js} +3 -3
  6. package/dist/{chunk-I6RY3XOG.mjs → chunk-5L7EMVB3.mjs} +20 -16
  7. package/dist/chunk-5L7EMVB3.mjs.map +1 -0
  8. package/dist/{chunk-BYBPZUHS.mjs → chunk-A4P4B3OF.mjs} +14 -6
  9. package/dist/chunk-A4P4B3OF.mjs.map +1 -0
  10. package/dist/{chunk-DWHMMJOW.mjs → chunk-AMDQXP37.mjs} +2 -2
  11. package/dist/{chunk-VEJ3MIZG.js → chunk-HBNQEJEM.js} +11 -2
  12. package/dist/chunk-HBNQEJEM.js.map +1 -0
  13. package/dist/chunk-HMOSP33F.js +36 -0
  14. package/dist/chunk-HMOSP33F.js.map +1 -0
  15. package/dist/chunk-HQSNKCXI.mjs +36 -0
  16. package/dist/chunk-HQSNKCXI.mjs.map +1 -0
  17. package/dist/{chunk-6XMG522E.mjs → chunk-K4KOSAGM.mjs} +8 -3
  18. package/dist/chunk-K4KOSAGM.mjs.map +1 -0
  19. package/dist/{chunk-PGTV7236.mjs → chunk-K7UC23EG.mjs} +3 -3
  20. package/dist/{chunk-JRBREX22.mjs → chunk-KG4UW4K4.mjs} +17 -4
  21. package/dist/chunk-KG4UW4K4.mjs.map +1 -0
  22. package/dist/{chunk-GE57YNGX.js → chunk-KT6UAKBB.js} +8 -3
  23. package/dist/chunk-KT6UAKBB.js.map +1 -0
  24. package/dist/{chunk-TZTP4JVA.js → chunk-L4S5SEV3.js} +4 -4
  25. package/dist/{chunk-7BG5XOXJ.js → chunk-NLE3SS2S.js} +26 -22
  26. package/dist/chunk-NLE3SS2S.js.map +1 -0
  27. package/dist/{chunk-QRSTF45Q.mjs → chunk-OLIA2HD4.mjs} +3 -3
  28. package/dist/{chunk-HS277C77.js → chunk-SD6CWFDF.js} +16 -3
  29. package/dist/chunk-SD6CWFDF.js.map +1 -0
  30. package/dist/{chunk-QEX3QMSL.js → chunk-SOSF65FI.js} +3 -3
  31. package/dist/{chunk-W57BD6NX.mjs → chunk-UADPSS35.mjs} +11 -2
  32. package/dist/chunk-UADPSS35.mjs.map +1 -0
  33. package/dist/{chunk-FHG5GY6F.js → chunk-UCY5PFZI.js} +6 -6
  34. package/dist/{chunk-GC77BSQZ.js → chunk-V5X6MZHN.js} +16 -8
  35. package/dist/chunk-V5X6MZHN.js.map +1 -0
  36. package/dist/{chunk-5UL3VDFT.mjs → chunk-VAOKN3J4.mjs} +2 -2
  37. package/dist/{chunk-IK55QTGO.mjs → chunk-ZWKHTNLF.mjs} +2 -2
  38. package/dist/errors.js +15 -0
  39. package/dist/errors.js.map +1 -0
  40. package/dist/errors.mjs +15 -0
  41. package/dist/errors.mjs.map +1 -0
  42. package/dist/gas-flows/DefaultGasFeeFlow.js +5 -5
  43. package/dist/gas-flows/DefaultGasFeeFlow.mjs +4 -4
  44. package/dist/gas-flows/LineaGasFeeFlow.js +6 -6
  45. package/dist/gas-flows/LineaGasFeeFlow.mjs +5 -5
  46. package/dist/helpers/EtherscanRemoteTransactionSource.js +1 -1
  47. package/dist/helpers/EtherscanRemoteTransactionSource.mjs +1 -1
  48. package/dist/helpers/GasFeePoller.js +4 -4
  49. package/dist/helpers/GasFeePoller.mjs +3 -3
  50. package/dist/helpers/MultichainTrackingHelper.js +1 -1
  51. package/dist/helpers/MultichainTrackingHelper.mjs +1 -1
  52. package/dist/helpers/PendingTransactionTracker.js +1 -1
  53. package/dist/helpers/PendingTransactionTracker.mjs +1 -1
  54. package/dist/index.js +18 -15
  55. package/dist/index.mjs +17 -14
  56. package/dist/tsconfig.build.tsbuildinfo +1 -1
  57. package/dist/types/TransactionController.d.ts.map +1 -1
  58. package/dist/types/errors.d.ts +15 -0
  59. package/dist/types/errors.d.ts.map +1 -0
  60. package/dist/types/index.d.ts +1 -1
  61. package/dist/types/index.d.ts.map +1 -1
  62. package/dist/types/types.d.ts +12 -4
  63. package/dist/types/types.d.ts.map +1 -1
  64. package/dist/types/utils/simulation-api.d.ts.map +1 -1
  65. package/dist/types/utils/simulation.d.ts.map +1 -1
  66. package/dist/types/utils/transaction-type.d.ts.map +1 -1
  67. package/dist/types.js +4 -2
  68. package/dist/types.mjs +3 -1
  69. package/dist/utils/external-transactions.js +1 -1
  70. package/dist/utils/external-transactions.mjs +1 -1
  71. package/dist/utils/gas-fees.js +4 -4
  72. package/dist/utils/gas-fees.mjs +3 -3
  73. package/dist/utils/gas-flow.js +3 -3
  74. package/dist/utils/gas-flow.mjs +2 -2
  75. package/dist/utils/simulation-api.js +4 -2
  76. package/dist/utils/simulation-api.mjs +3 -1
  77. package/dist/utils/simulation.js +5 -4
  78. package/dist/utils/simulation.mjs +4 -3
  79. package/dist/utils/swaps.js +1 -1
  80. package/dist/utils/swaps.mjs +1 -1
  81. package/dist/utils/transaction-type.js +3 -3
  82. package/dist/utils/transaction-type.mjs +2 -2
  83. package/dist/utils/utils.js +1 -1
  84. package/dist/utils/utils.mjs +1 -1
  85. package/dist/utils/validation.js +1 -1
  86. package/dist/utils/validation.mjs +1 -1
  87. package/package.json +2 -2
  88. package/dist/chunk-6XMG522E.mjs.map +0 -1
  89. package/dist/chunk-7BG5XOXJ.js.map +0 -1
  90. package/dist/chunk-BYBPZUHS.mjs.map +0 -1
  91. package/dist/chunk-GC77BSQZ.js.map +0 -1
  92. package/dist/chunk-GE57YNGX.js.map +0 -1
  93. package/dist/chunk-HS277C77.js.map +0 -1
  94. package/dist/chunk-I6RY3XOG.mjs.map +0 -1
  95. package/dist/chunk-JRBREX22.mjs.map +0 -1
  96. package/dist/chunk-VEJ3MIZG.js.map +0 -1
  97. package/dist/chunk-W57BD6NX.mjs.map +0 -1
  98. /package/dist/{chunk-PF3UOCRW.js.map → chunk-2AYEGKAN.js.map} +0 -0
  99. /package/dist/{chunk-5IHLDAOF.js.map → chunk-2JERLB6M.js.map} +0 -0
  100. /package/dist/{chunk-DWHMMJOW.mjs.map → chunk-AMDQXP37.mjs.map} +0 -0
  101. /package/dist/{chunk-PGTV7236.mjs.map → chunk-K7UC23EG.mjs.map} +0 -0
  102. /package/dist/{chunk-TZTP4JVA.js.map → chunk-L4S5SEV3.js.map} +0 -0
  103. /package/dist/{chunk-QRSTF45Q.mjs.map → chunk-OLIA2HD4.mjs.map} +0 -0
  104. /package/dist/{chunk-QEX3QMSL.js.map → chunk-SOSF65FI.js.map} +0 -0
  105. /package/dist/{chunk-FHG5GY6F.js.map → chunk-UCY5PFZI.js.map} +0 -0
  106. /package/dist/{chunk-5UL3VDFT.mjs.map → chunk-VAOKN3J4.mjs.map} +0 -0
  107. /package/dist/{chunk-IK55QTGO.mjs.map → chunk-ZWKHTNLF.mjs.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"names":["TransactionStatus","WalletDevice","TransactionType","TransactionEnvelopeType","UserFeeLevel","GasFeeEstimateLevel","SimulationTokenStandard","SimulationErrorCode"],"mappings":";AAgbO,IAAK,oBAAL,kBAAKA,uBAAL;AACL,EAAAA,mBAAA,cAAW;AAEX,EAAAA,mBAAA,eAAY;AACZ,EAAAA,mBAAA,eAAY;AACZ,EAAAA,mBAAA,aAAU;AACV,EAAAA,mBAAA,YAAS;AACT,EAAAA,mBAAA,cAAW;AACX,EAAAA,mBAAA,YAAS;AACT,EAAAA,mBAAA,eAAY;AACZ,EAAAA,mBAAA,gBAAa;AAVH,SAAAA;AAAA,GAAA;AAgBL,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,eAAY;AACZ,EAAAA,cAAA,kBAAe;AACf,EAAAA,cAAA,WAAQ;AAHE,SAAAA;AAAA,GAAA;AASL,IAAK,kBAAL,kBAAKC,qBAAL;AAIL,EAAAA,iBAAA,YAAS;AAOT,EAAAA,iBAAA,yBAAsB;AAKtB,EAAAA,iBAAA,oBAAiB;AAKjB,EAAAA,iBAAA,gBAAa;AAKb,EAAAA,iBAAA,+BAA4B;AAK5B,EAAAA,iBAAA,cAAW;AAKX,EAAAA,iBAAA,kBAAe;AAQf,EAAAA,iBAAA,WAAQ;AAKR,EAAAA,iBAAA,gBAAa;AAKb,EAAAA,iBAAA,UAAO;AAKP,EAAAA,iBAAA,mBAAgB;AAKhB,EAAAA,iBAAA,WAAQ;AAKR,EAAAA,iBAAA,UAAO;AAQP,EAAAA,iBAAA,kBAAe;AAMf,EAAAA,iBAAA,wBAAqB;AAQrB,EAAAA,iBAAA,iCAA8B;AAM9B,EAAAA,iBAAA,yBAAsB;AAOtB,EAAAA,iBAAA,6BAA0B;AAM1B,EAAAA,iBAAA,kCAA+B;AAK/B,EAAAA,iBAAA,kCAA+B;AAnHrB,SAAAA;AAAA,GAAA;AAqZL,IAAK,0BAAL,kBAAKC,6BAAL;AAIL,EAAAA,yBAAA,YAAS;AAOT,EAAAA,yBAAA,gBAAa;AAUb,EAAAA,yBAAA,eAAY;AArBF,SAAAA;AAAA,GAAA;AA2BL,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,YAAS;AACT,EAAAA,cAAA,oBAAiB;AACjB,EAAAA,cAAA,YAAS;AAHC,SAAAA;AAAA,GAAA;AA2FL,IAAK,sBAAL,kBAAKC,yBAAL;AACL,EAAAA,qBAAA,SAAM;AACN,EAAAA,qBAAA,YAAS;AACT,EAAAA,qBAAA,UAAO;AAHG,SAAAA;AAAA,GAAA;AAyGL,IAAK,0BAAL,kBAAKC,6BAAL;AACL,EAAAA,yBAAA,WAAQ;AACR,EAAAA,yBAAA,YAAS;AACT,EAAAA,yBAAA,aAAU;AAHA,SAAAA;AAAA,GAAA;AAsBL,IAAK,sBAAL,kBAAKC,yBAAL;AACL,EAAAA,qBAAA,uBAAoB;AACpB,EAAAA,qBAAA,cAAW;AACX,EAAAA,qBAAA,qBAAkB;AAClB,EAAAA,qBAAA,cAAW;AAJD,SAAAA;AAAA,GAAA","sourcesContent":["import type { AccessList } from '@ethereumjs/tx';\nimport type EthQuery from '@metamask/eth-query';\nimport type {\n FetchGasFeeEstimateOptions,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport type { Hex, Json } from '@metamask/utils';\nimport type { Operation } from 'fast-json-patch';\n\n/**\n * Given a record, ensures that each property matches the `Json` type.\n */\ntype MakeJsonCompatible<T> = T extends Json\n ? T\n : {\n [K in keyof T]: T[K] extends Json ? T[K] : never;\n };\n\n/**\n * `Json` from `@metamask/utils` is defined as a recursive type alias, but\n * `Operation` is defined as an interface, and the two are not compatible with\n * each other. Therefore, this is a variant of Operation from `fast-json-patch`\n * which is guaranteed to be type-compatible with `Json`.\n */\ntype JsonCompatibleOperation = MakeJsonCompatible<Operation>;\n\n/**\n * Representation of transaction metadata.\n */\nexport type TransactionMeta = TransactionMetaBase &\n (\n | {\n status: Exclude<TransactionStatus, TransactionStatus.failed>;\n }\n | {\n status: TransactionStatus.failed;\n error: TransactionError;\n }\n );\n\n/**\n * Information about a single transaction such as status and block number.\n */\ntype TransactionMetaBase = {\n /**\n * ID of the transaction that approved the swap token transfer.\n */\n approvalTxId?: string;\n\n /**\n * Unique ID to prevent duplicate requests.\n */\n actionId?: string;\n\n /**\n * Base fee of the block as a hex value, introduced in EIP-1559.\n */\n baseFeePerGas?: Hex;\n\n /**\n * Number of the block where the transaction has been included.\n */\n blockNumber?: string;\n\n /**\n * The timestamp for when the block was collated.\n */\n blockTimestamp?: string;\n\n /**\n * Network code as per EIP-155 for this transaction.\n */\n chainId: Hex;\n\n /**\n * A string representing a name of transaction contract method.\n */\n contractMethodName?: string;\n\n /**\n * The balance of the token that is being sent.\n */\n currentTokenBalance?: string;\n\n /**\n * Unique ID for custodian transaction.\n */\n custodyId?: string;\n\n /**\n * Custodian transaction status.\n */\n custodyStatus?: string;\n\n /** The optional custom nonce override as a decimal string. */\n customNonceValue?: string;\n\n /**\n * The custom token amount is the amount set by the user.\n */\n customTokenAmount?: string;\n\n /**\n * The dapp proposed token amount.\n */\n dappProposedTokenAmount?: string;\n\n /**\n * Gas values provided by the dApp.\n */\n dappSuggestedGasFees?: DappSuggestedGasFees;\n\n /**\n * The initial gas values set when the transaction was first created.\n */\n defaultGasEstimates?: DefaultGasEstimates;\n\n /**\n * String to indicate what device the transaction was confirmed on.\n */\n deviceConfirmedOn?: WalletDevice;\n\n /**\n * The address of the token being received of swap transaction.\n */\n destinationTokenAddress?: string;\n\n /**\n * The decimals of the token being received of swap transaction.\n */\n destinationTokenDecimals?: number;\n\n /**\n * The symbol of the token being received with swap.\n */\n destinationTokenSymbol?: string;\n\n /**\n * The estimated base fee of the transaction.\n */\n estimatedBaseFee?: string;\n\n /**\n * Which estimate level that the API suggested.\n */\n estimateSuggested?: string;\n\n /**\n * Which estimate level was used\n */\n estimateUsed?: string;\n\n /**\n * The chosen amount which will be the same as the originally proposed token\n * amount if the user does not edit the amount or will be a custom token\n * amount set by the user.\n */\n finalApprovalAmount?: string;\n\n /**\n * The number of the latest block when the transaction submit was first retried.\n */\n firstRetryBlockNumber?: string;\n\n /** Alternate EIP-1559 gas fee estimates for multiple priority levels. */\n gasFeeEstimates?: GasFeeEstimates;\n\n /** Whether the gas fee estimates have been checked at least once. */\n gasFeeEstimatesLoaded?: boolean;\n\n /**\n * A hex string of the transaction hash, used to identify the transaction on the network.\n */\n hash?: string;\n\n /**\n * A history of mutations to TransactionMeta.\n */\n history?: TransactionHistory;\n\n /**\n * Generated UUID associated with this transaction.\n */\n id: string;\n\n /**\n * Whether the transaction is a transfer.\n */\n isTransfer?: boolean;\n\n /**\n * Whether the transaction entry is generated from a user operation.\n */\n isUserOperation?: boolean;\n\n /**\n * Additional gas fees to cover the cost of persisting data on layer 1 for layer 2 networks.\n */\n layer1GasFee?: Hex;\n\n /**\n * The ID of the network client used by the transaction.\n */\n networkClientId?: NetworkClientId;\n\n /**\n * Network code as per EIP-155 for this transaction\n *\n * @deprecated Use `chainId` instead.\n */\n readonly networkID?: string;\n\n /**\n * Origin this transaction was sent from.\n */\n origin?: string;\n\n /**\n * The original dapp proposed token approval amount before edit by user.\n */\n originalApprovalAmount?: string;\n\n /**\n * The original gas estimation of the transaction.\n */\n originalGasEstimate?: string;\n\n /**\n * When we speed up a transaction, we set the type as Retry and we lose\n * information about type of transaction that is being set up, so we use\n * original type to track that information.\n */\n originalType?: TransactionType;\n\n /**\n * Account transaction balance after swap.\n */\n postTxBalance?: string;\n\n /**\n * Account transaction balance before swap.\n */\n preTxBalance?: string;\n\n /**\n * The previous gas properties before they were updated.\n */\n previousGas?: {\n /**\n * Maxmimum number of units of gas to use for this transaction.\n */\n gasLimit?: string;\n\n /**\n * Maximum amount per gas to pay for the transaction, including the priority fee.\n */\n maxFeePerGas?: string;\n\n /**\n * Maximum amount per gas to give to validator as incentive.\n */\n maxPriorityFeePerGas?: string;\n };\n\n /**\n * The transaction's 'r' value as a hex string.\n */\n r?: string;\n\n /**\n * Hex representation of the underlying transaction.\n */\n rawTx?: string;\n\n /**\n * When the transaction is dropped, this is the replacement transaction hash.\n */\n replacedBy?: string;\n\n /**\n * When the transaction is dropped, this is the replacement transaction ID.\n */\n replacedById?: string;\n\n /**\n * The number of times that the transaction submit has been retried.\n */\n retryCount?: number;\n\n /**\n * The transaction's 's' value as a hex string.\n */\n s?: string;\n\n /**\n * Response from security validator.\n */\n securityAlertResponse?: SecurityAlertResponse;\n\n /**\n * Response from security provider.\n */\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n securityProviderResponse?: Record<string, any>;\n\n /**\n * An array of entries that describe the user's journey through the send flow.\n * This is purely attached to state logs for troubleshooting and support.\n */\n sendFlowHistory?: SendFlowHistoryEntry[];\n\n /**\n * Simulation data for the transaction used to predict its outcome.\n */\n simulationData?: SimulationData;\n\n /**\n * If the gas estimation fails, an object containing error and block information.\n */\n simulationFails?: {\n reason?: string;\n errorKey?: string;\n debug: {\n blockNumber?: string;\n blockGasLimit?: string;\n };\n };\n\n /**\n * The time the transaction was submitted to the network, in Unix epoch time (ms).\n */\n submittedTime?: number;\n\n /**\n * The symbol of the token being swapped.\n */\n sourceTokenSymbol?: string;\n\n /**\n * The metadata of the swap transaction.\n */\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n swapMetaData?: Record<string, any>;\n\n /**\n * The value of the token being swapped.\n */\n swapTokenValue?: string;\n\n /**\n * Timestamp associated with this transaction.\n */\n time: number;\n\n /**\n * Whether transaction recipient is a smart contract.\n */\n toSmartContract?: boolean;\n\n /**\n * Additional transfer information.\n */\n transferInformation?: {\n contractAddress: string;\n decimals: number;\n symbol: string;\n };\n\n /**\n * Underlying Transaction object.\n */\n txParams: TransactionParams;\n\n /**\n * Transaction receipt.\n */\n txReceipt?: TransactionReceipt;\n\n /**\n * The type of transaction such as `cancel` or `swap`.\n */\n type?: TransactionType;\n\n /**\n * The gas limit supplied by user.\n */\n userEditedGasLimit?: boolean;\n\n /**\n * Estimate level user selected.\n */\n userFeeLevel?: string;\n\n /**\n * The transaction's 'v' value as a hex string.\n */\n v?: string;\n\n /**\n * Whether the transaction is verified on the blockchain.\n */\n verifiedOnBlockchain?: boolean;\n\n /**\n * Warning information for the transaction.\n */\n warning?: {\n error: string;\n message: string;\n };\n};\n\nexport type SendFlowHistoryEntry = {\n /**\n * String to indicate user interaction information.\n */\n entry: string;\n\n /**\n * Timestamp associated with this entry.\n */\n timestamp: number;\n};\n\n/**\n * The status of the transaction. Each status represents the state of the transaction internally\n * in the wallet. Some of these correspond with the state of the transaction on the network, but\n * some are wallet-specific.\n */\nexport enum TransactionStatus {\n approved = 'approved',\n /** @deprecated Determined by the clients using the transaction type. No longer used. */\n cancelled = 'cancelled',\n confirmed = 'confirmed',\n dropped = 'dropped',\n failed = 'failed',\n rejected = 'rejected',\n signed = 'signed',\n submitted = 'submitted',\n unapproved = 'unapproved',\n}\n\n/**\n * Options for wallet device.\n */\nexport enum WalletDevice {\n MM_MOBILE = 'metamask_mobile',\n MM_EXTENSION = 'metamask_extension',\n OTHER = 'other_device',\n}\n\n/**\n * The type of the transaction.\n */\nexport enum TransactionType {\n /**\n * A transaction sending a network's native asset to a recipient.\n */\n cancel = 'cancel',\n\n /**\n * A transaction that is interacting with a smart contract's methods that we\n * have not treated as a special case, such as approve, transfer, and\n * transferfrom.\n */\n contractInteraction = 'contractInteraction',\n\n /**\n * A transaction that deployed a smart contract.\n */\n deployContract = 'contractDeployment',\n\n /**\n * A transaction for Ethereum decryption.\n */\n ethDecrypt = 'eth_decrypt',\n\n /**\n * A transaction for getting an encryption public key.\n */\n ethGetEncryptionPublicKey = 'eth_getEncryptionPublicKey',\n\n /**\n * An incoming (deposit) transaction.\n */\n incoming = 'incoming',\n\n /**\n * A transaction for personal sign.\n */\n personalSign = 'personal_sign',\n\n /**\n * When a transaction is failed it can be retried by\n * resubmitting the same transaction with a higher gas fee. This type is also used\n * to speed up pending transactions. This is accomplished by creating a new tx with\n * the same nonce and higher gas fees.\n */\n retry = 'retry',\n\n /**\n * A transaction sending a network's native asset to a recipient.\n */\n simpleSend = 'simpleSend',\n\n /**\n * A transaction that is signing a message.\n */\n sign = 'eth_sign',\n\n /**\n * A transaction that is signing typed data.\n */\n signTypedData = 'eth_signTypedData',\n\n /**\n * A transaction sending a network's native asset to a recipient.\n */\n smart = 'smart',\n\n /**\n * A transaction swapping one token for another through MetaMask Swaps.\n */\n swap = 'swap',\n\n /**\n * Similar to the approve type, a swap approval is a special case of ERC20\n * approve method that requests an allowance of the token to spend on behalf\n * of the user for the MetaMask Swaps contract. The first swap for any token\n * will have an accompanying swapApproval transaction.\n */\n swapApproval = 'swapApproval',\n\n /**\n * A token transaction requesting an allowance of the token to spend on\n * behalf of the user.\n */\n tokenMethodApprove = 'approve',\n\n /**\n * A token transaction transferring tokens from an account that the sender\n * has an allowance of. The method is prefixed with safe because when calling\n * this method the contract checks to ensure that the receiver is an address\n * capable of handling the token being sent.\n */\n tokenMethodSafeTransferFrom = 'safetransferfrom',\n\n /**\n * A token transaction where the user is sending tokens that they own to\n * another address.\n */\n tokenMethodTransfer = 'transfer',\n\n /**\n * A token transaction transferring tokens from an account that the sender\n * has an allowance of. For more information on allowances, see the approve\n * type.\n */\n tokenMethodTransferFrom = 'transferfrom',\n\n /**\n * A token transaction requesting an allowance of all of a user's tokens to\n * spend on behalf of the user.\n */\n tokenMethodSetApprovalForAll = 'setapprovalforall',\n\n /**\n * Increase the allowance by a given increment\n */\n tokenMethodIncreaseAllowance = 'increaseAllowance',\n}\n\n/**\n * Standard data concerning a transaction to be processed by the blockchain.\n */\nexport type TransactionParams = {\n /**\n * A list of addresses and storage keys that the transaction plans to access.\n */\n accessList?: AccessList;\n\n /**\n * Network ID as per EIP-155.\n */\n chainId?: Hex;\n\n /**\n * Data to pass with this transaction.\n */\n data?: string;\n\n /**\n * Error message for gas estimation failure.\n */\n estimateGasError?: string;\n\n /**\n * Estimated base fee for this transaction.\n */\n estimatedBaseFee?: string;\n\n /**\n * Which estimate level that the API suggested.\n */\n estimateSuggested?: string;\n\n /**\n * Which estimate level was used\n */\n estimateUsed?: string;\n\n /**\n * Address to send this transaction from.\n */\n from: string;\n\n /**\n * same as gasLimit?\n */\n gas?: string;\n\n /**\n * Maxmimum number of units of gas to use for this transaction.\n */\n gasLimit?: string;\n\n /**\n * Price per gas for legacy txs\n */\n gasPrice?: string;\n\n /**\n * Gas used in the transaction.\n */\n gasUsed?: string;\n\n /**\n * Maximum amount per gas to pay for the transaction, including the priority\n * fee.\n */\n maxFeePerGas?: string;\n\n /**\n * Maximum amount per gas to give to validator as incentive.\n */\n maxPriorityFeePerGas?: string;\n\n /**\n * Unique number to prevent replay attacks.\n */\n nonce?: string;\n\n /**\n * Address to send this transaction to.\n */\n to?: string;\n\n /**\n * Value associated with this transaction.\n */\n value?: string;\n\n /**\n * Type of transaction.\n * 0x0 indicates a legacy transaction.\n */\n type?: string;\n};\n\n/**\n * Standard data concerning a transaction processed by the blockchain.\n */\nexport type TransactionReceipt = {\n /**\n * The block hash of the block that this transaction was included in.\n */\n blockHash?: string;\n\n /**\n * The block number of the block that this transaction was included in.\n */\n blockNumber?: string;\n\n /**\n * Effective gas price the transaction was charged at.\n */\n effectiveGasPrice?: string;\n\n /**\n * Gas used in the transaction.\n */\n gasUsed?: string;\n\n /**\n * Total used gas in hex.\n */\n l1Fee?: string;\n\n /**\n * All the logs emitted by this transaction.\n */\n logs?: Log[];\n\n /**\n * The status of the transaction.\n */\n status?: string;\n\n /**\n * The hexadecimal index of this transaction in the list of transactions included in the block this transaction was mined in.\n */\n transactionIndex?: string;\n};\n\n/**\n * Represents an event that has been included in a transaction using the EVM `LOG` opcode.\n */\nexport type Log = {\n /**\n * Address of the contract that generated log.\n */\n address?: string;\n /**\n * List of topics for log.\n */\n topics?: string;\n};\n\n/**\n * The configuration required to fetch transaction data from a RemoteTransactionSource.\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface RemoteTransactionSourceRequest {\n /**\n * The address of the account to fetch transactions for.\n */\n address: string;\n\n /**\n * The chainId of the current network.\n */\n currentChainId: Hex;\n\n /**\n * Block number to start fetching transactions from.\n */\n fromBlock?: number;\n\n /**\n * Maximum number of transactions to retrieve.\n */\n limit?: number;\n}\n\n/**\n * An object capable of fetching transaction data from a remote source.\n * Used by the IncomingTransactionHelper to retrieve remote transaction data.\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface RemoteTransactionSource {\n /**\n * @param chainId - The chainId of the current network.\n * @returns Whether the remote transaction source supports the specified network.\n */\n isSupportedNetwork: (chainId: Hex) => boolean;\n\n /**\n * @returns An array of additional keys to use when caching the last fetched block number.\n */\n getLastBlockVariations?: () => string[];\n\n /**\n * @param request - A request object containing data such as the address and chain ID.\n * @returns An array of transaction metadata for the retrieved transactions.\n */\n fetchTransactions: (\n request: RemoteTransactionSourceRequest,\n ) => Promise<TransactionMeta[]>;\n}\n\n/**\n * Gas values initially suggested by the dApp.\n */\nexport type DappSuggestedGasFees = {\n gas?: string;\n gasPrice?: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n};\n\n/**\n * Gas values saved by the user for a specific chain.\n */\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface SavedGasFees {\n maxBaseFee: string;\n priorityFee: string;\n}\n\n/**\n * A transaction history operation that includes a note and timestamp.\n */\ntype ExtendedHistoryOperation = JsonCompatibleOperation & {\n note?: string;\n timestamp?: number;\n};\n\n/**\n * A transaction history entry that includes the ExtendedHistoryOperation as the first element.\n */\nexport type TransactionHistoryEntry = [\n ExtendedHistoryOperation,\n ...JsonCompatibleOperation[],\n];\n\n/**\n * A transaction history that includes the transaction meta as the first element.\n * And the rest of the elements are the operation arrays that were applied to the transaction meta.\n */\nexport type TransactionHistory = [\n TransactionMeta,\n ...TransactionHistoryEntry[],\n];\n\n/**\n * Result of inferring the transaction type.\n */\nexport type InferTransactionTypeResult = {\n /**\n * The contract code, in hex format if it exists. '0x0' or\n * '0x' are also indicators of non-existent contract code.\n */\n getCodeResponse?: string | null;\n\n /**\n * The type of transaction\n */\n type: TransactionType;\n};\n\n/**\n * A function for verifying a transaction, whether it is malicious or not.\n */\nexport type SecurityProviderRequest = (\n requestData: TransactionMeta,\n messageType: string,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n) => Promise<any>;\n\n/**\n * Specifies the shape of the base transaction parameters.\n * Added in EIP-2718.\n */\nexport enum TransactionEnvelopeType {\n /**\n * A legacy transaction, the very first type.\n */\n legacy = '0x0',\n\n /**\n * EIP-2930 defined the access list transaction type that allowed for\n * specifying the state that a transaction would act upon in advance and\n * theoretically save on gas fees.\n */\n accessList = '0x1',\n\n /**\n * The type introduced comes from EIP-1559, Fee Market describes the addition\n * of a baseFee to blocks that will be burned instead of distributed to\n * miners. Transactions of this type have both a maxFeePerGas (maximum total\n * amount in gwei per gas to spend on the transaction) which is inclusive of\n * the maxPriorityFeePerGas (maximum amount of gwei per gas from the\n * transaction fee to distribute to miner).\n */\n feeMarket = '0x2',\n}\n\n/**\n * The source of the gas fee parameters on a transaction.\n */\nexport enum UserFeeLevel {\n CUSTOM = 'custom',\n DAPP_SUGGESTED = 'dappSuggested',\n MEDIUM = 'medium',\n}\n\n/**\n * Initial gas values set when the transaction was first created.\n */\nexport type DefaultGasEstimates = {\n /**\n * Source of the gas fee values, such as `dappSuggested` or `medium`.\n */\n estimateType?: string;\n\n /**\n * Maxmimum number of units of gas to use for this transaction.\n */\n gas?: string;\n\n /**\n * Price per gas for legacy transactions.\n */\n gasPrice?: string;\n\n /**\n * Maximum amount per gas to pay for the transaction, including the priority fee.\n */\n maxFeePerGas?: string;\n\n /**\n * Maximum amount per gas to give to validator as incentive.\n */\n maxPriorityFeePerGas?: string;\n};\n\n/**\n * Data concerning an error while processing a transaction.\n */\nexport type TransactionError = {\n /**\n * A descriptive error name.\n */\n name: string;\n\n /**\n * A descriptive error message providing details about the encountered error.\n */\n message: string;\n\n /**\n * The stack trace associated with the error, if available.\n */\n stack?: string;\n\n /**\n * An optional error code associated with the error.\n */\n code?: string;\n\n /**\n * The rpc property holds additional information related to the error.\n */\n // We are intentionally using `any` here instead of `Json` because it causes\n // `WritableDraft<TransactionMeta>` from Immer to cause TypeScript to error\n // with \"Type instantiation is excessively deep and possibly infinite\". See:\n // <https://github.com/immerjs/immer/issues/839>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rpc?: any;\n};\n\n/**\n * Type for security alert response from transaction validator.\n */\nexport type SecurityAlertResponse = {\n reason: string;\n features?: string[];\n result_type: string;\n providerRequestsCount?: Record<string, number>;\n};\n\n/** Gas fee estimates for a specific priority level. */\nexport type GasFeeEstimatesForLevel = {\n /** Maximum amount to pay per gas. */\n maxFeePerGas: Hex;\n\n /** Maximum amount per gas to give to the validator as an incentive. */\n maxPriorityFeePerGas: Hex;\n};\n\n/** Alternate priority levels for which values are provided in gas fee estimates. */\nexport enum GasFeeEstimateLevel {\n low = 'low',\n medium = 'medium',\n high = 'high',\n}\n\n/** Gas fee estimates for a transaction. */\nexport type GasFeeEstimates = {\n /** The gas fee estimate for a low priority transaction. */\n [GasFeeEstimateLevel.low]: GasFeeEstimatesForLevel;\n\n /** The gas fee estimate for a medium priority transaction. */\n [GasFeeEstimateLevel.medium]: GasFeeEstimatesForLevel;\n\n /** The gas fee estimate for a high priority transaction. */\n [GasFeeEstimateLevel.high]: GasFeeEstimatesForLevel;\n};\n\n/** Request to a gas fee flow to obtain gas fee estimates. */\nexport type GasFeeFlowRequest = {\n /** An EthQuery instance to enable queries to the associated RPC provider. */\n ethQuery: EthQuery;\n\n /** Callback to get the GasFeeController estimates. */\n getGasFeeControllerEstimates: (\n options: FetchGasFeeEstimateOptions,\n ) => Promise<GasFeeState>;\n\n /** The metadata of the transaction to obtain estimates for. */\n transactionMeta: TransactionMeta;\n};\n\n/** Response from a gas fee flow containing gas fee estimates. */\nexport type GasFeeFlowResponse = {\n /** The gas fee estimates for the transaction. */\n estimates: GasFeeEstimates;\n};\n\n/** A method of obtaining gas fee estimates for a specific transaction. */\nexport type GasFeeFlow = {\n /**\n * Determine if the gas fee flow supports the specified transaction.\n * @param transactionMeta - The transaction metadata.\n * @returns Whether the gas fee flow supports the transaction.\n */\n matchesTransaction(transactionMeta: TransactionMeta): boolean;\n\n /**\n * Get gas fee estimates for a specific transaction.\n * @param request - The gas fee flow request.\n * @returns The gas fee flow response containing the gas fee estimates.\n */\n getGasFees: (request: GasFeeFlowRequest) => Promise<GasFeeFlowResponse>;\n};\n\n/** Request to a layer 1 gas fee flow to obtain layer 1 fee estimate. */\nexport type Layer1GasFeeFlowRequest = {\n /** An EthQuery instance to enable queries to the associated RPC provider. */\n ethQuery: EthQuery;\n\n /** The metadata of the transaction to obtain estimates for. */\n transactionMeta: TransactionMeta;\n};\n\n/** Response from a layer 1 gas fee flow containing layer 1 fee estimate. */\nexport type Layer1GasFeeFlowResponse = {\n /** The gas fee estimates for the transaction. */\n layer1Fee: Hex;\n};\n\n/** A method of obtaining layer 1 gas fee estimates for a specific transaction. */\nexport type Layer1GasFeeFlow = {\n /**\n * Determine if the gas fee flow supports the specified transaction.\n * @param transactionMeta - The transaction metadata.\n * @returns Whether the layer1 gas fee flow supports the transaction.\n */\n matchesTransaction(transactionMeta: TransactionMeta): boolean;\n\n /**\n * Get layer 1 gas fee estimates for a specific transaction.\n * @param request - The gas fee flow request.\n * @returns The gas fee flow response containing the layer 1 gas fee estimate.\n */\n getLayer1Fee: (\n request: Layer1GasFeeFlowRequest,\n ) => Promise<Layer1GasFeeFlowResponse>;\n};\n\n/** Simulation data concerning an update to a native or token balance. */\nexport type SimulationBalanceChange = {\n /** The balance before the transaction. */\n previousBalance: Hex;\n\n /** The balance after the transaction. */\n newBalance: Hex;\n\n /** The difference in balance. */\n difference: Hex;\n\n /** Whether the balance is increasing or decreasing. */\n isDecrease: boolean;\n};\n\n/** Token standards supported by simulation. */\nexport enum SimulationTokenStandard {\n erc20 = 'erc20',\n erc721 = 'erc721',\n erc1155 = 'erc1155',\n}\n\n/** Simulation data concerning an updated token. */\nexport type SimulationToken = {\n /** The token's contract address. */\n address: Hex;\n\n /** The standard of the token. */\n standard: SimulationTokenStandard;\n\n /** The ID of the token if supported by the standard. */\n id?: Hex;\n};\n\n/** Simulation data concerning a change to the a token balance. */\nexport type SimulationTokenBalanceChange = SimulationToken &\n SimulationBalanceChange;\n\nexport enum SimulationErrorCode {\n ChainNotSupported = 'chain-not-supported',\n Disabled = 'disabled',\n InvalidResponse = 'invalid-response',\n Reverted = 'reverted',\n}\n\n/** Error data for a failed simulation. */\nexport type SimulationError = {\n /** Error code to identify the error type. */\n code?: string | number;\n\n /** Error message to describe the error. */\n message?: string;\n};\n\n/** Simulation data for a transaction. */\nexport type SimulationData = {\n /** Error data if the simulation failed or the transaction reverted. */\n error?: SimulationError;\n\n /** Data concerning a change to the user's native balance. */\n nativeBalanceChange?: SimulationBalanceChange;\n\n /** Data concerning a change to the user's token balances. */\n tokenBalanceChanges: SimulationTokenBalanceChange[];\n};\n"]}
@@ -0,0 +1,36 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/errors.ts
2
+ var SimulationError = class extends Error {
3
+ constructor(message, code) {
4
+ super(message ?? "Simulation failed");
5
+ this.code = code;
6
+ }
7
+ };
8
+ var SimulationChainNotSupportedError = class extends SimulationError {
9
+ constructor(chainId) {
10
+ super(
11
+ `Chain is not supported: ${chainId}`,
12
+ "chain-not-supported" /* ChainNotSupported */
13
+ );
14
+ }
15
+ };
16
+ var SimulationInvalidResponseError = class extends SimulationError {
17
+ constructor() {
18
+ super(
19
+ "Invalid response from simulation API",
20
+ "invalid-response" /* InvalidResponse */
21
+ );
22
+ }
23
+ };
24
+ var SimulationRevertedError = class extends SimulationError {
25
+ constructor() {
26
+ super("Transaction was reverted", "reverted" /* Reverted */);
27
+ }
28
+ };
29
+
30
+
31
+
32
+
33
+
34
+
35
+ exports.SimulationError = SimulationError; exports.SimulationChainNotSupportedError = SimulationChainNotSupportedError; exports.SimulationInvalidResponseError = SimulationInvalidResponseError; exports.SimulationRevertedError = SimulationRevertedError;
36
+ //# sourceMappingURL=chunk-HMOSP33F.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts"],"names":[],"mappings":";AAIO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAGzC,YAAY,SAAkB,MAAwB;AACpD,UAAM,WAAW,mBAAmB;AAEpC,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,mCAAN,cAA+C,gBAAgB;AAAA,EACpE,YAAY,SAAc;AACxB;AAAA,MACE,2BAA2B,OAAO;AAAA;AAAA,IAEpC;AAAA,EACF;AACF;AAEO,IAAM,iCAAN,cAA6C,gBAAgB;AAAA,EAClE,cAAc;AACZ;AAAA,MACE;AAAA;AAAA,IAEF;AAAA,EACF;AACF;AAEO,IAAM,0BAAN,cAAsC,gBAAgB;AAAA,EAC3D,cAAc;AACZ,UAAM,qDAAwD;AAAA,EAChE;AACF","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport { SimulationErrorCode } from './types';\n\nexport class SimulationError extends Error {\n code?: string | number;\n\n constructor(message?: string, code?: string | number) {\n super(message ?? 'Simulation failed');\n\n this.code = code;\n }\n}\n\nexport class SimulationChainNotSupportedError extends SimulationError {\n constructor(chainId: Hex) {\n super(\n `Chain is not supported: ${chainId}`,\n SimulationErrorCode.ChainNotSupported,\n );\n }\n}\n\nexport class SimulationInvalidResponseError extends SimulationError {\n constructor() {\n super(\n 'Invalid response from simulation API',\n SimulationErrorCode.InvalidResponse,\n );\n }\n}\n\nexport class SimulationRevertedError extends SimulationError {\n constructor() {\n super('Transaction was reverted', SimulationErrorCode.Reverted);\n }\n}\n"]}
@@ -0,0 +1,36 @@
1
+ // src/errors.ts
2
+ var SimulationError = class extends Error {
3
+ constructor(message, code) {
4
+ super(message ?? "Simulation failed");
5
+ this.code = code;
6
+ }
7
+ };
8
+ var SimulationChainNotSupportedError = class extends SimulationError {
9
+ constructor(chainId) {
10
+ super(
11
+ `Chain is not supported: ${chainId}`,
12
+ "chain-not-supported" /* ChainNotSupported */
13
+ );
14
+ }
15
+ };
16
+ var SimulationInvalidResponseError = class extends SimulationError {
17
+ constructor() {
18
+ super(
19
+ "Invalid response from simulation API",
20
+ "invalid-response" /* InvalidResponse */
21
+ );
22
+ }
23
+ };
24
+ var SimulationRevertedError = class extends SimulationError {
25
+ constructor() {
26
+ super("Transaction was reverted", "reverted" /* Reverted */);
27
+ }
28
+ };
29
+
30
+ export {
31
+ SimulationError,
32
+ SimulationChainNotSupportedError,
33
+ SimulationInvalidResponseError,
34
+ SimulationRevertedError
35
+ };
36
+ //# sourceMappingURL=chunk-HQSNKCXI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts"],"sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport { SimulationErrorCode } from './types';\n\nexport class SimulationError extends Error {\n code?: string | number;\n\n constructor(message?: string, code?: string | number) {\n super(message ?? 'Simulation failed');\n\n this.code = code;\n }\n}\n\nexport class SimulationChainNotSupportedError extends SimulationError {\n constructor(chainId: Hex) {\n super(\n `Chain is not supported: ${chainId}`,\n SimulationErrorCode.ChainNotSupported,\n );\n }\n}\n\nexport class SimulationInvalidResponseError extends SimulationError {\n constructor() {\n super(\n 'Invalid response from simulation API',\n SimulationErrorCode.InvalidResponse,\n );\n }\n}\n\nexport class SimulationRevertedError extends SimulationError {\n constructor() {\n super('Transaction was reverted', SimulationErrorCode.Reverted);\n }\n}\n"],"mappings":";AAIO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAGzC,YAAY,SAAkB,MAAwB;AACpD,UAAM,WAAW,mBAAmB;AAEpC,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,mCAAN,cAA+C,gBAAgB;AAAA,EACpE,YAAY,SAAc;AACxB;AAAA,MACE,2BAA2B,OAAO;AAAA;AAAA,IAEpC;AAAA,EACF;AACF;AAEO,IAAM,iCAAN,cAA6C,gBAAgB;AAAA,EAClE,cAAc;AACZ;AAAA,MACE;AAAA;AAAA,IAEF;AAAA,EACF;AACF;AAEO,IAAM,0BAAN,cAAsC,gBAAgB;AAAA,EAC3D,cAAc;AACZ,UAAM,qDAAwD;AAAA,EAChE;AACF;","names":[]}
@@ -1,3 +1,7 @@
1
+ import {
2
+ SimulationChainNotSupportedError,
3
+ SimulationError
4
+ } from "./chunk-HQSNKCXI.mjs";
1
5
  import {
2
6
  projectLogger
3
7
  } from "./chunk-UQQWZT6C.mjs";
@@ -27,7 +31,8 @@ async function simulateTransactions(chainId, request) {
27
31
  const responseJson = await response.json();
28
32
  log("Received response", responseJson);
29
33
  if (responseJson.error) {
30
- throw responseJson.error;
34
+ const { code, message } = responseJson.error;
35
+ throw new SimulationError(message, code);
31
36
  }
32
37
  return responseJson?.result;
33
38
  }
@@ -37,7 +42,7 @@ async function getSimulationUrl(chainId) {
37
42
  const network = networkData[chainIdDecimal];
38
43
  if (!network?.confirmations) {
39
44
  log("Chain is not supported", chainId);
40
- throw new Error(`Chain is not supported: ${chainId}`);
45
+ throw new SimulationChainNotSupportedError(chainId);
41
46
  }
42
47
  return getUrl(network.network);
43
48
  }
@@ -53,4 +58,4 @@ function getUrl(subdomain) {
53
58
  export {
54
59
  simulateTransactions
55
60
  };
56
- //# sourceMappingURL=chunk-6XMG522E.mjs.map
61
+ //# sourceMappingURL=chunk-K4KOSAGM.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/simulation-api.ts"],"sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { SimulationChainNotSupportedError, SimulationError } from '../errors';\nimport { projectLogger } from '../logger';\n\nconst log = createModuleLogger(projectLogger, 'simulation-api');\n\nconst RPC_METHOD = 'infura_simulateTransactions';\nconst BASE_URL = 'https://tx-sentinel-{0}.api.cx.metamask.io/';\nconst ENDPOINT_NETWORKS = 'networks';\n\n/** Single transaction to simulate in a simulation API request. */\nexport type SimulationRequestTransaction = {\n /** Data to send with the transaction. */\n data?: Hex;\n\n /** Sender of the transaction. */\n from: Hex;\n\n /** Gas limit for the transaction. */\n gas?: Hex;\n\n /** Maximum fee per gas for the transaction. */\n maxFeePerGas?: Hex;\n\n /** Maximum priority fee per gas for the transaction. */\n maxPriorityFeePerGas?: Hex;\n\n /** Recipient of the transaction. */\n to?: Hex;\n\n /** Value to send with the transaction. */\n value?: Hex;\n};\n\n/** Request to the simulation API to simulate transactions. */\nexport type SimulationRequest = {\n /**\n * Transactions to be sequentially simulated.\n * State changes impact subsequent transactions in the list.\n */\n transactions: SimulationRequestTransaction[];\n\n /**\n * Overrides to the state of the blockchain, keyed by smart contract address.\n */\n overrides?: {\n [address: Hex]: {\n /** Overrides to the storage slots for a smart contract account. */\n stateDiff: {\n [slot: Hex]: Hex;\n };\n };\n };\n\n /**\n * Whether to include call traces in the response.\n * Defaults to false.\n */\n withCallTrace?: boolean;\n\n /**\n * Whether to include event logs in the response.\n * Defaults to false.\n */\n withLogs?: boolean;\n};\n\n/** Raw event log emitted by a simulated transaction. */\nexport type SimulationResponseLog = {\n /** Address of the account that created the event. */\n address: Hex;\n\n /** Raw data in the event that is not indexed. */\n data: Hex;\n\n /** Raw indexed data from the event. */\n topics: Hex[];\n};\n\n/** Call trace of a single simulated transaction. */\nexport type SimulationResponseCallTrace = {\n /** Nested calls. */\n calls: SimulationResponseCallTrace[];\n\n /** Raw event logs created by the call. */\n logs: SimulationResponseLog[];\n};\n\n/**\n * Changes to the blockchain state.\n * Keyed by account address.\n */\nexport type SimulationResponseStateDiff = {\n [address: Hex]: {\n /** Native balance of the account. */\n balance?: Hex;\n\n /** Nonce of the account. */\n nonce?: Hex;\n\n /** Storage values per slot. */\n storage?: {\n [slot: Hex]: Hex;\n };\n };\n};\n\n/** Response from the simulation API for a single transaction. */\nexport type SimulationResponseTransaction = {\n /** An error message indicating the transaction could not be simulated. */\n error?: string;\n\n /** Return value of the transaction, such as the balance if calling balanceOf. */\n return: Hex;\n\n /** Hierarchy of call data including nested calls and logs. */\n callTrace?: SimulationResponseCallTrace;\n\n /** Changes to the blockchain state. */\n stateDiff?: {\n /** Initial blockchain state before the transaction. */\n pre?: SimulationResponseStateDiff;\n\n /** Updated blockchain state after the transaction. */\n post?: SimulationResponseStateDiff;\n };\n};\n\n/** Response from the simulation API. */\nexport type SimulationResponse = {\n /** Simulation data for each transaction in the request. */\n transactions: SimulationResponseTransaction[];\n};\n\n/** Data for a network supported by the Simulation API. */\ntype SimulationNetwork = {\n /** Subdomain of the API for the network. */\n network: string;\n\n /** Whether the network supports confirmation simulations. */\n confirmations: boolean;\n};\n\n/** Response from the simulation API containing supported networks. */\ntype SimulationNetworkResponse = {\n [chainIdDecimal: string]: SimulationNetwork;\n};\n\nlet requestIdCounter = 0;\n\n/**\n * Simulate transactions using the transaction simulation API.\n * @param chainId - The chain ID to simulate transactions on.\n * @param request - The request to simulate transactions.\n */\nexport async function simulateTransactions(\n chainId: Hex,\n request: SimulationRequest,\n): Promise<SimulationResponse> {\n const url = await getSimulationUrl(chainId);\n\n log('Sending request', url, request);\n\n const requestId = requestIdCounter;\n requestIdCounter += 1;\n\n const response = await fetch(url, {\n method: 'POST',\n body: JSON.stringify({\n id: String(requestId),\n jsonrpc: '2.0',\n method: RPC_METHOD,\n params: [request],\n }),\n });\n\n const responseJson = await response.json();\n\n log('Received response', responseJson);\n\n if (responseJson.error) {\n const { code, message } = responseJson.error;\n throw new SimulationError(message, code);\n }\n\n return responseJson?.result;\n}\n\n/**\n * Get the URL for the transaction simulation API.\n * @param chainId - The chain ID to get the URL for.\n * @returns The URL for the transaction simulation API.\n */\nasync function getSimulationUrl(chainId: Hex): Promise<string> {\n const networkData = await getNetworkData();\n const chainIdDecimal = convertHexToDecimal(chainId);\n const network = networkData[chainIdDecimal];\n\n if (!network?.confirmations) {\n log('Chain is not supported', chainId);\n throw new SimulationChainNotSupportedError(chainId);\n }\n\n return getUrl(network.network);\n}\n\n/**\n * Retrieve the supported network data from the simulation API.\n */\nasync function getNetworkData(): Promise<SimulationNetworkResponse> {\n const url = `${getUrl('ethereum-mainnet')}${ENDPOINT_NETWORKS}`;\n const response = await fetch(url);\n return response.json();\n}\n\n/**\n * Generate the URL for the specified subdomain in the simulation API.\n * @param subdomain - The subdomain to generate the URL for.\n * @returns The URL for the transaction simulation API.\n */\nfunction getUrl(subdomain: string): string {\n return BASE_URL.replace('{0}', subdomain);\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,2BAA2B;AACpC,SAAS,0BAAoC;AAK7C,IAAM,MAAM,mBAAmB,eAAe,gBAAgB;AAE9D,IAAM,aAAa;AACnB,IAAM,WAAW;AACjB,IAAM,oBAAoB;AA4I1B,IAAI,mBAAmB;AAOvB,eAAsB,qBACpB,SACA,SAC6B;AAC7B,QAAM,MAAM,MAAM,iBAAiB,OAAO;AAE1C,MAAI,mBAAmB,KAAK,OAAO;AAEnC,QAAM,YAAY;AAClB,sBAAoB;AAEpB,QAAM,WAAW,MAAM,MAAM,KAAK;AAAA,IAChC,QAAQ;AAAA,IACR,MAAM,KAAK,UAAU;AAAA,MACnB,IAAI,OAAO,SAAS;AAAA,MACpB,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,QAAQ,CAAC,OAAO;AAAA,IAClB,CAAC;AAAA,EACH,CAAC;AAED,QAAM,eAAe,MAAM,SAAS,KAAK;AAEzC,MAAI,qBAAqB,YAAY;AAErC,MAAI,aAAa,OAAO;AACtB,UAAM,EAAE,MAAM,QAAQ,IAAI,aAAa;AACvC,UAAM,IAAI,gBAAgB,SAAS,IAAI;AAAA,EACzC;AAEA,SAAO,cAAc;AACvB;AAOA,eAAe,iBAAiB,SAA+B;AAC7D,QAAM,cAAc,MAAM,eAAe;AACzC,QAAM,iBAAiB,oBAAoB,OAAO;AAClD,QAAM,UAAU,YAAY,cAAc;AAE1C,MAAI,CAAC,SAAS,eAAe;AAC3B,QAAI,0BAA0B,OAAO;AACrC,UAAM,IAAI,iCAAiC,OAAO;AAAA,EACpD;AAEA,SAAO,OAAO,QAAQ,OAAO;AAC/B;AAKA,eAAe,iBAAqD;AAClE,QAAM,MAAM,GAAG,OAAO,kBAAkB,CAAC,GAAG,iBAAiB;AAC7D,QAAM,WAAW,MAAM,MAAM,GAAG;AAChC,SAAO,SAAS,KAAK;AACvB;AAOA,SAAS,OAAO,WAA2B;AACzC,SAAO,SAAS,QAAQ,OAAO,SAAS;AAC1C;","names":[]}
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  DefaultGasFeeFlow
3
- } from "./chunk-QRSTF45Q.mjs";
3
+ } from "./chunk-OLIA2HD4.mjs";
4
4
  import {
5
5
  projectLogger
6
6
  } from "./chunk-UQQWZT6C.mjs";
7
7
  import {
8
8
  GasFeeEstimateLevel
9
- } from "./chunk-W57BD6NX.mjs";
9
+ } from "./chunk-UADPSS35.mjs";
10
10
  import {
11
11
  __privateAdd,
12
12
  __privateMethod
@@ -118,4 +118,4 @@ feesToString_fn = function(fees) {
118
118
  export {
119
119
  LineaGasFeeFlow
120
120
  };
121
- //# sourceMappingURL=chunk-PGTV7236.mjs.map
121
+ //# sourceMappingURL=chunk-K7UC23EG.mjs.map
@@ -1,11 +1,17 @@
1
1
  // src/utils/transaction-type.ts
2
2
  import { Interface } from "@ethersproject/abi";
3
3
  import { query } from "@metamask/controller-utils";
4
- import { abiERC721, abiERC20, abiERC1155 } from "@metamask/metamask-eth-abis";
4
+ import {
5
+ abiERC721,
6
+ abiERC20,
7
+ abiERC1155,
8
+ abiFiatTokenV2
9
+ } from "@metamask/metamask-eth-abis";
5
10
  var ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
6
11
  var ERC20Interface = new Interface(abiERC20);
7
12
  var ERC721Interface = new Interface(abiERC721);
8
13
  var ERC1155Interface = new Interface(abiERC1155);
14
+ var USDCInterface = new Interface(abiFiatTokenV2);
9
15
  async function determineTransactionType(txParams, ethQuery) {
10
16
  const { data, to } = txParams;
11
17
  if (data && !to) {
@@ -32,8 +38,11 @@ async function determineTransactionType(txParams, ethQuery) {
32
38
  "setapprovalforall" /* tokenMethodSetApprovalForAll */,
33
39
  "transfer" /* tokenMethodTransfer */,
34
40
  "transferfrom" /* tokenMethodTransferFrom */,
35
- "safetransferfrom" /* tokenMethodSafeTransferFrom */
36
- ].find((methodName) => methodName.toLowerCase() === name.toLowerCase());
41
+ "safetransferfrom" /* tokenMethodSafeTransferFrom */,
42
+ "increaseAllowance" /* tokenMethodIncreaseAllowance */
43
+ ].find(
44
+ (methodName) => methodName.toLowerCase() === name.toLowerCase()
45
+ );
37
46
  if (tokenMethodName) {
38
47
  return { type: tokenMethodName, getCodeResponse };
39
48
  }
@@ -55,6 +64,10 @@ function parseStandardTokenTransactionData(data) {
55
64
  return ERC1155Interface.parseTransaction({ data });
56
65
  } catch {
57
66
  }
67
+ try {
68
+ return USDCInterface.parseTransaction({ data });
69
+ } catch {
70
+ }
58
71
  return void 0;
59
72
  }
60
73
  async function readAddressAsContract(ethQuery, address) {
@@ -72,4 +85,4 @@ export {
72
85
  ESTIMATE_GAS_ERROR,
73
86
  determineTransactionType
74
87
  };
75
- //# sourceMappingURL=chunk-JRBREX22.mjs.map
88
+ //# sourceMappingURL=chunk-KG4UW4K4.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/transaction-type.ts"],"sourcesContent":["import type { TransactionDescription } from '@ethersproject/abi';\nimport { Interface } from '@ethersproject/abi';\nimport { query } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport {\n abiERC721,\n abiERC20,\n abiERC1155,\n abiFiatTokenV2,\n} from '@metamask/metamask-eth-abis';\n\nimport type { InferTransactionTypeResult, TransactionParams } from '../types';\nimport { TransactionType } from '../types';\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 ethQuery - EthQuery instance.\n * @returns A object with the transaction type and the contract code response in Hex.\n */\nexport async function determineTransactionType(\n txParams: TransactionParams,\n ethQuery: EthQuery,\n): Promise<InferTransactionTypeResult> {\n const { data, to } = txParams;\n\n if (data && !to) {\n return { type: TransactionType.deployContract, getCodeResponse: undefined };\n }\n\n const { contractCode: getCodeResponse, isContractAddress } =\n await readAddressAsContract(ethQuery, to);\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 = parseStandardTokenTransactionData(data)?.name;\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(\n (methodName) => methodName.toLowerCase() === (name as string).toLowerCase(),\n );\n\n if (tokenMethodName) {\n return { type: tokenMethodName, getCodeResponse };\n }\n\n return contractInteractionResult;\n}\n\n/**\n * Attempts to decode transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155.\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 * @returns A representation of an ethereum contract call.\n */\nfunction parseStandardTokenTransactionData(\n data?: string,\n): TransactionDescription | undefined {\n if (!data) {\n return undefined;\n }\n\n try {\n return ERC20Interface.parseTransaction({ data });\n } catch {\n // ignore and next try to parse with erc721 ABI\n }\n\n try {\n return ERC721Interface.parseTransaction({ data });\n } catch {\n // ignore and next try to parse with erc1155 ABI\n }\n\n try {\n return ERC1155Interface.parseTransaction({ data });\n } catch {\n // ignore and return undefined\n }\n\n try {\n return USDCInterface.parseTransaction({ data });\n } catch {\n // ignore and return undefined\n }\n\n return undefined;\n}\n\n/**\n * Reads an Ethereum address and determines if it is a contract address.\n *\n * @param ethQuery - The Ethereum query object used to interact with the Ethereum blockchain.\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 ethQuery: EthQuery,\n address?: string,\n): Promise<{\n contractCode: string | null;\n isContractAddress: boolean;\n}> {\n let contractCode;\n try {\n contractCode = await query(ethQuery, 'getCode', [address]);\n } catch (e) {\n contractCode = null;\n }\n\n const isContractAddress = contractCode\n ? contractCode !== '0x' && contractCode !== '0x0'\n : false;\n return { contractCode, isContractAddress };\n}\n"],"mappings":";AACA,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AAEtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAKA,IAAM,qBAAqB;AAElC,IAAM,iBAAiB,IAAI,UAAU,QAAQ;AAC7C,IAAM,kBAAkB,IAAI,UAAU,SAAS;AAC/C,IAAM,mBAAmB,IAAI,UAAU,UAAU;AACjD,IAAM,gBAAgB,IAAI,UAAU,cAAc;AAWlD,eAAsB,yBACpB,UACA,UACqC;AACrC,QAAM,EAAE,MAAM,GAAG,IAAI;AAErB,MAAI,QAAQ,CAAC,IAAI;AACf,WAAO,EAAE,iDAAsC,iBAAiB,OAAU;AAAA,EAC5E;AAEA,QAAM,EAAE,cAAc,iBAAiB,kBAAkB,IACvD,MAAM,sBAAsB,UAAU,EAAE;AAE1C,MAAI,CAAC,mBAAmB;AACtB,WAAO,EAAE,qCAAkC,gBAAgB;AAAA,EAC7D;AAEA,QAAM,WAAW,OAAO,SAAS,SAAS,GAAG,MAAM;AAEnD,QAAM,4BAA4B;AAAA,IAChC;AAAA,IACA;AAAA,EACF;AAEA,MAAI,CAAC,QAAQ,UAAU;AACrB,WAAO;AAAA,EACT;AAEA,QAAM,OAAO,kCAAkC,IAAI,GAAG;AAEtD,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,QAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOxB,EAAE;AAAA,IACA,CAAC,eAAe,WAAW,YAAY,MAAO,KAAgB,YAAY;AAAA,EAC5E;AAEA,MAAI,iBAAiB;AACnB,WAAO,EAAE,MAAM,iBAAiB,gBAAgB;AAAA,EAClD;AAEA,SAAO;AACT;AAUA,SAAS,kCACP,MACoC;AACpC,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,MAAI;AACF,WAAO,eAAe,iBAAiB,EAAE,KAAK,CAAC;AAAA,EACjD,QAAQ;AAAA,EAER;AAEA,MAAI;AACF,WAAO,gBAAgB,iBAAiB,EAAE,KAAK,CAAC;AAAA,EAClD,QAAQ;AAAA,EAER;AAEA,MAAI;AACF,WAAO,iBAAiB,iBAAiB,EAAE,KAAK,CAAC;AAAA,EACnD,QAAQ;AAAA,EAER;AAEA,MAAI;AACF,WAAO,cAAc,iBAAiB,EAAE,KAAK,CAAC;AAAA,EAChD,QAAQ;AAAA,EAER;AAEA,SAAO;AACT;AASA,eAAe,sBACb,UACA,SAIC;AACD,MAAI;AACJ,MAAI;AACF,mBAAe,MAAM,MAAM,UAAU,WAAW,CAAC,OAAO,CAAC;AAAA,EAC3D,SAAS,GAAG;AACV,mBAAe;AAAA,EACjB;AAEA,QAAM,oBAAoB,eACtB,iBAAiB,QAAQ,iBAAiB,QAC1C;AACJ,SAAO,EAAE,cAAc,kBAAkB;AAC3C;","names":[]}
@@ -1,5 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
+
4
+ var _chunkHMOSP33Fjs = require('./chunk-HMOSP33F.js');
5
+
6
+
3
7
  var _chunkS6VGOPUYjs = require('./chunk-S6VGOPUY.js');
4
8
 
5
9
  // src/utils/simulation-api.ts
@@ -27,7 +31,8 @@ async function simulateTransactions(chainId, request) {
27
31
  const responseJson = await response.json();
28
32
  log("Received response", responseJson);
29
33
  if (responseJson.error) {
30
- throw responseJson.error;
34
+ const { code, message } = responseJson.error;
35
+ throw new (0, _chunkHMOSP33Fjs.SimulationError)(message, code);
31
36
  }
32
37
  return responseJson?.result;
33
38
  }
@@ -37,7 +42,7 @@ async function getSimulationUrl(chainId) {
37
42
  const network = networkData[chainIdDecimal];
38
43
  if (!network?.confirmations) {
39
44
  log("Chain is not supported", chainId);
40
- throw new Error(`Chain is not supported: ${chainId}`);
45
+ throw new (0, _chunkHMOSP33Fjs.SimulationChainNotSupportedError)(chainId);
41
46
  }
42
47
  return getUrl(network.network);
43
48
  }
@@ -53,4 +58,4 @@ function getUrl(subdomain) {
53
58
 
54
59
 
55
60
  exports.simulateTransactions = simulateTransactions;
56
- //# sourceMappingURL=chunk-GE57YNGX.js.map
61
+ //# sourceMappingURL=chunk-KT6UAKBB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/simulation-api.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAS,2BAA2B;AACpC,SAAS,0BAAoC;AAK7C,IAAM,MAAM,mBAAmB,eAAe,gBAAgB;AAE9D,IAAM,aAAa;AACnB,IAAM,WAAW;AACjB,IAAM,oBAAoB;AA4I1B,IAAI,mBAAmB;AAOvB,eAAsB,qBACpB,SACA,SAC6B;AAC7B,QAAM,MAAM,MAAM,iBAAiB,OAAO;AAE1C,MAAI,mBAAmB,KAAK,OAAO;AAEnC,QAAM,YAAY;AAClB,sBAAoB;AAEpB,QAAM,WAAW,MAAM,MAAM,KAAK;AAAA,IAChC,QAAQ;AAAA,IACR,MAAM,KAAK,UAAU;AAAA,MACnB,IAAI,OAAO,SAAS;AAAA,MACpB,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,QAAQ,CAAC,OAAO;AAAA,IAClB,CAAC;AAAA,EACH,CAAC;AAED,QAAM,eAAe,MAAM,SAAS,KAAK;AAEzC,MAAI,qBAAqB,YAAY;AAErC,MAAI,aAAa,OAAO;AACtB,UAAM,EAAE,MAAM,QAAQ,IAAI,aAAa;AACvC,UAAM,IAAI,gBAAgB,SAAS,IAAI;AAAA,EACzC;AAEA,SAAO,cAAc;AACvB;AAOA,eAAe,iBAAiB,SAA+B;AAC7D,QAAM,cAAc,MAAM,eAAe;AACzC,QAAM,iBAAiB,oBAAoB,OAAO;AAClD,QAAM,UAAU,YAAY,cAAc;AAE1C,MAAI,CAAC,SAAS,eAAe;AAC3B,QAAI,0BAA0B,OAAO;AACrC,UAAM,IAAI,iCAAiC,OAAO;AAAA,EACpD;AAEA,SAAO,OAAO,QAAQ,OAAO;AAC/B;AAKA,eAAe,iBAAqD;AAClE,QAAM,MAAM,GAAG,OAAO,kBAAkB,CAAC,GAAG,iBAAiB;AAC7D,QAAM,WAAW,MAAM,MAAM,GAAG;AAChC,SAAO,SAAS,KAAK;AACvB;AAOA,SAAS,OAAO,WAA2B;AACzC,SAAO,SAAS,QAAQ,OAAO,SAAS;AAC1C","sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { SimulationChainNotSupportedError, SimulationError } from '../errors';\nimport { projectLogger } from '../logger';\n\nconst log = createModuleLogger(projectLogger, 'simulation-api');\n\nconst RPC_METHOD = 'infura_simulateTransactions';\nconst BASE_URL = 'https://tx-sentinel-{0}.api.cx.metamask.io/';\nconst ENDPOINT_NETWORKS = 'networks';\n\n/** Single transaction to simulate in a simulation API request. */\nexport type SimulationRequestTransaction = {\n /** Data to send with the transaction. */\n data?: Hex;\n\n /** Sender of the transaction. */\n from: Hex;\n\n /** Gas limit for the transaction. */\n gas?: Hex;\n\n /** Maximum fee per gas for the transaction. */\n maxFeePerGas?: Hex;\n\n /** Maximum priority fee per gas for the transaction. */\n maxPriorityFeePerGas?: Hex;\n\n /** Recipient of the transaction. */\n to?: Hex;\n\n /** Value to send with the transaction. */\n value?: Hex;\n};\n\n/** Request to the simulation API to simulate transactions. */\nexport type SimulationRequest = {\n /**\n * Transactions to be sequentially simulated.\n * State changes impact subsequent transactions in the list.\n */\n transactions: SimulationRequestTransaction[];\n\n /**\n * Overrides to the state of the blockchain, keyed by smart contract address.\n */\n overrides?: {\n [address: Hex]: {\n /** Overrides to the storage slots for a smart contract account. */\n stateDiff: {\n [slot: Hex]: Hex;\n };\n };\n };\n\n /**\n * Whether to include call traces in the response.\n * Defaults to false.\n */\n withCallTrace?: boolean;\n\n /**\n * Whether to include event logs in the response.\n * Defaults to false.\n */\n withLogs?: boolean;\n};\n\n/** Raw event log emitted by a simulated transaction. */\nexport type SimulationResponseLog = {\n /** Address of the account that created the event. */\n address: Hex;\n\n /** Raw data in the event that is not indexed. */\n data: Hex;\n\n /** Raw indexed data from the event. */\n topics: Hex[];\n};\n\n/** Call trace of a single simulated transaction. */\nexport type SimulationResponseCallTrace = {\n /** Nested calls. */\n calls: SimulationResponseCallTrace[];\n\n /** Raw event logs created by the call. */\n logs: SimulationResponseLog[];\n};\n\n/**\n * Changes to the blockchain state.\n * Keyed by account address.\n */\nexport type SimulationResponseStateDiff = {\n [address: Hex]: {\n /** Native balance of the account. */\n balance?: Hex;\n\n /** Nonce of the account. */\n nonce?: Hex;\n\n /** Storage values per slot. */\n storage?: {\n [slot: Hex]: Hex;\n };\n };\n};\n\n/** Response from the simulation API for a single transaction. */\nexport type SimulationResponseTransaction = {\n /** An error message indicating the transaction could not be simulated. */\n error?: string;\n\n /** Return value of the transaction, such as the balance if calling balanceOf. */\n return: Hex;\n\n /** Hierarchy of call data including nested calls and logs. */\n callTrace?: SimulationResponseCallTrace;\n\n /** Changes to the blockchain state. */\n stateDiff?: {\n /** Initial blockchain state before the transaction. */\n pre?: SimulationResponseStateDiff;\n\n /** Updated blockchain state after the transaction. */\n post?: SimulationResponseStateDiff;\n };\n};\n\n/** Response from the simulation API. */\nexport type SimulationResponse = {\n /** Simulation data for each transaction in the request. */\n transactions: SimulationResponseTransaction[];\n};\n\n/** Data for a network supported by the Simulation API. */\ntype SimulationNetwork = {\n /** Subdomain of the API for the network. */\n network: string;\n\n /** Whether the network supports confirmation simulations. */\n confirmations: boolean;\n};\n\n/** Response from the simulation API containing supported networks. */\ntype SimulationNetworkResponse = {\n [chainIdDecimal: string]: SimulationNetwork;\n};\n\nlet requestIdCounter = 0;\n\n/**\n * Simulate transactions using the transaction simulation API.\n * @param chainId - The chain ID to simulate transactions on.\n * @param request - The request to simulate transactions.\n */\nexport async function simulateTransactions(\n chainId: Hex,\n request: SimulationRequest,\n): Promise<SimulationResponse> {\n const url = await getSimulationUrl(chainId);\n\n log('Sending request', url, request);\n\n const requestId = requestIdCounter;\n requestIdCounter += 1;\n\n const response = await fetch(url, {\n method: 'POST',\n body: JSON.stringify({\n id: String(requestId),\n jsonrpc: '2.0',\n method: RPC_METHOD,\n params: [request],\n }),\n });\n\n const responseJson = await response.json();\n\n log('Received response', responseJson);\n\n if (responseJson.error) {\n const { code, message } = responseJson.error;\n throw new SimulationError(message, code);\n }\n\n return responseJson?.result;\n}\n\n/**\n * Get the URL for the transaction simulation API.\n * @param chainId - The chain ID to get the URL for.\n * @returns The URL for the transaction simulation API.\n */\nasync function getSimulationUrl(chainId: Hex): Promise<string> {\n const networkData = await getNetworkData();\n const chainIdDecimal = convertHexToDecimal(chainId);\n const network = networkData[chainIdDecimal];\n\n if (!network?.confirmations) {\n log('Chain is not supported', chainId);\n throw new SimulationChainNotSupportedError(chainId);\n }\n\n return getUrl(network.network);\n}\n\n/**\n * Retrieve the supported network data from the simulation API.\n */\nasync function getNetworkData(): Promise<SimulationNetworkResponse> {\n const url = `${getUrl('ethereum-mainnet')}${ENDPOINT_NETWORKS}`;\n const response = await fetch(url);\n return response.json();\n}\n\n/**\n * Generate the URL for the specified subdomain in the simulation API.\n * @param subdomain - The subdomain to generate the URL for.\n * @returns The URL for the transaction simulation API.\n */\nfunction getUrl(subdomain: string): string {\n return BASE_URL.replace('{0}', subdomain);\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkVEJ3MIZGjs = require('./chunk-VEJ3MIZG.js');
3
+ var _chunkHBNQEJEMjs = require('./chunk-HBNQEJEM.js');
4
4
 
5
5
  // src/utils/gas-flow.ts
6
6
  var _controllerutils = require('@metamask/controller-utils');
@@ -18,7 +18,7 @@ function mergeGasFeeEstimates({
18
18
  transactionGasFeeEstimates
19
19
  }) {
20
20
  if (gasFeeControllerEstimateType === _gasfeecontroller.GAS_ESTIMATE_TYPES.FEE_MARKET) {
21
- return Object.values(_chunkVEJ3MIZGjs.GasFeeEstimateLevel).reduce(
21
+ return Object.values(_chunkHBNQEJEMjs.GasFeeEstimateLevel).reduce(
22
22
  (result, level) => ({
23
23
  ...result,
24
24
  [level]: mergeFeeMarketEstimate(
@@ -30,7 +30,7 @@ function mergeGasFeeEstimates({
30
30
  );
31
31
  }
32
32
  if (gasFeeControllerEstimateType === _gasfeecontroller.GAS_ESTIMATE_TYPES.LEGACY) {
33
- return Object.values(_chunkVEJ3MIZGjs.GasFeeEstimateLevel).reduce(
33
+ return Object.values(_chunkHBNQEJEMjs.GasFeeEstimateLevel).reduce(
34
34
  (result, level) => ({
35
35
  ...result,
36
36
  [level]: getLegacyEstimate(transactionGasFeeEstimates[level])
@@ -59,4 +59,4 @@ function getLegacyEstimate(transactionGasFeeEstimate) {
59
59
 
60
60
 
61
61
  exports.getGasFeeFlow = getGasFeeFlow; exports.mergeGasFeeEstimates = mergeGasFeeEstimates;
62
- //# sourceMappingURL=chunk-TZTP4JVA.js.map
62
+ //# sourceMappingURL=chunk-L4S5SEV3.js.map
@@ -1,5 +1,8 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
2
 
3
+ var _chunkSD6CWFDFjs = require('./chunk-SD6CWFDF.js');
4
+
5
+
3
6
 
4
7
  var _chunkVH47Q6TSjs = require('./chunk-VH47Q6TS.js');
5
8
 
@@ -17,13 +20,10 @@ var _chunkQP75SWIQjs = require('./chunk-QP75SWIQ.js');
17
20
  var _chunkZNZEJDOEjs = require('./chunk-ZNZEJDOE.js');
18
21
 
19
22
 
20
- var _chunkGC77BSQZjs = require('./chunk-GC77BSQZ.js');
21
-
22
-
23
- var _chunkHS277C77js = require('./chunk-HS277C77.js');
23
+ var _chunkV5X6MZHNjs = require('./chunk-V5X6MZHN.js');
24
24
 
25
25
 
26
- var _chunkQEX3QMSLjs = require('./chunk-QEX3QMSL.js');
26
+ var _chunkSOSF65FIjs = require('./chunk-SOSF65FI.js');
27
27
 
28
28
 
29
29
  var _chunkR7NJVDWNjs = require('./chunk-R7NJVDWN.js');
@@ -35,19 +35,22 @@ var _chunkDTDTOMTBjs = require('./chunk-DTDTOMTB.js');
35
35
  var _chunkNRWEI43Qjs = require('./chunk-NRWEI43Q.js');
36
36
 
37
37
 
38
+ var _chunkF3CMU2DMjs = require('./chunk-F3CMU2DM.js');
39
+
40
+
38
41
  var _chunk5XBULBP2js = require('./chunk-5XBULBP2.js');
39
42
 
40
43
 
41
44
  var _chunk7LXE4KHVjs = require('./chunk-7LXE4KHV.js');
42
45
 
43
46
 
44
- var _chunkFHG5GY6Fjs = require('./chunk-FHG5GY6F.js');
47
+ var _chunkUCY5PFZIjs = require('./chunk-UCY5PFZI.js');
45
48
 
46
49
 
47
- var _chunkPF3UOCRWjs = require('./chunk-PF3UOCRW.js');
50
+ var _chunk2AYEGKANjs = require('./chunk-2AYEGKAN.js');
48
51
 
49
52
 
50
- var _chunk5IHLDAOFjs = require('./chunk-5IHLDAOF.js');
53
+ var _chunk2JERLB6Mjs = require('./chunk-2JERLB6M.js');
51
54
 
52
55
 
53
56
 
@@ -66,9 +69,6 @@ var _chunk5OQ373JSjs = require('./chunk-5OQ373JS.js');
66
69
  var _chunkUGFBA4GVjs = require('./chunk-UGFBA4GV.js');
67
70
 
68
71
 
69
- var _chunkF3CMU2DMjs = require('./chunk-F3CMU2DM.js');
70
-
71
-
72
72
  var _chunkS6VGOPUYjs = require('./chunk-S6VGOPUY.js');
73
73
 
74
74
 
@@ -300,7 +300,7 @@ var TransactionController = class extends _basecontroller.BaseController {
300
300
  });
301
301
  this.gasFeeFlows = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getGasFeeFlows, getGasFeeFlows_fn).call(this);
302
302
  this.layer1GasFeeFlows = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getLayer1GasFeeFlows, getLayer1GasFeeFlows_fn).call(this);
303
- const gasFeePoller = new (0, _chunkQEX3QMSLjs.GasFeePoller)({
303
+ const gasFeePoller = new (0, _chunkSOSF65FIjs.GasFeePoller)({
304
304
  // Default gas fee polling is not yet supported by the clients
305
305
  gasFeeFlows: this.gasFeeFlows.slice(0, -1),
306
306
  getEthQuery: (chainId, networkClientId) => _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _multichainTrackingHelper).getEthQuery({
@@ -459,7 +459,7 @@ var TransactionController = class extends _basecontroller.BaseController {
459
459
  networkClientId,
460
460
  chainId
461
461
  });
462
- const transactionType = type ?? (await _chunkHS277C77js.determineTransactionType.call(void 0, txParams, ethQuery)).type;
462
+ const transactionType = type ?? (await _chunkSD6CWFDFjs.determineTransactionType.call(void 0, txParams, ethQuery)).type;
463
463
  const existingTransactionMeta = this.getTransactionWithActionId(actionId);
464
464
  let addedTransactionMeta = existingTransactionMeta ? _lodash.cloneDeep.call(void 0, existingTransactionMeta) : {
465
465
  // Add actionId to txMeta to check if same actionId is seen again
@@ -504,7 +504,11 @@ var TransactionController = class extends _basecontroller.BaseController {
504
504
  }
505
505
  );
506
506
  this.addMetadata(addedTransactionMeta);
507
- _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateSimulationData, updateSimulationData_fn).call(this, addedTransactionMeta);
507
+ if (requireApproval !== false) {
508
+ _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateSimulationData, updateSimulationData_fn).call(this, addedTransactionMeta);
509
+ } else {
510
+ _chunkS6VGOPUYjs.projectLogger.call(void 0, "Skipping simulation as approval not required");
511
+ }
508
512
  this.messagingSystem.publish(
509
513
  `${controllerName}:unapprovedTransactionAdded`,
510
514
  addedTransactionMeta
@@ -1141,7 +1145,7 @@ var TransactionController = class extends _basecontroller.BaseController {
1141
1145
  networkClientId: transactionMeta.networkClientId,
1142
1146
  chainId: transactionMeta.chainId
1143
1147
  });
1144
- const { type } = await _chunkHS277C77js.determineTransactionType.call(void 0,
1148
+ const { type } = await _chunkSD6CWFDFjs.determineTransactionType.call(void 0,
1145
1149
  updatedTransaction.txParams,
1146
1150
  ethQuery
1147
1151
  );
@@ -1433,7 +1437,7 @@ var TransactionController = class extends _basecontroller.BaseController {
1433
1437
  isCustomNetwork,
1434
1438
  txMeta: transactionMeta
1435
1439
  });
1436
- await _chunk5IHLDAOFjs.updateGasFees.call(void 0, {
1440
+ await _chunk2JERLB6Mjs.updateGasFees.call(void 0, {
1437
1441
  eip1559: isEIP1559Compatible,
1438
1442
  ethQuery,
1439
1443
  gasFeeFlows: this.gasFeeFlows,
@@ -1636,7 +1640,7 @@ var TransactionController = class extends _basecontroller.BaseController {
1636
1640
  }
1637
1641
  _chunkS6VGOPUYjs.projectLogger.call(void 0, "Publishing transaction", txParams);
1638
1642
  let { transactionHash: hash } = await this.publish(
1639
- transactionMeta,
1643
+ updatedTransactionMeta,
1640
1644
  rawTx
1641
1645
  );
1642
1646
  if (hash === void 0) {
@@ -2284,7 +2288,7 @@ getNonceTrackerPendingTransactions_fn = function(chainId, address) {
2284
2288
  };
2285
2289
  _getGasFeeFlows = new WeakSet();
2286
2290
  getGasFeeFlows_fn = function() {
2287
- return [new (0, _chunkFHG5GY6Fjs.LineaGasFeeFlow)(), new (0, _chunkPF3UOCRWjs.DefaultGasFeeFlow)()];
2291
+ return [new (0, _chunkUCY5PFZIjs.LineaGasFeeFlow)(), new (0, _chunk2AYEGKANjs.DefaultGasFeeFlow)()];
2288
2292
  };
2289
2293
  _getLayer1GasFeeFlows = new WeakSet();
2290
2294
  getLayer1GasFeeFlows_fn = function() {
@@ -2347,14 +2351,14 @@ updateSimulationData_fn = async function(transactionMeta) {
2347
2351
  const { from, to, value, data } = txParams;
2348
2352
  let simulationData = {
2349
2353
  error: {
2350
- message: "Simulation disabled",
2351
- isReverted: false
2354
+ code: "disabled" /* Disabled */,
2355
+ message: "Simulation disabled"
2352
2356
  },
2353
2357
  tokenBalanceChanges: []
2354
2358
  };
2355
2359
  if (_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _isSimulationEnabled).call(this)) {
2356
2360
  _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateTransactionInternal, updateTransactionInternal_fn).call(this, { ...transactionMeta, simulationData: void 0 }, { skipHistory: true });
2357
- simulationData = await _chunkGC77BSQZjs.getSimulationData.call(void 0, {
2361
+ simulationData = await _chunkV5X6MZHNjs.getSimulationData.call(void 0, {
2358
2362
  chainId,
2359
2363
  from,
2360
2364
  to,
@@ -2385,4 +2389,4 @@ updateSimulationData_fn = async function(transactionMeta) {
2385
2389
 
2386
2390
 
2387
2391
  exports.HARDFORK = HARDFORK; exports.CANCEL_RATE = CANCEL_RATE; exports.SPEED_UP_RATE = SPEED_UP_RATE; exports.ApprovalState = ApprovalState; exports.TransactionController = TransactionController;
2388
- //# sourceMappingURL=chunk-7BG5XOXJ.js.map
2392
+ //# sourceMappingURL=chunk-NLE3SS2S.js.map