@aztec/ethereum 0.0.1-commit.fce3e4f → 0.0.1-commit.fffb133c

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 (166) hide show
  1. package/dest/client.js +6 -2
  2. package/dest/config.d.ts +19 -68
  3. package/dest/config.d.ts.map +1 -1
  4. package/dest/config.js +51 -378
  5. package/dest/contracts/empire_base.d.ts +2 -1
  6. package/dest/contracts/empire_base.d.ts.map +1 -1
  7. package/dest/contracts/empire_slashing_proposer.d.ts +2 -1
  8. package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -1
  9. package/dest/contracts/empire_slashing_proposer.js +9 -0
  10. package/dest/contracts/fee_asset_handler.d.ts +6 -5
  11. package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
  12. package/dest/contracts/fee_asset_handler.js +9 -9
  13. package/dest/contracts/governance.d.ts +3 -1
  14. package/dest/contracts/governance.d.ts.map +1 -1
  15. package/dest/contracts/governance.js +9 -1
  16. package/dest/contracts/governance_proposer.d.ts +2 -1
  17. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  18. package/dest/contracts/governance_proposer.js +391 -8
  19. package/dest/contracts/inbox.d.ts +24 -3
  20. package/dest/contracts/inbox.d.ts.map +1 -1
  21. package/dest/contracts/inbox.js +36 -1
  22. package/dest/contracts/index.d.ts +3 -1
  23. package/dest/contracts/index.d.ts.map +1 -1
  24. package/dest/contracts/index.js +2 -0
  25. package/dest/contracts/log.d.ts +13 -0
  26. package/dest/contracts/log.d.ts.map +1 -0
  27. package/dest/contracts/log.js +1 -0
  28. package/dest/contracts/outbox.d.ts +41 -0
  29. package/dest/contracts/outbox.d.ts.map +1 -0
  30. package/dest/contracts/outbox.js +86 -0
  31. package/dest/contracts/rollup.d.ts +176 -96
  32. package/dest/contracts/rollup.d.ts.map +1 -1
  33. package/dest/contracts/rollup.js +698 -141
  34. package/dest/contracts/tally_slashing_proposer.d.ts +3 -2
  35. package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -1
  36. package/dest/contracts/tally_slashing_proposer.js +1 -1
  37. package/dest/deploy_aztec_l1_contracts.d.ts +260 -0
  38. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  39. package/dest/deploy_aztec_l1_contracts.js +398 -0
  40. package/dest/deploy_l1_contract.d.ts +68 -0
  41. package/dest/deploy_l1_contract.d.ts.map +1 -0
  42. package/dest/deploy_l1_contract.js +312 -0
  43. package/dest/forwarder_proxy.d.ts +32 -0
  44. package/dest/forwarder_proxy.d.ts.map +1 -0
  45. package/dest/forwarder_proxy.js +93 -0
  46. package/dest/generated/l1-contracts-defaults.d.ts +30 -0
  47. package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
  48. package/dest/generated/l1-contracts-defaults.js +30 -0
  49. package/dest/l1_artifacts.d.ts +4964 -1573
  50. package/dest/l1_artifacts.d.ts.map +1 -1
  51. package/dest/l1_contract_addresses.d.ts +1 -1
  52. package/dest/l1_contract_addresses.d.ts.map +1 -1
  53. package/dest/l1_contract_addresses.js +3 -3
  54. package/dest/l1_reader.d.ts +3 -1
  55. package/dest/l1_reader.d.ts.map +1 -1
  56. package/dest/l1_reader.js +6 -0
  57. package/dest/l1_tx_utils/config.d.ts +3 -3
  58. package/dest/l1_tx_utils/config.d.ts.map +1 -1
  59. package/dest/l1_tx_utils/config.js +17 -3
  60. package/dest/l1_tx_utils/constants.d.ts +7 -1
  61. package/dest/l1_tx_utils/constants.d.ts.map +1 -1
  62. package/dest/l1_tx_utils/constants.js +25 -0
  63. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  64. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  65. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  66. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  67. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  68. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  69. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  70. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  71. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  72. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  73. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  74. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  75. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  76. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  77. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +48 -0
  78. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  79. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  80. package/dest/l1_tx_utils/index-blobs.js +2 -0
  81. package/dest/l1_tx_utils/index.d.ts +3 -1
  82. package/dest/l1_tx_utils/index.d.ts.map +1 -1
  83. package/dest/l1_tx_utils/index.js +2 -0
  84. package/dest/l1_tx_utils/interfaces.d.ts +2 -2
  85. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -1
  86. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
  87. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  88. package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
  89. package/dest/l1_tx_utils/l1_tx_utils.d.ts +1 -1
  90. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
  91. package/dest/l1_tx_utils/l1_tx_utils.js +17 -4
  92. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +4 -15
  93. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  94. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +52 -159
  95. package/dest/queries.d.ts +2 -2
  96. package/dest/queries.d.ts.map +1 -1
  97. package/dest/queries.js +12 -4
  98. package/dest/test/chain_monitor.d.ts +15 -13
  99. package/dest/test/chain_monitor.d.ts.map +1 -1
  100. package/dest/test/chain_monitor.js +7 -9
  101. package/dest/test/eth_cheat_codes.d.ts +13 -1
  102. package/dest/test/eth_cheat_codes.d.ts.map +1 -1
  103. package/dest/test/eth_cheat_codes.js +4 -2
  104. package/dest/test/rollup_cheat_codes.d.ts +7 -6
  105. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  106. package/dest/test/rollup_cheat_codes.js +23 -6
  107. package/dest/test/start_anvil.d.ts +3 -1
  108. package/dest/test/start_anvil.d.ts.map +1 -1
  109. package/dest/test/tx_delayer.d.ts +1 -1
  110. package/dest/test/tx_delayer.d.ts.map +1 -1
  111. package/dest/test/tx_delayer.js +4 -3
  112. package/dest/types.d.ts +57 -2
  113. package/dest/types.d.ts.map +1 -1
  114. package/dest/utils.d.ts +15 -3
  115. package/dest/utils.d.ts.map +1 -1
  116. package/dest/utils.js +18 -0
  117. package/package.json +33 -14
  118. package/src/client.ts +2 -2
  119. package/src/config.ts +62 -457
  120. package/src/contracts/README.md +157 -0
  121. package/src/contracts/empire_base.ts +1 -1
  122. package/src/contracts/empire_slashing_proposer.ts +6 -1
  123. package/src/contracts/fee_asset_handler.ts +8 -7
  124. package/src/contracts/governance.ts +8 -1
  125. package/src/contracts/governance_proposer.ts +6 -1
  126. package/src/contracts/inbox.ts +55 -3
  127. package/src/contracts/index.ts +2 -0
  128. package/src/contracts/log.ts +13 -0
  129. package/src/contracts/outbox.ts +98 -0
  130. package/src/contracts/rollup.ts +375 -111
  131. package/src/contracts/tally_slashing_proposer.ts +3 -1
  132. package/src/deploy_aztec_l1_contracts.ts +619 -0
  133. package/src/deploy_l1_contract.ts +362 -0
  134. package/src/forwarder_proxy.ts +108 -0
  135. package/src/generated/l1-contracts-defaults.ts +32 -0
  136. package/src/l1_contract_addresses.ts +22 -20
  137. package/src/l1_reader.ts +8 -0
  138. package/src/l1_tx_utils/config.ts +24 -6
  139. package/src/l1_tx_utils/constants.ts +11 -0
  140. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  141. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
  142. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
  143. package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
  144. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +119 -0
  145. package/src/l1_tx_utils/index-blobs.ts +2 -0
  146. package/src/l1_tx_utils/index.ts +2 -0
  147. package/src/l1_tx_utils/interfaces.ts +1 -1
  148. package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
  149. package/src/l1_tx_utils/l1_tx_utils.ts +24 -4
  150. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +65 -204
  151. package/src/queries.ts +11 -3
  152. package/src/test/chain_monitor.ts +18 -16
  153. package/src/test/eth_cheat_codes.ts +2 -2
  154. package/src/test/rollup_cheat_codes.ts +23 -9
  155. package/src/test/start_anvil.ts +2 -0
  156. package/src/test/tx_delayer.ts +5 -3
  157. package/src/types.ts +62 -0
  158. package/src/utils.ts +30 -1
  159. package/dest/deploy_l1_contracts.d.ts +0 -673
  160. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  161. package/dest/deploy_l1_contracts.js +0 -1491
  162. package/dest/index.d.ts +0 -18
  163. package/dest/index.d.ts.map +0 -1
  164. package/dest/index.js +0 -17
  165. package/src/deploy_l1_contracts.ts +0 -1869
  166. package/src/index.ts +0 -17
