@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.017a351

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 (285) hide show
  1. package/dest/account.d.ts +2 -0
  2. package/dest/account.d.ts.map +1 -0
  3. package/dest/account.js +4 -0
  4. package/dest/chain.d.ts +1 -1
  5. package/dest/client.d.ts +28 -4
  6. package/dest/client.d.ts.map +1 -1
  7. package/dest/client.js +73 -3
  8. package/dest/config.d.ts +70 -23
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +151 -34
  11. package/dest/constants.d.ts +1 -1
  12. package/dest/contracts/chain_state_override.d.ts +78 -0
  13. package/dest/contracts/chain_state_override.d.ts.map +1 -0
  14. package/dest/contracts/chain_state_override.js +137 -0
  15. package/dest/contracts/empire_base.d.ts +25 -8
  16. package/dest/contracts/empire_base.d.ts.map +1 -1
  17. package/dest/contracts/empire_base.js +75 -2
  18. package/dest/contracts/errors.d.ts +7 -0
  19. package/dest/contracts/errors.d.ts.map +1 -0
  20. package/dest/contracts/errors.js +12 -0
  21. package/dest/contracts/fee_asset_handler.d.ts +20 -0
  22. package/dest/contracts/fee_asset_handler.d.ts.map +1 -0
  23. package/dest/contracts/fee_asset_handler.js +59 -0
  24. package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
  25. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  26. package/dest/contracts/fee_asset_price_oracle.js +656 -0
  27. package/dest/contracts/fee_juice.d.ts +6 -7
  28. package/dest/contracts/fee_juice.d.ts.map +1 -1
  29. package/dest/contracts/fee_juice.js +27 -20
  30. package/dest/contracts/governance.d.ts +131 -43
  31. package/dest/contracts/governance.d.ts.map +1 -1
  32. package/dest/contracts/governance.js +281 -87
  33. package/dest/contracts/governance_proposer.d.ts +49 -13
  34. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  35. package/dest/contracts/governance_proposer.js +483 -26
  36. package/dest/contracts/gse.d.ts +32 -0
  37. package/dest/contracts/gse.d.ts.map +1 -0
  38. package/dest/contracts/gse.js +72 -0
  39. package/dest/contracts/inbox.d.ts +47 -0
  40. package/dest/contracts/inbox.d.ts.map +1 -0
  41. package/dest/contracts/inbox.js +85 -0
  42. package/dest/contracts/index.d.ts +11 -2
  43. package/dest/contracts/index.d.ts.map +1 -1
  44. package/dest/contracts/index.js +10 -1
  45. package/dest/contracts/log.d.ts +13 -0
  46. package/dest/contracts/log.d.ts.map +1 -0
  47. package/dest/contracts/log.js +1 -0
  48. package/dest/contracts/multicall.d.ts +136 -0
  49. package/dest/contracts/multicall.d.ts.map +1 -0
  50. package/dest/contracts/multicall.js +264 -0
  51. package/dest/contracts/outbox.d.ts +64 -0
  52. package/dest/contracts/outbox.d.ts.map +1 -0
  53. package/dest/contracts/outbox.js +113 -0
  54. package/dest/contracts/registry.d.ts +12 -5
  55. package/dest/contracts/registry.d.ts.map +1 -1
  56. package/dest/contracts/registry.js +74 -17
  57. package/dest/contracts/rollup.d.ts +5526 -52
  58. package/dest/contracts/rollup.d.ts.map +1 -1
  59. package/dest/contracts/rollup.js +1446 -118
  60. package/dest/contracts/slasher_contract.d.ts +44 -0
  61. package/dest/contracts/slasher_contract.d.ts.map +1 -0
  62. package/dest/contracts/slasher_contract.js +75 -0
  63. package/dest/contracts/slashing_proposer.d.ts +133 -15
  64. package/dest/contracts/slashing_proposer.d.ts.map +1 -1
  65. package/dest/contracts/slashing_proposer.js +293 -22
  66. package/dest/contracts/utils.d.ts +3 -0
  67. package/dest/contracts/utils.d.ts.map +1 -0
  68. package/dest/contracts/utils.js +11 -0
  69. package/dest/deploy_aztec_l1_contracts.d.ts +256 -0
  70. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  71. package/dest/deploy_aztec_l1_contracts.js +411 -0
  72. package/dest/deploy_l1_contract.d.ts +68 -0
  73. package/dest/deploy_l1_contract.d.ts.map +1 -0
  74. package/dest/deploy_l1_contract.js +312 -0
  75. package/dest/eth-signer/eth-signer.d.ts +21 -0
  76. package/dest/eth-signer/eth-signer.d.ts.map +1 -0
  77. package/dest/eth-signer/eth-signer.js +5 -0
  78. package/dest/eth-signer/index.d.ts +2 -0
  79. package/dest/eth-signer/index.d.ts.map +1 -0
  80. package/dest/eth-signer/index.js +1 -0
  81. package/dest/forwarder_proxy.d.ts +32 -0
  82. package/dest/forwarder_proxy.d.ts.map +1 -0
  83. package/dest/forwarder_proxy.js +93 -0
  84. package/dest/generated/l1-contracts-defaults.d.ts +30 -0
  85. package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
  86. package/dest/generated/l1-contracts-defaults.js +30 -0
  87. package/dest/l1_artifacts.d.ts +79270 -0
  88. package/dest/l1_artifacts.d.ts.map +1 -0
  89. package/dest/l1_artifacts.js +151 -0
  90. package/dest/l1_contract_addresses.d.ts +61 -45
  91. package/dest/l1_contract_addresses.d.ts.map +1 -1
  92. package/dest/l1_contract_addresses.js +99 -76
  93. package/dest/l1_reader.d.ts +8 -6
  94. package/dest/l1_reader.d.ts.map +1 -1
  95. package/dest/l1_reader.js +20 -12
  96. package/dest/l1_tx_utils/config.d.ts +65 -0
  97. package/dest/l1_tx_utils/config.d.ts.map +1 -0
  98. package/dest/l1_tx_utils/config.js +109 -0
  99. package/dest/l1_tx_utils/constants.d.ts +12 -0
  100. package/dest/l1_tx_utils/constants.d.ts.map +1 -0
  101. package/dest/l1_tx_utils/constants.js +39 -0
  102. package/dest/l1_tx_utils/factory.d.ts +32 -0
  103. package/dest/l1_tx_utils/factory.d.ts.map +1 -0
  104. package/dest/l1_tx_utils/factory.js +22 -0
  105. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  106. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  107. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  108. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  109. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  110. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  111. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  112. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  113. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  114. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  115. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  116. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  117. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  118. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  119. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
  120. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  121. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  122. package/dest/l1_tx_utils/index-blobs.js +2 -0
  123. package/dest/l1_tx_utils/index.d.ts +13 -0
  124. package/dest/l1_tx_utils/index.d.ts.map +1 -0
  125. package/dest/l1_tx_utils/index.js +13 -0
  126. package/dest/l1_tx_utils/interfaces.d.ts +76 -0
  127. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
  128. package/dest/l1_tx_utils/interfaces.js +4 -0
  129. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
  130. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  131. package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
  132. package/dest/l1_tx_utils/l1_tx_utils.d.ts +113 -0
  133. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
  134. package/dest/l1_tx_utils/l1_tx_utils.js +658 -0
  135. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +83 -0
  136. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
  137. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +328 -0
  138. package/dest/l1_tx_utils/signer.d.ts +4 -0
  139. package/dest/l1_tx_utils/signer.d.ts.map +1 -0
  140. package/dest/l1_tx_utils/signer.js +16 -0
  141. package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
  142. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  143. package/dest/l1_tx_utils/tx_delayer.js +223 -0
  144. package/dest/l1_tx_utils/types.d.ts +67 -0
  145. package/dest/l1_tx_utils/types.d.ts.map +1 -0
  146. package/dest/l1_tx_utils/types.js +26 -0
  147. package/dest/l1_tx_utils/utils.d.ts +4 -0
  148. package/dest/l1_tx_utils/utils.d.ts.map +1 -0
  149. package/dest/l1_tx_utils/utils.js +14 -0
  150. package/dest/l1_types.d.ts +6 -0
  151. package/dest/l1_types.d.ts.map +1 -0
  152. package/dest/l1_types.js +1 -0
  153. package/dest/publisher_manager.d.ts +30 -0
  154. package/dest/publisher_manager.d.ts.map +1 -0
  155. package/dest/publisher_manager.js +162 -0
  156. package/dest/queries.d.ts +17 -4
  157. package/dest/queries.d.ts.map +1 -1
  158. package/dest/queries.js +120 -12
  159. package/dest/test/chain_monitor.d.ts +95 -0
  160. package/dest/test/chain_monitor.d.ts.map +1 -0
  161. package/dest/test/chain_monitor.js +249 -0
  162. package/dest/test/eth_cheat_codes.d.ts +237 -0
  163. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  164. package/dest/test/eth_cheat_codes.js +573 -0
  165. package/dest/test/eth_cheat_codes_with_state.d.ts +2 -2
  166. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
  167. package/dest/test/eth_cheat_codes_with_state.js +1 -1
  168. package/dest/test/index.d.ts +4 -3
  169. package/dest/test/index.d.ts.map +1 -1
  170. package/dest/test/index.js +3 -2
  171. package/dest/test/rollup_cheat_codes.d.ts +118 -0
  172. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  173. package/dest/test/rollup_cheat_codes.js +344 -0
  174. package/dest/test/start_anvil.d.ts +30 -2
  175. package/dest/test/start_anvil.d.ts.map +1 -1
  176. package/dest/test/start_anvil.js +147 -24
  177. package/dest/test/upgrade_utils.d.ts +6 -5
  178. package/dest/test/upgrade_utils.d.ts.map +1 -1
  179. package/dest/test/upgrade_utils.js +23 -16
  180. package/dest/types.d.ts +62 -8
  181. package/dest/types.d.ts.map +1 -1
  182. package/dest/types.js +3 -1
  183. package/dest/utils.d.ts +25 -4
  184. package/dest/utils.d.ts.map +1 -1
  185. package/dest/utils.js +142 -91
  186. package/dest/zkPassportVerifierAddress.d.ts +15 -0
  187. package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
  188. package/dest/zkPassportVerifierAddress.js +11 -0
  189. package/package.json +52 -26
  190. package/src/account.ts +5 -0
  191. package/src/client.ts +107 -5
  192. package/src/config.ts +218 -43
  193. package/src/contracts/README.md +157 -0
  194. package/src/contracts/chain_state_override.ts +200 -0
  195. package/src/contracts/empire_base.ts +77 -7
  196. package/src/contracts/errors.ts +13 -0
  197. package/src/contracts/fee_asset_handler.ts +66 -0
  198. package/src/contracts/fee_asset_price_oracle.ts +285 -0
  199. package/src/contracts/fee_juice.ts +29 -15
  200. package/src/contracts/governance.ts +343 -74
  201. package/src/contracts/governance_proposer.ts +128 -25
  202. package/src/contracts/gse.ts +88 -0
  203. package/src/contracts/inbox.ts +123 -0
  204. package/src/contracts/index.ts +10 -1
  205. package/src/contracts/log.ts +13 -0
  206. package/src/contracts/multicall.ts +296 -0
  207. package/src/contracts/outbox.ts +132 -0
  208. package/src/contracts/registry.ts +81 -26
  209. package/src/contracts/rollup.ts +1246 -90
  210. package/src/contracts/slasher_contract.ts +89 -0
  211. package/src/contracts/slashing_proposer.ts +296 -27
  212. package/src/contracts/utils.ts +14 -0
  213. package/src/deploy_aztec_l1_contracts.ts +646 -0
  214. package/src/deploy_l1_contract.ts +362 -0
  215. package/src/eth-signer/eth-signer.ts +25 -0
  216. package/src/eth-signer/index.ts +1 -0
  217. package/src/forwarder_proxy.ts +108 -0
  218. package/src/generated/l1-contracts-defaults.ts +32 -0
  219. package/src/l1_artifacts.ts +231 -0
  220. package/src/l1_contract_addresses.ts +121 -80
  221. package/src/l1_reader.ts +31 -16
  222. package/src/l1_tx_utils/README.md +177 -0
  223. package/src/l1_tx_utils/config.ts +181 -0
  224. package/src/l1_tx_utils/constants.ts +29 -0
  225. package/src/l1_tx_utils/factory.ts +64 -0
  226. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  227. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
  228. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
  229. package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
  230. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +108 -0
  231. package/src/l1_tx_utils/index-blobs.ts +2 -0
  232. package/src/l1_tx_utils/index.ts +15 -0
  233. package/src/l1_tx_utils/interfaces.ts +86 -0
  234. package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
  235. package/src/l1_tx_utils/l1_tx_utils.ts +789 -0
  236. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +424 -0
  237. package/src/l1_tx_utils/signer.ts +28 -0
  238. package/src/l1_tx_utils/tx_delayer.ts +303 -0
  239. package/src/l1_tx_utils/types.ts +85 -0
  240. package/src/l1_tx_utils/utils.ts +16 -0
  241. package/src/l1_types.ts +6 -0
  242. package/src/publisher_manager.ts +203 -0
  243. package/src/queries.ts +149 -17
  244. package/src/test/chain_monitor.ts +307 -0
  245. package/src/test/eth_cheat_codes.ts +600 -0
  246. package/src/test/eth_cheat_codes_with_state.ts +1 -1
  247. package/src/test/index.ts +3 -2
  248. package/src/test/rollup_cheat_codes.ts +388 -0
  249. package/src/test/start_anvil.ts +189 -22
  250. package/src/test/upgrade_utils.ts +30 -21
  251. package/src/types.ts +71 -7
  252. package/src/utils.ts +164 -96
  253. package/src/zkPassportVerifierAddress.ts +15 -0
  254. package/dest/contracts/forwarder.d.ts +0 -24
  255. package/dest/contracts/forwarder.d.ts.map +0 -1
  256. package/dest/contracts/forwarder.js +0 -101
  257. package/dest/deploy_l1_contracts.d.ts +0 -21210
  258. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  259. package/dest/deploy_l1_contracts.js +0 -687
  260. package/dest/eth_cheat_codes.d.ts +0 -147
  261. package/dest/eth_cheat_codes.d.ts.map +0 -1
  262. package/dest/eth_cheat_codes.js +0 -303
  263. package/dest/index.d.ts +0 -14
  264. package/dest/index.d.ts.map +0 -1
  265. package/dest/index.js +0 -13
  266. package/dest/l1_tx_utils.d.ts +0 -192
  267. package/dest/l1_tx_utils.d.ts.map +0 -1
  268. package/dest/l1_tx_utils.js +0 -641
  269. package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
  270. package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
  271. package/dest/l1_tx_utils_with_blobs.js +0 -64
  272. package/dest/test/delayed_tx_utils.d.ts +0 -8
  273. package/dest/test/delayed_tx_utils.d.ts.map +0 -1
  274. package/dest/test/delayed_tx_utils.js +0 -21
  275. package/dest/test/tx_delayer.d.ts +0 -25
  276. package/dest/test/tx_delayer.d.ts.map +0 -1
  277. package/dest/test/tx_delayer.js +0 -116
  278. package/src/contracts/forwarder.ts +0 -132
  279. package/src/deploy_l1_contracts.ts +0 -948
  280. package/src/eth_cheat_codes.ts +0 -314
  281. package/src/index.ts +0 -13
  282. package/src/l1_tx_utils.ts +0 -847
  283. package/src/l1_tx_utils_with_blobs.ts +0 -86
  284. package/src/test/delayed_tx_utils.ts +0 -24
  285. package/src/test/tx_delayer.ts +0 -163
