@aztec/ethereum 3.0.3 → 3.9.9-nightly.20260312

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 (175) hide show
  1. package/dest/client.js +6 -2
  2. package/dest/config.d.ts +19 -27
  3. package/dest/config.d.ts.map +1 -1
  4. package/dest/config.js +60 -55
  5. package/dest/contracts/empire_base.d.ts +4 -1
  6. package/dest/contracts/empire_base.d.ts.map +1 -1
  7. package/dest/contracts/empire_slashing_proposer.d.ts +4 -1
  8. package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -1
  9. package/dest/contracts/empire_slashing_proposer.js +31 -15
  10. package/dest/contracts/fee_asset_handler.d.ts +6 -5
  11. package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
  12. package/dest/contracts/fee_asset_handler.js +11 -9
  13. package/dest/contracts/fee_asset_price_oracle.d.ts +101 -0
  14. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  15. package/dest/contracts/fee_asset_price_oracle.js +651 -0
  16. package/dest/contracts/governance.d.ts +3 -1
  17. package/dest/contracts/governance.d.ts.map +1 -1
  18. package/dest/contracts/governance.js +14 -4
  19. package/dest/contracts/governance_proposer.d.ts +4 -1
  20. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  21. package/dest/contracts/governance_proposer.js +404 -9
  22. package/dest/contracts/inbox.d.ts +22 -1
  23. package/dest/contracts/inbox.d.ts.map +1 -1
  24. package/dest/contracts/inbox.js +36 -1
  25. package/dest/contracts/index.d.ts +4 -1
  26. package/dest/contracts/index.d.ts.map +1 -1
  27. package/dest/contracts/index.js +3 -0
  28. package/dest/contracts/log.d.ts +13 -0
  29. package/dest/contracts/log.d.ts.map +1 -0
  30. package/dest/contracts/log.js +1 -0
  31. package/dest/contracts/multicall.d.ts +1 -1
  32. package/dest/contracts/multicall.d.ts.map +1 -1
  33. package/dest/contracts/multicall.js +2 -1
  34. package/dest/contracts/outbox.d.ts +41 -0
  35. package/dest/contracts/outbox.d.ts.map +1 -0
  36. package/dest/contracts/outbox.js +86 -0
  37. package/dest/contracts/registry.d.ts +3 -1
  38. package/dest/contracts/registry.d.ts.map +1 -1
  39. package/dest/contracts/registry.js +30 -1
  40. package/dest/contracts/rollup.d.ts +163 -81
  41. package/dest/contracts/rollup.d.ts.map +1 -1
  42. package/dest/contracts/rollup.js +703 -132
  43. package/dest/contracts/tally_slashing_proposer.d.ts +1 -1
  44. package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -1
  45. package/dest/contracts/tally_slashing_proposer.js +8 -1
  46. package/dest/deploy_aztec_l1_contracts.d.ts +18 -4
  47. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
  48. package/dest/deploy_aztec_l1_contracts.js +117 -35
  49. package/dest/deploy_l1_contract.js +3 -3
  50. package/dest/generated/l1-contracts-defaults.d.ts +30 -0
  51. package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
  52. package/dest/generated/l1-contracts-defaults.js +30 -0
  53. package/dest/l1_artifacts.d.ts +5975 -1575
  54. package/dest/l1_artifacts.d.ts.map +1 -1
  55. package/dest/l1_contract_addresses.d.ts +1 -1
  56. package/dest/l1_contract_addresses.d.ts.map +1 -1
  57. package/dest/l1_contract_addresses.js +3 -3
  58. package/dest/l1_tx_utils/config.d.ts +7 -1
  59. package/dest/l1_tx_utils/config.d.ts.map +1 -1
  60. package/dest/l1_tx_utils/config.js +14 -1
  61. package/dest/l1_tx_utils/constants.d.ts +8 -2
  62. package/dest/l1_tx_utils/constants.d.ts.map +1 -1
  63. package/dest/l1_tx_utils/constants.js +27 -2
  64. package/dest/l1_tx_utils/factory.d.ts +18 -10
  65. package/dest/l1_tx_utils/factory.d.ts.map +1 -1
  66. package/dest/l1_tx_utils/factory.js +17 -7
  67. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  68. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  69. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  70. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  71. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  72. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  73. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  74. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  75. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  76. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  77. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  78. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  79. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +15 -15
  80. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -1
  81. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +9 -15
  82. package/dest/l1_tx_utils/index-blobs.d.ts +3 -3
  83. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -1
  84. package/dest/l1_tx_utils/index-blobs.js +2 -2
  85. package/dest/l1_tx_utils/index.d.ts +4 -1
  86. package/dest/l1_tx_utils/index.d.ts.map +1 -1
  87. package/dest/l1_tx_utils/index.js +3 -0
  88. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
  89. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  90. package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
  91. package/dest/l1_tx_utils/l1_tx_utils.d.ts +18 -7
  92. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
  93. package/dest/l1_tx_utils/l1_tx_utils.js +58 -42
  94. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +4 -15
  95. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  96. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +43 -147
  97. package/dest/l1_tx_utils/tx_delayer.d.ts +56 -0
  98. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  99. package/dest/{test → l1_tx_utils}/tx_delayer.js +62 -34
  100. package/dest/publisher_manager.d.ts +3 -2
  101. package/dest/publisher_manager.d.ts.map +1 -1
  102. package/dest/publisher_manager.js +2 -2
  103. package/dest/queries.d.ts +2 -2
  104. package/dest/queries.d.ts.map +1 -1
  105. package/dest/queries.js +12 -4
  106. package/dest/test/chain_monitor.js +1 -2
  107. package/dest/test/eth_cheat_codes.d.ts +13 -1
  108. package/dest/test/eth_cheat_codes.d.ts.map +1 -1
  109. package/dest/test/eth_cheat_codes.js +3 -1
  110. package/dest/test/index.d.ts +1 -3
  111. package/dest/test/index.d.ts.map +1 -1
  112. package/dest/test/index.js +0 -2
  113. package/dest/test/rollup_cheat_codes.d.ts +5 -2
  114. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  115. package/dest/test/rollup_cheat_codes.js +22 -3
  116. package/dest/test/start_anvil.js +1 -1
  117. package/dest/test/upgrade_utils.js +2 -2
  118. package/dest/utils.d.ts +15 -2
  119. package/dest/utils.d.ts.map +1 -1
  120. package/dest/utils.js +64 -0
  121. package/package.json +9 -7
  122. package/src/client.ts +2 -2
  123. package/src/config.ts +76 -54
  124. package/src/contracts/README.md +157 -0
  125. package/src/contracts/empire_base.ts +3 -1
  126. package/src/contracts/empire_slashing_proposer.ts +28 -28
  127. package/src/contracts/fee_asset_handler.ts +10 -7
  128. package/src/contracts/fee_asset_price_oracle.ts +280 -0
  129. package/src/contracts/governance.ts +13 -4
  130. package/src/contracts/governance_proposer.ts +16 -2
  131. package/src/contracts/inbox.ts +53 -1
  132. package/src/contracts/index.ts +3 -0
  133. package/src/contracts/log.ts +13 -0
  134. package/src/contracts/multicall.ts +5 -2
  135. package/src/contracts/outbox.ts +98 -0
  136. package/src/contracts/registry.ts +31 -1
  137. package/src/contracts/rollup.ts +382 -94
  138. package/src/contracts/tally_slashing_proposer.ts +5 -1
  139. package/src/deploy_aztec_l1_contracts.ts +147 -44
  140. package/src/deploy_l1_contract.ts +3 -3
  141. package/src/generated/l1-contracts-defaults.ts +32 -0
  142. package/src/l1_contract_addresses.ts +22 -20
  143. package/src/l1_tx_utils/config.ts +20 -0
  144. package/src/l1_tx_utils/constants.ts +13 -2
  145. package/src/l1_tx_utils/factory.ts +31 -31
  146. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  147. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
  148. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
  149. package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
  150. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +43 -54
  151. package/src/l1_tx_utils/index-blobs.ts +2 -2
  152. package/src/l1_tx_utils/index.ts +3 -0
  153. package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
  154. package/src/l1_tx_utils/l1_tx_utils.ts +60 -32
  155. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +56 -190
  156. package/src/{test → l1_tx_utils}/tx_delayer.ts +78 -50
  157. package/src/publisher_manager.ts +4 -2
  158. package/src/queries.ts +11 -3
  159. package/src/test/chain_monitor.ts +1 -1
  160. package/src/test/eth_cheat_codes.ts +1 -1
  161. package/src/test/index.ts +0 -2
  162. package/src/test/rollup_cheat_codes.ts +22 -4
  163. package/src/test/start_anvil.ts +1 -1
  164. package/src/test/upgrade_utils.ts +2 -2
  165. package/src/utils.ts +82 -0
  166. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +0 -26
  167. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +0 -1
  168. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +0 -26
  169. package/dest/test/delayed_tx_utils.d.ts +0 -13
  170. package/dest/test/delayed_tx_utils.d.ts.map +0 -1
  171. package/dest/test/delayed_tx_utils.js +0 -28
  172. package/dest/test/tx_delayer.d.ts +0 -36
  173. package/dest/test/tx_delayer.d.ts.map +0 -1
  174. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
  175. package/src/test/delayed_tx_utils.ts +0 -52
