@metamask-previews/user-operation-controller 40.0.0-preview-d4351f75 → 40.0.0-preview-bf3ab7d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/UserOperationController.cjs +0 -4
  2. package/dist/UserOperationController.cjs.map +1 -1
  3. package/dist/UserOperationController.d.cts.map +1 -1
  4. package/dist/UserOperationController.d.mts.map +1 -1
  5. package/dist/UserOperationController.mjs +0 -4
  6. package/dist/UserOperationController.mjs.map +1 -1
  7. package/dist/helpers/Bundler.cjs +3 -5
  8. package/dist/helpers/Bundler.cjs.map +1 -1
  9. package/dist/helpers/Bundler.d.cts +2 -0
  10. package/dist/helpers/Bundler.d.cts.map +1 -1
  11. package/dist/helpers/Bundler.d.mts +2 -0
  12. package/dist/helpers/Bundler.d.mts.map +1 -1
  13. package/dist/helpers/Bundler.mjs +3 -5
  14. package/dist/helpers/Bundler.mjs.map +1 -1
  15. package/dist/helpers/PendingUserOperationTracker.cjs +1 -1
  16. package/dist/helpers/PendingUserOperationTracker.cjs.map +1 -1
  17. package/dist/helpers/PendingUserOperationTracker.d.cts +1 -1
  18. package/dist/helpers/PendingUserOperationTracker.d.cts.map +1 -1
  19. package/dist/helpers/PendingUserOperationTracker.d.mts +1 -1
  20. package/dist/helpers/PendingUserOperationTracker.d.mts.map +1 -1
  21. package/dist/helpers/PendingUserOperationTracker.mjs +1 -1
  22. package/dist/helpers/PendingUserOperationTracker.mjs.map +1 -1
  23. package/dist/helpers/SnapSmartContractAccount.cjs.map +1 -1
  24. package/dist/helpers/SnapSmartContractAccount.mjs.map +1 -1
  25. package/dist/types.cjs.map +1 -1
  26. package/dist/types.d.cts +3 -0
  27. package/dist/types.d.cts.map +1 -1
  28. package/dist/types.d.mts +3 -0
  29. package/dist/types.d.mts.map +1 -1
  30. package/dist/types.mjs.map +1 -1
  31. package/dist/utils/gas-fees.cjs +7 -0
  32. package/dist/utils/gas-fees.cjs.map +1 -1
  33. package/dist/utils/gas-fees.d.cts +1 -0
  34. package/dist/utils/gas-fees.d.cts.map +1 -1
  35. package/dist/utils/gas-fees.d.mts +1 -0
  36. package/dist/utils/gas-fees.d.mts.map +1 -1
  37. package/dist/utils/gas-fees.mjs +7 -0
  38. package/dist/utils/gas-fees.mjs.map +1 -1
  39. package/dist/utils/gas.cjs +2 -0
  40. package/dist/utils/gas.cjs.map +1 -1
  41. package/dist/utils/gas.d.cts +1 -0
  42. package/dist/utils/gas.d.cts.map +1 -1
  43. package/dist/utils/gas.d.mts +1 -0
  44. package/dist/utils/gas.d.mts.map +1 -1
  45. package/dist/utils/gas.mjs +2 -0
  46. package/dist/utils/gas.mjs.map +1 -1
  47. package/dist/utils/transaction.cjs +2 -0
  48. package/dist/utils/transaction.cjs.map +1 -1
  49. package/dist/utils/transaction.d.cts +1 -0
  50. package/dist/utils/transaction.d.cts.map +1 -1
  51. package/dist/utils/transaction.d.mts +1 -0
  52. package/dist/utils/transaction.d.mts.map +1 -1
  53. package/dist/utils/transaction.mjs +2 -0
  54. package/dist/utils/transaction.mjs.map +1 -1
  55. package/dist/utils/validation.cjs +8 -2
  56. package/dist/utils/validation.cjs.map +1 -1
  57. package/dist/utils/validation.d.cts +5 -0
  58. package/dist/utils/validation.d.cts.map +1 -1
  59. package/dist/utils/validation.d.mts +5 -0
  60. package/dist/utils/validation.d.mts.map +1 -1
  61. package/dist/utils/validation.mjs +8 -2
  62. package/dist/utils/validation.mjs.map +1 -1
  63. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"gas-fees.cjs","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":";;;;;;AAAA,iEAKoC;AACpC,oEAA2C;AAC3C,qEAGsC;AAGtC,6EAAgE;AAEhE,2CAAwC;AAExC,gDAA2C;AAC3C,0CAA8D;AAI9D,MAAM,GAAG,GAAG,IAAA,2BAAkB,EAAC,sBAAa,EAAE,UAAU,CAAC,CAAC;AAe1D;;;;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C,KAAK,CAAC,CAAC,CAAC;AACtC,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,CAAC,KAAK,IAAI,KAAK,KAAK,uBAAW,CAAC;AACzC,CAAC","sourcesContent":["import {\n gweiDecToWEIBN,\n ORIGIN_METAMASK,\n query,\n toHex,\n} from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport {\n GAS_ESTIMATE_TYPES,\n type GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { Provider } from '@metamask/network-controller';\nimport type { TransactionParams } from '@metamask/transaction-controller';\nimport { UserFeeLevel } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x } from '@metamask/utils';\n\nimport { EMPTY_BYTES } from '../constants';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { UserOperation, UserOperationMetadata } from '../types';\nimport type { AddUserOperationRequest } from '../UserOperationController';\n\nconst log = createModuleLogger(projectLogger, 'gas-fees');\n\nexport type UpdateGasFeesRequest = {\n getGasFeeEstimates: () => Promise<GasFeeState>;\n metadata: UserOperationMetadata;\n originalRequest: AddUserOperationRequest;\n provider: Provider;\n transaction?: TransactionParams;\n};\n\ntype SuggestedGasFees = {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n};\n\n/**\n * Populates the gas fee properties for a user operation.\n * @param request - The request to update the gas fees.\n * @param request.getGasFeeEstimates - A callback to get gas fee estimates.\n * @param request.metadata - The metadata for the user operation.\n * @param request.originalRequest - The original request to add the user operation.\n * @param request.provider - A provider to query the network.\n * @param request.transaction - The transaction that created the user operation.\n */\nexport async function updateGasFees(request: UpdateGasFeesRequest) {\n const { metadata, originalRequest, transaction } = request;\n const { userOperation } = metadata;\n let suggestedGasFees: SuggestedGasFees | undefined;\n\n const getGasFeeEstimates = async () => {\n if (!suggestedGasFees) {\n suggestedGasFees = await getSuggestedGasFees(request);\n }\n\n return suggestedGasFees;\n };\n\n userOperation.maxFeePerGas = await getMaxFeePerGas(\n originalRequest,\n getGasFeeEstimates,\n transaction,\n );\n\n userOperation.maxPriorityFeePerGas = await getMaxPriorityFeePerGas(\n originalRequest,\n getGasFeeEstimates,\n userOperation,\n transaction,\n );\n\n metadata.userFeeLevel = getUserFeeLevel(\n metadata,\n originalRequest,\n suggestedGasFees,\n transaction,\n );\n}\n\n/**\n * Gets the maxFeePerGas for a user operation.\n * @param originalRequest - The original request to add the user operation.\n * @param getGetFasEstimates - A callback to get gas fee estimates.\n * @param transaction - The transaction that created the user operation.\n * @returns The maxFeePerGas for the user operation.\n */\nasync function getMaxFeePerGas(\n originalRequest: AddUserOperationRequest,\n getGetFasEstimates: () => Promise<SuggestedGasFees>,\n transaction?: TransactionParams,\n) {\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n const { gasPrice } = transaction ?? {};\n\n if (!isGasFeeEmpty(maxFeePerGas)) {\n log('Using maxFeePerGas from request', maxFeePerGas);\n return maxFeePerGas as string;\n }\n\n if (isGasFeeEmpty(maxPriorityFeePerGas) && gasPrice) {\n log('Setting maxFeePerGas to transaction gasPrice', gasPrice);\n return gasPrice;\n }\n\n const { maxFeePerGas: suggestedMaxFeePerGas } = await getGetFasEstimates();\n\n if (!suggestedMaxFeePerGas) {\n throw new Error('Failed to get gas fee estimate for maxFeePerGas');\n }\n\n log('Using maxFeePerGas from estimate', suggestedMaxFeePerGas);\n\n return suggestedMaxFeePerGas;\n}\n\n/**\n * Gets the maxPriorityFeePerGas for a user operation.\n * @param originalRequest - The original request to add the user operation.\n * @param getGetFasEstimates - A callback to get gas fee estimates.\n * @param userOperation - The user operation being updated.\n * @param transaction - The transaction that created the user operation.\n * @returns The maxPriorityFeePerGas for the user operation.\n */\nasync function getMaxPriorityFeePerGas(\n originalRequest: AddUserOperationRequest,\n getGetFasEstimates: () => Promise<SuggestedGasFees>,\n userOperation: UserOperation,\n transaction?: TransactionParams,\n) {\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n const { gasPrice } = transaction ?? {};\n const { maxFeePerGas: updatedMaxFeePerGas } = userOperation;\n\n if (!isGasFeeEmpty(maxPriorityFeePerGas)) {\n log('Using maxPriorityFeePerGas from request', maxPriorityFeePerGas);\n return maxPriorityFeePerGas as string;\n }\n\n if (isGasFeeEmpty(maxFeePerGas) && gasPrice) {\n log('Setting maxPriorityFeePerGas to transaction gasPrice', gasPrice);\n return gasPrice;\n }\n\n const { maxPriorityFeePerGas: suggestedMaxPriorityFeePerGas } =\n await getGetFasEstimates();\n\n if (suggestedMaxPriorityFeePerGas) {\n log(\n 'Using maxPriorityFeePerGas from estimate',\n suggestedMaxPriorityFeePerGas,\n );\n return suggestedMaxPriorityFeePerGas;\n }\n\n log('Setting maxPriorityFeePerGas to maxFeePerGas', updatedMaxFeePerGas);\n\n return updatedMaxFeePerGas;\n}\n\n/**\n * Gets the userFeeLevel for a user operation.\n * @param metadata - The metadata for the user operation.\n * @param originalRequest - The original request to add the user operation.\n * @param suggestedGasFees - The suggested gas fees, if any.\n * @param transaction - The transaction that created the user operation.\n * @returns The userFeeLevel for the user operation.\n */\nfunction getUserFeeLevel(\n metadata: UserOperationMetadata,\n originalRequest: AddUserOperationRequest,\n suggestedGasFees?: SuggestedGasFees,\n transaction?: TransactionParams,\n): UserFeeLevel {\n const { origin } = metadata;\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n\n const {\n maxFeePerGas: suggestedMaxFeePerGas,\n maxPriorityFeePerGas: suggestedMaxPriorityFeePerGas,\n } = suggestedGasFees || {};\n\n if (\n isGasFeeEmpty(maxFeePerGas) &&\n isGasFeeEmpty(maxPriorityFeePerGas) &&\n transaction?.gasPrice\n ) {\n return origin === ORIGIN_METAMASK\n ? UserFeeLevel.CUSTOM\n : UserFeeLevel.DAPP_SUGGESTED;\n }\n\n if (\n isGasFeeEmpty(maxFeePerGas) &&\n isGasFeeEmpty(maxPriorityFeePerGas) &&\n suggestedMaxFeePerGas &&\n suggestedMaxPriorityFeePerGas\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (origin === ORIGIN_METAMASK) {\n return UserFeeLevel.CUSTOM;\n }\n\n return UserFeeLevel.DAPP_SUGGESTED;\n}\n\n/**\n * Gets suggested gas fees.\n * @param request - The request to update the gas fees.\n * @param request.getGasFeeEstimates - A callback to get gas fee estimates.\n * @param request.provider - A provider to query the network.\n * @returns The suggested gas fees.\n */\nasync function getSuggestedGasFees(\n request: UpdateGasFeesRequest,\n): Promise<{ maxFeePerGas?: Hex; maxPriorityFeePerGas?: Hex }> {\n const { getGasFeeEstimates, provider } = request;\n\n try {\n const { gasFeeEstimates, gasEstimateType } = await getGasFeeEstimates();\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n /* istanbul ignore next */\n const {\n medium: { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = {},\n } = gasFeeEstimates;\n\n if (suggestedMaxPriorityFeePerGas && suggestedMaxFeePerGas) {\n const values = {\n maxFeePerGas: gweiDecimalToWeiHex(suggestedMaxFeePerGas),\n maxPriorityFeePerGas: gweiDecimalToWeiHex(\n suggestedMaxPriorityFeePerGas,\n ),\n };\n\n log('Using medium values from fee market estimate', values);\n\n return values;\n }\n }\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {\n const maxFeePerGas = gweiDecimalToWeiHex(gasFeeEstimates.medium);\n\n log('Using medium value from legacy estimate', maxFeePerGas);\n\n return {\n maxFeePerGas,\n };\n }\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.ETH_GASPRICE) {\n const maxFeePerGas = gweiDecimalToWeiHex(gasFeeEstimates.gasPrice);\n\n log('Using gasPrice from estimate', maxFeePerGas);\n\n return {\n maxFeePerGas,\n };\n }\n } catch (error) {\n log('Failed to get estimate', error);\n }\n\n const gasPriceDecimal = (await query(new EthQuery(provider), 'gasPrice')) as\n | number\n | undefined;\n\n if (!gasPriceDecimal) {\n return {};\n }\n\n const maxFeePerGas = add0x(gasPriceDecimal.toString(16)) as Hex;\n\n log('Using gasPrice from network as fallback', maxFeePerGas);\n\n return { maxFeePerGas };\n}\n\n/**\n * Converts a GWEI decimal string to a WEI hexadecimal string.\n * @param value - The GWEI decimal string to convert.\n * @returns The WEI hexadecimal string.\n */\nfunction gweiDecimalToWeiHex(value: string) {\n return toHex(gweiDecToWEIBN(value));\n}\n\n/**\n * Checks if a gas fee property is empty.\n * @param value - The gas fee value to check.\n * @returns Whether the gas fee property is empty.\n */\nfunction isGasFeeEmpty(value?: string): boolean {\n return !value || value === EMPTY_BYTES;\n}\n"]}
