@pimlico/alto 0.0.7 → 0.0.9

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 (268) hide show
  1. package/esm/cli/alto.js +3 -1
  2. package/esm/cli/alto.js.map +1 -1
  3. package/esm/cli/config/bundler.d.ts +320 -272
  4. package/esm/cli/config/bundler.js +26 -7
  5. package/esm/cli/config/bundler.js.map +1 -1
  6. package/esm/cli/config/options.js +65 -10
  7. package/esm/cli/config/options.js.map +1 -1
  8. package/esm/cli/customTransport.js +40 -7
  9. package/esm/cli/customTransport.js.map +1 -1
  10. package/esm/cli/deploySimulationsContract.d.ts +8 -0
  11. package/esm/cli/deploySimulationsContract.js +35 -0
  12. package/esm/cli/deploySimulationsContract.js.map +1 -0
  13. package/esm/cli/handler.d.ts +2 -2
  14. package/esm/cli/handler.js +78 -89
  15. package/esm/cli/handler.js.map +1 -1
  16. package/esm/cli/instrumentation.js +4 -2
  17. package/esm/cli/instrumentation.js.map +1 -1
  18. package/esm/cli/parseArgs.d.ts +8 -0
  19. package/esm/cli/parseArgs.js +21 -0
  20. package/esm/cli/parseArgs.js.map +1 -0
  21. package/esm/cli/setupServer.d.ts +4 -9
  22. package/esm/cli/setupServer.js +100 -82
  23. package/esm/cli/setupServer.js.map +1 -1
  24. package/esm/createConfig.d.ts +15 -0
  25. package/esm/createConfig.js +8 -0
  26. package/esm/createConfig.js.map +1 -0
  27. package/esm/executor/executor.d.ts +48 -14
  28. package/esm/executor/executor.js +262 -139
  29. package/esm/executor/executor.js.map +1 -1
  30. package/esm/executor/executorManager.d.ts +14 -10
  31. package/esm/executor/executorManager.js +36 -39
  32. package/esm/executor/executorManager.js.map +1 -1
  33. package/esm/executor/senderManager.d.ts +11 -6
  34. package/esm/executor/senderManager.js +39 -36
  35. package/esm/executor/senderManager.js.map +1 -1
  36. package/esm/executor/utilityWalletMonitor.d.ts +9 -5
  37. package/esm/executor/utilityWalletMonitor.js +8 -8
  38. package/esm/executor/utilityWalletMonitor.js.map +1 -1
  39. package/esm/executor/utils.d.ts +2 -1
  40. package/esm/executor/utils.js +7 -2
  41. package/esm/executor/utils.js.map +1 -1
  42. package/esm/handlers/arbitrumGasPriceManager.d.ts +11 -0
  43. package/esm/handlers/arbitrumGasPriceManager.js +29 -0
  44. package/esm/handlers/arbitrumGasPriceManager.js.map +1 -0
  45. package/esm/handlers/eventManager.d.ts +7 -3
  46. package/esm/handlers/eventManager.js +24 -16
  47. package/esm/handlers/eventManager.js.map +1 -1
  48. package/esm/handlers/gasPriceManager.d.ts +14 -41
  49. package/esm/handlers/gasPriceManager.js +87 -208
  50. package/esm/handlers/gasPriceManager.js.map +1 -1
  51. package/esm/handlers/mantleGasPriceManager.d.ts +20 -0
  52. package/esm/handlers/mantleGasPriceManager.js +28 -0
  53. package/esm/handlers/mantleGasPriceManager.js.map +1 -0
  54. package/esm/mempool/mempool.d.ts +13 -10
  55. package/esm/mempool/mempool.js +29 -26
  56. package/esm/mempool/mempool.js.map +1 -1
  57. package/esm/mempool/reputationManager.d.ts +4 -6
  58. package/esm/mempool/reputationManager.js +25 -29
  59. package/esm/mempool/reputationManager.js.map +1 -1
  60. package/esm/mempool/store.d.ts +1 -1
  61. package/esm/rpc/estimation/gasEstimationHandler.d.ts +7 -7
  62. package/esm/rpc/estimation/gasEstimationHandler.js +18 -33
  63. package/esm/rpc/estimation/gasEstimationHandler.js.map +1 -1
  64. package/esm/rpc/estimation/gasEstimationsV06.d.ts +7 -7
  65. package/esm/rpc/estimation/gasEstimationsV06.js +90 -48
  66. package/esm/rpc/estimation/gasEstimationsV06.js.map +1 -1
  67. package/esm/rpc/estimation/gasEstimationsV07.d.ts +7 -12
  68. package/esm/rpc/estimation/gasEstimationsV07.js +53 -37
  69. package/esm/rpc/estimation/gasEstimationsV07.js.map +1 -1
  70. package/esm/rpc/nonceQueuer.d.ts +10 -6
  71. package/esm/rpc/nonceQueuer.js +10 -10
  72. package/esm/rpc/nonceQueuer.js.map +1 -1
  73. package/esm/rpc/rpcHandler.d.ts +19 -16
  74. package/esm/rpc/rpcHandler.js +98 -90
  75. package/esm/rpc/rpcHandler.js.map +1 -1
  76. package/esm/rpc/server.d.ts +9 -7
  77. package/esm/rpc/server.js +27 -25
  78. package/esm/rpc/server.js.map +1 -1
  79. package/esm/rpc/validation/SafeValidator.d.ts +11 -6
  80. package/esm/rpc/validation/SafeValidator.js +14 -11
  81. package/esm/rpc/validation/SafeValidator.js.map +1 -1
  82. package/esm/rpc/validation/TracerResultParserV06.d.ts +1 -1
  83. package/esm/rpc/validation/TracerResultParserV06.js.map +1 -1
  84. package/esm/rpc/validation/TracerResultParserV07.d.ts +1 -1
  85. package/esm/rpc/validation/TracerResultParserV07.js +1 -1
  86. package/esm/rpc/validation/TracerResultParserV07.js.map +1 -1
  87. package/esm/rpc/validation/UnsafeValidator.d.ts +11 -12
  88. package/esm/rpc/validation/UnsafeValidator.js +28 -29
  89. package/esm/rpc/validation/UnsafeValidator.js.map +1 -1
  90. package/esm/types/contracts/ArbitrumL1FeeAbi.d.ts +32 -0
  91. package/esm/types/contracts/ArbitrumL1FeeAbi.js +42 -0
  92. package/esm/types/contracts/ArbitrumL1FeeAbi.js.map +1 -0
  93. package/esm/types/contracts/EntryPointSimulationsV6.d.ts +34 -0
  94. package/esm/types/contracts/EntryPointSimulationsV6.js +48 -0
  95. package/esm/types/contracts/EntryPointSimulationsV6.js.map +1 -0
  96. package/esm/types/contracts/{EntryPointSimulations.d.ts → EntryPointSimulationsV7.d.ts} +1 -9
  97. package/esm/types/contracts/{EntryPointSimulations.js → EntryPointSimulationsV7.js} +1 -13
  98. package/esm/types/contracts/EntryPointSimulationsV7.js.map +1 -0
  99. package/esm/types/contracts/MantleBvmGasPriceOracle.d.ts +219 -0
  100. package/esm/types/contracts/MantleBvmGasPriceOracle.js +177 -0
  101. package/esm/types/contracts/MantleBvmGasPriceOracle.js.map +1 -0
  102. package/esm/types/contracts/OpL1FeeAbi.d.ts +114 -0
  103. package/esm/types/contracts/OpL1FeeAbi.js +74 -0
  104. package/esm/types/contracts/OpL1FeeAbi.js.map +1 -0
  105. package/esm/types/contracts/PimlicoEntryPointSimulations.d.ts +1 -1
  106. package/esm/types/contracts/PimlicoEntryPointSimulations.js +1 -1
  107. package/esm/types/contracts/PimlicoEntryPointSimulations.js.map +1 -1
  108. package/esm/types/contracts/index.d.ts +5 -1
  109. package/esm/types/contracts/index.js +5 -1
  110. package/esm/types/contracts/index.js.map +1 -1
  111. package/esm/types/interfaces.d.ts +2 -2
  112. package/esm/types/mempool.d.ts +1 -2
  113. package/esm/types/mempool.js.map +1 -1
  114. package/esm/types/schemas.d.ts +26 -26
  115. package/esm/types/schemas.js +3 -3
  116. package/esm/types/schemas.js.map +1 -1
  117. package/esm/types/utils.d.ts +1 -1
  118. package/esm/utils/bigInt.js +2 -2
  119. package/esm/utils/bigInt.js.map +1 -1
  120. package/esm/utils/helpers.js +1 -1
  121. package/esm/utils/helpers.js.map +1 -1
  122. package/esm/utils/metrics.d.ts +1 -0
  123. package/esm/utils/metrics.js +7 -0
  124. package/esm/utils/metrics.js.map +1 -1
  125. package/esm/utils/rpc-reply.d.ts +1 -1
  126. package/esm/utils/timedQueue.d.ts +12 -0
  127. package/esm/utils/timedQueue.js +51 -0
  128. package/esm/utils/timedQueue.js.map +1 -0
  129. package/esm/utils/userop.d.ts +3 -3
  130. package/esm/utils/userop.js +4 -3
  131. package/esm/utils/userop.js.map +1 -1
  132. package/esm/utils/validation.d.ts +14 -6
  133. package/esm/utils/validation.js +160 -168
  134. package/esm/utils/validation.js.map +1 -1
  135. package/lib/cli/alto.js +2 -0
  136. package/lib/cli/alto.js.map +1 -1
  137. package/lib/cli/config/bundler.d.ts +320 -272
  138. package/lib/cli/config/bundler.js +25 -6
  139. package/lib/cli/config/bundler.js.map +1 -1
  140. package/lib/cli/config/options.js +65 -10
  141. package/lib/cli/config/options.js.map +1 -1
  142. package/lib/cli/customTransport.js +38 -5
  143. package/lib/cli/customTransport.js.map +1 -1
  144. package/lib/cli/deploySimulationsContract.d.ts +8 -0
  145. package/lib/cli/deploySimulationsContract.js +39 -0
  146. package/lib/cli/deploySimulationsContract.js.map +1 -0
  147. package/lib/cli/handler.d.ts +2 -2
  148. package/lib/cli/handler.js +77 -88
  149. package/lib/cli/handler.js.map +1 -1
  150. package/lib/cli/instrumentation.js +4 -2
  151. package/lib/cli/instrumentation.js.map +1 -1
  152. package/lib/cli/parseArgs.d.ts +8 -0
  153. package/lib/cli/parseArgs.js +25 -0
  154. package/lib/cli/parseArgs.js.map +1 -0
  155. package/lib/cli/setupServer.d.ts +4 -9
  156. package/lib/cli/setupServer.js +100 -82
  157. package/lib/cli/setupServer.js.map +1 -1
  158. package/lib/createConfig.d.ts +15 -0
  159. package/lib/createConfig.js +12 -0
  160. package/lib/createConfig.js.map +1 -0
  161. package/lib/executor/executor.d.ts +48 -14
  162. package/lib/executor/executor.js +258 -135
  163. package/lib/executor/executor.js.map +1 -1
  164. package/lib/executor/executorManager.d.ts +14 -10
  165. package/lib/executor/executorManager.js +34 -37
  166. package/lib/executor/executorManager.js.map +1 -1
  167. package/lib/executor/senderManager.d.ts +11 -6
  168. package/lib/executor/senderManager.js +39 -36
  169. package/lib/executor/senderManager.js.map +1 -1
  170. package/lib/executor/utilityWalletMonitor.d.ts +9 -5
  171. package/lib/executor/utilityWalletMonitor.js +8 -8
  172. package/lib/executor/utilityWalletMonitor.js.map +1 -1
  173. package/lib/executor/utils.d.ts +2 -1
  174. package/lib/executor/utils.js +9 -3
  175. package/lib/executor/utils.js.map +1 -1
  176. package/lib/handlers/arbitrumGasPriceManager.d.ts +11 -0
  177. package/lib/handlers/arbitrumGasPriceManager.js +33 -0
  178. package/lib/handlers/arbitrumGasPriceManager.js.map +1 -0
  179. package/lib/handlers/eventManager.d.ts +7 -3
  180. package/lib/handlers/eventManager.js +24 -16
  181. package/lib/handlers/eventManager.js.map +1 -1
  182. package/lib/handlers/gasPriceManager.d.ts +14 -41
  183. package/lib/handlers/gasPriceManager.js +85 -206
  184. package/lib/handlers/gasPriceManager.js.map +1 -1
  185. package/lib/handlers/mantleGasPriceManager.d.ts +20 -0
  186. package/lib/handlers/mantleGasPriceManager.js +32 -0
  187. package/lib/handlers/mantleGasPriceManager.js.map +1 -0
  188. package/lib/mempool/mempool.d.ts +13 -10
  189. package/lib/mempool/mempool.js +28 -25
  190. package/lib/mempool/mempool.js.map +1 -1
  191. package/lib/mempool/reputationManager.d.ts +4 -6
  192. package/lib/mempool/reputationManager.js +25 -29
  193. package/lib/mempool/reputationManager.js.map +1 -1
  194. package/lib/mempool/store.d.ts +1 -1
  195. package/lib/rpc/estimation/gasEstimationHandler.d.ts +7 -7
  196. package/lib/rpc/estimation/gasEstimationHandler.js +18 -33
  197. package/lib/rpc/estimation/gasEstimationHandler.js.map +1 -1
  198. package/lib/rpc/estimation/gasEstimationsV06.d.ts +7 -7
  199. package/lib/rpc/estimation/gasEstimationsV06.js +88 -46
  200. package/lib/rpc/estimation/gasEstimationsV06.js.map +1 -1
  201. package/lib/rpc/estimation/gasEstimationsV07.d.ts +7 -12
  202. package/lib/rpc/estimation/gasEstimationsV07.js +52 -36
  203. package/lib/rpc/estimation/gasEstimationsV07.js.map +1 -1
  204. package/lib/rpc/nonceQueuer.d.ts +10 -6
  205. package/lib/rpc/nonceQueuer.js +9 -9
  206. package/lib/rpc/nonceQueuer.js.map +1 -1
  207. package/lib/rpc/rpcHandler.d.ts +19 -16
  208. package/lib/rpc/rpcHandler.js +97 -89
  209. package/lib/rpc/rpcHandler.js.map +1 -1
  210. package/lib/rpc/server.d.ts +9 -7
  211. package/lib/rpc/server.js +26 -24
  212. package/lib/rpc/server.js.map +1 -1
  213. package/lib/rpc/validation/SafeValidator.d.ts +11 -6
  214. package/lib/rpc/validation/SafeValidator.js +13 -10
  215. package/lib/rpc/validation/SafeValidator.js.map +1 -1
  216. package/lib/rpc/validation/TracerResultParserV06.d.ts +1 -1
  217. package/lib/rpc/validation/TracerResultParserV07.d.ts +1 -1
  218. package/lib/rpc/validation/TracerResultParserV07.js +1 -1
  219. package/lib/rpc/validation/TracerResultParserV07.js.map +1 -1
  220. package/lib/rpc/validation/UnsafeValidator.d.ts +11 -12
  221. package/lib/rpc/validation/UnsafeValidator.js +28 -29
  222. package/lib/rpc/validation/UnsafeValidator.js.map +1 -1
  223. package/lib/types/contracts/ArbitrumL1FeeAbi.d.ts +32 -0
  224. package/lib/types/contracts/ArbitrumL1FeeAbi.js +45 -0
  225. package/lib/types/contracts/ArbitrumL1FeeAbi.js.map +1 -0
  226. package/lib/types/contracts/EntryPointSimulationsV6.d.ts +34 -0
  227. package/lib/types/contracts/EntryPointSimulationsV6.js +51 -0
  228. package/lib/types/contracts/EntryPointSimulationsV6.js.map +1 -0
  229. package/lib/types/contracts/{EntryPointSimulations.d.ts → EntryPointSimulationsV7.d.ts} +1 -9
  230. package/lib/types/contracts/{EntryPointSimulations.js → EntryPointSimulationsV7.js} +2 -14
  231. package/lib/types/contracts/EntryPointSimulationsV7.js.map +1 -0
  232. package/lib/types/contracts/MantleBvmGasPriceOracle.d.ts +219 -0
  233. package/lib/types/contracts/MantleBvmGasPriceOracle.js +180 -0
  234. package/lib/types/contracts/MantleBvmGasPriceOracle.js.map +1 -0
  235. package/lib/types/contracts/OpL1FeeAbi.d.ts +114 -0
  236. package/lib/types/contracts/OpL1FeeAbi.js +77 -0
  237. package/lib/types/contracts/OpL1FeeAbi.js.map +1 -0
  238. package/lib/types/contracts/PimlicoEntryPointSimulations.d.ts +1 -1
  239. package/lib/types/contracts/PimlicoEntryPointSimulations.js +1 -1
  240. package/lib/types/contracts/PimlicoEntryPointSimulations.js.map +1 -1
  241. package/lib/types/contracts/index.d.ts +5 -1
  242. package/lib/types/contracts/index.js +5 -1
  243. package/lib/types/contracts/index.js.map +1 -1
  244. package/lib/types/interfaces.d.ts +2 -2
  245. package/lib/types/mempool.d.ts +1 -2
  246. package/lib/types/mempool.js.map +1 -1
  247. package/lib/types/schemas.d.ts +26 -26
  248. package/lib/types/schemas.js +3 -3
  249. package/lib/types/schemas.js.map +1 -1
  250. package/lib/types/utils.d.ts +1 -1
  251. package/lib/utils/bigInt.js +2 -2
  252. package/lib/utils/bigInt.js.map +1 -1
  253. package/lib/utils/metrics.d.ts +1 -0
  254. package/lib/utils/metrics.js +7 -0
  255. package/lib/utils/metrics.js.map +1 -1
  256. package/lib/utils/rpc-reply.d.ts +1 -1
  257. package/lib/utils/timedQueue.d.ts +12 -0
  258. package/lib/utils/timedQueue.js +55 -0
  259. package/lib/utils/timedQueue.js.map +1 -0
  260. package/lib/utils/userop.d.ts +3 -3
  261. package/lib/utils/userop.js +3 -2
  262. package/lib/utils/userop.js.map +1 -1
  263. package/lib/utils/validation.d.ts +14 -6
  264. package/lib/utils/validation.js +164 -168
  265. package/lib/utils/validation.js.map +1 -1
  266. package/package.json +1 -1
  267. package/esm/types/contracts/EntryPointSimulations.js.map +0 -1
  268. package/lib/types/contracts/EntryPointSimulations.js.map +0 -1
