@aztec/ethereum 3.0.0-nightly.20251214 → 3.0.0-nightly.20251217

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 (47) hide show
  1. package/dest/deploy_aztec_l1_contracts.d.ts +2 -2
  2. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
  3. package/dest/deploy_aztec_l1_contracts.js +144 -107
  4. package/dest/l1_artifacts.d.ts +61 -41
  5. package/dest/l1_artifacts.d.ts.map +1 -1
  6. package/dest/l1_contract_addresses.d.ts +1 -1
  7. package/dest/l1_contract_addresses.d.ts.map +1 -1
  8. package/dest/l1_contract_addresses.js +3 -3
  9. package/dest/l1_tx_utils/constants.d.ts +7 -1
  10. package/dest/l1_tx_utils/constants.d.ts.map +1 -1
  11. package/dest/l1_tx_utils/constants.js +25 -0
  12. package/dest/l1_tx_utils/fee-strategies/index.d.ts +9 -0
  13. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  14. package/dest/l1_tx_utils/fee-strategies/index.js +11 -0
  15. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +18 -0
  16. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  17. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +111 -0
  18. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +32 -0
  19. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  20. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +173 -0
  21. package/dest/l1_tx_utils/fee-strategies/types.d.ts +64 -0
  22. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  23. package/dest/l1_tx_utils/fee-strategies/types.js +24 -0
  24. package/dest/l1_tx_utils/index.d.ts +3 -1
  25. package/dest/l1_tx_utils/index.d.ts.map +1 -1
  26. package/dest/l1_tx_utils/index.js +2 -0
  27. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +232 -0
  28. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  29. package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
  30. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +1 -10
  31. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  32. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +43 -121
  33. package/dest/utils.d.ts +14 -2
  34. package/dest/utils.d.ts.map +1 -1
  35. package/dest/utils.js +18 -0
  36. package/package.json +6 -5
  37. package/src/deploy_aztec_l1_contracts.ts +141 -107
  38. package/src/l1_contract_addresses.ts +22 -20
  39. package/src/l1_tx_utils/constants.ts +11 -0
  40. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  41. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +159 -0
  42. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +241 -0
  43. package/src/l1_tx_utils/fee-strategies/types.ts +88 -0
  44. package/src/l1_tx_utils/index.ts +2 -0
  45. package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
  46. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +47 -158
  47. package/src/utils.ts +29 -0
