@metamask-previews/user-operation-controller 41.2.9-preview-8bfa290fb → 42.0.0-preview-0a30e47

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 (159) hide show
  1. package/CHANGELOG.md +22 -2
  2. package/dist/{BlockTrackerPollingController.d.mts → BlockTrackerPollingController.d.ts} +11 -11
  3. package/dist/BlockTrackerPollingController.d.ts.map +1 -0
  4. package/dist/{BlockTrackerPollingController.mjs → BlockTrackerPollingController.js} +17 -19
  5. package/dist/BlockTrackerPollingController.js.map +1 -0
  6. package/dist/{UserOperationController-method-action-types.d.cts → UserOperationController-method-action-types.d.ts} +2 -2
  7. package/dist/UserOperationController-method-action-types.d.ts.map +1 -0
  8. package/dist/{UserOperationController-method-action-types.mjs → UserOperationController-method-action-types.js} +1 -1
  9. package/dist/UserOperationController-method-action-types.js.map +1 -0
  10. package/dist/{UserOperationController.d.cts → UserOperationController.d.ts} +13 -15
  11. package/dist/UserOperationController.d.ts.map +1 -0
  12. package/dist/UserOperationController.js +495 -0
  13. package/dist/UserOperationController.js.map +1 -0
  14. package/dist/{constants.d.cts → constants.d.ts} +1 -1
  15. package/dist/constants.d.ts.map +1 -0
  16. package/dist/{constants.mjs → constants.js} +1 -1
  17. package/dist/constants.js.map +1 -0
  18. package/dist/helpers/{Bundler.d.cts → Bundler.d.ts} +2 -2
  19. package/dist/helpers/Bundler.d.ts.map +1 -0
  20. package/dist/helpers/Bundler.js +74 -0
  21. package/dist/helpers/Bundler.js.map +1 -0
  22. package/dist/helpers/{PendingUserOperationTracker.d.cts → PendingUserOperationTracker.d.ts} +10 -12
  23. package/dist/helpers/PendingUserOperationTracker.d.ts.map +1 -0
  24. package/dist/helpers/PendingUserOperationTracker.js +115 -0
  25. package/dist/helpers/PendingUserOperationTracker.js.map +1 -0
  26. package/dist/helpers/{SnapSmartContractAccount.d.cts → SnapSmartContractAccount.d.ts} +3 -3
  27. package/dist/helpers/SnapSmartContractAccount.d.ts.map +1 -0
  28. package/dist/helpers/SnapSmartContractAccount.js +47 -0
  29. package/dist/helpers/SnapSmartContractAccount.js.map +1 -0
  30. package/dist/index.d.ts +4 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +3 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/logger.d.ts +4 -0
  35. package/dist/logger.d.ts.map +1 -0
  36. package/dist/{logger.mjs → logger.js} +2 -2
  37. package/dist/logger.js.map +1 -0
  38. package/dist/{types.d.mts → types.d.ts} +3 -3
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/{types.mjs → types.js} +1 -1
  41. package/dist/types.js.map +1 -0
  42. package/dist/utils/{chain-id.d.cts → chain-id.d.ts} +1 -1
  43. package/dist/utils/chain-id.d.ts.map +1 -0
  44. package/dist/utils/{chain-id.mjs → chain-id.js} +1 -1
  45. package/dist/utils/chain-id.js.map +1 -0
  46. package/dist/utils/{gas-fees.d.cts → gas-fees.d.ts} +6 -6
  47. package/dist/utils/gas-fees.d.ts.map +1 -0
  48. package/dist/utils/{gas-fees.mjs → gas-fees.js} +8 -15
  49. package/dist/utils/gas-fees.js.map +1 -0
  50. package/dist/utils/{gas.d.mts → gas.d.ts} +2 -2
  51. package/dist/utils/gas.d.ts.map +1 -0
  52. package/dist/utils/{gas.mjs → gas.js} +7 -14
  53. package/dist/utils/gas.js.map +1 -0
  54. package/dist/utils/{transaction.d.cts → transaction.d.ts} +3 -3
  55. package/dist/utils/transaction.d.ts.map +1 -0
  56. package/dist/utils/{transaction.mjs → transaction.js} +6 -13
  57. package/dist/utils/transaction.js.map +1 -0
  58. package/dist/utils/{validation.d.cts → validation.d.ts} +3 -3
  59. package/dist/utils/validation.d.ts.map +1 -0
  60. package/dist/utils/{validation.mjs → validation.js} +5 -5
  61. package/dist/utils/validation.js.map +1 -0
  62. package/package.json +24 -28
  63. package/dist/BlockTrackerPollingController.cjs +0 -68
  64. package/dist/BlockTrackerPollingController.cjs.map +0 -1
  65. package/dist/BlockTrackerPollingController.d.cts +0 -41
  66. package/dist/BlockTrackerPollingController.d.cts.map +0 -1
  67. package/dist/BlockTrackerPollingController.d.mts.map +0 -1
  68. package/dist/BlockTrackerPollingController.mjs.map +0 -1
  69. package/dist/UserOperationController-method-action-types.cjs +0 -7
  70. package/dist/UserOperationController-method-action-types.cjs.map +0 -1
  71. package/dist/UserOperationController-method-action-types.d.cts.map +0 -1
  72. package/dist/UserOperationController-method-action-types.d.mts +0 -57
  73. package/dist/UserOperationController-method-action-types.d.mts.map +0 -1
  74. package/dist/UserOperationController-method-action-types.mjs.map +0 -1
  75. package/dist/UserOperationController.cjs +0 -495
  76. package/dist/UserOperationController.cjs.map +0 -1
  77. package/dist/UserOperationController.d.cts.map +0 -1
  78. package/dist/UserOperationController.d.mts +0 -136
  79. package/dist/UserOperationController.d.mts.map +0 -1
  80. package/dist/UserOperationController.mjs +0 -489
  81. package/dist/UserOperationController.mjs.map +0 -1
  82. package/dist/constants.cjs +0 -7
  83. package/dist/constants.cjs.map +0 -1
  84. package/dist/constants.d.cts.map +0 -1
  85. package/dist/constants.d.mts +0 -4
  86. package/dist/constants.d.mts.map +0 -1
  87. package/dist/constants.mjs.map +0 -1
  88. package/dist/helpers/Bundler.cjs +0 -91
  89. package/dist/helpers/Bundler.cjs.map +0 -1
  90. package/dist/helpers/Bundler.d.cts.map +0 -1
  91. package/dist/helpers/Bundler.d.mts +0 -46
  92. package/dist/helpers/Bundler.d.mts.map +0 -1
  93. package/dist/helpers/Bundler.mjs +0 -87
  94. package/dist/helpers/Bundler.mjs.map +0 -1
  95. package/dist/helpers/PendingUserOperationTracker.cjs +0 -127
  96. package/dist/helpers/PendingUserOperationTracker.cjs.map +0 -1
  97. package/dist/helpers/PendingUserOperationTracker.d.cts.map +0 -1
  98. package/dist/helpers/PendingUserOperationTracker.d.mts +0 -51
  99. package/dist/helpers/PendingUserOperationTracker.d.mts.map +0 -1
  100. package/dist/helpers/PendingUserOperationTracker.mjs +0 -127
  101. package/dist/helpers/PendingUserOperationTracker.mjs.map +0 -1
  102. package/dist/helpers/SnapSmartContractAccount.cjs +0 -64
  103. package/dist/helpers/SnapSmartContractAccount.cjs.map +0 -1
  104. package/dist/helpers/SnapSmartContractAccount.d.cts.map +0 -1
  105. package/dist/helpers/SnapSmartContractAccount.d.mts +0 -10
  106. package/dist/helpers/SnapSmartContractAccount.d.mts.map +0 -1
  107. package/dist/helpers/SnapSmartContractAccount.mjs +0 -60
  108. package/dist/helpers/SnapSmartContractAccount.mjs.map +0 -1
  109. package/dist/index.cjs +0 -19
  110. package/dist/index.cjs.map +0 -1
  111. package/dist/index.d.cts +0 -4
  112. package/dist/index.d.cts.map +0 -1
  113. package/dist/index.d.mts +0 -4
  114. package/dist/index.d.mts.map +0 -1
  115. package/dist/index.mjs +0 -3
  116. package/dist/index.mjs.map +0 -1
  117. package/dist/logger.cjs +0 -8
  118. package/dist/logger.cjs.map +0 -1
  119. package/dist/logger.d.cts +0 -5
  120. package/dist/logger.d.cts.map +0 -1
  121. package/dist/logger.d.mts +0 -5
  122. package/dist/logger.d.mts.map +0 -1
  123. package/dist/logger.mjs.map +0 -1
  124. package/dist/types.cjs +0 -16
  125. package/dist/types.cjs.map +0 -1
  126. package/dist/types.d.cts +0 -294
  127. package/dist/types.d.cts.map +0 -1
  128. package/dist/types.d.mts.map +0 -1
  129. package/dist/types.mjs.map +0 -1
  130. package/dist/utils/chain-id.cjs +0 -17
  131. package/dist/utils/chain-id.cjs.map +0 -1
  132. package/dist/utils/chain-id.d.cts.map +0 -1
  133. package/dist/utils/chain-id.d.mts +0 -8
  134. package/dist/utils/chain-id.d.mts.map +0 -1
  135. package/dist/utils/chain-id.mjs.map +0 -1
  136. package/dist/utils/gas-fees.cjs +0 -194
  137. package/dist/utils/gas-fees.cjs.map +0 -1
  138. package/dist/utils/gas-fees.d.cts.map +0 -1
  139. package/dist/utils/gas-fees.d.mts +0 -24
  140. package/dist/utils/gas-fees.d.mts.map +0 -1
  141. package/dist/utils/gas-fees.mjs.map +0 -1
  142. package/dist/utils/gas.cjs +0 -72
  143. package/dist/utils/gas.cjs.map +0 -1
  144. package/dist/utils/gas.d.cts +0 -10
  145. package/dist/utils/gas.d.cts.map +0 -1
  146. package/dist/utils/gas.d.mts.map +0 -1
  147. package/dist/utils/gas.mjs.map +0 -1
  148. package/dist/utils/transaction.cjs +0 -117
  149. package/dist/utils/transaction.cjs.map +0 -1
  150. package/dist/utils/transaction.d.cts.map +0 -1
  151. package/dist/utils/transaction.d.mts +0 -10
  152. package/dist/utils/transaction.d.mts.map +0 -1
  153. package/dist/utils/transaction.mjs.map +0 -1
  154. package/dist/utils/validation.cjs +0 -162
  155. package/dist/utils/validation.cjs.map +0 -1
  156. package/dist/utils/validation.d.cts.map +0 -1
  157. package/dist/utils/validation.d.mts +0 -33
  158. package/dist/utils/validation.d.mts.map +0 -1
  159. package/dist/utils/validation.mjs.map +0 -1
