@metamask/transaction-controller 65.0.0 → 65.2.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.
- package/CHANGELOG.md +35 -1
- package/dist/TransactionController-method-action-types.cjs.map +1 -1
- package/dist/TransactionController-method-action-types.d.cts +69 -1
- package/dist/TransactionController-method-action-types.d.cts.map +1 -1
- package/dist/TransactionController-method-action-types.d.mts +69 -1
- package/dist/TransactionController-method-action-types.d.mts.map +1 -1
- package/dist/TransactionController-method-action-types.mjs.map +1 -1
- package/dist/TransactionController.cjs +37 -1
- package/dist/TransactionController.cjs.map +1 -1
- package/dist/TransactionController.d.cts.map +1 -1
- package/dist/TransactionController.d.mts.map +1 -1
- package/dist/TransactionController.mjs +37 -1
- package/dist/TransactionController.mjs.map +1 -1
- package/dist/api/simulation-api.cjs.map +1 -1
- package/dist/api/simulation-api.d.cts +2 -0
- package/dist/api/simulation-api.d.cts.map +1 -1
- package/dist/api/simulation-api.d.mts +2 -0
- package/dist/api/simulation-api.d.mts.map +1 -1
- package/dist/api/simulation-api.mjs.map +1 -1
- package/dist/helpers/PendingTransactionTracker.cjs +13 -2
- package/dist/helpers/PendingTransactionTracker.cjs.map +1 -1
- package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -1
- package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -1
- package/dist/helpers/PendingTransactionTracker.mjs +13 -2
- package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +22 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +22 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/balance-changes.cjs +21 -1
- package/dist/utils/balance-changes.cjs.map +1 -1
- package/dist/utils/balance-changes.d.cts +2 -1
- package/dist/utils/balance-changes.d.cts.map +1 -1
- package/dist/utils/balance-changes.d.mts +2 -1
- package/dist/utils/balance-changes.d.mts.map +1 -1
- package/dist/utils/balance-changes.mjs +21 -1
- package/dist/utils/balance-changes.mjs.map +1 -1
- package/dist/utils/eip7702.cjs +38 -9
- package/dist/utils/eip7702.cjs.map +1 -1
- package/dist/utils/eip7702.d.cts +12 -0
- package/dist/utils/eip7702.d.cts.map +1 -1
- package/dist/utils/eip7702.d.mts +12 -0
- package/dist/utils/eip7702.d.mts.map +1 -1
- package/dist/utils/eip7702.mjs +36 -8
- package/dist/utils/eip7702.mjs.map +1 -1
- package/dist/utils/gas.cjs +12 -5
- package/dist/utils/gas.cjs.map +1 -1
- package/dist/utils/gas.d.cts +2 -1
- package/dist/utils/gas.d.cts.map +1 -1
- package/dist/utils/gas.d.mts +2 -1
- package/dist/utils/gas.d.mts.map +1 -1
- package/dist/utils/gas.mjs +12 -5
- package/dist/utils/gas.mjs.map +1 -1
- package/dist/utils/revert-reason.cjs +192 -0
- package/dist/utils/revert-reason.cjs.map +1 -0
- package/dist/utils/revert-reason.d.cts +57 -0
- package/dist/utils/revert-reason.d.cts.map +1 -0
- package/dist/utils/revert-reason.d.mts +57 -0
- package/dist/utils/revert-reason.d.mts.map +1 -0
- package/dist/utils/revert-reason.mjs +186 -0
- package/dist/utils/revert-reason.mjs.map +1 -0
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulation-api.cjs","sourceRoot":"","sources":["../../src/api/simulation-api.ts"],"names":[],"mappings":";;;AAAA,iEAAiE;AACjE,2CAAqD;AAErD,mCAAmC;AAEnC,gDAGsB;AACtB,0CAA8E;AAC9E,0CAA0C;AAG1C,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,gBAAgB,CAAC,CAAC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Y,EAAE,CAAC;QAClD,MAAM,YAAY,GAAG,WAAW,CAAC,EAAE,EAAE,WAAW,EAAS,CAAC;QAE1D,MAAM,qBAAqB,GACzB,wCAA4B,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAEtD,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC3B,SAAS;QACX,CAAC;QAED,UAAU,CAAC,SAAS,GAAG,UAAU,CAAC,SAAS,IAAI,EAAE,CAAC;QAElD,UAAU,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG;YACnC,IAAI,EAAE,uDAA2C;SAClD,CAAC;IACJ,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\nimport { cloneDeep } from 'lodash';\n\nimport {\n CODE_DELEGATION_MANAGER_NO_SIGNATURE_ERRORS,\n DELEGATION_MANAGER_ADDRESSES,\n} from '../constants';\nimport { SimulationChainNotSupportedError, SimulationError } from '../errors';\nimport { projectLogger } from '../logger';\nimport type { GetSimulationConfig } from '../types';\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 * Function to get the simulation configuration.\n */\n getSimulationConfig: GetSimulationConfig;\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[] | null;\n\n /** Error message for the call, if any. */\n error?: string;\n\n /** Raw event logs created by the call. */\n logs?: SimulationResponseLog[] | null;\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 sponsorship: {\n /** Whether the gas costs are sponsored meaning a transfer is not required. */\n isSponsored: boolean;\n\n /** Error message for the determination of sponsorship. */\n error: string | null;\n };\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 let url = await getSimulationUrl(chainId);\n\n const { newUrl, authorization } =\n (await request.getSimulationConfig(url)) || {};\n if (newUrl) {\n url = newUrl;\n }\n\n const requestId = requestIdCounter;\n requestIdCounter += 1;\n\n const finalRequest = finalizeRequest(request);\n\n log('Sending request', url, request);\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n // Add optional authorization header, if provided.\n if (authorization) {\n headers.Authorization = authorization;\n }\n\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JSON.stringify({\n id: String(requestId),\n jsonrpc: '2.0',\n method: RPC_METHOD,\n params: [finalRequest],\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\n/**\n * Finalize the simulation request.\n * Overrides the DelegationManager code to remove signature errors.\n * Temporary pending support in the simulation API.\n *\n * @param request - The simulation request to finalize.\n * @returns The finalized simulation request.\n */\nfunction finalizeRequest(request: SimulationRequest): SimulationRequest {\n const newRequest = cloneDeep(request);\n\n for (const transaction of newRequest.transactions) {\n const normalizedTo = transaction.to?.toLowerCase() as Hex;\n\n const isToDelegationManager =\n DELEGATION_MANAGER_ADDRESSES.includes(normalizedTo);\n\n if (!isToDelegationManager) {\n continue;\n }\n\n newRequest.overrides = newRequest.overrides ?? {};\n\n newRequest.overrides[normalizedTo] = {\n code: CODE_DELEGATION_MANAGER_NO_SIGNATURE_ERRORS,\n };\n }\n\n return newRequest;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"simulation-api.cjs","sourceRoot":"","sources":["../../src/api/simulation-api.ts"],"names":[],"mappings":";;;AAAA,iEAAiE;AACjE,2CAAqD;AAErD,mCAAmC;AAEnC,gDAGsB;AACtB,0CAA8E;AAC9E,0CAA0C;AAG1C,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,gBAAgB,CAAC,CAAC;AAEhE,MAAM,UAAU,GAAG,6BAA6B,CAAC;AACjD,MAAM,QAAQ,GAAG,6CAA6C,CAAC;AAC/D,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAmQrC,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAEzB;;;;;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qBAAqB,EAAE,CAAC;YAC3B,SAAS;QACX,CAAC;QAED,UAAU,CAAC,SAAS,GAAG,UAAU,CAAC,SAAS,IAAI,EAAE,CAAC;QAElD,UAAU,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG;YACnC,IAAI,EAAE,uDAA2C;SAClD,CAAC;IACJ,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\nimport { cloneDeep } from 'lodash';\n\nimport {\n CODE_DELEGATION_MANAGER_NO_SIGNATURE_ERRORS,\n DELEGATION_MANAGER_ADDRESSES,\n} from '../constants';\nimport { SimulationChainNotSupportedError, SimulationError } from '../errors';\nimport { projectLogger } from '../logger';\nimport type { GetSimulationConfig } from '../types';\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 * Function to get the simulation configuration.\n */\n getSimulationConfig: GetSimulationConfig;\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[] | null;\n\n /** Error message for the call, if any. */\n error?: string;\n\n /** Raw event logs created by the call. */\n logs?: SimulationResponseLog[] | null;\n\n /** Raw return data from the call (revert hex when reverted). */\n output?: Hex;\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 sponsorship: {\n /** Whether the gas costs are sponsored meaning a transfer is not required. */\n isSponsored: boolean;\n\n /** Error message for the determination of sponsorship. */\n error: string | null;\n };\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 let url = await getSimulationUrl(chainId);\n\n const { newUrl, authorization } =\n (await request.getSimulationConfig(url)) || {};\n if (newUrl) {\n url = newUrl;\n }\n\n const requestId = requestIdCounter;\n requestIdCounter += 1;\n\n const finalRequest = finalizeRequest(request);\n\n log('Sending request', url, request);\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n // Add optional authorization header, if provided.\n if (authorization) {\n headers.Authorization = authorization;\n }\n\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JSON.stringify({\n id: String(requestId),\n jsonrpc: '2.0',\n method: RPC_METHOD,\n params: [finalRequest],\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\n/**\n * Finalize the simulation request.\n * Overrides the DelegationManager code to remove signature errors.\n * Temporary pending support in the simulation API.\n *\n * @param request - The simulation request to finalize.\n * @returns The finalized simulation request.\n */\nfunction finalizeRequest(request: SimulationRequest): SimulationRequest {\n const newRequest = cloneDeep(request);\n\n for (const transaction of newRequest.transactions) {\n const normalizedTo = transaction.to?.toLowerCase() as Hex;\n\n const isToDelegationManager =\n DELEGATION_MANAGER_ADDRESSES.includes(normalizedTo);\n\n if (!isToDelegationManager) {\n continue;\n }\n\n newRequest.overrides = newRequest.overrides ?? {};\n\n newRequest.overrides[normalizedTo] = {\n code: CODE_DELEGATION_MANAGER_NO_SIGNATURE_ERRORS,\n };\n }\n\n return newRequest;\n}\n"]}
|
|
@@ -96,6 +96,8 @@ export type SimulationResponseCallTrace = {
|
|
|
96
96
|
error?: string;
|
|
97
97
|
/** Raw event logs created by the call. */
|
|
98
98
|
logs?: SimulationResponseLog[] | null;
|
|
99
|
+
/** Raw return data from the call (revert hex when reverted). */
|
|
100
|
+
output?: Hex;
|
|
99
101
|
};
|
|
100
102
|
/**
|
|
101
103
|
* Changes to the blockchain state.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulation-api.d.cts","sourceRoot":"","sources":["../../src/api/simulation-api.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAS3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAiB;AAQpD,mEAAmE;AACnE,MAAM,MAAM,4BAA4B,GAAG;IACzC,iBAAiB,CAAC,EAAE;QAClB,oEAAoE;QACpE,OAAO,EAAE,GAA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1B,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;IAE9C,WAAW,EAAE;QACX,8EAA8E;QAC9E,WAAW,EAAE,OAAO,CAAC;QAErB,0DAA0D;QAC1D,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;KACtB,CAAC;CACH,CAAC;AAkBF;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,kBAAkB,CAAC,CA8C7B"}
|
|
@@ -96,6 +96,8 @@ export type SimulationResponseCallTrace = {
|
|
|
96
96
|
error?: string;
|
|
97
97
|
/** Raw event logs created by the call. */
|
|
98
98
|
logs?: SimulationResponseLog[] | null;
|
|
99
|
+
/** Raw return data from the call (revert hex when reverted). */
|
|
100
|
+
output?: Hex;
|
|
99
101
|
};
|
|
100
102
|
/**
|
|
101
103
|
* Changes to the blockchain state.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulation-api.d.mts","sourceRoot":"","sources":["../../src/api/simulation-api.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAS3C,OAAO,K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S,eAAe,CAAC,OAA0B;IACjD,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAEtC,KAAK,MAAM,WAAW,IAAI,UAAU,CAAC,YAAY,EAAE,CAAC;QAClD,MAAM,YAAY,GAAG,WAAW,CAAC,EAAE,EAAE,WAAW,EAAS,CAAC;QAE1D,MAAM,qBAAqB,GACzB,4BAA4B,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAEtD,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC3B,SAAS;QACX,CAAC;QAED,UAAU,CAAC,SAAS,GAAG,UAAU,CAAC,SAAS,IAAI,EAAE,CAAC;QAElD,UAAU,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG;YACnC,IAAI,EAAE,2CAA2C;SAClD,CAAC;IACJ,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\nimport { cloneDeep } from 'lodash';\n\nimport {\n CODE_DELEGATION_MANAGER_NO_SIGNATURE_ERRORS,\n DELEGATION_MANAGER_ADDRESSES,\n} from '../constants';\nimport { SimulationChainNotSupportedError, SimulationError } from '../errors';\nimport { projectLogger } from '../logger';\nimport type { GetSimulationConfig } from '../types';\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 * Function to get the simulation configuration.\n */\n getSimulationConfig: GetSimulationConfig;\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[] | null;\n\n /** Error message for the call, if any. */\n error?: string;\n\n /** Raw event logs created by the call. */\n logs?: SimulationResponseLog[] | null;\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 sponsorship: {\n /** Whether the gas costs are sponsored meaning a transfer is not required. */\n isSponsored: boolean;\n\n /** Error message for the determination of sponsorship. */\n error: string | null;\n };\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 let url = await getSimulationUrl(chainId);\n\n const { newUrl, authorization } =\n (await request.getSimulationConfig(url)) || {};\n if (newUrl) {\n url = newUrl;\n }\n\n const requestId = requestIdCounter;\n requestIdCounter += 1;\n\n const finalRequest = finalizeRequest(request);\n\n log('Sending request', url, request);\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n // Add optional authorization header, if provided.\n if (authorization) {\n headers.Authorization = authorization;\n }\n\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JSON.stringify({\n id: String(requestId),\n jsonrpc: '2.0',\n method: RPC_METHOD,\n params: [finalRequest],\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\n/**\n * Finalize the simulation request.\n * Overrides the DelegationManager code to remove signature errors.\n * Temporary pending support in the simulation API.\n *\n * @param request - The simulation request to finalize.\n * @returns The finalized simulation request.\n */\nfunction finalizeRequest(request: SimulationRequest): SimulationRequest {\n const newRequest = cloneDeep(request);\n\n for (const transaction of newRequest.transactions) {\n const normalizedTo = transaction.to?.toLowerCase() as Hex;\n\n const isToDelegationManager =\n DELEGATION_MANAGER_ADDRESSES.includes(normalizedTo);\n\n if (!isToDelegationManager) {\n continue;\n }\n\n newRequest.overrides = newRequest.overrides ?? {};\n\n newRequest.overrides[normalizedTo] = {\n code: CODE_DELEGATION_MANAGER_NO_SIGNATURE_ERRORS,\n };\n }\n\n return newRequest;\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,EAAE,wBAAwB;;;AAIrD,OAAO,EACL,2CAA2C,EAC3C,4BAA4B,EAC7B,yBAAqB;AACtB,OAAO,EAAE,gCAAgC,EAAE,eAAe,EAAE,sBAAkB;AAC9E,OAAO,EAAE,aAAa,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C,OAAO,CAAC,CAAC;IAEtC,KAAK,MAAM,WAAW,IAAI,UAAU,CAAC,YAAY,EAAE,CAAC;QAClD,MAAM,YAAY,GAAG,WAAW,CAAC,EAAE,EAAE,WAAW,EAAS,CAAC;QAE1D,MAAM,qBAAqB,GACzB,4BAA4B,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAEtD,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC3B,SAAS;QACX,CAAC;QAED,UAAU,CAAC,SAAS,GAAG,UAAU,CAAC,SAAS,IAAI,EAAE,CAAC;QAElD,UAAU,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG;YACnC,IAAI,EAAE,2CAA2C;SAClD,CAAC;IACJ,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\nimport { cloneDeep } from 'lodash';\n\nimport {\n CODE_DELEGATION_MANAGER_NO_SIGNATURE_ERRORS,\n DELEGATION_MANAGER_ADDRESSES,\n} from '../constants';\nimport { SimulationChainNotSupportedError, SimulationError } from '../errors';\nimport { projectLogger } from '../logger';\nimport type { GetSimulationConfig } from '../types';\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 * Function to get the simulation configuration.\n */\n getSimulationConfig: GetSimulationConfig;\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[] | null;\n\n /** Error message for the call, if any. */\n error?: string;\n\n /** Raw event logs created by the call. */\n logs?: SimulationResponseLog[] | null;\n\n /** Raw return data from the call (revert hex when reverted). */\n output?: Hex;\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 sponsorship: {\n /** Whether the gas costs are sponsored meaning a transfer is not required. */\n isSponsored: boolean;\n\n /** Error message for the determination of sponsorship. */\n error: string | null;\n };\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 let url = await getSimulationUrl(chainId);\n\n const { newUrl, authorization } =\n (await request.getSimulationConfig(url)) || {};\n if (newUrl) {\n url = newUrl;\n }\n\n const requestId = requestIdCounter;\n requestIdCounter += 1;\n\n const finalRequest = finalizeRequest(request);\n\n log('Sending request', url, request);\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n // Add optional authorization header, if provided.\n if (authorization) {\n headers.Authorization = authorization;\n }\n\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JSON.stringify({\n id: String(requestId),\n jsonrpc: '2.0',\n method: RPC_METHOD,\n params: [finalRequest],\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\n/**\n * Finalize the simulation request.\n * Overrides the DelegationManager code to remove signature errors.\n * Temporary pending support in the simulation API.\n *\n * @param request - The simulation request to finalize.\n * @returns The finalized simulation request.\n */\nfunction finalizeRequest(request: SimulationRequest): SimulationRequest {\n const newRequest = cloneDeep(request);\n\n for (const transaction of newRequest.transactions) {\n const normalizedTo = transaction.to?.toLowerCase() as Hex;\n\n const isToDelegationManager =\n DELEGATION_MANAGER_ADDRESSES.includes(normalizedTo);\n\n if (!isToDelegationManager) {\n continue;\n }\n\n newRequest.overrides = newRequest.overrides ?? {};\n\n newRequest.overrides[normalizedTo] = {\n code: CODE_DELEGATION_MANAGER_NO_SIGNATURE_ERRORS,\n };\n }\n\n return newRequest;\n}\n"]}
|
|
@@ -24,6 +24,7 @@ const logger_1 = require("../logger.cjs");
|
|
|
24
24
|
const types_1 = require("../types.cjs");
|
|
25
25
|
const feature_flags_1 = require("../utils/feature-flags.cjs");
|
|
26
26
|
const provider_1 = require("../utils/provider.cjs");
|
|
27
|
+
const revert_reason_1 = require("../utils/revert-reason.cjs");
|
|
27
28
|
const TransactionPoller_1 = require("./TransactionPoller.cjs");
|
|
28
29
|
/**
|
|
29
30
|
* We wait this many blocks before emitting a 'transaction-dropped' event
|
|
@@ -270,8 +271,18 @@ _PendingTransactionTracker_beforeCheckPendingTransaction = new WeakMap(), _Pendi
|
|
|
270
271
|
const isSuccess = receipt?.status === RECEIPT_STATUS_SUCCESS;
|
|
271
272
|
const isFailure = receipt?.status === RECEIPT_STATUS_FAILURE;
|
|
272
273
|
if (isFailure) {
|
|
273
|
-
__classPrivateFieldGet(this, _PendingTransactionTracker_log, "f").call(this, 'Transaction receipt has failed status'
|
|
274
|
-
|
|
274
|
+
__classPrivateFieldGet(this, _PendingTransactionTracker_log, "f").call(this, 'Transaction receipt has failed status', {
|
|
275
|
+
id: txMeta.id,
|
|
276
|
+
hash: txMeta.hash,
|
|
277
|
+
chainId: txMeta.chainId,
|
|
278
|
+
blockNumber: receipt.blockNumber,
|
|
279
|
+
});
|
|
280
|
+
const revert = await (0, revert_reason_1.extractRevert)({
|
|
281
|
+
messenger: __classPrivateFieldGet(this, _PendingTransactionTracker_messenger, "f"),
|
|
282
|
+
networkClientId: txMeta.networkClientId,
|
|
283
|
+
txParams: txMeta.txParams,
|
|
284
|
+
});
|
|
285
|
+
__classPrivateFieldGet(this, _PendingTransactionTracker_instances, "m", _PendingTransactionTracker_failTransaction).call(this, txMeta, new revert_reason_1.OnChainFailureError(revert));
|
|
275
286
|
return;
|
|
276
287
|
}
|
|
277
288
|
const { blockNumber, blockHash } = receipt ?? {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PendingTransactionTracker.cjs","sourceRoot":"","sources":["../../src/helpers/PendingTransactionTracker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAKA,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAClC,mCAA0C;AAE1C,0CAA8D;AAG9D,wCAA8D;AAC9D,8DAGgC;AAChC,oDAA2D;AAC3D,+DAAwD;AAExD;;;GAGG;AACH,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAE9B,MAAM,sBAAsB,GAAG,KAAK,CAAC;AACrC,MAAM,sBAAsB,GAAG,KAAK,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AAM,CACnC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,eAAe,KAAK,eAAe,CAC/C,CAAC;AACJ,CAAC","sourcesContent":["import type {\n BlockTracker,\n NetworkClientId,\n} from '@metamask/network-controller';\nimport type { Json } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\nimport { cloneDeep, merge } from 'lodash';\n\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type { TransactionMeta, TransactionReceipt } from '../types';\nimport { TransactionStatus, TransactionType } from '../types';\nimport {\n getAcceleratedPollingParams,\n getTimeoutAttempts,\n} from '../utils/feature-flags';\nimport { getChainId, rpcRequest } from '../utils/provider';\nimport { TransactionPoller } from './TransactionPoller';\n\n/**\n * We wait this many blocks before emitting a 'transaction-dropped' event\n * This is because we could be talking to a node that is out of sync\n */\nconst DROPPED_BLOCK_COUNT = 3;\n\nconst RECEIPT_STATUS_SUCCESS = '0x1';\nconst RECEIPT_STATUS_FAILURE = '0x0';\nconst MAX_RETRY_BLOCK_DISTANCE = 50;\n\nconst KNOWN_TRANSACTION_ERRORS = [\n 'replacement transaction underpriced',\n 'known transaction',\n 'gas price too low to replace',\n 'transaction with the same hash was already imported',\n 'gateway timeout',\n 'nonce too low',\n];\n\nconst log = createModuleLogger(projectLogger, 'pending-transactions');\n\ntype SuccessfulTransactionReceipt = TransactionReceipt & {\n blockNumber: string;\n blockHash: string;\n};\n\ntype Events = {\n 'transaction-confirmed': [txMeta: TransactionMeta];\n 'transaction-dropped': [txMeta: TransactionMeta];\n 'transaction-failed': [txMeta: TransactionMeta, error: Error];\n 'transaction-updated': [txMeta: TransactionMeta, note: string];\n};\n\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface PendingTransactionTrackerEventEmitter extends EventEmitter {\n on<EventName extends keyof Events>(\n eventName: EventName,\n listener: (...args: Events[EventName]) => void,\n ): this;\n\n emit<EventName extends keyof Events>(\n eventName: EventName,\n ...args: Events[EventName]\n ): boolean;\n}\n\nexport class PendingTransactionTracker {\n hub: PendingTransactionTrackerEventEmitter;\n\n readonly #beforeCheckPendingTransaction: (\n transactionMeta: TransactionMeta,\n ) => Promise<boolean>;\n\n readonly #droppedBlockCountByHash: Map<string, number>;\n\n readonly #isTimeoutEnabled: (transactionMeta: TransactionMeta) => boolean;\n\n readonly #getGlobalLock: () => Promise<() => void>;\n\n readonly #chainId: string;\n\n readonly #networkClientId: NetworkClientId;\n\n readonly #getTransactions: () => TransactionMeta[];\n\n readonly #isResubmitEnabled: () => boolean;\n\n readonly #lastSeenTimestampByHash: Map<string, number>;\n\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n readonly #listener: any;\n\n readonly #log: debug.Debugger;\n\n readonly #messenger: TransactionControllerMessenger;\n\n readonly #publishTransaction: (\n transactionMeta: TransactionMeta,\n ) => Promise<string>;\n\n #running: boolean;\n\n readonly #transactionPoller: TransactionPoller;\n\n #transactionToForcePoll: TransactionMeta | undefined;\n\n constructor({\n blockTracker,\n getGlobalLock,\n getTransactions,\n isTimeoutEnabled,\n hooks,\n isResubmitEnabled,\n messenger,\n networkClientId,\n publishTransaction,\n }: {\n blockTracker: BlockTracker;\n getGlobalLock: () => Promise<() => void>;\n getTransactions: () => TransactionMeta[];\n hooks?: {\n beforeCheckPendingTransaction?: (\n transactionMeta: TransactionMeta,\n ) => Promise<boolean>;\n };\n isResubmitEnabled?: () => boolean;\n isTimeoutEnabled: (transactionMeta: TransactionMeta) => boolean;\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n publishTransaction: (transactionMeta: TransactionMeta) => Promise<string>;\n }) {\n this.hub = new EventEmitter() as PendingTransactionTrackerEventEmitter;\n\n const chainId = getChainId({ messenger, networkClientId });\n\n this.#chainId = chainId;\n this.#droppedBlockCountByHash = new Map();\n this.#getGlobalLock = getGlobalLock;\n this.#networkClientId = networkClientId;\n this.#getTransactions = getTransactions;\n this.#isResubmitEnabled = isResubmitEnabled ?? ((): boolean => true);\n this.#lastSeenTimestampByHash = new Map();\n this.#listener = this.#onLatestBlock.bind(this);\n this.#messenger = messenger;\n this.#publishTransaction = publishTransaction;\n this.#running = false;\n this.#transactionToForcePoll = undefined;\n\n this.#transactionPoller = new TransactionPoller({\n blockTracker,\n chainId,\n messenger,\n });\n\n this.#beforeCheckPendingTransaction =\n hooks?.beforeCheckPendingTransaction ??\n /* istanbul ignore next */\n ((): Promise<boolean> => Promise.resolve(true));\n\n this.#isTimeoutEnabled = isTimeoutEnabled;\n\n this.#log = createModuleLogger(log, `${chainId}:${networkClientId}`);\n }\n\n startIfPendingTransactions = (): void => {\n const pendingTransactions = this.#getPendingTransactions();\n\n if (pendingTransactions.length) {\n this.#start(pendingTransactions);\n } else {\n this.stop();\n }\n };\n\n /**\n * Adds a transaction to the polling mechanism for monitoring its status.\n *\n * This method forcefully adds a single transaction to the list of transactions\n * being polled, ensuring that its status is checked, event emitted but no update is performed.\n * It overrides the default behavior by prioritizing the given transaction for polling.\n *\n * @param transactionMeta - The transaction metadata to be added for polling.\n *\n * The transaction will now be monitored for updates, such as confirmation or failure.\n */\n addTransactionToPoll(transactionMeta: TransactionMeta): void {\n this.#start([transactionMeta]);\n this.#transactionToForcePoll = transactionMeta;\n }\n\n /**\n * Force checks the network if the given transaction is confirmed and updates it's status.\n *\n * @param txMeta - The transaction to check\n */\n async forceCheckTransaction(txMeta: TransactionMeta): Promise<void> {\n const releaseLock = await this.#getGlobalLock();\n\n try {\n await this.#checkTransaction(txMeta);\n } catch (error) {\n /* istanbul ignore next */\n this.#log('Failed to check transaction', error);\n } finally {\n releaseLock();\n }\n }\n\n #start(pendingTransactions: TransactionMeta[]): void {\n this.#transactionPoller.setPendingTransactions(pendingTransactions);\n\n if (this.#running) {\n return;\n }\n\n this.#transactionPoller.start(this.#listener);\n this.#running = true;\n\n this.#log('Started polling');\n }\n\n stop(): void {\n if (!this.#running) {\n return;\n }\n\n this.#transactionPoller.stop();\n this.#running = false;\n\n this.#log('Stopped polling');\n }\n\n async #onLatestBlock(latestBlockNumber: string): Promise<void> {\n const releaseLock = await this.#getGlobalLock();\n\n try {\n await this.#checkTransactions();\n } catch (error) {\n /* istanbul ignore next */\n this.#log('Failed to check transactions', error);\n } finally {\n releaseLock();\n }\n\n try {\n await this.#resubmitTransactions(latestBlockNumber);\n } catch (error) {\n /* istanbul ignore next */\n this.#log('Failed to resubmit transactions', error);\n }\n }\n\n async #checkTransactions(): Promise<void> {\n this.#log('Checking transactions');\n\n const pendingTransactions: TransactionMeta[] = [\n ...this.#getPendingTransactions(),\n ...(this.#transactionToForcePoll ? [this.#transactionToForcePoll] : []),\n ];\n\n if (!pendingTransactions.length) {\n this.#log('No pending transactions to check');\n return;\n }\n\n this.#log('Found pending transactions to check', {\n count: pendingTransactions.length,\n ids: pendingTransactions.map((tx) => tx.id),\n });\n\n await Promise.all(\n pendingTransactions.map((tx) => this.#checkTransaction(tx)),\n );\n }\n\n async #resubmitTransactions(latestBlockNumber: string): Promise<void> {\n if (!this.#isResubmitEnabled() || !this.#running) {\n return;\n }\n\n this.#log('Resubmitting transactions');\n\n const pendingTransactions = this.#getPendingTransactions();\n\n if (!pendingTransactions.length) {\n this.#log('No pending transactions to resubmit');\n return;\n }\n\n this.#log('Found pending transactions to resubmit', {\n count: pendingTransactions.length,\n ids: pendingTransactions.map((tx) => tx.id),\n });\n\n for (const txMeta of pendingTransactions) {\n try {\n await this.#resubmitTransaction(txMeta, latestBlockNumber);\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n /* istanbul ignore next */\n const errorMessage =\n error.value?.message?.toLowerCase() ??\n error.message?.toLowerCase() ??\n String(error);\n\n if (this.#isKnownTransactionError(errorMessage)) {\n this.#log('Ignoring known transaction error', errorMessage);\n continue;\n }\n\n this.#warnTransaction(\n txMeta,\n error.message,\n 'There was an error when resubmitting this transaction.',\n );\n }\n }\n }\n\n #isKnownTransactionError(errorMessage: string): boolean {\n return KNOWN_TRANSACTION_ERRORS.some((knownError) =>\n errorMessage.includes(knownError),\n );\n }\n\n async #resubmitTransaction(\n txMeta: TransactionMeta,\n latestBlockNumber: string,\n ): Promise<void> {\n if (!this.#isResubmitDue(txMeta, latestBlockNumber)) {\n return;\n }\n\n if (!(await this.#beforeCheckPendingTransaction(txMeta))) {\n return;\n }\n\n await this.#publishTransaction(txMeta);\n\n const retryCount = (txMeta.retryCount ?? 0) + 1;\n\n this.#updateTransaction(\n merge({}, txMeta, { retryCount }),\n 'PendingTransactionTracker:transaction-retry - Retry count increased',\n );\n }\n\n #isResubmitDue(txMeta: TransactionMeta, latestBlockNumber: string): boolean {\n const txMetaWithFirstRetryBlockNumber = cloneDeep(txMeta);\n\n if (!txMetaWithFirstRetryBlockNumber.firstRetryBlockNumber) {\n txMetaWithFirstRetryBlockNumber.firstRetryBlockNumber = latestBlockNumber;\n\n this.#updateTransaction(\n txMetaWithFirstRetryBlockNumber,\n 'PendingTransactionTracker:#isResubmitDue - First retry block number set',\n );\n }\n\n const { firstRetryBlockNumber } = txMetaWithFirstRetryBlockNumber;\n\n const blocksSinceFirstRetry =\n Number.parseInt(latestBlockNumber, 16) -\n Number.parseInt(firstRetryBlockNumber, 16);\n\n const retryCount = txMeta.retryCount ?? 0;\n\n // Exponential backoff to limit retries at publishing\n // Capped at ~15 minutes between retries\n const requiredBlocksSinceFirstRetry = Math.min(\n MAX_RETRY_BLOCK_DISTANCE,\n Math.pow(2, retryCount),\n );\n\n return blocksSinceFirstRetry >= requiredBlocksSinceFirstRetry;\n }\n\n #cleanTransaction(txMeta: TransactionMeta): void {\n const { hash, id } = txMeta;\n\n if (this.#transactionToForcePoll?.id === id) {\n this.#transactionToForcePoll = undefined;\n }\n\n if (hash) {\n this.#lastSeenTimestampByHash.delete(hash);\n }\n }\n\n async #checkTransaction(txMeta: TransactionMeta): Promise<void> {\n const {\n hash,\n id,\n isIntentComplete,\n txParams: { from },\n } = txMeta;\n\n if (isIntentComplete) {\n await this.#onTransactionConfirmed(txMeta);\n return;\n }\n\n if (!hash && (await this.#beforeCheckPendingTransaction(txMeta))) {\n const error = new Error(\n 'We had an error while submitting this transaction, please try again.',\n );\n\n error.name = 'NoTxHashError';\n\n this.#failTransaction(txMeta, error);\n\n return;\n }\n\n if (this.#isNonceTaken(txMeta)) {\n this.#log('Nonce already taken', id);\n this.#dropTransaction(txMeta);\n return;\n }\n\n try {\n const receipt = await this.#getTransactionReceipt(hash);\n const isSuccess = receipt?.status === RECEIPT_STATUS_SUCCESS;\n const isFailure = receipt?.status === RECEIPT_STATUS_FAILURE;\n\n if (isFailure) {\n this.#log('Transaction receipt has failed status');\n\n this.#failTransaction(txMeta, new Error('Transaction failed on-chain'));\n\n return;\n }\n\n const { blockNumber, blockHash } = receipt ?? {};\n\n if (isSuccess && blockNumber && blockHash) {\n await this.#onTransactionConfirmed(txMeta, {\n ...receipt,\n blockNumber,\n blockHash,\n });\n\n return;\n }\n\n this.#log('No receipt status', { hash, receipt });\n\n const nextNonceHex = await this.#getNetworkTransactionCount(from);\n const nextNonce = parseInt(nextNonceHex, 16);\n\n // Check if transaction should be failed due to no receipt\n if (!receipt && (await this.#isTransactionTimeout(txMeta, nextNonce))) {\n return;\n }\n\n if (await this.#isTransactionDropped(txMeta, nextNonce)) {\n this.#dropTransaction(txMeta);\n }\n } catch (error) {\n this.#log('Failed to check transaction', id, error);\n\n this.#warnTransaction(\n txMeta,\n (error as { message: string }).message,\n 'There was a problem loading this transaction.',\n );\n }\n }\n\n async #onTransactionConfirmed(\n txMeta: TransactionMeta,\n receipt?: SuccessfulTransactionReceipt,\n ): Promise<void> {\n const { id } = txMeta;\n const { blockHash } = receipt ?? {};\n\n this.#log('Transaction confirmed', id);\n\n const isForcePollTransaction = this.#transactionToForcePoll?.id === id;\n\n this.#cleanTransaction(txMeta);\n\n if (isForcePollTransaction) {\n this.hub.emit('transaction-confirmed', txMeta);\n return;\n }\n\n const updatedTxMeta = cloneDeep(txMeta);\n\n if (receipt && blockHash) {\n const { baseFeePerGas, timestamp: blockTimestamp } =\n await this.#getBlockByHash(blockHash, false);\n\n updatedTxMeta.baseFeePerGas = baseFeePerGas;\n updatedTxMeta.blockTimestamp = blockTimestamp;\n updatedTxMeta.txParams = {\n ...updatedTxMeta.txParams,\n gasUsed: receipt.gasUsed,\n };\n updatedTxMeta.txReceipt = receipt;\n updatedTxMeta.verifiedOnBlockchain = true;\n }\n\n updatedTxMeta.status = TransactionStatus.confirmed;\n\n this.#updateTransaction(\n updatedTxMeta,\n 'PendingTransactionTracker:#onTransactionConfirmed - Transaction confirmed',\n );\n\n this.hub.emit('transaction-confirmed', updatedTxMeta);\n }\n\n async #isTransactionTimeout(\n txMeta: TransactionMeta,\n nextNonce: number,\n ): Promise<boolean> {\n const {\n chainId,\n hash,\n id: transactionId,\n submittedTime,\n txParams: { nonce },\n } = txMeta;\n\n if (!hash || !nonce) {\n return false;\n }\n\n if (!this.#isTimeoutEnabled(txMeta)) {\n this.#log('Timeout disabled for transaction', txMeta);\n return false;\n }\n\n const threshold = getTimeoutAttempts(chainId, this.#messenger);\n\n // Feature is disabled if threshold is undefined or zero\n if (threshold === undefined || threshold === 0) {\n this.#log('Timeout disabled due to threshold', { chainId, threshold });\n return false;\n }\n\n // Skip timeout if this transaction's nonce is a queued transaction with a future nonce\n const nonceNumber = parseInt(nonce, 16);\n\n if (nonceNumber > nextNonce) {\n this.#log('Skipping timeout as queued transaction', {\n transactionNonce: nonceNumber,\n nextNonce,\n });\n return false;\n }\n\n try {\n // Check if transaction exists on the network\n const transaction = await this.#getTransactionByHash(hash);\n\n // If transaction exists, record the timestamp\n if (transaction !== null) {\n const currentTimestamp = Date.now();\n\n this.#log(\n 'Transaction found on network, recording timestamp',\n transactionId,\n );\n\n this.#lastSeenTimestampByHash.set(hash, currentTimestamp);\n return false;\n }\n\n const lastSeenTimestamp =\n this.#lastSeenTimestampByHash.get(hash) ?? submittedTime;\n\n if (lastSeenTimestamp === undefined) {\n this.#log(\n 'Transaction not yet seen on network and has no submitted time, skipping timeout check',\n transactionId,\n );\n\n return false;\n }\n\n const { blockTime } = getAcceleratedPollingParams(\n chainId,\n this.#messenger,\n );\n\n const currentTimestamp = Date.now();\n const durationSinceLastSeen = currentTimestamp - lastSeenTimestamp;\n const timeoutDuration = blockTime * threshold;\n\n this.#log('Checking timeout duration', {\n transactionId,\n durationSinceLastSeen,\n timeoutDuration,\n threshold,\n blockTime,\n });\n\n if (durationSinceLastSeen < timeoutDuration) {\n return false;\n }\n\n this.#log('Hit timeout duration threshold', transactionId);\n this.#lastSeenTimestampByHash.delete(hash);\n\n this.#failTransaction(\n txMeta,\n new Error('Transaction not found on network after timeout'),\n );\n\n return true;\n } catch (error) {\n this.#log('Failed to check transaction by hash', transactionId, error);\n return false;\n }\n }\n\n async #isTransactionDropped(\n txMeta: TransactionMeta,\n nextNonce: number,\n ): Promise<boolean> {\n const {\n hash,\n id,\n txParams: { nonce },\n } = txMeta;\n\n /* istanbul ignore next */\n if (!nonce || !hash) {\n return false;\n }\n\n const nonceNumber = parseInt(nonce, 16);\n\n if (nonceNumber >= nextNonce) {\n return false;\n }\n\n let droppedBlockCount = this.#droppedBlockCountByHash.get(hash);\n\n if (droppedBlockCount === undefined) {\n droppedBlockCount = 0;\n this.#droppedBlockCountByHash.set(hash, droppedBlockCount);\n }\n\n if (droppedBlockCount < DROPPED_BLOCK_COUNT) {\n this.#log('Incrementing dropped block count', { id, droppedBlockCount });\n this.#droppedBlockCountByHash.set(hash, droppedBlockCount + 1);\n return false;\n }\n\n this.#log('Hit dropped block count', id);\n\n this.#droppedBlockCountByHash.delete(hash);\n return true;\n }\n\n #isNonceTaken(txMeta: TransactionMeta): boolean {\n const { id, txParams } = txMeta;\n\n return this.#getChainTransactions().some(\n (tx) =>\n tx.id !== id &&\n tx.txParams.from === txParams.from &&\n tx.status === TransactionStatus.confirmed &&\n tx.txParams.nonce &&\n tx.txParams.nonce === txParams.nonce &&\n tx.type !== TransactionType.incoming &&\n tx.isTransfer === undefined,\n );\n }\n\n #getPendingTransactions(): TransactionMeta[] {\n return this.#getNetworkClientTransactions().filter(\n (tx) =>\n tx.status === TransactionStatus.submitted &&\n !tx.verifiedOnBlockchain &&\n !tx.isUserOperation &&\n !tx.isStateOnly,\n );\n }\n\n #warnTransaction(\n txMeta: TransactionMeta,\n error: string,\n message: string,\n ): void {\n this.#updateTransaction(\n {\n ...txMeta,\n warning: { error, message },\n },\n 'PendingTransactionTracker:#warnTransaction - Warning added',\n );\n }\n\n #failTransaction(txMeta: TransactionMeta, error: Error): void {\n this.#log('Transaction failed', txMeta.id, error);\n this.#cleanTransaction(txMeta);\n this.hub.emit('transaction-failed', txMeta, error);\n }\n\n #dropTransaction(txMeta: TransactionMeta): void {\n this.#log('Transaction dropped', txMeta.id);\n this.#cleanTransaction(txMeta);\n this.hub.emit('transaction-dropped', txMeta);\n }\n\n #updateTransaction(txMeta: TransactionMeta, note: string): void {\n this.hub.emit('transaction-updated', txMeta, note);\n }\n\n async #getTransactionReceipt(\n txHash?: string,\n ): Promise<TransactionReceipt | undefined> {\n return (await rpcRequest({\n messenger: this.#messenger,\n networkClientId: this.#networkClientId,\n method: 'eth_getTransactionReceipt',\n params: [txHash as string],\n })) as TransactionReceipt | undefined;\n }\n\n async #getTransactionByHash(txHash?: string): Promise<Json> {\n return (await rpcRequest({\n messenger: this.#messenger,\n networkClientId: this.#networkClientId,\n method: 'eth_getTransactionByHash',\n params: [txHash as string],\n })) as Json;\n }\n\n async #getBlockByHash(\n blockHash: string,\n includeTransactionDetails: boolean,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n return await rpcRequest({\n messenger: this.#messenger,\n networkClientId: this.#networkClientId,\n method: 'eth_getBlockByHash',\n params: [blockHash, includeTransactionDetails],\n });\n }\n\n async #getNetworkTransactionCount(address: string): Promise<string> {\n return (await rpcRequest({\n messenger: this.#messenger,\n networkClientId: this.#networkClientId,\n method: 'eth_getTransactionCount',\n params: [address, 'latest'],\n })) as string;\n }\n\n #getChainTransactions(): TransactionMeta[] {\n return this.#getTransactions().filter((tx) => tx.chainId === this.#chainId);\n }\n\n #getNetworkClientTransactions(): TransactionMeta[] {\n const networkClientId = this.#networkClientId;\n return this.#getTransactions().filter(\n (tx) => tx.networkClientId === networkClientId,\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PendingTransactionTracker.cjs","sourceRoot":"","sources":["../../src/helpers/PendingTransactionTracker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAKA,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAClC,mCAA0C;AAE1C,0CAA8D;AAG9D,wCAA8D;AAC9D,8DAGgC;AAChC,oDAA2D;AAC3D,8DAA4E;AAC5E,+DAAwD;AAExD;;;GAGG;AACH,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAE9B,MAAM,sBAAsB,GAAG,KAAK,CAAC;AACrC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AACrC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAEpC,MAAM,wBAAwB,GAAG;IAC/B,qCAAqC;IACrC,mBAAmB;IACnB,8BAA8B;IAC9B,qDAAqD;IACrD,iBAAiB;IACjB,eAAe;CAChB,CAAC;AAEF,MAAM,GAAG,GAAG,IAAA,2BAAkB,EAAC,sBAAa,EAAE,sBAAsB,CAAC,CAAC;AA6BtE,MAAa,yBAAyB;IAyCpC,YAAY,EACV,YAAY,EACZ,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,KAAK,EACL,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,kBAAkB,GAenB;;QA9DQ,2EAEa;QAEb,qEAA8C;QAE9C,8DAAiE;QAEjE,2DAA0C;QAE1C,qDAAiB;QAEjB,6DAAkC;QAElC,6DAA0C;QAE1C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oDAED,KAAK,0DAAuB,MAAe;IACzC,OAAO,CAAC,MAAM,IAAA,qBAAU,EAAC;QACvB,SAAS,EAAE,uBAAA,IAAI,4CAAW;QAC1B,eAAe,EAAE,uBAAA,IAAI,kDAAiB;QACtC,MAAM,EAAE,0BAA0B;QAClC,MAAM,EAAE,CAAC,MAAgB,CAAC;KAC3B,CAAC,CAAS,CAAC;AACd,CAAC,8CAED,KAAK,oDACH,SAAiB,EACjB,yBAAkC;IAIlC,OAAO,MAAM,IAAA,qBAAU,EAAC;QACtB,SAAS,EAAE,uBAAA,IAAI,4CAAW;QAC1B,eAAe,EAAE,uBAAA,IAAI,kDAAiB;QACtC,MAAM,EAAE,oBAAoB;QAC5B,MAAM,EAAE,CAAC,SAAS,EAAE,yBAAyB,CAAC;KAC/C,CAAC,CAAC;AACL,CAAC,0DAED,KAAK,gEAA6B,OAAe;IAC/C,OAAO,CAAC,MAAM,IAAA,qBAAU,EAAC;QACvB,SAAS,EAAE,uBAAA,IAAI,4CAAW;QAC1B,eAAe,EAAE,uBAAA,IAAI,kDAAiB;QACtC,MAAM,EAAE,yBAAyB;QACjC,MAAM,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;KAC5B,CAAC,CAAW,CAAC;AAChB,CAAC;IAGC,OAAO,uBAAA,IAAI,kDAAiB,MAArB,IAAI,CAAmB,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,KAAK,uBAAA,IAAI,0CAAS,CAAC,CAAC;AAC9E,CAAC;IAGC,MAAM,eAAe,GAAG,uBAAA,IAAI,kDAAiB,CAAC;IAC9C,OAAO,uBAAA,IAAI,kDAAiB,MAArB,IAAI,CAAmB,CAAC,MAAM,CACnC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,eAAe,KAAK,eAAe,CAC/C,CAAC;AACJ,CAAC","sourcesContent":["import type {\n BlockTracker,\n NetworkClientId,\n} from '@metamask/network-controller';\nimport type { Json } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\nimport { cloneDeep, merge } from 'lodash';\n\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type { TransactionMeta, TransactionReceipt } from '../types';\nimport { TransactionStatus, TransactionType } from '../types';\nimport {\n getAcceleratedPollingParams,\n getTimeoutAttempts,\n} from '../utils/feature-flags';\nimport { getChainId, rpcRequest } from '../utils/provider';\nimport { extractRevert, OnChainFailureError } from '../utils/revert-reason';\nimport { TransactionPoller } from './TransactionPoller';\n\n/**\n * We wait this many blocks before emitting a 'transaction-dropped' event\n * This is because we could be talking to a node that is out of sync\n */\nconst DROPPED_BLOCK_COUNT = 3;\n\nconst RECEIPT_STATUS_SUCCESS = '0x1';\nconst RECEIPT_STATUS_FAILURE = '0x0';\nconst MAX_RETRY_BLOCK_DISTANCE = 50;\n\nconst KNOWN_TRANSACTION_ERRORS = [\n 'replacement transaction underpriced',\n 'known transaction',\n 'gas price too low to replace',\n 'transaction with the same hash was already imported',\n 'gateway timeout',\n 'nonce too low',\n];\n\nconst log = createModuleLogger(projectLogger, 'pending-transactions');\n\ntype SuccessfulTransactionReceipt = TransactionReceipt & {\n blockNumber: string;\n blockHash: string;\n};\n\ntype Events = {\n 'transaction-confirmed': [txMeta: TransactionMeta];\n 'transaction-dropped': [txMeta: TransactionMeta];\n 'transaction-failed': [txMeta: TransactionMeta, error: Error];\n 'transaction-updated': [txMeta: TransactionMeta, note: string];\n};\n\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface PendingTransactionTrackerEventEmitter extends EventEmitter {\n on<EventName extends keyof Events>(\n eventName: EventName,\n listener: (...args: Events[EventName]) => void,\n ): this;\n\n emit<EventName extends keyof Events>(\n eventName: EventName,\n ...args: Events[EventName]\n ): boolean;\n}\n\nexport class PendingTransactionTracker {\n hub: PendingTransactionTrackerEventEmitter;\n\n readonly #beforeCheckPendingTransaction: (\n transactionMeta: TransactionMeta,\n ) => Promise<boolean>;\n\n readonly #droppedBlockCountByHash: Map<string, number>;\n\n readonly #isTimeoutEnabled: (transactionMeta: TransactionMeta) => boolean;\n\n readonly #getGlobalLock: () => Promise<() => void>;\n\n readonly #chainId: string;\n\n readonly #networkClientId: NetworkClientId;\n\n readonly #getTransactions: () => TransactionMeta[];\n\n readonly #isResubmitEnabled: () => boolean;\n\n readonly #lastSeenTimestampByHash: Map<string, number>;\n\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n readonly #listener: any;\n\n readonly #log: debug.Debugger;\n\n readonly #messenger: TransactionControllerMessenger;\n\n readonly #publishTransaction: (\n transactionMeta: TransactionMeta,\n ) => Promise<string>;\n\n #running: boolean;\n\n readonly #transactionPoller: TransactionPoller;\n\n #transactionToForcePoll: TransactionMeta | undefined;\n\n constructor({\n blockTracker,\n getGlobalLock,\n getTransactions,\n isTimeoutEnabled,\n hooks,\n isResubmitEnabled,\n messenger,\n networkClientId,\n publishTransaction,\n }: {\n blockTracker: BlockTracker;\n getGlobalLock: () => Promise<() => void>;\n getTransactions: () => TransactionMeta[];\n hooks?: {\n beforeCheckPendingTransaction?: (\n transactionMeta: TransactionMeta,\n ) => Promise<boolean>;\n };\n isResubmitEnabled?: () => boolean;\n isTimeoutEnabled: (transactionMeta: TransactionMeta) => boolean;\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n publishTransaction: (transactionMeta: TransactionMeta) => Promise<string>;\n }) {\n this.hub = new EventEmitter() as PendingTransactionTrackerEventEmitter;\n\n const chainId = getChainId({ messenger, networkClientId });\n\n this.#chainId = chainId;\n this.#droppedBlockCountByHash = new Map();\n this.#getGlobalLock = getGlobalLock;\n this.#networkClientId = networkClientId;\n this.#getTransactions = getTransactions;\n this.#isResubmitEnabled = isResubmitEnabled ?? ((): boolean => true);\n this.#lastSeenTimestampByHash = new Map();\n this.#listener = this.#onLatestBlock.bind(this);\n this.#messenger = messenger;\n this.#publishTransaction = publishTransaction;\n this.#running = false;\n this.#transactionToForcePoll = undefined;\n\n this.#transactionPoller = new TransactionPoller({\n blockTracker,\n chainId,\n messenger,\n });\n\n this.#beforeCheckPendingTransaction =\n hooks?.beforeCheckPendingTransaction ??\n /* istanbul ignore next */\n ((): Promise<boolean> => Promise.resolve(true));\n\n this.#isTimeoutEnabled = isTimeoutEnabled;\n\n this.#log = createModuleLogger(log, `${chainId}:${networkClientId}`);\n }\n\n startIfPendingTransactions = (): void => {\n const pendingTransactions = this.#getPendingTransactions();\n\n if (pendingTransactions.length) {\n this.#start(pendingTransactions);\n } else {\n this.stop();\n }\n };\n\n /**\n * Adds a transaction to the polling mechanism for monitoring its status.\n *\n * This method forcefully adds a single transaction to the list of transactions\n * being polled, ensuring that its status is checked, event emitted but no update is performed.\n * It overrides the default behavior by prioritizing the given transaction for polling.\n *\n * @param transactionMeta - The transaction metadata to be added for polling.\n *\n * The transaction will now be monitored for updates, such as confirmation or failure.\n */\n addTransactionToPoll(transactionMeta: TransactionMeta): void {\n this.#start([transactionMeta]);\n this.#transactionToForcePoll = transactionMeta;\n }\n\n /**\n * Force checks the network if the given transaction is confirmed and updates it's status.\n *\n * @param txMeta - The transaction to check\n */\n async forceCheckTransaction(txMeta: TransactionMeta): Promise<void> {\n const releaseLock = await this.#getGlobalLock();\n\n try {\n await this.#checkTransaction(txMeta);\n } catch (error) {\n /* istanbul ignore next */\n this.#log('Failed to check transaction', error);\n } finally {\n releaseLock();\n }\n }\n\n #start(pendingTransactions: TransactionMeta[]): void {\n this.#transactionPoller.setPendingTransactions(pendingTransactions);\n\n if (this.#running) {\n return;\n }\n\n this.#transactionPoller.start(this.#listener);\n this.#running = true;\n\n this.#log('Started polling');\n }\n\n stop(): void {\n if (!this.#running) {\n return;\n }\n\n this.#transactionPoller.stop();\n this.#running = false;\n\n this.#log('Stopped polling');\n }\n\n async #onLatestBlock(latestBlockNumber: string): Promise<void> {\n const releaseLock = await this.#getGlobalLock();\n\n try {\n await this.#checkTransactions();\n } catch (error) {\n /* istanbul ignore next */\n this.#log('Failed to check transactions', error);\n } finally {\n releaseLock();\n }\n\n try {\n await this.#resubmitTransactions(latestBlockNumber);\n } catch (error) {\n /* istanbul ignore next */\n this.#log('Failed to resubmit transactions', error);\n }\n }\n\n async #checkTransactions(): Promise<void> {\n this.#log('Checking transactions');\n\n const pendingTransactions: TransactionMeta[] = [\n ...this.#getPendingTransactions(),\n ...(this.#transactionToForcePoll ? [this.#transactionToForcePoll] : []),\n ];\n\n if (!pendingTransactions.length) {\n this.#log('No pending transactions to check');\n return;\n }\n\n this.#log('Found pending transactions to check', {\n count: pendingTransactions.length,\n ids: pendingTransactions.map((tx) => tx.id),\n });\n\n await Promise.all(\n pendingTransactions.map((tx) => this.#checkTransaction(tx)),\n );\n }\n\n async #resubmitTransactions(latestBlockNumber: string): Promise<void> {\n if (!this.#isResubmitEnabled() || !this.#running) {\n return;\n }\n\n this.#log('Resubmitting transactions');\n\n const pendingTransactions = this.#getPendingTransactions();\n\n if (!pendingTransactions.length) {\n this.#log('No pending transactions to resubmit');\n return;\n }\n\n this.#log('Found pending transactions to resubmit', {\n count: pendingTransactions.length,\n ids: pendingTransactions.map((tx) => tx.id),\n });\n\n for (const txMeta of pendingTransactions) {\n try {\n await this.#resubmitTransaction(txMeta, latestBlockNumber);\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n /* istanbul ignore next */\n const errorMessage =\n error.value?.message?.toLowerCase() ??\n error.message?.toLowerCase() ??\n String(error);\n\n if (this.#isKnownTransactionError(errorMessage)) {\n this.#log('Ignoring known transaction error', errorMessage);\n continue;\n }\n\n this.#warnTransaction(\n txMeta,\n error.message,\n 'There was an error when resubmitting this transaction.',\n );\n }\n }\n }\n\n #isKnownTransactionError(errorMessage: string): boolean {\n return KNOWN_TRANSACTION_ERRORS.some((knownError) =>\n errorMessage.includes(knownError),\n );\n }\n\n async #resubmitTransaction(\n txMeta: TransactionMeta,\n latestBlockNumber: string,\n ): Promise<void> {\n if (!this.#isResubmitDue(txMeta, latestBlockNumber)) {\n return;\n }\n\n if (!(await this.#beforeCheckPendingTransaction(txMeta))) {\n return;\n }\n\n await this.#publishTransaction(txMeta);\n\n const retryCount = (txMeta.retryCount ?? 0) + 1;\n\n this.#updateTransaction(\n merge({}, txMeta, { retryCount }),\n 'PendingTransactionTracker:transaction-retry - Retry count increased',\n );\n }\n\n #isResubmitDue(txMeta: TransactionMeta, latestBlockNumber: string): boolean {\n const txMetaWithFirstRetryBlockNumber = cloneDeep(txMeta);\n\n if (!txMetaWithFirstRetryBlockNumber.firstRetryBlockNumber) {\n txMetaWithFirstRetryBlockNumber.firstRetryBlockNumber = latestBlockNumber;\n\n this.#updateTransaction(\n txMetaWithFirstRetryBlockNumber,\n 'PendingTransactionTracker:#isResubmitDue - First retry block number set',\n );\n }\n\n const { firstRetryBlockNumber } = txMetaWithFirstRetryBlockNumber;\n\n const blocksSinceFirstRetry =\n Number.parseInt(latestBlockNumber, 16) -\n Number.parseInt(firstRetryBlockNumber, 16);\n\n const retryCount = txMeta.retryCount ?? 0;\n\n // Exponential backoff to limit retries at publishing\n // Capped at ~15 minutes between retries\n const requiredBlocksSinceFirstRetry = Math.min(\n MAX_RETRY_BLOCK_DISTANCE,\n Math.pow(2, retryCount),\n );\n\n return blocksSinceFirstRetry >= requiredBlocksSinceFirstRetry;\n }\n\n #cleanTransaction(txMeta: TransactionMeta): void {\n const { hash, id } = txMeta;\n\n if (this.#transactionToForcePoll?.id === id) {\n this.#transactionToForcePoll = undefined;\n }\n\n if (hash) {\n this.#lastSeenTimestampByHash.delete(hash);\n }\n }\n\n async #checkTransaction(txMeta: TransactionMeta): Promise<void> {\n const {\n hash,\n id,\n isIntentComplete,\n txParams: { from },\n } = txMeta;\n\n if (isIntentComplete) {\n await this.#onTransactionConfirmed(txMeta);\n return;\n }\n\n if (!hash && (await this.#beforeCheckPendingTransaction(txMeta))) {\n const error = new Error(\n 'We had an error while submitting this transaction, please try again.',\n );\n\n error.name = 'NoTxHashError';\n\n this.#failTransaction(txMeta, error);\n\n return;\n }\n\n if (this.#isNonceTaken(txMeta)) {\n this.#log('Nonce already taken', id);\n this.#dropTransaction(txMeta);\n return;\n }\n\n try {\n const receipt = await this.#getTransactionReceipt(hash);\n const isSuccess = receipt?.status === RECEIPT_STATUS_SUCCESS;\n const isFailure = receipt?.status === RECEIPT_STATUS_FAILURE;\n\n if (isFailure) {\n this.#log('Transaction receipt has failed status', {\n id: txMeta.id,\n hash: txMeta.hash,\n chainId: txMeta.chainId,\n blockNumber: receipt.blockNumber,\n });\n\n const revert = await extractRevert({\n messenger: this.#messenger,\n networkClientId: txMeta.networkClientId,\n txParams: txMeta.txParams,\n });\n\n this.#failTransaction(txMeta, new OnChainFailureError(revert));\n\n return;\n }\n\n const { blockNumber, blockHash } = receipt ?? {};\n\n if (isSuccess && blockNumber && blockHash) {\n await this.#onTransactionConfirmed(txMeta, {\n ...receipt,\n blockNumber,\n blockHash,\n });\n\n return;\n }\n\n this.#log('No receipt status', { hash, receipt });\n\n const nextNonceHex = await this.#getNetworkTransactionCount(from);\n const nextNonce = parseInt(nextNonceHex, 16);\n\n // Check if transaction should be failed due to no receipt\n if (!receipt && (await this.#isTransactionTimeout(txMeta, nextNonce))) {\n return;\n }\n\n if (await this.#isTransactionDropped(txMeta, nextNonce)) {\n this.#dropTransaction(txMeta);\n }\n } catch (error) {\n this.#log('Failed to check transaction', id, error);\n\n this.#warnTransaction(\n txMeta,\n (error as { message: string }).message,\n 'There was a problem loading this transaction.',\n );\n }\n }\n\n async #onTransactionConfirmed(\n txMeta: TransactionMeta,\n receipt?: SuccessfulTransactionReceipt,\n ): Promise<void> {\n const { id } = txMeta;\n const { blockHash } = receipt ?? {};\n\n this.#log('Transaction confirmed', id);\n\n const isForcePollTransaction = this.#transactionToForcePoll?.id === id;\n\n this.#cleanTransaction(txMeta);\n\n if (isForcePollTransaction) {\n this.hub.emit('transaction-confirmed', txMeta);\n return;\n }\n\n const updatedTxMeta = cloneDeep(txMeta);\n\n if (receipt && blockHash) {\n const { baseFeePerGas, timestamp: blockTimestamp } =\n await this.#getBlockByHash(blockHash, false);\n\n updatedTxMeta.baseFeePerGas = baseFeePerGas;\n updatedTxMeta.blockTimestamp = blockTimestamp;\n updatedTxMeta.txParams = {\n ...updatedTxMeta.txParams,\n gasUsed: receipt.gasUsed,\n };\n updatedTxMeta.txReceipt = receipt;\n updatedTxMeta.verifiedOnBlockchain = true;\n }\n\n updatedTxMeta.status = TransactionStatus.confirmed;\n\n this.#updateTransaction(\n updatedTxMeta,\n 'PendingTransactionTracker:#onTransactionConfirmed - Transaction confirmed',\n );\n\n this.hub.emit('transaction-confirmed', updatedTxMeta);\n }\n\n async #isTransactionTimeout(\n txMeta: TransactionMeta,\n nextNonce: number,\n ): Promise<boolean> {\n const {\n chainId,\n hash,\n id: transactionId,\n submittedTime,\n txParams: { nonce },\n } = txMeta;\n\n if (!hash || !nonce) {\n return false;\n }\n\n if (!this.#isTimeoutEnabled(txMeta)) {\n this.#log('Timeout disabled for transaction', txMeta);\n return false;\n }\n\n const threshold = getTimeoutAttempts(chainId, this.#messenger);\n\n // Feature is disabled if threshold is undefined or zero\n if (threshold === undefined || threshold === 0) {\n this.#log('Timeout disabled due to threshold', { chainId, threshold });\n return false;\n }\n\n // Skip timeout if this transaction's nonce is a queued transaction with a future nonce\n const nonceNumber = parseInt(nonce, 16);\n\n if (nonceNumber > nextNonce) {\n this.#log('Skipping timeout as queued transaction', {\n transactionNonce: nonceNumber,\n nextNonce,\n });\n return false;\n }\n\n try {\n // Check if transaction exists on the network\n const transaction = await this.#getTransactionByHash(hash);\n\n // If transaction exists, record the timestamp\n if (transaction !== null) {\n const currentTimestamp = Date.now();\n\n this.#log(\n 'Transaction found on network, recording timestamp',\n transactionId,\n );\n\n this.#lastSeenTimestampByHash.set(hash, currentTimestamp);\n return false;\n }\n\n const lastSeenTimestamp =\n this.#lastSeenTimestampByHash.get(hash) ?? submittedTime;\n\n if (lastSeenTimestamp === undefined) {\n this.#log(\n 'Transaction not yet seen on network and has no submitted time, skipping timeout check',\n transactionId,\n );\n\n return false;\n }\n\n const { blockTime } = getAcceleratedPollingParams(\n chainId,\n this.#messenger,\n );\n\n const currentTimestamp = Date.now();\n const durationSinceLastSeen = currentTimestamp - lastSeenTimestamp;\n const timeoutDuration = blockTime * threshold;\n\n this.#log('Checking timeout duration', {\n transactionId,\n durationSinceLastSeen,\n timeoutDuration,\n threshold,\n blockTime,\n });\n\n if (durationSinceLastSeen < timeoutDuration) {\n return false;\n }\n\n this.#log('Hit timeout duration threshold', transactionId);\n this.#lastSeenTimestampByHash.delete(hash);\n\n this.#failTransaction(\n txMeta,\n new Error('Transaction not found on network after timeout'),\n );\n\n return true;\n } catch (error) {\n this.#log('Failed to check transaction by hash', transactionId, error);\n return false;\n }\n }\n\n async #isTransactionDropped(\n txMeta: TransactionMeta,\n nextNonce: number,\n ): Promise<boolean> {\n const {\n hash,\n id,\n txParams: { nonce },\n } = txMeta;\n\n /* istanbul ignore next */\n if (!nonce || !hash) {\n return false;\n }\n\n const nonceNumber = parseInt(nonce, 16);\n\n if (nonceNumber >= nextNonce) {\n return false;\n }\n\n let droppedBlockCount = this.#droppedBlockCountByHash.get(hash);\n\n if (droppedBlockCount === undefined) {\n droppedBlockCount = 0;\n this.#droppedBlockCountByHash.set(hash, droppedBlockCount);\n }\n\n if (droppedBlockCount < DROPPED_BLOCK_COUNT) {\n this.#log('Incrementing dropped block count', { id, droppedBlockCount });\n this.#droppedBlockCountByHash.set(hash, droppedBlockCount + 1);\n return false;\n }\n\n this.#log('Hit dropped block count', id);\n\n this.#droppedBlockCountByHash.delete(hash);\n return true;\n }\n\n #isNonceTaken(txMeta: TransactionMeta): boolean {\n const { id, txParams } = txMeta;\n\n return this.#getChainTransactions().some(\n (tx) =>\n tx.id !== id &&\n tx.txParams.from === txParams.from &&\n tx.status === TransactionStatus.confirmed &&\n tx.txParams.nonce &&\n tx.txParams.nonce === txParams.nonce &&\n tx.type !== TransactionType.incoming &&\n tx.isTransfer === undefined,\n );\n }\n\n #getPendingTransactions(): TransactionMeta[] {\n return this.#getNetworkClientTransactions().filter(\n (tx) =>\n tx.status === TransactionStatus.submitted &&\n !tx.verifiedOnBlockchain &&\n !tx.isUserOperation &&\n !tx.isStateOnly,\n );\n }\n\n #warnTransaction(\n txMeta: TransactionMeta,\n error: string,\n message: string,\n ): void {\n this.#updateTransaction(\n {\n ...txMeta,\n warning: { error, message },\n },\n 'PendingTransactionTracker:#warnTransaction - Warning added',\n );\n }\n\n #failTransaction(txMeta: TransactionMeta, error: Error): void {\n this.#log('Transaction failed', txMeta.id, error);\n this.#cleanTransaction(txMeta);\n this.hub.emit('transaction-failed', txMeta, error);\n }\n\n #dropTransaction(txMeta: TransactionMeta): void {\n this.#log('Transaction dropped', txMeta.id);\n this.#cleanTransaction(txMeta);\n this.hub.emit('transaction-dropped', txMeta);\n }\n\n #updateTransaction(txMeta: TransactionMeta, note: string): void {\n this.hub.emit('transaction-updated', txMeta, note);\n }\n\n async #getTransactionReceipt(\n txHash?: string,\n ): Promise<TransactionReceipt | undefined> {\n return (await rpcRequest({\n messenger: this.#messenger,\n networkClientId: this.#networkClientId,\n method: 'eth_getTransactionReceipt',\n params: [txHash as string],\n })) as TransactionReceipt | undefined;\n }\n\n async #getTransactionByHash(txHash?: string): Promise<Json> {\n return (await rpcRequest({\n messenger: this.#messenger,\n networkClientId: this.#networkClientId,\n method: 'eth_getTransactionByHash',\n params: [txHash as string],\n })) as Json;\n }\n\n async #getBlockByHash(\n blockHash: string,\n includeTransactionDetails: boolean,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n return await rpcRequest({\n messenger: this.#messenger,\n networkClientId: this.#networkClientId,\n method: 'eth_getBlockByHash',\n params: [blockHash, includeTransactionDetails],\n });\n }\n\n async #getNetworkTransactionCount(address: string): Promise<string> {\n return (await rpcRequest({\n messenger: this.#messenger,\n networkClientId: this.#networkClientId,\n method: 'eth_getTransactionCount',\n params: [address, 'latest'],\n })) as string;\n }\n\n #getChainTransactions(): TransactionMeta[] {\n return this.#getTransactions().filter((tx) => tx.chainId === this.#chainId);\n }\n\n #getNetworkClientTransactions(): TransactionMeta[] {\n const networkClientId = this.#networkClientId;\n return this.#getTransactions().filter(\n (tx) => tx.networkClientId === networkClientId,\n );\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PendingTransactionTracker.d.cts","sourceRoot":"","sources":["../../src/helpers/PendingTransactionTracker.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EAChB,qCAAqC;AAItC,OAAO,YAAY,eAAe;AAIlC,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAsB,qBAAiB;
|
|
1
|
+
{"version":3,"file":"PendingTransactionTracker.d.cts","sourceRoot":"","sources":["../../src/helpers/PendingTransactionTracker.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EAChB,qCAAqC;AAItC,OAAO,YAAY,eAAe;AAIlC,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAsB,qBAAiB;AAoCpE,KAAK,MAAM,GAAG;IACZ,uBAAuB,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACnD,qBAAqB,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACjD,oBAAoB,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAC9D,qBAAqB,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;CAChE,CAAC;AAKF,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E,IAAI,IAAI,IAAI;CA6iBb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PendingTransactionTracker.d.mts","sourceRoot":"","sources":["../../src/helpers/PendingTransactionTracker.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EAChB,qCAAqC;AAItC,OAAO,YAAY,eAAe;AAIlC,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAsB,qBAAiB;
|
|
1
|
+
{"version":3,"file":"PendingTransactionTracker.d.mts","sourceRoot":"","sources":["../../src/helpers/PendingTransactionTracker.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EAChB,qCAAqC;AAItC,OAAO,YAAY,eAAe;AAIlC,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAsB,qBAAiB;AAoCpE,KAAK,MAAM,GAAG;IACZ,uBAAuB,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACnD,qBAAqB,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACjD,oBAAoB,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAC9D,qBAAqB,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;CAChE,CAAC;AAKF,MAAM,WAAW,qCAAsC,SAAQ,YAAY;IACzE,EAAE,CAAC,SAAS,SAAS,MAAM,MAAM,EAC/B,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,IAAI,GAC7C,IAAI,CAAC;IAER,IAAI,CAAC,SAAS,SAAS,MAAM,MAAM,EACjC,SAAS,EAAE,SAAS,EACpB,GAAG,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,GACzB,OAAO,CAAC;CACZ;AAED,qBAAa,yBAAyB;;IACpC,GAAG,EAAE,qCAAqC,CAAC;gBAwC/B,EACV,YAAY,EACZ,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,KAAK,EACL,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,kBAAkB,GACnB,EAAE;QACD,YAAY,EAAE,YAAY,CAAC;QAC3B,aAAa,EAAE,MAAM,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;QACzC,eAAe,EAAE,MAAM,eAAe,EAAE,CAAC;QACzC,KAAK,CAAC,EAAE;YACN,6BAA6B,CAAC,EAAE,CAC9B,eAAe,EAAE,eAAe,KAC7B,OAAO,CAAC,OAAO,CAAC,CAAC;SACvB,CAAC;QACF,iBAAiB,CAAC,EAAE,MAAM,OAAO,CAAC;QAClC,gBAAgB,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,OAAO,CAAC;QAChE,SAAS,EAAE,8BAA8B,CAAC;QAC1C,eAAe,EAAE,eAAe,CAAC;QACjC,kBAAkB,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;KAC3E;IAkCD,0BAA0B,QAAO,IAAI,CAQnC;IAEF;;;;;;;;;;OAUG;IACH,oBAAoB,CAAC,eAAe,EAAE,eAAe,GAAG,IAAI;IAK5D;;;;OAIG;IACG,qBAAqB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BnE,IAAI,IAAI,IAAI;CA6iBb"}
|
|
@@ -19,6 +19,7 @@ import { createModuleLogger, projectLogger } from "../logger.mjs";
|
|
|
19
19
|
import { TransactionStatus, TransactionType } from "../types.mjs";
|
|
20
20
|
import { getAcceleratedPollingParams, getTimeoutAttempts } from "../utils/feature-flags.mjs";
|
|
21
21
|
import { getChainId, rpcRequest } from "../utils/provider.mjs";
|
|
22
|
+
import { extractRevert, OnChainFailureError } from "../utils/revert-reason.mjs";
|
|
22
23
|
import { TransactionPoller } from "./TransactionPoller.mjs";
|
|
23
24
|
/**
|
|
24
25
|
* We wait this many blocks before emitting a 'transaction-dropped' event
|
|
@@ -264,8 +265,18 @@ _PendingTransactionTracker_beforeCheckPendingTransaction = new WeakMap(), _Pendi
|
|
|
264
265
|
const isSuccess = receipt?.status === RECEIPT_STATUS_SUCCESS;
|
|
265
266
|
const isFailure = receipt?.status === RECEIPT_STATUS_FAILURE;
|
|
266
267
|
if (isFailure) {
|
|
267
|
-
__classPrivateFieldGet(this, _PendingTransactionTracker_log, "f").call(this, 'Transaction receipt has failed status'
|
|
268
|
-
|
|
268
|
+
__classPrivateFieldGet(this, _PendingTransactionTracker_log, "f").call(this, 'Transaction receipt has failed status', {
|
|
269
|
+
id: txMeta.id,
|
|
270
|
+
hash: txMeta.hash,
|
|
271
|
+
chainId: txMeta.chainId,
|
|
272
|
+
blockNumber: receipt.blockNumber,
|
|
273
|
+
});
|
|
274
|
+
const revert = await extractRevert({
|
|
275
|
+
messenger: __classPrivateFieldGet(this, _PendingTransactionTracker_messenger, "f"),
|
|
276
|
+
networkClientId: txMeta.networkClientId,
|
|
277
|
+
txParams: txMeta.txParams,
|
|
278
|
+
});
|
|
279
|
+
__classPrivateFieldGet(this, _PendingTransactionTracker_instances, "m", _PendingTransactionTracker_failTransaction).call(this, txMeta, new OnChainFailureError(revert));
|
|
269
280
|
return;
|
|
270
281
|
}
|
|
271
282
|
const { blockNumber, blockHash } = receipt ?? {};
|