@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.0208eb9
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 +68 -23
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +145 -32
- 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 +207 -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 +59 -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 +45 -32
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +98 -85
- 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 +432 -26
- 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 +47 -0
- package/dest/contracts/inbox.d.ts.map +1 -0
- package/dest/contracts/inbox.js +80 -0
- package/dest/contracts/index.d.ts +11 -3
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +10 -2
- 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 +21 -0
- package/dest/contracts/multicall.d.ts.map +1 -0
- package/dest/contracts/multicall.js +157 -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 +297 -53
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +1127 -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 +320 -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 +260 -0
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_aztec_l1_contracts.js +399 -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/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 +80735 -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 +16 -0
- package/dest/publisher_manager.d.ts.map +1 -0
- package/dest/publisher_manager.js +88 -0
- package/dest/queries.d.ts +5 -3
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +61 -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 +229 -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 +90 -0
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
- package/dest/test/rollup_cheat_codes.js +292 -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 +17 -3
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +107 -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 +51 -23
- package/src/account.ts +5 -0
- package/src/client.ts +43 -5
- package/src/config.ts +207 -41
- package/src/contracts/README.md +157 -0
- package/src/contracts/empire_base.ts +77 -7
- package/src/contracts/empire_slashing_proposer.ts +259 -0
- package/src/contracts/errors.ts +13 -0
- package/src/contracts/fee_asset_handler.ts +66 -0
- package/src/contracts/fee_juice.ts +29 -15
- package/src/contracts/governance.ts +90 -78
- package/src/contracts/governance_proposer.ts +75 -25
- package/src/contracts/gse.ts +88 -0
- package/src/contracts/inbox.ts +115 -0
- package/src/contracts/index.ts +10 -2
- package/src/contracts/log.ts +13 -0
- package/src/contracts/multicall.ts +158 -0
- package/src/contracts/outbox.ts +98 -0
- package/src/contracts/registry.ts +51 -26
- package/src/contracts/rollup.ts +879 -89
- package/src/contracts/slasher_contract.ts +89 -0
- package/src/contracts/tally_slashing_proposer.ts +322 -0
- package/src/contracts/utils.ts +14 -0
- package/src/deploy_aztec_l1_contracts.ts +623 -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/generated/l1-contracts-defaults.ts +32 -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 +108 -0
- package/src/queries.ts +82 -16
- 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 +330 -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 +133 -92
- 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
|
@@ -0,0 +1,259 @@
|
|
|
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
|
+
public listenToSubmittablePayloads(callback: (args: { payload: `0x${string}`; round: bigint }) => unknown) {
|
|
130
|
+
return this.proposer.watchEvent.PayloadSubmittable(
|
|
131
|
+
{},
|
|
132
|
+
{
|
|
133
|
+
strict: true,
|
|
134
|
+
onLogs: logs => {
|
|
135
|
+
for (const log of logs) {
|
|
136
|
+
const { payload, round } = log.args;
|
|
137
|
+
if (payload && round) {
|
|
138
|
+
callback({ payload, round });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
public listenToPayloadSubmitted(callback: (args: { round: bigint; payload: `0x${string}` }) => unknown) {
|
|
147
|
+
return this.proposer.watchEvent.PayloadSubmitted(
|
|
148
|
+
{},
|
|
149
|
+
{
|
|
150
|
+
onLogs: logs => {
|
|
151
|
+
for (const log of logs) {
|
|
152
|
+
const { payload, round } = log.args;
|
|
153
|
+
if (round && payload) {
|
|
154
|
+
callback({ round, payload });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
public listenToSignalCasted(
|
|
163
|
+
callback: (args: { round: bigint; payload: `0x${string}`; signaler: `0x${string}` }) => unknown,
|
|
164
|
+
) {
|
|
165
|
+
return this.proposer.watchEvent.SignalCast(
|
|
166
|
+
{},
|
|
167
|
+
{
|
|
168
|
+
onLogs: logs => {
|
|
169
|
+
for (const log of logs) {
|
|
170
|
+
const { round, payload, signaler } = log.args;
|
|
171
|
+
if (round && payload && signaler) {
|
|
172
|
+
callback({ round, payload, signaler });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Creates an L1TxRequest to submit the round winner for the given round. */
|
|
181
|
+
public buildExecuteRoundRequest(round: bigint): L1TxRequest {
|
|
182
|
+
return {
|
|
183
|
+
to: this.address.toString(),
|
|
184
|
+
abi: EmpireSlashingProposerAbi,
|
|
185
|
+
data: encodeFunctionData({
|
|
186
|
+
abi: EmpireSlashingProposerAbi,
|
|
187
|
+
functionName: 'submitRoundWinner',
|
|
188
|
+
args: [round],
|
|
189
|
+
}),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Tries to extract a PayloadSubmitted event from the given logs. */
|
|
194
|
+
public tryExtractPayloadSubmittedEvent(logs: Log[]) {
|
|
195
|
+
return tryExtractEvent(logs, this.address.toString(), EmpireSlashingProposerAbi, 'PayloadSubmitted');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Wait for a round to be reached.
|
|
200
|
+
*
|
|
201
|
+
* @param round - The round to wait for.
|
|
202
|
+
* @param pollingIntervalSeconds - The interval in seconds to poll for the round.
|
|
203
|
+
* @returns True if the round was reached, false otherwise.
|
|
204
|
+
*/
|
|
205
|
+
public waitForRound(round: bigint, pollingIntervalSeconds: number = 1): Promise<boolean> {
|
|
206
|
+
return retryUntil(
|
|
207
|
+
async () => {
|
|
208
|
+
const currentRound = await this.proposer.read.getCurrentRound().catch(e => {
|
|
209
|
+
this.logger.error('Error getting current round', e);
|
|
210
|
+
return undefined;
|
|
211
|
+
});
|
|
212
|
+
return currentRound !== undefined && currentRound >= round;
|
|
213
|
+
},
|
|
214
|
+
`Waiting for round ${round} to be reached`,
|
|
215
|
+
0, // no timeout
|
|
216
|
+
pollingIntervalSeconds,
|
|
217
|
+
).catch(() => false);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public async executeRound(
|
|
221
|
+
txUtils: L1TxUtils,
|
|
222
|
+
round: bigint | number,
|
|
223
|
+
): ReturnType<typeof txUtils.sendAndMonitorTransaction> {
|
|
224
|
+
if (typeof round === 'number') {
|
|
225
|
+
round = BigInt(round);
|
|
226
|
+
}
|
|
227
|
+
const request = this.buildExecuteRoundRequest(round);
|
|
228
|
+
const response = await txUtils
|
|
229
|
+
.sendAndMonitorTransaction(request, {
|
|
230
|
+
// Gas estimation is way off for this, likely because we are creating the contract/selector to call
|
|
231
|
+
// for the actual slashing dynamically.
|
|
232
|
+
gasLimitBufferPercentage: 50, // +50% gas
|
|
233
|
+
})
|
|
234
|
+
.catch(err => {
|
|
235
|
+
if (err instanceof FormattedViemError && err.message.includes('ProposalAlreadyExecuted')) {
|
|
236
|
+
throw new ProposalAlreadyExecutedError(round);
|
|
237
|
+
}
|
|
238
|
+
throw err;
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
if (response.receipt.status === 'reverted') {
|
|
242
|
+
const args = {
|
|
243
|
+
abi: EmpireSlashingProposerAbi,
|
|
244
|
+
functionName: 'submitRoundWinner' as const,
|
|
245
|
+
args: [round] as const,
|
|
246
|
+
address: this.address.toString(),
|
|
247
|
+
};
|
|
248
|
+
const error = await txUtils.tryGetErrorFromRevertedTx(request.data!, args, undefined, []);
|
|
249
|
+
if (error?.includes('ProposalAlreadyExecuted')) {
|
|
250
|
+
throw new ProposalAlreadyExecutedError(round);
|
|
251
|
+
}
|
|
252
|
+
const errorMessage = `Failed to execute round ${round}, TxHash: ${response.receipt.transactionHash}, Error: ${
|
|
253
|
+
error ?? 'Unknown error'
|
|
254
|
+
}`;
|
|
255
|
+
throw new Error(errorMessage);
|
|
256
|
+
}
|
|
257
|
+
return response;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class BlockTagTooOldError extends Error {
|
|
2
|
+
constructor(blockTag: bigint | number, latestBlock: bigint | number) {
|
|
3
|
+
super(`Block tag ${blockTag} is more than 128 blocks behind the latest block ${latestBlock}`);
|
|
4
|
+
this.name = 'BlockTagTooOldError';
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class NoCommitteeError extends Error {
|
|
9
|
+
constructor() {
|
|
10
|
+
super('The committee does not exist on L1');
|
|
11
|
+
this.name = 'NoCommitteeError';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import { FeeAssetHandlerAbi } from '@aztec/l1-artifacts/FeeAssetHandlerAbi';
|
|
3
|
+
|
|
4
|
+
import { type Hex, encodeFunctionData, getContract } from 'viem';
|
|
5
|
+
|
|
6
|
+
import type { L1TxUtils } from '../l1_tx_utils/index.js';
|
|
7
|
+
import type { ViemClient } from '../types.js';
|
|
8
|
+
|
|
9
|
+
export class FeeAssetHandlerContract {
|
|
10
|
+
public address: EthAddress;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
public readonly client: ViemClient,
|
|
14
|
+
address: Hex | EthAddress,
|
|
15
|
+
) {
|
|
16
|
+
if (address instanceof EthAddress) {
|
|
17
|
+
address = address.toString();
|
|
18
|
+
}
|
|
19
|
+
this.address = EthAddress.fromString(address);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public async getOwner(): Promise<EthAddress> {
|
|
23
|
+
const contract = getContract({
|
|
24
|
+
abi: FeeAssetHandlerAbi,
|
|
25
|
+
address: this.address.toString(),
|
|
26
|
+
client: this.client,
|
|
27
|
+
});
|
|
28
|
+
return EthAddress.fromString(await contract.read.owner());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public getMintAmount() {
|
|
32
|
+
const contract = getContract({
|
|
33
|
+
abi: FeeAssetHandlerAbi,
|
|
34
|
+
address: this.address.toString(),
|
|
35
|
+
client: this.client,
|
|
36
|
+
});
|
|
37
|
+
return contract.read.mintAmount();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public mint(txUtils: L1TxUtils, recipient: Hex | EthAddress) {
|
|
41
|
+
if (recipient instanceof EthAddress) {
|
|
42
|
+
recipient = recipient.toString();
|
|
43
|
+
}
|
|
44
|
+
return txUtils.sendAndMonitorTransaction({
|
|
45
|
+
to: this.address.toString(),
|
|
46
|
+
abi: FeeAssetHandlerAbi,
|
|
47
|
+
data: encodeFunctionData({
|
|
48
|
+
abi: FeeAssetHandlerAbi,
|
|
49
|
+
functionName: 'mint',
|
|
50
|
+
args: [recipient],
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public setMintAmount(txUtils: L1TxUtils, amount: bigint) {
|
|
56
|
+
return txUtils.sendAndMonitorTransaction({
|
|
57
|
+
to: this.address.toString(),
|
|
58
|
+
abi: FeeAssetHandlerAbi,
|
|
59
|
+
data: encodeFunctionData({
|
|
60
|
+
abi: FeeAssetHandlerAbi,
|
|
61
|
+
functionName: 'setMintAmount',
|
|
62
|
+
args: [amount],
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -1,43 +1,57 @@
|
|
|
1
1
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
-
import { TestERC20Abi as FeeJuiceAbi } from '@aztec/l1-artifacts';
|
|
2
|
+
import { TestERC20Abi as FeeJuiceAbi } from '@aztec/l1-artifacts/TestERC20Abi';
|
|
3
3
|
|
|
4
4
|
import { type GetContractReturnType, type Hex, getContract } from 'viem';
|
|
5
5
|
|
|
6
|
-
import type
|
|
6
|
+
import { type ExtendedViemWalletClient, type ViemClient, isExtendedClient } from '../types.js';
|
|
7
7
|
|
|
8
8
|
export class FeeJuiceContract {
|
|
9
|
-
private readonly
|
|
10
|
-
private readonly walletFeeJuice: GetContractReturnType<typeof FeeJuiceAbi, L1Clients['walletClient']> | undefined;
|
|
9
|
+
private readonly feeJuiceContract: GetContractReturnType<typeof FeeJuiceAbi, ViemClient>;
|
|
11
10
|
|
|
12
11
|
constructor(
|
|
13
|
-
address: Hex,
|
|
14
|
-
public readonly
|
|
15
|
-
public readonly walletClient: L1Clients['walletClient'] | undefined,
|
|
12
|
+
address: Hex | EthAddress,
|
|
13
|
+
public readonly client: ViemClient,
|
|
16
14
|
) {
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
if (address instanceof EthAddress) {
|
|
16
|
+
address = address.toString();
|
|
17
|
+
}
|
|
18
|
+
this.feeJuiceContract = getContract({ address, abi: FeeJuiceAbi, client });
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
public get address() {
|
|
22
|
-
return EthAddress.fromString(this.
|
|
22
|
+
return EthAddress.fromString(this.feeJuiceContract.address);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public async getOwner(): Promise<EthAddress> {
|
|
26
|
+
return EthAddress.fromString(await this.feeJuiceContract.read.owner());
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
private assertWalletFeeJuice() {
|
|
26
|
-
if (!this.
|
|
29
|
+
private assertWalletFeeJuice(): GetContractReturnType<typeof FeeJuiceAbi, ExtendedViemWalletClient> {
|
|
30
|
+
if (!isExtendedClient(this.client)) {
|
|
27
31
|
throw new Error('Wallet client is required for this operation');
|
|
28
32
|
}
|
|
29
|
-
return this.
|
|
33
|
+
return this.feeJuiceContract as GetContractReturnType<typeof FeeJuiceAbi, ExtendedViemWalletClient>;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
public async mint(to: Hex, amount: bigint) {
|
|
33
37
|
const walletFeeJuice = this.assertWalletFeeJuice();
|
|
34
38
|
const tx = await walletFeeJuice.write.mint([to, amount]);
|
|
35
|
-
await this.
|
|
39
|
+
const receipt = await this.client.waitForTransactionReceipt({ hash: tx });
|
|
40
|
+
|
|
41
|
+
if (receipt.status === 'success') {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
throw new Error('Mint failed');
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
public async approve(spender: Hex, amount: bigint) {
|
|
39
48
|
const walletFeeJuice = this.assertWalletFeeJuice();
|
|
40
49
|
const tx = await walletFeeJuice.write.approve([spender, amount]);
|
|
41
|
-
await this.
|
|
50
|
+
const receipt = await this.client.waitForTransactionReceipt({ hash: tx });
|
|
51
|
+
|
|
52
|
+
if (receipt.status === 'success') {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
throw new Error('Approve failed');
|
|
42
56
|
}
|
|
43
57
|
}
|