@aztec/ethereum 0.0.1-commit.b655e406 → 0.0.1-commit.b9865e97

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 (236) hide show
  1. package/dest/account.d.ts +1 -1
  2. package/dest/chain.d.ts +1 -1
  3. package/dest/client.d.ts +25 -3
  4. package/dest/client.d.ts.map +1 -1
  5. package/dest/client.js +60 -4
  6. package/dest/config.d.ts +29 -73
  7. package/dest/config.d.ts.map +1 -1
  8. package/dest/config.js +70 -387
  9. package/dest/constants.d.ts +1 -1
  10. package/dest/contracts/chain_state_override.d.ts +78 -0
  11. package/dest/contracts/chain_state_override.d.ts.map +1 -0
  12. package/dest/contracts/chain_state_override.js +137 -0
  13. package/dest/contracts/empire_base.d.ts +7 -5
  14. package/dest/contracts/empire_base.d.ts.map +1 -1
  15. package/dest/contracts/empire_base.js +1 -1
  16. package/dest/contracts/errors.d.ts +1 -1
  17. package/dest/contracts/errors.d.ts.map +1 -1
  18. package/dest/contracts/fee_asset_handler.d.ts +6 -5
  19. package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
  20. package/dest/contracts/fee_asset_handler.js +11 -9
  21. package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
  22. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  23. package/dest/contracts/fee_asset_price_oracle.js +656 -0
  24. package/dest/contracts/fee_juice.d.ts +1 -1
  25. package/dest/contracts/fee_juice.d.ts.map +1 -1
  26. package/dest/contracts/governance.d.ts +113 -36
  27. package/dest/contracts/governance.d.ts.map +1 -1
  28. package/dest/contracts/governance.js +207 -16
  29. package/dest/contracts/governance_proposer.d.ts +38 -4
  30. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  31. package/dest/contracts/governance_proposer.js +455 -12
  32. package/dest/contracts/gse.d.ts +1 -1
  33. package/dest/contracts/gse.d.ts.map +1 -1
  34. package/dest/contracts/inbox.d.ts +24 -3
  35. package/dest/contracts/inbox.d.ts.map +1 -1
  36. package/dest/contracts/inbox.js +42 -2
  37. package/dest/contracts/index.d.ts +6 -3
  38. package/dest/contracts/index.d.ts.map +1 -1
  39. package/dest/contracts/index.js +5 -2
  40. package/dest/contracts/log.d.ts +13 -0
  41. package/dest/contracts/log.d.ts.map +1 -0
  42. package/dest/contracts/log.js +1 -0
  43. package/dest/contracts/multicall.d.ts +127 -12
  44. package/dest/contracts/multicall.d.ts.map +1 -1
  45. package/dest/contracts/multicall.js +201 -93
  46. package/dest/contracts/outbox.d.ts +64 -0
  47. package/dest/contracts/outbox.d.ts.map +1 -0
  48. package/dest/contracts/outbox.js +113 -0
  49. package/dest/contracts/registry.d.ts +3 -1
  50. package/dest/contracts/registry.d.ts.map +1 -1
  51. package/dest/contracts/registry.js +30 -1
  52. package/dest/contracts/rollup.d.ts +5432 -131
  53. package/dest/contracts/rollup.d.ts.map +1 -1
  54. package/dest/contracts/rollup.js +1114 -231
  55. package/dest/contracts/slasher_contract.d.ts +1 -1
  56. package/dest/contracts/slasher_contract.d.ts.map +1 -1
  57. package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +11 -10
  58. package/dest/contracts/slashing_proposer.d.ts.map +1 -0
  59. package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +21 -16
  60. package/dest/contracts/utils.d.ts +1 -1
  61. package/dest/deploy_aztec_l1_contracts.d.ts +257 -0
  62. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  63. package/dest/deploy_aztec_l1_contracts.js +410 -0
  64. package/dest/deploy_l1_contract.d.ts +68 -0
  65. package/dest/deploy_l1_contract.d.ts.map +1 -0
  66. package/dest/deploy_l1_contract.js +312 -0
  67. package/dest/eth-signer/eth-signer.d.ts +1 -1
  68. package/dest/eth-signer/index.d.ts +1 -1
  69. package/dest/forwarder_proxy.d.ts +32 -0
  70. package/dest/forwarder_proxy.d.ts.map +1 -0
  71. package/dest/forwarder_proxy.js +93 -0
  72. package/dest/generated/l1-contracts-defaults.d.ts +30 -0
  73. package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
  74. package/dest/generated/l1-contracts-defaults.js +30 -0
  75. package/dest/l1_artifacts.d.ts +19816 -16730
  76. package/dest/l1_artifacts.d.ts.map +1 -1
  77. package/dest/l1_artifacts.js +9 -24
  78. package/dest/l1_contract_addresses.d.ts +61 -65
  79. package/dest/l1_contract_addresses.d.ts.map +1 -1
  80. package/dest/l1_contract_addresses.js +99 -80
  81. package/dest/l1_reader.d.ts +7 -5
  82. package/dest/l1_reader.d.ts.map +1 -1
  83. package/dest/l1_reader.js +15 -7
  84. package/dest/l1_tx_utils/config.d.ts +11 -5
  85. package/dest/l1_tx_utils/config.d.ts.map +1 -1
  86. package/dest/l1_tx_utils/config.js +43 -7
  87. package/dest/l1_tx_utils/constants.d.ts +8 -2
  88. package/dest/l1_tx_utils/constants.d.ts.map +1 -1
  89. package/dest/l1_tx_utils/constants.js +27 -2
  90. package/dest/l1_tx_utils/factory.d.ts +18 -10
  91. package/dest/l1_tx_utils/factory.d.ts.map +1 -1
  92. package/dest/l1_tx_utils/factory.js +17 -7
  93. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  94. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  95. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  96. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  97. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  98. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  99. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  100. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  101. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  102. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  103. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  104. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  105. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  106. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  107. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
  108. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  109. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  110. package/dest/l1_tx_utils/index-blobs.js +2 -0
  111. package/dest/l1_tx_utils/index.d.ts +4 -1
  112. package/dest/l1_tx_utils/index.d.ts.map +1 -1
  113. package/dest/l1_tx_utils/index.js +3 -0
  114. package/dest/l1_tx_utils/interfaces.d.ts +2 -2
  115. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -1
  116. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
  117. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  118. package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
  119. package/dest/l1_tx_utils/l1_tx_utils.d.ts +26 -8
  120. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
  121. package/dest/l1_tx_utils/l1_tx_utils.js +118 -70
  122. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +19 -30
  123. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  124. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +65 -168
  125. package/dest/l1_tx_utils/signer.d.ts +1 -1
  126. package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
  127. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  128. package/dest/{test → l1_tx_utils}/tx_delayer.js +70 -39
  129. package/dest/l1_tx_utils/types.d.ts +1 -1
  130. package/dest/l1_tx_utils/types.d.ts.map +1 -1
  131. package/dest/l1_tx_utils/utils.d.ts +1 -1
  132. package/dest/l1_types.d.ts +1 -1
  133. package/dest/publisher_manager.d.ts +21 -6
  134. package/dest/publisher_manager.d.ts.map +1 -1
  135. package/dest/publisher_manager.js +81 -7
  136. package/dest/queries.d.ts +14 -3
  137. package/dest/queries.d.ts.map +1 -1
  138. package/dest/queries.js +78 -9
  139. package/dest/test/chain_monitor.d.ts +48 -25
  140. package/dest/test/chain_monitor.d.ts.map +1 -1
  141. package/dest/test/chain_monitor.js +71 -38
  142. package/dest/test/eth_cheat_codes.d.ts +22 -6
  143. package/dest/test/eth_cheat_codes.d.ts.map +1 -1
  144. package/dest/test/eth_cheat_codes.js +28 -7
  145. package/dest/test/eth_cheat_codes_with_state.d.ts +1 -1
  146. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
  147. package/dest/test/index.d.ts +1 -3
  148. package/dest/test/index.d.ts.map +1 -1
  149. package/dest/test/index.js +0 -2
  150. package/dest/test/rollup_cheat_codes.d.ts +46 -14
  151. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  152. package/dest/test/rollup_cheat_codes.js +118 -42
  153. package/dest/test/start_anvil.d.ts +25 -2
  154. package/dest/test/start_anvil.d.ts.map +1 -1
  155. package/dest/test/start_anvil.js +143 -28
  156. package/dest/test/upgrade_utils.d.ts +1 -1
  157. package/dest/test/upgrade_utils.js +2 -2
  158. package/dest/types.d.ts +57 -2
  159. package/dest/types.d.ts.map +1 -1
  160. package/dest/utils.d.ts +24 -4
  161. package/dest/utils.d.ts.map +1 -1
  162. package/dest/utils.js +112 -16
  163. package/dest/zkPassportVerifierAddress.d.ts +1 -1
  164. package/package.json +35 -17
  165. package/src/client.ts +66 -2
  166. package/src/config.ts +91 -469
  167. package/src/contracts/README.md +157 -0
  168. package/src/contracts/chain_state_override.ts +200 -0
  169. package/src/contracts/empire_base.ts +6 -5
  170. package/src/contracts/fee_asset_handler.ts +10 -7
  171. package/src/contracts/fee_asset_price_oracle.ts +285 -0
  172. package/src/contracts/governance.ts +279 -13
  173. package/src/contracts/governance_proposer.ts +74 -7
  174. package/src/contracts/inbox.ts +64 -4
  175. package/src/contracts/index.ts +5 -2
  176. package/src/contracts/log.ts +13 -0
  177. package/src/contracts/multicall.ts +243 -102
  178. package/src/contracts/outbox.ts +132 -0
  179. package/src/contracts/registry.ts +31 -1
  180. package/src/contracts/rollup.ts +819 -192
  181. package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +26 -21
  182. package/src/deploy_aztec_l1_contracts.ts +646 -0
  183. package/src/deploy_l1_contract.ts +362 -0
  184. package/src/forwarder_proxy.ts +108 -0
  185. package/src/generated/l1-contracts-defaults.ts +32 -0
  186. package/src/l1_artifacts.ts +12 -35
  187. package/src/l1_contract_addresses.ts +120 -92
  188. package/src/l1_reader.ts +25 -10
  189. package/src/l1_tx_utils/config.ts +52 -11
  190. package/src/l1_tx_utils/constants.ts +13 -2
  191. package/src/l1_tx_utils/factory.ts +31 -31
  192. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  193. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
  194. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
  195. package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
  196. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +108 -0
  197. package/src/l1_tx_utils/index-blobs.ts +2 -0
  198. package/src/l1_tx_utils/index.ts +3 -0
  199. package/src/l1_tx_utils/interfaces.ts +1 -1
  200. package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
  201. package/src/l1_tx_utils/l1_tx_utils.ts +123 -52
  202. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +79 -214
  203. package/src/{test → l1_tx_utils}/tx_delayer.ts +97 -58
  204. package/src/publisher_manager.ts +107 -10
  205. package/src/queries.ts +87 -10
  206. package/src/test/chain_monitor.ts +115 -51
  207. package/src/test/eth_cheat_codes.ts +25 -7
  208. package/src/test/index.ts +0 -2
  209. package/src/test/rollup_cheat_codes.ts +123 -45
  210. package/src/test/start_anvil.ts +179 -27
  211. package/src/test/upgrade_utils.ts +2 -2
  212. package/src/types.ts +62 -0
  213. package/src/utils.ts +128 -19
  214. package/dest/contracts/empire_slashing_proposer.d.ts +0 -65
  215. package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
  216. package/dest/contracts/empire_slashing_proposer.js +0 -194
  217. package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
  218. package/dest/deploy_l1_contracts.d.ts +0 -226
  219. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  220. package/dest/deploy_l1_contracts.js +0 -1473
  221. package/dest/index.d.ts +0 -18
  222. package/dest/index.d.ts.map +0 -1
  223. package/dest/index.js +0 -17
  224. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +0 -26
  225. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +0 -1
  226. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +0 -26
  227. package/dest/test/delayed_tx_utils.d.ts +0 -13
  228. package/dest/test/delayed_tx_utils.d.ts.map +0 -1
  229. package/dest/test/delayed_tx_utils.js +0 -28
  230. package/dest/test/tx_delayer.d.ts +0 -36
  231. package/dest/test/tx_delayer.d.ts.map +0 -1
  232. package/src/contracts/empire_slashing_proposer.ts +0 -259
  233. package/src/deploy_l1_contracts.ts +0 -1849
  234. package/src/index.ts +0 -17
  235. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
  236. package/src/test/delayed_tx_utils.ts +0 -52
