@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.21caa21
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 +16 -2
- package/dest/config.d.ts +111 -17
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +462 -22
- package/dest/constants.d.ts +1 -1
- package/dest/contracts/empire_base.d.ts +24 -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 +66 -0
- package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/empire_slashing_proposer.js +200 -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 +19 -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 +16 -13
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +37 -17
- 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 +26 -0
- package/dest/contracts/inbox.d.ts.map +1 -0
- package/dest/contracts/inbox.js +45 -0
- package/dest/contracts/index.d.ts +9 -3
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +8 -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/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 +204 -40
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +529 -79
- 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 +139 -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_l1_contracts.d.ts +577 -21114
- package/dest/deploy_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_l1_contracts.js +1225 -421
- 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/index.d.ts +7 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +6 -2
- package/dest/l1_artifacts.d.ts +77344 -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 +22 -18
- package/dest/l1_reader.d.ts +2 -2
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +8 -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 +82 -0
- package/dest/l1_tx_utils/constants.d.ts +6 -0
- package/dest/l1_tx_utils/constants.d.ts.map +1 -0
- package/dest/l1_tx_utils/constants.js +14 -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/index.d.ts +10 -0
- package/dest/l1_tx_utils/index.d.ts.map +1 -0
- package/dest/l1_tx_utils/index.js +10 -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_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 +610 -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 +94 -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 +430 -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 +53 -12
- package/dest/test/chain_monitor.d.ts +73 -0
- package/dest/test/chain_monitor.d.ts.map +1 -0
- package/dest/test/chain_monitor.js +215 -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 +558 -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 +87 -0
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
- package/dest/test/rollup_cheat_codes.js +266 -0
- package/dest/test/start_anvil.d.ts +7 -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 +95 -19
- 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 +7 -8
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +3 -1
- package/dest/utils.d.ts +2 -1
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +43 -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 +28 -19
- package/src/account.ts +5 -0
- package/src/client.ts +42 -4
- package/src/config.ts +592 -31
- package/src/contracts/empire_base.ts +77 -7
- package/src/contracts/empire_slashing_proposer.ts +265 -0
- package/src/contracts/errors.ts +13 -0
- package/src/contracts/fee_asset_handler.ts +63 -0
- package/src/contracts/fee_juice.ts +29 -15
- package/src/contracts/governance.ts +80 -77
- package/src/contracts/governance_proposer.ts +66 -24
- package/src/contracts/gse.ts +88 -0
- package/src/contracts/inbox.ts +63 -0
- package/src/contracts/index.ts +8 -2
- package/src/contracts/multicall.ts +155 -0
- package/src/contracts/registry.ts +51 -26
- package/src/contracts/rollup.ts +596 -74
- package/src/contracts/slasher_contract.ts +89 -0
- package/src/contracts/tally_slashing_proposer.ts +316 -0
- package/src/contracts/utils.ts +14 -0
- package/src/deploy_l1_contracts.ts +1459 -538
- package/src/eth-signer/eth-signer.ts +25 -0
- package/src/eth-signer/index.ts +1 -0
- package/src/index.ts +6 -2
- package/src/l1_artifacts.ts +254 -0
- package/src/l1_contract_addresses.ts +32 -19
- package/src/l1_reader.ts +9 -9
- package/src/l1_tx_utils/README.md +177 -0
- package/src/l1_tx_utils/config.ts +143 -0
- package/src/l1_tx_utils/constants.ts +18 -0
- package/src/l1_tx_utils/factory.ts +64 -0
- package/src/l1_tx_utils/index.ts +12 -0
- package/src/l1_tx_utils/interfaces.ts +86 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +718 -0
- package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +77 -0
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +558 -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 +73 -15
- package/src/test/chain_monitor.ts +243 -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 +307 -0
- package/src/test/start_anvil.ts +22 -5
- package/src/test/tx_delayer.ts +127 -26
- package/src/test/upgrade_utils.ts +30 -21
- package/src/types.ts +10 -8
- package/src/utils.ts +49 -90
- 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/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/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/eth_cheat_codes.ts +0 -314
- package/src/l1_tx_utils.ts +0 -847
- package/src/l1_tx_utils_with_blobs.ts +0 -86
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
2
|
import type { Logger } from '@aztec/foundation/log';
|
|
3
3
|
import { sleep } from '@aztec/foundation/sleep';
|
|
4
|
-
import { GovernanceAbi } from '@aztec/l1-artifacts';
|
|
4
|
+
import { GovernanceAbi } from '@aztec/l1-artifacts/GovernanceAbi';
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
type EncodeFunctionDataParameters,
|
|
8
8
|
type GetContractReturnType,
|
|
9
9
|
type Hex,
|
|
10
|
+
type Log,
|
|
10
11
|
encodeFunctionData,
|
|
11
12
|
getContract,
|
|
13
|
+
parseEventLogs,
|
|
12
14
|
} from 'viem';
|
|
13
15
|
|
|
14
16
|
import type { L1ContractAddresses } from '../l1_contract_addresses.js';
|
|
15
|
-
import {
|
|
16
|
-
import type
|
|
17
|
-
import { GovernanceProposerContract } from './governance_proposer.js';
|
|
17
|
+
import { createL1TxUtilsFromViemWallet } from '../l1_tx_utils/index.js';
|
|
18
|
+
import { type ExtendedViemWalletClient, type ViemClient, isExtendedClient } from '../types.js';
|
|
18
19
|
|
|
19
20
|
export type L1GovernanceContractAddresses = Pick<
|
|
20
21
|
L1ContractAddresses,
|
|
@@ -33,87 +34,54 @@ export enum ProposalState {
|
|
|
33
34
|
Expired,
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
export
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
export function extractProposalIdFromLogs(logs: Log[]): bigint {
|
|
38
|
+
const parsedLogs = parseEventLogs({
|
|
39
|
+
abi: GovernanceAbi,
|
|
40
|
+
logs: logs,
|
|
41
|
+
eventName: 'Proposed',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (parsedLogs.length === 0) {
|
|
45
|
+
throw new Error('Proposal log not found');
|
|
46
|
+
}
|
|
47
|
+
return parsedLogs[0].args.proposalId;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class ReadOnlyGovernanceContract {
|
|
51
|
+
protected readonly governanceContract: GetContractReturnType<typeof GovernanceAbi, ViemClient>;
|
|
39
52
|
|
|
40
53
|
constructor(
|
|
41
54
|
address: Hex,
|
|
42
|
-
public readonly
|
|
43
|
-
public readonly walletClient: ViemWalletClient | undefined,
|
|
55
|
+
public readonly client: ViemClient,
|
|
44
56
|
) {
|
|
45
|
-
this.
|
|
46
|
-
this.walletGovernance = walletClient
|
|
47
|
-
? getContract({ address, abi: GovernanceAbi, client: walletClient })
|
|
48
|
-
: undefined;
|
|
57
|
+
this.governanceContract = getContract({ address, abi: GovernanceAbi, client: client });
|
|
49
58
|
}
|
|
50
59
|
|
|
51
60
|
public get address() {
|
|
52
|
-
return EthAddress.fromString(this.
|
|
61
|
+
return EthAddress.fromString(this.governanceContract.address);
|
|
53
62
|
}
|
|
54
63
|
|
|
55
|
-
public async
|
|
56
|
-
|
|
57
|
-
return new GovernanceProposerContract(this.publicClient, governanceProposerAddress.toString());
|
|
64
|
+
public async getGovernanceProposerAddress() {
|
|
65
|
+
return EthAddress.fromString(await this.governanceContract.read.governanceProposer());
|
|
58
66
|
}
|
|
59
67
|
|
|
60
|
-
public
|
|
61
|
-
|
|
62
|
-
const [rollupAddress, registryAddress] = await Promise.all([
|
|
63
|
-
governanceProposer.getRollupAddress(),
|
|
64
|
-
governanceProposer.getRegistryAddress(),
|
|
65
|
-
]);
|
|
66
|
-
return {
|
|
67
|
-
governanceAddress: this.address,
|
|
68
|
-
rollupAddress,
|
|
69
|
-
registryAddress,
|
|
70
|
-
governanceProposerAddress: governanceProposer.address,
|
|
71
|
-
};
|
|
68
|
+
public getConfiguration() {
|
|
69
|
+
return this.governanceContract.read.getConfiguration();
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
public getProposal(proposalId: bigint) {
|
|
75
|
-
return this.
|
|
73
|
+
return this.governanceContract.read.getProposal([proposalId]);
|
|
76
74
|
}
|
|
77
75
|
|
|
78
76
|
public async getProposalState(proposalId: bigint): Promise<ProposalState> {
|
|
79
|
-
const state = await this.
|
|
77
|
+
const state = await this.governanceContract.read.getProposalState([proposalId]);
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
80
79
|
if (state < 0 || state > ProposalState.Expired) {
|
|
81
80
|
throw new Error(`Invalid proposal state: ${state}`);
|
|
82
81
|
}
|
|
83
82
|
return state as ProposalState;
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
private assertWalletGovernance(): NonNullable<typeof this.walletGovernance> {
|
|
87
|
-
if (!this.walletGovernance) {
|
|
88
|
-
throw new Error('Wallet client is required for this operation');
|
|
89
|
-
}
|
|
90
|
-
return this.walletGovernance;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public async deposit(onBehalfOf: Hex, amount: bigint) {
|
|
94
|
-
const walletGovernance = this.assertWalletGovernance();
|
|
95
|
-
const depositTx = await walletGovernance.write.deposit([onBehalfOf, amount]);
|
|
96
|
-
await this.publicClient.waitForTransactionReceipt({ hash: depositTx });
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
public async proposeWithLock({
|
|
100
|
-
payloadAddress,
|
|
101
|
-
withdrawAddress,
|
|
102
|
-
}: {
|
|
103
|
-
payloadAddress: Hex;
|
|
104
|
-
withdrawAddress: Hex;
|
|
105
|
-
}): Promise<number> {
|
|
106
|
-
const walletGovernance = this.assertWalletGovernance();
|
|
107
|
-
const proposeTx = await walletGovernance.write.proposeWithLock([payloadAddress, withdrawAddress]);
|
|
108
|
-
const receipt = await this.publicClient.waitForTransactionReceipt({ hash: proposeTx });
|
|
109
|
-
if (receipt.status !== 'success') {
|
|
110
|
-
throw new Error(`Proposal failed: ${receipt.status}`);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const proposalId = Number(receipt.logs[1].topics[1]);
|
|
114
|
-
return proposalId;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
85
|
public async awaitProposalActive({ proposalId, logger }: { proposalId: bigint; logger: Logger }) {
|
|
118
86
|
const state = await this.getProposalState(proposalId);
|
|
119
87
|
if (state === ProposalState.Active) {
|
|
@@ -123,7 +91,7 @@ export class GovernanceContract {
|
|
|
123
91
|
} else {
|
|
124
92
|
const proposal = await this.getProposal(proposalId);
|
|
125
93
|
const startOfActive = proposal.creation + proposal.config.votingDelay;
|
|
126
|
-
const block = await this.
|
|
94
|
+
const block = await this.client.getBlock();
|
|
127
95
|
// Add 12 seconds to the time to make sure we don't vote too early
|
|
128
96
|
const secondsToActive = Number(startOfActive - block.timestamp) + 12;
|
|
129
97
|
const now = new Date();
|
|
@@ -151,7 +119,7 @@ export class GovernanceContract {
|
|
|
151
119
|
proposal.config.votingDelay +
|
|
152
120
|
proposal.config.votingDuration +
|
|
153
121
|
proposal.config.executionDelay;
|
|
154
|
-
const block = await this.
|
|
122
|
+
const block = await this.client.getBlock();
|
|
155
123
|
const secondsToExecutable = Number(startOfExecutable - block.timestamp) + 12;
|
|
156
124
|
const now = new Date();
|
|
157
125
|
logger.info(`
|
|
@@ -162,11 +130,48 @@ export class GovernanceContract {
|
|
|
162
130
|
await sleep(secondsToExecutable * 1000);
|
|
163
131
|
}
|
|
164
132
|
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export class GovernanceContract extends ReadOnlyGovernanceContract {
|
|
136
|
+
protected override readonly governanceContract: GetContractReturnType<typeof GovernanceAbi, ExtendedViemWalletClient>;
|
|
137
|
+
|
|
138
|
+
constructor(
|
|
139
|
+
address: Hex | EthAddress,
|
|
140
|
+
public override readonly client: ExtendedViemWalletClient,
|
|
141
|
+
) {
|
|
142
|
+
if (address instanceof EthAddress) {
|
|
143
|
+
address = address.toString();
|
|
144
|
+
}
|
|
145
|
+
super(address, client);
|
|
146
|
+
if (!isExtendedClient(client)) {
|
|
147
|
+
throw new Error('GovernanceContract has to be instantiated with a wallet client.');
|
|
148
|
+
}
|
|
149
|
+
this.governanceContract = getContract({ address, abi: GovernanceAbi, client });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public async deposit(onBehalfOf: Hex, amount: bigint) {
|
|
153
|
+
const depositTx = await this.governanceContract.write.deposit([onBehalfOf, amount]);
|
|
154
|
+
await this.client.waitForTransactionReceipt({ hash: depositTx });
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public async proposeWithLock({
|
|
158
|
+
payloadAddress,
|
|
159
|
+
withdrawAddress,
|
|
160
|
+
}: {
|
|
161
|
+
payloadAddress: Hex;
|
|
162
|
+
withdrawAddress: Hex;
|
|
163
|
+
}): Promise<bigint> {
|
|
164
|
+
const proposeTx = await this.governanceContract.write.proposeWithLock([payloadAddress, withdrawAddress]);
|
|
165
|
+
const receipt = await this.client.waitForTransactionReceipt({ hash: proposeTx });
|
|
166
|
+
if (receipt.status !== 'success') {
|
|
167
|
+
throw new Error(`Proposal failed: ${receipt.status}`);
|
|
168
|
+
}
|
|
169
|
+
return extractProposalIdFromLogs(receipt.logs);
|
|
170
|
+
}
|
|
165
171
|
|
|
166
172
|
public async getPower(): Promise<bigint> {
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
return walletGovernance.read.powerAt([this.walletClient!.account.address, now.timestamp]);
|
|
173
|
+
const now = await this.client.getBlock();
|
|
174
|
+
return this.governanceContract.read.powerAt([this.client.account.address, now.timestamp]);
|
|
170
175
|
}
|
|
171
176
|
|
|
172
177
|
public async vote({
|
|
@@ -182,8 +187,7 @@ export class GovernanceContract {
|
|
|
182
187
|
retries: number;
|
|
183
188
|
logger: Logger;
|
|
184
189
|
}) {
|
|
185
|
-
const
|
|
186
|
-
const l1TxUtils = new L1TxUtils(this.publicClient, this.walletClient!, logger);
|
|
190
|
+
const l1TxUtils = createL1TxUtilsFromViemWallet(this.client, { logger });
|
|
187
191
|
const retryDelaySeconds = 12;
|
|
188
192
|
|
|
189
193
|
voteAmount = voteAmount ?? (await this.getPower());
|
|
@@ -199,7 +203,7 @@ export class GovernanceContract {
|
|
|
199
203
|
const encodedVoteData = encodeFunctionData(voteFunctionData);
|
|
200
204
|
|
|
201
205
|
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
202
|
-
to:
|
|
206
|
+
to: this.governanceContract.address,
|
|
203
207
|
data: encodedVoteData,
|
|
204
208
|
});
|
|
205
209
|
|
|
@@ -209,7 +213,7 @@ export class GovernanceContract {
|
|
|
209
213
|
} else {
|
|
210
214
|
const args = {
|
|
211
215
|
...voteFunctionData,
|
|
212
|
-
address:
|
|
216
|
+
address: this.governanceContract.address,
|
|
213
217
|
};
|
|
214
218
|
const errorMsg = await l1TxUtils.tryGetErrorFromRevertedTx(encodedVoteData, args, undefined, []);
|
|
215
219
|
logger.error(`Error voting on proposal ${proposalId}: ${errorMsg}`);
|
|
@@ -226,9 +230,9 @@ export class GovernanceContract {
|
|
|
226
230
|
}
|
|
227
231
|
logger.info(`Voted [${inFavor ? 'yea' : 'nay'}] on proposal [${proposalId}]`);
|
|
228
232
|
const proposal = await this.getProposal(proposalId);
|
|
229
|
-
logger.info(`Proposal [${proposalId}] has state [${proposal.
|
|
233
|
+
logger.info(`Proposal [${proposalId}] has cached state [${proposal.cachedState}]`);
|
|
230
234
|
logger.info(`Proposal [${proposalId}] has summedBallot yea [${proposal.summedBallot.yea}]`);
|
|
231
|
-
logger.info(`Proposal [${proposalId}] has summedBallot
|
|
235
|
+
logger.info(`Proposal [${proposalId}] has summedBallot nay [${proposal.summedBallot.nay}]`);
|
|
232
236
|
}
|
|
233
237
|
|
|
234
238
|
public async executeProposal({
|
|
@@ -240,8 +244,7 @@ export class GovernanceContract {
|
|
|
240
244
|
retries: number;
|
|
241
245
|
logger: Logger;
|
|
242
246
|
}) {
|
|
243
|
-
const
|
|
244
|
-
const l1TxUtils = new L1TxUtils(this.publicClient, this.walletClient!, logger);
|
|
247
|
+
const l1TxUtils = createL1TxUtilsFromViemWallet(this.client, { logger });
|
|
245
248
|
const retryDelaySeconds = 12;
|
|
246
249
|
let success = false;
|
|
247
250
|
for (let i = 0; i < retries; i++) {
|
|
@@ -254,7 +257,7 @@ export class GovernanceContract {
|
|
|
254
257
|
const encodedExecuteData = encodeFunctionData(executeFunctionData);
|
|
255
258
|
|
|
256
259
|
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
257
|
-
to:
|
|
260
|
+
to: this.governanceContract.address,
|
|
258
261
|
data: encodedExecuteData,
|
|
259
262
|
});
|
|
260
263
|
|
|
@@ -264,7 +267,7 @@ export class GovernanceContract {
|
|
|
264
267
|
} else {
|
|
265
268
|
const args = {
|
|
266
269
|
...executeFunctionData,
|
|
267
|
-
address:
|
|
270
|
+
address: this.governanceContract.address,
|
|
268
271
|
};
|
|
269
272
|
const errorMsg = await l1TxUtils.tryGetErrorFromRevertedTx(encodedExecuteData, args, undefined, []);
|
|
270
273
|
logger.error(`Error executing proposal ${proposalId}: ${errorMsg}`);
|
|
@@ -1,17 +1,32 @@
|
|
|
1
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { memoize } from '@aztec/foundation/decorators';
|
|
2
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
-
import { GovernanceProposerAbi } from '@aztec/l1-artifacts';
|
|
4
|
+
import { GovernanceProposerAbi } from '@aztec/l1-artifacts/GovernanceProposerAbi';
|
|
4
5
|
|
|
5
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
type GetContractReturnType,
|
|
8
|
+
type Hex,
|
|
9
|
+
type TransactionReceipt,
|
|
10
|
+
type TypedDataDefinition,
|
|
11
|
+
encodeFunctionData,
|
|
12
|
+
getContract,
|
|
13
|
+
} from 'viem';
|
|
6
14
|
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import { type IEmpireBase,
|
|
15
|
+
import type { L1TxRequest, L1TxUtils } from '../l1_tx_utils/index.js';
|
|
16
|
+
import type { ViemClient } from '../types.js';
|
|
17
|
+
import { type IEmpireBase, encodeSignal, encodeSignalWithSignature, signSignalWithSig } from './empire_base.js';
|
|
18
|
+
import { extractProposalIdFromLogs } from './governance.js';
|
|
10
19
|
|
|
11
20
|
export class GovernanceProposerContract implements IEmpireBase {
|
|
12
|
-
private readonly proposer: GetContractReturnType<typeof GovernanceProposerAbi,
|
|
21
|
+
private readonly proposer: GetContractReturnType<typeof GovernanceProposerAbi, ViemClient>;
|
|
13
22
|
|
|
14
|
-
constructor(
|
|
23
|
+
constructor(
|
|
24
|
+
public readonly client: ViemClient,
|
|
25
|
+
address: Hex | EthAddress,
|
|
26
|
+
) {
|
|
27
|
+
if (address instanceof EthAddress) {
|
|
28
|
+
address = address.toString();
|
|
29
|
+
}
|
|
15
30
|
this.proposer = getContract({ address, abi: GovernanceProposerAbi, client });
|
|
16
31
|
}
|
|
17
32
|
|
|
@@ -29,54 +44,81 @@ export class GovernanceProposerContract implements IEmpireBase {
|
|
|
29
44
|
}
|
|
30
45
|
|
|
31
46
|
public getQuorumSize(): Promise<bigint> {
|
|
32
|
-
return this.proposer.read.
|
|
47
|
+
return this.proposer.read.QUORUM_SIZE();
|
|
33
48
|
}
|
|
34
49
|
|
|
35
50
|
public getRoundSize(): Promise<bigint> {
|
|
36
|
-
return this.proposer.read.
|
|
51
|
+
return this.proposer.read.ROUND_SIZE();
|
|
37
52
|
}
|
|
38
53
|
|
|
39
|
-
public
|
|
40
|
-
return this.proposer.read.
|
|
54
|
+
public getInstance() {
|
|
55
|
+
return this.proposer.read.getInstance();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public computeRound(slot: SlotNumber): Promise<bigint> {
|
|
59
|
+
return this.proposer.read.computeRound([BigInt(slot)]);
|
|
41
60
|
}
|
|
42
61
|
|
|
43
62
|
public async getRoundInfo(
|
|
44
63
|
rollupAddress: Hex,
|
|
45
64
|
round: bigint,
|
|
46
|
-
): Promise<{
|
|
47
|
-
const
|
|
65
|
+
): Promise<{ lastSignalSlot: SlotNumber; payloadWithMostSignals: Hex; executed: boolean }> {
|
|
66
|
+
const result = await this.proposer.read.getRoundData([rollupAddress, round]);
|
|
48
67
|
return {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
executed:
|
|
68
|
+
lastSignalSlot: SlotNumber.fromBigInt(result.lastSignalSlot),
|
|
69
|
+
payloadWithMostSignals: result.payloadWithMostSignals,
|
|
70
|
+
executed: result.executed,
|
|
52
71
|
};
|
|
53
72
|
}
|
|
54
73
|
|
|
55
|
-
public
|
|
56
|
-
return this.proposer.read.
|
|
74
|
+
public getPayloadSignals(rollupAddress: Hex, round: bigint, payload: Hex): Promise<bigint> {
|
|
75
|
+
return this.proposer.read.signalCount([rollupAddress, round, payload]);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public createSignalRequest(payload: Hex): L1TxRequest {
|
|
79
|
+
return {
|
|
80
|
+
to: this.address.toString(),
|
|
81
|
+
data: encodeSignal(payload),
|
|
82
|
+
};
|
|
57
83
|
}
|
|
58
84
|
|
|
59
|
-
public
|
|
85
|
+
public async createSignalRequestWithSignature(
|
|
86
|
+
payload: Hex,
|
|
87
|
+
slot: SlotNumber,
|
|
88
|
+
chainId: number,
|
|
89
|
+
signerAddress: Hex,
|
|
90
|
+
signer: (msg: TypedDataDefinition) => Promise<Hex>,
|
|
91
|
+
): Promise<L1TxRequest> {
|
|
92
|
+
const signature = await signSignalWithSig(
|
|
93
|
+
signer,
|
|
94
|
+
payload,
|
|
95
|
+
slot,
|
|
96
|
+
await this.getInstance(),
|
|
97
|
+
this.address.toString(),
|
|
98
|
+
chainId,
|
|
99
|
+
);
|
|
60
100
|
return {
|
|
61
101
|
to: this.address.toString(),
|
|
62
|
-
data:
|
|
102
|
+
data: encodeSignalWithSignature(payload, signature),
|
|
63
103
|
};
|
|
64
104
|
}
|
|
65
105
|
|
|
66
|
-
public
|
|
106
|
+
public async submitRoundWinner(
|
|
67
107
|
round: bigint,
|
|
68
108
|
l1TxUtils: L1TxUtils,
|
|
69
109
|
): Promise<{
|
|
70
110
|
receipt: TransactionReceipt;
|
|
71
|
-
|
|
111
|
+
proposalId: bigint;
|
|
72
112
|
}> {
|
|
73
|
-
|
|
113
|
+
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
74
114
|
to: this.address.toString(),
|
|
75
115
|
data: encodeFunctionData({
|
|
76
116
|
abi: this.proposer.abi,
|
|
77
|
-
functionName: '
|
|
117
|
+
functionName: 'submitRoundWinner',
|
|
78
118
|
args: [round],
|
|
79
119
|
}),
|
|
80
120
|
});
|
|
121
|
+
const proposalId = extractProposalIdFromLogs(receipt.logs);
|
|
122
|
+
return { receipt, proposalId };
|
|
81
123
|
}
|
|
82
124
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import { GSEAbi } from '@aztec/l1-artifacts/GSEAbi';
|
|
3
|
+
|
|
4
|
+
import type { ProjPointType } from '@noble/curves/abstract/weierstrass';
|
|
5
|
+
import { bn254 } from '@noble/curves/bn254';
|
|
6
|
+
import { type GetContractReturnType, type Hex, getContract } from 'viem';
|
|
7
|
+
|
|
8
|
+
import type { ViemClient } from '../types.js';
|
|
9
|
+
|
|
10
|
+
export type RegistrationTuple = {
|
|
11
|
+
publicKeyInG1: {
|
|
12
|
+
x: bigint;
|
|
13
|
+
y: bigint;
|
|
14
|
+
};
|
|
15
|
+
publicKeyInG2: {
|
|
16
|
+
x0: bigint;
|
|
17
|
+
x1: bigint;
|
|
18
|
+
y0: bigint;
|
|
19
|
+
y1: bigint;
|
|
20
|
+
};
|
|
21
|
+
proofOfPossession: {
|
|
22
|
+
x: bigint;
|
|
23
|
+
y: bigint;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export class GSEContract {
|
|
28
|
+
public address: EthAddress;
|
|
29
|
+
private readonly gse: GetContractReturnType<typeof GSEAbi, ViemClient>;
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
public readonly client: ViemClient,
|
|
33
|
+
address: Hex | EthAddress,
|
|
34
|
+
) {
|
|
35
|
+
if (address instanceof EthAddress) {
|
|
36
|
+
address = address.toString();
|
|
37
|
+
}
|
|
38
|
+
this.address = EthAddress.fromString(address);
|
|
39
|
+
this.gse = getContract({ address, abi: GSEAbi, client });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public async getOwner(): Promise<EthAddress> {
|
|
43
|
+
return EthAddress.fromString(await this.gse.read.owner());
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public async getGovernance(): Promise<EthAddress> {
|
|
47
|
+
return EthAddress.fromString(await this.gse.read.getGovernance());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
getAttestersFromIndicesAtTime(instance: Hex | EthAddress, ts: bigint, indices: bigint[]) {
|
|
51
|
+
if (instance instanceof EthAddress) {
|
|
52
|
+
instance = instance.toString();
|
|
53
|
+
}
|
|
54
|
+
return this.gse.read.getAttestersFromIndicesAtTime([instance, ts, indices]);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public async getRegistrationDigest(publicKey: ProjPointType<bigint>): Promise<ProjPointType<bigint>> {
|
|
58
|
+
const affinePublicKey = publicKey.toAffine();
|
|
59
|
+
const g1PointDigest = await this.gse.read.getRegistrationDigest([{ x: affinePublicKey.x, y: affinePublicKey.y }]);
|
|
60
|
+
return bn254.G1.ProjectivePoint.fromAffine(g1PointDigest);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public async makeRegistrationTuple(privateKey: bigint): Promise<RegistrationTuple> {
|
|
64
|
+
const publicKeyG1 = bn254.G1.ProjectivePoint.BASE.multiply(privateKey);
|
|
65
|
+
const digest = await this.getRegistrationDigest(publicKeyG1);
|
|
66
|
+
const signature = digest.multiply(privateKey);
|
|
67
|
+
const publicKeyG2 = bn254.G2.ProjectivePoint.BASE.multiply(privateKey);
|
|
68
|
+
const publicKeyG1Affine = publicKeyG1.toAffine();
|
|
69
|
+
const signatureAffine = signature.toAffine();
|
|
70
|
+
const publicKeyG2Affine = publicKeyG2.toAffine();
|
|
71
|
+
return {
|
|
72
|
+
publicKeyInG1: {
|
|
73
|
+
x: publicKeyG1Affine.x,
|
|
74
|
+
y: publicKeyG1Affine.y,
|
|
75
|
+
},
|
|
76
|
+
publicKeyInG2: {
|
|
77
|
+
x0: publicKeyG2Affine.x.c0,
|
|
78
|
+
x1: publicKeyG2Affine.x.c1,
|
|
79
|
+
y0: publicKeyG2Affine.y.c0,
|
|
80
|
+
y1: publicKeyG2Affine.y.c1,
|
|
81
|
+
},
|
|
82
|
+
proofOfPossession: {
|
|
83
|
+
x: signatureAffine.x,
|
|
84
|
+
y: signatureAffine.y,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Buffer16 } from '@aztec/foundation/buffer';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import { InboxAbi } from '@aztec/l1-artifacts/InboxAbi';
|
|
4
|
+
|
|
5
|
+
import { type BlockTag, type GetContractReturnType, type Hex, getContract } from 'viem';
|
|
6
|
+
|
|
7
|
+
import { getPublicClient } from '../client.js';
|
|
8
|
+
import type { DeployL1ContractsReturnType } from '../deploy_l1_contracts.js';
|
|
9
|
+
import type { L1ReaderConfig } from '../l1_reader.js';
|
|
10
|
+
import type { ViemClient } from '../types.js';
|
|
11
|
+
import { checkBlockTag } from './utils.js';
|
|
12
|
+
|
|
13
|
+
export class InboxContract {
|
|
14
|
+
private readonly inbox: GetContractReturnType<typeof InboxAbi, ViemClient>;
|
|
15
|
+
|
|
16
|
+
static getFromL1ContractsValues(deployL1ContractsValues: DeployL1ContractsReturnType) {
|
|
17
|
+
const {
|
|
18
|
+
l1Client,
|
|
19
|
+
l1ContractAddresses: { inboxAddress },
|
|
20
|
+
} = deployL1ContractsValues;
|
|
21
|
+
return new InboxContract(l1Client, inboxAddress.toString());
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static getFromConfig(config: L1ReaderConfig) {
|
|
25
|
+
const client = getPublicClient(config);
|
|
26
|
+
const address = config.l1Contracts.inboxAddress.toString();
|
|
27
|
+
return new InboxContract(client, address);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
constructor(
|
|
31
|
+
public readonly client: ViemClient,
|
|
32
|
+
address: Hex | EthAddress,
|
|
33
|
+
) {
|
|
34
|
+
if (address instanceof EthAddress) {
|
|
35
|
+
address = address.toString();
|
|
36
|
+
}
|
|
37
|
+
this.inbox = getContract({ address, abi: InboxAbi, client });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public get address() {
|
|
41
|
+
return this.inbox.address;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public getContract(): GetContractReturnType<typeof InboxAbi, ViemClient> {
|
|
45
|
+
return this.inbox;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public async getState(opts: { blockTag?: BlockTag; blockNumber?: bigint } = {}): Promise<InboxContractState> {
|
|
49
|
+
await checkBlockTag(opts.blockNumber, this.client);
|
|
50
|
+
const state = await this.inbox.read.getState(opts);
|
|
51
|
+
return {
|
|
52
|
+
totalMessagesInserted: state.totalMessagesInserted,
|
|
53
|
+
messagesRollingHash: Buffer16.fromString(state.rollingHash),
|
|
54
|
+
treeInProgress: state.inProgress,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type InboxContractState = {
|
|
60
|
+
totalMessagesInserted: bigint;
|
|
61
|
+
messagesRollingHash: Buffer16;
|
|
62
|
+
treeInProgress: bigint;
|
|
63
|
+
};
|
package/src/contracts/index.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
export * from './empire_base.js';
|
|
2
|
+
export * from './errors.js';
|
|
3
|
+
export * from './fee_asset_handler.js';
|
|
2
4
|
export * from './fee_juice.js';
|
|
3
|
-
export * from './forwarder.js';
|
|
4
5
|
export * from './governance.js';
|
|
5
6
|
export * from './governance_proposer.js';
|
|
7
|
+
export * from './gse.js';
|
|
8
|
+
export * from './inbox.js';
|
|
9
|
+
export * from './multicall.js';
|
|
6
10
|
export * from './registry.js';
|
|
7
11
|
export * from './rollup.js';
|
|
8
|
-
export * from './
|
|
12
|
+
export * from './empire_slashing_proposer.js';
|
|
13
|
+
export * from './tally_slashing_proposer.js';
|
|
14
|
+
export * from './slasher_contract.js';
|