@pimlico/alto 0.0.3 → 0.0.5

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 (247) hide show
  1. package/esm/cli/alto.js +0 -4
  2. package/esm/cli/alto.js.map +1 -1
  3. package/esm/cli/config/bundler.d.ts +2302 -22
  4. package/esm/cli/config/bundler.js +32 -4
  5. package/esm/cli/config/bundler.js.map +1 -1
  6. package/esm/cli/config/options.js +59 -4
  7. package/esm/cli/config/options.js.map +1 -1
  8. package/esm/cli/customTransport.js +5 -1
  9. package/esm/cli/customTransport.js.map +1 -1
  10. package/esm/cli/handler.js +39 -4
  11. package/esm/cli/handler.js.map +1 -1
  12. package/esm/cli/instrumentation.js +2 -2
  13. package/esm/cli/instrumentation.js.map +1 -1
  14. package/esm/cli/setupServer.d.ts +2 -1
  15. package/esm/cli/setupServer.js +51 -27
  16. package/esm/cli/setupServer.js.map +1 -1
  17. package/esm/executor/executor.d.ts +7 -14
  18. package/esm/executor/executor.js +139 -128
  19. package/esm/executor/executor.js.map +1 -1
  20. package/esm/executor/executorManager.d.ts +58 -4
  21. package/esm/executor/executorManager.js +206 -52
  22. package/esm/executor/executorManager.js.map +1 -1
  23. package/esm/executor/senderManager.d.ts +2 -1
  24. package/esm/executor/senderManager.js +3 -0
  25. package/esm/executor/senderManager.js.map +1 -1
  26. package/esm/executor/utilityWalletMonitor.d.ts +15 -0
  27. package/esm/executor/utilityWalletMonitor.js +38 -0
  28. package/esm/executor/utilityWalletMonitor.js.map +1 -0
  29. package/esm/executor/utils.d.ts +1 -2
  30. package/esm/executor/utils.js +49 -38
  31. package/esm/executor/utils.js.map +1 -1
  32. package/esm/handlers/compressionHandler.js.map +1 -0
  33. package/esm/handlers/eventManager.d.ts +21 -0
  34. package/esm/handlers/eventManager.js +166 -0
  35. package/esm/handlers/eventManager.js.map +1 -0
  36. package/{lib/utils → esm/handlers}/gasPriceManager.d.ts +19 -5
  37. package/esm/{utils → handlers}/gasPriceManager.js +58 -13
  38. package/esm/handlers/gasPriceManager.js.map +1 -0
  39. package/esm/handlers/index.d.ts +4 -0
  40. package/esm/handlers/index.js +4 -0
  41. package/esm/handlers/index.js.map +1 -0
  42. package/esm/mempool/index.d.ts +0 -1
  43. package/esm/mempool/index.js +0 -1
  44. package/esm/mempool/index.js.map +1 -1
  45. package/esm/mempool/mempool.d.ts +4 -2
  46. package/esm/mempool/mempool.js +70 -26
  47. package/esm/mempool/mempool.js.map +1 -1
  48. package/esm/mempool/reputationManager.js +7 -3
  49. package/esm/mempool/reputationManager.js.map +1 -1
  50. package/esm/rpc/EntryPointSimulationsV07.d.ts +7 -3
  51. package/esm/rpc/EntryPointSimulationsV07.js +12 -9
  52. package/esm/rpc/EntryPointSimulationsV07.js.map +1 -1
  53. package/esm/rpc/gasEstimation.d.ts +3 -3
  54. package/esm/rpc/gasEstimation.js +23 -14
  55. package/esm/rpc/gasEstimation.js.map +1 -1
  56. package/esm/rpc/nonceQueuer.d.ts +4 -1
  57. package/esm/rpc/nonceQueuer.js +9 -3
  58. package/esm/rpc/nonceQueuer.js.map +1 -1
  59. package/esm/rpc/rpcHandler.d.ts +53 -3
  60. package/esm/rpc/rpcHandler.js +150 -238
  61. package/esm/rpc/rpcHandler.js.map +1 -1
  62. package/esm/rpc/server.d.ts +2 -1
  63. package/esm/rpc/server.js +10 -1
  64. package/esm/rpc/server.js.map +1 -1
  65. package/esm/rpc/validation/SafeValidator.d.ts +5 -8
  66. package/esm/rpc/validation/SafeValidator.js +51 -208
  67. package/esm/rpc/validation/SafeValidator.js.map +1 -1
  68. package/esm/rpc/validation/TracerResultParserV07.js +6 -2
  69. package/esm/rpc/validation/TracerResultParserV07.js.map +1 -1
  70. package/esm/rpc/validation/UnsafeValidator.d.ts +7 -3
  71. package/esm/rpc/validation/UnsafeValidator.js +52 -48
  72. package/esm/rpc/validation/UnsafeValidator.js.map +1 -1
  73. package/esm/rpc/validation/tracer.js +1 -0
  74. package/esm/rpc/validation/tracer.js.map +1 -1
  75. package/esm/types/contracts/EntryPointSimulations.d.ts +0 -1
  76. package/esm/types/contracts/EntryPointSimulations.js +1941 -2
  77. package/esm/types/contracts/EntryPointSimulations.js.map +1 -1
  78. package/esm/types/contracts/PimlicoEntryPointSimulations.d.ts +1 -1
  79. package/esm/types/contracts/PimlicoEntryPointSimulations.js +1 -1
  80. package/esm/types/contracts/PimlicoEntryPointSimulations.js.map +1 -1
  81. package/esm/types/schemas.d.ts +1029 -333
  82. package/esm/types/schemas.js +94 -20
  83. package/esm/types/schemas.js.map +1 -1
  84. package/esm/types/utils.d.ts +1 -1
  85. package/esm/types/validation.js +7 -2
  86. package/esm/types/validation.js.map +1 -1
  87. package/esm/utils/bigInt.d.ts +1 -0
  88. package/esm/utils/bigInt.js +4 -0
  89. package/esm/utils/bigInt.js.map +1 -1
  90. package/esm/utils/helpers.d.ts +1 -0
  91. package/esm/utils/helpers.js +6 -0
  92. package/esm/utils/helpers.js.map +1 -1
  93. package/esm/utils/index.d.ts +0 -3
  94. package/esm/utils/index.js +0 -3
  95. package/esm/utils/index.js.map +1 -1
  96. package/esm/utils/metrics.d.ts +4 -0
  97. package/esm/utils/metrics.js +29 -1
  98. package/esm/utils/metrics.js.map +1 -1
  99. package/esm/utils/rpc-reply.d.ts +1 -1
  100. package/esm/utils/rpc-reply.js +2 -1
  101. package/esm/utils/rpc-reply.js.map +1 -1
  102. package/esm/utils/userop.d.ts +66 -6
  103. package/esm/utils/userop.js +182 -95
  104. package/esm/utils/userop.js.map +1 -1
  105. package/esm/utils/validation.d.ts +1 -1
  106. package/esm/utils/validation.js +9 -13
  107. package/esm/utils/validation.js.map +1 -1
  108. package/lib/cli/alto.js +0 -4
  109. package/lib/cli/alto.js.map +1 -1
  110. package/lib/cli/config/bundler.d.ts +2302 -22
  111. package/lib/cli/config/bundler.js +31 -3
  112. package/lib/cli/config/bundler.js.map +1 -1
  113. package/lib/cli/config/options.js +59 -4
  114. package/lib/cli/config/options.js.map +1 -1
  115. package/lib/cli/customTransport.js +5 -1
  116. package/lib/cli/customTransport.js.map +1 -1
  117. package/lib/cli/handler.js +38 -3
  118. package/lib/cli/handler.js.map +1 -1
  119. package/lib/cli/instrumentation.js +2 -2
  120. package/lib/cli/instrumentation.js.map +1 -1
  121. package/lib/cli/setupServer.d.ts +2 -1
  122. package/lib/cli/setupServer.js +52 -28
  123. package/lib/cli/setupServer.js.map +1 -1
  124. package/lib/executor/executor.d.ts +7 -14
  125. package/lib/executor/executor.js +138 -128
  126. package/lib/executor/executor.js.map +1 -1
  127. package/lib/executor/executorManager.d.ts +58 -4
  128. package/lib/executor/executorManager.js +204 -50
  129. package/lib/executor/executorManager.js.map +1 -1
  130. package/lib/executor/senderManager.d.ts +2 -1
  131. package/lib/executor/senderManager.js +3 -0
  132. package/lib/executor/senderManager.js.map +1 -1
  133. package/lib/executor/utilityWalletMonitor.d.ts +15 -0
  134. package/lib/executor/utilityWalletMonitor.js +42 -0
  135. package/lib/executor/utilityWalletMonitor.js.map +1 -0
  136. package/lib/executor/utils.d.ts +1 -2
  137. package/lib/executor/utils.js +48 -37
  138. package/lib/executor/utils.js.map +1 -1
  139. package/lib/handlers/compressionHandler.js.map +1 -0
  140. package/lib/handlers/eventManager.d.ts +21 -0
  141. package/lib/handlers/eventManager.js +196 -0
  142. package/lib/handlers/eventManager.js.map +1 -0
  143. package/{esm/utils → lib/handlers}/gasPriceManager.d.ts +19 -5
  144. package/lib/{utils → handlers}/gasPriceManager.js +58 -13
  145. package/lib/handlers/gasPriceManager.js.map +1 -0
  146. package/lib/handlers/index.d.ts +4 -0
  147. package/lib/handlers/index.js +20 -0
  148. package/lib/handlers/index.js.map +1 -0
  149. package/lib/mempool/index.d.ts +0 -1
  150. package/lib/mempool/index.js +0 -1
  151. package/lib/mempool/index.js.map +1 -1
  152. package/lib/mempool/mempool.d.ts +4 -2
  153. package/lib/mempool/mempool.js +70 -26
  154. package/lib/mempool/mempool.js.map +1 -1
  155. package/lib/mempool/reputationManager.js +7 -3
  156. package/lib/mempool/reputationManager.js.map +1 -1
  157. package/lib/rpc/EntryPointSimulationsV07.d.ts +7 -3
  158. package/lib/rpc/EntryPointSimulationsV07.js +13 -9
  159. package/lib/rpc/EntryPointSimulationsV07.js.map +1 -1
  160. package/lib/rpc/gasEstimation.d.ts +3 -3
  161. package/lib/rpc/gasEstimation.js +23 -14
  162. package/lib/rpc/gasEstimation.js.map +1 -1
  163. package/lib/rpc/nonceQueuer.d.ts +4 -1
  164. package/lib/rpc/nonceQueuer.js +9 -3
  165. package/lib/rpc/nonceQueuer.js.map +1 -1
  166. package/lib/rpc/rpcHandler.d.ts +53 -3
  167. package/lib/rpc/rpcHandler.js +147 -258
  168. package/lib/rpc/rpcHandler.js.map +1 -1
  169. package/lib/rpc/server.d.ts +2 -1
  170. package/lib/rpc/server.js +10 -1
  171. package/lib/rpc/server.js.map +1 -1
  172. package/lib/rpc/validation/SafeValidator.d.ts +5 -8
  173. package/lib/rpc/validation/SafeValidator.js +50 -207
  174. package/lib/rpc/validation/SafeValidator.js.map +1 -1
  175. package/lib/rpc/validation/TracerResultParserV07.js +6 -2
  176. package/lib/rpc/validation/TracerResultParserV07.js.map +1 -1
  177. package/lib/rpc/validation/UnsafeValidator.d.ts +7 -3
  178. package/lib/rpc/validation/UnsafeValidator.js +52 -48
  179. package/lib/rpc/validation/UnsafeValidator.js.map +1 -1
  180. package/lib/rpc/validation/tracer.js +1 -0
  181. package/lib/rpc/validation/tracer.js.map +1 -1
  182. package/lib/types/contracts/EntryPointSimulations.d.ts +0 -1
  183. package/lib/types/contracts/EntryPointSimulations.js +1942 -3
  184. package/lib/types/contracts/EntryPointSimulations.js.map +1 -1
  185. package/lib/types/contracts/PimlicoEntryPointSimulations.d.ts +1 -1
  186. package/lib/types/contracts/PimlicoEntryPointSimulations.js +2 -2
  187. package/lib/types/contracts/PimlicoEntryPointSimulations.js.map +1 -1
  188. package/lib/types/schemas.d.ts +1029 -333
  189. package/lib/types/schemas.js +93 -19
  190. package/lib/types/schemas.js.map +1 -1
  191. package/lib/types/utils.d.ts +1 -1
  192. package/lib/types/validation.js +7 -2
  193. package/lib/types/validation.js.map +1 -1
  194. package/lib/utils/bigInt.d.ts +1 -0
  195. package/lib/utils/bigInt.js +6 -1
  196. package/lib/utils/bigInt.js.map +1 -1
  197. package/lib/utils/helpers.d.ts +1 -0
  198. package/lib/utils/helpers.js +8 -1
  199. package/lib/utils/helpers.js.map +1 -1
  200. package/lib/utils/index.d.ts +0 -3
  201. package/lib/utils/index.js +0 -3
  202. package/lib/utils/index.js.map +1 -1
  203. package/lib/utils/metrics.d.ts +4 -0
  204. package/lib/utils/metrics.js +29 -1
  205. package/lib/utils/metrics.js.map +1 -1
  206. package/lib/utils/rpc-reply.d.ts +1 -1
  207. package/lib/utils/rpc-reply.js +2 -1
  208. package/lib/utils/rpc-reply.js.map +1 -1
  209. package/lib/utils/userop.d.ts +66 -6
  210. package/lib/utils/userop.js +184 -95
  211. package/lib/utils/userop.js.map +1 -1
  212. package/lib/utils/validation.d.ts +1 -1
  213. package/lib/utils/validation.js +9 -36
  214. package/lib/utils/validation.js.map +1 -1
  215. package/package.json +16 -14
  216. package/esm/executor/test/utils.d.ts +0 -13
  217. package/esm/executor/test/utils.js +0 -75
  218. package/esm/executor/test/utils.js.map +0 -1
  219. package/esm/mempool/nullMempool.d.ts +0 -15
  220. package/esm/mempool/nullMempool.js +0 -36
  221. package/esm/mempool/nullMempool.js.map +0 -1
  222. package/esm/types/test/validationTestErrors.d.ts +0 -3
  223. package/esm/types/test/validationTestErrors.js +0 -229
  224. package/esm/types/test/validationTestErrors.js.map +0 -1
  225. package/esm/utils/compressionHandler.js.map +0 -1
  226. package/esm/utils/gasPriceManager.js.map +0 -1
  227. package/esm/utils/test.d.ts +0 -17
  228. package/esm/utils/test.js +0 -130
  229. package/esm/utils/test.js.map +0 -1
  230. package/lib/executor/test/utils.d.ts +0 -13
  231. package/lib/executor/test/utils.js +0 -81
  232. package/lib/executor/test/utils.js.map +0 -1
  233. package/lib/mempool/nullMempool.d.ts +0 -15
  234. package/lib/mempool/nullMempool.js +0 -40
  235. package/lib/mempool/nullMempool.js.map +0 -1
  236. package/lib/types/test/validationTestErrors.d.ts +0 -3
  237. package/lib/types/test/validationTestErrors.js +0 -232
  238. package/lib/types/test/validationTestErrors.js.map +0 -1
  239. package/lib/utils/compressionHandler.js.map +0 -1
  240. package/lib/utils/gasPriceManager.js.map +0 -1
  241. package/lib/utils/test.d.ts +0 -17
  242. package/lib/utils/test.js +0 -161
  243. package/lib/utils/test.js.map +0 -1
  244. /package/esm/{utils → handlers}/compressionHandler.d.ts +0 -0
  245. /package/esm/{utils → handlers}/compressionHandler.js +0 -0
  246. /package/lib/{utils → handlers}/compressionHandler.d.ts +0 -0
  247. /package/lib/{utils → handlers}/compressionHandler.js +0 -0
