@metamask/transaction-controller 63.3.0 → 64.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/CHANGELOG.md +33 -1
  2. package/dist/TransactionController.cjs +85 -103
  3. package/dist/TransactionController.cjs.map +1 -1
  4. package/dist/TransactionController.d.cts.map +1 -1
  5. package/dist/TransactionController.d.mts.map +1 -1
  6. package/dist/TransactionController.mjs +86 -108
  7. package/dist/TransactionController.mjs.map +1 -1
  8. package/dist/gas-flows/LineaGasFeeFlow.cjs +22 -11
  9. package/dist/gas-flows/LineaGasFeeFlow.cjs.map +1 -1
  10. package/dist/gas-flows/LineaGasFeeFlow.d.cts.map +1 -1
  11. package/dist/gas-flows/LineaGasFeeFlow.d.mts.map +1 -1
  12. package/dist/gas-flows/LineaGasFeeFlow.mjs +23 -12
  13. package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -1
  14. package/dist/helpers/AccountsApiRemoteTransactionSource.cjs +2 -2
  15. package/dist/helpers/AccountsApiRemoteTransactionSource.cjs.map +1 -1
  16. package/dist/helpers/AccountsApiRemoteTransactionSource.d.cts.map +1 -1
  17. package/dist/helpers/AccountsApiRemoteTransactionSource.d.mts.map +1 -1
  18. package/dist/helpers/AccountsApiRemoteTransactionSource.mjs +1 -1
  19. package/dist/helpers/AccountsApiRemoteTransactionSource.mjs.map +1 -1
  20. package/dist/helpers/GasFeePoller.cjs +5 -19
  21. package/dist/helpers/GasFeePoller.cjs.map +1 -1
  22. package/dist/helpers/GasFeePoller.d.cts +1 -6
  23. package/dist/helpers/GasFeePoller.d.cts.map +1 -1
  24. package/dist/helpers/GasFeePoller.d.mts +1 -6
  25. package/dist/helpers/GasFeePoller.d.mts.map +1 -1
  26. package/dist/helpers/GasFeePoller.mjs +5 -26
  27. package/dist/helpers/GasFeePoller.mjs.map +1 -1
  28. package/dist/helpers/MethodDataHelper.cjs +10 -6
  29. package/dist/helpers/MethodDataHelper.cjs.map +1 -1
  30. package/dist/helpers/MethodDataHelper.d.cts +4 -4
  31. package/dist/helpers/MethodDataHelper.d.cts.map +1 -1
  32. package/dist/helpers/MethodDataHelper.d.mts +4 -4
  33. package/dist/helpers/MethodDataHelper.d.mts.map +1 -1
  34. package/dist/helpers/MethodDataHelper.mjs +10 -6
  35. package/dist/helpers/MethodDataHelper.mjs.map +1 -1
  36. package/dist/helpers/MultichainTrackingHelper.cjs +0 -2
  37. package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -1
  38. package/dist/helpers/MultichainTrackingHelper.d.cts +0 -2
  39. package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -1
  40. package/dist/helpers/MultichainTrackingHelper.d.mts +0 -2
  41. package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -1
  42. package/dist/helpers/MultichainTrackingHelper.mjs +0 -2
  43. package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -1
  44. package/dist/helpers/PendingTransactionTracker.cjs +38 -24
  45. package/dist/helpers/PendingTransactionTracker.cjs.map +1 -1
  46. package/dist/helpers/PendingTransactionTracker.d.cts +3 -7
  47. package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -1
  48. package/dist/helpers/PendingTransactionTracker.d.mts +3 -7
  49. package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -1
  50. package/dist/helpers/PendingTransactionTracker.mjs +38 -24
  51. package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
  52. package/dist/hooks/SequentialPublishBatchHook.cjs +4 -6
  53. package/dist/hooks/SequentialPublishBatchHook.cjs.map +1 -1
  54. package/dist/hooks/SequentialPublishBatchHook.d.cts +2 -4
  55. package/dist/hooks/SequentialPublishBatchHook.d.cts.map +1 -1
  56. package/dist/hooks/SequentialPublishBatchHook.d.mts +2 -4
  57. package/dist/hooks/SequentialPublishBatchHook.d.mts.map +1 -1
  58. package/dist/hooks/SequentialPublishBatchHook.mjs +4 -6
  59. package/dist/hooks/SequentialPublishBatchHook.mjs.map +1 -1
  60. package/dist/index.cjs +1 -3
  61. package/dist/index.cjs.map +1 -1
  62. package/dist/index.d.cts +0 -1
  63. package/dist/index.d.cts.map +1 -1
  64. package/dist/index.d.mts +0 -1
  65. package/dist/index.d.mts.map +1 -1
  66. package/dist/index.mjs +0 -1
  67. package/dist/index.mjs.map +1 -1
  68. package/dist/types.cjs.map +1 -1
  69. package/dist/types.d.cts +14 -3
  70. package/dist/types.d.cts.map +1 -1
  71. package/dist/types.d.mts +14 -3
  72. package/dist/types.d.mts.map +1 -1
  73. package/dist/types.mjs.map +1 -1
  74. package/dist/utils/balance-changes.cjs +2 -2
  75. package/dist/utils/balance-changes.cjs.map +1 -1
  76. package/dist/utils/balance-changes.d.cts +4 -2
  77. package/dist/utils/balance-changes.d.cts.map +1 -1
  78. package/dist/utils/balance-changes.d.mts +4 -2
  79. package/dist/utils/balance-changes.d.mts.map +1 -1
  80. package/dist/utils/balance-changes.mjs +2 -2
  81. package/dist/utils/balance-changes.mjs.map +1 -1
  82. package/dist/utils/balance.cjs +14 -10
  83. package/dist/utils/balance.cjs.map +1 -1
  84. package/dist/utils/balance.d.cts +8 -5
  85. package/dist/utils/balance.d.cts.map +1 -1
  86. package/dist/utils/balance.d.mts +8 -5
  87. package/dist/utils/balance.d.mts.map +1 -1
  88. package/dist/utils/balance.mjs +14 -10
  89. package/dist/utils/balance.mjs.map +1 -1
  90. package/dist/utils/batch.cjs +19 -19
  91. package/dist/utils/batch.cjs.map +1 -1
  92. package/dist/utils/batch.d.cts +1 -5
  93. package/dist/utils/batch.d.cts.map +1 -1
  94. package/dist/utils/batch.d.mts +1 -5
  95. package/dist/utils/batch.d.mts.map +1 -1
  96. package/dist/utils/batch.mjs +20 -20
  97. package/dist/utils/batch.mjs.map +1 -1
  98. package/dist/utils/eip7702.cjs +13 -6
  99. package/dist/utils/eip7702.cjs.map +1 -1
  100. package/dist/utils/eip7702.d.cts +6 -5
  101. package/dist/utils/eip7702.d.cts.map +1 -1
  102. package/dist/utils/eip7702.d.mts +6 -5
  103. package/dist/utils/eip7702.d.mts.map +1 -1
  104. package/dist/utils/eip7702.mjs +14 -7
  105. package/dist/utils/eip7702.mjs.map +1 -1
  106. package/dist/utils/gas-fee-tokens.cjs +4 -3
  107. package/dist/utils/gas-fee-tokens.cjs.map +1 -1
  108. package/dist/utils/gas-fee-tokens.d.cts +6 -4
  109. package/dist/utils/gas-fee-tokens.d.cts.map +1 -1
  110. package/dist/utils/gas-fee-tokens.d.mts +6 -4
  111. package/dist/utils/gas-fee-tokens.d.mts.map +1 -1
  112. package/dist/utils/gas-fee-tokens.mjs +4 -3
  113. package/dist/utils/gas-fee-tokens.mjs.map +1 -1
  114. package/dist/utils/gas-fees.cjs +8 -6
  115. package/dist/utils/gas-fees.cjs.map +1 -1
  116. package/dist/utils/gas-fees.d.cts +0 -2
  117. package/dist/utils/gas-fees.d.cts.map +1 -1
  118. package/dist/utils/gas-fees.d.mts +0 -2
  119. package/dist/utils/gas-fees.d.mts.map +1 -1
  120. package/dist/utils/gas-fees.mjs +9 -7
  121. package/dist/utils/gas-fees.mjs.map +1 -1
  122. package/dist/utils/gas.cjs +60 -34
  123. package/dist/utils/gas.cjs.map +1 -1
  124. package/dist/utils/gas.d.cts +6 -11
  125. package/dist/utils/gas.d.cts.map +1 -1
  126. package/dist/utils/gas.d.mts +6 -11
  127. package/dist/utils/gas.d.mts.map +1 -1
  128. package/dist/utils/gas.mjs +61 -35
  129. package/dist/utils/gas.mjs.map +1 -1
  130. package/dist/utils/layer1-gas-fee-flow.cjs +7 -3
  131. package/dist/utils/layer1-gas-fee-flow.cjs.map +1 -1
  132. package/dist/utils/layer1-gas-fee-flow.d.cts +2 -5
  133. package/dist/utils/layer1-gas-fee-flow.d.cts.map +1 -1
  134. package/dist/utils/layer1-gas-fee-flow.d.mts +2 -5
  135. package/dist/utils/layer1-gas-fee-flow.d.mts.map +1 -1
  136. package/dist/utils/layer1-gas-fee-flow.mjs +7 -3
  137. package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -1
  138. package/dist/utils/provider.cjs +74 -0
  139. package/dist/utils/provider.cjs.map +1 -0
  140. package/dist/utils/provider.d.cts +65 -0
  141. package/dist/utils/provider.d.cts.map +1 -0
  142. package/dist/utils/provider.d.mts +65 -0
  143. package/dist/utils/provider.d.mts.map +1 -0
  144. package/dist/utils/provider.mjs +67 -0
  145. package/dist/utils/provider.mjs.map +1 -0
  146. package/dist/utils/swaps.cjs +11 -7
  147. package/dist/utils/swaps.cjs.map +1 -1
  148. package/dist/utils/swaps.d.cts +6 -4
  149. package/dist/utils/swaps.d.cts.map +1 -1
  150. package/dist/utils/swaps.d.mts +6 -4
  151. package/dist/utils/swaps.d.mts.map +1 -1
  152. package/dist/utils/swaps.mjs +11 -7
  153. package/dist/utils/swaps.mjs.map +1 -1
  154. package/dist/utils/transaction-type.cjs +17 -8
  155. package/dist/utils/transaction-type.cjs.map +1 -1
  156. package/dist/utils/transaction-type.d.cts +9 -3
  157. package/dist/utils/transaction-type.d.cts.map +1 -1
  158. package/dist/utils/transaction-type.d.mts +9 -3
  159. package/dist/utils/transaction-type.d.mts.map +1 -1
  160. package/dist/utils/transaction-type.mjs +17 -8
  161. package/dist/utils/transaction-type.mjs.map +1 -1
  162. package/package.json +13 -13