1
+ {"version":3,"file":"gas-fees.cjs","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":";;;;;;AAAA,iEAKoC;AACpC,oEAA2C;AAC3C,qEAGsC;AAGtC,6EAAgE;AAEhE,2CAAwC;AAExC,gDAA2C;AAC3C,0CAA8D;AAI9D,MAAM,GAAG,GAAG,IAAA,2BAAkB,EAAC,sBAAa,EAAE,UAAU,CAAC,CAAC;AAe1D;;;;;;;;;GASG;AACI,KAAK,UAAU,aAAa,CAAC,OAA6B;IAC/D,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAC3D,MAAM,EAAE,aAAa,EAAE,GAAG,QAAQ,CAAC;IACnC,IAAI,gBAA8C,CAAC;IAEnD,MAAM,kBAAkB,GAAG,KAAK,IAAI,EAAE;QACpC,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,gBAAgB,GAAG,MAAM,mBAAmB,CAAC,OAAO,CAAC,CAAC;QACxD,CAAC;QAED,OAAO,gBAAgB,CAAC;IAC1B,CAAC,CAAC;IAEF,aAAa,CAAC,YAAY,GAAG,MAAM,eAAe,CAChD,eAAe,EACf,kBAAkB,EAClB,WAAW,CACZ,CAAC;IAEF,aAAa,CAAC,oBAAoB,GAAG,MAAM,uBAAuB,CAChE,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,WAAW,CACZ,CAAC;IAEF,QAA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C;YAElD,OAAO;gBACL,YAAY;aACb,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,eAAe,GAAG,CAAC,MAAM,IAAA,wBAAK,EAAC,IAAI,mBAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,CAE3D,CAAC;IAEd,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,YAAY,GAAG,IAAA,aAAK,EAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAQ,CAAC;IAEhE,GAAG,CAAC,yCAAyC,EAAE,YAAY,CAAC,CAAC;IAE7D,OAAO,EAAE,YAAY,EAAE,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,SAAS,mBAAmB,CAAC,KAAa;IACxC,OAAO,IAAA,wBAAK,EAAC,IAAA,iCAAc,EAAC,KAAK,CAAC,CAAC,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,CAAC,KAAK,IAAI,KAAK,KAAK,uBAAW,CAAC;AACzC,CAAC","sourcesContent":["import {\n gweiDecToWEIBN,\n ORIGIN_METAMASK,\n query,\n toHex,\n} from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport {\n GAS_ESTIMATE_TYPES,\n type GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { Provider } from '@metamask/network-controller';\nimport type { TransactionParams } from '@metamask/transaction-controller';\nimport { UserFeeLevel } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x } from '@metamask/utils';\n\nimport { EMPTY_BYTES } from '../constants';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { UserOperation, UserOperationMetadata } from '../types';\nimport type { AddUserOperationRequest } from '../UserOperationController';\n\nconst log = createModuleLogger(projectLogger, 'gas-fees');\n\nexport type UpdateGasFeesRequest = {\n getGasFeeEstimates: () => Promise<GasFeeState>;\n metadata: UserOperationMetadata;\n originalRequest: AddUserOperationRequest;\n provider: Provider;\n transaction?: TransactionParams;\n};\n\ntype SuggestedGasFees = {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n};\n\n/**\n * Populates the gas fee properties for a user operation.\n *\n * @param request - The request to update the gas fees.\n * @param request.getGasFeeEstimates - A callback to get gas fee estimates.\n * @param request.metadata - The metadata for the user operation.\n * @param request.originalRequest - The original request to add the user operation.\n * @param request.provider - A provider to query the network.\n * @param request.transaction - The transaction that created the user operation.\n */\nexport async function updateGasFees(request: UpdateGasFeesRequest) {\n const { metadata, originalRequest, transaction } = request;\n const { userOperation } = metadata;\n let suggestedGasFees: SuggestedGasFees | undefined;\n\n const getGasFeeEstimates = async () => {\n if (!suggestedGasFees) {\n suggestedGasFees = await getSuggestedGasFees(request);\n }\n\n return suggestedGasFees;\n };\n\n userOperation.maxFeePerGas = await getMaxFeePerGas(\n originalRequest,\n getGasFeeEstimates,\n transaction,\n );\n\n userOperation.maxPriorityFeePerGas = await getMaxPriorityFeePerGas(\n originalRequest,\n getGasFeeEstimates,\n userOperation,\n transaction,\n );\n\n metadata.userFeeLevel = getUserFeeLevel(\n metadata,\n originalRequest,\n suggestedGasFees,\n transaction,\n );\n}\n\n/**\n * Gets the maxFeePerGas for a user operation.\n *\n * @param originalRequest - The original request to add the user operation.\n * @param getGetFasEstimates - A callback to get gas fee estimates.\n * @param transaction - The transaction that created the user operation.\n * @returns The maxFeePerGas for the user operation.\n */\nasync function getMaxFeePerGas(\n originalRequest: AddUserOperationRequest,\n getGetFasEstimates: () => Promise<SuggestedGasFees>,\n transaction?: TransactionParams,\n) {\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n const { gasPrice } = transaction ?? {};\n\n if (!isGasFeeEmpty(maxFeePerGas)) {\n log('Using maxFeePerGas from request', maxFeePerGas);\n return maxFeePerGas as string;\n }\n\n if (isGasFeeEmpty(maxPriorityFeePerGas) && gasPrice) {\n log('Setting maxFeePerGas to transaction gasPrice', gasPrice);\n return gasPrice;\n }\n\n const { maxFeePerGas: suggestedMaxFeePerGas } = await getGetFasEstimates();\n\n if (!suggestedMaxFeePerGas) {\n throw new Error('Failed to get gas fee estimate for maxFeePerGas');\n }\n\n log('Using maxFeePerGas from estimate', suggestedMaxFeePerGas);\n\n return suggestedMaxFeePerGas;\n}\n\n/**\n * Gets the maxPriorityFeePerGas for a user operation.\n *\n * @param originalRequest - The original request to add the user operation.\n * @param getGetFasEstimates - A callback to get gas fee estimates.\n * @param userOperation - The user operation being updated.\n * @param transaction - The transaction that created the user operation.\n * @returns The maxPriorityFeePerGas for the user operation.\n */\nasync function getMaxPriorityFeePerGas(\n originalRequest: AddUserOperationRequest,\n getGetFasEstimates: () => Promise<SuggestedGasFees>,\n userOperation: UserOperation,\n transaction?: TransactionParams,\n) {\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n const { gasPrice } = transaction ?? {};\n const { maxFeePerGas: updatedMaxFeePerGas } = userOperation;\n\n if (!isGasFeeEmpty(maxPriorityFeePerGas)) {\n log('Using maxPriorityFeePerGas from request', maxPriorityFeePerGas);\n return maxPriorityFeePerGas as string;\n }\n\n if (isGasFeeEmpty(maxFeePerGas) && gasPrice) {\n log('Setting maxPriorityFeePerGas to transaction gasPrice', gasPrice);\n return gasPrice;\n }\n\n const { maxPriorityFeePerGas: suggestedMaxPriorityFeePerGas } =\n await getGetFasEstimates();\n\n if (suggestedMaxPriorityFeePerGas) {\n log(\n 'Using maxPriorityFeePerGas from estimate',\n suggestedMaxPriorityFeePerGas,\n );\n return suggestedMaxPriorityFeePerGas;\n }\n\n log('Setting maxPriorityFeePerGas to maxFeePerGas', updatedMaxFeePerGas);\n\n return updatedMaxFeePerGas;\n}\n\n/**\n * Gets the userFeeLevel for a user operation.\n *\n * @param metadata - The metadata for the user operation.\n * @param originalRequest - The original request to add the user operation.\n * @param suggestedGasFees - The suggested gas fees, if any.\n * @param transaction - The transaction that created the user operation.\n * @returns The userFeeLevel for the user operation.\n */\nfunction getUserFeeLevel(\n metadata: UserOperationMetadata,\n originalRequest: AddUserOperationRequest,\n suggestedGasFees?: SuggestedGasFees,\n transaction?: TransactionParams,\n): UserFeeLevel {\n const { origin } = metadata;\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n\n const {\n maxFeePerGas: suggestedMaxFeePerGas,\n maxPriorityFeePerGas: suggestedMaxPriorityFeePerGas,\n } = suggestedGasFees || {};\n\n if (\n isGasFeeEmpty(maxFeePerGas) &&\n isGasFeeEmpty(maxPriorityFeePerGas) &&\n transaction?.gasPrice\n ) {\n return origin === ORIGIN_METAMASK\n ? UserFeeLevel.CUSTOM\n : UserFeeLevel.DAPP_SUGGESTED;\n }\n\n if (\n isGasFeeEmpty(maxFeePerGas) &&\n isGasFeeEmpty(maxPriorityFeePerGas) &&\n suggestedMaxFeePerGas &&\n suggestedMaxPriorityFeePerGas\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (origin === ORIGIN_METAMASK) {\n return UserFeeLevel.CUSTOM;\n }\n\n return UserFeeLevel.DAPP_SUGGESTED;\n}\n\n/**\n * Gets suggested gas fees.\n *\n * @param request - The request to update the gas fees.\n * @param request.getGasFeeEstimates - A callback to get gas fee estimates.\n * @param request.provider - A provider to query the network.\n * @returns The suggested gas fees.\n */\nasync function getSuggestedGasFees(\n request: UpdateGasFeesRequest,\n): Promise<{ maxFeePerGas?: Hex; maxPriorityFeePerGas?: Hex }> {\n const { getGasFeeEstimates, provider } = request;\n\n try {\n const { gasFeeEstimates, gasEstimateType } = await getGasFeeEstimates();\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n /* istanbul ignore next */\n const {\n medium: { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = {},\n } = gasFeeEstimates;\n\n if (suggestedMaxPriorityFeePerGas && suggestedMaxFeePerGas) {\n const values = {\n maxFeePerGas: gweiDecimalToWeiHex(suggestedMaxFeePerGas),\n maxPriorityFeePerGas: gweiDecimalToWeiHex(\n suggestedMaxPriorityFeePerGas,\n ),\n };\n\n log('Using medium values from fee market estimate', values);\n\n return values;\n }\n }\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {\n const maxFeePerGas = gweiDecimalToWeiHex(gasFeeEstimates.medium);\n\n log('Using medium value from legacy estimate', maxFeePerGas);\n\n return {\n maxFeePerGas,\n };\n }\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.ETH_GASPRICE) {\n const maxFeePerGas = gweiDecimalToWeiHex(gasFeeEstimates.gasPrice);\n\n log('Using gasPrice from estimate', maxFeePerGas);\n\n return {\n maxFeePerGas,\n };\n }\n } catch (error) {\n log('Failed to get estimate', error);\n }\n\n const gasPriceDecimal = (await query(new EthQuery(provider), 'gasPrice')) as\n | number\n | undefined;\n\n if (!gasPriceDecimal) {\n return {};\n }\n\n const maxFeePerGas = add0x(gasPriceDecimal.toString(16)) as Hex;\n\n log('Using gasPrice from network as fallback', maxFeePerGas);\n\n return { maxFeePerGas };\n}\n\n/**\n * Converts a GWEI decimal string to a WEI hexadecimal string.\n *\n * @param value - The GWEI decimal string to convert.\n * @returns The WEI hexadecimal string.\n */\nfunction gweiDecimalToWeiHex(value: string) {\n return toHex(gweiDecToWEIBN(value));\n}\n\n/**\n * Checks if a gas fee property is empty.\n *\n * @param value - The gas fee value to check.\n * @returns Whether the gas fee property is empty.\n */\nfunction isGasFeeEmpty(value?: string): boolean {\n return !value || value === EMPTY_BYTES;\n}\n"]}
@@ -12,6 +12,7 @@ export type UpdateGasFeesRequest = {
12
12
  };