@@ -1,35 +1,10 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.RpcHandler = void 0;
27
4
  const types_1 = require("../types/index.js");
28
5
  const utils_1 = require("../utils/index.js");
29
6
  const viem_1 = require("viem");
30
- const chains = __importStar(require("viem/chains"));
31
- const zod_1 = require("zod");
32
- const zod_validation_error_1 = require("zod-validation-error");
7
+ const chains_1 = require("viem/chains");
33
8
  class RpcHandler {
34
9
  entryPoints;
35
10
  publicClient;
@@ -53,7 +28,9 @@ class RpcHandler {
53
28
  gasPriceManager;
54
29
  gasPriceMultipliers;
55
30
  paymasterGasLimitMultiplier;
56
- constructor(entryPoints, publicClient, validator, mempool, executor, monitor, nonceQueuer, executorManager, reputationManager, usingTenderly, rpcMaxBlockRange, logger, metrics, enableDebugEndpoints, compressionHandler, legacyTransactions, gasPriceManager, gasPriceMultipliers, chainType, paymasterGasLimitMultiplier, dangerousSkipUserOperationValidation = false) {
31
+ eventManager;
32
+ enableInstantBundlingEndpoint;
33
+ constructor(entryPoints, publicClient, validator, mempool, executor, monitor, nonceQueuer, executorManager, reputationManager, usingTenderly, rpcMaxBlockRange, logger, metrics, enableDebugEndpoints, compressionHandler, legacyTransactions, gasPriceManager, gasPriceMultipliers, chainType, paymasterGasLimitMultiplier, eventManager, enableInstantBundlingEndpoint, dangerousSkipUserOperationValidation = false) {
57
34
  this.entryPoints = entryPoints;
58
35
  this.publicClient = publicClient;
59
36
  this.validator = validator;
@@ -77,6 +54,8 @@ class RpcHandler {
77
54
  this.chainType = chainType;
78
55
  this.gasPriceManager = gasPriceManager;
79
56
  this.paymasterGasLimitMultiplier = paymasterGasLimitMultiplier;
57
+ this.enableInstantBundlingEndpoint = enableInstantBundlingEndpoint;
58
+ this.eventManager = eventManager;
80
59
  }
81
60
  async handleMethod(request, apiVersion) {
82
61
  // call the method with the params
@@ -167,6 +146,47 @@ class RpcHandler {
167
146
  method,
168
147
  result: await this.pimlico_sendCompressedUserOperation(apiVersion, ...request.params)
169
148
  };
149
+ case "pimlico_sendUserOperationNow":
150
+ return {
151
+ method,
152
+ result: await this.pimlico_sendUserOperationNow(apiVersion, ...request.params)
153
+ };
154
+ }
155
+ }
156
+ ensureEntryPointIsSupported(entryPoint) {
157
+ if (!this.entryPoints.includes(entryPoint)) {
158
+ throw new Error(`EntryPoint ${entryPoint} not supported, supported EntryPoints: ${this.entryPoints.join(", ")}`);
159
+ }
160
+ }
161
+ ensureDebugEndpointsAreEnabled(methodName) {
162
+ if (!this.enableDebugEndpoints) {
163
+ throw new types_1.RpcError(`${methodName} is only available in development environment`);
164
+ }
165
+ }
166
+ async preMempoolChecks(opHash, userOperation, apiVersion, entryPoint) {
167
+ if (this.legacyTransactions &&
168
+ userOperation.maxFeePerGas !== userOperation.maxPriorityFeePerGas) {
169
+ const reason = "maxPriorityFeePerGas must equal maxFeePerGas on chains that don't support EIP-1559";
170
+ this.eventManager.emitFailedValidation(opHash, reason);
171
+ throw new types_1.RpcError(reason);
172
+ }
173
+ if (apiVersion !== "v1") {
174
+ await this.gasPriceManager.validateGasPrice({
175
+ maxFeePerGas: userOperation.maxFeePerGas,
176
+ maxPriorityFeePerGas: userOperation.maxPriorityFeePerGas
177
+ });
178
+ }
179
+ if (userOperation.verificationGasLimit < 10000n) {
180
+ const reason = "verificationGasLimit must be at least 10000";
181
+ this.eventManager.emitFailedValidation(opHash, reason);
182
+ throw new types_1.RpcError(reason);
183
+ }
184
+ this.logger.trace({ userOperation, entryPoint }, "beginning validation");
185
+ if (userOperation.preVerificationGas === 0n ||
186
+ userOperation.verificationGasLimit === 0n) {
187
+ const reason = "user operation gas limits must be larger than 0";
188
+ this.eventManager.emitFailedValidation(opHash, reason);
189
+ throw new types_1.RpcError(reason);
170
190
  }
171
191
  }
172
192
  eth_chainId() {
@@ -176,10 +196,7 @@ class RpcHandler {
176
196
  return this.entryPoints;
177
197
  }
178
198
  async eth_estimateUserOperationGas(apiVersion, userOperation, entryPoint, stateOverrides) {
179
- // check if entryPoint is supported, if not throw
180
- if (!this.entryPoints.includes(entryPoint)) {
181
- throw new Error(`EntryPoint ${entryPoint} not supported, supported EntryPoints: ${this.entryPoints.join(", ")}`);
182
- }
199
+ this.ensureEntryPointIsSupported(entryPoint);
183
200
  if (userOperation.maxFeePerGas === 0n) {
184
201
  throw new types_1.RpcError("user operation max fee per gas must be larger than 0 during gas estimation");
185
202
  }
@@ -189,14 +206,9 @@ class RpcHandler {
189
206
  userOperation.preVerificationGas = 1000000n;
190
207
  userOperation.verificationGasLimit = 10000000n;
191
208
  userOperation.callGasLimit = 10000000n;
192
- if (this.chainId === chains.base.id) {
209
+ if (this.chainId === chains_1.base.id) {
193
210
  userOperation.verificationGasLimit = 5000000n;
194
211
  }
195
- if (this.chainId === chains.celoAlfajores.id ||
196
- this.chainId === chains.celo.id) {
197
- userOperation.verificationGasLimit = 1000000n;
198
- userOperation.callGasLimit = 1000000n;
199
- }
200
212
  if ((0, utils_1.isVersion07)(userOperation)) {
201
213
  userOperation.paymasterPostOpGasLimit = 2000000n;
202
214
  userOperation.paymasterVerificationGasLimit = 5000000n;
@@ -247,12 +259,10 @@ class RpcHandler {
247
259
  paymasterPostOpGasLimit =
248
260
  (paymasterPostOpGasLimit * multiplier) / 100n;
249
261
  }
250
- if (this.chainId === chains.base.id ||
251
- this.chainId === chains.baseSepolia.id) {
262
+ if (this.chainId === chains_1.base.id || this.chainId === chains_1.baseSepolia.id) {
252
263
  callGasLimit += 10000n;
253
264
  }
254
- if (this.chainId === chains.base.id ||
255
- this.chainId === chains.optimism.id) {
265
+ if (this.chainId === chains_1.base.id || this.chainId === chains_1.optimism.id) {
256
266
  callGasLimit = (0, utils_1.maxBigInt)(callGasLimit, 120000n);
257
267
  }
258
268
  if (userOperation.callData === "0x") {
@@ -282,10 +292,11 @@ class RpcHandler {
282
292
  };
283
293
  }
284
294
  async eth_sendUserOperation(apiVersion, userOperation, entryPoint) {
295
+ const hash = (0, utils_1.getUserOperationHash)(userOperation, entryPoint, this.chainId);
296
+ this.eventManager.emitReceived(hash);
285
297
  let status = "rejected";
286
298
  try {
287
299
  status = await this.addToMempoolIfValid(userOperation, entryPoint, apiVersion);
288
- const hash = (0, utils_1.getUserOperationHash)(userOperation, entryPoint, this.chainId);
289
300
  return hash;
290
301
  }
291
302
  catch (error) {
@@ -349,27 +360,38 @@ class RpcHandler {
349
360
  if (!tx.to) {
350
361
  return null;
351
362
  }
352
- let op = undefined;
363
+ let op;
353
364
  try {
354
365
  const decoded = (0, viem_1.decodeFunctionData)({
355
- abi: types_1.EntryPointV06Abi,
366
+ abi: [...types_1.EntryPointV06Abi, ...types_1.EntryPointV07Abi],
356
367
  data: tx.input
357
368
  });
358
369
  if (decoded.functionName !== "handleOps") {
359
370
  return null;
360
371
  }
361
372
  const ops = decoded.args[0];
362
- op = ops.find((op) => op.sender === userOperationEvent.args.sender &&
373
+ const foundOp = ops.find((op) => op.sender === userOperationEvent.args.sender &&
363
374
  op.nonce === userOperationEvent.args.nonce);
375
+ if (foundOp === undefined) {
376
+ return null;
377
+ }
378
+ const handleOpsV07AbiItem = (0, viem_1.getAbiItem)({
379
+ abi: types_1.EntryPointV07Abi,
380
+ name: "handleOps"
381
+ });
382
+ const handleOpsV07Selector = (0, viem_1.toFunctionSelector)(handleOpsV07AbiItem);
383
+ if ((0, viem_1.slice)(tx.input, 0, 4) === handleOpsV07Selector) {
384
+ op = (0, utils_1.toUnpackedUserOperation)(foundOp);
385
+ }
386
+ else {
387
+ op = foundOp;
388
+ }
364
389
  }
365
390
  catch {
366
391
  return null;
367
392
  }
368
- if (op === undefined) {
369
- return null;
370
- }
371
393
  const result = {
372
- userOperation: (0, utils_1.isVersion06)(op) ? op : (0, utils_1.toUnpackedUserOperation)(op),
394
+ userOperation: op,
373
395
  entryPoint: (0, viem_1.getAddress)(tx.to),
374
396
  transactionHash: txHash,
375
397
  blockHash: tx.blockHash ?? "0x",
@@ -377,211 +399,53 @@ class RpcHandler {
377
399
  };
378
400
  return result;
379
401
  }
380
- async eth_getUserOperationReceipt(userOperationHash) {
381
- const userOperationEventAbiItem = (0, viem_1.getAbiItem)({
382
- abi: types_1.EntryPointV06Abi,
383
- name: "UserOperationEvent"
384
- });
385
- let fromBlock = undefined;
386
- let toBlock = undefined;
387
- if (this.rpcMaxBlockRange !== undefined) {
388
- const latestBlock = await this.publicClient.getBlockNumber();
389
- fromBlock = latestBlock - BigInt(this.rpcMaxBlockRange);
390
- if (fromBlock < 0n) {
391
- fromBlock = 0n;
392
- }
393
- toBlock = "latest";
394
- }
395
- const filterResult = await this.publicClient.getLogs({
396
- address: this.entryPoints,
397
- event: userOperationEventAbiItem,
398
- fromBlock,
399
- toBlock,
400
- args: {
401
- userOpHash: userOperationHash
402
- }
403
- });
404
- if (filterResult.length === 0) {
405
- return null;
406
- }
407
- const userOperationEvent = filterResult[0];
408
- // throw if any of the members of userOperationEvent are undefined
409
- if (userOperationEvent.args.actualGasCost === undefined ||
410
- userOperationEvent.args.sender === undefined ||
411
- userOperationEvent.args.nonce === undefined ||
412
- userOperationEvent.args.userOpHash === undefined ||
413
- userOperationEvent.args.success === undefined ||
414
- userOperationEvent.args.paymaster === undefined ||
415
- userOperationEvent.args.actualGasUsed === undefined) {
416
- throw new Error("userOperationEvent has undefined members");
417
- }
418
- const txHash = userOperationEvent.transactionHash;
419
- if (txHash === null) {
420
- // transaction pending
421
- return null;
422
- }
423
- const getTransactionReceipt = async (txHash) => {
424
- while (true) {
425
- try {
426
- return await this.publicClient.getTransactionReceipt({
427
- hash: txHash
428
- });
429
- }
430
- catch (e) {
431
- if (e instanceof viem_1.TransactionReceiptNotFoundError) {
432
- continue;
433
- }
434
- throw e;
435
- }
436
- }
437
- };
438
- const receipt = await getTransactionReceipt(txHash);
439
- const logs = receipt.logs;
440
- if (logs.some((log) => log.blockHash === null ||
441
- log.blockNumber === null ||
442
- log.transactionIndex === null ||
443
- log.transactionHash === null ||
444
- log.logIndex === null ||
445
- log.topics.length === 0)) {
446
- // transaction pending
447
- return null;
448
- }
449
- const userOperationRevertReasonAbi = (0, viem_1.parseAbi)([
450
- "event UserOperationRevertReason(bytes32 indexed userOpHash, address indexed sender, uint256 nonce, bytes revertReason)"
451
- ]);
452
- const userOperationRevertReasonTopicEvent = (0, viem_1.encodeEventTopics)({
453
- abi: userOperationRevertReasonAbi
454
- })[0];
455
- let entryPoint = viem_1.zeroAddress;
456
- let revertReason = undefined;
457
- let startIndex = -1;
458
- let endIndex = -1;
459
- logs.forEach((log, index) => {
460
- if (log?.topics[0] === userOperationEvent.topics[0]) {
461
- // process UserOperationEvent
462
- if (log.topics[1] === userOperationEvent.topics[1]) {
463
- // it's our userOpHash. save as end of logs array
464
- endIndex = index;
465
- entryPoint = log.address;
466
- }
467
- else if (endIndex === -1) {
468
- // it's a different hash. remember it as beginning index, but only if we didn't find our end index yet.
469
- startIndex = index;
470
- }
471
- }
472
- if (log?.topics[0] === userOperationRevertReasonTopicEvent) {
473
- // process UserOperationRevertReason
474
- if (log.topics[1] === userOperationEvent.topics[1]) {
475
- // it's our userOpHash. capture revert reason.
476
- const decodedLog = (0, viem_1.decodeEventLog)({
477
- abi: userOperationRevertReasonAbi,
478
- data: log.data,
479
- topics: log.topics
480
- });
481
- revertReason = decodedLog.args.revertReason;
482
- }
483
- }
484
- });
485
- if (endIndex === -1) {
486
- throw new Error("fatal: no UserOperationEvent in logs");
487
- }
488
- const filteredLogs = logs.slice(startIndex + 1, endIndex);
489
- const logsParsing = zod_1.z.array(types_1.logSchema).safeParse(filteredLogs);
490
- if (!logsParsing.success) {
491
- const err = (0, zod_validation_error_1.fromZodError)(logsParsing.error);
492
- throw err;
493
- }
494
- const receiptParsing = types_1.receiptSchema.safeParse({
495
- ...receipt,
496
- status: receipt.status === "success" ? 1 : 0
497
- });
498
- if (!receiptParsing.success) {
499
- const err = (0, zod_validation_error_1.fromZodError)(receiptParsing.error);
500
- throw err;
501
- }
502
- let paymaster = userOperationEvent.args.paymaster;
503
- paymaster = paymaster === viem_1.zeroAddress ? undefined : paymaster;
504
- const userOperationReceipt = {
505
- userOpHash: userOperationHash,
506
- entryPoint,
507
- sender: userOperationEvent.args.sender,
508
- nonce: userOperationEvent.args.nonce,
509
- paymaster,
510
- actualGasUsed: userOperationEvent.args.actualGasUsed,
511
- actualGasCost: userOperationEvent.args.actualGasCost,
512
- success: userOperationEvent.args.success,
513
- reason: revertReason,
514
- logs: logsParsing.data,
515
- receipt: receiptParsing.data
516
- };
517
- return userOperationReceipt;
402
+ eth_getUserOperationReceipt(userOperationHash) {
403
+ return this.executorManager.getUserOperationReceipt(userOperationHash);
518
404
  }
519
405
  debug_bundler_clearState() {
520
- if (!this.enableDebugEndpoints) {
521
- throw new types_1.RpcError("debug_bundler_clearState is only available in development environment");
522
- }
406
+ this.ensureDebugEndpointsAreEnabled("debug_bundler_clearState");
523
407
  this.mempool.clear();
524
408
  this.reputationManager.clear();
525
409
  return "ok";
526
410
  }
527
411
  debug_bundler_clearMempool() {
528
- if (!this.enableDebugEndpoints) {
529
- throw new types_1.RpcError("debug_bundler_clearMempool is only available in development environment");
530
- }
412
+ this.ensureDebugEndpointsAreEnabled("debug_bundler_clearMempool");
531
413
  this.mempool.clear();
532
414
  this.reputationManager.clearEntityCount();
533
415
  return "ok";
534
416
  }
535
417
  async debug_bundler_dumpMempool(entryPoint) {
536
- if (!this.enableDebugEndpoints) {
537
- throw new types_1.RpcError("debug_bundler_dumpMempool is only available in development environment");
538
- }
539
- if (!this.entryPoints.includes(entryPoint)) {
540
- throw new types_1.RpcError(`EntryPoint ${entryPoint} not supported, supported EntryPoints: ${this.entryPoints.join(", ")}`);
541
- }
418
+ this.ensureDebugEndpointsAreEnabled("debug_bundler_dumpMempool");
419
+ this.ensureEntryPointIsSupported(entryPoint);
542
420
  return this.mempool
543
421
  .dumpOutstanding()
544
422
  .map((userOpInfo) => (0, types_1.deriveUserOperation)(userOpInfo.mempoolUserOperation));
545
423
  }
546
424
  async debug_bundler_sendBundleNow() {
547
- if (!this.enableDebugEndpoints) {
548
- throw new types_1.RpcError("debug_bundler_sendBundleNow is only available in development environment");
549
- }
425
+ this.ensureDebugEndpointsAreEnabled("debug_bundler_sendBundleNow");
550
426
  const transactions = await this.executorManager.bundleNow();
551
427
  return transactions[0];
552
428
  }
553
429
  debug_bundler_setBundlingMode(bundlingMode) {
554
- if (!this.enableDebugEndpoints) {
555
- throw new types_1.RpcError("debug_bundler_setBundlingMode is only available in development environment");
556
- }
430
+ this.ensureDebugEndpointsAreEnabled("debug_bundler_setBundlingMode");
557
431
  this.executorManager.setBundlingMode(bundlingMode);
558
432
  return "ok";
559
433
  }
560
434
  debug_bundler_dumpReputation(entryPoint) {
561
- if (!this.enableDebugEndpoints) {
562
- throw new types_1.RpcError("debug_bundler_setRe is only available in development environment");
563
- }
564
- if (!this.entryPoints.includes(entryPoint)) {
565
- throw new types_1.RpcError(`EntryPoint ${entryPoint} not supported, supported EntryPoints: ${this.entryPoints.join(", ")}`);
566
- }
435
+ this.ensureDebugEndpointsAreEnabled("debug_bundler_setReputation");
436
+ this.ensureEntryPointIsSupported(entryPoint);
567
437
  return this.reputationManager.dumpReputations(entryPoint);
568
438
  }
569
439
  async debug_bundler_getStakeStatus(address, entryPoint) {
570
- if (!this.enableDebugEndpoints) {
571
- throw new types_1.RpcError("debug_bundler_getStakeStatus is only available in development environment");
572
- }
573
- if (!this.entryPoints.includes(entryPoint)) {
574
- throw new types_1.RpcError(`EntryPoint ${entryPoint} not supported, supported EntryPoints: ${this.entryPoints.join(", ")}`);
575
- }
440
+ this.ensureDebugEndpointsAreEnabled("debug_bundler_getStakeStatus");
441
+ this.ensureEntryPointIsSupported(entryPoint);
576
442
  return types_1.bundlerGetStakeStatusResponseSchema.parse({
577
443
  method: "debug_bundler_getStakeStatus",
578
444
  result: await this.reputationManager.getStakeStatus(entryPoint, address)
579
445
  }).result;
580
446
  }
581
447
  debug_bundler_setReputation(args) {
582
- if (!this.enableDebugEndpoints) {
583
- throw new types_1.RpcError("debug_bundler_setReputation is only available in development environment");
584
- }
448
+ this.ensureDebugEndpointsAreEnabled("debug_bundler_setReputation");
585
449
  this.reputationManager.setReputation(args[1], args[0]);
586
450
  return "ok";
587
451
  }
@@ -589,57 +453,44 @@ class RpcHandler {
589
453
  return this.monitor.getUserOperationStatus(userOperationHash);
590
454
  }
591
455
  async pimlico_getUserOperationGasPrice() {
592
- const gasPrice = await this.gasPriceManager.getGasPrice();
456
+ let { maxFeePerGas, maxPriorityFeePerGas } = await this.gasPriceManager.getGasPrice();
457
+ if (this.chainType === "hedera") {
458
+ maxFeePerGas /= 10n ** 9n;
459
+ maxPriorityFeePerGas /= 10n ** 9n;
460
+ }
593
461
  const { slow, standard, fast } = this.gasPriceMultipliers;
594
462
  return {
595
463
  slow: {
596
- maxFeePerGas: (gasPrice.maxFeePerGas * slow) / 100n,
597
- maxPriorityFeePerGas: (gasPrice.maxPriorityFeePerGas * slow) / 100n
464
+ maxFeePerGas: (maxFeePerGas * slow) / 100n,
465
+ maxPriorityFeePerGas: (maxPriorityFeePerGas * slow) / 100n
598
466
  },
599
467
  standard: {
600
- maxFeePerGas: (gasPrice.maxFeePerGas * standard) / 100n,
601
- maxPriorityFeePerGas: (gasPrice.maxPriorityFeePerGas * standard) / 100n
468
+ maxFeePerGas: (maxFeePerGas * standard) / 100n,
469
+ maxPriorityFeePerGas: (maxPriorityFeePerGas * standard) / 100n
602
470
  },
603
471
  fast: {
604
- maxFeePerGas: (gasPrice.maxFeePerGas * fast) / 100n,
605
- maxPriorityFeePerGas: (gasPrice.maxPriorityFeePerGas * fast) / 100n
472
+ maxFeePerGas: (maxFeePerGas * fast) / 100n,
473
+ maxPriorityFeePerGas: (maxPriorityFeePerGas * fast) / 100n
606
474
  }
607
475
  };
608
476
  }
609
477
  // check if we want to bundle userOperation. If yes, add to mempool
610
478
  async addToMempoolIfValid(op, entryPoint, apiVersion) {
479
+ this.ensureEntryPointIsSupported(entryPoint);
611
480
  const userOperation = (0, types_1.deriveUserOperation)(op);
612
- if (!this.entryPoints.includes(entryPoint)) {
613
- throw new types_1.RpcError(`EntryPoint ${entryPoint} not supported, supported EntryPoints: ${this.entryPoints.join(", ")}`);
614
- }
615
- if (this.chainId === chains.celoAlfajores.id ||
616
- this.chainId === chains.celo.id) {
617
- if (userOperation.maxFeePerGas !==
618
- userOperation.maxPriorityFeePerGas) {
619
- throw new types_1.RpcError("maxPriorityFeePerGas must equal maxFeePerGas on Celo chains");
620
- }
621
- }
622
- if (apiVersion !== "v1") {
623
- await this.gasPriceManager.validateGasPrice({
624
- maxFeePerGas: userOperation.maxFeePerGas,
625
- maxPriorityFeePerGas: userOperation.maxPriorityFeePerGas
626
- });
627
- }
628
- if (userOperation.verificationGasLimit < 10000n) {
629
- throw new types_1.RpcError("verificationGasLimit must be at least 10000");
630
- }
631
- this.logger.trace({ userOperation, entryPoint }, "beginning validation");
632
- if (userOperation.preVerificationGas === 0n ||
633
- userOperation.verificationGasLimit === 0n) {
634
- throw new types_1.RpcError("user operation gas limits must be larger than 0");
635
- }
481
+ const opHash = (0, utils_1.getUserOperationHash)(userOperation, entryPoint, this.chainId);
482
+ await this.preMempoolChecks(opHash, userOperation, apiVersion, entryPoint);
636
483
  const currentNonceValue = await this.getNonceValue(userOperation, entryPoint);
637
484
  const [, userOperationNonceValue] = (0, utils_1.getNonceKeyAndValue)(userOperation.nonce);
638
485
  if (userOperationNonceValue < currentNonceValue) {
639
- throw new types_1.RpcError("UserOperation reverted during simulation with reason: AA25 invalid account nonce", types_1.ValidationErrors.InvalidFields);
486
+ const reason = "UserOperation failed validation with reason: AA25 invalid account nonce";
487
+ this.eventManager.emitFailedValidation(opHash, reason, "AA25");
488
+ throw new types_1.RpcError(reason, types_1.ValidationErrors.InvalidFields);
640
489
  }
641
490
  if (userOperationNonceValue > currentNonceValue + 10n) {
642
- throw new types_1.RpcError("UserOperation reverted during simulation with reason: AA25 invalid account nonce", types_1.ValidationErrors.InvalidFields);
491
+ const reason = "UserOperation failed validaiton with reason: AA25 invalid account nonce";
492
+ this.eventManager.emitFailedValidation(opHash, reason, "AA25");
493
+ throw new types_1.RpcError(reason, types_1.ValidationErrors.InvalidFields);
643
494
  }
644
495
  let queuedUserOperations = [];
645
496
  if (userOperationNonceValue > currentNonceValue &&
@@ -649,9 +500,10 @@ class RpcHandler {
649
500
  if (userOperationNonceValue ===
650
501
  currentNonceValue + BigInt(queuedUserOperations.length)) {
651
502
  if (this.dangerousSkipUserOperationValidation) {
652
- const success = this.mempool.add(op, entryPoint);
503
+ const [success, errorReason] = this.mempool.add(op, entryPoint);
653
504
  if (!success) {
654
- throw new types_1.RpcError("UserOperation reverted during simulation with reason: AA25 invalid account nonce", types_1.ValidationErrors.InvalidFields);
505
+ this.eventManager.emitFailedValidation(opHash, errorReason, (0, utils_1.getAAError)(errorReason));
506
+ throw new types_1.RpcError(`UserOperation reverted during simulation with reason: ${errorReason}`, types_1.ValidationErrors.InvalidFields);
655
507
  }
656
508
  }
657
509
  else {
@@ -661,9 +513,10 @@ class RpcHandler {
661
513
  const validationResult = await this.validator.validateUserOperation(apiVersion !== "v1", userOperation, queuedUserOperations, entryPoint);
662
514
  await this.reputationManager.checkReputation(userOperation, entryPoint, validationResult);
663
515
  await this.mempool.checkEntityMultipleRoleViolation(userOperation);
664
- const success = this.mempool.add(op, entryPoint, validationResult.referencedContracts);
516
+ const [success, errorReason] = this.mempool.add(op, entryPoint, validationResult.referencedContracts);
665
517
  if (!success) {
666
- throw new types_1.RpcError("UserOperation reverted during simulation with reason: AA25 invalid account nonce", types_1.ValidationErrors.InvalidFields);
518
+ this.eventManager.emitFailedValidation(opHash, errorReason, (0, utils_1.getAAError)(errorReason));
519
+ throw new types_1.RpcError(`UserOperation reverted during simulation with reason: ${errorReason}`, types_1.ValidationErrors.InvalidFields);
667
520
  }
668
521
  return "added";
669
522
  }
@@ -671,10 +524,47 @@ class RpcHandler {
671
524
  this.nonceQueuer.add(op, entryPoint);
672
525
  return "queued";
673
526
  }
527
+ async pimlico_sendUserOperationNow(apiVersion, userOperation, entryPoint) {
528
+ if (!this.enableInstantBundlingEndpoint) {
529
+ throw new types_1.RpcError("pimlico_sendUserOperationNow endpoint is not enabled", types_1.ValidationErrors.InvalidFields);
530
+ }
531
+ this.ensureEntryPointIsSupported(entryPoint);
532
+ const opHash = (0, utils_1.getUserOperationHash)(userOperation, entryPoint, this.chainId);
533
+ await this.preMempoolChecks(opHash, userOperation, apiVersion, entryPoint);
534
+ const result = (await this.executor.bundle(entryPoint, [userOperation]))[0];
535
+ if (result.status === "failure") {
536
+ const { userOpHash, reason } = result.error;
537
+ this.monitor.setUserOperationStatus(userOpHash, {
538
+ status: "rejected",
539
+ transactionHash: null
540
+ });
541
+ this.logger.warn({
542
+ userOperation: JSON.stringify(result.error.userOperation, (_k, v) => (typeof v === "bigint" ? v.toString() : v)),
543
+ userOpHash,
544
+ reason
545
+ }, "user operation rejected");
546
+ this.metrics.userOperationsSubmitted
547
+ .labels({ status: "failed" })
548
+ .inc();
549
+ const { error } = result;
550
+ throw new types_1.RpcError(`userOperation reverted during simulation with reason: ${error.reason}`);
551
+ }
552
+ const res = result;
553
+ // wait for receipt
554
+ const receipt = await this.publicClient.waitForTransactionReceipt({
555
+ hash: res.value.transactionInfo.transactionHash,
556
+ pollingInterval: 100
557
+ });
558
+ const userOperationReceipt = (0, utils_1.parseUserOperationReceipt)(opHash, receipt);
559
+ return userOperationReceipt;
560
+ }
674
561
  async pimlico_sendCompressedUserOperation(apiVersion, compressedCalldata, inflatorAddress, entryPoint) {
562
+ const receivedTimestamp = Date.now();
675
563
  let status = "rejected";
676
564
  try {
677
565
  const { inflatedOp, inflatorId } = await this.validateAndInflateCompressedUserOperation(inflatorAddress, compressedCalldata);
566
+ const hash = (0, utils_1.getUserOperationHash)(inflatedOp, entryPoint, this.chainId);
567
+ this.eventManager.emitReceived(hash, receivedTimestamp);
678
568
  const compressedUserOp = {
679
569
  compressedCalldata,
680
570
  inflatedOp,
@@ -683,7 +573,6 @@ class RpcHandler {
683
573
  };
684
574
  // check userOps inputs.
685
575
  status = await this.addToMempoolIfValid(compressedUserOp, entryPoint, apiVersion);
686
- const hash = (0, utils_1.getUserOperationHash)(inflatedOp, entryPoint, this.chainId);
687
576
  return hash;
688
577
  }
689
578
  catch (error) {