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