@@ -1,7 +1,11 @@
1
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';
2
4
  import { memoize } from '@aztec/foundation/decorators';
3
5
  import { EthAddress } from '@aztec/foundation/eth-address';
4
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';
5
9
  import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
6
10
  import { RollupStorage } from '@aztec/l1-artifacts/RollupStorage';
7
11
 
@@ -27,6 +31,7 @@ import type { ViemClient } from '../types.js';
27
31
  import { formatViemError } from '../utils.js';
28
32
  import { EmpireSlashingProposerContract } from './empire_slashing_proposer.js';
29
33
  import { GSEContract } from './gse.js';
34
+ import type { L1EventLog } from './log.js';
30
35
  import { SlasherContract } from './slasher_contract.js';
31
36
  import { TallySlashingProposerContract } from './tally_slashing_proposer.js';
32
37
  import { checkBlockTag } from './utils.js';
@@ -57,13 +62,16 @@ export type L1RollupContractAddresses = Pick<
57
62
  export type EpochProofPublicInputArgs = {
58
63
  previousArchive: `0x${string}`;
59
64
  endArchive: `0x${string}`;
65
+ outHash: `0x${string}`;
60
66
  proverId: `0x${string}`;
61
67
  };
62
68
 
63
69
  export type ViemHeader = {
64
70
  lastArchiveRoot: `0x${string}`;
65
71
  blockHeadersHash: `0x${string}`;
66
- contentCommitment: ViemContentCommitment;
72
+ blobsHash: `0x${string}`;
73
+ inHash: `0x${string}`;
74
+ outHash: `0x${string}`;
67
75
  slotNumber: bigint;
68
76
  timestamp: bigint;
69
77
  coinbase: `0x${string}`;
@@ -72,12 +80,6 @@ export type ViemHeader = {
72
80
  totalManaUsed: bigint;
73
81
  };
74
82
 
75
- export type ViemContentCommitment = {
76
- blobsHash: `0x${string}`;
77
- inHash: `0x${string}`;
78
- outHash: `0x${string}`;
79
- };
80
-
81
83
  export type ViemGasFees = {
82
84
  feePerDaGas: bigint;
83
85
  feePerL2Gas: bigint;
@@ -89,10 +91,125 @@ export enum SlashingProposerType {
89
91
  Empire = 2,
90
92
  }
91
93
 
94
+ /**
95
+ * Status of a validator/attester in the staking system.
96
+ * Matches the Status enum in StakingLib.sol
97
+ */
98
+ export enum AttesterStatus {
99
+ NONE = 0,
100
+ VALIDATING = 1,
101
+ ZOMBIE = 2,
102
+ EXITING = 3,
103
+ }
104
+
105
+ /**
106
+ * Fee header data for a checkpoint
107
+ */
108
+ export type FeeHeader = {
109
+ excessMana: bigint;
110
+ manaUsed: bigint;
111
+ ethPerFeeAsset: bigint;
112
+ congestionCost: bigint;
113
+ proverCost: bigint;
114
+ };
115
+
116
+ /**
117
+ * Checkpoint log data returned from the rollup contract
118
+ */
119
+ export type CheckpointLog = {
120
+ archive: Fr;
121
+ headerHash: Buffer32;
122
+ blobCommitmentsHash: Buffer32;
123
+ attestationsHash: Buffer32;
124
+ payloadDigest: Buffer32;
125
+ slotNumber: SlotNumber;
126
+ feeHeader: FeeHeader;
127
+ };
128
+
129
+ /**
130
+ * L1 fee data (base fee and blob fee)
131
+ */
132
+ export type L1FeeData = {
133
+ baseFee: bigint;
134
+ blobFee: bigint;
135
+ };
136
+
137
+ /**
138
+ * Reward configuration for the rollup
139
+ */
140
+ export type RewardConfig = {
141
+ rewardDistributor: EthAddress;
142
+ sequencerBps: bigint;
143
+ booster: EthAddress;
144
+ checkpointReward: bigint;
145
+ };
146
+
147
+ /**
148
+ * Exit information for a validator
149
+ */
150
+ export type Exit = {
151
+ withdrawalId: bigint;
152
+ amount: bigint;
153
+ exitableAt: bigint;
154
+ recipientOrWithdrawer: EthAddress;
155
+ isRecipient: boolean;
156
+ exists: boolean;
157
+ };
158
+
159
+ /**
160
+ * Attester configuration including public key and withdrawer
161
+ */
162
+ export type AttesterConfig = {
163
+ publicKey: {
164
+ x: bigint;
165
+ y: bigint;
166
+ };
167
+ withdrawer: EthAddress;
168
+ };
169
+
170
+ /**
171
+ * Complete view of an attester's state
172
+ */
173
+ export type AttesterView = {
174
+ status: AttesterStatus;
175
+ effectiveBalance: bigint;
176
+ exit: Exit;
177
+ config: AttesterConfig;
178
+ };
179
+
180
+ /**
181
+ * Return for a status call
182
+ */
183
+ export type RollupStatusResponse = {
184
+ provenCheckpointNumber: CheckpointNumber;
185
+ provenArchive: Fr;
186
+ pendingCheckpointNumber: CheckpointNumber;
187
+ pendingArchive: Fr;
188
+ archiveOfMyCheckpoint: Fr;
189
+ };
190
+
191
+ /** Arguments for the CheckpointProposed event. */
192
+ export type CheckpointProposedArgs = {
193
+ checkpointNumber: CheckpointNumber;
194
+ archive: Fr;
195
+ versionedBlobHashes: Buffer[];
196
+ /** Hash of attestations emitted in the CheckpointProposed event. */
197
+ attestationsHash: Buffer32;
198
+ /** Digest of the payload emitted in the CheckpointProposed event. */
199
+ payloadDigest: Buffer32;
200
+ };
201
+
202
+ /** Log type for CheckpointProposed events. */
203
+ export type CheckpointProposedLog = L1EventLog<CheckpointProposedArgs>;
204
+
92
205
  export class RollupContract {
93
206
  private readonly rollup: GetContractReturnType<typeof RollupAbi, ViemClient>;
94
207
 
95
208
  private static cachedStfStorageSlot: Hex | undefined;
209
+ private cachedEscapeHatch?: {
210
+ address: EthAddress;
211
+ contract: GetContractReturnType<typeof EscapeHatchAbi, ViemClient>;
212
+ };
96
213
 
97
214
  static get checkBlobStorageSlot(): bigint {
98
215
  const asString = RollupStorage.find(storage => storage.label === 'checkBlob')?.slot;
@@ -130,8 +247,8 @@ export class RollupContract {
130
247
  this.rollup = getContract({ address, abi: RollupAbi, client });
131
248
  }
132
249
 
133
- getGSE() {
134
- return this.rollup.read.getGSE();
250
+ async getGSE(): Promise<EthAddress> {
251
+ return EthAddress.fromString(await this.rollup.read.getGSE());
135
252
  }
136
253
 
137
254
  public get address() {
@@ -173,23 +290,23 @@ export class RollupContract {
173
290
  }
174
291
 
175
292
  @memoize
176
- getL1StartBlock() {
293
+ getL1StartBlock(): Promise<bigint> {
177
294
  return this.rollup.read.L1_BLOCK_AT_GENESIS();
178
295
  }
179
296
 
180
297
  @memoize
181
- getL1GenesisTime() {
298
+ getL1GenesisTime(): Promise<bigint> {
182
299
  return this.rollup.read.getGenesisTime();
183
300
  }
184
301
 
185
302
  @memoize
186
- getProofSubmissionEpochs() {
187
- return this.rollup.read.getProofSubmissionEpochs();
303
+ async getProofSubmissionEpochs(): Promise<number> {
304
+ return Number(await this.rollup.read.getProofSubmissionEpochs());
188
305
  }
189
306
 
190
307
  @memoize
191
- getEpochDuration() {
192
- return this.rollup.read.getEpochDuration();
308
+ async getEpochDuration(): Promise<number> {
309
+ return Number(await this.rollup.read.getEpochDuration());
193
310
  }
194
311
 
195
312
  @memoize
@@ -198,68 +315,68 @@ export class RollupContract {
198
315
  }
199
316
 
200
317
  @memoize
201
- getTargetCommitteeSize() {
202
- return this.rollup.read.getTargetCommitteeSize();
318
+ async getTargetCommitteeSize(): Promise<number> {
319
+ return Number(await this.rollup.read.getTargetCommitteeSize());
203
320
  }
204
321
 
205
322
  @memoize
206
- getEjectionThreshold() {
323
+ getEjectionThreshold(): Promise<bigint> {
207
324
  return this.rollup.read.getEjectionThreshold();
208
325
  }
209
326
 
210
327
  @memoize
211
- getLocalEjectionThreshold() {
328
+ getLocalEjectionThreshold(): Promise<bigint> {
212
329
  return this.rollup.read.getLocalEjectionThreshold();
213
330
  }
214
331
 
215
332
  @memoize
216
- getLagInEpochsForValidatorSet() {
217
- return this.rollup.read.getLagInEpochsForValidatorSet();
333
+ async getLagInEpochsForValidatorSet(): Promise<number> {
334
+ return Number(await this.rollup.read.getLagInEpochsForValidatorSet());
218
335
  }
219
336
 
220
337
  @memoize
221
- getLagInEpochsForRandao() {
222
- return this.rollup.read.getLagInEpochsForRandao();
338
+ async getLagInEpochsForRandao(): Promise<number> {
339
+ return Number(await this.rollup.read.getLagInEpochsForRandao());
223
340
  }
224
341
 
225
342
  @memoize
226
- getActivationThreshold() {
343
+ getActivationThreshold(): Promise<bigint> {
227
344
  return this.rollup.read.getActivationThreshold();
228
345
  }
229
346
 
230
347
  @memoize
231
- getExitDelay() {
232
- return this.rollup.read.getExitDelay();
348
+ async getExitDelay(): Promise<number> {
349
+ return Number(await this.rollup.read.getExitDelay());
233
350
  }
234
351
 
235
352
  @memoize
236
- getManaTarget() {
353
+ getManaTarget(): Promise<bigint> {
237
354
  return this.rollup.read.getManaTarget();
238
355
  }
239
356
 
240
357
  @memoize
241
- getProvingCostPerMana() {
358
+ getProvingCostPerMana(): Promise<bigint> {
242
359
  return this.rollup.read.getProvingCostPerManaInEth();
243
360
  }
244
361
 
245
362
  @memoize
246
- getProvingCostPerManaInFeeAsset() {
363
+ getProvingCostPerManaInFeeAsset(): Promise<bigint> {
247
364
  return this.rollup.read.getProvingCostPerManaInFeeAsset();
248
365
  }
249
366
 
250
367
  @memoize
251
- getManaLimit() {
368
+ getManaLimit(): Promise<bigint> {
252
369
  return this.rollup.read.getManaLimit();
253
370
  }
254
371
 
255
372
  @memoize
256
- getVersion() {
373
+ getVersion(): Promise<bigint> {
257
374
  return this.rollup.read.getVersion();
258
375
  }
259
376
 
260
377
  @memoize
261
- async getGenesisArchiveTreeRoot(): Promise<`0x${string}`> {
262
- return await this.rollup.read.archiveAt([0n]);
378
+ async getGenesisArchiveTreeRoot(): Promise<Fr> {
379
+ return Fr.fromString(await this.rollup.read.archiveAt([0n]));
263
380
  }
264
381
 
265
382
  /**
@@ -274,13 +391,25 @@ export class RollupContract {
274
391
  slotDuration: number;
275
392
  epochDuration: number;
276
393
  proofSubmissionEpochs: number;
394
+ targetCommitteeSize: number;
395
+ rollupManaLimit: number;
277
396
  }> {
278
- const [l1StartBlock, l1GenesisTime, slotDuration, epochDuration, proofSubmissionEpochs] = await Promise.all([
397
+ const [
398
+ l1StartBlock,
399
+ l1GenesisTime,
400
+ slotDuration,
401
+ epochDuration,
402
+ proofSubmissionEpochs,
403
+ targetCommitteeSize,
404
+ rollupManaLimit,
405
+ ] = await Promise.all([
279
406
  this.getL1StartBlock(),
280
407
  this.getL1GenesisTime(),
281
408
  this.getSlotDuration(),
282
409
  this.getEpochDuration(),
283
410
  this.getProofSubmissionEpochs(),
411
+ this.getTargetCommitteeSize(),
412
+ this.getManaLimit(),
284
413
  ]);
285
414
  return {
286
415
  l1StartBlock,
@@ -288,30 +417,84 @@ export class RollupContract {
288
417
  slotDuration,
289
418
  epochDuration: Number(epochDuration),
290
419
  proofSubmissionEpochs: Number(proofSubmissionEpochs),
420
+ targetCommitteeSize,
421
+ rollupManaLimit: Number(rollupManaLimit),
291
422
  };
292
423
  }
293
424
 
294
- getSlasherAddress() {
295
- return this.rollup.read.getSlasher();
425
+ async getSlasherAddress(): Promise<EthAddress> {
426
+ return EthAddress.fromString(await this.rollup.read.getSlasher());
427
+ }
428
+
429
+ /**
430
+ * Returns the configured escape hatch contract address, or zero if disabled.
431
+ */
432
+ async getEscapeHatchAddress(): Promise<EthAddress> {
433
+ return EthAddress.fromString(await this.rollup.read.getEscapeHatch());
434
+ }
435
+
436
+ private async getEscapeHatchContract(): Promise<
437
+ GetContractReturnType<typeof EscapeHatchAbi, ViemClient> | undefined
438
+ > {
439
+ const escapeHatchAddress = await this.getEscapeHatchAddress();
440
+ if (escapeHatchAddress.isZero()) {
441
+ return undefined;
442
+ }
443
+
444
+ // Cache the viem contract wrapper since it will be used frequently.
445
+ if (!this.cachedEscapeHatch || !this.cachedEscapeHatch.address.equals(escapeHatchAddress)) {
446
+ this.cachedEscapeHatch = {
447
+ address: escapeHatchAddress,
448
+ contract: getContract({
449
+ address: escapeHatchAddress.toString(),
450
+ abi: EscapeHatchAbi,
451
+ client: this.client,
452
+ }),
453
+ };
454
+ }
455
+
456
+ return this.cachedEscapeHatch.contract;
457
+ }
458
+
459
+ /**
460
+ * Returns whether the escape hatch is open for the given epoch.
461
+ * If escape hatch is not configured, returns false.
462
+ *
463
+ * This function is intentionally defensive: any failure to query the escape hatch
464
+ * (RPC issues, transient errors, etc.) is treated as "closed" to avoid callers
465
+ * needing to sprinkle try/catch everywhere.
466
+ */
467
+ async isEscapeHatchOpen(epoch: EpochNumber): Promise<boolean> {
468
+ try {
469
+ const escapeHatch = await this.getEscapeHatchContract();
470
+ if (!escapeHatch) {
471
+ return false;
472
+ }
473
+
474
+ const [isOpen] = await escapeHatch.read.isHatchOpen([BigInt(epoch)]);
475
+ return isOpen;
476
+ } catch {
477
+ return false;
478
+ }
296
479
  }
297
480
 
298
481
  /**
299
482
  * Returns a SlasherContract instance for interacting with the slasher contract.
300
483
  */
301
484
  async getSlasherContract(): Promise<SlasherContract | undefined> {
302
- const slasherAddress = EthAddress.fromString(await this.getSlasherAddress());
485
+ const slasherAddress = await this.getSlasherAddress();
303
486
  if (slasherAddress.isZero()) {
304
487
  return undefined;
305
488
  }
306
489
  return new SlasherContract(this.client, slasherAddress);
307
490
  }
308
491
 
309
- getOwner() {
310
- return this.rollup.read.owner();
492
+ async getOwner(): Promise<EthAddress> {
493
+ return EthAddress.fromString(await this.rollup.read.owner());
311
494
  }
312
495
 
313
- getActiveAttesterCount() {
314
- return this.rollup.read.getActiveAttesterCount();
496
+ async getActiveAttesterCount(): Promise<number> {
497
+ return Number(await this.rollup.read.getActiveAttesterCount());
315
498
  }
316
499
 
317
500
  public async getSlashingProposerAddress() {
@@ -322,7 +505,7 @@ export class RollupContract {
322
505
  return await slasher.getProposer();
323
506
  }
324
507
 
325
- getCheckpointReward() {
508
+ getCheckpointReward(): Promise<bigint> {
326
509
  return this.rollup.read.getCheckpointReward();
327
510
  }
328
511
 
@@ -338,15 +521,19 @@ export class RollupContract {
338
521
  return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
339
522
  }
340
523
 
341
- getL1FeesAt(timestamp: bigint) {
342
- return this.rollup.read.getL1FeesAt([timestamp]);
524
+ async getL1FeesAt(timestamp: bigint): Promise<L1FeeData> {
525
+ const result = await this.rollup.read.getL1FeesAt([timestamp]);
526
+ return {
527
+ baseFee: result.baseFee,
528
+ blobFee: result.blobFee,
529
+ };
343
530
  }
344
531
 
345
- getFeeAssetPerEth() {
346
- return this.rollup.read.getFeeAssetPerEth();
532
+ getEthPerFeeAsset(): Promise<bigint> {
533
+ return this.rollup.read.getEthPerFeeAsset();
347
534
  }
348
535
 
349
- async getCommitteeAt(timestamp: bigint): Promise<readonly `0x${string}`[] | undefined> {
536
+ async getCommitteeAt(timestamp: bigint): Promise<EthAddress[] | undefined> {
350
537
  const { result } = await this.client
351
538
  .simulateContract({
352
539
  address: this.address,
@@ -361,22 +548,22 @@ export class RollupContract {
361
548
  throw e;
362
549
  });
363
550
 
364
- return result;
551
+ return result ? result.map(addr => EthAddress.fromString(addr)) : undefined;
365
552
  }
366
553
 
367
- getSampleSeedAt(timestamp: bigint) {
368
- return this.rollup.read.getSampleSeedAt([timestamp]);
554
+ async getSampleSeedAt(timestamp: bigint): Promise<Buffer32> {
555
+ return Buffer32.fromBigInt(await this.rollup.read.getSampleSeedAt([timestamp]));
369
556
  }
370
557
 
371
- getCurrentSampleSeed() {
372
- return this.rollup.read.getCurrentSampleSeed();
558
+ async getCurrentSampleSeed(): Promise<Buffer32> {
559
+ return Buffer32.fromBigInt(await this.rollup.read.getCurrentSampleSeed());
373
560
  }
374
561
 
375
562
  async getCurrentEpoch(): Promise<EpochNumber> {
376
563
  return EpochNumber.fromBigInt(await this.rollup.read.getCurrentEpoch());
377
564
  }
378
565
 
379
- async getCurrentEpochCommittee(): Promise<readonly `0x${string}`[] | undefined> {
566
+ async getCurrentEpochCommittee(): Promise<EthAddress[] | undefined> {
380
567
  const { result } = await this.client
381
568
  .simulateContract({
382
569
  address: this.address,
@@ -391,10 +578,10 @@ export class RollupContract {
391
578
  throw e;
392
579
  });
393
580
 
394
- return result;
581
+ return result ? result.map(addr => EthAddress.fromString(addr)) : undefined;
395
582
  }
396
583
 
397
- async getCurrentProposer() {
584
+ async getCurrentProposer(): Promise<EthAddress> {
398
585
  const { result } = await this.client.simulateContract({
399
586
  address: this.address,
400
587
  abi: RollupAbi,
@@ -402,10 +589,10 @@ export class RollupContract {
402
589
  args: [],
403
590
  });
404
591
 
405
- return result;
592
+ return EthAddress.fromString(result);
406
593
  }
407
594
 
408
- async getProposerAt(timestamp: bigint) {
595
+ async getProposerAt(timestamp: bigint): Promise<EthAddress> {
409
596
  const { result } = await this.client.simulateContract({
410
597
  address: this.address,
411
598
  abi: RollupAbi,
@@ -413,11 +600,41 @@ export class RollupContract {
413
600
  args: [timestamp],
414
601
  });
415
602
 
416
- return result;
603
+ return EthAddress.fromString(result);
417
604
  }
418
605
 
419
- getCheckpoint(checkpointNumber: CheckpointNumber) {
420
- return this.rollup.read.getCheckpoint([BigInt(checkpointNumber)]);
606
+ async getCheckpoint(checkpointNumber: CheckpointNumber): Promise<CheckpointLog> {
607
+ const result = await this.rollup.read.getCheckpoint([BigInt(checkpointNumber)]);
608
+ return {
609
+ archive: Fr.fromString(result.archive),
610
+ headerHash: Buffer32.fromString(result.headerHash),
611
+ blobCommitmentsHash: Buffer32.fromString(result.blobCommitmentsHash),
612
+ attestationsHash: Buffer32.fromString(result.attestationsHash),
613
+ payloadDigest: Buffer32.fromString(result.payloadDigest),
614
+ slotNumber: SlotNumber.fromBigInt(result.slotNumber),
615
+ feeHeader: {
616
+ excessMana: result.feeHeader.excessMana,
617
+ manaUsed: result.feeHeader.manaUsed,
618
+ ethPerFeeAsset: result.feeHeader.ethPerFeeAsset,
619
+ congestionCost: result.feeHeader.congestionCost,
620
+ proverCost: result.feeHeader.proverCost,
621
+ },
622
+ };
623
+ }
624
+
625
+ /** Returns the pending checkpoint from the rollup contract */
626
+ getPendingCheckpoint() {
627
+ // We retry because of race conditions during prunes: we may get a pending checkpoint number which is immediately
628
+ // reorged out due to a prune happening, causing the subsequent getCheckpoint call to fail. So we try again in that case.
629
+ return retry(
630
+ async () => {
631
+ const pendingCheckpointNumber = await this.getCheckpointNumber();
632
+ const pendingCheckpoint = await this.getCheckpoint(pendingCheckpointNumber);
633
+ return pendingCheckpoint;
634
+ },
635
+ 'getting pending checkpoint',
636
+ makeBackoff([0.5, 0.5, 0.5]),
637
+ );
421
638
  }
422
639
 
423
640
  async getTips(): Promise<{ pending: CheckpointNumber; proven: CheckpointNumber }> {
@@ -428,16 +645,16 @@ export class RollupContract {
428
645
  };
429
646
  }
430
647
 
431
- getTimestampForSlot(slot: SlotNumber) {
648
+ getTimestampForSlot(slot: SlotNumber): Promise<bigint> {
432
649
  return this.rollup.read.getTimestampForSlot([BigInt(slot)]);
433
650
  }
434
651
 
435
- getEntryQueueLength() {
436
- return this.rollup.read.getEntryQueueLength();
652
+ async getEntryQueueLength(): Promise<number> {
653
+ return Number(await this.rollup.read.getEntryQueueLength());
437
654
  }
438
655
 
439
- getAvailableValidatorFlushes() {
440
- return this.rollup.read.getAvailableValidatorFlushes();
656
+ async getAvailableValidatorFlushes(): Promise<number> {
657
+ return Number(await this.rollup.read.getAvailableValidatorFlushes());
441
658
  }
442
659
 
443
660
  async getNextFlushableEpoch(): Promise<EpochNumber> {
@@ -493,10 +710,11 @@ export class RollupContract {
493
710
  return EpochNumber.fromBigInt(await this.rollup.read.getEpochAtSlot([BigInt(slotNumber)]));
494
711
  }
495
712
 
496
- getEpochProofPublicInputs(
713
+ async getEpochProofPublicInputs(
497
714
  args: readonly [bigint, bigint, EpochProofPublicInputArgs, readonly `0x${string}`[], `0x${string}`],
498
- ) {
499
- return this.rollup.read.getEpochProofPublicInputs(args);
715
+ ): Promise<Fr[]> {
716
+ const result = await this.rollup.read.getEpochProofPublicInputs(args);
717
+ return result.map(Fr.fromString);
500
718
  }
501
719
 
502
720
  public async validateHeader(
@@ -601,6 +819,7 @@ export class RollupContract {
601
819
  ): L1TxRequest {
602
820
  return {
603
821
  to: this.address,
822
+ abi: RollupAbi,
604
823
  data: encodeFunctionData({
605
824
  abi: RollupAbi,
606
825
  functionName: 'invalidateBadAttestation',
@@ -622,6 +841,7 @@ export class RollupContract {
622
841
  ): L1TxRequest {
623
842
  return {
624
843
  to: this.address,
844
+ abi: RollupAbi,
625
845
  data: encodeFunctionData({
626
846
  abi: RollupAbi,
627
847
  functionName: 'invalidateInsufficientAttestations',
@@ -638,90 +858,124 @@ export class RollupContract {
638
858
  return this.rollup.read.getHasSubmitted([BigInt(epochNumber), BigInt(numberOfCheckpointsInEpoch), prover]);
639
859
  }
640
860
 
641
- getManaBaseFeeAt(timestamp: bigint, inFeeAsset: boolean) {
642
- return this.rollup.read.getManaBaseFeeAt([timestamp, inFeeAsset]);
861
+ getManaMinFeeAt(timestamp: bigint, inFeeAsset: boolean): Promise<bigint> {
862
+ return this.rollup.read.getManaMinFeeAt([timestamp, inFeeAsset]);
643
863
  }
644
864
 
645
865
  async getSlotAt(timestamp: bigint): Promise<SlotNumber> {
646
866
  return SlotNumber.fromBigInt(await this.rollup.read.getSlotAt([timestamp]));
647
867
  }
648
868
 
649
- async status(checkpointNumber: CheckpointNumber, options?: { blockNumber?: bigint }) {
869
+ async status(checkpointNumber: CheckpointNumber, options?: { blockNumber?: bigint }): Promise<RollupStatusResponse> {
650
870
  await checkBlockTag(options?.blockNumber, this.client);
651
- return this.rollup.read.status([BigInt(checkpointNumber)], options);
871
+ const result = await this.rollup.read.status([BigInt(checkpointNumber)], options);
872
+ return {
873
+ provenCheckpointNumber: CheckpointNumber.fromBigInt(result[0]),
874
+ provenArchive: Fr.fromString(result[1]),
875
+ pendingCheckpointNumber: CheckpointNumber.fromBigInt(result[2]),
876
+ pendingArchive: Fr.fromString(result[3]),
877
+ archiveOfMyCheckpoint: Fr.fromString(result[4]),
878
+ };
652
879
  }
653
880
 
654
- async canPruneAtTime(timestamp: bigint, options?: { blockNumber?: bigint }) {
881
+ async canPruneAtTime(timestamp: bigint, options?: { blockNumber?: bigint }): Promise<boolean> {
655
882
  await checkBlockTag(options?.blockNumber, this.client);
656
883
  return this.rollup.read.canPruneAtTime([timestamp], options);
657
884
  }
658
885
 
659
- archive() {
660
- return this.rollup.read.archive();
886
+ async archive(): Promise<Fr> {
887
+ return Fr.fromString(await this.rollup.read.archive());
661
888
  }
662
889
 
663
- archiveAt(checkpointNumber: CheckpointNumber) {
664
- return this.rollup.read.archiveAt([BigInt(checkpointNumber)]);
890
+ async archiveAt(checkpointNumber: CheckpointNumber): Promise<Fr> {
891
+ return Fr.fromString(await this.rollup.read.archiveAt([BigInt(checkpointNumber)]));
665
892
  }
666
893
 
667
- getSequencerRewards(address: Hex | EthAddress) {
894
+ getSequencerRewards(address: Hex | EthAddress): Promise<bigint> {
668
895
  if (address instanceof EthAddress) {
669
896
  address = address.toString();
670
897
  }
671
898
  return this.rollup.read.getSequencerRewards([address]);
672
899
  }
673
900
 
674
- getSpecificProverRewardsForEpoch(epoch: bigint, prover: Hex | EthAddress) {
901
+ getSpecificProverRewardsForEpoch(epoch: bigint, prover: Hex | EthAddress): Promise<bigint> {
675
902
  if (prover instanceof EthAddress) {
676
903
  prover = prover.toString();
677
904
  }
678
905
  return this.rollup.read.getSpecificProverRewardsForEpoch([epoch, prover]);
679
906
  }
680
907
 
681
- async getAttesters() {
908
+ async getAttesters(): Promise<EthAddress[]> {
682
909
  const attesterSize = await this.getActiveAttesterCount();
683
910
  const gse = new GSEContract(this.client, await this.getGSE());
684
911
  const ts = (await this.client.getBlock()).timestamp;
685
912
 
686
- const indices = Array.from({ length: Number(attesterSize) }, (_, i) => BigInt(i));
913
+ const indices = Array.from({ length: attesterSize }, (_, i) => BigInt(i));
687
914
  const chunks = chunk(indices, 1000);
688
915
 
689
- return (await Promise.all(chunks.map(chunk => gse.getAttestersFromIndicesAtTime(this.address, ts, chunk)))).flat();
916
+ const results = await Promise.all(chunks.map(chunk => gse.getAttestersFromIndicesAtTime(this.address, ts, chunk)));
917
+ return results.flat().map(addr => EthAddress.fromString(addr));
690
918
  }
691
919
 
692
- getAttesterView(address: Hex | EthAddress) {
920
+ async getAttesterView(address: Hex | EthAddress): Promise<AttesterView> {
693
921
  if (address instanceof EthAddress) {
694
922
  address = address.toString();
695
923
  }
696
- return this.rollup.read.getAttesterView([address]);
924
+ const result = await this.rollup.read.getAttesterView([address]);
925
+ return {
926
+ status: result.status as AttesterStatus,
927
+ effectiveBalance: result.effectiveBalance,
928
+ exit: {
929
+ withdrawalId: result.exit.withdrawalId,
930
+ amount: result.exit.amount,
931
+ exitableAt: result.exit.exitableAt,
932
+ recipientOrWithdrawer: EthAddress.fromString(result.exit.recipientOrWithdrawer),
933
+ isRecipient: result.exit.isRecipient,
934
+ exists: result.exit.exists,
935
+ },
936
+ config: {
937
+ publicKey: {
938
+ x: result.config.publicKey.x,
939
+ y: result.config.publicKey.y,
940
+ },
941
+ withdrawer: EthAddress.fromString(result.config.withdrawer),
942
+ },
943
+ };
697
944
  }
698
945
 
699
- getStatus(address: Hex | EthAddress) {
946
+ async getStatus(address: Hex | EthAddress): Promise<AttesterStatus> {
700
947
  if (address instanceof EthAddress) {
701
948
  address = address.toString();
702
949
  }
703
- return this.rollup.read.getStatus([address]);
950
+ return (await this.rollup.read.getStatus([address])) as AttesterStatus;
704
951
  }
705
952
 
706
- getBlobCommitmentsHash(checkpointNumber: CheckpointNumber) {
707
- return this.rollup.read.getBlobCommitmentsHash([BigInt(checkpointNumber)]);
953
+ async getBlobCommitmentsHash(checkpointNumber: CheckpointNumber): Promise<Buffer32> {
954
+ return Buffer32.fromString(await this.rollup.read.getBlobCommitmentsHash([BigInt(checkpointNumber)]));
708
955
  }
709
956
 
710
- getCurrentBlobCommitmentsHash() {
711
- return this.rollup.read.getCurrentBlobCommitmentsHash();
957
+ async getCurrentBlobCommitmentsHash(): Promise<Buffer32> {
958
+ return Buffer32.fromString(await this.rollup.read.getCurrentBlobCommitmentsHash());
712
959
  }
713
960
 
714
- getStakingAsset() {
715
- return this.rollup.read.getStakingAsset();
961
+ async getStakingAsset(): Promise<EthAddress> {
962
+ return EthAddress.fromString(await this.rollup.read.getStakingAsset());
716
963
  }
717
964
 
718
- getRewardConfig() {
719
- return this.rollup.read.getRewardConfig();
965
+ async getRewardConfig(): Promise<RewardConfig> {
966
+ const result = await this.rollup.read.getRewardConfig();
967
+ return {
968
+ rewardDistributor: EthAddress.fromString(result.rewardDistributor),
969
+ sequencerBps: BigInt(result.sequencerBps),
970
+ booster: EthAddress.fromString(result.booster),
971
+ checkpointReward: result.checkpointReward,
972
+ };
720
973
  }
721
974
 
722
975
  setupEpoch(l1TxUtils: L1TxUtils) {
723
976
  return l1TxUtils.sendAndMonitorTransaction({
724
977
  to: this.address,
978
+ abi: RollupAbi,
725
979
  data: encodeFunctionData({
726
980
  abi: RollupAbi,
727
981
  functionName: 'setupEpoch',
@@ -733,6 +987,7 @@ export class RollupContract {
733
987
  vote(l1TxUtils: L1TxUtils, proposalId: bigint) {
734
988
  return l1TxUtils.sendAndMonitorTransaction({
735
989
  to: this.address,
990
+ abi: RollupAbi,
736
991
  data: encodeFunctionData({
737
992
  abi: RollupAbi,
738
993
  functionName: 'vote',
@@ -801,4 +1056,37 @@ export class RollupContract {
801
1056
  },
802
1057
  );
803
1058
  }
1059
+
1060
+ /** Fetches CheckpointProposed events within the given block range. */
1061
+ async getCheckpointProposedEvents(fromBlock: bigint, toBlock: bigint): Promise<CheckpointProposedLog[]> {
1062
+ const logs = await this.rollup.getEvents.CheckpointProposed({}, { fromBlock, toBlock });
1063
+ return logs
1064
+ .filter(log => log.blockNumber! >= fromBlock && log.blockNumber! <= toBlock)
1065
+ .map(log => ({
1066
+ l1BlockNumber: log.blockNumber!,
1067
+ l1BlockHash: Buffer32.fromString(log.blockHash!),
1068
+ l1TransactionHash: log.transactionHash!,
1069
+ args: {
1070
+ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
1071
+ archive: Fr.fromString(log.args.archive!),
1072
+ versionedBlobHashes: log.args.versionedBlobHashes!.map(h => Buffer.from(h.slice(2), 'hex')),
1073
+ attestationsHash: (() => {
1074
+ if (!log.args.attestationsHash) {
1075
+ throw new Error(
1076
+ `CheckpointProposed event missing attestationsHash for checkpoint ${log.args.checkpointNumber}`,
1077
+ );
1078
+ }
1079
+ return Buffer32.fromString(log.args.attestationsHash);
1080
+ })(),
1081
+ payloadDigest: (() => {
1082
+ if (!log.args.payloadDigest) {
1083
+ throw new Error(
1084
+ `CheckpointProposed event missing payloadDigest for checkpoint ${log.args.checkpointNumber}`,
1085
+ );
1086
+ }
1087
+ return Buffer32.fromString(log.args.payloadDigest);
1088
+ })(),
1089
+ },
1090
+ }));
1091
+ }
804
1092
  }