@aztec/ethereum 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0

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 (224) hide show
  1. package/dest/client.d.ts +25 -3
  2. package/dest/client.d.ts.map +1 -1
  3. package/dest/client.js +60 -4
  4. package/dest/config.d.ts +45 -73
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +114 -386
  7. package/dest/contracts/chain_state_override.d.ts +78 -0
  8. package/dest/contracts/chain_state_override.d.ts.map +1 -0
  9. package/dest/contracts/chain_state_override.js +137 -0
  10. package/dest/contracts/empire_base.d.ts +2 -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 +105 -0
  16. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  17. package/dest/contracts/fee_asset_price_oracle.js +656 -0
  18. package/dest/contracts/governance.d.ts +110 -33
  19. package/dest/contracts/governance.d.ts.map +1 -1
  20. package/dest/contracts/governance.js +207 -16
  21. package/dest/contracts/governance_proposer.d.ts +34 -1
  22. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  23. package/dest/contracts/governance_proposer.js +447 -10
  24. package/dest/contracts/gse.d.ts +4 -2
  25. package/dest/contracts/gse.d.ts.map +1 -1
  26. package/dest/contracts/gse.js +2 -2
  27. package/dest/contracts/inbox.d.ts +24 -3
  28. package/dest/contracts/inbox.d.ts.map +1 -1
  29. package/dest/contracts/inbox.js +42 -2
  30. package/dest/contracts/index.d.ts +6 -3
  31. package/dest/contracts/index.d.ts.map +1 -1
  32. package/dest/contracts/index.js +5 -2
  33. package/dest/contracts/log.d.ts +13 -0
  34. package/dest/contracts/log.d.ts.map +1 -0
  35. package/dest/contracts/log.js +1 -0
  36. package/dest/contracts/multicall.d.ts +130 -13
  37. package/dest/contracts/multicall.d.ts.map +1 -1
  38. package/dest/contracts/multicall.js +203 -93
  39. package/dest/contracts/outbox.d.ts +64 -0
  40. package/dest/contracts/outbox.d.ts.map +1 -0
  41. package/dest/contracts/outbox.js +113 -0
  42. package/dest/contracts/registry.d.ts +3 -1
  43. package/dest/contracts/registry.d.ts.map +1 -1
  44. package/dest/contracts/registry.js +30 -1
  45. package/dest/contracts/rollup.d.ts +5571 -102
  46. package/dest/contracts/rollup.d.ts.map +1 -1
  47. package/dest/contracts/rollup.js +1076 -192
  48. package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +5 -5
  49. package/dest/contracts/slashing_proposer.d.ts.map +1 -0
  50. package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +18 -13
  51. package/dest/deploy_aztec_l1_contracts.d.ts +267 -0
  52. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  53. package/dest/deploy_aztec_l1_contracts.js +424 -0
  54. package/dest/deploy_l1_contract.d.ts +68 -0
  55. package/dest/deploy_l1_contract.d.ts.map +1 -0
  56. package/dest/deploy_l1_contract.js +312 -0
  57. package/dest/forwarder_proxy.d.ts +32 -0
  58. package/dest/forwarder_proxy.d.ts.map +1 -0
  59. package/dest/forwarder_proxy.js +93 -0
  60. package/dest/foundry_binary.d.ts +13 -0
  61. package/dest/foundry_binary.d.ts.map +1 -0
  62. package/dest/foundry_binary.js +52 -0
  63. package/dest/l1_artifacts.d.ts +19674 -16606
  64. package/dest/l1_artifacts.d.ts.map +1 -1
  65. package/dest/l1_artifacts.js +9 -24
  66. package/dest/l1_contract_addresses.d.ts +61 -65
  67. package/dest/l1_contract_addresses.d.ts.map +1 -1
  68. package/dest/l1_contract_addresses.js +99 -80
  69. package/dest/l1_reader.d.ts +7 -5
  70. package/dest/l1_reader.d.ts.map +1 -1
  71. package/dest/l1_reader.js +15 -7
  72. package/dest/l1_tx_utils/config.d.ts +9 -3
  73. package/dest/l1_tx_utils/config.d.ts.map +1 -1
  74. package/dest/l1_tx_utils/config.js +34 -7
  75. package/dest/l1_tx_utils/constants.d.ts +8 -2
  76. package/dest/l1_tx_utils/constants.d.ts.map +1 -1
  77. package/dest/l1_tx_utils/constants.js +27 -2
  78. package/dest/l1_tx_utils/factory.d.ts +18 -10
  79. package/dest/l1_tx_utils/factory.d.ts.map +1 -1
  80. package/dest/l1_tx_utils/factory.js +17 -7
  81. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  82. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  83. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  84. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  85. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  86. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  87. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  88. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  89. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  90. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  91. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  92. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  93. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  94. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  95. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
  96. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  97. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  98. package/dest/l1_tx_utils/index-blobs.js +2 -0
  99. package/dest/l1_tx_utils/index.d.ts +4 -1
  100. package/dest/l1_tx_utils/index.d.ts.map +1 -1
  101. package/dest/l1_tx_utils/index.js +3 -0
  102. package/dest/l1_tx_utils/interfaces.d.ts +2 -2
  103. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -1
  104. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +252 -0
  105. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  106. package/dest/l1_tx_utils/l1_fee_analyzer.js +568 -0
  107. package/dest/l1_tx_utils/l1_tx_utils.d.ts +26 -7
  108. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
  109. package/dest/l1_tx_utils/l1_tx_utils.js +202 -92
  110. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +4 -15
  111. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  112. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +63 -165
  113. package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
  114. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  115. package/dest/{test → l1_tx_utils}/tx_delayer.js +70 -39
  116. package/dest/l1_tx_utils/types.d.ts +27 -1
  117. package/dest/l1_tx_utils/types.d.ts.map +1 -1
  118. package/dest/l1_tx_utils/types.js +10 -0
  119. package/dest/publisher_manager.d.ts +34 -7
  120. package/dest/publisher_manager.d.ts.map +1 -1
  121. package/dest/publisher_manager.js +119 -8
  122. package/dest/queries.d.ts +14 -3
  123. package/dest/queries.d.ts.map +1 -1
  124. package/dest/queries.js +80 -7
  125. package/dest/test/blob_kzg_warmup.d.ts +19 -0
  126. package/dest/test/blob_kzg_warmup.d.ts.map +1 -0
  127. package/dest/test/blob_kzg_warmup.js +64 -0
  128. package/dest/test/chain_monitor.d.ts +55 -4
  129. package/dest/test/chain_monitor.d.ts.map +1 -1
  130. package/dest/test/chain_monitor.js +105 -5
  131. package/dest/test/eth_cheat_codes.d.ts +49 -6
  132. package/dest/test/eth_cheat_codes.d.ts.map +1 -1
  133. package/dest/test/eth_cheat_codes.js +93 -43
  134. package/dest/test/index.d.ts +2 -3
  135. package/dest/test/index.d.ts.map +1 -1
  136. package/dest/test/index.js +1 -2
  137. package/dest/test/rollup_cheat_codes.d.ts +64 -4
  138. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  139. package/dest/test/rollup_cheat_codes.js +109 -8
  140. package/dest/test/start_anvil.d.ts +24 -2
  141. package/dest/test/start_anvil.d.ts.map +1 -1
  142. package/dest/test/start_anvil.js +182 -32
  143. package/dest/test/upgrade_utils.js +2 -2
  144. package/dest/types.d.ts +57 -2
  145. package/dest/types.d.ts.map +1 -1
  146. package/dest/utils.d.ts +24 -4
  147. package/dest/utils.d.ts.map +1 -1
  148. package/dest/utils.js +112 -16
  149. package/package.json +31 -15
  150. package/src/client.ts +66 -2
  151. package/src/config.ts +153 -469
  152. package/src/contracts/README.md +157 -0
  153. package/src/contracts/chain_state_override.ts +200 -0
  154. package/src/contracts/empire_base.ts +1 -1
  155. package/src/contracts/fee_asset_handler.ts +10 -7
  156. package/src/contracts/fee_asset_price_oracle.ts +285 -0
  157. package/src/contracts/governance.ts +279 -13
  158. package/src/contracts/governance_proposer.ts +64 -3
  159. package/src/contracts/gse.ts +7 -2
  160. package/src/contracts/inbox.ts +64 -4
  161. package/src/contracts/index.ts +5 -2
  162. package/src/contracts/log.ts +13 -0
  163. package/src/contracts/multicall.ts +247 -103
  164. package/src/contracts/outbox.ts +132 -0
  165. package/src/contracts/registry.ts +31 -1
  166. package/src/contracts/rollup.ts +789 -154
  167. package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +18 -14
  168. package/src/deploy_aztec_l1_contracts.ts +664 -0
  169. package/src/deploy_l1_contract.ts +362 -0
  170. package/src/forwarder_proxy.ts +108 -0
  171. package/src/foundry_binary.ts +57 -0
  172. package/src/l1_artifacts.ts +12 -35
  173. package/src/l1_contract_addresses.ts +120 -92
  174. package/src/l1_reader.ts +25 -10
  175. package/src/l1_tx_utils/config.ts +47 -9
  176. package/src/l1_tx_utils/constants.ts +13 -2
  177. package/src/l1_tx_utils/factory.ts +31 -31
  178. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  179. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
  180. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
  181. package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
  182. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +108 -0
  183. package/src/l1_tx_utils/index-blobs.ts +2 -0
  184. package/src/l1_tx_utils/index.ts +3 -0
  185. package/src/l1_tx_utils/interfaces.ts +1 -1
  186. package/src/l1_tx_utils/l1_fee_analyzer.ts +875 -0
  187. package/src/l1_tx_utils/l1_tx_utils.ts +194 -72
  188. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +77 -211
  189. package/src/{test → l1_tx_utils}/tx_delayer.ts +97 -58
  190. package/src/l1_tx_utils/types.ts +32 -0
  191. package/src/publisher_manager.ts +145 -12
  192. package/src/queries.ts +87 -7
  193. package/src/test/blob_kzg_warmup.ts +65 -0
  194. package/src/test/chain_monitor.ts +150 -4
  195. package/src/test/eth_cheat_codes.ts +84 -47
  196. package/src/test/index.ts +1 -2
  197. package/src/test/rollup_cheat_codes.ts +136 -8
  198. package/src/test/start_anvil.ts +213 -31
  199. package/src/test/upgrade_utils.ts +2 -2
  200. package/src/types.ts +62 -0
  201. package/src/utils.ts +128 -19
  202. package/dest/contracts/empire_slashing_proposer.d.ts +0 -66
  203. package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
  204. package/dest/contracts/empire_slashing_proposer.js +0 -200
  205. package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
  206. package/dest/deploy_l1_contracts.d.ts +0 -673
  207. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  208. package/dest/deploy_l1_contracts.js +0 -1491
  209. package/dest/index.d.ts +0 -18
  210. package/dest/index.d.ts.map +0 -1
  211. package/dest/index.js +0 -17
  212. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +0 -26
  213. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +0 -1
  214. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +0 -26
  215. package/dest/test/delayed_tx_utils.d.ts +0 -13
  216. package/dest/test/delayed_tx_utils.d.ts.map +0 -1
  217. package/dest/test/delayed_tx_utils.js +0 -28
  218. package/dest/test/tx_delayer.d.ts +0 -36
  219. package/dest/test/tx_delayer.d.ts.map +0 -1
  220. package/src/contracts/empire_slashing_proposer.ts +0 -265
  221. package/src/deploy_l1_contracts.ts +0 -1869
  222. package/src/index.ts +0 -17
  223. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
  224. package/src/test/delayed_tx_utils.ts +0 -52
