@aztec/ethereum 0.0.1-commit.24de95ac → 0.0.1-commit.3469e52

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 (202) hide show
  1. package/dest/account.d.ts +1 -1
  2. package/dest/chain.d.ts +1 -1
  3. package/dest/client.d.ts +1 -1
  4. package/dest/client.js +6 -2
  5. package/dest/config.d.ts +20 -68
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +52 -378
  8. package/dest/constants.d.ts +1 -1
  9. package/dest/contracts/empire_base.d.ts +7 -5
  10. package/dest/contracts/empire_base.d.ts.map +1 -1
  11. package/dest/contracts/empire_base.js +1 -1
  12. package/dest/contracts/empire_slashing_proposer.d.ts +6 -4
  13. package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -1
  14. package/dest/contracts/empire_slashing_proposer.js +17 -2
  15. package/dest/contracts/errors.d.ts +1 -1
  16. package/dest/contracts/errors.d.ts.map +1 -1
  17. package/dest/contracts/fee_asset_handler.d.ts +6 -5
  18. package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
  19. package/dest/contracts/fee_asset_handler.js +9 -9
  20. package/dest/contracts/fee_juice.d.ts +1 -1
  21. package/dest/contracts/fee_juice.d.ts.map +1 -1
  22. package/dest/contracts/governance.d.ts +16 -16
  23. package/dest/contracts/governance.d.ts.map +1 -1
  24. package/dest/contracts/governance_proposer.d.ts +6 -4
  25. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  26. package/dest/contracts/governance_proposer.js +399 -10
  27. package/dest/contracts/gse.d.ts +1 -1
  28. package/dest/contracts/gse.d.ts.map +1 -1
  29. package/dest/contracts/inbox.d.ts +24 -3
  30. package/dest/contracts/inbox.d.ts.map +1 -1
  31. package/dest/contracts/inbox.js +36 -1
  32. package/dest/contracts/index.d.ts +3 -1
  33. package/dest/contracts/index.d.ts.map +1 -1
  34. package/dest/contracts/index.js +2 -0
  35. package/dest/contracts/log.d.ts +13 -0
  36. package/dest/contracts/log.d.ts.map +1 -0
  37. package/dest/contracts/log.js +1 -0
  38. package/dest/contracts/multicall.d.ts +2 -2
  39. package/dest/contracts/multicall.d.ts.map +1 -1
  40. package/dest/contracts/outbox.d.ts +41 -0
  41. package/dest/contracts/outbox.d.ts.map +1 -0
  42. package/dest/contracts/outbox.js +86 -0
  43. package/dest/contracts/registry.d.ts +1 -1
  44. package/dest/contracts/registry.d.ts.map +1 -1
  45. package/dest/contracts/rollup.d.ts +193 -122
  46. package/dest/contracts/rollup.d.ts.map +1 -1
  47. package/dest/contracts/rollup.js +744 -182
  48. package/dest/contracts/slasher_contract.d.ts +1 -1
  49. package/dest/contracts/slasher_contract.d.ts.map +1 -1
  50. package/dest/contracts/tally_slashing_proposer.d.ts +9 -7
  51. package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -1
  52. package/dest/contracts/tally_slashing_proposer.js +4 -4
  53. package/dest/contracts/utils.d.ts +1 -1
  54. package/dest/deploy_aztec_l1_contracts.d.ts +258 -0
  55. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  56. package/dest/deploy_aztec_l1_contracts.js +397 -0
  57. package/dest/deploy_l1_contract.d.ts +68 -0
  58. package/dest/deploy_l1_contract.d.ts.map +1 -0
  59. package/dest/deploy_l1_contract.js +312 -0
  60. package/dest/eth-signer/eth-signer.d.ts +1 -1
  61. package/dest/eth-signer/index.d.ts +1 -1
  62. package/dest/forwarder_proxy.d.ts +32 -0
  63. package/dest/forwarder_proxy.d.ts.map +1 -0
  64. package/dest/forwarder_proxy.js +93 -0
  65. package/dest/generated/l1-contracts-defaults.d.ts +29 -0
  66. package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
  67. package/dest/generated/l1-contracts-defaults.js +29 -0
  68. package/dest/l1_artifacts.d.ts +5791 -2036
  69. package/dest/l1_artifacts.d.ts.map +1 -1
  70. package/dest/l1_contract_addresses.d.ts +3 -3
  71. package/dest/l1_contract_addresses.d.ts.map +1 -1
  72. package/dest/l1_contract_addresses.js +3 -3
  73. package/dest/l1_reader.d.ts +3 -1
  74. package/dest/l1_reader.d.ts.map +1 -1
  75. package/dest/l1_reader.js +6 -0
  76. package/dest/l1_tx_utils/config.d.ts +5 -5
  77. package/dest/l1_tx_utils/config.d.ts.map +1 -1
  78. package/dest/l1_tx_utils/config.js +30 -7
  79. package/dest/l1_tx_utils/constants.d.ts +7 -1
  80. package/dest/l1_tx_utils/constants.d.ts.map +1 -1
  81. package/dest/l1_tx_utils/constants.js +25 -0
  82. package/dest/l1_tx_utils/factory.d.ts +1 -1
  83. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  84. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  85. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  86. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  87. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  88. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  89. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  90. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  91. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  92. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  93. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  94. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  95. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  96. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  97. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +48 -0
  98. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  99. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  100. package/dest/l1_tx_utils/index-blobs.js +2 -0
  101. package/dest/l1_tx_utils/index.d.ts +3 -1
  102. package/dest/l1_tx_utils/index.d.ts.map +1 -1
  103. package/dest/l1_tx_utils/index.js +2 -0
  104. package/dest/l1_tx_utils/interfaces.d.ts +2 -2
  105. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -1
  106. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
  107. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  108. package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
  109. package/dest/l1_tx_utils/l1_tx_utils.d.ts +1 -2
  110. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
  111. package/dest/l1_tx_utils/l1_tx_utils.js +17 -4
  112. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +1 -1
  113. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +1 -1
  114. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +19 -30
  115. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  116. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +54 -162
  117. package/dest/l1_tx_utils/signer.d.ts +1 -1
  118. package/dest/l1_tx_utils/types.d.ts +1 -1
  119. package/dest/l1_tx_utils/types.d.ts.map +1 -1
  120. package/dest/l1_tx_utils/utils.d.ts +1 -1
  121. package/dest/l1_types.d.ts +1 -1
  122. package/dest/publisher_manager.d.ts +1 -1
  123. package/dest/publisher_manager.d.ts.map +1 -1
  124. package/dest/queries.d.ts +2 -2
  125. package/dest/queries.d.ts.map +1 -1
  126. package/dest/queries.js +14 -5
  127. package/dest/test/chain_monitor.d.ts +27 -24
  128. package/dest/test/chain_monitor.d.ts.map +1 -1
  129. package/dest/test/chain_monitor.js +33 -36
  130. package/dest/test/delayed_tx_utils.d.ts +1 -1
  131. package/dest/test/delayed_tx_utils.d.ts.map +1 -1
  132. package/dest/test/eth_cheat_codes.d.ts +11 -3
  133. package/dest/test/eth_cheat_codes.d.ts.map +1 -1
  134. package/dest/test/eth_cheat_codes.js +11 -3
  135. package/dest/test/eth_cheat_codes_with_state.d.ts +1 -1
  136. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
  137. package/dest/test/index.d.ts +1 -1
  138. package/dest/test/rollup_cheat_codes.d.ts +15 -13
  139. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  140. package/dest/test/rollup_cheat_codes.js +54 -39
  141. package/dest/test/start_anvil.d.ts +4 -1
  142. package/dest/test/start_anvil.d.ts.map +1 -1
  143. package/dest/test/start_anvil.js +2 -1
  144. package/dest/test/tx_delayer.d.ts +1 -1
  145. package/dest/test/tx_delayer.d.ts.map +1 -1
  146. package/dest/test/tx_delayer.js +4 -3
  147. package/dest/test/upgrade_utils.d.ts +1 -1
  148. package/dest/types.d.ts +57 -2
  149. package/dest/types.d.ts.map +1 -1
  150. package/dest/utils.d.ts +15 -3
  151. package/dest/utils.d.ts.map +1 -1
  152. package/dest/utils.js +18 -0
  153. package/dest/zkPassportVerifierAddress.d.ts +1 -1
  154. package/package.json +34 -14
  155. package/src/client.ts +2 -2
  156. package/src/config.ts +64 -458
  157. package/src/contracts/README.md +157 -0
  158. package/src/contracts/empire_base.ts +6 -5
  159. package/src/contracts/empire_slashing_proposer.ts +16 -5
  160. package/src/contracts/fee_asset_handler.ts +8 -7
  161. package/src/contracts/governance_proposer.ts +16 -5
  162. package/src/contracts/inbox.ts +55 -3
  163. package/src/contracts/index.ts +2 -0
  164. package/src/contracts/log.ts +13 -0
  165. package/src/contracts/outbox.ts +98 -0
  166. package/src/contracts/rollup.ts +416 -159
  167. package/src/contracts/tally_slashing_proposer.ts +11 -8
  168. package/src/deploy_aztec_l1_contracts.ts +618 -0
  169. package/src/deploy_l1_contract.ts +362 -0
  170. package/src/forwarder_proxy.ts +108 -0
  171. package/src/generated/l1-contracts-defaults.ts +31 -0
  172. package/src/l1_contract_addresses.ts +22 -20
  173. package/src/l1_reader.ts +8 -0
  174. package/src/l1_tx_utils/config.ts +32 -11
  175. package/src/l1_tx_utils/constants.ts +11 -0
  176. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  177. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
  178. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
  179. package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
  180. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +119 -0
  181. package/src/l1_tx_utils/index-blobs.ts +2 -0
  182. package/src/l1_tx_utils/index.ts +2 -0
  183. package/src/l1_tx_utils/interfaces.ts +1 -1
  184. package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
  185. package/src/l1_tx_utils/l1_tx_utils.ts +24 -4
  186. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +67 -207
  187. package/src/queries.ts +16 -6
  188. package/src/test/chain_monitor.ts +51 -49
  189. package/src/test/eth_cheat_codes.ts +9 -3
  190. package/src/test/rollup_cheat_codes.ts +54 -43
  191. package/src/test/start_anvil.ts +4 -0
  192. package/src/test/tx_delayer.ts +5 -3
  193. package/src/types.ts +62 -0
  194. package/src/utils.ts +30 -1
  195. package/dest/deploy_l1_contracts.d.ts +0 -226
  196. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  197. package/dest/deploy_l1_contracts.js +0 -1473
  198. package/dest/index.d.ts +0 -18
  199. package/dest/index.d.ts.map +0 -1
  200. package/dest/index.js +0 -17
  201. package/src/deploy_l1_contracts.ts +0 -1849
  202. package/src/index.ts +0 -17
