@pimlico/alto 0.0.0-main.20240607T034324 → 0.0.0-staging.20240606T093925

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 (238) hide show
  1. package/lib/cli/index.d.ts +0 -1
  2. package/lib/cli/index.js +0 -1
  3. package/lib/cli/index.js.map +1 -1
  4. package/lib/executor/executor.js +0 -6
  5. package/lib/executor/executor.js.map +1 -1
  6. package/lib/executor/executorManager.js +0 -1
  7. package/lib/executor/executorManager.js.map +1 -1
  8. package/lib/executor/utils.js +1 -3
  9. package/lib/executor/utils.js.map +1 -1
  10. package/lib/index.d.ts +5 -1
  11. package/lib/index.js +120 -1
  12. package/lib/index.js.map +1 -1
  13. package/lib/rpc/server.js +1 -2
  14. package/lib/rpc/server.js.map +1 -1
  15. package/lib/types/mempool.d.ts +1 -2
  16. package/package.json +67 -70
  17. package/esm/cli/alto.d.ts +0 -6
  18. package/esm/cli/alto.js +0 -92
  19. package/esm/cli/alto.js.map +0 -1
  20. package/esm/cli/config/bundler.d.ts +0 -391
  21. package/esm/cli/config/bundler.js +0 -132
  22. package/esm/cli/config/bundler.js.map +0 -1
  23. package/esm/cli/config/index.d.ts +0 -3
  24. package/esm/cli/config/index.js +0 -3
  25. package/esm/cli/config/index.js.map +0 -1
  26. package/esm/cli/config/options.d.ts +0 -11
  27. package/esm/cli/config/options.js +0 -336
  28. package/esm/cli/config/options.js.map +0 -1
  29. package/esm/cli/customTransport.d.ts +0 -14
  30. package/esm/cli/customTransport.js +0 -53
  31. package/esm/cli/customTransport.js.map +0 -1
  32. package/esm/cli/handler.d.ts +0 -3
  33. package/esm/cli/handler.js +0 -116
  34. package/esm/cli/handler.js.map +0 -1
  35. package/esm/cli/index.d.ts +0 -4
  36. package/esm/cli/index.js +0 -4
  37. package/esm/cli/index.js.map +0 -1
  38. package/esm/cli/instrumentation.d.ts +0 -2
  39. package/esm/cli/instrumentation.js +0 -39
  40. package/esm/cli/instrumentation.js.map +0 -1
  41. package/esm/cli/setupServer.d.ts +0 -17
  42. package/esm/cli/setupServer.js +0 -155
  43. package/esm/cli/setupServer.js.map +0 -1
  44. package/esm/cli/util.d.ts +0 -22
  45. package/esm/cli/util.js +0 -30
  46. package/esm/cli/util.js.map +0 -1
  47. package/esm/executor/executor.d.ts +0 -54
  48. package/esm/executor/executor.js +0 -643
  49. package/esm/executor/executor.js.map +0 -1
  50. package/esm/executor/executorManager.d.ts +0 -34
  51. package/esm/executor/executorManager.js +0 -402
  52. package/esm/executor/executorManager.js.map +0 -1
  53. package/esm/executor/index.d.ts +0 -5
  54. package/esm/executor/index.js +0 -5
  55. package/esm/executor/index.js.map +0 -1
  56. package/esm/executor/senderManager.d.ts +0 -17
  57. package/esm/executor/senderManager.js +0 -160
  58. package/esm/executor/senderManager.js.map +0 -1
  59. package/esm/executor/test/utils.d.ts +0 -13
  60. package/esm/executor/test/utils.js +0 -75
  61. package/esm/executor/test/utils.js.map +0 -1
  62. package/esm/executor/utils.d.ts +0 -32
  63. package/esm/executor/utils.js +0 -241
  64. package/esm/executor/utils.js.map +0 -1
  65. package/esm/index.d.ts +0 -2
  66. package/esm/index.js +0 -2
  67. package/esm/index.js.map +0 -1
  68. package/esm/mempool/index.d.ts +0 -5
  69. package/esm/mempool/index.js +0 -5
  70. package/esm/mempool/index.js.map +0 -1
  71. package/esm/mempool/mempool.d.ts +0 -64
  72. package/esm/mempool/mempool.js +0 -489
  73. package/esm/mempool/mempool.js.map +0 -1
  74. package/esm/mempool/monitoring.d.ts +0 -10
  75. package/esm/mempool/monitoring.js +0 -34
  76. package/esm/mempool/monitoring.js.map +0 -1
  77. package/esm/mempool/nullMempool.d.ts +0 -15
  78. package/esm/mempool/nullMempool.js +0 -36
  79. package/esm/mempool/nullMempool.js.map +0 -1
  80. package/esm/mempool/reputationManager.d.ts +0 -115
  81. package/esm/mempool/reputationManager.js +0 -397
  82. package/esm/mempool/reputationManager.js.map +0 -1
  83. package/esm/mempool/store.d.ts +0 -22
  84. package/esm/mempool/store.js +0 -123
  85. package/esm/mempool/store.js.map +0 -1
  86. package/esm/rpc/EntryPointSimulationsV07.d.ts +0 -58
  87. package/esm/rpc/EntryPointSimulationsV07.js +0 -407
  88. package/esm/rpc/EntryPointSimulationsV07.js.map +0 -1
  89. package/esm/rpc/ExecuteSimulator.d.ts +0 -37
  90. package/esm/rpc/ExecuteSimulator.js +0 -48
  91. package/esm/rpc/ExecuteSimulator.js.map +0 -1
  92. package/esm/rpc/gasEstimation.d.ts +0 -17
  93. package/esm/rpc/gasEstimation.js +0 -410
  94. package/esm/rpc/gasEstimation.js.map +0 -1
  95. package/esm/rpc/index.d.ts +0 -5
  96. package/esm/rpc/index.js +0 -5
  97. package/esm/rpc/index.js.map +0 -1
  98. package/esm/rpc/nonceQueuer.d.ts +0 -25
  99. package/esm/rpc/nonceQueuer.js +0 -135
  100. package/esm/rpc/nonceQueuer.js.map +0 -1
  101. package/esm/rpc/rpcHandler.d.ts +0 -64
  102. package/esm/rpc/rpcHandler.js +0 -727
  103. package/esm/rpc/rpcHandler.js.map +0 -1
  104. package/esm/rpc/server.d.ts +0 -31
  105. package/esm/rpc/server.js +0 -239
  106. package/esm/rpc/server.js.map +0 -1
  107. package/esm/rpc/validation/BundlerCollectorTracerV06.d.ts +0 -102
  108. package/esm/rpc/validation/BundlerCollectorTracerV06.js +0 -255
  109. package/esm/rpc/validation/BundlerCollectorTracerV06.js.map +0 -1
  110. package/esm/rpc/validation/BundlerCollectorTracerV07.d.ts +0 -102
  111. package/esm/rpc/validation/BundlerCollectorTracerV07.js +0 -254
  112. package/esm/rpc/validation/BundlerCollectorTracerV07.js.map +0 -1
  113. package/esm/rpc/validation/SafeValidator.d.ts +0 -35
  114. package/esm/rpc/validation/SafeValidator.js +0 -487
  115. package/esm/rpc/validation/SafeValidator.js.map +0 -1
  116. package/esm/rpc/validation/TracerResultParserV06.d.ts +0 -13
  117. package/esm/rpc/validation/TracerResultParserV06.js +0 -578
  118. package/esm/rpc/validation/TracerResultParserV06.js.map +0 -1
  119. package/esm/rpc/validation/TracerResultParserV07.d.ts +0 -33
  120. package/esm/rpc/validation/TracerResultParserV07.js +0 -557
  121. package/esm/rpc/validation/TracerResultParserV07.js.map +0 -1
  122. package/esm/rpc/validation/UnsafeValidator.d.ts +0 -63
  123. package/esm/rpc/validation/UnsafeValidator.js +0 -257
  124. package/esm/rpc/validation/UnsafeValidator.js.map +0 -1
  125. package/esm/rpc/validation/index.d.ts +0 -3
  126. package/esm/rpc/validation/index.js +0 -3
  127. package/esm/rpc/validation/index.js.map +0 -1
  128. package/esm/rpc/validation/tracer.d.ts +0 -122
  129. package/esm/rpc/validation/tracer.js +0 -82
  130. package/esm/rpc/validation/tracer.js.map +0 -1
  131. package/esm/types/contracts/BundleBulker.d.ts +0 -120
  132. package/esm/types/contracts/BundleBulker.js +0 -157
  133. package/esm/types/contracts/BundleBulker.js.map +0 -1
  134. package/esm/types/contracts/CallEngine.d.ts +0 -28
  135. package/esm/types/contracts/CallEngine.js +0 -37
  136. package/esm/types/contracts/CallEngine.js.map +0 -1
  137. package/esm/types/contracts/CodeHashGetter.d.ts +0 -37
  138. package/esm/types/contracts/CodeHashGetter.js +0 -45
  139. package/esm/types/contracts/CodeHashGetter.js.map +0 -1
  140. package/esm/types/contracts/EntryPoint.d.ts +0 -1789
  141. package/esm/types/contracts/EntryPoint.js +0 -2304
  142. package/esm/types/contracts/EntryPoint.js.map +0 -1
  143. package/esm/types/contracts/EntryPointSimulations.d.ts +0 -153
  144. package/esm/types/contracts/EntryPointSimulations.js +0 -15
  145. package/esm/types/contracts/EntryPointSimulations.js.map +0 -1
  146. package/esm/types/contracts/IOpInflator.d.ts +0 -61
  147. package/esm/types/contracts/IOpInflator.js +0 -80
  148. package/esm/types/contracts/IOpInflator.js.map +0 -1
  149. package/esm/types/contracts/IPaymaster.d.ts +0 -3
  150. package/esm/types/contracts/IPaymaster.js +0 -117
  151. package/esm/types/contracts/IPaymaster.js.map +0 -1
  152. package/esm/types/contracts/Inflator.d.ts +0 -65
  153. package/esm/types/contracts/Inflator.js +0 -84
  154. package/esm/types/contracts/Inflator.js.map +0 -1
  155. package/esm/types/contracts/PerOpInflator.d.ts +0 -176
  156. package/esm/types/contracts/PerOpInflator.js +0 -229
  157. package/esm/types/contracts/PerOpInflator.js.map +0 -1
  158. package/esm/types/contracts/PimlicoEntryPointSimulations.d.ts +0 -23
  159. package/esm/types/contracts/PimlicoEntryPointSimulations.js +0 -33
  160. package/esm/types/contracts/PimlicoEntryPointSimulations.js.map +0 -1
  161. package/esm/types/contracts/SenderCreator.d.ts +0 -4
  162. package/esm/types/contracts/SenderCreator.js +0 -23
  163. package/esm/types/contracts/SenderCreator.js.map +0 -1
  164. package/esm/types/contracts/SimpleAccountFactory.d.ts +0 -57
  165. package/esm/types/contracts/SimpleAccountFactory.js +0 -76
  166. package/esm/types/contracts/SimpleAccountFactory.js.map +0 -1
  167. package/esm/types/contracts/TestOpcodesAccount.d.ts +0 -4
  168. package/esm/types/contracts/TestOpcodesAccount.js +0 -281
  169. package/esm/types/contracts/TestOpcodesAccount.js.map +0 -1
  170. package/esm/types/contracts/TestOpcodesAccountFactory.d.ts +0 -4
  171. package/esm/types/contracts/TestOpcodesAccountFactory.js +0 -23
  172. package/esm/types/contracts/TestOpcodesAccountFactory.js.map +0 -1
  173. package/esm/types/contracts/TestStorageAccount.d.ts +0 -4
  174. package/esm/types/contracts/TestStorageAccount.js +0 -313
  175. package/esm/types/contracts/TestStorageAccount.js.map +0 -1
  176. package/esm/types/contracts/index.d.ts +0 -17
  177. package/esm/types/contracts/index.js +0 -17
  178. package/esm/types/contracts/index.js.map +0 -1
  179. package/esm/types/gasPrice.d.ts +0 -110
  180. package/esm/types/gasPrice.js +0 -52
  181. package/esm/types/gasPrice.js.map +0 -1
  182. package/esm/types/index.d.ts +0 -11
  183. package/esm/types/index.js +0 -11
  184. package/esm/types/index.js.map +0 -1
  185. package/esm/types/interfaces.d.ts +0 -26
  186. package/esm/types/interfaces.js +0 -2
  187. package/esm/types/interfaces.js.map +0 -1
  188. package/esm/types/mempool.d.ts +0 -79
  189. package/esm/types/mempool.js +0 -16
  190. package/esm/types/mempool.js.map +0 -1
  191. package/esm/types/schemas.d.ts +0 -4791
  192. package/esm/types/schemas.js +0 -497
  193. package/esm/types/schemas.js.map +0 -1
  194. package/esm/types/test/validationTestErrors.d.ts +0 -3
  195. package/esm/types/test/validationTestErrors.js +0 -229
  196. package/esm/types/test/validationTestErrors.js.map +0 -1
  197. package/esm/types/utils.d.ts +0 -24
  198. package/esm/types/utils.js +0 -30
  199. package/esm/types/utils.js.map +0 -1
  200. package/esm/types/validation.d.ts +0 -14327
  201. package/esm/types/validation.js +0 -304
  202. package/esm/types/validation.js.map +0 -1
  203. package/esm/utils/bigInt.d.ts +0 -3
  204. package/esm/utils/bigInt.js +0 -9
  205. package/esm/utils/bigInt.js.map +0 -1
  206. package/esm/utils/compressionHandler.d.ts +0 -11
  207. package/esm/utils/compressionHandler.js +0 -39
  208. package/esm/utils/compressionHandler.js.map +0 -1
  209. package/esm/utils/gasPriceManager.d.ts +0 -34
  210. package/esm/utils/gasPriceManager.js +0 -338
  211. package/esm/utils/gasPriceManager.js.map +0 -1
  212. package/esm/utils/helpers.d.ts +0 -4
  213. package/esm/utils/helpers.js +0 -13
  214. package/esm/utils/helpers.js.map +0 -1
  215. package/esm/utils/index.d.ts +0 -11
  216. package/esm/utils/index.js +0 -10
  217. package/esm/utils/index.js.map +0 -1
  218. package/esm/utils/logger.d.ts +0 -6
  219. package/esm/utils/logger.js +0 -76
  220. package/esm/utils/logger.js.map +0 -1
  221. package/esm/utils/metrics.d.ts +0 -22
  222. package/esm/utils/metrics.js +0 -150
  223. package/esm/utils/metrics.js.map +0 -1
  224. package/esm/utils/rpc-reply.d.ts +0 -17
  225. package/esm/utils/rpc-reply.js +0 -41
  226. package/esm/utils/rpc-reply.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/esm/utils/userop.d.ts +0 -49
  231. package/esm/utils/userop.js +0 -408
  232. package/esm/utils/userop.js.map +0 -1
  233. package/esm/utils/validation.d.ts +0 -65
  234. package/esm/utils/validation.js +0 -461
  235. package/esm/utils/validation.js.map +0 -1
  236. package/lib/cli/alto.d.ts +0 -6
  237. package/lib/cli/alto.js +0 -123
  238. package/lib/cli/alto.js.map +0 -1
