@metamask-previews/transaction-controller 72.3.0-preview-406090321 → 72.3.0-preview-313288d71

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.
@@ -13,13 +13,13 @@ const log = createModuleLogger(projectLogger, 'gas-fee-tokens');
13
13
  * @param request - The request object.
14
14
  * @param request.chainId - The chain ID of the transaction.
15
15
  * @param request.isEIP7702GasFeeTokensEnabled - Callback to check if EIP-7702 gas fee tokens are enabled.
16
+ * @param request.getSimulationConfig - Optional callback to rewrite the simulation request URL.
16
17
  * @param request.messenger - The messenger instance.
17
18
  * @param request.publicKeyEIP7702 - Public key to validate EIP-7702 contract signatures.
18
19
  * @param request.transactionMeta - The transaction metadata.
19
- * @param request.getSimulationConfig - Optional transaction simulation parameters.
20
20
  * @returns An array of gas fee tokens.
21
21
  */
22
- export async function getGasFeeTokens({ chainId, isEIP7702GasFeeTokensEnabled, messenger, publicKeyEIP7702, transactionMeta, getSimulationConfig, }) {
22
+ export async function getGasFeeTokens({ chainId, isEIP7702GasFeeTokensEnabled, getSimulationConfig, messenger, publicKeyEIP7702, transactionMeta, }) {
23
23
  const { delegationAddress, txParams } = transactionMeta;
24
24
  const { authorizationList: authorizationListRequest } = txParams;
25
25
  const data = txParams.data;
@@ -42,8 +42,7 @@ export async function getGasFeeTokens({ chainId, isEIP7702GasFeeTokensEnabled, m
42
42
  });
43
43
  }
44
44
  try {
45
- const response = await simulateTransactions(chainId, {
46
- getSimulationConfig,
45
+ const response = await simulateTransactions(messenger, chainId, {
47
46
  transactions: [
48
47
  {
49
48
  authorizationList,
@@ -61,7 +60,7 @@ export async function getGasFeeTokens({ chainId, isEIP7702GasFeeTokensEnabled, m
61
60
  // signers via a RedeemerEnforcer caveat, so include it in the estimate.
62
61
  withRedeemerEnforcer: with7702,
63
62
  },
64
- });
63
+ }, { getSimulationConfig });
65
64
  log('Response', response);
66
65
  const result = parseGasFeeTokens(response);
67
66
  log('Gas fee tokens', result);
@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Q,CAAC,gBAAgB;YACtC,YAAY,EAAE,QAAQ,CAAC,YAAY;YACnC,oBAAoB,EAAE,QAAQ,CAAC,oBAAoB;YACnD,OAAO,EAAE,QAAQ,CAAC,OAAO;YACzB,SAAS,EAAE,QAAQ,CAAC,YAAY;YAChC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC/B,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM;YAC7B,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,OAAO;SACrC,CAAC,CAAC;QACH,iBAAiB;KAClB,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,sBAAsB,CAAC,EAC9B,OAAO,EACP,IAAI,EACJ,SAAS,EACT,gBAAgB,GAMjB;IACC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,SAAS,CAAC,QAAQ,CAAC,uBAAuB,CAAC,CAAC;IACpD,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 gasFeeSponsor?: string;\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. gasFeeSponsor: Who pays the gas fee if sponsored.\n */\nfunction parseGasFeeTokens(response: SimulationResponse): {\n gasFeeSponsor?: string;\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 const sponsor = isGasFeeSponsored ? response.sponsorship?.sponsor : undefined;\n\n const tokenFees = feeLevel?.tokenFees ?? [];\n\n return {\n ...(sponsor ? { gasFeeSponsor: sponsor } : {}),\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 ...(sponsor ? { sponsor } : {}),\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;AAOjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAMhE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,iCAAiC,EAAE,MAAM,YAAY,CAA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ACH,iBAAiB;KAClB,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,sBAAsB,CAAC,EAC9B,OAAO,EACP,IAAI,EACJ,SAAS,EACT,gBAAgB,GAMjB;IACC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,SAAS,CAAC,QAAQ,CAAC,uBAAuB,CAAC,CAAC;IACpD,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 {\n SentinelSimulationResponse,\n SentinelSimulationResponseTransaction,\n SentinelSimulationTransaction,\n} from '@metamask/sentinel-api-service';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { simulateTransactions } 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.getSimulationConfig - Optional callback to rewrite the simulation request URL.\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 * @returns An array of gas fee tokens.\n */\nexport async function getGasFeeTokens({\n chainId,\n isEIP7702GasFeeTokensEnabled,\n getSimulationConfig,\n messenger,\n publicKeyEIP7702,\n transactionMeta,\n}: GetGasFeeTokensRequest): Promise<{\n gasFeeSponsor?: string;\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 | SentinelSimulationTransaction['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(\n messenger,\n chainId,\n {\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 { getSimulationConfig },\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. gasFeeSponsor: Who pays the gas fee if sponsored.\n */\nfunction parseGasFeeTokens(response: SentinelSimulationResponse): {\n gasFeeSponsor?: string;\n gasFeeTokens: GasFeeToken[];\n isGasFeeSponsored: boolean;\n} {\n const feeLevel = response.transactions?.[0]\n ?.fees?.[0] as Required<SentinelSimulationResponseTransaction>['fees'][0];\n\n const isGasFeeSponsored = response.sponsorship?.isSponsored ?? false;\n const sponsor = isGasFeeSponsored ? response.sponsorship?.sponsor : undefined;\n\n const tokenFees = feeLevel?.tokenFees ?? [];\n\n return {\n ...(sponsor ? { gasFeeSponsor: sponsor } : {}),\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 ...(sponsor ? { sponsor } : {}),\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}): SentinelSimulationTransaction['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"]}
@@ -5,7 +5,7 @@ import type { BatchTransactionParams, GetSimulationConfig, IsAtomicBatchSupporte
5
5
  export type UpdateGasRequest = {
6
6
  isCustomNetwork: boolean;
7
7
  isSimulationEnabled: boolean;
8
- getSimulationConfig: GetSimulationConfig;
8
+ getSimulationConfig?: GetSimulationConfig;
9
9
  messenger: TransactionControllerMessenger;
10
10
  txMeta: TransactionMeta;
11
11
  };
@@ -62,7 +62,7 @@ export declare function updateGas(request: UpdateGasRequest): Promise<void>;
62
62
  * @param options - The options object.
63
63
  * @param options.ignoreDelegationSignatures - Ignore signature errors if submitting delegations to the DelegationManager.
64
64
  * @param options.isSimulationEnabled - Whether the simulation is enabled.
65
- * @param options.getSimulationConfig - The function to get the simulation configuration.
65
+ * @param options.getSimulationConfig - Optional callback to rewrite the simulation request URL.
66
66
  * @param options.messenger - The messenger instance for communication.
67
67
  * @param options.networkClientId - The network client ID.
68
68
  * @param options.txParams - The transaction parameters.
@@ -71,7 +71,7 @@ export declare function updateGas(request: UpdateGasRequest): Promise<void>;
71
71
  export declare function estimateGas({ ignoreDelegationSignatures, isSimulationEnabled, getSimulationConfig, messenger, networkClientId, txParams, }: {
72
72
  ignoreDelegationSignatures?: boolean;
73
73
  isSimulationEnabled: boolean;
74
- getSimulationConfig: GetSimulationConfig;
74
+ getSimulationConfig?: GetSimulationConfig;
75
75
  messenger: TransactionControllerMessenger;
76
76
  networkClientId: NetworkClientId;
77
77
  txParams: TransactionParams;
@@ -109,7 +109,7 @@ export declare function getProvidedBatchGasLimits(transactions: BatchTransaction
109
109
  } | undefined;
110
110
  export declare function estimateGasBatch({ from, getSimulationConfig, isAtomicBatchSupported, messenger, networkClientId, transactions, }: {
111
111
  from: Hex;
112
- getSimulationConfig: GetSimulationConfig;
112
+ getSimulationConfig?: GetSimulationConfig;
113
113
  isAtomicBatchSupported: (request: IsAtomicBatchSupportedRequest) => Promise<IsAtomicBatchSupportedResult>;
114
114
  messenger: TransactionControllerMessenger;
115
115
  networkClientId: NetworkClientId;
@@ -131,14 +131,16 @@ export declare function addGasBuffer(estimatedGas: string, blockGasLimit: string
131
131
  * @param options - The options object.
132
132
  * @param options.chainId - The chain ID of the transactions.
133
133
  * @param options.from - The address of the sender.
134
- * @param options.getSimulationConfig - The function to get the simulation configuration.
134
+ * @param options.getSimulationConfig - Optional callback to rewrite the simulation request URL.
135
+ * @param options.messenger - The messenger instance used to invoke the Sentinel simulation action.
135
136
  * @param options.transactions - The array of transactions within a batch request.
136
137
  * @returns An object containing the transactions with their gas limits and the total gas limit.
137
138
  */
138
- export declare function simulateGasBatch({ chainId, from, getSimulationConfig, transactions, }: {
139
+ export declare function simulateGasBatch({ chainId, from, getSimulationConfig, messenger, transactions, }: {
139
140
  chainId: Hex;
140
141
  from: Hex;
141
- getSimulationConfig: GetSimulationConfig;
142
+ getSimulationConfig?: GetSimulationConfig;
143
+ messenger: TransactionControllerMessenger;
142
144
  transactions: TransactionBatchSingleRequest[];
143
145
  }): Promise<{
144
146
  totalGasLimit: Hex;
@@ -1 +1 @@
1
- {"version":3,"file":"gas.d.ts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,M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E,SAAS,EAAE,MAAM,EAAE,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAW5D;AAED,wBAAsB,gBAAgB,CAAC,EACrC,IAAI,EACJ,mBAAmB,EACnB,sBAAsB,EACtB,SAAS,EACT,eAAe,EACf,YAAY,GACb,EAAE;IACD,IAAI,EAAE,GAAG,CAAC;IACV,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,sBAAsB,EAAE,CACtB,OAAO,EAAE,6BAA6B,KACnC,OAAO,CAAC,4BAA4B,CAAC,CAAC;IAC3C,SAAS,EAAE,8BAA8B,CAAC;IAC1C,eAAe,EAAE,eAAe,CAAC;IACjC,YAAY,EAAE,sBAAsB,EAAE,CAAC;CACxC,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAgHlC;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,GACjB,MAAM,CA0BR;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,OAAO,EACP,IAAI,EACJ,mBAAmB,EACnB,SAAS,EACT,YAAY,GACb,EAAE;IACD,OAAO,EAAE,GAAG,CAAC;IACb,IAAI,EAAE,GAAG,CAAC;IACV,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,SAAS,EAAE,8BAA8B,CAAC;IAC1C,YAAY,EAAE,6BAA6B,EAAE,CAAC;CAC/C,GAAG,OAAO,CAAC;IAAE,aAAa,EAAE,GAAG,CAAC;IAAC,SAAS,EAAE,GAAG,EAAE,CAAA;CAAE,CAAC,CAkDpD"}
package/dist/utils/gas.js CHANGED
@@ -66,7 +66,7 @@ export async function updateGas(request) {
66
66
  * @param options - The options object.
67
67
  * @param options.ignoreDelegationSignatures - Ignore signature errors if submitting delegations to the DelegationManager.
68
68
  * @param options.isSimulationEnabled - Whether the simulation is enabled.
69
- * @param options.getSimulationConfig - The function to get the simulation configuration.
69
+ * @param options.getSimulationConfig - Optional callback to rewrite the simulation request URL.
70
70
  * @param options.messenger - The messenger instance for communication.
71
71
  * @param options.networkClientId - The network client ID.
72
72
  * @param options.txParams - The transaction parameters.
@@ -128,6 +128,7 @@ export async function estimateGas({ ignoreDelegationSignatures, isSimulationEnab
128
128
  estimatedGas = await simulateGas({
129
129
  chainId,
130
130
  getSimulationConfig,
131
+ messenger,
131
132
  transaction: request,
132
133
  });
133
134
  }
@@ -257,6 +258,7 @@ export async function estimateGasBatch({ from, getSimulationConfig, isAtomicBatc
257
258
  chainId,
258
259
  from,
259
260
  getSimulationConfig,
261
+ messenger,
260
262
  transactions: transactions.map((transaction) => ({
261
263
  params: transaction,
262
264
  })),
@@ -301,19 +303,19 @@ export function addGasBuffer(estimatedGas, blockGasLimit, multiplier) {
301
303
  * @param options - The options object.
302
304
  * @param options.chainId - The chain ID of the transactions.
303
305
  * @param options.from - The address of the sender.
304
- * @param options.getSimulationConfig - The function to get the simulation configuration.
306
+ * @param options.getSimulationConfig - Optional callback to rewrite the simulation request URL.
307
+ * @param options.messenger - The messenger instance used to invoke the Sentinel simulation action.
305
308
  * @param options.transactions - The array of transactions within a batch request.
306
309
  * @returns An object containing the transactions with their gas limits and the total gas limit.
307
310
  */
308
- export async function simulateGasBatch({ chainId, from, getSimulationConfig, transactions, }) {
311
+ export async function simulateGasBatch({ chainId, from, getSimulationConfig, messenger, transactions, }) {
309
312
  try {
310
- const response = await simulateTransactions(chainId, {
311
- getSimulationConfig,
313
+ const response = await simulateTransactions(messenger, chainId, {
312
314
  transactions: transactions.map((transaction) => ({
313
315
  ...transaction.params,
314
316
  from,
315
317
  })),
316
- });
318
+ }, { getSimulationConfig });
317
319
  if (response?.transactions?.length !== transactions.length) {
318
320
  throw new Error('Simulation response does not match transaction count');
319
321
  }
@@ -410,7 +412,7 @@ async function getLatestBlock(messenger, networkClientId) {
410
412
  * @param options - The options object.
411
413
  * @param options.authorizationList - The original authorization list of the transaction.
412
414
  * @param options.chainId - The chain ID of the transaction.
413
- * @param options.getSimulationConfig - The function to get the simulation configuration.
415
+ * @param options.getSimulationConfig - Optional callback to rewrite the simulation request URL.
414
416
  * @param options.isSimulationEnabled - Whether the simulation is enabled.
415
417
  * @param options.messenger - The messenger instance for communication.
416
418
  * @param options.networkClientId - The network client ID.
@@ -436,6 +438,7 @@ async function estimateGasType4({ authorizationList, chainId, getSimulationConfi
436
438
  authorizationList: simulationAuthorizationList,
437
439
  chainId,
438
440
  getSimulationConfig,
441
+ messenger,
439
442
  transaction: txParams,
440
443
  });
441
444
  }
@@ -511,13 +514,13 @@ async function estimateGasType4Node({ authorizationList, messenger, networkClien
511
514
  * @param options - The options object.
512
515
  * @param options.authorizationList - The authorization list with the authority of each entry.
513
516
  * @param options.chainId - The chain ID of the transaction.
514
- * @param options.getSimulationConfig - The function to get the simulation configuration.
517
+ * @param options.getSimulationConfig - Optional callback to rewrite the simulation request URL.
518
+ * @param options.messenger - The messenger instance used to invoke the Sentinel simulation action.
515
519
  * @param options.transaction - The transaction parameters.
516
520
  * @returns The simulated gas.
517
521
  */
518
- async function simulateGas({ authorizationList, chainId, getSimulationConfig, transaction, }) {
519
- const response = await simulateTransactions(chainId, {
520
- getSimulationConfig,
522
+ async function simulateGas({ authorizationList, chainId, getSimulationConfig, messenger, transaction, }) {
523
+ const response = await simulateTransactions(messenger, chainId, {
521
524
  transactions: [
522
525
  {
523
526
  ...(authorizationList ? { authorizationList } : {}),
@@ -527,7 +530,7 @@ async function simulateGas({ authorizationList, chainId, getSimulationConfig, tr
527
530
  value: transaction.value,
528
531
  },
529
532
  ],
530
- });
533
+ }, { getSimulationConfig });
531
534
  const simulatedTransaction = response?.transactions?.[0];
532
535
  const gasLimit = simulatedTransaction?.gasLimit;
533
536
  if (authorizationList && simulatedTransaction?.error) {
@@ -1 +1 @@
1
- {"version":3,"file":"gas.js","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAAA,OAAO,E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O,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAE9D,OAAO,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AACzD,CAAC;AAED;;;;;;;;GAQG;AACH,KAAK,UAAU,eAAe,CAC5B,SAAyC,EACzC,eAAgC,EAChC,QAA2B,EAC3B,iBAAuB;IAEvB,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC;IAC1B,MAAM,MAAM,GAAG,CAAC,QAAQ,CAAW,CAAC;IAEpC,IAAI,iBAAiB,EAAE,CAAC;QACtB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEtB,MAAM,CAAC,IAAI,CAAC;YACV,CAAC,IAAI,CAAC,EAAE;gBACN,IAAI,EAAE,iBAAiB,GAAG,QAAQ,CAAC,iBAAiB,CAAC;aACtD;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,CAAC,MAAM,UAAU,CAAC;QACvB,SAAS;QACT,eAAe;QACf,MAAM,EAAE,iBAAiB;QACzB,MAAM;KACP,CAAC,CAAQ,CAAC;AACb,CAAC","sourcesContent":["import {\n BNToHex,\n fractionBN,\n hexToBN,\n toHex,\n} from '@metamask/controller-utils';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport type { Hex, Json } from '@metamask/utils';\nimport {\n add0x,\n createModuleLogger,\n isStrictHexString,\n remove0x,\n} from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport { simulateTransactions } from '../api/simulation-api.js';\nimport type { SimulationRequestTransaction } from '../api/simulation-api.js';\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport { TransactionEnvelopeType } from '../types.js';\nimport type {\n AuthorizationList,\n BatchTransactionParams,\n GetSimulationConfig,\n IsAtomicBatchSupportedRequest,\n IsAtomicBatchSupportedResult,\n Revert,\n TransactionBatchSingleRequest,\n TransactionMeta,\n TransactionParams,\n} from '../types.js';\nimport {\n DELEGATION_PREFIX,\n doesAccountSupportEIP7702,\n generateEIP7702BatchTransaction,\n getAuthorizationAuthority,\n getDelegationAddress,\n isAuthorizationSigned,\n} from './eip7702.js';\nimport {\n getGasEstimateBuffer,\n getGasEstimateFallback,\n} from './feature-flags.js';\nimport { getChainId, rpcRequest } from './provider.js';\nimport { decodeRevert } from './revert-reason.js';\n\nexport type UpdateGasRequest = {\n isCustomNetwork: boolean;\n isSimulationEnabled: boolean;\n getSimulationConfig: GetSimulationConfig;\n messenger: TransactionControllerMessenger;\n txMeta: TransactionMeta;\n};\n\n/**\n * How the gas limits of a batch are applied.\n * - `eip7702` - A single gas limit for the outer EIP-7702 transaction.\n * - `separate` - One gas limit per transaction, submitted separately.\n */\nexport type EstimateGasBatchMode = 'eip7702' | 'separate';\n\nexport type EstimateGasBatchResult = {\n /** Gas limits, with a single entry if `mode` is `eip7702`. */\n gasLimits: number[];\n\n /** How the gas limits are applied. */\n mode: EstimateGasBatchMode;\n\n /** Whether the outer EIP-7702 transaction upgrades the sender. */\n requiresAuthorizationList?: true;\n\n /** Total of all gas limits. */\n totalGasLimit: number;\n};\n\nexport const log = createModuleLogger(projectLogger, 'gas');\n\nexport const DEFAULT_GAS_MULTIPLIER = 1.5;\nexport const MAX_GAS_BLOCK_PERCENT = 90;\n\nexport const DUMMY_AUTHORIZATION_SIGNATURE =\n '0x1111111111111111111111111111111111111111111111111111111111111111';\n\n/**\n * EIP-2780 state gas charged at runtime when a valid authorization sets a\n * delegation indicator for an authority that had none at the start of the\n * transaction, at most once per authority.\n *\n * When the authority is the sender, this is the only runtime authorization\n * charge: `ACCOUNT_WRITE` is covered by the transaction base cost, and the\n * sender always exists in state as its nonce is incremented first.\n */\nexport const EIP_2780_AUTHORIZATION_GAS = 35190;\n\n/**\n * Intrinsic gas cost for each authorization omitted from the node estimate.\n */\nexport const EIP7280_AUTHORIZATION_INTRINSIC_GAS = 7816;\n\n/**\n * Gas for the upgrade authorization of the sender that is not included in the\n * sum of the provided gas values of a batch: the EIP-7280 intrinsic cost of an\n * authorization plus the delegation indicator charge.\n */\nexport const UPGRADE_AUTHORIZATION_GAS =\n EIP7280_AUTHORIZATION_INTRINSIC_GAS + EIP_2780_AUTHORIZATION_GAS;\n\n/**\n * Error for a simulated transaction that failed, as opposed to the simulation\n * itself being unavailable.\n */\nclass SimulatedTransactionError extends Error {}\n\n/**\n * Populate the gas properties of the provided transaction meta.\n *\n * @param request - The request object including the necessary parameters.\n */\nexport async function updateGas(request: UpdateGasRequest): Promise<void> {\n const { txMeta } = request;\n const initialParams = { ...txMeta.txParams };\n\n const [gas, simulationFails, gasLimitNoBuffer, gasRevert] =\n await getGas(request);\n\n txMeta.txParams.gas = gas;\n txMeta.simulationFails = simulationFails;\n txMeta.gasLimitNoBuffer = gasLimitNoBuffer;\n\n if (gasRevert) {\n txMeta.revert = { ...txMeta.revert, gas: gasRevert };\n }\n\n if (!initialParams.gas) {\n txMeta.originalGasEstimate = txMeta.txParams.gas;\n }\n\n txMeta.defaultGasEstimates ??= {};\n txMeta.defaultGasEstimates.gas = txMeta.txParams.gas;\n}\n\n/**\n * Estimate the gas for the provided transaction parameters.\n * If the gas estimate fails, the fallback value is returned.\n *\n * @param options - The options object.\n * @param options.ignoreDelegationSignatures - Ignore signature errors if submitting delegations to the DelegationManager.\n * @param options.isSimulationEnabled - Whether the simulation is enabled.\n * @param options.getSimulationConfig - The function to get the simulation configuration.\n * @param options.messenger - The messenger instance for communication.\n * @param options.networkClientId - The network client ID.\n * @param options.txParams - The transaction parameters.\n * @returns The estimated gas and related info.\n */\nexport async function estimateGas({\n ignoreDelegationSignatures,\n isSimulationEnabled,\n getSimulationConfig,\n messenger,\n networkClientId,\n txParams,\n}: {\n ignoreDelegationSignatures?: boolean;\n isSimulationEnabled: boolean;\n getSimulationConfig: GetSimulationConfig;\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n txParams: TransactionParams;\n}): Promise<{\n blockGasLimit: string;\n estimatedGas: string;\n gasRevert?: Revert;\n isUpgradeWithData: boolean;\n simulationFails: TransactionMeta['simulationFails'];\n}> {\n const request = { ...txParams };\n const { authorizationList, data, value } = request;\n const chainId = getChainId({ messenger, networkClientId });\n\n if (ignoreDelegationSignatures && !isSimulationEnabled) {\n throw new Error(\n 'Gas estimation with ignored delegation signatures is not supported as simulation disabled',\n );\n }\n\n const { gasLimit: blockGasLimit, number: blockNumber } = await getLatestBlock(\n messenger,\n networkClientId,\n );\n\n const blockGasLimitBN = hexToBN(blockGasLimit);\n const { percentage, fixed, maxGasLimit } = getGasEstimateFallback(\n chainId,\n messenger,\n );\n\n const uncappedFallback = fixed\n ? toHex(fixed)\n : BNToHex(fractionBN(blockGasLimitBN, percentage, 100));\n\n // Clamp the fallback to the chain's per-transaction gas cap so it can never\n // exceed the gas limit the RPC will accept. Without this, a percentage of a\n // high block gas limit can overshoot the cap (e.g. 35% of Polygon's ~140M\n // block limit is ~49M, but the node caps a tx at ~33.5M and rejects it with\n // \"transaction gas limit too high\").\n const fallback =\n maxGasLimit !== undefined &&\n hexToBN(uncappedFallback).gt(hexToBN(toHex(maxGasLimit)))\n ? toHex(maxGasLimit)\n : uncappedFallback;\n\n log('Estimation fallback values', fallback);\n\n request.data = data ? add0x(data) : data;\n request.value = normalizeValue(value);\n\n request.authorizationList = normalizeAuthorizationList(\n request.authorizationList,\n chainId,\n );\n\n delete request.gasPrice;\n delete request.maxFeePerGas;\n delete request.maxPriorityFeePerGas;\n\n let estimatedGas = fallback;\n let simulationFails: TransactionMeta['simulationFails'];\n let gasRevert: Revert | undefined;\n\n const isUpgradeWithData =\n txParams.type === TransactionEnvelopeType.setCode &&\n Boolean(authorizationList?.length) &&\n Boolean(data) &&\n data !== '0x';\n\n const type4AuthorizationList =\n txParams.type === TransactionEnvelopeType.setCode &&\n authorizationList?.length\n ? authorizationList\n : undefined;\n\n try {\n if (type4AuthorizationList) {\n estimatedGas = await estimateGasType4({\n authorizationList: type4AuthorizationList,\n chainId,\n getSimulationConfig,\n isSimulationEnabled,\n messenger,\n networkClientId,\n txParams: request,\n });\n } else if (ignoreDelegationSignatures && isSimulationEnabled) {\n estimatedGas = await simulateGas({\n chainId,\n getSimulationConfig,\n transaction: request,\n });\n } else {\n estimatedGas = await estimateGasNode(messenger, networkClientId, request);\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n simulationFails = {\n reason: error.message,\n errorKey: error.errorKey,\n debug: {\n blockNumber,\n blockGasLimit,\n },\n };\n\n gasRevert = decodeRevert(error, 'gas');\n\n log('Estimation failed', { ...simulationFails, fallback, gasRevert });\n }\n\n return {\n blockGasLimit,\n estimatedGas,\n gasRevert,\n isUpgradeWithData,\n simulationFails,\n };\n}\n\n/**\n * Sum caller-provided gas limits across a batch.\n *\n * If every transaction in the batch already has a `gas` value, returns the\n * parsed per-tx limits and their sum. Otherwise returns `undefined`.\n *\n * Used by `estimateGasBatch`:\n * - non-7702 path: short-circuits simulation entirely when present.\n * - EIP-7702 path: used as a fallback when simulation fails — required for\n * callers that submit batches whose individual sub-calls cannot be simulated\n * standalone (e.g. predict-withdraw, where the batch's first sub-call\n * provides source-token balance to subsequent sub-calls). When 7702\n * simulation succeeds it is preferred since the bundled call has no per-tx\n * intrinsic gas cost and produces a tighter estimate. If the sender requires\n * an upgrade, the fallback adds the authorization intrinsic gas and, if no\n * delegation exists yet, the delegation indicator charge. The provided gas\n * values do not include these authorization costs.\n *\n * @param transactions - Batch transactions to inspect.\n * @returns Parsed gas limits and total when every transaction has gas; otherwise `undefined`.\n */\nexport function getProvidedBatchGasLimits(\n transactions: BatchTransactionParams[],\n): { gasLimits: number[]; totalGasLimit: number } | undefined {\n if (!transactions.every((transaction) => transaction.gas !== undefined)) {\n return undefined;\n }\n\n const gasLimits = transactions.map((transaction) =>\n new BigNumber(transaction.gas as Hex).toNumber(),\n );\n const totalGasLimit = gasLimits.reduce((acc, gasLimit) => acc + gasLimit, 0);\n\n return { gasLimits, totalGasLimit };\n}\n\nexport async function estimateGasBatch({\n from,\n getSimulationConfig,\n isAtomicBatchSupported,\n messenger,\n networkClientId,\n transactions,\n}: {\n from: Hex;\n getSimulationConfig: GetSimulationConfig;\n isAtomicBatchSupported: (\n request: IsAtomicBatchSupportedRequest,\n ) => Promise<IsAtomicBatchSupportedResult>;\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n transactions: BatchTransactionParams[];\n}): Promise<EstimateGasBatchResult> {\n const chainId = getChainId({ messenger, networkClientId });\n\n const is7702Result = await isAtomicBatchSupported({\n address: from,\n chainIds: [chainId],\n });\n\n const accountSupports7702 = doesAccountSupportEIP7702(messenger, from);\n\n const chainResult = accountSupports7702\n ? is7702Result.find((result) => result.chainId === chainId)\n : undefined;\n\n const isUpgradeRequired = Boolean(chainResult && !chainResult.isSupported);\n\n if (isUpgradeRequired && !chainResult?.upgradeContractAddress) {\n throw new Error('Upgrade contract address not found');\n }\n\n if (chainResult) {\n const providedBatchGasLimits = getProvidedBatchGasLimits(transactions);\n\n const authorizationList = isUpgradeRequired\n ? [{ address: chainResult.upgradeContractAddress as Hex }]\n : undefined;\n\n const type = isUpgradeRequired\n ? TransactionEnvelopeType.setCode\n : undefined;\n\n const params: TransactionParams = {\n ...generateEIP7702BatchTransaction(from, transactions),\n authorizationList,\n from,\n type,\n };\n\n // Prefer real EIP-7702 simulation when it succeeds — the bundled call has\n // no per-tx intrinsic gas cost so the estimate is typically lower than\n // summing per-tx provided limits. Fall back to the provided sum when the\n // node-level simulation fails (e.g. predict-withdraw, where the batch's\n // first sub-call provides source-token balance to subsequent sub-calls).\n const { estimatedGas: gasLimitHex, simulationFails } = await estimateGas({\n isSimulationEnabled: true,\n getSimulationConfig,\n messenger,\n networkClientId,\n txParams: params,\n });\n\n if (simulationFails && providedBatchGasLimits) {\n const upgradeGas = chainResult.delegationAddress\n ? EIP7280_AUTHORIZATION_INTRINSIC_GAS\n : UPGRADE_AUTHORIZATION_GAS;\n const fallbackGasLimit =\n providedBatchGasLimits.totalGasLimit +\n (isUpgradeRequired ? upgradeGas : 0);\n\n log(\n 'EIP-7702 estimation failed, using batch parameter gas limits',\n { fallbackGasLimit },\n simulationFails,\n );\n\n return {\n gasLimits: [fallbackGasLimit],\n mode: 'eip7702',\n ...(isUpgradeRequired ? { requiresAuthorizationList: true } : {}),\n totalGasLimit: fallbackGasLimit,\n };\n }\n\n const totalGasLimit = new BigNumber(gasLimitHex).toNumber();\n\n log('Estimated EIP-7702 gas limit', totalGasLimit);\n\n return {\n gasLimits: [totalGasLimit],\n mode: 'eip7702',\n ...(isUpgradeRequired ? { requiresAuthorizationList: true } : {}),\n totalGasLimit,\n };\n }\n\n const providedBatchGasLimits = getProvidedBatchGasLimits(transactions);\n if (providedBatchGasLimits) {\n log('Using batch parameter gas limits', providedBatchGasLimits);\n return { ...providedBatchGasLimits, mode: 'separate' };\n }\n\n const { gasLimits: gasLimitsHex } = await simulateGasBatch({\n chainId,\n from,\n getSimulationConfig,\n transactions: transactions.map((transaction) => ({\n params: transaction,\n })),\n });\n\n const gasLimits = transactions.map((transaction, index) =>\n transaction.gas\n ? new BigNumber(transaction.gas).toNumber()\n : new BigNumber(gasLimitsHex[index]).toNumber(),\n );\n\n const totalGasLimit = gasLimits.reduce((acc, gasLimit) => acc + gasLimit, 0);\n\n log('Simulated batch gas limits', { totalGasLimit, gasLimits });\n\n return { gasLimits, mode: 'separate', totalGasLimit };\n}\n\n/**\n * Add a buffer to the provided estimated gas.\n * The buffer is calculated based on the block gas limit and a multiplier.\n *\n * @param estimatedGas - The estimated gas.\n * @param blockGasLimit - The block gas limit.\n * @param multiplier - The multiplier to apply to the estimated gas.\n * @returns The gas with the buffer applied.\n */\nexport function addGasBuffer(\n estimatedGas: string,\n blockGasLimit: string,\n multiplier: number,\n): string {\n const estimatedGasBN = hexToBN(estimatedGas);\n\n const maxGasBN = fractionBN(\n hexToBN(blockGasLimit),\n MAX_GAS_BLOCK_PERCENT,\n 100,\n );\n\n const paddedGasBN = fractionBN(estimatedGasBN, multiplier * 100, 100);\n\n if (estimatedGasBN.gt(maxGasBN)) {\n const estimatedGasHex = add0x(estimatedGas);\n log('Using estimated value', estimatedGasHex);\n return estimatedGasHex;\n }\n\n if (paddedGasBN.lt(maxGasBN)) {\n const paddedHex = add0x(BNToHex(paddedGasBN));\n log('Using padded estimate', paddedHex, multiplier);\n return paddedHex;\n }\n\n const maxHex = add0x(BNToHex(maxGasBN));\n log('Using 90% of block gas limit', maxHex);\n return maxHex;\n}\n\n/**\n * Simulate the required gas for a batch of transactions using the simulation API.\n *\n * @param options - The options object.\n * @param options.chainId - The chain ID of the transactions.\n * @param options.from - The address of the sender.\n * @param options.getSimulationConfig - The function to get the simulation configuration.\n * @param options.transactions - The array of transactions within a batch request.\n * @returns An object containing the transactions with their gas limits and the total gas limit.\n */\nexport async function simulateGasBatch({\n chainId,\n from,\n getSimulationConfig,\n transactions,\n}: {\n chainId: Hex;\n from: Hex;\n getSimulationConfig: GetSimulationConfig;\n transactions: TransactionBatchSingleRequest[];\n}): Promise<{ totalGasLimit: Hex; gasLimits: Hex[] }> {\n try {\n const response = await simulateTransactions(chainId, {\n getSimulationConfig,\n transactions: transactions.map((transaction) => ({\n ...transaction.params,\n from,\n })),\n });\n\n if (response?.transactions?.length !== transactions.length) {\n throw new Error('Simulation response does not match transaction count');\n }\n\n return response.transactions.reduce<{\n totalGasLimit: Hex;\n gasLimits: Hex[];\n }>(\n (acc, transaction) => {\n const gasLimit = transaction?.gasLimit;\n\n if (!gasLimit) {\n throw new Error(\n 'No simulated gas returned for one of the transactions',\n );\n }\n\n acc.gasLimits.push(gasLimit);\n\n acc.totalGasLimit = BNToHex(\n hexToBN(acc.totalGasLimit).add(hexToBN(gasLimit)),\n );\n\n return acc;\n },\n {\n totalGasLimit: '0x0',\n gasLimits: [],\n },\n );\n } catch (error: unknown) {\n log('Error while simulating gas batch', error);\n throw new Error(\n 'Cannot estimate transaction batch total gas as simulation failed',\n );\n }\n}\n\n/**\n * Determine the gas for the provided request.\n *\n * @param request - The request object including the necessary parameters.\n * @returns The final gas value and the estimate used.\n */\nasync function getGas(\n request: UpdateGasRequest,\n): Promise<[string, TransactionMeta['simulationFails']?, string?, Revert?]> {\n const {\n isCustomNetwork,\n isSimulationEnabled,\n getSimulationConfig,\n messenger,\n txMeta,\n } = request;\n const { networkClientId } = txMeta;\n const chainId = getChainId({ messenger, networkClientId });\n const { disableGasBuffer } = txMeta;\n\n if (txMeta.txParams.gas) {\n log('Using value from request', txMeta.txParams.gas);\n return [txMeta.txParams.gas, undefined, txMeta.txParams.gas];\n }\n\n const {\n blockGasLimit,\n estimatedGas,\n gasRevert,\n isUpgradeWithData,\n simulationFails,\n } = await estimateGas({\n isSimulationEnabled,\n getSimulationConfig,\n messenger,\n networkClientId,\n txParams: txMeta.txParams,\n });\n\n log('Original estimated gas', estimatedGas);\n\n if (simulationFails) {\n log('Using original fallback estimate as simulation failed');\n }\n\n if (disableGasBuffer) {\n log('Gas buffer disabled');\n }\n\n if (simulationFails || disableGasBuffer) {\n return [estimatedGas, simulationFails, estimatedGas, gasRevert];\n }\n\n const bufferMultiplier = getGasEstimateBuffer({\n chainId,\n isCustomRPC: isCustomNetwork,\n isUpgradeWithData,\n messenger,\n });\n\n log('Buffer', bufferMultiplier);\n\n const bufferedGas = addGasBuffer(\n estimatedGas,\n blockGasLimit,\n bufferMultiplier,\n );\n\n log('Buffered gas', bufferedGas);\n\n return [bufferedGas, simulationFails, estimatedGas, gasRevert];\n}\n\n/**\n * Get the latest block from the network.\n *\n * @param messenger - The messenger instance for communication.\n * @param networkClientId - The network client ID.\n * @returns The latest block number.\n */\nasync function getLatestBlock(\n messenger: TransactionControllerMessenger,\n networkClientId: NetworkClientId,\n): Promise<{ gasLimit: string; number: string }> {\n return (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_getBlockByNumber',\n params: ['latest', false],\n })) as { gasLimit: string; number: string };\n}\n\n/**\n * Estimate the gas for a type 4 transaction as one outer transaction.\n *\n * - If all authorizations are signed, the selected node estimates the exact\n * transaction.\n * - Otherwise, the Simulation API estimates the exact transaction, with the\n * authority of each authorization so that it can apply any EIP-2780 runtime\n * authorization charges.\n * - If the Simulation API is disabled, unsupported or unavailable, the selected\n * node estimates the transaction without unsigned authorizations and with the\n * delegation of the sender overridden. Intrinsic gas is added for each omitted\n * authorization, plus the EIP-2780 delegation charge if the sender is not yet\n * delegated. A simulated transaction error is not retried using the node.\n *\n * @param options - The options object.\n * @param options.authorizationList - The original authorization list of the transaction.\n * @param options.chainId - The chain ID of the transaction.\n * @param options.getSimulationConfig - The function to get the simulation configuration.\n * @param options.isSimulationEnabled - Whether the simulation is enabled.\n * @param options.messenger - The messenger instance for communication.\n * @param options.networkClientId - The network client ID.\n * @param options.txParams - The normalized transaction parameters.\n * @returns The estimated gas.\n */\nasync function estimateGasType4({\n authorizationList,\n chainId,\n getSimulationConfig,\n isSimulationEnabled,\n messenger,\n networkClientId,\n txParams,\n}: {\n authorizationList: AuthorizationList;\n chainId: Hex;\n getSimulationConfig: GetSimulationConfig;\n isSimulationEnabled: boolean;\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n txParams: TransactionParams;\n}): Promise<Hex> {\n if (authorizationList.every(isAuthorizationSigned)) {\n log('Estimating type 4 gas using node as all authorizations signed');\n return await estimateGasNode(messenger, networkClientId, txParams);\n }\n\n if (isSimulationEnabled) {\n const simulationAuthorizationList = authorizationList.map(\n (authorization) => {\n const authority = getAuthorizationAuthority(\n authorization,\n txParams.from,\n );\n\n if (!authority) {\n throw new Error('Cannot determine authority of signed authorization');\n }\n\n return { address: authorization.address, from: authority };\n },\n );\n\n log('Estimating type 4 gas using simulation', simulationAuthorizationList);\n\n try {\n return await simulateGas({\n authorizationList: simulationAuthorizationList,\n chainId,\n getSimulationConfig,\n transaction: txParams,\n });\n } catch (error) {\n if (error instanceof SimulatedTransactionError) {\n throw error;\n }\n\n log('Simulation unavailable, estimating type 4 gas using node', error);\n }\n }\n\n return await estimateGasType4Node({\n authorizationList,\n messenger,\n networkClientId,\n txParams,\n });\n}\n\n/**\n * Estimate the gas for a type 4 transaction with unsigned authorizations using\n * the selected node.\n *\n * Unsigned authorizations are omitted from the node request and their intrinsic\n * gas is added manually per entry. Their authority is the sender, so the\n * delegation of the sender is set with a state override, and the EIP-2780 charge\n * for a new delegation indicator is added once if the sender is not yet\n * delegated. Signed authorizations remain in the request and are charged by the\n * node.\n *\n * @param options - The options object.\n * @param options.authorizationList - The original authorization list of the transaction.\n * @param options.messenger - The messenger instance for communication.\n * @param options.networkClientId - The network client ID.\n * @param options.txParams - The normalized transaction parameters.\n * @returns The estimated gas including omitted authorization costs.\n */\nasync function estimateGasType4Node({\n authorizationList,\n messenger,\n networkClientId,\n txParams,\n}: {\n authorizationList: AuthorizationList;\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n txParams: TransactionParams;\n}): Promise<Hex> {\n const unsignedAuthorizations = authorizationList.filter(\n (authorization) => !isAuthorizationSigned(authorization),\n );\n const signedAuthorizations = authorizationList.filter(isAuthorizationSigned);\n const nodeTxParams = {\n ...txParams,\n authorizationList: signedAuthorizations.length\n ? signedAuthorizations\n : undefined,\n type: signedAuthorizations.length ? txParams.type : undefined,\n };\n\n // Unsigned authorizations are signed by the sender, and the last valid\n // authorization for an authority sets its delegation.\n const delegationAddress =\n unsignedAuthorizations[unsignedAuthorizations.length - 1].address;\n\n const [nodeGas, currentDelegationAddress] = await Promise.all([\n estimateGasNode(\n messenger,\n networkClientId,\n nodeTxParams,\n delegationAddress,\n ),\n getDelegationAddress(txParams.from as Hex, messenger, networkClientId),\n ]);\n\n const intrinsicGas =\n unsignedAuthorizations.length * EIP7280_AUTHORIZATION_INTRINSIC_GAS;\n const delegationGas = currentDelegationAddress\n ? 0\n : EIP_2780_AUTHORIZATION_GAS;\n\n log('Type 4 gas using node', {\n currentDelegationAddress,\n delegationGas,\n intrinsicGas,\n nodeGas,\n });\n\n return BNToHex(hexToBN(nodeGas).addn(intrinsicGas + delegationGas));\n}\n\n/**\n * Simulate the required gas using the simulation API.\n *\n * If an authorization list is provided, it is included in the simulated\n * transaction, a simulated transaction error is thrown as a\n * `SimulatedTransactionError`, and the response must include a non-zero gas\n * limit.\n *\n * @param options - The options object.\n * @param options.authorizationList - The authorization list with the authority of each entry.\n * @param options.chainId - The chain ID of the transaction.\n * @param options.getSimulationConfig - The function to get the simulation configuration.\n * @param options.transaction - The transaction parameters.\n * @returns The simulated gas.\n */\nasync function simulateGas({\n authorizationList,\n chainId,\n getSimulationConfig,\n transaction,\n}: {\n authorizationList?: SimulationRequestTransaction['authorizationList'];\n chainId: Hex;\n getSimulationConfig: GetSimulationConfig;\n transaction: TransactionParams;\n}): Promise<Hex> {\n const response = await simulateTransactions(chainId, {\n getSimulationConfig,\n transactions: [\n {\n ...(authorizationList ? { authorizationList } : {}),\n to: transaction.to as Hex,\n from: transaction.from as Hex,\n data: transaction.data as Hex,\n value: transaction.value as Hex,\n },\n ],\n });\n\n const simulatedTransaction = response?.transactions?.[0];\n const gasLimit = simulatedTransaction?.gasLimit;\n\n if (authorizationList && simulatedTransaction?.error) {\n throw new SimulatedTransactionError(\n `Simulation failed: ${simulatedTransaction.error}`,\n );\n }\n\n if (!gasLimit || (authorizationList && hexToBN(gasLimit).isZero())) {\n throw new Error('No simulated gas returned');\n }\n\n return gasLimit;\n}\n\n/**\n * Populate the authorization list with dummy values.\n *\n * @param authorizationList - The authorization list to prepare.\n * @param chainId - The chain ID to use.\n * @returns The authorization list with dummy values.\n */\nfunction normalizeAuthorizationList(\n authorizationList: AuthorizationList | undefined,\n chainId: Hex,\n): AuthorizationList | undefined {\n return authorizationList?.map((authorization) => ({\n ...authorization,\n chainId: authorization.chainId ?? chainId,\n nonce: authorization.nonce ?? '0x1',\n r: authorization.r ?? DUMMY_AUTHORIZATION_SIGNATURE,\n s: authorization.s ?? DUMMY_AUTHORIZATION_SIGNATURE,\n yParity: authorization.yParity ?? '0x1',\n }));\n}\n\n/**\n * Normalize the value to a canonical hex quantity with no leading zero digits.\n * Some RPC nodes (e.g. Go's `hexutil`) reject quantities such as `0x00` or\n * `0x0de0b6b3a7640000`, failing gas estimation entirely.\n *\n * @param value - The transaction value to normalize.\n * @returns The normalized transaction value.\n */\nfunction normalizeValue(value: string | undefined): string {\n const valueOrDefault = value ?? '0x0';\n\n if (!isStrictHexString(valueOrDefault)) {\n return valueOrDefault;\n }\n\n const stripped = remove0x(valueOrDefault).replace(/^0+/u, '');\n\n return stripped.length === 0 ? '0x0' : add0x(stripped);\n}\n\n/**\n * Estimate the gas for a transaction using the `eth_estimateGas` method.\n *\n * @param messenger - The messenger instance for communication.\n * @param networkClientId - The network client ID.\n * @param txParams - The transaction parameters.\n * @param delegationAddress - The delegation address of the sender to mock.\n * @returns The estimated gas as a hex string.\n */\nasync function estimateGasNode(\n messenger: TransactionControllerMessenger,\n networkClientId: NetworkClientId,\n txParams: TransactionParams,\n delegationAddress?: Hex,\n): Promise<Hex> {\n const { from } = txParams;\n const params = [txParams] as Json[];\n\n if (delegationAddress) {\n params.push('latest');\n\n params.push({\n [from]: {\n code: DELEGATION_PREFIX + remove0x(delegationAddress),\n },\n });\n }\n\n return (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_estimateGas',\n params,\n })) as Hex;\n}\n"]}
1
+ {"version":3,"file":"gas.js","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,UAAU,EACV,OAAO,EACP,KAAK,GACN,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EACL,KAAK,EACL,kBAAkB,EAClB,iBAAiB,EACjB,QAAQ,GACT,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE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C,eAAgC,EAChC,QAA2B,EAC3B,iBAAuB;IAEvB,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC;IAC1B,MAAM,MAAM,GAAG,CAAC,QAAQ,CAAW,CAAC;IAEpC,IAAI,iBAAiB,EAAE,CAAC;QACtB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEtB,MAAM,CAAC,IAAI,CAAC;YACV,CAAC,IAAI,CAAC,EAAE;gBACN,IAAI,EAAE,iBAAiB,GAAG,QAAQ,CAAC,iBAAiB,CAAC;aACtD;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,CAAC,MAAM,UAAU,CAAC;QACvB,SAAS;QACT,eAAe;QACf,MAAM,EAAE,iBAAiB;QACzB,MAAM;KACP,CAAC,CAAQ,CAAC;AACb,CAAC","sourcesContent":["import {\n BNToHex,\n fractionBN,\n hexToBN,\n toHex,\n} from '@metamask/controller-utils';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport type { SentinelSimulationTransaction } from '@metamask/sentinel-api-service';\nimport type { Hex, Json } from '@metamask/utils';\nimport {\n add0x,\n createModuleLogger,\n isStrictHexString,\n remove0x,\n} from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport { simulateTransactions } from '../api/simulation-api.js';\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport { TransactionEnvelopeType } from '../types.js';\nimport type {\n AuthorizationList,\n BatchTransactionParams,\n GetSimulationConfig,\n IsAtomicBatchSupportedRequest,\n IsAtomicBatchSupportedResult,\n Revert,\n TransactionBatchSingleRequest,\n TransactionMeta,\n TransactionParams,\n} from '../types.js';\nimport {\n DELEGATION_PREFIX,\n doesAccountSupportEIP7702,\n generateEIP7702BatchTransaction,\n getAuthorizationAuthority,\n getDelegationAddress,\n isAuthorizationSigned,\n} from './eip7702.js';\nimport {\n getGasEstimateBuffer,\n getGasEstimateFallback,\n} from './feature-flags.js';\nimport { getChainId, rpcRequest } from './provider.js';\nimport { decodeRevert } from './revert-reason.js';\n\nexport type UpdateGasRequest = {\n isCustomNetwork: boolean;\n isSimulationEnabled: boolean;\n getSimulationConfig?: GetSimulationConfig;\n messenger: TransactionControllerMessenger;\n txMeta: TransactionMeta;\n};\n\n/**\n * How the gas limits of a batch are applied.\n * - `eip7702` - A single gas limit for the outer EIP-7702 transaction.\n * - `separate` - One gas limit per transaction, submitted separately.\n */\nexport type EstimateGasBatchMode = 'eip7702' | 'separate';\n\nexport type EstimateGasBatchResult = {\n /** Gas limits, with a single entry if `mode` is `eip7702`. */\n gasLimits: number[];\n\n /** How the gas limits are applied. */\n mode: EstimateGasBatchMode;\n\n /** Whether the outer EIP-7702 transaction upgrades the sender. */\n requiresAuthorizationList?: true;\n\n /** Total of all gas limits. */\n totalGasLimit: number;\n};\n\nexport const log = createModuleLogger(projectLogger, 'gas');\n\nexport const DEFAULT_GAS_MULTIPLIER = 1.5;\nexport const MAX_GAS_BLOCK_PERCENT = 90;\n\nexport const DUMMY_AUTHORIZATION_SIGNATURE =\n '0x1111111111111111111111111111111111111111111111111111111111111111';\n\n/**\n * EIP-2780 state gas charged at runtime when a valid authorization sets a\n * delegation indicator for an authority that had none at the start of the\n * transaction, at most once per authority.\n *\n * When the authority is the sender, this is the only runtime authorization\n * charge: `ACCOUNT_WRITE` is covered by the transaction base cost, and the\n * sender always exists in state as its nonce is incremented first.\n */\nexport const EIP_2780_AUTHORIZATION_GAS = 35190;\n\n/**\n * Intrinsic gas cost for each authorization omitted from the node estimate.\n */\nexport const EIP7280_AUTHORIZATION_INTRINSIC_GAS = 7816;\n\n/**\n * Gas for the upgrade authorization of the sender that is not included in the\n * sum of the provided gas values of a batch: the EIP-7280 intrinsic cost of an\n * authorization plus the delegation indicator charge.\n */\nexport const UPGRADE_AUTHORIZATION_GAS =\n EIP7280_AUTHORIZATION_INTRINSIC_GAS + EIP_2780_AUTHORIZATION_GAS;\n\n/**\n * Error for a simulated transaction that failed, as opposed to the simulation\n * itself being unavailable.\n */\nclass SimulatedTransactionError extends Error {}\n\n/**\n * Populate the gas properties of the provided transaction meta.\n *\n * @param request - The request object including the necessary parameters.\n */\nexport async function updateGas(request: UpdateGasRequest): Promise<void> {\n const { txMeta } = request;\n const initialParams = { ...txMeta.txParams };\n\n const [gas, simulationFails, gasLimitNoBuffer, gasRevert] =\n await getGas(request);\n\n txMeta.txParams.gas = gas;\n txMeta.simulationFails = simulationFails;\n txMeta.gasLimitNoBuffer = gasLimitNoBuffer;\n\n if (gasRevert) {\n txMeta.revert = { ...txMeta.revert, gas: gasRevert };\n }\n\n if (!initialParams.gas) {\n txMeta.originalGasEstimate = txMeta.txParams.gas;\n }\n\n txMeta.defaultGasEstimates ??= {};\n txMeta.defaultGasEstimates.gas = txMeta.txParams.gas;\n}\n\n/**\n * Estimate the gas for the provided transaction parameters.\n * If the gas estimate fails, the fallback value is returned.\n *\n * @param options - The options object.\n * @param options.ignoreDelegationSignatures - Ignore signature errors if submitting delegations to the DelegationManager.\n * @param options.isSimulationEnabled - Whether the simulation is enabled.\n * @param options.getSimulationConfig - Optional callback to rewrite the simulation request URL.\n * @param options.messenger - The messenger instance for communication.\n * @param options.networkClientId - The network client ID.\n * @param options.txParams - The transaction parameters.\n * @returns The estimated gas and related info.\n */\nexport async function estimateGas({\n ignoreDelegationSignatures,\n isSimulationEnabled,\n getSimulationConfig,\n messenger,\n networkClientId,\n txParams,\n}: {\n ignoreDelegationSignatures?: boolean;\n isSimulationEnabled: boolean;\n getSimulationConfig?: GetSimulationConfig;\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n txParams: TransactionParams;\n}): Promise<{\n blockGasLimit: string;\n estimatedGas: string;\n gasRevert?: Revert;\n isUpgradeWithData: boolean;\n simulationFails: TransactionMeta['simulationFails'];\n}> {\n const request = { ...txParams };\n const { authorizationList, data, value } = request;\n const chainId = getChainId({ messenger, networkClientId });\n\n if (ignoreDelegationSignatures && !isSimulationEnabled) {\n throw new Error(\n 'Gas estimation with ignored delegation signatures is not supported as simulation disabled',\n );\n }\n\n const { gasLimit: blockGasLimit, number: blockNumber } = await getLatestBlock(\n messenger,\n networkClientId,\n );\n\n const blockGasLimitBN = hexToBN(blockGasLimit);\n const { percentage, fixed, maxGasLimit } = getGasEstimateFallback(\n chainId,\n messenger,\n );\n\n const uncappedFallback = fixed\n ? toHex(fixed)\n : BNToHex(fractionBN(blockGasLimitBN, percentage, 100));\n\n // Clamp the fallback to the chain's per-transaction gas cap so it can never\n // exceed the gas limit the RPC will accept. Without this, a percentage of a\n // high block gas limit can overshoot the cap (e.g. 35% of Polygon's ~140M\n // block limit is ~49M, but the node caps a tx at ~33.5M and rejects it with\n // \"transaction gas limit too high\").\n const fallback =\n maxGasLimit !== undefined &&\n hexToBN(uncappedFallback).gt(hexToBN(toHex(maxGasLimit)))\n ? toHex(maxGasLimit)\n : uncappedFallback;\n\n log('Estimation fallback values', fallback);\n\n request.data = data ? add0x(data) : data;\n request.value = normalizeValue(value);\n\n request.authorizationList = normalizeAuthorizationList(\n request.authorizationList,\n chainId,\n );\n\n delete request.gasPrice;\n delete request.maxFeePerGas;\n delete request.maxPriorityFeePerGas;\n\n let estimatedGas = fallback;\n let simulationFails: TransactionMeta['simulationFails'];\n let gasRevert: Revert | undefined;\n\n const isUpgradeWithData =\n txParams.type === TransactionEnvelopeType.setCode &&\n Boolean(authorizationList?.length) &&\n Boolean(data) &&\n data !== '0x';\n\n const type4AuthorizationList =\n txParams.type === TransactionEnvelopeType.setCode &&\n authorizationList?.length\n ? authorizationList\n : undefined;\n\n try {\n if (type4AuthorizationList) {\n estimatedGas = await estimateGasType4({\n authorizationList: type4AuthorizationList,\n chainId,\n getSimulationConfig,\n isSimulationEnabled,\n messenger,\n networkClientId,\n txParams: request,\n });\n } else if (ignoreDelegationSignatures && isSimulationEnabled) {\n estimatedGas = await simulateGas({\n chainId,\n getSimulationConfig,\n messenger,\n transaction: request,\n });\n } else {\n estimatedGas = await estimateGasNode(messenger, networkClientId, request);\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n simulationFails = {\n reason: error.message,\n errorKey: error.errorKey,\n debug: {\n blockNumber,\n blockGasLimit,\n },\n };\n\n gasRevert = decodeRevert(error, 'gas');\n\n log('Estimation failed', { ...simulationFails, fallback, gasRevert });\n }\n\n return {\n blockGasLimit,\n estimatedGas,\n gasRevert,\n isUpgradeWithData,\n simulationFails,\n };\n}\n\n/**\n * Sum caller-provided gas limits across a batch.\n *\n * If every transaction in the batch already has a `gas` value, returns the\n * parsed per-tx limits and their sum. Otherwise returns `undefined`.\n *\n * Used by `estimateGasBatch`:\n * - non-7702 path: short-circuits simulation entirely when present.\n * - EIP-7702 path: used as a fallback when simulation fails — required for\n * callers that submit batches whose individual sub-calls cannot be simulated\n * standalone (e.g. predict-withdraw, where the batch's first sub-call\n * provides source-token balance to subsequent sub-calls). When 7702\n * simulation succeeds it is preferred since the bundled call has no per-tx\n * intrinsic gas cost and produces a tighter estimate. If the sender requires\n * an upgrade, the fallback adds the authorization intrinsic gas and, if no\n * delegation exists yet, the delegation indicator charge. The provided gas\n * values do not include these authorization costs.\n *\n * @param transactions - Batch transactions to inspect.\n * @returns Parsed gas limits and total when every transaction has gas; otherwise `undefined`.\n */\nexport function getProvidedBatchGasLimits(\n transactions: BatchTransactionParams[],\n): { gasLimits: number[]; totalGasLimit: number } | undefined {\n if (!transactions.every((transaction) => transaction.gas !== undefined)) {\n return undefined;\n }\n\n const gasLimits = transactions.map((transaction) =>\n new BigNumber(transaction.gas as Hex).toNumber(),\n );\n const totalGasLimit = gasLimits.reduce((acc, gasLimit) => acc + gasLimit, 0);\n\n return { gasLimits, totalGasLimit };\n}\n\nexport async function estimateGasBatch({\n from,\n getSimulationConfig,\n isAtomicBatchSupported,\n messenger,\n networkClientId,\n transactions,\n}: {\n from: Hex;\n getSimulationConfig?: GetSimulationConfig;\n isAtomicBatchSupported: (\n request: IsAtomicBatchSupportedRequest,\n ) => Promise<IsAtomicBatchSupportedResult>;\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n transactions: BatchTransactionParams[];\n}): Promise<EstimateGasBatchResult> {\n const chainId = getChainId({ messenger, networkClientId });\n\n const is7702Result = await isAtomicBatchSupported({\n address: from,\n chainIds: [chainId],\n });\n\n const accountSupports7702 = doesAccountSupportEIP7702(messenger, from);\n\n const chainResult = accountSupports7702\n ? is7702Result.find((result) => result.chainId === chainId)\n : undefined;\n\n const isUpgradeRequired = Boolean(chainResult && !chainResult.isSupported);\n\n if (isUpgradeRequired && !chainResult?.upgradeContractAddress) {\n throw new Error('Upgrade contract address not found');\n }\n\n if (chainResult) {\n const providedBatchGasLimits = getProvidedBatchGasLimits(transactions);\n\n const authorizationList = isUpgradeRequired\n ? [{ address: chainResult.upgradeContractAddress as Hex }]\n : undefined;\n\n const type = isUpgradeRequired\n ? TransactionEnvelopeType.setCode\n : undefined;\n\n const params: TransactionParams = {\n ...generateEIP7702BatchTransaction(from, transactions),\n authorizationList,\n from,\n type,\n };\n\n // Prefer real EIP-7702 simulation when it succeeds — the bundled call has\n // no per-tx intrinsic gas cost so the estimate is typically lower than\n // summing per-tx provided limits. Fall back to the provided sum when the\n // node-level simulation fails (e.g. predict-withdraw, where the batch's\n // first sub-call provides source-token balance to subsequent sub-calls).\n const { estimatedGas: gasLimitHex, simulationFails } = await estimateGas({\n isSimulationEnabled: true,\n getSimulationConfig,\n messenger,\n networkClientId,\n txParams: params,\n });\n\n if (simulationFails && providedBatchGasLimits) {\n const upgradeGas = chainResult.delegationAddress\n ? EIP7280_AUTHORIZATION_INTRINSIC_GAS\n : UPGRADE_AUTHORIZATION_GAS;\n const fallbackGasLimit =\n providedBatchGasLimits.totalGasLimit +\n (isUpgradeRequired ? upgradeGas : 0);\n\n log(\n 'EIP-7702 estimation failed, using batch parameter gas limits',\n { fallbackGasLimit },\n simulationFails,\n );\n\n return {\n gasLimits: [fallbackGasLimit],\n mode: 'eip7702',\n ...(isUpgradeRequired ? { requiresAuthorizationList: true } : {}),\n totalGasLimit: fallbackGasLimit,\n };\n }\n\n const totalGasLimit = new BigNumber(gasLimitHex).toNumber();\n\n log('Estimated EIP-7702 gas limit', totalGasLimit);\n\n return {\n gasLimits: [totalGasLimit],\n mode: 'eip7702',\n ...(isUpgradeRequired ? { requiresAuthorizationList: true } : {}),\n totalGasLimit,\n };\n }\n\n const providedBatchGasLimits = getProvidedBatchGasLimits(transactions);\n if (providedBatchGasLimits) {\n log('Using batch parameter gas limits', providedBatchGasLimits);\n return { ...providedBatchGasLimits, mode: 'separate' };\n }\n\n const { gasLimits: gasLimitsHex } = await simulateGasBatch({\n chainId,\n from,\n getSimulationConfig,\n messenger,\n transactions: transactions.map((transaction) => ({\n params: transaction,\n })),\n });\n\n const gasLimits = transactions.map((transaction, index) =>\n transaction.gas\n ? new BigNumber(transaction.gas).toNumber()\n : new BigNumber(gasLimitsHex[index]).toNumber(),\n );\n\n const totalGasLimit = gasLimits.reduce((acc, gasLimit) => acc + gasLimit, 0);\n\n log('Simulated batch gas limits', { totalGasLimit, gasLimits });\n\n return { gasLimits, mode: 'separate', totalGasLimit };\n}\n\n/**\n * Add a buffer to the provided estimated gas.\n * The buffer is calculated based on the block gas limit and a multiplier.\n *\n * @param estimatedGas - The estimated gas.\n * @param blockGasLimit - The block gas limit.\n * @param multiplier - The multiplier to apply to the estimated gas.\n * @returns The gas with the buffer applied.\n */\nexport function addGasBuffer(\n estimatedGas: string,\n blockGasLimit: string,\n multiplier: number,\n): string {\n const estimatedGasBN = hexToBN(estimatedGas);\n\n const maxGasBN = fractionBN(\n hexToBN(blockGasLimit),\n MAX_GAS_BLOCK_PERCENT,\n 100,\n );\n\n const paddedGasBN = fractionBN(estimatedGasBN, multiplier * 100, 100);\n\n if (estimatedGasBN.gt(maxGasBN)) {\n const estimatedGasHex = add0x(estimatedGas);\n log('Using estimated value', estimatedGasHex);\n return estimatedGasHex;\n }\n\n if (paddedGasBN.lt(maxGasBN)) {\n const paddedHex = add0x(BNToHex(paddedGasBN));\n log('Using padded estimate', paddedHex, multiplier);\n return paddedHex;\n }\n\n const maxHex = add0x(BNToHex(maxGasBN));\n log('Using 90% of block gas limit', maxHex);\n return maxHex;\n}\n\n/**\n * Simulate the required gas for a batch of transactions using the simulation API.\n *\n * @param options - The options object.\n * @param options.chainId - The chain ID of the transactions.\n * @param options.from - The address of the sender.\n * @param options.getSimulationConfig - Optional callback to rewrite the simulation request URL.\n * @param options.messenger - The messenger instance used to invoke the Sentinel simulation action.\n * @param options.transactions - The array of transactions within a batch request.\n * @returns An object containing the transactions with their gas limits and the total gas limit.\n */\nexport async function simulateGasBatch({\n chainId,\n from,\n getSimulationConfig,\n messenger,\n transactions,\n}: {\n chainId: Hex;\n from: Hex;\n getSimulationConfig?: GetSimulationConfig;\n messenger: TransactionControllerMessenger;\n transactions: TransactionBatchSingleRequest[];\n}): Promise<{ totalGasLimit: Hex; gasLimits: Hex[] }> {\n try {\n const response = await simulateTransactions(\n messenger,\n chainId,\n {\n transactions: transactions.map((transaction) => ({\n ...transaction.params,\n from,\n })),\n },\n { getSimulationConfig },\n );\n\n if (response?.transactions?.length !== transactions.length) {\n throw new Error('Simulation response does not match transaction count');\n }\n\n return response.transactions.reduce<{\n totalGasLimit: Hex;\n gasLimits: Hex[];\n }>(\n (acc, transaction) => {\n const gasLimit = transaction?.gasLimit;\n\n if (!gasLimit) {\n throw new Error(\n 'No simulated gas returned for one of the transactions',\n );\n }\n\n acc.gasLimits.push(gasLimit);\n\n acc.totalGasLimit = BNToHex(\n hexToBN(acc.totalGasLimit).add(hexToBN(gasLimit)),\n );\n\n return acc;\n },\n {\n totalGasLimit: '0x0',\n gasLimits: [],\n },\n );\n } catch (error: unknown) {\n log('Error while simulating gas batch', error);\n throw new Error(\n 'Cannot estimate transaction batch total gas as simulation failed',\n );\n }\n}\n\n/**\n * Determine the gas for the provided request.\n *\n * @param request - The request object including the necessary parameters.\n * @returns The final gas value and the estimate used.\n */\nasync function getGas(\n request: UpdateGasRequest,\n): Promise<[string, TransactionMeta['simulationFails']?, string?, Revert?]> {\n const {\n isCustomNetwork,\n isSimulationEnabled,\n getSimulationConfig,\n messenger,\n txMeta,\n } = request;\n const { networkClientId } = txMeta;\n const chainId = getChainId({ messenger, networkClientId });\n const { disableGasBuffer } = txMeta;\n\n if (txMeta.txParams.gas) {\n log('Using value from request', txMeta.txParams.gas);\n return [txMeta.txParams.gas, undefined, txMeta.txParams.gas];\n }\n\n const {\n blockGasLimit,\n estimatedGas,\n gasRevert,\n isUpgradeWithData,\n simulationFails,\n } = await estimateGas({\n isSimulationEnabled,\n getSimulationConfig,\n messenger,\n networkClientId,\n txParams: txMeta.txParams,\n });\n\n log('Original estimated gas', estimatedGas);\n\n if (simulationFails) {\n log('Using original fallback estimate as simulation failed');\n }\n\n if (disableGasBuffer) {\n log('Gas buffer disabled');\n }\n\n if (simulationFails || disableGasBuffer) {\n return [estimatedGas, simulationFails, estimatedGas, gasRevert];\n }\n\n const bufferMultiplier = getGasEstimateBuffer({\n chainId,\n isCustomRPC: isCustomNetwork,\n isUpgradeWithData,\n messenger,\n });\n\n log('Buffer', bufferMultiplier);\n\n const bufferedGas = addGasBuffer(\n estimatedGas,\n blockGasLimit,\n bufferMultiplier,\n );\n\n log('Buffered gas', bufferedGas);\n\n return [bufferedGas, simulationFails, estimatedGas, gasRevert];\n}\n\n/**\n * Get the latest block from the network.\n *\n * @param messenger - The messenger instance for communication.\n * @param networkClientId - The network client ID.\n * @returns The latest block number.\n */\nasync function getLatestBlock(\n messenger: TransactionControllerMessenger,\n networkClientId: NetworkClientId,\n): Promise<{ gasLimit: string; number: string }> {\n return (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_getBlockByNumber',\n params: ['latest', false],\n })) as { gasLimit: string; number: string };\n}\n\n/**\n * Estimate the gas for a type 4 transaction as one outer transaction.\n *\n * - If all authorizations are signed, the selected node estimates the exact\n * transaction.\n * - Otherwise, the Simulation API estimates the exact transaction, with the\n * authority of each authorization so that it can apply any EIP-2780 runtime\n * authorization charges.\n * - If the Simulation API is disabled, unsupported or unavailable, the selected\n * node estimates the transaction without unsigned authorizations and with the\n * delegation of the sender overridden. Intrinsic gas is added for each omitted\n * authorization, plus the EIP-2780 delegation charge if the sender is not yet\n * delegated. A simulated transaction error is not retried using the node.\n *\n * @param options - The options object.\n * @param options.authorizationList - The original authorization list of the transaction.\n * @param options.chainId - The chain ID of the transaction.\n * @param options.getSimulationConfig - Optional callback to rewrite the simulation request URL.\n * @param options.isSimulationEnabled - Whether the simulation is enabled.\n * @param options.messenger - The messenger instance for communication.\n * @param options.networkClientId - The network client ID.\n * @param options.txParams - The normalized transaction parameters.\n * @returns The estimated gas.\n */\nasync function estimateGasType4({\n authorizationList,\n chainId,\n getSimulationConfig,\n isSimulationEnabled,\n messenger,\n networkClientId,\n txParams,\n}: {\n authorizationList: AuthorizationList;\n chainId: Hex;\n getSimulationConfig?: GetSimulationConfig;\n isSimulationEnabled: boolean;\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n txParams: TransactionParams;\n}): Promise<Hex> {\n if (authorizationList.every(isAuthorizationSigned)) {\n log('Estimating type 4 gas using node as all authorizations signed');\n return await estimateGasNode(messenger, networkClientId, txParams);\n }\n\n if (isSimulationEnabled) {\n const simulationAuthorizationList = authorizationList.map(\n (authorization) => {\n const authority = getAuthorizationAuthority(\n authorization,\n txParams.from,\n );\n\n if (!authority) {\n throw new Error('Cannot determine authority of signed authorization');\n }\n\n return { address: authorization.address, from: authority };\n },\n );\n\n log('Estimating type 4 gas using simulation', simulationAuthorizationList);\n\n try {\n return await simulateGas({\n authorizationList: simulationAuthorizationList,\n chainId,\n getSimulationConfig,\n messenger,\n transaction: txParams,\n });\n } catch (error) {\n if (error instanceof SimulatedTransactionError) {\n throw error;\n }\n\n log('Simulation unavailable, estimating type 4 gas using node', error);\n }\n }\n\n return await estimateGasType4Node({\n authorizationList,\n messenger,\n networkClientId,\n txParams,\n });\n}\n\n/**\n * Estimate the gas for a type 4 transaction with unsigned authorizations using\n * the selected node.\n *\n * Unsigned authorizations are omitted from the node request and their intrinsic\n * gas is added manually per entry. Their authority is the sender, so the\n * delegation of the sender is set with a state override, and the EIP-2780 charge\n * for a new delegation indicator is added once if the sender is not yet\n * delegated. Signed authorizations remain in the request and are charged by the\n * node.\n *\n * @param options - The options object.\n * @param options.authorizationList - The original authorization list of the transaction.\n * @param options.messenger - The messenger instance for communication.\n * @param options.networkClientId - The network client ID.\n * @param options.txParams - The normalized transaction parameters.\n * @returns The estimated gas including omitted authorization costs.\n */\nasync function estimateGasType4Node({\n authorizationList,\n messenger,\n networkClientId,\n txParams,\n}: {\n authorizationList: AuthorizationList;\n messenger: TransactionControllerMessenger;\n networkClientId: NetworkClientId;\n txParams: TransactionParams;\n}): Promise<Hex> {\n const unsignedAuthorizations = authorizationList.filter(\n (authorization) => !isAuthorizationSigned(authorization),\n );\n const signedAuthorizations = authorizationList.filter(isAuthorizationSigned);\n const nodeTxParams = {\n ...txParams,\n authorizationList: signedAuthorizations.length\n ? signedAuthorizations\n : undefined,\n type: signedAuthorizations.length ? txParams.type : undefined,\n };\n\n // Unsigned authorizations are signed by the sender, and the last valid\n // authorization for an authority sets its delegation.\n const delegationAddress =\n unsignedAuthorizations[unsignedAuthorizations.length - 1].address;\n\n const [nodeGas, currentDelegationAddress] = await Promise.all([\n estimateGasNode(\n messenger,\n networkClientId,\n nodeTxParams,\n delegationAddress,\n ),\n getDelegationAddress(txParams.from as Hex, messenger, networkClientId),\n ]);\n\n const intrinsicGas =\n unsignedAuthorizations.length * EIP7280_AUTHORIZATION_INTRINSIC_GAS;\n const delegationGas = currentDelegationAddress\n ? 0\n : EIP_2780_AUTHORIZATION_GAS;\n\n log('Type 4 gas using node', {\n currentDelegationAddress,\n delegationGas,\n intrinsicGas,\n nodeGas,\n });\n\n return BNToHex(hexToBN(nodeGas).addn(intrinsicGas + delegationGas));\n}\n\n/**\n * Simulate the required gas using the simulation API.\n *\n * If an authorization list is provided, it is included in the simulated\n * transaction, a simulated transaction error is thrown as a\n * `SimulatedTransactionError`, and the response must include a non-zero gas\n * limit.\n *\n * @param options - The options object.\n * @param options.authorizationList - The authorization list with the authority of each entry.\n * @param options.chainId - The chain ID of the transaction.\n * @param options.getSimulationConfig - Optional callback to rewrite the simulation request URL.\n * @param options.messenger - The messenger instance used to invoke the Sentinel simulation action.\n * @param options.transaction - The transaction parameters.\n * @returns The simulated gas.\n */\nasync function simulateGas({\n authorizationList,\n chainId,\n getSimulationConfig,\n messenger,\n transaction,\n}: {\n authorizationList?: SentinelSimulationTransaction['authorizationList'];\n chainId: Hex;\n getSimulationConfig?: GetSimulationConfig;\n messenger: TransactionControllerMessenger;\n transaction: TransactionParams;\n}): Promise<Hex> {\n const response = await simulateTransactions(\n messenger,\n chainId,\n {\n transactions: [\n {\n ...(authorizationList ? { authorizationList } : {}),\n to: transaction.to as Hex,\n from: transaction.from as Hex,\n data: transaction.data as Hex,\n value: transaction.value as Hex,\n },\n ],\n },\n { getSimulationConfig },\n );\n\n const simulatedTransaction = response?.transactions?.[0];\n const gasLimit = simulatedTransaction?.gasLimit;\n\n if (authorizationList && simulatedTransaction?.error) {\n throw new SimulatedTransactionError(\n `Simulation failed: ${simulatedTransaction.error}`,\n );\n }\n\n if (!gasLimit || (authorizationList && hexToBN(gasLimit).isZero())) {\n throw new Error('No simulated gas returned');\n }\n\n return gasLimit;\n}\n\n/**\n * Populate the authorization list with dummy values.\n *\n * @param authorizationList - The authorization list to prepare.\n * @param chainId - The chain ID to use.\n * @returns The authorization list with dummy values.\n */\nfunction normalizeAuthorizationList(\n authorizationList: AuthorizationList | undefined,\n chainId: Hex,\n): AuthorizationList | undefined {\n return authorizationList?.map((authorization) => ({\n ...authorization,\n chainId: authorization.chainId ?? chainId,\n nonce: authorization.nonce ?? '0x1',\n r: authorization.r ?? DUMMY_AUTHORIZATION_SIGNATURE,\n s: authorization.s ?? DUMMY_AUTHORIZATION_SIGNATURE,\n yParity: authorization.yParity ?? '0x1',\n }));\n}\n\n/**\n * Normalize the value to a canonical hex quantity with no leading zero digits.\n * Some RPC nodes (e.g. Go's `hexutil`) reject quantities such as `0x00` or\n * `0x0de0b6b3a7640000`, failing gas estimation entirely.\n *\n * @param value - The transaction value to normalize.\n * @returns The normalized transaction value.\n */\nfunction normalizeValue(value: string | undefined): string {\n const valueOrDefault = value ?? '0x0';\n\n if (!isStrictHexString(valueOrDefault)) {\n return valueOrDefault;\n }\n\n const stripped = remove0x(valueOrDefault).replace(/^0+/u, '');\n\n return stripped.length === 0 ? '0x0' : add0x(stripped);\n}\n\n/**\n * Estimate the gas for a transaction using the `eth_estimateGas` method.\n *\n * @param messenger - The messenger instance for communication.\n * @param networkClientId - The network client ID.\n * @param txParams - The transaction parameters.\n * @param delegationAddress - The delegation address of the sender to mock.\n * @returns The estimated gas as a hex string.\n */\nasync function estimateGasNode(\n messenger: TransactionControllerMessenger,\n networkClientId: NetworkClientId,\n txParams: TransactionParams,\n delegationAddress?: Hex,\n): Promise<Hex> {\n const { from } = txParams;\n const params = [txParams] as Json[];\n\n if (delegationAddress) {\n params.push('latest');\n\n params.push({\n [from]: {\n code: DELEGATION_PREFIX + remove0x(delegationAddress),\n },\n });\n }\n\n return (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_estimateGas',\n params,\n })) as Hex;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/transaction-controller",
3
- "version": "72.3.0-preview-406090321",
3
+ "version": "72.3.0-preview-313288d71",
4
4
  "description": "Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -69,6 +69,7 @@
69
69
  "@metamask/nonce-tracker": "^6.1.0",
70
70
  "@metamask/remote-feature-flag-controller": "^7.0.0",
71
71
  "@metamask/rpc-errors": "^7.0.3",
72
+ "@metamask/sentinel-api-service": "^2.1.0",
72
73
  "@metamask/utils": "^12.0.1",
73
74
  "async-mutex": "^0.5.0",
74
75
  "bignumber.js": "^9.1.2",