@@ -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
  /**
@@ -1,6 +1,8 @@
1
1
  import { pick } from '@aztec/foundation/collection';
2
- import { createLogger } from '@aztec/foundation/log';
2
+ import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
+ import { RunningPromise } from '@aztec/foundation/running-promise';
3
4
 
5
+ import { Multicall3 } from './contracts/multicall.js';
4
6
  import { L1TxUtils, TxUtilsState } from './l1_tx_utils/index.js';
5
7
 
6
8
  // Defines the order in which we prioritise publishers based on their state (first is better)
@@ -27,22 +29,72 @@ const busyStates: TxUtilsState[] = [
27
29
 
28
30
  export type PublisherFilter<UtilsType extends L1TxUtils> = (utils: UtilsType) => boolean;
29
31
 
32
+ /** Config accepted by PublisherManager. */
33
+ type PublisherManagerConfig = {
34
+ publisherAllowInvalidStates?: boolean;
35
+ publisherFundingThreshold?: bigint;
36
+ publisherFundingAmount?: bigint;
37
+ };
38
+
30
39
  export class PublisherManager<UtilsType extends L1TxUtils = L1TxUtils> {
31
- private log = createLogger('publisher:manager');
32
- private config: { publisherAllowInvalidStates?: boolean };
40
+ private log: Logger;
41
+ private config: PublisherManagerConfig;
42
+ private static readonly FUNDING_CHECK_INTERVAL_MS = 2 * 60 * 1000;
43
+ private funder?: UtilsType;
44
+ private fundingPromise?: RunningPromise;
33
45
 
34
46
  constructor(
35
47
  private publishers: UtilsType[],
36
- config: { publisherAllowInvalidStates?: boolean },
48
+ config: PublisherManagerConfig,
49
+ opts?: { bindings?: LoggerBindings; funder?: UtilsType },
37
50
  ) {
51
+ this.funder = opts?.funder;
52
+ this.log = createLogger('publisher:manager', opts?.bindings);
38
53
  this.log.info(`PublisherManager initialized with ${publishers.length} publishers.`);
39
54
  this.publishers = publishers;
40
- this.config = pick(config, 'publisherAllowInvalidStates');
55
+ this.config = pick(config, 'publisherAllowInvalidStates', 'publisherFundingThreshold', 'publisherFundingAmount');
56
+
57
+ const hasThreshold = this.config.publisherFundingThreshold !== undefined;
58
+ const hasAmount = this.config.publisherFundingAmount !== undefined;
59
+ if (hasThreshold !== hasAmount) {
60
+ this.log.warn(`Incomplete funding config: both publisherFundingThreshold and publisherFundingAmount must be set`);
61
+ }
62
+
63
+ if (this.funder) {
64
+ const funderAddress = this.funder.getSenderAddress();
65
+ if (publishers.some(p => p.getSenderAddress().equals(funderAddress))) {
66
+ this.log.error(`Funding account ${funderAddress} is also a publisher, disabling funding to avoid self-funding`);
67
+ this.funder = undefined;
68
+ }
69
+ }
41
70
  }
42
71
 
43
- /** Loads the state of all publishers and resumes monitoring any pending txs */
44
- public async loadState(): Promise<void> {
45
- await Promise.all(this.publishers.map(pub => pub.loadStateAndResumeMonitoring()));
72
+ /** Loads the state of all publishers and the funder, and starts periodic funding checks. */
73
+ public async start(): Promise<void> {
74
+ await Promise.all([
75
+ ...this.publishers.map(pub => pub.loadStateAndResumeMonitoring()),
76
+ this.funder?.loadStateAndResumeMonitoring(),
77
+ ]);
78
+
79
+ if (
80
+ this.funder &&
81
+ this.config.publisherFundingThreshold !== undefined &&
82
+ this.config.publisherFundingAmount !== undefined
83
+ ) {
84
+ this.fundingPromise = new RunningPromise(
85
+ () => this.triggerFundingIfNeeded(),
86
+ this.log,
87
+ PublisherManager.FUNDING_CHECK_INTERVAL_MS,
88
+ );
89
+ this.fundingPromise.start();
90
+ }
91
+ }
92
+
93
+ /** Stops the funding loop and interrupts all publishers. */
94
+ public async stop(): Promise<void> {
95
+ await this.fundingPromise?.stop();
96
+ this.publishers.forEach(pub => pub.interrupt());
97
+ this.funder?.interrupt();
46
98
  }
47
99
 
48
100
  // Finds and prioritises available publishers based on
@@ -100,7 +152,52 @@ export class PublisherManager<UtilsType extends L1TxUtils = L1TxUtils> {
100
152
  return sortedPublishers[0].publisher;
101
153
  }
102
154
 
103
- public interrupt() {
104
- this.publishers.forEach(pub => pub.interrupt());
155
+ /** Check all publisher balances and fund those below threshold. */
156
+ private async triggerFundingIfNeeded(): Promise<void> {
157
+ const { funder, config } = this;
158
+ if (!funder || config.publisherFundingThreshold === undefined || config.publisherFundingAmount === undefined) {
159
+ return;
160
+ }
161
+
162
+ const allBalances = await Promise.all(
163
+ this.publishers.map(async pub => ({ balance: await pub.getSenderBalance(), publisher: pub })),
164
+ );
165
+ const lowBalance = allBalances.filter(p => p.balance < config.publisherFundingThreshold!);
166
+ if (lowBalance.length === 0) {
167
+ return;
168
+ }
169
+
170
+ const fundingAmount = config.publisherFundingAmount!;
171
+ const funderBalance = await funder.getSenderBalance();
172
+
173
+ if (funderBalance < 10n * fundingAmount) {
174
+ this.log.warn(`Funding account balance is low`, { funderBalance, threshold: 10n * fundingAmount });
175
+ }
176
+ const affordableCount = Number(funderBalance / fundingAmount);
177
+ if (affordableCount === 0) {
178
+ this.log.error(`Funding account balance too low to fund any publisher`, { funderBalance, fundingAmount });
179
+ return;
180
+ }
181
+ if (affordableCount < lowBalance.length) {
182
+ this.log.warn(`Funder can only afford ${affordableCount}/${lowBalance.length} publishers`, {
183
+ funderBalance,
184
+ fundingAmount,
185
+ });
186
+ }
187
+
188
+ const toFund = lowBalance.slice(0, affordableCount).map(p => p.publisher);
189
+ await this.fundPublishers(toFund);
190
+ }
191
+
192
+ /** Fund publishers via a single Multicall3 aggregate3Value transaction. */
193
+ private async fundPublishers(publishers: UtilsType[]): Promise<void> {
194
+ const fundingAmount = this.config.publisherFundingAmount!;
195
+ const calls = publishers.map(pub => ({
196
+ to: pub.getSenderAddress().toString(),
197
+ value: fundingAmount,
198
+ }));
199
+
200
+ await Multicall3.forwardValue(calls, this.funder!, this.log);
201
+ this.log.info(`Funded ${publishers.length} publishers`);
105
202
  }
106
203
  }
package/src/queries.ts CHANGED
@@ -1,10 +1,77 @@
1
1
  import { EthAddress } from '@aztec/foundation/eth-address';
2
2
 
3
- import type { L1ContractsConfig } from './config.js';
3
+ import { BaseError, type Block } from 'viem';
4
+
5
+ import { DefaultL1ContractsConfig, type L1ContractsConfig } from './config.js';
4
6
  import { ReadOnlyGovernanceContract } from './contracts/governance.js';
5
7
  import { GovernanceProposerContract } from './contracts/governance_proposer.js';
8
+ import { InboxContract } from './contracts/inbox.js';
6
9
  import { RollupContract } from './contracts/rollup.js';
7
- import type { ViemPublicClient } from './types.js';
10
+ import type { ViemClient, ViemPublicClient } from './types.js';
11
+
12
+ /**
13
+ * Returns the L1 finalized block, or `undefined` if the chain does not yet have one
14
+ * (common on freshly started devnets). Rethrows any other RPC error.
15
+ */
16
+ export async function getFinalizedL1Block(client: ViemClient): Promise<Block<bigint, false, 'finalized'> | undefined> {
17
+ try {
18
+ return await client.getBlock({ blockTag: 'finalized', includeTransactions: false });
19
+ } catch (err) {
20
+ if (isFinalizedBlockTagNotFoundError(err)) {
21
+ return undefined;
22
+ }
23
+ throw err;
24
+ }
25
+ }
26
+
27
+ // Error messages returned by popular Ethereum execution clients when
28
+ // eth_getBlockByNumber / eth_call is called with blockTag "finalized" or
29
+ // "safe" and no such block has been produced yet:
30
+ //
31
+ // geth "finalized block not found"
32
+ // "safe block not found"
33
+ // reth "block not found: finalized"
34
+ // "block not found: safe"
35
+ // nethermind "Unknown block error" (same for both tags)
36
+ // besu "Unknown block"
37
+ // erigon 'block "finalized" not available (head block: N)'
38
+ // 'block "safe" not available (head block: N)'
39
+ //
40
+ // A combined regex covers all five:
41
+ const FINALIZED_BLOCK_TAG_NOT_FOUND_MESSAGE_RE =
42
+ /(finalized|safe) block not found|block not found: (finalized|safe)|unknown block|block "(finalized|safe)" not available/i;
43
+
44
+ /**
45
+ * Returns true if the error originates from an RPC call that failed because
46
+ * the "finalized" (or "safe") block tag is not yet available on the chain.
47
+ */
48
+ export function isFinalizedBlockTagNotFoundError(err: unknown): boolean {
49
+ if (!err) {
50
+ return false;
51
+ }
52
+
53
+ if (err instanceof BaseError) {
54
+ const hit = err.walk((e: any) => matchesFinalizedBlockTagNotFound(e));
55
+ if (hit) {
56
+ return true;
57
+ }
58
+ }
59
+
60
+ for (let cur: any = err, i = 0; cur && i < 10; cur = cur.cause, i++) {
61
+ if (matchesFinalizedBlockTagNotFound(cur)) {
62
+ return true;
63
+ }
64
+ }
65
+ return false;
66
+ }
67
+
68
+ function matchesFinalizedBlockTagNotFound(e: any): boolean {
69
+ if (!e) {
70
+ return false;
71
+ }
72
+ const text = `${e.details ?? ''} ${e.message ?? ''} ${e.shortMessage ?? ''}`;
73
+ return FINALIZED_BLOCK_TAG_NOT_FOUND_MESSAGE_RE.test(text);
74
+ }
8
75
 
9
76
  /** Reads the L1ContractsConfig from L1 contracts. */
10
77
  export async function getL1ContractsConfig(
@@ -25,6 +92,8 @@ export async function getL1ContractsConfig(
25
92
  const rollup = new RollupContract(publicClient, rollupAddress.toString());
26
93
  const slasherProposer = await rollup.getSlashingProposer();
27
94
  const slasher = await rollup.getSlasherContract();
95
+ const rollupAddresses = await rollup.getRollupAddresses();
96
+ const inboxContract = new InboxContract(publicClient, rollupAddresses.inboxAddress.toString());
28
97
 
29
98
  const [
30
99
  l1StartBlock,
@@ -33,7 +102,9 @@ export async function getL1ContractsConfig(
33
102
  aztecSlotDuration,
34
103
  aztecProofSubmissionEpochs,
35
104
  aztecTargetCommitteeSize,
36
- lagInEpochs,
105
+ lagInEpochsForValidatorSet,
106
+ lagInEpochsForRandao,
107
+ inboxLag,
37
108
  activationThreshold,
38
109
  ejectionThreshold,
39
110
  localEjectionThreshold,
@@ -59,7 +130,9 @@ export async function getL1ContractsConfig(
59
130
  rollup.getSlotDuration(),
60
131
  rollup.getProofSubmissionEpochs(),
61
132
  rollup.getTargetCommitteeSize(),
62
- rollup.getLagInEpochs(),
133
+ rollup.getLagInEpochsForValidatorSet(),
134
+ rollup.getLagInEpochsForRandao(),
135
+ inboxContract.getLag(),
63
136
  rollup.getActivationThreshold(),
64
137
  rollup.getEjectionThreshold(),
65
138
  rollup.getLocalEjectionThreshold(),
@@ -69,8 +142,8 @@ export async function getL1ContractsConfig(
69
142
  slasherProposer?.getRoundSize() ?? 0n,
70
143
  slasherProposer?.getLifetimeInRounds() ?? 0n,
71
144
  slasherProposer?.getExecutionDelayInRounds() ?? 0n,
72
- slasherProposer?.type === 'tally' ? slasherProposer.getSlashOffsetInRounds() : 0n,
73
- slasherProposer?.type === 'tally' ? slasherProposer.getSlashingAmounts() : [0n, 0n, 0n],
145
+ slasherProposer?.getSlashOffsetInRounds() ?? 0n,
146
+ slasherProposer?.getSlashingAmounts() ?? [0n, 0n, 0n],
74
147
  slasher?.getVetoer() ?? EthAddress.ZERO,
75
148
  slasher?.getSlashingDisableDuration() ?? 0,
76
149
  rollup.getManaTarget(),
@@ -87,14 +160,17 @@ export async function getL1ContractsConfig(
87
160
  aztecSlotDuration: Number(aztecSlotDuration),
88
161
  aztecProofSubmissionEpochs: Number(aztecProofSubmissionEpochs),
89
162
  aztecTargetCommitteeSize: Number(aztecTargetCommitteeSize),
90
- lagInEpochs: Number(lagInEpochs),
163
+ lagInEpochsForValidatorSet: Number(lagInEpochsForValidatorSet),
164
+ lagInEpochsForRandao: Number(lagInEpochsForRandao),
165
+ inboxLag: Number(inboxLag),
91
166
  governanceProposerQuorum: Number(governanceProposerQuorum),
92
167
  governanceProposerRoundSize: Number(governanceProposerRoundSize),
168
+ governanceVotingDuration: DefaultL1ContractsConfig.governanceVotingDuration,
93
169
  activationThreshold,
94
170
  ejectionThreshold,
95
171
  localEjectionThreshold,
96
172
  slashingQuorum: Number(slashingQuorum),
97
- slashingRoundSizeInEpochs: Number(slashingRoundSize / aztecEpochDuration),
173
+ slashingRoundSizeInEpochs: Number(Number(slashingRoundSize) / aztecEpochDuration),
98
174
  slashingLifetimeInRounds: Number(slashingLifetimeInRounds),
99
175
  slashingExecutionDelayInRounds: Number(slashingExecutionDelayInRounds),
100
176
  slashingVetoer,
@@ -102,12 +178,13 @@ export async function getL1ContractsConfig(
102
178
  manaTarget,
103
179
  provingCostPerMana: provingCostPerMana,
104
180
  rollupVersion: Number(rollupVersion),
105
- genesisArchiveTreeRoot,
181
+ genesisArchiveTreeRoot: genesisArchiveTreeRoot.toString(),
106
182
  exitDelaySeconds: Number(exitDelay),
107
- slasherFlavor: slasherProposer?.type ?? 'tally',
183
+ slasherEnabled: !!slasherProposer,
108
184
  slashingOffsetInRounds: Number(slashingOffsetInRounds),
109
185
  slashAmountSmall: slashingAmounts[0],
110
186
  slashAmountMedium: slashingAmounts[1],
111
187
  slashAmountLarge: slashingAmounts[2],
188
+ initialEthPerFeeAsset: DefaultL1ContractsConfig.initialEthPerFeeAsset,
112
189
  };
113
190
  }