@@ -1 +0,0 @@
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,EAAE,kBAAkB,EAAE,qCAAqC;AAIlE,OAAO,EAAE,YAAY,EAAE,yCAAyC;AAEhE,OAAO,EAAE,KAAK,EAAE,wBAAwB;AAExC,OAAO,EAAE,WAAW,EAAE,yBAAwB;AAC9C,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,sBAAqB;AAIjE,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;AAe1D;;;;;;;;;GASG;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,QAA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} from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';\nimport type { GasFeeState } 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.js';\nimport { createModuleLogger, projectLogger } from '../logger.js';\nimport type { UserOperation, UserOperationMetadata } from '../types.js';\nimport type { AddUserOperationRequest } from '../UserOperationController.js';\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));\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"]}
@@ -1,72 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.updateGas = void 0;
7
- const controller_utils_1 = require("@metamask/controller-utils");
8
- const utils_1 = require("@metamask/utils");
9
- const bn_js_1 = __importDefault(require("bn.js"));
10
- const constants_js_1 = require("../constants.cjs");
11
- const Bundler_js_1 = require("../helpers/Bundler.cjs");
12
- const logger_js_1 = require("../logger.cjs");
13
- const log = (0, logger_js_1.createModuleLogger)(logger_js_1.projectLogger, 'gas');
14
- /**
15
- * A multiplier to apply to all gas estimate values returned from the bundler.
16
- */
17
- const GAS_ESTIMATE_MULTIPLIER = 1.5;
18
- /**
19
- * Populates the gas properties for a user operation.
20
- *
21
- * @param metadata - The metadata for the user operation.
22
- * @param prepareResponse - The prepare response from the smart contract account.
23
- * @param entrypoint - Address of the entrypoint contract.
24
- */
25
- async function updateGas(metadata, prepareResponse, entrypoint) {
26
- const { userOperation } = metadata;
27
- if (prepareResponse.gas) {
28
- userOperation.callGasLimit = prepareResponse.gas.callGasLimit;
29
- userOperation.preVerificationGas = prepareResponse.gas.preVerificationGas;
30
- userOperation.verificationGasLimit =
31
- prepareResponse.gas.verificationGasLimit;
32
- log('Using gas values from smart contract account', {
33
- callGasLimit: userOperation.callGasLimit,
34
- preVerificationGas: userOperation.preVerificationGas,
35
- verificationGasLimit: userOperation.verificationGasLimit,
36
- });
37
- return;
38
- }
39
- const payload = {
40
- ...userOperation,
41
- maxFeePerGas: constants_js_1.VALUE_ZERO,
42
- maxPriorityFeePerGas: constants_js_1.VALUE_ZERO,
43
- callGasLimit: constants_js_1.VALUE_ZERO,
44
- preVerificationGas: constants_js_1.VALUE_ZERO,
45
- verificationGasLimit: '0xF4240',
46
- };
47
- const bundler = new Bundler_js_1.Bundler(metadata.bundlerUrl);
48
- const estimate = await bundler.estimateUserOperationGas(payload, entrypoint);
49
- userOperation.callGasLimit = normalizeGasEstimate(estimate.callGasLimit);
50
- userOperation.preVerificationGas = normalizeGasEstimate(estimate.preVerificationGas);
51
- userOperation.verificationGasLimit = normalizeGasEstimate((estimate.verificationGasLimit ?? estimate.verificationGas));
52
- log('Using buffered gas values from bundler estimate', {
53
- callGasLimit: userOperation.callGasLimit,
54
- preVerificationGas: userOperation.preVerificationGas,
55
- verificationGasLimit: userOperation.verificationGasLimit,
56
- multiplier: GAS_ESTIMATE_MULTIPLIER,
57
- estimate,
58
- });
59
- }
60
- exports.updateGas = updateGas;
61
- /**
62
- * Normalizes a gas estimate value from the bundler.
63
- *
64
- * @param rawValue - The raw value to normalize.
65
- * @returns The normalized value as a hexadecimal string.
66
- */
67
- function normalizeGasEstimate(rawValue) {
68
- const value = typeof rawValue === 'string' ? (0, controller_utils_1.hexToBN)(rawValue) : new bn_js_1.default(rawValue);
69
- const bufferedValue = value.muln(GAS_ESTIMATE_MULTIPLIER);
70
- return (0, utils_1.add0x)(bufferedValue.toString(16));
71
- }
72
- //# sourceMappingURL=gas.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gas.cjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";;;;;;AAAA,iEAAqD;AACrD,2CAAwC;AACxC,kDAAuB;AAEvB,mDAA6C;AAC7C,uDAAgD;AAChD,6CAAiE;AAMjE,MAAM,GAAG,GAAG,IAAA,8BAAkB,EAAC,yBAAa,EAAE,KAAK,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC;;;;;;GAMG;AACI,KAAK,UAAU,SAAS,CAC7B,QAA+B,EAC/B,eAA6C,EA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C,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.js';\nimport { Bundler } from '../helpers/Bundler.js';\nimport { createModuleLogger, projectLogger } from '../logger.js';\nimport type {\n PrepareUserOperationResponse,\n UserOperationMetadata,\n} from '../types.js';\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,10 +0,0 @@
1
- import type { PrepareUserOperationResponse, UserOperationMetadata } from "../types.cjs";
2
- /**
3
- * Populates the gas properties for a user operation.
4
- *
5
- * @param metadata - The metadata for the user operation.
6
- * @param prepareResponse - The prepare response from the smart contract account.
7
- * @param entrypoint - Address of the entrypoint contract.
8
- */
9
- export declare function updateGas(metadata: UserOperationMetadata, prepareResponse: PrepareUserOperationResponse, entrypoint: string): Promise<void>;
10
- //# sourceMappingURL=gas.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gas.d.cts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,4BAA4B,EAC5B,qBAAqB,EACtB,qBAAoB;AASrB;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,qBAAqB,EAC/B,eAAe,EAAE,4BAA4B,EAC7C,UAAU,EAAE,MAAM,iBAgDnB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"gas.d.mts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,4BAA4B,EAC5B,qBAAqB,EACtB,qBAAoB;AASrB;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,qBAAqB,EAC/B,eAAe,EAAE,4BAA4B,EAC7C,UAAU,EAAE,MAAM,iBAgDnB"}
@@ -1 +0,0 @@
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,yBAAwB;AAC7C,OAAO,EAAE,OAAO,EAAE,+BAA8B;AAChD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,sBAAqB;AAMjE,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,QAA+B,EAC/B,eAA6C,EAC7C,UAAkB;IAElB,MAAM,EAAE,aAAa,EAAE,GAAG,QAAQ,CAAC;IAEnC,IAAI,eAAe,CAAC,GAAG,EAAE,CAAC;QACxB,aAAa,CAAC,YAAY,GAAG,eAAe,CAAC,GAAG,CAAC,YAAY,CAAC;QAC9D,aAAa,CAA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O,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.js';\nimport { Bundler } from '../helpers/Bundler.js';\nimport { createModuleLogger, projectLogger } from '../logger.js';\nimport type {\n PrepareUserOperationResponse,\n UserOperationMetadata,\n} from '../types.js';\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,117 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getTransactionMetadata = void 0;
7
- const transaction_controller_1 = require("@metamask/transaction-controller");
8
- const utils_1 = require("@metamask/utils");
9
- const bn_js_1 = __importDefault(require("bn.js"));
10
- const constants_js_1 = require("../constants.cjs");
11
- const types_js_1 = require("../types.cjs");
12
- /**
13
- * Converts a user operation metadata object into a transaction metadata object.
14
- *
15
- * @param metadata - The user operation metadata object to convert.
16
- * @returns The equivalent transaction metadata object.
17
- */
18
- function getTransactionMetadata(metadata) {
19
- const { actualGasCost, actualGasUsed, baseFeePerGas, chainId, error: rawError, origin, transactionHash, id, swapsMetadata, time, transactionParams, transactionType, userFeeLevel: rawUserFeeLevel, userOperation, } = metadata;
20
- if (!transactionParams) {
21
- return undefined;
22
- }
23
- // effectiveGasPrice = actualGasCost / actualGasUsed
24
- const effectiveGasPrice = actualGasCost && actualGasUsed
25
- ? (0, utils_1.add0x)(new bn_js_1.default((0, utils_1.remove0x)(actualGasCost), 16)
26
- .div(new bn_js_1.default((0, utils_1.remove0x)(actualGasUsed), 16))
27
- .toString(16))
28
- : undefined;
29
- const error = (rawError
30
- ? {
31
- name: rawError.name,
32
- message: rawError.message,
33
- stack: rawError.stack,
34
- code: rawError.code,
35
- rpc: rawError.rpc,
36
- }
37
- : undefined);
38
- const status = {
39
- [types_js_1.UserOperationStatus.Unapproved]: transaction_controller_1.TransactionStatus.unapproved,
40
- [types_js_1.UserOperationStatus.Approved]: transaction_controller_1.TransactionStatus.approved,
41
- [types_js_1.UserOperationStatus.Signed]: transaction_controller_1.TransactionStatus.signed,
42
- [types_js_1.UserOperationStatus.Submitted]: transaction_controller_1.TransactionStatus.submitted,
43
- [types_js_1.UserOperationStatus.Confirmed]: transaction_controller_1.TransactionStatus.confirmed,
44
- [types_js_1.UserOperationStatus.Failed]: transaction_controller_1.TransactionStatus.failed,
45
- }[metadata.status];
46
- const gas = addHex(userOperation.preVerificationGas, userOperation.verificationGasLimit, userOperation.callGasLimit);
47
- const hasPaymaster = userOperation.paymasterAndData !== constants_js_1.EMPTY_BYTES;
48
- const maxFeePerGas = hasPaymaster ? constants_js_1.VALUE_ZERO : userOperation.maxFeePerGas;
49
- const maxPriorityFeePerGas = hasPaymaster
50
- ? constants_js_1.VALUE_ZERO
51
- : userOperation.maxPriorityFeePerGas;
52
- const nonce = userOperation.nonce === constants_js_1.EMPTY_BYTES ? undefined : userOperation.nonce;
53
- const txParams = {
54
- ...transactionParams,
55
- from: userOperation.sender,
56
- gas,
57
- nonce,
58
- maxFeePerGas,
59
- maxPriorityFeePerGas,
60
- };
61
- // User operations only support EIP-1559 gas fee properties.
62
- delete txParams.gasPrice;
63
- const swaps = {
64
- approvalTxId: swapsMetadata?.approvalTxId ?? undefined,
65
- destinationTokenAddress: swapsMetadata?.destinationTokenAddress ?? undefined,
66
- destinationTokenAmount: swapsMetadata?.destinationTokenAmount ?? undefined,
67
- destinationTokenDecimals: swapsMetadata?.destinationTokenDecimals ?? undefined,
68
- destinationTokenSymbol: swapsMetadata?.destinationTokenSymbol ?? undefined,
69
- estimatedBaseFee: swapsMetadata?.estimatedBaseFee ?? undefined,
70
- sourceTokenAddress: swapsMetadata?.sourceTokenAddress ?? undefined,
71
- sourceTokenAmount: swapsMetadata?.sourceTokenAmount ?? undefined,
72
- sourceTokenDecimals: swapsMetadata?.sourceTokenDecimals ?? undefined,
73
- sourceTokenSymbol: swapsMetadata?.sourceTokenSymbol ?? undefined,
74
- swapAndSendRecipient: swapsMetadata?.swapAndSendRecipient ?? undefined,
75
- swapMetaData: swapsMetadata?.swapMetaData ?? undefined,
76
- swapTokenValue: swapsMetadata?.swapTokenValue ?? undefined,
77
- };
78
- const userFeeLevel = hasPaymaster ? transaction_controller_1.UserFeeLevel.CUSTOM : rawUserFeeLevel;
79
- return {
80
- baseFeePerGas: baseFeePerGas ?? undefined,
81
- chainId: chainId,
82
- error,
83
- hash: transactionHash ?? undefined,
84
- id,
85
- isUserOperation: true,
86
- networkClientId: 'user-operation',
87
- origin,
88
- status,
89
- time,
90
- txParams,
91
- txReceipt: {
92
- effectiveGasPrice: effectiveGasPrice ?? undefined,
93
- gasUsed: actualGasUsed ?? undefined,
94
- },
95
- type: transactionType ?? undefined,
96
- userFeeLevel: userFeeLevel,
97
- ...swaps,
98
- };
99
- }
100
- exports.getTransactionMetadata = getTransactionMetadata;
101
- /**
102
- * Adds the given hexadecimal values together.
103
- *
104
- * @param values - The hexadecimal values to add together.
105
- * @returns The sum of the given hexadecimal values.
106
- */
107
- function addHex(...values) {
108
- const total = new bn_js_1.default(0);
109
- for (const value of values) {
110
- if (!value) {
111
- continue;
112
- }
113
- total.iadd(new bn_js_1.default((0, utils_1.remove0x)(value), 16));
114
- }
115
- return (0, utils_1.add0x)(total.toString(16));
116
- }
117
- //# sourceMappingURL=transaction.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transaction.cjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;;;;AAKA,6EAG0C;AAE1C,2CAAkD;AAClD,kDAAuB;AAEvB,mDAA0D;AAC1D,2CAAkD;AAGlD;;;;;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,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,8BAAmB,CAAC,UAAU,CAAC,E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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.js';\nimport { UserOperationStatus } from '../types.js';\nimport type { UserOperationMetadata } from '../types.js';\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"]}
@@ -1 +0,0 @@
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,qBAAoB;AAEzD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,qBAAqB,GAC9B,eAAe,GAAG,SAAS,CA0H7B"}
@@ -1,10 +0,0 @@
1
- import type { TransactionMeta } from "@metamask/transaction-controller";
2
- import type { UserOperationMetadata } from "../types.mjs";
3
- /**
4
- * Converts a user operation metadata object into a transaction metadata object.
5
- *
6
- * @param metadata - The user operation metadata object to convert.
7
- * @returns The equivalent transaction metadata object.
8
- */
9
- export declare function getTransactionMetadata(metadata: UserOperationMetadata): TransactionMeta | undefined;
10
- //# sourceMappingURL=transaction.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transaction.d.mts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[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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;;;;;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,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.js';\nimport { UserOperationStatus } from '../types.js';\nimport type { UserOperationMetadata } from '../types.js';\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"]}
@@ -1,162 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateSignUserOperationResponse = exports.validateUpdateUserOperationResponse = exports.validatePrepareUserOperationResponse = exports.validateAddUserOperationOptions = exports.validateAddUserOperationRequest = void 0;
4
- const superstruct_1 = require("@metamask/superstruct");
5
- const transaction_controller_1 = require("@metamask/transaction-controller");
6
- const utils_1 = require("@metamask/utils");
7
- const constants_js_1 = require("../constants.cjs");
8
- /**
9
- * Validate a request to add a user operation.
10
- *
11
- * @param request - The request to validate.
12
- */
13
- function validateAddUserOperationRequest(request) {
14
- const Hex = defineHex();
15
- const HexOrEmptyBytes = defineHexOrEmptyBytes();
16
- const ValidRequest = (0, superstruct_1.object)({
17
- data: (0, superstruct_1.optional)(HexOrEmptyBytes),
18
- from: Hex,
19
- maxFeePerGas: (0, superstruct_1.optional)(Hex),
20
- maxPriorityFeePerGas: (0, superstruct_1.optional)(Hex),
21
- to: (0, superstruct_1.optional)(Hex),
22
- value: (0, superstruct_1.optional)(Hex),
23
- });
24
- validate(request, ValidRequest, 'Invalid request to add user operation');
25
- }
26
- exports.validateAddUserOperationRequest = validateAddUserOperationRequest;
27
- /**
28
- * Validate the options when adding a user operation.
29
- *
30
- * @param options - The options to validate.
31
- */
32
- function validateAddUserOperationOptions(options) {
33
- const ValidOptions = (0, superstruct_1.object)({
34
- networkClientId: (0, superstruct_1.string)(),
35
- origin: (0, superstruct_1.string)(),
36
- requireApproval: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
37
- smartContractAccount: (0, superstruct_1.optional)((0, superstruct_1.object)({
38
- prepareUserOperation: (0, superstruct_1.func)(),
39
- updateUserOperation: (0, superstruct_1.func)(),
40
- signUserOperation: (0, superstruct_1.func)(),
41
- })),
42
- swaps: (0, superstruct_1.optional)((0, superstruct_1.object)({
43
- approvalTxId: (0, superstruct_1.optional)((0, superstruct_1.string)()),
44
- destinationTokenAddress: (0, superstruct_1.optional)((0, superstruct_1.string)()),
45
- destinationTokenDecimals: (0, superstruct_1.optional)((0, superstruct_1.number)()),
46
- destinationTokenSymbol: (0, superstruct_1.optional)((0, superstruct_1.string)()),
47
- estimatedBaseFee: (0, superstruct_1.optional)((0, superstruct_1.string)()),
48
- sourceTokenSymbol: (0, superstruct_1.optional)((0, superstruct_1.string)()),
49
- swapMetaData: (0, superstruct_1.optional)((0, superstruct_1.object)()),
50
- swapTokenValue: (0, superstruct_1.optional)((0, superstruct_1.string)()),
51
- destinationTokenAmount: (0, superstruct_1.optional)((0, superstruct_1.string)()),
52
- sourceTokenAddress: (0, superstruct_1.optional)((0, superstruct_1.string)()),
53
- sourceTokenAmount: (0, superstruct_1.optional)((0, superstruct_1.string)()),
54
- sourceTokenDecimals: (0, superstruct_1.optional)((0, superstruct_1.number)()),
55
- swapAndSendRecipient: (0, superstruct_1.optional)((0, superstruct_1.string)()),
56
- })),
57
- type: (0, superstruct_1.optional)((0, superstruct_1.enums)(Object.values(transaction_controller_1.TransactionType))),
58
- });
59
- validate(options, ValidOptions, 'Invalid options to add user operation');
60
- }
61
- exports.validateAddUserOperationOptions = validateAddUserOperationOptions;
62
- /**
63
- * Validate the response from a smart contract account when preparing the user operation.
64
- *
65
- * @param response - The response to validate.
66
- */
67
- function validatePrepareUserOperationResponse(response) {
68
- const Hex = defineHex();
69
- const HexOrEmptyBytes = defineHexOrEmptyBytes();
70
- const ValidResponse = (0, superstruct_1.refine)((0, superstruct_1.object)({
71
- bundler: (0, superstruct_1.string)(),
72
- callData: Hex,
73
- dummyPaymasterAndData: (0, superstruct_1.optional)(HexOrEmptyBytes),
74
- dummySignature: (0, superstruct_1.optional)(HexOrEmptyBytes),
75
- gas: (0, superstruct_1.optional)((0, superstruct_1.object)({
76
- callGasLimit: Hex,
77
- preVerificationGas: Hex,
78
- verificationGasLimit: Hex,
79
- })),
80
- initCode: (0, superstruct_1.optional)(HexOrEmptyBytes),
81
- nonce: Hex,
82
- sender: Hex,
83
- }), 'ValidPrepareUserOperationResponse', ({ gas, dummySignature }) => {
84
- if (!gas && (!dummySignature || dummySignature === constants_js_1.EMPTY_BYTES)) {
85
- return 'Must specify dummySignature if not specifying gas';
86
- }
87
- /* istanbul ignore next */
88
- return true;
89
- });
90
- validate(response, ValidResponse, 'Invalid response when preparing user operation');
91
- }
92
- exports.validatePrepareUserOperationResponse = validatePrepareUserOperationResponse;
93
- /**
94
- * Validate the response from a smart contract account when updating the user operation.
95
- *
96
- * @param response - The response to validate.
97
- */
98
- function validateUpdateUserOperationResponse(response) {
99
- const ValidResponse = (0, superstruct_1.optional)((0, superstruct_1.object)({
100
- paymasterAndData: (0, superstruct_1.optional)(defineHexOrEmptyBytes()),
101
- callGasLimit: (0, superstruct_1.optional)(defineHexOrEmptyBytes()),
102
- preVerificationGas: (0, superstruct_1.optional)(defineHexOrEmptyBytes()),
103
- verificationGasLimit: (0, superstruct_1.optional)(defineHexOrEmptyBytes()),
104
- }));
105
- validate(response, ValidResponse, 'Invalid response when updating user operation');
106
- }
107
- exports.validateUpdateUserOperationResponse = validateUpdateUserOperationResponse;
108
- /**
109
- * Validate the response from a smart contract account when signing the user operation.
110
- *
111
- * @param response - The response to validate.
112
- */
113
- function validateSignUserOperationResponse(response) {
114
- const Hex = defineHex();
115
- const ValidResponse = (0, superstruct_1.object)({
116
- signature: Hex,
117
- });
118
- validate(response, ValidResponse, 'Invalid response when signing user operation');
119
- }
120
- exports.validateSignUserOperationResponse = validateSignUserOperationResponse;
121
- /**
122
- * Validate data against a struct.
123
- *
124
- * @param data - The data to validate.
125
- * @param struct - The struct to validate against.
126
- * @param message - The message to throw if validation fails.
127
- */
128
- function validate(data, struct, message) {
129
- try {
130
- (0, superstruct_1.assert)(data, struct, message);
131
- }
132
- catch (error) {
133
- const causes = error
134
- .failures()
135
- .map((failure) => {
136
- if (!failure.path.length) {
137
- return failure.message;
138
- }
139
- return `${failure.path.join('.')} - ${failure.message}`;
140
- })
141
- .join('\n');
142
- const finalMessage = `${message}\n${causes}`;
143
- throw new Error(finalMessage);
144
- }
145
- }
146
- /**
147
- * Define the Hex type used by superstruct.
148
- *
149
- * @returns The Hex superstruct type.
150
- */
151
- function defineHex() {
152
- return (0, superstruct_1.define)('Hexadecimal String', (value) => (0, utils_1.isStrictHexString)(value));
153
- }
154
- /**
155
- * Define the HexOrEmptyBytes type used by superstruct.
156
- *
157
- * @returns The HexOrEmptyBytes superstruct type.
158
- */
159
- function defineHexOrEmptyBytes() {
160
- return (0, superstruct_1.define)('Hexadecimal String or 0x', (value) => (0, utils_1.isStrictHexString)(value) || value === constants_js_1.EMPTY_BYTES);
161
- }
162
- //# sourceMappingURL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M,EACX,0BAA0B,EAC1B,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,yBAAiB,EAAC,KAAK,CAAC,IAAI,KAAK,KAAK,0BAAW,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["import type { Struct, StructError } from '@metamask/superstruct';\nimport {\n assert,\n boolean,\n define,\n enums,\n func,\n number,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport { isStrictHexString } from '@metamask/utils';\n\nimport { EMPTY_BYTES } from '../constants.js';\nimport type {\n PrepareUserOperationResponse,\n SignUserOperationResponse,\n UpdateUserOperationResponse,\n} from '../types.js';\nimport type {\n AddUserOperationOptions,\n AddUserOperationRequest,\n} from '../UserOperationController.js';\n\n/**\n * Validate a request to add a user operation.\n *\n * @param request - The request to validate.\n */\nexport function validateAddUserOperationRequest(\n request: AddUserOperationRequest,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidRequest = object({\n data: optional(HexOrEmptyBytes),\n from: Hex,\n maxFeePerGas: optional(Hex),\n maxPriorityFeePerGas: optional(Hex),\n to: optional(Hex),\n value: optional(Hex),\n });\n\n validate(request, ValidRequest, 'Invalid request to add user operation');\n}\n\n/**\n * Validate the options when adding a user operation.\n *\n * @param options - The options to validate.\n */\nexport function validateAddUserOperationOptions(\n options: AddUserOperationOptions,\n) {\n const ValidOptions = object({\n networkClientId: string(),\n origin: string(),\n requireApproval: optional(boolean()),\n smartContractAccount: optional(\n object({\n prepareUserOperation: func(),\n updateUserOperation: func(),\n signUserOperation: func(),\n }),\n ),\n swaps: optional(\n object({\n approvalTxId: optional(string()),\n destinationTokenAddress: optional(string()),\n destinationTokenDecimals: optional(number()),\n destinationTokenSymbol: optional(string()),\n estimatedBaseFee: optional(string()),\n sourceTokenSymbol: optional(string()),\n swapMetaData: optional(object()),\n swapTokenValue: optional(string()),\n destinationTokenAmount: optional(string()),\n sourceTokenAddress: optional(string()),\n sourceTokenAmount: optional(string()),\n sourceTokenDecimals: optional(number()),\n swapAndSendRecipient: optional(string()),\n }),\n ),\n type: optional(enums(Object.values(TransactionType))),\n });\n\n validate(options, ValidOptions, 'Invalid options to add user operation');\n}\n\n/**\n * Validate the response from a smart contract account when preparing the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validatePrepareUserOperationResponse(\n response: PrepareUserOperationResponse,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidResponse = refine(\n object({\n bundler: string(),\n callData: Hex,\n dummyPaymasterAndData: optional(HexOrEmptyBytes),\n dummySignature: optional(HexOrEmptyBytes),\n gas: optional(\n object({\n callGasLimit: Hex,\n preVerificationGas: Hex,\n verificationGasLimit: Hex,\n }),\n ),\n initCode: optional(HexOrEmptyBytes),\n nonce: Hex,\n sender: Hex,\n }),\n 'ValidPrepareUserOperationResponse',\n ({ gas, dummySignature }) => {\n if (!gas && (!dummySignature || dummySignature === EMPTY_BYTES)) {\n return 'Must specify dummySignature if not specifying gas';\n }\n\n /* istanbul ignore next */\n return true;\n },\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when preparing user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when updating the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validateUpdateUserOperationResponse(\n response: UpdateUserOperationResponse,\n) {\n const ValidResponse = optional(\n object({\n paymasterAndData: optional(defineHexOrEmptyBytes()),\n callGasLimit: optional(defineHexOrEmptyBytes()),\n preVerificationGas: optional(defineHexOrEmptyBytes()),\n verificationGasLimit: optional(defineHexOrEmptyBytes()),\n }),\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when updating user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when signing the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validateSignUserOperationResponse(\n response: SignUserOperationResponse,\n) {\n const Hex = defineHex();\n\n const ValidResponse = object({\n signature: Hex,\n });\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when signing user operation',\n );\n}\n\n/**\n * Validate data against a struct.\n *\n * @param data - The data to validate.\n * @param struct - The struct to validate against.\n * @param message - The message to throw if validation fails.\n */\nfunction validate<T>(data: unknown, struct: Struct<T>, message: string) {\n try {\n assert(data, struct, message);\n } catch (error) {\n const causes = (error as StructError)\n .failures()\n .map((failure) => {\n if (!failure.path.length) {\n return failure.message;\n }\n\n return `${failure.path.join('.')} - ${failure.message}`;\n })\n .join('\\n');\n\n const finalMessage = `${message}\\n${causes}`;\n\n throw new Error(finalMessage);\n }\n}\n\n/**\n * Define the Hex type used by superstruct.\n *\n * @returns The Hex superstruct type.\n */\nfunction defineHex() {\n return define<string>('Hexadecimal String', (value) =>\n isStrictHexString(value),\n );\n}\n\n/**\n * Define the HexOrEmptyBytes type used by superstruct.\n *\n * @returns The HexOrEmptyBytes superstruct type.\n */\nfunction defineHexOrEmptyBytes() {\n return define<string>(\n 'Hexadecimal String or 0x',\n (value) => isStrictHexString(value) || value === EMPTY_BYTES,\n );\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"validation.d.cts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,EAC5B,qBAAoB;AACrB,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,uCAAsC;AAEvC;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAejC;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAkCjC;AAED;;;;GAIG;AACH,wBAAgB,oCAAoC,CAClD,QAAQ,EAAE,4BAA4B,QAsCvC;AAED;;;;GAIG;AACH,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,2BAA2B,QAgBtC;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,yBAAyB,QAapC"}
@@ -1,33 +0,0 @@
1
- import type { PrepareUserOperationResponse, SignUserOperationResponse, UpdateUserOperationResponse } from "../types.mjs";
2
- import type { AddUserOperationOptions, AddUserOperationRequest } from "../UserOperationController.mjs";
3
- /**
4
- * Validate a request to add a user operation.
5
- *
6
- * @param request - The request to validate.
7
- */
8
- export declare function validateAddUserOperationRequest(request: AddUserOperationRequest): void;
9
- /**
10
- * Validate the options when adding a user operation.
11
- *
12
- * @param options - The options to validate.
13
- */
14
- export declare function validateAddUserOperationOptions(options: AddUserOperationOptions): void;
15
- /**
16
- * Validate the response from a smart contract account when preparing the user operation.
17
- *
18
- * @param response - The response to validate.
19
- */
20
- export declare function validatePrepareUserOperationResponse(response: PrepareUserOperationResponse): void;
21
- /**
22
- * Validate the response from a smart contract account when updating the user operation.
23
- *
24
- * @param response - The response to validate.
25
- */
26
- export declare function validateUpdateUserOperationResponse(response: UpdateUserOperationResponse): void;
27
- /**
28
- * Validate the response from a smart contract account when signing the user operation.
29
- *
30
- * @param response - The response to validate.
31
- */
32
- export declare function validateSignUserOperationResponse(response: SignUserOperationResponse): void;
33
- //# sourceMappingURL=validation.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validation.d.mts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,EAC5B,qBAAoB;AACrB,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,uCAAsC;AAEvC;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAejC;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAkCjC;AAED;;;;GAIG;AACH,wBAAgB,oCAAoC,CAClD,QAAQ,EAAE,4BAA4B,QAsCvC;AAED;;;;GAIG;AACH,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,2BAA2B,QAgBtC;AAED;;;;GAIG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AEH,QAAQ,CACN,QAAQ,EACR,aAAa,EACb,8CAA8C,CAC/C,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAS,QAAQ,CAAI,IAAa,EAAE,MAAiB,EAAE,OAAe;IACpE,IAAI,CAAC;QACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GAAI,KAAqB;aAClC,QAAQ,EAAE;aACV,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YACf,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACzB,OAAO,OAAO,CAAC,OAAO,CAAC;YACzB,CAAC;YAED,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QAC1D,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,MAAM,YAAY,GAAG,GAAG,OAAO,KAAK,MAAM,EAAE,CAAC;QAE7C,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IAChC,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS;IAChB,OAAO,MAAM,CAAS,oBAAoB,EAAE,CAAC,KAAK,EAAE,EAAE,CACpD,iBAAiB,CAAC,KAAK,CAAC,CACzB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,qBAAqB;IAC5B,OAAO,MAAM,CACX,0BAA0B,EAC1B,CAAC,KAAK,EAAE,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,WAAW,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["import type { Struct, StructError } from '@metamask/superstruct';\nimport {\n assert,\n boolean,\n define,\n enums,\n func,\n number,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport { isStrictHexString } from '@metamask/utils';\n\nimport { EMPTY_BYTES } from '../constants.js';\nimport type {\n PrepareUserOperationResponse,\n SignUserOperationResponse,\n UpdateUserOperationResponse,\n} from '../types.js';\nimport type {\n AddUserOperationOptions,\n AddUserOperationRequest,\n} from '../UserOperationController.js';\n\n/**\n * Validate a request to add a user operation.\n *\n * @param request - The request to validate.\n */\nexport function validateAddUserOperationRequest(\n request: AddUserOperationRequest,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidRequest = object({\n data: optional(HexOrEmptyBytes),\n from: Hex,\n maxFeePerGas: optional(Hex),\n maxPriorityFeePerGas: optional(Hex),\n to: optional(Hex),\n value: optional(Hex),\n });\n\n validate(request, ValidRequest, 'Invalid request to add user operation');\n}\n\n/**\n * Validate the options when adding a user operation.\n *\n * @param options - The options to validate.\n */\nexport function validateAddUserOperationOptions(\n options: AddUserOperationOptions,\n) {\n const ValidOptions = object({\n networkClientId: string(),\n origin: string(),\n requireApproval: optional(boolean()),\n smartContractAccount: optional(\n object({\n prepareUserOperation: func(),\n updateUserOperation: func(),\n signUserOperation: func(),\n }),\n ),\n swaps: optional(\n object({\n approvalTxId: optional(string()),\n destinationTokenAddress: optional(string()),\n destinationTokenDecimals: optional(number()),\n destinationTokenSymbol: optional(string()),\n estimatedBaseFee: optional(string()),\n sourceTokenSymbol: optional(string()),\n swapMetaData: optional(object()),\n swapTokenValue: optional(string()),\n destinationTokenAmount: optional(string()),\n sourceTokenAddress: optional(string()),\n sourceTokenAmount: optional(string()),\n sourceTokenDecimals: optional(number()),\n swapAndSendRecipient: optional(string()),\n }),\n ),\n type: optional(enums(Object.values(TransactionType))),\n });\n\n validate(options, ValidOptions, 'Invalid options to add user operation');\n}\n\n/**\n * Validate the response from a smart contract account when preparing the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validatePrepareUserOperationResponse(\n response: PrepareUserOperationResponse,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidResponse = refine(\n object({\n bundler: string(),\n callData: Hex,\n dummyPaymasterAndData: optional(HexOrEmptyBytes),\n dummySignature: optional(HexOrEmptyBytes),\n gas: optional(\n object({\n callGasLimit: Hex,\n preVerificationGas: Hex,\n verificationGasLimit: Hex,\n }),\n ),\n initCode: optional(HexOrEmptyBytes),\n nonce: Hex,\n sender: Hex,\n }),\n 'ValidPrepareUserOperationResponse',\n ({ gas, dummySignature }) => {\n if (!gas && (!dummySignature || dummySignature === EMPTY_BYTES)) {\n return 'Must specify dummySignature if not specifying gas';\n }\n\n /* istanbul ignore next */\n return true;\n },\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when preparing user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when updating the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validateUpdateUserOperationResponse(\n response: UpdateUserOperationResponse,\n) {\n const ValidResponse = optional(\n object({\n paymasterAndData: optional(defineHexOrEmptyBytes()),\n callGasLimit: optional(defineHexOrEmptyBytes()),\n preVerificationGas: optional(defineHexOrEmptyBytes()),\n verificationGasLimit: optional(defineHexOrEmptyBytes()),\n }),\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when updating user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when signing the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validateSignUserOperationResponse(\n response: SignUserOperationResponse,\n) {\n const Hex = defineHex();\n\n const ValidResponse = object({\n signature: Hex,\n });\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when signing user operation',\n );\n}\n\n/**\n * Validate data against a struct.\n *\n * @param data - The data to validate.\n * @param struct - The struct to validate against.\n * @param message - The message to throw if validation fails.\n */\nfunction validate<T>(data: unknown, struct: Struct<T>, message: string) {\n try {\n assert(data, struct, message);\n } catch (error) {\n const causes = (error as StructError)\n .failures()\n .map((failure) => {\n if (!failure.path.length) {\n return failure.message;\n }\n\n return `${failure.path.join('.')} - ${failure.message}`;\n })\n .join('\\n');\n\n const finalMessage = `${message}\\n${causes}`;\n\n throw new Error(finalMessage);\n }\n}\n\n/**\n * Define the Hex type used by superstruct.\n *\n * @returns The Hex superstruct type.\n */\nfunction defineHex() {\n return define<string>('Hexadecimal String', (value) =>\n isStrictHexString(value),\n );\n}\n\n/**\n * Define the HexOrEmptyBytes type used by superstruct.\n *\n * @returns The HexOrEmptyBytes superstruct type.\n */\nfunction defineHexOrEmptyBytes() {\n return define<string>(\n 'Hexadecimal String or 0x',\n (value) => isStrictHexString(value) || value === EMPTY_BYTES,\n );\n}\n"]}