@metamask/transaction-controller 57.0.0 → 57.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/dist/TransactionController.cjs +18 -55
  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 +21 -58
  7. package/dist/TransactionController.mjs.map +1 -1
  8. package/dist/api/simulation-api.cjs.map +1 -1
  9. package/dist/api/simulation-api.d.cts +22 -5
  10. package/dist/api/simulation-api.d.cts.map +1 -1
  11. package/dist/api/simulation-api.d.mts +22 -5
  12. package/dist/api/simulation-api.d.mts.map +1 -1
  13. package/dist/api/simulation-api.mjs.map +1 -1
  14. package/dist/hooks/ExtraTransactionsPublishHook.cjs +3 -1
  15. package/dist/hooks/ExtraTransactionsPublishHook.cjs.map +1 -1
  16. package/dist/hooks/ExtraTransactionsPublishHook.d.cts.map +1 -1
  17. package/dist/hooks/ExtraTransactionsPublishHook.d.mts.map +1 -1
  18. package/dist/hooks/ExtraTransactionsPublishHook.mjs +3 -1
  19. package/dist/hooks/ExtraTransactionsPublishHook.mjs.map +1 -1
  20. package/dist/types.cjs.map +1 -1
  21. package/dist/types.d.cts +23 -4
  22. package/dist/types.d.cts.map +1 -1
  23. package/dist/types.d.mts +23 -4
  24. package/dist/types.d.mts.map +1 -1
  25. package/dist/types.mjs.map +1 -1
  26. package/dist/utils/{simulation.cjs → balance-changes.cjs} +103 -112
  27. package/dist/utils/balance-changes.cjs.map +1 -0
  28. package/dist/utils/balance-changes.d.cts +30 -0
  29. package/dist/utils/balance-changes.d.cts.map +1 -0
  30. package/dist/utils/balance-changes.d.mts +30 -0
  31. package/dist/utils/balance-changes.d.mts.map +1 -0
  32. package/dist/utils/{simulation.mjs → balance-changes.mjs} +107 -111
  33. package/dist/utils/balance-changes.mjs.map +1 -0
  34. package/dist/utils/batch.cjs +77 -35
  35. package/dist/utils/batch.cjs.map +1 -1
  36. package/dist/utils/batch.d.cts +1 -0
  37. package/dist/utils/batch.d.cts.map +1 -1
  38. package/dist/utils/batch.d.mts +1 -0
  39. package/dist/utils/batch.d.mts.map +1 -1
  40. package/dist/utils/batch.mjs +78 -36
  41. package/dist/utils/batch.mjs.map +1 -1
  42. package/dist/utils/gas-fee-tokens.cjs +123 -0
  43. package/dist/utils/gas-fee-tokens.cjs.map +1 -0
  44. package/dist/utils/gas-fee-tokens.d.cts +22 -0
  45. package/dist/utils/gas-fee-tokens.d.cts.map +1 -0
  46. package/dist/utils/gas-fee-tokens.d.mts +22 -0
  47. package/dist/utils/gas-fee-tokens.d.mts.map +1 -0
  48. package/dist/utils/gas-fee-tokens.mjs +119 -0
  49. package/dist/utils/gas-fee-tokens.mjs.map +1 -0
  50. package/dist/utils/gas.cjs +40 -1
  51. package/dist/utils/gas.cjs.map +1 -1
  52. package/dist/utils/gas.d.cts +17 -0
  53. package/dist/utils/gas.d.cts.map +1 -1
  54. package/dist/utils/gas.d.mts +17 -0
  55. package/dist/utils/gas.d.mts.map +1 -1
  56. package/dist/utils/gas.mjs +38 -0
  57. package/dist/utils/gas.mjs.map +1 -1
  58. package/package.json +1 -1
  59. package/dist/utils/simulation.cjs.map +0 -1
  60. package/dist/utils/simulation.d.cts +0 -60
  61. package/dist/utils/simulation.d.cts.map +0 -1
  62. package/dist/utils/simulation.d.mts +0 -60
  63. package/dist/utils/simulation.d.mts.map +0 -1
  64. package/dist/utils/simulation.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"simulation-api.cjs","sourceRoot":"","sources":["../../src/api/simulation-api.ts"],"names":[],"mappings":";;;AAAA,iEAAiE;AACjE,2CAA+D;AAE/D,0CAA8E;AAC9E,0CAA0C;AAE1C,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,gBAAgB,CAAC,CAAC;AAEhE,MAAM,UA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G,WAAW,CAAC,cAAc,CAAC,CAAC;IAE5C,IAAI,CAAC,OAAO,EAAE,aAAa,EAAE;QAC3B,GAAG,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAC;QACvC,MAAM,IAAI,yCAAgC,CAAC,OAAO,CAAC,CAAC;KACrD;IAED,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,cAAc;IAC3B,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,kBAAkB,CAAC,GAAG,iBAAiB,EAAE,CAAC;IAChE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACH,SAAS,MAAM,CAAC,SAAiB;IAC/B,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AAC5C,CAAC","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 authorizationList?: {\n /** Address of a smart contract that contains the code to be set. */\n address: Hex;\n\n /** Address of the account being upgraded. */\n from: Hex;\n }[];\n\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 blockOverrides?: {\n time?: Hex;\n };\n\n /**\n * Overrides to the state of the blockchain, keyed by address.\n */\n overrides?: {\n [address: Hex]: {\n /** Override the code for an address. */\n code?: Hex;\n\n /** Overrides to the storage slots for an address. */\n stateDiff?: {\n [slot: Hex]: Hex;\n };\n };\n };\n\n /**\n * Whether to include available token fees.\n */\n suggestFees?: {\n /* Whether to estimate gas for the transaction being submitted via a delegation. */\n with7702?: boolean;\n\n /* Whether to include the gas fee of the token transfer. */\n withFeeTransfer?: boolean;\n\n /* Whether to include the native transfer if available. */\n withTransfer?: boolean;\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\nexport type SimulationResponseTokenFee = {\n /** Token data independent of current transaction. */\n token: {\n /** Address of the token contract. */\n address: Hex;\n\n /** Decimals of the token. */\n decimals: number;\n\n /** Symbol of the token. */\n symbol: string;\n };\n\n /** Amount of tokens needed to pay for gas. */\n balanceNeededToken: Hex;\n\n /** Current token balance of sender. */\n currentBalanceToken: Hex;\n\n /** Account address that token should be transferred to. */\n feeRecipient: Hex;\n\n /** Conversation rate of 1 token to native WEI. */\n rateWei: Hex;\n\n /** Estimated gas limit required for fee transfer. */\n transferEstimate: Hex;\n};\n\n/** Response from the simulation API for a single transaction. */\nexport type SimulationResponseTransaction = {\n /** Hierarchy of call data including nested calls and logs. */\n callTrace?: SimulationResponseCallTrace;\n\n /** An error message indicating the transaction could not be simulated. */\n error?: string;\n\n /** Recommended gas fees for the transaction. */\n fees?: {\n /** Gas limit for the fee level. */\n gas: Hex;\n\n /** Maximum fee per gas for the fee level. */\n maxFeePerGas: Hex;\n\n /** Maximum priority fee per gas for the fee level. */\n maxPriorityFeePerGas: Hex;\n\n /** Token fee data for the fee level. */\n tokenFees: SimulationResponseTokenFee[];\n }[];\n\n /** Required `gasLimit` for the transaction. */\n gasLimit?: Hex;\n\n /** Total gas used by the transaction. */\n gasUsed?: Hex;\n\n /** Return value of the transaction, such as the balance if calling balanceOf. */\n return: Hex;\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 *\n * @param chainId - The chain ID to simulate transactions on.\n * @param request - The request to simulate transactions.\n * @returns The response from the simulation API.\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 *\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 *\n * @returns The network data response 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 *\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
