@aztec/ethereum 0.0.0-test.0 → 0.0.1-commit.001888fc

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 (289) 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 +14 -4
  6. package/dest/client.d.ts.map +1 -1
  7. package/dest/client.js +27 -3
  8. package/dest/config.d.ts +70 -23
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +155 -34
  11. package/dest/constants.d.ts +1 -1
  12. package/dest/contracts/empire_base.d.ts +27 -8
  13. package/dest/contracts/empire_base.d.ts.map +1 -1
  14. package/dest/contracts/empire_base.js +75 -2
  15. package/dest/contracts/empire_slashing_proposer.d.ts +69 -0
  16. package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -0
  17. package/dest/contracts/empire_slashing_proposer.js +216 -0
  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 +101 -0
  25. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  26. package/dest/contracts/fee_asset_price_oracle.js +651 -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 +45 -32
  31. package/dest/contracts/governance.d.ts.map +1 -1
  32. package/dest/contracts/governance.js +98 -85
  33. package/dest/contracts/governance_proposer.d.ts +19 -13
  34. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  35. package/dest/contracts/governance_proposer.js +441 -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 +80 -0
  42. package/dest/contracts/index.d.ts +12 -3
  43. package/dest/contracts/index.d.ts.map +1 -1
  44. package/dest/contracts/index.js +11 -2
  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 +21 -0
  49. package/dest/contracts/multicall.d.ts.map +1 -0
  50. package/dest/contracts/multicall.js +157 -0
  51. package/dest/contracts/outbox.d.ts +41 -0
  52. package/dest/contracts/outbox.d.ts.map +1 -0
  53. package/dest/contracts/outbox.js +86 -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 +311 -53
  58. package/dest/contracts/rollup.d.ts.map +1 -1
  59. package/dest/contracts/rollup.js +1180 -116
  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/tally_slashing_proposer.d.ts +140 -0
  64. package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -0
  65. package/dest/contracts/tally_slashing_proposer.js +320 -0
  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 +259 -0
  70. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  71. package/dest/deploy_aztec_l1_contracts.js +413 -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 +81744 -0
  88. package/dest/l1_artifacts.d.ts.map +1 -0
  89. package/dest/l1_artifacts.js +166 -0
  90. package/dest/l1_contract_addresses.d.ts +24 -4
  91. package/dest/l1_contract_addresses.d.ts.map +1 -1
  92. package/dest/l1_contract_addresses.js +25 -21
  93. package/dest/l1_reader.d.ts +6 -2
  94. package/dest/l1_reader.d.ts.map +1 -1
  95. package/dest/l1_reader.js +20 -9
  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 +105 -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 +639 -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 +327 -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 +56 -0
  142. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  143. package/dest/l1_tx_utils/tx_delayer.js +221 -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 +16 -0
  154. package/dest/publisher_manager.d.ts.map +1 -0
  155. package/dest/publisher_manager.js +88 -0
  156. package/dest/queries.d.ts +5 -3
  157. package/dest/queries.d.ts.map +1 -1
  158. package/dest/queries.js +61 -12
  159. package/dest/test/chain_monitor.d.ts +94 -0
  160. package/dest/test/chain_monitor.d.ts.map +1 -0
  161. package/dest/test/chain_monitor.js +244 -0
  162. package/dest/test/eth_cheat_codes.d.ts +229 -0
  163. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  164. package/dest/test/eth_cheat_codes.js +560 -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 +90 -0
  172. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  173. package/dest/test/rollup_cheat_codes.js +292 -0
  174. package/dest/test/start_anvil.d.ts +23 -2
  175. package/dest/test/start_anvil.d.ts.map +1 -1
  176. package/dest/test/start_anvil.js +133 -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 +17 -3
  184. package/dest/utils.d.ts.map +1 -1
  185. package/dest/utils.js +111 -88
  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 +51 -25
  190. package/src/account.ts +5 -0
  191. package/src/client.ts +51 -5
  192. package/src/config.ts +222 -43
  193. package/src/contracts/README.md +157 -0
  194. package/src/contracts/empire_base.ts +79 -7
  195. package/src/contracts/empire_slashing_proposer.ts +265 -0
  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 +280 -0
  199. package/src/contracts/fee_juice.ts +29 -15
  200. package/src/contracts/governance.ts +90 -78
  201. package/src/contracts/governance_proposer.ts +81 -25
  202. package/src/contracts/gse.ts +88 -0
  203. package/src/contracts/inbox.ts +115 -0
  204. package/src/contracts/index.ts +11 -2
  205. package/src/contracts/log.ts +13 -0
  206. package/src/contracts/multicall.ts +158 -0
  207. package/src/contracts/outbox.ts +98 -0
  208. package/src/contracts/registry.ts +81 -26
  209. package/src/contracts/rollup.ts +940 -89
  210. package/src/contracts/slasher_contract.ts +89 -0
  211. package/src/contracts/tally_slashing_proposer.ts +322 -0
  212. package/src/contracts/utils.ts +14 -0
  213. package/src/deploy_aztec_l1_contracts.ts +650 -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 +254 -0
  220. package/src/l1_contract_addresses.ts +49 -34
  221. package/src/l1_reader.ts +30 -10
  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 +766 -0
  236. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +423 -0
  237. package/src/l1_tx_utils/signer.ts +28 -0
  238. package/src/l1_tx_utils/tx_delayer.ts +294 -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 +108 -0
  243. package/src/queries.ts +82 -16
  244. package/src/test/chain_monitor.ts +302 -0
  245. package/src/test/eth_cheat_codes.ts +588 -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 +330 -0
  249. package/src/test/start_anvil.ts +166 -22
  250. package/src/test/upgrade_utils.ts +30 -21
  251. package/src/types.ts +71 -7
  252. package/src/utils.ts +137 -93
  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/contracts/slashing_proposer.d.ts +0 -21
  258. package/dest/contracts/slashing_proposer.d.ts.map +0 -1
  259. package/dest/contracts/slashing_proposer.js +0 -47
  260. package/dest/deploy_l1_contracts.d.ts +0 -21210
  261. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  262. package/dest/deploy_l1_contracts.js +0 -687
  263. package/dest/eth_cheat_codes.d.ts +0 -147
  264. package/dest/eth_cheat_codes.d.ts.map +0 -1
  265. package/dest/eth_cheat_codes.js +0 -303
  266. package/dest/index.d.ts +0 -14
  267. package/dest/index.d.ts.map +0 -1
  268. package/dest/index.js +0 -13
  269. package/dest/l1_tx_utils.d.ts +0 -192
  270. package/dest/l1_tx_utils.d.ts.map +0 -1
  271. package/dest/l1_tx_utils.js +0 -641
  272. package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
  273. package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
  274. package/dest/l1_tx_utils_with_blobs.js +0 -64
  275. package/dest/test/delayed_tx_utils.d.ts +0 -8
  276. package/dest/test/delayed_tx_utils.d.ts.map +0 -1
  277. package/dest/test/delayed_tx_utils.js +0 -21
  278. package/dest/test/tx_delayer.d.ts +0 -25
  279. package/dest/test/tx_delayer.d.ts.map +0 -1
  280. package/dest/test/tx_delayer.js +0 -116
  281. package/src/contracts/forwarder.ts +0 -132
  282. package/src/contracts/slashing_proposer.ts +0 -51
  283. package/src/deploy_l1_contracts.ts +0 -948
  284. package/src/eth_cheat_codes.ts +0 -314
  285. package/src/index.ts +0 -13
  286. package/src/l1_tx_utils.ts +0 -847
  287. package/src/l1_tx_utils_with_blobs.ts +0 -86
  288. package/src/test/delayed_tx_utils.ts +0 -24
  289. package/src/test/tx_delayer.ts +0 -163
