@aztec/ethereum 2.1.9-rc.3 → 2.1.9-rc.4

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 (40) hide show
  1. package/dest/deploy_l1_contracts.d.ts.map +1 -1
  2. package/dest/deploy_l1_contracts.js +9 -8
  3. package/dest/l1_tx_utils/constants.d.ts +6 -0
  4. package/dest/l1_tx_utils/constants.d.ts.map +1 -1
  5. package/dest/l1_tx_utils/constants.js +25 -0
  6. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  7. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  8. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  9. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  10. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  11. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  12. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  13. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  14. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  15. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  16. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  17. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  18. package/dest/l1_tx_utils/index.d.ts +2 -0
  19. package/dest/l1_tx_utils/index.d.ts.map +1 -1
  20. package/dest/l1_tx_utils/index.js +2 -0
  21. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +235 -0
  22. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  23. package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
  24. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +0 -13
  25. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  26. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +30 -143
  27. package/dest/utils.d.ts +13 -1
  28. package/dest/utils.d.ts.map +1 -1
  29. package/dest/utils.js +18 -0
  30. package/package.json +6 -5
  31. package/src/deploy_l1_contracts.ts +7 -6
  32. package/src/l1_tx_utils/constants.ts +11 -0
  33. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  34. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
  35. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
  36. package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
  37. package/src/l1_tx_utils/index.ts +2 -0
  38. package/src/l1_tx_utils/l1_fee_analyzer.ts +802 -0
  39. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +42 -186
  40. package/src/utils.ts +29 -0
