@aztec/ethereum 0.0.1-fake-ceab37513c → 0.0.6-commit.a2d1860fe9

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