@@ -0,0 +1,111 @@
1
+ import { median } from '@aztec/foundation/collection';
2
+ import { formatGwei } from 'viem';
3
+ import { calculatePercentile } from '../../utils.js';
4
+ import { WEI_CONST } from '../constants.js';
5
+ import { HISTORICAL_BLOCK_COUNT } from './types.js';
6
+ /**
7
+ * Our current competitive priority fee strategy.
8
+ * Analyzes p75 of pending transactions and 5-block fee history to determine a competitive priority fee.
9
+ * Falls back to network estimate if data is unavailable.
10
+ */ export const P75AllTxsPriorityFeeStrategy = {
11
+ name: 'Competitive (P75 + History) - CURRENT',
12
+ id: 'p75_pending_txs_and_history_all_txs',
13
+ getRequiredPromises (client) {
14
+ return {
15
+ networkEstimate: client.estimateMaxPriorityFeePerGas().catch(()=>0n),
16
+ pendingBlock: client.getBlock({
17
+ blockTag: 'pending',
18
+ includeTransactions: true
19
+ }).catch(()=>null),
20
+ feeHistory: client.getFeeHistory({
21
+ blockCount: HISTORICAL_BLOCK_COUNT,
22
+ rewardPercentiles: [
23
+ 75
24
+ ],
25
+ blockTag: 'latest'
26
+ }).catch(()=>null)
27
+ };
28
+ },
29
+ calculate (results, context) {
30
+ const { logger } = context;
31
+ // Extract network estimate from settled result
32
+ const networkEstimate = results.networkEstimate.status === 'fulfilled' && typeof results.networkEstimate.value === 'bigint' ? results.networkEstimate.value : 0n;
33
+ let competitiveFee = networkEstimate;
34
+ const debugInfo = {
35
+ networkEstimateGwei: formatGwei(networkEstimate)
36
+ };
37
+ // Extract pending block from settled result
38
+ const pendingBlock = results.pendingBlock.status === 'fulfilled' ? results.pendingBlock.value : null;
39
+ // Analyze pending block transactions
40
+ if (pendingBlock?.transactions && pendingBlock.transactions.length > 0) {
41
+ const pendingFees = pendingBlock.transactions.map((tx)=>{
42
+ if (typeof tx === 'string') {
43
+ return 0n;
44
+ }
45
+ const fee = tx.maxPriorityFeePerGas || 0n;
46
+ return fee;
47
+ }).filter((fee)=>fee > 0n);
48
+ if (pendingFees.length > 0) {
49
+ // Use 75th percentile of pending fees to be competitive
50
+ const pendingCompetitiveFee = calculatePercentile(pendingFees, 75);
51
+ if (pendingCompetitiveFee > competitiveFee) {
52
+ competitiveFee = pendingCompetitiveFee;
53
+ }
54
+ debugInfo.pendingTxCount = pendingFees.length;
55
+ debugInfo.pendingP75Gwei = formatGwei(pendingCompetitiveFee);
56
+ logger?.debug('Analyzed pending transactions for competitive pricing', {
57
+ pendingTxCount: pendingFees.length,
58
+ pendingP75: formatGwei(pendingCompetitiveFee)
59
+ });
60
+ }
61
+ }
62
+ // Extract fee history from settled result
63
+ const feeHistory = results.feeHistory.status === 'fulfilled' ? results.feeHistory.value : null;
64
+ // Analyze fee history
65
+ if (feeHistory?.reward && feeHistory.reward.length > 0) {
66
+ // Extract 75th percentile fees from each block
67
+ const percentile75Fees = feeHistory.reward.map((rewards)=>rewards[0] || 0n).filter((fee)=>fee > 0n);
68
+ if (percentile75Fees.length > 0) {
69
+ // Calculate median of the 75th percentile fees across blocks
70
+ const medianHistoricalFee = median(percentile75Fees) ?? 0n;
71
+ // Debug: Log suspicious fees from history
72
+ if (medianHistoricalFee > 100n * WEI_CONST) {
73
+ logger?.warn('Suspicious high fee in history', {
74
+ historicalMedian: formatGwei(medianHistoricalFee),
75
+ allP75Fees: percentile75Fees.map((f)=>formatGwei(f))
76
+ });
77
+ }
78
+ if (medianHistoricalFee > competitiveFee) {
79
+ competitiveFee = medianHistoricalFee;
80
+ }
81
+ debugInfo.historicalMedianGwei = formatGwei(medianHistoricalFee);
82
+ logger?.debug('Analyzed fee history for competitive pricing', {
83
+ historicalMedian: formatGwei(medianHistoricalFee)
84
+ });
85
+ }
86
+ }
87
+ // Sanity check: cap competitive fee at 100x network estimate to avoid using unrealistic fees
88
+ const maxReasonableFee = networkEstimate * 100n;
89
+ if (competitiveFee > maxReasonableFee && networkEstimate > 0n) {
90
+ logger?.warn('Competitive fee exceeds sanity cap, using capped value', {
91
+ competitiveFee: formatGwei(competitiveFee),
92
+ networkEstimate: formatGwei(networkEstimate),
93
+ cappedTo: formatGwei(maxReasonableFee)
94
+ });
95
+ competitiveFee = maxReasonableFee;
96
+ debugInfo.cappedToGwei = formatGwei(maxReasonableFee);
97
+ }
98
+ // Log final decision
99
+ if (competitiveFee > networkEstimate) {
100
+ logger?.debug('Using competitive fee from market analysis', {
101
+ networkEstimate: formatGwei(networkEstimate),
102
+ competitive: formatGwei(competitiveFee)
103
+ });
104
+ }
105
+ debugInfo.finalFeeGwei = formatGwei(competitiveFee);
106
+ return {
107
+ priorityFee: competitiveFee,
108
+ debugInfo
109
+ };
110
+ }
111
+ };
@@ -0,0 +1,32 @@
1
+ import { type GetFeeHistoryReturnType } from 'viem';
2
+ import type { ViemClient } from '../../types.js';
3
+ import { type PriorityFeeStrategy } from './types.js';
4
+ /**
5
+ * Type for the promises required by the competitive strategy
6
+ */
7
+ type P75AllTxsStrategyPromises = {
8
+ networkEstimate: Promise<bigint>;
9
+ pendingBlock: Promise<Awaited<ReturnType<ViemClient['getBlock']>> | null>;
10
+ feeHistory: Promise<Awaited<ReturnType<ViemClient['getFeeHistory']>> | null>;
11
+ };
12
+ /**
13
+ * Fetches historical blocks and calculates reward percentiles for blob transactions only.
14
+ * Returns data in the same format as getFeeHistory for easy drop-in replacement.
15
+ *
16
+ * @param client - Viem client to use for RPC calls
17
+ * @param blockCount - Number of historical blocks to fetch
18
+ * @param rewardPercentiles - Array of percentiles to calculate (e.g., [75] for 75th percentile)
19
+ * @returns Object with reward field containing percentile fees for each block, similar to getFeeHistory
20
+ * @throws Error if fetching blocks fails
21
+ */
22
+ export declare function getBlobPriorityFeeHistory(client: ViemClient, blockCount: number, rewardPercentiles: number[]): Promise<GetFeeHistoryReturnType>;
23
+ /**
24
+ * Similar to our current competitive priority fee strategy, but only considers blob transactions
25
+ * when calculating competitive priority fee for blob transactions.
26
+ * This strategy also has NO cap on the competitive fee if it's much higher than the network estimate.
27
+ * Analyzes p75 of pending transactions and 5-block fee history to determine a competitive priority fee.
28
+ * Falls back to network estimate if data is unavailable.
29
+ */
30
+ export declare const P75BlobTxsOnlyPriorityFeeStrategy: PriorityFeeStrategy<P75AllTxsStrategyPromises>;
31
+ export {};
32
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicDc1X2NvbXBldGl0aXZlX2Jsb2JfdHhzX29ubHkuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9sMV90eF91dGlscy9mZWUtc3RyYXRlZ2llcy9wNzVfY29tcGV0aXRpdmVfYmxvYl90eHNfb25seS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUsS0FBSyx1QkFBdUIsRUFBYyxNQUFNLE1BQU0sQ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AGzB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,KAAK,yBAAyB,GAAG;IAC/B,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACjC,YAAY,EAAE,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1E,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;CAC9E,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,UAAU,EAClB,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,MAAM,EAAE,GAC1B,OAAO,CAAC,uBAAuB,CAAC,CAsElC;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iCAAiC,EAAE,mBAAmB,CAAC,yBAAyB,CA4H5F,CAAC"}
@@ -0,0 +1,173 @@
1
+ import { median } from '@aztec/foundation/collection';
2
+ import { formatGwei } from 'viem';
3
+ import { calculatePercentile, isBlobTransaction } from '../../utils.js';
4
+ import { WEI_CONST } from '../constants.js';
5
+ import { HISTORICAL_BLOCK_COUNT } from './types.js';
6
+ /**
7
+ * Fetches historical blocks and calculates reward percentiles for blob transactions only.
8
+ * Returns data in the same format as getFeeHistory for easy drop-in replacement.
9
+ *
10
+ * @param client - Viem client to use for RPC calls
11
+ * @param blockCount - Number of historical blocks to fetch
12
+ * @param rewardPercentiles - Array of percentiles to calculate (e.g., [75] for 75th percentile)
13
+ * @returns Object with reward field containing percentile fees for each block, similar to getFeeHistory
14
+ * @throws Error if fetching blocks fails
15
+ */ export async function getBlobPriorityFeeHistory(client, blockCount, rewardPercentiles) {
16
+ const latestBlockNumber = await client.getBlockNumber();
17
+ // Fetch multiple blocks in parallel
18
+ const blockPromises = Array.from({
19
+ length: blockCount
20
+ }, (_, i)=>client.getBlock({
21
+ blockNumber: latestBlockNumber - BigInt(i),
22
+ includeTransactions: true
23
+ }));
24
+ const blocks = await Promise.all(blockPromises);
25
+ // Process each block to extract blob transaction fees and other data
26
+ const baseFeePerGas = [];
27
+ const gasUsedRatio = [];
28
+ const reward = [];
29
+ for (const block of blocks){
30
+ // Collect base fee per gas
31
+ baseFeePerGas.push(block.baseFeePerGas || 0n);
32
+ // Calculate gas used ratio
33
+ const gasUsed = block.gasUsed || 0n;
34
+ const gasLimit = block.gasLimit || 1n; // Avoid division by zero
35
+ gasUsedRatio.push(Number(gasUsed) / Number(gasLimit));
36
+ if (!block.transactions || block.transactions.length === 0) {
37
+ // No transactions in this block - return zeros for each percentile
38
+ reward.push(rewardPercentiles.map(()=>0n));
39
+ continue;
40
+ }
41
+ // Extract priority fees from blob transactions only
42
+ const blobFees = block.transactions.map((tx)=>{
43
+ // Transaction can be just a hash string
44
+ if (typeof tx === 'string') {
45
+ return 0n;
46
+ }
47
+ if (!isBlobTransaction(tx)) {
48
+ return 0n;
49
+ }
50
+ return tx.maxPriorityFeePerGas || 0n;
51
+ }).filter((fee)=>fee > 0n);
52
+ if (blobFees.length === 0) {
53
+ // No blob transactions in this block - return zeros for each percentile
54
+ reward.push(rewardPercentiles.map(()=>0n));
55
+ continue;
56
+ }
57
+ // Calculate requested percentiles
58
+ const percentiles = rewardPercentiles.map((percentile)=>calculatePercentile(blobFees, percentile));
59
+ reward.push(percentiles);
60
+ }
61
+ // Calculate oldest block number (the last block in our array)
62
+ const oldestBlock = latestBlockNumber - BigInt(blockCount - 1);
63
+ // Reverse arrays to match getFeeHistory behavior (oldest first)
64
+ return {
65
+ baseFeePerGas: baseFeePerGas.reverse(),
66
+ gasUsedRatio: gasUsedRatio.reverse(),
67
+ oldestBlock,
68
+ reward: reward.reverse()
69
+ };
70
+ }
71
+ /**
72
+ * Similar to our current competitive priority fee strategy, but only considers blob transactions
73
+ * when calculating competitive priority fee for blob transactions.
74
+ * This strategy also has NO cap on the competitive fee if it's much higher than the network estimate.
75
+ * Analyzes p75 of pending transactions and 5-block fee history to determine a competitive priority fee.
76
+ * Falls back to network estimate if data is unavailable.
77
+ */ export const P75BlobTxsOnlyPriorityFeeStrategy = {
78
+ name: 'Competitive (P75 + History) - Blob Txs Only',
79
+ id: 'p75_pending_txs_and_history_blob_txs_only',
80
+ getRequiredPromises (client, opts) {
81
+ return {
82
+ networkEstimate: client.estimateMaxPriorityFeePerGas().catch(()=>0n),
83
+ pendingBlock: client.getBlock({
84
+ blockTag: 'pending',
85
+ includeTransactions: true
86
+ }).catch(()=>null),
87
+ feeHistory: opts.isBlobTx ? getBlobPriorityFeeHistory(client, HISTORICAL_BLOCK_COUNT, [
88
+ 75
89
+ ]) : client.getFeeHistory({
90
+ blockCount: HISTORICAL_BLOCK_COUNT,
91
+ rewardPercentiles: [
92
+ 75
93
+ ],
94
+ blockTag: 'latest'
95
+ }).catch(()=>null)
96
+ };
97
+ },
98
+ calculate (results, context) {
99
+ const { logger } = context;
100
+ // Extract network estimate from settled result
101
+ const networkEstimate = results.networkEstimate.status === 'fulfilled' && typeof results.networkEstimate.value === 'bigint' ? results.networkEstimate.value : 0n;
102
+ let competitiveFee = networkEstimate;
103
+ const debugInfo = {
104
+ networkEstimateGwei: formatGwei(networkEstimate)
105
+ };
106
+ // Extract pending block from settled result
107
+ const pendingBlock = results.pendingBlock.status === 'fulfilled' ? results.pendingBlock.value : null;
108
+ // Analyze pending block transactions
109
+ if (pendingBlock?.transactions && pendingBlock.transactions.length > 0) {
110
+ const pendingFees = pendingBlock.transactions.map((tx)=>{
111
+ if (typeof tx === 'string') {
112
+ return 0n;
113
+ }
114
+ if (context.isBlobTx) {
115
+ if (!isBlobTransaction(tx)) {
116
+ return 0n;
117
+ }
118
+ }
119
+ const fee = tx.maxPriorityFeePerGas || 0n;
120
+ return fee;
121
+ }).filter((fee)=>fee > 0n);
122
+ if (pendingFees.length > 0) {
123
+ const pendingCompetitiveFee = calculatePercentile(pendingFees, 75);
124
+ if (pendingCompetitiveFee > competitiveFee) {
125
+ competitiveFee = pendingCompetitiveFee;
126
+ }
127
+ debugInfo.pendingTxCount = pendingFees.length;
128
+ debugInfo.pendingP75Gwei = formatGwei(pendingCompetitiveFee);
129
+ logger?.debug('Analyzed pending transactions for competitive pricing', {
130
+ pendingTxCount: pendingFees.length,
131
+ pendingP75: formatGwei(pendingCompetitiveFee)
132
+ });
133
+ }
134
+ }
135
+ // Extract fee history from settled result
136
+ const feeHistory = results.feeHistory.status === 'fulfilled' ? results.feeHistory.value : null;
137
+ // Analyze fee history
138
+ if (feeHistory?.reward && feeHistory.reward.length > 0) {
139
+ // Extract 75th percentile fees from each block
140
+ const percentile75Fees = feeHistory.reward.map((rewards)=>rewards[0] || 0n).filter((fee)=>fee > 0n);
141
+ if (percentile75Fees.length > 0) {
142
+ // Calculate median of the 75th percentile fees across blocks
143
+ const medianHistoricalFee = median(percentile75Fees) ?? 0n;
144
+ // Debug: Log suspicious fees from history
145
+ if (medianHistoricalFee > 100n * WEI_CONST) {
146
+ logger?.warn('Suspicious high fee in history', {
147
+ historicalMedian: formatGwei(medianHistoricalFee),
148
+ allP75Fees: percentile75Fees.map((f)=>formatGwei(f))
149
+ });
150
+ }
151
+ if (medianHistoricalFee > competitiveFee) {
152
+ competitiveFee = medianHistoricalFee;
153
+ }
154
+ debugInfo.historicalMedianGwei = formatGwei(medianHistoricalFee);
155
+ logger?.debug('Analyzed fee history for competitive pricing', {
156
+ historicalMedian: formatGwei(medianHistoricalFee)
157
+ });
158
+ }
159
+ }
160
+ // Log final decision
161
+ if (competitiveFee > networkEstimate) {
162
+ logger?.debug('Using competitive fee from market analysis', {
163
+ networkEstimate: formatGwei(networkEstimate),
164
+ competitive: formatGwei(competitiveFee)
165
+ });
166
+ }
167
+ debugInfo.finalFeeGwei = formatGwei(competitiveFee);
168
+ return {
169
+ priorityFee: competitiveFee,
170
+ debugInfo
171
+ };
172
+ }
173
+ };
@@ -0,0 +1,64 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+ import type { ViemClient } from '../../types.js';
3
+ import type { L1TxUtilsConfig } from '../config.js';
4
+ /**
5
+ * Historical block count for fee history queries
6
+ */
7
+ export declare const HISTORICAL_BLOCK_COUNT = 5;
8
+ /**
9
+ * Result from a priority fee strategy calculation
10
+ */
11
+ export interface PriorityFeeStrategyResult {
12
+ /** The calculated priority fee in wei */
13
+ priorityFee: bigint;
14
+ /** Optional debug info about how the fee was calculated */
15
+ debugInfo?: Record<string, string | number>;
16
+ }
17
+ /**
18
+ * Context passed to the strategy calculation function (excluding promise results)
19
+ */
20
+ export interface PriorityFeeStrategyContext {
21
+ /** Gas configuration */
22
+ gasConfig: L1TxUtilsConfig;
23
+ /** Whether this is for a blob transaction */
24
+ isBlobTx: boolean;
25
+ /** Logger for debugging */
26
+ logger?: Logger;
27
+ }
28
+ /**
29
+ * A strategy for calculating the priority fee for L1 transactions.
30
+ * Each strategy defines what promises it needs and how to calculate the fee from their results.
31
+ * This design allows strategies to be plugged into both L1FeeAnalyzer and ReadOnlyL1TxUtils.
32
+ */
33
+ export interface PriorityFeeStrategy<TPromises extends Record<string, Promise<any>> = Record<string, Promise<any>>> {
34
+ /** Human-readable name for logging */
35
+ name: string;
36
+ /** Unique identifier for metrics */
37
+ id: string;
38
+ /**
39
+ * Returns the promises that need to be executed for this strategy.
40
+ * These will be run in parallel with Promise.allSettled.
41
+ * @param client - The viem client to use for RPC calls
42
+ * @returns An object of promises keyed by name
43
+ */
44
+ getRequiredPromises(client: ViemClient, opts: Partial<PriorityFeeStrategyContext>): TPromises;
45
+ /**
46
+ * Calculate the priority fee based on the settled promise results.
47
+ * @param results - The settled results of the promises from getRequiredPromises
48
+ * @param context - Contains gas config, whether it's a blob tx, and logger
49
+ * @returns The calculated priority fee result
50
+ */
51
+ calculate(results: {
52
+ [K in keyof TPromises]: PromiseSettledResult<Awaited<TPromises[K]>>;
53
+ }, context: PriorityFeeStrategyContext): PriorityFeeStrategyResult;
54
+ }
55
+ /**
56
+ * Helper function to execute a strategy's promises and calculate the result.
57
+ * This can be used by both L1FeeAnalyzer and ReadOnlyL1TxUtils.
58
+ * @param strategy - The strategy to execute
59
+ * @param client - The viem client to use for RPC calls
60
+ * @param context - The context for calculation
61
+ * @returns The strategy result
62
+ */
63
+ export declare function executeStrategy<TPromises extends Record<string, Promise<any>>>(strategy: PriorityFeeStrategy<TPromises>, client: ViemClient, context: PriorityFeeStrategyContext): Promise<PriorityFeeStrategyResult>;
64
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9sMV90eF91dGlscy9mZWUtc3RyYXRlZ2llcy90eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUVwRCxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSxnQkFBZ0IsQ0FBQztBQUNqRCxPQUFPLEtBQUssRUFBRSxlQUFlLEVBQUUsTUFBTSxjQUFjLENBQUM7QUFFcEQ7O0dBRUc7QUFDSCxlQUFPLE1BQU0sc0JBQXNCLElBQUksQ0FBQztBQUV4Qzs7R0FFRztBQUNILE1BQU0sV0FBVyx5QkFBeUI7SUFDeEMseUNBQXlDO0lBQ3pDLFdBQVcsRUFBRSxNQUFNLENBQUM7SUFDcEIsMkRBQTJEO0lBQzNELFNBQVMsQ0FBQyxFQUFFLE1BQU0sQ0FBQyxNQUFNLEVBQUUsTUFBTSxHQUFHLE1BQU0sQ0FBQyxDQUFDO0NBQzdDO0FBRUQ7O0dBRUc7QUFDSCxNQUFNLFdBQVcsMEJBQTBCO0lBQ3pDLHdCQUF3QjtJQUN4QixTQUFTLEVBQUUsZUFBZSxDQUFDO0lBQzNCLDZDQUE2QztJQUM3QyxRQUFRLEVBQUUsT0FBTyxD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C,yBAAyB,CAAC;CAC9B;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,CAAC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,EAClF,QAAQ,EAAE,mBAAmB,CAAC,SAAS,CAAC,EACxC,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,yBAAyB,CAAC,CAcpC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Historical block count for fee history queries
3
+ */ export const HISTORICAL_BLOCK_COUNT = 5;
4
+ /**
5
+ * Helper function to execute a strategy's promises and calculate the result.
6
+ * This can be used by both L1FeeAnalyzer and ReadOnlyL1TxUtils.
7
+ * @param strategy - The strategy to execute
8
+ * @param client - The viem client to use for RPC calls
9
+ * @param context - The context for calculation
10
+ * @returns The strategy result
11
+ */ export async function executeStrategy(strategy, client, context) {
12
+ const promises = strategy.getRequiredPromises(client, {
13
+ isBlobTx: context.isBlobTx
14
+ });
15
+ const keys = Object.keys(promises);
16
+ const promiseArray = keys.map((k)=>promises[k]);
17
+ const settledResults = await Promise.allSettled(promiseArray);
18
+ // Reconstruct the results object with the same keys, preserving the type mapping
19
+ const results = {};
20
+ keys.forEach((key, index)=>{
21
+ results[key] = settledResults[index];
22
+ });
23
+ return strategy.calculate(results, context);
24
+ }
@@ -1,10 +1,12 @@
1
1
  export * from './config.js';
