@aztec/ethereum 0.0.0-test.0

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 (118) hide show
  1. package/README.md +3 -0
  2. package/dest/chain.d.ts +25 -0
  3. package/dest/chain.d.ts.map +1 -0
  4. package/dest/chain.js +53 -0
  5. package/dest/client.d.ts +16 -0
  6. package/dest/client.d.ts.map +1 -0
  7. package/dest/client.js +31 -0
  8. package/dest/config.d.ts +39 -0
  9. package/dest/config.d.ts.map +1 -0
  10. package/dest/config.js +70 -0
  11. package/dest/constants.d.ts +4 -0
  12. package/dest/constants.d.ts.map +1 -0
  13. package/dest/constants.js +2 -0
  14. package/dest/contracts/empire_base.d.ts +13 -0
  15. package/dest/contracts/empire_base.d.ts.map +1 -0
  16. package/dest/contracts/empire_base.js +11 -0
  17. package/dest/contracts/fee_juice.d.ts +15 -0
  18. package/dest/contracts/fee_juice.d.ts.map +1 -0
  19. package/dest/contracts/fee_juice.js +52 -0
  20. package/dest/contracts/forwarder.d.ts +24 -0
  21. package/dest/contracts/forwarder.d.ts.map +1 -0
  22. package/dest/contracts/forwarder.js +101 -0
  23. package/dest/contracts/governance.d.ts +79 -0
  24. package/dest/contracts/governance.d.ts.map +1 -0
  25. package/dest/contracts/governance.js +247 -0
  26. package/dest/contracts/governance_proposer.d.ts +28 -0
  27. package/dest/contracts/governance_proposer.d.ts.map +1 -0
  28. package/dest/contracts/governance_proposer.js +82 -0
  29. package/dest/contracts/index.d.ts +9 -0
  30. package/dest/contracts/index.d.ts.map +1 -0
  31. package/dest/contracts/index.js +8 -0
  32. package/dest/contracts/registry.d.ts +24 -0
  33. package/dest/contracts/registry.d.ts.map +1 -0
  34. package/dest/contracts/registry.js +85 -0
  35. package/dest/contracts/rollup.d.ts +92 -0
  36. package/dest/contracts/rollup.d.ts.map +1 -0
  37. package/dest/contracts/rollup.js +234 -0
  38. package/dest/contracts/slashing_proposer.d.ts +21 -0
  39. package/dest/contracts/slashing_proposer.d.ts.map +1 -0
  40. package/dest/contracts/slashing_proposer.js +47 -0
  41. package/dest/deploy_l1_contracts.d.ts +21210 -0
  42. package/dest/deploy_l1_contracts.d.ts.map +1 -0
  43. package/dest/deploy_l1_contracts.js +687 -0
  44. package/dest/eth_cheat_codes.d.ts +147 -0
  45. package/dest/eth_cheat_codes.d.ts.map +1 -0
  46. package/dest/eth_cheat_codes.js +303 -0
  47. package/dest/index.d.ts +14 -0
  48. package/dest/index.d.ts.map +1 -0
  49. package/dest/index.js +13 -0
  50. package/dest/l1_contract_addresses.d.ts +57 -0
  51. package/dest/l1_contract_addresses.d.ts.map +1 -0
  52. package/dest/l1_contract_addresses.js +97 -0
  53. package/dest/l1_reader.d.ts +16 -0
  54. package/dest/l1_reader.d.ts.map +1 -0
  55. package/dest/l1_reader.js +27 -0
  56. package/dest/l1_tx_utils.d.ts +192 -0
  57. package/dest/l1_tx_utils.d.ts.map +1 -0
  58. package/dest/l1_tx_utils.js +641 -0
  59. package/dest/l1_tx_utils_with_blobs.d.ts +12 -0
  60. package/dest/l1_tx_utils_with_blobs.d.ts.map +1 -0
  61. package/dest/l1_tx_utils_with_blobs.js +64 -0
  62. package/dest/queries.d.ts +12 -0
  63. package/dest/queries.d.ts.map +1 -0
  64. package/dest/queries.js +35 -0
  65. package/dest/test/delayed_tx_utils.d.ts +8 -0
  66. package/dest/test/delayed_tx_utils.d.ts.map +1 -0
  67. package/dest/test/delayed_tx_utils.js +21 -0
  68. package/dest/test/eth_cheat_codes_with_state.d.ts +18 -0
  69. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -0
  70. package/dest/test/eth_cheat_codes_with_state.js +34 -0
  71. package/dest/test/index.d.ts +6 -0
  72. package/dest/test/index.d.ts.map +1 -0
  73. package/dest/test/index.js +5 -0
  74. package/dest/test/start_anvil.d.ts +12 -0
  75. package/dest/test/start_anvil.d.ts.map +1 -0
  76. package/dest/test/start_anvil.js +46 -0
  77. package/dest/test/tx_delayer.d.ts +25 -0
  78. package/dest/test/tx_delayer.d.ts.map +1 -0
  79. package/dest/test/tx_delayer.js +116 -0
  80. package/dest/test/upgrade_utils.d.ts +11 -0
  81. package/dest/test/upgrade_utils.d.ts.map +1 -0
  82. package/dest/test/upgrade_utils.js +104 -0
  83. package/dest/types.d.ts +14 -0
  84. package/dest/types.d.ts.map +1 -0
  85. package/dest/types.js +1 -0
  86. package/dest/utils.d.ts +24 -0
  87. package/dest/utils.d.ts.map +1 -0
  88. package/dest/utils.js +209 -0
  89. package/package.json +98 -0
  90. package/src/chain.ts +71 -0
  91. package/src/client.ts +58 -0
  92. package/src/config.ts +103 -0
  93. package/src/constants.ts +4 -0
  94. package/src/contracts/empire_base.ts +19 -0
  95. package/src/contracts/fee_juice.ts +43 -0
  96. package/src/contracts/forwarder.ts +132 -0
  97. package/src/contracts/governance.ts +285 -0
  98. package/src/contracts/governance_proposer.ts +82 -0
  99. package/src/contracts/index.ts +8 -0
  100. package/src/contracts/registry.ts +106 -0
  101. package/src/contracts/rollup.ts +274 -0
  102. package/src/contracts/slashing_proposer.ts +51 -0
  103. package/src/deploy_l1_contracts.ts +948 -0
  104. package/src/eth_cheat_codes.ts +314 -0
  105. package/src/index.ts +13 -0
  106. package/src/l1_contract_addresses.ts +109 -0
  107. package/src/l1_reader.ts +42 -0
  108. package/src/l1_tx_utils.ts +847 -0
  109. package/src/l1_tx_utils_with_blobs.ts +86 -0
  110. package/src/queries.ts +58 -0
  111. package/src/test/delayed_tx_utils.ts +24 -0
  112. package/src/test/eth_cheat_codes_with_state.ts +38 -0
  113. package/src/test/index.ts +5 -0
  114. package/src/test/start_anvil.ts +52 -0
  115. package/src/test/tx_delayer.ts +163 -0
  116. package/src/test/upgrade_utils.ts +100 -0
  117. package/src/types.ts +33 -0
  118. package/src/utils.ts +276 -0