+ {"version":3,"file":"simulation-api.cjs","sourceRoot":"","sources":["../../src/api/simulation-api.ts"],"names":[],"mappings":";;;AAAA,iEAAiE;AACjE,2CAA+D;AAE/D,0CAA8E;AAC9E,0CAA0C;AAE1C,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,gBAAgB,CAAC,CAAC;AAEhE,MAAM,UAAU,GAAG,6BAA6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AAc,CAAC,CAAC;IAE5C,IAAI,CAAC,OAAO,EAAE,aAAa,EAAE;QAC3B,GAAG,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAC;QACvC,MAAM,IAAI,yCAAgC,CAAC,OAAO,CAAC,CAAC;KACrD;IAED,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,cAAc;IAC3B,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,kBAAkB,CAAC,GAAG,iBAAiB,EAAE,CAAC;IAChE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACH,SAAS,MAAM,CAAC,SAAiB;IAC/B,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AAC5C,CAAC","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 authorizationList?: {\n /** Address of a smart contract that contains the code to be set. */\n address: Hex;\n\n /** Address of the account being upgraded. */\n from: Hex;\n }[];\n\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 blockOverrides?: {\n time?: Hex;\n };\n\n /**\n * Overrides to the state of the blockchain, keyed by address.\n */\n overrides?: {\n [address: Hex]: {\n /** Override the code for an address. */\n code?: Hex;\n\n /** Overrides to the storage slots for an address. */\n stateDiff?: {\n [slot: Hex]: Hex;\n };\n };\n };\n\n /**\n * Whether to include available token fees.\n */\n suggestFees?: {\n /* Whether to estimate gas for the transaction being submitted via a delegation. */\n with7702?: boolean;\n\n /* Whether to include the gas fee of the token transfer. */\n withFeeTransfer?: boolean;\n\n /* Whether to include the native transfer if available. */\n withTransfer?: boolean;\n };\n\n /**\n * Transactions to be sequentially simulated.\n * State changes impact subsequent transactions in the list.\n */\n transactions: SimulationRequestTransaction[];\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 the default block data in the simulation.\n * Defaults to false.\n */\n withDefaultBlockOverrides?: boolean;\n\n /**\n * Whether to use the gas fees in the simulation.\n * Defaults to false.\n */\n withGas?: 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\nexport type SimulationResponseTokenFee = {\n /** Token data independent of current transaction. */\n token: {\n /** Address of the token contract. */\n address: Hex;\n\n /** Decimals of the token. */\n decimals: number;\n\n /** Symbol of the token. */\n symbol: string;\n };\n\n /** Amount of tokens needed to pay for gas. */\n balanceNeededToken: Hex;\n\n /** Current token balance of sender. */\n currentBalanceToken: Hex;\n\n /** Account address that token should be transferred to. */\n feeRecipient: Hex;\n\n /** Conversation rate of 1 token to native WEI. */\n rateWei: Hex;\n\n /** Portion of `balanceNeededToken` that is the fee paid to MetaMask. */\n serviceFee?: Hex;\n\n /** Estimated gas limit required for fee transfer. */\n transferEstimate: Hex;\n};\n\n/** Response from the simulation API for a single transaction. */\nexport type SimulationResponseTransaction = {\n /** Hierarchy of call data including nested calls and logs. */\n callTrace?: SimulationResponseCallTrace;\n\n /** An error message indicating the transaction could not be simulated. */\n error?: string;\n\n /** Recommended gas fees for the transaction. */\n fees?: {\n /** Gas limit for the fee level. */\n gas: Hex;\n\n /** Maximum fee per gas for the fee level. */\n maxFeePerGas: Hex;\n\n /** Maximum priority fee per gas for the fee level. */\n maxPriorityFeePerGas: Hex;\n\n /** Token fee data for the fee level. */\n tokenFees: SimulationResponseTokenFee[];\n }[];\n\n /**\n * Estimated total gas cost of the transaction.\n * Included in the stateDiff if `withGas` is true.\n */\n gasCost?: number;\n\n /** Required `gasLimit` for the transaction. */\n gasLimit?: Hex;\n\n /** Total gas used by the transaction. */\n gasUsed?: Hex;\n\n /** Return value of the transaction, such as the balance if calling balanceOf. */\n return: Hex;\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 *\n * @param chainId - The chain ID to simulate transactions on.\n * @param request - The request to simulate transactions.\n * @returns The response from the simulation API.\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 *\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 *\n * @returns The network data response 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 *\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"]}
@@ -24,11 +24,6 @@ export type SimulationRequestTransaction = {
24
24
  };