@@ -26,47 +26,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Executor = void 0;
27
27
  const types_1 = require("../types/index.js");
28
28
  const utils_1 = require("../utils/index.js");
29
- // biome-ignore lint/style/noNamespaceImport: explicitly make it clear when sentry is used
30
29
  const sentry = __importStar(require("@sentry/node"));
31
30
  const async_mutex_1 = require("async-mutex");
32
31
  const viem_1 = require("viem");
33
32
  const utils_2 = require("./utils.js");
34
33
  class Executor {
35
34
  // private unWatch: WatchBlocksReturnType | undefined
36
- publicClient;
37
- walletClient;
38
- entryPoints;
35
+ config;
39
36
  senderManager;
40
37
  logger;
41
38
  metrics;
42
- simulateTransaction;
43
- legacyTransactions;
44
- fixedGasLimitForEstimation;
45
- localGasLimitCalculation;
46
39
  reputationManager;
47
40
  compressionHandler;
48
41
  gasPriceManager;
49
- blockTagSupport;
50
42
  mutex;
43
+ mempool;
51
44
  eventManager;
52
- noProfitBundling; // if true, bundle such that all beneficiary fees go towards tx gasFees
53
- constructor(publicClient, walletClient, senderManager, reputationManager, entryPoints, logger, metrics, compressionHandler, gasPriceManager, eventManager, simulateTransaction = false, legacyTransactions = false, fixedGasLimitForEstimation, blockTagSupport = true, localGasLimitCalculation = false, noProfitBundling = false) {
54
- this.publicClient = publicClient;
55
- this.walletClient = walletClient;
45
+ constructor({ config, mempool, senderManager, reputationManager, metrics, compressionHandler, gasPriceManager, eventManager }) {
46
+ this.config = config;
47
+ this.mempool = mempool;
56
48
  this.senderManager = senderManager;
57
49
  this.reputationManager = reputationManager;
58
- this.logger = logger;
50
+ this.logger = config.getLogger({ module: "executor" }, {
51
+ level: config.executorLogLevel || config.logLevel
52
+ });
59
53
  this.metrics = metrics;
60
- this.simulateTransaction = simulateTransaction;
61
- this.legacyTransactions = legacyTransactions;
62
- this.fixedGasLimitForEstimation = fixedGasLimitForEstimation;
63
- this.localGasLimitCalculation = localGasLimitCalculation;
64
54
  this.compressionHandler = compressionHandler;
65
55
  this.gasPriceManager = gasPriceManager;
66
56
  this.eventManager = eventManager;
67
- this.blockTagSupport = blockTagSupport;
68
- this.entryPoints = entryPoints;
69
- this.noProfitBundling = noProfitBundling;
70
57
  this.mutex = new async_mutex_1.Mutex();
71
58
  }
72
59
  getCompressionHandler() {
@@ -86,7 +73,16 @@ class Executor {
86
73
  }
87
74
  async replaceTransaction(transactionInfo) {
88
75
  const newRequest = { ...transactionInfo.transactionRequest };
89
- const gasPriceParameters = await this.gasPriceManager.getGasPrice();
76
+ let gasPriceParameters;
77
+ try {
78
+ gasPriceParameters =
79
+ await this.gasPriceManager.tryGetNetworkGasPrice();
80
+ }
81
+ catch (err) {
82
+ this.logger.error({ error: err }, "Failed to get network gas price");
83
+ this.markWalletProcessed(transactionInfo.executor);
84
+ return { status: "failed" };
85
+ }
90
86
  newRequest.maxFeePerGas = (0, utils_1.maxBigInt)(gasPriceParameters.maxFeePerGas, (newRequest.maxFeePerGas * 11n + 9n) / 10n);
91
87
  newRequest.maxPriorityFeePerGas = (0, utils_1.maxBigInt)(gasPriceParameters.maxPriorityFeePerGas, (newRequest.maxPriorityFeePerGas * 11n + 9n) / 10n);
92
88
  newRequest.account = transactionInfo.executor;
@@ -94,7 +90,7 @@ class Executor {
94
90
  const op = (0, types_1.deriveUserOperation)(opInfo.mempoolUserOperation);
95
91
  return {
96
92
  mempoolUserOperation: opInfo.mempoolUserOperation,
97
- userOperationHash: (0, utils_1.getUserOperationHash)(op, transactionInfo.entryPoint, this.walletClient.chain.id),
93
+ userOperationHash: (0, utils_1.getUserOperationHash)(op, transactionInfo.entryPoint, this.config.walletClient.chain.id),
98
94
  entryPoint: opInfo.entryPoint
99
95
  };
100
96
  });
@@ -115,8 +111,8 @@ class Executor {
115
111
  abi: isUserOpVersion06 ? types_1.EntryPointV06Abi : types_1.EntryPointV07Abi,
116
112
  address: entryPoint,
117
113
  client: {
118
- public: this.publicClient,
119
- wallet: this.walletClient
114
+ public: this.config.publicClient,
115
+ wallet: this.config.walletClient
120
116
  }
121
117
  });
122
118
  callContext = {
@@ -127,13 +123,13 @@ class Executor {
127
123
  else {
128
124
  const compressionHandler = this.getCompressionHandler();
129
125
  callContext = {
130
- publicClient: this.publicClient,
126
+ publicClient: this.config.publicClient,
131
127
  bundleBulker: compressionHandler.bundleBulkerAddress,
132
128
  perOpInflatorId: compressionHandler.perOpInflatorId,
133
129
  type: "compressed"
134
130
  };
135
131
  }
136
- let { simulatedOps, gasLimit } = await (0, utils_2.filterOpsAndEstimateGas)(transactionInfo.entryPoint, callContext, transactionInfo.executor, opsWithHashes, newRequest.nonce, newRequest.maxFeePerGas, newRequest.maxPriorityFeePerGas, this.blockTagSupport ? "latest" : undefined, this.legacyTransactions, this.fixedGasLimitForEstimation, this.reputationManager, this.logger);
132
+ let { simulatedOps, gasLimit } = await (0, utils_2.filterOpsAndEstimateGas)(transactionInfo.entryPoint, callContext, transactionInfo.executor, opsWithHashes, newRequest.nonce, newRequest.maxFeePerGas, newRequest.maxPriorityFeePerGas, this.config.blockTagSupport ? "latest" : undefined, this.config.legacyTransactions, this.config.fixedGasLimitForEstimation, this.reputationManager, this.logger);
137
133
  const childLogger = this.logger.child({
138
134
  transactionHash: transactionInfo.transactionHash,
139
135
  executor: transactionInfo.executor.address
@@ -162,7 +158,7 @@ class Executor {
162
158
  }
163
159
  return opInfo;
164
160
  });
165
- if (this.localGasLimitCalculation) {
161
+ if (this.config.localGasLimitCalculation) {
166
162
  gasLimit = opsToBundle.reduce((acc, opInfo) => {
167
163
  const userOperation = (0, types_1.deriveUserOperation)(opInfo.mempoolUserOperation);
168
164
  return (acc +
@@ -186,6 +182,7 @@ class Executor {
186
182
  // ensures that we don't submit again with too low of a gas value
187
183
  newRequest.gas = (0, utils_1.maxBigInt)(newRequest.gas, gasLimit);
188
184
  // update calldata to include only ops that pass simulation
185
+ let txParam;
189
186
  if (transactionInfo.transactionType === "default") {
190
187
  const isUserOpVersion06 = opsWithHashes.reduce((acc, op) => {
191
188
  if (acc !==
@@ -194,27 +191,22 @@ class Executor {
194
191
  }
195
192
  return acc;
196
193
  }, (0, utils_1.isVersion06)(opsWithHashes[0].mempoolUserOperation));
197
- newRequest.data = isUserOpVersion06
198
- ? (0, viem_1.encodeFunctionData)({
199
- abi: types_1.EntryPointV06Abi,
200
- functionName: "handleOps",
201
- args: [
202
- opsToBundle.map((opInfo) => opInfo.mempoolUserOperation),
203
- transactionInfo.executor.address
204
- ]
205
- })
206
- : (0, viem_1.encodeFunctionData)({
207
- abi: types_1.EntryPointV07Abi,
208
- functionName: "handleOps",
209
- args: [
210
- opsToBundle.map((opInfo) => (0, utils_1.toPackedUserOperation)(opInfo.mempoolUserOperation)),
211
- transactionInfo.executor.address
212
- ]
213
- });
194
+ const userOps = opsToBundle.map((op) => isUserOpVersion06
195
+ ? op.mempoolUserOperation
196
+ : (0, utils_1.toPackedUserOperation)(op.mempoolUserOperation));
197
+ txParam = {
198
+ type: "default",
199
+ isUserOpVersion06,
200
+ ops: userOps,
201
+ entryPoint: transactionInfo.entryPoint
202
+ };
214
203
  }
215
- else if (transactionInfo.transactionType === "compressed") {
216
- const compressedOps = opsToBundle.map((opInfo) => opInfo.mempoolUserOperation);
217
- newRequest.data = (0, utils_2.createCompressedCalldata)(compressedOps, this.getCompressionHandler().perOpInflatorId);
204
+ else {
205
+ const compressedOps = opsToBundle.map(({ mempoolUserOperation }) => mempoolUserOperation);
206
+ txParam = {
207
+ type: "compressed",
208
+ compressedOps: compressedOps
209
+ };
218
210
  }
219
211
  try {
220
212
  childLogger.info({
@@ -226,20 +218,27 @@ class Executor {
226
218
  executor: newRequest.account.address,
227
219
  opsToBundle: opsToBundle.map((opInfo) => opInfo.userOperationHash)
228
220
  }, "replacing transaction");
229
- const txHash = await this.walletClient.sendTransaction(this.legacyTransactions
230
- ? {
231
- ...newRequest,
232
- gasPrice: newRequest.maxFeePerGas,
233
- maxFeePerGas: undefined,
234
- maxPriorityFeePerGas: undefined,
235
- type: "legacy",
236
- accessList: undefined
237
- }
238
- : newRequest);
239
- opsToBundle.map((opToBundle) => {
240
- const op = (0, types_1.deriveUserOperation)(opToBundle.mempoolUserOperation);
241
- const chainId = this.publicClient.chain?.id;
242
- const opHash = (0, utils_1.getUserOperationHash)(op, opToBundle.entryPoint, chainId);
221
+ const txHash = await this.sendHandleOpsTransaction({
222
+ txParam,
223
+ opts: this.config.legacyTransactions
224
+ ? {
225
+ account: newRequest.account,
226
+ gasPrice: newRequest.maxFeePerGas,
227
+ gas: newRequest.gas,
228
+ nonce: newRequest.nonce
229
+ }
230
+ : {
231
+ account: newRequest.account,
232
+ maxFeePerGas: newRequest.maxFeePerGas,
233
+ maxPriorityFeePerGas: newRequest.maxPriorityFeePerGas,
234
+ gas: newRequest.gas,
235
+ nonce: newRequest.nonce
236
+ }
237
+ });
238
+ opsToBundle.map(({ entryPoint, mempoolUserOperation }) => {
239
+ const op = (0, types_1.deriveUserOperation)(mempoolUserOperation);
240
+ const chainId = this.config.publicClient.chain?.id;
241
+ const opHash = (0, utils_1.getUserOperationHash)(op, entryPoint, chainId);
243
242
  this.eventManager.emitSubmitted(opHash, txHash);
244
243
  });
245
244
  const newTxInfo = {
@@ -297,18 +296,129 @@ class Executor {
297
296
  allWallets.add(utilityWallet);
298
297
  }
299
298
  const wallets = Array.from(allWallets);
300
- const gasPrice = await this.gasPriceManager.getGasPrice();
299
+ const gasPrice = await this.gasPriceManager.tryGetNetworkGasPrice();
301
300
  const promises = wallets.map((wallet) => {
302
- (0, utils_2.flushStuckTransaction)(this.publicClient, this.walletClient, wallet, gasPrice.maxFeePerGas * 5n, this.logger);
301
+ try {
302
+ (0, utils_2.flushStuckTransaction)(this.config.publicClient, this.config.walletClient, wallet, gasPrice.maxFeePerGas * 5n, this.logger);
303
+ }
304
+ catch (e) {
305
+ this.logger.error({ error: e }, "error flushing stuck transaction");
306
+ }
303
307
  });
304
308
  await Promise.all(promises);
305
309
  }
310
+ async sendHandleOpsTransaction({ txParam, opts }) {
311
+ let data;
312
+ let to;
313
+ if (txParam.type === "default") {
314
+ const { isUserOpVersion06, ops, entryPoint } = txParam;
315
+ data = (0, viem_1.encodeFunctionData)({
316
+ abi: isUserOpVersion06 ? types_1.EntryPointV06Abi : types_1.EntryPointV07Abi,
317
+ functionName: "handleOps",
318
+ args: [ops, opts.account.address]
319
+ });
320
+ to = entryPoint;
321
+ }
322
+ else {
323
+ const { compressedOps } = txParam;
324
+ const compressionHandler = this.getCompressionHandler();
325
+ data = (0, utils_2.createCompressedCalldata)(compressedOps, compressionHandler.perOpInflatorId);
326
+ to = compressionHandler.bundleBulkerAddress;
327
+ }
328
+ const request = await this.config.walletClient.prepareTransactionRequest({
329
+ to,
330
+ data,
331
+ ...opts
332
+ });
333
+ let isTransactionUnderPriced = false;
334
+ let attempts = 0;
335
+ let transactionHash;
336
+ const maxAttempts = 3;
337
+ // Try sending the transaction and updating relevant fields if there is an error.
338
+ while (attempts < maxAttempts) {
339
+ try {
340
+ transactionHash =
341
+ await this.config.walletClient.sendTransaction(request);
342
+ break;
343
+ }
344
+ catch (e) {
345
+ isTransactionUnderPriced = false;
346
+ let isErrorHandled = false;
347
+ if (e instanceof viem_1.BaseError) {
348
+ if ((0, utils_2.isTransactionUnderpricedError)(e)) {
349
+ this.logger.warn("Transaction underpriced, retrying");
350
+ request.maxFeePerGas = (0, utils_1.scaleBigIntByPercent)(request.maxFeePerGas, 150);
351
+ request.maxPriorityFeePerGas = (0, utils_1.scaleBigIntByPercent)(request.maxPriorityFeePerGas, 150);
352
+ isErrorHandled = true;
353
+ isTransactionUnderPriced = true;
354
+ }
355
+ }
356
+ const error = e;
357
+ if (error instanceof viem_1.TransactionExecutionError) {
358
+ const cause = error.cause;
359
+ if (cause instanceof viem_1.NonceTooLowError ||
360
+ cause instanceof viem_1.NonceTooHighError) {
361
+ this.logger.warn("Nonce too low, retrying");
362
+ request.nonce =
363
+ await this.config.publicClient.getTransactionCount({
364
+ address: request.from,
365
+ blockTag: "pending"
366
+ });
367
+ isErrorHandled = true;
368
+ }
369
+ if (cause instanceof viem_1.IntrinsicGasTooLowError) {
370
+ this.logger.warn("Intrinsic gas too low, retrying");
371
+ request.gas = (0, utils_1.scaleBigIntByPercent)(request.gas, 150);
372
+ isErrorHandled = true;
373
+ }
374
+ // This is thrown by OP-Stack chains that use proxyd.
375
+ // ref: https://github.com/ethereum-optimism/optimism/issues/2618#issuecomment-1630272888
376
+ if (cause.details?.includes("no backends available")) {
377
+ this.logger.warn("no backends avaiable error, retrying after 500ms");
378
+ await new Promise((resolve) => setTimeout(resolve, 500));
379
+ isErrorHandled = true;
380
+ }
381
+ }
382
+ if (attempts === maxAttempts || !isErrorHandled) {
383
+ throw error;
384
+ }
385
+ attempts++;
386
+ }
387
+ }
388
+ if (isTransactionUnderPriced) {
389
+ await this.handleTransactionUnderPriced({
390
+ nonce: request.nonce,
391
+ executor: request.from
392
+ });
393
+ }
394
+ // needed for TS
395
+ if (!transactionHash) {
396
+ throw new Error("Transaction hash not assigned");
397
+ }
398
+ return transactionHash;
399
+ }
400
+ // Occurs when tx was sent with conflicting nonce, we want to resubmit all conflicting ops
401
+ async handleTransactionUnderPriced({ nonce, executor }) {
402
+ const submitted = this.mempool.dumpSubmittedOps();
403
+ const conflictingOps = submitted
404
+ .filter((submitted) => {
405
+ const tx = submitted.transactionInfo;
406
+ return (tx.executor.address === executor &&
407
+ tx.transactionRequest.nonce === nonce);
408
+ })
409
+ .map(({ userOperation }) => userOperation);
410
+ conflictingOps.map((op) => {
411
+ this.logger.info(`Resubmitting ${op.userOperationHash} due to transaction underpriced`);
412
+ this.mempool.removeSubmitted(op.userOperationHash);
413
+ this.mempool.add(op.mempoolUserOperation, op.entryPoint);
414
+ });
415
+ }
306
416
  async bundle(entryPoint, ops) {
307
417
  const wallet = await this.senderManager.getWallet();
308
418
  const opsWithHashes = ops.map((op) => {
309
419
  return {
310
420
  mempoolUserOperation: op,
311
- userOperationHash: (0, utils_1.getUserOperationHash)(op, entryPoint, this.walletClient.chain.id)
421
+ userOperationHash: (0, utils_1.getUserOperationHash)(op, entryPoint, this.config.walletClient.chain.id)
312
422
  };
313
423
  });
314
424
  const isUserOpVersion06 = opsWithHashes.reduce((acc, op) => {
@@ -322,8 +432,8 @@ class Executor {
322
432
  abi: isUserOpVersion06 ? types_1.EntryPointV06Abi : types_1.EntryPointV07Abi,
323
433
  address: entryPoint,
324
434
  client: {
325
- public: this.publicClient,
326
- wallet: this.walletClient
435
+ public: this.config.publicClient,
436
+ wallet: this.config.walletClient
327
437
  }
328
438
  });
329
439
  let childLogger = this.logger.child({
@@ -331,18 +441,39 @@ class Executor {
331
441
  entryPoint
332
442
  });
333
443
  childLogger.debug("bundling user operation");
334
- const gasPriceParameters = await this.gasPriceManager.getGasPrice();
335
- childLogger.debug({ gasPriceParameters }, "got gas price");
336
- const nonce = await this.publicClient.getTransactionCount({
337
- address: wallet.address,
338
- blockTag: "pending"
339
- });
340
- childLogger.trace({ nonce }, "got nonce");
444
+ // These calls can throw, so we try/catch them to mark wallet as processed in event of error.
445
+ let nonce;
446
+ let gasPriceParameters;
447
+ try {
448
+ ;
449
+ [gasPriceParameters, nonce] = await Promise.all([
450
+ this.gasPriceManager.tryGetNetworkGasPrice(),
451
+ this.config.publicClient.getTransactionCount({
452
+ address: wallet.address,
453
+ blockTag: "pending"
454
+ })
455
+ ]);
456
+ }
457
+ catch (err) {
458
+ childLogger.error({ error: err }, "Failed to get parameters for bundling");
459
+ this.markWalletProcessed(wallet);
460
+ return opsWithHashes.map((owh) => {
461
+ return {
462
+ status: "resubmit",
463
+ info: {
464
+ entryPoint,
465
+ userOpHash: owh.userOperationHash,
466
+ userOperation: owh.mempoolUserOperation,
467
+ reason: "Failed to get parameters for bundling"
468
+ }
469
+ };
470
+ });
471
+ }
341
472
  const callContext = {
342
473
  ep,
343
474
  type: "default"
344
475
  };
345
- let { gasLimit, simulatedOps } = await (0, utils_2.filterOpsAndEstimateGas)(entryPoint, callContext, wallet, opsWithHashes, nonce, gasPriceParameters.maxFeePerGas, gasPriceParameters.maxPriorityFeePerGas, this.blockTagSupport ? "pending" : undefined, this.legacyTransactions, this.fixedGasLimitForEstimation, this.reputationManager, childLogger);
476
+ let { gasLimit, simulatedOps } = await (0, utils_2.filterOpsAndEstimateGas)(entryPoint, callContext, wallet, opsWithHashes, nonce, gasPriceParameters.maxFeePerGas, gasPriceParameters.maxPriorityFeePerGas, this.config.blockTagSupport ? "pending" : undefined, this.config.legacyTransactions, this.config.fixedGasLimitForEstimation, this.reputationManager, childLogger);
346
477
  if (simulatedOps.length === 0) {
347
478
  childLogger.error("gas limit simulation encountered unexpected failure");
348
479
  this.markWalletProcessed(wallet);
@@ -397,14 +528,14 @@ class Executor {
397
528
  childLogger.debug({ gasLimit }, "got gas limit");
398
529
  let transactionHash;
399
530
  try {
400
- const isLegacyTransaction = this.legacyTransactions;
531
+ const isLegacyTransaction = this.config.legacyTransactions;
401
532
  const gasOptions = isLegacyTransaction
402
533
  ? { gasPrice: gasPriceParameters.maxFeePerGas }
403
534
  : {
404
535
  maxFeePerGas: gasPriceParameters.maxFeePerGas,
405
536
  maxPriorityFeePerGas: gasPriceParameters.maxPriorityFeePerGas
406
537
  };
407
- if (this.noProfitBundling) {
538
+ if (this.config.noProfitBundling) {
408
539
  const gasPrice = totalBeneficiaryFees / gasLimit;
409
540
  if (isLegacyTransaction) {
410
541
  gasOptions.gasPrice = gasPrice;
@@ -422,7 +553,15 @@ class Executor {
422
553
  const userOps = opsWithHashToBundle.map((owh) => isUserOpVersion06
423
554
  ? owh.mempoolUserOperation
424
555
  : (0, utils_1.toPackedUserOperation)(owh.mempoolUserOperation));
425
- transactionHash = await ep.write.handleOps([userOps, wallet.address], opts);
556
+ transactionHash = await this.sendHandleOpsTransaction({
557
+ txParam: {
558
+ type: "default",
559
+ ops: userOps,
560
+ isUserOpVersion06,
561
+ entryPoint
562
+ },
563
+ opts
564
+ });
426
565
  opsWithHashToBundle.map(({ userOperationHash }) => {
427
566
  this.eventManager.emitSubmitted(userOperationHash, transactionHash);
428
567
  });
@@ -444,23 +583,6 @@ class Executor {
444
583
  };
445
584
  });
446
585
  }
447
- if (e?.details
448
- .toLowerCase()
449
- .includes("replacement transaction underpriced")) {
450
- childLogger.error({ error: e }, "replacement transaction underpriced");
451
- this.markWalletProcessed(wallet);
452
- return opsWithHashToBundle.map((owh) => {
453
- return {
454
- status: "resubmit",
455
- info: {
456
- entryPoint,
457
- userOpHash: owh.userOperationHash,
458
- userOperation: owh.mempoolUserOperation,
459
- reason: "replacement transaction underpriced"
460
- }
461
- };
462
- });
463
- }
464
586
  sentry.captureException(err);
465
587
  childLogger.error({ error: JSON.stringify(err) }, "error submitting bundle transaction");
466
588
  this.markWalletProcessed(wallet);
@@ -494,25 +616,8 @@ class Executor {
494
616
  transactionRequest: {
495
617
  account: wallet,
496
618
  to: ep.address,
497
- data: isUserOpVersion06
498
- ? (0, viem_1.encodeFunctionData)({
499
- abi: ep.abi,
500
- functionName: "handleOps",
501
- args: [
502
- opsWithHashToBundle.map((owh) => owh.mempoolUserOperation),
503
- wallet.address
504
- ]
505
- })
506
- : (0, viem_1.encodeFunctionData)({
507
- abi: ep.abi,
508
- functionName: "handleOps",
509
- args: [
510
- opsWithHashToBundle.map((owh) => (0, utils_1.toPackedUserOperation)(owh.mempoolUserOperation)),
511
- wallet.address
512
- ]
513
- }),
514
619
  gas: gasLimit,
515
- chain: this.walletClient.chain,
620
+ chain: this.config.walletClient.chain,
516
621
  maxFeePerGas: gasPriceParameters.maxFeePerGas,
517
622
  maxPriorityFeePerGas: gasPriceParameters.maxPriorityFeePerGas,
518
623
  nonce: nonce
@@ -542,15 +647,36 @@ class Executor {
542
647
  entryPoint: entryPoint
543
648
  });
544
649
  childLogger.debug("bundling compressed user operation");
545
- const gasPriceParameters = await this.gasPriceManager.getGasPrice();
546
- childLogger.debug({ gasPriceParameters }, "got gas price");
547
- const nonce = await this.publicClient.getTransactionCount({
548
- address: wallet.address,
549
- blockTag: "pending"
550
- });
551
- childLogger.trace({ nonce }, "got nonce");
650
+ let nonce;
651
+ let gasPriceParameters;
652
+ try {
653
+ ;
654
+ [gasPriceParameters, nonce] = await Promise.all([
655
+ this.gasPriceManager.tryGetNetworkGasPrice(),
656
+ this.config.publicClient.getTransactionCount({
657
+ address: wallet.address,
658
+ blockTag: "pending"
659
+ })
660
+ ]);
661
+ }
662
+ catch (err) {
663
+ childLogger.error({ error: err }, "Failed to get parameters for bundling");
664
+ this.markWalletProcessed(wallet);
665
+ return compressedOps.map((compressedOp) => {
666
+ const userOpHash = (0, utils_1.getUserOperationHash)(compressedOp.inflatedOp, entryPoint, this.config.walletClient.chain.id);
667
+ return {
668
+ status: "resubmit",
669
+ info: {
670
+ entryPoint,
671
+ userOpHash,
672
+ userOperation: compressedOp,
673
+ reason: "Failed to get parameters for bundling"
674
+ }
675
+ };
676
+ });
677
+ }
552
678
  const callContext = {
553
- publicClient: this.publicClient,
679
+ publicClient: this.config.publicClient,
554
680
  bundleBulker: compressionHandler.bundleBulkerAddress,
555
681
  perOpInflatorId: compressionHandler.perOpInflatorId,
556
682
  type: "compressed"
@@ -558,15 +684,15 @@ class Executor {
558
684
  let { gasLimit, simulatedOps } = await (0, utils_2.filterOpsAndEstimateGas)(entryPoint, callContext, wallet, compressedOps.map((compressedOp) => {
559
685
  return {
560
686
  mempoolUserOperation: compressedOp,
561
- userOperationHash: (0, utils_1.getUserOperationHash)(compressedOp.inflatedOp, entryPoint, this.walletClient.chain.id)
687
+ userOperationHash: (0, utils_1.getUserOperationHash)(compressedOp.inflatedOp, entryPoint, this.config.walletClient.chain.id)
562
688
  };
563
- }), nonce, gasPriceParameters.maxFeePerGas, gasPriceParameters.maxPriorityFeePerGas, this.blockTagSupport ? "pending" : undefined, this.legacyTransactions, this.fixedGasLimitForEstimation, this.reputationManager, childLogger);
689
+ }), nonce, gasPriceParameters.maxFeePerGas, gasPriceParameters.maxPriorityFeePerGas, this.config.blockTagSupport ? "pending" : undefined, this.config.legacyTransactions, this.config.fixedGasLimitForEstimation, this.reputationManager, childLogger);
564
690
  gasLimit += 10000n;
565
691
  if (simulatedOps.length === 0) {
566
692
  childLogger.warn("no ops to bundle");
567
693
  this.markWalletProcessed(wallet);
568
694
  return compressedOps.map((compressedOp) => {
569
- const userOpHash = (0, utils_1.getUserOperationHash)(compressedOp.inflatedOp, entryPoint, this.walletClient.chain.id);
695
+ const userOpHash = (0, utils_1.getUserOperationHash)(compressedOp.inflatedOp, entryPoint, this.config.walletClient.chain.id);
570
696
  return {
571
697
  status: "failure",
572
698
  error: {
@@ -599,7 +725,7 @@ class Executor {
599
725
  .map((simulatedOp) => simulatedOp.owh);
600
726
  let transactionHash;
601
727
  try {
602
- const gasOptions = this.legacyTransactions
728
+ const gasOptions = this.config.legacyTransactions
603
729
  ? {
604
730
  gasPrice: gasPriceParameters.maxFeePerGas
605
731
  }
@@ -611,14 +737,12 @@ class Executor {
611
737
  const compressedOp = mempoolUserOperation;
612
738
  return compressedOp;
613
739
  });
614
- // need to use sendTransaction to target BundleBulker's fallback
615
- transactionHash = await this.walletClient.sendTransaction({
616
- account: wallet,
617
- to: compressionHandler.bundleBulkerAddress,
618
- data: (0, utils_2.createCompressedCalldata)(compressedOpsToBundle, compressionHandler.perOpInflatorId),
619
- gas: gasLimit,
620
- nonce: nonce,
621
- ...gasOptions
740
+ transactionHash = await this.sendHandleOpsTransaction({
741
+ txParam: {
742
+ type: "compressed",
743
+ compressedOps: compressedOpsToBundle
744
+ },
745
+ opts: { ...gasOptions, gas: gasLimit, account: wallet, nonce }
622
746
  });
623
747
  opsToBundle.map(({ userOperationHash }) => {
624
748
  this.eventManager.emitSubmitted(userOperationHash, transactionHash);
@@ -657,10 +781,9 @@ class Executor {
657
781
  previousTransactionHashes: [],
658
782
  transactionRequest: {
659
783
  to: compressionHandler.bundleBulkerAddress,
660
- data: (0, utils_2.createCompressedCalldata)(compressedOps, compressionHandler.perOpInflatorId),
661
784
  gas: gasLimit,
662
785
  account: wallet,
663
- chain: this.walletClient.chain,
786
+ chain: this.config.walletClient.chain,
664
787
  maxFeePerGas: gasPriceParameters.maxFeePerGas,
665
788
  maxPriorityFeePerGas: gasPriceParameters.maxPriorityFeePerGas,
666
789
  nonce: nonce