@@ -0,0 +1,234 @@
1
+ function _ts_decorate(decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ }
7
+ import { memoize } from '@aztec/foundation/decorators';
8
+ import { EthAddress } from '@aztec/foundation/eth-address';
9
+ import { RollupAbi, RollupStorage, SlasherAbi } from '@aztec/l1-artifacts';
10
+ import { getAddress, getContract } from 'viem';
11
+ import { getPublicClient } from '../client.js';
12
+ import { formatViemError } from '../utils.js';
13
+ import { SlashingProposerContract } from './slashing_proposer.js';
14
+ export class RollupContract {
15
+ client;
16
+ rollup;
17
+ static get checkBlobStorageSlot() {
18
+ const asString = RollupStorage.find((storage)=>storage.label === 'checkBlob')?.slot;
19
+ if (asString === undefined) {
20
+ throw new Error('checkBlobStorageSlot not found');
21
+ }
22
+ return BigInt(asString);
23
+ }
24
+ static getFromL1ContractsValues(deployL1ContractsValues) {
25
+ const { publicClient, l1ContractAddresses: { rollupAddress } } = deployL1ContractsValues;
26
+ return new RollupContract(publicClient, rollupAddress.toString());
27
+ }
28
+ static getFromConfig(config) {
29
+ const client = getPublicClient(config);
30
+ const address = config.l1Contracts.rollupAddress.toString();
31
+ return new RollupContract(client, address);
32
+ }
33
+ constructor(client, address){
34
+ this.client = client;
35
+ if (address instanceof EthAddress) {
36
+ address = address.toString();
37
+ }
38
+ this.rollup = getContract({
39
+ address,
40
+ abi: RollupAbi,
41
+ client
42
+ });
43
+ }
44
+ get address() {
45
+ return this.rollup.address;
46
+ }
47
+ async getSlashingProposer() {
48
+ const slasherAddress = await this.rollup.read.getSlasher();
49
+ const slasher = getContract({
50
+ address: slasherAddress,
51
+ abi: SlasherAbi,
52
+ client: this.client
53
+ });
54
+ const proposerAddress = await slasher.read.PROPOSER();
55
+ return new SlashingProposerContract(this.client, proposerAddress);
56
+ }
57
+ getL1StartBlock() {
58
+ return this.rollup.read.L1_BLOCK_AT_GENESIS();
59
+ }
60
+ getL1GenesisTime() {
61
+ return this.rollup.read.getGenesisTime();
62
+ }
63
+ getProofSubmissionWindow() {
64
+ return this.rollup.read.getProofSubmissionWindow();
65
+ }
66
+ getEpochDuration() {
67
+ return this.rollup.read.getEpochDuration();
68
+ }
69
+ getSlotDuration() {
70
+ return this.rollup.read.getSlotDuration();
71
+ }
72
+ getTargetCommitteeSize() {
73
+ return this.rollup.read.getTargetCommitteeSize();
74
+ }
75
+ getMinimumStake() {
76
+ return this.rollup.read.getMinimumStake();
77
+ }
78
+ async getSlashingProposerAddress() {
79
+ const slasherAddress = await this.rollup.read.getSlasher();
80
+ const slasher = getContract({
81
+ address: getAddress(slasherAddress.toString()),
82
+ abi: SlasherAbi,
83
+ client: this.client
84
+ });
85
+ return EthAddress.fromString(await slasher.read.PROPOSER());
86
+ }
87
+ getBlockNumber() {
88
+ return this.rollup.read.getPendingBlockNumber();
89
+ }
90
+ getProvenBlockNumber() {
91
+ return this.rollup.read.getProvenBlockNumber();
92
+ }
93
+ getSlotNumber() {
94
+ return this.rollup.read.getCurrentSlot();
95
+ }
96
+ getCommitteeAt(timestamp) {
97
+ return this.rollup.read.getCommitteeAt([
98
+ timestamp
99
+ ]);
100
+ }
101
+ getSampleSeedAt(timestamp) {
102
+ return this.rollup.read.getSampleSeedAt([
103
+ timestamp
104
+ ]);
105
+ }
106
+ getCurrentSampleSeed() {
107
+ return this.rollup.read.getCurrentSampleSeed();
108
+ }
109
+ getCurrentEpochCommittee() {
110
+ return this.rollup.read.getCurrentEpochCommittee();
111
+ }
112
+ getCurrentProposer() {
113
+ return this.rollup.read.getCurrentProposer();
114
+ }
115
+ getProposerAt(timestamp) {
116
+ return this.rollup.read.getProposerAt([
117
+ timestamp
118
+ ]);
119
+ }
120
+ getBlock(blockNumber) {
121
+ return this.rollup.read.getBlock([
122
+ blockNumber
123
+ ]);
124
+ }
125
+ getTips() {
126
+ return this.rollup.read.getTips();
127
+ }
128
+ getTimestampForSlot(slot) {
129
+ return this.rollup.read.getTimestampForSlot([
130
+ slot
131
+ ]);
132
+ }
133
+ async getEpochNumber(blockNumber) {
134
+ blockNumber ??= await this.getBlockNumber();
135
+ return this.rollup.read.getEpochForBlock([
136
+ BigInt(blockNumber)
137
+ ]);
138
+ }
139
+ async getRollupAddresses() {
140
+ const [inboxAddress, outboxAddress, feeJuicePortalAddress, rewardDistributorAddress, feeJuiceAddress, stakingAssetAddress] = (await Promise.all([
141
+ this.rollup.read.getInbox(),
142
+ this.rollup.read.getOutbox(),
143
+ this.rollup.read.getFeeAssetPortal(),
144
+ this.rollup.read.getRewardDistributor(),
145
+ this.rollup.read.getFeeAsset(),
146
+ this.rollup.read.getStakingAsset()
147
+ ])).map(EthAddress.fromString);
148
+ return {
149
+ rollupAddress: EthAddress.fromString(this.address),
150
+ inboxAddress,
151
+ outboxAddress,
152
+ feeJuicePortalAddress,
153
+ feeJuiceAddress,
154
+ stakingAssetAddress,
155
+ rewardDistributorAddress
156
+ };
157
+ }
158
+ async getEpochNumberForSlotNumber(slotNumber) {
159
+ return await this.rollup.read.getEpochAtSlot([
160
+ slotNumber
161
+ ]);
162
+ }
163
+ getEpochProofPublicInputs(args) {
164
+ return this.rollup.read.getEpochProofPublicInputs(args);
165
+ }
166
+ async validateHeader(args, account) {
167
+ try {
168
+ await this.rollup.read.validateHeader(args, {
169
+ account
170
+ });
171
+ } catch (error) {
172
+ throw formatViemError(error);
173
+ }
174
+ }
175
+ /**
176
+ * @notice Calls `canProposeAtTime` with the time of the next Ethereum block and the sender address
177
+ *
178
+ * @dev Throws if unable to propose
179
+ *
180
+ * @param archive - The archive that we expect to be current state
181
+ * @return [slot, blockNumber] - If you can propose, the L2 slot number and L2 block number of the next Ethereum block,
182
+ * @throws otherwise
183
+ */ async canProposeAtNextEthBlock(archive, account, slotDuration) {
184
+ if (typeof slotDuration === 'number') {
185
+ slotDuration = BigInt(slotDuration);
186
+ }
187
+ const timeOfNextL1Slot = (await this.client.getBlock()).timestamp + slotDuration;
188
+ try {
189
+ const [slot, blockNumber] = await this.rollup.read.canProposeAtTime([
190
+ timeOfNextL1Slot,
191
+ `0x${archive.toString('hex')}`
192
+ ], {
193
+ account
194
+ });
195
+ return [
196
+ slot,
197
+ blockNumber
198
+ ];
199
+ } catch (err) {
200
+ throw formatViemError(err);
201
+ }
202
+ }
203
+ /** Calls getHasSubmitted directly. Returns whether the given prover has submitted a proof with the given length for the given epoch. */ getHasSubmittedProof(epochNumber, numberOfBlocksInEpoch, prover) {
204
+ return this.rollup.read.getHasSubmitted([
205
+ BigInt(epochNumber),
206
+ BigInt(numberOfBlocksInEpoch),
207
+ prover.toString()
208
+ ]);
209
+ }
210
+ }
211
+ _ts_decorate([
212
+ memoize
213
+ ], RollupContract.prototype, "getSlashingProposer", null);
214
+ _ts_decorate([
215
+ memoize
216
+ ], RollupContract.prototype, "getL1StartBlock", null);
217
+ _ts_decorate([
218
+ memoize
219
+ ], RollupContract.prototype, "getL1GenesisTime", null);
220
+ _ts_decorate([
221
+ memoize
222
+ ], RollupContract.prototype, "getProofSubmissionWindow", null);
223
+ _ts_decorate([
224
+ memoize
225
+ ], RollupContract.prototype, "getEpochDuration", null);
226
+ _ts_decorate([
227
+ memoize
228
+ ], RollupContract.prototype, "getSlotDuration", null);
229
+ _ts_decorate([
230
+ memoize
231
+ ], RollupContract.prototype, "getTargetCommitteeSize", null);
232
+ _ts_decorate([
233
+ memoize
234
+ ], RollupContract.prototype, "getMinimumStake", null);
@@ -0,0 +1,21 @@
1
+ import { EthAddress } from '@aztec/foundation/eth-address';
2
+ import { type Hex } from 'viem';
3
+ import type { L1TxRequest } from '../l1_tx_utils.js';
4
+ import type { ViemPublicClient } from '../types.js';
5
+ import { type IEmpireBase } from './empire_base.js';
6
+ export declare class SlashingProposerContract implements IEmpireBase {
7
+ readonly client: ViemPublicClient;
8
+ private readonly proposer;
9
+ constructor(client: ViemPublicClient, address: Hex);
10
+ get address(): EthAddress;
11
+ getQuorumSize(): Promise<bigint>;
12
+ getRoundSize(): Promise<bigint>;
13
+ computeRound(slot: bigint): Promise<bigint>;
14
+ getRoundInfo(rollupAddress: Hex, round: bigint): Promise<{
15
+ lastVote: bigint;
16
+ leader: Hex;
17
+ executed: boolean;
18
+ }>;
19
+ createVoteRequest(payload: Hex): L1TxRequest;
20
+ }
21
+ //# sourceMappingURL=slashing_proposer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slashing_proposer.d.ts","sourceRoot":"","sources":["../../src/contracts/slashing_proposer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAG3D,OAAO,EAA8B,KAAK,GAAG,EAAe,MAAM,MAAM,CAAC;AAEzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,KAAK,WAAW,EAAc,MAAM,kBAAkB,CAAC;AAEhE,qBAAa,wBAAyB,YAAW,WAAW;aAG9B,MAAM,EAAE,gBAAgB;IAFpD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsE;gBAEnE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,GAAG;IAIlE,IAAW,OAAO,eAEjB;IAEM,aAAa;IAIb,YAAY;IAIZ,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIrC,YAAY,CACvB,aAAa,EAAE,GAAG,EAClB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC;IASzD,iBAAiB,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW;CAMpD"}
@@ -0,0 +1,47 @@
1
+ import { EthAddress } from '@aztec/foundation/eth-address';
2
+ import { SlashingProposerAbi } from '@aztec/l1-artifacts';
3
+ import { getContract } from 'viem';
4
+ import { encodeVote } from './empire_base.js';
5
+ export class SlashingProposerContract {
6
+ client;
7
+ proposer;
8
+ constructor(client, address){
9
+ this.client = client;
10
+ this.proposer = getContract({
11
+ address,
12
+ abi: SlashingProposerAbi,
13
+ client
14
+ });
15
+ }
16
+ get address() {
17
+ return EthAddress.fromString(this.proposer.address);
18
+ }
19
+ getQuorumSize() {
20
+ return this.proposer.read.N();
21
+ }
22
+ getRoundSize() {
23
+ return this.proposer.read.M();
24
+ }
25
+ computeRound(slot) {
26
+ return this.proposer.read.computeRound([
27
+ slot
28
+ ]);
29
+ }
30
+ async getRoundInfo(rollupAddress, round) {
31
+ const roundInfo = await this.proposer.read.rounds([
32
+ rollupAddress,
33
+ round
34
+ ]);
35
+ return {
36
+ lastVote: roundInfo[0],
37
+ leader: roundInfo[1],
38
+ executed: roundInfo[2]
39
+ };
40
+ }
41
+ createVoteRequest(payload) {
42
+ return {
43
+ to: this.address.toString(),
44
+ data: encodeVote(payload)
45
+ };
46
+ }
47
+ }