@@ -1,643 +0,0 @@
1
- import { EntryPointV06Abi, EntryPointV07Abi, deriveUserOperation } from "../types/index.js";
2
- import { getUserOperationHash, isVersion06, maxBigInt, parseViemError, toPackedUserOperation } from "../utils/index.js";
3
- import * as sentry from "@sentry/node";
4
- import { Mutex } from "async-mutex";
5
- import { FeeCapTooLowError, InsufficientFundsError, IntrinsicGasTooLowError, NonceTooLowError, encodeFunctionData, getContract } from "viem";
6
- import { createCompressedCalldata, filterOpsAndEstimateGas, flushStuckTransaction, simulatedOpsToResults } from "./utils.js";
7
- export class NullExecutor {
8
- bundle(_entryPoint, _ops) {
9
- return Promise.resolve([]);
10
- }
11
- bundleCompressed(_entryPoint, _compressedOps) {
12
- return Promise.resolve([]);
13
- }
14
- replaceTransaction(_entryPoint, _transactionInfo) {
15
- return Promise.resolve({ status: "failed" });
16
- }
17
- replaceOps(_opHashes) {
18
- return Promise.resolve();
19
- }
20
- cancelOps(_entryPoint, _ops) {
21
- return Promise.resolve();
22
- }
23
- markWalletProcessed(_executor) {
24
- return Promise.resolve();
25
- }
26
- flushStuckTransactions() {
27
- return Promise.resolve();
28
- }
29
- }
30
- export class Executor {
31
- // private unWatch: WatchBlocksReturnType | undefined
32
- publicClient;
33
- walletClient;
34
- entryPoints;
35
- senderManager;
36
- logger;
37
- metrics;
38
- simulateTransaction;
39
- legacyTransactions;
40
- fixedGasLimitForEstimation;
41
- localGasLimitCalculation;
42
- reputationManager;
43
- compressionHandler;
44
- gasPriceManager;
45
- mutex;
46
- constructor(publicClient, walletClient, senderManager, reputationManager, entryPoints, logger, metrics, compressionHandler, gasPriceManager, simulateTransaction = false, legacyTransactions = false, fixedGasLimitForEstimation, localGasLimitCalculation = false) {
47
- this.publicClient = publicClient;
48
- this.walletClient = walletClient;
49
- this.senderManager = senderManager;
50
- this.reputationManager = reputationManager;
51
- this.logger = logger;
52
- this.metrics = metrics;
53
- this.simulateTransaction = simulateTransaction;
54
- this.legacyTransactions = legacyTransactions;
55
- this.fixedGasLimitForEstimation = fixedGasLimitForEstimation;
56
- this.localGasLimitCalculation = localGasLimitCalculation;
57
- this.compressionHandler = compressionHandler;
58
- this.gasPriceManager = gasPriceManager;
59
- this.entryPoints = entryPoints;
60
- this.mutex = new Mutex();
61
- }
62
- getCompressionHandler() {
63
- if (!this.compressionHandler) {
64
- throw new Error("Support for compressed bundles has not initialized");
65
- }
66
- return this.compressionHandler;
67
- }
68
- cancelOps(_entryPoint, _ops) {
69
- throw new Error("Method not implemented.");
70
- }
71
- markWalletProcessed(executor) {
72
- if (!this.senderManager.availableWallets.includes(executor)) {
73
- this.senderManager.pushWallet(executor);
74
- }
75
- return Promise.resolve();
76
- }
77
- async replaceTransaction(transactionInfo) {
78
- const newRequest = { ...transactionInfo.transactionRequest };
79
- const gasPriceParameters = await this.gasPriceManager.getGasPrice();
80
- newRequest.maxFeePerGas = maxBigInt(gasPriceParameters.maxFeePerGas, (newRequest.maxFeePerGas * 11n + 9n) / 10n);
81
- newRequest.maxPriorityFeePerGas = maxBigInt(gasPriceParameters.maxPriorityFeePerGas, (newRequest.maxPriorityFeePerGas * 11n + 9n) / 10n);
82
- newRequest.account = transactionInfo.executor;
83
- const opsWithHashes = transactionInfo.userOperationInfos.map((opInfo) => {
84
- const op = deriveUserOperation(opInfo.mempoolUserOperation);
85
- return {
86
- mempoolUserOperation: opInfo.mempoolUserOperation,
87
- userOperationHash: getUserOperationHash(op, transactionInfo.entryPoint, this.walletClient.chain.id),
88
- entryPoint: opInfo.entryPoint
89
- };
90
- });
91
- let callContext;
92
- if (transactionInfo.transactionType === "default") {
93
- const [isUserOpVersion06, entryPoint] = opsWithHashes.reduce((acc, op) => {
94
- if (acc[0] !==
95
- isVersion06(op.mempoolUserOperation) ||
96
- acc[1] !== op.entryPoint) {
97
- throw new Error("All user operations must be of the same version");
98
- }
99
- return acc;
100
- }, [
101
- isVersion06(opsWithHashes[0].mempoolUserOperation),
102
- opsWithHashes[0].entryPoint
103
- ]);
104
- const ep = getContract({
105
- abi: isUserOpVersion06 ? EntryPointV06Abi : EntryPointV07Abi,
106
- address: entryPoint,
107
- client: {
108
- public: this.publicClient,
109
- wallet: this.walletClient
110
- }
111
- });
112
- callContext = {
113
- ep,
114
- type: "default"
115
- };
116
- }
117
- else {
118
- const compressionHandler = this.getCompressionHandler();
119
- callContext = {
120
- publicClient: this.publicClient,
121
- bundleBulker: compressionHandler.bundleBulkerAddress,
122
- perOpInflatorId: compressionHandler.perOpInflatorId,
123
- type: "compressed"
124
- };
125
- }
126
- const result = await filterOpsAndEstimateGas(transactionInfo.entryPoint, callContext, transactionInfo.executor, opsWithHashes, newRequest.nonce, newRequest.maxFeePerGas, newRequest.maxPriorityFeePerGas, "latest", this.legacyTransactions, this.fixedGasLimitForEstimation, this.reputationManager, this.logger);
127
- const childLogger = this.logger.child({
128
- transactionHash: transactionInfo.transactionHash,
129
- executor: transactionInfo.executor.address
130
- });
131
- if (result.simulatedOps.length === 0) {
132
- childLogger.warn("no ops to bundle");
133
- this.markWalletProcessed(transactionInfo.executor);
134
- return { status: "failed" };
135
- }
136
- if (result.simulatedOps.every((op) => op.reason === "AA25 invalid account nonce" ||
137
- op.reason === "AA10 sender already constructed")) {
138
- childLogger.trace({ reasons: result.simulatedOps.map((sop) => sop.reason) }, "all ops failed simulation with nonce error");
139
- return { status: "potentially_already_included" };
140
- }
141
- if (result.simulatedOps.every((op) => op.reason !== undefined)) {
142
- childLogger.warn("all ops failed simulation");
143
- this.markWalletProcessed(transactionInfo.executor);
144
- return { status: "failed" };
145
- }
146
- const opsToBundle = result.simulatedOps
147
- .filter((op) => op.reason === undefined)
148
- .map((op) => {
149
- const opInfo = transactionInfo.userOperationInfos.find((info) => info.userOperationHash === op.owh.userOperationHash);
150
- if (!opInfo) {
151
- throw new Error("opInfo not found");
152
- }
153
- return opInfo;
154
- });
155
- newRequest.gas = this.localGasLimitCalculation
156
- ? opsToBundle.reduce((acc, opInfo) => {
157
- const userOperation = deriveUserOperation(opInfo.mempoolUserOperation);
158
- return (acc +
159
- userOperation.preVerificationGas +
160
- 3n * userOperation.verificationGasLimit +
161
- userOperation.callGasLimit);
162
- }, 0n)
163
- : result.gasLimit;
164
- // update calldata to include only ops that pass simulation
165
- if (transactionInfo.transactionType === "default") {
166
- const isUserOpVersion06 = opsWithHashes.reduce((acc, op) => {
167
- if (acc !==
168
- isVersion06(op.mempoolUserOperation)) {
169
- throw new Error("All user operations must be of the same version");
170
- }
171
- return acc;
172
- }, isVersion06(opsWithHashes[0].mempoolUserOperation));
173
- newRequest.data = isUserOpVersion06
174
- ? encodeFunctionData({
175
- abi: EntryPointV06Abi,
176
- functionName: "handleOps",
177
- args: [
178
- opsToBundle.map((opInfo) => opInfo.mempoolUserOperation),
179
- transactionInfo.executor.address
180
- ]
181
- })
182
- : encodeFunctionData({
183
- abi: EntryPointV07Abi,
184
- functionName: "handleOps",
185
- args: [
186
- opsToBundle.map((opInfo) => toPackedUserOperation(opInfo.mempoolUserOperation)),
187
- transactionInfo.executor.address
188
- ]
189
- });
190
- }
191
- else if (transactionInfo.transactionType === "compressed") {
192
- const compressedOps = opsToBundle.map((opInfo) => opInfo.mempoolUserOperation);
193
- newRequest.data = createCompressedCalldata(compressedOps, this.getCompressionHandler().perOpInflatorId);
194
- }
195
- try {
196
- childLogger.info({
197
- newRequest: {
198
- ...newRequest,
199
- abi: undefined,
200
- chain: undefined
201
- },
202
- executor: newRequest.account.address,
203
- opsToBundle: opsToBundle.map((opInfo) => opInfo.userOperationHash)
204
- }, "replacing transaction");
205
- const txHash = await this.walletClient.sendTransaction(this.legacyTransactions
206
- ? {
207
- ...newRequest,
208
- gasPrice: newRequest.maxFeePerGas,
209
- maxFeePerGas: undefined,
210
- maxPriorityFeePerGas: undefined,
211
- type: "legacy",
212
- accessList: undefined
213
- }
214
- : newRequest);
215
- const newTxInfo = {
216
- ...transactionInfo,
217
- transactionRequest: newRequest,
218
- transactionHash: txHash,
219
- previousTransactionHashes: [
220
- transactionInfo.transactionHash,
221
- ...transactionInfo.previousTransactionHashes
222
- ],
223
- lastReplaced: Date.now(),
224
- userOperationInfos: opsToBundle.map((opInfo) => {
225
- return {
226
- entryPoint: opInfo.entryPoint,
227
- mempoolUserOperation: opInfo.mempoolUserOperation,
228
- userOperationHash: opInfo.userOperationHash,
229
- lastReplaced: Date.now(),
230
- firstSubmitted: opInfo.firstSubmitted
231
- };
232
- })
233
- };
234
- return {
235
- status: "replaced",
236
- transactionInfo: newTxInfo
237
- };
238
- }
239
- catch (err) {
240
- const e = parseViemError(err);
241
- if (!e) {
242
- sentry.captureException(err);
243
- childLogger.error({ error: err }, "unknown error replacing transaction");
244
- }
245
- if (e instanceof NonceTooLowError) {
246
- childLogger.trace({ error: e }, "nonce too low, potentially already included");
247
- return { status: "potentially_already_included" };
248
- }
249
- if (e instanceof FeeCapTooLowError) {
250
- childLogger.warn({ error: e }, "fee cap too low, not replacing");
251
- }
252
- if (e instanceof InsufficientFundsError) {
253
- childLogger.warn({ error: e }, "insufficient funds, not replacing");
254
- }
255
- if (e instanceof IntrinsicGasTooLowError) {
256
- childLogger.warn({ error: e }, "intrinsic gas too low, not replacing");
257
- }
258
- childLogger.warn({ error: e }, "error replacing transaction");
259
- this.markWalletProcessed(transactionInfo.executor);
260
- return { status: "failed" };
261
- }
262
- }
263
- async flushStuckTransactions() {
264
- const gasPrice = await this.gasPriceManager.getGasPrice();
265
- const wallets = this.senderManager.utilityAccount
266
- ? Array.from(new Set([
267
- ...this.senderManager.wallets,
268
- this.senderManager.utilityAccount
269
- ]))
270
- : Array.from(new Set(this.senderManager.wallets));
271
- const promises = wallets.map(async (wallet) => {
272
- for (const entryPoint of this.entryPoints) {
273
- await flushStuckTransaction(this.publicClient, this.walletClient, wallet, gasPrice.maxFeePerGas * 5n, this.logger, entryPoint);
274
- }
275
- });
276
- await Promise.all(promises);
277
- }
278
- async bundle(entryPoint, ops) {
279
- const wallet = await this.senderManager.getWallet();
280
- const opsWithHashes = ops.map((op) => {
281
- return {
282
- mempoolUserOperation: op,
283
- userOperationHash: getUserOperationHash(op, entryPoint, this.walletClient.chain.id)
284
- };
285
- });
286
- const isUserOpVersion06 = opsWithHashes.reduce((acc, op) => {
287
- if (acc !==
288
- isVersion06(op.mempoolUserOperation)) {
289
- throw new Error("All user operations must be of the same version");
290
- }
291
- return acc;
292
- }, isVersion06(opsWithHashes[0].mempoolUserOperation));
293
- const ep = getContract({
294
- abi: isUserOpVersion06 ? EntryPointV06Abi : EntryPointV07Abi,
295
- address: entryPoint,
296
- client: {
297
- public: this.publicClient,
298
- wallet: this.walletClient
299
- }
300
- });
301
- let childLogger = this.logger.child({
302
- userOperations: opsWithHashes.map((oh) => oh.userOperationHash),
303
- entryPoint
304
- });
305
- childLogger.debug("bundling user operation");
306
- const gasPriceParameters = await this.gasPriceManager.getGasPrice();
307
- childLogger.debug({ gasPriceParameters }, "got gas price");
308
- const nonce = await this.publicClient.getTransactionCount({
309
- address: wallet.address,
310
- blockTag: "pending"
311
- });
312
- childLogger.trace({ nonce }, "got nonce");
313
- const callContext = {
314
- ep,
315
- type: "default"
316
- };
317
- let { gasLimit, simulatedOps, resubmitAllOps } = await filterOpsAndEstimateGas(entryPoint, callContext, wallet, opsWithHashes, nonce, gasPriceParameters.maxFeePerGas, gasPriceParameters.maxPriorityFeePerGas, "pending", this.legacyTransactions, this.fixedGasLimitForEstimation, this.reputationManager, childLogger);
318
- gasLimit += 10000n;
319
- if (resubmitAllOps) {
320
- this.markWalletProcessed(wallet);
321
- return opsWithHashes.map((owh) => {
322
- const bundleResult = {
323
- status: "resubmit",
324
- info: {
325
- entryPoint,
326
- userOpHash: owh.userOperationHash,
327
- userOperation: owh.mempoolUserOperation,
328
- reason: FeeCapTooLowError.name
329
- }
330
- };
331
- return bundleResult;
332
- });
333
- }
334
- if (simulatedOps.length === 0) {
335
- childLogger.error("gas limit simulation encountered unexpected failure");
336
- this.markWalletProcessed(wallet);
337
- return opsWithHashes.map((owh) => {
338
- return {
339
- status: "failure",
340
- error: {
341
- entryPoint,
342
- userOpHash: owh.userOperationHash,
343
- userOperation: owh.mempoolUserOperation,
344
- reason: "INTERNAL FAILURE"
345
- }
346
- };
347
- });
348
- }
349
- if (simulatedOps.every((op) => op.reason !== undefined)) {
350
- childLogger.warn("all ops failed simulation");
351
- this.markWalletProcessed(wallet);
352
- return simulatedOps.map((op) => {
353
- return {
354
- status: "failure",
355
- error: {
356
- entryPoint,
357
- userOpHash: op.owh.userOperationHash,
358
- userOperation: op.owh.mempoolUserOperation,
359
- reason: op.reason
360
- }
361
- };
362
- });
363
- }
364
- const opsWithHashToBundle = simulatedOps
365
- .filter((op) => op.reason === undefined)
366
- .map((op) => op.owh);
367
- childLogger = this.logger.child({
368
- userOperations: opsWithHashToBundle.map((owh) => owh.userOperationHash),
369
- entryPoint
370
- });
371
- childLogger.trace({ gasLimit }, "got gas limit");
372
- let txHash;
373
- try {
374
- const gasOptions = this.legacyTransactions
375
- ? {
376
- gasPrice: gasPriceParameters.maxFeePerGas
377
- }
378
- : {
379
- maxFeePerGas: gasPriceParameters.maxFeePerGas,
380
- maxPriorityFeePerGas: gasPriceParameters.maxPriorityFeePerGas
381
- };
382
- txHash = isUserOpVersion06
383
- ? await ep.write.handleOps([
384
- opsWithHashToBundle.map((owh) => owh.mempoolUserOperation),
385
- wallet.address
386
- ], {
387
- account: wallet,
388
- gas: gasLimit,
389
- nonce: nonce,
390
- ...gasOptions
391
- })
392
- : await ep.write.handleOps([
393
- opsWithHashToBundle.map((owh) => toPackedUserOperation(owh.mempoolUserOperation)),
394
- wallet.address
395
- ], {
396
- account: wallet,
397
- gas: gasLimit,
398
- nonce: nonce,
399
- ...gasOptions
400
- });
401
- }
402
- catch (err) {
403
- const e = parseViemError(err);
404
- if (e instanceof InsufficientFundsError) {
405
- childLogger.error({ error: e }, "insufficient funds, not submitting transaction");
406
- this.markWalletProcessed(wallet);
407
- return opsWithHashToBundle.map((owh) => {
408
- return {
409
- status: "resubmit",
410
- info: {
411
- entryPoint,
412
- userOpHash: owh.userOperationHash,
413
- userOperation: owh.mempoolUserOperation,
414
- reason: InsufficientFundsError.name
415
- }
416
- };
417
- });
418
- }
419
- sentry.captureException(err);
420
- childLogger.error({ error: JSON.stringify(err) }, "error submitting bundle transaction");
421
- this.markWalletProcessed(wallet);
422
- return opsWithHashes.map((owh) => {
423
- return {
424
- status: "failure",
425
- error: {
426
- entryPoint,
427
- userOpHash: owh.userOperationHash,
428
- userOperation: owh.mempoolUserOperation,
429
- reason: "INTERNAL FAILURE"
430
- }
431
- };
432
- });
433
- }
434
- const userOperationInfos = opsWithHashToBundle.map((op) => {
435
- return {
436
- entryPoint,
437
- mempoolUserOperation: op.mempoolUserOperation,
438
- userOperationHash: op.userOperationHash,
439
- lastReplaced: Date.now(),
440
- firstSubmitted: Date.now()
441
- };
442
- });
443
- const transactionInfo = {
444
- entryPoint,
445
- isVersion06: isUserOpVersion06,
446
- transactionType: "default",
447
- transactionHash: txHash,
448
- previousTransactionHashes: [],
449
- transactionRequest: {
450
- account: wallet,
451
- to: ep.address,
452
- data: isUserOpVersion06
453
- ? encodeFunctionData({
454
- abi: ep.abi,
455
- functionName: "handleOps",
456
- args: [
457
- opsWithHashToBundle.map((owh) => owh.mempoolUserOperation),
458
- wallet.address
459
- ]
460
- })
461
- : encodeFunctionData({
462
- abi: ep.abi,
463
- functionName: "handleOps",
464
- args: [
465
- opsWithHashToBundle.map((owh) => toPackedUserOperation(owh.mempoolUserOperation)),
466
- wallet.address
467
- ]
468
- }),
469
- gas: gasLimit,
470
- chain: this.walletClient.chain,
471
- maxFeePerGas: gasPriceParameters.maxFeePerGas,
472
- maxPriorityFeePerGas: gasPriceParameters.maxPriorityFeePerGas,
473
- nonce: nonce
474
- },
475
- executor: wallet,
476
- userOperationInfos,
477
- lastReplaced: Date.now(),
478
- firstSubmitted: Date.now(),
479
- timesPotentiallyIncluded: 0
480
- };
481
- const userOperationResults = simulatedOpsToResults(simulatedOps, transactionInfo);
482
- childLogger.info({
483
- transactionRequest: {
484
- ...transactionInfo.transactionRequest,
485
- abi: undefined
486
- },
487
- txHash,
488
- opHashes: opsWithHashToBundle.map((owh) => owh.userOperationHash)
489
- }, "submitted bundle transaction");
490
- return userOperationResults;
491
- }
492
- async bundleCompressed(entryPoint, compressedOps) {
493
- const compressionHandler = this.getCompressionHandler();
494
- const wallet = await this.senderManager.getWallet();
495
- const childLogger = this.logger.child({
496
- compressedUserOperations: compressedOps,
497
- entryPoint: entryPoint
498
- });
499
- childLogger.debug("bundling compressed user operation");
500
- const gasPriceParameters = await this.gasPriceManager.getGasPrice();
501
- childLogger.debug({ gasPriceParameters }, "got gas price");
502
- const nonce = await this.publicClient.getTransactionCount({
503
- address: wallet.address,
504
- blockTag: "pending"
505
- });
506
- childLogger.trace({ nonce }, "got nonce");
507
- const callContext = {
508
- publicClient: this.publicClient,
509
- bundleBulker: compressionHandler.bundleBulkerAddress,
510
- perOpInflatorId: compressionHandler.perOpInflatorId,
511
- type: "compressed"
512
- };
513
- let { gasLimit, simulatedOps, resubmitAllOps } = await filterOpsAndEstimateGas(entryPoint, callContext, wallet, compressedOps.map((compressedOp) => {
514
- return {
515
- mempoolUserOperation: compressedOp,
516
- userOperationHash: getUserOperationHash(compressedOp.inflatedOp, entryPoint, this.walletClient.chain.id)
517
- };
518
- }), nonce, gasPriceParameters.maxFeePerGas, gasPriceParameters.maxPriorityFeePerGas, "pending", this.legacyTransactions, this.fixedGasLimitForEstimation, this.reputationManager, childLogger);
519
- gasLimit += 10000n;
520
- if (resubmitAllOps) {
521
- this.markWalletProcessed(wallet);
522
- return compressedOps.map((compressedOp) => {
523
- return {
524
- status: "resubmit",
525
- info: {
526
- entryPoint,
527
- userOpHash: getUserOperationHash(compressedOp.inflatedOp, entryPoint, this.walletClient.chain.id),
528
- userOperation: compressedOp,
529
- reason: FeeCapTooLowError.name
530
- }
531
- };
532
- });
533
- }
534
- if (simulatedOps.length === 0) {
535
- childLogger.warn("no ops to bundle");
536
- this.markWalletProcessed(wallet);
537
- return compressedOps.map((compressedOp) => {
538
- return {
539
- status: "failure",
540
- error: {
541
- entryPoint,
542
- userOpHash: getUserOperationHash(compressedOp.inflatedOp, entryPoint, this.walletClient.chain.id),
543
- userOperation: compressedOp,
544
- reason: "INTERNAL FAILURE"
545
- }
546
- };
547
- });
548
- }
549
- // if not all succeeded, return error
550
- if (simulatedOps.some((simulatedOp) => simulatedOp.reason !== undefined)) {
551
- childLogger.warn("some ops failed simulation");
552
- this.markWalletProcessed(wallet);
553
- return simulatedOps.map((simulatedOp) => {
554
- return {
555
- status: "failure",
556
- error: {
557
- entryPoint,
558
- userOpHash: simulatedOp.owh.userOperationHash,
559
- userOperation: simulatedOp.owh.mempoolUserOperation,
560
- reason: simulatedOp.reason
561
- }
562
- };
563
- });
564
- }
565
- const opsToBundle = simulatedOps
566
- .filter((simulatedOp) => simulatedOp.reason === undefined)
567
- .map((simulatedOp) => simulatedOp.owh);
568
- let txHash;
569
- try {
570
- const gasOptions = this.legacyTransactions
571
- ? {
572
- gasPrice: gasPriceParameters.maxFeePerGas
573
- }
574
- : {
575
- maxFeePerGas: gasPriceParameters.maxFeePerGas,
576
- maxPriorityFeePerGas: gasPriceParameters.maxPriorityFeePerGas
577
- };
578
- // need to use sendTransaction to target BundleBulker's fallback
579
- txHash = await this.walletClient.sendTransaction({
580
- account: wallet,
581
- to: compressionHandler.bundleBulkerAddress,
582
- data: createCompressedCalldata(compressedOps, compressionHandler.perOpInflatorId),
583
- gas: gasLimit,
584
- nonce: nonce,
585
- ...gasOptions
586
- });
587
- }
588
- catch (err) {
589
- sentry.captureException(err);
590
- childLogger.error({ error: JSON.stringify(err) }, "error submitting bundle transaction");
591
- this.markWalletProcessed(wallet);
592
- return opsToBundle.map((op) => {
593
- return {
594
- status: "failure",
595
- error: {
596
- entryPoint,
597
- userOpHash: op.userOperationHash,
598
- userOperation: op.mempoolUserOperation,
599
- reason: "INTERNAL FAILURE"
600
- }
601
- };
602
- });
603
- }
604
- const userOperationInfos = opsToBundle.map((owh) => {
605
- return {
606
- entryPoint,
607
- mempoolUserOperation: owh.mempoolUserOperation,
608
- userOperationHash: owh.userOperationHash,
609
- lastReplaced: Date.now(),
610
- firstSubmitted: Date.now()
611
- };
612
- });
613
- const transactionInfo = {
614
- entryPoint,
615
- isVersion06: true, //TODO: compressed bundles are always v06
616
- transactionType: "compressed",
617
- transactionHash: txHash,
618
- previousTransactionHashes: [],
619
- transactionRequest: {
620
- to: compressionHandler.bundleBulkerAddress,
621
- data: createCompressedCalldata(compressedOps, compressionHandler.perOpInflatorId),
622
- gas: gasLimit,
623
- account: wallet,
624
- chain: this.walletClient.chain,
625
- maxFeePerGas: gasPriceParameters.maxFeePerGas,
626
- maxPriorityFeePerGas: gasPriceParameters.maxPriorityFeePerGas,
627
- nonce: nonce
628
- },
629
- executor: wallet,
630
- userOperationInfos,
631
- lastReplaced: Date.now(),
632
- firstSubmitted: Date.now(),
633
- timesPotentiallyIncluded: 0
634
- };
635
- const userOperationResults = simulatedOpsToResults(simulatedOps, transactionInfo);
636
- childLogger.info({
637
- txHash,
638
- opHashes: opsToBundle.map((owh) => owh.userOperationHash)
639
- }, "submitted bundle transaction");
640
- return userOperationResults;
641
- }
642
- }
643
- //# sourceMappingURL=executor.js.map