@@ -1,7 +1,9 @@
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';
6
+ import { getErrorCause } from '@aztec/foundation/types';
5
7
  import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
6
8
 
7
9
  import pickBy from 'lodash.pickby';
@@ -11,6 +13,7 @@ import {
11
13
  type BaseError,
12
14
  type BlockOverrides,
13
15
  type ContractFunctionExecutionError,
16
+ type GetCodeReturnType,
14
17
  type Hex,
15
18
  MethodNotFoundRpcError,
16
19
  MethodNotSupportedRpcError,
@@ -25,15 +28,17 @@ import type { ViemClient } from '../types.js';
25
28
  import { type L1TxUtilsConfig, defaultL1TxUtilsConfig, l1TxUtilsConfigMappings } from './config.js';
26
29
  import {
27
30
  BLOCK_TIME_MS,
28
- LARGE_GAS_LIMIT,
31
+ MAX_L1_TX_LIMIT,
29
32
  MIN_BLOB_REPLACEMENT_BUMP_PERCENTAGE,
30
33
  MIN_REPLACEMENT_BUMP_PERCENTAGE,
31
34
  WEI_CONST,
32
35
  } from './constants.js';
36
+ import { P75AllTxsPriorityFeeStrategy, type PriorityFeeStrategy } from './fee-strategies/index.js';
33
37
  import type { GasPrice, L1BlobInputs, L1TxRequest, TransactionStats } from './types.js';
34
38
  import { getCalldataGasUsage, tryGetCustomErrorNameContractFunction } from './utils.js';
35
39
 
36
- const HISTORICAL_BLOCK_COUNT = 5;
40
+ // Change this to the current strategy we want to use
41
+ const CurrentStrategy: PriorityFeeStrategy = P75AllTxsPriorityFeeStrategy;
37
42
 
38
43
  export class ReadOnlyL1TxUtils {
39
44
  public config: Required<L1TxUtilsConfig>;
@@ -65,122 +70,8 @@ export class ReadOnlyL1TxUtils {
65
70
  return this.client.getBlockNumber();
66
71
  }
67
72
 
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;
73
+ public getCode(address: EthAddress): Promise<GetCodeReturnType> {
74
+ return this.client.getCode({ address: address.toString() });
184
75
  }
185
76
 
186
77
  /**
@@ -194,76 +85,56 @@ export class ReadOnlyL1TxUtils {
194
85
  ): Promise<GasPrice> {
195
86
  const gasConfig = merge(this.config, gasConfigOverrides);
196
87
 
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',
88
+ // Execute strategy - it handles all RPC calls internally and returns everything we need
89
+ const strategyResult = await retry(
90
+ () =>
91
+ CurrentStrategy.execute(this.client, {
92
+ gasConfig,
93
+ isBlobTx,
94
+ logger: this.logger,
95
+ }),
96
+ 'Executing priority fee strategy',
97
+ makeBackoff(times(2, () => 0)),
98
+ this.logger,
99
+ true,
201
100
  );
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) {
101
+
102
+ const { latestBlock, blobBaseFee, priorityFee: strategyPriorityFee } = strategyResult;
103
+
104
+ // Extract base fee from latest block
105
+ const baseFee = latestBlock.baseFeePerGas ?? 0n;
106
+
107
+ // Handle blob base fee
108
+ if (isBlobTx && blobBaseFee === undefined) {
243
109
  this.logger?.warn('Failed to get L1 blob base fee', attempt);
244
110
  }
245
111
 
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);
112
+ let priorityFee = strategyPriorityFee;
113
+
114
+ // Apply minimum priority fee floor if configured
115
+ if (gasConfig.minimumPriorityFeePerGas) {
116
+ const minimumPriorityFee = BigInt(Math.trunc(gasConfig.minimumPriorityFeePerGas * Number(WEI_CONST)));
117
+ if (priorityFee < minimumPriorityFee) {
118
+ this.logger?.debug('Applying minimum priority fee floor', {
119
+ calculatedPriorityFee: formatGwei(priorityFee),
120
+ minimumPriorityFeePerGas: gasConfig.minimumPriorityFeePerGas,
121
+ appliedFee: formatGwei(minimumPriorityFee),
122
+ });
123
+ priorityFee = minimumPriorityFee;
124
+ }
255
125
  }
256
126
  let maxFeePerGas = baseFee;
257
127
 
258
- let maxFeePerBlobGas = blobBaseFee;
128
+ let maxFeePerBlobGas = blobBaseFee ?? 0n;
259
129
 
260
130
  // Bump base fee so it's valid for next blocks if it stalls
261
131
  const numBlocks = Math.ceil(gasConfig.stallTimeMs! / BLOCK_TIME_MS);
262
132
  for (let i = 0; i < numBlocks; i++) {
263
133
  // each block can go up 12.5% from previous baseFee
264
- maxFeePerGas = (maxFeePerGas * (1_000n + 125n)) / 1_000n;
134
+ // ceil, (a+b-1)/b, to avoid truncation at small values (e.g. 1 wei blob base fee)
135
+ maxFeePerGas = (maxFeePerGas * (1_000n + 125n) + 999n) / 1_000n;
265
136
  // same for blob gas fee
266
- maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n)) / 1_000n;
137
+ maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n) + 999n) / 1_000n;
267
138
  }
268
139
 
269
140
  if (attempt > 0) {
@@ -280,18 +151,15 @@ export class ReadOnlyL1TxUtils {
280
151
  (previousGasPrice!.maxPriorityFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
281
152
  const minMaxFee = (previousGasPrice!.maxFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
282
153
 
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;
154
+ // Apply bump percentage to competitive fee
155
+ const competitivePriorityFee = (priorityFee * (100_00n + BigInt(configBump * 1_00))) / 100_00n;
287
156
 
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
- }
157
+ this.logger?.debug(`Speed-up attempt ${attempt}: using competitive fee strategy`, {
158
+ networkEstimate: formatGwei(priorityFee),
159
+ competitiveFee: formatGwei(competitivePriorityFee),
160
+ minRequired: formatGwei(minPriorityFee),
161
+ bumpPercentage: configBump,
162
+ });
295
163
 
296
164
  // Use maximum between competitive fee and minimum required bump
297
165
  const finalPriorityFee = competitivePriorityFee > minPriorityFee ? competitivePriorityFee : minPriorityFee;
@@ -302,20 +170,16 @@ export class ReadOnlyL1TxUtils {
302
170
  maxFeePerGas += finalPriorityFee;
303
171
  maxFeePerGas = maxFeePerGas > minMaxFee ? maxFeePerGas : minMaxFee;
304
172
 
305
- if (!gasConfig.fixedPriorityFeePerGas) {
306
- this.logger?.debug(`Speed-up fee decision: using ${feeSource} fee`, {
307
- finalPriorityFee: formatGwei(finalPriorityFee),
308
- });
309
- }
173
+ this.logger?.debug(`Speed-up fee decision: using ${feeSource} fee`, {
174
+ finalPriorityFee: formatGwei(finalPriorityFee),
175
+ });
310
176
  } else {
311
177
  // First attempt: apply configured bump percentage to competitive fee
312
178
  // 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
- }
179
+ priorityFee = (priorityFee * (100_00n + BigInt((gasConfig.priorityFeeBumpPercentage || 0) * 1_00))) / 100_00n;
180
+ this.logger?.debug('Initial transaction: using competitive fee from market analysis', {
181
+ networkEstimate: formatGwei(priorityFee),
182
+ });
319
183
  maxFeePerGas += priorityFee;
320
184
  }
321
185
 
@@ -356,7 +220,7 @@ export class ReadOnlyL1TxUtils {
356
220
  baseFee: formatGwei(baseFee),
357
221
  maxFeePerGas: formatGwei(maxFeePerGas),
358
222
  maxPriorityFeePerGas: formatGwei(maxPriorityFeePerGas),
359
- blobBaseFee: formatGwei(blobBaseFee),
223
+ blobBaseFee: formatGwei(blobBaseFee ?? 0n),
360
224
  maxFeePerBlobGas: formatGwei(maxFeePerBlobGas),
361
225
  },
362
226
  );
@@ -380,19 +244,28 @@ export class ReadOnlyL1TxUtils {
380
244
  const gasConfig = { ...this.config, ..._gasConfig };
381
245
  let initialEstimate = 0n;
382
246
  if (_blobInputs) {
383
- // @note requests with blobs also require maxFeePerBlobGas to be set
247
+ // @note requests with blobs also require maxFeePerBlobGas to be set.
248
+ // Use 2x buffer for maxFeePerBlobGas to avoid stale fees and to pass EIP-4844 validation (even if it is a gas estimation call).
249
+ // 1. maxFeePerBlobGas >= blobBaseFee
250
+ // 2. account balance >= gas * maxFeePerGas + maxFeePerBlobGas * blobCount + value
384
251
  const gasPrice = await this.getGasPrice(gasConfig, true, 0);
385
252
  initialEstimate = await this.client.estimateGas({
386
253
  account,
387
254
  ...request,
388
255
  ..._blobInputs,
389
- maxFeePerBlobGas: gasPrice.maxFeePerBlobGas!,
390
- gas: LARGE_GAS_LIMIT,
256
+ maxFeePerBlobGas: gasPrice.maxFeePerBlobGas! * 2n,
257
+ gas: MAX_L1_TX_LIMIT,
258
+ blockTag: 'latest',
391
259
  });
392
260
 
393
261
  this.logger?.trace(`Estimated gas for blob tx: ${initialEstimate}`);
394
262
  } else {
395
- initialEstimate = await this.client.estimateGas({ account, ...request, gas: LARGE_GAS_LIMIT });
263
+ initialEstimate = await this.client.estimateGas({
264
+ account,
265
+ ...request,
266
+ gas: MAX_L1_TX_LIMIT,
267
+ blockTag: 'latest',
268
+ });
396
269
  this.logger?.trace(`Estimated gas for non-blob tx: ${initialEstimate}`);
397
270
  }
398
271
 
@@ -523,7 +396,7 @@ export class ReadOnlyL1TxUtils {
523
396
  this.logger?.debug(`L1 transaction simulation succeeded`, { ...result[0].calls[0] });
524
397
  return { gasUsed: result[0].gasUsed, result: result[0].calls[0].data as `0x${string}` };
525
398
  } catch (err) {
526
- if (err instanceof MethodNotFoundRpcError || err instanceof MethodNotSupportedRpcError) {
399
+ if (getErrorCause(err, MethodNotFoundRpcError) || getErrorCause(err, MethodNotSupportedRpcError)) {
527
400
  if (gasConfig.fallbackGasEstimate) {
528
401
  this.logger?.warn(
529
402
  `Node does not support eth_simulateV1 API. Using fallback gas estimate: ${gasConfig.fallbackGasEstimate}`,
@@ -548,11 +421,4 @@ export class ReadOnlyL1TxUtils {
548
421
  });
549
422
  return bumpedGasLimit;
550
423
  }
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
424
  }
@@ -1,5 +1,5 @@
1
1
  import { omit } from '@aztec/foundation/collection';
2
- import { type Logger, createLogger } from '@aztec/foundation/log';
2
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
3
  import { retryUntil } from '@aztec/foundation/retry';
4
4
  import type { DateProvider } from '@aztec/foundation/timer';
5
5
 
@@ -9,14 +9,18 @@ import {
9
9
  type Hex,
10
10
  type PublicClient,
11
11
  type TransactionSerializableEIP4844,
12
+ type TransactionSerialized,
12
13
  keccak256,
13
14
  parseTransaction,
14
15
  publicActions,
16
+ recoverTransactionAddress,
15
17
  serializeTransaction,
16
18
  walletActions,
17
19
  } from 'viem';
18
20
 
19
- import { type ViemClient, isExtendedClient } from '../types.js';
21
+ import type { ExtendedViemWalletClient, ViemClient } from '../types.js';
22
+
23
+ const MAX_WAIT_TIME_SECONDS = 180;
20
24
 
21
25
  export function waitUntilBlock<T extends Client>(
22
26
  client: T,
@@ -36,7 +40,7 @@ export function waitUntilBlock<T extends Client>(
36
40
  return currentBlockNumber >= BigInt(blockNumber);
37
41
  },
38
42
  `Wait until L1 block ${blockNumber}`,
39
- timeout ?? 120,
43
+ timeout ?? MAX_WAIT_TIME_SECONDS,
40
44
  0.1,
41
45
  );
42
46
  }
@@ -66,87 +70,107 @@ export function waitUntilL1Timestamp<T extends Client>(
66
70
  return currentTs >= BigInt(timestamp);
67
71
  },
68
72
  `Wait until L1 timestamp ${timestamp}`,
69
- timeout ?? 120,
73
+ timeout ?? MAX_WAIT_TIME_SECONDS,
70
74
  0.1,
71
75
  );
72
76
  }
73
77
 
74
- export interface Delayer {
75
- /** Returns the hashes of all effectively sent txs. */
76
- getSentTxHashes(): Hex[];
77
- /** Returns the raw hex for all cancelled txs. */
78
- getCancelledTxs(): Hex[];
79
- /** Delays the next tx to be sent so it lands on the given L1 block number. */
80
- pauseNextTxUntilBlock(l1BlockNumber: number | bigint | undefined): void;
81
- /** Delays the next tx to be sent so it lands on the given timestamp. */
82
- pauseNextTxUntilTimestamp(l1Timestamp: number | bigint | undefined): void;
83
- /** Delays the next tx to be sent indefinitely. */
84
- cancelNextTx(): void;
85
- /**
86
- * Sets max inclusion time into slot. If more than this many seconds have passed
87
- * since the last L1 block was mined, then any tx will not be mined in the current
88
- * L1 slot but will be deferred for the next one.
89
- */
90
- setMaxInclusionTimeIntoSlot(seconds: number | bigint | undefined): void;
91
- }
78
+ /** Manages tx delaying for testing, intercepting sendRawTransaction calls to delay or cancel them. */
79
+ export class Delayer {
80
+ private logger: Logger;
81
+
82
+ public maxInclusionTimeIntoSlot: number | undefined = undefined;
83
+ public ethereumSlotDuration: bigint;
84
+ public nextWait:
85
+ | { l1Timestamp: bigint; timeoutSeconds?: number }
86
+ | { l1BlockNumber: bigint; timeoutSeconds?: number }
87
+ | { indefinitely: true }
88
+ | undefined = undefined;
89
+ public sentTxHashes: Hex[] = [];
90
+ public cancelledTxs: Hex[] = [];
92
91
 
93
- class DelayerImpl implements Delayer {
94
- private logger = createLogger('ethereum:tx_delayer');
95
92
  constructor(
96
93
  public dateProvider: DateProvider,
97
94
  opts: { ethereumSlotDuration: bigint | number },
95
+ bindings: LoggerBindings,
98
96
  ) {
99
97
  this.ethereumSlotDuration = BigInt(opts.ethereumSlotDuration);
98
+ this.logger = createLogger('ethereum:tx_delayer', bindings);
100
99
  }
101
100
 
102
- public maxInclusionTimeIntoSlot: number | undefined = undefined;
103
- public ethereumSlotDuration: bigint;
104
- public nextWait: { l1Timestamp: bigint } | { l1BlockNumber: bigint } | { indefinitely: true } | undefined = undefined;
105
- public sentTxHashes: Hex[] = [];
106
- public cancelledTxs: Hex[] = [];
101
+ /** Returns the logger instance used by this delayer. */
102
+ getLogger(): Logger {
103
+ return this.logger;
104
+ }
107
105
 
106
+ /** Returns the hashes of all effectively sent txs. */
108
107
  getSentTxHashes() {
109
108
  return this.sentTxHashes;
110
109
  }
111
110
 
111
+ /** Returns the raw hex for all cancelled txs. */
112
112
  getCancelledTxs(): Hex[] {
113
113
  return this.cancelledTxs;
114
114
  }
115
115
 
116
- pauseNextTxUntilBlock(l1BlockNumber: number | bigint) {
117
- this.nextWait = { l1BlockNumber: BigInt(l1BlockNumber) };
116
+ /** Delays the next tx to be sent so it lands on the given L1 block number. */
117
+ pauseNextTxUntilBlock(l1BlockNumber: number | bigint, timeoutSeconds?: number) {
118
+ this.nextWait = { l1BlockNumber: BigInt(l1BlockNumber), timeoutSeconds };
118
119
  }
119
120
 
120
- pauseNextTxUntilTimestamp(l1Timestamp: number | bigint) {
121
- this.nextWait = { l1Timestamp: BigInt(l1Timestamp) };
121
+ /** Delays the next tx to be sent so it lands on the given timestamp. */
122
+ pauseNextTxUntilTimestamp(l1Timestamp: number | bigint, timeoutSeconds?: number) {
123
+ this.nextWait = { l1Timestamp: BigInt(l1Timestamp), timeoutSeconds };
122
124
  }
123
125
 
126
+ /** Delays the next tx to be sent indefinitely. */
124
127
  cancelNextTx() {
125
128
  this.nextWait = { indefinitely: true };
126
129
  }
127
130
 
131
+ /**
132
+ * Sets max inclusion time into slot. If more than this many seconds have passed
133
+ * since the last L1 block was mined, then any tx will not be mined in the current
134
+ * L1 slot but will be deferred for the next one.
135
+ */
128
136
  setMaxInclusionTimeIntoSlot(seconds: number | undefined) {
129
137
  this.maxInclusionTimeIntoSlot = seconds;
130
138
  }
131
139
  }
132
140
 
133
141
  /**
134
- * Returns a new client (without modifying the one passed in) with an injected tx delayer.
135
- * The delayer can be used to hold off the next tx to be sent until a given block number.
136
- * TODO(#10824): This doesn't play along well with blob txs for some reason.
142
+ * Creates a new Delayer instance. Exposed so callers can create a single shared delayer
143
+ * and pass it to multiple `wrapClientWithDelayer` calls.
137
144
  */
138
- export function withDelayer<T extends ViemClient>(
139
- client: T,
145
+ export function createDelayer(
140
146
  dateProvider: DateProvider,
141
147
  opts: { ethereumSlotDuration: bigint | number },
142
- ): { client: T; delayer: Delayer } {
143
- if (!isExtendedClient(client)) {
144
- throw new Error('withDelayer has to be instantiated with a wallet viem client.');
148
+ bindings: LoggerBindings,
149
+ ): Delayer {
150
+ return new Delayer(dateProvider, opts, bindings);
151
+ }
152
+
153
+ /** Tries to recover the sender address from a serialized signed transaction. */
154
+ async function tryRecoverSender(serializedTransaction: Hex): Promise<string | undefined> {
155
+ try {
156
+ return await recoverTransactionAddress({
157
+ serializedTransaction: serializedTransaction as TransactionSerialized,
158
+ });
159
+ } catch {
160
+ return undefined;
145
161
  }
146
- const logger = createLogger('ethereum:tx_delayer');
147
- const delayer = new DelayerImpl(dateProvider, opts);
162
+ }
148
163
 
149
- const extended = client
164
+ /**
165
+ * Wraps a viem client with tx delaying logic. Returns the wrapped client.
166
+ * The delayer intercepts sendRawTransaction calls and delays them based on the delayer's state.
167
+ */
168
+ export function wrapClientWithDelayer<T extends ViemClient>(client: T, delayer: Delayer): T {
169
+ const logger = delayer.getLogger();
170
+
171
+ // Cast to ExtendedViemWalletClient for the extend chain since it has sendRawTransaction.
172
+ // The sendRawTransaction override is applied to all clients regardless of type.
173
+ const withRawTx = (client as unknown as ExtendedViemWalletClient)
150
174
  // Tweak sendRawTransaction so it uses the delay defined in the delayer.
151
175
  // Note that this will only work with local accounts (ie accounts for which we have the private key).
152
176
  // Transactions signed by the node will not be delayed since they use sendTransaction directly,
@@ -158,6 +182,7 @@ export function withDelayer<T extends ViemClient>(
158
182
 
159
183
  const { serializedTransaction } = args[0];
160
184
  const publicClient = client as unknown as PublicClient;
185
+ const sender = await tryRecoverSender(serializedTransaction);
161
186
 
162
187
  if (delayer.nextWait !== undefined) {
163
188
  // Check if we have been instructed to delay the next tx.
@@ -169,7 +194,7 @@ export function withDelayer<T extends ViemClient>(
169
194
 
170
195
  // Cancel tx outright if instructed
171
196
  if ('indefinitely' in waitUntil && waitUntil.indefinitely) {
172
- logger.info(`Cancelling tx ${txHash}`);
197
+ logger.info(`Cancelling tx ${txHash}`, { sender });
173
198
  delayer.cancelledTxs.push(serializedTransaction);
174
199
  return Promise.resolve(txHash);
175
200
  }
@@ -177,12 +202,18 @@ export function withDelayer<T extends ViemClient>(
177
202
  // Or wait until the desired block number or timestamp
178
203
  wait =
179
204
  'l1BlockNumber' in waitUntil
180
- ? waitUntilBlock(publicClient, waitUntil.l1BlockNumber - 1n, logger)
205
+ ? waitUntilBlock(publicClient, waitUntil.l1BlockNumber - 1n, logger, waitUntil.timeoutSeconds)
181
206
  : 'l1Timestamp' in waitUntil
182
- ? waitUntilL1Timestamp(publicClient, waitUntil.l1Timestamp - delayer.ethereumSlotDuration, logger)
207
+ ? waitUntilL1Timestamp(
208
+ publicClient,
209
+ waitUntil.l1Timestamp - delayer.ethereumSlotDuration,
210
+ logger,
211
+ waitUntil.timeoutSeconds,
212
+ )
183
213
  : undefined;
184
214
 
185
215
  logger.info(`Delaying tx ${txHash} until ${inspect(waitUntil)}`, {
216
+ sender,
186
217
  argsLen: args.length,
187
218
  ...omit(parseTransaction(serializedTransaction), 'data', 'sidecars'),
188
219
  });
@@ -194,6 +225,7 @@ export function withDelayer<T extends ViemClient>(
194
225
 
195
226
  txHash = computeTxHash(serializedTransaction);
196
227
  const logData = {
228
+ sender,
197
229
  ...omit(parseTransaction(serializedTransaction), 'data', 'sidecars'),
198
230
  lastBlockTimestamp,
199
231
  now,
@@ -223,28 +255,35 @@ export function withDelayer<T extends ViemClient>(
223
255
  computedTxHash: txHash,
224
256
  });
225
257
  }
226
- logger.info(`Sent previously delayed tx ${clientTxHash}`);
258
+ logger.info(`Sent previously delayed tx ${clientTxHash}`, { sender });
227
259
  delayer.sentTxHashes.push(clientTxHash);
228
260
  })
229
261
  .catch(err => logger.error(`Error sending tx after delay`, err));
230
262
  return Promise.resolve(txHash!);
231
263
  } else {
232
264
  const txHash = await client.sendRawTransaction(...args);
233
- logger.verbose(`Sent tx immediately ${txHash}`);
265
+ logger.debug(`Sent tx immediately ${txHash}`, { sender });
234
266
  delayer.sentTxHashes.push(txHash);
235
267
  return txHash;
236
268
  }
237
269
  },
238
- }))
239
- // Re-extend with sendTransaction so it uses the modified sendRawTransaction.
240
- .extend(client => ({ sendTransaction: walletActions(client).sendTransaction }))
241
- // And with the actions that depend on the modified sendTransaction
242
- .extend(client => ({
243
- writeContract: walletActions(client).writeContract,
244
- deployContract: walletActions(client).deployContract,
245
- })) as T;
270
+ }));
271
+
272
+ // Only re-bind wallet actions (sendTransaction, writeContract, deployContract) for wallet clients.
273
+ // This is needed for tests that use wallet actions directly rather than sendRawTransaction.
274
+ const isWalletClient = 'account' in client && client.account !== undefined;
275
+ const extended = isWalletClient
276
+ ? withRawTx
277
+ // Re-extend with sendTransaction so it uses the modified sendRawTransaction.
278
+ .extend(client => ({ sendTransaction: walletActions(client).sendTransaction }))
279
+ // And with the actions that depend on the modified sendTransaction
280
+ .extend(client => ({
281
+ writeContract: walletActions(client).writeContract,
282
+ deployContract: walletActions(client).deployContract,
283
+ }))
284
+ : withRawTx;
246
285
 
247
- return { client: extended, delayer };
286
+ return extended as T;
248
287
  }
249
288
 
250
289
  /**