2
2
  export * from './constants.js';
3
3
  export * from './factory.js';
4
+ export * from './fee-strategies/index.js';
4
5
  export * from './interfaces.js';
6
+ export * from './l1_fee_analyzer.js';
5
7
  export * from './l1_tx_utils.js';
6
8
  export * from './readonly_l1_tx_utils.js';
7
9
  export * from './signer.js';
8
10
  export * from './types.js';
9
11
  export * from './utils.js';
10
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sMV90eF91dGlscy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLGFBQWEsQ0FBQztBQUM1QixjQUFjLGdCQUFnQixDQUFDO0FBQy9CLGNBQWMsY0FBYyxDQUFDO0FBQzdCLGNBQWMsaUJBQWlCLENBQUM7QUFDaEMsY0FBYyxrQkFBa0IsQ0FBQztBQUNqQyxjQUFjLDJCQUEyQixDQUFDO0FBQzFDLGNBQWMsYUFBYSxDQUFDO0FBQzVCLGNBQWMsWUFBWSxDQUFDO0FBQzNCLGNBQWMsWUFBWSxDQUFDIn0=
12
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sMV90eF91dGlscy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLGFBQWEsQ0FBQztBQUM1QixjQUFjLGdCQUFnQixDQUFDO0FBQy9CLGNBQWMsY0FBYyxDQUFDO0FBQzdCLGNBQWMsMkJBQTJCLENBQUM7QUFDMUMsY0FBYyxpQkFBaUIsQ0FBQztBQUNoQyxjQUFjLHNCQUFzQixDQUFDO0FBQ3JDLGNBQWMsa0JBQWtCLENBQUM7QUFDakMsY0FBYywyQkFBMkIsQ0FBQztBQUMxQyxjQUFjLGFBQWEsQ0FBQztBQUM1QixjQUFjLFlBQVksQ0FBQztBQUMzQixjQUFjLFlBQVksQ0FBQyJ9
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/l1_tx_utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/l1_tx_utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -1,7 +1,9 @@
1
1
  export * from './config.js';
2
2
  export * from './constants.js';
3
3
  export * from './factory.js';
4
+ export * from './fee-strategies/index.js';
4
5
  export * from './interfaces.js';
6
+ export * from './l1_fee_analyzer.js';
5
7
  export * from './l1_tx_utils.js';
6
8
  export * from './readonly_l1_tx_utils.js';
7
9
  export * from './signer.js';