@pimlico/alto 0.0.0-staging.20240606T101741 → 0.0.0-staging.20240606T103333

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 (220) hide show
  1. package/esm/cli/alto.d.ts +6 -0
  2. package/esm/cli/alto.js +92 -0
  3. package/esm/cli/alto.js.map +1 -0
  4. package/esm/cli/config/bundler.d.ts +391 -0
  5. package/esm/cli/config/bundler.js +132 -0
  6. package/esm/cli/config/bundler.js.map +1 -0
  7. package/esm/cli/config/index.d.ts +3 -0
  8. package/esm/cli/config/index.js +3 -0
  9. package/esm/cli/config/index.js.map +1 -0
  10. package/esm/cli/config/options.d.ts +11 -0
  11. package/esm/cli/config/options.js +336 -0
  12. package/esm/cli/config/options.js.map +1 -0
  13. package/esm/cli/customTransport.d.ts +14 -0
  14. package/esm/cli/customTransport.js +53 -0
  15. package/esm/cli/customTransport.js.map +1 -0
  16. package/esm/cli/handler.d.ts +3 -0
  17. package/esm/cli/handler.js +116 -0
  18. package/esm/cli/handler.js.map +1 -0
  19. package/esm/cli/index.d.ts +4 -0
  20. package/esm/cli/index.js +4 -0
  21. package/esm/cli/index.js.map +1 -0
  22. package/esm/cli/instrumentation.d.ts +2 -0
  23. package/esm/cli/instrumentation.js +39 -0
  24. package/esm/cli/instrumentation.js.map +1 -0
  25. package/esm/cli/setupServer.d.ts +17 -0
  26. package/esm/cli/setupServer.js +155 -0
  27. package/esm/cli/setupServer.js.map +1 -0
  28. package/esm/cli/util.d.ts +22 -0
  29. package/esm/cli/util.js +30 -0
  30. package/esm/cli/util.js.map +1 -0
  31. package/esm/executor/executor.d.ts +54 -0
  32. package/esm/executor/executor.js +637 -0
  33. package/esm/executor/executor.js.map +1 -0
  34. package/esm/executor/executorManager.d.ts +34 -0
  35. package/esm/executor/executorManager.js +401 -0
  36. package/esm/executor/executorManager.js.map +1 -0
  37. package/esm/executor/index.d.ts +5 -0
  38. package/esm/executor/index.js +5 -0
  39. package/esm/executor/index.js.map +1 -0
  40. package/esm/executor/senderManager.d.ts +17 -0
  41. package/esm/executor/senderManager.js +160 -0
  42. package/esm/executor/senderManager.js.map +1 -0
  43. package/esm/executor/test/utils.d.ts +13 -0
  44. package/esm/executor/test/utils.js +75 -0
  45. package/esm/executor/test/utils.js.map +1 -0
  46. package/esm/executor/utils.d.ts +32 -0
  47. package/esm/executor/utils.js +239 -0
  48. package/esm/executor/utils.js.map +1 -0
  49. package/esm/index.d.ts +2 -0
  50. package/esm/index.js +2 -0
  51. package/esm/index.js.map +1 -0
  52. package/esm/mempool/index.d.ts +5 -0
  53. package/esm/mempool/index.js +5 -0
  54. package/esm/mempool/index.js.map +1 -0
  55. package/esm/mempool/mempool.d.ts +64 -0
  56. package/esm/mempool/mempool.js +489 -0
  57. package/esm/mempool/mempool.js.map +1 -0
  58. package/esm/mempool/monitoring.d.ts +10 -0
  59. package/esm/mempool/monitoring.js +34 -0
  60. package/esm/mempool/monitoring.js.map +1 -0
  61. package/esm/mempool/nullMempool.d.ts +15 -0
  62. package/esm/mempool/nullMempool.js +36 -0
  63. package/esm/mempool/nullMempool.js.map +1 -0
  64. package/esm/mempool/reputationManager.d.ts +115 -0
  65. package/esm/mempool/reputationManager.js +397 -0
  66. package/esm/mempool/reputationManager.js.map +1 -0
  67. package/esm/mempool/store.d.ts +22 -0
  68. package/esm/mempool/store.js +123 -0
  69. package/esm/mempool/store.js.map +1 -0
  70. package/esm/rpc/EntryPointSimulationsV07.d.ts +58 -0
  71. package/esm/rpc/EntryPointSimulationsV07.js +407 -0
  72. package/esm/rpc/EntryPointSimulationsV07.js.map +1 -0
  73. package/esm/rpc/ExecuteSimulator.d.ts +37 -0
  74. package/esm/rpc/ExecuteSimulator.js +48 -0
  75. package/esm/rpc/ExecuteSimulator.js.map +1 -0
  76. package/esm/rpc/gasEstimation.d.ts +17 -0
  77. package/esm/rpc/gasEstimation.js +410 -0
  78. package/esm/rpc/gasEstimation.js.map +1 -0
  79. package/esm/rpc/index.d.ts +5 -0
  80. package/esm/rpc/index.js +5 -0
  81. package/esm/rpc/index.js.map +1 -0
  82. package/esm/rpc/nonceQueuer.d.ts +25 -0
  83. package/esm/rpc/nonceQueuer.js +135 -0
  84. package/esm/rpc/nonceQueuer.js.map +1 -0
  85. package/esm/rpc/rpcHandler.d.ts +64 -0
  86. package/esm/rpc/rpcHandler.js +727 -0
  87. package/esm/rpc/rpcHandler.js.map +1 -0
  88. package/esm/rpc/server.d.ts +31 -0
  89. package/esm/rpc/server.js +238 -0
  90. package/esm/rpc/server.js.map +1 -0
  91. package/esm/rpc/validation/BundlerCollectorTracerV06.d.ts +102 -0
  92. package/esm/rpc/validation/BundlerCollectorTracerV06.js +255 -0
  93. package/esm/rpc/validation/BundlerCollectorTracerV06.js.map +1 -0
  94. package/esm/rpc/validation/BundlerCollectorTracerV07.d.ts +102 -0
  95. package/esm/rpc/validation/BundlerCollectorTracerV07.js +254 -0
  96. package/esm/rpc/validation/BundlerCollectorTracerV07.js.map +1 -0
  97. package/esm/rpc/validation/SafeValidator.d.ts +35 -0
  98. package/esm/rpc/validation/SafeValidator.js +487 -0
  99. package/esm/rpc/validation/SafeValidator.js.map +1 -0
  100. package/esm/rpc/validation/TracerResultParserV06.d.ts +13 -0
  101. package/esm/rpc/validation/TracerResultParserV06.js +578 -0
  102. package/esm/rpc/validation/TracerResultParserV06.js.map +1 -0
  103. package/esm/rpc/validation/TracerResultParserV07.d.ts +33 -0
  104. package/esm/rpc/validation/TracerResultParserV07.js +557 -0
  105. package/esm/rpc/validation/TracerResultParserV07.js.map +1 -0
  106. package/esm/rpc/validation/UnsafeValidator.d.ts +63 -0
  107. package/esm/rpc/validation/UnsafeValidator.js +257 -0
  108. package/esm/rpc/validation/UnsafeValidator.js.map +1 -0
  109. package/esm/rpc/validation/index.d.ts +3 -0
  110. package/esm/rpc/validation/index.js +3 -0
  111. package/esm/rpc/validation/index.js.map +1 -0
  112. package/esm/rpc/validation/tracer.d.ts +122 -0
  113. package/esm/rpc/validation/tracer.js +82 -0
  114. package/esm/rpc/validation/tracer.js.map +1 -0
  115. package/esm/types/contracts/BundleBulker.d.ts +120 -0
  116. package/esm/types/contracts/BundleBulker.js +157 -0
  117. package/esm/types/contracts/BundleBulker.js.map +1 -0
  118. package/esm/types/contracts/CallEngine.d.ts +28 -0
  119. package/esm/types/contracts/CallEngine.js +37 -0
  120. package/esm/types/contracts/CallEngine.js.map +1 -0
  121. package/esm/types/contracts/CodeHashGetter.d.ts +37 -0
  122. package/esm/types/contracts/CodeHashGetter.js +45 -0
  123. package/esm/types/contracts/CodeHashGetter.js.map +1 -0
  124. package/esm/types/contracts/EntryPoint.d.ts +1789 -0
  125. package/esm/types/contracts/EntryPoint.js +2304 -0
  126. package/esm/types/contracts/EntryPoint.js.map +1 -0
  127. package/esm/types/contracts/EntryPointSimulations.d.ts +153 -0
  128. package/esm/types/contracts/EntryPointSimulations.js +15 -0
  129. package/esm/types/contracts/EntryPointSimulations.js.map +1 -0
  130. package/esm/types/contracts/IOpInflator.d.ts +61 -0
  131. package/esm/types/contracts/IOpInflator.js +80 -0
  132. package/esm/types/contracts/IOpInflator.js.map +1 -0
  133. package/esm/types/contracts/IPaymaster.d.ts +3 -0
  134. package/esm/types/contracts/IPaymaster.js +117 -0
  135. package/esm/types/contracts/IPaymaster.js.map +1 -0
  136. package/esm/types/contracts/Inflator.d.ts +65 -0
  137. package/esm/types/contracts/Inflator.js +84 -0
  138. package/esm/types/contracts/Inflator.js.map +1 -0
  139. package/esm/types/contracts/PerOpInflator.d.ts +176 -0
  140. package/esm/types/contracts/PerOpInflator.js +229 -0
  141. package/esm/types/contracts/PerOpInflator.js.map +1 -0
  142. package/esm/types/contracts/PimlicoEntryPointSimulations.d.ts +23 -0
  143. package/esm/types/contracts/PimlicoEntryPointSimulations.js +33 -0
  144. package/esm/types/contracts/PimlicoEntryPointSimulations.js.map +1 -0
  145. package/esm/types/contracts/SenderCreator.d.ts +4 -0
  146. package/esm/types/contracts/SenderCreator.js +23 -0
  147. package/esm/types/contracts/SenderCreator.js.map +1 -0
  148. package/esm/types/contracts/SimpleAccountFactory.d.ts +57 -0
  149. package/esm/types/contracts/SimpleAccountFactory.js +76 -0
  150. package/esm/types/contracts/SimpleAccountFactory.js.map +1 -0
  151. package/esm/types/contracts/TestOpcodesAccount.d.ts +4 -0
  152. package/esm/types/contracts/TestOpcodesAccount.js +281 -0
  153. package/esm/types/contracts/TestOpcodesAccount.js.map +1 -0
  154. package/esm/types/contracts/TestOpcodesAccountFactory.d.ts +4 -0
  155. package/esm/types/contracts/TestOpcodesAccountFactory.js +23 -0
  156. package/esm/types/contracts/TestOpcodesAccountFactory.js.map +1 -0
  157. package/esm/types/contracts/TestStorageAccount.d.ts +4 -0
  158. package/esm/types/contracts/TestStorageAccount.js +313 -0
  159. package/esm/types/contracts/TestStorageAccount.js.map +1 -0
  160. package/esm/types/contracts/index.d.ts +17 -0
  161. package/esm/types/contracts/index.js +17 -0
  162. package/esm/types/contracts/index.js.map +1 -0
  163. package/esm/types/gasPrice.d.ts +110 -0
  164. package/esm/types/gasPrice.js +52 -0
  165. package/esm/types/gasPrice.js.map +1 -0
  166. package/esm/types/index.d.ts +11 -0
  167. package/esm/types/index.js +11 -0
  168. package/esm/types/index.js.map +1 -0
  169. package/esm/types/interfaces.d.ts +26 -0
  170. package/esm/types/interfaces.js +2 -0
  171. package/esm/types/interfaces.js.map +1 -0
  172. package/esm/types/mempool.d.ts +78 -0
  173. package/esm/types/mempool.js +16 -0
  174. package/esm/types/mempool.js.map +1 -0
  175. package/esm/types/schemas.d.ts +4791 -0
  176. package/esm/types/schemas.js +497 -0
  177. package/esm/types/schemas.js.map +1 -0
  178. package/esm/types/test/validationTestErrors.d.ts +3 -0
  179. package/esm/types/test/validationTestErrors.js +229 -0
  180. package/esm/types/test/validationTestErrors.js.map +1 -0
  181. package/esm/types/utils.d.ts +24 -0
  182. package/esm/types/utils.js +30 -0
  183. package/esm/types/utils.js.map +1 -0
  184. package/esm/types/validation.d.ts +14327 -0
  185. package/esm/types/validation.js +304 -0
  186. package/esm/types/validation.js.map +1 -0
  187. package/esm/utils/bigInt.d.ts +3 -0
  188. package/esm/utils/bigInt.js +9 -0
  189. package/esm/utils/bigInt.js.map +1 -0
  190. package/esm/utils/compressionHandler.d.ts +11 -0
  191. package/esm/utils/compressionHandler.js +39 -0
  192. package/esm/utils/compressionHandler.js.map +1 -0
  193. package/esm/utils/gasPriceManager.d.ts +34 -0
  194. package/esm/utils/gasPriceManager.js +338 -0
  195. package/esm/utils/gasPriceManager.js.map +1 -0
  196. package/esm/utils/helpers.d.ts +4 -0
  197. package/esm/utils/helpers.js +13 -0
  198. package/esm/utils/helpers.js.map +1 -0
  199. package/esm/utils/index.d.ts +11 -0
  200. package/esm/utils/index.js +10 -0
  201. package/esm/utils/index.js.map +1 -0
  202. package/esm/utils/logger.d.ts +6 -0
  203. package/esm/utils/logger.js +76 -0
  204. package/esm/utils/logger.js.map +1 -0
  205. package/esm/utils/metrics.d.ts +22 -0
  206. package/esm/utils/metrics.js +150 -0
  207. package/esm/utils/metrics.js.map +1 -0
  208. package/esm/utils/rpc-reply.d.ts +17 -0
  209. package/esm/utils/rpc-reply.js +41 -0
  210. package/esm/utils/rpc-reply.js.map +1 -0
  211. package/esm/utils/test.d.ts +17 -0
  212. package/esm/utils/test.js +130 -0
  213. package/esm/utils/test.js.map +1 -0
  214. package/esm/utils/userop.d.ts +49 -0
  215. package/esm/utils/userop.js +408 -0
  216. package/esm/utils/userop.js.map +1 -0
  217. package/esm/utils/validation.d.ts +65 -0
  218. package/esm/utils/validation.js +461 -0
  219. package/esm/utils/validation.js.map +1 -0
  220. package/package.json +70 -66
