@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.1142ef1

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 (276) 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 +21 -3
  8. package/dest/config.d.ts +74 -16
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +144 -22
  11. package/dest/constants.d.ts +1 -1
  12. package/dest/contracts/empire_base.d.ts +25 -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 +67 -0
  16. package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -0
  17. package/dest/contracts/empire_slashing_proposer.js +209 -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 +20 -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 +17 -13
  31. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  32. package/dest/contracts/governance_proposer.js +428 -25
  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 +30 -0
  37. package/dest/contracts/inbox.d.ts.map +1 -0
  38. package/dest/contracts/inbox.js +49 -0
  39. package/dest/contracts/index.d.ts +10 -3
  40. package/dest/contracts/index.d.ts.map +1 -1
  41. package/dest/contracts/index.js +9 -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/outbox.d.ts +41 -0
  46. package/dest/contracts/outbox.d.ts.map +1 -0
  47. package/dest/contracts/outbox.js +86 -0
  48. package/dest/contracts/registry.d.ts +10 -5
  49. package/dest/contracts/registry.d.ts.map +1 -1
  50. package/dest/contracts/registry.js +44 -16
  51. package/dest/contracts/rollup.d.ts +266 -53
  52. package/dest/contracts/rollup.d.ts.map +1 -1
  53. package/dest/contracts/rollup.js +1059 -116
  54. package/dest/contracts/slasher_contract.d.ts +44 -0
  55. package/dest/contracts/slasher_contract.d.ts.map +1 -0
  56. package/dest/contracts/slasher_contract.js +75 -0
  57. package/dest/contracts/tally_slashing_proposer.d.ts +140 -0
  58. package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -0
  59. package/dest/contracts/tally_slashing_proposer.js +313 -0
  60. package/dest/contracts/utils.d.ts +3 -0
  61. package/dest/contracts/utils.d.ts.map +1 -0
  62. package/dest/contracts/utils.js +11 -0
  63. package/dest/deploy_aztec_l1_contracts.d.ts +255 -0
  64. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  65. package/dest/deploy_aztec_l1_contracts.js +385 -0
  66. package/dest/deploy_l1_contract.d.ts +68 -0
  67. package/dest/deploy_l1_contract.d.ts.map +1 -0
  68. package/dest/deploy_l1_contract.js +312 -0
  69. package/dest/eth-signer/eth-signer.d.ts +21 -0
  70. package/dest/eth-signer/eth-signer.d.ts.map +1 -0
  71. package/dest/eth-signer/eth-signer.js +5 -0
  72. package/dest/eth-signer/index.d.ts +2 -0
  73. package/dest/eth-signer/index.d.ts.map +1 -0
  74. package/dest/eth-signer/index.js +1 -0
  75. package/dest/forwarder_proxy.d.ts +32 -0
  76. package/dest/forwarder_proxy.d.ts.map +1 -0
  77. package/dest/forwarder_proxy.js +93 -0
  78. package/dest/l1_artifacts.d.ts +79812 -0
  79. package/dest/l1_artifacts.d.ts.map +1 -0
  80. package/dest/l1_artifacts.js +166 -0
  81. package/dest/l1_contract_addresses.d.ts +24 -4
  82. package/dest/l1_contract_addresses.d.ts.map +1 -1
  83. package/dest/l1_contract_addresses.js +25 -21
  84. package/dest/l1_reader.d.ts +4 -2
  85. package/dest/l1_reader.d.ts.map +1 -1
  86. package/dest/l1_reader.js +14 -8
  87. package/dest/l1_tx_utils/config.d.ts +59 -0
  88. package/dest/l1_tx_utils/config.d.ts.map +1 -0
  89. package/dest/l1_tx_utils/config.js +96 -0
  90. package/dest/l1_tx_utils/constants.d.ts +12 -0
  91. package/dest/l1_tx_utils/constants.d.ts.map +1 -0
  92. package/dest/l1_tx_utils/constants.js +39 -0
  93. package/dest/l1_tx_utils/factory.d.ts +24 -0
  94. package/dest/l1_tx_utils/factory.d.ts.map +1 -0
  95. package/dest/l1_tx_utils/factory.js +12 -0
  96. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  97. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  98. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  99. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  100. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  101. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  102. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  103. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  104. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  105. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  106. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  107. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  108. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  109. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  110. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +48 -0
  111. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  112. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  113. package/dest/l1_tx_utils/index-blobs.js +2 -0
  114. package/dest/l1_tx_utils/index.d.ts +12 -0
  115. package/dest/l1_tx_utils/index.d.ts.map +1 -0
  116. package/dest/l1_tx_utils/index.js +12 -0
  117. package/dest/l1_tx_utils/interfaces.d.ts +76 -0
  118. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
  119. package/dest/l1_tx_utils/interfaces.js +4 -0
  120. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
  121. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  122. package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
  123. package/dest/l1_tx_utils/l1_tx_utils.d.ts +94 -0
  124. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
  125. package/dest/l1_tx_utils/l1_tx_utils.js +623 -0
  126. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +26 -0
  127. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +1 -0
  128. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +26 -0
  129. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +83 -0
  130. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
  131. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +323 -0
  132. package/dest/l1_tx_utils/signer.d.ts +4 -0
  133. package/dest/l1_tx_utils/signer.d.ts.map +1 -0
  134. package/dest/l1_tx_utils/signer.js +16 -0
  135. package/dest/l1_tx_utils/types.d.ts +67 -0
  136. package/dest/l1_tx_utils/types.d.ts.map +1 -0
  137. package/dest/l1_tx_utils/types.js +26 -0
  138. package/dest/l1_tx_utils/utils.d.ts +4 -0
  139. package/dest/l1_tx_utils/utils.d.ts.map +1 -0
  140. package/dest/l1_tx_utils/utils.js +14 -0
  141. package/dest/l1_types.d.ts +6 -0
  142. package/dest/l1_types.d.ts.map +1 -0
  143. package/dest/l1_types.js +1 -0
  144. package/dest/publisher_manager.d.ts +15 -0
  145. package/dest/publisher_manager.d.ts.map +1 -0
  146. package/dest/publisher_manager.js +88 -0
  147. package/dest/queries.d.ts +4 -2
  148. package/dest/queries.d.ts.map +1 -1
  149. package/dest/queries.js +58 -12
  150. package/dest/test/chain_monitor.d.ts +75 -0
  151. package/dest/test/chain_monitor.d.ts.map +1 -0
  152. package/dest/test/chain_monitor.js +213 -0
  153. package/dest/test/delayed_tx_utils.d.ts +8 -3
  154. package/dest/test/delayed_tx_utils.d.ts.map +1 -1
  155. package/dest/test/delayed_tx_utils.js +13 -6
  156. package/dest/test/eth_cheat_codes.d.ts +217 -0
  157. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  158. package/dest/test/eth_cheat_codes.js +560 -0
  159. package/dest/test/eth_cheat_codes_with_state.d.ts +2 -2
  160. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
  161. package/dest/test/eth_cheat_codes_with_state.js +1 -1
  162. package/dest/test/index.d.ts +4 -1
  163. package/dest/test/index.d.ts.map +1 -1
  164. package/dest/test/index.js +3 -0
  165. package/dest/test/rollup_cheat_codes.d.ts +88 -0
  166. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  167. package/dest/test/rollup_cheat_codes.js +283 -0
  168. package/dest/test/start_anvil.d.ts +9 -1
  169. package/dest/test/start_anvil.d.ts.map +1 -1
  170. package/dest/test/start_anvil.js +16 -7
  171. package/dest/test/tx_delayer.d.ts +18 -7
  172. package/dest/test/tx_delayer.d.ts.map +1 -1
  173. package/dest/test/tx_delayer.js +97 -20
  174. package/dest/test/upgrade_utils.d.ts +6 -5
  175. package/dest/test/upgrade_utils.d.ts.map +1 -1
  176. package/dest/test/upgrade_utils.js +23 -16
  177. package/dest/types.d.ts +62 -8
  178. package/dest/types.d.ts.map +1 -1
  179. package/dest/types.js +3 -1
  180. package/dest/utils.d.ts +16 -3
  181. package/dest/utils.d.ts.map +1 -1
  182. package/dest/utils.js +61 -88
  183. package/dest/zkPassportVerifierAddress.d.ts +15 -0
  184. package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
  185. package/dest/zkPassportVerifierAddress.js +11 -0
  186. package/package.json +50 -23
  187. package/src/account.ts +5 -0
  188. package/src/client.ts +43 -5
  189. package/src/config.ts +196 -31
  190. package/src/contracts/empire_base.ts +77 -7
  191. package/src/contracts/empire_slashing_proposer.ts +270 -0
  192. package/src/contracts/errors.ts +13 -0
  193. package/src/contracts/fee_asset_handler.ts +64 -0
  194. package/src/contracts/fee_juice.ts +29 -15
  195. package/src/contracts/governance.ts +80 -77
  196. package/src/contracts/governance_proposer.ts +71 -24
  197. package/src/contracts/gse.ts +88 -0
  198. package/src/contracts/inbox.ts +68 -0
  199. package/src/contracts/index.ts +9 -2
  200. package/src/contracts/multicall.ts +155 -0
  201. package/src/contracts/outbox.ts +98 -0
  202. package/src/contracts/registry.ts +51 -26
  203. package/src/contracts/rollup.ts +784 -90
  204. package/src/contracts/slasher_contract.ts +89 -0
  205. package/src/contracts/tally_slashing_proposer.ts +318 -0
  206. package/src/contracts/utils.ts +14 -0
  207. package/src/deploy_aztec_l1_contracts.ts +605 -0
  208. package/src/deploy_l1_contract.ts +362 -0
  209. package/src/eth-signer/eth-signer.ts +25 -0
  210. package/src/eth-signer/index.ts +1 -0
  211. package/src/forwarder_proxy.ts +108 -0
  212. package/src/l1_artifacts.ts +254 -0
  213. package/src/l1_contract_addresses.ts +49 -34
  214. package/src/l1_reader.ts +17 -9
  215. package/src/l1_tx_utils/README.md +177 -0
  216. package/src/l1_tx_utils/config.ts +161 -0
  217. package/src/l1_tx_utils/constants.ts +29 -0
  218. package/src/l1_tx_utils/factory.ts +64 -0
  219. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  220. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
  221. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
  222. package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
  223. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +119 -0
  224. package/src/l1_tx_utils/index-blobs.ts +2 -0
  225. package/src/l1_tx_utils/index.ts +14 -0
  226. package/src/l1_tx_utils/interfaces.ts +86 -0
  227. package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
  228. package/src/l1_tx_utils/l1_tx_utils.ts +738 -0
  229. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +77 -0
  230. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +419 -0
  231. package/src/l1_tx_utils/signer.ts +28 -0
  232. package/src/l1_tx_utils/types.ts +85 -0
  233. package/src/l1_tx_utils/utils.ts +16 -0
  234. package/src/l1_types.ts +6 -0
  235. package/src/publisher_manager.ts +106 -0
  236. package/src/queries.ts +79 -15
  237. package/src/test/chain_monitor.ts +245 -0
  238. package/src/test/delayed_tx_utils.ts +34 -6
  239. package/src/test/eth_cheat_codes.ts +588 -0
  240. package/src/test/eth_cheat_codes_with_state.ts +1 -1
  241. package/src/test/index.ts +3 -0
  242. package/src/test/rollup_cheat_codes.ts +321 -0
  243. package/src/test/start_anvil.ts +24 -5
  244. package/src/test/tx_delayer.ts +130 -27
  245. package/src/test/upgrade_utils.ts +30 -21
  246. package/src/types.ts +71 -7
  247. package/src/utils.ts +79 -91
  248. package/src/zkPassportVerifierAddress.ts +15 -0
  249. package/dest/contracts/forwarder.d.ts +0 -24
  250. package/dest/contracts/forwarder.d.ts.map +0 -1
  251. package/dest/contracts/forwarder.js +0 -101
  252. package/dest/contracts/slashing_proposer.d.ts +0 -21
  253. package/dest/contracts/slashing_proposer.d.ts.map +0 -1
  254. package/dest/contracts/slashing_proposer.js +0 -47
  255. package/dest/deploy_l1_contracts.d.ts +0 -21210
  256. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  257. package/dest/deploy_l1_contracts.js +0 -687
  258. package/dest/eth_cheat_codes.d.ts +0 -147
  259. package/dest/eth_cheat_codes.d.ts.map +0 -1
  260. package/dest/eth_cheat_codes.js +0 -303
  261. package/dest/index.d.ts +0 -14
  262. package/dest/index.d.ts.map +0 -1
  263. package/dest/index.js +0 -13
  264. package/dest/l1_tx_utils.d.ts +0 -192
  265. package/dest/l1_tx_utils.d.ts.map +0 -1
  266. package/dest/l1_tx_utils.js +0 -641
  267. package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
  268. package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
  269. package/dest/l1_tx_utils_with_blobs.js +0 -64
  270. package/src/contracts/forwarder.ts +0 -132
  271. package/src/contracts/slashing_proposer.ts +0 -51
  272. package/src/deploy_l1_contracts.ts +0 -948
  273. package/src/eth_cheat_codes.ts +0 -314
  274. package/src/index.ts +0 -13
  275. package/src/l1_tx_utils.ts +0 -847
  276. package/src/l1_tx_utils_with_blobs.ts +0 -86