13
13
  /**
14
14
  * Populates the gas fee properties for a user operation.
15
+ *
15
16
  * @param request - The request to update the gas fees.
16
17
  * @param request.getGasFeeEstimates - A callback to get gas fee estimates.
17
18
  * @param request.metadata - The metadata for the user operation.
@@ -1 +1 @@
1
- {"version":3,"file":"gas-fees.d.cts","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,KAAK,WAAW,EACjB,qCAAqC;AACtC,OAAO,KAAK,EAAE,QAAQ,EAAE,qCAAqC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,yCAAyC;AAO1E,OAAO,KAAK,EAAiB,qBAAqB,EAAE,qBAAiB;AACrE,OAAO,KAAK,EAAE,uBAAuB,EAAE,uCAAmC;AAI1E,MAAM,MAAM,oBAAoB,GAAG;IACjC,kBAAkB,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/C,QAAQ,EAAE,qBAAqB,CAAC;IAChC,eAAe,EAAE,uBAAuB,CAAC;IACzC,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC,CAAC;AAOF;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,iBAgChE"}
1
+ {"version":3,"file":"gas-fees.d.cts","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,KAAK,WAAW,EACjB,qCAAqC;AACtC,OAAO,KAAK,EAAE,QAAQ,EAAE,qCAAqC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,yCAAyC;AAO1E,OAAO,KAAK,EAAiB,qBAAqB,EAAE,qBAAiB;AACrE,OAAO,KAAK,EAAE,uBAAuB,EAAE,uCAAmC;AAI1E,MAAM,MAAM,oBAAoB,GAAG;IACjC,kBAAkB,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/C,QAAQ,EAAE,qBAAqB,CAAC;IAChC,eAAe,EAAE,uBAAuB,CAAC;IACzC,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC,CAAC;AAOF;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,iBAgChE"}
@@ -12,6 +12,7 @@ export type UpdateGasFeesRequest = {
12
12
  };
13
13
  /**
14
14
  * Populates the gas fee properties for a user operation.
15
+ *
15
16
  * @param request - The request to update the gas fees.
16
17
  * @param request.getGasFeeEstimates - A callback to get gas fee estimates.
17
18
  * @param request.metadata - The metadata for the user operation.
@@ -1 +1 @@
1
- {"version":3,"file":"gas-fees.d.mts","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,KAAK,WAAW,EACjB,qCAAqC;AACtC,OAAO,KAAK,EAAE,QAAQ,EAAE,qCAAqC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,yCAAyC;AAO1E,OAAO,KAAK,EAAiB,qBAAqB,EAAE,qBAAiB;AACrE,OAAO,KAAK,EAAE,uBAAuB,EAAE,uCAAmC;AAI1E,MAAM,MAAM,oBAAoB,GAAG;IACjC,kBAAkB,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/C,QAAQ,EAAE,qBAAqB,CAAC;IAChC,eAAe,EAAE,uBAAuB,CAAC;IACzC,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC,CAAC;AAOF;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,iBAgChE"}
1
+ {"version":3,"file":"gas-fees.d.mts","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,KAAK,WAAW,EACjB,qCAAqC;AACtC,OAAO,KAAK,EAAE,QAAQ,EAAE,qCAAqC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,yCAAyC;AAO1E,OAAO,KAAK,EAAiB,qBAAqB,EAAE,qBAAiB;AACrE,OAAO,KAAK,EAAE,uBAAuB,EAAE,uCAAmC;AAI1E,MAAM,MAAM,oBAAoB,GAAG;IACjC,kBAAkB,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/C,QAAQ,EAAE,qBAAqB,CAAC;IAChC,eAAe,EAAE,uBAAuB,CAAC;IACzC,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC,CAAC;AAOF;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,iBAgChE"}
@@ -15,6 +15,7 @@ import { createModuleLogger, projectLogger } from "../logger.mjs";
15
15
  const log = createModuleLogger(projectLogger, 'gas-fees');
16
16
  /**
17
17
  * Populates the gas fee properties for a user operation.
18
+ *
18
19
  * @param request - The request to update the gas fees.
19
20
  * @param request.getGasFeeEstimates - A callback to get gas fee estimates.
20
21
  * @param request.metadata - The metadata for the user operation.
@@ -38,6 +39,7 @@ export async function updateGasFees(request) {
38
39
  }
39
40
  /**
40
41
  * Gets the maxFeePerGas for a user operation.
42
+ *
41
43
  * @param originalRequest - The original request to add the user operation.
42
44
  * @param getGetFasEstimates - A callback to get gas fee estimates.
43
45
  * @param transaction - The transaction that created the user operation.
@@ -63,6 +65,7 @@ async function getMaxFeePerGas(originalRequest, getGetFasEstimates, transaction)
63
65
  }
64
66
  /**
65
67
  * Gets the maxPriorityFeePerGas for a user operation.
68
+ *
66
69
  * @param originalRequest - The original request to add the user operation.
67
70
  * @param getGetFasEstimates - A callback to get gas fee estimates.
68
71
  * @param userOperation - The user operation being updated.
@@ -91,6 +94,7 @@ async function getMaxPriorityFeePerGas(originalRequest, getGetFasEstimates, user
91
94
  }
92
95
  /**
93
96
  * Gets the userFeeLevel for a user operation.
97
+ *
94
98
  * @param metadata - The metadata for the user operation.
95
99
  * @param originalRequest - The original request to add the user operation.
96
100
  * @param suggestedGasFees - The suggested gas fees, if any.
@@ -121,6 +125,7 @@ function getUserFeeLevel(metadata, originalRequest, suggestedGasFees, transactio
121
125
  }
122
126
  /**
123
127
  * Gets suggested gas fees.
128
+ *
124
129
  * @param request - The request to update the gas fees.
125
130
  * @param request.getGasFeeEstimates - A callback to get gas fee estimates.
126
131
  * @param request.provider - A provider to query the network.
@@ -170,6 +175,7 @@ async function getSuggestedGasFees(request) {
170
175
  }
171
176
  /**
172
177
  * Converts a GWEI decimal string to a WEI hexadecimal string.
178
+ *
173
179
  * @param value - The GWEI decimal string to convert.
174
180
  * @returns The WEI hexadecimal string.
175
181
  */
@@ -178,6 +184,7 @@ function gweiDecimalToWeiHex(value) {
178
184
  }
179
185
  /**
180
186
  * Checks if a gas fee property is empty.
187
+ *
181
188
  * @param value - The gas fee value to check.
182
189
  * @returns Whether the gas fee property is empty.
183
190
  */
