@aztec/ethereum 0.0.1-commit.5daedc8 → 0.0.1-commit.6201a7b05

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 (212) hide show
  1. package/dest/client.d.ts +16 -2
  2. package/dest/client.d.ts.map +1 -1
  3. package/dest/client.js +27 -3
  4. package/dest/config.d.ts +26 -73
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +64 -387
  7. package/dest/contracts/chain_state_override.d.ts +38 -0
  8. package/dest/contracts/chain_state_override.d.ts.map +1 -0
  9. package/dest/contracts/chain_state_override.js +100 -0
  10. package/dest/contracts/empire_base.d.ts +4 -1
  11. package/dest/contracts/empire_base.d.ts.map +1 -1
  12. package/dest/contracts/fee_asset_handler.d.ts +6 -5
  13. package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
  14. package/dest/contracts/fee_asset_handler.js +11 -9
  15. package/dest/contracts/fee_asset_price_oracle.d.ts +101 -0
  16. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  17. package/dest/contracts/fee_asset_price_oracle.js +651 -0
  18. package/dest/contracts/governance.d.ts +3 -1
  19. package/dest/contracts/governance.d.ts.map +1 -1
  20. package/dest/contracts/governance.js +14 -4
  21. package/dest/contracts/governance_proposer.d.ts +4 -1
  22. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  23. package/dest/contracts/governance_proposer.js +404 -9
  24. package/dest/contracts/inbox.d.ts +24 -3
  25. package/dest/contracts/inbox.d.ts.map +1 -1
  26. package/dest/contracts/inbox.js +41 -1
  27. package/dest/contracts/index.d.ts +6 -3
  28. package/dest/contracts/index.d.ts.map +1 -1
  29. package/dest/contracts/index.js +5 -2
  30. package/dest/contracts/log.d.ts +13 -0
  31. package/dest/contracts/log.d.ts.map +1 -0
  32. package/dest/contracts/log.js +1 -0
  33. package/dest/contracts/multicall.d.ts +51 -2
  34. package/dest/contracts/multicall.d.ts.map +1 -1
  35. package/dest/contracts/multicall.js +87 -1
  36. package/dest/contracts/outbox.d.ts +41 -0
  37. package/dest/contracts/outbox.d.ts.map +1 -0
  38. package/dest/contracts/outbox.js +86 -0
  39. package/dest/contracts/registry.d.ts +3 -1
  40. package/dest/contracts/registry.d.ts.map +1 -1
  41. package/dest/contracts/registry.js +30 -1
  42. package/dest/contracts/rollup.d.ts +5178 -108
  43. package/dest/contracts/rollup.d.ts.map +1 -1
  44. package/dest/contracts/rollup.js +1004 -188
  45. package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +5 -5
  46. package/dest/contracts/slashing_proposer.d.ts.map +1 -0
  47. package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +18 -13
  48. package/dest/deploy_aztec_l1_contracts.d.ts +256 -0
  49. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  50. package/dest/deploy_aztec_l1_contracts.js +411 -0
  51. package/dest/deploy_l1_contract.d.ts +68 -0
  52. package/dest/deploy_l1_contract.d.ts.map +1 -0
  53. package/dest/deploy_l1_contract.js +312 -0
  54. package/dest/forwarder_proxy.d.ts +32 -0
  55. package/dest/forwarder_proxy.d.ts.map +1 -0
  56. package/dest/forwarder_proxy.js +93 -0
  57. package/dest/generated/l1-contracts-defaults.d.ts +30 -0
  58. package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
  59. package/dest/generated/l1-contracts-defaults.js +30 -0
  60. package/dest/l1_artifacts.d.ts +14161 -17158
  61. package/dest/l1_artifacts.d.ts.map +1 -1
  62. package/dest/l1_artifacts.js +9 -24
  63. package/dest/l1_contract_addresses.d.ts +1 -5
  64. package/dest/l1_contract_addresses.d.ts.map +1 -1
  65. package/dest/l1_contract_addresses.js +3 -9
  66. package/dest/l1_reader.d.ts +5 -1
  67. package/dest/l1_reader.d.ts.map +1 -1
  68. package/dest/l1_reader.js +13 -2
  69. package/dest/l1_tx_utils/config.d.ts +9 -3
  70. package/dest/l1_tx_utils/config.d.ts.map +1 -1
  71. package/dest/l1_tx_utils/config.js +31 -4
  72. package/dest/l1_tx_utils/constants.d.ts +8 -2
  73. package/dest/l1_tx_utils/constants.d.ts.map +1 -1
  74. package/dest/l1_tx_utils/constants.js +27 -2
  75. package/dest/l1_tx_utils/factory.d.ts +18 -10
  76. package/dest/l1_tx_utils/factory.d.ts.map +1 -1
  77. package/dest/l1_tx_utils/factory.js +17 -7
  78. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  79. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  80. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  81. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  82. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  83. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  84. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  85. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  86. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  87. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  88. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  89. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  90. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  91. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  92. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
  93. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  94. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  95. package/dest/l1_tx_utils/index-blobs.js +2 -0
  96. package/dest/l1_tx_utils/index.d.ts +4 -1
  97. package/dest/l1_tx_utils/index.d.ts.map +1 -1
  98. package/dest/l1_tx_utils/index.js +3 -0
  99. package/dest/l1_tx_utils/interfaces.d.ts +2 -2
  100. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -1
  101. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
  102. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  103. package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
  104. package/dest/l1_tx_utils/l1_tx_utils.d.ts +20 -7
  105. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
  106. package/dest/l1_tx_utils/l1_tx_utils.js +98 -61
  107. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +4 -15
  108. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  109. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +61 -164
  110. package/dest/l1_tx_utils/tx_delayer.d.ts +56 -0
  111. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  112. package/dest/{test → l1_tx_utils}/tx_delayer.js +65 -36
  113. package/dest/publisher_manager.d.ts +21 -6
  114. package/dest/publisher_manager.d.ts.map +1 -1
  115. package/dest/publisher_manager.js +81 -7
  116. package/dest/queries.d.ts +14 -3
  117. package/dest/queries.d.ts.map +1 -1
  118. package/dest/queries.js +74 -7
  119. package/dest/test/chain_monitor.d.ts +36 -14
  120. package/dest/test/chain_monitor.d.ts.map +1 -1
  121. package/dest/test/chain_monitor.js +45 -11
  122. package/dest/test/eth_cheat_codes.d.ts +18 -4
  123. package/dest/test/eth_cheat_codes.d.ts.map +1 -1
  124. package/dest/test/eth_cheat_codes.js +10 -6
  125. package/dest/test/index.d.ts +1 -3
  126. package/dest/test/index.d.ts.map +1 -1
  127. package/dest/test/index.js +0 -2
  128. package/dest/test/rollup_cheat_codes.d.ts +13 -6
  129. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  130. package/dest/test/rollup_cheat_codes.js +41 -7
  131. package/dest/test/start_anvil.d.ts +24 -2
  132. package/dest/test/start_anvil.d.ts.map +1 -1
  133. package/dest/test/start_anvil.js +143 -29
  134. package/dest/test/upgrade_utils.js +2 -2
  135. package/dest/types.d.ts +57 -2
  136. package/dest/types.d.ts.map +1 -1
  137. package/dest/utils.d.ts +16 -3
  138. package/dest/utils.d.ts.map +1 -1
  139. package/dest/utils.js +80 -12
  140. package/package.json +33 -16
  141. package/src/client.ts +28 -2
  142. package/src/config.ts +82 -468
  143. package/src/contracts/README.md +157 -0
  144. package/src/contracts/chain_state_override.ts +147 -0
  145. package/src/contracts/empire_base.ts +3 -1
  146. package/src/contracts/fee_asset_handler.ts +10 -7
  147. package/src/contracts/fee_asset_price_oracle.ts +280 -0
  148. package/src/contracts/governance.ts +13 -4
  149. package/src/contracts/governance_proposer.ts +16 -2
  150. package/src/contracts/inbox.ts +63 -3
  151. package/src/contracts/index.ts +5 -2
  152. package/src/contracts/log.ts +13 -0
  153. package/src/contracts/multicall.ts +70 -3
  154. package/src/contracts/outbox.ts +98 -0
  155. package/src/contracts/registry.ts +31 -1
  156. package/src/contracts/rollup.ts +701 -149
  157. package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +18 -14
  158. package/src/deploy_aztec_l1_contracts.ts +646 -0
  159. package/src/deploy_l1_contract.ts +362 -0
  160. package/src/forwarder_proxy.ts +108 -0
  161. package/src/generated/l1-contracts-defaults.ts +32 -0
  162. package/src/l1_artifacts.ts +12 -35
  163. package/src/l1_contract_addresses.ts +21 -26
  164. package/src/l1_reader.ts +22 -2
  165. package/src/l1_tx_utils/config.ts +44 -6
  166. package/src/l1_tx_utils/constants.ts +13 -2
  167. package/src/l1_tx_utils/factory.ts +31 -31
  168. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  169. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
  170. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
  171. package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
  172. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +108 -0
  173. package/src/l1_tx_utils/index-blobs.ts +2 -0
  174. package/src/l1_tx_utils/index.ts +3 -0
  175. package/src/l1_tx_utils/interfaces.ts +1 -1
  176. package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
  177. package/src/l1_tx_utils/l1_tx_utils.ts +98 -40
  178. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +75 -210
  179. package/src/{test → l1_tx_utils}/tx_delayer.ts +82 -52
  180. package/src/publisher_manager.ts +107 -10
  181. package/src/queries.ts +81 -7
  182. package/src/test/chain_monitor.ts +82 -18
  183. package/src/test/eth_cheat_codes.ts +8 -6
  184. package/src/test/index.ts +0 -2
  185. package/src/test/rollup_cheat_codes.ts +43 -10
  186. package/src/test/start_anvil.ts +178 -28
  187. package/src/test/upgrade_utils.ts +2 -2
  188. package/src/types.ts +62 -0
  189. package/src/utils.ts +100 -15
  190. package/dest/contracts/empire_slashing_proposer.d.ts +0 -66
  191. package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
  192. package/dest/contracts/empire_slashing_proposer.js +0 -200
  193. package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
  194. package/dest/deploy_l1_contracts.d.ts +0 -673
  195. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  196. package/dest/deploy_l1_contracts.js +0 -1491
  197. package/dest/index.d.ts +0 -18
  198. package/dest/index.d.ts.map +0 -1
  199. package/dest/index.js +0 -17
  200. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +0 -26
  201. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +0 -1
  202. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +0 -26
  203. package/dest/test/delayed_tx_utils.d.ts +0 -13
  204. package/dest/test/delayed_tx_utils.d.ts.map +0 -1
  205. package/dest/test/delayed_tx_utils.js +0 -28
  206. package/dest/test/tx_delayer.d.ts +0 -36
  207. package/dest/test/tx_delayer.d.ts.map +0 -1
  208. package/src/contracts/empire_slashing_proposer.ts +0 -265
  209. package/src/deploy_l1_contracts.ts +0 -1869
  210. package/src/index.ts +0 -17
  211. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
  212. package/src/test/delayed_tx_utils.ts +0 -52
