@aztec/ethereum 0.0.1-commit.6c91f13 → 0.0.1-commit.6d63667d
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.
- package/dest/config.d.ts +15 -28
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +46 -55
- package/dest/contracts/empire_slashing_proposer.d.ts +1 -1
- package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/empire_slashing_proposer.js +13 -15
- package/dest/contracts/fee_asset_handler.d.ts +6 -5
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
- package/dest/contracts/fee_asset_handler.js +11 -9
- package/dest/contracts/governance.d.ts +3 -1
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +11 -1
- package/dest/contracts/governance_proposer.d.ts +1 -1
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +386 -9
- package/dest/contracts/inbox.d.ts +18 -1
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +32 -1
- package/dest/contracts/index.d.ts +3 -1
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +2 -0
- package/dest/contracts/log.d.ts +13 -0
- package/dest/contracts/log.d.ts.map +1 -0
- package/dest/contracts/log.js +1 -0
- package/dest/contracts/multicall.d.ts +1 -1
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +2 -1
- package/dest/contracts/outbox.d.ts +41 -0
- package/dest/contracts/outbox.d.ts.map +1 -0
- package/dest/contracts/outbox.js +86 -0
- package/dest/contracts/rollup.d.ts +160 -96
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +672 -129
- package/dest/contracts/tally_slashing_proposer.d.ts +1 -1
- package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/tally_slashing_proposer.js +8 -1
- package/dest/deploy_aztec_l1_contracts.d.ts +15 -2
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_aztec_l1_contracts.js +80 -17
- package/dest/generated/l1-contracts-defaults.d.ts +30 -0
- package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
- package/dest/generated/l1-contracts-defaults.js +30 -0
- package/dest/l1_artifacts.d.ts +4866 -1513
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_tx_utils/constants.d.ts +1 -1
- package/dest/l1_tx_utils/constants.js +2 -2
- package/dest/l1_tx_utils/fee-strategies/index.d.ts +3 -2
- package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -1
- package/dest/l1_tx_utils/fee-strategies/index.js +2 -1
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +2 -12
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -1
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +35 -17
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +2 -11
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -1
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +36 -18
- package/dest/l1_tx_utils/fee-strategies/types.d.ts +14 -27
- package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -1
- package/dest/l1_tx_utils/fee-strategies/types.js +0 -21
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +2 -2
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_fee_analyzer.js +3 -3
- package/dest/l1_tx_utils/l1_tx_utils.js +6 -6
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +1 -5
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +17 -54
- package/dest/publisher_manager.d.ts +3 -2
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +2 -2
- package/dest/queries.d.ts +2 -2
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +6 -3
- package/dest/test/chain_monitor.js +1 -2
- package/dest/test/eth_cheat_codes.d.ts +13 -1
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.d.ts +5 -2
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +19 -2
- package/dest/test/start_anvil.js +1 -1
- package/dest/utils.d.ts +2 -1
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +46 -0
- package/package.json +8 -7
- package/src/config.ts +55 -54
- package/src/contracts/README.md +157 -0
- package/src/contracts/empire_slashing_proposer.ts +16 -27
- package/src/contracts/fee_asset_handler.ts +10 -7
- package/src/contracts/governance.ts +10 -1
- package/src/contracts/governance_proposer.ts +4 -1
- package/src/contracts/inbox.ts +48 -1
- package/src/contracts/index.ts +2 -0
- package/src/contracts/log.ts +13 -0
- package/src/contracts/multicall.ts +5 -2
- package/src/contracts/outbox.ts +98 -0
- package/src/contracts/rollup.ts +337 -93
- package/src/contracts/tally_slashing_proposer.ts +5 -1
- package/src/deploy_aztec_l1_contracts.ts +82 -16
- package/src/generated/l1-contracts-defaults.ts +32 -0
- package/src/l1_tx_utils/constants.ts +2 -2
- package/src/l1_tx_utils/fee-strategies/index.ts +1 -1
- package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +45 -41
- package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +48 -44
- package/src/l1_tx_utils/fee-strategies/types.ts +14 -46
- package/src/l1_tx_utils/l1_fee_analyzer.ts +2 -3
- package/src/l1_tx_utils/l1_tx_utils.ts +6 -6
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +23 -62
- package/src/publisher_manager.ts +4 -2
- package/src/queries.ts +5 -3
- package/src/test/chain_monitor.ts +1 -1
- package/src/test/rollup_cheat_codes.ts +21 -3
- package/src/test/start_anvil.ts +1 -1
- package/src/utils.ts +53 -0
package/src/contracts/rollup.ts
CHANGED
|
@@ -1,8 +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';
|
|
5
7
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
8
|
+
import { EscapeHatchAbi } from '@aztec/l1-artifacts/EscapeHatchAbi';
|
|
6
9
|
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
7
10
|
import { RollupStorage } from '@aztec/l1-artifacts/RollupStorage';
|
|
8
11
|
|
|
@@ -28,6 +31,7 @@ import type { ViemClient } from '../types.js';
|
|
|
28
31
|
import { formatViemError } from '../utils.js';
|
|
29
32
|
import { EmpireSlashingProposerContract } from './empire_slashing_proposer.js';
|
|
30
33
|
import { GSEContract } from './gse.js';
|
|
34
|
+
import type { L1EventLog } from './log.js';
|
|
31
35
|
import { SlasherContract } from './slasher_contract.js';
|
|
32
36
|
import { TallySlashingProposerContract } from './tally_slashing_proposer.js';
|
|
33
37
|
import { checkBlockTag } from './utils.js';
|
|
@@ -58,13 +62,16 @@ export type L1RollupContractAddresses = Pick<
|
|
|
58
62
|
export type EpochProofPublicInputArgs = {
|
|
59
63
|
previousArchive: `0x${string}`;
|
|
60
64
|
endArchive: `0x${string}`;
|
|
65
|
+
outHash: `0x${string}`;
|
|
61
66
|
proverId: `0x${string}`;
|
|
62
67
|
};
|
|
63
68
|
|
|
64
69
|
export type ViemHeader = {
|
|
65
70
|
lastArchiveRoot: `0x${string}`;
|
|
66
71
|
blockHeadersHash: `0x${string}`;
|
|
67
|
-
|
|
72
|
+
blobsHash: `0x${string}`;
|
|
73
|
+
inHash: `0x${string}`;
|
|
74
|
+
outHash: `0x${string}`;
|
|
68
75
|
slotNumber: bigint;
|
|
69
76
|
timestamp: bigint;
|
|
70
77
|
coinbase: `0x${string}`;
|
|
@@ -73,12 +80,6 @@ export type ViemHeader = {
|
|
|
73
80
|
totalManaUsed: bigint;
|
|
74
81
|
};
|
|
75
82
|
|
|
76
|
-
export type ViemContentCommitment = {
|
|
77
|
-
blobsHash: `0x${string}`;
|
|
78
|
-
inHash: `0x${string}`;
|
|
79
|
-
outHash: `0x${string}`;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
83
|
export type ViemGasFees = {
|
|
83
84
|
feePerDaGas: bigint;
|
|
84
85
|
feePerL2Gas: bigint;
|
|
@@ -90,10 +91,125 @@ export enum SlashingProposerType {
|
|
|
90
91
|
Empire = 2,
|
|
91
92
|
}
|
|
92
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Status of a validator/attester in the staking system.
|
|
96
|
+
* Matches the Status enum in StakingLib.sol
|
|
97
|
+
*/
|
|
98
|
+
export enum AttesterStatus {
|
|
99
|
+
NONE = 0,
|
|
100
|
+
VALIDATING = 1,
|
|
101
|
+
ZOMBIE = 2,
|
|
102
|
+
EXITING = 3,
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Fee header data for a checkpoint
|
|
107
|
+
*/
|
|
108
|
+
export type FeeHeader = {
|
|
109
|
+
excessMana: bigint;
|
|
110
|
+
manaUsed: bigint;
|
|
111
|
+
ethPerFeeAsset: bigint;
|
|
112
|
+
congestionCost: bigint;
|
|
113
|
+
proverCost: bigint;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Checkpoint log data returned from the rollup contract
|
|
118
|
+
*/
|
|
119
|
+
export type CheckpointLog = {
|
|
120
|
+
archive: Fr;
|
|
121
|
+
headerHash: Buffer32;
|
|
122
|
+
blobCommitmentsHash: Buffer32;
|
|
123
|
+
attestationsHash: Buffer32;
|
|
124
|
+
payloadDigest: Buffer32;
|
|
125
|
+
slotNumber: SlotNumber;
|
|
126
|
+
feeHeader: FeeHeader;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* L1 fee data (base fee and blob fee)
|
|
131
|
+
*/
|
|
132
|
+
export type L1FeeData = {
|
|
133
|
+
baseFee: bigint;
|
|
134
|
+
blobFee: bigint;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Reward configuration for the rollup
|
|
139
|
+
*/
|
|
140
|
+
export type RewardConfig = {
|
|
141
|
+
rewardDistributor: EthAddress;
|
|
142
|
+
sequencerBps: bigint;
|
|
143
|
+
booster: EthAddress;
|
|
144
|
+
checkpointReward: bigint;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Exit information for a validator
|
|
149
|
+
*/
|
|
150
|
+
export type Exit = {
|
|
151
|
+
withdrawalId: bigint;
|
|
152
|
+
amount: bigint;
|
|
153
|
+
exitableAt: bigint;
|
|
154
|
+
recipientOrWithdrawer: EthAddress;
|
|
155
|
+
isRecipient: boolean;
|
|
156
|
+
exists: boolean;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Attester configuration including public key and withdrawer
|
|
161
|
+
*/
|
|
162
|
+
export type AttesterConfig = {
|
|
163
|
+
publicKey: {
|
|
164
|
+
x: bigint;
|
|
165
|
+
y: bigint;
|
|
166
|
+
};
|
|
167
|
+
withdrawer: EthAddress;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Complete view of an attester's state
|
|
172
|
+
*/
|
|
173
|
+
export type AttesterView = {
|
|
174
|
+
status: AttesterStatus;
|
|
175
|
+
effectiveBalance: bigint;
|
|
176
|
+
exit: Exit;
|
|
177
|
+
config: AttesterConfig;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Return for a status call
|
|
182
|
+
*/
|
|
183
|
+
export type RollupStatusResponse = {
|
|
184
|
+
provenCheckpointNumber: CheckpointNumber;
|
|
185
|
+
provenArchive: Fr;
|
|
186
|
+
pendingCheckpointNumber: CheckpointNumber;
|
|
187
|
+
pendingArchive: Fr;
|
|
188
|
+
archiveOfMyCheckpoint: Fr;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/** Arguments for the CheckpointProposed event. */
|
|
192
|
+
export type CheckpointProposedArgs = {
|
|
193
|
+
checkpointNumber: CheckpointNumber;
|
|
194
|
+
archive: Fr;
|
|
195
|
+
versionedBlobHashes: Buffer[];
|
|
196
|
+
/** Hash of attestations. Undefined for older events (backwards compatibility). */
|
|
197
|
+
attestationsHash?: Buffer32;
|
|
198
|
+
/** Digest of the payload. Undefined for older events (backwards compatibility). */
|
|
199
|
+
payloadDigest?: Buffer32;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/** Log type for CheckpointProposed events. */
|
|
203
|
+
export type CheckpointProposedLog = L1EventLog<CheckpointProposedArgs>;
|
|
204
|
+
|
|
93
205
|
export class RollupContract {
|
|
94
206
|
private readonly rollup: GetContractReturnType<typeof RollupAbi, ViemClient>;
|
|
95
207
|
|
|
96
208
|
private static cachedStfStorageSlot: Hex | undefined;
|
|
209
|
+
private cachedEscapeHatch?: {
|
|
210
|
+
address: EthAddress;
|
|
211
|
+
contract: GetContractReturnType<typeof EscapeHatchAbi, ViemClient>;
|
|
212
|
+
};
|
|
97
213
|
|
|
98
214
|
static get checkBlobStorageSlot(): bigint {
|
|
99
215
|
const asString = RollupStorage.find(storage => storage.label === 'checkBlob')?.slot;
|
|
@@ -131,8 +247,8 @@ export class RollupContract {
|
|
|
131
247
|
this.rollup = getContract({ address, abi: RollupAbi, client });
|
|
132
248
|
}
|
|
133
249
|
|
|
134
|
-
getGSE() {
|
|
135
|
-
return this.rollup.read.getGSE();
|
|
250
|
+
async getGSE(): Promise<EthAddress> {
|
|
251
|
+
return EthAddress.fromString(await this.rollup.read.getGSE());
|
|
136
252
|
}
|
|
137
253
|
|
|
138
254
|
public get address() {
|
|
@@ -174,23 +290,23 @@ export class RollupContract {
|
|
|
174
290
|
}
|
|
175
291
|
|
|
176
292
|
@memoize
|
|
177
|
-
getL1StartBlock() {
|
|
293
|
+
getL1StartBlock(): Promise<bigint> {
|
|
178
294
|
return this.rollup.read.L1_BLOCK_AT_GENESIS();
|
|
179
295
|
}
|
|
180
296
|
|
|
181
297
|
@memoize
|
|
182
|
-
getL1GenesisTime() {
|
|
298
|
+
getL1GenesisTime(): Promise<bigint> {
|
|
183
299
|
return this.rollup.read.getGenesisTime();
|
|
184
300
|
}
|
|
185
301
|
|
|
186
302
|
@memoize
|
|
187
|
-
getProofSubmissionEpochs() {
|
|
188
|
-
return this.rollup.read.getProofSubmissionEpochs();
|
|
303
|
+
async getProofSubmissionEpochs(): Promise<number> {
|
|
304
|
+
return Number(await this.rollup.read.getProofSubmissionEpochs());
|
|
189
305
|
}
|
|
190
306
|
|
|
191
307
|
@memoize
|
|
192
|
-
getEpochDuration() {
|
|
193
|
-
return this.rollup.read.getEpochDuration();
|
|
308
|
+
async getEpochDuration(): Promise<number> {
|
|
309
|
+
return Number(await this.rollup.read.getEpochDuration());
|
|
194
310
|
}
|
|
195
311
|
|
|
196
312
|
@memoize
|
|
@@ -199,68 +315,68 @@ export class RollupContract {
|
|
|
199
315
|
}
|
|
200
316
|
|
|
201
317
|
@memoize
|
|
202
|
-
getTargetCommitteeSize() {
|
|
203
|
-
return this.rollup.read.getTargetCommitteeSize();
|
|
318
|
+
async getTargetCommitteeSize(): Promise<number> {
|
|
319
|
+
return Number(await this.rollup.read.getTargetCommitteeSize());
|
|
204
320
|
}
|
|
205
321
|
|
|
206
322
|
@memoize
|
|
207
|
-
getEjectionThreshold() {
|
|
323
|
+
getEjectionThreshold(): Promise<bigint> {
|
|
208
324
|
return this.rollup.read.getEjectionThreshold();
|
|
209
325
|
}
|
|
210
326
|
|
|
211
327
|
@memoize
|
|
212
|
-
getLocalEjectionThreshold() {
|
|
328
|
+
getLocalEjectionThreshold(): Promise<bigint> {
|
|
213
329
|
return this.rollup.read.getLocalEjectionThreshold();
|
|
214
330
|
}
|
|
215
331
|
|
|
216
332
|
@memoize
|
|
217
|
-
getLagInEpochsForValidatorSet() {
|
|
218
|
-
return this.rollup.read.getLagInEpochsForValidatorSet();
|
|
333
|
+
async getLagInEpochsForValidatorSet(): Promise<number> {
|
|
334
|
+
return Number(await this.rollup.read.getLagInEpochsForValidatorSet());
|
|
219
335
|
}
|
|
220
336
|
|
|
221
337
|
@memoize
|
|
222
|
-
getLagInEpochsForRandao() {
|
|
223
|
-
return this.rollup.read.getLagInEpochsForRandao();
|
|
338
|
+
async getLagInEpochsForRandao(): Promise<number> {
|
|
339
|
+
return Number(await this.rollup.read.getLagInEpochsForRandao());
|
|
224
340
|
}
|
|
225
341
|
|
|
226
342
|
@memoize
|
|
227
|
-
getActivationThreshold() {
|
|
343
|
+
getActivationThreshold(): Promise<bigint> {
|
|
228
344
|
return this.rollup.read.getActivationThreshold();
|
|
229
345
|
}
|
|
230
346
|
|
|
231
347
|
@memoize
|
|
232
|
-
getExitDelay() {
|
|
233
|
-
return this.rollup.read.getExitDelay();
|
|
348
|
+
async getExitDelay(): Promise<number> {
|
|
349
|
+
return Number(await this.rollup.read.getExitDelay());
|
|
234
350
|
}
|
|
235
351
|
|
|
236
352
|
@memoize
|
|
237
|
-
getManaTarget() {
|
|
353
|
+
getManaTarget(): Promise<bigint> {
|
|
238
354
|
return this.rollup.read.getManaTarget();
|
|
239
355
|
}
|
|
240
356
|
|
|
241
357
|
@memoize
|
|
242
|
-
getProvingCostPerMana() {
|
|
358
|
+
getProvingCostPerMana(): Promise<bigint> {
|
|
243
359
|
return this.rollup.read.getProvingCostPerManaInEth();
|
|
244
360
|
}
|
|
245
361
|
|
|
246
362
|
@memoize
|
|
247
|
-
getProvingCostPerManaInFeeAsset() {
|
|
363
|
+
getProvingCostPerManaInFeeAsset(): Promise<bigint> {
|
|
248
364
|
return this.rollup.read.getProvingCostPerManaInFeeAsset();
|
|
249
365
|
}
|
|
250
366
|
|
|
251
367
|
@memoize
|
|
252
|
-
getManaLimit() {
|
|
368
|
+
getManaLimit(): Promise<bigint> {
|
|
253
369
|
return this.rollup.read.getManaLimit();
|
|
254
370
|
}
|
|
255
371
|
|
|
256
372
|
@memoize
|
|
257
|
-
getVersion() {
|
|
373
|
+
getVersion(): Promise<bigint> {
|
|
258
374
|
return this.rollup.read.getVersion();
|
|
259
375
|
}
|
|
260
376
|
|
|
261
377
|
@memoize
|
|
262
|
-
async getGenesisArchiveTreeRoot(): Promise
|
|
263
|
-
return await this.rollup.read.archiveAt([0n]);
|
|
378
|
+
async getGenesisArchiveTreeRoot(): Promise<Fr> {
|
|
379
|
+
return Fr.fromString(await this.rollup.read.archiveAt([0n]));
|
|
264
380
|
}
|
|
265
381
|
|
|
266
382
|
/**
|
|
@@ -292,27 +408,79 @@ export class RollupContract {
|
|
|
292
408
|
};
|
|
293
409
|
}
|
|
294
410
|
|
|
295
|
-
getSlasherAddress() {
|
|
296
|
-
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
|
+
}
|
|
297
465
|
}
|
|
298
466
|
|
|
299
467
|
/**
|
|
300
468
|
* Returns a SlasherContract instance for interacting with the slasher contract.
|
|
301
469
|
*/
|
|
302
470
|
async getSlasherContract(): Promise<SlasherContract | undefined> {
|
|
303
|
-
const slasherAddress =
|
|
471
|
+
const slasherAddress = await this.getSlasherAddress();
|
|
304
472
|
if (slasherAddress.isZero()) {
|
|
305
473
|
return undefined;
|
|
306
474
|
}
|
|
307
475
|
return new SlasherContract(this.client, slasherAddress);
|
|
308
476
|
}
|
|
309
477
|
|
|
310
|
-
getOwner() {
|
|
311
|
-
return this.rollup.read.owner();
|
|
478
|
+
async getOwner(): Promise<EthAddress> {
|
|
479
|
+
return EthAddress.fromString(await this.rollup.read.owner());
|
|
312
480
|
}
|
|
313
481
|
|
|
314
|
-
getActiveAttesterCount() {
|
|
315
|
-
return this.rollup.read.getActiveAttesterCount();
|
|
482
|
+
async getActiveAttesterCount(): Promise<number> {
|
|
483
|
+
return Number(await this.rollup.read.getActiveAttesterCount());
|
|
316
484
|
}
|
|
317
485
|
|
|
318
486
|
public async getSlashingProposerAddress() {
|
|
@@ -323,7 +491,7 @@ export class RollupContract {
|
|
|
323
491
|
return await slasher.getProposer();
|
|
324
492
|
}
|
|
325
493
|
|
|
326
|
-
getCheckpointReward() {
|
|
494
|
+
getCheckpointReward(): Promise<bigint> {
|
|
327
495
|
return this.rollup.read.getCheckpointReward();
|
|
328
496
|
}
|
|
329
497
|
|
|
@@ -339,15 +507,19 @@ export class RollupContract {
|
|
|
339
507
|
return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
|
|
340
508
|
}
|
|
341
509
|
|
|
342
|
-
getL1FeesAt(timestamp: bigint) {
|
|
343
|
-
|
|
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
|
+
};
|
|
344
516
|
}
|
|
345
517
|
|
|
346
|
-
|
|
347
|
-
return this.rollup.read.
|
|
518
|
+
getEthPerFeeAsset(): Promise<bigint> {
|
|
519
|
+
return this.rollup.read.getEthPerFeeAsset();
|
|
348
520
|
}
|
|
349
521
|
|
|
350
|
-
async getCommitteeAt(timestamp: bigint): Promise<
|
|
522
|
+
async getCommitteeAt(timestamp: bigint): Promise<EthAddress[] | undefined> {
|
|
351
523
|
const { result } = await this.client
|
|
352
524
|
.simulateContract({
|
|
353
525
|
address: this.address,
|
|
@@ -362,22 +534,22 @@ export class RollupContract {
|
|
|
362
534
|
throw e;
|
|
363
535
|
});
|
|
364
536
|
|
|
365
|
-
return result;
|
|
537
|
+
return result ? result.map(addr => EthAddress.fromString(addr)) : undefined;
|
|
366
538
|
}
|
|
367
539
|
|
|
368
|
-
getSampleSeedAt(timestamp: bigint) {
|
|
369
|
-
return this.rollup.read.getSampleSeedAt([timestamp]);
|
|
540
|
+
async getSampleSeedAt(timestamp: bigint): Promise<Buffer32> {
|
|
541
|
+
return Buffer32.fromBigInt(await this.rollup.read.getSampleSeedAt([timestamp]));
|
|
370
542
|
}
|
|
371
543
|
|
|
372
|
-
getCurrentSampleSeed() {
|
|
373
|
-
return this.rollup.read.getCurrentSampleSeed();
|
|
544
|
+
async getCurrentSampleSeed(): Promise<Buffer32> {
|
|
545
|
+
return Buffer32.fromBigInt(await this.rollup.read.getCurrentSampleSeed());
|
|
374
546
|
}
|
|
375
547
|
|
|
376
548
|
async getCurrentEpoch(): Promise<EpochNumber> {
|
|
377
549
|
return EpochNumber.fromBigInt(await this.rollup.read.getCurrentEpoch());
|
|
378
550
|
}
|
|
379
551
|
|
|
380
|
-
async getCurrentEpochCommittee(): Promise<
|
|
552
|
+
async getCurrentEpochCommittee(): Promise<EthAddress[] | undefined> {
|
|
381
553
|
const { result } = await this.client
|
|
382
554
|
.simulateContract({
|
|
383
555
|
address: this.address,
|
|
@@ -392,10 +564,10 @@ export class RollupContract {
|
|
|
392
564
|
throw e;
|
|
393
565
|
});
|
|
394
566
|
|
|
395
|
-
return result;
|
|
567
|
+
return result ? result.map(addr => EthAddress.fromString(addr)) : undefined;
|
|
396
568
|
}
|
|
397
569
|
|
|
398
|
-
async getCurrentProposer() {
|
|
570
|
+
async getCurrentProposer(): Promise<EthAddress> {
|
|
399
571
|
const { result } = await this.client.simulateContract({
|
|
400
572
|
address: this.address,
|
|
401
573
|
abi: RollupAbi,
|
|
@@ -403,10 +575,10 @@ export class RollupContract {
|
|
|
403
575
|
args: [],
|
|
404
576
|
});
|
|
405
577
|
|
|
406
|
-
return result;
|
|
578
|
+
return EthAddress.fromString(result);
|
|
407
579
|
}
|
|
408
580
|
|
|
409
|
-
async getProposerAt(timestamp: bigint) {
|
|
581
|
+
async getProposerAt(timestamp: bigint): Promise<EthAddress> {
|
|
410
582
|
const { result } = await this.client.simulateContract({
|
|
411
583
|
address: this.address,
|
|
412
584
|
abi: RollupAbi,
|
|
@@ -414,11 +586,26 @@ export class RollupContract {
|
|
|
414
586
|
args: [timestamp],
|
|
415
587
|
});
|
|
416
588
|
|
|
417
|
-
return result;
|
|
589
|
+
return EthAddress.fromString(result);
|
|
418
590
|
}
|
|
419
591
|
|
|
420
|
-
getCheckpoint(checkpointNumber: CheckpointNumber) {
|
|
421
|
-
|
|
592
|
+
async getCheckpoint(checkpointNumber: CheckpointNumber): Promise<CheckpointLog> {
|
|
593
|
+
const result = await this.rollup.read.getCheckpoint([BigInt(checkpointNumber)]);
|
|
594
|
+
return {
|
|
595
|
+
archive: Fr.fromString(result.archive),
|
|
596
|
+
headerHash: Buffer32.fromString(result.headerHash),
|
|
597
|
+
blobCommitmentsHash: Buffer32.fromString(result.blobCommitmentsHash),
|
|
598
|
+
attestationsHash: Buffer32.fromString(result.attestationsHash),
|
|
599
|
+
payloadDigest: Buffer32.fromString(result.payloadDigest),
|
|
600
|
+
slotNumber: SlotNumber.fromBigInt(result.slotNumber),
|
|
601
|
+
feeHeader: {
|
|
602
|
+
excessMana: result.feeHeader.excessMana,
|
|
603
|
+
manaUsed: result.feeHeader.manaUsed,
|
|
604
|
+
ethPerFeeAsset: result.feeHeader.ethPerFeeAsset,
|
|
605
|
+
congestionCost: result.feeHeader.congestionCost,
|
|
606
|
+
proverCost: result.feeHeader.proverCost,
|
|
607
|
+
},
|
|
608
|
+
};
|
|
422
609
|
}
|
|
423
610
|
|
|
424
611
|
/** Returns the pending checkpoint from the rollup contract */
|
|
@@ -444,16 +631,16 @@ export class RollupContract {
|
|
|
444
631
|
};
|
|
445
632
|
}
|
|
446
633
|
|
|
447
|
-
getTimestampForSlot(slot: SlotNumber) {
|
|
634
|
+
getTimestampForSlot(slot: SlotNumber): Promise<bigint> {
|
|
448
635
|
return this.rollup.read.getTimestampForSlot([BigInt(slot)]);
|
|
449
636
|
}
|
|
450
637
|
|
|
451
|
-
getEntryQueueLength() {
|
|
452
|
-
return this.rollup.read.getEntryQueueLength();
|
|
638
|
+
async getEntryQueueLength(): Promise<number> {
|
|
639
|
+
return Number(await this.rollup.read.getEntryQueueLength());
|
|
453
640
|
}
|
|
454
641
|
|
|
455
|
-
getAvailableValidatorFlushes() {
|
|
456
|
-
return this.rollup.read.getAvailableValidatorFlushes();
|
|
642
|
+
async getAvailableValidatorFlushes(): Promise<number> {
|
|
643
|
+
return Number(await this.rollup.read.getAvailableValidatorFlushes());
|
|
457
644
|
}
|
|
458
645
|
|
|
459
646
|
async getNextFlushableEpoch(): Promise<EpochNumber> {
|
|
@@ -509,10 +696,11 @@ export class RollupContract {
|
|
|
509
696
|
return EpochNumber.fromBigInt(await this.rollup.read.getEpochAtSlot([BigInt(slotNumber)]));
|
|
510
697
|
}
|
|
511
698
|
|
|
512
|
-
getEpochProofPublicInputs(
|
|
699
|
+
async getEpochProofPublicInputs(
|
|
513
700
|
args: readonly [bigint, bigint, EpochProofPublicInputArgs, readonly `0x${string}`[], `0x${string}`],
|
|
514
|
-
) {
|
|
515
|
-
|
|
701
|
+
): Promise<Fr[]> {
|
|
702
|
+
const result = await this.rollup.read.getEpochProofPublicInputs(args);
|
|
703
|
+
return result.map(Fr.fromString);
|
|
516
704
|
}
|
|
517
705
|
|
|
518
706
|
public async validateHeader(
|
|
@@ -617,6 +805,7 @@ export class RollupContract {
|
|
|
617
805
|
): L1TxRequest {
|
|
618
806
|
return {
|
|
619
807
|
to: this.address,
|
|
808
|
+
abi: RollupAbi,
|
|
620
809
|
data: encodeFunctionData({
|
|
621
810
|
abi: RollupAbi,
|
|
622
811
|
functionName: 'invalidateBadAttestation',
|
|
@@ -638,6 +827,7 @@ export class RollupContract {
|
|
|
638
827
|
): L1TxRequest {
|
|
639
828
|
return {
|
|
640
829
|
to: this.address,
|
|
830
|
+
abi: RollupAbi,
|
|
641
831
|
data: encodeFunctionData({
|
|
642
832
|
abi: RollupAbi,
|
|
643
833
|
functionName: 'invalidateInsufficientAttestations',
|
|
@@ -654,90 +844,124 @@ export class RollupContract {
|
|
|
654
844
|
return this.rollup.read.getHasSubmitted([BigInt(epochNumber), BigInt(numberOfCheckpointsInEpoch), prover]);
|
|
655
845
|
}
|
|
656
846
|
|
|
657
|
-
|
|
658
|
-
return this.rollup.read.
|
|
847
|
+
getManaMinFeeAt(timestamp: bigint, inFeeAsset: boolean): Promise<bigint> {
|
|
848
|
+
return this.rollup.read.getManaMinFeeAt([timestamp, inFeeAsset]);
|
|
659
849
|
}
|
|
660
850
|
|
|
661
851
|
async getSlotAt(timestamp: bigint): Promise<SlotNumber> {
|
|
662
852
|
return SlotNumber.fromBigInt(await this.rollup.read.getSlotAt([timestamp]));
|
|
663
853
|
}
|
|
664
854
|
|
|
665
|
-
async status(checkpointNumber: CheckpointNumber, options?: { blockNumber?: bigint }) {
|
|
855
|
+
async status(checkpointNumber: CheckpointNumber, options?: { blockNumber?: bigint }): Promise<RollupStatusResponse> {
|
|
666
856
|
await checkBlockTag(options?.blockNumber, this.client);
|
|
667
|
-
|
|
857
|
+
const result = await this.rollup.read.status([BigInt(checkpointNumber)], options);
|
|
858
|
+
return {
|
|
859
|
+
provenCheckpointNumber: CheckpointNumber.fromBigInt(result[0]),
|
|
860
|
+
provenArchive: Fr.fromString(result[1]),
|
|
861
|
+
pendingCheckpointNumber: CheckpointNumber.fromBigInt(result[2]),
|
|
862
|
+
pendingArchive: Fr.fromString(result[3]),
|
|
863
|
+
archiveOfMyCheckpoint: Fr.fromString(result[4]),
|
|
864
|
+
};
|
|
668
865
|
}
|
|
669
866
|
|
|
670
|
-
async canPruneAtTime(timestamp: bigint, options?: { blockNumber?: bigint }) {
|
|
867
|
+
async canPruneAtTime(timestamp: bigint, options?: { blockNumber?: bigint }): Promise<boolean> {
|
|
671
868
|
await checkBlockTag(options?.blockNumber, this.client);
|
|
672
869
|
return this.rollup.read.canPruneAtTime([timestamp], options);
|
|
673
870
|
}
|
|
674
871
|
|
|
675
|
-
archive() {
|
|
676
|
-
return this.rollup.read.archive();
|
|
872
|
+
async archive(): Promise<Fr> {
|
|
873
|
+
return Fr.fromString(await this.rollup.read.archive());
|
|
677
874
|
}
|
|
678
875
|
|
|
679
|
-
archiveAt(checkpointNumber: CheckpointNumber) {
|
|
680
|
-
return this.rollup.read.archiveAt([BigInt(checkpointNumber)]);
|
|
876
|
+
async archiveAt(checkpointNumber: CheckpointNumber): Promise<Fr> {
|
|
877
|
+
return Fr.fromString(await this.rollup.read.archiveAt([BigInt(checkpointNumber)]));
|
|
681
878
|
}
|
|
682
879
|
|
|
683
|
-
getSequencerRewards(address: Hex | EthAddress) {
|
|
880
|
+
getSequencerRewards(address: Hex | EthAddress): Promise<bigint> {
|
|
684
881
|
if (address instanceof EthAddress) {
|
|
685
882
|
address = address.toString();
|
|
686
883
|
}
|
|
687
884
|
return this.rollup.read.getSequencerRewards([address]);
|
|
688
885
|
}
|
|
689
886
|
|
|
690
|
-
getSpecificProverRewardsForEpoch(epoch: bigint, prover: Hex | EthAddress) {
|
|
887
|
+
getSpecificProverRewardsForEpoch(epoch: bigint, prover: Hex | EthAddress): Promise<bigint> {
|
|
691
888
|
if (prover instanceof EthAddress) {
|
|
692
889
|
prover = prover.toString();
|
|
693
890
|
}
|
|
694
891
|
return this.rollup.read.getSpecificProverRewardsForEpoch([epoch, prover]);
|
|
695
892
|
}
|
|
696
893
|
|
|
697
|
-
async getAttesters() {
|
|
894
|
+
async getAttesters(): Promise<EthAddress[]> {
|
|
698
895
|
const attesterSize = await this.getActiveAttesterCount();
|
|
699
896
|
const gse = new GSEContract(this.client, await this.getGSE());
|
|
700
897
|
const ts = (await this.client.getBlock()).timestamp;
|
|
701
898
|
|
|
702
|
-
const indices = Array.from({ length:
|
|
899
|
+
const indices = Array.from({ length: attesterSize }, (_, i) => BigInt(i));
|
|
703
900
|
const chunks = chunk(indices, 1000);
|
|
704
901
|
|
|
705
|
-
|
|
902
|
+
const results = await Promise.all(chunks.map(chunk => gse.getAttestersFromIndicesAtTime(this.address, ts, chunk)));
|
|
903
|
+
return results.flat().map(addr => EthAddress.fromString(addr));
|
|
706
904
|
}
|
|
707
905
|
|
|
708
|
-
getAttesterView(address: Hex | EthAddress) {
|
|
906
|
+
async getAttesterView(address: Hex | EthAddress): Promise<AttesterView> {
|
|
709
907
|
if (address instanceof EthAddress) {
|
|
710
908
|
address = address.toString();
|
|
711
909
|
}
|
|
712
|
-
|
|
910
|
+
const result = await this.rollup.read.getAttesterView([address]);
|
|
911
|
+
return {
|
|
912
|
+
status: result.status as AttesterStatus,
|
|
913
|
+
effectiveBalance: result.effectiveBalance,
|
|
914
|
+
exit: {
|
|
915
|
+
withdrawalId: result.exit.withdrawalId,
|
|
916
|
+
amount: result.exit.amount,
|
|
917
|
+
exitableAt: result.exit.exitableAt,
|
|
918
|
+
recipientOrWithdrawer: EthAddress.fromString(result.exit.recipientOrWithdrawer),
|
|
919
|
+
isRecipient: result.exit.isRecipient,
|
|
920
|
+
exists: result.exit.exists,
|
|
921
|
+
},
|
|
922
|
+
config: {
|
|
923
|
+
publicKey: {
|
|
924
|
+
x: result.config.publicKey.x,
|
|
925
|
+
y: result.config.publicKey.y,
|
|
926
|
+
},
|
|
927
|
+
withdrawer: EthAddress.fromString(result.config.withdrawer),
|
|
928
|
+
},
|
|
929
|
+
};
|
|
713
930
|
}
|
|
714
931
|
|
|
715
|
-
getStatus(address: Hex | EthAddress) {
|
|
932
|
+
async getStatus(address: Hex | EthAddress): Promise<AttesterStatus> {
|
|
716
933
|
if (address instanceof EthAddress) {
|
|
717
934
|
address = address.toString();
|
|
718
935
|
}
|
|
719
|
-
return this.rollup.read.getStatus([address]);
|
|
936
|
+
return (await this.rollup.read.getStatus([address])) as AttesterStatus;
|
|
720
937
|
}
|
|
721
938
|
|
|
722
|
-
getBlobCommitmentsHash(checkpointNumber: CheckpointNumber) {
|
|
723
|
-
return this.rollup.read.getBlobCommitmentsHash([BigInt(checkpointNumber)]);
|
|
939
|
+
async getBlobCommitmentsHash(checkpointNumber: CheckpointNumber): Promise<Buffer32> {
|
|
940
|
+
return Buffer32.fromString(await this.rollup.read.getBlobCommitmentsHash([BigInt(checkpointNumber)]));
|
|
724
941
|
}
|
|
725
942
|
|
|
726
|
-
getCurrentBlobCommitmentsHash() {
|
|
727
|
-
return this.rollup.read.getCurrentBlobCommitmentsHash();
|
|
943
|
+
async getCurrentBlobCommitmentsHash(): Promise<Buffer32> {
|
|
944
|
+
return Buffer32.fromString(await this.rollup.read.getCurrentBlobCommitmentsHash());
|
|
728
945
|
}
|
|
729
946
|
|
|
730
|
-
getStakingAsset() {
|
|
731
|
-
return this.rollup.read.getStakingAsset();
|
|
947
|
+
async getStakingAsset(): Promise<EthAddress> {
|
|
948
|
+
return EthAddress.fromString(await this.rollup.read.getStakingAsset());
|
|
732
949
|
}
|
|
733
950
|
|
|
734
|
-
getRewardConfig() {
|
|
735
|
-
|
|
951
|
+
async getRewardConfig(): Promise<RewardConfig> {
|
|
952
|
+
const result = await this.rollup.read.getRewardConfig();
|
|
953
|
+
return {
|
|
954
|
+
rewardDistributor: EthAddress.fromString(result.rewardDistributor),
|
|
955
|
+
sequencerBps: BigInt(result.sequencerBps),
|
|
956
|
+
booster: EthAddress.fromString(result.booster),
|
|
957
|
+
checkpointReward: result.checkpointReward,
|
|
958
|
+
};
|
|
736
959
|
}
|
|
737
960
|
|
|
738
961
|
setupEpoch(l1TxUtils: L1TxUtils) {
|
|
739
962
|
return l1TxUtils.sendAndMonitorTransaction({
|
|
740
963
|
to: this.address,
|
|
964
|
+
abi: RollupAbi,
|
|
741
965
|
data: encodeFunctionData({
|
|
742
966
|
abi: RollupAbi,
|
|
743
967
|
functionName: 'setupEpoch',
|
|
@@ -749,6 +973,7 @@ export class RollupContract {
|
|
|
749
973
|
vote(l1TxUtils: L1TxUtils, proposalId: bigint) {
|
|
750
974
|
return l1TxUtils.sendAndMonitorTransaction({
|
|
751
975
|
to: this.address,
|
|
976
|
+
abi: RollupAbi,
|
|
752
977
|
data: encodeFunctionData({
|
|
753
978
|
abi: RollupAbi,
|
|
754
979
|
functionName: 'vote',
|
|
@@ -817,4 +1042,23 @@ export class RollupContract {
|
|
|
817
1042
|
},
|
|
818
1043
|
);
|
|
819
1044
|
}
|
|
1045
|
+
|
|
1046
|
+
/** Fetches CheckpointProposed events within the given block range. */
|
|
1047
|
+
async getCheckpointProposedEvents(fromBlock: bigint, toBlock: bigint): Promise<CheckpointProposedLog[]> {
|
|
1048
|
+
const logs = await this.rollup.getEvents.CheckpointProposed({}, { fromBlock, toBlock });
|
|
1049
|
+
return logs
|
|
1050
|
+
.filter(log => log.blockNumber! >= fromBlock && log.blockNumber! <= toBlock)
|
|
1051
|
+
.map(log => ({
|
|
1052
|
+
l1BlockNumber: log.blockNumber!,
|
|
1053
|
+
l1BlockHash: Buffer32.fromString(log.blockHash!),
|
|
1054
|
+
l1TransactionHash: log.transactionHash!,
|
|
1055
|
+
args: {
|
|
1056
|
+
checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
|
|
1057
|
+
archive: Fr.fromString(log.args.archive!),
|
|
1058
|
+
versionedBlobHashes: log.args.versionedBlobHashes!.map(h => Buffer.from(h.slice(2), 'hex')),
|
|
1059
|
+
attestationsHash: log.args.attestationsHash ? Buffer32.fromString(log.args.attestationsHash) : undefined,
|
|
1060
|
+
payloadDigest: log.args.payloadDigest ? Buffer32.fromString(log.args.payloadDigest) : undefined,
|
|
1061
|
+
},
|
|
1062
|
+
}));
|
|
1063
|
+
}
|
|
820
1064
|
}
|