@@ -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,86 @@ 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; quorumReached: boolean; executed: boolean }> {
66
+ const result = await this.proposer.read.getRoundData([rollupAddress, round]);
67
+ const [signalCount, quorum] = await Promise.all([
68
+ this.proposer.read.signalCount([rollupAddress, round, result.payloadWithMostSignals]),
69
+ this.getQuorumSize(),
70
+ ]);
48
71
  return {
49
- lastVote: roundInfo[0],
50
- leader: roundInfo[1],
51
- executed: roundInfo[2],
72
+ lastSignalSlot: SlotNumber.fromBigInt(result.lastSignalSlot),
73
+ payloadWithMostSignals: result.payloadWithMostSignals,
74
+ quorumReached: signalCount >= quorum,
75
+ executed: result.executed,
52
76
  };
53
77
  }
54
78
 
55
- public getProposalVotes(rollupAddress: Hex, round: bigint, proposal: Hex): Promise<bigint> {
56
- return this.proposer.read.yeaCount([rollupAddress, round, proposal]);
79
+ public getPayloadSignals(rollupAddress: Hex, round: bigint, payload: Hex): Promise<bigint> {
80
+ return this.proposer.read.signalCount([rollupAddress, round, payload]);
81
+ }
82
+
83
+ public createSignalRequest(payload: Hex): L1TxRequest {
84
+ return {
85
+ to: this.address.toString(),
86
+ data: encodeSignal(payload),
87
+ };
57
88
  }
58
89
 
59
- public createVoteRequest(payload: Hex): L1TxRequest {
90
+ public async createSignalRequestWithSignature(
91
+ payload: Hex,
92
+ slot: SlotNumber,
93
+ chainId: number,
94
+ signerAddress: Hex,
95
+ signer: (msg: TypedDataDefinition) => Promise<Hex>,
96
+ ): Promise<L1TxRequest> {
97
+ const signature = await signSignalWithSig(
98
+ signer,
99
+ payload,
100
+ slot,
101
+ await this.getInstance(),
102
+ this.address.toString(),
103
+ chainId,
104
+ );
60
105
  return {
61
106
  to: this.address.toString(),
62
- data: encodeVote(payload),
107
+ data: encodeSignalWithSignature(payload, signature),
63
108
  };
64
109
  }
65
110
 
66
- public executeProposal(
111
+ public async submitRoundWinner(
67
112
  round: bigint,
68
113
  l1TxUtils: L1TxUtils,
69
114
  ): Promise<{
70
115
  receipt: TransactionReceipt;
71
- gasPrice: GasPrice;
116
+ proposalId: bigint;
72
117
  }> {
73
- return l1TxUtils.sendAndMonitorTransaction({
118
+ const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
74
119
  to: this.address.toString(),
75
120
  data: encodeFunctionData({
76
121
  abi: this.proposer.abi,
77
- functionName: 'executeProposal',
122
+ functionName: 'submitRoundWinner',
78
123
  args: [round],
79
124
  }),
80
125
  });
126
+ const proposalId = extractProposalIdFromLogs(receipt.logs);
127
+ return { receipt, proposalId };
81
128
  }
82
129
  }
@@ -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,68 @@
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 { DeployAztecL1ContractsReturnType } from '../deploy_aztec_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: DeployAztecL1ContractsReturnType) {
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 getLag(opts: { blockTag?: BlockTag; blockNumber?: bigint } = {}): Promise<bigint> {
49
+ await checkBlockTag(opts.blockNumber, this.client);
50
+ return await this.inbox.read.LAG(opts);
51
+ }
52
+
53
+ public async getState(opts: { blockTag?: BlockTag; blockNumber?: bigint } = {}): Promise<InboxContractState> {
54
+ await checkBlockTag(opts.blockNumber, this.client);
55
+ const state = await this.inbox.read.getState(opts);
56
+ return {
57
+ totalMessagesInserted: state.totalMessagesInserted,
58
+ messagesRollingHash: Buffer16.fromString(state.rollingHash),
59
+ treeInProgress: state.inProgress,
60
+ };
61
+ }
62
+ }
63
+
64
+ export type InboxContractState = {
65
+ totalMessagesInserted: bigint;
66
+ messagesRollingHash: Buffer16;
67
+ treeInProgress: bigint;
68
+ };
@@ -1,8 +1,15 @@
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';
10
+ export * from './outbox.js';
6
11
  export * from './registry.js';
7
12
  export * from './rollup.js';
8
- export * from './slashing_proposer.js';
13
+ export * from './empire_slashing_proposer.js';
14
+ export * from './tally_slashing_proposer.js';
15
+ export * from './slasher_contract.js';
@@ -0,0 +1,155 @@
1
+ import { toHex as toPaddedHex } from '@aztec/foundation/bigint-buffer';
2
+ import { TimeoutError } from '@aztec/foundation/error';
3
+ import type { Logger } from '@aztec/foundation/log';
4
+
5
+ import { type EncodeFunctionDataParameters, type Hex, encodeFunctionData, multicall3Abi } from 'viem';
6
+
7
+ import type { L1BlobInputs, L1TxConfig, L1TxRequest, L1TxUtils } from '../l1_tx_utils/index.js';
8
+ import type { ExtendedViemWalletClient } from '../types.js';
9
+ import { FormattedViemError, formatViemError } from '../utils.js';
10
+ import { RollupContract } from './rollup.js';
11
+
12
+ export const MULTI_CALL_3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11' as const;
13
+
14
+ export class Multicall3 {
15
+ static async forward(
16
+ requests: L1TxRequest[],
17
+ l1TxUtils: L1TxUtils,
18
+ gasConfig: L1TxConfig | undefined,
19
+ blobConfig: L1BlobInputs | undefined,
20
+ rollupAddress: Hex,
21
+ logger: Logger,
22
+ opts: { revertOnFailure?: boolean } = {},
23
+ ) {
24
+ requests = requests.filter(request => request.to !== null);
25
+ const args = requests.map(r => ({
26
+ target: r.to!,
27
+ callData: r.data!,
28
+ allowFailure: !opts.revertOnFailure,
29
+ }));
30
+ const forwarderFunctionData: Required<EncodeFunctionDataParameters<typeof multicall3Abi, 'aggregate3'>> = {
31
+ abi: multicall3Abi,
32
+ functionName: 'aggregate3',
33
+ args: [args],
34
+ };
35
+
36
+ const encodedForwarderData = encodeFunctionData(forwarderFunctionData);
37
+
38
+ try {
39
+ const { receipt, state } = await l1TxUtils.sendAndMonitorTransaction(
40
+ { to: MULTI_CALL_3_ADDRESS, data: encodedForwarderData },
41
+ gasConfig,
42
+ blobConfig,
43
+ );
44
+
45
+ if (receipt.status === 'success') {
46
+ const stats = await l1TxUtils.getTransactionStats(receipt.transactionHash);
47
+ return { receipt, stats };
48
+ } else {
49
+ logger.error('Forwarder transaction failed', undefined, { receipt });
50
+
51
+ const args = {
52
+ ...forwarderFunctionData,
53
+ address: MULTI_CALL_3_ADDRESS,
54
+ };
55
+
56
+ let errorMsg: string | undefined;
57
+
58
+ if (blobConfig) {
59
+ const maxFeePerBlobGas = blobConfig.maxFeePerBlobGas ?? state.gasPrice.maxFeePerBlobGas;
60
+ if (maxFeePerBlobGas === undefined) {
61
+ errorMsg = 'maxFeePerBlobGas is required to get the error message';
62
+ } else {
63
+ logger.debug('Trying to get error from reverted tx with blob config');
64
+ errorMsg = await l1TxUtils.tryGetErrorFromRevertedTx(
65
+ encodedForwarderData,
66
+ args,
67
+ {
68
+ blobs: blobConfig.blobs,
69
+ kzg: blobConfig.kzg,
70
+ maxFeePerBlobGas,
71
+ },
72
+ [
73
+ {
74
+ address: rollupAddress,
75
+ stateDiff: [
76
+ {
77
+ slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true),
78
+ value: toPaddedHex(0n, true),
79
+ },
80
+ ],
81
+ },
82
+ ],
83
+ );
84
+ }
85
+ } else {
86
+ logger.debug('Trying to get error from reverted tx without blob config');
87
+ errorMsg = await l1TxUtils.tryGetErrorFromRevertedTx(encodedForwarderData, args, undefined, []);
88
+ }
89
+
90
+ return { receipt, errorMsg };
91
+ }
92
+ } catch (err) {
93
+ if (err instanceof TimeoutError) {
94
+ throw err;
95
+ }
96
+
97
+ for (const request of requests) {
98
+ logger.debug('Simulating request', { request });
99
+ const result = await l1TxUtils
100
+ .simulate(request, undefined, [
101
+ {
102
+ address: rollupAddress,
103
+ stateDiff: [
104
+ { slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true), value: toPaddedHex(0n, true) },
105
+ ],
106
+ },
107
+ ])
108
+ .catch(err => formatViemError(err, request.abi));
109
+ if (result instanceof FormattedViemError) {
110
+ logger.error('Found error in simulation', result, {
111
+ to: request.to ?? 'null',
112
+ data: request.data,
113
+ });
114
+
115
+ return result;
116
+ }
117
+ }
118
+ logger.warn('Failed to get error from reverted tx', { err });
119
+ throw err;
120
+ }
121
+ }
122
+ }
123
+
124
+ export async function deployMulticall3(l1Client: ExtendedViemWalletClient, logger: Logger) {
125
+ const existing = await l1Client.getCode({ address: MULTI_CALL_3_ADDRESS });
126
+ if (existing && existing !== '0x') {
127
+ logger.verbose('Multicall3 already deployed', { address: MULTI_CALL_3_ADDRESS });
128
+ return;
129
+ }
130
+
131
+ const deployer = '0x05f32b3cc3888453ff71b01135b34ff8e41263f2';
132
+ const sendEth = await l1Client.sendTransaction({ to: deployer, value: 10n ** 17n });
133
+ logger.info('Sent 0.1 ETH to deployer', { deployer, value: 10n ** 17n });
134
+ const sendEthReceipt = await l1Client.waitForTransactionReceipt({ hash: sendEth });
135
+ if (sendEthReceipt.status !== 'success') {
136
+ logger.error('Failed to send ETH to deployer', undefined, { sendEthReceipt });
137
+ throw new Error('Failed to send ETH to deployer');
138
+ } else {
139
+ logger.info('Sent 0.1 ETH to deployer', { deployer, value: 10n ** 17n });
140
+ }
141
+
142
+ const tx =
143
+ '0xf90f538085174876e800830f42408080b90f00608060405234801561001057600080fd5b50610ee0806100206000396000f3fe6080604052600436106100f35760003560e01c80634d2301cc1161008a578063a8b0574e11610059578063a8b0574e1461025a578063bce38bd714610275578063c3077fa914610288578063ee82ac5e1461029b57600080fd5b80634d2301cc146101ec57806372425d9d1461022157806382ad56cb1461023457806386d516e81461024757600080fd5b80633408e470116100c65780633408e47014610191578063399542e9146101a45780633e64a696146101c657806342cbb15c146101d957600080fd5b80630f28c97d146100f8578063174dea711461011a578063252dba421461013a57806327e86d6e1461015b575b600080fd5b34801561010457600080fd5b50425b6040519081526020015b60405180910390f35b61012d610128366004610a85565b6102ba565b6040516101119190610bbe565b61014d610148366004610a85565b6104ef565b604051610111929190610bd8565b34801561016757600080fd5b50437fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0140610107565b34801561019d57600080fd5b5046610107565b6101b76101b2366004610c60565b610690565b60405161011193929190610cba565b3480156101d257600080fd5b5048610107565b3480156101e557600080fd5b5043610107565b3480156101f857600080fd5b50610107610207366004610ce2565b73ffffffffffffffffffffffffffffffffffffffff163190565b34801561022d57600080fd5b5044610107565b61012d610242366004610a85565b6106ab565b34801561025357600080fd5b5045610107565b34801561026657600080fd5b50604051418152602001610111565b61012d610283366004610c60565b61085a565b6101b7610296366004610a85565b610a1a565b3480156102a757600080fd5b506101076102b6366004610d18565b4090565b60606000828067ffffffffffffffff8111156102d8576102d8610d31565b60405190808252806020026020018201604052801561031e57816020015b6040805180820190915260008152606060208201528152602001906001900390816102f65790505b5092503660005b8281101561047757600085828151811061034157610341610d60565b6020026020010151905087878381811061035d5761035d610d60565b905060200281019061036f9190610d8f565b6040810135958601959093506103886020850185610ce2565b73ffffffffffffffffffffffffffffffffffffffff16816103ac6060870187610dcd565b6040516103ba929190610e32565b60006040518083038185875af1925050503d80600081146103f7576040519150601f19603f3d011682016040523d82523d6000602084013e6103fc565b606091505b50602080850191909152901515808452908501351761046d577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260846000fd5b5050600101610325565b508234146104e6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f4d756c746963616c6c333a2076616c7565206d69736d6174636800000000000060448201526064015b60405180910390fd5b50505092915050565b436060828067ffffffffffffffff81111561050c5761050c610d31565b60405190808252806020026020018201604052801561053f57816020015b606081526020019060019003908161052a5790505b5091503660005b8281101561068657600087878381811061056257610562610d60565b90506020028101906105749190610e42565b92506105836020840184610ce2565b73ffffffffffffffffffffffffffffffffffffffff166105a66020850185610dcd565b6040516105b4929190610e32565b6000604051808303816000865af19150503d80600081146105f1576040519150601f19603f3d011682016040523d82523d6000602084013e6105f6565b606091505b5086848151811061060957610609610d60565b602090810291909101015290508061067d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060448201526064016104dd565b50600101610546565b5050509250929050565b43804060606106a086868661085a565b905093509350939050565b6060818067ffffffffffffffff8111156106c7576106c7610d31565b60405190808252806020026020018201604052801561070d57816020015b6040805180820190915260008152606060208201528152602001906001900390816106e55790505b5091503660005b828110156104e657600084828151811061073057610730610d60565b6020026020010151905086868381811061074c5761074c610d60565b905060200281019061075e9190610e76565b925061076d6020840184610ce2565b73ffffffffffffffffffffffffffffffffffffffff166107906040850185610dcd565b60405161079e929190610e32565b6000604051808303816000865af19150503d80600081146107db576040519150601f19603f3d011682016040523d82523d6000602084013e6107e0565b606091505b506020808401919091529015158083529084013517610851577f08c379a000000000000000000000000000000000000000000000000000000000600052602060045260176024527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060445260646000fd5b50600101610714565b6060818067ffffffffffffffff81111561087657610876610d31565b6040519080825280602002602001820160405280156108bc57816020015b6040805180820190915260008152606060208201528152602001906001900390816108945790505b5091503660005b82811015610a105760008482815181106108df576108df610d60565b602002602001015190508686838181106108fb576108fb610d60565b905060200281019061090d9190610e42565b925061091c6020840184610ce2565b73ffffffffffffffffffffffffffffffffffffffff1661093f6020850185610dcd565b60405161094d929190610e32565b6000604051808303816000865af19150503d806000811461098a576040519150601f19603f3d011682016040523d82523d6000602084013e61098f565b606091505b506020830152151581528715610a07578051610a07576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4d756c746963616c6c333a2063616c6c206661696c656400000000000000000060448201526064016104dd565b506001016108c3565b5050509392505050565b6000806060610a2b60018686610690565b919790965090945092505050565b60008083601f840112610a4b57600080fd5b50813567ffffffffffffffff811115610a6357600080fd5b6020830191508360208260051b8501011115610a7e57600080fd5b9250929050565b60008060208385031215610a9857600080fd5b823567ffffffffffffffff811115610aaf57600080fd5b610abb85828601610a39565b90969095509350505050565b6000815180845260005b81811015610aed57602081850181015186830182015201610ad1565b81811115610aff576000602083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b600082825180855260208086019550808260051b84010181860160005b84811015610bb1578583037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001895281518051151584528401516040858501819052610b9d81860183610ac7565b9a86019a9450505090830190600101610b4f565b5090979650505050505050565b602081526000610bd16020830184610b32565b9392505050565b600060408201848352602060408185015281855180845260608601915060608160051b870101935082870160005b82811015610c52577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa0888703018452610c40868351610ac7565b95509284019290840190600101610c06565b509398975050505050505050565b600080600060408486031215610c7557600080fd5b83358015158114610c8557600080fd5b9250602084013567ffffffffffffffff811115610ca157600080fd5b610cad86828701610a39565b9497909650939450505050565b838152826020820152606060408201526000610cd96060830184610b32565b95945050505050565b600060208284031215610cf457600080fd5b813573ffffffffffffffffffffffffffffffffffffffff81168114610bd157600080fd5b600060208284031215610d2a57600080fd5b5035919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81833603018112610dc357600080fd5b9190910192915050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112610e0257600080fd5b83018035915067ffffffffffffffff821115610e1d57600080fd5b602001915036819003821315610a7e57600080fd5b8183823760009101908152919050565b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc1833603018112610dc357600080fd5b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa1833603018112610dc357600080fdfea2646970667358221220bb2b5c71a328032f97c676ae39a1ec2148d3e5d6f73d95e9b17910152d61f16264736f6c634300080c00331ca0edce47092c0f398cebf3ffc267f05c8e7076e3b89445e0fe50f6332273d4569ba01b0b9d000e19b24c5869b0fc3b22b0d6fa47cd63316875cbbd577d76e6fde086';
144
+
145
+ const deployTx = await l1Client.sendRawTransaction({
146
+ serializedTransaction: tx,
147
+ });
148
+ const deployTxReceipt = await l1Client.waitForTransactionReceipt({ hash: deployTx });
149
+ if (deployTxReceipt.status !== 'success') {
150
+ logger.error('Failed to deploy Multicall3', undefined, { deployTxReceipt });
151
+ throw new Error('Failed to deploy Multicall3');
152
+ } else {
153
+ logger.info('Deployed Multicall3');
154
+ }
155
+ }
@@ -0,0 +1,98 @@
1
+ import type { EpochNumber } from '@aztec/foundation/branded-types';
2
+ import { EthAddress } from '@aztec/foundation/eth-address';
3
+ import { OutboxAbi } from '@aztec/l1-artifacts/OutboxAbi';
4
+
5
+ import { type GetContractReturnType, type Hex, encodeAbiParameters, getContract, hexToBigInt, keccak256 } from 'viem';
6
+
7
+ import { getPublicClient } from '../client.js';
8
+ import type { DeployAztecL1ContractsReturnType } from '../deploy_aztec_l1_contracts.js';
9
+ import type { L1ReaderConfig } from '../l1_reader.js';
10
+ import { type ExtendedViemWalletClient, type ViemClient, isExtendedClient } from '../types.js';
11
+
12
+ export type ViemL1Actor = {
13
+ actor: Hex;
14
+ chainId: bigint;
15
+ };
16
+
17
+ export type ViemL2Actor = {
18
+ actor: Hex;
19
+ version: bigint;
20
+ };
21
+
22
+ export type ViemL2ToL1Msg = {
23
+ sender: ViemL2Actor;
24
+ recipient: ViemL1Actor;
25
+ content: Hex;
26
+ };
27
+
28
+ export class OutboxContract {
29
+ private readonly outbox: GetContractReturnType<typeof OutboxAbi, ViemClient>;
30
+
31
+ static getFromL1ContractsValues(deployL1ContractsValues: DeployAztecL1ContractsReturnType) {
32
+ const {
33
+ l1Client,
34
+ l1ContractAddresses: { outboxAddress },
35
+ } = deployL1ContractsValues;
36
+ return new OutboxContract(l1Client, outboxAddress.toString());
37
+ }
38
+
39
+ static getFromConfig(config: L1ReaderConfig) {
40
+ const client = getPublicClient(config);
41
+ const address = config.l1Contracts.outboxAddress.toString();
42
+ return new OutboxContract(client, address);
43
+ }
44
+
45
+ static getEpochRootStorageSlot(epoch: EpochNumber) {
46
+ return hexToBigInt(keccak256(encodeAbiParameters([{ type: 'uint256' }, { type: 'uint256' }], [BigInt(epoch), 0n])));
47
+ }
48
+
49
+ constructor(
50
+ public readonly client: ViemClient,
51
+ address: Hex | EthAddress,
52
+ ) {
53
+ if (address instanceof EthAddress) {
54
+ address = address.toString();
55
+ }
56
+ this.outbox = getContract({ address, abi: OutboxAbi, client });
57
+ }
58
+
59
+ public get address() {
60
+ return this.outbox.address;
61
+ }
62
+
63
+ public getContract(): GetContractReturnType<typeof OutboxAbi, ViemClient> {
64
+ return this.outbox;
65
+ }
66
+
67
+ public hasMessageBeenConsumedAtEpoch(epoch: EpochNumber, leafId: bigint) {
68
+ return this.outbox.read.hasMessageBeenConsumedAtEpoch([BigInt(epoch), leafId]);
69
+ }
70
+
71
+ public getRootData(epoch: EpochNumber) {
72
+ return this.outbox.read.getRootData([BigInt(epoch)]);
73
+ }
74
+
75
+ public consume(message: ViemL2ToL1Msg, epoch: EpochNumber, leafIndex: bigint, path: Hex[]) {
76
+ const wallet = this.assertWallet();
77
+ return wallet.write.consume([message, BigInt(epoch), leafIndex, path]);
78
+ }
79
+
80
+ public async getMessageConsumedEvents(
81
+ l1BlockHash: Hex,
82
+ ): Promise<{ epoch: bigint; root: Hex; messageHash: Hex; leafId: bigint }[]> {
83
+ const events = await this.outbox.getEvents.MessageConsumed({}, { blockHash: l1BlockHash, strict: true });
84
+ return events.map(event => ({
85
+ epoch: event.args.epoch!,
86
+ root: event.args.root!,
87
+ messageHash: event.args.messageHash!,
88
+ leafId: event.args.leafId!,
89
+ }));
90
+ }
91
+
92
+ private assertWallet(): GetContractReturnType<typeof OutboxAbi, ExtendedViemWalletClient> {
93
+ if (!isExtendedClient(this.client)) {
94
+ throw new Error('Wallet client is required for this operation');
95
+ }
96
+ return this.outbox as GetContractReturnType<typeof OutboxAbi, ExtendedViemWalletClient>;
97
+ }
98
+ }