@@ -0,0 +1,506 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+ import { retryUntil } from '@aztec/foundation/retry';
3
+ import { DateProvider } from '@aztec/foundation/timer';
4
+ import { formatGwei } from 'viem';
5
+ import { calculatePercentile, isBlobTransaction } from '../utils.js';
6
+ import { BLOB_CAPACITY_SCHEDULE, GAS_PER_BLOB, WEI_CONST } from './constants.js';
7
+ import { DEFAULT_PRIORITY_FEE_STRATEGIES } from './fee-strategies/index.js';
8
+ /**
9
+ * Gets the maximum blob capacity for a given block timestamp
10
+ */ function getMaxBlobCapacity(blockTimestamp) {
11
+ const timestamp = Number(blockTimestamp);
12
+ // Find the applicable schedule entry (sorted by timestamp descending)
13
+ for (const schedule of BLOB_CAPACITY_SCHEDULE){
14
+ if (timestamp >= schedule.timestamp) {
15
+ return schedule.max;
16
+ }
17
+ }
18
+ // Fallback (should never hit)
19
+ return BLOB_CAPACITY_SCHEDULE[BLOB_CAPACITY_SCHEDULE.length - 1].max;
20
+ }
21
+ /**
22
+ * Processes a list of transactions to extract blob transaction info and priority fees.
23
+ * Handles both pending and mined transactions.
24
+ * Note: Only works with blocks fetched with includeTransactions: true
25
+ */ function processTransactions(transactions) {
26
+ const blobTxs = [];
27
+ const allPriorityFees = [];
28
+ const blobPriorityFees = [];
29
+ let totalBlobCount = 0;
30
+ if (!transactions) {
31
+ return {
32
+ blobTxs,
33
+ allPriorityFees,
34
+ blobPriorityFees,
35
+ totalBlobCount
36
+ };
37
+ }
38
+ for (const tx of transactions){
39
+ const priorityFee = tx.maxPriorityFeePerGas || 0n;
40
+ if (priorityFee > 0n) {
41
+ allPriorityFees.push(priorityFee);
42
+ }
43
+ // Check if this is a blob transaction
44
+ if (isBlobTransaction(tx)) {
45
+ const blobCount = tx.blobVersionedHashes.length;
46
+ totalBlobCount += blobCount;
47
+ if (priorityFee > 0n) {
48
+ blobPriorityFees.push(priorityFee);
49
+ }
50
+ blobTxs.push({
51
+ hash: tx.hash,
52
+ maxPriorityFeePerGas: priorityFee,
53
+ maxFeePerGas: tx.maxFeePerGas || 0n,
54
+ maxFeePerBlobGas: tx.maxFeePerBlobGas,
55
+ blobCount,
56
+ gas: tx.gas
57
+ });
58
+ }
59
+ }
60
+ return {
61
+ blobTxs,
62
+ allPriorityFees,
63
+ blobPriorityFees,
64
+ totalBlobCount
65
+ };
66
+ }
67
+ /**
68
+ * Analyzes L1 transaction fees in fisherman mode.
69
+ * Captures pending block state, records gas calculations, and compares to what gets included.
70
+ * Supports multiple priority fee calculation strategies for comparison.
71
+ */ export class L1FeeAnalyzer {
72
+ client;
73
+ dateProvider;
74
+ logger;
75
+ maxCompletedAnalyses;
76
+ gasConfig;
77
+ pendingAnalyses;
78
+ pendingCallbacks;
79
+ completedAnalyses;
80
+ analysisCounter;
81
+ strategies;
82
+ constructor(client, dateProvider = new DateProvider(), logger = createLogger('ethereum:l1-fee-analyzer'), maxCompletedAnalyses = 100, strategies = DEFAULT_PRIORITY_FEE_STRATEGIES, gasConfig = {}){
83
+ this.client = client;
84
+ this.dateProvider = dateProvider;
85
+ this.logger = logger;
86
+ this.maxCompletedAnalyses = maxCompletedAnalyses;
87
+ this.gasConfig = gasConfig;
88
+ this.pendingAnalyses = new Map();
89
+ this.pendingCallbacks = new Map();
90
+ this.completedAnalyses = [];
91
+ this.analysisCounter = 0;
92
+ this.strategies = strategies;
93
+ }
94
+ /**
95
+ * Executes all configured strategies and returns their results.
96
+ * Each strategy handles its own RPC calls internally.
97
+ * @param isBlobTx - Whether this is a blob transaction
98
+ * @returns Array of strategy results
99
+ */ async executeAllStrategies(isBlobTx) {
100
+ const results = [];
101
+ const context = {
102
+ gasConfig: this.gasConfig,
103
+ isBlobTx,
104
+ logger: this.logger
105
+ };
106
+ for (const strategy of this.strategies){
107
+ try {
108
+ const result = await strategy.execute(this.client, context);
109
+ results.push({
110
+ strategyId: strategy.id,
111
+ strategyName: strategy.name,
112
+ calculatedPriorityFee: result.priorityFee,
113
+ debugInfo: result.debugInfo
114
+ });
115
+ this.logger.debug(`Strategy "${strategy.name}" calculated priority fee`, {
116
+ strategyId: strategy.id,
117
+ priorityFee: formatGwei(result.priorityFee),
118
+ ...result.debugInfo
119
+ });
120
+ } catch (err) {
121
+ this.logger.error(`Error calculating priority fee for strategy "${strategy.name}"`, err, {
122
+ strategyId: strategy.id
123
+ });
124
+ }
125
+ }
126
+ return results;
127
+ }
128
+ /**
129
+ * Captures a snapshot of the current pending block state
130
+ */ async capturePendingSnapshot() {
131
+ const timestamp = this.dateProvider.now();
132
+ // Fetch data in parallel
133
+ const [latestBlock, pendingBlock, blobBaseFee] = await Promise.all([
134
+ this.client.getBlock({
135
+ blockTag: 'latest'
136
+ }),
137
+ this.client.getBlock({
138
+ blockTag: 'pending',
139
+ includeTransactions: true
140
+ }).catch(()=>null),
141
+ this.client.getBlobBaseFee().catch(()=>0n)
142
+ ]);
143
+ const baseFeePerGas = latestBlock.baseFeePerGas || 0n;
144
+ const latestBlockNumber = latestBlock.number;
145
+ // Extract blob transaction info from pending block
146
+ const { blobTxs: pendingBlobTxs, allPriorityFees: allPendingPriorityFees, blobPriorityFees: pendingBlobPriorityFees, totalBlobCount: pendingBlobCount } = processTransactions(pendingBlock?.transactions);
147
+ // Calculate 75th percentile priority fees
148
+ const pendingP75PriorityFee = calculatePercentile(allPendingPriorityFees, 75);
149
+ const pendingBlobP75PriorityFee = calculatePercentile(pendingBlobPriorityFees, 75);
150
+ const pendingTxCount = pendingBlock?.transactions?.length || 0;
151
+ return {
152
+ timestamp,
153
+ latestBlockNumber,
154
+ baseFeePerGas,
155
+ blobBaseFee,
156
+ pendingTxCount,
157
+ pendingBlobTxCount: pendingBlobTxs.length,
158
+ pendingBlobCount,
159
+ pendingBlobTxs,
160
+ pendingP75PriorityFee,
161
+ pendingBlobP75PriorityFee
162
+ };
163
+ }
164
+ /**
165
+ * Starts a fee analysis for a transaction bundle
166
+ * @param l2SlotNumber - The L2 slot this analysis is for
167
+ * @param gasLimit - The estimated gas limit
168
+ * @param requests - The transaction requests being analyzed
169
+ * @param blobInputs - Blob inputs if this is a blob transaction
170
+ * @param onComplete - Optional callback to invoke when analysis completes
171
+ * @returns The analysis ID for tracking
172
+ */ async startAnalysis(l2SlotNumber, gasLimit, requests, blobInputs, onComplete) {
173
+ const id = `fee-analysis-${++this.analysisCounter}-${Date.now()}`;
174
+ const blobCount = blobInputs?.blobs?.length || 0;
175
+ const isBlobTx = blobCount > 0;
176
+ // Execute all strategies and capture pending snapshot in parallel
177
+ const [pendingSnapshot, strategyResults] = await Promise.all([
178
+ this.capturePendingSnapshot(),
179
+ this.executeAllStrategies(isBlobTx)
180
+ ]);
181
+ const analysis = {
182
+ id,
183
+ l2SlotNumber,
184
+ pendingSnapshot,
185
+ computedPrices: {
186
+ gasLimit,
187
+ blobCount,
188
+ strategyResults
189
+ },
190
+ txInfo: {
191
+ requestCount: requests.length,
192
+ hasBlobData: isBlobTx,
193
+ totalEstimatedGas: gasLimit
194
+ }
195
+ };
196
+ this.pendingAnalyses.set(id, analysis);
197
+ if (onComplete) {
198
+ this.pendingCallbacks.set(id, onComplete);
199
+ }
200
+ // Log strategy calculations
201
+ const strategyLogInfo = strategyResults.reduce((acc, s)=>{
202
+ acc[`strategy_${s.strategyId}`] = formatGwei(s.calculatedPriorityFee);
203
+ return acc;
204
+ }, {});
205
+ this.logger.debug('Started fee analysis with strategy calculations', {
206
+ id,
207
+ l2SlotNumber: l2SlotNumber.toString(),
208
+ pendingBlobTxCount: pendingSnapshot.pendingBlobTxCount,
209
+ pendingBlobCount: pendingSnapshot.pendingBlobCount,
210
+ pendingBlobP75: formatGwei(pendingSnapshot.pendingBlobP75PriorityFee),
211
+ strategiesAnalyzed: strategyResults.length,
212
+ ...strategyLogInfo
213
+ });
214
+ // Start watching for the next block
215
+ void this.watchForNextBlock(id, pendingSnapshot.latestBlockNumber);
216
+ return id;
217
+ }
218
+ /**
219
+ * Watches for the next block to be mined and completes the analysis
220
+ */ async watchForNextBlock(analysisId, startBlockNumber) {
221
+ const analysis = this.pendingAnalyses.get(analysisId);
222
+ if (!analysis) {
223
+ return;
224
+ }
225
+ try {
226
+ // wait for next block
227
+ await retryUntil(async ()=>{
228
+ const currentBlockNumber = await this.client.getBlockNumber();
229
+ if (currentBlockNumber > startBlockNumber) {
230
+ return true;
231
+ }
232
+ return false;
233
+ }, 'Wait for next block', 13_000, 0.5);
234
+ const minedBlock = await this.client.getBlock({
235
+ includeTransactions: true
236
+ });
237
+ this.completeAnalysis(analysisId, minedBlock);
238
+ } catch (err) {
239
+ this.logger.error('Error waiting for next block in fee analysis', err, {
240
+ analysisId
241
+ });
242
+ } finally{
243
+ this.pendingAnalyses.delete(analysisId);
244
+ }
245
+ }
246
+ /**
247
+ * Completes the analysis once the next block is mined
248
+ */ completeAnalysis(analysisId, minedBlock) {
249
+ const analysis = this.pendingAnalyses.get(analysisId);
250
+ if (!analysis) {
251
+ return;
252
+ }
253
+ // Extract blob transaction info from mined block
254
+ const { blobTxs: includedBlobTxs, allPriorityFees: includedPriorityFees, blobPriorityFees: includedBlobPriorityFees, totalBlobCount: includedBlobCount } = processTransactions(minedBlock.transactions);
255
+ // Get minimum included fees
256
+ const minIncludedPriorityFee = includedPriorityFees.length > 0 ? this.minBigInt(includedPriorityFees) : 0n;
257
+ const minIncludedBlobPriorityFee = includedBlobPriorityFees.length > 0 ? this.minBigInt(includedBlobPriorityFees) : 0n;
258
+ // Populate mined block info
259
+ analysis.minedBlock = {
260
+ blockNumber: minedBlock.number,
261
+ blockHash: minedBlock.hash,
262
+ blockTimestamp: minedBlock.timestamp,
263
+ baseFeePerGas: minedBlock.baseFeePerGas || 0n,
264
+ blobGasUsed: minedBlock.blobGasUsed || 0n,
265
+ txCount: minedBlock.transactions?.length || 0,
266
+ includedBlobTxCount: includedBlobTxs.length,
267
+ includedBlobCount,
268
+ includedBlobTxs,
269
+ minIncludedPriorityFee,
270
+ minIncludedBlobPriorityFee
271
+ };
272
+ // Calculate time before block mined
273
+ const blockTimestampMs = Number(minedBlock.timestamp) * 1000;
274
+ const timeBeforeBlockMs = blockTimestampMs - analysis.pendingSnapshot.timestamp;
275
+ // Calculate how many blobs were actually in the mined block
276
+ const blobsInBlock = minedBlock.blobGasUsed > 0n ? Number(minedBlock.blobGasUsed / GAS_PER_BLOB) : 0;
277
+ const maxBlobCapacity = getMaxBlobCapacity(minedBlock.timestamp);
278
+ const blockBlobsFull = blobsInBlock >= maxBlobCapacity;
279
+ // Count how many pending blob txs actually got included
280
+ const pendingBlobHashes = new Set(analysis.pendingSnapshot.pendingBlobTxs.map((tx)=>tx.hash));
281
+ const includedBlobHashes = new Set(includedBlobTxs.map((tx)=>tx.hash));
282
+ const pendingBlobTxsIncludedCount = [
283
+ ...pendingBlobHashes
284
+ ].filter((h)=>includedBlobHashes.has(h)).length;
285
+ const pendingBlobTxsExcludedCount = analysis.pendingSnapshot.pendingBlobTxCount - pendingBlobTxsIncludedCount;
286
+ analysis.analysis = {
287
+ timeBeforeBlockMs,
288
+ pendingBlobTxsIncludedCount,
289
+ pendingBlobTxsExcludedCount,
290
+ blobsInBlock,
291
+ maxBlobCapacity,
292
+ blockBlobsFull
293
+ };
294
+ // Evaluate each strategy against the mined block
295
+ const isBlobTx = analysis.computedPrices.blobCount > 0;
296
+ const minPriorityFeeToCompare = isBlobTx ? minIncludedBlobPriorityFee : minIncludedPriorityFee;
297
+ const gasLimit = analysis.computedPrices.gasLimit;
298
+ if (analysis.computedPrices.strategyResults) {
299
+ for (const strategyResult of analysis.computedPrices.strategyResults){
300
+ const strategyPriorityFee = strategyResult.calculatedPriorityFee;
301
+ const strategyPriorityFeeDelta = strategyPriorityFee - minPriorityFeeToCompare;
302
+ // Determine if this strategy would have resulted in inclusion
303
+ let strategyWouldBeIncluded = true;
304
+ let strategyExclusionReason;
305
+ if (isBlobTx) {
306
+ // For blob txs, only consider priority fee if blob space was full
307
+ if (includedBlobPriorityFees.length > 0 && strategyPriorityFee < minIncludedBlobPriorityFee && blockBlobsFull) {
308
+ strategyWouldBeIncluded = false;
309
+ strategyExclusionReason = 'priority_fee_too_low';
310
+ }
311
+ } else {
312
+ // For non-blob txs, use the old logic
313
+ if (includedPriorityFees.length > 0 && strategyPriorityFee < minIncludedPriorityFee) {
314
+ strategyWouldBeIncluded = false;
315
+ strategyExclusionReason = 'priority_fee_too_low';
316
+ }
317
+ }
318
+ // Calculate estimated cost in ETH for this strategy
319
+ // Cost = gasLimit * (baseFee + priorityFee)
320
+ const baseFee = analysis.minedBlock.baseFeePerGas;
321
+ // Execution cost: gasLimit * (baseFee + priorityFee)
322
+ const executionCostWei = gasLimit * (baseFee + strategyPriorityFee);
323
+ const estimatedCostEth = Number(executionCostWei) / 1e18;
324
+ // Calculate minimum cost needed for inclusion
325
+ const minExecutionCostWei = gasLimit * (baseFee + minPriorityFeeToCompare);
326
+ const minCostEth = Number(minExecutionCostWei) / 1e18;
327
+ // Overpayment is the difference
328
+ const estimatedOverpaymentEth = estimatedCostEth - minCostEth;
329
+ // Update the strategy result with analysis data
330
+ strategyResult.wouldBeIncluded = strategyWouldBeIncluded;
331
+ strategyResult.exclusionReason = strategyExclusionReason;
332
+ strategyResult.priorityFeeDelta = strategyPriorityFeeDelta;
333
+ strategyResult.estimatedCostEth = estimatedCostEth;
334
+ strategyResult.estimatedOverpaymentEth = estimatedOverpaymentEth;
335
+ // Log per-strategy results
336
+ this.logger.info(`Strategy "${strategyResult.strategyName}" analysis`, {
337
+ id: analysisId,
338
+ strategyId: strategyResult.strategyId,
339
+ strategyName: strategyResult.strategyName,
340
+ calculatedPriorityFee: formatGwei(strategyPriorityFee),
341
+ minIncludedPriorityFee: formatGwei(minPriorityFeeToCompare),
342
+ priorityFeeDelta: formatGwei(strategyPriorityFeeDelta),
343
+ wouldBeIncluded: strategyWouldBeIncluded,
344
+ exclusionReason: strategyExclusionReason,
345
+ estimatedCostEth: estimatedCostEth.toFixed(6),
346
+ estimatedOverpaymentEth: estimatedOverpaymentEth.toFixed(6)
347
+ });
348
+ }
349
+ // Create cost ranking
350
+ const costRanking = analysis.computedPrices.strategyResults.map((s)=>({
351
+ strategyId: s.strategyId,
352
+ strategyName: s.strategyName,
353
+ estimatedCostEth: s.estimatedCostEth,
354
+ wouldBeIncluded: s.wouldBeIncluded
355
+ })).sort((a, b)=>a.estimatedCostEth - b.estimatedCostEth);
356
+ analysis.analysis.costRanking = costRanking;
357
+ // Log cost ranking summary
358
+ this.logger.info('Strategy cost ranking', {
359
+ id: analysisId,
360
+ cheapestStrategy: costRanking[0]?.strategyName,
361
+ cheapestCost: costRanking[0]?.estimatedCostEth.toFixed(6),
362
+ cheapestWouldBeIncluded: costRanking[0]?.wouldBeIncluded,
363
+ mostExpensiveStrategy: costRanking[costRanking.length - 1]?.strategyName,
364
+ mostExpensiveCost: costRanking[costRanking.length - 1]?.estimatedCostEth.toFixed(6),
365
+ mostExpensiveWouldBeIncluded: costRanking[costRanking.length - 1]?.wouldBeIncluded,
366
+ costSpread: costRanking.length > 1 ? (costRanking[costRanking.length - 1].estimatedCostEth - costRanking[0].estimatedCostEth).toFixed(6) : '0'
367
+ });
368
+ }
369
+ // Log the overall results
370
+ this.logger.info('Fee analysis completed', {
371
+ id: analysisId,
372
+ l2SlotNumber: analysis.l2SlotNumber.toString(),
373
+ timeBeforeBlockMs,
374
+ pendingBlobTxCount: analysis.pendingSnapshot.pendingBlobTxCount,
375
+ includedBlobTxCount: analysis.minedBlock.includedBlobTxCount,
376
+ pendingBlobTxsIncludedCount,
377
+ pendingBlobTxsExcludedCount,
378
+ blobsInBlock,
379
+ maxBlobCapacity,
380
+ blockBlobsFull,
381
+ minIncludedPriorityFee: formatGwei(minIncludedPriorityFee),
382
+ minIncludedBlobPriorityFee: formatGwei(minIncludedBlobPriorityFee),
383
+ strategiesAnalyzed: analysis.computedPrices.strategyResults?.length ?? 0
384
+ });
385
+ // Move to completed analyses
386
+ this.pendingAnalyses.delete(analysisId);
387
+ this.completedAnalyses.push(analysis);
388
+ // Trim old completed analyses if needed
389
+ while(this.completedAnalyses.length > this.maxCompletedAnalyses){
390
+ this.completedAnalyses.shift();
391
+ }
392
+ // Invoke the callback for this specific analysis
393
+ const callback = this.pendingCallbacks.get(analysisId);
394
+ if (callback) {
395
+ try {
396
+ callback(analysis);
397
+ } catch (err) {
398
+ this.logger.error('Error in analysis complete callback', err);
399
+ }
400
+ this.pendingCallbacks.delete(analysisId);
401
+ }
402
+ }
403
+ /**
404
+ * Gets a specific analysis result by ID
405
+ */ getAnalysis(id) {
406
+ return this.pendingAnalyses.get(id) || this.completedAnalyses.find((a)=>a.id === id);
407
+ }
408
+ /**
409
+ * Gets all completed analyses
410
+ */ getCompletedAnalyses() {
411
+ return [
412
+ ...this.completedAnalyses
413
+ ];
414
+ }
415
+ /**
416
+ * Gets statistics about all completed analyses
417
+ */ getAnalysisStats() {
418
+ const completed = this.completedAnalyses.filter((a)=>a.analysis);
419
+ if (completed.length === 0) {
420
+ return {
421
+ totalAnalyses: 0,
422
+ avgTimeBeforeBlockMs: 0,
423
+ avgBlobsInBlock: 0,
424
+ blocksBlobsFull: 0
425
+ };
426
+ }
427
+ const avgTimeBeforeBlockMs = completed.reduce((sum, a)=>sum + a.analysis.timeBeforeBlockMs, 0) / completed.length;
428
+ const avgBlobsInBlock = completed.reduce((sum, a)=>sum + a.analysis.blobsInBlock, 0) / completed.length;
429
+ const blocksBlobsFull = completed.filter((a)=>a.analysis.blockBlobsFull).length;
430
+ return {
431
+ totalAnalyses: completed.length,
432
+ avgTimeBeforeBlockMs,
433
+ avgBlobsInBlock,
434
+ blocksBlobsFull
435
+ };
436
+ }
437
+ /**
438
+ * Gets comparative statistics for all strategies across completed analyses
439
+ */ getStrategyComparison() {
440
+ const completed = this.completedAnalyses.filter((a)=>a.analysis);
441
+ if (completed.length === 0) {
442
+ return [];
443
+ }
444
+ // Collect data by strategy ID
445
+ const strategyData = new Map();
446
+ for (const analysis of completed){
447
+ if (!analysis.computedPrices.strategyResults) {
448
+ continue;
449
+ }
450
+ for (const strategyResult of analysis.computedPrices.strategyResults){
451
+ if (!strategyData.has(strategyResult.strategyId)) {
452
+ strategyData.set(strategyResult.strategyId, {
453
+ strategyName: strategyResult.strategyName,
454
+ analyses: 0,
455
+ inclusions: 0,
456
+ totalCostEth: 0,
457
+ totalOverpaymentEth: 0,
458
+ totalPriorityFeeDelta: 0
459
+ });
460
+ }
461
+ const data = strategyData.get(strategyResult.strategyId);
462
+ data.analyses++;
463
+ if (strategyResult.wouldBeIncluded) {
464
+ data.inclusions++;
465
+ }
466
+ if (strategyResult.estimatedCostEth !== undefined) {
467
+ data.totalCostEth += strategyResult.estimatedCostEth;
468
+ }
469
+ if (strategyResult.estimatedOverpaymentEth !== undefined) {
470
+ data.totalOverpaymentEth += strategyResult.estimatedOverpaymentEth;
471
+ }
472
+ if (strategyResult.priorityFeeDelta !== undefined) {
473
+ data.totalPriorityFeeDelta += Number(strategyResult.priorityFeeDelta);
474
+ }
475
+ }
476
+ }
477
+ // Convert to output format
478
+ const results = Array.from(strategyData.entries()).map(([strategyId, data])=>({
479
+ strategyId,
480
+ strategyName: data.strategyName,
481
+ totalAnalyses: data.analyses,
482
+ inclusionCount: data.inclusions,
483
+ inclusionRate: data.analyses > 0 ? data.inclusions / data.analyses : 0,
484
+ avgEstimatedCostEth: data.analyses > 0 ? data.totalCostEth / data.analyses : 0,
485
+ totalEstimatedCostEth: data.totalCostEth,
486
+ avgOverpaymentEth: data.analyses > 0 ? data.totalOverpaymentEth / data.analyses : 0,
487
+ totalOverpaymentEth: data.totalOverpaymentEth,
488
+ avgPriorityFeeDeltaGwei: data.analyses > 0 ? data.totalPriorityFeeDelta / data.analyses / Number(WEI_CONST) : 0
489
+ }));
490
+ // Sort by inclusion rate descending, then by avg cost ascending
491
+ return results.sort((a, b)=>{
492
+ if (Math.abs(a.inclusionRate - b.inclusionRate) > 0.01) {
493
+ return b.inclusionRate - a.inclusionRate;
494
+ }
495
+ return a.avgEstimatedCostEth - b.avgEstimatedCostEth;
496
+ });
497
+ }
498
+ /**
499
+ * Gets the minimum value from an array of bigints
500
+ */ minBigInt(values) {
501
+ if (values.length === 0) {
502
+ return 0n;
503
+ }
504
+ return values.reduce((min, val)=>val < min ? val : min, values[0]);
505
+ }
506
+ }
@@ -44,15 +44,6 @@ export declare class ReadOnlyL1TxUtils {
44
44
  transactions: `0x${string}`[];
45
45
  }>;
