@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.017a351

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 (285) 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 +28 -4
  6. package/dest/client.d.ts.map +1 -1
  7. package/dest/client.js +73 -3
  8. package/dest/config.d.ts +70 -23
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +151 -34
  11. package/dest/constants.d.ts +1 -1
  12. package/dest/contracts/chain_state_override.d.ts +78 -0
  13. package/dest/contracts/chain_state_override.d.ts.map +1 -0
  14. package/dest/contracts/chain_state_override.js +137 -0
  15. package/dest/contracts/empire_base.d.ts +25 -8
  16. package/dest/contracts/empire_base.d.ts.map +1 -1
  17. package/dest/contracts/empire_base.js +75 -2
  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 +59 -0
  24. package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
  25. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  26. package/dest/contracts/fee_asset_price_oracle.js +656 -0
  27. package/dest/contracts/fee_juice.d.ts +6 -7
  28. package/dest/contracts/fee_juice.d.ts.map +1 -1
  29. package/dest/contracts/fee_juice.js +27 -20
  30. package/dest/contracts/governance.d.ts +131 -43
  31. package/dest/contracts/governance.d.ts.map +1 -1
  32. package/dest/contracts/governance.js +281 -87
  33. package/dest/contracts/governance_proposer.d.ts +49 -13
  34. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  35. package/dest/contracts/governance_proposer.js +483 -26
  36. package/dest/contracts/gse.d.ts +32 -0
  37. package/dest/contracts/gse.d.ts.map +1 -0
  38. package/dest/contracts/gse.js +72 -0
  39. package/dest/contracts/inbox.d.ts +47 -0
  40. package/dest/contracts/inbox.d.ts.map +1 -0
  41. package/dest/contracts/inbox.js +85 -0
  42. package/dest/contracts/index.d.ts +11 -2
  43. package/dest/contracts/index.d.ts.map +1 -1
  44. package/dest/contracts/index.js +10 -1
  45. package/dest/contracts/log.d.ts +13 -0
  46. package/dest/contracts/log.d.ts.map +1 -0
  47. package/dest/contracts/log.js +1 -0
  48. package/dest/contracts/multicall.d.ts +136 -0
  49. package/dest/contracts/multicall.d.ts.map +1 -0
  50. package/dest/contracts/multicall.js +264 -0
  51. package/dest/contracts/outbox.d.ts +64 -0
  52. package/dest/contracts/outbox.d.ts.map +1 -0
  53. package/dest/contracts/outbox.js +113 -0
  54. package/dest/contracts/registry.d.ts +12 -5
  55. package/dest/contracts/registry.d.ts.map +1 -1
  56. package/dest/contracts/registry.js +74 -17
  57. package/dest/contracts/rollup.d.ts +5526 -52
  58. package/dest/contracts/rollup.d.ts.map +1 -1
  59. package/dest/contracts/rollup.js +1446 -118
  60. package/dest/contracts/slasher_contract.d.ts +44 -0
  61. package/dest/contracts/slasher_contract.d.ts.map +1 -0
  62. package/dest/contracts/slasher_contract.js +75 -0
  63. package/dest/contracts/slashing_proposer.d.ts +133 -15
  64. package/dest/contracts/slashing_proposer.d.ts.map +1 -1
  65. package/dest/contracts/slashing_proposer.js +293 -22
  66. package/dest/contracts/utils.d.ts +3 -0
  67. package/dest/contracts/utils.d.ts.map +1 -0
  68. package/dest/contracts/utils.js +11 -0
  69. package/dest/deploy_aztec_l1_contracts.d.ts +256 -0
  70. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  71. package/dest/deploy_aztec_l1_contracts.js +411 -0
  72. package/dest/deploy_l1_contract.d.ts +68 -0
  73. package/dest/deploy_l1_contract.d.ts.map +1 -0
  74. package/dest/deploy_l1_contract.js +312 -0
  75. package/dest/eth-signer/eth-signer.d.ts +21 -0
  76. package/dest/eth-signer/eth-signer.d.ts.map +1 -0
  77. package/dest/eth-signer/eth-signer.js +5 -0
  78. package/dest/eth-signer/index.d.ts +2 -0
  79. package/dest/eth-signer/index.d.ts.map +1 -0
  80. package/dest/eth-signer/index.js +1 -0
  81. package/dest/forwarder_proxy.d.ts +32 -0
  82. package/dest/forwarder_proxy.d.ts.map +1 -0
  83. package/dest/forwarder_proxy.js +93 -0
  84. package/dest/generated/l1-contracts-defaults.d.ts +30 -0
  85. package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
  86. package/dest/generated/l1-contracts-defaults.js +30 -0
  87. package/dest/l1_artifacts.d.ts +79270 -0
  88. package/dest/l1_artifacts.d.ts.map +1 -0
  89. package/dest/l1_artifacts.js +151 -0
  90. package/dest/l1_contract_addresses.d.ts +61 -45
  91. package/dest/l1_contract_addresses.d.ts.map +1 -1
  92. package/dest/l1_contract_addresses.js +99 -76
  93. package/dest/l1_reader.d.ts +8 -6
  94. package/dest/l1_reader.d.ts.map +1 -1
  95. package/dest/l1_reader.js +20 -12
  96. package/dest/l1_tx_utils/config.d.ts +65 -0
  97. package/dest/l1_tx_utils/config.d.ts.map +1 -0
  98. package/dest/l1_tx_utils/config.js +109 -0
  99. package/dest/l1_tx_utils/constants.d.ts +12 -0
  100. package/dest/l1_tx_utils/constants.d.ts.map +1 -0
  101. package/dest/l1_tx_utils/constants.js +39 -0
  102. package/dest/l1_tx_utils/factory.d.ts +32 -0
  103. package/dest/l1_tx_utils/factory.d.ts.map +1 -0
  104. package/dest/l1_tx_utils/factory.js +22 -0
  105. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  106. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  107. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  108. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  109. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  110. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  111. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  112. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  113. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  114. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  115. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  116. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  117. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  118. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  119. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
  120. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  121. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  122. package/dest/l1_tx_utils/index-blobs.js +2 -0
  123. package/dest/l1_tx_utils/index.d.ts +13 -0
  124. package/dest/l1_tx_utils/index.d.ts.map +1 -0
  125. package/dest/l1_tx_utils/index.js +13 -0
  126. package/dest/l1_tx_utils/interfaces.d.ts +76 -0
  127. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
  128. package/dest/l1_tx_utils/interfaces.js +4 -0
  129. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
  130. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  131. package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
  132. package/dest/l1_tx_utils/l1_tx_utils.d.ts +113 -0
  133. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
  134. package/dest/l1_tx_utils/l1_tx_utils.js +658 -0
  135. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +83 -0
  136. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
  137. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +328 -0
  138. package/dest/l1_tx_utils/signer.d.ts +4 -0
  139. package/dest/l1_tx_utils/signer.d.ts.map +1 -0
  140. package/dest/l1_tx_utils/signer.js +16 -0
  141. package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
  142. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  143. package/dest/l1_tx_utils/tx_delayer.js +223 -0
  144. package/dest/l1_tx_utils/types.d.ts +67 -0
  145. package/dest/l1_tx_utils/types.d.ts.map +1 -0
  146. package/dest/l1_tx_utils/types.js +26 -0
  147. package/dest/l1_tx_utils/utils.d.ts +4 -0
  148. package/dest/l1_tx_utils/utils.d.ts.map +1 -0
  149. package/dest/l1_tx_utils/utils.js +14 -0
  150. package/dest/l1_types.d.ts +6 -0
  151. package/dest/l1_types.d.ts.map +1 -0
  152. package/dest/l1_types.js +1 -0
  153. package/dest/publisher_manager.d.ts +30 -0
  154. package/dest/publisher_manager.d.ts.map +1 -0
  155. package/dest/publisher_manager.js +162 -0
  156. package/dest/queries.d.ts +17 -4
  157. package/dest/queries.d.ts.map +1 -1
  158. package/dest/queries.js +120 -12
  159. package/dest/test/chain_monitor.d.ts +95 -0
  160. package/dest/test/chain_monitor.d.ts.map +1 -0
  161. package/dest/test/chain_monitor.js +249 -0
  162. package/dest/test/eth_cheat_codes.d.ts +237 -0
  163. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  164. package/dest/test/eth_cheat_codes.js +573 -0
  165. package/dest/test/eth_cheat_codes_with_state.d.ts +2 -2
  166. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
  167. package/dest/test/eth_cheat_codes_with_state.js +1 -1
  168. package/dest/test/index.d.ts +4 -3
  169. package/dest/test/index.d.ts.map +1 -1
  170. package/dest/test/index.js +3 -2
  171. package/dest/test/rollup_cheat_codes.d.ts +118 -0
  172. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  173. package/dest/test/rollup_cheat_codes.js +344 -0
  174. package/dest/test/start_anvil.d.ts +30 -2
  175. package/dest/test/start_anvil.d.ts.map +1 -1
  176. package/dest/test/start_anvil.js +147 -24
  177. package/dest/test/upgrade_utils.d.ts +6 -5
  178. package/dest/test/upgrade_utils.d.ts.map +1 -1
  179. package/dest/test/upgrade_utils.js +23 -16
  180. package/dest/types.d.ts +62 -8
  181. package/dest/types.d.ts.map +1 -1
  182. package/dest/types.js +3 -1
  183. package/dest/utils.d.ts +25 -4
  184. package/dest/utils.d.ts.map +1 -1
  185. package/dest/utils.js +142 -91
  186. package/dest/zkPassportVerifierAddress.d.ts +15 -0
  187. package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
  188. package/dest/zkPassportVerifierAddress.js +11 -0
  189. package/package.json +52 -26
  190. package/src/account.ts +5 -0
  191. package/src/client.ts +107 -5
  192. package/src/config.ts +218 -43
  193. package/src/contracts/README.md +157 -0
  194. package/src/contracts/chain_state_override.ts +200 -0
  195. package/src/contracts/empire_base.ts +77 -7
  196. package/src/contracts/errors.ts +13 -0
  197. package/src/contracts/fee_asset_handler.ts +66 -0
  198. package/src/contracts/fee_asset_price_oracle.ts +285 -0
  199. package/src/contracts/fee_juice.ts +29 -15
  200. package/src/contracts/governance.ts +343 -74
  201. package/src/contracts/governance_proposer.ts +128 -25
  202. package/src/contracts/gse.ts +88 -0
  203. package/src/contracts/inbox.ts +123 -0
  204. package/src/contracts/index.ts +10 -1
  205. package/src/contracts/log.ts +13 -0
  206. package/src/contracts/multicall.ts +296 -0
  207. package/src/contracts/outbox.ts +132 -0
  208. package/src/contracts/registry.ts +81 -26
  209. package/src/contracts/rollup.ts +1246 -90
  210. package/src/contracts/slasher_contract.ts +89 -0
  211. package/src/contracts/slashing_proposer.ts +296 -27
  212. package/src/contracts/utils.ts +14 -0
  213. package/src/deploy_aztec_l1_contracts.ts +646 -0
  214. package/src/deploy_l1_contract.ts +362 -0
  215. package/src/eth-signer/eth-signer.ts +25 -0
  216. package/src/eth-signer/index.ts +1 -0
  217. package/src/forwarder_proxy.ts +108 -0
  218. package/src/generated/l1-contracts-defaults.ts +32 -0
  219. package/src/l1_artifacts.ts +231 -0
  220. package/src/l1_contract_addresses.ts +121 -80
  221. package/src/l1_reader.ts +31 -16
  222. package/src/l1_tx_utils/README.md +177 -0
  223. package/src/l1_tx_utils/config.ts +181 -0
  224. package/src/l1_tx_utils/constants.ts +29 -0
  225. package/src/l1_tx_utils/factory.ts +64 -0
  226. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  227. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
  228. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
  229. package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
  230. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +108 -0
  231. package/src/l1_tx_utils/index-blobs.ts +2 -0
  232. package/src/l1_tx_utils/index.ts +15 -0
  233. package/src/l1_tx_utils/interfaces.ts +86 -0
  234. package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
  235. package/src/l1_tx_utils/l1_tx_utils.ts +789 -0
  236. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +424 -0
  237. package/src/l1_tx_utils/signer.ts +28 -0
  238. package/src/l1_tx_utils/tx_delayer.ts +303 -0
  239. package/src/l1_tx_utils/types.ts +85 -0
  240. package/src/l1_tx_utils/utils.ts +16 -0
  241. package/src/l1_types.ts +6 -0
  242. package/src/publisher_manager.ts +203 -0
  243. package/src/queries.ts +149 -17
  244. package/src/test/chain_monitor.ts +307 -0
  245. package/src/test/eth_cheat_codes.ts +600 -0
  246. package/src/test/eth_cheat_codes_with_state.ts +1 -1
  247. package/src/test/index.ts +3 -2
  248. package/src/test/rollup_cheat_codes.ts +388 -0
  249. package/src/test/start_anvil.ts +189 -22
  250. package/src/test/upgrade_utils.ts +30 -21
  251. package/src/types.ts +71 -7
  252. package/src/utils.ts +164 -96
  253. package/src/zkPassportVerifierAddress.ts +15 -0
  254. package/dest/contracts/forwarder.d.ts +0 -24
  255. package/dest/contracts/forwarder.d.ts.map +0 -1
  256. package/dest/contracts/forwarder.js +0 -101
  257. package/dest/deploy_l1_contracts.d.ts +0 -21210
  258. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  259. package/dest/deploy_l1_contracts.js +0 -687
  260. package/dest/eth_cheat_codes.d.ts +0 -147
  261. package/dest/eth_cheat_codes.d.ts.map +0 -1
  262. package/dest/eth_cheat_codes.js +0 -303
  263. package/dest/index.d.ts +0 -14
  264. package/dest/index.d.ts.map +0 -1
  265. package/dest/index.js +0 -13
  266. package/dest/l1_tx_utils.d.ts +0 -192
  267. package/dest/l1_tx_utils.d.ts.map +0 -1
  268. package/dest/l1_tx_utils.js +0 -641
  269. package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
  270. package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
  271. package/dest/l1_tx_utils_with_blobs.js +0 -64
  272. package/dest/test/delayed_tx_utils.d.ts +0 -8
  273. package/dest/test/delayed_tx_utils.d.ts.map +0 -1
  274. package/dest/test/delayed_tx_utils.js +0 -21
  275. package/dest/test/tx_delayer.d.ts +0 -25
  276. package/dest/test/tx_delayer.d.ts.map +0 -1
  277. package/dest/test/tx_delayer.js +0 -116
  278. package/src/contracts/forwarder.ts +0 -132
  279. package/src/deploy_l1_contracts.ts +0 -948
  280. package/src/eth_cheat_codes.ts +0 -314
  281. package/src/index.ts +0 -13
  282. package/src/l1_tx_utils.ts +0 -847
  283. package/src/l1_tx_utils_with_blobs.ts +0 -86
  284. package/src/test/delayed_tx_utils.ts +0 -24
  285. package/src/test/tx_delayer.ts +0 -163
