@aztec/ethereum 0.0.1-commit.e0f15ab9b → 0.0.1-commit.e304674f1

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 (47) hide show
  1. package/dest/config.d.ts +6 -6
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +5 -9
  4. package/dest/contracts/inbox.d.ts +3 -3
  5. package/dest/contracts/inbox.d.ts.map +1 -1
  6. package/dest/contracts/inbox.js +5 -6
  7. package/dest/contracts/index.d.ts +2 -3
  8. package/dest/contracts/index.d.ts.map +1 -1
  9. package/dest/contracts/index.js +1 -2
  10. package/dest/contracts/rollup.d.ts +28 -11
  11. package/dest/contracts/rollup.d.ts.map +1 -1
  12. package/dest/contracts/rollup.js +152 -41
  13. package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +3 -4
  14. package/dest/contracts/slashing_proposer.d.ts.map +1 -0
  15. package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +13 -15
  16. package/dest/deploy_aztec_l1_contracts.d.ts +3 -6
  17. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
  18. package/dest/deploy_aztec_l1_contracts.js +2 -4
  19. package/dest/generated/l1-contracts-defaults.d.ts +1 -1
  20. package/dest/generated/l1-contracts-defaults.js +1 -1
  21. package/dest/l1_artifacts.d.ts +8176 -15179
  22. package/dest/l1_artifacts.d.ts.map +1 -1
  23. package/dest/l1_artifacts.js +9 -24
  24. package/dest/l1_contract_addresses.d.ts +1 -5
  25. package/dest/l1_contract_addresses.d.ts.map +1 -1
  26. package/dest/l1_contract_addresses.js +0 -6
  27. package/dest/l1_tx_utils/l1_tx_utils.d.ts +3 -1
  28. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
  29. package/dest/l1_tx_utils/l1_tx_utils.js +34 -26
  30. package/dest/queries.js +3 -3
  31. package/package.json +5 -5
  32. package/src/config.ts +9 -13
  33. package/src/contracts/inbox.ts +4 -4
  34. package/src/contracts/index.ts +1 -2
  35. package/src/contracts/rollup.ts +171 -35
  36. package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +14 -16
  37. package/src/deploy_aztec_l1_contracts.ts +1 -5
  38. package/src/generated/l1-contracts-defaults.ts +1 -1
  39. package/src/l1_artifacts.ts +12 -35
  40. package/src/l1_contract_addresses.ts +0 -7
  41. package/src/l1_tx_utils/l1_tx_utils.ts +24 -14
  42. package/src/queries.ts +3 -3
  43. package/dest/contracts/empire_slashing_proposer.d.ts +0 -69
  44. package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
  45. package/dest/contracts/empire_slashing_proposer.js +0 -216
  46. package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
  47. package/src/contracts/empire_slashing_proposer.ts +0 -265
