@aztec/ethereum 0.0.0-test.0 → 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.
Files changed (232) hide show
  1. package/dest/account.d.ts +2 -0
  2. package/dest/account.d.ts.map +1 -0
  3. package/dest/account.js +4 -0
  4. package/dest/chain.d.ts +1 -1
  5. package/dest/client.d.ts +6 -4
  6. package/dest/client.d.ts.map +1 -1
  7. package/dest/client.js +16 -2
  8. package/dest/config.d.ts +111 -17
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +462 -22
  11. package/dest/constants.d.ts +1 -1
  12. package/dest/contracts/empire_base.d.ts +24 -8
  13. package/dest/contracts/empire_base.d.ts.map +1 -1
  14. package/dest/contracts/empire_base.js +75 -2
  15. package/dest/contracts/empire_slashing_proposer.d.ts +66 -0
  16. package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -0
  17. package/dest/contracts/empire_slashing_proposer.js +200 -0
  18. package/dest/contracts/errors.d.ts +7 -0
  19. package/dest/contracts/errors.d.ts.map +1 -0
  20. package/dest/contracts/errors.js +12 -0
  21. package/dest/contracts/fee_asset_handler.d.ts +19 -0
  22. package/dest/contracts/fee_asset_handler.d.ts.map +1 -0
  23. package/dest/contracts/fee_asset_handler.js +57 -0
  24. package/dest/contracts/fee_juice.d.ts +6 -7
  25. package/dest/contracts/fee_juice.d.ts.map +1 -1
  26. package/dest/contracts/fee_juice.js +27 -20
  27. package/dest/contracts/governance.d.ts +43 -32
  28. package/dest/contracts/governance.d.ts.map +1 -1
  29. package/dest/contracts/governance.js +87 -84
  30. package/dest/contracts/governance_proposer.d.ts +16 -13
  31. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  32. package/dest/contracts/governance_proposer.js +37 -17
  33. package/dest/contracts/gse.d.ts +32 -0
  34. package/dest/contracts/gse.d.ts.map +1 -0
  35. package/dest/contracts/gse.js +72 -0
  36. package/dest/contracts/inbox.d.ts +26 -0
  37. package/dest/contracts/inbox.d.ts.map +1 -0
  38. package/dest/contracts/inbox.js +45 -0
  39. package/dest/contracts/index.d.ts +9 -3
  40. package/dest/contracts/index.d.ts.map +1 -1
  41. package/dest/contracts/index.js +8 -2
  42. package/dest/contracts/multicall.d.ts +21 -0
  43. package/dest/contracts/multicall.d.ts.map +1 -0
  44. package/dest/contracts/multicall.js +156 -0
  45. package/dest/contracts/registry.d.ts +10 -5
  46. package/dest/contracts/registry.d.ts.map +1 -1
  47. package/dest/contracts/registry.js +44 -16
  48. package/dest/contracts/rollup.d.ts +204 -40
  49. package/dest/contracts/rollup.d.ts.map +1 -1
  50. package/dest/contracts/rollup.js +529 -79
  51. package/dest/contracts/slasher_contract.d.ts +44 -0
  52. package/dest/contracts/slasher_contract.d.ts.map +1 -0
  53. package/dest/contracts/slasher_contract.js +75 -0
  54. package/dest/contracts/tally_slashing_proposer.d.ts +139 -0
  55. package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -0
  56. package/dest/contracts/tally_slashing_proposer.js +313 -0
  57. package/dest/contracts/utils.d.ts +3 -0
  58. package/dest/contracts/utils.d.ts.map +1 -0
  59. package/dest/contracts/utils.js +11 -0
  60. package/dest/deploy_l1_contracts.d.ts +577 -21114
  61. package/dest/deploy_l1_contracts.d.ts.map +1 -1
  62. package/dest/deploy_l1_contracts.js +1225 -421
  63. package/dest/eth-signer/eth-signer.d.ts +21 -0
  64. package/dest/eth-signer/eth-signer.d.ts.map +1 -0
  65. package/dest/eth-signer/eth-signer.js +5 -0
  66. package/dest/eth-signer/index.d.ts +2 -0
  67. package/dest/eth-signer/index.d.ts.map +1 -0
  68. package/dest/eth-signer/index.js +1 -0
  69. package/dest/index.d.ts +7 -3
  70. package/dest/index.d.ts.map +1 -1
  71. package/dest/index.js +6 -2
  72. package/dest/l1_artifacts.d.ts +77344 -0
  73. package/dest/l1_artifacts.d.ts.map +1 -0
  74. package/dest/l1_artifacts.js +166 -0
  75. package/dest/l1_contract_addresses.d.ts +24 -4
  76. package/dest/l1_contract_addresses.d.ts.map +1 -1
  77. package/dest/l1_contract_addresses.js +22 -18
  78. package/dest/l1_reader.d.ts +2 -2
  79. package/dest/l1_reader.d.ts.map +1 -1
  80. package/dest/l1_reader.js +8 -8
  81. package/dest/l1_tx_utils/config.d.ts +59 -0
  82. package/dest/l1_tx_utils/config.d.ts.map +1 -0
  83. package/dest/l1_tx_utils/config.js +82 -0
  84. package/dest/l1_tx_utils/constants.d.ts +6 -0
  85. package/dest/l1_tx_utils/constants.d.ts.map +1 -0
  86. package/dest/l1_tx_utils/constants.js +14 -0
  87. package/dest/l1_tx_utils/factory.d.ts +24 -0
  88. package/dest/l1_tx_utils/factory.d.ts.map +1 -0
  89. package/dest/l1_tx_utils/factory.js +12 -0
  90. package/dest/l1_tx_utils/index.d.ts +10 -0
  91. package/dest/l1_tx_utils/index.d.ts.map +1 -0
  92. package/dest/l1_tx_utils/index.js +10 -0
  93. package/dest/l1_tx_utils/interfaces.d.ts +76 -0
  94. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
  95. package/dest/l1_tx_utils/interfaces.js +4 -0
  96. package/dest/l1_tx_utils/l1_tx_utils.d.ts +94 -0
  97. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
  98. package/dest/l1_tx_utils/l1_tx_utils.js +610 -0
  99. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +26 -0
  100. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +1 -0
  101. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +26 -0
  102. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +94 -0
  103. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
  104. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +430 -0
  105. package/dest/l1_tx_utils/signer.d.ts +4 -0
  106. package/dest/l1_tx_utils/signer.d.ts.map +1 -0
  107. package/dest/l1_tx_utils/signer.js +16 -0
  108. package/dest/l1_tx_utils/types.d.ts +67 -0
  109. package/dest/l1_tx_utils/types.d.ts.map +1 -0
  110. package/dest/l1_tx_utils/types.js +26 -0
  111. package/dest/l1_tx_utils/utils.d.ts +4 -0
  112. package/dest/l1_tx_utils/utils.d.ts.map +1 -0
  113. package/dest/l1_tx_utils/utils.js +14 -0
  114. package/dest/l1_types.d.ts +6 -0
  115. package/dest/l1_types.d.ts.map +1 -0
  116. package/dest/l1_types.js +1 -0
  117. package/dest/publisher_manager.d.ts +15 -0
  118. package/dest/publisher_manager.d.ts.map +1 -0
  119. package/dest/publisher_manager.js +88 -0
  120. package/dest/queries.d.ts +4 -2
  121. package/dest/queries.d.ts.map +1 -1
  122. package/dest/queries.js +53 -12
  123. package/dest/test/chain_monitor.d.ts +73 -0
  124. package/dest/test/chain_monitor.d.ts.map +1 -0
  125. package/dest/test/chain_monitor.js +215 -0
  126. package/dest/test/delayed_tx_utils.d.ts +8 -3
  127. package/dest/test/delayed_tx_utils.d.ts.map +1 -1
  128. package/dest/test/delayed_tx_utils.js +13 -6
  129. package/dest/test/eth_cheat_codes.d.ts +217 -0
  130. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  131. package/dest/test/eth_cheat_codes.js +558 -0
  132. package/dest/test/eth_cheat_codes_with_state.d.ts +2 -2
  133. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
  134. package/dest/test/eth_cheat_codes_with_state.js +1 -1
  135. package/dest/test/index.d.ts +4 -1
  136. package/dest/test/index.d.ts.map +1 -1
  137. package/dest/test/index.js +3 -0
  138. package/dest/test/rollup_cheat_codes.d.ts +87 -0
  139. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  140. package/dest/test/rollup_cheat_codes.js +266 -0
  141. package/dest/test/start_anvil.d.ts +7 -1
  142. package/dest/test/start_anvil.d.ts.map +1 -1
  143. package/dest/test/start_anvil.js +16 -7
  144. package/dest/test/tx_delayer.d.ts +18 -7
  145. package/dest/test/tx_delayer.d.ts.map +1 -1
  146. package/dest/test/tx_delayer.js +95 -19
  147. package/dest/test/upgrade_utils.d.ts +6 -5
  148. package/dest/test/upgrade_utils.d.ts.map +1 -1
  149. package/dest/test/upgrade_utils.js +23 -16
  150. package/dest/types.d.ts +7 -8
  151. package/dest/types.d.ts.map +1 -1
  152. package/dest/types.js +3 -1
  153. package/dest/utils.d.ts +2 -1
  154. package/dest/utils.d.ts.map +1 -1
  155. package/dest/utils.js +43 -88
  156. package/dest/zkPassportVerifierAddress.d.ts +15 -0
  157. package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
  158. package/dest/zkPassportVerifierAddress.js +11 -0
  159. package/package.json +28 -19
  160. package/src/account.ts +5 -0
  161. package/src/client.ts +42 -4
  162. package/src/config.ts +592 -31
  163. package/src/contracts/empire_base.ts +77 -7
  164. package/src/contracts/empire_slashing_proposer.ts +265 -0
  165. package/src/contracts/errors.ts +13 -0
  166. package/src/contracts/fee_asset_handler.ts +63 -0
  167. package/src/contracts/fee_juice.ts +29 -15
  168. package/src/contracts/governance.ts +80 -77
  169. package/src/contracts/governance_proposer.ts +66 -24
  170. package/src/contracts/gse.ts +88 -0
  171. package/src/contracts/inbox.ts +63 -0
  172. package/src/contracts/index.ts +8 -2
  173. package/src/contracts/multicall.ts +155 -0
  174. package/src/contracts/registry.ts +51 -26
  175. package/src/contracts/rollup.ts +596 -74
  176. package/src/contracts/slasher_contract.ts +89 -0
  177. package/src/contracts/tally_slashing_proposer.ts +316 -0
  178. package/src/contracts/utils.ts +14 -0
  179. package/src/deploy_l1_contracts.ts +1459 -538
  180. package/src/eth-signer/eth-signer.ts +25 -0
  181. package/src/eth-signer/index.ts +1 -0
  182. package/src/index.ts +6 -2
  183. package/src/l1_artifacts.ts +254 -0
  184. package/src/l1_contract_addresses.ts +32 -19
  185. package/src/l1_reader.ts +9 -9
  186. package/src/l1_tx_utils/README.md +177 -0
  187. package/src/l1_tx_utils/config.ts +143 -0
  188. package/src/l1_tx_utils/constants.ts +18 -0
  189. package/src/l1_tx_utils/factory.ts +64 -0
  190. package/src/l1_tx_utils/index.ts +12 -0
  191. package/src/l1_tx_utils/interfaces.ts +86 -0
  192. package/src/l1_tx_utils/l1_tx_utils.ts +718 -0
  193. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +77 -0
  194. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +558 -0
  195. package/src/l1_tx_utils/signer.ts +28 -0
  196. package/src/l1_tx_utils/types.ts +85 -0
  197. package/src/l1_tx_utils/utils.ts +16 -0
  198. package/src/l1_types.ts +6 -0
  199. package/src/publisher_manager.ts +106 -0
  200. package/src/queries.ts +73 -15
  201. package/src/test/chain_monitor.ts +243 -0
  202. package/src/test/delayed_tx_utils.ts +34 -6
  203. package/src/test/eth_cheat_codes.ts +588 -0
  204. package/src/test/eth_cheat_codes_with_state.ts +1 -1
  205. package/src/test/index.ts +3 -0
  206. package/src/test/rollup_cheat_codes.ts +307 -0
  207. package/src/test/start_anvil.ts +22 -5
  208. package/src/test/tx_delayer.ts +127 -26
  209. package/src/test/upgrade_utils.ts +30 -21
  210. package/src/types.ts +10 -8
  211. package/src/utils.ts +49 -90
  212. package/src/zkPassportVerifierAddress.ts +15 -0
  213. package/dest/contracts/forwarder.d.ts +0 -24
  214. package/dest/contracts/forwarder.d.ts.map +0 -1
  215. package/dest/contracts/forwarder.js +0 -101
  216. package/dest/contracts/slashing_proposer.d.ts +0 -21
  217. package/dest/contracts/slashing_proposer.d.ts.map +0 -1
  218. package/dest/contracts/slashing_proposer.js +0 -47
  219. package/dest/eth_cheat_codes.d.ts +0 -147
  220. package/dest/eth_cheat_codes.d.ts.map +0 -1
  221. package/dest/eth_cheat_codes.js +0 -303
  222. package/dest/l1_tx_utils.d.ts +0 -192
  223. package/dest/l1_tx_utils.d.ts.map +0 -1
  224. package/dest/l1_tx_utils.js +0 -641
  225. package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
  226. package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
  227. package/dest/l1_tx_utils_with_blobs.js +0 -64
  228. package/src/contracts/forwarder.ts +0 -132
  229. package/src/contracts/slashing_proposer.ts +0 -51
  230. package/src/eth_cheat_codes.ts +0 -314
  231. package/src/l1_tx_utils.ts +0 -847
  232. 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 { L1TxUtils } from '../l1_tx_utils.js';
