@aztec/ethereum 0.0.0-test.0 → 0.0.1-commit.03f7ef2

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 (272) 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 +71 -16
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +138 -22
  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 +209 -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 +19 -0
  22. package/dest/contracts/fee_asset_handler.d.ts.map +1 -0
  23. package/dest/contracts/fee_asset_handler.js +57 -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 +43 -32
  28. package/dest/contracts/governance.d.ts.map +1 -1
  29. package/dest/contracts/governance.js +87 -84
  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 +46 -17
  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 +26 -0
  37. package/dest/contracts/inbox.d.ts.map +1 -0
  38. package/dest/contracts/inbox.js +45 -0
  39. package/dest/contracts/index.d.ts +9 -3
  40. package/dest/contracts/index.d.ts.map +1 -1
  41. package/dest/contracts/index.js +8 -2
  42. package/dest/contracts/multicall.d.ts +21 -0
  43. package/dest/contracts/multicall.d.ts.map +1 -0
  44. package/dest/contracts/multicall.js +156 -0
  45. package/dest/contracts/registry.d.ts +10 -5
  46. package/dest/contracts/registry.d.ts.map +1 -1
  47. package/dest/contracts/registry.js +44 -16
  48. package/dest/contracts/rollup.d.ts +221 -41
  49. package/dest/contracts/rollup.d.ts.map +1 -1
  50. package/dest/contracts/rollup.js +549 -81
  51. package/dest/contracts/slasher_contract.d.ts +44 -0
  52. package/dest/contracts/slasher_contract.d.ts.map +1 -0
  53. package/dest/contracts/slasher_contract.js +75 -0
  54. package/dest/contracts/tally_slashing_proposer.d.ts +140 -0
  55. package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -0
  56. package/dest/contracts/tally_slashing_proposer.js +313 -0
  57. package/dest/contracts/utils.d.ts +3 -0
  58. package/dest/contracts/utils.d.ts.map +1 -0
  59. package/dest/contracts/utils.js +11 -0
  60. package/dest/deploy_aztec_l1_contracts.d.ts +245 -0
  61. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  62. package/dest/deploy_aztec_l1_contracts.js +335 -0
  63. package/dest/deploy_l1_contract.d.ts +68 -0
  64. package/dest/deploy_l1_contract.d.ts.map +1 -0
  65. package/dest/deploy_l1_contract.js +312 -0
  66. package/dest/eth-signer/eth-signer.d.ts +21 -0
  67. package/dest/eth-signer/eth-signer.d.ts.map +1 -0
  68. package/dest/eth-signer/eth-signer.js +5 -0
  69. package/dest/eth-signer/index.d.ts +2 -0
  70. package/dest/eth-signer/index.d.ts.map +1 -0
  71. package/dest/eth-signer/index.js +1 -0
  72. package/dest/forwarder_proxy.d.ts +32 -0
  73. package/dest/forwarder_proxy.d.ts.map +1 -0
  74. package/dest/forwarder_proxy.js +93 -0
  75. package/dest/l1_artifacts.d.ts +77364 -0
  76. package/dest/l1_artifacts.d.ts.map +1 -0
  77. package/dest/l1_artifacts.js +166 -0
  78. package/dest/l1_contract_addresses.d.ts +24 -4
  79. package/dest/l1_contract_addresses.d.ts.map +1 -1
  80. package/dest/l1_contract_addresses.js +25 -21
  81. package/dest/l1_reader.d.ts +4 -2
  82. package/dest/l1_reader.d.ts.map +1 -1
  83. package/dest/l1_reader.js +14 -8
  84. package/dest/l1_tx_utils/config.d.ts +59 -0
  85. package/dest/l1_tx_utils/config.d.ts.map +1 -0
  86. package/dest/l1_tx_utils/config.js +96 -0
  87. package/dest/l1_tx_utils/constants.d.ts +12 -0
  88. package/dest/l1_tx_utils/constants.d.ts.map +1 -0
  89. package/dest/l1_tx_utils/constants.js +39 -0
  90. package/dest/l1_tx_utils/factory.d.ts +24 -0
  91. package/dest/l1_tx_utils/factory.d.ts.map +1 -0
  92. package/dest/l1_tx_utils/factory.js +12 -0
  93. package/dest/l1_tx_utils/fee-strategies/index.d.ts +9 -0
  94. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  95. package/dest/l1_tx_utils/fee-strategies/index.js +11 -0
  96. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +18 -0
  97. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  98. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +111 -0
  99. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +32 -0
  100. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  101. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +173 -0
  102. package/dest/l1_tx_utils/fee-strategies/types.d.ts +64 -0
  103. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  104. package/dest/l1_tx_utils/fee-strategies/types.js +24 -0
  105. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  106. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  107. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +48 -0
  108. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  109. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  110. package/dest/l1_tx_utils/index-blobs.js +2 -0
  111. package/dest/l1_tx_utils/index.d.ts +12 -0
  112. package/dest/l1_tx_utils/index.d.ts.map +1 -0
  113. package/dest/l1_tx_utils/index.js +12 -0
  114. package/dest/l1_tx_utils/interfaces.d.ts +76 -0
  115. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
  116. package/dest/l1_tx_utils/interfaces.js +4 -0
  117. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
  118. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  119. package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
  120. package/dest/l1_tx_utils/l1_tx_utils.d.ts +94 -0
  121. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
  122. package/dest/l1_tx_utils/l1_tx_utils.js +623 -0
  123. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +26 -0
  124. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +1 -0
  125. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +26 -0
  126. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +87 -0
  127. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
  128. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +360 -0
  129. package/dest/l1_tx_utils/signer.d.ts +4 -0
  130. package/dest/l1_tx_utils/signer.d.ts.map +1 -0
  131. package/dest/l1_tx_utils/signer.js +16 -0
  132. package/dest/l1_tx_utils/types.d.ts +67 -0
  133. package/dest/l1_tx_utils/types.d.ts.map +1 -0
  134. package/dest/l1_tx_utils/types.js +26 -0
  135. package/dest/l1_tx_utils/utils.d.ts +4 -0
  136. package/dest/l1_tx_utils/utils.d.ts.map +1 -0
  137. package/dest/l1_tx_utils/utils.js +14 -0
  138. package/dest/l1_types.d.ts +6 -0
  139. package/dest/l1_types.d.ts.map +1 -0
  140. package/dest/l1_types.js +1 -0
  141. package/dest/publisher_manager.d.ts +15 -0
  142. package/dest/publisher_manager.d.ts.map +1 -0
  143. package/dest/publisher_manager.js +88 -0
  144. package/dest/queries.d.ts +4 -2
  145. package/dest/queries.d.ts.map +1 -1
  146. package/dest/queries.js +53 -12
  147. package/dest/test/chain_monitor.d.ts +75 -0
  148. package/dest/test/chain_monitor.d.ts.map +1 -0
  149. package/dest/test/chain_monitor.js +214 -0
  150. package/dest/test/delayed_tx_utils.d.ts +8 -3
  151. package/dest/test/delayed_tx_utils.d.ts.map +1 -1
  152. package/dest/test/delayed_tx_utils.js +13 -6
  153. package/dest/test/eth_cheat_codes.d.ts +217 -0
  154. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  155. package/dest/test/eth_cheat_codes.js +560 -0
  156. package/dest/test/eth_cheat_codes_with_state.d.ts +2 -2
  157. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
  158. package/dest/test/eth_cheat_codes_with_state.js +1 -1
  159. package/dest/test/index.d.ts +4 -1
  160. package/dest/test/index.d.ts.map +1 -1
  161. package/dest/test/index.js +3 -0
  162. package/dest/test/rollup_cheat_codes.d.ts +87 -0
  163. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  164. package/dest/test/rollup_cheat_codes.js +275 -0
  165. package/dest/test/start_anvil.d.ts +9 -1
  166. package/dest/test/start_anvil.d.ts.map +1 -1
  167. package/dest/test/start_anvil.js +16 -7
  168. package/dest/test/tx_delayer.d.ts +18 -7
  169. package/dest/test/tx_delayer.d.ts.map +1 -1
  170. package/dest/test/tx_delayer.js +97 -20
  171. package/dest/test/upgrade_utils.d.ts +6 -5
  172. package/dest/test/upgrade_utils.d.ts.map +1 -1
  173. package/dest/test/upgrade_utils.js +23 -16
  174. package/dest/types.d.ts +62 -8
  175. package/dest/types.d.ts.map +1 -1
  176. package/dest/types.js +3 -1
  177. package/dest/utils.d.ts +16 -3
  178. package/dest/utils.d.ts.map +1 -1
  179. package/dest/utils.js +61 -88
  180. package/dest/zkPassportVerifierAddress.d.ts +15 -0
  181. package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
  182. package/dest/zkPassportVerifierAddress.js +11 -0
  183. package/package.json +50 -23
  184. package/src/account.ts +5 -0
  185. package/src/client.ts +43 -5
  186. package/src/config.ts +188 -31
  187. package/src/contracts/empire_base.ts +77 -7
  188. package/src/contracts/empire_slashing_proposer.ts +270 -0
  189. package/src/contracts/errors.ts +13 -0
  190. package/src/contracts/fee_asset_handler.ts +63 -0
  191. package/src/contracts/fee_juice.ts +29 -15
  192. package/src/contracts/governance.ts +80 -77
  193. package/src/contracts/governance_proposer.ts +71 -24
  194. package/src/contracts/gse.ts +88 -0
  195. package/src/contracts/inbox.ts +63 -0
  196. package/src/contracts/index.ts +8 -2
  197. package/src/contracts/multicall.ts +155 -0
  198. package/src/contracts/registry.ts +51 -26
  199. package/src/contracts/rollup.ts +624 -78
  200. package/src/contracts/slasher_contract.ts +89 -0
  201. package/src/contracts/tally_slashing_proposer.ts +318 -0
  202. package/src/contracts/utils.ts +14 -0
  203. package/src/deploy_aztec_l1_contracts.ts +556 -0
  204. package/src/deploy_l1_contract.ts +362 -0
  205. package/src/eth-signer/eth-signer.ts +25 -0
  206. package/src/eth-signer/index.ts +1 -0
  207. package/src/forwarder_proxy.ts +108 -0
  208. package/src/l1_artifacts.ts +254 -0
  209. package/src/l1_contract_addresses.ts +49 -34
  210. package/src/l1_reader.ts +17 -9
  211. package/src/l1_tx_utils/README.md +177 -0
  212. package/src/l1_tx_utils/config.ts +161 -0
  213. package/src/l1_tx_utils/constants.ts +29 -0
  214. package/src/l1_tx_utils/factory.ts +64 -0
  215. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  216. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +159 -0
  217. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +241 -0
  218. package/src/l1_tx_utils/fee-strategies/types.ts +88 -0
  219. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +119 -0
  220. package/src/l1_tx_utils/index-blobs.ts +2 -0
  221. package/src/l1_tx_utils/index.ts +14 -0
  222. package/src/l1_tx_utils/interfaces.ts +86 -0
  223. package/src/l1_tx_utils/l1_fee_analyzer.ts +804 -0
  224. package/src/l1_tx_utils/l1_tx_utils.ts +738 -0
  225. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +77 -0
  226. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +458 -0
  227. package/src/l1_tx_utils/signer.ts +28 -0
  228. package/src/l1_tx_utils/types.ts +85 -0
  229. package/src/l1_tx_utils/utils.ts +16 -0
  230. package/src/l1_types.ts +6 -0
  231. package/src/publisher_manager.ts +106 -0
  232. package/src/queries.ts +73 -15
  233. package/src/test/chain_monitor.ts +245 -0
  234. package/src/test/delayed_tx_utils.ts +34 -6
  235. package/src/test/eth_cheat_codes.ts +588 -0
  236. package/src/test/eth_cheat_codes_with_state.ts +1 -1
  237. package/src/test/index.ts +3 -0
  238. package/src/test/rollup_cheat_codes.ts +312 -0
  239. package/src/test/start_anvil.ts +24 -5
  240. package/src/test/tx_delayer.ts +130 -27
  241. package/src/test/upgrade_utils.ts +30 -21
  242. package/src/types.ts +71 -7
  243. package/src/utils.ts +79 -91
  244. package/src/zkPassportVerifierAddress.ts +15 -0
  245. package/dest/contracts/forwarder.d.ts +0 -24
  246. package/dest/contracts/forwarder.d.ts.map +0 -1
  247. package/dest/contracts/forwarder.js +0 -101
  248. package/dest/contracts/slashing_proposer.d.ts +0 -21
  249. package/dest/contracts/slashing_proposer.d.ts.map +0 -1
  250. package/dest/contracts/slashing_proposer.js +0 -47
  251. package/dest/deploy_l1_contracts.d.ts +0 -21210
  252. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  253. package/dest/deploy_l1_contracts.js +0 -687
  254. package/dest/eth_cheat_codes.d.ts +0 -147
  255. package/dest/eth_cheat_codes.d.ts.map +0 -1
  256. package/dest/eth_cheat_codes.js +0 -303
  257. package/dest/index.d.ts +0 -14
  258. package/dest/index.d.ts.map +0 -1
  259. package/dest/index.js +0 -13
  260. package/dest/l1_tx_utils.d.ts +0 -192
  261. package/dest/l1_tx_utils.d.ts.map +0 -1
  262. package/dest/l1_tx_utils.js +0 -641
  263. package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
  264. package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
  265. package/dest/l1_tx_utils_with_blobs.js +0 -64
  266. package/src/contracts/forwarder.ts +0 -132
  267. package/src/contracts/slashing_proposer.ts +0 -51
  268. package/src/deploy_l1_contracts.ts +0 -948
  269. package/src/eth_cheat_codes.ts +0 -314
  270. package/src/index.ts +0 -13
  271. package/src/l1_tx_utils.ts +0 -847
  272. package/src/l1_tx_utils_with_blobs.ts +0 -86