@@ -1 +1 @@
1
- {"version":3,"file":"gas-fees.mjs","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,cAAc,EACd,eAAe,EACf,KAAK,EACL,KAAK,EACN,mCAAmC;AACpC,OAAO,SAAQ,4BAA4B;;AAC3C,OAAO,EACL,kBAAkB,EAEnB,qCAAqC;AAGtC,OAAO,EAAE,YAAY,EAAE,yCAAyC;AAEhE,OAAO,EAAE,KAAK,EAAE,wBAAwB;AAExC,OAAO,EAAE,WAAW,EAAE,yBAAqB;AAC3C,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,sBAAkB;AAI9D,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;AAe1D;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAA6B;IAC/D,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAC3D,MAAM,EAAE,aAAa,EAAE,GAAG,QAAQ,CAAC;IACnC,IAAI,gBAA8C,CAAC;IAEnD,MAAM,kBAAkB,GAAG,KAAK,IAAI,EAAE;QACpC,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,gBAAgB,GAAG,MAAM,mBAAmB,CAAC,OAAO,CAAC,CAAC;QACxD,CAAC;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;YAE7D,OAAO;gBACL,YAAY;aACb,CAAC;QACJ,CAAC;QAED,IAAI,eAAe,KAAK,kBAAkB,CAAC,YAAY,EAAE,CAAC;YACxD,MAAM,YAAY,GAAG,mBAAmB,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;YAEnE,GAAG,CAAC,8BAA8B,EAAE,YAAY,CAAC,CAAC;YAElD,OAAO;gBACL,YAAY;aACb,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,eAAe,GAAG,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,CAE3D,CAAC;IAEd,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,YAAY,GAAG,KAAK,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAQ,CAAC;IAEhE,GAAG,CAAC,yCAAyC,EAAE,YAAY,CAAC,CAAC;IAE7D,OAAO,EAAE,YAAY,EAAE,CAAC;AAC1B,CAAC;AAED;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,KAAa;IACxC,OAAO,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;AACtC,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,CAAC,KAAK,IAAI,KAAK,KAAK,WAAW,CAAC;AACzC,CAAC","sourcesContent":["import {\n gweiDecToWEIBN,\n ORIGIN_METAMASK,\n query,\n toHex,\n} from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport {\n GAS_ESTIMATE_TYPES,\n type GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { Provider } from '@metamask/network-controller';\nimport type { TransactionParams } from '@metamask/transaction-controller';\nimport { UserFeeLevel } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x } from '@metamask/utils';\n\nimport { EMPTY_BYTES } from '../constants';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { UserOperation, UserOperationMetadata } from '../types';\nimport type { AddUserOperationRequest } from '../UserOperationController';\n\nconst log = createModuleLogger(projectLogger, 'gas-fees');\n\nexport type UpdateGasFeesRequest = {\n getGasFeeEstimates: () => Promise<GasFeeState>;\n metadata: UserOperationMetadata;\n originalRequest: AddUserOperationRequest;\n provider: Provider;\n transaction?: TransactionParams;\n};\n\ntype SuggestedGasFees = {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n};\n\n/**\n * Populates the gas fee properties for a user operation.\n * @param request - The request to update the gas fees.\n * @param request.getGasFeeEstimates - A callback to get gas fee estimates.\n * @param request.metadata - The metadata for the user operation.\n * @param request.originalRequest - The original request to add the user operation.\n * @param request.provider - A provider to query the network.\n * @param request.transaction - The transaction that created the user operation.\n */\nexport async function updateGasFees(request: UpdateGasFeesRequest) {\n const { metadata, originalRequest, transaction } = request;\n const { userOperation } = metadata;\n let suggestedGasFees: SuggestedGasFees | undefined;\n\n const getGasFeeEstimates = async () => {\n if (!suggestedGasFees) {\n suggestedGasFees = await getSuggestedGasFees(request);\n }\n\n return suggestedGasFees;\n };\n\n userOperation.maxFeePerGas = await getMaxFeePerGas(\n originalRequest,\n getGasFeeEstimates,\n transaction,\n );\n\n userOperation.maxPriorityFeePerGas = await getMaxPriorityFeePerGas(\n originalRequest,\n getGasFeeEstimates,\n userOperation,\n transaction,\n );\n\n metadata.userFeeLevel = getUserFeeLevel(\n metadata,\n originalRequest,\n suggestedGasFees,\n transaction,\n );\n}\n\n/**\n * Gets the maxFeePerGas for a user operation.\n * @param originalRequest - The original request to add the user operation.\n * @param getGetFasEstimates - A callback to get gas fee estimates.\n * @param transaction - The transaction that created the user operation.\n * @returns The maxFeePerGas for the user operation.\n */\nasync function getMaxFeePerGas(\n originalRequest: AddUserOperationRequest,\n getGetFasEstimates: () => Promise<SuggestedGasFees>,\n transaction?: TransactionParams,\n) {\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n const { gasPrice } = transaction ?? {};\n\n if (!isGasFeeEmpty(maxFeePerGas)) {\n log('Using maxFeePerGas from request', maxFeePerGas);\n return maxFeePerGas as string;\n }\n\n if (isGasFeeEmpty(maxPriorityFeePerGas) && gasPrice) {\n log('Setting maxFeePerGas to transaction gasPrice', gasPrice);\n return gasPrice;\n }\n\n const { maxFeePerGas: suggestedMaxFeePerGas } = await getGetFasEstimates();\n\n if (!suggestedMaxFeePerGas) {\n throw new Error('Failed to get gas fee estimate for maxFeePerGas');\n }\n\n log('Using maxFeePerGas from estimate', suggestedMaxFeePerGas);\n\n return suggestedMaxFeePerGas;\n}\n\n/**\n * Gets the maxPriorityFeePerGas for a user operation.\n * @param originalRequest - The original request to add the user operation.\n * @param getGetFasEstimates - A callback to get gas fee estimates.\n * @param userOperation - The user operation being updated.\n * @param transaction - The transaction that created the user operation.\n * @returns The maxPriorityFeePerGas for the user operation.\n */\nasync function getMaxPriorityFeePerGas(\n originalRequest: AddUserOperationRequest,\n getGetFasEstimates: () => Promise<SuggestedGasFees>,\n userOperation: UserOperation,\n transaction?: TransactionParams,\n) {\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n const { gasPrice } = transaction ?? {};\n const { maxFeePerGas: updatedMaxFeePerGas } = userOperation;\n\n if (!isGasFeeEmpty(maxPriorityFeePerGas)) {\n log('Using maxPriorityFeePerGas from request', maxPriorityFeePerGas);\n return maxPriorityFeePerGas as string;\n }\n\n if (isGasFeeEmpty(maxFeePerGas) && gasPrice) {\n log('Setting maxPriorityFeePerGas to transaction gasPrice', gasPrice);\n return gasPrice;\n }\n\n const { maxPriorityFeePerGas: suggestedMaxPriorityFeePerGas } =\n await getGetFasEstimates();\n\n if (suggestedMaxPriorityFeePerGas) {\n log(\n 'Using maxPriorityFeePerGas from estimate',\n suggestedMaxPriorityFeePerGas,\n );\n return suggestedMaxPriorityFeePerGas;\n }\n\n log('Setting maxPriorityFeePerGas to maxFeePerGas', updatedMaxFeePerGas);\n\n return updatedMaxFeePerGas;\n}\n\n/**\n * Gets the userFeeLevel for a user operation.\n * @param metadata - The metadata for the user operation.\n * @param originalRequest - The original request to add the user operation.\n * @param suggestedGasFees - The suggested gas fees, if any.\n * @param transaction - The transaction that created the user operation.\n * @returns The userFeeLevel for the user operation.\n */\nfunction getUserFeeLevel(\n metadata: UserOperationMetadata,\n originalRequest: AddUserOperationRequest,\n suggestedGasFees?: SuggestedGasFees,\n transaction?: TransactionParams,\n): UserFeeLevel {\n const { origin } = metadata;\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n\n const {\n maxFeePerGas: suggestedMaxFeePerGas,\n maxPriorityFeePerGas: suggestedMaxPriorityFeePerGas,\n } = suggestedGasFees || {};\n\n if (\n isGasFeeEmpty(maxFeePerGas) &&\n isGasFeeEmpty(maxPriorityFeePerGas) &&\n transaction?.gasPrice\n ) {\n return origin === ORIGIN_METAMASK\n ? UserFeeLevel.CUSTOM\n : UserFeeLevel.DAPP_SUGGESTED;\n }\n\n if (\n isGasFeeEmpty(maxFeePerGas) &&\n isGasFeeEmpty(maxPriorityFeePerGas) &&\n suggestedMaxFeePerGas &&\n suggestedMaxPriorityFeePerGas\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (origin === ORIGIN_METAMASK) {\n return UserFeeLevel.CUSTOM;\n }\n\n return UserFeeLevel.DAPP_SUGGESTED;\n}\n\n/**\n * Gets suggested gas fees.\n * @param request - The request to update the gas fees.\n * @param request.getGasFeeEstimates - A callback to get gas fee estimates.\n * @param request.provider - A provider to query the network.\n * @returns The suggested gas fees.\n */\nasync function getSuggestedGasFees(\n request: UpdateGasFeesRequest,\n): Promise<{ maxFeePerGas?: Hex; maxPriorityFeePerGas?: Hex }> {\n const { getGasFeeEstimates, provider } = request;\n\n try {\n const { gasFeeEstimates, gasEstimateType } = await getGasFeeEstimates();\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n /* istanbul ignore next */\n const {\n medium: { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = {},\n } = gasFeeEstimates;\n\n if (suggestedMaxPriorityFeePerGas && suggestedMaxFeePerGas) {\n const values = {\n maxFeePerGas: gweiDecimalToWeiHex(suggestedMaxFeePerGas),\n maxPriorityFeePerGas: gweiDecimalToWeiHex(\n suggestedMaxPriorityFeePerGas,\n ),\n };\n\n log('Using medium values from fee market estimate', values);\n\n return values;\n }\n }\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {\n const maxFeePerGas = gweiDecimalToWeiHex(gasFeeEstimates.medium);\n\n log('Using medium value from legacy estimate', maxFeePerGas);\n\n return {\n maxFeePerGas,\n };\n }\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.ETH_GASPRICE) {\n const maxFeePerGas = gweiDecimalToWeiHex(gasFeeEstimates.gasPrice);\n\n log('Using gasPrice from estimate', maxFeePerGas);\n\n return {\n maxFeePerGas,\n };\n }\n } catch (error) {\n log('Failed to get estimate', error);\n }\n\n const gasPriceDecimal = (await query(new EthQuery(provider), 'gasPrice')) as\n | number\n | undefined;\n\n if (!gasPriceDecimal) {\n return {};\n }\n\n const maxFeePerGas = add0x(gasPriceDecimal.toString(16)) as Hex;\n\n log('Using gasPrice from network as fallback', maxFeePerGas);\n\n return { maxFeePerGas };\n}\n\n/**\n * Converts a GWEI decimal string to a WEI hexadecimal string.\n * @param value - The GWEI decimal string to convert.\n * @returns The WEI hexadecimal string.\n */\nfunction gweiDecimalToWeiHex(value: string) {\n return toHex(gweiDecToWEIBN(value));\n}\n\n/**\n * Checks if a gas fee property is empty.\n * @param value - The gas fee value to check.\n * @returns Whether the gas fee property is empty.\n */\nfunction isGasFeeEmpty(value?: string): boolean {\n return !value || value === EMPTY_BYTES;\n}\n"]}
1
+ {"version":3,"file":"gas-fees.mjs","sourceRoot":"","sources":["../../src/utils/gas-fees.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Q,CAAC,EAAE,UAAU,CAAC,CAE3D,CAAC;IAEd,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,YAAY,GAAG,KAAK,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAQ,CAAC;IAEhE,GAAG,CAAC,yCAAyC,EAAE,YAAY,CAAC,CAAC;IAE7D,OAAO,EAAE,YAAY,EAAE,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,SAAS,mBAAmB,CAAC,KAAa;IACxC,OAAO,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,CAAC,KAAK,IAAI,KAAK,KAAK,WAAW,CAAC;AACzC,CAAC","sourcesContent":["import {\n gweiDecToWEIBN,\n ORIGIN_METAMASK,\n query,\n toHex,\n} from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport {\n GAS_ESTIMATE_TYPES,\n type GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type { Provider } from '@metamask/network-controller';\nimport type { TransactionParams } from '@metamask/transaction-controller';\nimport { UserFeeLevel } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x } from '@metamask/utils';\n\nimport { EMPTY_BYTES } from '../constants';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { UserOperation, UserOperationMetadata } from '../types';\nimport type { AddUserOperationRequest } from '../UserOperationController';\n\nconst log = createModuleLogger(projectLogger, 'gas-fees');\n\nexport type UpdateGasFeesRequest = {\n getGasFeeEstimates: () => Promise<GasFeeState>;\n metadata: UserOperationMetadata;\n originalRequest: AddUserOperationRequest;\n provider: Provider;\n transaction?: TransactionParams;\n};\n\ntype SuggestedGasFees = {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n};\n\n/**\n * Populates the gas fee properties for a user operation.\n *\n * @param request - The request to update the gas fees.\n * @param request.getGasFeeEstimates - A callback to get gas fee estimates.\n * @param request.metadata - The metadata for the user operation.\n * @param request.originalRequest - The original request to add the user operation.\n * @param request.provider - A provider to query the network.\n * @param request.transaction - The transaction that created the user operation.\n */\nexport async function updateGasFees(request: UpdateGasFeesRequest) {\n const { metadata, originalRequest, transaction } = request;\n const { userOperation } = metadata;\n let suggestedGasFees: SuggestedGasFees | undefined;\n\n const getGasFeeEstimates = async () => {\n if (!suggestedGasFees) {\n suggestedGasFees = await getSuggestedGasFees(request);\n }\n\n return suggestedGasFees;\n };\n\n userOperation.maxFeePerGas = await getMaxFeePerGas(\n originalRequest,\n getGasFeeEstimates,\n transaction,\n );\n\n userOperation.maxPriorityFeePerGas = await getMaxPriorityFeePerGas(\n originalRequest,\n getGasFeeEstimates,\n userOperation,\n transaction,\n );\n\n metadata.userFeeLevel = getUserFeeLevel(\n metadata,\n originalRequest,\n suggestedGasFees,\n transaction,\n );\n}\n\n/**\n * Gets the maxFeePerGas for a user operation.\n *\n * @param originalRequest - The original request to add the user operation.\n * @param getGetFasEstimates - A callback to get gas fee estimates.\n * @param transaction - The transaction that created the user operation.\n * @returns The maxFeePerGas for the user operation.\n */\nasync function getMaxFeePerGas(\n originalRequest: AddUserOperationRequest,\n getGetFasEstimates: () => Promise<SuggestedGasFees>,\n transaction?: TransactionParams,\n) {\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n const { gasPrice } = transaction ?? {};\n\n if (!isGasFeeEmpty(maxFeePerGas)) {\n log('Using maxFeePerGas from request', maxFeePerGas);\n return maxFeePerGas as string;\n }\n\n if (isGasFeeEmpty(maxPriorityFeePerGas) && gasPrice) {\n log('Setting maxFeePerGas to transaction gasPrice', gasPrice);\n return gasPrice;\n }\n\n const { maxFeePerGas: suggestedMaxFeePerGas } = await getGetFasEstimates();\n\n if (!suggestedMaxFeePerGas) {\n throw new Error('Failed to get gas fee estimate for maxFeePerGas');\n }\n\n log('Using maxFeePerGas from estimate', suggestedMaxFeePerGas);\n\n return suggestedMaxFeePerGas;\n}\n\n/**\n * Gets the maxPriorityFeePerGas for a user operation.\n *\n * @param originalRequest - The original request to add the user operation.\n * @param getGetFasEstimates - A callback to get gas fee estimates.\n * @param userOperation - The user operation being updated.\n * @param transaction - The transaction that created the user operation.\n * @returns The maxPriorityFeePerGas for the user operation.\n */\nasync function getMaxPriorityFeePerGas(\n originalRequest: AddUserOperationRequest,\n getGetFasEstimates: () => Promise<SuggestedGasFees>,\n userOperation: UserOperation,\n transaction?: TransactionParams,\n) {\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n const { gasPrice } = transaction ?? {};\n const { maxFeePerGas: updatedMaxFeePerGas } = userOperation;\n\n if (!isGasFeeEmpty(maxPriorityFeePerGas)) {\n log('Using maxPriorityFeePerGas from request', maxPriorityFeePerGas);\n return maxPriorityFeePerGas as string;\n }\n\n if (isGasFeeEmpty(maxFeePerGas) && gasPrice) {\n log('Setting maxPriorityFeePerGas to transaction gasPrice', gasPrice);\n return gasPrice;\n }\n\n const { maxPriorityFeePerGas: suggestedMaxPriorityFeePerGas } =\n await getGetFasEstimates();\n\n if (suggestedMaxPriorityFeePerGas) {\n log(\n 'Using maxPriorityFeePerGas from estimate',\n suggestedMaxPriorityFeePerGas,\n );\n return suggestedMaxPriorityFeePerGas;\n }\n\n log('Setting maxPriorityFeePerGas to maxFeePerGas', updatedMaxFeePerGas);\n\n return updatedMaxFeePerGas;\n}\n\n/**\n * Gets the userFeeLevel for a user operation.\n *\n * @param metadata - The metadata for the user operation.\n * @param originalRequest - The original request to add the user operation.\n * @param suggestedGasFees - The suggested gas fees, if any.\n * @param transaction - The transaction that created the user operation.\n * @returns The userFeeLevel for the user operation.\n */\nfunction getUserFeeLevel(\n metadata: UserOperationMetadata,\n originalRequest: AddUserOperationRequest,\n suggestedGasFees?: SuggestedGasFees,\n transaction?: TransactionParams,\n): UserFeeLevel {\n const { origin } = metadata;\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n\n const {\n maxFeePerGas: suggestedMaxFeePerGas,\n maxPriorityFeePerGas: suggestedMaxPriorityFeePerGas,\n } = suggestedGasFees || {};\n\n if (\n isGasFeeEmpty(maxFeePerGas) &&\n isGasFeeEmpty(maxPriorityFeePerGas) &&\n transaction?.gasPrice\n ) {\n return origin === ORIGIN_METAMASK\n ? UserFeeLevel.CUSTOM\n : UserFeeLevel.DAPP_SUGGESTED;\n }\n\n if (\n isGasFeeEmpty(maxFeePerGas) &&\n isGasFeeEmpty(maxPriorityFeePerGas) &&\n suggestedMaxFeePerGas &&\n suggestedMaxPriorityFeePerGas\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (origin === ORIGIN_METAMASK) {\n return UserFeeLevel.CUSTOM;\n }\n\n return UserFeeLevel.DAPP_SUGGESTED;\n}\n\n/**\n * Gets suggested gas fees.\n *\n * @param request - The request to update the gas fees.\n * @param request.getGasFeeEstimates - A callback to get gas fee estimates.\n * @param request.provider - A provider to query the network.\n * @returns The suggested gas fees.\n */\nasync function getSuggestedGasFees(\n request: UpdateGasFeesRequest,\n): Promise<{ maxFeePerGas?: Hex; maxPriorityFeePerGas?: Hex }> {\n const { getGasFeeEstimates, provider } = request;\n\n try {\n const { gasFeeEstimates, gasEstimateType } = await getGasFeeEstimates();\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n /* istanbul ignore next */\n const {\n medium: { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = {},\n } = gasFeeEstimates;\n\n if (suggestedMaxPriorityFeePerGas && suggestedMaxFeePerGas) {\n const values = {\n maxFeePerGas: gweiDecimalToWeiHex(suggestedMaxFeePerGas),\n maxPriorityFeePerGas: gweiDecimalToWeiHex(\n suggestedMaxPriorityFeePerGas,\n ),\n };\n\n log('Using medium values from fee market estimate', values);\n\n return values;\n }\n }\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {\n const maxFeePerGas = gweiDecimalToWeiHex(gasFeeEstimates.medium);\n\n log('Using medium value from legacy estimate', maxFeePerGas);\n\n return {\n maxFeePerGas,\n };\n }\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.ETH_GASPRICE) {\n const maxFeePerGas = gweiDecimalToWeiHex(gasFeeEstimates.gasPrice);\n\n log('Using gasPrice from estimate', maxFeePerGas);\n\n return {\n maxFeePerGas,\n };\n }\n } catch (error) {\n log('Failed to get estimate', error);\n }\n\n const gasPriceDecimal = (await query(new EthQuery(provider), 'gasPrice')) as\n | number\n | undefined;\n\n if (!gasPriceDecimal) {\n return {};\n }\n\n const maxFeePerGas = add0x(gasPriceDecimal.toString(16)) as Hex;\n\n log('Using gasPrice from network as fallback', maxFeePerGas);\n\n return { maxFeePerGas };\n}\n\n/**\n * Converts a GWEI decimal string to a WEI hexadecimal string.\n *\n * @param value - The GWEI decimal string to convert.\n * @returns The WEI hexadecimal string.\n */\nfunction gweiDecimalToWeiHex(value: string) {\n return toHex(gweiDecToWEIBN(value));\n}\n\n/**\n * Checks if a gas fee property is empty.\n *\n * @param value - The gas fee value to check.\n * @returns Whether the gas fee property is empty.\n */\nfunction isGasFeeEmpty(value?: string): boolean {\n return !value || value === EMPTY_BYTES;\n}\n"]}
@@ -17,6 +17,7 @@ const log = (0, logger_1.createModuleLogger)(logger_1.projectLogger, 'gas');
17
17
  const GAS_ESTIMATE_MULTIPLIER = 1.5;
18
18
  /**
19
19
  * Populates the gas properties for a user operation.
20
+ *
20
21
  * @param metadata - The metadata for the user operation.
21
22
  * @param prepareResponse - The prepare response from the smart contract account.
22
23
  * @param entrypoint - Address of the entrypoint contract.
@@ -59,6 +60,7 @@ async function updateGas(metadata, prepareResponse, entrypoint) {
59
60
  exports.updateGas = updateGas;
60
61
  /**
61
62
  * Normalizes a gas estimate value from the bundler.
63
+ *
62
64
  * @param rawValue - The raw value to normalize.
63
65
  * @returns The normalized value as a hexadecimal string.
64
66
  */
@@ -1 +1 @@
1
- {"version":3,"file":"gas.cjs","sourceRoot":"","s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,QAAQ,CAAC,YAAY,CAAC,CAAC;IACzE,aAAa,CAAC,kBAAkB,GAAG,oBAAoB,CACrD,QAAQ,CAAC,kBAAkB,CAC5B,CAAC;IACF,aAAa,CAAC,oBAAoB,GAAG,oBAAoB,CACvD,CAAC,QAAQ,CAAC,oBAAoB,IAAI,QAAQ,CAAC,eAAe,CAEhD,CACX,CAAC;IAEF,GAAG,CAAC,iDAAiD,EAAE;QACrD,YAAY,EAAE,aAAa,CAAC,YAAY;QACxC,kBAAkB,EAAE,aAAa,CAAC,kBAAkB;QACpD,oBAAoB,EAAE,aAAa,CAAC,oBAAoB;QACxD,UAAU,EAAE,uBAAuB;QACnC,QAAQ;KACT,CAAC,CAAC;AACL,CAAC;AAnDD,8BAmDC;AAED;;;;GAIG;AACH,SAAS,oBAAoB,CAAC,QAAyB;IACrD,MAAM,KAAK,GACT,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA,0BAAO,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,eAAE,CAAC,QAAQ,CAAC,CAAC;IAEtE,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAE1D,OAAO,IAAA,aAAK,EAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { hexToBN } from '@metamask/controller-utils';\nimport { add0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { VALUE_ZERO } from '../constants';\nimport { Bundler } from '../helpers/Bundler';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type {\n PrepareUserOperationResponse,\n UserOperationMetadata,\n} from '../types';\n\nconst log = createModuleLogger(projectLogger, 'gas');\n\n/**\n * A multiplier to apply to all gas estimate values returned from the bundler.\n */\nconst GAS_ESTIMATE_MULTIPLIER = 1.5;\n\n/**\n * Populates the gas properties for a user operation.\n * @param metadata - The metadata for the user operation.\n * @param prepareResponse - The prepare response from the smart contract account.\n * @param entrypoint - Address of the entrypoint contract.\n */\nexport async function updateGas(\n metadata: UserOperationMetadata,\n prepareResponse: PrepareUserOperationResponse,\n entrypoint: string,\n) {\n const { userOperation } = metadata;\n\n if (prepareResponse.gas) {\n userOperation.callGasLimit = prepareResponse.gas.callGasLimit;\n userOperation.preVerificationGas = prepareResponse.gas.preVerificationGas;\n userOperation.verificationGasLimit =\n prepareResponse.gas.verificationGasLimit;\n\n log('Using gas values from smart contract account', {\n callGasLimit: userOperation.callGasLimit,\n preVerificationGas: userOperation.preVerificationGas,\n verificationGasLimit: userOperation.verificationGasLimit,\n });\n\n return;\n }\n\n const payload = {\n ...userOperation,\n maxFeePerGas: VALUE_ZERO,\n maxPriorityFeePerGas: VALUE_ZERO,\n callGasLimit: VALUE_ZERO,\n preVerificationGas: VALUE_ZERO,\n verificationGasLimit: '0xF4240',\n };\n\n const bundler = new Bundler(metadata.bundlerUrl as string);\n const estimate = await bundler.estimateUserOperationGas(payload, entrypoint);\n\n userOperation.callGasLimit = normalizeGasEstimate(estimate.callGasLimit);\n userOperation.preVerificationGas = normalizeGasEstimate(\n estimate.preVerificationGas,\n );\n userOperation.verificationGasLimit = normalizeGasEstimate(\n (estimate.verificationGasLimit ?? estimate.verificationGas) as\n | string\n | number,\n );\n\n log('Using buffered gas values from bundler estimate', {\n callGasLimit: userOperation.callGasLimit,\n preVerificationGas: userOperation.preVerificationGas,\n verificationGasLimit: userOperation.verificationGasLimit,\n multiplier: GAS_ESTIMATE_MULTIPLIER,\n estimate,\n });\n}\n\n/**\n * Normalizes a gas estimate value from the bundler.\n * @param rawValue - The raw value to normalize.\n * @returns The normalized value as a hexadecimal string.\n */\nfunction normalizeGasEstimate(rawValue: string | number): string {\n const value =\n typeof rawValue === 'string' ? hexToBN(rawValue) : new BN(rawValue);\n\n const bufferedValue = value.muln(GAS_ESTIMATE_MULTIPLIER);\n\n return add0x(bufferedValue.toString(16));\n}\n"]}
1
+ {"version":3,"file":"gas.cjs","sourceRoot":"","s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C,QAAQ,CAAC,YAAY,CAAC,CAAC;IACzE,aAAa,CAAC,kBAAkB,GAAG,oBAAoB,CACrD,QAAQ,CAAC,kBAAkB,CAC5B,CAAC;IACF,aAAa,CAAC,oBAAoB,GAAG,oBAAoB,CACvD,CAAC,QAAQ,CAAC,oBAAoB,IAAI,QAAQ,CAAC,eAAe,CAEhD,CACX,CAAC;IAEF,GAAG,CAAC,iDAAiD,EAAE;QACrD,YAAY,EAAE,aAAa,CAAC,YAAY;QACxC,kBAAkB,EAAE,aAAa,CAAC,kBAAkB;QACpD,oBAAoB,EAAE,aAAa,CAAC,oBAAoB;QACxD,UAAU,EAAE,uBAAuB;QACnC,QAAQ;KACT,CAAC,CAAC;AACL,CAAC;AAnDD,8BAmDC;AAED;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,QAAyB;IACrD,MAAM,KAAK,GACT,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA,0BAAO,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,eAAE,CAAC,QAAQ,CAAC,CAAC;IAEtE,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAE1D,OAAO,IAAA,aAAK,EAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { hexToBN } from '@metamask/controller-utils';\nimport { add0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { VALUE_ZERO } from '../constants';\nimport { Bundler } from '../helpers/Bundler';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type {\n PrepareUserOperationResponse,\n UserOperationMetadata,\n} from '../types';\n\nconst log = createModuleLogger(projectLogger, 'gas');\n\n/**\n * A multiplier to apply to all gas estimate values returned from the bundler.\n */\nconst GAS_ESTIMATE_MULTIPLIER = 1.5;\n\n/**\n * Populates the gas properties for a user operation.\n *\n * @param metadata - The metadata for the user operation.\n * @param prepareResponse - The prepare response from the smart contract account.\n * @param entrypoint - Address of the entrypoint contract.\n */\nexport async function updateGas(\n metadata: UserOperationMetadata,\n prepareResponse: PrepareUserOperationResponse,\n entrypoint: string,\n) {\n const { userOperation } = metadata;\n\n if (prepareResponse.gas) {\n userOperation.callGasLimit = prepareResponse.gas.callGasLimit;\n userOperation.preVerificationGas = prepareResponse.gas.preVerificationGas;\n userOperation.verificationGasLimit =\n prepareResponse.gas.verificationGasLimit;\n\n log('Using gas values from smart contract account', {\n callGasLimit: userOperation.callGasLimit,\n preVerificationGas: userOperation.preVerificationGas,\n verificationGasLimit: userOperation.verificationGasLimit,\n });\n\n return;\n }\n\n const payload = {\n ...userOperation,\n maxFeePerGas: VALUE_ZERO,\n maxPriorityFeePerGas: VALUE_ZERO,\n callGasLimit: VALUE_ZERO,\n preVerificationGas: VALUE_ZERO,\n verificationGasLimit: '0xF4240',\n };\n\n const bundler = new Bundler(metadata.bundlerUrl as string);\n const estimate = await bundler.estimateUserOperationGas(payload, entrypoint);\n\n userOperation.callGasLimit = normalizeGasEstimate(estimate.callGasLimit);\n userOperation.preVerificationGas = normalizeGasEstimate(\n estimate.preVerificationGas,\n );\n userOperation.verificationGasLimit = normalizeGasEstimate(\n (estimate.verificationGasLimit ?? estimate.verificationGas) as\n | string\n | number,\n );\n\n log('Using buffered gas values from bundler estimate', {\n callGasLimit: userOperation.callGasLimit,\n preVerificationGas: userOperation.preVerificationGas,\n verificationGasLimit: userOperation.verificationGasLimit,\n multiplier: GAS_ESTIMATE_MULTIPLIER,\n estimate,\n });\n}\n\n/**\n * Normalizes a gas estimate value from the bundler.\n *\n * @param rawValue - The raw value to normalize.\n * @returns The normalized value as a hexadecimal string.\n */\nfunction normalizeGasEstimate(rawValue: string | number): string {\n const value =\n typeof rawValue === 'string' ? hexToBN(rawValue) : new BN(rawValue);\n\n const bufferedValue = value.muln(GAS_ESTIMATE_MULTIPLIER);\n\n return add0x(bufferedValue.toString(16));\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import type { PrepareUserOperationResponse, UserOperationMetadata } from "../types.cjs";
2
2
  /**
3
3
  * Populates the gas properties for a user operation.
4
+ *
4
5
  * @param metadata - The metadata for the user operation.
5
6
  * @param prepareResponse - The prepare response from the smart contract account.
6
7
  * @param entrypoint - Address of the entrypoint contract.
@@ -1 +1 @@
1
- {"version":3,"file":"gas.d.cts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,4BAA4B,EAC5B,qBAAqB,EACtB,qBAAiB;AASlB;;;;;GAKG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,qBAAqB,EAC/B,eAAe,EAAE,4BAA4B,EAC7C,UAAU,EAAE,MAAM,iBAgDnB"}
1
+ {"version":3,"file":"gas.d.cts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,4BAA4B,EAC5B,qBAAqB,EACtB,qBAAiB;AASlB;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,qBAAqB,EAC/B,eAAe,EAAE,4BAA4B,EAC7C,UAAU,EAAE,MAAM,iBAgDnB"}
@@ -1,6 +1,7 @@
1
1
  import type { PrepareUserOperationResponse, UserOperationMetadata } from "../types.mjs";
2
2
  /**
3
3
  * Populates the gas properties for a user operation.
4
+ *
4
5
  * @param metadata - The metadata for the user operation.
5
6
  * @param prepareResponse - The prepare response from the smart contract account.
6
7
  * @param entrypoint - Address of the entrypoint contract.
@@ -1 +1 @@
1
- {"version":3,"file":"gas.d.mts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,4BAA4B,EAC5B,qBAAqB,EACtB,qBAAiB;AASlB;;;;;GAKG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,qBAAqB,EAC/B,eAAe,EAAE,4BAA4B,EAC7C,UAAU,EAAE,MAAM,iBAgDnB"}
1
+ {"version":3,"file":"gas.d.mts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,4BAA4B,EAC5B,qBAAqB,EACtB,qBAAiB;AASlB;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,qBAAqB,EAC/B,eAAe,EAAE,4BAA4B,EAC7C,UAAU,EAAE,MAAM,iBAgDnB"}
@@ -18,6 +18,7 @@ const log = createModuleLogger(projectLogger, 'gas');
18
18
  const GAS_ESTIMATE_MULTIPLIER = 1.5;
19
19
  /**
20
20
  * Populates the gas properties for a user operation.
21
+ *
21
22
  * @param metadata - The metadata for the user operation.
22
23
  * @param prepareResponse - The prepare response from the smart contract account.
23
24
  * @param entrypoint - Address of the entrypoint contract.
@@ -59,6 +60,7 @@ export async function updateGas(metadata, prepareResponse, entrypoint) {
59
60
  }
60
61
  /**
61
62
  * Normalizes a gas estimate value from the bundler.
63
+ *
62
64
  * @param rawValue - The raw value to normalize.
63
65
  * @returns The normalized value as a hexadecimal string.
64
66
  */
@@ -1 +1 @@
1
- {"version":3,"file":"gas.mjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,mCAAmC;AACrD,OAAO,EAAE,KAAK,EAAE,wBAAwB;AACxC,OAAO,GAAE,cAAc;;AAEvB,OAAO,EAAE,UAAU,EAAE,yBAAqB;AAC1C,OAAO,EAAE,OAAO,EAAE,+BAA2B;AAC7C,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,sBAAkB;AAM9D,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,QAA+B,EAC/B,eAA6C,EAC7C,UAAkB;IAElB,MAAM,EAAE,aAAa,EAAE,GAAG,QAAQ,CAAC;IAEnC,I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B;QACnC,QAAQ;KACT,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,SAAS,oBAAoB,CAAC,QAAyB;IACrD,MAAM,KAAK,GACT,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC;IAEtE,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAE1D,OAAO,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { hexToBN } from '@metamask/controller-utils';\nimport { add0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { VALUE_ZERO } from '../constants';\nimport { Bundler } from '../helpers/Bundler';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type {\n PrepareUserOperationResponse,\n UserOperationMetadata,\n} from '../types';\n\nconst log = createModuleLogger(projectLogger, 'gas');\n\n/**\n * A multiplier to apply to all gas estimate values returned from the bundler.\n */\nconst GAS_ESTIMATE_MULTIPLIER = 1.5;\n\n/**\n * Populates the gas properties for a user operation.\n * @param metadata - The metadata for the user operation.\n * @param prepareResponse - The prepare response from the smart contract account.\n * @param entrypoint - Address of the entrypoint contract.\n */\nexport async function updateGas(\n metadata: UserOperationMetadata,\n prepareResponse: PrepareUserOperationResponse,\n entrypoint: string,\n) {\n const { userOperation } = metadata;\n\n if (prepareResponse.gas) {\n userOperation.callGasLimit = prepareResponse.gas.callGasLimit;\n userOperation.preVerificationGas = prepareResponse.gas.preVerificationGas;\n userOperation.verificationGasLimit =\n prepareResponse.gas.verificationGasLimit;\n\n log('Using gas values from smart contract account', {\n callGasLimit: userOperation.callGasLimit,\n preVerificationGas: userOperation.preVerificationGas,\n verificationGasLimit: userOperation.verificationGasLimit,\n });\n\n return;\n }\n\n const payload = {\n ...userOperation,\n maxFeePerGas: VALUE_ZERO,\n maxPriorityFeePerGas: VALUE_ZERO,\n callGasLimit: VALUE_ZERO,\n preVerificationGas: VALUE_ZERO,\n verificationGasLimit: '0xF4240',\n };\n\n const bundler = new Bundler(metadata.bundlerUrl as string);\n const estimate = await bundler.estimateUserOperationGas(payload, entrypoint);\n\n userOperation.callGasLimit = normalizeGasEstimate(estimate.callGasLimit);\n userOperation.preVerificationGas = normalizeGasEstimate(\n estimate.preVerificationGas,\n );\n userOperation.verificationGasLimit = normalizeGasEstimate(\n (estimate.verificationGasLimit ?? estimate.verificationGas) as\n | string\n | number,\n );\n\n log('Using buffered gas values from bundler estimate', {\n callGasLimit: userOperation.callGasLimit,\n preVerificationGas: userOperation.preVerificationGas,\n verificationGasLimit: userOperation.verificationGasLimit,\n multiplier: GAS_ESTIMATE_MULTIPLIER,\n estimate,\n });\n}\n\n/**\n * Normalizes a gas estimate value from the bundler.\n * @param rawValue - The raw value to normalize.\n * @returns The normalized value as a hexadecimal string.\n */\nfunction normalizeGasEstimate(rawValue: string | number): string {\n const value =\n typeof rawValue === 'string' ? hexToBN(rawValue) : new BN(rawValue);\n\n const bufferedValue = value.muln(GAS_ESTIMATE_MULTIPLIER);\n\n return add0x(bufferedValue.toString(16));\n}\n"]}
1
+ {"version":3,"file":"gas.mjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,mCAAmC;AACrD,OAAO,EAAE,KAAK,EAAE,wBAAwB;AACxC,OAAO,GAAE,cAAc;;AAEvB,OAAO,EAAE,UAAU,EAAE,yBAAqB;AAC1C,OAAO,EAAE,OAAO,EAAE,+BAA2B;AAC7C,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,sBAAkB;AAM9D,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,CAAC,KA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AAC,YAAY;QACxC,kBAAkB,EAAE,aAAa,CAAC,kBAAkB;QACpD,oBAAoB,EAAE,aAAa,CAAC,oBAAoB;QACxD,UAAU,EAAE,uBAAuB;QACnC,QAAQ;KACT,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,QAAyB;IACrD,MAAM,KAAK,GACT,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC;IAEtE,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAE1D,OAAO,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { hexToBN } from '@metamask/controller-utils';\nimport { add0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { VALUE_ZERO } from '../constants';\nimport { Bundler } from '../helpers/Bundler';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type {\n PrepareUserOperationResponse,\n UserOperationMetadata,\n} from '../types';\n\nconst log = createModuleLogger(projectLogger, 'gas');\n\n/**\n * A multiplier to apply to all gas estimate values returned from the bundler.\n */\nconst GAS_ESTIMATE_MULTIPLIER = 1.5;\n\n/**\n * Populates the gas properties for a user operation.\n *\n * @param metadata - The metadata for the user operation.\n * @param prepareResponse - The prepare response from the smart contract account.\n * @param entrypoint - Address of the entrypoint contract.\n */\nexport async function updateGas(\n metadata: UserOperationMetadata,\n prepareResponse: PrepareUserOperationResponse,\n entrypoint: string,\n) {\n const { userOperation } = metadata;\n\n if (prepareResponse.gas) {\n userOperation.callGasLimit = prepareResponse.gas.callGasLimit;\n userOperation.preVerificationGas = prepareResponse.gas.preVerificationGas;\n userOperation.verificationGasLimit =\n prepareResponse.gas.verificationGasLimit;\n\n log('Using gas values from smart contract account', {\n callGasLimit: userOperation.callGasLimit,\n preVerificationGas: userOperation.preVerificationGas,\n verificationGasLimit: userOperation.verificationGasLimit,\n });\n\n return;\n }\n\n const payload = {\n ...userOperation,\n maxFeePerGas: VALUE_ZERO,\n maxPriorityFeePerGas: VALUE_ZERO,\n callGasLimit: VALUE_ZERO,\n preVerificationGas: VALUE_ZERO,\n verificationGasLimit: '0xF4240',\n };\n\n const bundler = new Bundler(metadata.bundlerUrl as string);\n const estimate = await bundler.estimateUserOperationGas(payload, entrypoint);\n\n userOperation.callGasLimit = normalizeGasEstimate(estimate.callGasLimit);\n userOperation.preVerificationGas = normalizeGasEstimate(\n estimate.preVerificationGas,\n );\n userOperation.verificationGasLimit = normalizeGasEstimate(\n (estimate.verificationGasLimit ?? estimate.verificationGas) as\n | string\n | number,\n );\n\n log('Using buffered gas values from bundler estimate', {\n callGasLimit: userOperation.callGasLimit,\n preVerificationGas: userOperation.preVerificationGas,\n verificationGasLimit: userOperation.verificationGasLimit,\n multiplier: GAS_ESTIMATE_MULTIPLIER,\n estimate,\n });\n}\n\n/**\n * Normalizes a gas estimate value from the bundler.\n *\n * @param rawValue - The raw value to normalize.\n * @returns The normalized value as a hexadecimal string.\n */\nfunction normalizeGasEstimate(rawValue: string | number): string {\n const value =\n typeof rawValue === 'string' ? hexToBN(rawValue) : new BN(rawValue);\n\n const bufferedValue = value.muln(GAS_ESTIMATE_MULTIPLIER);\n\n return add0x(bufferedValue.toString(16));\n}\n"]}
@@ -11,6 +11,7 @@ const constants_1 = require("../constants.cjs");
11
11
  const types_1 = require("../types.cjs");