@@ -0,0 +1,34 @@
1
+ import type { Metrics, Logger, GasPriceManager } from "../utils/index.js";
2
+ import type { InterfaceReputationManager, MemoryMempool, Monitor } from "../mempool/index.js";
3
+ import { type BundlingMode, type MempoolUserOperation, type TransactionInfo } from "../types/index.js";
4
+ import type { Address, Block, Chain, Hash, PublicClient, Transport } from "viem";
5
+ import type { Executor } from "./executor.js";
6
+ export declare class ExecutorManager {
7
+ private entryPoints;
8
+ private executor;
9
+ private mempool;
10
+ private monitor;
11
+ private publicClient;
12
+ private pollingInterval;
13
+ private logger;
14
+ private metrics;
15
+ private reputationManager;
16
+ private unWatch;
17
+ private currentlyHandlingBlock;
18
+ private timer?;
19
+ private bundlerFrequency;
20
+ private maxGasLimitPerBundle;
21
+ private gasPriceManager;
22
+ constructor(executor: Executor, entryPoints: Address[], mempool: MemoryMempool, monitor: Monitor, reputationManager: InterfaceReputationManager, publicClient: PublicClient<Transport, Chain>, pollingInterval: number, logger: Logger, metrics: Metrics, bundleMode: BundlingMode, bundlerFrequency: number, maxGasLimitPerBundle: bigint, gasPriceManager: GasPriceManager);
23
+ setBundlingMode(bundleMode: BundlingMode): void;
24
+ bundleNow(): Promise<Hash[]>;
25
+ sendToExecutor(entryPoint: Address, mempoolOps: MempoolUserOperation[]): Promise<`0x${string}` | undefined>;
26
+ bundle(): Promise<void>;
27
+ startWatchingBlocks(handleBlock: (block: Block) => void): void;
28
+ stopWatchingBlocks(): void;
29
+ private refreshTransactionStatus;
30
+ refreshUserOperationStatuses(): Promise<void>;
31
+ handleBlock(block: Block): Promise<void>;
32
+ replaceTransaction(txInfo: TransactionInfo, reason: string): Promise<void>;
33
+ }
34
+ //# sourceMappingURL=executorManager.d.ts.map
@@ -0,0 +1,401 @@
1
+ import { deriveUserOperation, isCompressedType } from "../types/index.js";
2
+ import { transactionIncluded } from "../utils/index.js";
3
+ function getTransactionsFromUserOperationEntries(entries) {
4
+ return Array.from(new Set(entries.map((entry) => {
5
+ return entry.transactionInfo;
6
+ })));
7
+ }
8
+ export class ExecutorManager {
9
+ entryPoints;
10
+ executor;
11
+ mempool;
12
+ monitor;
13
+ publicClient;
14
+ pollingInterval;
15
+ logger;
16
+ metrics;
17
+ reputationManager;
18
+ unWatch;
19
+ currentlyHandlingBlock = false;
20
+ timer;
21
+ bundlerFrequency;
22
+ maxGasLimitPerBundle;
23
+ gasPriceManager;
24
+ constructor(executor, entryPoints, mempool, monitor, reputationManager, publicClient, pollingInterval, logger, metrics, bundleMode, bundlerFrequency, maxGasLimitPerBundle, gasPriceManager) {
25
+ this.entryPoints = entryPoints;
26
+ this.reputationManager = reputationManager;
27
+ this.executor = executor;
28
+ this.mempool = mempool;
29
+ this.monitor = monitor;
30
+ this.publicClient = publicClient;
31
+ this.pollingInterval = pollingInterval;
32
+ this.logger = logger;
33
+ this.metrics = metrics;
34
+ this.bundlerFrequency = bundlerFrequency;
35
+ this.maxGasLimitPerBundle = maxGasLimitPerBundle;
36
+ this.gasPriceManager = gasPriceManager;
37
+ if (bundleMode === "auto") {
38
+ this.timer = setInterval(async () => {
39
+ await this.bundle();
40
+ }, bundlerFrequency);
41
+ }
42
+ }
43
+ setBundlingMode(bundleMode) {
44
+ if (bundleMode === "auto" && !this.timer) {
45
+ this.timer = setInterval(async () => {
46
+ await this.bundle();
47
+ }, this.bundlerFrequency);
48
+ }
49
+ else if (bundleMode === "manual" && this.timer) {
50
+ clearInterval(this.timer);
51
+ this.timer = undefined;
52
+ }
53
+ }
54
+ async bundleNow() {
55
+ const ops = await this.mempool.process(this.maxGasLimitPerBundle, 1);
56
+ if (ops.length === 0) {
57
+ throw new Error("no ops to bundle");
58
+ }
59
+ const opEntryPointMap = new Map();
60
+ for (const op of ops) {
61
+ if (!opEntryPointMap.has(op.entryPoint)) {
62
+ opEntryPointMap.set(op.entryPoint, []);
63
+ }
64
+ opEntryPointMap.get(op.entryPoint)?.push(op.mempoolUserOperation);
65
+ }
66
+ const txHashes = [];
67
+ await Promise.all(this.entryPoints.map(async (entryPoint) => {
68
+ const ops = opEntryPointMap.get(entryPoint);
69
+ if (ops) {
70
+ const txHash = await this.sendToExecutor(entryPoint, ops);
71
+ if (!txHash) {
72
+ throw new Error("no tx hash");
73
+ }
74
+ txHashes.push(txHash);
75
+ }
76
+ else {
77
+ this.logger.warn({ entryPoint }, "no user operations for entry point");
78
+ }
79
+ }));
80
+ return txHashes;
81
+ }
82
+ async sendToExecutor(entryPoint, mempoolOps) {
83
+ const ops = mempoolOps
84
+ .filter((op) => !isCompressedType(op))
85
+ .map((op) => op);
86
+ const compressedOps = mempoolOps
87
+ .filter((op) => isCompressedType(op))
88
+ .map((op) => op);
89
+ const bundles = [];
90
+ if (ops.length > 0) {
91
+ bundles.push(await this.executor.bundle(entryPoint, ops));
92
+ }
93
+ if (compressedOps.length > 0) {
94
+ bundles.push(await this.executor.bundleCompressed(entryPoint, compressedOps));
95
+ }
96
+ for (const bundle of bundles) {
97
+ const isBundleSuccess = bundle.every((result) => result.status === "success");
98
+ if (isBundleSuccess) {
99
+ this.metrics.bundlesSubmitted
100
+ .labels({ status: "success" })
101
+ .inc();
102
+ }
103
+ else {
104
+ this.metrics.bundlesSubmitted.labels({ status: "failed" }).inc();
105
+ }
106
+ }
107
+ const results = bundles.flat();
108
+ const filteredOutOps = mempoolOps.length - results.length;
109
+ if (filteredOutOps > 0) {
110
+ this.logger.debug({ filteredOutOps }, "user operations filtered out");
111
+ this.metrics.userOperationsSubmitted
112
+ .labels({ status: "filtered" })
113
+ .inc(filteredOutOps);
114
+ }
115
+ let txHash = undefined;
116
+ for (const result of results) {
117
+ if (result.status === "success") {
118
+ const res = result.value;
119
+ this.mempool.markSubmitted(res.userOperation.userOperationHash, res.transactionInfo);
120
+ // this.monitoredTransactions.set(result.transactionInfo.transactionHash, result.transactionInfo)
121
+ this.monitor.setUserOperationStatus(res.userOperation.userOperationHash, {
122
+ status: "submitted",
123
+ transactionHash: res.transactionInfo.transactionHash
124
+ });
125
+ txHash = res.transactionInfo.transactionHash;
126
+ this.startWatchingBlocks(this.handleBlock.bind(this));
127
+ this.metrics.userOperationsSubmitted
128
+ .labels({ status: "success" })
129
+ .inc();
130
+ }
131
+ if (result.status === "failure") {
132
+ this.mempool.removeProcessing(result.error.userOpHash);
133
+ this.monitor.setUserOperationStatus(result.error.userOpHash, {
134
+ status: "rejected",
135
+ transactionHash: null
136
+ });
137
+ this.logger.warn({
138
+ userOpHash: result.error.userOpHash,
139
+ reason: result.error.reason
140
+ }, "user operation rejected");
141
+ this.metrics.userOperationsSubmitted
142
+ .labels({ status: "failed" })
143
+ .inc();
144
+ }
145
+ if (result.status === "resubmit") {
146
+ this.logger.info({
147
+ userOpHash: result.info.userOpHash,
148
+ reason: result.info.reason
149
+ }, "resubmitting user operation");
150
+ this.mempool.removeProcessing(result.info.userOpHash);
151
+ this.mempool.add(result.info.userOperation, result.info.entryPoint);
152
+ this.metrics.userOperationsResubmitted.inc();
153
+ }
154
+ }
155
+ return txHash;
156
+ }
157
+ async bundle() {
158
+ const opsToBundle = [];
159
+ while (true) {
160
+ const ops = await this.mempool.process(5000000n, 1);
161
+ if (ops?.length > 0) {
162
+ opsToBundle.push(ops);
163
+ }
164
+ else {
165
+ break;
166
+ }
167
+ }
168
+ if (opsToBundle.length === 0) {
169
+ return;
170
+ }
171
+ await Promise.all(opsToBundle.map(async (ops) => {
172
+ const opEntryPointMap = new Map();
173
+ for (const op of ops) {
174
+ if (!opEntryPointMap.has(op.entryPoint)) {
175
+ opEntryPointMap.set(op.entryPoint, []);
176
+ }
177
+ opEntryPointMap
178
+ .get(op.entryPoint)
179
+ ?.push(op.mempoolUserOperation);
180
+ }
181
+ await Promise.all(this.entryPoints.map(async (entryPoint) => {
182
+ const userOperations = opEntryPointMap.get(entryPoint);
183
+ if (userOperations) {
184
+ await this.sendToExecutor(entryPoint, userOperations);
185
+ }
186
+ else {
187
+ this.logger.warn({ entryPoint }, "no user operations for entry point");
188
+ }
189
+ }));
190
+ }));
191
+ }
192
+ startWatchingBlocks(handleBlock) {
193
+ if (this.unWatch) {
194
+ return;
195
+ }
196
+ this.unWatch = this.publicClient.watchBlocks({
197
+ onBlock: handleBlock,
198
+ // onBlock: async (block) => {
199
+ // // Use an arrow function to ensure correct binding of `this`
200
+ // this.checkAndReplaceTransactions(block)
201
+ // .then(() => {
202
+ // this.logger.trace("block handled")
203
+ // // Handle the resolution of the promise here, if needed
204
+ // })
205
+ // .catch((error) => {
206
+ // // Handle any errors that occur during the execution of the promise
207
+ // this.logger.error({ error }, "error while handling block")
208
+ // })
209
+ // },
210
+ onError: (error) => {
211
+ this.logger.error({ error }, "error while watching blocks");
212
+ },
213
+ emitMissed: false,
214
+ includeTransactions: false,
215
+ pollingInterval: this.pollingInterval
216
+ });
217
+ this.logger.debug("started watching blocks");
218
+ }
219
+ stopWatchingBlocks() {
220
+ if (this.unWatch) {
221
+ this.logger.debug("stopped watching blocks");
222
+ this.unWatch();
223
+ this.unWatch = undefined;
224
+ }
225
+ }
226
+ async refreshTransactionStatus(entryPoint, transactionInfo) {
227
+ const hashesToCheck = [
228
+ transactionInfo.transactionHash,
229
+ ...transactionInfo.previousTransactionHashes
230
+ ];
231
+ const opInfos = transactionInfo.userOperationInfos;
232
+ // const opHashes = transactionInfo.userOperationInfos.map((opInfo) => opInfo.userOperationHash)
233
+ const transactionStatuses = await Promise.all(hashesToCheck.map(async (hash) => {
234
+ return {
235
+ hash: hash,
236
+ transactionStatuses: await transactionIncluded(transactionInfo.isVersion06, hash, this.publicClient, entryPoint)
237
+ };
238
+ }));
239
+ const status = transactionStatuses.find((status) => status.transactionStatuses.status === "included" ||
240
+ status.transactionStatuses.status === "failed" ||
241
+ status.transactionStatuses.status === "reverted");
242
+ if (!status) {
243
+ opInfos.map((info) => {
244
+ this.logger.trace({
245
+ userOpHash: info.userOperationHash,
246
+ transactionHash: transactionInfo.transactionHash
247
+ }, "user op still pending");
248
+ });
249
+ return;
250
+ }
251
+ this.metrics.userOperationsOnChain
252
+ .labels({ status: status.transactionStatuses.status })
253
+ .inc(opInfos.length);
254
+ if (status.transactionStatuses.status === "included") {
255
+ opInfos.map((info) => {
256
+ this.metrics.userOperationInclusionDuration.observe((Date.now() - info.firstSubmitted) / 1000);
257
+ this.reputationManager.updateUserOperationIncludedStatus(deriveUserOperation(info.mempoolUserOperation), info.entryPoint, status.transactionStatuses[info.userOperationHash]
258
+ .accountDeployed);
259
+ this.mempool.removeSubmitted(info.userOperationHash);
260
+ this.monitor.setUserOperationStatus(info.userOperationHash, {
261
+ status: "included",
262
+ transactionHash: status.hash
263
+ });
264
+ this.logger.info({
265
+ userOpHash: info.userOperationHash,
266
+ transactionHash: status.hash
267
+ }, "user op included");
268
+ });
269
+ this.executor.markWalletProcessed(transactionInfo.executor);
270
+ }
271
+ else if (status.transactionStatuses.status === "failed" ||
272
+ status.transactionStatuses.status === "reverted") {
273
+ opInfos.map((info) => {
274
+ this.mempool.removeSubmitted(info.userOperationHash);
275
+ this.monitor.setUserOperationStatus(info.userOperationHash, {
276
+ status: "rejected",
277
+ transactionHash: status.hash
278
+ });
279
+ this.logger.info({
280
+ userOpHash: info.userOperationHash,
281
+ transactionHash: status.hash
282
+ }, "user op rejected");
283
+ });
284
+ this.executor.markWalletProcessed(transactionInfo.executor);
285
+ }
286
+ }
287
+ async refreshUserOperationStatuses() {
288
+ const ops = this.mempool.dumpSubmittedOps();
289
+ const opEntryPointMap = new Map();
290
+ for (const op of ops) {
291
+ if (!opEntryPointMap.has(op.userOperation.entryPoint)) {
292
+ opEntryPointMap.set(op.userOperation.entryPoint, []);
293
+ }
294
+ opEntryPointMap.get(op.userOperation.entryPoint)?.push(op);
295
+ }
296
+ await Promise.all(this.entryPoints.map(async (entryPoint) => {
297
+ const ops = opEntryPointMap.get(entryPoint);
298
+ if (ops) {
299
+ const txs = getTransactionsFromUserOperationEntries(ops);
300
+ await Promise.all(txs.map(async (txInfo) => {
301
+ await this.refreshTransactionStatus(entryPoint, txInfo);
302
+ }));
303
+ }
304
+ else {
305
+ this.logger.warn({ entryPoint }, "no user operations for entry point");
306
+ }
307
+ }));
308
+ }
309
+ async handleBlock(block) {
310
+ if (this.currentlyHandlingBlock) {
311
+ return;
312
+ }
313
+ this.currentlyHandlingBlock = true;
314
+ this.logger.debug({ blockNumber: block.number }, "handling block");
315
+ const submittedEntries = this.mempool.dumpSubmittedOps();
316
+ if (submittedEntries.length === 0) {
317
+ this.stopWatchingBlocks();
318
+ this.currentlyHandlingBlock = false;
319
+ return;
320
+ }
321
+ // refresh op statuses
322
+ await this.refreshUserOperationStatuses();
323
+ // for all still not included check if needs to be replaced (based on gas price)
324
+ const gasPriceParameters = await this.gasPriceManager.getGasPrice();
325
+ this.logger.trace({ gasPriceParameters }, "fetched gas price parameters");
326
+ const transactionInfos = getTransactionsFromUserOperationEntries(this.mempool.dumpSubmittedOps());
327
+ await Promise.all(transactionInfos.map(async (txInfo) => {
328
+ if (txInfo.transactionRequest.maxFeePerGas >=
329
+ gasPriceParameters.maxFeePerGas &&
330
+ txInfo.transactionRequest.maxPriorityFeePerGas >=
331
+ gasPriceParameters.maxPriorityFeePerGas) {
332
+ return;
333
+ }
334
+ await this.replaceTransaction(txInfo, "gas_price");
335
+ }));
336
+ // for any left check if enough time has passed, if so replace
337
+ const transactionInfos2 = getTransactionsFromUserOperationEntries(this.mempool.dumpSubmittedOps());
338
+ await Promise.all(transactionInfos2.map(async (txInfo) => {
339
+ if (Date.now() - txInfo.lastReplaced < 5 * 60 * 1000) {
340
+ return;
341
+ }
342
+ await this.replaceTransaction(txInfo, "stuck");
343
+ }));
344
+ this.currentlyHandlingBlock = false;
345
+ }
346
+ async replaceTransaction(txInfo, reason) {
347
+ let replaceResult = undefined;
348
+ try {
349
+ replaceResult = await this.executor.replaceTransaction(txInfo);
350
+ }
351
+ finally {
352
+ this.metrics.replacedTransactions
353
+ .labels({ reason, status: replaceResult?.status || "failed" })
354
+ .inc();
355
+ }
356
+ if (replaceResult.status === "failed") {
357
+ txInfo.userOperationInfos.map((opInfo) => {
358
+ this.mempool.removeSubmitted(opInfo.userOperationHash);
359
+ });
360
+ this.logger.warn({ oldTxHash: txInfo.transactionHash, reason }, "failed to replace transaction");
361
+ return;
362
+ }
363
+ if (replaceResult.status === "potentially_already_included") {
364
+ this.logger.info({ oldTxHash: txInfo.transactionHash, reason }, "transaction potentially already included");
365
+ txInfo.timesPotentiallyIncluded += 1;
366
+ if (txInfo.timesPotentiallyIncluded >= 3) {
367
+ txInfo.userOperationInfos.map((opInfo) => {
368
+ this.mempool.removeSubmitted(opInfo.userOperationHash);
369
+ });
370
+ this.executor.markWalletProcessed(txInfo.executor);
371
+ this.logger.warn({ oldTxHash: txInfo.transactionHash, reason }, "transaction potentially already included too many times, removing");
372
+ }
373
+ return;
374
+ }
375
+ const newTxInfo = replaceResult.transactionInfo;
376
+ const missingOps = txInfo.userOperationInfos.filter((info) => !newTxInfo.userOperationInfos
377
+ .map((ni) => ni.userOperationHash)
378
+ .includes(info.userOperationHash));
379
+ const matchingOps = txInfo.userOperationInfos.filter((info) => newTxInfo.userOperationInfos
380
+ .map((ni) => ni.userOperationHash)
381
+ .includes(info.userOperationHash));
382
+ matchingOps.map((opInfo) => {
383
+ this.mempool.replaceSubmitted(opInfo, newTxInfo);
384
+ });
385
+ missingOps.map((opInfo) => {
386
+ this.mempool.removeSubmitted(opInfo.userOperationHash);
387
+ this.logger.warn({
388
+ oldTxHash: txInfo.transactionHash,
389
+ newTxHash: newTxInfo.transactionHash,
390
+ reason
391
+ }, "missing op in new tx");
392
+ });
393
+ this.logger.info({
394
+ oldTxHash: txInfo.transactionHash,
395
+ newTxHash: newTxInfo.transactionHash,
396
+ reason
397
+ }, "replaced transaction");
398
+ return;
399
+ }
400
+ }
401
+ //# sourceMappingURL=executorManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executorManager.js","sourceRoot":"","sources":["../../executor/executorManager.ts"],"names":[],"mappings":"AAMA,OAAO,EAOH,mBAAmB,EACnB,gBAAgB,EAInB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAYjD,SAAS,uCAAuC,CAC5C,OAAiC;IAEjC,OAAO,KAAK,CAAC,IAAI,CACb,IAAI,GAAG,CACH,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAClB,OAAO,KAAK,C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M,UAAU,GAAG,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAC/C,CAAC,IAAI,EAAE,EAAE,CACL,CAAC,SAAS,CAAC,kBAAkB;aACxB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,iBAAiB,CAAC;aACjC,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAC5C,CAAA;QACD,MAAM,WAAW,GAAG,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAC1D,SAAS,CAAC,kBAAkB;aACvB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,iBAAiB,CAAC;aACjC,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,CACxC,CAAA;QAED,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YACvB,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;QACpD,CAAC,CAAC,CAAA;QAEF,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YACtB,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAA;YACtD,IAAI,CAAC,MAAM,CAAC,IAAI,CACZ;gBACI,SAAS,EAAE,MAAM,CAAC,eAAe;gBACjC,SAAS,EAAE,SAAS,CAAC,eAAe;gBACpC,MAAM;aACT,EACD,sBAAsB,CACzB,CAAA;QACL,CAAC,CAAC,CAAA;QAEF,IAAI,CAAC,MAAM,CAAC,IAAI,CACZ;YACI,SAAS,EAAE,MAAM,CAAC,eAAe;YACjC,SAAS,EAAE,SAAS,CAAC,eAAe;YACpC,MAAM;SACT,EACD,sBAAsB,CACzB,CAAA;QAED,OAAM;IACV,CAAC;CACJ"}
@@ -0,0 +1,5 @@
1
+ export * from "./senderManager.js";
2
+ export * from "./executor.js";
3
+ export * from "./executorManager.js";
4
+ export * from "./utils.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ export * from "./senderManager.js";
2
+ export * from "./executor.js";
3
+ export * from "./executorManager.js";
4
+ export * from "./utils.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../executor/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,SAAS,CAAA"}
@@ -0,0 +1,17 @@
1
+ import type { GasPriceManager, Logger, Metrics } from "../utils/index.js";
2
+ import { type Account, type Chain, type PublicClient, type Transport, type WalletClient } from "viem";
3
+ export declare class SenderManager {
4
+ wallets: Account[];
5
+ utilityAccount: Account | undefined;
6
+ availableWallets: Account[];
7
+ private logger;
8
+ private metrics;
9
+ private legacyTransactions;
10
+ private semaphore;
11
+ private gasPriceManager;
12
+ constructor(wallets: Account[], utilityAccount: Account | undefined, logger: Logger, metrics: Metrics, legacyTransactions: boolean, gasPriceManager: GasPriceManager, maxSigners?: number);
13
+ validateAndRefillWallets(publicClient: PublicClient, walletClient: WalletClient<Transport, Chain>, minBalance?: bigint): Promise<void>;
14
+ getWallet(): Promise<Account>;
15
+ pushWallet(wallet: Account): void;
16
+ }
17
+ //# sourceMappingURL=senderManager.d.ts.map
@@ -0,0 +1,160 @@
1
+ import { CallEngineAbi } from "../types/index.js";
2
+ import { Semaphore } from "async-mutex";
3
+ import { formatEther, getContract } from "viem";
4
+ const waitForTransactionReceipt = async (publicClient, tx) => {
5
+ try {
6
+ return await publicClient.waitForTransactionReceipt({ hash: tx });
7
+ }
8
+ catch {
9
+ return await waitForTransactionReceipt(publicClient, tx);
10
+ }
11
+ };
12
+ export class SenderManager {
13
+ wallets;
14
+ utilityAccount;
15
+ availableWallets;
16
+ logger;
17
+ metrics;
18
+ legacyTransactions;
19
+ semaphore;
20
+ gasPriceManager;
21
+ constructor(wallets, utilityAccount, logger, metrics, legacyTransactions, gasPriceManager, maxSigners) {
22
+ if (maxSigners !== undefined && wallets.length > maxSigners) {
23
+ this.wallets = wallets.slice(0, maxSigners);
24
+ this.availableWallets = wallets.slice(0, maxSigners);
25
+ }
26
+ else {
27
+ this.wallets = wallets;
28
+ this.availableWallets = wallets;
29
+ }
30
+ this.utilityAccount = utilityAccount;
31
+ this.logger = logger;
32
+ this.metrics = metrics;
33
+ this.legacyTransactions = legacyTransactions;
34
+ metrics.walletsAvailable.set(this.availableWallets.length);
35
+ metrics.walletsTotal.set(this.wallets.length);
36
+ this.semaphore = new Semaphore(this.availableWallets.length);
37
+ this.gasPriceManager = gasPriceManager;
38
+ }
39
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
40
+ async validateAndRefillWallets(publicClient, walletClient, minBalance) {
41
+ if (!(minBalance && this.utilityAccount)) {
42
+ return;
43
+ }
44
+ const utilityWalletBalance = await publicClient.getBalance({
45
+ address: this.utilityAccount.address
46
+ });
47
+ const balancesMissing = {};
48
+ const balanceRequestPromises = this.availableWallets.map(async (wallet) => {
49
+ const balance = await publicClient.getBalance({
50
+ address: wallet.address
51
+ });
52
+ if (balance < minBalance) {
53
+ const missingBalance = (minBalance * 6n) / 5n - balance;
54
+ balancesMissing[wallet.address] = missingBalance;
55
+ }
56
+ });
57
+ await Promise.all(balanceRequestPromises);
58
+ const totalBalanceMissing = Object.values(balancesMissing).reduce((a, b) => a + b, 0n);
59
+ if (utilityWalletBalance < (totalBalanceMissing * 11n) / 10n) {
60
+ this.logger.info({ balancesMissing, totalBalanceMissing }, "balances missing");
61
+ this.logger.error({
62
+ minBalance,
63
+ utilityWalletBalance,
64
+ totalBalanceMissing,
65
+ utilityAccount: this.utilityAccount.address
66
+ }, "utility wallet has insufficient balance to refill wallets");
67
+ throw new Error(`utility wallet ${this.utilityAccount.address} has insufficient balance ${formatEther(utilityWalletBalance)} < ${formatEther(totalBalanceMissing)}`);
68
+ }
69
+ if (Object.keys(balancesMissing).length > 0) {
70
+ const { maxFeePerGas, maxPriorityFeePerGas } = await this.gasPriceManager.getGasPrice();
71
+ if (walletClient.chain.id === 59140 ||
72
+ walletClient.chain.id === 137 ||
73
+ walletClient.chain.id === 10) {
74
+ const instructions = [];
75
+ for (const [address, missingBalance] of Object.entries(balancesMissing)) {
76
+ instructions.push({
77
+ to: address,
78
+ value: missingBalance,
79
+ data: "0x"
80
+ });
81
+ }
82
+ let refillAddress;
83
+ if (walletClient.chain.id === 59140) {
84
+ refillAddress = "0xEad1aC3DF6F96b91491d6396F4d1610C5638B4Db";
85
+ }
86
+ else if (walletClient.chain.id === 137) {
87
+ refillAddress = "0x3402DB43152dAB9ab72fa805fdD5f391cD3E3822";
88
+ }
89
+ else {
90
+ refillAddress = "0x3402DB43152dAB9ab72fa805fdD5f391cD3E3822";
91
+ }
92
+ const callEngine = getContract({
93
+ abi: CallEngineAbi,
94
+ address: refillAddress,
95
+ client: {
96
+ public: publicClient,
97
+ wallet: walletClient
98
+ }
99
+ });
100
+ const tx = await callEngine.write.execute([instructions], {
101
+ account: this.utilityAccount,
102
+ value: totalBalanceMissing,
103
+ maxFeePerGas: maxFeePerGas * 2n,
104
+ maxPriorityFeePerGas: maxPriorityFeePerGas * 2n
105
+ });
106
+ await waitForTransactionReceipt(publicClient, tx);
107
+ for (const [address, missingBalance] of Object.entries(balancesMissing)) {
108
+ this.logger.info({ tx, executor: address, missingBalance }, "refilled wallet");
109
+ }
110
+ }
111
+ else {
112
+ for (const [address, missingBalance] of Object.entries(balancesMissing)) {
113
+ const tx = await walletClient.sendTransaction({
114
+ account: this.utilityAccount,
115
+ // @ts-ignore
116
+ to: address,
117
+ value: missingBalance,
118
+ maxFeePerGas: this.legacyTransactions
119
+ ? undefined
120
+ : maxFeePerGas,
121
+ maxPriorityFeePerGas: this.legacyTransactions
122
+ ? undefined
123
+ : maxPriorityFeePerGas,
124
+ gasPrice: this.legacyTransactions
125
+ ? maxFeePerGas
126
+ : undefined
127
+ });
128
+ await waitForTransactionReceipt(publicClient, tx);
129
+ this.logger.info({ tx, executor: address, missingBalance }, "refilled wallet");
130
+ }
131
+ }
132
+ }
133
+ else {
134
+ this.logger.info("no wallets need to be refilled");
135
+ }
136
+ }
137
+ async getWallet() {
138
+ this.logger.trace(`waiting for semaphore with count ${this.semaphore.getValue()}`);
139
+ await this.semaphore.waitForUnlock();
140
+ await this.semaphore.acquire();
141
+ const wallet = this.availableWallets.shift();
142
+ // should never happen because of semaphore
143
+ if (!wallet) {
144
+ this.semaphore.release();
145
+ this.logger.error("no more wallets");
146
+ throw new Error("no more wallets");
147
+ }
148
+ this.logger.trace({ executor: wallet.address }, "got wallet from sender manager");
149
+ this.metrics.walletsAvailable.set(this.availableWallets.length);
150
+ return wallet;
151
+ }
152
+ pushWallet(wallet) {
153
+ this.availableWallets.push(wallet);
154
+ this.semaphore.release();
155
+ this.logger.trace({ executor: wallet.address }, "pushed wallet to sender manager");
156
+ this.metrics.walletsAvailable.set(this.availableWallets.length);
157
+ return;
158
+ }
159
+ }
160
+ //# sourceMappingURL=senderManager.js.map