@metamask-previews/transaction-controller 72.0.1-preview-0f8c056e2 → 72.1.0-preview-0305ce0

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 CHANGED
@@ -9,9 +9,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Changed
11
11
 
12
+ - Bump `@metamask/network-controller` from `^37.0.0` to `^37.0.1` ([#10658](https://github.com/MetaMask/core/pull/10658))
13
+ - Bump `@metamask/core-backend` from `^12.0.0` to `^12.0.1` ([#10662](https://github.com/MetaMask/core/pull/10662))
14
+
15
+ ## [72.1.0]
16
+
17
+ ### Changed
18
+
19
+ - Include a `RedeemerEnforcer` caveat in EIP-7702 gas fee token simulations via `suggestFees.withRedeemerEnforcer` ([#10615](https://github.com/MetaMask/core/pull/10615))
20
+
12
21
  - Bump `ethereum-cryptography` from `^2.1.2` to `^2.2.1` ([#10485](https://github.com/MetaMask/core/pull/10485))
13
22
  - Bump `lodash-es` from `^4.17.21` to `^4.18.1` ([#10447](https://github.com/MetaMask/core/pull/10447))
14
23
  - Bump `@ethersproject/wallet` from `^5.7.0` to `^5.8.0` ([#10484](https://github.com/MetaMask/core/pull/10484))
24
+ - Bump `@metamask/core-backend` from `^11.0.0` to `^12.0.0` ([#10648](https://github.com/MetaMask/core/pull/10648))
15
25
 
16
26
  ## [72.0.1]
17
27
 
@@ -2802,7 +2812,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2802
2812
 
2803
2813
  All changes listed after this point were applied to this package following the monorepo conversion.
2804
2814
 
2805
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@72.0.1...HEAD
2815
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@72.1.0...HEAD
2816
+ [72.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@72.0.1...@metamask/transaction-controller@72.1.0
2806
2817
  [72.0.1]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@72.0.0...@metamask/transaction-controller@72.0.1
2807
2818
  [72.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@71.0.0...@metamask/transaction-controller@72.0.0
2808
2819
  [71.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@70.1.0...@metamask/transaction-controller@71.0.0
@@ -51,6 +51,7 @@ export type SimulationRequest = {
51
51
  suggestFees?: {
52
52
  with7702?: boolean;
53
53
  withFeeTransfer?: boolean;
54
+ withRedeemerEnforcer?: boolean;
54
55
  withTransfer?: boolean;
55
56
  };
56
57
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"simulation-api.d.ts","sourceRoot":"","sources":["../../src/api/simulation-api.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAY3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAQvD,mEAAmE;AACnE,MAAM,MAAM,4BAA4B,GAAG;IACzC,iBAAiB,CAAC,EAAE;QAClB,oEAAoE;QACpE,OAAO,EAAE,GAAG,CAAC;QAEb,6CAA6C;QAC7C,IAAI,EAAE,GAAG,CAAC;KACX,EAAE,CAAC;IAEJ,yCAAyC;IACzC,IAAI,CAAC,EAAE,GAAG,CAAC;IAEX,iCAAiC;IACjC,IAAI,EAAE,GAAG,CAAC;IAEV,qCAAqC;IACrC,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,+CAA+C;IAC/C,YAAY,CAAC,EAAE,GAAG,CAAC;IAEnB,wDAAwD;IACxD,oBAAoB,CAAC,EAAE,GAAG,CAAC;IAE3B,oCAAoC;IACpC,EAAE,CAAC,EAAE,GAAG,CAAC;IAET,0CAA0C;IAC1C,KAAK,CAAC,EAAE,GAAG,CAAC;CACb,CAAC;AAEF,8DAA8D;AAC9D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,CAAC,EAAE;QACf,IAAI,C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M,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACH,SAAS,MAAM,CAAC,SAAiB;IAC/B,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,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-es';\n\nimport {\n CODE_DELEGATION_MANAGER_NO_SIGNATURE_ERRORS,\n DELEGATION_MANAGER_ADDRESSES,\n} from '../constants.js';\nimport {\n SimulationChainNotSupportedError,\n SimulationError,\n} from '../errors.js';\nimport { projectLogger } from '../logger.js';\nimport type { GetSimulationConfig } from '../types.js';\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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;IAC3B,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,kBAAkB,CAAC,GAAG,iBAAiB,EAAE,CAAC;IAChE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACH,SAAS,MAAM,CAAC,SAAiB;IAC/B,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,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-es';\n\nimport {\n CODE_DELEGATION_MANAGER_NO_SIGNATURE_ERRORS,\n DELEGATION_MANAGER_ADDRESSES,\n} from '../constants.js';\nimport {\n SimulationChainNotSupportedError,\n SimulationError,\n} from '../errors.js';\nimport { projectLogger } from '../logger.js';\nimport type { GetSimulationConfig } from '../types.js';\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 /*\n * Whether to include a RedeemerEnforcer caveat, restricting redemption to\n * the relay signers, in the delegation used for the EIP-7702 estimate.\n */\n withRedeemerEnforcer?: 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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"gas-fee-tokens.d.ts","sourceRoot":"","sources":["../../src/utils/gas-fee-tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEpE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAS3C,OAAO,KAAK,EACV,WAAW,EACX,8BAA8B,EAC9B,eAAe,EAChB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAQvD,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,GAAG,CAAC;IACb,4BAA4B,EAAE,CAC5B,eAAe,EAAE,eAAe,KAC7B,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,SAAS,EAAE,8BAA8B,CAAC;IAC1C,gBAAgB,CAAC,EAAE,GAAG,CAAC;IACvB,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CAAC,EACpC,OAAO,EACP,4BAA4B,EAC5B,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,mBAAmB,GACpB,EAAE,sBAAsB,GAAG,OAAO,CAAC;IAClC,YAAY,EAAE,WAAW,EAAE,CAAC;IAC5B,iBAAiB,EAAE,OAAO,CAAC;CAC5B,CAAC,CA8DD;AAED;;;;;;;;;GASG;AACH,wBAAsB,6BAA6B,CAAC,EAClD,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,iBAAiB,GACl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AAC,CAiED;AAED;;;;;;;;;GASG;AACH,wBAAsB,6BAA6B,CAAC,EAClD,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,iBAAiB,GAClB,EAAE;IACD,SAAS,EAAE,8BAA8B,CAAC;IAC1C,eAAe,EAAE,eAAe,CAAC;IACjC,iBAAiB,EAAE,CAAC,WAAW,EAAE,eAAe,KAAK,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC5E,WAAW,EAAE,eAAe,CAAC;IAC7B,iBAAiB,EAAE,CACjB,aAAa,EAAE,MAAM,EACrB,EAAE,EAAE,CAAC,EAAE,EAAE,eAAe,KAAK,IAAI,KAC9B,IAAI,CAAC;CACX,GAAG,OAAO,CAAC,IAAI,CAAC,CAgEhB"}
@@ -57,6 +57,9 @@ export async function getGasFeeTokens({ chainId, isEIP7702GasFeeTokensEnabled, m
57
57
  withTransfer: true,
58
58
  withFeeTransfer: true,
59
59
  with7702,
60
+ // The EIP-7702 publish hook always restricts redemption to the relay
61
+ // signers via a RedeemerEnforcer caveat, so include it in the estimate.
62
+ withRedeemerEnforcer: with7702,
60
63
  },
61
64
  });
62
65
  log('Response', response);
@@ -1 +1 @@
1
- {"version":3,"file":"gas-fee-tokens.js","sourceRoot":"","sources":["../../src/utils/gas-fee-tokens.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAWhE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,iCAAiC,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,gCAAgC,EAAE,M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AC;AACJ,CAAC","sourcesContent":["import type { NetworkClientId } from '@metamask/network-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { simulateTransactions } from '../api/simulation-api.js';\nimport type { SimulationRequestTransaction } from '../api/simulation-api.js';\nimport type {\n SimulationResponse,\n SimulationResponseTransaction,\n} from '../api/simulation-api.js';\nimport type {\n GasFeeToken,\n TransactionControllerMessenger,\n TransactionMeta,\n} from '../index.js';\nimport { projectLogger } from '../logger.js';\nimport type { GetSimulationConfig } from '../types.js';\nimport { isNativeBalanceSufficientForGas } from './balance.js';\nimport { ERROR_MESSAGE_NO_UPGRADE_CONTRACT } from './batch.js';\nimport { ERROR_MESSGE_PUBLIC_KEY, doesChainSupportEIP7702 } from './eip7702.js';\nimport { getEIP7702UpgradeContractAddress } from './feature-flags.js';\n\nconst log = createModuleLogger(projectLogger, 'gas-fee-tokens');\n\nexport type GetGasFeeTokensRequest = {\n chainId: Hex;\n isEIP7702GasFeeTokensEnabled: (\n transactionMeta: TransactionMeta,\n ) => Promise<boolean>;\n getSimulationConfig: GetSimulationConfig;\n messenger: TransactionControllerMessenger;\n publicKeyEIP7702?: Hex;\n transactionMeta: TransactionMeta;\n};\n\n/**\n * Get gas fee tokens for a transaction.\n *\n * @param request - The request object.\n * @param request.chainId - The chain ID of the transaction.\n * @param request.isEIP7702GasFeeTokensEnabled - Callback to check if EIP-7702 gas fee tokens are enabled.\n * @param request.messenger - The messenger instance.\n * @param request.publicKeyEIP7702 - Public key to validate EIP-7702 contract signatures.\n * @param request.transactionMeta - The transaction metadata.\n * @param request.getSimulationConfig - Optional transaction simulation parameters.\n * @returns An array of gas fee tokens.\n */\nexport async function getGasFeeTokens({\n chainId,\n isEIP7702GasFeeTokensEnabled,\n messenger,\n publicKeyEIP7702,\n transactionMeta,\n getSimulationConfig,\n}: GetGasFeeTokensRequest): Promise<{\n gasFeeTokens: GasFeeToken[];\n isGasFeeSponsored: boolean;\n}> {\n const { delegationAddress, txParams } = transactionMeta;\n const { authorizationList: authorizationListRequest } = txParams;\n const data = txParams.data as Hex;\n const from = txParams.from as Hex;\n const to = txParams.to as Hex;\n const value = txParams.value as Hex;\n\n log('Request', { chainId, txParams });\n\n const is7702GasFeeTokensEnabled =\n await isEIP7702GasFeeTokensEnabled(transactionMeta);\n\n const with7702 =\n is7702GasFeeTokensEnabled && doesChainSupportEIP7702(chainId, messenger);\n\n let authorizationList:\n | SimulationRequestTransaction['authorizationList']\n | undefined = authorizationListRequest?.map((authorization) => ({\n address: authorization.address,\n from,\n }));\n\n if (with7702 && !delegationAddress && !authorizationList) {\n authorizationList = buildAuthorizationList({\n chainId,\n from,\n messenger,\n publicKeyEIP7702,\n });\n }\n\n try {\n const response = await simulateTransactions(chainId, {\n getSimulationConfig,\n transactions: [\n {\n authorizationList,\n data,\n from,\n to,\n value,\n },\n ],\n suggestFees: {\n withTransfer: true,\n withFeeTransfer: true,\n with7702,\n },\n });\n\n log('Response', response);\n\n const result = parseGasFeeTokens(response);\n\n log('Gas fee tokens', result);\n\n return result;\n } catch (error) {\n log('Failed to gas fee tokens', error);\n return { gasFeeTokens: [], isGasFeeSponsored: false };\n }\n}\n\n/**\n * Check and update gas fee token selection before publishing a transaction.\n *\n * @param request - Request object.\n * @param request.messenger - The transaction controller messenger.\n * @param request.networkClientId - The network client ID.\n * @param request.fetchGasFeeTokens - Function to fetch gas fee tokens.\n * @param request.transaction - Transaction metadata.\n * @param request.updateTransaction - Function to update the transaction.\n */\nexport async function checkGasFeeTokenBeforePublish({\n messenger,\n networkClientId,\n fetchGasFeeTokens,\n transaction,\n updateTransaction,\n}: {\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n fetchGasFeeTokens: (transaction: TransactionMeta) => Promise<GasFeeToken[]>;\n transaction: TransactionMeta;\n updateTransaction: (\n transactionId: string,\n fn: (tx: TransactionMeta) => void,\n ) => void;\n}): Promise<void> {\n const {\n excludeNativeTokenForFee,\n isGasFeeTokenIgnoredIfBalance,\n selectedGasFeeToken,\n } = transaction;\n\n if (\n !selectedGasFeeToken ||\n (!isGasFeeTokenIgnoredIfBalance && !excludeNativeTokenForFee)\n ) {\n return;\n }\n\n log('Checking gas fee token before publish', { selectedGasFeeToken });\n\n if (!excludeNativeTokenForFee) {\n const hasNativeBalance = await isNativeBalanceSufficientForGas(\n transaction,\n messenger,\n networkClientId,\n );\n\n if (hasNativeBalance) {\n log(\n 'Ignoring gas fee token before publish due to sufficient native balance',\n );\n\n updateTransaction(transaction.id, (tx) => {\n tx.isExternalSign = false;\n tx.selectedGasFeeToken = undefined;\n });\n\n return;\n }\n }\n\n const gasFeeTokens = await fetchGasFeeTokens({\n ...transaction,\n isExternalSign: true,\n });\n\n const isSelectedGasFeeTokenAvailable = gasFeeTokens?.some(\n (token) =>\n token.tokenAddress.toLowerCase() === selectedGasFeeToken.toLowerCase(),\n );\n\n if (!isSelectedGasFeeTokenAvailable) {\n updateTransaction(transaction.id, (tx) => {\n tx.gasFeeTokens = gasFeeTokens;\n tx.isExternalSign = false;\n });\n\n throw new Error('Gas fee token not found and insufficient native balance');\n }\n\n updateTransaction(transaction.id, (tx) => {\n tx.gasFeeTokens = gasFeeTokens;\n tx.isExternalSign = true;\n tx.txParams.nonce = undefined;\n });\n\n log('Updated gas fee tokens before publish', gasFeeTokens);\n log('Publishing with selected gas fee token', { selectedGasFeeToken });\n}\n\n/**\n * Extract gas fee tokens from a simulation response.\n *\n * @param response - The simulation response.\n * @returns gasFeeTokens: An array of gas fee tokens. isGasFeeSponsored: Whether the transaction is sponsored\n */\nfunction parseGasFeeTokens(response: SimulationResponse): {\n gasFeeTokens: GasFeeToken[];\n isGasFeeSponsored: boolean;\n} {\n const feeLevel = response.transactions?.[0]\n ?.fees?.[0] as Required<SimulationResponseTransaction>['fees'][0];\n\n const isGasFeeSponsored = response.sponsorship?.isSponsored ?? false;\n\n const tokenFees = feeLevel?.tokenFees ?? [];\n\n return {\n gasFeeTokens: tokenFees.map((tokenFee) => ({\n amount: tokenFee.balanceNeededToken,\n balance: tokenFee.currentBalanceToken,\n decimals: tokenFee.token.decimals,\n fee: tokenFee.serviceFee,\n gas: feeLevel.gas,\n gasTransfer: tokenFee.transferEstimate,\n maxFeePerGas: feeLevel.maxFeePerGas,\n maxPriorityFeePerGas: feeLevel.maxPriorityFeePerGas,\n rateWei: tokenFee.rateWei,\n recipient: tokenFee.feeRecipient,\n symbol: tokenFee.token.symbol,\n tokenAddress: tokenFee.token.address,\n })),\n isGasFeeSponsored,\n };\n}\n\n/**\n * Generate the authorization list for the request.\n *\n * @param request - The request object.\n * @param request.chainId - The chain ID.\n * @param request.from - The sender's address.\n * @param request.messenger - The messenger instance.\n * @param request.publicKeyEIP7702 - The public key for EIP-7702.\n * @returns The authorization list.\n */\nfunction buildAuthorizationList({\n chainId,\n from,\n messenger,\n publicKeyEIP7702,\n}: {\n chainId: Hex;\n from: Hex;\n messenger: TransactionControllerMessenger;\n publicKeyEIP7702?: Hex;\n}): SimulationRequestTransaction['authorizationList'] | undefined {\n if (!publicKeyEIP7702) {\n throw rpcErrors.internal(ERROR_MESSGE_PUBLIC_KEY);\n }\n\n const upgradeAddress = getEIP7702UpgradeContractAddress(\n chainId,\n messenger,\n publicKeyEIP7702,\n );\n\n if (!upgradeAddress) {\n throw rpcErrors.internal(ERROR_MESSAGE_NO_UPGRADE_CONTRACT);\n }\n\n return [\n {\n address: upgradeAddress,\n from,\n },\n ];\n}\n"]}
1
+ {"version":3,"file":"gas-fee-tokens.js","sourceRoot":"","sources":["../../src/utils/gas-fee-tokens.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAWhE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OA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CAAC;IAED,MAAM,cAAc,GAAG,gCAAgC,CACrD,OAAO,EACP,SAAS,EACT,gBAAgB,CACjB,CAAC;IAEF,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,SAAS,CAAC,QAAQ,CAAC,iCAAiC,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO;QACL;YACE,OAAO,EAAE,cAAc;YACvB,IAAI;SACL;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { NetworkClientId } from '@metamask/network-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { simulateTransactions } from '../api/simulation-api.js';\nimport type { SimulationRequestTransaction } from '../api/simulation-api.js';\nimport type {\n SimulationResponse,\n SimulationResponseTransaction,\n} from '../api/simulation-api.js';\nimport type {\n GasFeeToken,\n TransactionControllerMessenger,\n TransactionMeta,\n} from '../index.js';\nimport { projectLogger } from '../logger.js';\nimport type { GetSimulationConfig } from '../types.js';\nimport { isNativeBalanceSufficientForGas } from './balance.js';\nimport { ERROR_MESSAGE_NO_UPGRADE_CONTRACT } from './batch.js';\nimport { ERROR_MESSGE_PUBLIC_KEY, doesChainSupportEIP7702 } from './eip7702.js';\nimport { getEIP7702UpgradeContractAddress } from './feature-flags.js';\n\nconst log = createModuleLogger(projectLogger, 'gas-fee-tokens');\n\nexport type GetGasFeeTokensRequest = {\n chainId: Hex;\n isEIP7702GasFeeTokensEnabled: (\n transactionMeta: TransactionMeta,\n ) => Promise<boolean>;\n getSimulationConfig: GetSimulationConfig;\n messenger: TransactionControllerMessenger;\n publicKeyEIP7702?: Hex;\n transactionMeta: TransactionMeta;\n};\n\n/**\n * Get gas fee tokens for a transaction.\n *\n * @param request - The request object.\n * @param request.chainId - The chain ID of the transaction.\n * @param request.isEIP7702GasFeeTokensEnabled - Callback to check if EIP-7702 gas fee tokens are enabled.\n * @param request.messenger - The messenger instance.\n * @param request.publicKeyEIP7702 - Public key to validate EIP-7702 contract signatures.\n * @param request.transactionMeta - The transaction metadata.\n * @param request.getSimulationConfig - Optional transaction simulation parameters.\n * @returns An array of gas fee tokens.\n */\nexport async function getGasFeeTokens({\n chainId,\n isEIP7702GasFeeTokensEnabled,\n messenger,\n publicKeyEIP7702,\n transactionMeta,\n getSimulationConfig,\n}: GetGasFeeTokensRequest): Promise<{\n gasFeeTokens: GasFeeToken[];\n isGasFeeSponsored: boolean;\n}> {\n const { delegationAddress, txParams } = transactionMeta;\n const { authorizationList: authorizationListRequest } = txParams;\n const data = txParams.data as Hex;\n const from = txParams.from as Hex;\n const to = txParams.to as Hex;\n const value = txParams.value as Hex;\n\n log('Request', { chainId, txParams });\n\n const is7702GasFeeTokensEnabled =\n await isEIP7702GasFeeTokensEnabled(transactionMeta);\n\n const with7702 =\n is7702GasFeeTokensEnabled && doesChainSupportEIP7702(chainId, messenger);\n\n let authorizationList:\n | SimulationRequestTransaction['authorizationList']\n | undefined = authorizationListRequest?.map((authorization) => ({\n address: authorization.address,\n from,\n }));\n\n if (with7702 && !delegationAddress && !authorizationList) {\n authorizationList = buildAuthorizationList({\n chainId,\n from,\n messenger,\n publicKeyEIP7702,\n });\n }\n\n try {\n const response = await simulateTransactions(chainId, {\n getSimulationConfig,\n transactions: [\n {\n authorizationList,\n data,\n from,\n to,\n value,\n },\n ],\n suggestFees: {\n withTransfer: true,\n withFeeTransfer: true,\n with7702,\n // The EIP-7702 publish hook always restricts redemption to the relay\n // signers via a RedeemerEnforcer caveat, so include it in the estimate.\n withRedeemerEnforcer: with7702,\n },\n });\n\n log('Response', response);\n\n const result = parseGasFeeTokens(response);\n\n log('Gas fee tokens', result);\n\n return result;\n } catch (error) {\n log('Failed to gas fee tokens', error);\n return { gasFeeTokens: [], isGasFeeSponsored: false };\n }\n}\n\n/**\n * Check and update gas fee token selection before publishing a transaction.\n *\n * @param request - Request object.\n * @param request.messenger - The transaction controller messenger.\n * @param request.networkClientId - The network client ID.\n * @param request.fetchGasFeeTokens - Function to fetch gas fee tokens.\n * @param request.transaction - Transaction metadata.\n * @param request.updateTransaction - Function to update the transaction.\n */\nexport async function checkGasFeeTokenBeforePublish({\n messenger,\n networkClientId,\n fetchGasFeeTokens,\n transaction,\n updateTransaction,\n}: {\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n fetchGasFeeTokens: (transaction: TransactionMeta) => Promise<GasFeeToken[]>;\n transaction: TransactionMeta;\n updateTransaction: (\n transactionId: string,\n fn: (tx: TransactionMeta) => void,\n ) => void;\n}): Promise<void> {\n const {\n excludeNativeTokenForFee,\n isGasFeeTokenIgnoredIfBalance,\n selectedGasFeeToken,\n } = transaction;\n\n if (\n !selectedGasFeeToken ||\n (!isGasFeeTokenIgnoredIfBalance && !excludeNativeTokenForFee)\n ) {\n return;\n }\n\n log('Checking gas fee token before publish', { selectedGasFeeToken });\n\n if (!excludeNativeTokenForFee) {\n const hasNativeBalance = await isNativeBalanceSufficientForGas(\n transaction,\n messenger,\n networkClientId,\n );\n\n if (hasNativeBalance) {\n log(\n 'Ignoring gas fee token before publish due to sufficient native balance',\n );\n\n updateTransaction(transaction.id, (tx) => {\n tx.isExternalSign = false;\n tx.selectedGasFeeToken = undefined;\n });\n\n return;\n }\n }\n\n const gasFeeTokens = await fetchGasFeeTokens({\n ...transaction,\n isExternalSign: true,\n });\n\n const isSelectedGasFeeTokenAvailable = gasFeeTokens?.some(\n (token) =>\n token.tokenAddress.toLowerCase() === selectedGasFeeToken.toLowerCase(),\n );\n\n if (!isSelectedGasFeeTokenAvailable) {\n updateTransaction(transaction.id, (tx) => {\n tx.gasFeeTokens = gasFeeTokens;\n tx.isExternalSign = false;\n });\n\n throw new Error('Gas fee token not found and insufficient native balance');\n }\n\n updateTransaction(transaction.id, (tx) => {\n tx.gasFeeTokens = gasFeeTokens;\n tx.isExternalSign = true;\n tx.txParams.nonce = undefined;\n });\n\n log('Updated gas fee tokens before publish', gasFeeTokens);\n log('Publishing with selected gas fee token', { selectedGasFeeToken });\n}\n\n/**\n * Extract gas fee tokens from a simulation response.\n *\n * @param response - The simulation response.\n * @returns gasFeeTokens: An array of gas fee tokens. isGasFeeSponsored: Whether the transaction is sponsored\n */\nfunction parseGasFeeTokens(response: SimulationResponse): {\n gasFeeTokens: GasFeeToken[];\n isGasFeeSponsored: boolean;\n} {\n const feeLevel = response.transactions?.[0]\n ?.fees?.[0] as Required<SimulationResponseTransaction>['fees'][0];\n\n const isGasFeeSponsored = response.sponsorship?.isSponsored ?? false;\n\n const tokenFees = feeLevel?.tokenFees ?? [];\n\n return {\n gasFeeTokens: tokenFees.map((tokenFee) => ({\n amount: tokenFee.balanceNeededToken,\n balance: tokenFee.currentBalanceToken,\n decimals: tokenFee.token.decimals,\n fee: tokenFee.serviceFee,\n gas: feeLevel.gas,\n gasTransfer: tokenFee.transferEstimate,\n maxFeePerGas: feeLevel.maxFeePerGas,\n maxPriorityFeePerGas: feeLevel.maxPriorityFeePerGas,\n rateWei: tokenFee.rateWei,\n recipient: tokenFee.feeRecipient,\n symbol: tokenFee.token.symbol,\n tokenAddress: tokenFee.token.address,\n })),\n isGasFeeSponsored,\n };\n}\n\n/**\n * Generate the authorization list for the request.\n *\n * @param request - The request object.\n * @param request.chainId - The chain ID.\n * @param request.from - The sender's address.\n * @param request.messenger - The messenger instance.\n * @param request.publicKeyEIP7702 - The public key for EIP-7702.\n * @returns The authorization list.\n */\nfunction buildAuthorizationList({\n chainId,\n from,\n messenger,\n publicKeyEIP7702,\n}: {\n chainId: Hex;\n from: Hex;\n messenger: TransactionControllerMessenger;\n publicKeyEIP7702?: Hex;\n}): SimulationRequestTransaction['authorizationList'] | undefined {\n if (!publicKeyEIP7702) {\n throw rpcErrors.internal(ERROR_MESSGE_PUBLIC_KEY);\n }\n\n const upgradeAddress = getEIP7702UpgradeContractAddress(\n chainId,\n messenger,\n publicKeyEIP7702,\n );\n\n if (!upgradeAddress) {\n throw rpcErrors.internal(ERROR_MESSAGE_NO_UPGRADE_CONTRACT);\n }\n\n return [\n {\n address: upgradeAddress,\n from,\n },\n ];\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/transaction-controller",
3
- "version": "72.0.1-preview-0f8c056e2",
3
+ "version": "72.1.0-preview-0305ce0",
4
4
  "description": "Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -39,10 +39,10 @@
39
39
  "build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
40
40
  "changelog:update": "../../scripts/update-changelog.sh @metamask/transaction-controller",
41
41
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/transaction-controller",
42
- "lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.ts",
43
- "lint:tsconfigs:fix": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.ts --fix",
44
- "messenger-action-types:check": "tsx ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --check",
45
- "messenger-action-types:generate": "tsx ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --generate",
42
+ "lint:tsconfigs": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../scripts/lint-tsconfigs/lint-tsconfigs.ts",
43
+ "lint:tsconfigs:fix": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../scripts/lint-tsconfigs/lint-tsconfigs.ts --fix",
44
+ "messenger-action-types:check": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --check",
45
+ "messenger-action-types:generate": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --generate",
46
46
  "since-latest-release": "../../scripts/since-latest-release.sh",
47
47
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
48
48
  "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
@@ -61,11 +61,11 @@
61
61
  "@metamask/approval-controller": "^10.0.0",
62
62
  "@metamask/base-controller": "^10.0.0",
63
63
  "@metamask/controller-utils": "^13.0.0",
64
- "@metamask/core-backend": "^11.0.0",
64
+ "@metamask/core-backend": "^12.0.1",
65
65
  "@metamask/gas-fee-controller": "^27.0.0",
66
66
  "@metamask/messenger": "^3.0.0",
67
67
  "@metamask/metamask-eth-abis": "^3.1.1",
68
- "@metamask/network-controller": "^37.0.0",
68
+ "@metamask/network-controller": "^37.0.1",
69
69
  "@metamask/nonce-tracker": "^6.0.0",
70
70
  "@metamask/remote-feature-flag-controller": "^7.0.0",
71
71
  "@metamask/rpc-errors": "^7.0.2",
@@ -97,7 +97,6 @@
97
97
  "nock": "^13.5.6",
98
98
  "rimraf": "^6.1.3",
99
99
  "ts-jest": "^29.4.14",
100
- "tsx": "^4.23.15",
101
100
  "typedoc": "^0.25.13",
102
101
  "typedoc-plugin-missing-exports": "^2.0.0",
103
102
  "typescript": "npm:@typescript/typescript6@^6.0.2"