@aztec/ethereum 2.1.9-rc.2 → 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,235 @@
1
+ import { type Logger } from '@aztec/foundation/log';
2
+ import { DateProvider } from '@aztec/foundation/timer';
3
+ import { type Hex } from 'viem';
4
+ import type { ViemClient } from '../types.js';
5
+ import type { L1TxUtilsConfig } from './config.js';
6
+ import { type PriorityFeeStrategy } from './fee-strategies/index.js';
7
+ import type { L1BlobInputs, L1TxRequest } from './types.js';
8
+ /**
9
+ * Information about a blob transaction in the pending pool or mined block
10
+ */
11
+ export interface BlobTxInfo {
12
+ hash: Hex;
13
+ maxPriorityFeePerGas: bigint;
14
+ maxFeePerGas: bigint;
15
+ maxFeePerBlobGas: bigint;
16
+ blobCount: number;
17
+ gas: bigint;
18
+ }
19
+ /**
20
+ * Snapshot of the pending block state at the time of analysis
21
+ */
22
+ export interface PendingBlockSnapshot {
23
+ /** Timestamp when the snapshot was taken */
24
+ timestamp: number;
25
+ /** The latest L1 block number at the time of snapshot */
26
+ latestBlockNumber: bigint;
27
+ /** Base fee per gas of the latest block */
28
+ baseFeePerGas: bigint;
29
+ /** Blob base fee at the time of snapshot */
30
+ blobBaseFee: bigint;
31
+ /** Total number of transactions in the pending block */
32
+ pendingTxCount: number;
33
+ /** Number of blob transactions in the pending block */
34
+ pendingBlobTxCount: number;
35
+ /** Total number of blobs in pending blob transactions */
36
+ pendingBlobCount: number;
37
+ /** Details of blob transactions in the pending pool */
38
+ pendingBlobTxs: BlobTxInfo[];
39
+ /** 75th percentile priority fee from pending transactions */
40
+ pendingP75PriorityFee: bigint;
41
+ /** 75th percentile priority fee from pending blob transactions */
42
+ pendingBlobP75PriorityFee: bigint;
43
+ }
44
+ /**
45
+ * Result of a strategy's priority fee calculation for analysis
46
+ */
47
+ export interface StrategyAnalysisResult {
48
+ /** Strategy ID */
49
+ strategyId: string;
50
+ /** Strategy name */
51
+ strategyName: string;
52
+ /** Calculated priority fee from this strategy */
53
+ calculatedPriorityFee: bigint;
54
+ /** Debug info from the strategy calculation */
55
+ debugInfo?: Record<string, string | number>;
56
+ /** Whether this transaction would have been included with this strategy's fee */
57
+ wouldBeIncluded?: boolean;
58
+ /** If not included, reason why */
59
+ exclusionReason?: 'priority_fee_too_low' | 'block_full';
60
+ /** Priority fee delta compared to minimum included fee */
61
+ priorityFeeDelta?: bigint;
62
+ /** Estimated total cost in ETH for this strategy */
63
+ estimatedCostEth?: number;
64
+ /** Estimated overpayment in ETH vs minimum required */
65
+ estimatedOverpaymentEth?: number;
66
+ }
67
+ /**
68
+ * Transaction metadata and strategy analysis results
69
+ */
70
+ export interface ComputedGasPrices {
71
+ /** Estimated gas limit for the transaction */
72
+ gasLimit: bigint;
73
+ /** Number of blobs in our transaction */
74
+ blobCount: number;
75
+ /** Results from all strategies analyzed */
76
+ strategyResults?: StrategyAnalysisResult[];
77
+ }
78
+ /**
79
+ * Information about what actually got included in the mined block
80
+ */
81
+ export interface MinedBlockInfo {
82
+ /** The block number that was mined */
83
+ blockNumber: bigint;
84
+ /** The block hash */
85
+ blockHash: Hex;
86
+ /** Timestamp of the mined block */
87
+ blockTimestamp: bigint;
88
+ /** Base fee per gas in the mined block */
89
+ baseFeePerGas: bigint;
90
+ /** Blob gas used in the mined block */
91
+ blobGasUsed: bigint;
92
+ /** Total number of transactions in the mined block */
93
+ txCount: number;
94
+ /** Number of blob transactions that got included */
95
+ includedBlobTxCount: number;
96
+ /** Total number of blobs included in the block */
97
+ includedBlobCount: number;
98
+ /** Details of blob transactions that got included */
99
+ includedBlobTxs: BlobTxInfo[];
100
+ /** Minimum priority fee among included transactions */
101
+ minIncludedPriorityFee: bigint;
102
+ /** Minimum priority fee among included blob transactions */
103
+ minIncludedBlobPriorityFee: bigint;
104
+ }
105
+ /**
106
+ * Complete fee analysis result comparing our estimates to what happened
107
+ */
108
+ export interface L1FeeAnalysisResult {
109
+ /** Unique identifier for this analysis */
110
+ id: string;
111
+ /** L2 slot number this analysis was performed for */
112
+ l2SlotNumber: bigint;
113
+ /** Snapshot of pending state when we computed our fees */
114
+ pendingSnapshot: PendingBlockSnapshot;
115
+ /** Our computed gas prices */
116
+ computedPrices: ComputedGasPrices;
117
+ /** Information about what we were trying to send */
118
+ txInfo: {
119
+ requestCount: number;
120
+ hasBlobData: boolean;
121
+ totalEstimatedGas: bigint;
122
+ };
123
+ /** Information about the block that was eventually mined (populated after block mines) */
124
+ minedBlock?: MinedBlockInfo;
125
+ /** Analysis results (populated after block mines) */
126
+ analysis?: {
127
+ /** Time in ms between our snapshot and block mining */
128
+ timeBeforeBlockMs: number;
129
+ /** How many blob txs from pending actually got included */
130
+ pendingBlobTxsIncludedCount: number;
131
+ /** How many blob txs from pending were NOT included */
132
+ pendingBlobTxsExcludedCount: number;
133
+ /** Number of blobs in the mined block */
134
+ blobsInBlock: number;
135
+ /** Maximum blob capacity for this block */
136
+ maxBlobCapacity: number;
137
+ /** Whether the block's blob space was full */
138
+ blockBlobsFull: boolean;
139
+ /** Actual cost in ETH if this analysis is linked to a mined tx */
140
+ actualCostEth?: number;
141
+ /** Strategy results ranked by estimated cost */
142
+ costRanking?: Array<{
143
+ strategyId: string;
144
+ strategyName: string;
145
+ estimatedCostEth: number;
146
+ wouldBeIncluded: boolean;
147
+ }>;
148
+ };
149
+ }
150
+ /** Callback type for when an analysis is completed */
151
+ export type L1FeeAnalysisCallback = (analysis: L1FeeAnalysisResult) => void;
152
+ /**
153
+ * Analyzes L1 transaction fees in fisherman mode.
154
+ * Captures pending block state, records gas calculations, and compares to what gets included.
155
+ * Supports multiple priority fee calculation strategies for comparison.
156
+ */
157
+ export declare class L1FeeAnalyzer {
158
+ private client;
159
+ private dateProvider;
160
+ private logger;
161
+ private maxCompletedAnalyses;
162
+ private gasConfig;
163
+ private pendingAnalyses;
164
+ private pendingCallbacks;
165
+ private completedAnalyses;
166
+ private analysisCounter;
167
+ private strategies;
168
+ constructor(client: ViemClient, dateProvider?: DateProvider, logger?: Logger, maxCompletedAnalyses?: number, strategies?: PriorityFeeStrategy[], gasConfig?: L1TxUtilsConfig);
169
+ /**
170
+ * Executes all configured strategies and returns their results.
171
+ * Each strategy handles its own RPC calls internally.
172
+ * @param isBlobTx - Whether this is a blob transaction
173
+ * @returns Array of strategy results
174
+ */
175
+ executeAllStrategies(isBlobTx: boolean): Promise<StrategyAnalysisResult[]>;
176
+ /**
177
+ * Captures a snapshot of the current pending block state
178
+ */
179
+ capturePendingSnapshot(): Promise<PendingBlockSnapshot>;
180
+ /**
181
+ * Starts a fee analysis for a transaction bundle
182
+ * @param l2SlotNumber - The L2 slot this analysis is for
183
+ * @param gasLimit - The estimated gas limit
184
+ * @param requests - The transaction requests being analyzed
185
+ * @param blobInputs - Blob inputs if this is a blob transaction
186
+ * @param onComplete - Optional callback to invoke when analysis completes
187
+ * @returns The analysis ID for tracking
188
+ */
189
+ startAnalysis(l2SlotNumber: bigint, gasLimit: bigint, requests: L1TxRequest[], blobInputs?: L1BlobInputs, onComplete?: L1FeeAnalysisCallback): Promise<string>;
190
+ /**
191
+ * Watches for the next block to be mined and completes the analysis
192
+ */
193
+ private watchForNextBlock;
194
+ /**
195
+ * Completes the analysis once the next block is mined
196
+ */
197
+ private completeAnalysis;
198
+ /**
199
+ * Gets a specific analysis result by ID
200
+ */
201
+ getAnalysis(id: string): L1FeeAnalysisResult | undefined;
202
+ /**
203
+ * Gets all completed analyses
204
+ */
205
+ getCompletedAnalyses(): L1FeeAnalysisResult[];
206
+ /**
207
+ * Gets statistics about all completed analyses
208
+ */
209
+ getAnalysisStats(): {
210
+ totalAnalyses: number;
211
+ avgTimeBeforeBlockMs: number;
212
+ avgBlobsInBlock: number;
213
+ blocksBlobsFull: number;
214
+ };
215
+ /**
216
+ * Gets comparative statistics for all strategies across completed analyses
217
+ */
218
+ getStrategyComparison(): Array<{
219
+ strategyId: string;
220
+ strategyName: string;
221
+ totalAnalyses: number;
222
+ inclusionCount: number;
223
+ inclusionRate: number;
224
+ avgEstimatedCostEth: number;
225
+ totalEstimatedCostEth: number;
226
+ avgOverpaymentEth: number;
227
+ totalOverpaymentEth: number;
228
+ avgPriorityFeeDeltaGwei: number;
229
+ }>;
230
+ /**
231
+ * Gets the minimum value from an array of bigints
232
+ */
233
+ private minBigInt;
234
+ }
235
+ //# sourceMappingURL=l1_fee_analyzer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"l1_fee_analyzer.d.ts","sourceRoot":"","sources":["../../src/l1_tx_utils/l1_fee_analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAAyC,KAAK,GAAG,EAAc,MAAM,MAAM,CAAC;AAEnF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAEL,KAAK,mBAAmB,EAEzB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,GAAG,CAAC;I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