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