@@ -1,265 +0,0 @@
1
- import { SlotNumber } from '@aztec/foundation/branded-types';
2
- import { EthAddress } from '@aztec/foundation/eth-address';
3
- import { createLogger } from '@aztec/foundation/log';
4
- import { retryUntil } from '@aztec/foundation/retry';
5
- import { EmpireSlashingProposerAbi } from '@aztec/l1-artifacts/EmpireSlashingProposerAbi';
6
-
7
- import EventEmitter from 'events';
8
- import {
9
- type GetContractReturnType,
10
- type Hex,
11
- type Log,
12
- type TypedDataDefinition,
13
- encodeFunctionData,
14
- getContract,
15
- } from 'viem';
16
-
17
- import type { L1TxRequest, L1TxUtils } from '../l1_tx_utils/index.js';
18
- import type { ViemClient } from '../types.js';
19
- import { FormattedViemError, tryExtractEvent } from '../utils.js';
20
- import { type IEmpireBase, encodeSignal, encodeSignalWithSignature, signSignalWithSig } from './empire_base.js';
21
-
22
- export class ProposalAlreadyExecutedError extends Error {
23
- constructor(round: bigint) {
24
- super(`Proposal already executed: ${round}`);
25
- }
26
- }
27
-
28
- export class EmpireSlashingProposerContract extends EventEmitter implements IEmpireBase {
29
- private readonly logger = createLogger('ethereum:contracts:empire_slashing_proposer');
30
- private readonly proposer: GetContractReturnType<typeof EmpireSlashingProposerAbi, ViemClient>;
31
-
32
- public readonly type = 'empire' as const;
33
-
34
- constructor(
35
- public readonly client: ViemClient,
36
- address: Hex | EthAddress,
37
- ) {
38
- super();
39
- this.proposer = getContract({
40
- address: typeof address === 'string' ? address : address.toString(),
41
- abi: EmpireSlashingProposerAbi,
42
- client,
43
- });
44
- }
45
-
46
- public get address() {
47
- return EthAddress.fromString(this.proposer.address);
48
- }
49
-
50
- public getQuorumSize() {
51
- return this.proposer.read.QUORUM_SIZE();
52
- }
53
-
54
- public getRoundSize() {
55
- return this.proposer.read.ROUND_SIZE();
56
- }
57
-
58
- public getLifetimeInRounds() {
59
- return this.proposer.read.LIFETIME_IN_ROUNDS();
60
- }
61
-
62
- public getExecutionDelayInRounds() {
63
- return this.proposer.read.EXECUTION_DELAY_IN_ROUNDS();
64
- }
65
-
66
- public getCurrentRound() {
67
- return this.proposer.read.getCurrentRound();
68
- }
69
-
70
- public computeRound(slot: SlotNumber): Promise<bigint> {
71
- return this.proposer.read.computeRound([BigInt(slot)]);
72
- }
73
-
74
- public getInstance() {
75
- return this.proposer.read.getInstance();
76
- }
77
-
78
- public async getRoundInfo(
79
- rollupAddress: Hex,
80
- round: bigint,
81
- ): Promise<{ lastSignalSlot: SlotNumber; payloadWithMostSignals: Hex; quorumReached: boolean; executed: boolean }> {
82
- const result = await this.proposer.read.getRoundData([rollupAddress, round]);
83
- const [signalCount, quorum] = await Promise.all([
84
- this.proposer.read.signalCount([rollupAddress, round, result.payloadWithMostSignals]),
85
- this.getQuorumSize(),
86
- ]);
87
- return {
88
- lastSignalSlot: SlotNumber.fromBigInt(result.lastSignalSlot),
89
- payloadWithMostSignals: result.payloadWithMostSignals,
90
- quorumReached: signalCount >= quorum,
91
- executed: result.executed,
92
- };
93
- }
94
-
95
- public getPayloadSignals(rollupAddress: Hex, round: bigint, payload: Hex): Promise<bigint> {
96
- return this.proposer.read.signalCount([rollupAddress, round, payload]);
97
- }
98
-
99
- public createSignalRequest(payload: Hex): L1TxRequest {
100
- return {
101
- to: this.address.toString(),
102
- abi: EmpireSlashingProposerAbi,
103
- data: encodeSignal(payload),
104
- };
105
- }
106
-
107
- public async createSignalRequestWithSignature(
108
- payload: Hex,
109
- slot: SlotNumber,
110
- chainId: number,
111
- signerAddress: Hex,
112
- signer: (msg: TypedDataDefinition) => Promise<Hex>,
113
- ): Promise<L1TxRequest> {
114
- const signature = await signSignalWithSig(
115
- signer,
116
- payload,
117
- slot,
118
- await this.getInstance(),
119
- this.address.toString(),
120
- chainId,
121
- );
122
- return {
123
- to: this.address.toString(),
124
- abi: EmpireSlashingProposerAbi,
125
- data: encodeSignalWithSignature(payload, signature),
126
- };
127
- }
128
-
129
- /** Checks if a payload was ever submitted to governance via submitRoundWinner. */
130
- public async hasPayloadBeenProposed(payload: Hex, fromBlock: bigint): Promise<boolean> {
131
- const events = await this.proposer.getEvents.PayloadSubmitted({ payload }, { fromBlock, strict: true });
132
- return events.length > 0;
133
- }
134
-
135
- public listenToSubmittablePayloads(callback: (args: { payload: `0x${string}`; round: bigint }) => unknown) {
136
- return this.proposer.watchEvent.PayloadSubmittable(
137
- {},
138
- {
139
- strict: true,
140
- onLogs: logs => {
141
- for (const log of logs) {
142
- const { payload, round } = log.args;
143
- if (payload && round) {
144
- callback({ payload, round });
145
- }
146
- }
147
- },
148
- },
149
- );
150
- }
151
-
152
- public listenToPayloadSubmitted(callback: (args: { round: bigint; payload: `0x${string}` }) => unknown) {
153
- return this.proposer.watchEvent.PayloadSubmitted(
154
- {},
155
- {
156
- onLogs: logs => {
157
- for (const log of logs) {
158
- const { payload, round } = log.args;
159
- if (round && payload) {
160
- callback({ round, payload });
161
- }
162
- }
163
- },
164
- },
165
- );
166
- }
167
-
168
- public listenToSignalCasted(
169
- callback: (args: { round: bigint; payload: `0x${string}`; signaler: `0x${string}` }) => unknown,
170
- ) {
171
- return this.proposer.watchEvent.SignalCast(
172
- {},
173
- {
174
- onLogs: logs => {
175
- for (const log of logs) {
176
- const { round, payload, signaler } = log.args;
177
- if (round && payload && signaler) {
178
- callback({ round, payload, signaler });
179
- }
180
- }
181
- },
182
- },
183
- );
184
- }
185
-
186
- /** Creates an L1TxRequest to submit the round winner for the given round. */
187
- public buildExecuteRoundRequest(round: bigint): L1TxRequest {
188
- return {
189
- to: this.address.toString(),
190
- abi: EmpireSlashingProposerAbi,
191
- data: encodeFunctionData({
192
- abi: EmpireSlashingProposerAbi,
193
- functionName: 'submitRoundWinner',
194
- args: [round],
195
- }),
196
- };
197
- }
198
-
199
- /** Tries to extract a PayloadSubmitted event from the given logs. */
200
- public tryExtractPayloadSubmittedEvent(logs: Log[]) {
201
- return tryExtractEvent(logs, this.address.toString(), EmpireSlashingProposerAbi, 'PayloadSubmitted');
202
- }
203
-
204
- /**
205
- * Wait for a round to be reached.
206
- *
207
- * @param round - The round to wait for.
208
- * @param pollingIntervalSeconds - The interval in seconds to poll for the round.
209
- * @returns True if the round was reached, false otherwise.
210
- */
211
- public waitForRound(round: bigint, pollingIntervalSeconds: number = 1): Promise<boolean> {
212
- return retryUntil(
213
- async () => {
214
- const currentRound = await this.proposer.read.getCurrentRound().catch(e => {
215
- this.logger.error('Error getting current round', e);
216
- return undefined;
217
- });
218
- return currentRound !== undefined && currentRound >= round;
219
- },
220
- `Waiting for round ${round} to be reached`,
221
- 0, // no timeout
222
- pollingIntervalSeconds,
223
- ).catch(() => false);
224
- }
225
-
226
- public async executeRound(
227
- txUtils: L1TxUtils,
228
- round: bigint | number,
229
- ): ReturnType<typeof txUtils.sendAndMonitorTransaction> {
230
- if (typeof round === 'number') {
231
- round = BigInt(round);
232
- }
233
- const request = this.buildExecuteRoundRequest(round);
234
- const response = await txUtils
235
- .sendAndMonitorTransaction(request, {
236
- // Gas estimation is way off for this, likely because we are creating the contract/selector to call
237
- // for the actual slashing dynamically.
238
- gasLimitBufferPercentage: 50, // +50% gas
239
- })
240
- .catch(err => {
241
- if (err instanceof FormattedViemError && err.message.includes('ProposalAlreadyExecuted')) {
242
- throw new ProposalAlreadyExecutedError(round);
243
- }
244
- throw err;
245
- });
246
-
247
- if (response.receipt.status === 'reverted') {
248
- const args = {
249
- abi: EmpireSlashingProposerAbi,
250
- functionName: 'submitRoundWinner' as const,
251
- args: [round] as const,
252
- address: this.address.toString(),
253
- };
254
- const error = await txUtils.tryGetErrorFromRevertedTx(request.data!, args, undefined, []);
255
- if (error?.includes('ProposalAlreadyExecuted')) {
256
- throw new ProposalAlreadyExecutedError(round);
257
- }
258
- const errorMessage = `Failed to execute round ${round}, TxHash: ${response.receipt.transactionHash}, Error: ${
259
- error ?? 'Unknown error'
260
- }`;
261
- throw new Error(errorMessage);
262
- }
263
- return response;
264
- }
265
- }