@@ -1 +1 @@
1
- {"version":3,"file":"swaps.mjs","sourceRoot":"","sources":["../../src/utils/swaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,mCAAmC;;;AAInD,OAAO,EAAE,+BAA+B,EAAE,oBAAgB;AAC1D,OAAO,EAAE,SAAS,EAAE,yBAAqB;AACzC,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,sBAAkB;AAG9D,OAAO,EAAE,eAAe,EAAE,qBAAiB;AAE3C,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAEvD;;GAEG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAEnD;;GAEG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tB,gBAAgB;QAChB,kBAAkB;QAClB,iBAAiB;QACjB,mBAAmB;QACnB,iBAAiB;QACjB,oBAAoB;QACpB,YAAY;QACZ,cAAc;QACd,IAAI;KACL,CAAC;IACF,gCAAgC;IAChC,8DAA8D;IAC9D,eAAe,GAAG,MAAM,CAAC,eAAe,CAAQ,CAAC;IAEjD,OAAO,KAAK,CAAC,EAAE,EAAE,eAAe,EAAE,eAAe,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,6BAA6B,CACpC,eAAgC,EAChC,EAAE,IAAI,EAAE,iBAAiB,EAA4B;IAErD,+BAA+B,CAC7B,eAAe,EACf,+BAA+B,CAChC,CAAC;IAEF,gCAAgC;IAChC,8DAA8D;IAC9D,IAAI,uBAAuB,GAAG,EAAE,IAAI,EAAE,iBAAiB,EAAS,CAAC;IACjE,uBAAuB,GAAG,MAAM,CAAC;QAC/B,IAAI;QACJ,iBAAiB;KAClB,CAA6B,CAAC;IAE/B,OAAO,KAAK,CAAC,EAAE,EAAE,eAAe,EAAE,uBAAuB,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,0BAA0B,CAAC,OAAe,EAAE,OAAe;IAClE,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CACL,OAAO;QACP,+BAA+B,CAC7B,OAAuD,CACxD,EAAE,OAAO,CACX,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import { query } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport { merge, pickBy } from 'lodash';\n\nimport { validateIfTransactionUnapproved } from './utils';\nimport { CHAIN_IDS } from '../constants';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type { TransactionMeta } from '../types';\nimport { TransactionType } from '../types';\n\nconst log = createModuleLogger(projectLogger, 'swaps');\n\n/**\n * Interval in milliseconds between checks of post transaction balance\n */\nexport const UPDATE_POST_TX_BALANCE_TIMEOUT = 5000;\n\n/**\n * Retry attempts for checking post transaction balance\n */\nexport const UPDATE_POST_TX_BALANCE_ATTEMPTS = 6;\n\nconst SWAPS_TESTNET_CHAIN_ID = '0x539';\n\n/**\n * An address that the metaswap-api recognizes as the default token for the current network, in place of the token address that ERC-20 tokens have\n */\nexport const DEFAULT_TOKEN_ADDRESS =\n '0x0000000000000000000000000000000000000000';\n\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\ninterface SwapsTokenObject {\n /**\n * The name for the network\n */\n name: string;\n /**\n * An address that the metaswap-api recognizes as the default token\n */\n address: string;\n /**\n * Number of digits after decimal point\n */\n decimals: number;\n}\n\nconst ETH_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Ether',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n};\n\nconst BNB_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Binance Coin',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst MATIC_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Matic',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst AVAX_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Avalanche',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst TEST_ETH_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Test Ether',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst GOERLI_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Ether',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst ARBITRUM_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n ...ETH_SWAPS_TOKEN_OBJECT,\n} as const;\n\nconst OPTIMISM_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n ...ETH_SWAPS_TOKEN_OBJECT,\n} as const;\n\nconst ZKSYNC_ERA_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n ...ETH_SWAPS_TOKEN_OBJECT,\n} as const;\n\nconst SEI_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Sei',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst MONAD_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Mon',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst HYPEREVM_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Hyperliquid',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nexport const SWAPS_CHAINID_DEFAULT_TOKEN_MAP = {\n [CHAIN_IDS.MAINNET]: ETH_SWAPS_TOKEN_OBJECT,\n [SWAPS_TESTNET_CHAIN_ID]: TEST_ETH_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.BSC]: BNB_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.POLYGON]: MATIC_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.GOERLI]: GOERLI_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.AVALANCHE]: AVAX_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.OPTIMISM]: OPTIMISM_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.ARBITRUM]: ARBITRUM_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.ZKSYNC_ERA]: ZKSYNC_ERA_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.SEI]: SEI_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.MONAD]: MONAD_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.HYPEREVM]: HYPEREVM_SWAPS_TOKEN_OBJECT,\n} as const;\n\nexport const SWAP_TRANSACTION_TYPES = [\n TransactionType.swap,\n TransactionType.swapAndSend,\n TransactionType.swapApproval,\n];\n\n/**\n * Updates the transaction meta object with the swap information\n *\n * @param transactionMeta - The transaction meta object to update\n * @param transactionType - The type of the transaction\n * @param swaps - The swaps object\n * @param swaps.hasApproveTx - Whether the swap has an approval transaction\n * @param swaps.meta - The swap meta object\n * @param updateSwapsTransactionRequest - Dependency bag\n * @param updateSwapsTransactionRequest.isSwapsDisabled - Whether swaps are disabled\n * @param updateSwapsTransactionRequest.cancelTransaction - Function to cancel a transaction\n * @param updateSwapsTransactionRequest.messenger - TransactionController messenger\n * @returns A copy of the transaction meta object with updates, or the same\n * transaction meta object if no updates were made.\n */\nexport function updateSwapsTransaction(\n transactionMeta: TransactionMeta,\n transactionType: TransactionType,\n swaps: {\n hasApproveTx?: boolean;\n meta?: Partial<TransactionMeta>;\n },\n {\n isSwapsDisabled,\n cancelTransaction,\n messenger,\n }: {\n isSwapsDisabled: boolean;\n cancelTransaction: (transactionId: string) => void;\n messenger: TransactionControllerMessenger;\n },\n): TransactionMeta {\n if (isSwapsDisabled || !SWAP_TRANSACTION_TYPES.includes(transactionType)) {\n return transactionMeta;\n }\n\n // The simulationFails property is added if the estimateGas call fails. In cases\n // when no swaps approval tx is required, this indicates that the swap will likely\n // fail. There was an earlier estimateGas call made by the swaps controller,\n // but it is possible that external conditions have change since then, and\n // a previously succeeding estimate gas call could now fail. By checking for\n // the `simulationFails` property here, we can reduce the number of swap\n // transactions that get published to the blockchain only to fail and thereby\n // waste the user's funds on gas.\n if (\n transactionType === TransactionType.swap &&\n swaps?.hasApproveTx === false &&\n transactionMeta.simulationFails\n ) {\n cancelTransaction(transactionMeta.id);\n throw new Error('Simulation failed');\n }\n\n const swapsMeta = swaps?.meta as Partial<TransactionMeta>;\n\n if (!swapsMeta) {\n return transactionMeta;\n }\n\n let updatedTransactionMeta = transactionMeta;\n\n if (transactionType === TransactionType.swapApproval) {\n updatedTransactionMeta = updateSwapApprovalTransaction(\n transactionMeta,\n swapsMeta,\n );\n messenger.publish('TransactionController:transactionNewSwapApproval', {\n transactionMeta: updatedTransactionMeta,\n });\n }\n\n if (transactionType === TransactionType.swapAndSend) {\n updatedTransactionMeta = updateSwapAndSendTransaction(\n transactionMeta,\n swapsMeta,\n );\n messenger.publish('TransactionController:transactionNewSwapAndSend', {\n transactionMeta: updatedTransactionMeta,\n });\n }\n\n if (transactionType === TransactionType.swap) {\n updatedTransactionMeta = updateSwapTransaction(transactionMeta, swapsMeta);\n messenger.publish('TransactionController:transactionNewSwap', {\n transactionMeta: updatedTransactionMeta,\n });\n }\n\n return updatedTransactionMeta;\n}\n\n/**\n * Attempts to update the post transaction balance of the provided transaction\n *\n * @param transactionMeta - Transaction meta object to update\n * @param updatePostTransactionBalanceRequest - Dependency bag\n * @param updatePostTransactionBalanceRequest.ethQuery - EthQuery object\n * @param updatePostTransactionBalanceRequest.getTransaction - Reading function for the latest transaction state\n * @param updatePostTransactionBalanceRequest.updateTransaction - Updating transaction function\n * @returns Updated transaction metadata and approval transaction metadata if applicable.\n */\nexport async function updatePostTransactionBalance(\n transactionMeta: TransactionMeta,\n {\n ethQuery,\n getTransaction,\n updateTransaction,\n }: {\n ethQuery: EthQuery;\n getTransaction: (transactionId: string) => TransactionMeta | undefined;\n updateTransaction: (transactionMeta: TransactionMeta, note: string) => void;\n },\n): Promise<{\n updatedTransactionMeta: TransactionMeta;\n approvalTransactionMeta?: TransactionMeta;\n}> {\n log('Updating post transaction balance', transactionMeta.id);\n\n const transactionId = transactionMeta.id;\n let latestTransactionMeta: TransactionMeta | undefined;\n let approvalTransactionMeta;\n\n for (let i = 0; i < UPDATE_POST_TX_BALANCE_ATTEMPTS; i++) {\n log('Querying balance', { attempt: i });\n\n const postTransactionBalance = await query(ethQuery, 'getBalance', [\n transactionMeta.txParams.from,\n ]);\n\n latestTransactionMeta = {\n ...(getTransaction(transactionId) ?? ({} as TransactionMeta)),\n };\n\n approvalTransactionMeta = latestTransactionMeta.approvalTxId\n ? getTransaction(latestTransactionMeta.approvalTxId)\n : undefined;\n\n latestTransactionMeta.postTxBalance = postTransactionBalance.toString(16);\n\n const isDefaultTokenAddress = isSwapsDefaultTokenAddress(\n transactionMeta.destinationTokenAddress as string,\n transactionMeta.chainId,\n );\n\n if (\n !isDefaultTokenAddress ||\n transactionMeta.preTxBalance !== latestTransactionMeta.postTxBalance\n ) {\n log('Finishing post balance update', {\n isDefaultTokenAddress,\n preTxBalance: transactionMeta.preTxBalance,\n postTxBalance: latestTransactionMeta.postTxBalance,\n });\n\n break;\n }\n\n log('Waiting for balance to update', {\n delay: UPDATE_POST_TX_BALANCE_TIMEOUT,\n });\n\n await sleep(UPDATE_POST_TX_BALANCE_TIMEOUT);\n }\n\n updateTransaction(\n latestTransactionMeta as TransactionMeta,\n 'TransactionController#updatePostTransactionBalance - Add post transaction balance',\n );\n\n log('Completed post balance update', latestTransactionMeta?.postTxBalance);\n\n return {\n updatedTransactionMeta: latestTransactionMeta as TransactionMeta,\n approvalTransactionMeta,\n };\n}\n\n/**\n * Updates the transaction meta object with the swap information\n *\n * @param transactionMeta - Transaction meta object to update\n * @param propsToUpdate - Properties to update\n * @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped\n * @param propsToUpdate.destinationTokenSymbol - Symbol of the token to be received\n * @param propsToUpdate.type - Type of the transaction\n * @param propsToUpdate.destinationTokenDecimals - Decimals of the token to be received\n * @param propsToUpdate.destinationTokenAddress - Address of the token to be received\n * @param propsToUpdate.swapMetaData - Metadata of the swap\n * @param propsToUpdate.swapTokenValue - Value of the token to be swapped\n * @param propsToUpdate.estimatedBaseFee - Estimated base fee of the transaction\n * @param propsToUpdate.approvalTxId - Transaction id of the approval transaction\n * @returns The updated transaction meta object.\n */\nfunction updateSwapTransaction(\n transactionMeta: TransactionMeta,\n {\n sourceTokenSymbol,\n destinationTokenSymbol,\n type,\n destinationTokenDecimals,\n destinationTokenAddress,\n swapMetaData,\n swapTokenValue,\n estimatedBaseFee,\n approvalTxId,\n }: Partial<TransactionMeta>,\n): TransactionMeta {\n validateIfTransactionUnapproved(transactionMeta, 'updateSwapTransaction');\n\n let swapTransaction = {\n sourceTokenSymbol,\n destinationTokenSymbol,\n type,\n destinationTokenDecimals,\n destinationTokenAddress,\n swapMetaData,\n swapTokenValue,\n estimatedBaseFee,\n approvalTxId,\n };\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n swapTransaction = pickBy(swapTransaction) as any;\n\n return merge({}, transactionMeta, swapTransaction);\n}\n\n/**\n * Updates the transaction meta object with the swap information\n *\n * @param transactionMeta - Transaction meta object to update\n * @param propsToUpdate - Properties to update\n * @param propsToUpdate.approvalTxId - Transaction id of the approval transaction\n * @param propsToUpdate.destinationTokenAddress - Address of the token to be received\n * @param propsToUpdate.destinationTokenAmount - The raw amount of the destination token\n * @param propsToUpdate.destinationTokenDecimals - Decimals of the token to be received\n * @param propsToUpdate.destinationTokenSymbol - Symbol of the token to be received\n * @param propsToUpdate.estimatedBaseFee - Estimated base fee of the transaction\n * @param propsToUpdate.sourceTokenAddress - The address of the source token\n * @param propsToUpdate.sourceTokenAmount - The raw amount of the source token\n * @param propsToUpdate.sourceTokenDecimals - The decimals of the source token\n * @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped\n * @param propsToUpdate.swapAndSendRecipient - The recipient of the swap and send transaction\n * @param propsToUpdate.swapMetaData - Metadata of the swap\n * @param propsToUpdate.swapTokenValue - Value of the token to be swapped – possibly the same as sourceTokenAmount; included for consistency\n * @param propsToUpdate.type - Type of the transaction\n * @returns The updated transaction meta object.\n */\nfunction updateSwapAndSendTransaction(\n transactionMeta: TransactionMeta,\n {\n approvalTxId,\n destinationTokenAddress,\n destinationTokenAmount,\n destinationTokenDecimals,\n destinationTokenSymbol,\n estimatedBaseFee,\n sourceTokenAddress,\n sourceTokenAmount,\n sourceTokenDecimals,\n sourceTokenSymbol,\n swapAndSendRecipient,\n swapMetaData,\n swapTokenValue,\n type,\n }: Partial<TransactionMeta>,\n): TransactionMeta {\n validateIfTransactionUnapproved(transactionMeta, 'updateSwapTransaction');\n\n let swapTransaction = {\n approvalTxId,\n destinationTokenAddress,\n destinationTokenAmount,\n destinationTokenDecimals,\n destinationTokenSymbol,\n estimatedBaseFee,\n sourceTokenAddress,\n sourceTokenAmount,\n sourceTokenDecimals,\n sourceTokenSymbol,\n swapAndSendRecipient,\n swapMetaData,\n swapTokenValue,\n type,\n };\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n swapTransaction = pickBy(swapTransaction) as any;\n\n return merge({}, transactionMeta, swapTransaction);\n}\n\n/**\n * Updates the transaction meta object with the swap approval information\n *\n * @param transactionMeta - Transaction meta object to update\n * @param propsToUpdate - Properties to update\n * @param propsToUpdate.type - Type of the transaction\n * @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped\n * @returns The updated transaction meta object.\n */\nfunction updateSwapApprovalTransaction(\n transactionMeta: TransactionMeta,\n { type, sourceTokenSymbol }: Partial<TransactionMeta>,\n): TransactionMeta {\n validateIfTransactionUnapproved(\n transactionMeta,\n 'updateSwapApprovalTransaction',\n );\n\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let swapApprovalTransaction = { type, sourceTokenSymbol } as any;\n swapApprovalTransaction = pickBy({\n type,\n sourceTokenSymbol,\n }) as Partial<TransactionMeta>;\n\n return merge({}, transactionMeta, swapApprovalTransaction);\n}\n\n/**\n * Checks whether the provided address is strictly equal to the address for\n * the default swaps token of the provided chain.\n *\n * @param address - The string to compare to the default token address\n * @param chainId - The hex encoded chain ID of the default swaps token to check\n * @returns Whether the address is the provided chain's default token address\n */\nfunction isSwapsDefaultTokenAddress(address: string, chainId: string): boolean {\n if (!address || !chainId) {\n return false;\n }\n\n return (\n address ===\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP[\n chainId as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP\n ]?.address\n );\n}\n\n/**\n * Sleeps for the provided number of milliseconds\n *\n * @param ms - Number of milliseconds to sleep\n * @returns Promise that resolves after the provided number of milliseconds\n */\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"]}
1
+ {"version":3,"file":"swaps.mjs","sourceRoot":"","sources":["../../src/utils/swaps.ts"],"names":[],"mappings":";;AAGA,OAAO,EAAE,UAAU,EAAE,uBAAmB;AACxC,OAAO,EAAE,+BAA+B,EAAE,oBAAgB;AAC1D,OAAO,EAAE,SAAS,EAAE,yBAAqB;AACzC,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,sBAAkB;AAG9D,OAAO,EAAE,eAAe,EAAE,qBAAiB;AAE3C,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAEvD;;GAEG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,CAAC;AAEjD,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAEvC;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAChC,4CAA4C,CAAC;AAmB/C,MAAM,sBAAsB,GAAqB;IAC/C,IAAI,EAAE,OAAO;IACb,OAAO,EAAE,qBAAqB;IAC9B,QAAQ,EAAE,EAAE;CACb,CAAC;AAEF,MAAM,sBAAsB,GAAqB;IAC/C,IAAI,EAAE,cAAc;IACpB,OAAO,EAAE,qBAAqB;IAC9B,QAAQ,EAAE,EAAE;CACJ,CAAC;AAEX,MAAM,wBAAwB,GAAqB;IACjD,IAAI,EAAE,OAAO;IACb,OAAO,EAAE,qBAAqB;IAC9B,QAAQ,EAAE,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,gCAAgC;IAChC,8DAA8D;IAC9D,IAAI,uBAAuB,GAAG,EAAE,IAAI,EAAE,iBAAiB,EAAS,CAAC;IACjE,uBAAuB,GAAG,MAAM,CAAC;QAC/B,IAAI;QACJ,iBAAiB;KAClB,CAA6B,CAAC;IAE/B,OAAO,KAAK,CAAC,EAAE,EAAE,eAAe,EAAE,uBAAuB,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,0BAA0B,CAAC,OAAe,EAAE,OAAe;IAClE,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CACL,OAAO;QACP,+BAA+B,CAC7B,OAAuD,CACxD,EAAE,OAAO,CACX,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import type { NetworkClientId } from '@metamask/network-controller';\nimport { merge, pickBy } from 'lodash';\n\nimport { rpcRequest } from './provider';\nimport { validateIfTransactionUnapproved } from './utils';\nimport { CHAIN_IDS } from '../constants';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type { TransactionMeta } from '../types';\nimport { TransactionType } from '../types';\n\nconst log = createModuleLogger(projectLogger, 'swaps');\n\n/**\n * Interval in milliseconds between checks of post transaction balance\n */\nexport const UPDATE_POST_TX_BALANCE_TIMEOUT = 5000;\n\n/**\n * Retry attempts for checking post transaction balance\n */\nexport const UPDATE_POST_TX_BALANCE_ATTEMPTS = 6;\n\nconst SWAPS_TESTNET_CHAIN_ID = '0x539';\n\n/**\n * An address that the metaswap-api recognizes as the default token for the current network, in place of the token address that ERC-20 tokens have\n */\nexport const DEFAULT_TOKEN_ADDRESS =\n '0x0000000000000000000000000000000000000000';\n\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\ninterface SwapsTokenObject {\n /**\n * The name for the network\n */\n name: string;\n /**\n * An address that the metaswap-api recognizes as the default token\n */\n address: string;\n /**\n * Number of digits after decimal point\n */\n decimals: number;\n}\n\nconst ETH_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Ether',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n};\n\nconst BNB_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Binance Coin',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst MATIC_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Matic',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst AVAX_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Avalanche',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst TEST_ETH_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Test Ether',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst GOERLI_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Ether',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst ARBITRUM_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n ...ETH_SWAPS_TOKEN_OBJECT,\n} as const;\n\nconst OPTIMISM_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n ...ETH_SWAPS_TOKEN_OBJECT,\n} as const;\n\nconst ZKSYNC_ERA_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n ...ETH_SWAPS_TOKEN_OBJECT,\n} as const;\n\nconst SEI_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Sei',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst MONAD_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Mon',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst HYPEREVM_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Hyperliquid',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nexport const SWAPS_CHAINID_DEFAULT_TOKEN_MAP = {\n [CHAIN_IDS.MAINNET]: ETH_SWAPS_TOKEN_OBJECT,\n [SWAPS_TESTNET_CHAIN_ID]: TEST_ETH_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.BSC]: BNB_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.POLYGON]: MATIC_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.GOERLI]: GOERLI_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.AVALANCHE]: AVAX_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.OPTIMISM]: OPTIMISM_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.ARBITRUM]: ARBITRUM_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.ZKSYNC_ERA]: ZKSYNC_ERA_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.SEI]: SEI_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.MONAD]: MONAD_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.HYPEREVM]: HYPEREVM_SWAPS_TOKEN_OBJECT,\n} as const;\n\nexport const SWAP_TRANSACTION_TYPES = [\n TransactionType.swap,\n TransactionType.swapAndSend,\n TransactionType.swapApproval,\n];\n\n/**\n * Updates the transaction meta object with the swap information\n *\n * @param transactionMeta - The transaction meta object to update\n * @param transactionType - The type of the transaction\n * @param swaps - The swaps object\n * @param swaps.hasApproveTx - Whether the swap has an approval transaction\n * @param swaps.meta - The swap meta object\n * @param updateSwapsTransactionRequest - Dependency bag\n * @param updateSwapsTransactionRequest.isSwapsDisabled - Whether swaps are disabled\n * @param updateSwapsTransactionRequest.cancelTransaction - Function to cancel a transaction\n * @param updateSwapsTransactionRequest.messenger - TransactionController messenger\n * @returns A copy of the transaction meta object with updates, or the same\n * transaction meta object if no updates were made.\n */\nexport function updateSwapsTransaction(\n transactionMeta: TransactionMeta,\n transactionType: TransactionType,\n swaps: {\n hasApproveTx?: boolean;\n meta?: Partial<TransactionMeta>;\n },\n {\n isSwapsDisabled,\n cancelTransaction,\n messenger,\n }: {\n isSwapsDisabled: boolean;\n cancelTransaction: (transactionId: string) => void;\n messenger: TransactionControllerMessenger;\n },\n): TransactionMeta {\n if (isSwapsDisabled || !SWAP_TRANSACTION_TYPES.includes(transactionType)) {\n return transactionMeta;\n }\n\n // The simulationFails property is added if the estimateGas call fails. In cases\n // when no swaps approval tx is required, this indicates that the swap will likely\n // fail. There was an earlier estimateGas call made by the swaps controller,\n // but it is possible that external conditions have change since then, and\n // a previously succeeding estimate gas call could now fail. By checking for\n // the `simulationFails` property here, we can reduce the number of swap\n // transactions that get published to the blockchain only to fail and thereby\n // waste the user's funds on gas.\n if (\n transactionType === TransactionType.swap &&\n swaps?.hasApproveTx === false &&\n transactionMeta.simulationFails\n ) {\n cancelTransaction(transactionMeta.id);\n throw new Error('Simulation failed');\n }\n\n const swapsMeta = swaps?.meta as Partial<TransactionMeta>;\n\n if (!swapsMeta) {\n return transactionMeta;\n }\n\n let updatedTransactionMeta = transactionMeta;\n\n if (transactionType === TransactionType.swapApproval) {\n updatedTransactionMeta = updateSwapApprovalTransaction(\n transactionMeta,\n swapsMeta,\n );\n messenger.publish('TransactionController:transactionNewSwapApproval', {\n transactionMeta: updatedTransactionMeta,\n });\n }\n\n if (transactionType === TransactionType.swapAndSend) {\n updatedTransactionMeta = updateSwapAndSendTransaction(\n transactionMeta,\n swapsMeta,\n );\n messenger.publish('TransactionController:transactionNewSwapAndSend', {\n transactionMeta: updatedTransactionMeta,\n });\n }\n\n if (transactionType === TransactionType.swap) {\n updatedTransactionMeta = updateSwapTransaction(transactionMeta, swapsMeta);\n messenger.publish('TransactionController:transactionNewSwap', {\n transactionMeta: updatedTransactionMeta,\n });\n }\n\n return updatedTransactionMeta;\n}\n\n/**\n * Attempts to update the post transaction balance of the provided transaction\n *\n * @param transactionMeta - Transaction meta object to update\n * @param updatePostTransactionBalanceRequest - Dependency bag\n * @param updatePostTransactionBalanceRequest.messenger - The TransactionController messenger\n * @param updatePostTransactionBalanceRequest.networkClientId - The network client ID\n * @param updatePostTransactionBalanceRequest.getTransaction - Reading function for the latest transaction state\n * @param updatePostTransactionBalanceRequest.updateTransaction - Updating transaction function\n * @returns Updated transaction metadata and approval transaction metadata if applicable.\n */\nexport async function updatePostTransactionBalance(\n transactionMeta: TransactionMeta,\n {\n messenger,\n networkClientId,\n getTransaction,\n updateTransaction,\n }: {\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n getTransaction: (transactionId: string) => TransactionMeta | undefined;\n updateTransaction: (transactionMeta: TransactionMeta, note: string) => void;\n },\n): Promise<{\n updatedTransactionMeta: TransactionMeta;\n approvalTransactionMeta?: TransactionMeta;\n}> {\n log('Updating post transaction balance', transactionMeta.id);\n\n const transactionId = transactionMeta.id;\n let latestTransactionMeta: TransactionMeta | undefined;\n let approvalTransactionMeta;\n\n for (let i = 0; i < UPDATE_POST_TX_BALANCE_ATTEMPTS; i++) {\n log('Querying balance', { attempt: i });\n\n const postTransactionBalance = (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_getBalance',\n params: [transactionMeta.txParams.from, 'latest'],\n })) as string;\n\n latestTransactionMeta = {\n ...(getTransaction(transactionId) ?? ({} as TransactionMeta)),\n };\n\n approvalTransactionMeta = latestTransactionMeta.approvalTxId\n ? getTransaction(latestTransactionMeta.approvalTxId)\n : undefined;\n\n latestTransactionMeta.postTxBalance = postTransactionBalance;\n\n const isDefaultTokenAddress = isSwapsDefaultTokenAddress(\n transactionMeta.destinationTokenAddress as string,\n transactionMeta.chainId,\n );\n\n if (\n !isDefaultTokenAddress ||\n transactionMeta.preTxBalance !== latestTransactionMeta.postTxBalance\n ) {\n log('Finishing post balance update', {\n isDefaultTokenAddress,\n preTxBalance: transactionMeta.preTxBalance,\n postTxBalance: latestTransactionMeta.postTxBalance,\n });\n\n break;\n }\n\n log('Waiting for balance to update', {\n delay: UPDATE_POST_TX_BALANCE_TIMEOUT,\n });\n\n await sleep(UPDATE_POST_TX_BALANCE_TIMEOUT);\n }\n\n updateTransaction(\n latestTransactionMeta as TransactionMeta,\n 'TransactionController#updatePostTransactionBalance - Add post transaction balance',\n );\n\n log('Completed post balance update', latestTransactionMeta?.postTxBalance);\n\n return {\n updatedTransactionMeta: latestTransactionMeta as TransactionMeta,\n approvalTransactionMeta,\n };\n}\n\n/**\n * Updates the transaction meta object with the swap information\n *\n * @param transactionMeta - Transaction meta object to update\n * @param propsToUpdate - Properties to update\n * @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped\n * @param propsToUpdate.destinationTokenSymbol - Symbol of the token to be received\n * @param propsToUpdate.type - Type of the transaction\n * @param propsToUpdate.destinationTokenDecimals - Decimals of the token to be received\n * @param propsToUpdate.destinationTokenAddress - Address of the token to be received\n * @param propsToUpdate.swapMetaData - Metadata of the swap\n * @param propsToUpdate.swapTokenValue - Value of the token to be swapped\n * @param propsToUpdate.estimatedBaseFee - Estimated base fee of the transaction\n * @param propsToUpdate.approvalTxId - Transaction id of the approval transaction\n * @returns The updated transaction meta object.\n */\nfunction updateSwapTransaction(\n transactionMeta: TransactionMeta,\n {\n sourceTokenSymbol,\n destinationTokenSymbol,\n type,\n destinationTokenDecimals,\n destinationTokenAddress,\n swapMetaData,\n swapTokenValue,\n estimatedBaseFee,\n approvalTxId,\n }: Partial<TransactionMeta>,\n): TransactionMeta {\n validateIfTransactionUnapproved(transactionMeta, 'updateSwapTransaction');\n\n let swapTransaction = {\n sourceTokenSymbol,\n destinationTokenSymbol,\n type,\n destinationTokenDecimals,\n destinationTokenAddress,\n swapMetaData,\n swapTokenValue,\n estimatedBaseFee,\n approvalTxId,\n };\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n swapTransaction = pickBy(swapTransaction) as any;\n\n return merge({}, transactionMeta, swapTransaction);\n}\n\n/**\n * Updates the transaction meta object with the swap information\n *\n * @param transactionMeta - Transaction meta object to update\n * @param propsToUpdate - Properties to update\n * @param propsToUpdate.approvalTxId - Transaction id of the approval transaction\n * @param propsToUpdate.destinationTokenAddress - Address of the token to be received\n * @param propsToUpdate.destinationTokenAmount - The raw amount of the destination token\n * @param propsToUpdate.destinationTokenDecimals - Decimals of the token to be received\n * @param propsToUpdate.destinationTokenSymbol - Symbol of the token to be received\n * @param propsToUpdate.estimatedBaseFee - Estimated base fee of the transaction\n * @param propsToUpdate.sourceTokenAddress - The address of the source token\n * @param propsToUpdate.sourceTokenAmount - The raw amount of the source token\n * @param propsToUpdate.sourceTokenDecimals - The decimals of the source token\n * @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped\n * @param propsToUpdate.swapAndSendRecipient - The recipient of the swap and send transaction\n * @param propsToUpdate.swapMetaData - Metadata of the swap\n * @param propsToUpdate.swapTokenValue - Value of the token to be swapped – possibly the same as sourceTokenAmount; included for consistency\n * @param propsToUpdate.type - Type of the transaction\n * @returns The updated transaction meta object.\n */\nfunction updateSwapAndSendTransaction(\n transactionMeta: TransactionMeta,\n {\n approvalTxId,\n destinationTokenAddress,\n destinationTokenAmount,\n destinationTokenDecimals,\n destinationTokenSymbol,\n estimatedBaseFee,\n sourceTokenAddress,\n sourceTokenAmount,\n sourceTokenDecimals,\n sourceTokenSymbol,\n swapAndSendRecipient,\n swapMetaData,\n swapTokenValue,\n type,\n }: Partial<TransactionMeta>,\n): TransactionMeta {\n validateIfTransactionUnapproved(transactionMeta, 'updateSwapTransaction');\n\n let swapTransaction = {\n approvalTxId,\n destinationTokenAddress,\n destinationTokenAmount,\n destinationTokenDecimals,\n destinationTokenSymbol,\n estimatedBaseFee,\n sourceTokenAddress,\n sourceTokenAmount,\n sourceTokenDecimals,\n sourceTokenSymbol,\n swapAndSendRecipient,\n swapMetaData,\n swapTokenValue,\n type,\n };\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n swapTransaction = pickBy(swapTransaction) as any;\n\n return merge({}, transactionMeta, swapTransaction);\n}\n\n/**\n * Updates the transaction meta object with the swap approval information\n *\n * @param transactionMeta - Transaction meta object to update\n * @param propsToUpdate - Properties to update\n * @param propsToUpdate.type - Type of the transaction\n * @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped\n * @returns The updated transaction meta object.\n */\nfunction updateSwapApprovalTransaction(\n transactionMeta: TransactionMeta,\n { type, sourceTokenSymbol }: Partial<TransactionMeta>,\n): TransactionMeta {\n validateIfTransactionUnapproved(\n transactionMeta,\n 'updateSwapApprovalTransaction',\n );\n\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let swapApprovalTransaction = { type, sourceTokenSymbol } as any;\n swapApprovalTransaction = pickBy({\n type,\n sourceTokenSymbol,\n }) as Partial<TransactionMeta>;\n\n return merge({}, transactionMeta, swapApprovalTransaction);\n}\n\n/**\n * Checks whether the provided address is strictly equal to the address for\n * the default swaps token of the provided chain.\n *\n * @param address - The string to compare to the default token address\n * @param chainId - The hex encoded chain ID of the default swaps token to check\n * @returns Whether the address is the provided chain's default token address\n */\nfunction isSwapsDefaultTokenAddress(address: string, chainId: string): boolean {\n if (!address || !chainId) {\n return false;\n }\n\n return (\n address ===\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP[\n chainId as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP\n ]?.address\n );\n}\n\n/**\n * Sleeps for the provided number of milliseconds\n *\n * @param ms - Number of milliseconds to sleep\n * @returns Promise that resolves after the provided number of milliseconds\n */\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"]}
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.decodeTransactionData = exports.determineTransactionType = exports.ESTIMATE_GAS_ERROR = void 0;
4
4
  const abi_1 = require("@ethersproject/abi");