@@ -1,6 +1,11 @@
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';
7
+ import { makeBackoff, retry } from '@aztec/foundation/retry';
8
+ import { EscapeHatchAbi } from '@aztec/l1-artifacts/EscapeHatchAbi';
4
9
  import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
5
10
  import { RollupStorage } from '@aztec/l1-artifacts/RollupStorage';
6
11
 
@@ -18,7 +23,7 @@ import {
18
23
  } from 'viem';
19
24
 
20
25
  import { getPublicClient } from '../client.js';
21
- import type { DeployL1ContractsReturnType } from '../deploy_l1_contracts.js';
26
+ import type { DeployAztecL1ContractsReturnType } from '../deploy_aztec_l1_contracts.js';
22
27
  import type { L1ContractAddresses } from '../l1_contract_addresses.js';
23
28
  import type { L1ReaderConfig } from '../l1_reader.js';
24
29
  import type { L1TxRequest, L1TxUtils } from '../l1_tx_utils/index.js';
@@ -26,6 +31,7 @@ import type { ViemClient } from '../types.js';
26
31
  import { formatViemError } from '../utils.js';
27
32
  import { EmpireSlashingProposerContract } from './empire_slashing_proposer.js';
28
33
  import { GSEContract } from './gse.js';
34
+ import type { L1EventLog } from './log.js';
29
35
  import { SlasherContract } from './slasher_contract.js';
