@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.0208eb9

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