5
- const controller_utils_1 = require("@metamask/controller-utils");
6
5
  const metamask_eth_abis_1 = require("@metamask/metamask-eth-abis");
7
6
  const eip7702_1 = require("./eip7702.cjs");
7
+ const provider_1 = require("./provider.cjs");
8
8
  const types_1 = require("../types.cjs");
9
9
  exports.ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';
10
10
  const ERC20Interface = new abi_1.Interface(metamask_eth_abis_1.abiERC20);
@@ -17,18 +17,21 @@ const USDCInterface = new abi_1.Interface(metamask_eth_abis_1.abiFiatTokenV2);
17
17
  * represent specific events that we specify manually at transaction creation.
18
18
  *
19
19
  * @param txParams - Parameters for the transaction.
20
- * @param ethQuery - EthQuery instance.
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.
21
23
  * @returns A object with the transaction type and the contract code response in Hex.
22
24
  */
23
- async function determineTransactionType(txParams, ethQuery) {
25
+ async function determineTransactionType(txParams, options) {
24
26
  const { data, to } = txParams;
25
27
  if (data && !to) {
26
28
  return { type: types_1.TransactionType.deployContract, getCodeResponse: undefined };
27
29
  }
28
30
  let getCodeResponse;
29
31
  let isContractAddress = Boolean(data?.length);
30
- if (ethQuery) {
31
- const response = await readAddressAsContract(ethQuery, to);
32
+ if (options) {
33
+ const { messenger, networkClientId } = options;
34
+ const response = await readAddressAsContract(messenger, networkClientId, to);
32
35
  getCodeResponse = response.contractCode;
33
36
  isContractAddress = response.isContractAddress;
34
37
  }
@@ -109,14 +112,20 @@ function getMethodName(data) {
109
112
  /**
110
113
  * Reads an Ethereum address and determines if it is a contract address.
111
114
  *
112
- * @param ethQuery - The Ethereum query object used to interact with the Ethereum blockchain.
115
+ * @param messenger - The TransactionController messenger.
116
+ * @param networkClientId - The network client ID to use.
113
117
  * @param address - The Ethereum address.
114
118
  * @returns An object containing the contract code and a boolean indicating if it is a contract address.
115
119
  */
116
- async function readAddressAsContract(ethQuery, address) {
120
+ async function readAddressAsContract(messenger, networkClientId, address) {
117
121
  let contractCode;
118
122
  try {
119
- contractCode = await (0, controller_utils_1.query)(ethQuery, 'getCode', [address]);
123
+ contractCode = (await (0, provider_1.rpcRequest)({
124
+ messenger,
125
+ networkClientId,
126
+ method: 'eth_getCode',
127
+ params: [address, 'latest'],
128
+ }));
120
129
  // Not used
121
130
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
122
131
  }
@@ -1 +1 @@
1
- {"version":3,"file":"transaction-type.cjs","sourceRoot":"","sources":["../../src/utils/transaction-type.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAE/C,iEAAmD;AAEnD,mEAKqC;AAErC,2CAA8C;AAE9C,wCAA2C;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;;;;;;;;GAQG;AACI,KAAK,UAAU,wBAAwB,CAC5C,QAA2B,EAC3B,QAAmB;IAEnB,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,QAAQ,CAAC;IAE9B,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;QAChB,OAAO,EAAE,IAAI,EAAE,uBAAe,CAAC,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;IAC9E,CAAC;IAED,IAAI,eAAe,CAAC;IACpB,IAAI,iBAAiB,GAAG,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAE9C,IAAI,QAA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BAAiB,CAAC;QAC7C,CAAC,CAAC,KAAK,CAAC;IACV,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport type { TransactionDescription } 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 { DELEGATION_PREFIX } from './eip7702';\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 let getCodeResponse;\n let isContractAddress = Boolean(data?.length);\n\n if (ethQuery) {\n const response = await readAddressAsContract(ethQuery, to);\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 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 // 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"]}
1
+ {"version":3,"file":"transaction-type.cjs","sourceRoot":"","sources":["../../src/utils/transaction-type.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAE/C,mEAKqC;AAGrC,2CAA8C;AAC9C,6CAAwC;AAGxC,wCAA2C;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,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;QAChB,OAAO,EAAE,IAAI,EAAE,uBAAe,CAAC,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;IAC9E,CAAC;IAED,IAAI,eAAe,CAAC;IACpB,IAAI,iBAAiB,GAAG,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAE9C,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;QAC/C,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAC1C,SAAS,EACT,eAAe,EACf,EAAE,CACH,CAAC;QAEF,eAAe,GAAG,QAAQ,CAAC,YAAY,CAAC;QAC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,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAC7C,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 { DELEGATION_PREFIX } from './eip7702';\nimport { rpcRequest } from './provider';\nimport type { TransactionControllerMessenger } from '../TransactionController';\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 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 if (data && !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"]}
@@ -1,5 +1,6 @@
1
1
  import type { TransactionDescription } from "@ethersproject/abi";
2
- import type EthQuery from "@metamask/eth-query";
2
+ import type { NetworkClientId } from "@metamask/network-controller";
3
+ import type { TransactionControllerMessenger } from "../TransactionController.cjs";
3
4
  import type { InferTransactionTypeResult, TransactionParams } from "../types.cjs";
4
5
  export declare const ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
5
6
  /**
@@ -8,10 +9,15 @@ export declare const ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
8
9
  * represent specific events that we specify manually at transaction creation.
9
10
  *
10
11
  * @param txParams - Parameters for the transaction.
11
- * @param ethQuery - EthQuery instance.
12
+ * @param options - Optional messenger and network client ID to query the network.
13
+ * @param options.messenger - The TransactionController messenger.
14
+ * @param options.networkClientId - The network client ID to use.
12
15
  * @returns A object with the transaction type and the contract code response in Hex.
13
16
  */
14
- export declare function determineTransactionType(txParams: TransactionParams, ethQuery?: EthQuery): Promise<InferTransactionTypeResult>;
17
+ export declare function determineTransactionType(txParams: TransactionParams, options?: {
18
+ messenger: TransactionControllerMessenger;
19
+ networkClientId: NetworkClientId;
20
+ }): Promise<InferTransactionTypeResult>;
15
21
  /**
16
22
  * Parses transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155 and USDC.
17
23
  * The data will decode correctly if the transaction is an interaction with a contract that matches one of these
@@ -1 +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;AAEjE,OAAO,KAAK,QAAQ,4BAA4B;AAShD,OAAO,KAAK,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,qBAAiB;AAG9E,eAAO,MAAM,kBAAkB,qCAAqC,CAAC;AAOrE;;;;;;;;GAQG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,CAAC,EAAE,QAAQ,GAClB,OAAO,CAAC,0BAA0B,CAAC,CAoDrC;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"}
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;AAIpE,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,qBAAiB;AAG9E,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,CAyDrC;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"}
@@ -1,5 +1,6 @@
1
1
  import type { TransactionDescription } from "@ethersproject/abi";
2
- import type EthQuery from "@metamask/eth-query";
2
+ import type { NetworkClientId } from "@metamask/network-controller";
3
+ import type { TransactionControllerMessenger } from "../TransactionController.mjs";
3
4
  import type { InferTransactionTypeResult, TransactionParams } from "../types.mjs";
4
5
  export declare const ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
5
6
  /**
@@ -8,10 +9,15 @@ export declare const ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
8
9
  * represent specific events that we specify manually at transaction creation.
9
10
  *
10
11
  * @param txParams - Parameters for the transaction.
11
- * @param ethQuery - EthQuery instance.
12
+ * @param options - Optional messenger and network client ID to query the network.
13
+ * @param options.messenger - The TransactionController messenger.
14
+ * @param options.networkClientId - The network client ID to use.
12
15
  * @returns A object with the transaction type and the contract code response in Hex.
13
16
  */
14
- export declare function determineTransactionType(txParams: TransactionParams, ethQuery?: EthQuery): Promise<InferTransactionTypeResult>;
17
+ export declare function determineTransactionType(txParams: TransactionParams, options?: {
18
+ messenger: TransactionControllerMessenger;
19
+ networkClientId: NetworkClientId;
20
+ }): Promise<InferTransactionTypeResult>;
15
21
  /**
16
22
  * Parses transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155 and USDC.
17
23
  * The data will decode correctly if the transaction is an interaction with a contract that matches one of these
@@ -1 +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;AAEjE,OAAO,KAAK,QAAQ,4BAA4B;AAShD,OAAO,KAAK,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,qBAAiB;AAG9E,eAAO,MAAM,kBAAkB,qCAAqC,CAAC;AAOrE;;;;;;;;GAQG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,CAAC,EAAE,QAAQ,GAClB,OAAO,CAAC,0BAA0B,CAAC,CAoDrC;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"}
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;AAIpE,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,qBAAiB;AAG9E,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,CAyDrC;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"}
@@ -1,7 +1,7 @@
1
1
  import { Interface } from "@ethersproject/abi";
2
- import { query } from "@metamask/controller-utils";
3
2
  import { abiERC721, abiERC20, abiERC1155, abiFiatTokenV2 } from "@metamask/metamask-eth-abis";
4
3
  import { DELEGATION_PREFIX } from "./eip7702.mjs";
4
+ import { rpcRequest } from "./provider.mjs";
5
5
  import { TransactionType } from "../types.mjs";
6
6
  export const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';
7
7
  const ERC20Interface = new Interface(abiERC20);
@@ -14,18 +14,21 @@ const USDCInterface = new Interface(abiFiatTokenV2);
14
14
  * represent specific events that we specify manually at transaction creation.
15
15
  *
16
16
  * @param txParams - Parameters for the transaction.
17
- * @param ethQuery - EthQuery instance.
17
+ * @param options - Optional messenger and network client ID to query the network.
18
+ * @param options.messenger - The TransactionController messenger.
19
+ * @param options.networkClientId - The network client ID to use.
18
20
  * @returns A object with the transaction type and the contract code response in Hex.
19
21
  */
20
- export async function determineTransactionType(txParams, ethQuery) {
22
+ export async function determineTransactionType(txParams, options) {
21
23
  const { data, to } = txParams;
22
24
  if (data && !to) {
23
25
  return { type: TransactionType.deployContract, getCodeResponse: undefined };
24
26
  }
25
27
  let getCodeResponse;
26
28
  let isContractAddress = Boolean(data?.length);
27
- if (ethQuery) {
28
- const response = await readAddressAsContract(ethQuery, to);
29
+ if (options) {
30
+ const { messenger, networkClientId } = options;
31
+ const response = await readAddressAsContract(messenger, networkClientId, to);
29
32
  getCodeResponse = response.contractCode;
30
33
  isContractAddress = response.isContractAddress;
31
34
  }
@@ -104,14 +107,20 @@ function getMethodName(data) {
104
107
  /**
105
108
  * Reads an Ethereum address and determines if it is a contract address.
106
109
  *
107
- * @param ethQuery - The Ethereum query object used to interact with the Ethereum blockchain.
110
+ * @param messenger - The TransactionController messenger.
111
+ * @param networkClientId - The network client ID to use.
108
112
  * @param address - The Ethereum address.
109
113
  * @returns An object containing the contract code and a boolean indicating if it is a contract address.
110
114
  */
111
- async function readAddressAsContract(ethQuery, address) {
115
+ async function readAddressAsContract(messenger, networkClientId, address) {
112
116
  let contractCode;
113
117
  try {
114
- contractCode = await query(ethQuery, 'getCode', [address]);
118
+ contractCode = (await rpcRequest({
119
+ messenger,
120
+ networkClientId,
121
+ method: 'eth_getCode',
122
+ params: [address, 'latest'],
123
+ }));
115
124
  // Not used
116
125
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
117
126
  }
@@ -1 +1 @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,KAAK,IAAI;QAClB,cAAc;QACd,eAAe;QACf,gBAAgB;QAChB,aAAa;KACd,EAAE,CAAC;QACF,IAAI,CAAC;YACH,IAAI,OAAO,EAAE,aAAa,EAAE,CAAC;gBAC3B,OAAO,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC;YAC3C,CAAC;YACD,OAAO,KAAK,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1C,CAAC;QAAC,MAAM,CAAC;YACP,sBAAsB;QACxB,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,IAAa;IAClC,OAAO,qBAAqB,CAAC,IAAc,EAAE;QAC3C,aAAa,EAAE,IAAI;KACpB,CAAuB,CAAC;AAC3B,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,qBAAqB,CAClC,QAAkB,EAClB,OAAgB;IAKhB,IAAI,YAAY,CAAC;IACjB,IAAI,CAAC;QACH,YAAY,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;QAC3D,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","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport type { TransactionDescription } 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 { DELEGATION_PREFIX } from './eip7702';\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 let getCodeResponse;\n let isContractAddress = Boolean(data?.length);\n\n if (ethQuery) {\n const response = await readAddressAsContract(ethQuery, to);\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 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 // 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"]}
1
+ {"version":3,"file":"transaction-type.mjs","sourceRoot":"","sources":["../../src/utils/transaction-type.ts"],"names":[],"mappings":"A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;QAClB,cAAc;QACd,eAAe;QACf,gBAAgB;QAChB,aAAa;KACd,EAAE,CAAC;QACF,IAAI,CAAC;YACH,IAAI,OAAO,EAAE,aAAa,EAAE,CAAC;gBAC3B,OAAO,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC;YAC3C,CAAC;YACD,OAAO,KAAK,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1C,CAAC;QAAC,MAAM,CAAC;YACP,sBAAsB;QACxB,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,IAAa;IAClC,OAAO,qBAAqB,CAAC,IAAc,EAAE;QAC3C,aAAa,EAAE,IAAI;KACpB,CAAuB,CAAC;AAC3B,CAAC;AAED;;;;;;;GAOG;AACH,KAAK,UAAU,qBAAqB,CAClC,SAAyC,EACzC,eAAgC,EAChC,OAAgB;IAKhB,IAAI,YAAY,CAAC;IACjB,IAAI,CAAC;QACH,YAAY,GAAG,CAAC,MAAM,UAAU,CAAC;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","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 { DELEGATION_PREFIX } from './eip7702';\nimport { rpcRequest } from './provider';\nimport type { TransactionControllerMessenger } from '../TransactionController';\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 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 if (data && !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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/transaction-controller",
3
- "version": "63.3.0",
3
+ "version": "64.0.0",
4
4
  "description": "Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -40,7 +40,7 @@
40
40
  "build:docs": "typedoc",
41
41
  "changelog:update": "../../scripts/update-changelog.sh @metamask/transaction-controller",
42
42
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/transaction-controller",
43
- "generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
43
+ "generate-method-action-types": "tsx ../../packages/messenger/src/generate-action-types/cli.ts",
44
44
  "since-latest-release": "../../scripts/since-latest-release.sh",
45
45
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
46
46
  "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
@@ -55,18 +55,17 @@
55
55
  "@ethersproject/contracts": "^5.7.0",
56
56
  "@ethersproject/providers": "^5.7.0",
57
57
  "@ethersproject/wallet": "^5.7.0",
58
- "@metamask/accounts-controller": "^37.0.0",
59
- "@metamask/approval-controller": "^9.0.0",
60
- "@metamask/base-controller": "^9.0.0",
61
- "@metamask/controller-utils": "^11.19.0",
62
- "@metamask/core-backend": "^6.2.0",
63
- "@metamask/eth-query": "^4.0.0",
64
- "@metamask/gas-fee-controller": "^26.1.0",
65
- "@metamask/messenger": "^0.3.0",
58
+ "@metamask/accounts-controller": "^37.1.1",
59
+ "@metamask/approval-controller": "^9.0.1",
60
+ "@metamask/base-controller": "^9.0.1",
61
+ "@metamask/controller-utils": "^11.20.0",
62
+ "@metamask/core-backend": "^6.2.1",
63
+ "@metamask/gas-fee-controller": "^26.1.1",
64
+ "@metamask/messenger": "^1.0.0",
66
65
  "@metamask/metamask-eth-abis": "^3.1.1",
67
- "@metamask/network-controller": "^30.0.0",
66
+ "@metamask/network-controller": "^30.0.1",
68
67
  "@metamask/nonce-tracker": "^6.0.0",
69
- "@metamask/remote-feature-flag-controller": "^4.1.0",
68
+ "@metamask/remote-feature-flag-controller": "^4.2.0",
70
69
  "@metamask/rpc-errors": "^7.0.2",
71
70
  "@metamask/utils": "^11.9.0",
72
71
  "async-mutex": "^0.5.0",
@@ -80,8 +79,9 @@
80
79
  "devDependencies": {
81
80
  "@babel/runtime": "^7.23.9",
82
81
  "@metamask/auto-changelog": "^3.4.4",
82
+ "@metamask/connectivity-controller": "^0.2.0",
83
83
  "@metamask/eth-block-tracker": "^15.0.0",
84
- "@metamask/eth-json-rpc-provider": "^6.0.0",
84
+ "@metamask/eth-json-rpc-provider": "^6.0.1",
85
85
  "@metamask/ethjs-provider-http": "^0.3.0",
86
86
  "@ts-bridge/cli": "^0.6.4",
87
87
  "@types/bn.js": "^5.1.5",