@@ -1,8 +1,10 @@
1
+ import type { BlobKzgInstance } from '@aztec/blob-lib/types';
1
2
  import { maxBigint } from '@aztec/foundation/bigint';
2
3
  import { merge, pick } from '@aztec/foundation/collection';
3
4
  import { InterruptError, TimeoutError } from '@aztec/foundation/error';
4
5
  import { EthAddress } from '@aztec/foundation/eth-address';
5
- import { type Logger, createLogger } from '@aztec/foundation/log';
6
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
7
+ import { Semaphore } from '@aztec/foundation/queue';
6
8
  import { retryUntil } from '@aztec/foundation/retry';
7
9
  import { sleep } from '@aztec/foundation/sleep';
8
10
  import { DateProvider } from '@aztec/foundation/timer';
@@ -13,23 +15,21 @@ import {
13
15
  type Abi,
14
16
  type BlockOverrides,
15
17
  type Hex,
16
- type NonceManager,
17
18
  type PrepareTransactionRequestRequest,
18
19
  type StateOverride,
19
20
  type TransactionReceipt,
20
21
  type TransactionSerializable,
21
- createNonceManager,
22
22
  formatGwei,
23
23
  serializeTransaction,
24
24
  } from 'viem';
25
- import { jsonRpc } from 'viem/nonce';
26
25
 