@@ -130,12 +130,32 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
130
130
  return;
131
131
  }
132
132
 
133
- // Convert loaded states (which have id) to the txs format
134
- this.txs = loadedStates;
135
- this.logger.info(`Rehydrated ${loadedStates.length} tx states for account ${account}`);
133
+ // Clean up excess states if we have more than MAX_L1_TX_STATES
134
+ if (loadedStates.length > MAX_L1_TX_STATES) {
135
+ this.logger.warn(
136
+ `Found ${loadedStates.length} tx states for account ${account}, pruning to most recent ${MAX_L1_TX_STATES}`,
137
+ );
138
+
139
+ // Keep only the most recent MAX_L1_TX_STATES
140
+ const statesToKeep = loadedStates.slice(-MAX_L1_TX_STATES);
141
+ const statesToDelete = loadedStates.slice(0, -MAX_L1_TX_STATES);
142
+
143
+ // Batch delete old states in a transaction for efficiency
144
+ const idsToDelete = statesToDelete.map(s => s.id);
145
+ await this.store.deleteState(account, ...idsToDelete);
146
+
147
+ this.txs = statesToKeep;
148
+ this.logger.info(
149
+ `Cleaned up ${statesToDelete.length} old tx states, kept ${statesToKeep.length} for account ${account}`,
150
+ );
151
+ } else {
152
+ // Convert loaded states (which have id) to the txs format
153
+ this.txs = loadedStates;
154
+ this.logger.info(`Rehydrated ${loadedStates.length} tx states for account ${account}`);
155
+ }
136
156
 
137
157
  // Find all pending states and resume monitoring
138
- const pendingStates = loadedStates.filter(state => !TerminalTxUtilsState.includes(state.status));
158
+ const pendingStates = this.txs.filter(state => !TerminalTxUtilsState.includes(state.status));
139
159
  if (pendingStates.length === 0) {
140
160
  return;
141
161
  }
@@ -1,4 +1,5 @@
1
- import { getKeys, median, merge, pick, times } from '@aztec/foundation/collection';
1
+ import { getKeys, merge, pick, times } from '@aztec/foundation/collection';
2
+ import type { EthAddress } from '@aztec/foundation/eth-address';
2
3
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
4
  import { makeBackoff, retry } from '@aztec/foundation/retry';
4
5
  import { DateProvider } from '@aztec/foundation/timer';