@@ -1,17 +1,46 @@
1
+ import { CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import { memoize } from '@aztec/foundation/decorators';
2
3
  import { EthAddress } from '@aztec/foundation/eth-address';
3
4
  import type { ViemSignature } from '@aztec/foundation/eth-signature';
4
- import { RollupAbi, RollupStorage, SlasherAbi } from '@aztec/l1-artifacts';
5
-
6
- import { type Account, type GetContractReturnType, type Hex, getAddress, getContract } from 'viem';
5
+ import { makeBackoff, retry } from '@aztec/foundation/retry';
6
+ import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
7
+ import { RollupStorage } from '@aztec/l1-artifacts/RollupStorage';
8
+
9
+ import chunk from 'lodash.chunk';
10
+ import {
11
+ type Account,
12
+ type GetContractReturnType,
13
+ type Hex,
14
+ type StateOverride,
15
+ type WatchContractEventReturnType,
16
+ encodeFunctionData,
17
+ getContract,
18
+ hexToBigInt,
19
+ keccak256,
20
+ } from 'viem';
7
21
 
8
22
  import { getPublicClient } from '../client.js';
9
- import type { DeployL1ContractsReturnType } from '../deploy_l1_contracts.js';
23
+ import type { DeployAztecL1ContractsReturnType } from '../deploy_aztec_l1_contracts.js';
10
24
  import type { L1ContractAddresses } from '../l1_contract_addresses.js';
11
25
  import type { L1ReaderConfig } from '../l1_reader.js';
12
- import type { ViemPublicClient } from '../types.js';
26
+ import type { L1TxRequest, L1TxUtils } from '../l1_tx_utils/index.js';
27
+ import type { ViemClient } from '../types.js';
13
28
  import { formatViemError } from '../utils.js';
14
- import { SlashingProposerContract } from './slashing_proposer.js';
29
+ import { EmpireSlashingProposerContract } from './empire_slashing_proposer.js';
30
+ import { GSEContract } from './gse.js';
31
+ import { SlasherContract } from './slasher_contract.js';
32
+ import { TallySlashingProposerContract } from './tally_slashing_proposer.js';
33
+ import { checkBlockTag } from './utils.js';
34
+
35
+ export type ViemCommitteeAttestation = {
36
+ addr: `0x${string}`;
37
+ signature: ViemSignature;
38
+ };
39
+
40
+ export type ViemCommitteeAttestations = {
41
+ signatureIndices: `0x${string}`;
42
+ signaturesOrAddresses: `0x${string}`;
43
+ };
15
44
 
16
45
  export type L1RollupContractAddresses = Pick<
17
46
  L1ContractAddresses,
@@ -23,20 +52,48 @@ export type L1RollupContractAddresses = Pick<
23
52
  | 'stakingAssetAddress'
24
53
  | 'rewardDistributorAddress'
25
54
  | 'slashFactoryAddress'
55
+ | 'gseAddress'
26
56
  >;
27
57
 
28
58
  export type EpochProofPublicInputArgs = {
29
59
  previousArchive: `0x${string}`;
30
60
  endArchive: `0x${string}`;
31
- previousBlockHash: `0x${string}`;
32
- endBlockHash: `0x${string}`;
33
- endTimestamp: bigint;
34
- outHash: `0x${string}`;
35
61
  proverId: `0x${string}`;
36
62
  };
37
63
 
64
+ export type ViemHeader = {
65
+ lastArchiveRoot: `0x${string}`;
66
+ blockHeadersHash: `0x${string}`;
67
+ contentCommitment: ViemContentCommitment;
68
+ slotNumber: bigint;
69
+ timestamp: bigint;
70
+ coinbase: `0x${string}`;
71
+ feeRecipient: `0x${string}`;
72
+ gasFees: ViemGasFees;
73
+ totalManaUsed: bigint;
74
+ };
75
+
76
+ export type ViemContentCommitment = {
77
+ blobsHash: `0x${string}`;
78
+ inHash: `0x${string}`;
79
+ outHash: `0x${string}`;
80
+ };
81
+
82
+ export type ViemGasFees = {
83
+ feePerDaGas: bigint;
84
+ feePerL2Gas: bigint;
85
+ };
86
+
87
+ export enum SlashingProposerType {
88
+ None = 0,
89
+ Tally = 1,
90
+ Empire = 2,
91
+ }
92
+
38
93
  export class RollupContract {
39
- private readonly rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>;
94
+ private readonly rollup: GetContractReturnType<typeof RollupAbi, ViemClient>;
95
+
96
+ private static cachedStfStorageSlot: Hex | undefined;
40
97
 
41
98
  static get checkBlobStorageSlot(): bigint {
42
99
  const asString = RollupStorage.find(storage => storage.label === 'checkBlob')?.slot;
@@ -46,12 +103,16 @@ export class RollupContract {
46
103
  return BigInt(asString);
47
104
  }
48
105
 
49
- static getFromL1ContractsValues(deployL1ContractsValues: DeployL1ContractsReturnType) {
106
+ static get stfStorageSlot(): Hex {
107
+ return (RollupContract.cachedStfStorageSlot ??= keccak256(Buffer.from('aztec.stf.storage', 'utf-8')));
108
+ }
109
+
110
+ static getFromL1ContractsValues(deployL1ContractsValues: DeployAztecL1ContractsReturnType) {
50
111
  const {
51
- publicClient,
112
+ l1Client,
52
113
  l1ContractAddresses: { rollupAddress },
53
114
  } = deployL1ContractsValues;
54
- return new RollupContract(publicClient, rollupAddress.toString());
115
+ return new RollupContract(l1Client, rollupAddress.toString());
55
116
  }
56
117
 
57
118
  static getFromConfig(config: L1ReaderConfig) {
@@ -60,23 +121,56 @@ export class RollupContract {
60
121
  return new RollupContract(client, address);
61
122
  }
62
123
 
63
- constructor(public readonly client: ViemPublicClient, address: Hex | EthAddress) {
124
+ constructor(
125
+ public readonly client: ViemClient,
126
+ address: Hex | EthAddress,
127
+ ) {
64
128
  if (address instanceof EthAddress) {
65
129
  address = address.toString();
66
130
  }
67
131
  this.rollup = getContract({ address, abi: RollupAbi, client });
68
132
  }
69
133
 
134
+ getGSE() {
135
+ return this.rollup.read.getGSE();
136
+ }
137
+
70
138
  public get address() {
71
139
  return this.rollup.address;
72
140
  }
73
141
 
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);
142
+ getContract(): GetContractReturnType<typeof RollupAbi, ViemClient> {
143
+ return this.rollup;
144
+ }
145
+
146
+ public async getSlashingProposer(): Promise<
147
+ EmpireSlashingProposerContract | TallySlashingProposerContract | undefined
148
+ > {
149
+ const slasher = await this.getSlasherContract();
150
+ if (!slasher) {
151
+ return undefined;
152
+ }
153
+
154
+ const proposerAddress = await slasher.getProposer();
155
+ const proposerAbi = [
156
+ {
157
+ type: 'function',
158
+ name: 'SLASHING_PROPOSER_TYPE',
159
+ inputs: [],
160
+ outputs: [{ name: '', type: 'uint8', internalType: 'enum SlasherFlavor' }],
161
+ stateMutability: 'view',
162
+ },
163
+ ] as const;
164
+
165
+ const proposer = getContract({ address: proposerAddress.toString(), abi: proposerAbi, client: this.client });
166
+ const proposerType = await proposer.read.SLASHING_PROPOSER_TYPE();
167
+ if (proposerType === SlashingProposerType.Tally.valueOf()) {
168
+ return new TallySlashingProposerContract(this.client, proposerAddress);
169
+ } else if (proposerType === SlashingProposerType.Empire.valueOf()) {
170
+ return new EmpireSlashingProposerContract(this.client, proposerAddress);
171
+ } else {
172
+ throw new Error(`Unknown slashing proposer type: ${proposerType}`);
173
+ }
80
174
  }
81
175
 
82
176
  @memoize
@@ -90,8 +184,8 @@ export class RollupContract {
90
184
  }
91
185
 
92
186
  @memoize
93
- getProofSubmissionWindow() {
94
- return this.rollup.read.getProofSubmissionWindow();
187
+ getProofSubmissionEpochs() {
188
+ return this.rollup.read.getProofSubmissionEpochs();
95
189
  }
96
190
 
97
191
  @memoize
@@ -100,8 +194,8 @@ export class RollupContract {
100
194
  }
101
195
 
102
196
  @memoize
103
- getSlotDuration() {
104
- return this.rollup.read.getSlotDuration();
197
+ async getSlotDuration(): Promise<number> {
198
+ return Number(await this.rollup.read.getSlotDuration());
105
199
  }
106
200
 
107
201
  @memoize
@@ -110,34 +204,165 @@ export class RollupContract {
110
204
  }
111
205
 
112
206
  @memoize
113
- getMinimumStake() {
114
- return this.rollup.read.getMinimumStake();
207
+ getEjectionThreshold() {
208
+ return this.rollup.read.getEjectionThreshold();
209
+ }
210
+
211
+ @memoize
212
+ getLocalEjectionThreshold() {
213
+ return this.rollup.read.getLocalEjectionThreshold();
214
+ }
215
+
216
+ @memoize
217
+ getLagInEpochsForValidatorSet() {
218
+ return this.rollup.read.getLagInEpochsForValidatorSet();
219
+ }
220
+
221
+ @memoize
222
+ getLagInEpochsForRandao() {
223
+ return this.rollup.read.getLagInEpochsForRandao();
224
+ }
225
+
226
+ @memoize
227
+ getActivationThreshold() {
228
+ return this.rollup.read.getActivationThreshold();
229
+ }
230
+
231
+ @memoize
232
+ getExitDelay() {
233
+ return this.rollup.read.getExitDelay();
234
+ }
235
+
236
+ @memoize
237
+ getManaTarget() {
238
+ return this.rollup.read.getManaTarget();
239
+ }
240
+
241
+ @memoize
242
+ getProvingCostPerMana() {
243
+ return this.rollup.read.getProvingCostPerManaInEth();
244
+ }
245
+
246
+ @memoize
247
+ getProvingCostPerManaInFeeAsset() {
248
+ return this.rollup.read.getProvingCostPerManaInFeeAsset();
249
+ }
250
+
251
+ @memoize
252
+ getManaLimit() {
253
+ return this.rollup.read.getManaLimit();
254
+ }
255
+
256
+ @memoize
257
+ getVersion() {
258
+ return this.rollup.read.getVersion();
259
+ }
260
+
261
+ @memoize
262
+ async getGenesisArchiveTreeRoot(): Promise<`0x${string}`> {
263
+ return await this.rollup.read.archiveAt([0n]);
264
+ }
265
+
266
+ /**
267
+ * Returns rollup constants used for epoch queries.
268
+ * Return type is `L1RollupConstants` which is defined in stdlib,
269
+ * so we cant reference it until we move this contract to that package.
270
+ */
271
+ @memoize
272
+ public async getRollupConstants(): Promise<{
273
+ l1StartBlock: bigint;
274
+ l1GenesisTime: bigint;
275
+ slotDuration: number;
276
+ epochDuration: number;
277
+ proofSubmissionEpochs: number;
278
+ }> {
279
+ const [l1StartBlock, l1GenesisTime, slotDuration, epochDuration, proofSubmissionEpochs] = await Promise.all([
280
+ this.getL1StartBlock(),
281
+ this.getL1GenesisTime(),
282
+ this.getSlotDuration(),
283
+ this.getEpochDuration(),
284
+ this.getProofSubmissionEpochs(),
285
+ ]);
286
+ return {
287
+ l1StartBlock,
288
+ l1GenesisTime,
289
+ slotDuration,
290
+ epochDuration: Number(epochDuration),
291
+ proofSubmissionEpochs: Number(proofSubmissionEpochs),
292
+ };
293
+ }
294
+
295
+ getSlasherAddress() {
296
+ return this.rollup.read.getSlasher();
297
+ }
298
+
299
+ /**
300
+ * Returns a SlasherContract instance for interacting with the slasher contract.
301
+ */
302
+ async getSlasherContract(): Promise<SlasherContract | undefined> {
303
+ const slasherAddress = EthAddress.fromString(await this.getSlasherAddress());
304
+ if (slasherAddress.isZero()) {
305
+ return undefined;
306
+ }
307
+ return new SlasherContract(this.client, slasherAddress);
308
+ }
309
+
310
+ getOwner() {
311
+ return this.rollup.read.owner();
312
+ }
313
+
314
+ getActiveAttesterCount() {
315
+ return this.rollup.read.getActiveAttesterCount();
115
316
  }
116
317
 
117
318
  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());
319
+ const slasher = await this.getSlasherContract();
320
+ if (!slasher) {
321
+ return EthAddress.ZERO;
322
+ }
323
+ return await slasher.getProposer();
324
+ }
325
+
326
+ getCheckpointReward() {
327
+ return this.rollup.read.getCheckpointReward();
328
+ }
329
+
330
+ async getCheckpointNumber(): Promise<CheckpointNumber> {
331
+ return CheckpointNumber.fromBigInt(await this.rollup.read.getPendingCheckpointNumber());
332
+ }
333
+
334
+ async getProvenCheckpointNumber(): Promise<CheckpointNumber> {
335
+ return CheckpointNumber.fromBigInt(await this.rollup.read.getProvenCheckpointNumber());
125
336
  }
126
337
 
127
- getBlockNumber() {
128
- return this.rollup.read.getPendingBlockNumber();
338
+ async getSlotNumber(): Promise<SlotNumber> {
339
+ return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
129
340
  }
130
341
 
131
- getProvenBlockNumber() {
132
- return this.rollup.read.getProvenBlockNumber();
342
+ getL1FeesAt(timestamp: bigint) {
343
+ return this.rollup.read.getL1FeesAt([timestamp]);
133
344
  }
134
345
 
135
- getSlotNumber() {
136
- return this.rollup.read.getCurrentSlot();
346
+ getFeeAssetPerEth() {
347
+ return this.rollup.read.getFeeAssetPerEth();
137
348
  }
138
349
 
139
- getCommitteeAt(timestamp: bigint) {
140
- return this.rollup.read.getCommitteeAt([timestamp]);
350
+ async getCommitteeAt(timestamp: bigint): Promise<readonly `0x${string}`[] | undefined> {
351
+ const { result } = await this.client
352
+ .simulateContract({
353
+ address: this.address,
354
+ abi: RollupAbi,
355
+ functionName: 'getCommitteeAt',
356
+ args: [timestamp],
357
+ })
358
+ .catch(e => {
359
+ if (e instanceof Error && e.message.includes('ValidatorSelection__InsufficientValidatorSetSize')) {
360
+ return { result: undefined };
361
+ }
362
+ throw e;
363
+ });
364
+
365
+ return result;
141
366
  }
142
367
 
143
368
  getSampleSeedAt(timestamp: bigint) {
@@ -148,33 +373,99 @@ export class RollupContract {
148
373
  return this.rollup.read.getCurrentSampleSeed();
149
374
  }
150
375
 
151
- getCurrentEpochCommittee() {
152
- return this.rollup.read.getCurrentEpochCommittee();
376
+ async getCurrentEpoch(): Promise<EpochNumber> {
377
+ return EpochNumber.fromBigInt(await this.rollup.read.getCurrentEpoch());
153
378
  }
154
379
 
155
- getCurrentProposer() {
156
- return this.rollup.read.getCurrentProposer();
380
+ async getCurrentEpochCommittee(): Promise<readonly `0x${string}`[] | undefined> {
381
+ const { result } = await this.client
382
+ .simulateContract({
383
+ address: this.address,
384
+ abi: RollupAbi,
385
+ functionName: 'getCurrentEpochCommittee',
386
+ args: [],
387
+ })
388
+ .catch(e => {
389
+ if (e instanceof Error && e.message.includes('ValidatorSelection__InsufficientValidatorSetSize')) {
390
+ return { result: undefined };
391
+ }
392
+ throw e;
393
+ });
394
+
395
+ return result;
157
396
  }
158
397
 
159
- getProposerAt(timestamp: bigint) {
160
- return this.rollup.read.getProposerAt([timestamp]);
398
+ async getCurrentProposer() {
399
+ const { result } = await this.client.simulateContract({
400
+ address: this.address,
401
+ abi: RollupAbi,
402
+ functionName: 'getCurrentProposer',
403
+ args: [],
404
+ });
405
+
406
+ return result;
161
407
  }
162
408
 
163
- getBlock(blockNumber: bigint) {
164
- return this.rollup.read.getBlock([blockNumber]);
409
+ async getProposerAt(timestamp: bigint) {
410
+ const { result } = await this.client.simulateContract({
411
+ address: this.address,
412
+ abi: RollupAbi,
413
+ functionName: 'getProposerAt',
414
+ args: [timestamp],
415
+ });
416
+
417
+ return result;
165
418
  }
166
419
 
167
- getTips() {
168
- return this.rollup.read.getTips();
420
+ getCheckpoint(checkpointNumber: CheckpointNumber) {
421
+ return this.rollup.read.getCheckpoint([BigInt(checkpointNumber)]);
169
422
  }
170
423
 
171
- getTimestampForSlot(slot: bigint) {
172
- return this.rollup.read.getTimestampForSlot([slot]);
424
+ /** Returns the pending checkpoint from the rollup contract */
425
+ getPendingCheckpoint() {
426
+ // We retry because of race conditions during prunes: we may get a pending checkpoint number which is immediately
427
+ // reorged out due to a prune happening, causing the subsequent getCheckpoint call to fail. So we try again in that case.
428
+ return retry(
429
+ async () => {
430
+ const pendingCheckpointNumber = await this.getCheckpointNumber();
431
+ const pendingCheckpoint = await this.getCheckpoint(pendingCheckpointNumber);
432
+ return pendingCheckpoint;
433
+ },
434
+ 'getting pending checkpoint',
435
+ makeBackoff([0.5, 0.5, 0.5]),
436
+ );
173
437
  }
174
438
 
175
- async getEpochNumber(blockNumber?: bigint) {
176
- blockNumber ??= await this.getBlockNumber();
177
- return this.rollup.read.getEpochForBlock([BigInt(blockNumber)]);
439
+ async getTips(): Promise<{ pending: CheckpointNumber; proven: CheckpointNumber }> {
440
+ const { pending, proven } = await this.rollup.read.getTips();
441
+ return {
442
+ pending: CheckpointNumber.fromBigInt(pending),
443
+ proven: CheckpointNumber.fromBigInt(proven),
444
+ };
445
+ }
446
+
447
+ getTimestampForSlot(slot: SlotNumber) {
448
+ return this.rollup.read.getTimestampForSlot([BigInt(slot)]);
449
+ }
450
+
451
+ getEntryQueueLength() {
452
+ return this.rollup.read.getEntryQueueLength();
453
+ }
454
+
455
+ getAvailableValidatorFlushes() {
456
+ return this.rollup.read.getAvailableValidatorFlushes();
457
+ }
458
+
459
+ async getNextFlushableEpoch(): Promise<EpochNumber> {
460
+ return EpochNumber.fromBigInt(await this.rollup.read.getNextFlushableEpoch());
461
+ }
462
+
463
+ async getCurrentEpochNumber(): Promise<EpochNumber> {
464
+ return EpochNumber.fromBigInt(await this.rollup.read.getCurrentEpoch());
465
+ }
466
+
467
+ async getEpochNumberForCheckpoint(checkpointNumber: CheckpointNumber): Promise<EpochNumber> {
468
+ return EpochNumber.fromBigInt(await this.rollup.read.getEpochForCheckpoint([BigInt(checkpointNumber)]));
178
469
  }
179
470
 
180
471
  async getRollupAddresses(): Promise<L1RollupContractAddresses> {
@@ -185,6 +476,7 @@ export class RollupContract {
185
476
  rewardDistributorAddress,
186
477
  feeJuiceAddress,
187
478
  stakingAssetAddress,
479
+ gseAddress,
188
480
  ] = (
189
481
  await Promise.all([
190
482
  this.rollup.read.getInbox(),
@@ -193,6 +485,7 @@ export class RollupContract {
193
485
  this.rollup.read.getRewardDistributor(),
194
486
  this.rollup.read.getFeeAsset(),
195
487
  this.rollup.read.getStakingAsset(),
488
+ this.rollup.read.getGSE(),
196
489
  ] as const)
197
490
  ).map(EthAddress.fromString);
198
491
 
@@ -204,25 +497,31 @@ export class RollupContract {
204
497
  feeJuiceAddress,
205
498
  stakingAssetAddress,
206
499
  rewardDistributorAddress,
500
+ gseAddress,
207
501
  };
208
502
  }
209
503
 
210
- public async getEpochNumberForSlotNumber(slotNumber: bigint): Promise<bigint> {
211
- return await this.rollup.read.getEpochAtSlot([slotNumber]);
504
+ public async getFeeJuicePortal() {
505
+ return EthAddress.fromString(await this.rollup.read.getFeeAssetPortal());
506
+ }
507
+
508
+ public async getEpochNumberForSlotNumber(slotNumber: SlotNumber): Promise<EpochNumber> {
509
+ return EpochNumber.fromBigInt(await this.rollup.read.getEpochAtSlot([BigInt(slotNumber)]));
212
510
  }
213
511
 
214
512
  getEpochProofPublicInputs(
215
- args: readonly [bigint, bigint, EpochProofPublicInputArgs, readonly `0x${string}`[], `0x${string}`, `0x${string}`],
513
+ args: readonly [bigint, bigint, EpochProofPublicInputArgs, readonly `0x${string}`[], `0x${string}`],
216
514
  ) {
217
515
  return this.rollup.read.getEpochProofPublicInputs(args);
218
516
  }
219
517
 
220
518
  public async validateHeader(
221
519
  args: readonly [
520
+ ViemHeader,
521
+ ViemCommitteeAttestations,
522
+ `0x${string}`[],
523
+ ViemSignature,
222
524
  `0x${string}`,
223
- ViemSignature[],
224
- `0x${string}`,
225
- bigint,
226
525
  `0x${string}`,
227
526
  {
228
527
  ignoreDA: boolean;
@@ -232,7 +531,13 @@ export class RollupContract {
232
531
  account: `0x${string}` | Account,
233
532
  ): Promise<void> {
234
533
  try {
235
- await this.rollup.read.validateHeader(args, { account });
534
+ await this.client.simulateContract({
535
+ address: this.address,
536
+ abi: RollupAbi,
537
+ functionName: 'validateHeaderWithAttestations',
538
+ args,
539
+ account,
540
+ });
236
541
  } catch (error: unknown) {
237
542
  throw formatViemError(error);
238
543
  }
@@ -244,31 +549,272 @@ export class RollupContract {
244
549
  * @dev Throws if unable to propose
245
550
  *
246
551
  * @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,
552
+ * @return [slot, checkpointNumber, timeOfNextL1Slot] - If you can propose, the L2 slot number, checkpoint number and
553
+ * timestamp of the next L1 block
248
554
  * @throws otherwise
249
555
  */
250
556
  public async canProposeAtNextEthBlock(
251
557
  archive: Buffer,
252
558
  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;
559
+ slotDuration: number,
560
+ opts: { forcePendingCheckpointNumber?: CheckpointNumber } = {},
561
+ ): Promise<{ slot: SlotNumber; checkpointNumber: CheckpointNumber; timeOfNextL1Slot: bigint }> {
562
+ const latestBlock = await this.client.getBlock();
563
+ const timeOfNextL1Slot = latestBlock.timestamp + BigInt(slotDuration);
564
+ const who = typeof account === 'string' ? account : account.address;
565
+
259
566
  try {
260
- const [slot, blockNumber] = await this.rollup.read.canProposeAtTime(
261
- [timeOfNextL1Slot, `0x${archive.toString('hex')}`],
262
- { account },
263
- );
264
- return [slot, blockNumber];
567
+ const {
568
+ result: [slot, checkpointNumber],
569
+ } = await this.client.simulateContract({
570
+ address: this.address,
571
+ abi: RollupAbi,
572
+ functionName: 'canProposeAtTime',
573
+ args: [timeOfNextL1Slot, `0x${archive.toString('hex')}`, who],
574
+ account,
575
+ stateOverride: await this.makePendingCheckpointNumberOverride(opts.forcePendingCheckpointNumber),
576
+ });
577
+
578
+ return {
579
+ slot: SlotNumber.fromBigInt(slot),
580
+ checkpointNumber: CheckpointNumber.fromBigInt(checkpointNumber),
581
+ timeOfNextL1Slot,
582
+ };
265
583
  } catch (err: unknown) {
266
584
  throw formatViemError(err);
267
585
  }
268
586
  }
269
587
 
588
+ /**
589
+ * Returns a state override that sets the pending checkpoint number to the specified value. Useful for simulations.
590
+ * Requires querying the current state of the contract to get the current proven checkpoint number, as they are both
591
+ * stored in the same slot. If the argument is undefined, it returns an empty override.
592
+ */
593
+ public async makePendingCheckpointNumberOverride(
594
+ forcePendingCheckpointNumber: CheckpointNumber | undefined,
595
+ ): Promise<StateOverride> {
596
+ if (forcePendingCheckpointNumber === undefined) {
597
+ return [];
598
+ }
599
+ const slot = RollupContract.stfStorageSlot;
600
+ const currentValue = await this.client.getStorageAt({ address: this.address, slot });
601
+ const currentProvenCheckpointNumber = currentValue ? hexToBigInt(currentValue) & ((1n << 128n) - 1n) : 0n;
602
+ const newValue = (BigInt(forcePendingCheckpointNumber) << 128n) | currentProvenCheckpointNumber;
603
+ return [
604
+ {
605
+ address: this.address,
606
+ stateDiff: [{ slot, value: `0x${newValue.toString(16).padStart(64, '0')}` }],
607
+ },
608
+ ];
609
+ }
610
+
611
+ /** Creates a request to Rollup#invalidateBadAttestation to be simulated or sent */
612
+ public buildInvalidateBadAttestationRequest(
613
+ checkpointNumber: CheckpointNumber,
614
+ attestationsAndSigners: ViemCommitteeAttestations,
615
+ committee: EthAddress[],
616
+ invalidIndex: number,
617
+ ): L1TxRequest {
618
+ return {
619
+ to: this.address,
620
+ data: encodeFunctionData({
621
+ abi: RollupAbi,
622
+ functionName: 'invalidateBadAttestation',
623
+ args: [
624
+ BigInt(checkpointNumber),
625
+ attestationsAndSigners,
626
+ committee.map(addr => addr.toString()),
627
+ BigInt(invalidIndex),
628
+ ],
629
+ }),
630
+ };
631
+ }
632
+
633
+ /** Creates a request to Rollup#invalidateInsufficientAttestations to be simulated or sent */
634
+ public buildInvalidateInsufficientAttestationsRequest(
635
+ checkpointNumber: CheckpointNumber,
636
+ attestationsAndSigners: ViemCommitteeAttestations,
637
+ committee: EthAddress[],
638
+ ): L1TxRequest {
639
+ return {
640
+ to: this.address,
641
+ data: encodeFunctionData({
642
+ abi: RollupAbi,
643
+ functionName: 'invalidateInsufficientAttestations',
644
+ args: [BigInt(checkpointNumber), attestationsAndSigners, committee.map(addr => addr.toString())],
645
+ }),
646
+ };
647
+ }
648
+
270
649
  /** 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()]);
650
+ public getHasSubmittedProof(epochNumber: EpochNumber, numberOfCheckpointsInEpoch: number, prover: Hex | EthAddress) {
651
+ if (prover instanceof EthAddress) {
652
+ prover = prover.toString();
653
+ }
654
+ return this.rollup.read.getHasSubmitted([BigInt(epochNumber), BigInt(numberOfCheckpointsInEpoch), prover]);
655
+ }
656
+
657
+ getManaBaseFeeAt(timestamp: bigint, inFeeAsset: boolean) {
658
+ return this.rollup.read.getManaBaseFeeAt([timestamp, inFeeAsset]);
659
+ }
660
+
661
+ async getSlotAt(timestamp: bigint): Promise<SlotNumber> {
662
+ return SlotNumber.fromBigInt(await this.rollup.read.getSlotAt([timestamp]));
663
+ }
664
+
665
+ async status(checkpointNumber: CheckpointNumber, options?: { blockNumber?: bigint }) {
666
+ await checkBlockTag(options?.blockNumber, this.client);
667
+ return this.rollup.read.status([BigInt(checkpointNumber)], options);
668
+ }
669
+
670
+ async canPruneAtTime(timestamp: bigint, options?: { blockNumber?: bigint }) {
671
+ await checkBlockTag(options?.blockNumber, this.client);
672
+ return this.rollup.read.canPruneAtTime([timestamp], options);
673
+ }
674
+
675
+ archive() {
676
+ return this.rollup.read.archive();
677
+ }
678
+
679
+ archiveAt(checkpointNumber: CheckpointNumber) {
680
+ return this.rollup.read.archiveAt([BigInt(checkpointNumber)]);
681
+ }
682
+
683
+ getSequencerRewards(address: Hex | EthAddress) {
684
+ if (address instanceof EthAddress) {
685
+ address = address.toString();
686
+ }
687
+ return this.rollup.read.getSequencerRewards([address]);
688
+ }
689
+
690
+ getSpecificProverRewardsForEpoch(epoch: bigint, prover: Hex | EthAddress) {
691
+ if (prover instanceof EthAddress) {
692
+ prover = prover.toString();
693
+ }
694
+ return this.rollup.read.getSpecificProverRewardsForEpoch([epoch, prover]);
695
+ }
696
+
697
+ async getAttesters() {
698
+ const attesterSize = await this.getActiveAttesterCount();
699
+ const gse = new GSEContract(this.client, await this.getGSE());
700
+ const ts = (await this.client.getBlock()).timestamp;
701
+
702
+ const indices = Array.from({ length: Number(attesterSize) }, (_, i) => BigInt(i));
703
+ const chunks = chunk(indices, 1000);
704
+
705
+ return (await Promise.all(chunks.map(chunk => gse.getAttestersFromIndicesAtTime(this.address, ts, chunk)))).flat();
706
+ }
707
+
708
+ getAttesterView(address: Hex | EthAddress) {
709
+ if (address instanceof EthAddress) {
710
+ address = address.toString();
711
+ }
712
+ return this.rollup.read.getAttesterView([address]);
713
+ }
714
+
715
+ getStatus(address: Hex | EthAddress) {
716
+ if (address instanceof EthAddress) {
717
+ address = address.toString();
718
+ }
719
+ return this.rollup.read.getStatus([address]);
720
+ }
721
+
722
+ getBlobCommitmentsHash(checkpointNumber: CheckpointNumber) {
723
+ return this.rollup.read.getBlobCommitmentsHash([BigInt(checkpointNumber)]);
724
+ }
725
+
726
+ getCurrentBlobCommitmentsHash() {
727
+ return this.rollup.read.getCurrentBlobCommitmentsHash();
728
+ }
729
+
730
+ getStakingAsset() {
731
+ return this.rollup.read.getStakingAsset();
732
+ }
733
+
734
+ getRewardConfig() {
735
+ return this.rollup.read.getRewardConfig();
736
+ }
737
+
738
+ setupEpoch(l1TxUtils: L1TxUtils) {
739
+ return l1TxUtils.sendAndMonitorTransaction({
740
+ to: this.address,
741
+ data: encodeFunctionData({
742
+ abi: RollupAbi,
743
+ functionName: 'setupEpoch',
744
+ args: [],
745
+ }),
746
+ });
747
+ }
748
+
749
+ vote(l1TxUtils: L1TxUtils, proposalId: bigint) {
750
+ return l1TxUtils.sendAndMonitorTransaction({
751
+ to: this.address,
752
+ data: encodeFunctionData({
753
+ abi: RollupAbi,
754
+ functionName: 'vote',
755
+ args: [proposalId],
756
+ }),
757
+ });
758
+ }
759
+
760
+ public listenToSlasherChanged(
761
+ callback: (args: { oldSlasher: `0x${string}`; newSlasher: `0x${string}` }) => unknown,
762
+ ): WatchContractEventReturnType {
763
+ return this.rollup.watchEvent.SlasherUpdated(
764
+ {},
765
+ {
766
+ onLogs: logs => {
767
+ for (const log of logs) {
768
+ const args = log.args;
769
+ if (args.oldSlasher && args.newSlasher) {
770
+ callback(args as { oldSlasher: `0x${string}`; newSlasher: `0x${string}` });
771
+ }
772
+ }
773
+ },
774
+ },
775
+ );
776
+ }
777
+
778
+ public listenToCheckpointInvalidated(
779
+ callback: (args: { checkpointNumber: CheckpointNumber }) => unknown,
780
+ ): WatchContractEventReturnType {
781
+ return this.rollup.watchEvent.CheckpointInvalidated(
782
+ {},
783
+ {
784
+ onLogs: logs => {
785
+ for (const log of logs) {
786
+ const args = log.args;
787
+ if (args.checkpointNumber !== undefined) {
788
+ callback({ checkpointNumber: CheckpointNumber.fromBigInt(args.checkpointNumber) });
789
+ }
790
+ }
791
+ },
792
+ },
793
+ );
794
+ }
795
+
796
+ public async getSlashEvents(l1BlockHash: Hex): Promise<{ amount: bigint; attester: EthAddress }[]> {
797
+ const events = await this.rollup.getEvents.Slashed({}, { blockHash: l1BlockHash, strict: true });
798
+ return events.map(event => ({
799
+ amount: event.args.amount!,
800
+ attester: EthAddress.fromString(event.args.attester!),
801
+ }));
802
+ }
803
+
804
+ public listenToSlash(
805
+ callback: (args: { amount: bigint; attester: EthAddress }) => unknown,
806
+ ): WatchContractEventReturnType {
807
+ return this.rollup.watchEvent.Slashed(
808
+ {},
809
+ {
810
+ strict: true,
811
+ onLogs: logs => {
812
+ for (const log of logs) {
813
+ const args = log.args;
814
+ callback({ amount: args.amount!, attester: EthAddress.fromString(args.attester!) });
815
+ }
816
+ },
817
+ },
818
+ );
273
819
  }
274
820
  }