25
25
  /** Request to the simulation API to simulate transactions. */
26
26
  export type SimulationRequest = {
27
- /**
28
- * Transactions to be sequentially simulated.
29
- * State changes impact subsequent transactions in the list.
30
- */
31
- transactions: SimulationRequestTransaction[];
32
27
  blockOverrides?: {
33
28
  time?: Hex;
34
29
  };
@@ -53,11 +48,26 @@ export type SimulationRequest = {
53
48
  withFeeTransfer?: boolean;
54
49
  withTransfer?: boolean;
55
50
  };
51
+ /**
52
+ * Transactions to be sequentially simulated.
53
+ * State changes impact subsequent transactions in the list.
54
+ */
55
+ transactions: SimulationRequestTransaction[];
56
56
  /**
57
57
  * Whether to include call traces in the response.
58
58
  * Defaults to false.
59
59
  */
60
60
  withCallTrace?: boolean;
61
+ /**
62
+ * Whether to include the default block data in the simulation.
63
+ * Defaults to false.
64
+ */
65
+ withDefaultBlockOverrides?: boolean;
66
+ /**
67
+ * Whether to use the gas fees in the simulation.
68
+ * Defaults to false.
69
+ */
70
+ withGas?: boolean;
61
71
  /**
62
72
  * Whether to include event logs in the response.
63
73
  * Defaults to false.
@@ -114,6 +124,8 @@ export type SimulationResponseTokenFee = {
114
124
  feeRecipient: Hex;
115
125
  /** Conversation rate of 1 token to native WEI. */
116
126
  rateWei: Hex;
127
+ /** Portion of `balanceNeededToken` that is the fee paid to MetaMask. */
128
+ serviceFee?: Hex;
117
129
  /** Estimated gas limit required for fee transfer. */
118
130
  transferEstimate: Hex;
119
131
  };
@@ -134,6 +146,11 @@ export type SimulationResponseTransaction = {
134
146
  /** Token fee data for the fee level. */
135
147
  tokenFees: SimulationResponseTokenFee[];
136
148
  }[];
149
+ /**
150
+ * Estimated total gas cost of the transaction.
151
+ * Included in the stateDiff if `withGas` is true.
152
+ */
153
+ gasCost?: number;
137
154
  /** Required `gasLimit` for the transaction. */
138
155
  gasLimit?: Hex;
139
156
  /** Total gas used by the transaction. */
@@ -1 +1 @@
1
- {"version":3,"file":"simulation-api.d.cts","sourceRoot":"","s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AA0E;IAC1E,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,gDAAgD;IAChD,IAAI,CAAC,EAAE;QACL,mCAAmC;QACnC,GAAG,EAAE,GAAG,CAAC;QAET,6CAA6C;QAC7C,YAAY,EAAE,GAAG,CAAC;QAElB,sDAAsD;QACtD,oBAAoB,EAAE,GAAG,CAAC;QAE1B,wCAAwC;QACxC,SAAS,EAAE,0BAA0B,EAAE,CAAC;KACzC,EAAE,CAAC;IAEJ;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,GAAG,CAAC;IAEf,yCAAyC;IACzC,OAAO,CAAC,EAAE,GAAG,CAAC;IAEd,iFAAiF;IACjF,MAAM,EAAE,GAAG,CAAC;IAEZ,uCAAuC;IACvC,SAAS,CAAC,EAAE;QACV,uDAAuD;QACvD,GAAG,CAAC,EAAE,2BAA2B,CAAC;QAElC,sDAAsD;QACtD,IAAI,CAAC,EAAE,2BAA2B,CAAC;KACpC,CAAC;CACH,CAAC;AAEF,wCAAwC;AACxC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,2DAA2D;IAC3D,YAAY,EAAE,6BAA6B,EAAE,CAAC;CAC/C,CAAC;AAkBF;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,kBAAkB,CAAC,CA4B7B"}
@@ -24,11 +24,6 @@ export type SimulationRequestTransaction = {
24
24
  };
25
25
  /** Request to the simulation API to simulate transactions. */
26
26
  export type SimulationRequest = {
27
- /**
28
- * Transactions to be sequentially simulated.
29
- * State changes impact subsequent transactions in the list.
30
- */
31
- transactions: SimulationRequestTransaction[];
32
27
  blockOverrides?: {
33
28
  time?: Hex;
34
29
  };
@@ -53,11 +48,26 @@ export type SimulationRequest = {
53
48
  withFeeTransfer?: boolean;
54
49
  withTransfer?: boolean;
55
50
  };
51
+ /**
52
+ * Transactions to be sequentially simulated.
53
+ * State changes impact subsequent transactions in the list.
54
+ */
55
+ transactions: SimulationRequestTransaction[];
56
56
  /**
57
57
  * Whether to include call traces in the response.
58
58
  * Defaults to false.
59
59
  */
60
60
  withCallTrace?: boolean;
61
+ /**
62
+ * Whether to include the default block data in the simulation.
63
+ * Defaults to false.
64
+ */
65
+ withDefaultBlockOverrides?: boolean;
66
+ /**
67
+ * Whether to use the gas fees in the simulation.
68
+ * Defaults to false.
69
+ */
70
+ withGas?: boolean;
61
71
  /**
62
72
  * Whether to include event logs in the response.
63
73
  * Defaults to false.
@@ -114,6 +124,8 @@ export type SimulationResponseTokenFee = {
114
124
  feeRecipient: Hex;
115
125
  /** Conversation rate of 1 token to native WEI. */
116
126
  rateWei: Hex;
127
+ /** Portion of `balanceNeededToken` that is the fee paid to MetaMask. */
128
+ serviceFee?: Hex;
117
129
  /** Estimated gas limit required for fee transfer. */
118
130
  transferEstimate: Hex;
119
131
  };