12
12
  /**
13
13
  * Converts a user operation metadata object into a transaction metadata object.
14
+ *
14
15
  * @param metadata - The user operation metadata object to convert.
15
16
  * @returns The equivalent transaction metadata object.
16
17
  */
@@ -99,6 +100,7 @@ function getTransactionMetadata(metadata) {
99
100
  exports.getTransactionMetadata = getTransactionMetadata;
100
101
  /**
101
102
  * Adds the given hexadecimal values together.
103
+ *
102
104
  * @param values - The hexadecimal values to add together.
103
105
  * @returns The sum of the given hexadecimal values.
104
106
  */
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.cjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;;;;AAKA,6EAG0C;AAE1C,2CAAkD;AAClD,kDAAuB;AAEvB,gDAAuD;AACvD,wCAA+C;AAG/C;;;;GAIG;AACH,SAAgB,sBAAsB,CACpC,QAA+B;IAE/B,MAAM,EACJ,aAAa,EACb,aAAa,EACb,aAAa,EACb,OAAO,EACP,KAAK,EAAE,QAAQ,EACf,MAAM,EACN,eAAe,EACf,EAAE,EACF,aAAa,EACb,IAAI,EACJ,iBAAiB,EACjB,eAAe,EACf,YAAY,EAAE,eAAe,EAC7B,aAAa,GACd,GAAG,QAAQ,CAAC;IAEb,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,oDAAoD;IACpD,MAAM,iBAAiB,GACrB,aAAa,IAAI,aAAa;QAC5B,CAAC,CAAC,IAAA,aAAK,EACH,IAAI,eAAE,CAAC,IAAA,gBAAQ,EAAC,aAAa,CAAC,EAAE,EAAE,CAAC;aAChC,GAAG,CAAC,IAAI,eAAE,CAAC,IAAA,gBAAQ,EAAC,aAAa,CAAC,EAAE,EAAE,CAAC,CAAC;aACxC,QAAQ,CAAC,EAAE,CAAC,CAChB;QACH,CAAC,CAAC,SAAS,CAAC;IAEhB,MAAM,KAAK,GAAG,CACZ,QAAQ;QACN,CAAC,CAAC;YACE,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,OAAO,EAAE,QAAQ,CAAC,OAAO;YACzB,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,GAAG,EAAE,QAAQ,CAAC,GAAG;SAClB;QACH,CAAC,CAAC,SAAS,CACM,CAAC;IAEtB,MAAM,MAAM,GAAsB;QAChC,CAAC,2BAAmB,CAAC,UAAU,CAAC,EAAE,0CAAiB,CAAC,UAAU;QAC9D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AK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,SAAS;QACX,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,IAAI,eAAE,CAAC,IAAA,gBAAQ,EAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,IAAA,aAAK,EAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AACnC,CAAC","sourcesContent":["import type {\n TransactionError,\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport {\n TransactionStatus,\n UserFeeLevel,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, remove0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { EMPTY_BYTES, VALUE_ZERO } from '../constants';\nimport { UserOperationStatus } from '../types';\nimport type { UserOperationMetadata } from '../types';\n\n/**\n * Converts a user operation metadata object into a transaction metadata object.\n * @param metadata - The user operation metadata object to convert.\n * @returns The equivalent transaction metadata object.\n */\nexport function getTransactionMetadata(\n metadata: UserOperationMetadata,\n): TransactionMeta | undefined {\n const {\n actualGasCost,\n actualGasUsed,\n baseFeePerGas,\n chainId,\n error: rawError,\n origin,\n transactionHash,\n id,\n swapsMetadata,\n time,\n transactionParams,\n transactionType,\n userFeeLevel: rawUserFeeLevel,\n userOperation,\n } = metadata;\n\n if (!transactionParams) {\n return undefined;\n }\n\n // effectiveGasPrice = actualGasCost / actualGasUsed\n const effectiveGasPrice =\n actualGasCost && actualGasUsed\n ? add0x(\n new BN(remove0x(actualGasCost), 16)\n .div(new BN(remove0x(actualGasUsed), 16))\n .toString(16),\n )\n : undefined;\n\n const error = (\n rawError\n ? {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.rpc,\n }\n : undefined\n ) as TransactionError;\n\n const status: TransactionStatus = {\n [UserOperationStatus.Unapproved]: TransactionStatus.unapproved,\n [UserOperationStatus.Approved]: TransactionStatus.approved,\n [UserOperationStatus.Signed]: TransactionStatus.signed,\n [UserOperationStatus.Submitted]: TransactionStatus.submitted,\n [UserOperationStatus.Confirmed]: TransactionStatus.confirmed,\n [UserOperationStatus.Failed]: TransactionStatus.failed,\n }[metadata.status];\n\n const gas = addHex(\n userOperation.preVerificationGas,\n userOperation.verificationGasLimit,\n userOperation.callGasLimit,\n );\n\n const hasPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const maxFeePerGas = hasPaymaster ? VALUE_ZERO : userOperation.maxFeePerGas;\n\n const maxPriorityFeePerGas = hasPaymaster\n ? VALUE_ZERO\n : userOperation.maxPriorityFeePerGas;\n\n const nonce =\n userOperation.nonce === EMPTY_BYTES ? undefined : userOperation.nonce;\n\n const txParams = {\n ...transactionParams,\n from: userOperation.sender,\n gas,\n nonce,\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as TransactionParams;\n\n // User operations only support EIP-1559 gas fee properties.\n delete txParams.gasPrice;\n\n const swaps = {\n approvalTxId: swapsMetadata?.approvalTxId ?? undefined,\n destinationTokenAddress:\n swapsMetadata?.destinationTokenAddress ?? undefined,\n destinationTokenAmount: swapsMetadata?.destinationTokenAmount ?? undefined,\n destinationTokenDecimals:\n swapsMetadata?.destinationTokenDecimals ?? undefined,\n destinationTokenSymbol: swapsMetadata?.destinationTokenSymbol ?? undefined,\n estimatedBaseFee: swapsMetadata?.estimatedBaseFee ?? undefined,\n sourceTokenAddress: swapsMetadata?.sourceTokenAddress ?? undefined,\n sourceTokenAmount: swapsMetadata?.sourceTokenAmount ?? undefined,\n sourceTokenDecimals: swapsMetadata?.sourceTokenDecimals ?? undefined,\n sourceTokenSymbol: swapsMetadata?.sourceTokenSymbol ?? undefined,\n swapAndSendRecipient: swapsMetadata?.swapAndSendRecipient ?? undefined,\n swapMetaData: swapsMetadata?.swapMetaData ?? undefined,\n swapTokenValue: swapsMetadata?.swapTokenValue ?? undefined,\n };\n\n const userFeeLevel = hasPaymaster ? UserFeeLevel.CUSTOM : rawUserFeeLevel;\n\n return {\n baseFeePerGas: (baseFeePerGas as Hex) ?? undefined,\n chainId: chainId as Hex,\n error,\n hash: transactionHash ?? undefined,\n id,\n isUserOperation: true,\n networkClientId: 'user-operation',\n origin,\n status,\n time,\n txParams,\n txReceipt: {\n effectiveGasPrice: effectiveGasPrice ?? undefined,\n gasUsed: actualGasUsed ?? undefined,\n },\n type: transactionType ?? undefined,\n userFeeLevel: userFeeLevel as string,\n ...swaps,\n };\n}\n\n/**\n * Adds the given hexadecimal values together.\n * @param values - The hexadecimal values to add together.\n * @returns The sum of the given hexadecimal values.\n */\nfunction addHex(...values: (string | undefined)[]) {\n const total = new BN(0);\n\n for (const value of values) {\n if (!value) {\n continue;\n }\n\n total.iadd(new BN(remove0x(value), 16));\n }\n\n return add0x(total.toString(16));\n}\n"]}
1
+ {"version":3,"file":"transaction.cjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;;;;AAKA,6EAG0C;AAE1C,2CAAkD;AAClD,kDAAuB;AAEvB,gDAAuD;AACvD,wCAA+C;AAG/C;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,QAA+B;IAE/B,MAAM,EACJ,aAAa,EACb,aAAa,EACb,aAAa,EACb,OAAO,EACP,KAAK,EAAE,QAAQ,EACf,MAAM,EACN,eAAe,EACf,EAAE,EACF,aAAa,EACb,IAAI,EACJ,iBAAiB,EACjB,eAAe,EACf,YAAY,EAAE,eAAe,EAC7B,aAAa,GACd,GAAG,QAAQ,CAAC;IAEb,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,oDAAoD;IACpD,MAAM,iBAAiB,GACrB,aAAa,IAAI,aAAa;QAC5B,CAAC,CAAC,IAAA,aAAK,EACH,IAAI,eAAE,CAAC,IAAA,gBAAQ,EAAC,aAAa,CAAC,EAAE,EAAE,CAAC;aAChC,GAAG,CAAC,IAAI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AAE,OAAc;QACvB,KAAK;QACL,IAAI,EAAE,eAAe,IAAI,SAAS;QAClC,EAAE;QACF,eAAe,EAAE,IAAI;QACrB,eAAe,EAAE,gBAAgB;QACjC,MAAM;QACN,MAAM;QACN,IAAI;QACJ,QAAQ;QACR,SAAS,EAAE;YACT,iBAAiB,EAAE,iBAAiB,IAAI,SAAS;YACjD,OAAO,EAAE,aAAa,IAAI,SAAS;SACpC;QACD,IAAI,EAAE,eAAe,IAAI,SAAS;QAClC,YAAY,EAAE,YAAsB;QACpC,GAAG,KAAK;KACT,CAAC;AACJ,CAAC;AA5HD,wDA4HC;AAED;;;;;GAKG;AACH,SAAS,MAAM,CAAC,GAAG,MAA8B;IAC/C,MAAM,KAAK,GAAG,IAAI,eAAE,CAAC,CAAC,CAAC,CAAC;IAExB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,SAAS;QACX,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,IAAI,eAAE,CAAC,IAAA,gBAAQ,EAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,IAAA,aAAK,EAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AACnC,CAAC","sourcesContent":["import type {\n TransactionError,\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport {\n TransactionStatus,\n UserFeeLevel,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, remove0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { EMPTY_BYTES, VALUE_ZERO } from '../constants';\nimport { UserOperationStatus } from '../types';\nimport type { UserOperationMetadata } from '../types';\n\n/**\n * Converts a user operation metadata object into a transaction metadata object.\n *\n * @param metadata - The user operation metadata object to convert.\n * @returns The equivalent transaction metadata object.\n */\nexport function getTransactionMetadata(\n metadata: UserOperationMetadata,\n): TransactionMeta | undefined {\n const {\n actualGasCost,\n actualGasUsed,\n baseFeePerGas,\n chainId,\n error: rawError,\n origin,\n transactionHash,\n id,\n swapsMetadata,\n time,\n transactionParams,\n transactionType,\n userFeeLevel: rawUserFeeLevel,\n userOperation,\n } = metadata;\n\n if (!transactionParams) {\n return undefined;\n }\n\n // effectiveGasPrice = actualGasCost / actualGasUsed\n const effectiveGasPrice =\n actualGasCost && actualGasUsed\n ? add0x(\n new BN(remove0x(actualGasCost), 16)\n .div(new BN(remove0x(actualGasUsed), 16))\n .toString(16),\n )\n : undefined;\n\n const error = (\n rawError\n ? {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.rpc,\n }\n : undefined\n ) as TransactionError;\n\n const status: TransactionStatus = {\n [UserOperationStatus.Unapproved]: TransactionStatus.unapproved,\n [UserOperationStatus.Approved]: TransactionStatus.approved,\n [UserOperationStatus.Signed]: TransactionStatus.signed,\n [UserOperationStatus.Submitted]: TransactionStatus.submitted,\n [UserOperationStatus.Confirmed]: TransactionStatus.confirmed,\n [UserOperationStatus.Failed]: TransactionStatus.failed,\n }[metadata.status];\n\n const gas = addHex(\n userOperation.preVerificationGas,\n userOperation.verificationGasLimit,\n userOperation.callGasLimit,\n );\n\n const hasPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const maxFeePerGas = hasPaymaster ? VALUE_ZERO : userOperation.maxFeePerGas;\n\n const maxPriorityFeePerGas = hasPaymaster\n ? VALUE_ZERO\n : userOperation.maxPriorityFeePerGas;\n\n const nonce =\n userOperation.nonce === EMPTY_BYTES ? undefined : userOperation.nonce;\n\n const txParams = {\n ...transactionParams,\n from: userOperation.sender,\n gas,\n nonce,\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as TransactionParams;\n\n // User operations only support EIP-1559 gas fee properties.\n delete txParams.gasPrice;\n\n const swaps = {\n approvalTxId: swapsMetadata?.approvalTxId ?? undefined,\n destinationTokenAddress:\n swapsMetadata?.destinationTokenAddress ?? undefined,\n destinationTokenAmount: swapsMetadata?.destinationTokenAmount ?? undefined,\n destinationTokenDecimals:\n swapsMetadata?.destinationTokenDecimals ?? undefined,\n destinationTokenSymbol: swapsMetadata?.destinationTokenSymbol ?? undefined,\n estimatedBaseFee: swapsMetadata?.estimatedBaseFee ?? undefined,\n sourceTokenAddress: swapsMetadata?.sourceTokenAddress ?? undefined,\n sourceTokenAmount: swapsMetadata?.sourceTokenAmount ?? undefined,\n sourceTokenDecimals: swapsMetadata?.sourceTokenDecimals ?? undefined,\n sourceTokenSymbol: swapsMetadata?.sourceTokenSymbol ?? undefined,\n swapAndSendRecipient: swapsMetadata?.swapAndSendRecipient ?? undefined,\n swapMetaData: swapsMetadata?.swapMetaData ?? undefined,\n swapTokenValue: swapsMetadata?.swapTokenValue ?? undefined,\n };\n\n const userFeeLevel = hasPaymaster ? UserFeeLevel.CUSTOM : rawUserFeeLevel;\n\n return {\n baseFeePerGas: (baseFeePerGas as Hex) ?? undefined,\n chainId: chainId as Hex,\n error,\n hash: transactionHash ?? undefined,\n id,\n isUserOperation: true,\n networkClientId: 'user-operation',\n origin,\n status,\n time,\n txParams,\n txReceipt: {\n effectiveGasPrice: effectiveGasPrice ?? undefined,\n gasUsed: actualGasUsed ?? undefined,\n },\n type: transactionType ?? undefined,\n userFeeLevel: userFeeLevel as string,\n ...swaps,\n };\n}\n\n/**\n * Adds the given hexadecimal values together.\n *\n * @param values - The hexadecimal values to add together.\n * @returns The sum of the given hexadecimal values.\n */\nfunction addHex(...values: (string | undefined)[]) {\n const total = new BN(0);\n\n for (const value of values) {\n if (!value) {\n continue;\n }\n\n total.iadd(new BN(remove0x(value), 16));\n }\n\n return add0x(total.toString(16));\n}\n"]}
@@ -2,6 +2,7 @@ import type { TransactionMeta } from "@metamask/transaction-controller";
2
2
  import type { UserOperationMetadata } from "../types.cjs";
3
3
  /**
4
4
  * Converts a user operation metadata object into a transaction metadata object.
5
+ *
5
6
  * @param metadata - The user operation metadata object to convert.
6
7
  * @returns The equivalent transaction metadata object.
7
8
  */
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.d.cts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,yCAAyC;AAW1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAiB;AAEtD;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,qBAAqB,GAC9B,eAAe,GAAG,SAAS,CA0H7B"}
1
+ {"version":3,"file":"transaction.d.cts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,yCAAyC;AAW1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAiB;AAEtD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,qBAAqB,GAC9B,eAAe,GAAG,SAAS,CA0H7B"}
@@ -2,6 +2,7 @@ import type { TransactionMeta } from "@metamask/transaction-controller";
2
2
  import type { UserOperationMetadata } from "../types.mjs";
3
3
  /**
4
4
  * Converts a user operation metadata object into a transaction metadata object.
5
+ *
5
6
  * @param metadata - The user operation metadata object to convert.
6
7
  * @returns The equivalent transaction metadata object.
7
8
  */
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.d.mts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,yCAAyC;AAW1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAiB;AAEtD;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,qBAAqB,GAC9B,eAAe,GAAG,SAAS,CA0H7B"}
1
+ {"version":3,"file":"transaction.d.mts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,yCAAyC;AAW1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAiB;AAEtD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,qBAAqB,GAC9B,eAAe,GAAG,SAAS,CA0H7B"}
@@ -12,6 +12,7 @@ import { EMPTY_BYTES, VALUE_ZERO } from "../constants.mjs";
12
12
  import { UserOperationStatus } from "../types.mjs";
13
13
  /**
14
14
  * Converts a user operation metadata object into a transaction metadata object.
15
+ *
15
16
  * @param metadata - The user operation metadata object to convert.
16
17
  * @returns The equivalent transaction metadata object.
17
18
  */
@@ -99,6 +100,7 @@ export function getTransactionMetadata(metadata) {
99
100
  }
100
101
  /**
101
102
  * Adds the given hexadecimal values together.
103
+ *
102
104
  * @param values - The hexadecimal values to add together.
103
105
  * @returns The sum of the given hexadecimal values.
104
106
  */
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.mjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;;;;AAKA,OAAO,EACL,iBAAiB,EACjB,YAAY,EACb,yCAAyC;AAE1C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,wBAAwB;AAClD,OAAO,GAAE,cAAc;;AAEvB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,yBAAqB;AACvD,OAAO,EAAE,mBAAmB,EAAE,qBAAiB;AAG/C;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CACpC,QAA+B;IAE/B,MAAM,EACJ,aAAa,EACb,aAAa,EACb,aAAa,EACb,OAAO,EACP,KAAK,EAAE,QAAQ,EACf,MAAM,EACN,eAAe,EACf,EAAE,EACF,aAAa,EACb,IAAI,EACJ,iBAAiB,EACjB,eAAe,EACf,YAAY,EAAE,eAAe,EAC7B,aAAa,GACd,GAAG,QAAQ,CAAC;IAEb,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,oDAAoD;IACpD,MAAM,iBAAiB,GACrB,aAAa,IAAI,aAAa;QAC5B,CAAC,CAAC,KAAK,CAC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AAe,CAAC;IAE1E,OAAO;QACL,aAAa,EAAG,aAAqB,IAAI,SAAS;QAClD,OAAO,EAAE,OAAc;QACvB,KAAK;QACL,IAAI,EAAE,eAAe,IAAI,SAAS;QAClC,EAAE;QACF,eAAe,EAAE,IAAI;QACrB,eAAe,EAAE,gBAAgB;QACjC,MAAM;QACN,MAAM;QACN,IAAI;QACJ,QAAQ;QACR,SAAS,EAAE;YACT,iBAAiB,EAAE,iBAAiB,IAAI,SAAS;YACjD,OAAO,EAAE,aAAa,IAAI,SAAS;SACpC;QACD,IAAI,EAAE,eAAe,IAAI,SAAS;QAClC,YAAY,EAAE,YAAsB;QACpC,GAAG,KAAK;KACT,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,MAAM,CAAC,GAAG,MAA8B;IAC/C,MAAM,KAAK,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAExB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,SAAS;QACX,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AACnC,CAAC","sourcesContent":["import type {\n TransactionError,\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport {\n TransactionStatus,\n UserFeeLevel,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, remove0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { EMPTY_BYTES, VALUE_ZERO } from '../constants';\nimport { UserOperationStatus } from '../types';\nimport type { UserOperationMetadata } from '../types';\n\n/**\n * Converts a user operation metadata object into a transaction metadata object.\n * @param metadata - The user operation metadata object to convert.\n * @returns The equivalent transaction metadata object.\n */\nexport function getTransactionMetadata(\n metadata: UserOperationMetadata,\n): TransactionMeta | undefined {\n const {\n actualGasCost,\n actualGasUsed,\n baseFeePerGas,\n chainId,\n error: rawError,\n origin,\n transactionHash,\n id,\n swapsMetadata,\n time,\n transactionParams,\n transactionType,\n userFeeLevel: rawUserFeeLevel,\n userOperation,\n } = metadata;\n\n if (!transactionParams) {\n return undefined;\n }\n\n // effectiveGasPrice = actualGasCost / actualGasUsed\n const effectiveGasPrice =\n actualGasCost && actualGasUsed\n ? add0x(\n new BN(remove0x(actualGasCost), 16)\n .div(new BN(remove0x(actualGasUsed), 16))\n .toString(16),\n )\n : undefined;\n\n const error = (\n rawError\n ? {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.rpc,\n }\n : undefined\n ) as TransactionError;\n\n const status: TransactionStatus = {\n [UserOperationStatus.Unapproved]: TransactionStatus.unapproved,\n [UserOperationStatus.Approved]: TransactionStatus.approved,\n [UserOperationStatus.Signed]: TransactionStatus.signed,\n [UserOperationStatus.Submitted]: TransactionStatus.submitted,\n [UserOperationStatus.Confirmed]: TransactionStatus.confirmed,\n [UserOperationStatus.Failed]: TransactionStatus.failed,\n }[metadata.status];\n\n const gas = addHex(\n userOperation.preVerificationGas,\n userOperation.verificationGasLimit,\n userOperation.callGasLimit,\n );\n\n const hasPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const maxFeePerGas = hasPaymaster ? VALUE_ZERO : userOperation.maxFeePerGas;\n\n const maxPriorityFeePerGas = hasPaymaster\n ? VALUE_ZERO\n : userOperation.maxPriorityFeePerGas;\n\n const nonce =\n userOperation.nonce === EMPTY_BYTES ? undefined : userOperation.nonce;\n\n const txParams = {\n ...transactionParams,\n from: userOperation.sender,\n gas,\n nonce,\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as TransactionParams;\n\n // User operations only support EIP-1559 gas fee properties.\n delete txParams.gasPrice;\n\n const swaps = {\n approvalTxId: swapsMetadata?.approvalTxId ?? undefined,\n destinationTokenAddress:\n swapsMetadata?.destinationTokenAddress ?? undefined,\n destinationTokenAmount: swapsMetadata?.destinationTokenAmount ?? undefined,\n destinationTokenDecimals:\n swapsMetadata?.destinationTokenDecimals ?? undefined,\n destinationTokenSymbol: swapsMetadata?.destinationTokenSymbol ?? undefined,\n estimatedBaseFee: swapsMetadata?.estimatedBaseFee ?? undefined,\n sourceTokenAddress: swapsMetadata?.sourceTokenAddress ?? undefined,\n sourceTokenAmount: swapsMetadata?.sourceTokenAmount ?? undefined,\n sourceTokenDecimals: swapsMetadata?.sourceTokenDecimals ?? undefined,\n sourceTokenSymbol: swapsMetadata?.sourceTokenSymbol ?? undefined,\n swapAndSendRecipient: swapsMetadata?.swapAndSendRecipient ?? undefined,\n swapMetaData: swapsMetadata?.swapMetaData ?? undefined,\n swapTokenValue: swapsMetadata?.swapTokenValue ?? undefined,\n };\n\n const userFeeLevel = hasPaymaster ? UserFeeLevel.CUSTOM : rawUserFeeLevel;\n\n return {\n baseFeePerGas: (baseFeePerGas as Hex) ?? undefined,\n chainId: chainId as Hex,\n error,\n hash: transactionHash ?? undefined,\n id,\n isUserOperation: true,\n networkClientId: 'user-operation',\n origin,\n status,\n time,\n txParams,\n txReceipt: {\n effectiveGasPrice: effectiveGasPrice ?? undefined,\n gasUsed: actualGasUsed ?? undefined,\n },\n type: transactionType ?? undefined,\n userFeeLevel: userFeeLevel as string,\n ...swaps,\n };\n}\n\n/**\n * Adds the given hexadecimal values together.\n * @param values - The hexadecimal values to add together.\n * @returns The sum of the given hexadecimal values.\n */\nfunction addHex(...values: (string | undefined)[]) {\n const total = new BN(0);\n\n for (const value of values) {\n if (!value) {\n continue;\n }\n\n total.iadd(new BN(remove0x(value), 16));\n }\n\n return add0x(total.toString(16));\n}\n"]}
1
+ {"version":3,"file":"transaction.mjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;;;;AAKA,OAAO,EACL,iBAAiB,EACjB,YAAY,EACb,yCAAyC;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AK,EAAE,CAAC;YACX,SAAS;QACX,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AACnC,CAAC","sourcesContent":["import type {\n TransactionError,\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport {\n TransactionStatus,\n UserFeeLevel,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, remove0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { EMPTY_BYTES, VALUE_ZERO } from '../constants';\nimport { UserOperationStatus } from '../types';\nimport type { UserOperationMetadata } from '../types';\n\n/**\n * Converts a user operation metadata object into a transaction metadata object.\n *\n * @param metadata - The user operation metadata object to convert.\n * @returns The equivalent transaction metadata object.\n */\nexport function getTransactionMetadata(\n metadata: UserOperationMetadata,\n): TransactionMeta | undefined {\n const {\n actualGasCost,\n actualGasUsed,\n baseFeePerGas,\n chainId,\n error: rawError,\n origin,\n transactionHash,\n id,\n swapsMetadata,\n time,\n transactionParams,\n transactionType,\n userFeeLevel: rawUserFeeLevel,\n userOperation,\n } = metadata;\n\n if (!transactionParams) {\n return undefined;\n }\n\n // effectiveGasPrice = actualGasCost / actualGasUsed\n const effectiveGasPrice =\n actualGasCost && actualGasUsed\n ? add0x(\n new BN(remove0x(actualGasCost), 16)\n .div(new BN(remove0x(actualGasUsed), 16))\n .toString(16),\n )\n : undefined;\n\n const error = (\n rawError\n ? {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.rpc,\n }\n : undefined\n ) as TransactionError;\n\n const status: TransactionStatus = {\n [UserOperationStatus.Unapproved]: TransactionStatus.unapproved,\n [UserOperationStatus.Approved]: TransactionStatus.approved,\n [UserOperationStatus.Signed]: TransactionStatus.signed,\n [UserOperationStatus.Submitted]: TransactionStatus.submitted,\n [UserOperationStatus.Confirmed]: TransactionStatus.confirmed,\n [UserOperationStatus.Failed]: TransactionStatus.failed,\n }[metadata.status];\n\n const gas = addHex(\n userOperation.preVerificationGas,\n userOperation.verificationGasLimit,\n userOperation.callGasLimit,\n );\n\n const hasPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const maxFeePerGas = hasPaymaster ? VALUE_ZERO : userOperation.maxFeePerGas;\n\n const maxPriorityFeePerGas = hasPaymaster\n ? VALUE_ZERO\n : userOperation.maxPriorityFeePerGas;\n\n const nonce =\n userOperation.nonce === EMPTY_BYTES ? undefined : userOperation.nonce;\n\n const txParams = {\n ...transactionParams,\n from: userOperation.sender,\n gas,\n nonce,\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as TransactionParams;\n\n // User operations only support EIP-1559 gas fee properties.\n delete txParams.gasPrice;\n\n const swaps = {\n approvalTxId: swapsMetadata?.approvalTxId ?? undefined,\n destinationTokenAddress:\n swapsMetadata?.destinationTokenAddress ?? undefined,\n destinationTokenAmount: swapsMetadata?.destinationTokenAmount ?? undefined,\n destinationTokenDecimals:\n swapsMetadata?.destinationTokenDecimals ?? undefined,\n destinationTokenSymbol: swapsMetadata?.destinationTokenSymbol ?? undefined,\n estimatedBaseFee: swapsMetadata?.estimatedBaseFee ?? undefined,\n sourceTokenAddress: swapsMetadata?.sourceTokenAddress ?? undefined,\n sourceTokenAmount: swapsMetadata?.sourceTokenAmount ?? undefined,\n sourceTokenDecimals: swapsMetadata?.sourceTokenDecimals ?? undefined,\n sourceTokenSymbol: swapsMetadata?.sourceTokenSymbol ?? undefined,\n swapAndSendRecipient: swapsMetadata?.swapAndSendRecipient ?? undefined,\n swapMetaData: swapsMetadata?.swapMetaData ?? undefined,\n swapTokenValue: swapsMetadata?.swapTokenValue ?? undefined,\n };\n\n const userFeeLevel = hasPaymaster ? UserFeeLevel.CUSTOM : rawUserFeeLevel;\n\n return {\n baseFeePerGas: (baseFeePerGas as Hex) ?? undefined,\n chainId: chainId as Hex,\n error,\n hash: transactionHash ?? undefined,\n id,\n isUserOperation: true,\n networkClientId: 'user-operation',\n origin,\n status,\n time,\n txParams,\n txReceipt: {\n effectiveGasPrice: effectiveGasPrice ?? undefined,\n gasUsed: actualGasUsed ?? undefined,\n },\n type: transactionType ?? undefined,\n userFeeLevel: userFeeLevel as string,\n ...swaps,\n };\n}\n\n/**\n * Adds the given hexadecimal values together.\n *\n * @param values - The hexadecimal values to add together.\n * @returns The sum of the given hexadecimal values.\n */\nfunction addHex(...values: (string | undefined)[]) {\n const total = new BN(0);\n\n for (const value of values) {\n if (!value) {\n continue;\n }\n\n total.iadd(new BN(remove0x(value), 16));\n }\n\n return add0x(total.toString(16));\n}\n"]}
@@ -7,6 +7,7 @@ const utils_1 = require("@metamask/utils");
7
7
  const constants_1 = require("../constants.cjs");
8
8
  /**
9
9
  * Validate a request to add a user operation.
10
+ *
10
11
  * @param request - The request to validate.
11
12
  */
12
13
  function validateAddUserOperationRequest(request) {
@@ -25,6 +26,7 @@ function validateAddUserOperationRequest(request) {
25
26
  exports.validateAddUserOperationRequest = validateAddUserOperationRequest;
26
27
  /**
27
28
  * Validate the options when adding a user operation.
29
+ *
28
30
  * @param options - The options to validate.
29
31
  */
30
32
  function validateAddUserOperationOptions(options) {
@@ -59,6 +61,7 @@ function validateAddUserOperationOptions(options) {
59
61
  exports.validateAddUserOperationOptions = validateAddUserOperationOptions;
60
62
  /**
61
63
  * Validate the response from a smart contract account when preparing the user operation.
64
+ *
62
65
  * @param response - The response to validate.
63
66
  */
64
67
  function validatePrepareUserOperationResponse(response) {
@@ -89,6 +92,7 @@ function validatePrepareUserOperationResponse(response) {
89
92
  exports.validatePrepareUserOperationResponse = validatePrepareUserOperationResponse;
90
93
  /**
91
94
  * Validate the response from a smart contract account when updating the user operation.
95
+ *
92
96
  * @param response - The response to validate.
93
97
  */
94
98
  function validateUpdateUserOperationResponse(response) {
@@ -103,6 +107,7 @@ function validateUpdateUserOperationResponse(response) {
103
107
  exports.validateUpdateUserOperationResponse = validateUpdateUserOperationResponse;
104
108
  /**
105
109
  * Validate the response from a smart contract account when signing the user operation.
110
+ *
106
111
  * @param response - The response to validate.
107
112
  */
108
113
  function validateSignUserOperationResponse(response) {
@@ -115,12 +120,11 @@ function validateSignUserOperationResponse(response) {
115
120
  exports.validateSignUserOperationResponse = validateSignUserOperationResponse;
116
121
  /**
117
122
  * Validate data against a struct.
123
+ *
118
124
  * @param data - The data to validate.
119
125
  * @param struct - The struct to validate against.
120
126
  * @param message - The message to throw if validation fails.
121
127
  */
122
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
123
- // eslint-disable-next-line @typescript-eslint/naming-convention
124
128
  function validate(data, struct, message) {
125
129
  try {
126
130
  (0, superstruct_1.assert)(data, struct, message);
@@ -141,6 +145,7 @@ function validate(data, struct, message) {
141
145
  }
142
146
  /**
143
147
  * Define the Hex type used by superstruct.
148
+ *
144
149
  * @returns The Hex superstruct type.
145
150
  */
146
151
  function defineHex() {
@@ -148,6 +153,7 @@ function defineHex() {
148
153
  }
149
154
  /**
150
155
  * Define the HexOrEmptyBytes type used by superstruct.
156
+ *
151
157
  * @returns The HexOrEmptyBytes superstruct type.
152
158
  */
153
159
  function defineHexOrEmptyBytes() {