16
- import type { ViemPublicClient, ViemWalletClient } from '../types.js';
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 class GovernanceContract {
37
- private readonly publicGovernance: GetContractReturnType<typeof GovernanceAbi, ViemPublicClient>;
38
- private readonly walletGovernance: GetContractReturnType<typeof GovernanceAbi, ViemWalletClient> | undefined;
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 publicClient: ViemPublicClient,
43
- public readonly walletClient: ViemWalletClient | undefined,
55
+ public readonly client: ViemClient,
44
56
  ) {
45
- this.publicGovernance = getContract({ address, abi: GovernanceAbi, client: publicClient });
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.publicGovernance.address);
61
+ return EthAddress.fromString(this.governanceContract.address);
53
62
  }
54
63
 
55
- public async getProposer() {
56
- const governanceProposerAddress = EthAddress.fromString(await this.publicGovernance.read.governanceProposer());
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 async getGovernanceAddresses(): Promise<L1GovernanceContractAddresses> {
61
- const governanceProposer = await this.getProposer();
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.publicGovernance.read.getProposal([proposalId]);
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.publicGovernance.read.getProposalState([proposalId]);
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.publicClient.getBlock();
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.publicClient.getBlock();
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 walletGovernance = this.assertWalletGovernance();
168
- const now = await this.publicClient.getBlock();
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 walletGovernance = this.assertWalletGovernance();
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: walletGovernance.address,
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: walletGovernance.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.state}]`);
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 nea [${proposal.summedBallot.nea}]`);
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 walletGovernance = this.assertWalletGovernance();
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: walletGovernance.address,
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: walletGovernance.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 { type GetContractReturnType, type Hex, type TransactionReceipt, encodeFunctionData, getContract } from 'viem';
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 { GasPrice, L1TxRequest, L1TxUtils } from '../l1_tx_utils.js';
8
- import type { ViemPublicClient } from '../types.js';
9
- import { type IEmpireBase, encodeVote } from './empire_base.js';
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, ViemPublicClient>;
21
+ private readonly proposer: GetContractReturnType<typeof GovernanceProposerAbi, ViemClient>;
13
22
 