@@ -134,6 +146,11 @@ export type SimulationResponseTransaction = {
134
146
  /** Token fee data for the fee level. */
135
147
  tokenFees: SimulationResponseTokenFee[];
136
148
  }[];
149
+ /**
150
+ * Estimated total gas cost of the transaction.
151
+ * Included in the stateDiff if `withGas` is true.
152
+ */
153
+ gasCost?: number;
137
154
  /** Required `gasLimit` for the transaction. */
138
155
  gasLimit?: Hex;
139
156
  /** Total gas used by the transaction. */
@@ -1 +1 @@
1
- {"version":3,"file":"simulation-api.d.mts","sourceRoot":"","sources":["../../src/api/simulation-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,GAAG,EAAE,wBAAwB;AAW/D,mEAAmE;AACnE,MAAM,MAAM,4BAA4B,GAAG;IACzC,iBAAiB,CAAC,EAAE;QAClB,oEAAoE;QACpE,OAAO,EAAE,GAAG,CAAC;QAEb,6CAA6C;QAC7C,IAAI,EAAE,GAAG,CAAC;KACX,EAAE,CAAC;IAEJ,yCAAyC;IACzC,IAAI,CAAC,EAAE,GAAG,CAAC;I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,GAAG,GAAG,GAAG,MAAM,CAAC,kBAAkB,CAAC,GAAG,iBAAiB,EAAE,CAAC;IAChE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACH,SAAS,MAAM,CAAC,SAAiB;IAC/B,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AAC5C,CAAC","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 authorizationList?: {\n /** Address of a smart contract that contains the code to be set. */\n address: Hex;\n\n /** Address of the account being upgraded. */\n from: Hex;\n }[];\n\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 blockOverrides?: {\n time?: Hex;\n };\n\n /**\n * Overrides to the state of the blockchain, keyed by address.\n */\n overrides?: {\n [address: Hex]: {\n /** Override the code for an address. */\n code?: Hex;\n\n /** Overrides to the storage slots for an address. */\n stateDiff?: {\n [slot: Hex]: Hex;\n };\n };\n };\n\n /**\n * Whether to include available token fees.\n */\n suggestFees?: {\n /* Whether to estimate gas for the transaction being submitted via a delegation. */\n with7702?: boolean;\n\n /* Whether to include the gas fee of the token transfer. */\n withFeeTransfer?: boolean;\n\n /* Whether to include the native transfer if available. */\n withTransfer?: boolean;\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\nexport type SimulationResponseTokenFee = {\n /** Token data independent of current transaction. */\n token: {\n /** Address of the token contract. */\n address: Hex;\n\n /** Decimals of the token. */\n decimals: number;\n\n /** Symbol of the token. */\n symbol: string;\n };\n\n /** Amount of tokens needed to pay for gas. */\n balanceNeededToken: Hex;\n\n /** Current token balance of sender. */\n currentBalanceToken: Hex;\n\n /** Account address that token should be transferred to. */\n feeRecipient: Hex;\n\n /** Conversation rate of 1 token to native WEI. */\n rateWei: Hex;\n\n /** Estimated gas limit required for fee transfer. */\n transferEstimate: Hex;\n};\n\n/** Response from the simulation API for a single transaction. */\nexport type SimulationResponseTransaction = {\n /** Hierarchy of call data including nested calls and logs. */\n callTrace?: SimulationResponseCallTrace;\n\n /** An error message indicating the transaction could not be simulated. */\n error?: string;\n\n /** Recommended gas fees for the transaction. */\n fees?: {\n /** Gas limit for the fee level. */\n gas: Hex;\n\n /** Maximum fee per gas for the fee level. */\n maxFeePerGas: Hex;\n\n /** Maximum priority fee per gas for the fee level. */\n maxPriorityFeePerGas: Hex;\n\n /** Token fee data for the fee level. */\n tokenFees: SimulationResponseTokenFee[];\n }[];\n\n /** Required `gasLimit` for the transaction. */\n gasLimit?: Hex;\n\n /** Total gas used by the transaction. */\n gasUsed?: Hex;\n\n /** Return value of the transaction, such as the balance if calling balanceOf. */\n return: Hex;\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 *\n * @param chainId - The chain ID to simulate transactions on.\n * @param request - The request to simulate transactions.\n * @returns The response from the simulation API.\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 *\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 *\n * @returns The network data response 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 *\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
+ {"version":3,"file":"simulation-api.mjs","sourceRoot":"","sources":["../../src/api/simulation-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,mCAAmC;AACjE,OAAO,EAAE,kBAAkB,EAAY,wBAAwB;AAE/D,OAAO,EAAE,gCAAgC,EAAE,eAAe,EAAE,sBAAkB;AAC9E,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAE1C,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;AAEhE,MAAM,UAAU,GAAG,6BAA6B,CAAC;AACjD,MAAM,QAAQ,GAAG,6CAA6C,CAAC;AAC/D,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAgPrC,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAEzB;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,O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OAAO,CAAC,CAAC;AACjC,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,cAAc;IAC3B,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,kBAAkB,CAAC,GAAG,iBAAiB,EAAE,CAAC;IAChE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACH,SAAS,MAAM,CAAC,SAAiB;IAC/B,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AAC5C,CAAC","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 authorizationList?: {\n /** Address of a smart contract that contains the code to be set. */\n address: Hex;\n\n /** Address of the account being upgraded. */\n from: Hex;\n }[];\n\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 blockOverrides?: {\n time?: Hex;\n };\n\n /**\n * Overrides to the state of the blockchain, keyed by address.\n */\n overrides?: {\n [address: Hex]: {\n /** Override the code for an address. */\n code?: Hex;\n\n /** Overrides to the storage slots for an address. */\n stateDiff?: {\n [slot: Hex]: Hex;\n };\n };\n };\n\n /**\n * Whether to include available token fees.\n */\n suggestFees?: {\n /* Whether to estimate gas for the transaction being submitted via a delegation. */\n with7702?: boolean;\n\n /* Whether to include the gas fee of the token transfer. */\n withFeeTransfer?: boolean;\n\n /* Whether to include the native transfer if available. */\n withTransfer?: boolean;\n };\n\n /**\n * Transactions to be sequentially simulated.\n * State changes impact subsequent transactions in the list.\n */\n transactions: SimulationRequestTransaction[];\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 the default block data in the simulation.\n * Defaults to false.\n */\n withDefaultBlockOverrides?: boolean;\n\n /**\n * Whether to use the gas fees in the simulation.\n * Defaults to false.\n */\n withGas?: 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\nexport type SimulationResponseTokenFee = {\n /** Token data independent of current transaction. */\n token: {\n /** Address of the token contract. */\n address: Hex;\n\n /** Decimals of the token. */\n decimals: number;\n\n /** Symbol of the token. */\n symbol: string;\n };\n\n /** Amount of tokens needed to pay for gas. */\n balanceNeededToken: Hex;\n\n /** Current token balance of sender. */\n currentBalanceToken: Hex;\n\n /** Account address that token should be transferred to. */\n feeRecipient: Hex;\n\n /** Conversation rate of 1 token to native WEI. */\n rateWei: Hex;\n\n /** Portion of `balanceNeededToken` that is the fee paid to MetaMask. */\n serviceFee?: Hex;\n\n /** Estimated gas limit required for fee transfer. */\n transferEstimate: Hex;\n};\n\n/** Response from the simulation API for a single transaction. */\nexport type SimulationResponseTransaction = {\n /** Hierarchy of call data including nested calls and logs. */\n callTrace?: SimulationResponseCallTrace;\n\n /** An error message indicating the transaction could not be simulated. */\n error?: string;\n\n /** Recommended gas fees for the transaction. */\n fees?: {\n /** Gas limit for the fee level. */\n gas: Hex;\n\n /** Maximum fee per gas for the fee level. */\n maxFeePerGas: Hex;\n\n /** Maximum priority fee per gas for the fee level. */\n maxPriorityFeePerGas: Hex;\n\n /** Token fee data for the fee level. */\n tokenFees: SimulationResponseTokenFee[];\n }[];\n\n /**\n * Estimated total gas cost of the transaction.\n * Included in the stateDiff if `withGas` is true.\n */\n gasCost?: number;\n\n /** Required `gasLimit` for the transaction. */\n gasLimit?: Hex;\n\n /** Total gas used by the transaction. */\n gasUsed?: Hex;\n\n /** Return value of the transaction, such as the balance if calling balanceOf. */\n return: Hex;\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 *\n * @param chainId - The chain ID to simulate transactions on.\n * @param request - The request to simulate transactions.\n * @returns The response from the simulation API.\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 *\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 *\n * @returns The network data response 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 *\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"]}
@@ -83,7 +83,9 @@ _ExtraTransactionsPublishHook_addTransactionBatch = new WeakMap(), _ExtraTransac
83
83
  from,
84
84
  networkClientId,
85
85
  transactions,
86
- useHook: true,
86
+ disable7702: true,
87
+ disableHook: false,
88
+ disableSequential: true,
87
89
  });
