@pimlico/alto 0.0.0-staging.20240606T101054 → 0.0.0-staging.20240606T102147

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 +4 -2
@@ -0,0 +1,338 @@
1
+ import { RpcError, gasStationResult } from "../types/index.js";
2
+ import { maxBigInt, minBigInt } from "./index.js";
3
+ import * as sentry from "@sentry/node";
4
+ import { parseGwei } from "viem";
5
+ import * as chains from "viem/chains";
6
+ var ChainId;
7
+ (function (ChainId) {
8
+ ChainId[ChainId["Goerli"] = 5] = "Goerli";
9
+ ChainId[ChainId["Polygon"] = 137] = "Polygon";
10
+ ChainId[ChainId["Mumbai"] = 80001] = "Mumbai";
11
+ ChainId[ChainId["LineaTestnet"] = 59140] = "LineaTestnet";
12
+ ChainId[ChainId["Linea"] = 59144] = "Linea";
13
+ })(ChainId || (ChainId = {}));
14
+ const MIN_POLYGON_GAS_PRICE = parseGwei("31");
15
+ const MIN_MUMBAI_GAS_PRICE = parseGwei("1");
16
+ function getGasStationUrl(chainId) {
17
+ switch (chainId) {
18
+ case ChainId.Polygon:
19
+ return "https://gasstation.polygon.technology/v2";
20
+ case ChainId.Mumbai:
21
+ return "https://gasstation-testnet.polygon.technology/v2";
22
+ }
23
+ }
24
+ export class GasPriceManager {
25
+ chain;
26
+ publicClient;
27
+ legacyTransactions;
28
+ logger;
29
+ queueBaseFeePerGas = []; // Store pairs of [price, timestamp]
30
+ queueMaxFeePerGas = []; // Store pairs of [price, timestamp]
31
+ queueMaxPriorityFeePerGas = []; // Store pairs of [price, timestamp]
32
+ maxQueueSize;
33
+ gasBumpMultiplier;
34
+ constructor(chain, publicClient, legacyTransactions, logger, gasBumpMultiplier, gasPriceTimeValidityInSeconds = 10) {
35
+ this.maxQueueSize = gasPriceTimeValidityInSeconds;
36
+ this.chain = chain;
37
+ this.publicClient = publicClient;
38
+ this.legacyTransactions = legacyTransactions;
39
+ this.logger = logger;
40
+ this.gasBumpMultiplier = gasBumpMultiplier;
41
+ }
42
+ getDefaultGasFee(chainId) {
43
+ switch (chainId) {
44
+ case ChainId.Polygon:
45
+ return MIN_POLYGON_GAS_PRICE;
46
+ case ChainId.Mumbai:
47
+ return MIN_MUMBAI_GAS_PRICE;
48
+ default:
49
+ return 0n;
50
+ }
51
+ }
52
+ async getPolygonGasPriceParameters() {
53
+ const gasStationUrl = getGasStationUrl(this.chain.id);
54
+ try {
55
+ const data = await (await fetch(gasStationUrl)).json();
56
+ // take the standard speed here, SDK options will define the extra tip
57
+ const parsedData = gasStationResult.parse(data);
58
+ return parsedData.fast;
59
+ }
60
+ catch (e) {
61
+ this.logger.error({ error: e }, "failed to get gas price from gas station, using default");
62
+ return null;
63
+ }
64
+ }
65
+ bumpTheGasPrice(gasPriceParameters) {
66
+ const bumpAmount = this.gasBumpMultiplier;
67
+ const maxPriorityFeePerGas = maxBigInt(gasPriceParameters.maxPriorityFeePerGas, this.getDefaultGasFee(this.chain.id));
68
+ const maxFeePerGas = maxBigInt(gasPriceParameters.maxFeePerGas, maxPriorityFeePerGas);
69
+ const result = {
70
+ maxFeePerGas: (maxFeePerGas * bumpAmount) / 100n,
71
+ maxPriorityFeePerGas: (maxPriorityFeePerGas * bumpAmount) / 100n
72
+ };
73
+ if (this.chain.id === chains.celo.id ||
74
+ this.chain.id === chains.celoAlfajores.id) {
75
+ const maxFee = maxBigInt(result.maxFeePerGas, result.maxPriorityFeePerGas);
76
+ return {
77
+ maxFeePerGas: maxFee,
78
+ maxPriorityFeePerGas: maxFee
79
+ };
80
+ }
81
+ if (this.chain.id === chains.dfk.id) {
82
+ const maxFeePerGas = maxBigInt(5000000000n, result.maxFeePerGas);
83
+ const maxPriorityFeePerGas = maxBigInt(5000000000n, result.maxPriorityFeePerGas);
84
+ return {
85
+ maxFeePerGas,
86
+ maxPriorityFeePerGas
87
+ };
88
+ }
89
+ // set a minimum maxPriorityFee & maxFee to 1.5gwei on avalanche (because eth_maxPriorityFeePerGas returns 0)
90
+ if (this.chain.id === chains.avalanche.id) {
91
+ const maxFeePerGas = maxBigInt(parseGwei("1.5"), result.maxFeePerGas);
92
+ const maxPriorityFeePerGas = maxBigInt(parseGwei("1.5"), result.maxPriorityFeePerGas);
93
+ return {
94
+ maxFeePerGas,
95
+ maxPriorityFeePerGas
96
+ };
97
+ }
98
+ return result;
99
+ }
100
+ async getFallBackMaxPriorityFeePerGas(publicClient, gasPrice) {
101
+ const feeHistory = await publicClient.getFeeHistory({
102
+ blockCount: 10,
103
+ rewardPercentiles: [20],
104
+ blockTag: "latest"
105
+ });
106
+ if (feeHistory.reward === undefined || feeHistory.reward === null) {
107
+ return gasPrice;
108
+ }
109
+ const feeAverage = feeHistory.reward.reduce((acc, cur) => cur[0] + acc, 0n) / 10n;
110
+ return minBigInt(feeAverage, gasPrice);
111
+ }
112
+ async getNextBaseFee(publicClient) {
113
+ const block = await publicClient.getBlock({
114
+ blockTag: "latest"
115
+ });
116
+ const currentBaseFeePerGas = block.baseFeePerGas || (await publicClient.getGasPrice());
117
+ const currentGasUsed = block.gasUsed;
118
+ const gasTarget = block.gasLimit / 2n;
119
+ if (currentGasUsed === gasTarget) {
120
+ return currentBaseFeePerGas;
121
+ }
122
+ if (currentGasUsed > gasTarget) {
123
+ const gasUsedDelta = currentGasUsed - gasTarget;
124
+ const baseFeePerGasDelta = maxBigInt((currentBaseFeePerGas * gasUsedDelta) / gasTarget / 8n, 1n);
125
+ return currentBaseFeePerGas + baseFeePerGasDelta;
126
+ }
127
+ const gasUsedDelta = currentGasUsed - gasTarget;
128
+ const baseFeePerGasDelta = (currentBaseFeePerGas * gasUsedDelta) / gasTarget / 8n;
129
+ return currentBaseFeePerGas - baseFeePerGasDelta;
130
+ }
131
+ async getLegacyTransactionGasPrice() {
132
+ let gasPrice;
133
+ try {
134
+ const gasInfo = await this.publicClient.estimateFeesPerGas({
135
+ chain: this.chain,
136
+ type: "legacy"
137
+ });
138
+ gasPrice = gasInfo.gasPrice;
139
+ }
140
+ catch (e) {
141
+ sentry.captureException(e);
142
+ this.logger.error("failed to fetch legacy gasPrices from estimateFeesPerGas", { error: e });
143
+ gasPrice = undefined;
144
+ }
145
+ if (gasPrice === undefined) {
146
+ this.logger.warn("gasPrice is undefined, using fallback value");
147
+ try {
148
+ gasPrice = await this.publicClient.getGasPrice();
149
+ }
150
+ catch (e) {
151
+ this.logger.error("failed to get fallback gasPrice");
152
+ sentry.captureException(e);
153
+ throw e;
154
+ }
155
+ }
156
+ return {
157
+ maxFeePerGas: gasPrice,
158
+ maxPriorityFeePerGas: gasPrice
159
+ };
160
+ }
161
+ async estimateGasPrice() {
162
+ let maxFeePerGas;
163
+ let maxPriorityFeePerGas;
164
+ try {
165
+ const fees = await this.publicClient.estimateFeesPerGas({
166
+ chain: this.chain
167
+ });
168
+ maxFeePerGas = fees.maxFeePerGas;
169
+ maxPriorityFeePerGas = fees.maxPriorityFeePerGas;
170
+ }
171
+ catch (e) {
172
+ sentry.captureException(e);
173
+ this.logger.error("failed to fetch eip-1559 gasPrices from estimateFeesPerGas", { error: e });
174
+ maxFeePerGas = undefined;
175
+ maxPriorityFeePerGas = undefined;
176
+ }
177
+ if (maxPriorityFeePerGas === undefined) {
178
+ this.logger.warn("maxPriorityFeePerGas is undefined, using fallback value");
179
+ try {
180
+ maxPriorityFeePerGas =
181
+ await this.getFallBackMaxPriorityFeePerGas(this.publicClient, maxFeePerGas ?? 0n);
182
+ }
183
+ catch (e) {
184
+ this.logger.error("failed to get fallback maxPriorityFeePerGas");
185
+ sentry.captureException(e);
186
+ throw e;
187
+ }
188
+ }
189
+ if (maxFeePerGas === undefined) {
190
+ this.logger.warn("maxFeePerGas is undefined, using fallback value");
191
+ try {
192
+ maxFeePerGas =
193
+ (await this.getNextBaseFee(this.publicClient)) +
194
+ maxPriorityFeePerGas;
195
+ }
196
+ catch (e) {
197
+ this.logger.error("failed to get fallback maxFeePerGas");
198
+ sentry.captureException(e);
199
+ throw e;
200
+ }
201
+ }
202
+ if (maxPriorityFeePerGas === 0n) {
203
+ maxPriorityFeePerGas = maxFeePerGas / 200n;
204
+ }
205
+ return { maxFeePerGas, maxPriorityFeePerGas };
206
+ }
207
+ saveBaseFeePerGas(gasPrice, timestamp) {
208
+ const queue = this.queueBaseFeePerGas;
209
+ const last = queue.length > 0 ? queue[queue.length - 1] : null;
210
+ if (!last || timestamp - last.timestamp >= 1000) {
211
+ if (queue.length >= this.maxQueueSize) {
212
+ queue.shift();
213
+ }
214
+ queue.push({ baseFeePerGas: gasPrice, timestamp });
215
+ }
216
+ else if (gasPrice < last.baseFeePerGas) {
217
+ last.baseFeePerGas = gasPrice;
218
+ last.timestamp = timestamp;
219
+ }
220
+ }
221
+ saveMaxFeePerGas(gasPrice, timestamp) {
222
+ const queue = this.queueMaxFeePerGas;
223
+ const last = queue.length > 0 ? queue[queue.length - 1] : null;
224
+ if (!last || timestamp - last.timestamp >= 1000) {
225
+ if (queue.length >= this.maxQueueSize) {
226
+ queue.shift();
227
+ }
228
+ queue.push({ maxFeePerGas: gasPrice, timestamp });
229
+ }
230
+ else if (gasPrice < last.maxFeePerGas) {
231
+ last.maxFeePerGas = gasPrice;
232
+ last.timestamp = timestamp;
233
+ }
234
+ }
235
+ saveMaxPriorityFeePerGas(gasPrice, timestamp) {
236
+ const queue = this.queueMaxPriorityFeePerGas;
237
+ const last = queue.length > 0 ? queue[queue.length - 1] : null;
238
+ if (!last || timestamp - last.timestamp >= 1000) {
239
+ if (queue.length >= this.maxQueueSize) {
240
+ queue.shift();
241
+ }
242
+ queue.push({ maxPriorityFeePerGas: gasPrice, timestamp });
243
+ }
244
+ else if (gasPrice < last.maxPriorityFeePerGas) {
245
+ last.maxPriorityFeePerGas = gasPrice;
246
+ last.timestamp = timestamp;
247
+ }
248
+ }
249
+ saveGasPrice(gasPrice, timestamp) {
250
+ return new Promise((resolve) => {
251
+ this.saveMaxFeePerGas(gasPrice.maxFeePerGas, timestamp);
252
+ this.saveMaxPriorityFeePerGas(gasPrice.maxPriorityFeePerGas, timestamp);
253
+ resolve();
254
+ });
255
+ }
256
+ async innerGetGasPrice() {
257
+ let maxFeePerGas = 0n;
258
+ let maxPriorityFeePerGas = 0n;
259
+ if (this.chain.id === chains.polygon.id ||
260
+ this.chain.id === chains.polygonMumbai.id) {
261
+ const polygonEstimate = await this.getPolygonGasPriceParameters();
262
+ if (polygonEstimate) {
263
+ const gasPrice = this.bumpTheGasPrice({
264
+ maxFeePerGas: polygonEstimate.maxFeePerGas,
265
+ maxPriorityFeePerGas: polygonEstimate.maxPriorityFeePerGas
266
+ });
267
+ return {
268
+ maxFeePerGas: maxBigInt(gasPrice.maxFeePerGas, maxFeePerGas),
269
+ maxPriorityFeePerGas: maxBigInt(gasPrice.maxPriorityFeePerGas, maxPriorityFeePerGas)
270
+ };
271
+ }
272
+ }
273
+ if (this.legacyTransactions) {
274
+ const gasPrice = this.bumpTheGasPrice(await this.getLegacyTransactionGasPrice());
275
+ return {
276
+ maxFeePerGas: maxBigInt(gasPrice.maxFeePerGas, maxFeePerGas),
277
+ maxPriorityFeePerGas: maxBigInt(gasPrice.maxPriorityFeePerGas, maxPriorityFeePerGas)
278
+ };
279
+ }
280
+ const estimatedPrice = await this.estimateGasPrice();
281
+ maxFeePerGas = estimatedPrice.maxFeePerGas;
282
+ maxPriorityFeePerGas = estimatedPrice.maxPriorityFeePerGas;
283
+ const gasPrice = this.bumpTheGasPrice({
284
+ maxFeePerGas,
285
+ maxPriorityFeePerGas
286
+ });
287
+ return {
288
+ maxFeePerGas: maxBigInt(gasPrice.maxFeePerGas, maxFeePerGas),
289
+ maxPriorityFeePerGas: maxBigInt(gasPrice.maxPriorityFeePerGas, maxPriorityFeePerGas)
290
+ };
291
+ }
292
+ async getBaseFee() {
293
+ const latestBlock = await this.publicClient.getBlock();
294
+ if (latestBlock.baseFeePerGas === null) {
295
+ throw new RpcError("block does not have baseFeePerGas");
296
+ }
297
+ const baseFee = latestBlock.baseFeePerGas;
298
+ this.saveBaseFeePerGas(baseFee, Date.now());
299
+ return baseFee;
300
+ }
301
+ async getGasPrice() {
302
+ const gasPrice = await this.innerGetGasPrice();
303
+ this.saveGasPrice({
304
+ maxFeePerGas: gasPrice.maxFeePerGas,
305
+ maxPriorityFeePerGas: gasPrice.maxPriorityFeePerGas
306
+ }, Date.now());
307
+ return gasPrice;
308
+ }
309
+ async getMaxBaseFeePerGas() {
310
+ if (this.queueBaseFeePerGas.length === 0) {
311
+ await this.getBaseFee();
312
+ }
313
+ return this.queueBaseFeePerGas.reduce((acc, cur) => maxBigInt(cur.baseFeePerGas, acc), this.queueBaseFeePerGas[0].baseFeePerGas);
314
+ }
315
+ async getMinMaxFeePerGas() {
316
+ if (this.queueMaxFeePerGas.length === 0) {
317
+ await this.getGasPrice();
318
+ }
319
+ return this.queueMaxFeePerGas.reduce((acc, cur) => minBigInt(cur.maxFeePerGas, acc), this.queueMaxFeePerGas[0].maxFeePerGas);
320
+ }
321
+ async getMinMaxPriorityFeePerGas() {
322
+ if (this.queueMaxPriorityFeePerGas.length === 0) {
323
+ await this.getGasPrice();
324
+ }
325
+ return this.queueMaxPriorityFeePerGas.reduce((acc, cur) => minBigInt(cur.maxPriorityFeePerGas, acc), this.queueMaxPriorityFeePerGas[0].maxPriorityFeePerGas);
326
+ }
327
+ async validateGasPrice(gasPrice) {
328
+ const lowestMaxFeePerGas = await this.getMinMaxFeePerGas();
329
+ const lowestMaxPriorityFeePerGas = await this.getMinMaxPriorityFeePerGas();
330
+ if (gasPrice.maxFeePerGas < lowestMaxFeePerGas) {
331
+ throw new RpcError(`maxFeePerGas must be at least ${lowestMaxFeePerGas} (current maxFeePerGas: ${gasPrice.maxFeePerGas}) - use pimlico_getUserOperationGasPrice to get the current gas price`);
332
+ }
333
+ if (gasPrice.maxPriorityFeePerGas < lowestMaxPriorityFeePerGas) {
334
+ throw new RpcError(`maxPriorityFeePerGas must be at least ${lowestMaxPriorityFeePerGas} (current maxPriorityFeePerGas: ${gasPrice.maxPriorityFeePerGas}) - use pimlico_getUserOperationGasPrice to get the current gas price`);
335
+ }
336
+ }
337
+ }
338
+ //# sourceMappingURL=gasPriceManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gasPriceManager.js","sourceRoot":"","sources":["../../utils/gasPriceManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,EACR,gBAAgB,EAEnB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAe,MAAM,aAAa,CAAA;AAC/D,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO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AAQ,CAAC,oBAAoB,GAAG,0BAA0B,EAAE,CAAC;YAC7D,MAAM,IAAI,QAAQ,CACd,yCAAyC,0BAA0B,mCAAmC,QAAQ,CAAC,oBAAoB,uEAAuE,CAC7M,CAAA;QACL,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,4 @@
1
+ import { type Address } from "viem";
2
+ export declare const areAddressesEqual: (a: Address, b: Address) => boolean;
3
+ export declare function getRevertErrorData(err: unknown): `0x${string}` | undefined;
4
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { getAddress, BaseError } from "viem";
2
+ /// Ensure proper equality by converting both addresses into their checksum type
3
+ export const areAddressesEqual = (a, b) => {
4
+ return getAddress(a) === getAddress(b);
5
+ };
6
+ export function getRevertErrorData(err) {
7
+ // biome-ignore lint/style/useBlockStatements:
8
+ if (!(err instanceof BaseError))
9
+ return undefined;
10
+ const error = err.walk();
11
+ return typeof error?.data === "object" ? error.data?.data : error.data;
12
+ }
13
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../utils/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,UAAU,EACV,SAAS,EAEZ,MAAM,MAAM,CAAA;AAEb,gFAAgF;AAChF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAU,EAAE,CAAU,EAAE,EAAE;IACxD,OAAO,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAA;AAC1C,CAAC,CAAA;AAED,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC3C,8CAA8C;IAC9C,IAAI,CAAC,CAAC,GAAG,YAAY,SAAS,CAAC;QAAE,OAAO,SAAS,CAAA;IACjD,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAsB,CAAA;IAC5C,OAAO,OAAO,KAAK,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAA;AAC1E,CAAC"}
@@ -0,0 +1,11 @@
1
+ export * from "./logger.js";
2
+ export * from "./metrics.js";
3
+ export * from "./bigInt.js";
4
+ export * from "./gasPriceManager.js";
5
+ export * from "./test.js";
6
+ export * from "./validation.js";
7
+ export * from "./userop.js";
8
+ export * from "./compressionHandler.js";
9
+ export * from "./helpers.js";
10
+ export { Logger } from "pino";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,10 @@
1
+ export * from "./logger.js";
2
+ export * from "./metrics.js";
3
+ export * from "./bigInt.js";
4
+ export * from "./gasPriceManager.js";
5
+ export * from "./test.js";
6
+ export * from "./validation.js";
7
+ export * from "./userop.js";
8
+ export * from "./compressionHandler.js";
9
+ export * from "./helpers.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,mBAAmB,CAAA;AACjC,cAAc,QAAQ,CAAA;AACtB,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,sBAAsB,CAAA;AACpC,cAAc,WAAW,CAAA"}
@@ -0,0 +1,6 @@
1
+ import type { Logger } from "./index.js";
2
+ import { type SerializerFn } from "pino";
3
+ export declare const customSerializer: SerializerFn;
4
+ export declare const initDebugLogger: (level?: string) => Logger;
5
+ export declare const initProductionLogger: (level: string) => Logger;
6
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1,76 @@
1
+ import logger from "pino";
2
+ import { toHex } from "viem";
3
+ // biome-ignore lint/suspicious/noExplicitAny: it's a generic type
4
+ function bigintToJson(_key, value) {
5
+ if (typeof value === "bigint") {
6
+ return toHex(value);
7
+ }
8
+ return value;
9
+ }
10
+ function logLevel(label) {
11
+ return {
12
+ level: label
13
+ };
14
+ }
15
+ function stringifyWithCircularHandling(obj,
16
+ // biome-ignore lint/suspicious/noExplicitAny: it's a generic type
17
+ replacer) {
18
+ // biome-ignore lint/suspicious/noExplicitAny: it's a generic type
19
+ const cache = new Set();
20
+ return JSON.stringify(obj, (key, value) => {
21
+ if (typeof value === "object" && value !== null) {
22
+ if (cache.has(value)) {
23
+ return; // Circular reference found, discard the key
24
+ }
25
+ cache.add(value);
26
+ }
27
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
28
+ return replacer ? replacer(key, value) : value;
29
+ });
30
+ }
31
+ export const customSerializer = (input) => {
32
+ const output = {};
33
+ for (const key in input) {
34
+ if (Object.prototype.hasOwnProperty.call(input, key)) {
35
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
36
+ const value = input[key];
37
+ if (typeof value === "object" && value !== null) {
38
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument
39
+ output[key] = JSON.parse(stringifyWithCircularHandling(value, bigintToJson));
40
+ }
41
+ else {
42
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
43
+ output[key] = bigintToJson(key, value);
44
+ }
45
+ }
46
+ }
47
+ return output;
48
+ };
49
+ export const initDebugLogger = (level = "debug") => {
50
+ const l = logger({
51
+ transport: {
52
+ target: "pino-pretty",
53
+ options: {
54
+ colorize: true
55
+ }
56
+ },
57
+ formatters: {
58
+ level: logLevel,
59
+ log: customSerializer
60
+ }
61
+ });
62
+ l.level = level;
63
+ return l;
64
+ };
65
+ export const initProductionLogger = (level) => {
66
+ const l = logger({
67
+ base: undefined, // do not log pid and hostname, we don't need it
68
+ formatters: {
69
+ level: logLevel,
70
+ log: customSerializer
71
+ }
72
+ });
73
+ l.level = level;
74
+ return l;
75
+ };
76
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../utils/logger.ts"],"names":[],"m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
+ export declare function createMetrics(registry: Registry, register?: boolean): {
4
+ httpRequests: Counter<"code" | "method" | "route" | "network" | "chainId" | "rpc_method" | "rpc_status">;
5
+ httpRequestsDuration: Histogram<"code" | "method" | "route" | "network" | "chainId" | "rpc_method" | "rpc_status" | "api_version">;
6
+ userOperationsInMempool: Gauge<"status" | "network" | "chainId">;
7
+ walletsAvailable: Gauge<never>;
8
+ walletsTotal: Gauge<never>;
9
+ userOperationsOnChain: Counter<"status">;
10
+ userOperationsSubmitted: Counter<"status">;
11
+ bundlesIncluded: Counter<never>;
12
+ bundlesSubmitted: Counter<"status">;
13
+ userOperationsReceived: Counter<"type" | "status">;
14
+ userOperationsValidationSuccess: Counter<never>;
15
+ userOperationsValidationFailure: Counter<never>;
16
+ userOperationInclusionDuration: Histogram<never>;
17
+ verificationGasLimitEstimationTime: Histogram<never>;
18
+ verificationGasLimitEstimationCount: Histogram<never>;
19
+ replacedTransactions: Counter<"reason" | "status">;
20
+ userOperationsResubmitted: Counter<never>;
21
+ };
22
+ //# sourceMappingURL=metrics.d.ts.map