@@ -0,0 +1,296 @@
1
+ import { EthAddress } from '@aztec/foundation/eth-address';
2
+ import type { Logger } from '@aztec/foundation/log';
3
+
4
+ import {
5
+ type Abi,
6
+ type Address,
7
+ type BlockOverrides,
8
+ type Hex,
9
+ type RequiredBy,
10
+ type StateOverride,
11
+ type TransactionReceipt,
12
+ decodeFunctionResult,
13
+ encodeFunctionData,
14
+ multicall3Abi,
15
+ } from 'viem';
16
+
17
+ import type { L1BlobInputs, L1TxConfig, L1TxRequest, L1TxUtils } from '../l1_tx_utils/index.js';
18
+ import type { ExtendedViemWalletClient } from '../types.js';
19
+ import { tryDecodeRevertReason } from '../utils.js';
20
+
21
+ export const MULTI_CALL_3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11' as const;
22
+
23
+ /**
24
+ * Thrown by `Multicall3.forward` when the forwarder transaction lands but the receipt reports a
25
+ * reverted status. This is not expected (aggregate3 uses allowFailure: true), so callers should
26
+ * treat it as a fatal on-chain failure rather than retrying on a different publisher.
27
+ */
28
+ export class MulticallForwarderRevertedError extends Error {
29
+ constructor(public readonly receipt: TransactionReceipt) {
30
+ super(`Multicall3 forwarder tx reverted: ${receipt.transactionHash}`);
31
+ this.name = 'MulticallForwarderRevertedError';
32
+ }
33
+ }
34
+
35
+ /** ABI fragment for aggregate3Value — not included in viem's multicall3Abi. */
36
+ export const aggregate3ValueAbi = [
37
+ {
38
+ inputs: [
39
+ {
40
+ components: [
41
+ { internalType: 'address', name: 'target', type: 'address' },
42
+ { internalType: 'bool', name: 'allowFailure', type: 'bool' },
43
+ { internalType: 'uint256', name: 'value', type: 'uint256' },
44
+ { internalType: 'bytes', name: 'callData', type: 'bytes' },
45
+ ],
46
+ internalType: 'struct Multicall3.Call3Value[]',
47
+ name: 'calls',
48
+ type: 'tuple[]',
49
+ },
50
+ ],
51
+ name: 'aggregate3Value',
52
+ outputs: [
53
+ {
54
+ components: [
55
+ { internalType: 'bool', name: 'success', type: 'bool' },
56
+ { internalType: 'bytes', name: 'returnData', type: 'bytes' },
57
+ ],
58
+ internalType: 'struct Multicall3.Result[]',
59
+ name: 'returnData',
60
+ type: 'tuple[]',
61
+ },
62
+ ],
63
+ stateMutability: 'payable',
64
+ type: 'function',
65
+ },
66
+ ] as const;
67
+
68
+ /** A single call to embed inside an aggregate3 simulation. The abi is used to decode revert reasons. */
69
+ export type SimulateAggregate3Request = {
70
+ to: Address;
71
+ data: Hex;
72
+ /** Optional ABI used to decode the revert reason if this entry reverts. */
73
+ abi?: Abi;
74
+ };
75
+
76
+ export type SimulateAggregate3EntryResult = {
77
+ success: boolean;
78
+ /** Decoded revert reason text when `success === false` and a request abi was provided. */
79
+ revertReason?: string;
80
+ /** Raw return data hex. `'0x'` for successful entries with void return. */
81
+ returnData: Hex;
82
+ };
83
+
84
+ /**
85
+ * Outcome of a bundle simulation.
86
+ * - `decoded`: eth_simulateV1 ran and produced a per-entry Result[]. Use `entries` for filtering.
87
+ * - `fallback`: the node does not support eth_simulateV1; `fallbackGasEstimate` was returned and no
88
+ * per-entry info is available. Caller should send the bundle as-is with a conservative gas cap.
89
+ */
90
+ export type SimulateAggregate3Result =
91
+ | { kind: 'decoded'; entries: SimulateAggregate3EntryResult[]; gasUsed: bigint }
92
+ | { kind: 'fallback'; gasUsed: bigint };
93
+
94
+ export type SimulateAggregate3Options = {
95
+ blockOverrides?: BlockOverrides<bigint, number>;
96
+ stateOverrides?: StateOverride;
97
+ /**
98
+ * If set, append a state override that fakes the sender's balance during the simulation so a
99
+ * low or zero balance does not cause the simulate to fail with insufficient funds. The fake
100
+ * balance is applied to `l1TxUtils.getSenderAddress()`.
101
+ */
102
+ fakeSenderBalance?: bigint;
103
+ /** Gas cap to pass on the simulate call itself (defaults to viem's behavior). */
104
+ gas?: bigint;
105
+ /** When eth_simulateV1 is unavailable, fall back to this gas estimate instead of throwing. */
106
+ fallbackGasEstimate?: bigint;
107
+ };
108
+
109
+ export class Multicall3 {
110
+ /**
111
+ * Returns true iff Multicall3 bytecode is deployed at MULTI_CALL_3_ADDRESS. An empty result from
112
+ * a non-existent contract would otherwise silently validate any bundle that uses Multicall3.
113
+ */
114
+ static async hasCode(l1TxUtils: L1TxUtils): Promise<boolean> {
115
+ const code = await l1TxUtils.getCode(EthAddress.fromString(MULTI_CALL_3_ADDRESS));
116
+ return !!code && code !== '0x';
117
+ }
118
+
119
+ /**
120
+ * Simulates an aggregate3 call composed of the given requests via eth_simulateV1 and decodes the
121
+ * per-entry Result[]. Entries that revert are returned with a decoded revertReason (if the request
122
+ * provided an abi).
123
+ *
124
+ * Use this to pre-validate a bundle before sending it through `Multicall3.forward`. The caller can
125
+ * drop reverted entries from the bundle and re-simulate with the reduced list to get an accurate
126
+ * `gasUsed`.
127
+ */
128
+ static async simulateAggregate3(
129
+ requests: SimulateAggregate3Request[],
130
+ l1TxUtils: L1TxUtils,
131
+ opts: SimulateAggregate3Options = {},
132
+ ): Promise<SimulateAggregate3Result> {
133
+ const calldata = encodeFunctionData({
134
+ abi: multicall3Abi,
135
+ functionName: 'aggregate3',
136
+ args: [
137
+ requests.map(r => ({
138
+ target: r.to,
139
+ callData: r.data,
140
+ allowFailure: true,
141
+ })),
142
+ ],
143
+ });
144
+
145
+ const stateOverrides: StateOverride = [...(opts.stateOverrides ?? [])];
146
+ if (opts.fakeSenderBalance !== undefined) {
147
+ stateOverrides.push({
148
+ address: l1TxUtils.getSenderAddress().toString(),
149
+ balance: opts.fakeSenderBalance,
150
+ });
151
+ }
152
+
153
+ const simResult = await l1TxUtils.simulate(
154
+ { to: MULTI_CALL_3_ADDRESS, data: calldata, gas: opts.gas },
155
+ opts.blockOverrides,
156
+ stateOverrides,
157
+ multicall3Abi,
158
+ { fallbackGasEstimate: opts.fallbackGasEstimate },
159
+ );
160
+
161
+ if (simResult.result === '0x') {
162
+ return { kind: 'fallback', gasUsed: simResult.gasUsed };
163
+ }
164
+
165
+ const decoded = decodeFunctionResult({
166
+ abi: multicall3Abi,
167
+ functionName: 'aggregate3',
168
+ data: simResult.result,
169
+ }) as readonly { success: boolean; returnData: `0x${string}` }[];
170
+
171
+ const entries: SimulateAggregate3EntryResult[] = decoded.map((entry, i) => {
172
+ if (entry.success) {
173
+ return { success: true, returnData: entry.returnData };
174
+ }
175
+ const abi = requests[i].abi;
176
+ const revertReason = abi ? tryDecodeRevertReason(entry.returnData, abi) : undefined;
177
+ return { success: false, returnData: entry.returnData, revertReason };
178
+ });
179
+
180
+ return { kind: 'decoded', entries, gasUsed: simResult.gasUsed };
181
+ }
182
+
183
+ /**
184
+ * Sends a batch of requests through aggregate3. Individual calls may fail (allowFailure: true),
185
+ * but the top-level multicall is expected to land successfully. Throws if the send fails or if
186
+ * the receipt reports a reverted status.
187
+ */
188
+ static async forward<TOptGasLimitRequired extends boolean>(
189
+ requests: L1TxRequest[],
190
+ l1TxUtils: L1TxUtils,
191
+ gasConfig: TOptGasLimitRequired extends true ? RequiredBy<L1TxConfig, 'gasLimit'> : L1TxConfig | undefined,
192
+ blobConfig: L1BlobInputs | undefined,
193
+ opts: { gasLimitRequired?: TOptGasLimitRequired } = {},
194
+ ) {
195
+ if (opts.gasLimitRequired && !gasConfig?.gasLimit) {
196
+ throw new Error('Multicall gasLimit is required when gasLimitRequired is true');
197
+ }
198
+
199
+ const args = requests
200
+ .filter(request => request.to !== null)
201
+ .map(r => ({
202
+ target: r.to!,
203
+ callData: r.data!,
204
+ allowFailure: true,
205
+ }));
206
+ const encodedForwarderData = encodeFunctionData({
207
+ abi: multicall3Abi,
208
+ functionName: 'aggregate3',
209
+ args: [args],
210
+ });
211
+
212
+ const { receipt } = await l1TxUtils.sendAndMonitorTransaction(
213
+ {
214
+ to: MULTI_CALL_3_ADDRESS,
215
+ data: encodedForwarderData,
216
+ abi: multicall3Abi,
217
+ },
218
+ gasConfig,
219
+ blobConfig,
220
+ );
221
+
222
+ // This shouldn't happen. Any failure in individual calls is swallowed by forward since we set
223
+ // allowFailure to true for all calls, so a reverted status here would indicate a problem with
224
+ // the Multicall3 contract itself or the forwarder transaction (such as an out-of-gas).
225
+ if (receipt.status !== 'success') {
226
+ throw new MulticallForwarderRevertedError(receipt);
227
+ }
228
+
229
+ const stats = await l1TxUtils.getTransactionStats(receipt.transactionHash);
230
+ return { receipt, stats, multicallData: encodedForwarderData };
231
+ }
232
+
233
+ /** Batch multiple value transfers into a single aggregate3Value call on Multicall3. */
234
+ static async forwardValue(calls: { to: Address; value: bigint }[], l1TxUtils: L1TxUtils, logger: Logger) {
235
+ const args = calls.map(c => ({
236
+ target: c.to,
237
+ allowFailure: false,
238
+ value: c.value,
239
+ callData: '0x' as Hex,
240
+ }));
241
+
242
+ const data = encodeFunctionData({
243
+ abi: aggregate3ValueAbi,
244
+ functionName: 'aggregate3Value',
245
+ args: [args],
246
+ });
247
+
248
+ const totalValue = calls.reduce((sum, c) => sum + c.value, 0n);
249
+
250
+ logger.info(`Sending aggregate3Value with ${calls.length} calls`, { totalValue });
251
+ const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
252
+ to: MULTI_CALL_3_ADDRESS,
253
+ data,
254
+ value: totalValue,
255
+ });
256
+
257
+ if (receipt.status !== 'success') {
258
+ throw new Error(`aggregate3Value transaction reverted: ${receipt.transactionHash}`);
259
+ }
260
+
261
+ return { receipt };
262
+ }
263
+ }
264
+
265
+ export async function deployMulticall3(l1Client: ExtendedViemWalletClient, logger: Logger) {
266
+ const existing = await l1Client.getCode({ address: MULTI_CALL_3_ADDRESS });
267
+ if (existing && existing !== '0x') {
268
+ logger.verbose('Multicall3 already deployed', { address: MULTI_CALL_3_ADDRESS });
269
+ return;
270
+ }
271
+
272
+ const deployer = '0x05f32b3cc3888453ff71b01135b34ff8e41263f2';
273
+ const sendEth = await l1Client.sendTransaction({ to: deployer, value: 10n ** 17n });
274
+ logger.info('Sent 0.1 ETH to deployer', { deployer, value: 10n ** 17n });
275
+ const sendEthReceipt = await l1Client.waitForTransactionReceipt({ hash: sendEth });
276
+ if (sendEthReceipt.status !== 'success') {
277
+ logger.error('Failed to send ETH to deployer', undefined, { sendEthReceipt });
278
+ throw new Error('Failed to send ETH to deployer');
279
+ } else {
280
+ logger.info('Sent 0.1 ETH to deployer', { deployer, value: 10n ** 17n });
281
+ }
282
+
283
+ const tx =
284
+ '0xf90f538085174876e800830f42408080b90f00608060405234801561001057600080fd5b50610ee0806100206000396000f3fe6080604052600436106100f35760003560e01c80634d2301cc1161008a578063a8b0574e11610059578063a8b0574e1461025a578063bce38bd714610275578063c3077fa914610288578063ee82ac5e1461029b57600080fd5b80634d2301cc146101ec57806372425d9d1461022157806382ad56cb1461023457806386d516e81461024757600080fd5b80633408e470116100c65780633408e47014610191578063399542e9146101a45780633e64a696146101c657806342cbb15c146101d957600080fd5b80630f28c97d146100f8578063174dea711461011a578063252dba421461013a57806327e86d6e1461015b575b600080fd5b34801561010457600080fd5b50425b6040519081526020015b60405180910390f35b61012d610128366004610a85565b6102ba565b6040516101119190610bbe565b61014d610148366004610a85565b6104ef565b604051610111929190610bd8565b34801561016757600080fd5b50437fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0140610107565b34801561019d57600080fd5b5046610107565b6101b76101b2366004610c60565b610690565b60405161011193929190610cba565b3480156101d257600080fd5b5048610107565b3480156101e557600080fd5b5043610107565b3480156101f857600080fd5b50610107610207366004610ce2565b73ffffffffffffffffffffffffffffffffffffffff163190565b34801561022d57600080fd5b5044610107565b61012d610242366004610a85565b6106ab565b34801561025357600080fd5b5045610107565b34801561026657600080fd5b50604051418152602001610111565b61012d610283366004610c60565b61085a565b6101b7610296366004610a85565b610a1a565b3480156102a757600080fd5b506101076102b6366004610d18565b4090565b60606000828067ffffffffffffffff8111156102d8576102d8610d31565b60405190808252806020026020018201604052801561031e57816020015b6040805180820190915260008152606060208201528152602001906001900390816102f65790505b5092503660005b8281101561047757600085828151811061034157610341610d60565b6020026020010151905087878381811061035d5761035d610d60565b905060200281019061036f9190610d8f565b6040810135958601959093506103886020850185610ce2565b73ffffffffffffffffffffffffffffffffffffffff16816103ac6060870187610dcd565b6040516103ba929190610e32565b60006040518083038185875af1925050503d80600081146103f7576040519150601f19603f3d011682016040523d82523d6000602084013e6103fc565b606091505b50602080850191909152901515808452908501351761046d577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260846000fd5b5050600101610325565b508234146104e6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f4d756c746963616c6c333a2076616c7565206d69736d6174636800000000000060448201526064015b60405180910390fd5b50505092915050565b436060828067ffffffffffffffff81111561050c5761050c610d31565b60405190808252806020026020018201604052801561053f57816020015b606081526020019060019003908161052a5790505b5091503660005b8281101561068657600087878381811061056257610562610d60565b90506020028101906105749190610e42565b92506105836020840184610ce2565b73ffffffffffffffffffffffffffffffffffffffff166105a66020850185610dcd565b6040516105b4929190610e32565b6000604051808303816000865af19150503d80600081146105f1576040519150601f19603f3d011682016040523d82523d6000602084013e6105f6565b606091505b5086848151811061060957610609610d60565b602090810291909101015290508061067d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060448201526064016104dd565b50600101610546565b5050509250929050565b43804060606106a086868661085a565b905093509350939050565b6060818067ffffffffffffffff8111156106c7576106c7610d31565b60405190808252806020026020018201604052801561070d57816020015b6040805180820190915260008152606060208201528152602001906001900390816106e55790505b5091503660005b828110156104e657600084828151811061073057610730610d60565b6020026020010151905086868381811061074c5761074c610d60565b905060200281019061075e9190610e76565b925061076d6020840184610ce2565b73ffffffffffffffffffffffffffffffffffffffff166107906040850185610dcd565b60405161079e929190610e32565b6000604051808303816000865af19150503d80600081146107db576040519150601f19603f3d011682016040523d82523d6000602084013e6107e0565b606091505b506020808401919091529015158083529084013517610851577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260646000fd5b50600101610714565b6060818067ffffffffffffffff81111561087657610876610d31565b6040519080825280602002602001820160405280156108bc57816020015b6040805180820190915260008152606060208201528152602001906001900390816108945790505b5091503660005b82811015610a105760008482815181106108df576108df610d60565b602002602001015190508686838181106108fb576108fb610d60565b905060200281019061090d9190610e42565b925061091c6020840184610ce2565b73ffffffffffffffffffffffffffffffffffffffff1661093f6020850185610dcd565b60405161094d929190610e32565b6000604051808303816000865af19150503d806000811461098a576040519150601f19603f3d011682016040523d82523d6000602084013e61098f565b606091505b506020830152151581528715610a07578051610a07576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060448201526064016104dd565b506001016108c3565b5050509392505050565b6000806060610a2b60018686610690565b919790965090945092505050565b60008083601f840112610a4b57600080fd5b50813567ffffffffffffffff811115610a6357600080fd5b6020830191508360208260051b8501011115610a7e57600080fd5b9250929050565b60008060208385031215610a9857600080fd5b823567ffffffffffffffff811115610aaf57600080fd5b610abb85828601610a39565b90969095509350505050565b6000815180845260005b81811015610aed57602081850181015186830182015201610ad1565b81811115610aff576000602083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b600082825180855260208086019550808260051b84010181860160005b84811015610bb1578583037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001895281518051151584528401516040858501819052610b9d81860183610ac7565b9a86019a9450505090830190600101610b4f565b5090979650505050505050565b602081526000610bd16020830184610b32565b9392505050565b600060408201848352602060408185015281855180845260608601915060608160051b870101935082870160005b82811015610c52577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa0888703018452610c40868351610ac7565b95509284019290840190600101610c06565b509398975050505050505050565b600080600060408486031215610c7557600080fd5b83358015158114610c8557600080fd5b9250602084013567ffffffffffffffff811115610ca157600080fd5b610cad86828701610a39565b9497909650939450505050565b838152826020820152606060408201526000610cd96060830184610b32565b95945050505050565b600060208284031215610cf457600080fd5b813573ffffffffffffffffffffffffffffffffffffffff81168114610bd157600080fd5b600060208284031215610d2a57600080fd5b5035919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81833603018112610dc357600080fd5b9190910192915050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112610e0257600080fd5b83018035915067ffffffffffffffff821115610e1d57600080fd5b602001915036819003821315610a7e57600080fd5b8183823760009101908152919050565b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc1833603018112610dc357600080fd5b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa1833603018112610dc357600080fdfea2646970667358221220bb2b5c71a328032f97c676ae39a1ec2148d3e5d6f73d95e9b17910152d61f16264736f6c634300080c00331ca0edce47092c0f398cebf3ffc267f05c8e7076e3b89445e0fe50f6332273d4569ba01b0b9d000e19b24c5869b0fc3b22b0d6fa47cd63316875cbbd577d76e6fde086';
285
+
286
+ const deployTx = await l1Client.sendRawTransaction({
287
+ serializedTransaction: tx,
288
+ });
289
+ const deployTxReceipt = await l1Client.waitForTransactionReceipt({ hash: deployTx });
290
+ if (deployTxReceipt.status !== 'success') {
291
+ logger.error('Failed to deploy Multicall3', undefined, { deployTxReceipt });
292
+ throw new Error('Failed to deploy Multicall3');
293
+ } else {
294
+ logger.info('Deployed Multicall3');
295
+ }
296
+ }
@@ -0,0 +1,132 @@
1
+ import type { EpochNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { EthAddress } from '@aztec/foundation/eth-address';
4
+ import { OutboxAbi } from '@aztec/l1-artifacts/OutboxAbi';
5
+
6
+ import { type GetContractReturnType, type Hex, encodeAbiParameters, getContract, hexToBigInt, keccak256 } from 'viem';
7
+
8
+ import { getPublicClient } from '../client.js';
9
+ import type { DeployAztecL1ContractsReturnType } from '../deploy_aztec_l1_contracts.js';
10
+ import type { L1ReaderConfig } from '../l1_reader.js';
11
+ import { type ExtendedViemWalletClient, type ViemClient, isExtendedClient } from '../types.js';
12
+
13
+ export type ViemL1Actor = {
14
+ actor: Hex;
15
+ chainId: bigint;
16
+ };
17
+
18
+ export type ViemL2Actor = {
19
+ actor: Hex;
20
+ version: bigint;
21
+ };
22
+
23
+ export type ViemL2ToL1Msg = {
24
+ sender: ViemL2Actor;
25
+ recipient: ViemL1Actor;
26
+ content: Hex;
27
+ };
28
+
29
+ export class OutboxContract {
30
+ private readonly outbox: GetContractReturnType<typeof OutboxAbi, ViemClient>;
31
+
32
+ static getFromL1ContractsValues(deployL1ContractsValues: DeployAztecL1ContractsReturnType) {
33
+ const {
34
+ l1Client,
35
+ l1ContractAddresses: { outboxAddress },
36
+ } = deployL1ContractsValues;
37
+ return new OutboxContract(l1Client, outboxAddress.toString());
38
+ }
39
+
40
+ static getFromConfig(config: L1ReaderConfig) {
41
+ const client = getPublicClient(config);
42
+ const address = config.outboxAddress.toString();
43
+ return new OutboxContract(client, address);
44
+ }
45
+
46
+ /**
47
+ * Storage slot of `epochs[epoch].roots[numCheckpointsInEpoch - 1]` in the Outbox contract.
48
+ *
49
+ * The Outbox lays out storage as `mapping(Epoch => EpochData) internal epochs` at base slot 0
50
+ * (ROLLUP and VERSION are immutable and do not occupy slots). For a mapping at slot `b`, the
51
+ * value for key `k` begins at `keccak256(abi.encode(k, b))`. `EpochData` starts with a fixed-
52
+ * size `bytes32[MAX_CHECKPOINTS_PER_EPOCH] roots` array, so `roots[i]` sits at the EpochData's
53
+ * base slot plus `i`. `numCheckpointsInEpoch` is 1-indexed (matches `Outbox.insert`/`consume`).
54
+ */
55
+ static getEpochRootStorageSlot(epoch: EpochNumber, numCheckpointsInEpoch: number) {
56
+ const epochDataSlot = hexToBigInt(
57
+ keccak256(encodeAbiParameters([{ type: 'uint256' }, { type: 'uint256' }], [BigInt(epoch), 0n])),
58
+ );
59
+ return epochDataSlot + BigInt(numCheckpointsInEpoch - 1);
60
+ }
61
+
62
+ constructor(
63
+ public readonly client: ViemClient,
64
+ address: Hex | EthAddress,
65
+ ) {
66
+ if (address instanceof EthAddress) {
67
+ address = address.toString();
68
+ }
69
+ this.outbox = getContract({ address, abi: OutboxAbi, client });
70
+ }
71
+
72
+ public get address() {
73
+ return this.outbox.address;
74
+ }
75
+
76
+ public getContract(): GetContractReturnType<typeof OutboxAbi, ViemClient> {
77
+ return this.outbox;
78
+ }
79
+
80
+ public hasMessageBeenConsumedAtEpoch(epoch: EpochNumber, leafId: bigint) {
81
+ return this.outbox.read.hasMessageBeenConsumedAtEpoch([BigInt(epoch), leafId]);
82
+ }
83
+
84
+ public getRootData(epoch: EpochNumber, numCheckpointsInEpoch: number) {
85
+ return this.outbox.read.getRootData([BigInt(epoch), BigInt(numCheckpointsInEpoch)]);
86
+ }
87
+
88
+ /**
89
+ * Returns every root stored for `epoch`. Slot `i` of the returned array holds the root inserted
90
+ * for `numCheckpointsInEpoch = i + 1`, or `Fr.ZERO` if no proof of that depth has been inserted
91
+ * yet. The array length is always `MAX_CHECKPOINTS_PER_EPOCH`.
92
+ *
93
+ * @param opts - Optional viem read options. Pass `blockNumber` to pin the read to a specific L1
94
+ * block, which is important for callers that want a consistent snapshot across multiple reads
95
+ * (e.g. the archiver's outbox-trees resolver, which pins to the node's synced L1 block).
96
+ */
97
+ public async getRoots(epoch: EpochNumber, opts?: { blockNumber?: bigint }): Promise<Fr[]> {
98
+ const raw = await this.outbox.read.getRoots([BigInt(epoch)], opts);
99
+ return raw.map(hex => Fr.fromString(hex));
100
+ }
101
+
102
+ public consume(
103
+ message: ViemL2ToL1Msg,
104
+ epoch: EpochNumber,
105
+ numCheckpointsInEpoch: number,
106
+ leafIndex: bigint,
107
+ path: Hex[],
108
+ ) {
109
+ const wallet = this.assertWallet();
110
+ return wallet.write.consume([message, BigInt(epoch), BigInt(numCheckpointsInEpoch), leafIndex, path]);
111
+ }
112
+
113
+ public async getMessageConsumedEvents(
114
+ l1BlockHash: Hex,
115
+ ): Promise<{ epoch: bigint; root: Hex; messageHash: Hex; leafId: bigint; numCheckpointsInEpoch: bigint }[]> {
116
+ const events = await this.outbox.getEvents.MessageConsumed({}, { blockHash: l1BlockHash, strict: true });
117
+ return events.map(event => ({
118
+ epoch: event.args.epoch!,
119
+ root: event.args.root!,
120
+ messageHash: event.args.messageHash!,
121
+ leafId: event.args.leafId!,
122
+ numCheckpointsInEpoch: event.args.numCheckpointsInEpoch!,
123
+ }));
124
+ }
125
+
126
+ private assertWallet(): GetContractReturnType<typeof OutboxAbi, ExtendedViemWalletClient> {
127
+ if (!isExtendedClient(this.client)) {
128
+ throw new Error('Wallet client is required for this operation');
129
+ }
130
+ return this.outbox as GetContractReturnType<typeof OutboxAbi, ExtendedViemWalletClient>;
131
+ }
132
+ }
@@ -1,26 +1,25 @@
1
1
  import { EthAddress } from '@aztec/foundation/eth-address';
2
+ import { createLogger } from '@aztec/foundation/log';
2
3
  import { RegistryAbi } from '@aztec/l1-artifacts/RegistryAbi';
3
4
  import { TestERC20Abi } from '@aztec/l1-artifacts/TestERC20Abi';
4
5
 
5
- import {
6
- type Chain,
7
- type GetContractReturnType,
8
- type Hex,
9
- type HttpTransport,
10
- type PublicClient,
11
- getContract,
12
- } from 'viem';
6
+ import { type GetContractReturnType, type Hex, getAbiItem, getContract } from 'viem';
13
7
 
14
8
  import type { L1ContractAddresses } from '../l1_contract_addresses.js';
15
- import type { L1Clients, ViemPublicClient } from '../types.js';
16
- import { GovernanceContract } from './governance.js';
9
+ import type { ViemClient } from '../types.js';
10
+ import { ReadOnlyGovernanceContract } from './governance.js';
17
11
  import { RollupContract } from './rollup.js';
18
12
 
19
13
  export class RegistryContract {
20
14
  public address: EthAddress;
21
- private readonly registry: GetContractReturnType<typeof RegistryAbi, PublicClient<HttpTransport, Chain>>;
22
15
 
23
- constructor(public readonly client: L1Clients['publicClient'], address: Hex | EthAddress) {
16
+ private readonly log = createLogger('ethereum:contracts:registry');
17
+ private readonly registry: GetContractReturnType<typeof RegistryAbi, ViemClient>;
18
+
19
+ constructor(
20
+ public readonly client: ViemClient,
21
+ address: Hex | EthAddress,
22
+ ) {
24
23
  if (address instanceof EthAddress) {
25
24
  address = address.toString();
26
25
  }
@@ -28,6 +27,10 @@ export class RegistryContract {
28
27
  this.registry = getContract({ address, abi: RegistryAbi, client });
29
28
  }
30
29
 
30
+ public async getOwner(): Promise<EthAddress> {
31
+ return EthAddress.fromString(await this.registry.read.owner());
32
+ }
33
+
31
34
  /**
32
35
  * Returns the address of the rollup for a given version.
33
36
  * @param version - The version of the rollup. 'canonical' can be used to get the canonical address (i.e. the latest version).
@@ -42,12 +45,19 @@ export class RegistryContract {
42
45
  version = BigInt(version);
43
46
  }
44
47
 
45
- const snapshot = await this.registry.read.getSnapshot([version]);
46
- const address = EthAddress.fromString(snapshot.rollup);
47
- if (address.equals(EthAddress.ZERO)) {
48
+ try {
49
+ return EthAddress.fromString(await this.registry.read.getRollup([version]));
50
+ } catch {
51
+ this.log.warn(`Failed fetching rollup address for version ${version}. Retrying as index.`);
52
+ }
53
+
54
+ try {
55
+ const actualVersion = await this.registry.read.getVersion([version]);
56
+ const rollupAddress = await this.registry.read.getRollup([actualVersion]);
57
+ return EthAddress.fromString(rollupAddress);
58
+ } catch {
48
59
  throw new Error('Rollup address is undefined');
49
60
  }
50
- return address;
51
61
  }
52
62
 
53
63
  /**
@@ -55,28 +65,23 @@ export class RegistryContract {
55
65
  * @returns The canonical address of the rollup. If the rollup is not set, throws an error.
56
66
  */
57
67
  public async getCanonicalAddress(): Promise<EthAddress> {
58
- const snapshot = await this.registry.read.getCurrentSnapshot();
59
- const address = EthAddress.fromString(snapshot.rollup);
60
- if (address.equals(EthAddress.ZERO)) {
61
- throw new Error('Rollup address is undefined');
62
- }
63
- return address;
68
+ return EthAddress.fromString(await this.registry.read.getCanonicalRollup());
64
69
  }
65
70
 
66
71
  public async getGovernanceAddresses(): Promise<
67
72
  Pick<L1ContractAddresses, 'governanceProposerAddress' | 'governanceAddress'>
68
73
  > {
69
74
  const governanceAddress = await this.registry.read.getGovernance();
70
- const governance = new GovernanceContract(governanceAddress, this.client, undefined);
71
- const governanceProposer = await governance.getProposer();
75
+ const governance = new ReadOnlyGovernanceContract(governanceAddress, this.client);
76
+ const governanceProposerAddress = await governance.getGovernanceProposerAddress();
72
77
  return {
73
78
  governanceAddress: governance.address,
74
- governanceProposerAddress: governanceProposer.address,
79
+ governanceProposerAddress: governanceProposerAddress,
75
80
  };
76
81
  }
77
82
 
78
83
  public static async collectAddresses(
79
- client: ViemPublicClient,
84
+ client: ViemClient,
80
85
  registryAddress: Hex | EthAddress,
81
86
  rollupVersion: number | bigint | 'canonical',
82
87
  ): Promise<L1ContractAddresses> {
@@ -103,4 +108,54 @@ export class RegistryContract {
103
108
  coinIssuerAddress: EthAddress.fromString(coinIssuer),
104
109
  };
105
110
  }
111
+
112
+ public async getNumberOfVersions(): Promise<number> {
113
+ const version = await this.registry.read.numberOfVersions();
114
+ return Number(version);
115
+ }
116
+
117
+ public async getRollupVersions(): Promise<bigint[]> {
118
+ const count = await this.getNumberOfVersions();
119
+
120
+ const versions: bigint[] = [];
121
+ for (let i = 0; i < count; i++) {
122
+ versions.push(await this.registry.read.getVersion([BigInt(i)]));
123
+ }
124
+
125
+ return versions;
126
+ }
127
+
128
+ public async getRewardDistributor(): Promise<EthAddress> {
129
+ return EthAddress.fromString(await this.registry.read.getRewardDistributor());
130
+ }
131
+
132
+ /** Returns the L1 timestamp at which the given rollup was registered via addRollup(). */
133
+ public async getCanonicalRollupRegistrationTimestamp(
134
+ rollupAddress: EthAddress,
135
+ fromBlock?: bigint,
136
+ ): Promise<bigint | undefined> {
137
+ const event = getAbiItem({ abi: RegistryAbi, name: 'CanonicalRollupUpdated' });
138
+ const start = fromBlock ?? 0n;
139
+ const latestBlock = await this.client.getBlockNumber();
140
+ const chunkSize = 1_000n;
141
+
142
+ for (let from = start; from <= latestBlock; from += chunkSize) {
143
+ const to = from + chunkSize - 1n > latestBlock ? latestBlock : from + chunkSize - 1n;
144
+ const logs = await this.client.getLogs({
145
+ address: this.address.toString(),
146
+ fromBlock: from,
147
+ toBlock: to,
148
+ strict: true,
149
+ event,
150
+ args: { instance: rollupAddress.toString() },
151
+ });
152
+
153
+ if (logs.length > 0) {
154
+ const block = await this.client.getBlock({ blockNumber: logs[0].blockNumber });
155
+ return block.timestamp;
156
+ }
157
+ }
158
+
159
+ return undefined;
160
+ }
106
161
  }