@@ -1,17 +1,40 @@
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 { ReadOnlyGovernanceContract, 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
+ /**
24
+ * Cache of bytecode-existence checks keyed by payload address. The check is stable for a
25
+ * contract's lifetime -- a contract either has code or it does not, and code cannot be removed
26
+ * after deployment (selfdestruct aside, which is not relevant here). Safe to memoize
27
+ * indefinitely for the lifetime of this instance.
28
+ */
29
+ private readonly emptyPayloadCache: Map<Hex, boolean> = new Map();
30
+
31
+ constructor(
32
+ public readonly client: ViemClient,
33
+ address: Hex | EthAddress,
34
+ ) {
35
+ if (address instanceof EthAddress) {
36
+ address = address.toString();
37
+ }
15
38
  this.proposer = getContract({ address, abi: GovernanceProposerAbi, client });
16
39
  }
17
40
 
@@ -29,54 +52,134 @@ export class GovernanceProposerContract implements IEmpireBase {
29
52
  }
30
53
 
31
54
  public getQuorumSize(): Promise<bigint> {
32
- return this.proposer.read.N();
55
+ return this.proposer.read.QUORUM_SIZE();
33
56
  }
34
57
 
35
58
  public getRoundSize(): Promise<bigint> {
36
- return this.proposer.read.M();
59
+ return this.proposer.read.ROUND_SIZE();
60
+ }
61
+
62
+ public getInstance() {
63
+ return this.proposer.read.getInstance();
37
64
  }
38
65
 
39
- public computeRound(slot: bigint): Promise<bigint> {
40
- return this.proposer.read.computeRound([slot]);
66
+ public computeRound(slot: SlotNumber): Promise<bigint> {
67
+ return this.proposer.read.computeRound([BigInt(slot)]);
41
68
  }
42
69
 
43
70
  public async getRoundInfo(
44
71
  rollupAddress: Hex,
45
72
  round: bigint,
46
- ): Promise<{ lastVote: bigint; leader: Hex; executed: boolean }> {
47
- const roundInfo = await this.proposer.read.rounds([rollupAddress, round]);
73
+ ): Promise<{ lastSignalSlot: SlotNumber; payloadWithMostSignals: Hex; quorumReached: boolean; executed: boolean }> {
74
+ const result = await this.proposer.read.getRoundData([rollupAddress, round]);
75
+ const [signalCount, quorum] = await Promise.all([
76
+ this.proposer.read.signalCount([rollupAddress, round, result.payloadWithMostSignals]),
77
+ this.getQuorumSize(),
78
+ ]);
48
79
  return {
49
- lastVote: roundInfo[0],
50
- leader: roundInfo[1],
51
- executed: roundInfo[2],
80
+ lastSignalSlot: SlotNumber.fromBigInt(result.lastSignalSlot),
81
+ payloadWithMostSignals: result.payloadWithMostSignals,
82
+ quorumReached: signalCount >= quorum,
83
+ executed: result.executed,
52
84
  };
53
85
  }
54
86
 
55
- public getProposalVotes(rollupAddress: Hex, round: bigint, proposal: Hex): Promise<bigint> {
56
- return this.proposer.read.yeaCount([rollupAddress, round, proposal]);
87
+ public getPayloadSignals(rollupAddress: Hex, round: bigint, payload: Hex): Promise<bigint> {
88
+ return this.proposer.read.signalCount([rollupAddress, round, payload]);
89
+ }
90
+
91
+ public createSignalRequest(payload: Hex): L1TxRequest {
92
+ return {
93
+ to: this.address.toString(),
94
+ abi: GovernanceProposerAbi,
95
+ data: encodeSignal(payload),
96
+ };
57
97
  }
58
98
 
59
- public createVoteRequest(payload: Hex): L1TxRequest {
99
+ public async createSignalRequestWithSignature(
100
+ payload: Hex,
101
+ slot: SlotNumber,
102
+ chainId: number,
103
+ signerAddress: Hex,
104
+ signer: (msg: TypedDataDefinition) => Promise<Hex>,
105
+ ): Promise<L1TxRequest> {
106
+ const signature = await signSignalWithSig(
107
+ signer,
108
+ payload,
109
+ slot,
110
+ await this.getInstance(),
111
+ this.address.toString(),
112
+ chainId,
113
+ );
60
114
  return {
61
115
  to: this.address.toString(),
62
- data: encodeVote(payload),
116
+ abi: GovernanceProposerAbi,
117
+ data: encodeSignalWithSignature(payload, signature),
63
118
  };
64
119
  }
65
120
 
66
- public executeProposal(
121
+ /**
122
+ * Resolves the Governance contract this proposer submits winners to. Lazily reads
123
+ * `GovernanceProposer.getGovernance()` (which itself looks the address up via the registry) and
124
+ * memoizes the resulting wrapper.
125
+ */
126
+ @memoize
127
+ public async getGovernance(): Promise<ReadOnlyGovernanceContract> {
128
+ const address = await this.proposer.read.getGovernance();
129
+ return new ReadOnlyGovernanceContract(address, this.client);
130
+ }
131
+
132
+ /**
133
+ * Returns true iff the given original payload is currently the subject of a live (non-terminal)
134
+ * Governance proposal. Delegates to `ReadOnlyGovernanceContract.hasActiveProposalWithPayload`, which
135
+ * implements the actual sweep against the Governance contract -- this method exists only as a
136
+ * convenience wrapper so callers that already hold a GovernanceProposer reference don't have to
137
+ * resolve the Governance address themselves.
138
+ */
139
+ public async hasActiveProposalWithPayload(payload: Hex): Promise<boolean> {
140
+ const governance = await this.getGovernance();
141
+ return governance.hasActiveProposalWithPayload(payload);
142
+ }
143
+
144
+ /**
145
+ * Returns true if the given payload address has no deployed bytecode. Used as a cheap
146
+ * pre-flight check before casting a governance signal — voting for a zero-code address
147
+ * is unrecoverable.
148
+ *
149
+ * We only cache the `false` result (address has bytecode). The `true` result is NOT
150
+ * cached because a CREATE2-redeployed address could go from empty to populated, and
151
+ * caching `true` would make us keep skipping a payload that later becomes valid.
152
+ */
153
+ public async isPayloadEmpty(payload: EthAddress): Promise<boolean> {
154
+ const key = payload.toString() as Hex;
155
+ if (this.emptyPayloadCache.get(key) === false) {
156
+ return false;
157
+ }
158
+ const code = await this.client.getCode({ address: key });
159
+ const isEmpty = !code || code === '0x';
160
+ if (!isEmpty) {
161
+ this.emptyPayloadCache.set(key, false);
162
+ }
163
+ return isEmpty;
164
+ }
165
+
166
+ public async submitRoundWinner(
67
167
  round: bigint,
68
168
  l1TxUtils: L1TxUtils,
69
169
  ): Promise<{
70
170
  receipt: TransactionReceipt;
71
- gasPrice: GasPrice;
171
+ proposalId: bigint;
72
172
  }> {
73
- return l1TxUtils.sendAndMonitorTransaction({
173
+ const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
74
174
  to: this.address.toString(),
175
+ abi: GovernanceProposerAbi,
75
176
  data: encodeFunctionData({
76
- abi: this.proposer.abi,
77
- functionName: 'executeProposal',
177
+ abi: GovernanceProposerAbi,
178
+ functionName: 'submitRoundWinner',
78
179
  args: [round],
79
180
  }),
80
181
  });
182
+ const proposalId = extractProposalIdFromLogs(receipt.logs);
183
+ return { receipt, proposalId };
81
184
  }
82
185
  }
@@ -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,123 @@
1
+ import { maxBigint } from '@aztec/foundation/bigint';
2
+ import { CheckpointNumber } from '@aztec/foundation/branded-types';
3
+ import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
+ import { EthAddress } from '@aztec/foundation/eth-address';
6
+ import { InboxAbi } from '@aztec/l1-artifacts/InboxAbi';
7
+
8
+ import { type BlockTag, type GetContractReturnType, type Hex, getContract } from 'viem';
9
+
10
+ import { getPublicClient } from '../client.js';
11
+ import type { DeployAztecL1ContractsReturnType } from '../deploy_aztec_l1_contracts.js';
12
+ import type { L1ReaderConfig } from '../l1_reader.js';
13
+ import type { ViemClient } from '../types.js';
14
+ import type { L1EventLog } from './log.js';
15
+ import { checkBlockTag } from './utils.js';
16
+
17
+ /** Arguments for the MessageSent event. */
18
+ export type MessageSentArgs = {
19
+ index: bigint;
20
+ leaf: Fr;
21
+ checkpointNumber: CheckpointNumber;
22
+ rollingHash: Buffer16;
23
+ };
24
+
25
+ /** Log type for MessageSent events. */
26
+ export type MessageSentLog = L1EventLog<MessageSentArgs>;
27
+
28
+ export class InboxContract {
29
+ private readonly inbox: GetContractReturnType<typeof InboxAbi, ViemClient>;
30
+
31
+ static getFromL1ContractsValues(deployL1ContractsValues: DeployAztecL1ContractsReturnType) {
32
+ const {
33
+ l1Client,
34
+ l1ContractAddresses: { inboxAddress },
35
+ } = deployL1ContractsValues;
36
+ return new InboxContract(l1Client, inboxAddress.toString());
37
+ }
38
+
39
+ static getFromConfig(config: L1ReaderConfig) {
40
+ const client = getPublicClient(config);
41
+ const address = config.inboxAddress.toString();
42
+ return new InboxContract(client, address);
43
+ }
44
+
45
+ constructor(
46
+ public readonly client: ViemClient,
47
+ address: Hex | EthAddress,
48
+ ) {
49
+ if (address instanceof EthAddress) {
50
+ address = address.toString();
51
+ }
52
+ this.inbox = getContract({ address, abi: InboxAbi, client });
53
+ }
54
+
55
+ public get address() {
56
+ return this.inbox.address;
57
+ }
58
+
59
+ public getContract(): GetContractReturnType<typeof InboxAbi, ViemClient> {
60
+ return this.inbox;
61
+ }
62
+
63
+ public async getLag(opts: { blockTag?: BlockTag; blockNumber?: bigint } = {}): Promise<bigint> {
64
+ await checkBlockTag(opts.blockNumber, this.client);
65
+ return await this.inbox.read.LAG(opts);
66
+ }
67
+
68
+ public async getState(opts: { blockTag?: BlockTag; blockNumber?: bigint } = {}): Promise<InboxContractState> {
69
+ await checkBlockTag(opts.blockNumber, this.client);
70
+ const state = await this.inbox.read.getState(opts);
71
+ return {
72
+ totalMessagesInserted: state.totalMessagesInserted,
73
+ messagesRollingHash: Buffer16.fromString(state.rollingHash),
74
+ treeInProgress: state.inProgress,
75
+ };
76
+ }
77
+
78
+ /** Fetches MessageSent events within the given block range. */
79
+ async getMessageSentEvents(fromBlock: bigint, toBlock: bigint): Promise<MessageSentLog[]> {
80
+ const logs = await this.inbox.getEvents.MessageSent({}, { fromBlock, toBlock });
81
+ return logs
82
+ .filter(log => log.blockNumber! >= fromBlock && log.blockNumber! <= toBlock)
83
+ .map(log => this.mapMessageSentLog(log));
84
+ }
85
+
86
+ /** Fetches MessageSent events for a specific message hash around a specific block. */
87
+ async getMessageSentEventByHash(msgHash: Hex, aroundL1BlockNumber: bigint): Promise<MessageSentLog> {
88
+ // We don't use blockHash here because we don't want the query to throw if the L1 block number no longer exists on chain
89
+ // due to an L1 reorg. The use case for this method is usually checking if a message still exists on the Inbox after
90
+ // a reorg, so it's possible the message was moved one block up or down, and that the original L1 block where we
91
+ // saw it no longer exists, rendering the block-by-hash approach invalid.
92
+ const [log] = await this.inbox.getEvents.MessageSent(
93
+ { hash: msgHash },
94
+ { fromBlock: maxBigint(aroundL1BlockNumber - 5n, 1n), toBlock: aroundL1BlockNumber + 5n },
95
+ );
96
+ return log && this.mapMessageSentLog(log);
97
+ }
98
+
99
+ private mapMessageSentLog(log: {
100
+ blockNumber: bigint | null;
101
+ blockHash: `0x${string}` | null;
102
+ transactionHash: `0x${string}` | null;
103
+ args: { index?: bigint; hash?: `0x${string}`; checkpointNumber?: bigint; rollingHash?: `0x${string}` };
104
+ }): MessageSentLog {
105
+ return {
106
+ l1BlockNumber: log.blockNumber!,
107
+ l1BlockHash: Buffer32.fromString(log.blockHash!),
108
+ l1TransactionHash: log.transactionHash!,
109
+ args: {
110
+ index: log.args.index!,
111
+ leaf: Fr.fromString(log.args.hash!),
112
+ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
113
+ rollingHash: Buffer16.fromString(log.args.rollingHash!),
114
+ },
115
+ };
116
+ }
117
+ }
118
+
119
+ export type InboxContractState = {
120
+ totalMessagesInserted: bigint;
121
+ messagesRollingHash: Buffer16;
122
+ treeInProgress: bigint;
123
+ };
@@ -1,8 +1,17 @@
1
+ export * from './chain_state_override.js';
1
2
  export * from './empire_base.js';
3
+ export * from './errors.js';
4
+ export * from './fee_asset_handler.js';
5
+ export * from './fee_asset_price_oracle.js';
2
6
  export * from './fee_juice.js';
3
- export * from './forwarder.js';
4
7
  export * from './governance.js';
5
8
  export * from './governance_proposer.js';
9
+ export * from './gse.js';
10
+ export * from './inbox.js';
11
+ export * from './log.js';
12
+ export * from './multicall.js';
13
+ export * from './outbox.js';
6
14
  export * from './registry.js';
7
15
  export * from './rollup.js';
8
16
  export * from './slashing_proposer.js';
17
+ export * from './slasher_contract.js';
@@ -0,0 +1,13 @@
1
+ import type { Buffer32 } from '@aztec/foundation/buffer';
2
+
3
+ /** Base L1 event log with common fields. */
4
+ export type L1EventLog<T> = {
5
+ /** L1 block number where the event was emitted. */
6
+ l1BlockNumber: bigint;
7
+ /** L1 block hash. */
8
+ l1BlockHash: Buffer32;
9
+ /** L1 transaction hash that emitted the event. */
10
+ l1TransactionHash: `0x${string}`;
11
+ /** Event-specific arguments. */
12
+ args: T;
13
+ };