46
46
  getBlockNumber(): Promise<bigint>;
47
- /**
48
- * Analyzes pending transactions and recent fee history to determine a competitive priority fee.
49
- * Falls back to network estimate if data is unavailable or fails.
50
- * @param networkEstimateResult - Result from estimateMaxPriorityFeePerGas RPC call
51
- * @param pendingBlockResult - Result from getBlock with pending tag RPC call
52
- * @param feeHistoryResult - Result from getFeeHistory RPC call
53
- * @returns A competitive priority fee based on pending txs and recent block history
54
- */
55
- protected getCompetitivePriorityFee(networkEstimateResult: PromiseSettledResult<bigint | null>, pendingBlockResult: PromiseSettledResult<Awaited<ReturnType<ViemClient['getBlock']>> | null>, feeHistoryResult: PromiseSettledResult<Awaited<ReturnType<ViemClient['getFeeHistory']>> | null>): bigint;
56
47
  /**
57
48
  * Gets the current gas price with bounds checking
58
49
  */
@@ -86,9 +77,5 @@ export declare class ReadOnlyL1TxUtils {
86
77
  result: `0x${string}`;
87
78
  }>;
88
79
  bumpGasLimit(gasLimit: bigint, _gasConfig?: L1TxUtilsConfig): bigint;