@@ -11,6 +12,7 @@ import {
11
12
  type BaseError,
12
13
  type BlockOverrides,
13
14
  type ContractFunctionExecutionError,
15
+ type GetCodeReturnType,
14
16
  type Hex,
15
17
  MethodNotFoundRpcError,
16
18
  MethodNotSupportedRpcError,
@@ -30,10 +32,12 @@ import {
30
32
  MIN_REPLACEMENT_BUMP_PERCENTAGE,
31
33
  WEI_CONST,
32
34
  } from './constants.js';
35
+ import { P75AllTxsPriorityFeeStrategy, type PriorityFeeStrategy } from './fee-strategies/index.js';
33
36
  import type { GasPrice, L1BlobInputs, L1TxRequest, TransactionStats } from './types.js';
34
37
  import { getCalldataGasUsage, tryGetCustomErrorNameContractFunction } from './utils.js';
35
38
 
36
- const HISTORICAL_BLOCK_COUNT = 5;
39
+ // Change this to the current strategy we want to use
40
+ const CurrentStrategy: PriorityFeeStrategy = P75AllTxsPriorityFeeStrategy;
37
41
 
38
42
  export class ReadOnlyL1TxUtils {
39
43
  public config: Required<L1TxUtilsConfig>;
@@ -65,122 +69,8 @@ export class ReadOnlyL1TxUtils {
65
69
  return this.client.getBlockNumber();
66
70
  }
67
71
 
68
- /**
69
- * Analyzes pending transactions and recent fee history to determine a competitive priority fee.
70
- * Falls back to network estimate if data is unavailable or fails.
71
- * @param networkEstimateResult - Result from estimateMaxPriorityFeePerGas RPC call
72
- * @param pendingBlockResult - Result from getBlock with pending tag RPC call
73
- * @param feeHistoryResult - Result from getFeeHistory RPC call
74
- * @returns A competitive priority fee based on pending txs and recent block history
75
- */
76
- protected getCompetitivePriorityFee(
77
- networkEstimateResult: PromiseSettledResult<bigint | null>,
78
- pendingBlockResult: PromiseSettledResult<Awaited<ReturnType<ViemClient['getBlock']>> | null>,
79
- feeHistoryResult: PromiseSettledResult<Awaited<ReturnType<ViemClient['getFeeHistory']>> | null>,
80
- ): bigint {
81
- const networkEstimate =
82
- networkEstimateResult.status === 'fulfilled' && typeof networkEstimateResult.value === 'bigint'
83
- ? networkEstimateResult.value
84
- : 0n;
85
- let competitiveFee = networkEstimate;
86
-
87
- if (
88
- pendingBlockResult.status === 'fulfilled' &&
89
- pendingBlockResult.value !== null &&
90
- pendingBlockResult.value.transactions &&
91
- pendingBlockResult.value.transactions.length > 0
92
- ) {
93
- const pendingBlock = pendingBlockResult.value;
94
- // Extract priority fees from pending transactions
95
- const pendingFees = pendingBlock.transactions
96
- .map(tx => {
97
- // Transaction can be just a hash string, so we need to check if it's an object
98
- if (typeof tx === 'string') {
99
- return 0n;
100
- }
101
- const fee = tx.maxPriorityFeePerGas || 0n;
102
- // Debug: Log suspicious fees
103
- if (fee > 100n * WEI_CONST) {
104
- this.logger?.warn('Suspicious high priority fee in pending tx', {
105
- txHash: tx.hash,
106
- maxPriorityFeePerGas: formatGwei(fee),
107
- maxFeePerGas: formatGwei(tx.maxFeePerGas || 0n),
108
- maxFeePerBlobGas: tx.maxFeePerBlobGas ? formatGwei(tx.maxFeePerBlobGas) : 'N/A',
109
- });
110
- }
111
- return fee;
112
- })
113
- .filter((fee: bigint) => fee > 0n);
114
-
115
- if (pendingFees.length > 0) {
116
- // Use 75th percentile of pending fees to be competitive
117
- const sortedPendingFees = [...pendingFees].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
118
- const percentile75Index = Math.floor((sortedPendingFees.length - 1) * 0.75);
119
- const pendingCompetitiveFee = sortedPendingFees[percentile75Index];
120
-
121
- if (pendingCompetitiveFee > competitiveFee) {
122
- competitiveFee = pendingCompetitiveFee;
123
- }
124
-
125
- this.logger?.debug('Analyzed pending transactions for competitive pricing', {
126
- pendingTxCount: pendingFees.length,
127
- pendingP75: formatGwei(pendingCompetitiveFee),
128
- });
129
- }
130
- }
131
- if (
132
- feeHistoryResult.status === 'fulfilled' &&
133
- feeHistoryResult.value !== null &&
134
- feeHistoryResult.value.reward &&
135
- feeHistoryResult.value.reward.length > 0
136
- ) {
137
- const feeHistory = feeHistoryResult.value;
138
- // Extract 75th percentile fees from each block
139
- const percentile75Fees = feeHistory.reward!.map(rewards => rewards[0] || 0n).filter(fee => fee > 0n);
140
-
141
- if (percentile75Fees.length > 0) {
142
- // Calculate median of the 75th percentile fees across blocks
143
- const medianHistoricalFee = median(percentile75Fees) ?? 0n;
144
-
145
- // Debug: Log suspicious fees from history
146
- if (medianHistoricalFee > 100n * WEI_CONST) {
147
- this.logger?.warn('Suspicious high fee in history', {
148
- historicalMedian: formatGwei(medianHistoricalFee),
149
- allP75Fees: percentile75Fees.map(f => formatGwei(f)),
150
- });
151
- }
152
-
153
- if (medianHistoricalFee > competitiveFee) {
154
- competitiveFee = medianHistoricalFee;
155
- }
156
-
157
- this.logger?.debug('Analyzed fee history for competitive pricing', {
158
- historicalMedian: formatGwei(medianHistoricalFee),
159
- });
160
- }
161
- }
162
-
163
- // Sanity check: cap competitive fee at 100x network estimate to avoid using unrealistic fees
164
- // (e.g., Anvil returns inflated historical fees that don't reflect actual network conditions)
165
- const maxReasonableFee = networkEstimate * 100n;
166
- if (competitiveFee > maxReasonableFee) {
167
- this.logger?.warn('Competitive fee exceeds sanity cap, using capped value', {
168
- competitiveFee: formatGwei(competitiveFee),
169
- networkEstimate: formatGwei(networkEstimate),
170
- cappedTo: formatGwei(maxReasonableFee),
171
- });
172
- competitiveFee = maxReasonableFee;
173
- }
174
-
175
- // Log final decision
176
- if (competitiveFee > networkEstimate) {
177
- this.logger?.debug('Using competitive fee from market analysis', {
178
- networkEstimate: formatGwei(networkEstimate),
179
- competitive: formatGwei(competitiveFee),
180
- });
181
- }
182
-
183
- return competitiveFee;
72
+ public getCode(address: EthAddress): Promise<GetCodeReturnType> {
73
+ return this.client.getCode({ address: address.toString() });
184
74
  }
185
75
 
186
76
  /**
@@ -194,68 +84,47 @@ export class ReadOnlyL1TxUtils {
194
84
  ): Promise<GasPrice> {
195
85
  const gasConfig = merge(this.config, gasConfigOverrides);
196
86
 
197
- // Make all RPC calls in parallel upfront with retry logic
198
- const latestBlockPromise = this.tryTwice(
199
- () => this.client.getBlock({ blockTag: 'latest' }),
200
- 'Getting latest block',
87
+ // Execute strategy - it handles all RPC calls internally and returns everything we need
88
+ const strategyResult = await retry(
89
+ () =>
90
+ CurrentStrategy.execute(this.client, {
91
+ gasConfig,
92
+ isBlobTx,
93
+ logger: this.logger,
94
+ }),
95
+ 'Executing priority fee strategy',
96
+ makeBackoff(times(2, () => 0)),
97
+ this.logger,
98
+ true,
201
99
  );
202
- const networkEstimatePromise = gasConfig.fixedPriorityFeePerGas
203
- ? null
204
- : this.tryTwice(() => this.client.estimateMaxPriorityFeePerGas(), 'Estimating max priority fee per gas');
205
- const pendingBlockPromise = gasConfig.fixedPriorityFeePerGas
206
- ? null
207
- : this.tryTwice(
208
- () => this.client.getBlock({ blockTag: 'pending', includeTransactions: true }),
209
- 'Getting pending block',
210
- );
211
- const feeHistoryPromise = gasConfig.fixedPriorityFeePerGas
212
- ? null
213
- : this.tryTwice(
214
- () => this.client.getFeeHistory({ blockCount: HISTORICAL_BLOCK_COUNT, rewardPercentiles: [75] }),
215
- 'Getting fee history',
216
- );
217
- const blobBaseFeePromise = isBlobTx
218
- ? this.tryTwice(() => this.client.getBlobBaseFee(), 'Getting blob base fee')
219
- : null;
220
-
221
- const [latestBlockResult, networkEstimateResult, pendingBlockResult, feeHistoryResult, blobBaseFeeResult] =
222
- await Promise.allSettled([
223
- latestBlockPromise,
224
- networkEstimatePromise ?? Promise.resolve(0n),
225
- pendingBlockPromise ?? Promise.resolve(null),
226
- feeHistoryPromise ?? Promise.resolve(null),
227
- blobBaseFeePromise ?? Promise.resolve(0n),
228
- ]);
229
-
230
- // Extract results
231
- const baseFee =
232
- latestBlockResult.status === 'fulfilled' &&
233
- typeof latestBlockResult.value === 'object' &&
234
- latestBlockResult.value.baseFeePerGas
235
- ? latestBlockResult.value.baseFeePerGas
236
- : 0n;
237
-
238
- // Get blob base fee if available
239
- let blobBaseFee = 0n;
240
- if (isBlobTx && blobBaseFeeResult.status === 'fulfilled' && typeof blobBaseFeeResult.value === 'bigint') {
241
- blobBaseFee = blobBaseFeeResult.value;
242
- } else if (isBlobTx) {
100
+
101
+ const { latestBlock, blobBaseFee, priorityFee: strategyPriorityFee } = strategyResult;
102
+
103
+ // Extract base fee from latest block
104
+ const baseFee = latestBlock.baseFeePerGas ?? 0n;
105
+
106
+ // Handle blob base fee
107
+ if (isBlobTx && blobBaseFee === undefined) {
243
108
  this.logger?.warn('Failed to get L1 blob base fee', attempt);
244
109
  }
245
110
 
246
- let priorityFee: bigint;
247
- if (gasConfig.fixedPriorityFeePerGas) {
248
- this.logger?.debug('Using fixed priority fee per L1 gas', {
249
- fixedPriorityFeePerGas: gasConfig.fixedPriorityFeePerGas,
250
- });
251
- priorityFee = BigInt(Math.trunc(gasConfig.fixedPriorityFeePerGas * Number(WEI_CONST)));
252
- } else {
253
- // Get competitive priority fee (includes network estimate + analysis)
254
- priorityFee = this.getCompetitivePriorityFee(networkEstimateResult, pendingBlockResult, feeHistoryResult);
111
+ let priorityFee = strategyPriorityFee;
112
+
113
+ // Apply minimum priority fee floor if configured
114
+ if (gasConfig.minimumPriorityFeePerGas) {
115
+ const minimumPriorityFee = BigInt(Math.trunc(gasConfig.minimumPriorityFeePerGas * Number(WEI_CONST)));
116
+ if (priorityFee < minimumPriorityFee) {
117
+ this.logger?.debug('Applying minimum priority fee floor', {
118
+ calculatedPriorityFee: formatGwei(priorityFee),
119
+ minimumPriorityFeePerGas: gasConfig.minimumPriorityFeePerGas,
120
+ appliedFee: formatGwei(minimumPriorityFee),
121
+ });
122
+ priorityFee = minimumPriorityFee;
123
+ }
255
124
  }
256
125
  let maxFeePerGas = baseFee;
257
126
 
258
- let maxFeePerBlobGas = blobBaseFee;
127
+ let maxFeePerBlobGas = blobBaseFee ?? 0n;
259
128
 
260
129
  // Bump base fee so it's valid for next blocks if it stalls
261
130
  const numBlocks = Math.ceil(gasConfig.stallTimeMs! / BLOCK_TIME_MS);
@@ -280,18 +149,15 @@ export class ReadOnlyL1TxUtils {
280
149
  (previousGasPrice!.maxPriorityFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
281
150
  const minMaxFee = (previousGasPrice!.maxFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
282
151
 
283
- let competitivePriorityFee = priorityFee;
284
- if (!gasConfig.fixedPriorityFeePerGas) {
285
- // Apply bump percentage to competitive fee
286
- competitivePriorityFee = (priorityFee * (100_00n + BigInt(configBump * 1_00))) / 100_00n;
152
+ // Apply bump percentage to competitive fee
153
+ const competitivePriorityFee = (priorityFee * (100_00n + BigInt(configBump * 1_00))) / 100_00n;
287
154
 
288
- this.logger?.debug(`Speed-up attempt ${attempt}: using competitive fee strategy`, {
289
- networkEstimate: formatGwei(priorityFee),
290
- competitiveFee: formatGwei(competitivePriorityFee),
291
- minRequired: formatGwei(minPriorityFee),
292
- bumpPercentage: configBump,
293
- });
294
- }
155
+ this.logger?.debug(`Speed-up attempt ${attempt}: using competitive fee strategy`, {
156
+ networkEstimate: formatGwei(priorityFee),
157
+ competitiveFee: formatGwei(competitivePriorityFee),
158
+ minRequired: formatGwei(minPriorityFee),
159
+ bumpPercentage: configBump,
160
+ });
295
161
 
296
162
  // Use maximum between competitive fee and minimum required bump
297
163
  const finalPriorityFee = competitivePriorityFee > minPriorityFee ? competitivePriorityFee : minPriorityFee;
@@ -302,20 +168,16 @@ export class ReadOnlyL1TxUtils {
302
168
  maxFeePerGas += finalPriorityFee;
303
169
  maxFeePerGas = maxFeePerGas > minMaxFee ? maxFeePerGas : minMaxFee;
304
170
 
305
- if (!gasConfig.fixedPriorityFeePerGas) {
306
- this.logger?.debug(`Speed-up fee decision: using ${feeSource} fee`, {
307
- finalPriorityFee: formatGwei(finalPriorityFee),
308
- });
309
- }
171
+ this.logger?.debug(`Speed-up fee decision: using ${feeSource} fee`, {
172
+ finalPriorityFee: formatGwei(finalPriorityFee),
173
+ });
310
174
  } else {
311
175
  // First attempt: apply configured bump percentage to competitive fee
312
176
  // multiply by 100 & divide by 100 to maintain some precision
313
- if (!gasConfig.fixedPriorityFeePerGas) {
314
- priorityFee = (priorityFee * (100_00n + BigInt((gasConfig.priorityFeeBumpPercentage || 0) * 1_00))) / 100_00n;
315
- this.logger?.debug('Initial transaction: using competitive fee from market analysis', {
316
- networkEstimate: formatGwei(priorityFee),
317
- });
318
- }
177
+ priorityFee = (priorityFee * (100_00n + BigInt((gasConfig.priorityFeeBumpPercentage || 0) * 1_00))) / 100_00n;
178
+ this.logger?.debug('Initial transaction: using competitive fee from market analysis', {
179
+ networkEstimate: formatGwei(priorityFee),
180
+ });
319
181
  maxFeePerGas += priorityFee;
320
182
  }
321
183
 
@@ -356,7 +218,7 @@ export class ReadOnlyL1TxUtils {
356
218
  baseFee: formatGwei(baseFee),
357
219
  maxFeePerGas: formatGwei(maxFeePerGas),
358
220
  maxPriorityFeePerGas: formatGwei(maxPriorityFeePerGas),
359
- blobBaseFee: formatGwei(blobBaseFee),
221
+ blobBaseFee: formatGwei(blobBaseFee ?? 0n),
360
222
  maxFeePerBlobGas: formatGwei(maxFeePerBlobGas),
361
223
  },
362
224
  );
@@ -388,11 +250,17 @@ export class ReadOnlyL1TxUtils {
388
250
  ..._blobInputs,
389
251
  maxFeePerBlobGas: gasPrice.maxFeePerBlobGas!,
390
252
  gas: LARGE_GAS_LIMIT,
253
+ blockTag: 'latest',
391
254
  });
392
255
 
393
256
  this.logger?.trace(`Estimated gas for blob tx: ${initialEstimate}`);
394
257
  } else {
395
- initialEstimate = await this.client.estimateGas({ account, ...request, gas: LARGE_GAS_LIMIT });
258
+ initialEstimate = await this.client.estimateGas({
259
+ account,
260
+ ...request,
261
+ gas: LARGE_GAS_LIMIT,
262
+ blockTag: 'latest',
263
+ });
396
264
  this.logger?.trace(`Estimated gas for non-blob tx: ${initialEstimate}`);
397
265
  }
398
266
 
@@ -548,11 +416,4 @@ export class ReadOnlyL1TxUtils {
548
416
  });
549
417
  return bumpedGasLimit;
550
418
  }
551
-
552
- /**
553
- * Helper function to retry RPC calls twice
554
- */
555
- private tryTwice<T>(fn: () => Promise<T>, description: string): Promise<T> {
556
- return retry<T>(fn, description, makeBackoff(times(2, () => 0)), this.logger, true);
557
- }
558
419
  }
package/src/queries.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { EthAddress } from '@aztec/foundation/eth-address';
2
2
 
3
- import type { L1ContractsConfig } from './config.js';
3
+ import { DefaultL1ContractsConfig, type L1ContractsConfig } from './config.js';
4
4
  import { ReadOnlyGovernanceContract } from './contracts/governance.js';
5
5
  import { GovernanceProposerContract } from './contracts/governance_proposer.js';
6
+ import { InboxContract } from './contracts/inbox.js';
6
7
  import { RollupContract } from './contracts/rollup.js';
7
8
  import type { ViemPublicClient } from './types.js';
8
9
 
@@ -25,6 +26,8 @@ export async function getL1ContractsConfig(
25
26
  const rollup = new RollupContract(publicClient, rollupAddress.toString());
26
27
  const slasherProposer = await rollup.getSlashingProposer();
27
28
  const slasher = await rollup.getSlasherContract();
29
+ const rollupAddresses = await rollup.getRollupAddresses();
30
+ const inboxContract = new InboxContract(publicClient, rollupAddresses.inboxAddress.toString());
28
31
 
29
32
  const [
30
33
  l1StartBlock,
@@ -35,6 +38,7 @@ export async function getL1ContractsConfig(
35
38
  aztecTargetCommitteeSize,
36
39
  lagInEpochsForValidatorSet,
37
40
  lagInEpochsForRandao,
41
+ inboxLag,
38
42
  activationThreshold,
39
43
  ejectionThreshold,
40
44
  localEjectionThreshold,
@@ -62,6 +66,7 @@ export async function getL1ContractsConfig(
62
66
  rollup.getTargetCommitteeSize(),
63
67
  rollup.getLagInEpochsForValidatorSet(),
64
68
  rollup.getLagInEpochsForRandao(),
69
+ inboxContract.getLag(),
65
70
  rollup.getActivationThreshold(),
66
71
  rollup.getEjectionThreshold(),
67
72
  rollup.getLocalEjectionThreshold(),
@@ -91,13 +96,15 @@ export async function getL1ContractsConfig(
91
96
  aztecTargetCommitteeSize: Number(aztecTargetCommitteeSize),
92
97
  lagInEpochsForValidatorSet: Number(lagInEpochsForValidatorSet),
93
98
  lagInEpochsForRandao: Number(lagInEpochsForRandao),
99
+ inboxLag: Number(inboxLag),
94
100
  governanceProposerQuorum: Number(governanceProposerQuorum),
95
101
  governanceProposerRoundSize: Number(governanceProposerRoundSize),
102
+ governanceVotingDuration: DefaultL1ContractsConfig.governanceVotingDuration,
96
103
  activationThreshold,
97
104
  ejectionThreshold,
98
105
  localEjectionThreshold,
99
106
  slashingQuorum: Number(slashingQuorum),
100
- slashingRoundSizeInEpochs: Number(slashingRoundSize / aztecEpochDuration),
107
+ slashingRoundSizeInEpochs: Number(Number(slashingRoundSize) / aztecEpochDuration),
101
108
  slashingLifetimeInRounds: Number(slashingLifetimeInRounds),
102
109
  slashingExecutionDelayInRounds: Number(slashingExecutionDelayInRounds),
103
110
  slashingVetoer,
@@ -105,12 +112,13 @@ export async function getL1ContractsConfig(
105
112
  manaTarget,
106
113
  provingCostPerMana: provingCostPerMana,
107
114
  rollupVersion: Number(rollupVersion),
108
- genesisArchiveTreeRoot,
115
+ genesisArchiveTreeRoot: genesisArchiveTreeRoot.toString(),
109
116
  exitDelaySeconds: Number(exitDelay),
110
117
  slasherFlavor: slasherProposer?.type ?? 'tally',
111
118
  slashingOffsetInRounds: Number(slashingOffsetInRounds),
112
119
  slashAmountSmall: slashingAmounts[0],
113
120
  slashAmountMedium: slashingAmounts[1],
114
121
  slashAmountLarge: slashingAmounts[2],
122
+ initialEthPerFeeAsset: DefaultL1ContractsConfig.initialEthPerFeeAsset,
115
123
  };
116
124
  }
@@ -1,5 +1,6 @@
1
- import { InboxContract, type RollupContract } from '@aztec/ethereum/contracts';
2
- import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
1
+ import type { RollupContract } from '@aztec/ethereum/contracts';
2
+ import { InboxContract } from '@aztec/ethereum/contracts';
3
+ import { CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
4
  import { EthAddress } from '@aztec/foundation/eth-address';
4
5
  import { createLogger } from '@aztec/foundation/log';
5
6
  import { promiseWithResolvers } from '@aztec/foundation/promise';
@@ -11,8 +12,10 @@ import type { ViemClient } from '../types.js';
11
12
 
12
13
  export type ChainMonitorEventMap = {
13
14
  'l1-block': [{ l1BlockNumber: number; timestamp: bigint }];
14
- checkpoint: [{ checkpointNumber: number; l1BlockNumber: number; l2SlotNumber: SlotNumber; timestamp: bigint }];
15
- 'checkpoint-proven': [{ provenCheckpointNumber: number; l1BlockNumber: number; timestamp: bigint }];
15
+ checkpoint: [
16
+ { checkpointNumber: CheckpointNumber; l1BlockNumber: number; l2SlotNumber: SlotNumber; timestamp: bigint },
17
+ ];
18
+ 'checkpoint-proven': [{ provenCheckpointNumber: CheckpointNumber; l1BlockNumber: number; timestamp: bigint }];
16
19
  'l2-messages': [{ totalL2Messages: number; l1BlockNumber: number }];
17
20
  'l2-epoch': [{ l2EpochNumber: EpochNumber; timestamp: bigint; committee: EthAddress[] | undefined }];
18
21
  'l2-slot': [{ l2SlotNumber: SlotNumber; timestamp: bigint }];
@@ -29,9 +32,9 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
29
32
  /** Current L1 block number */
30
33
  public l1BlockNumber!: number;
31
34
  /** Current checkpoint number */
32
- public checkpointNumber!: number;
35
+ public checkpointNumber!: CheckpointNumber;
33
36
  /** Current proven checkpoint number */
34
- public provenCheckpointNumber!: number;
37
+ public provenCheckpointNumber!: CheckpointNumber;
35
38
  /** L1 timestamp for the current checkpoint */
36
39
  public checkpointTimestamp!: bigint;
37
40
  /** L1 timestamp for the proven checkpoint */
@@ -115,9 +118,9 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
115
118
  this.emit('l1-block', { l1BlockNumber: newL1BlockNumber, timestamp });
116
119
  let msg = `L1 block ${newL1BlockNumber} mined at ${timestampString}`;
117
120
 
118
- const newCheckpointNumber = Number(await this.rollup.getCheckpointNumber());
121
+ const newCheckpointNumber = await this.rollup.getCheckpointNumber();
119
122
  if (this.checkpointNumber !== newCheckpointNumber) {
120
- const epochNumber = await this.rollup.getEpochNumberForCheckpoint(BigInt(newCheckpointNumber));
123
+ const epochNumber = await this.rollup.getEpochNumberForCheckpoint(newCheckpointNumber);
121
124
  msg += ` with new checkpoint ${newCheckpointNumber} for epoch ${epochNumber}`;
122
125
  this.checkpointNumber = newCheckpointNumber;
123
126
  this.checkpointTimestamp = timestamp;
@@ -129,9 +132,9 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
129
132
  });
130
133
  }
131
134
 
132
- const newProvenCheckpointNumber = Number(await this.rollup.getProvenCheckpointNumber());
135
+ const newProvenCheckpointNumber = await this.rollup.getProvenCheckpointNumber();
133
136
  if (this.provenCheckpointNumber !== newProvenCheckpointNumber) {
134
- const epochNumber = await this.rollup.getEpochNumberForCheckpoint(BigInt(newProvenCheckpointNumber));
137
+ const epochNumber = await this.rollup.getEpochNumberForCheckpoint(newProvenCheckpointNumber);
135
138
  msg += ` with proof up to checkpoint ${newProvenCheckpointNumber} for epoch ${epochNumber}`;
136
139
  this.provenCheckpointNumber = newProvenCheckpointNumber;
137
140
  this.provenCheckpointTimestamp = timestamp;
@@ -153,7 +156,7 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
153
156
  let committee: EthAddress[] | undefined;
154
157
  if (l2Epoch !== this.l2EpochNumber) {
155
158
  this.l2EpochNumber = l2Epoch;
156
- committee = (await this.rollup.getCurrentEpochCommittee())?.map(addr => EthAddress.fromString(addr));
159
+ committee = await this.rollup.getCurrentEpochCommittee();
157
160
  this.emit('l2-epoch', { l2EpochNumber: l2Epoch, timestamp, committee });
158
161
  msg += ` starting new epoch ${this.l2EpochNumber} `;
159
162
  }
@@ -225,14 +228,13 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
225
228
  });
226
229
  }
227
230
 
228
- public waitUntilCheckpoint(checkpointNumber: number | bigint): Promise<void> {
229
- const targetBlock = typeof checkpointNumber === 'bigint' ? checkpointNumber.valueOf() : checkpointNumber;
230
- if (this.checkpointNumber >= targetBlock) {
231
+ public waitUntilCheckpoint(checkpointNumber: CheckpointNumber): Promise<void> {
232
+ if (this.checkpointNumber >= checkpointNumber) {
231
233
  return Promise.resolve();
232
234
  }
233
235
  return new Promise(resolve => {
234
- const listener = (data: { checkpointNumber: number; timestamp: bigint }) => {
235
- if (data.checkpointNumber >= targetBlock) {
236
+ const listener = (data: { checkpointNumber: CheckpointNumber; timestamp: bigint }) => {
237
+ if (data.checkpointNumber >= checkpointNumber) {
236
238
  this.off('checkpoint', listener);
237
239
  resolve();
238
240
  }
@@ -1,5 +1,5 @@
1
1
  import { toBigIntBE, toHex } from '@aztec/foundation/bigint-buffer';
2
- import { keccak256 } from '@aztec/foundation/crypto';
2
+ import { keccak256 } from '@aztec/foundation/crypto/keccak';
3
3
  import { EthAddress } from '@aztec/foundation/eth-address';
4
4
  import { jsonStringify } from '@aztec/foundation/json-rpc';
5
5
  import { createLogger } from '@aztec/foundation/log';
@@ -35,7 +35,7 @@ export class EthCheatCodes {
35
35
  public chain: Chain = foundry,
36
36
  ) {
37
37
  this.publicClient = createPublicClient({
38
- transport: fallback(this.rpcUrls.map(url => http(url))),
38
+ transport: fallback(this.rpcUrls.map(url => http(url, { batch: false }))),
39
39
  chain: chain,
40
40
  });
41
41
  }
@@ -1,6 +1,7 @@
1
- import { RollupContract, type ViemPublicClient } from '@aztec/ethereum';
1
+ import { OutboxContract, RollupContract } from '@aztec/ethereum/contracts';
2
2
  import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
3
- import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
+ import type { ViemPublicClient } from '@aztec/ethereum/types';
4
+ import { CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
4
5
  import { EthAddress } from '@aztec/foundation/eth-address';
5
6
  import { createLogger } from '@aztec/foundation/log';
6
7
  import type { DateProvider } from '@aztec/foundation/timer';
@@ -31,7 +32,7 @@ export class RollupCheatCodes {
31
32
  ) {
32
33
  this.client = createPublicClient({
33
34
  chain: ethCheatCodes.chain,
34
- transport: fallback(ethCheatCodes.rpcUrls.map(url => http(url))),
35
+ transport: fallback(ethCheatCodes.rpcUrls.map(url => http(url, { batch: false }))),
35
36
  });
36
37
  this.rollup = getContract({
37
38
  abi: RollupAbi,
@@ -66,10 +67,14 @@ export class RollupCheatCodes {
66
67
  * @returns The pending and proven chain tips
67
68
  */
68
69
  public async getTips(): Promise<{
69
- /** The pending chain tip */ pending: bigint;
70
- /** The proven chain tip */ proven: bigint;
70
+ /** The pending chain tip */ pending: CheckpointNumber;
71
+ /** The proven chain tip */ proven: CheckpointNumber;
71
72
  }> {
72
- return await this.rollup.read.getTips();
73
+ const { pending, proven } = await this.rollup.read.getTips();
74
+ return {
75
+ pending: CheckpointNumber.fromBigInt(pending),
76
+ proven: CheckpointNumber.fromBigInt(proven),
77
+ };
73
78
  }
74
79
 
75
80
  /**
@@ -119,11 +124,11 @@ export class RollupCheatCodes {
119
124
  } = {},
120
125
  ) {
121
126
  const { epochDuration: slotsInEpoch } = await this.getConfig();
122
- const slotNumber = SlotNumber(epoch * Number(slotsInEpoch));
127
+ const slotNumber = SlotNumber(Number(epoch) * Number(slotsInEpoch));
123
128
  const timestamp = (await this.rollup.read.getTimestampForSlot([BigInt(slotNumber)])) + BigInt(opts.offset ?? 0);
124
129
  try {
125
130
  await this.ethCheatCodes.warp(Number(timestamp), { ...opts, silent: true, resetBlockInterval: true });
126
- this.logger.warn(`Warped to epoch ${epoch}`);
131
+ this.logger.warn(`Warped to epoch ${epoch}`, { offset: opts.offset, timestamp });
127
132
  } catch (err) {
128
133
  this.logger.warn(`Warp to epoch ${epoch} failed: ${err}`);
129
134
  }
@@ -171,7 +176,7 @@ export class RollupCheatCodes {
171
176
  * Marks the specified checkpoint (or latest if none) as proven
172
177
  * @param maybeCheckpointNumber - The checkpoint number to mark as proven (defaults to latest pending)
173
178
  */
174
- public markAsProven(maybeCheckpointNumber?: number | bigint) {
179
+ public markAsProven(maybeCheckpointNumber?: CheckpointNumber) {
175
180
  return this.ethCheatCodes.execWithPausedAnvil(async () => {
176
181
  const tipsBefore = await this.getTips();
177
182
  const { pending, proven } = tipsBefore;
@@ -245,6 +250,15 @@ export class RollupCheatCodes {
245
250
  });
246
251
  }
247
252
 
253
+ public insertOutbox(epoch: EpochNumber, outHash: bigint) {
254
+ return this.ethCheatCodes.execWithPausedAnvil(async () => {
255
+ const outboxAddress = await this.rollup.read.getOutbox();
256
+ const epochRootSlot = OutboxContract.getEpochRootStorageSlot(epoch);
257
+ await this.ethCheatCodes.store(EthAddress.fromString(outboxAddress), epochRootSlot, outHash);
258
+ this.logger.warn(`Advanced outbox to epoch ${epoch} with out hash ${outHash}`);
259
+ });
260
+ }
261
+
248
262
  /**
249
263
  * Executes an action impersonated as the owner of the Rollup contract.
250
264
  * @param action - The action to execute
@@ -16,6 +16,8 @@ export async function startAnvil(
16
16
  captureMethodCalls?: boolean;
17
17
  accounts?: number;
18
18
  chainId?: number;
19
+ /** The hardfork to use - note: @viem/anvil types are out of date but 'cancun' and 'latest' work */
20
+ hardfork?: string;
19
21
  } = {},
20
22
  ): Promise<{ anvil: Anvil; methodCalls?: string[]; rpcUrl: string; stop: () => Promise<void> }> {
21
23
  const anvilBinary = resolve(dirname(fileURLToPath(import.meta.url)), '../../', 'scripts/anvil_kill_wrapper.sh');