30
36
  import { TallySlashingProposerContract } from './tally_slashing_proposer.js';
31
37
  import { checkBlockTag } from './utils.js';
@@ -56,12 +62,16 @@ export type L1RollupContractAddresses = Pick<
56
62
  export type EpochProofPublicInputArgs = {
57
63
  previousArchive: `0x${string}`;
58
64
  endArchive: `0x${string}`;
65
+ outHash: `0x${string}`;
59
66
  proverId: `0x${string}`;
60
67
  };
61
68
 
62
69
  export type ViemHeader = {
63
70
  lastArchiveRoot: `0x${string}`;
64
- contentCommitment: ViemContentCommitment;
71
+ blockHeadersHash: `0x${string}`;
72
+ blobsHash: `0x${string}`;
73
+ inHash: `0x${string}`;
74
+ outHash: `0x${string}`;
65
75
  slotNumber: bigint;
66
76
  timestamp: bigint;
67
77
  coinbase: `0x${string}`;
@@ -70,43 +80,136 @@ export type ViemHeader = {
70
80
  totalManaUsed: bigint;
71
81
  };
72
82
 
73
- export type ViemContentCommitment = {
74
- blobsHash: `0x${string}`;
75
- inHash: `0x${string}`;
76
- outHash: `0x${string}`;
77
- };
78
-
79
83
  export type ViemGasFees = {
80
84
  feePerDaGas: bigint;
81
85
  feePerL2Gas: bigint;
82
86
  };
83
87
 
84
- export type ViemStateReference = {
85
- l1ToL2MessageTree: ViemAppendOnlyTreeSnapshot;
86
- partialStateReference: ViemPartialStateReference;
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
+ feeAssetPriceNumerator: bigint;
112
+ congestionCost: bigint;
113
+ proverCost: bigint;
87
114
  };
88
115
 
89
- export type ViemPartialStateReference = {
90
- noteHashTree: ViemAppendOnlyTreeSnapshot;
91
- nullifierTree: ViemAppendOnlyTreeSnapshot;
92
- publicDataTree: ViemAppendOnlyTreeSnapshot;
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;
93
127
  };
94
128
 
95
- export type ViemAppendOnlyTreeSnapshot = {
96
- root: `0x${string}`;
97
- nextAvailableLeafIndex: number;
129
+ /**
130
+ * L1 fee data (base fee and blob fee)
131
+ */
132
+ export type L1FeeData = {
133
+ baseFee: bigint;
134
+ blobFee: bigint;
98
135
  };
99
136
 
100
- export enum SlashingProposerType {
101
- None = 0,
102
- Tally = 1,
103
- Empire = 2,
104
- }
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>;
105
204
 
106
205
  export class RollupContract {
107
206
  private readonly rollup: GetContractReturnType<typeof RollupAbi, ViemClient>;
108
207
 
109
208
  private static cachedStfStorageSlot: Hex | undefined;
209
+ private cachedEscapeHatch?: {
210
+ address: EthAddress;
211
+ contract: GetContractReturnType<typeof EscapeHatchAbi, ViemClient>;
212
+ };
110
213
 
111
214
  static get checkBlobStorageSlot(): bigint {
112
215
  const asString = RollupStorage.find(storage => storage.label === 'checkBlob')?.slot;
@@ -120,7 +223,7 @@ export class RollupContract {
120
223
  return (RollupContract.cachedStfStorageSlot ??= keccak256(Buffer.from('aztec.stf.storage', 'utf-8')));
121
224
  }
122
225
 
123
- static getFromL1ContractsValues(deployL1ContractsValues: DeployL1ContractsReturnType) {
226
+ static getFromL1ContractsValues(deployL1ContractsValues: DeployAztecL1ContractsReturnType) {
124
227
  const {
125
228
  l1Client,
126
229
  l1ContractAddresses: { rollupAddress },
@@ -144,8 +247,8 @@ export class RollupContract {
144
247
  this.rollup = getContract({ address, abi: RollupAbi, client });
145
248
  }
146
249
 
147
- getGSE() {
148
- return this.rollup.read.getGSE();
250
+ async getGSE(): Promise<EthAddress> {
251
+ return EthAddress.fromString(await this.rollup.read.getGSE());
149
252
  }
150
253
 
151
254
  public get address() {
@@ -187,88 +290,93 @@ export class RollupContract {
187
290
  }
188
291
 
189
292
  @memoize
190
- getL1StartBlock() {
293
+ getL1StartBlock(): Promise<bigint> {
191
294
  return this.rollup.read.L1_BLOCK_AT_GENESIS();
192
295
  }
193
296
 
194
297
  @memoize
195
- getL1GenesisTime() {
298
+ getL1GenesisTime(): Promise<bigint> {
196
299
  return this.rollup.read.getGenesisTime();
197
300
  }
198
301
 
199
302
  @memoize
200
- getProofSubmissionEpochs() {
201
- return this.rollup.read.getProofSubmissionEpochs();
303
+ async getProofSubmissionEpochs(): Promise<number> {
304
+ return Number(await this.rollup.read.getProofSubmissionEpochs());
202
305
  }
203
306
 
204
307
  @memoize
205
- getEpochDuration() {
206
- return this.rollup.read.getEpochDuration();
308
+ async getEpochDuration(): Promise<number> {
309
+ return Number(await this.rollup.read.getEpochDuration());
207
310
  }
208
311
 
209
312
  @memoize
210
- getSlotDuration() {
211
- return this.rollup.read.getSlotDuration();
313
+ async getSlotDuration(): Promise<number> {
314
+ return Number(await this.rollup.read.getSlotDuration());
212
315
  }
213
316
 
214
317
  @memoize
215
- getTargetCommitteeSize() {
216
- return this.rollup.read.getTargetCommitteeSize();
318
+ async getTargetCommitteeSize(): Promise<number> {
319
+ return Number(await this.rollup.read.getTargetCommitteeSize());
217
320
  }
218
321
 
219
322
  @memoize
220
- getEjectionThreshold() {
323
+ getEjectionThreshold(): Promise<bigint> {
221
324
  return this.rollup.read.getEjectionThreshold();
222
325
  }
223
326
 
224
327
  @memoize
225
- getLocalEjectionThreshold() {
328
+ getLocalEjectionThreshold(): Promise<bigint> {
226
329
  return this.rollup.read.getLocalEjectionThreshold();
227
330
  }
228
331
 
229
332
  @memoize
230
- getLagInEpochs() {
231
- return this.rollup.read.getLagInEpochs();
333
+ async getLagInEpochsForValidatorSet(): Promise<number> {
334
+ return Number(await this.rollup.read.getLagInEpochsForValidatorSet());
335
+ }
336
+
337
+ @memoize
338
+ async getLagInEpochsForRandao(): Promise<number> {
339
+ return Number(await this.rollup.read.getLagInEpochsForRandao());
232
340
  }
233
341
 
234
342
  @memoize
235
- getActivationThreshold() {
343
+ getActivationThreshold(): Promise<bigint> {
236
344
  return this.rollup.read.getActivationThreshold();
237
345
  }
238
346
 
239
347
  @memoize
240
- getExitDelay() {
241
- return this.rollup.read.getExitDelay();
348
+ async getExitDelay(): Promise<number> {
349
+ return Number(await this.rollup.read.getExitDelay());
242
350
  }
243
351
 
244
352
  @memoize
245
- getManaTarget() {
353
+ getManaTarget(): Promise<bigint> {
246
354
  return this.rollup.read.getManaTarget();
247
355
  }
248
356
 
249
357
  @memoize
250
- getProvingCostPerMana() {
358
+ getProvingCostPerMana(): Promise<bigint> {
251
359
  return this.rollup.read.getProvingCostPerManaInEth();
252
360
  }
253
361
 
254
362
  @memoize
255
- getProvingCostPerManaInFeeAsset() {
363
+ getProvingCostPerManaInFeeAsset(): Promise<bigint> {
256
364
  return this.rollup.read.getProvingCostPerManaInFeeAsset();
257
365
  }
258
366
 
259
367
  @memoize
260
- getManaLimit() {
368
+ getManaLimit(): Promise<bigint> {
261
369
  return this.rollup.read.getManaLimit();
262
370
  }
263
371
 
264
372
  @memoize
265
- getVersion() {
373
+ getVersion(): Promise<bigint> {
266
374
  return this.rollup.read.getVersion();
267
375
  }
268
376
 
269
377
  @memoize
270
- async getGenesisArchiveTreeRoot(): Promise<`0x${string}`> {
271
- return await this.rollup.read.archiveAt([0n]);
378
+ async getGenesisArchiveTreeRoot(): Promise<Fr> {
379
+ return Fr.fromString(await this.rollup.read.archiveAt([0n]));
272
380
  }
273
381
 
274
382
  /**
@@ -294,33 +402,85 @@ export class RollupContract {
294
402
  return {
295
403
  l1StartBlock,
296
404
  l1GenesisTime,
297
- slotDuration: Number(slotDuration),
405
+ slotDuration,
298
406
  epochDuration: Number(epochDuration),
299
407
  proofSubmissionEpochs: Number(proofSubmissionEpochs),
300
408
  };
301
409
  }
302
410
 
303
- getSlasherAddress() {
304
- return this.rollup.read.getSlasher();
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
+ }
305
465
  }
306
466
 
307
467
  /**
308
468
  * Returns a SlasherContract instance for interacting with the slasher contract.
309
469
  */
310
470
  async getSlasherContract(): Promise<SlasherContract | undefined> {
311
- const slasherAddress = EthAddress.fromString(await this.getSlasherAddress());
471
+ const slasherAddress = await this.getSlasherAddress();
312
472
  if (slasherAddress.isZero()) {
313
473
  return undefined;
314
474
  }
315
475
  return new SlasherContract(this.client, slasherAddress);
316
476
  }
317
477
 
318
- getOwner() {
319
- return this.rollup.read.owner();
478
+ async getOwner(): Promise<EthAddress> {
479
+ return EthAddress.fromString(await this.rollup.read.owner());
320
480
  }
321
481
 
322
- getActiveAttesterCount() {
323
- return this.rollup.read.getActiveAttesterCount();
482
+ async getActiveAttesterCount(): Promise<number> {
483
+ return Number(await this.rollup.read.getActiveAttesterCount());
324
484
  }
325
485
 
326
486
  public async getSlashingProposerAddress() {
@@ -331,31 +491,35 @@ export class RollupContract {
331
491
  return await slasher.getProposer();
332
492
  }
333
493
 
334
- getBlockReward() {
335
- return this.rollup.read.getBlockReward();
494
+ getCheckpointReward(): Promise<bigint> {
495
+ return this.rollup.read.getCheckpointReward();
336
496
  }
337
497
 
338
- getBlockNumber() {
339
- return this.rollup.read.getPendingBlockNumber();
498
+ async getCheckpointNumber(): Promise<CheckpointNumber> {
499
+ return CheckpointNumber.fromBigInt(await this.rollup.read.getPendingCheckpointNumber());
340
500
  }
341
501
 
342
- getProvenBlockNumber() {
343
- return this.rollup.read.getProvenBlockNumber();
502
+ async getProvenCheckpointNumber(): Promise<CheckpointNumber> {
503
+ return CheckpointNumber.fromBigInt(await this.rollup.read.getProvenCheckpointNumber());
344
504
  }
345
505
 
346
- getSlotNumber() {
347
- return this.rollup.read.getCurrentSlot();
506
+ async getSlotNumber(): Promise<SlotNumber> {
507
+ return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
348
508
  }
349
509
 
350
- getL1FeesAt(timestamp: bigint) {
351
- return this.rollup.read.getL1FeesAt([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
+ };
352
516
  }
353
517
 
354
- getFeeAssetPerEth() {
518
+ getFeeAssetPerEth(): Promise<bigint> {
355
519
  return this.rollup.read.getFeeAssetPerEth();
356
520
  }
357
521
 
358
- async getCommitteeAt(timestamp: bigint): Promise<readonly `0x${string}`[] | undefined> {
522
+ async getCommitteeAt(timestamp: bigint): Promise<EthAddress[] | undefined> {
359
523
  const { result } = await this.client
360
524
  .simulateContract({
361
525
  address: this.address,
@@ -370,22 +534,22 @@ export class RollupContract {
370
534
  throw e;
371
535
  });
372
536
 
373
- return result;
537
+ return result ? result.map(addr => EthAddress.fromString(addr)) : undefined;
374
538
  }
375
539
 
376
- getSampleSeedAt(timestamp: bigint) {
377
- return this.rollup.read.getSampleSeedAt([timestamp]);
540
+ async getSampleSeedAt(timestamp: bigint): Promise<Buffer32> {
541
+ return Buffer32.fromBigInt(await this.rollup.read.getSampleSeedAt([timestamp]));
378
542
  }
379
543
 
380
- getCurrentSampleSeed() {
381
- return this.rollup.read.getCurrentSampleSeed();
544
+ async getCurrentSampleSeed(): Promise<Buffer32> {
545
+ return Buffer32.fromBigInt(await this.rollup.read.getCurrentSampleSeed());
382
546
  }
383
547
 
384
- getCurrentEpoch() {
385
- return this.rollup.read.getCurrentEpoch();
548
+ async getCurrentEpoch(): Promise<EpochNumber> {
549
+ return EpochNumber.fromBigInt(await this.rollup.read.getCurrentEpoch());
386
550
  }
387
551
 
388
- async getCurrentEpochCommittee(): Promise<readonly `0x${string}`[] | undefined> {
552
+ async getCurrentEpochCommittee(): Promise<EthAddress[] | undefined> {
389
553
  const { result } = await this.client
390
554
  .simulateContract({
391
555
  address: this.address,
@@ -400,10 +564,10 @@ export class RollupContract {
400
564
  throw e;
401
565
  });
402
566
 
403
- return result;
567
+ return result ? result.map(addr => EthAddress.fromString(addr)) : undefined;
404
568
  }
405
569
 
406
- async getCurrentProposer() {
570
+ async getCurrentProposer(): Promise<EthAddress> {
407
571
  const { result } = await this.client.simulateContract({
408
572
  address: this.address,
409
573
  abi: RollupAbi,
@@ -411,10 +575,10 @@ export class RollupContract {
411
575
  args: [],
412
576
  });
413
577
 
414
- return result;
578
+ return EthAddress.fromString(result);
415
579
  }
416
580
 
417
- async getProposerAt(timestamp: bigint) {
581
+ async getProposerAt(timestamp: bigint): Promise<EthAddress> {
418
582
  const { result } = await this.client.simulateContract({
419
583
  address: this.address,
420
584
  abi: RollupAbi,
@@ -422,39 +586,73 @@ export class RollupContract {
422
586
  args: [timestamp],
423
587
  });
424
588
 
425
- return result;
589
+ return EthAddress.fromString(result);
426
590
  }
427
591
 
428
- getBlock(blockNumber: bigint | number) {
429
- return this.rollup.read.getBlock([BigInt(blockNumber)]);
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
+ feeAssetPriceNumerator: result.feeHeader.feeAssetPriceNumerator,
605
+ congestionCost: result.feeHeader.congestionCost,
606
+ proverCost: result.feeHeader.proverCost,
607
+ },
608
+ };
430
609
  }
431
610
 
432
- getTips() {
433
- return this.rollup.read.getTips();
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
+ );
624
+ }
625
+
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
+ };
434
632
  }
435
633
 
436
- getTimestampForSlot(slot: bigint) {
437
- return this.rollup.read.getTimestampForSlot([slot]);
634
+ getTimestampForSlot(slot: SlotNumber): Promise<bigint> {
635
+ return this.rollup.read.getTimestampForSlot([BigInt(slot)]);
438
636
  }
439
637
 
440
- getEntryQueueLength() {
441
- return this.rollup.read.getEntryQueueLength();
638
+ async getEntryQueueLength(): Promise<number> {
639
+ return Number(await this.rollup.read.getEntryQueueLength());
442
640
  }
443
641
 
444
- getAvailableValidatorFlushes() {
445
- return this.rollup.read.getAvailableValidatorFlushes();
642
+ async getAvailableValidatorFlushes(): Promise<number> {
643
+ return Number(await this.rollup.read.getAvailableValidatorFlushes());
446
644
  }
447
645
 
448
- getNextFlushableEpoch() {
449
- return this.rollup.read.getNextFlushableEpoch();
646
+ async getNextFlushableEpoch(): Promise<EpochNumber> {
647
+ return EpochNumber.fromBigInt(await this.rollup.read.getNextFlushableEpoch());
450
648
  }
451
649
 
452
- getCurrentEpochNumber(): Promise<bigint> {
453
- return this.rollup.read.getCurrentEpoch();
650
+ async getCurrentEpochNumber(): Promise<EpochNumber> {
651
+ return EpochNumber.fromBigInt(await this.rollup.read.getCurrentEpoch());
454
652
  }
455
653
 
456
- getEpochNumberForBlock(blockNumber: bigint) {
457
- return this.rollup.read.getEpochForBlock([BigInt(blockNumber)]);
654
+ async getEpochNumberForCheckpoint(checkpointNumber: CheckpointNumber): Promise<EpochNumber> {
655
+ return EpochNumber.fromBigInt(await this.rollup.read.getEpochForCheckpoint([BigInt(checkpointNumber)]));
458
656
  }
459
657
 
460
658
  async getRollupAddresses(): Promise<L1RollupContractAddresses> {
@@ -494,14 +692,15 @@ export class RollupContract {
494
692
  return EthAddress.fromString(await this.rollup.read.getFeeAssetPortal());
495
693
  }
496
694
 
497
- public async getEpochNumberForSlotNumber(slotNumber: bigint): Promise<bigint> {
498
- return await this.rollup.read.getEpochAtSlot([slotNumber]);
695
+ public async getEpochNumberForSlotNumber(slotNumber: SlotNumber): Promise<EpochNumber> {
696
+ return EpochNumber.fromBigInt(await this.rollup.read.getEpochAtSlot([BigInt(slotNumber)]));
499
697
  }
500
698
 
501
- getEpochProofPublicInputs(
699
+ async getEpochProofPublicInputs(
502
700
  args: readonly [bigint, bigint, EpochProofPublicInputArgs, readonly `0x${string}`[], `0x${string}`],
503
- ) {
504
- return this.rollup.read.getEpochProofPublicInputs(args);
701
+ ): Promise<Fr[]> {
702
+ const result = await this.rollup.read.getEpochProofPublicInputs(args);
703
+ return result.map(Fr.fromString);
505
704
  }
506
705
 
507
706
  public async validateHeader(
@@ -538,53 +737,57 @@ export class RollupContract {
538
737
  * @dev Throws if unable to propose
539
738
  *
540
739
  * @param archive - The archive that we expect to be current state
541
- * @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
542
742
  * @throws otherwise
543
743
  */
544
744
  public async canProposeAtNextEthBlock(
545
745
  archive: Buffer,
546
746
  account: `0x${string}` | Account,
547
- slotDuration: bigint | number,
548
- opts: { forcePendingBlockNumber?: number } = {},
549
- ): Promise<{ slot: bigint; blockNumber: bigint; timeOfNextL1Slot: bigint }> {
550
- if (typeof slotDuration === 'number') {
551
- slotDuration = BigInt(slotDuration);
552
- }
747
+ slotDuration: number,
748
+ opts: { forcePendingCheckpointNumber?: CheckpointNumber } = {},
749
+ ): Promise<{ slot: SlotNumber; checkpointNumber: CheckpointNumber; timeOfNextL1Slot: bigint }> {
553
750
  const latestBlock = await this.client.getBlock();
554
- const timeOfNextL1Slot = latestBlock.timestamp + slotDuration;
751
+ const timeOfNextL1Slot = latestBlock.timestamp + BigInt(slotDuration);
555
752
  const who = typeof account === 'string' ? account : account.address;
556
753
 
557
754
  try {
558
755
  const {
559
- result: [slot, blockNumber],
756
+ result: [slot, checkpointNumber],
560
757
  } = await this.client.simulateContract({
561
758
  address: this.address,
562
759
  abi: RollupAbi,
563
760
  functionName: 'canProposeAtTime',
564
761
  args: [timeOfNextL1Slot, `0x${archive.toString('hex')}`, who],
565
762
  account,
566
- stateOverride: await this.makePendingBlockNumberOverride(opts.forcePendingBlockNumber),
763
+ stateOverride: await this.makePendingCheckpointNumberOverride(opts.forcePendingCheckpointNumber),
567
764
  });
568
765
 
569
- return { slot, blockNumber, timeOfNextL1Slot };
766
+ return {
767
+ slot: SlotNumber.fromBigInt(slot),
768
+ checkpointNumber: CheckpointNumber.fromBigInt(checkpointNumber),
769
+ timeOfNextL1Slot,
770
+ };
570
771
  } catch (err: unknown) {
571
772
  throw formatViemError(err);
572
773
  }
573
774
  }
574
775
 
575
776
  /**
576
- * Returns a state override that sets the pending block number to the specified value. Useful for simulations.
577
- * Requires querying the current state of the contract to get the current proven block number, as they are both
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
578
779
  * stored in the same slot. If the argument is undefined, it returns an empty override.
579
780
  */
580
- public async makePendingBlockNumberOverride(forcePendingBlockNumber: number | undefined): Promise<StateOverride> {
581
- if (forcePendingBlockNumber === undefined) {
781
+ public async makePendingCheckpointNumberOverride(
782
+ forcePendingCheckpointNumber: CheckpointNumber | undefined,
783
+ ): Promise<StateOverride> {
784
+ if (forcePendingCheckpointNumber === undefined) {
582
785
  return [];
583
786
  }
584
787
  const slot = RollupContract.stfStorageSlot;
585
788
  const currentValue = await this.client.getStorageAt({ address: this.address, slot });
586
- const currentProvenBlockNumber = currentValue ? hexToBigInt(currentValue) & ((1n << 128n) - 1n) : 0n;
587
- const newValue = (BigInt(forcePendingBlockNumber) << 128n) | currentProvenBlockNumber;
789
+ const currentProvenCheckpointNumber = currentValue ? hexToBigInt(currentValue) & ((1n << 128n) - 1n) : 0n;
790
+ const newValue = (BigInt(forcePendingCheckpointNumber) << 128n) | currentProvenCheckpointNumber;
588
791
  return [
589
792
  {
590
793
  address: this.address,
@@ -595,7 +798,7 @@ export class RollupContract {
595
798
 
596
799
  /** Creates a request to Rollup#invalidateBadAttestation to be simulated or sent */
597
800
  public buildInvalidateBadAttestationRequest(
598
- blockNumber: number,
801
+ checkpointNumber: CheckpointNumber,
599
802
  attestationsAndSigners: ViemCommitteeAttestations,
600
803
  committee: EthAddress[],
601
804
  invalidIndex: number,
@@ -606,7 +809,7 @@ export class RollupContract {
606
809
  abi: RollupAbi,
607
810
  functionName: 'invalidateBadAttestation',
608
811
  args: [
609
- BigInt(blockNumber),
812
+ BigInt(checkpointNumber),
610
813
  attestationsAndSigners,
611
814
  committee.map(addr => addr.toString()),
612
815
  BigInt(invalidIndex),
@@ -617,7 +820,7 @@ export class RollupContract {
617
820
 
618
821
  /** Creates a request to Rollup#invalidateInsufficientAttestations to be simulated or sent */
619
822
  public buildInvalidateInsufficientAttestationsRequest(
620
- blockNumber: number,
823
+ checkpointNumber: CheckpointNumber,
621
824
  attestationsAndSigners: ViemCommitteeAttestations,
622
825
  committee: EthAddress[],
623
826
  ): L1TxRequest {
@@ -626,98 +829,131 @@ export class RollupContract {
626
829
  data: encodeFunctionData({
627
830
  abi: RollupAbi,
628
831
  functionName: 'invalidateInsufficientAttestations',
629
- args: [BigInt(blockNumber), attestationsAndSigners, committee.map(addr => addr.toString())],
832
+ args: [BigInt(checkpointNumber), attestationsAndSigners, committee.map(addr => addr.toString())],
630
833
  }),
631
834
  };
632
835
  }
633
836
 
634
837
  /** Calls getHasSubmitted directly. Returns whether the given prover has submitted a proof with the given length for the given epoch. */
635
- public getHasSubmittedProof(epochNumber: number, numberOfBlocksInEpoch: number, prover: Hex | EthAddress) {
838
+ public getHasSubmittedProof(epochNumber: EpochNumber, numberOfCheckpointsInEpoch: number, prover: Hex | EthAddress) {
636
839
  if (prover instanceof EthAddress) {
637
840
  prover = prover.toString();
638
841
  }
639
- return this.rollup.read.getHasSubmitted([BigInt(epochNumber), BigInt(numberOfBlocksInEpoch), prover]);
842
+ return this.rollup.read.getHasSubmitted([BigInt(epochNumber), BigInt(numberOfCheckpointsInEpoch), prover]);
640
843
  }
641
844
 
642
- getManaBaseFeeAt(timestamp: bigint, inFeeAsset: boolean) {
643
- return this.rollup.read.getManaBaseFeeAt([timestamp, inFeeAsset]);
845
+ getManaMinFeeAt(timestamp: bigint, inFeeAsset: boolean): Promise<bigint> {
846
+ return this.rollup.read.getManaMinFeeAt([timestamp, inFeeAsset]);
644
847
  }
645
848
 
646
- getSlotAt(timestamp: bigint) {
647
- return this.rollup.read.getSlotAt([timestamp]);
849
+ async getSlotAt(timestamp: bigint): Promise<SlotNumber> {
850
+ return SlotNumber.fromBigInt(await this.rollup.read.getSlotAt([timestamp]));
648
851
  }
649
852
 
650
- async status(blockNumber: bigint, options?: { blockNumber?: bigint }) {
853
+ async status(checkpointNumber: CheckpointNumber, options?: { blockNumber?: bigint }): Promise<RollupStatusResponse> {
651
854
  await checkBlockTag(options?.blockNumber, this.client);
652
- return this.rollup.read.status([blockNumber], options);
855
+ const result = await this.rollup.read.status([BigInt(checkpointNumber)], options);
856
+ return {
857
+ provenCheckpointNumber: CheckpointNumber.fromBigInt(result[0]),
858
+ provenArchive: Fr.fromString(result[1]),
859
+ pendingCheckpointNumber: CheckpointNumber.fromBigInt(result[2]),
860
+ pendingArchive: Fr.fromString(result[3]),
861
+ archiveOfMyCheckpoint: Fr.fromString(result[4]),
862
+ };
653
863
  }
654
864
 
655
- async canPruneAtTime(timestamp: bigint, options?: { blockNumber?: bigint }) {
865
+ async canPruneAtTime(timestamp: bigint, options?: { blockNumber?: bigint }): Promise<boolean> {
656
866
  await checkBlockTag(options?.blockNumber, this.client);
657
867
  return this.rollup.read.canPruneAtTime([timestamp], options);
658
868
  }
659
869
 
660
- archive() {
661
- return this.rollup.read.archive();
870
+ async archive(): Promise<Fr> {
871
+ return Fr.fromString(await this.rollup.read.archive());
662
872
  }
663
873
 
664
- archiveAt(blockNumber: bigint) {
665
- return this.rollup.read.archiveAt([blockNumber]);
874
+ async archiveAt(checkpointNumber: CheckpointNumber): Promise<Fr> {
875
+ return Fr.fromString(await this.rollup.read.archiveAt([BigInt(checkpointNumber)]));
666
876
  }
667
877
 
668
- getSequencerRewards(address: Hex | EthAddress) {
878
+ getSequencerRewards(address: Hex | EthAddress): Promise<bigint> {
669
879
  if (address instanceof EthAddress) {
670
880
  address = address.toString();
671
881
  }
672
882
  return this.rollup.read.getSequencerRewards([address]);
673
883
  }
674
884
 
675
- getSpecificProverRewardsForEpoch(epoch: bigint, prover: Hex | EthAddress) {
885
+ getSpecificProverRewardsForEpoch(epoch: bigint, prover: Hex | EthAddress): Promise<bigint> {
676
886
  if (prover instanceof EthAddress) {
677
887
  prover = prover.toString();
678
888
  }
679
889
  return this.rollup.read.getSpecificProverRewardsForEpoch([epoch, prover]);
680
890
  }
681
891
 
682
- async getAttesters() {
892
+ async getAttesters(): Promise<EthAddress[]> {
683
893
  const attesterSize = await this.getActiveAttesterCount();
684
894
  const gse = new GSEContract(this.client, await this.getGSE());
685
895
  const ts = (await this.client.getBlock()).timestamp;
686
896
 
687
- const indices = Array.from({ length: Number(attesterSize) }, (_, i) => BigInt(i));
897
+ const indices = Array.from({ length: attesterSize }, (_, i) => BigInt(i));
688
898
  const chunks = chunk(indices, 1000);
689
899
 
690
- return (await Promise.all(chunks.map(chunk => gse.getAttestersFromIndicesAtTime(this.address, ts, chunk)))).flat();
900
+ const results = await Promise.all(chunks.map(chunk => gse.getAttestersFromIndicesAtTime(this.address, ts, chunk)));
901
+ return results.flat().map(addr => EthAddress.fromString(addr));
691
902
  }
692
903
 
693
- getAttesterView(address: Hex | EthAddress) {
904
+ async getAttesterView(address: Hex | EthAddress): Promise<AttesterView> {
694
905
  if (address instanceof EthAddress) {
695
906
  address = address.toString();
696
907
  }
697
- return this.rollup.read.getAttesterView([address]);
908
+ const result = await this.rollup.read.getAttesterView([address]);
909
+ return {
910
+ status: result.status as AttesterStatus,
911
+ effectiveBalance: result.effectiveBalance,
912
+ exit: {
913
+ withdrawalId: result.exit.withdrawalId,
914
+ amount: result.exit.amount,
915
+ exitableAt: result.exit.exitableAt,
916
+ recipientOrWithdrawer: EthAddress.fromString(result.exit.recipientOrWithdrawer),
917
+ isRecipient: result.exit.isRecipient,
918
+ exists: result.exit.exists,
919
+ },
920
+ config: {
921
+ publicKey: {
922
+ x: result.config.publicKey.x,
923
+ y: result.config.publicKey.y,
924
+ },
925
+ withdrawer: EthAddress.fromString(result.config.withdrawer),
926
+ },
927
+ };
698
928
  }
699
929
 
700
- getStatus(address: Hex | EthAddress) {
930
+ async getStatus(address: Hex | EthAddress): Promise<AttesterStatus> {
701
931
  if (address instanceof EthAddress) {
702
932
  address = address.toString();
703
933
  }
704
- return this.rollup.read.getStatus([address]);
934
+ return (await this.rollup.read.getStatus([address])) as AttesterStatus;
705
935
  }
706
936
 
707
- getBlobCommitmentsHash(blockNumber: bigint) {
708
- return this.rollup.read.getBlobCommitmentsHash([blockNumber]);
937
+ async getBlobCommitmentsHash(checkpointNumber: CheckpointNumber): Promise<Buffer32> {
938
+ return Buffer32.fromString(await this.rollup.read.getBlobCommitmentsHash([BigInt(checkpointNumber)]));
709
939
  }
710
940
 
711
- getCurrentBlobCommitmentsHash() {
712
- return this.rollup.read.getCurrentBlobCommitmentsHash();
941
+ async getCurrentBlobCommitmentsHash(): Promise<Buffer32> {
942
+ return Buffer32.fromString(await this.rollup.read.getCurrentBlobCommitmentsHash());
713
943
  }
714
944
 
715
- getStakingAsset() {
716
- return this.rollup.read.getStakingAsset();
945
+ async getStakingAsset(): Promise<EthAddress> {
946
+ return EthAddress.fromString(await this.rollup.read.getStakingAsset());
717
947
  }
718
948
 
719
- getRewardConfig() {
720
- return this.rollup.read.getRewardConfig();
949
+ async getRewardConfig(): Promise<RewardConfig> {
950
+ const result = await this.rollup.read.getRewardConfig();
951
+ return {
952
+ rewardDistributor: EthAddress.fromString(result.rewardDistributor),
953
+ sequencerBps: BigInt(result.sequencerBps),
954
+ booster: EthAddress.fromString(result.booster),
955
+ checkpointReward: result.checkpointReward,
956
+ };
721
957
  }
722
958
 
723
959
  setupEpoch(l1TxUtils: L1TxUtils) {
@@ -760,15 +996,17 @@ export class RollupContract {
760
996
  );
761
997
  }
762
998
 
763
- public listenToBlockInvalidated(callback: (args: { blockNumber: bigint }) => unknown): WatchContractEventReturnType {
764
- return this.rollup.watchEvent.BlockInvalidated(
999
+ public listenToCheckpointInvalidated(
1000
+ callback: (args: { checkpointNumber: CheckpointNumber }) => unknown,
1001
+ ): WatchContractEventReturnType {
1002
+ return this.rollup.watchEvent.CheckpointInvalidated(
765
1003
  {},
766
1004
  {
767
1005
  onLogs: logs => {
768
1006
  for (const log of logs) {
769
1007
  const args = log.args;
770
- if (args.blockNumber !== undefined) {
771
- callback({ blockNumber: args.blockNumber });
1008
+ if (args.checkpointNumber !== undefined) {
1009
+ callback({ checkpointNumber: CheckpointNumber.fromBigInt(args.checkpointNumber) });
772
1010
  }
773
1011
  }
774
1012
  },
@@ -800,4 +1038,23 @@ export class RollupContract {
800
1038
  },
801
1039
  );
802
1040
  }
1041
+
1042
+ /** Fetches CheckpointProposed events within the given block range. */
1043
+ async getCheckpointProposedEvents(fromBlock: bigint, toBlock: bigint): Promise<CheckpointProposedLog[]> {
1044
+ const logs = await this.rollup.getEvents.CheckpointProposed({}, { fromBlock, toBlock });
1045
+ return logs
1046
+ .filter(log => log.blockNumber! >= fromBlock && log.blockNumber! <= toBlock)
1047
+ .map(log => ({
1048
+ l1BlockNumber: log.blockNumber!,
1049
+ l1BlockHash: Buffer32.fromString(log.blockHash!),
1050
+ l1TransactionHash: log.transactionHash!,
1051
+ args: {
1052
+ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
1053
+ archive: Fr.fromString(log.args.archive!),
1054
+ versionedBlobHashes: log.args.versionedBlobHashes!.map(h => Buffer.from(h.slice(2), 'hex')),
1055
+ attestationsHash: log.args.attestationsHash ? Buffer32.fromString(log.args.attestationsHash) : undefined,
1056
+ payloadDigest: log.args.payloadDigest ? Buffer32.fromString(log.args.payloadDigest) : undefined,
1057
+ },
1058
+ }));
1059
+ }
803
1060
  }