27
26
  import type { ViemClient } from '../types.js';
28
27
  import { formatViemError } from '../utils.js';
29
28
  import { type L1TxUtilsConfig, l1TxUtilsConfigMappings } from './config.js';
30
- import { LARGE_GAS_LIMIT } from './constants.js';
29
+ import { MAX_L1_TX_LIMIT } from './constants.js';
31
30
  import type { IL1TxMetrics, IL1TxStore } from './interfaces.js';
32
31
  import { ReadOnlyL1TxUtils } from './readonly_l1_tx_utils.js';
32
+ import { Delayer, createDelayer, wrapClientWithDelayer } from './tx_delayer.js';
33
33
  import {
34
34
  DroppedTransactionError,
35
35
  type L1BlobInputs,
@@ -45,8 +45,15 @@ import {
45
45
  const MAX_L1_TX_STATES = 32;
46
46
 
47
47
  export class L1TxUtils extends ReadOnlyL1TxUtils {
48
- protected nonceManager: NonceManager;
49
48
  protected txs: L1TxState[] = [];
49
+ /** Last nonce successfully sent to the chain. Used as a lower bound when a fallback RPC node returns a stale count. */
50
+ private lastSentNonce: number | undefined;
51
+ /** Mutex to prevent concurrent sendTransaction calls from racing on the same nonce. */
52
+ private readonly sendMutex = new Semaphore(1);
53
+ /** Tx delayer for testing. Only set when enableDelayer config is true. */
54
+ public delayer?: Delayer;
55
+ /** KZG instance for blob operations. */
56
+ protected kzg?: BlobKzgInstance;
50
57
 
51
58
  constructor(
52
59
  public override client: ViemClient,
@@ -58,9 +65,25 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
58
65
  debugMaxGasLimit: boolean = false,
59
66
  protected store?: IL1TxStore,
60
67
  protected metrics?: IL1TxMetrics,
68
+ kzg?: BlobKzgInstance,
69
+ delayer?: Delayer,
61
70
  ) {
62
71
  super(client, logger, dateProvider, config, debugMaxGasLimit);
63
- this.nonceManager = createNonceManager({ source: jsonRpc() });
72
+ this.kzg = kzg;
73
+
74
+ // Set up delayer: use provided one or create new
75
+ if (config?.enableDelayer && config?.ethereumSlotDuration) {
76
+ this.delayer =
77
+ delayer ?? this.createDelayer({ ethereumSlotDuration: config.ethereumSlotDuration }, logger.getBindings());
78
+ this.client = wrapClientWithDelayer(this.client, this.delayer);
79
+ if (config.txDelayerMaxInclusionTimeIntoSlot !== undefined) {
80
+ this.delayer.setMaxInclusionTimeIntoSlot(config.txDelayerMaxInclusionTimeIntoSlot);
81
+ }
82
+ } else if (delayer) {
83
+ // Delayer provided but enableDelayer not set — just store it without wrapping
84
+ logger.warn('Delayer provided but enableDelayer config is not set; delayer will not be used');
85
+ this.delayer = delayer;
86
+ }
64
87
  }
65
88
 
66
89
  public get state() {
@@ -87,6 +110,11 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
87
110
  this.metrics?.recordMinedTx(l1TxState, new Date(l1Timestamp));
88
111
  } else if (newState === TxUtilsState.NOT_MINED) {
89
112
  this.metrics?.recordDroppedTx(l1TxState);
113
+ // The tx was dropped: the chain nonce reverted to l1TxState.nonce, so our lower bound is
114
+ // no longer valid. Clear it so the next send fetches the real nonce from the chain.
115
+ if (this.lastSentNonce === l1TxState.nonce) {
116
+ this.lastSentNonce = undefined;
117
+ }
90
118
  }
91
119
 
92
120
  // Update state in the store
@@ -130,12 +158,32 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
130
158
  return;
131
159
  }
132
160
 
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}`);
161
+ // Clean up excess states if we have more than MAX_L1_TX_STATES
162
+ if (loadedStates.length > MAX_L1_TX_STATES) {
163
+ this.logger.warn(
164
+ `Found ${loadedStates.length} tx states for account ${account}, pruning to most recent ${MAX_L1_TX_STATES}`,
165
+ );
166
+
167
+ // Keep only the most recent MAX_L1_TX_STATES
168
+ const statesToKeep = loadedStates.slice(-MAX_L1_TX_STATES);
169
+ const statesToDelete = loadedStates.slice(0, -MAX_L1_TX_STATES);
170
+
171
+ // Batch delete old states in a transaction for efficiency
172
+ const idsToDelete = statesToDelete.map(s => s.id);
173
+ await this.store.deleteState(account, ...idsToDelete);
174
+
175
+ this.txs = statesToKeep;
176
+ this.logger.info(
177
+ `Cleaned up ${statesToDelete.length} old tx states, kept ${statesToKeep.length} for account ${account}`,
178
+ );
179
+ } else {
180
+ // Convert loaded states (which have id) to the txs format
181
+ this.txs = loadedStates;
182
+ this.logger.info(`Rehydrated ${loadedStates.length} tx states for account ${account}`);
183
+ }
136
184
 
137
185
  // Find all pending states and resume monitoring
138
- const pendingStates = loadedStates.filter(state => !TerminalTxUtilsState.includes(state.status));
186
+ const pendingStates = this.txs.filter(state => !TerminalTxUtilsState.includes(state.status));
139
187
  if (pendingStates.length === 0) {
140
188
  return;
141
189
  }
@@ -187,7 +235,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
187
235
 
188
236
  let gasLimit: bigint;
189
237
  if (this.debugMaxGasLimit) {
190
- gasLimit = LARGE_GAS_LIMIT;
238
+ gasLimit = MAX_L1_TX_LIMIT;
191
239
  } else if (gasConfig.gasLimit) {
192
240
  gasLimit = gasConfig.gasLimit;
193
241
  } else {
@@ -201,15 +249,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
201
249
  throw new InterruptError(`Transaction sending is interrupted`);
202
250
  }
203
251
 
204
- const nonce = await this.nonceManager.consume({
205
- client: this.client,
206
- address: account,
207
- chainId: this.client.chain.id,
208
- });
209
-
210
- const baseState = { request, gasLimit, blobInputs, gasPrice, nonce };
211
- const txData = this.makeTxData(baseState, { isCancelTx: false });
212
-
213
252
  const now = new Date(await this.getL1Timestamp());
214
253
  if (gasConfig.txTimeoutAt && now > gasConfig.txTimeoutAt) {
215
254
  throw new TimeoutError(
@@ -217,14 +256,32 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
217
256
  );
218
257
  }
219
258
 
220
- // Send the new tx
221
- const signedRequest = await this.prepareSignedTransaction(txData);
222
- const txHash = await this.client.sendRawTransaction({ serializedTransaction: signedRequest });
259
+ let txHash: Hex;
260
+ let nonce: number;
261
+ let baseState: Pick<L1TxState, 'request' | 'gasLimit' | 'blobInputs' | 'gasPrice' | 'nonce'>;
262
+
263
+ await this.sendMutex.acquire();
264
+ try {
265
+ const chainNonce = await this.client.getTransactionCount({ address: account, blockTag: 'pending' });
266
+ // If a fallback RPC node returns a stale count (lower than what we last sent), use our
267
+ // local lower bound to avoid sending a duplicate of an already-pending transaction.
268
+ nonce =
269
+ this.lastSentNonce !== undefined && chainNonce <= this.lastSentNonce ? this.lastSentNonce + 1 : chainNonce;
270
+
271
+ baseState = { request, gasLimit, blobInputs, gasPrice, nonce };
272
+ const txData = this.makeTxData(baseState, { isCancelTx: false });
273
+
274
+ const signedRequest = await this.prepareSignedTransaction(txData);
275
+ txHash = await this.client.sendRawTransaction({ serializedTransaction: signedRequest });
276
+ this.lastSentNonce = nonce;
277
+ } finally {
278
+ this.sendMutex.release();
279
+ }
223
280
 
224
281
  // Create the new state for monitoring
225
282
  const l1TxState: L1TxState = {
226
283
  ...baseState,
227
- id: (await this.store?.consumeNextStateId(account)) ?? Math.max(...this.txs.map(tx => tx.id), 0),
284
+ id: (await this.store?.consumeNextStateId(account)) ?? Math.max(...this.txs.map(tx => tx.id), -1) + 1,
228
285
  txHashes: [txHash],
229
286
  cancelTxHashes: [],
230
287
  status: TxUtilsState.IDLE,
@@ -263,7 +320,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
263
320
  return { txHash, state: l1TxState };
264
321
  } catch (err: any) {
265
322
  const viemError = formatViemError(err, request.abi);
266
- this.logger.error(`Failed to send L1 transaction`, viemError, {
323
+ this.logger.error(`Failed to send L1 transaction: ${viemError.message}`, viemError, {
267
324
  request: pick(request, 'to', 'value'),
268
325
  });
269
326
  throw viemError;
@@ -403,7 +460,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
403
460
  { nonce, account, pendingNonce, timePassed },
404
461
  );
405
462
  await this.updateState(state, TxUtilsState.NOT_MINED);
406
- this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
407
463
  throw new DroppedTransactionError(nonce, account);
408
464
  }
409
465
 
@@ -495,12 +551,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
495
551
 
496
552
  // Oh no, the transaction has timed out!
497
553
  if (isCancelTx || !gasConfig.cancelTxOnTimeout) {
498
- // If this was already a cancellation tx, or we are configured to not cancel txs, we just mark it as NOT_MINED
499
- // and reset the nonce manager, so the next tx that comes along can reuse the nonce if/when this tx gets dropped.
500
- // This is the nastiest scenario for us, since the new tx could acquire the next nonce, but then this tx is dropped,
501
- // and the new tx would never get mined. Eventually, the new tx would also drop.
502
554
  await this.updateState(state, TxUtilsState.NOT_MINED);
503
- this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
504
555
  } else {
505
556
  // Otherwise we fire the cancellation without awaiting to avoid blocking the caller,
506
557
  // and monitor it in the background so we can speed it up as needed.
@@ -611,12 +662,12 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
611
662
  from: request.from ?? this.getSenderAddress().toString(),
612
663
  maxFeePerGas: gasPrice.maxFeePerGas,
613
664
  maxPriorityFeePerGas: gasPrice.maxPriorityFeePerGas,
614
- gas: request.gas ?? LARGE_GAS_LIMIT,
665
+ gas: request.gas ?? MAX_L1_TX_LIMIT,
615
666
  };
616
667
 
617
668
  if (!request.gas && !gasConfig.ignoreBlockGasLimit) {
618
- // LARGE_GAS_LIMIT is set as call.gas, increase block gasLimit
619
- blockOverrides.gasLimit = LARGE_GAS_LIMIT * 2n;
669
+ // MAX_L1_TX_LIMIT is set as call.gas, ensure block gasLimit is sufficient
670
+ blockOverrides.gasLimit = MAX_L1_TX_LIMIT;
620
671
  }
621
672
 
622
673
  return this._simulate(call, blockOverrides, stateOverrides, gasConfig, abi);
@@ -639,7 +690,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
639
690
  { nonce, account },
640
691
  );
641
692
  await this.updateState(state, TxUtilsState.NOT_MINED);
642
- this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
643
693
  return;
644
694
  }
645
695
 
@@ -651,7 +701,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
651
701
  { nonce, account, currentNonce },
652
702
  );
653
703
  await this.updateState(state, TxUtilsState.NOT_MINED);
654
- this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
655
704
  return;
656
705
  }
657
706
 
@@ -711,8 +760,17 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
711
760
  return Number(timestamp) * 1000;
712
761
  }
713
762
 
714
- /** Makes empty blob inputs for the cancellation tx. To be overridden in L1TxUtilsWithBlobs. */
715
- protected makeEmptyBlobInputs(_maxFeePerBlobGas: bigint): Required<L1BlobInputs> {
716
- throw new Error('Cannot make empty blob inputs for cancellation');
763
+ /** Makes empty blob inputs for the cancellation tx. */
764
+ protected makeEmptyBlobInputs(maxFeePerBlobGas: bigint): Required<L1BlobInputs> {
765
+ if (!this.kzg) {
766
+ throw new Error('Cannot make empty blob inputs for cancellation without kzg');
767
+ }
768
+ const blobData = new Uint8Array(131072).fill(0);
769
+ return { blobs: [blobData], kzg: this.kzg, maxFeePerBlobGas };
770
+ }
771
+
772
+ /** Creates a new delayer instance. */
773
+ protected createDelayer(opts: { ethereumSlotDuration: bigint | number }, bindings: LoggerBindings): Delayer {
774
+ return createDelayer(this.dateProvider, opts, bindings);
717
775
  }
718
776
  }
@@ -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,
@@ -25,15 +27,17 @@ import type { ViemClient } from '../types.js';
25
27
  import { type L1TxUtilsConfig, defaultL1TxUtilsConfig, l1TxUtilsConfigMappings } from './config.js';
26
28
  import {
27
29
  BLOCK_TIME_MS,
28
- LARGE_GAS_LIMIT,
30
+ MAX_L1_TX_LIMIT,
29
31
  MIN_BLOB_REPLACEMENT_BUMP_PERCENTAGE,
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,76 +84,56 @@ 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);
262
131
  for (let i = 0; i < numBlocks; i++) {
263
132
  // each block can go up 12.5% from previous baseFee
264
- maxFeePerGas = (maxFeePerGas * (1_000n + 125n)) / 1_000n;
133
+ // ceil, (a+b-1)/b, to avoid truncation at small values (e.g. 1 wei blob base fee)
134
+ maxFeePerGas = (maxFeePerGas * (1_000n + 125n) + 999n) / 1_000n;
265
135
  // same for blob gas fee
266
- maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n)) / 1_000n;
136
+ maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n) + 999n) / 1_000n;
267
137
  }
268
138
 
269
139
  if (attempt > 0) {
@@ -280,18 +150,15 @@ export class ReadOnlyL1TxUtils {
280
150
  (previousGasPrice!.maxPriorityFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
281
151
  const minMaxFee = (previousGasPrice!.maxFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
282
152
 
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;
153
+ // Apply bump percentage to competitive fee
154
+ const competitivePriorityFee = (priorityFee * (100_00n + BigInt(configBump * 1_00))) / 100_00n;
287
155
 
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
- }
156
+ this.logger?.debug(`Speed-up attempt ${attempt}: using competitive fee strategy`, {
157
+ networkEstimate: formatGwei(priorityFee),
158
+ competitiveFee: formatGwei(competitivePriorityFee),
159
+ minRequired: formatGwei(minPriorityFee),
160
+ bumpPercentage: configBump,
161
+ });
295
162
 
296
163
  // Use maximum between competitive fee and minimum required bump
297
164
  const finalPriorityFee = competitivePriorityFee > minPriorityFee ? competitivePriorityFee : minPriorityFee;
@@ -302,20 +169,16 @@ export class ReadOnlyL1TxUtils {
302
169
  maxFeePerGas += finalPriorityFee;
303
170
  maxFeePerGas = maxFeePerGas > minMaxFee ? maxFeePerGas : minMaxFee;
304
171
 
305
- if (!gasConfig.fixedPriorityFeePerGas) {
306
- this.logger?.debug(`Speed-up fee decision: using ${feeSource} fee`, {
307
- finalPriorityFee: formatGwei(finalPriorityFee),
308
- });
309
- }
172
+ this.logger?.debug(`Speed-up fee decision: using ${feeSource} fee`, {
173
+ finalPriorityFee: formatGwei(finalPriorityFee),
174
+ });
310
175
  } else {
311
176
  // First attempt: apply configured bump percentage to competitive fee
312
177
  // 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
- }
178
+ priorityFee = (priorityFee * (100_00n + BigInt((gasConfig.priorityFeeBumpPercentage || 0) * 1_00))) / 100_00n;
179
+ this.logger?.debug('Initial transaction: using competitive fee from market analysis', {
180
+ networkEstimate: formatGwei(priorityFee),
181
+ });
319
182
  maxFeePerGas += priorityFee;
320
183
  }
321
184
 
@@ -356,7 +219,7 @@ export class ReadOnlyL1TxUtils {
356
219
  baseFee: formatGwei(baseFee),
357
220
  maxFeePerGas: formatGwei(maxFeePerGas),
358
221
  maxPriorityFeePerGas: formatGwei(maxPriorityFeePerGas),
359
- blobBaseFee: formatGwei(blobBaseFee),
222
+ blobBaseFee: formatGwei(blobBaseFee ?? 0n),
360
223
  maxFeePerBlobGas: formatGwei(maxFeePerBlobGas),
361
224
  },
362
225
  );
@@ -380,19 +243,28 @@ export class ReadOnlyL1TxUtils {
380
243
  const gasConfig = { ...this.config, ..._gasConfig };
381
244
  let initialEstimate = 0n;
382
245
  if (_blobInputs) {
383
- // @note requests with blobs also require maxFeePerBlobGas to be set
246
+ // @note requests with blobs also require maxFeePerBlobGas to be set.
247
+ // Use 2x buffer for maxFeePerBlobGas to avoid stale fees and to pass EIP-4844 validation (even if it is a gas estimation call).
248
+ // 1. maxFeePerBlobGas >= blobBaseFee
249
+ // 2. account balance >= gas * maxFeePerGas + maxFeePerBlobGas * blobCount + value
384
250
  const gasPrice = await this.getGasPrice(gasConfig, true, 0);
385
251
  initialEstimate = await this.client.estimateGas({
386
252
  account,
387
253
  ...request,
388
254
  ..._blobInputs,
389
- maxFeePerBlobGas: gasPrice.maxFeePerBlobGas!,
390
- gas: LARGE_GAS_LIMIT,
255
+ maxFeePerBlobGas: gasPrice.maxFeePerBlobGas! * 2n,
256
+ gas: MAX_L1_TX_LIMIT,
257
+ blockTag: 'latest',
391
258
  });
392
259
 
393
260
  this.logger?.trace(`Estimated gas for blob tx: ${initialEstimate}`);
394
261
  } else {
395
- initialEstimate = await this.client.estimateGas({ account, ...request, gas: LARGE_GAS_LIMIT });
262
+ initialEstimate = await this.client.estimateGas({
263
+ account,
264
+ ...request,
265
+ gas: MAX_L1_TX_LIMIT,
266
+ blockTag: 'latest',
267
+ });
396
268
  this.logger?.trace(`Estimated gas for non-blob tx: ${initialEstimate}`);
397
269
  }
398
270
 
@@ -548,11 +420,4 @@ export class ReadOnlyL1TxUtils {
548
420
  });
549
421
  return bumpedGasLimit;
550
422
  }
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
423
  }