14
- constructor(public readonly client: ViemPublicClient, address: Hex) {
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.N();
47
+ return this.proposer.read.QUORUM_SIZE();
33
48
  }
34
49
 
35
50
  public getRoundSize(): Promise<bigint> {
36
- return this.proposer.read.M();
51
+ return this.proposer.read.ROUND_SIZE();
37
52
  }
38
53
 
39
- public computeRound(slot: bigint): Promise<bigint> {
40
- return this.proposer.read.computeRound([slot]);
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<{ lastVote: bigint; leader: Hex; executed: boolean }> {
47
- const roundInfo = await this.proposer.read.rounds([rollupAddress, round]);
65
+ ): Promise<{ lastSignalSlot: SlotNumber; payloadWithMostSignals: Hex; executed: boolean }> {
66
+ const result = await this.proposer.read.getRoundData([rollupAddress, round]);
48
67
  return {
49
- lastVote: roundInfo[0],
50
- leader: roundInfo[1],
51
- executed: roundInfo[2],
68
+ lastSignalSlot: SlotNumber.fromBigInt(result.lastSignalSlot),
69
+ payloadWithMostSignals: result.payloadWithMostSignals,
70
+ executed: result.executed,
52
71
  };
53
72
  }
54
73
 
55
- public getProposalVotes(rollupAddress: Hex, round: bigint, proposal: Hex): Promise<bigint> {
56
- return this.proposer.read.yeaCount([rollupAddress, round, proposal]);
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 createVoteRequest(payload: Hex): L1TxRequest {
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: encodeVote(payload),
102
+ data: encodeSignalWithSignature(payload, signature),
63
103
  };
64
104
  }
65
105
 
66
- public executeProposal(
106
+ public async submitRoundWinner(
67
107
  round: bigint,
68
108
  l1TxUtils: L1TxUtils,
69
109
  ): Promise<{
70
110
  receipt: TransactionReceipt;
71
- gasPrice: GasPrice;
111
+ proposalId: bigint;
72
112
  }> {
73
- return l1TxUtils.sendAndMonitorTransaction({
113
+ const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
74
114
  to: this.address.toString(),
75
115
  data: encodeFunctionData({
76
116
  abi: this.proposer.abi,
77
- functionName: 'executeProposal',
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
+ };
@@ -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 './slashing_proposer.js';
12
+ export * from './empire_slashing_proposer.js';
13
+ export * from './tally_slashing_proposer.js';
14
+ export * from './slasher_contract.js';