88
90
  return resultPromise.promise;
89
91
  };
@@ -1 +1 @@
1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,GAAG,CAAC,EAAE,eAAe,EAAgC,EAAE,EAAE;QACtE,aAAa,CAAC,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC;IAC7C,CAAC,CAAC;IAEF,MAAM,WAAW,GAA2B;QAC1C,IAAI;QACJ,GAAG;QACH,YAAY;QACZ,oBAAoB;QACpB,EAAE;QACF,KAAK;KACN,CAAC;IAEF,MAAM,gBAAgB,GAAkC;QACtD,mBAAmB,EAAE;YACnB,EAAE;YACF,SAAS;YACT,iBAAiB;SAClB;QACD,MAAM,EAAE,WAAW;KACpB,CAAC;IAEF,MAAM,iBAAiB,GACrB,uBAAA,IAAI,kDAAc,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACvC,MAAM,EAAE,WAAW;KACpB,CAAC,CAAC,CAAC;IAEN,MAAM,YAAY,GAAoC;QACpD,gBAAgB;QAChB,GAAG,iBAAiB;KACrB,CAAC;IAEF,GAAG,CAAC,0BAA0B,EAAE;QAC9B,IAAI;QACJ,eAAe;QACf,YAAY;KACb,CAAC,CAAC;IAEH,MAAM,uBAAA,IAAI,yDAAqB,MAAzB,IAAI,EAAsB;QAC9B,IAAI;QACJ,eAAe;QACf,YAAY;QACZ,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC,OAAO,CAAC;AAC/B,CAAC","sourcesContent":["import {\n createDeferredPromise,\n createModuleLogger,\n type Hex,\n} from '@metamask/utils';\n\nimport type { TransactionController } from '..';\nimport { projectLogger } from '../logger';\nimport type {\n BatchTransactionParams,\n PublishHook,\n PublishHookResult,\n TransactionBatchSingleRequest,\n TransactionMeta,\n} from '../types';\n\nconst log = createModuleLogger(\n projectLogger,\n 'extra-transactions-publish-hook',\n);\n\n/**\n * Custom publish logic that also publishes additional transactions in an batch.\n * Requires the batch to be successful to resolve.\n */\nexport class ExtraTransactionsPublishHook {\n readonly #addTransactionBatch: TransactionController['addTransactionBatch'];\n\n readonly #transactions: BatchTransactionParams[];\n\n constructor({\n addTransactionBatch,\n transactions,\n }: {\n addTransactionBatch: TransactionController['addTransactionBatch'];\n transactions: BatchTransactionParams[];\n }) {\n this.#addTransactionBatch = addTransactionBatch;\n this.#transactions = transactions;\n }\n\n /**\n * @returns The publish hook function.\n */\n getHook(): PublishHook {\n return this.#hook.bind(this);\n }\n\n async #hook(\n transactionMeta: TransactionMeta,\n signedTx: string,\n ): Promise<PublishHookResult> {\n log('Publishing transaction as batch', { transactionMeta, signedTx });\n\n const { id, networkClientId, txParams } = transactionMeta;\n const from = txParams.from as Hex;\n const to = txParams.to as Hex | undefined;\n const data = txParams.data as Hex | undefined;\n const value = txParams.value as Hex | undefined;\n const gas = txParams.gas as Hex | undefined;\n const maxFeePerGas = txParams.maxFeePerGas as Hex | undefined;\n const maxPriorityFeePerGas = txParams.maxPriorityFeePerGas as\n | Hex\n | undefined;\n const signedTransaction = signedTx as Hex;\n const resultPromise = createDeferredPromise<PublishHookResult>();\n\n const onPublish = ({ transactionHash }: { transactionHash?: string }) => {\n resultPromise.resolve({ transactionHash });\n };\n\n const firstParams: BatchTransactionParams = {\n data,\n gas,\n maxFeePerGas,\n maxPriorityFeePerGas,\n to,\n value,\n };\n\n const firstTransaction: TransactionBatchSingleRequest = {\n existingTransaction: {\n id,\n onPublish,\n signedTransaction,\n },\n params: firstParams,\n };\n\n const extraTransactions: TransactionBatchSingleRequest[] =\n this.#transactions.map((transaction) => ({\n params: transaction,\n }));\n\n const transactions: TransactionBatchSingleRequest[] = [\n firstTransaction,\n ...extraTransactions,\n ];\n\n log('Adding transaction batch', {\n from,\n networkClientId,\n transactions,\n });\n\n await this.#addTransactionBatch({\n from,\n networkClientId,\n transactions,\n useHook: true,\n });\n\n return resultPromise.promise;\n }\n}\n"]}
1
+ {"version":3,"file":"ExtraTransactionsPublishHook.cjs","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAIyB;AAGz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WAAW,GAA2B;QAC1C,IAAI;QACJ,GAAG;QACH,YAAY;QACZ,oBAAoB;QACpB,EAAE;QACF,KAAK;KACN,CAAC;IAEF,MAAM,gBAAgB,GAAkC;QACtD,mBAAmB,EAAE;YACnB,EAAE;YACF,SAAS;YACT,iBAAiB;SAClB;QACD,MAAM,EAAE,WAAW;KACpB,CAAC;IAEF,MAAM,iBAAiB,GACrB,uBAAA,IAAI,kDAAc,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACvC,MAAM,EAAE,WAAW;KACpB,CAAC,CAAC,CAAC;IAEN,MAAM,YAAY,GAAoC;QACpD,gBAAgB;QAChB,GAAG,iBAAiB;KACrB,CAAC;IAEF,GAAG,CAAC,0BAA0B,EAAE;QAC9B,IAAI;QACJ,eAAe;QACf,YAAY;KACb,CAAC,CAAC;IAEH,MAAM,uBAAA,IAAI,yDAAqB,MAAzB,IAAI,EAAsB;QAC9B,IAAI;QACJ,eAAe;QACf,YAAY;QACZ,WAAW,EAAE,IAAI;QACjB,WAAW,EAAE,KAAK;QAClB,iBAAiB,EAAE,IAAI;KACxB,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC,OAAO,CAAC;AAC/B,CAAC","sourcesContent":["import {\n createDeferredPromise,\n createModuleLogger,\n type Hex,\n} from '@metamask/utils';\n\nimport type { TransactionController } from '..';\nimport { projectLogger } from '../logger';\nimport type {\n BatchTransactionParams,\n PublishHook,\n PublishHookResult,\n TransactionBatchSingleRequest,\n TransactionMeta,\n} from '../types';\n\nconst log = createModuleLogger(\n projectLogger,\n 'extra-transactions-publish-hook',\n);\n\n/**\n * Custom publish logic that also publishes additional transactions in an batch.\n * Requires the batch to be successful to resolve.\n */\nexport class ExtraTransactionsPublishHook {\n readonly #addTransactionBatch: TransactionController['addTransactionBatch'];\n\n readonly #transactions: BatchTransactionParams[];\n\n constructor({\n addTransactionBatch,\n transactions,\n }: {\n addTransactionBatch: TransactionController['addTransactionBatch'];\n transactions: BatchTransactionParams[];\n }) {\n this.#addTransactionBatch = addTransactionBatch;\n this.#transactions = transactions;\n }\n\n /**\n * @returns The publish hook function.\n */\n getHook(): PublishHook {\n return this.#hook.bind(this);\n }\n\n async #hook(\n transactionMeta: TransactionMeta,\n signedTx: string,\n ): Promise<PublishHookResult> {\n log('Publishing transaction as batch', { transactionMeta, signedTx });\n\n const { id, networkClientId, txParams } = transactionMeta;\n const from = txParams.from as Hex;\n const to = txParams.to as Hex | undefined;\n const data = txParams.data as Hex | undefined;\n const value = txParams.value as Hex | undefined;\n const gas = txParams.gas as Hex | undefined;\n const maxFeePerGas = txParams.maxFeePerGas as Hex | undefined;\n const maxPriorityFeePerGas = txParams.maxPriorityFeePerGas as\n | Hex\n | undefined;\n const signedTransaction = signedTx as Hex;\n const resultPromise = createDeferredPromise<PublishHookResult>();\n\n const onPublish = ({ transactionHash }: { transactionHash?: string }) => {\n resultPromise.resolve({ transactionHash });\n };\n\n const firstParams: BatchTransactionParams = {\n data,\n gas,\n maxFeePerGas,\n maxPriorityFeePerGas,\n to,\n value,\n };\n\n const firstTransaction: TransactionBatchSingleRequest = {\n existingTransaction: {\n id,\n onPublish,\n signedTransaction,\n },\n params: firstParams,\n };\n\n const extraTransactions: TransactionBatchSingleRequest[] =\n this.#transactions.map((transaction) => ({\n params: transaction,\n }));\n\n const transactions: TransactionBatchSingleRequest[] = [\n firstTransaction,\n ...extraTransactions,\n ];\n\n log('Adding transaction batch', {\n from,\n networkClientId,\n transactions,\n });\n\n await this.#addTransactionBatch({\n from,\n networkClientId,\n transactions,\n disable7702: true,\n disableHook: false,\n disableSequential: true,\n });\n\n return resultPromise.promise;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ExtraTransactionsPublishHook.d.cts","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAW;AAEhD,OAAO,KAAK,EACV,sBAAsB,EACtB,WAAW,EAIZ,qBAAiB;AAOlB;;;GAGG;AACH,qBAAa,4BAA4B;;gBAK3B,EACV,mBAAmB,EACnB,YAAY,GACb,EAAE;QACD,mBAAmB,EAAE,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;QAClE,YAAY,EAAE,sBAAsB,EAAE,CAAC;KACxC;IAKD;;OAEG;IACH,OAAO,IAAI,WAAW;CAsEvB"}
1
+ {"version":3,"file":"ExtraTransactionsPublishHook.d.cts","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAW;AAEhD,OAAO,KAAK,EACV,sBAAsB,EACtB,WAAW,EAIZ,qBAAiB;AAOlB;;;GAGG;AACH,qBAAa,4BAA4B;;gBAK3B,EACV,mBAAmB,EACnB,YAAY,GACb,EAAE;QACD,mBAAmB,EAAE,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;QAClE,YAAY,EAAE,sBAAsB,EAAE,CAAC;KACxC;IAKD;;OAEG;IACH,OAAO,IAAI,WAAW;CAwEvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"ExtraTransactionsPublishHook.d.mts","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAW;AAEhD,OAAO,KAAK,EACV,sBAAsB,EACtB,WAAW,EAIZ,qBAAiB;AAOlB;;;GAGG;AACH,qBAAa,4BAA4B;;gBAK3B,EACV,mBAAmB,EACnB,YAAY,GACb,EAAE;QACD,mBAAmB,EAAE,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;QAClE,YAAY,EAAE,sBAAsB,EAAE,CAAC;KACxC;IAKD;;OAEG;IACH,OAAO,IAAI,WAAW;CAsEvB"}
1
+ {"version":3,"file":"ExtraTransactionsPublishHook.d.mts","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAW;AAEhD,OAAO,KAAK,EACV,sBAAsB,EACtB,WAAW,EAIZ,qBAAiB;AAOlB;;;GAGG;AACH,qBAAa,4BAA4B;;gBAK3B,EACV,mBAAmB,EACnB,YAAY,GACb,EAAE;QACD,mBAAmB,EAAE,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;QAClE,YAAY,EAAE,sBAAsB,EAAE,CAAC;KACxC;IAKD;;OAEG;IACH,OAAO,IAAI,WAAW;CAwEvB"}
@@ -79,7 +79,9 @@ _ExtraTransactionsPublishHook_addTransactionBatch = new WeakMap(), _ExtraTransac
79
79
  from,
80
80
  networkClientId,
81
81
  transactions,
82
- useHook: true,
82
+ disable7702: true,
83
+ disableHook: false,
84
+ disableSequential: true,
83
85
  });
84
86
  return resultPromise.promise;
85
87
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ExtraTransactionsPublishHook.mjs","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAEnB,wBAAwB;AAGzB,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAS1C,MAAM,GAAG,GAAG,kBAAkB,CAC5B,aAAa,EACb,iCAAiC,CAClC,CAAC;AAEF;;;GAGG;AACH,MAAM,OAAO,4BAA4B;IAKvC,YAAY,EACV,mBAAmB,EACnB,YAAY,GAIb;;QAVQ,oEAAmE;QAEnE,6DAAwC;QAS/C,uBAAA,IAAI,qDAAwB,mBAAmB,MAAA,CAAC;QAChD,uBAAA,IAAI,8CAAiB,YAAY,MAAA,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,uBAAA,IAAI,mFAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CAoEF;6NAlEC,KAAK,6CACH,eAAgC,EAChC,QAAgB;IAEhB,GAAG,CAAC,iCAA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f,YAAY;KACb,CAAC,CAAC;IAEH,MAAM,uBAAA,IAAI,yDAAqB,MAAzB,IAAI,EAAsB;QAC9B,IAAI;QACJ,eAAe;QACf,YAAY;QACZ,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC,OAAO,CAAC;AAC/B,CAAC","sourcesContent":["import {\n createDeferredPromise,\n createModuleLogger,\n type Hex,\n} from '@metamask/utils';\n\nimport type { TransactionController } from '..';\nimport { projectLogger } from '../logger';\nimport type {\n BatchTransactionParams,\n PublishHook,\n PublishHookResult,\n TransactionBatchSingleRequest,\n TransactionMeta,\n} from '../types';\n\nconst log = createModuleLogger(\n projectLogger,\n 'extra-transactions-publish-hook',\n);\n\n/**\n * Custom publish logic that also publishes additional transactions in an batch.\n * Requires the batch to be successful to resolve.\n */\nexport class ExtraTransactionsPublishHook {\n readonly #addTransactionBatch: TransactionController['addTransactionBatch'];\n\n readonly #transactions: BatchTransactionParams[];\n\n constructor({\n addTransactionBatch,\n transactions,\n }: {\n addTransactionBatch: TransactionController['addTransactionBatch'];\n transactions: BatchTransactionParams[];\n }) {\n this.#addTransactionBatch = addTransactionBatch;\n this.#transactions = transactions;\n }\n\n /**\n * @returns The publish hook function.\n */\n getHook(): PublishHook {\n return this.#hook.bind(this);\n }\n\n async #hook(\n transactionMeta: TransactionMeta,\n signedTx: string,\n ): Promise<PublishHookResult> {\n log('Publishing transaction as batch', { transactionMeta, signedTx });\n\n const { id, networkClientId, txParams } = transactionMeta;\n const from = txParams.from as Hex;\n const to = txParams.to as Hex | undefined;\n const data = txParams.data as Hex | undefined;\n const value = txParams.value as Hex | undefined;\n const gas = txParams.gas as Hex | undefined;\n const maxFeePerGas = txParams.maxFeePerGas as Hex | undefined;\n const maxPriorityFeePerGas = txParams.maxPriorityFeePerGas as\n | Hex\n | undefined;\n const signedTransaction = signedTx as Hex;\n const resultPromise = createDeferredPromise<PublishHookResult>();\n\n const onPublish = ({ transactionHash }: { transactionHash?: string }) => {\n resultPromise.resolve({ transactionHash });\n };\n\n const firstParams: BatchTransactionParams = {\n data,\n gas,\n maxFeePerGas,\n maxPriorityFeePerGas,\n to,\n value,\n };\n\n const firstTransaction: TransactionBatchSingleRequest = {\n existingTransaction: {\n id,\n onPublish,\n signedTransaction,\n },\n params: firstParams,\n };\n\n const extraTransactions: TransactionBatchSingleRequest[] =\n this.#transactions.map((transaction) => ({\n params: transaction,\n }));\n\n const transactions: TransactionBatchSingleRequest[] = [\n firstTransaction,\n ...extraTransactions,\n ];\n\n log('Adding transaction batch', {\n from,\n networkClientId,\n transactions,\n });\n\n await this.#addTransactionBatch({\n from,\n networkClientId,\n transactions,\n useHook: true,\n });\n\n return resultPromise.promise;\n }\n}\n"]}
1
+ {"version":3,"file":"ExtraTransactionsPublishHook.mjs","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAEnB,wBAAwB;AAGzB,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAS1C,MAAM,GAAG,GAAG,kBAAkB,CAC5B,aAAa,EACb,iCAAiC,CAClC,CAAC;AAEF;;;GAGG;AACH,MAAM,OAAO,4BAA4B;IAKvC,YAAY,EACV,mBAAmB,EACnB,YAAY,GAIb;;QAVQ,oEAAmE;QAEnE,6DAAwC;QAS/C,uBAAA,IAAI,qDAAwB,mBAAmB,MAAA,CAAC;QAChD,uBAAA,IAAI,8CAAiB,YAAY,MAAA,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,uBAAA,IAAI,mFAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CAsEF;6NApEC,KAAK,6CACH,eAAgC,EAChC,QAAgB;IAEhB,GAAG,CAAC,iCAAiC,EAAE,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,CAAC;IAEtE,MAAM,EAAE,EAAE,EAAE,eAAe,EAAE,Q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,eAAe;QACf,YAAY;QACZ,WAAW,EAAE,IAAI;QACjB,WAAW,EAAE,KAAK;QAClB,iBAAiB,EAAE,IAAI;KACxB,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC,OAAO,CAAC;AAC/B,CAAC","sourcesContent":["import {\n createDeferredPromise,\n createModuleLogger,\n type Hex,\n} from '@metamask/utils';\n\nimport type { TransactionController } from '..';\nimport { projectLogger } from '../logger';\nimport type {\n BatchTransactionParams,\n PublishHook,\n PublishHookResult,\n TransactionBatchSingleRequest,\n TransactionMeta,\n} from '../types';\n\nconst log = createModuleLogger(\n projectLogger,\n 'extra-transactions-publish-hook',\n);\n\n/**\n * Custom publish logic that also publishes additional transactions in an batch.\n * Requires the batch to be successful to resolve.\n */\nexport class ExtraTransactionsPublishHook {\n readonly #addTransactionBatch: TransactionController['addTransactionBatch'];\n\n readonly #transactions: BatchTransactionParams[];\n\n constructor({\n addTransactionBatch,\n transactions,\n }: {\n addTransactionBatch: TransactionController['addTransactionBatch'];\n transactions: BatchTransactionParams[];\n }) {\n this.#addTransactionBatch = addTransactionBatch;\n this.#transactions = transactions;\n }\n\n /**\n * @returns The publish hook function.\n */\n getHook(): PublishHook {\n return this.#hook.bind(this);\n }\n\n async #hook(\n transactionMeta: TransactionMeta,\n signedTx: string,\n ): Promise<PublishHookResult> {\n log('Publishing transaction as batch', { transactionMeta, signedTx });\n\n const { id, networkClientId, txParams } = transactionMeta;\n const from = txParams.from as Hex;\n const to = txParams.to as Hex | undefined;\n const data = txParams.data as Hex | undefined;\n const value = txParams.value as Hex | undefined;\n const gas = txParams.gas as Hex | undefined;\n const maxFeePerGas = txParams.maxFeePerGas as Hex | undefined;\n const maxPriorityFeePerGas = txParams.maxPriorityFeePerGas as\n | Hex\n | undefined;\n const signedTransaction = signedTx as Hex;\n const resultPromise = createDeferredPromise<PublishHookResult>();\n\n const onPublish = ({ transactionHash }: { transactionHash?: string }) => {\n resultPromise.resolve({ transactionHash });\n };\n\n const firstParams: BatchTransactionParams = {\n data,\n gas,\n maxFeePerGas,\n maxPriorityFeePerGas,\n to,\n value,\n };\n\n const firstTransaction: TransactionBatchSingleRequest = {\n existingTransaction: {\n id,\n onPublish,\n signedTransaction,\n },\n params: firstParams,\n };\n\n const extraTransactions: TransactionBatchSingleRequest[] =\n this.#transactions.map((transaction) => ({\n params: transaction,\n }));\n\n const transactions: TransactionBatchSingleRequest[] = [\n firstTransaction,\n ...extraTransactions,\n ];\n\n log('Adding transaction batch', {\n from,\n networkClientId,\n transactions,\n });\n\n await this.#addTransactionBatch({\n from,\n networkClientId,\n transactions,\n disable7702: true,\n disableHook: false,\n disableSequential: true,\n });\n\n return resultPromise.promise;\n }\n}\n"]}