89
- /**
90
- * Helper function to retry RPC calls twice
91
- */
92
- private tryTwice;
93
80
  }
94
81
  //# sourceMappingURL=readonly_l1_tx_utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"readonly_l1_tx_utils.d.ts","sourceRoot":"","sources":["../../src/l1_tx_utils/readonly_l1_tx_utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAIvD,OAAO,EACL,KAAK,GAAG,EACR,KAAK,OAAO,EAEZ,KAAK,cAAc,EAEnB,KAAK,GAAG,EAGR,KAAK,aAAa,EAKnB,MAAM,MAAM,CAAC;AAEd,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,KAAK,eAAe,EAAmD,MAAM,aAAa,CAAC;AAQpG,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAKxF,qBAAa,iBAAiB;IAKnB,MAAM,EAAE,UAAU;IACzB,SAAS,CAAC,MAAM,EAAE,MAAM;aACR,YAAY,EAAE,YAAY;IAE1C,SAAS,CAAC,gBAAgB,EAAE,OAAO;IAR9B,MAAM,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;IACzC,SAAS,CAAC,WAAW,UAAS;gBAGrB,MAAM,EAAE,UAAU,EACf,MAAM,EAAE,MAAM,YAA6C,EACrD,YAAY,EAAE,YAAY,EAC1C,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,EACvB,gBAAgB,GAAE,OAAe;IAKtC,SAAS;IAIT,OAAO;IAIP,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAIR,cAA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