@@ -1,17 +1,50 @@
1
+ import { CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
+ import { Buffer32 } from '@aztec/foundation/buffer';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
1
4
  import { memoize } from '@aztec/foundation/decorators';
2
5
  import { EthAddress } from '@aztec/foundation/eth-address';
3
6
  import type { ViemSignature } from '@aztec/foundation/eth-signature';
4
- import { RollupAbi, RollupStorage, SlasherAbi } from '@aztec/l1-artifacts';
7
+ import { makeBackoff, retry } from '@aztec/foundation/retry';
8
+ import { EscapeHatchAbi } from '@aztec/l1-artifacts/EscapeHatchAbi';
9
+ import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
10
+ import { RollupStorage } from '@aztec/l1-artifacts/RollupStorage';
5
11
 
6
- import { type Account, type GetContractReturnType, type Hex, getAddress, getContract } from 'viem';
12
+ import chunk from 'lodash.chunk';
13
+ import {
14
+ type Account,
15
+ type GetContractReturnType,
16
+ type Hex,
17
+ type StateOverride,
18
+ type WatchContractEventReturnType,
19
+ encodeFunctionData,
20
+ getContract,
21
+ hexToBigInt,
22
+ keccak256,
23
+ } from 'viem';
7
24
 
8
25
  import { getPublicClient } from '../client.js';
9
- import type { DeployL1ContractsReturnType } from '../deploy_l1_contracts.js';
26
+ import type { DeployAztecL1ContractsReturnType } from '../deploy_aztec_l1_contracts.js';
10
27
  import type { L1ContractAddresses } from '../l1_contract_addresses.js';
11
28
  import type { L1ReaderConfig } from '../l1_reader.js';
12
- import type { ViemPublicClient } from '../types.js';
29
+ import type { L1TxRequest, L1TxUtils } from '../l1_tx_utils/index.js';
30
+ import type { ViemClient } from '../types.js';
13
31
  import { formatViemError } from '../utils.js';
14
- import { SlashingProposerContract } from './slashing_proposer.js';
32
+ import { EmpireSlashingProposerContract } from './empire_slashing_proposer.js';
33
+ import { GSEContract } from './gse.js';
34
+ import type { L1EventLog } from './log.js';
35
+ import { SlasherContract } from './slasher_contract.js';
36
+ import { TallySlashingProposerContract } from './tally_slashing_proposer.js';
37
+ import { checkBlockTag } from './utils.js';
38
+
39
+ export type ViemCommitteeAttestation = {
40
+ addr: `0x${string}`;
41
+ signature: ViemSignature;
42
+ };
43
+
44
+ export type ViemCommitteeAttestations = {
45
+ signatureIndices: `0x${string}`;
46
+ signaturesOrAddresses: `0x${string}`;
47
+ };
15
48
 
16
49
  export type L1RollupContractAddresses = Pick<
17
50
  L1ContractAddresses,
@@ -23,20 +56,168 @@ export type L1RollupContractAddresses = Pick<
23
56
  | 'stakingAssetAddress'
24
57
  | 'rewardDistributorAddress'
25
58
  | 'slashFactoryAddress'
59
+ | 'gseAddress'
26
60
  >;
27
61
 
28
62
  export type EpochProofPublicInputArgs = {
29
63
  previousArchive: `0x${string}`;
30
64
  endArchive: `0x${string}`;
31
- previousBlockHash: `0x${string}`;
32
- endBlockHash: `0x${string}`;
33
- endTimestamp: bigint;
34
65
  outHash: `0x${string}`;
35
66
  proverId: `0x${string}`;
36
67
  };
37
68
 
69
+ export type ViemHeader = {
70
+ lastArchiveRoot: `0x${string}`;
71
+ blockHeadersHash: `0x${string}`;
72
+ blobsHash: `0x${string}`;
73
+ inHash: `0x${string}`;
74
+ outHash: `0x${string}`;
75
+ slotNumber: bigint;
76
+ timestamp: bigint;
77
+ coinbase: `0x${string}`;
78
+ feeRecipient: `0x${string}`;
79
+ gasFees: ViemGasFees;
80
+ totalManaUsed: bigint;
81
+ };
82
+
83
+ export type ViemGasFees = {
84
+ feePerDaGas: bigint;
85
+ feePerL2Gas: bigint;
86
+ };
87
+
88
+ export enum SlashingProposerType {
89
+ None = 0,
90
+ Tally = 1,
91
+ Empire = 2,
92
+ }
93
+
94
+ /**
95
+ * Status of a validator/attester in the staking system.
96
+ * Matches the Status enum in StakingLib.sol
97
+ */
98
+ export enum AttesterStatus {
99
+ NONE = 0,
100
+ VALIDATING = 1,
101
+ ZOMBIE = 2,
102
+ EXITING = 3,
103
+ }
104
+
105
+ /**
106
+ * Fee header data for a checkpoint
107
+ */
108
+ export type FeeHeader = {
109
+ excessMana: bigint;
110
+ manaUsed: bigint;
111
+ ethPerFeeAsset: bigint;
112
+ congestionCost: bigint;
113
+ proverCost: bigint;
114
+ };
115
+
116
+ /**
117
+ * Checkpoint log data returned from the rollup contract
118
+ */
119
+ export type CheckpointLog = {
120
+ archive: Fr;
121
+ headerHash: Buffer32;
122
+ blobCommitmentsHash: Buffer32;
123
+ attestationsHash: Buffer32;
124
+ payloadDigest: Buffer32;
125
+ slotNumber: SlotNumber;
126
+ feeHeader: FeeHeader;
127
+ };
128
+
129
+ /**
130
+ * L1 fee data (base fee and blob fee)
131
+ */
132
+ export type L1FeeData = {
133
+ baseFee: bigint;
134
+ blobFee: bigint;
135
+ };
136
+
137
+ /** Components of the minimum fee per mana, as returned by the L1 rollup contract. */
138
+ export type ManaMinFeeComponents = {
139
+ sequencerCost: bigint;
140
+ proverCost: bigint;
141
+ congestionCost: bigint;
142
+ congestionMultiplier: bigint;
143
+ };
144
+
145
+ /**
146
+ * Reward configuration for the rollup
147
+ */
148
+ export type RewardConfig = {
149
+ rewardDistributor: EthAddress;
150
+ sequencerBps: bigint;
151
+ booster: EthAddress;
152
+ checkpointReward: bigint;
153
+ };
154
+
155
+ /**
156
+ * Exit information for a validator
157
+ */
158
+ export type Exit = {
159
+ withdrawalId: bigint;
160
+ amount: bigint;
161
+ exitableAt: bigint;
162
+ recipientOrWithdrawer: EthAddress;
163
+ isRecipient: boolean;
164
+ exists: boolean;
165
+ };
166
+
167
+ /**
168
+ * Attester configuration including public key and withdrawer
169
+ */
170
+ export type AttesterConfig = {
171
+ publicKey: {
172
+ x: bigint;
173
+ y: bigint;
174
+ };
175
+ withdrawer: EthAddress;
176
+ };
177
+
178
+ /**
179
+ * Complete view of an attester's state
180
+ */
181
+ export type AttesterView = {
182
+ status: AttesterStatus;
183
+ effectiveBalance: bigint;
184
+ exit: Exit;
185
+ config: AttesterConfig;
186
+ };
187
+
188
+ /**
189
+ * Return for a status call
190
+ */
191
+ export type RollupStatusResponse = {
192
+ provenCheckpointNumber: CheckpointNumber;
193
+ provenArchive: Fr;
194
+ pendingCheckpointNumber: CheckpointNumber;
195
+ pendingArchive: Fr;
196
+ archiveOfMyCheckpoint: Fr;
197
+ };
198
+
199
+ /** Arguments for the CheckpointProposed event. */
200
+ export type CheckpointProposedArgs = {
201
+ checkpointNumber: CheckpointNumber;
202
+ archive: Fr;
203
+ versionedBlobHashes: Buffer[];
204
+ /** Hash of attestations emitted in the CheckpointProposed event. */
205
+ attestationsHash: Buffer32;
206
+ /** Digest of the payload emitted in the CheckpointProposed event. */
207
+ payloadDigest: Buffer32;
208
+ };
209
+
210
+ /** Log type for CheckpointProposed events. */
211
+ export type CheckpointProposedLog = L1EventLog<CheckpointProposedArgs>;
212
+
38
213
  export class RollupContract {
39
- private readonly rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>;
214
+ private readonly rollup: GetContractReturnType<typeof RollupAbi, ViemClient>;
215
+
216
+ private static cachedStfStorageSlot: Hex | undefined;
217
+ private cachedEscapeHatch?: {
218
+ address: EthAddress;
219
+ contract: GetContractReturnType<typeof EscapeHatchAbi, ViemClient>;
220
+ };
40
221
 
41
222
  static get checkBlobStorageSlot(): bigint {
42
223
  const asString = RollupStorage.find(storage => storage.label === 'checkBlob')?.slot;
@@ -46,12 +227,16 @@ export class RollupContract {
46
227
  return BigInt(asString);
47
228
  }
48
229
 
49
- static getFromL1ContractsValues(deployL1ContractsValues: DeployL1ContractsReturnType) {
230
+ static get stfStorageSlot(): Hex {
231
+ return (RollupContract.cachedStfStorageSlot ??= keccak256(Buffer.from('aztec.stf.storage', 'utf-8')));
232
+ }
233
+
234
+ static getFromL1ContractsValues(deployL1ContractsValues: DeployAztecL1ContractsReturnType) {
50
235
  const {
51
- publicClient,
236
+ l1Client,
52
237
  l1ContractAddresses: { rollupAddress },
53
238
  } = deployL1ContractsValues;
54
- return new RollupContract(publicClient, rollupAddress.toString());
239
+ return new RollupContract(l1Client, rollupAddress.toString());
55
240
  }
56
241
 
57
242
  static getFromConfig(config: L1ReaderConfig) {
@@ -60,121 +245,451 @@ export class RollupContract {
60
245
  return new RollupContract(client, address);
61
246
  }
62
247
 
63
- constructor(public readonly client: ViemPublicClient, address: Hex | EthAddress) {
248
+ constructor(
249
+ public readonly client: ViemClient,
250
+ address: Hex | EthAddress,
251
+ ) {
64
252
  if (address instanceof EthAddress) {
65
253
  address = address.toString();
66
254
  }
67
255
  this.rollup = getContract({ address, abi: RollupAbi, client });
68
256
  }
69
257
 
258
+ async getGSE(): Promise<EthAddress> {
259
+ return EthAddress.fromString(await this.rollup.read.getGSE());
260
+ }
261
+
70
262
  public get address() {
71
263
  return this.rollup.address;
72
264
  }
73
265
 
74
- @memoize
75
- public async getSlashingProposer() {
76
- const slasherAddress = await this.rollup.read.getSlasher();
77
- const slasher = getContract({ address: slasherAddress, abi: SlasherAbi, client: this.client });
78
- const proposerAddress = await slasher.read.PROPOSER();
79
- return new SlashingProposerContract(this.client, proposerAddress);
266
+ getContract(): GetContractReturnType<typeof RollupAbi, ViemClient> {
267
+ return this.rollup;
268
+ }
269
+
270
+ public async getSlashingProposer(): Promise<
271
+ EmpireSlashingProposerContract | TallySlashingProposerContract | undefined
272
+ > {
273
+ const slasher = await this.getSlasherContract();
274
+ if (!slasher) {
275
+ return undefined;
276
+ }
277
+
278
+ const proposerAddress = await slasher.getProposer();
279
+ const proposerAbi = [
280
+ {
281
+ type: 'function',
282
+ name: 'SLASHING_PROPOSER_TYPE',
283
+ inputs: [],
284
+ outputs: [{ name: '', type: 'uint8', internalType: 'enum SlasherFlavor' }],
285
+ stateMutability: 'view',
286
+ },
287
+ ] as const;
288
+
289
+ const proposer = getContract({ address: proposerAddress.toString(), abi: proposerAbi, client: this.client });
290
+ const proposerType = await proposer.read.SLASHING_PROPOSER_TYPE();
291
+ if (proposerType === SlashingProposerType.Tally.valueOf()) {
292
+ return new TallySlashingProposerContract(this.client, proposerAddress);
293
+ } else if (proposerType === SlashingProposerType.Empire.valueOf()) {
294
+ return new EmpireSlashingProposerContract(this.client, proposerAddress);
295
+ } else {
296
+ throw new Error(`Unknown slashing proposer type: ${proposerType}`);
297
+ }
80
298
  }
81
299
 
82
300
  @memoize
83
- getL1StartBlock() {
301
+ getL1StartBlock(): Promise<bigint> {
84
302
  return this.rollup.read.L1_BLOCK_AT_GENESIS();
85
303
  }
86
304
 
87
305
  @memoize
88
- getL1GenesisTime() {
306
+ getL1GenesisTime(): Promise<bigint> {
89
307
  return this.rollup.read.getGenesisTime();
90
308
  }
91
309
 
92
310
  @memoize
93
- getProofSubmissionWindow() {
94
- return this.rollup.read.getProofSubmissionWindow();
311
+ async getProofSubmissionEpochs(): Promise<number> {
312
+ return Number(await this.rollup.read.getProofSubmissionEpochs());
95
313
  }
96
314
 
97
315
  @memoize
98
- getEpochDuration() {
99
- return this.rollup.read.getEpochDuration();
316
+ async getEpochDuration(): Promise<number> {
317
+ return Number(await this.rollup.read.getEpochDuration());
100
318
  }
101
319
 
102
320
  @memoize
103
- getSlotDuration() {
104
- return this.rollup.read.getSlotDuration();
321
+ async getSlotDuration(): Promise<number> {
322
+ return Number(await this.rollup.read.getSlotDuration());
105
323
  }
106
324
 
107
325
  @memoize
108
- getTargetCommitteeSize() {
109
- return this.rollup.read.getTargetCommitteeSize();
326
+ async getTargetCommitteeSize(): Promise<number> {
327
+ return Number(await this.rollup.read.getTargetCommitteeSize());
110
328
  }
111
329
 
112
330
  @memoize
113
- getMinimumStake() {
114
- return this.rollup.read.getMinimumStake();
331
+ getEjectionThreshold(): Promise<bigint> {
332
+ return this.rollup.read.getEjectionThreshold();
333
+ }
334
+
335
+ @memoize
336
+ getLocalEjectionThreshold(): Promise<bigint> {
337
+ return this.rollup.read.getLocalEjectionThreshold();
338
+ }
339
+
340
+ @memoize
341
+ async getLagInEpochsForValidatorSet(): Promise<number> {
342
+ return Number(await this.rollup.read.getLagInEpochsForValidatorSet());
343
+ }
344
+
345
+ @memoize
346
+ async getLagInEpochsForRandao(): Promise<number> {
347
+ return Number(await this.rollup.read.getLagInEpochsForRandao());
348
+ }
349
+
350
+ @memoize
351
+ getActivationThreshold(): Promise<bigint> {
352
+ return this.rollup.read.getActivationThreshold();
353
+ }
354
+
355
+ @memoize
356
+ async getExitDelay(): Promise<number> {
357
+ return Number(await this.rollup.read.getExitDelay());
358
+ }
359
+
360
+ @memoize
361
+ getManaTarget(): Promise<bigint> {
362
+ return this.rollup.read.getManaTarget();
363
+ }
364
+
365
+ @memoize
366
+ getProvingCostPerMana(): Promise<bigint> {
367
+ return this.rollup.read.getProvingCostPerManaInEth();
368
+ }
369
+
370
+ @memoize
371
+ getProvingCostPerManaInFeeAsset(): Promise<bigint> {
372
+ return this.rollup.read.getProvingCostPerManaInFeeAsset();
373
+ }
374
+
375
+ @memoize
376
+ getManaLimit(): Promise<bigint> {
377
+ return this.rollup.read.getManaLimit();
378
+ }
379
+
380
+ @memoize
381
+ getVersion(): Promise<bigint> {
382
+ return this.rollup.read.getVersion();
383
+ }
384
+
385
+ @memoize
386
+ async getGenesisArchiveTreeRoot(): Promise<Fr> {
387
+ return Fr.fromString(await this.rollup.read.archiveAt([0n]));
388
+ }
389
+
390
+ @memoize
391
+ async getVkTreeRoot(): Promise<Fr> {
392
+ const slot = BigInt(RollupContract.stfStorageSlot) + 3n;
393
+ const value = await this.client.getStorageAt({ address: this.address, slot: `0x${slot.toString(16)}` });
394
+ return Fr.fromString(value ?? '0x0');
395
+ }
396
+
397
+ @memoize
398
+ async getProtocolContractsHash(): Promise<Fr> {
399
+ const slot = BigInt(RollupContract.stfStorageSlot) + 4n;
400
+ const value = await this.client.getStorageAt({ address: this.address, slot: `0x${slot.toString(16)}` });
401
+ return Fr.fromString(value ?? '0x0');
402
+ }
403
+
404
+ /**
405
+ * Returns rollup constants used for epoch queries.
406
+ * Return type is `L1RollupConstants` which is defined in stdlib,
407
+ * so we cant reference it until we move this contract to that package.
408
+ */
409
+ @memoize
410
+ public async getRollupConstants(): Promise<{
411
+ l1StartBlock: bigint;
412
+ l1GenesisTime: bigint;
413
+ slotDuration: number;
414
+ epochDuration: number;
415
+ proofSubmissionEpochs: number;
416
+ targetCommitteeSize: number;
417
+ rollupManaLimit: number;
418
+ }> {
419
+ const [
420
+ l1StartBlock,
421
+ l1GenesisTime,
422
+ slotDuration,
423
+ epochDuration,
424
+ proofSubmissionEpochs,
425
+ targetCommitteeSize,
426
+ rollupManaLimit,
427
+ ] = await Promise.all([
428
+ this.getL1StartBlock(),
429
+ this.getL1GenesisTime(),
430
+ this.getSlotDuration(),
431
+ this.getEpochDuration(),
432
+ this.getProofSubmissionEpochs(),
433
+ this.getTargetCommitteeSize(),
434
+ this.getManaLimit(),
435
+ ]);
436
+ return {
437
+ l1StartBlock,
438
+ l1GenesisTime,
439
+ slotDuration,
440
+ epochDuration: Number(epochDuration),
441
+ proofSubmissionEpochs: Number(proofSubmissionEpochs),
442
+ targetCommitteeSize,
443
+ rollupManaLimit: Number(rollupManaLimit),
444
+ };
445
+ }
446
+
447
+ async getSlasherAddress(): Promise<EthAddress> {
448
+ return EthAddress.fromString(await this.rollup.read.getSlasher());
449
+ }
450
+
451
+ /**
452
+ * Returns the configured escape hatch contract address, or zero if disabled.
453
+ */
454
+ async getEscapeHatchAddress(): Promise<EthAddress> {
455
+ return EthAddress.fromString(await this.rollup.read.getEscapeHatch());
456
+ }
457
+
458
+ private async getEscapeHatchContract(): Promise<
459
+ GetContractReturnType<typeof EscapeHatchAbi, ViemClient> | undefined
460
+ > {
461
+ const escapeHatchAddress = await this.getEscapeHatchAddress();
462
+ if (escapeHatchAddress.isZero()) {
463
+ return undefined;
464
+ }
465
+
466
+ // Cache the viem contract wrapper since it will be used frequently.
467
+ if (!this.cachedEscapeHatch || !this.cachedEscapeHatch.address.equals(escapeHatchAddress)) {
468
+ this.cachedEscapeHatch = {
469
+ address: escapeHatchAddress,
470
+ contract: getContract({
471
+ address: escapeHatchAddress.toString(),
472
+ abi: EscapeHatchAbi,
473
+ client: this.client,
474
+ }),
475
+ };
476
+ }
477
+
478
+ return this.cachedEscapeHatch.contract;
479
+ }
480
+
481
+ /**
482
+ * Returns whether the escape hatch is open for the given epoch.
483
+ * If escape hatch is not configured, returns false.
484
+ *
485
+ * This function is intentionally defensive: any failure to query the escape hatch
486
+ * (RPC issues, transient errors, etc.) is treated as "closed" to avoid callers
487
+ * needing to sprinkle try/catch everywhere.
488
+ */
489
+ async isEscapeHatchOpen(epoch: EpochNumber): Promise<boolean> {
490
+ try {
491
+ const escapeHatch = await this.getEscapeHatchContract();
492
+ if (!escapeHatch) {
493
+ return false;
494
+ }
495
+
496
+ const [isOpen] = await escapeHatch.read.isHatchOpen([BigInt(epoch)]);
497
+ return isOpen;
498
+ } catch {
499
+ return false;
500
+ }
501
+ }
502
+
503
+ /**
504
+ * Returns a SlasherContract instance for interacting with the slasher contract.
505
+ */
506
+ async getSlasherContract(): Promise<SlasherContract | undefined> {
507
+ const slasherAddress = await this.getSlasherAddress();
508
+ if (slasherAddress.isZero()) {
509
+ return undefined;
510
+ }
511
+ return new SlasherContract(this.client, slasherAddress);
512
+ }
513
+
514
+ async getOwner(): Promise<EthAddress> {
515
+ return EthAddress.fromString(await this.rollup.read.owner());
516
+ }
517
+
518
+ async getActiveAttesterCount(): Promise<number> {
519
+ return Number(await this.rollup.read.getActiveAttesterCount());
115
520
  }
116
521
 
117
522
  public async getSlashingProposerAddress() {
118
- const slasherAddress = await this.rollup.read.getSlasher();
119
- const slasher = getContract({
120
- address: getAddress(slasherAddress.toString()),
121
- abi: SlasherAbi,
122
- client: this.client,
123
- });
124
- return EthAddress.fromString(await slasher.read.PROPOSER());
523
+ const slasher = await this.getSlasherContract();
524
+ if (!slasher) {
525
+ return EthAddress.ZERO;
526
+ }
527
+ return await slasher.getProposer();
528
+ }
529
+
530
+ getCheckpointReward(): Promise<bigint> {
531
+ return this.rollup.read.getCheckpointReward();
125
532
  }
126
533
 
127
- getBlockNumber() {
128
- return this.rollup.read.getPendingBlockNumber();
534
+ async getCheckpointNumber(): Promise<CheckpointNumber> {
535
+ return CheckpointNumber.fromBigInt(await this.rollup.read.getPendingCheckpointNumber());
129
536
  }
130
537
 
131
- getProvenBlockNumber() {
132
- return this.rollup.read.getProvenBlockNumber();
538
+ async getProvenCheckpointNumber(options?: { blockNumber?: bigint }): Promise<CheckpointNumber> {
539
+ await checkBlockTag(options?.blockNumber, this.client);
540
+ return CheckpointNumber.fromBigInt(await this.rollup.read.getProvenCheckpointNumber(options));
133
541
  }
134
542
 
135
- getSlotNumber() {
136
- return this.rollup.read.getCurrentSlot();
543
+ async getSlotNumber(): Promise<SlotNumber> {
544
+ return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
137
545
  }
138
546
 
139
- getCommitteeAt(timestamp: bigint) {
140
- return this.rollup.read.getCommitteeAt([timestamp]);
547
+ async getL1FeesAt(timestamp: bigint): Promise<L1FeeData> {
548
+ const result = await this.rollup.read.getL1FeesAt([timestamp]);
549
+ return {
550
+ baseFee: result.baseFee,
551
+ blobFee: result.blobFee,
552
+ };
141
553
  }
142
554
 
143
- getSampleSeedAt(timestamp: bigint) {
144
- return this.rollup.read.getSampleSeedAt([timestamp]);
555
+ getEthPerFeeAsset(): Promise<bigint> {
556
+ return this.rollup.read.getEthPerFeeAsset();
145
557
  }
146
558
 
147
- getCurrentSampleSeed() {
148
- return this.rollup.read.getCurrentSampleSeed();
559
+ async getCommitteeAt(timestamp: bigint): Promise<EthAddress[] | undefined> {
560
+ const { result } = await this.client
561
+ .simulateContract({
562
+ address: this.address,
563
+ abi: RollupAbi,
564
+ functionName: 'getCommitteeAt',
565
+ args: [timestamp],
566
+ })
567
+ .catch(e => {
568
+ if (e instanceof Error && e.message.includes('ValidatorSelection__InsufficientValidatorSetSize')) {
569
+ return { result: undefined };
570
+ }
571
+ throw e;
572
+ });
573
+
574
+ return result ? result.map(addr => EthAddress.fromString(addr)) : undefined;
149
575
  }
150
576
 
151
- getCurrentEpochCommittee() {
152
- return this.rollup.read.getCurrentEpochCommittee();
577
+ async getSampleSeedAt(timestamp: bigint): Promise<Buffer32> {
578
+ return Buffer32.fromBigInt(await this.rollup.read.getSampleSeedAt([timestamp]));
153
579
  }
154
580
 
155
- getCurrentProposer() {
156
- return this.rollup.read.getCurrentProposer();
581
+ async getCurrentSampleSeed(): Promise<Buffer32> {
582
+ return Buffer32.fromBigInt(await this.rollup.read.getCurrentSampleSeed());
157
583
  }
158
584
 
159
- getProposerAt(timestamp: bigint) {
160
- return this.rollup.read.getProposerAt([timestamp]);
585
+ async getCurrentEpoch(): Promise<EpochNumber> {
586
+ return EpochNumber.fromBigInt(await this.rollup.read.getCurrentEpoch());
161
587
  }
162
588
 
163
- getBlock(blockNumber: bigint) {
164
- return this.rollup.read.getBlock([blockNumber]);
589
+ async getCurrentEpochCommittee(): Promise<EthAddress[] | undefined> {
590
+ const { result } = await this.client
591
+ .simulateContract({
592
+ address: this.address,
593
+ abi: RollupAbi,
594
+ functionName: 'getCurrentEpochCommittee',
595
+ args: [],
596
+ })
597
+ .catch(e => {
598
+ if (e instanceof Error && e.message.includes('ValidatorSelection__InsufficientValidatorSetSize')) {
599
+ return { result: undefined };
600
+ }
601
+ throw e;
602
+ });
603
+
604
+ return result ? result.map(addr => EthAddress.fromString(addr)) : undefined;
165
605
  }
166
606
 
167
- getTips() {
168
- return this.rollup.read.getTips();
607
+ async getCurrentProposer(): Promise<EthAddress> {
608
+ const { result } = await this.client.simulateContract({
609
+ address: this.address,
610
+ abi: RollupAbi,
611
+ functionName: 'getCurrentProposer',
612
+ args: [],
613
+ });
614
+
615
+ return EthAddress.fromString(result);
169
616
  }
170
617
 
171
- getTimestampForSlot(slot: bigint) {
172
- return this.rollup.read.getTimestampForSlot([slot]);
618
+ async getProposerAt(timestamp: bigint): Promise<EthAddress> {
619
+ const { result } = await this.client.simulateContract({
620
+ address: this.address,
621
+ abi: RollupAbi,
622
+ functionName: 'getProposerAt',
623
+ args: [timestamp],
624
+ });
625
+
626
+ return EthAddress.fromString(result);
173
627
  }
174
628
 
175
- async getEpochNumber(blockNumber?: bigint) {
176
- blockNumber ??= await this.getBlockNumber();
177
- return this.rollup.read.getEpochForBlock([BigInt(blockNumber)]);
629
+ async getCheckpoint(checkpointNumber: CheckpointNumber): Promise<CheckpointLog> {
630
+ const result = await this.rollup.read.getCheckpoint([BigInt(checkpointNumber)]);
631
+ return {
632
+ archive: Fr.fromString(result.archive),
633
+ headerHash: Buffer32.fromString(result.headerHash),
634
+ blobCommitmentsHash: Buffer32.fromString(result.blobCommitmentsHash),
635
+ attestationsHash: Buffer32.fromString(result.attestationsHash),
636
+ payloadDigest: Buffer32.fromString(result.payloadDigest),
637
+ slotNumber: SlotNumber.fromBigInt(result.slotNumber),
638
+ feeHeader: {
639
+ excessMana: result.feeHeader.excessMana,
640
+ manaUsed: result.feeHeader.manaUsed,
641
+ ethPerFeeAsset: result.feeHeader.ethPerFeeAsset,
642
+ congestionCost: result.feeHeader.congestionCost,
643
+ proverCost: result.feeHeader.proverCost,
644
+ },
645
+ };
646
+ }
647
+
648
+ /** Returns the pending checkpoint from the rollup contract */
649
+ getPendingCheckpoint() {
650
+ // We retry because of race conditions during prunes: we may get a pending checkpoint number which is immediately
651
+ // reorged out due to a prune happening, causing the subsequent getCheckpoint call to fail. So we try again in that case.
652
+ return retry(
653
+ async () => {
654
+ const pendingCheckpointNumber = await this.getCheckpointNumber();
655
+ const pendingCheckpoint = await this.getCheckpoint(pendingCheckpointNumber);
656
+ return pendingCheckpoint;
657
+ },
658
+ 'getting pending checkpoint',
659
+ makeBackoff([0.5, 0.5, 0.5]),
660
+ );
661
+ }
662
+
663
+ async getTips(): Promise<{ pending: CheckpointNumber; proven: CheckpointNumber }> {
664
+ const { pending, proven } = await this.rollup.read.getTips();
665
+ return {
666
+ pending: CheckpointNumber.fromBigInt(pending),
667
+ proven: CheckpointNumber.fromBigInt(proven),
668
+ };
669
+ }
670
+
671
+ getTimestampForSlot(slot: SlotNumber): Promise<bigint> {
672
+ return this.rollup.read.getTimestampForSlot([BigInt(slot)]);
673
+ }
674
+
675
+ async getEntryQueueLength(): Promise<number> {
676
+ return Number(await this.rollup.read.getEntryQueueLength());
677
+ }
678
+
679
+ async getAvailableValidatorFlushes(): Promise<number> {
680
+ return Number(await this.rollup.read.getAvailableValidatorFlushes());
681
+ }
682
+
683
+ async getNextFlushableEpoch(): Promise<EpochNumber> {
684
+ return EpochNumber.fromBigInt(await this.rollup.read.getNextFlushableEpoch());
685
+ }
686
+
687
+ async getCurrentEpochNumber(): Promise<EpochNumber> {
688
+ return EpochNumber.fromBigInt(await this.rollup.read.getCurrentEpoch());
689
+ }
690
+
691
+ async getEpochNumberForCheckpoint(checkpointNumber: CheckpointNumber): Promise<EpochNumber> {
692
+ return EpochNumber.fromBigInt(await this.rollup.read.getEpochForCheckpoint([BigInt(checkpointNumber)]));
178
693
  }
179
694
 
180
695
  async getRollupAddresses(): Promise<L1RollupContractAddresses> {
@@ -185,6 +700,7 @@ export class RollupContract {
185
700
  rewardDistributorAddress,
186
701
  feeJuiceAddress,
187
702
  stakingAssetAddress,
703
+ gseAddress,
188
704
  ] = (
189
705
  await Promise.all([
190
706
  this.rollup.read.getInbox(),
@@ -193,6 +709,7 @@ export class RollupContract {
193
709
  this.rollup.read.getRewardDistributor(),
194
710
  this.rollup.read.getFeeAsset(),
195
711
  this.rollup.read.getStakingAsset(),
712
+ this.rollup.read.getGSE(),
196
713
  ] as const)
197
714
  ).map(EthAddress.fromString);
198
715
 
@@ -204,25 +721,32 @@ export class RollupContract {
204
721
  feeJuiceAddress,
205
722
  stakingAssetAddress,
206
723
  rewardDistributorAddress,
724
+ gseAddress,
207
725
  };
208
726
  }
209
727
 
210
- public async getEpochNumberForSlotNumber(slotNumber: bigint): Promise<bigint> {
211
- return await this.rollup.read.getEpochAtSlot([slotNumber]);
728
+ public async getFeeJuicePortal() {
729
+ return EthAddress.fromString(await this.rollup.read.getFeeAssetPortal());
212
730
  }
213
731
 
214
- getEpochProofPublicInputs(
215
- args: readonly [bigint, bigint, EpochProofPublicInputArgs, readonly `0x${string}`[], `0x${string}`, `0x${string}`],
216
- ) {
217
- return this.rollup.read.getEpochProofPublicInputs(args);
732
+ public async getEpochNumberForSlotNumber(slotNumber: SlotNumber): Promise<EpochNumber> {
733
+ return EpochNumber.fromBigInt(await this.rollup.read.getEpochAtSlot([BigInt(slotNumber)]));
734
+ }
735
+
736
+ async getEpochProofPublicInputs(
737
+ args: readonly [bigint, bigint, EpochProofPublicInputArgs, readonly `0x${string}`[], `0x${string}`],
738
+ ): Promise<Fr[]> {
739
+ const result = await this.rollup.read.getEpochProofPublicInputs(args);
740
+ return result.map(Fr.fromString);
218
741
  }
219
742
 
220
743
  public async validateHeader(
221
744
  args: readonly [
745
+ ViemHeader,
746
+ ViemCommitteeAttestations,
747
+ `0x${string}`[],
748
+ ViemSignature,
222
749
  `0x${string}`,
223
- ViemSignature[],
224
- `0x${string}`,
225
- bigint,
226
750
  `0x${string}`,
227
751
  {
228
752
  ignoreDA: boolean;
@@ -232,7 +756,13 @@ export class RollupContract {
232
756
  account: `0x${string}` | Account,
233
757
  ): Promise<void> {
234
758
  try {
235
- await this.rollup.read.validateHeader(args, { account });
759
+ await this.client.simulateContract({
760
+ address: this.address,
761
+ abi: RollupAbi,
762
+ functionName: 'validateHeaderWithAttestations',
763
+ args,
764
+ account,
765
+ });
236
766
  } catch (error: unknown) {
237
767
  throw formatViemError(error);
238
768
  }
@@ -244,31 +774,352 @@ export class RollupContract {
244
774
  * @dev Throws if unable to propose
245
775
  *
246
776
  * @param archive - The archive that we expect to be current state
247
- * @return [slot, blockNumber] - If you can propose, the L2 slot number and L2 block number of the next Ethereum block,
777
+ * @return [slot, checkpointNumber, timeOfNextL1Slot] - If you can propose, the L2 slot number, checkpoint number and
778
+ * timestamp of the next L1 block
248
779
  * @throws otherwise
249
780
  */
250
781
  public async canProposeAtNextEthBlock(
251
782
  archive: Buffer,
252
783
  account: `0x${string}` | Account,
253
- slotDuration: bigint | number,
254
- ): Promise<[bigint, bigint]> {
255
- if (typeof slotDuration === 'number') {
256
- slotDuration = BigInt(slotDuration);
257
- }
258
- const timeOfNextL1Slot = (await this.client.getBlock()).timestamp + slotDuration;
784
+ slotDuration: number,
785
+ opts: { forcePendingCheckpointNumber?: CheckpointNumber } = {},
786
+ ): Promise<{ slot: SlotNumber; checkpointNumber: CheckpointNumber; timeOfNextL1Slot: bigint }> {
787
+ const latestBlock = await this.client.getBlock();
788
+ const timeOfNextL1Slot = latestBlock.timestamp + BigInt(slotDuration);
789
+ const who = typeof account === 'string' ? account : account.address;
790
+
259
791
  try {
260
- const [slot, blockNumber] = await this.rollup.read.canProposeAtTime(
261
- [timeOfNextL1Slot, `0x${archive.toString('hex')}`],
262
- { account },
263
- );
264
- return [slot, blockNumber];
792
+ const {
793
+ result: [slot, checkpointNumber],
794
+ } = await this.client.simulateContract({
795
+ address: this.address,
796
+ abi: RollupAbi,
797
+ functionName: 'canProposeAtTime',
798
+ args: [timeOfNextL1Slot, `0x${archive.toString('hex')}`, who],
799
+ account,
800
+ stateOverride: await this.makePendingCheckpointNumberOverride(opts.forcePendingCheckpointNumber),
801
+ });
802
+
803
+ return {
804
+ slot: SlotNumber.fromBigInt(slot),
805
+ checkpointNumber: CheckpointNumber.fromBigInt(checkpointNumber),
806
+ timeOfNextL1Slot,
807
+ };
265
808
  } catch (err: unknown) {
266
809
  throw formatViemError(err);
267
810
  }
268
811
  }
269
812
 
813
+ /**
814
+ * Returns a state override that sets the pending checkpoint number to the specified value. Useful for simulations.
815
+ * Requires querying the current state of the contract to get the current proven checkpoint number, as they are both
816
+ * stored in the same slot. If the argument is undefined, it returns an empty override.
817
+ */
818
+ public async makePendingCheckpointNumberOverride(
819
+ forcePendingCheckpointNumber: CheckpointNumber | undefined,
820
+ ): Promise<StateOverride> {
821
+ if (forcePendingCheckpointNumber === undefined) {
822
+ return [];
823
+ }
824
+ const slot = RollupContract.stfStorageSlot;
825
+ const currentValue = await this.client.getStorageAt({ address: this.address, slot });
826
+ const currentProvenCheckpointNumber = currentValue ? hexToBigInt(currentValue) & ((1n << 128n) - 1n) : 0n;
827
+ const newValue = (BigInt(forcePendingCheckpointNumber) << 128n) | currentProvenCheckpointNumber;
828
+ return [
829
+ {
830
+ address: this.address,
831
+ stateDiff: [{ slot, value: `0x${newValue.toString(16).padStart(64, '0')}` }],
832
+ },
833
+ ];
834
+ }
835
+
836
+ /** Creates a request to Rollup#invalidateBadAttestation to be simulated or sent */
837
+ public buildInvalidateBadAttestationRequest(
838
+ checkpointNumber: CheckpointNumber,
839
+ attestationsAndSigners: ViemCommitteeAttestations,
840
+ committee: EthAddress[],
841
+ invalidIndex: number,
842
+ ): L1TxRequest {
843
+ return {
844
+ to: this.address,
845
+ abi: RollupAbi,
846
+ data: encodeFunctionData({
847
+ abi: RollupAbi,
848
+ functionName: 'invalidateBadAttestation',
849
+ args: [
850
+ BigInt(checkpointNumber),
851
+ attestationsAndSigners,
852
+ committee.map(addr => addr.toString()),
853
+ BigInt(invalidIndex),
854
+ ],
855
+ }),
856
+ };
857
+ }
858
+
859
+ /** Creates a request to Rollup#invalidateInsufficientAttestations to be simulated or sent */
860
+ public buildInvalidateInsufficientAttestationsRequest(
861
+ checkpointNumber: CheckpointNumber,
862
+ attestationsAndSigners: ViemCommitteeAttestations,
863
+ committee: EthAddress[],
864
+ ): L1TxRequest {
865
+ return {
866
+ to: this.address,
867
+ abi: RollupAbi,
868
+ data: encodeFunctionData({
869
+ abi: RollupAbi,
870
+ functionName: 'invalidateInsufficientAttestations',
871
+ args: [BigInt(checkpointNumber), attestationsAndSigners, committee.map(addr => addr.toString())],
872
+ }),
873
+ };
874
+ }
875
+
270
876
  /** Calls getHasSubmitted directly. Returns whether the given prover has submitted a proof with the given length for the given epoch. */
271
- public getHasSubmittedProof(epochNumber: number, numberOfBlocksInEpoch: number, prover: EthAddress) {
272
- return this.rollup.read.getHasSubmitted([BigInt(epochNumber), BigInt(numberOfBlocksInEpoch), prover.toString()]);
877
+ public getHasSubmittedProof(epochNumber: EpochNumber, numberOfCheckpointsInEpoch: number, prover: Hex | EthAddress) {
878
+ if (prover instanceof EthAddress) {
879
+ prover = prover.toString();
880
+ }
881
+ return this.rollup.read.getHasSubmitted([BigInt(epochNumber), BigInt(numberOfCheckpointsInEpoch), prover]);
882
+ }
883
+
884
+ getManaMinFeeAt(timestamp: bigint, inFeeAsset: boolean): Promise<bigint> {
885
+ return this.rollup.read.getManaMinFeeAt([timestamp, inFeeAsset]);
886
+ }
887
+
888
+ async getManaMinFeeComponentsAt(timestamp: bigint, inFeeAsset: boolean): Promise<ManaMinFeeComponents> {
889
+ const result = await this.rollup.read.getManaMinFeeComponentsAt([timestamp, inFeeAsset]);
890
+ return {
891
+ sequencerCost: result.sequencerCost,
892
+ proverCost: result.proverCost,
893
+ congestionCost: result.congestionCost,
894
+ congestionMultiplier: result.congestionMultiplier,
895
+ };
896
+ }
897
+
898
+ async getSlotAt(timestamp: bigint): Promise<SlotNumber> {
899
+ return SlotNumber.fromBigInt(await this.rollup.read.getSlotAt([timestamp]));
900
+ }
901
+
902
+ async status(checkpointNumber: CheckpointNumber, options?: { blockNumber?: bigint }): Promise<RollupStatusResponse> {
903
+ await checkBlockTag(options?.blockNumber, this.client);
904
+ const result = await this.rollup.read.status([BigInt(checkpointNumber)], options);
905
+ return {
906
+ provenCheckpointNumber: CheckpointNumber.fromBigInt(result[0]),
907
+ provenArchive: Fr.fromString(result[1]),
908
+ pendingCheckpointNumber: CheckpointNumber.fromBigInt(result[2]),
909
+ pendingArchive: Fr.fromString(result[3]),
910
+ archiveOfMyCheckpoint: Fr.fromString(result[4]),
911
+ };
912
+ }
913
+
914
+ async canPruneAtTime(timestamp: bigint, options?: { blockNumber?: bigint }): Promise<boolean> {
915
+ await checkBlockTag(options?.blockNumber, this.client);
916
+ return this.rollup.read.canPruneAtTime([timestamp], options);
917
+ }
918
+
919
+ async archive(): Promise<Fr> {
920
+ return Fr.fromString(await this.rollup.read.archive());
921
+ }
922
+
923
+ async archiveAt(checkpointNumber: CheckpointNumber): Promise<Fr> {
924
+ return Fr.fromString(await this.rollup.read.archiveAt([BigInt(checkpointNumber)]));
925
+ }
926
+
927
+ getSequencerRewards(address: Hex | EthAddress): Promise<bigint> {
928
+ if (address instanceof EthAddress) {
929
+ address = address.toString();
930
+ }
931
+ return this.rollup.read.getSequencerRewards([address]);
932
+ }
933
+
934
+ getSpecificProverRewardsForEpoch(epoch: bigint, prover: Hex | EthAddress): Promise<bigint> {
935
+ if (prover instanceof EthAddress) {
936
+ prover = prover.toString();
937
+ }
938
+ return this.rollup.read.getSpecificProverRewardsForEpoch([epoch, prover]);
939
+ }
940
+
941
+ async getAttesters(): Promise<EthAddress[]> {
942
+ const attesterSize = await this.getActiveAttesterCount();
943
+ const gse = new GSEContract(this.client, await this.getGSE());
944
+ const ts = (await this.client.getBlock()).timestamp;
945
+
946
+ const indices = Array.from({ length: attesterSize }, (_, i) => BigInt(i));
947
+ const chunks = chunk(indices, 1000);
948
+
949
+ const results = await Promise.all(chunks.map(chunk => gse.getAttestersFromIndicesAtTime(this.address, ts, chunk)));
950
+ return results.flat().map(addr => EthAddress.fromString(addr));
951
+ }
952
+
953
+ async getAttesterView(address: Hex | EthAddress): Promise<AttesterView> {
954
+ if (address instanceof EthAddress) {
955
+ address = address.toString();
956
+ }
957
+ const result = await this.rollup.read.getAttesterView([address]);
958
+ return {
959
+ status: result.status as AttesterStatus,
960
+ effectiveBalance: result.effectiveBalance,
961
+ exit: {
962
+ withdrawalId: result.exit.withdrawalId,
963
+ amount: result.exit.amount,
964
+ exitableAt: result.exit.exitableAt,
965
+ recipientOrWithdrawer: EthAddress.fromString(result.exit.recipientOrWithdrawer),
966
+ isRecipient: result.exit.isRecipient,
967
+ exists: result.exit.exists,
968
+ },
969
+ config: {
970
+ publicKey: {
971
+ x: result.config.publicKey.x,
972
+ y: result.config.publicKey.y,
973
+ },
974
+ withdrawer: EthAddress.fromString(result.config.withdrawer),
975
+ },
976
+ };
977
+ }
978
+
979
+ async getStatus(address: Hex | EthAddress): Promise<AttesterStatus> {
980
+ if (address instanceof EthAddress) {
981
+ address = address.toString();
982
+ }
983
+ return (await this.rollup.read.getStatus([address])) as AttesterStatus;
984
+ }
985
+
986
+ async getBlobCommitmentsHash(checkpointNumber: CheckpointNumber): Promise<Buffer32> {
987
+ return Buffer32.fromString(await this.rollup.read.getBlobCommitmentsHash([BigInt(checkpointNumber)]));
988
+ }
989
+
990
+ async getCurrentBlobCommitmentsHash(): Promise<Buffer32> {
991
+ return Buffer32.fromString(await this.rollup.read.getCurrentBlobCommitmentsHash());
992
+ }
993
+
994
+ async getStakingAsset(): Promise<EthAddress> {
995
+ return EthAddress.fromString(await this.rollup.read.getStakingAsset());
996
+ }
997
+
998
+ async getRewardConfig(): Promise<RewardConfig> {
999
+ const result = await this.rollup.read.getRewardConfig();
1000
+ return {
1001
+ rewardDistributor: EthAddress.fromString(result.rewardDistributor),
1002
+ sequencerBps: BigInt(result.sequencerBps),
1003
+ booster: EthAddress.fromString(result.booster),
1004
+ checkpointReward: result.checkpointReward,
1005
+ };
1006
+ }
1007
+
1008
+ setupEpoch(l1TxUtils: L1TxUtils) {
1009
+ return l1TxUtils.sendAndMonitorTransaction({
1010
+ to: this.address,
1011
+ abi: RollupAbi,
1012
+ data: encodeFunctionData({
1013
+ abi: RollupAbi,
1014
+ functionName: 'setupEpoch',
1015
+ args: [],
1016
+ }),
1017
+ });
1018
+ }
1019
+
1020
+ vote(l1TxUtils: L1TxUtils, proposalId: bigint) {
1021
+ return l1TxUtils.sendAndMonitorTransaction({
1022
+ to: this.address,
1023
+ abi: RollupAbi,
1024
+ data: encodeFunctionData({
1025
+ abi: RollupAbi,
1026
+ functionName: 'vote',
1027
+ args: [proposalId],
1028
+ }),
1029
+ });
1030
+ }
1031
+
1032
+ public listenToSlasherChanged(
1033
+ callback: (args: { oldSlasher: `0x${string}`; newSlasher: `0x${string}` }) => unknown,
1034
+ ): WatchContractEventReturnType {
1035
+ return this.rollup.watchEvent.SlasherUpdated(
1036
+ {},
1037
+ {
1038
+ onLogs: logs => {
1039
+ for (const log of logs) {
1040
+ const args = log.args;
1041
+ if (args.oldSlasher && args.newSlasher) {
1042
+ callback(args as { oldSlasher: `0x${string}`; newSlasher: `0x${string}` });
1043
+ }
1044
+ }
1045
+ },
1046
+ },
1047
+ );
1048
+ }
1049
+
1050
+ public listenToCheckpointInvalidated(
1051
+ callback: (args: { checkpointNumber: CheckpointNumber }) => unknown,
1052
+ ): WatchContractEventReturnType {
1053
+ return this.rollup.watchEvent.CheckpointInvalidated(
1054
+ {},
1055
+ {
1056
+ onLogs: logs => {
1057
+ for (const log of logs) {
1058
+ const args = log.args;
1059
+ if (args.checkpointNumber !== undefined) {
1060
+ callback({ checkpointNumber: CheckpointNumber.fromBigInt(args.checkpointNumber) });
1061
+ }
1062
+ }
1063
+ },
1064
+ },
1065
+ );
1066
+ }
1067
+
1068
+ public async getSlashEvents(l1BlockHash: Hex): Promise<{ amount: bigint; attester: EthAddress }[]> {
1069
+ const events = await this.rollup.getEvents.Slashed({}, { blockHash: l1BlockHash, strict: true });
1070
+ return events.map(event => ({
1071
+ amount: event.args.amount!,
1072
+ attester: EthAddress.fromString(event.args.attester!),
1073
+ }));
1074
+ }
1075
+
1076
+ public listenToSlash(
1077
+ callback: (args: { amount: bigint; attester: EthAddress }) => unknown,
1078
+ ): WatchContractEventReturnType {
1079
+ return this.rollup.watchEvent.Slashed(
1080
+ {},
1081
+ {
1082
+ strict: true,
1083
+ onLogs: logs => {
1084
+ for (const log of logs) {
1085
+ const args = log.args;
1086
+ callback({ amount: args.amount!, attester: EthAddress.fromString(args.attester!) });
1087
+ }
1088
+ },
1089
+ },
1090
+ );
1091
+ }
1092
+
1093
+ /** Fetches CheckpointProposed events within the given block range. */
1094
+ async getCheckpointProposedEvents(fromBlock: bigint, toBlock: bigint): Promise<CheckpointProposedLog[]> {
1095
+ const logs = await this.rollup.getEvents.CheckpointProposed({}, { fromBlock, toBlock });
1096
+ return logs
1097
+ .filter(log => log.blockNumber! >= fromBlock && log.blockNumber! <= toBlock)
1098
+ .map(log => ({
1099
+ l1BlockNumber: log.blockNumber!,
1100
+ l1BlockHash: Buffer32.fromString(log.blockHash!),
1101
+ l1TransactionHash: log.transactionHash!,
1102
+ args: {
1103
+ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
1104
+ archive: Fr.fromString(log.args.archive!),
1105
+ versionedBlobHashes: log.args.versionedBlobHashes!.map(h => Buffer.from(h.slice(2), 'hex')),
1106
+ attestationsHash: (() => {
1107
+ if (!log.args.attestationsHash) {
1108
+ throw new Error(
1109
+ `CheckpointProposed event missing attestationsHash for checkpoint ${log.args.checkpointNumber}`,
1110
+ );
1111
+ }
1112
+ return Buffer32.fromString(log.args.attestationsHash);
1113
+ })(),
1114
+ payloadDigest: (() => {
1115
+ if (!log.args.payloadDigest) {
1116
+ throw new Error(
1117
+ `CheckpointProposed event missing payloadDigest for checkpoint ${log.args.checkpointNumber}`,
1118
+ );
1119
+ }
1120
+ return Buffer32.fromString(log.args.payloadDigest);
1121
+ })(),
1122
+ },
1123
+ }));
273
1124
  }
274
1125
  }