@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.001888fc

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 (289) 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 +14 -4
  6. package/dest/client.d.ts.map +1 -1
  7. package/dest/client.js +27 -3
  8. package/dest/config.d.ts +70 -23
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +155 -34
  11. package/dest/constants.d.ts +1 -1
  12. package/dest/contracts/empire_base.d.ts +27 -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 +69 -0
  16. package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -0
  17. package/dest/contracts/empire_slashing_proposer.js +216 -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 +59 -0
  24. package/dest/contracts/fee_asset_price_oracle.d.ts +101 -0
  25. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  26. package/dest/contracts/fee_asset_price_oracle.js +651 -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 +45 -32
  31. package/dest/contracts/governance.d.ts.map +1 -1
  32. package/dest/contracts/governance.js +98 -85
  33. package/dest/contracts/governance_proposer.d.ts +19 -13
  34. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  35. package/dest/contracts/governance_proposer.js +441 -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 +80 -0
  42. package/dest/contracts/index.d.ts +12 -3
  43. package/dest/contracts/index.d.ts.map +1 -1
  44. package/dest/contracts/index.js +11 -2
  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 +21 -0
  49. package/dest/contracts/multicall.d.ts.map +1 -0
  50. package/dest/contracts/multicall.js +157 -0
  51. package/dest/contracts/outbox.d.ts +41 -0
  52. package/dest/contracts/outbox.d.ts.map +1 -0
  53. package/dest/contracts/outbox.js +86 -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 +311 -53
  58. package/dest/contracts/rollup.d.ts.map +1 -1
  59. package/dest/contracts/rollup.js +1180 -116
  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/tally_slashing_proposer.d.ts +140 -0
  64. package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -0
  65. package/dest/contracts/tally_slashing_proposer.js +320 -0
  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 +259 -0
  70. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  71. package/dest/deploy_aztec_l1_contracts.js +413 -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 +81744 -0
  88. package/dest/l1_artifacts.d.ts.map +1 -0
  89. package/dest/l1_artifacts.js +166 -0
  90. package/dest/l1_contract_addresses.d.ts +24 -4
  91. package/dest/l1_contract_addresses.d.ts.map +1 -1
  92. package/dest/l1_contract_addresses.js +25 -21
  93. package/dest/l1_reader.d.ts +6 -2
  94. package/dest/l1_reader.d.ts.map +1 -1
  95. package/dest/l1_reader.js +20 -9
  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 +105 -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 +639 -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 +327 -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 +56 -0
  142. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  143. package/dest/l1_tx_utils/tx_delayer.js +221 -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 +16 -0
  154. package/dest/publisher_manager.d.ts.map +1 -0
  155. package/dest/publisher_manager.js +88 -0
  156. package/dest/queries.d.ts +5 -3
  157. package/dest/queries.d.ts.map +1 -1
  158. package/dest/queries.js +61 -12
  159. package/dest/test/chain_monitor.d.ts +94 -0
  160. package/dest/test/chain_monitor.d.ts.map +1 -0
  161. package/dest/test/chain_monitor.js +244 -0
  162. package/dest/test/eth_cheat_codes.d.ts +229 -0
  163. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  164. package/dest/test/eth_cheat_codes.js +560 -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 +90 -0
  172. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  173. package/dest/test/rollup_cheat_codes.js +292 -0
  174. package/dest/test/start_anvil.d.ts +23 -2
  175. package/dest/test/start_anvil.d.ts.map +1 -1
  176. package/dest/test/start_anvil.js +133 -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 +17 -3
  184. package/dest/utils.d.ts.map +1 -1
  185. package/dest/utils.js +111 -88
  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 +51 -25
  190. package/src/account.ts +5 -0
  191. package/src/client.ts +51 -5
  192. package/src/config.ts +222 -43
  193. package/src/contracts/README.md +157 -0
  194. package/src/contracts/empire_base.ts +79 -7
  195. package/src/contracts/empire_slashing_proposer.ts +265 -0
  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 +280 -0
  199. package/src/contracts/fee_juice.ts +29 -15
  200. package/src/contracts/governance.ts +90 -78
  201. package/src/contracts/governance_proposer.ts +81 -25
  202. package/src/contracts/gse.ts +88 -0
  203. package/src/contracts/inbox.ts +115 -0
  204. package/src/contracts/index.ts +11 -2
  205. package/src/contracts/log.ts +13 -0
  206. package/src/contracts/multicall.ts +158 -0
  207. package/src/contracts/outbox.ts +98 -0
  208. package/src/contracts/registry.ts +81 -26
  209. package/src/contracts/rollup.ts +940 -89
  210. package/src/contracts/slasher_contract.ts +89 -0
  211. package/src/contracts/tally_slashing_proposer.ts +322 -0
  212. package/src/contracts/utils.ts +14 -0
  213. package/src/deploy_aztec_l1_contracts.ts +650 -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 +254 -0
  220. package/src/l1_contract_addresses.ts +49 -34
  221. package/src/l1_reader.ts +30 -10
  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 +766 -0
  236. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +423 -0
  237. package/src/l1_tx_utils/signer.ts +28 -0
  238. package/src/l1_tx_utils/tx_delayer.ts +294 -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 +108 -0
  243. package/src/queries.ts +82 -16
  244. package/src/test/chain_monitor.ts +302 -0
  245. package/src/test/eth_cheat_codes.ts +588 -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 +330 -0
  249. package/src/test/start_anvil.ts +166 -22
  250. package/src/test/upgrade_utils.ts +30 -21
  251. package/src/types.ts +71 -7
  252. package/src/utils.ts +137 -93
  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/contracts/slashing_proposer.d.ts +0 -21
  258. package/dest/contracts/slashing_proposer.d.ts.map +0 -1
  259. package/dest/contracts/slashing_proposer.js +0 -47
  260. package/dest/deploy_l1_contracts.d.ts +0 -21210
  261. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  262. package/dest/deploy_l1_contracts.js +0 -687
  263. package/dest/eth_cheat_codes.d.ts +0 -147
  264. package/dest/eth_cheat_codes.d.ts.map +0 -1
  265. package/dest/eth_cheat_codes.js +0 -303
  266. package/dest/index.d.ts +0 -14
  267. package/dest/index.d.ts.map +0 -1
  268. package/dest/index.js +0 -13
  269. package/dest/l1_tx_utils.d.ts +0 -192
  270. package/dest/l1_tx_utils.d.ts.map +0 -1
  271. package/dest/l1_tx_utils.js +0 -641
  272. package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
  273. package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
  274. package/dest/l1_tx_utils_with_blobs.js +0 -64
  275. package/dest/test/delayed_tx_utils.d.ts +0 -8
  276. package/dest/test/delayed_tx_utils.d.ts.map +0 -1
  277. package/dest/test/delayed_tx_utils.js +0 -21
  278. package/dest/test/tx_delayer.d.ts +0 -25
  279. package/dest/test/tx_delayer.d.ts.map +0 -1
  280. package/dest/test/tx_delayer.js +0 -116
  281. package/src/contracts/forwarder.ts +0 -132
  282. package/src/contracts/slashing_proposer.ts +0 -51
  283. package/src/deploy_l1_contracts.ts +0 -948
  284. package/src/eth_cheat_codes.ts +0 -314
  285. package/src/index.ts +0 -13
  286. package/src/l1_tx_utils.ts +0 -847
  287. package/src/l1_tx_utils_with_blobs.ts +0 -86
  288. package/src/test/delayed_tx_utils.ts +0 -24
  289. package/src/test/tx_delayer.ts +0 -163
package/src/client.ts CHANGED
@@ -1,20 +1,41 @@
1
1
  import type { Logger } from '@aztec/foundation/log';
2
2
  import { retryUntil } from '@aztec/foundation/retry';
3
3
 
4
- import { createPublicClient, fallback, http } from 'viem';
4
+ import {
5
+ type Chain,
6
+ type HDAccount,
7
+ type LocalAccount,
8
+ type PrivateKeyAccount,
9
+ createPublicClient,
10
+ createWalletClient,
11
+ fallback,
12
+ http,
13
+ publicActions,
14
+ } from 'viem';
15
+ import { mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
16
+ import { foundry } from 'viem/chains';
5
17
 
6
18
  import { createEthereumChain } from './chain.js';
7
- import type { ViemPublicClient } from './types.js';
19
+ import type { ExtendedViemWalletClient, ViemPublicClient } from './types.js';
8
20
 
9
21
  type Config = {
10
- /** The RPC Url of the ethereum host. */
22
+ /** List of URLs of Ethereum RPC nodes that services will connect to (comma separated). */
11
23
  l1RpcUrls: string[];
12
24
  /** The chain ID of the ethereum host. */
13
25
  l1ChainId: number;
14
26
  /** The polling interval viem uses in ms */
15
27
  viemPollingIntervalMS?: number;
28
+ /** Timeout for HTTP requests to the L1 RPC node in ms. */
29
+ l1HttpTimeoutMS?: number;
16
30
  };
17
31
 
32
+ export type { Config as EthereumClientConfig };
33
+
34
+ /** Creates a viem fallback HTTP transport for the given L1 RPC URLs. */
35
+ export function makeL1HttpTransport(rpcUrls: string[], opts?: { timeout?: number }) {
36
+ return fallback(rpcUrls.map(url => http(url, { batch: false, timeout: opts?.timeout })));
37
+ }
38
+
18
39
  // TODO: Use these methods to abstract the creation of viem clients.
19
40
 
20
41
  /** Returns a viem public client given the L1 config. */
@@ -22,7 +43,7 @@ export function getPublicClient(config: Config): ViemPublicClient {
22
43
  const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
23
44
  return createPublicClient({
24
45
  chain: chain.chainInfo,
25
- transport: fallback(config.l1RpcUrls.map(url => http(url))),
46
+ transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
26
47
  pollingInterval: config.viemPollingIntervalMS,
27
48
  });
28
49
  }
@@ -40,7 +61,7 @@ async function waitForRpc(client: ViemPublicClient, config: Config, logger?: Log
40
61
  let chainId = 0;
41
62
  try {
42
63
  chainId = await client.getChainId();
43
- } catch (err) {
64
+ } catch {
44
65
  logger?.warn(`Failed to connect to Ethereum node at ${config.l1RpcUrls.join(', ')}. Retrying...`);
45
66
  }
46
67
  return chainId;
@@ -56,3 +77,28 @@ async function waitForRpc(client: ViemPublicClient, config: Config, logger?: Log
56
77
  );
57
78
  }
58
79
  }
80
+
81
+ export function createExtendedL1Client(
82
+ rpcUrls: string[],
83
+ mnemonicOrPrivateKeyOrHdAccount: string | HDAccount | PrivateKeyAccount | LocalAccount,
84
+ chain: Chain = foundry,
85
+ pollingIntervalMS?: number,
86
+ addressIndex?: number,
87
+ opts?: { httpTimeoutMS?: number },
88
+ ): ExtendedViemWalletClient {
89
+ const hdAccount =
90
+ typeof mnemonicOrPrivateKeyOrHdAccount === 'string'
91
+ ? mnemonicOrPrivateKeyOrHdAccount.startsWith('0x')
92
+ ? privateKeyToAccount(mnemonicOrPrivateKeyOrHdAccount as `0x${string}`)
93
+ : mnemonicToAccount(mnemonicOrPrivateKeyOrHdAccount, { addressIndex })
94
+ : mnemonicOrPrivateKeyOrHdAccount;
95
+
96
+ const extendedClient = createWalletClient({
97
+ account: hdAccount,
98
+ chain,
99
+ transport: makeL1HttpTransport(rpcUrls, { timeout: opts?.httpTimeoutMS }),
100
+ pollingInterval: pollingIntervalMS,
101
+ }).extend(publicActions);
102
+
103
+ return extendedClient;
104
+ }
package/src/config.ts CHANGED
@@ -1,11 +1,27 @@
1
1
  import {
2
2
  type ConfigMappingsType,
3
3
  bigintConfigHelper,
4
+ booleanConfigHelper,
5
+ enumConfigHelper,
4
6
  getConfigFromMappings,
7
+ getDefaultConfig,
5
8
  numberConfigHelper,
9
+ omitConfigMappings,
10
+ optionalNumberConfigHelper,
6
11
  } from '@aztec/foundation/config';
12
+ import { EthAddress } from '@aztec/foundation/eth-address';
7
13
 
8
- import { type L1TxUtilsConfig, l1TxUtilsConfigMappings } from './l1_tx_utils.js';
14
+ import { l1ContractsDefaultEnv } from './generated/l1-contracts-defaults.js';
15
+ import { type L1TxUtilsConfig, l1TxUtilsConfigMappings } from './l1_tx_utils/config.js';
16
+
17
+ export type GenesisStateConfig = {
18
+ /** Whether to populate the genesis state with initial fee juice for the test accounts */
19
+ testAccounts: boolean;
20
+ /** Whether to populate the genesis state with initial fee juice for the sponsored FPC */
21
+ sponsoredFPC: boolean;
22
+ /** Additional addresses to prefund with fee juice at genesis */
23
+ prefundAddresses: string[];
24
+ };
9
25
 
10
26
  export type L1ContractsConfig = {
11
27
  /** How many seconds an L1 slot lasts. */
@@ -16,88 +32,251 @@ export type L1ContractsConfig = {
16
32
  aztecEpochDuration: number;
17
33
  /** The target validator committee size. */
18
34
  aztecTargetCommitteeSize: number;
19
- /** The number of L2 slots that we can wait for a proof of an epoch to be produced. */
20
- aztecProofSubmissionWindow: number;
35
+ /** The number of epochs to lag behind the current epoch for validator selection. */
36
+ lagInEpochsForValidatorSet: number;
37
+ /** The number of epochs to lag behind the current epoch for randao selection. */
38
+ lagInEpochsForRandao: number;
39
+ /** The number of checkpoints to lag in the inbox (prevents sequencer DOS attacks). */
40
+ inboxLag: number;
41
+ /** The number of epochs after an epoch ends that proofs are still accepted. */
42
+ aztecProofSubmissionEpochs: number;
43
+ /** The deposit amount for a validator */
44
+ activationThreshold: bigint;
21
45
  /** The minimum stake for a validator. */
22
- minimumStake: bigint;
23
- /** The slashing quorum */
24
- slashingQuorum: number;
25
- /** The slashing round size */
26
- slashingRoundSize: number;
27
- /** Governance proposing quorum */
28
- governanceProposerQuorum: number;
46
+ ejectionThreshold: bigint;
47
+ /** The local ejection threshold for a validator. Stricter than ejectionThreshold but local to a specific rollup */
48
+ localEjectionThreshold: bigint;
49
+ /** The slashing quorum, i.e. how many slots must signal for the same payload in a round for it to be submittable to the Slasher (defaults to slashRoundSize / 2 + 1) */
50
+ slashingQuorum?: number;
51
+ /** The slashing round size, i.e. how many epochs are in a slashing round */
52
+ slashingRoundSizeInEpochs: number;
53
+ /** The slashing lifetime in rounds. I.e., if 1, round N must be submitted before round N + 2 */
54
+ slashingLifetimeInRounds: number;
55
+ /** The slashing execution delay in rounds. I.e., if 1, round N may not be submitted until round N + 2 */
56
+ slashingExecutionDelayInRounds: number;
57
+ /** The slashing vetoer. May blacklist a payload from being submitted. */
58
+ slashingVetoer: EthAddress;
59
+ /** How many slashing rounds back we slash (ie when slashing in round N, we slash for offenses committed during epochs of round N-offset) */
60
+ slashingOffsetInRounds: number;
61
+ /** How long slashing can be disabled for in seconds when vetoer disables it */
62
+ slashingDisableDuration: number;
63
+ /** Type of slasher proposer */
64
+ slasherFlavor: 'empire' | 'tally' | 'none';
65
+ /** Minimum amount that can be slashed in tally slashing */
66
+ slashAmountSmall: bigint;
67
+ /** Medium amount to slash in tally slashing */
68
+ slashAmountMedium: bigint;
69
+ /** Largest amount that can be slashed per round in tally slashing */
70
+ slashAmountLarge: bigint;
71
+ /** Governance proposing quorum (defaults to roundSize/2 + 1) */
72
+ governanceProposerQuorum?: number;
29
73
  /** Governance proposing round size */
30
74
  governanceProposerRoundSize: number;
75
+ /** Governance voting duration in seconds (only for local/devnet/next-net, default 3600) */
76
+ governanceVotingDuration?: number;
77
+ /** The mana target for the rollup */
78
+ manaTarget: bigint;
79
+ /** The proving cost per mana */
80
+ provingCostPerMana: bigint;
81
+ /** The initial ETH per fee asset price (with 1e12 precision) */
82
+ initialEthPerFeeAsset: bigint;
83
+ /** The number of seconds to wait for an exit */
84
+ exitDelaySeconds: number;
31
85
  } & L1TxUtilsConfig;
32
86
 
33
- export const DefaultL1ContractsConfig = {
34
- ethereumSlotDuration: 12,
35
- aztecSlotDuration: 24,
36
- aztecEpochDuration: 16,
37
- aztecTargetCommitteeSize: 48,
38
- aztecProofSubmissionWindow: 31, // you have a full epoch to submit a proof after the epoch to prove ends
39
- minimumStake: BigInt(100e18),
40
- slashingQuorum: 6,
41
- slashingRoundSize: 10,
42
- governanceProposerQuorum: 6,
43
- governanceProposerRoundSize: 10,
44
- } satisfies L1ContractsConfig;
45
-
87
+ /**
88
+ * Config mappings for L1ContractsConfig.
89
+ * Default values come from generated l1-contracts-defaults.json (source: defaults.yml).
90
+ * Real deployments use forge scripts which require explicit env vars (vm.envUint).
91
+ */
46
92
  export const l1ContractsConfigMappings: ConfigMappingsType<L1ContractsConfig> = {
47
93
  ethereumSlotDuration: {
48
94
  env: 'ETHEREUM_SLOT_DURATION',
49
95
  description: 'How many seconds an L1 slot lasts.',
50
- ...numberConfigHelper(DefaultL1ContractsConfig.ethereumSlotDuration),
96
+ ...numberConfigHelper(l1ContractsDefaultEnv.ETHEREUM_SLOT_DURATION),
51
97
  },
52
98
  aztecSlotDuration: {
53
99
  env: 'AZTEC_SLOT_DURATION',
54
100
  description: 'How many seconds an L2 slots lasts (must be multiple of ethereum slot duration).',
55
- ...numberConfigHelper(DefaultL1ContractsConfig.aztecSlotDuration),
101
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLOT_DURATION),
56
102
  },
57
103
  aztecEpochDuration: {
58
104
  env: 'AZTEC_EPOCH_DURATION',
59
- description: `How many L2 slots an epoch lasts (maximum AZTEC_MAX_EPOCH_DURATION).`,
60
- ...numberConfigHelper(DefaultL1ContractsConfig.aztecEpochDuration),
105
+ description: `How many L2 slots an epoch lasts (maximum MAX_CHECKPOINTS_PER_EPOCH).`,
106
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_EPOCH_DURATION),
61
107
  },
62
108
  aztecTargetCommitteeSize: {
63
109
  env: 'AZTEC_TARGET_COMMITTEE_SIZE',
64
110
  description: 'The target validator committee size.',
65
- ...numberConfigHelper(DefaultL1ContractsConfig.aztecTargetCommitteeSize),
111
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_TARGET_COMMITTEE_SIZE),
66
112
  },
67
- aztecProofSubmissionWindow: {
68
- env: 'AZTEC_PROOF_SUBMISSION_WINDOW',
69
- description:
70
- 'The number of L2 slots that a proof for an epoch can be submitted in, starting from the beginning of the epoch.',
71
- ...numberConfigHelper(DefaultL1ContractsConfig.aztecProofSubmissionWindow),
113
+ lagInEpochsForValidatorSet: {
114
+ env: 'AZTEC_LAG_IN_EPOCHS_FOR_VALIDATOR_SET',
115
+ description: 'The number of epochs to lag behind the current epoch for validator selection.',
116
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_LAG_IN_EPOCHS_FOR_VALIDATOR_SET),
117
+ },
118
+ lagInEpochsForRandao: {
119
+ env: 'AZTEC_LAG_IN_EPOCHS_FOR_RANDAO',
120
+ description: 'The number of epochs to lag behind the current epoch for randao selection.',
121
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_LAG_IN_EPOCHS_FOR_RANDAO),
72
122
  },
73
- minimumStake: {
74
- env: 'AZTEC_MINIMUM_STAKE',
123
+ inboxLag: {
124
+ env: 'AZTEC_INBOX_LAG',
125
+ description: 'The number of checkpoints to lag in the inbox (prevents sequencer DOS attacks).',
126
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_INBOX_LAG),
127
+ },
128
+ aztecProofSubmissionEpochs: {
129
+ env: 'AZTEC_PROOF_SUBMISSION_EPOCHS',
130
+ description: 'The number of epochs after an epoch ends that proofs are still accepted.',
131
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_PROOF_SUBMISSION_EPOCHS),
132
+ },
133
+ activationThreshold: {
134
+ env: 'AZTEC_ACTIVATION_THRESHOLD',
135
+ description: 'The deposit amount for a validator',
136
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_ACTIVATION_THRESHOLD)),
137
+ },
138
+ ejectionThreshold: {
139
+ env: 'AZTEC_EJECTION_THRESHOLD',
75
140
  description: 'The minimum stake for a validator.',
76
- ...bigintConfigHelper(DefaultL1ContractsConfig.minimumStake),
141
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_EJECTION_THRESHOLD)),
142
+ },
143
+ localEjectionThreshold: {
144
+ env: 'AZTEC_LOCAL_EJECTION_THRESHOLD',
145
+ description:
146
+ 'The local ejection threshold for a validator. Stricter than ejectionThreshold but local to a specific rollup',
147
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_LOCAL_EJECTION_THRESHOLD)),
148
+ },
149
+ slashingOffsetInRounds: {
150
+ env: 'AZTEC_SLASHING_OFFSET_IN_ROUNDS',
151
+ description:
152
+ 'How many slashing rounds back we slash (ie when slashing in round N, we slash for offenses committed during epochs of round N-offset)',
153
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_OFFSET_IN_ROUNDS),
154
+ },
155
+ slasherFlavor: {
156
+ env: 'AZTEC_SLASHER_FLAVOR',
157
+ description: 'Type of slasher proposer (empire, tally, or none)',
158
+ ...enumConfigHelper(
159
+ ['empire', 'tally', 'none'] as const,
160
+ l1ContractsDefaultEnv.AZTEC_SLASHER_FLAVOR as 'empire' | 'tally' | 'none',
161
+ ),
162
+ },
163
+ slashAmountSmall: {
164
+ env: 'AZTEC_SLASH_AMOUNT_SMALL',
165
+ description: 'Small slashing amount for light offenses',
166
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_SLASH_AMOUNT_SMALL)),
167
+ },
168
+ slashAmountMedium: {
169
+ env: 'AZTEC_SLASH_AMOUNT_MEDIUM',
170
+ description: 'Medium slashing amount for moderate offenses',
171
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_SLASH_AMOUNT_MEDIUM)),
172
+ },
173
+ slashAmountLarge: {
174
+ env: 'AZTEC_SLASH_AMOUNT_LARGE',
175
+ description: 'Large slashing amount for severe offenses',
176
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_SLASH_AMOUNT_LARGE)),
77
177
  },
78
178
  slashingQuorum: {
79
179
  env: 'AZTEC_SLASHING_QUORUM',
80
180
  description: 'The slashing quorum',
81
- ...numberConfigHelper(DefaultL1ContractsConfig.slashingQuorum),
181
+ ...optionalNumberConfigHelper(),
82
182
  },
83
- slashingRoundSize: {
84
- env: 'AZTEC_SLASHING_ROUND_SIZE',
183
+ slashingRoundSizeInEpochs: {
184
+ env: 'AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS',
85
185
  description: 'The slashing round size',
86
- ...numberConfigHelper(DefaultL1ContractsConfig.slashingRoundSize),
186
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS),
187
+ },
188
+ slashingLifetimeInRounds: {
189
+ env: 'AZTEC_SLASHING_LIFETIME_IN_ROUNDS',
190
+ description: 'The slashing lifetime in rounds',
191
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_LIFETIME_IN_ROUNDS),
192
+ },
193
+ slashingExecutionDelayInRounds: {
194
+ env: 'AZTEC_SLASHING_EXECUTION_DELAY_IN_ROUNDS',
195
+ description: 'The slashing execution delay in rounds',
196
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_EXECUTION_DELAY_IN_ROUNDS),
197
+ },
198
+ slashingVetoer: {
199
+ env: 'AZTEC_SLASHING_VETOER',
200
+ description: 'The slashing vetoer',
201
+ parseEnv: (val: string) => EthAddress.fromString(val),
202
+ defaultValue: EthAddress.fromString(l1ContractsDefaultEnv.AZTEC_SLASHING_VETOER),
203
+ },
204
+ slashingDisableDuration: {
205
+ env: 'AZTEC_SLASHING_DISABLE_DURATION',
206
+ description: 'How long slashing can be disabled for in seconds when vetoer disables it',
207
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_DISABLE_DURATION),
87
208
  },
88
209
  governanceProposerQuorum: {
89
210
  env: 'AZTEC_GOVERNANCE_PROPOSER_QUORUM',
90
211
  description: 'The governance proposing quorum',
91
- ...numberConfigHelper(DefaultL1ContractsConfig.governanceProposerQuorum),
212
+ ...optionalNumberConfigHelper(),
92
213
  },
93
214
  governanceProposerRoundSize: {
94
215
  env: 'AZTEC_GOVERNANCE_PROPOSER_ROUND_SIZE',
95
216
  description: 'The governance proposing round size',
96
- ...numberConfigHelper(DefaultL1ContractsConfig.governanceProposerRoundSize),
217
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_GOVERNANCE_PROPOSER_ROUND_SIZE),
218
+ },
219
+ governanceVotingDuration: {
220
+ env: 'AZTEC_GOVERNANCE_VOTING_DURATION',
221
+ description: 'Governance voting duration in seconds (only for local/devnet/next-net)',
222
+ ...numberConfigHelper(3600), // 1 hour default, not in generated defaults as it's deployment-time only
223
+ },
224
+ manaTarget: {
225
+ env: 'AZTEC_MANA_TARGET',
226
+ description: 'The mana target for the rollup',
227
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_MANA_TARGET)),
228
+ },
229
+ provingCostPerMana: {
230
+ env: 'AZTEC_PROVING_COST_PER_MANA',
231
+ description: 'The proving cost per mana',
232
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_PROVING_COST_PER_MANA)),
233
+ },
234
+ initialEthPerFeeAsset: {
235
+ env: 'AZTEC_INITIAL_ETH_PER_FEE_ASSET',
236
+ description: 'The initial ETH per fee asset price (with 1e12 precision)',
237
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_INITIAL_ETH_PER_FEE_ASSET)),
238
+ },
239
+ exitDelaySeconds: {
240
+ env: 'AZTEC_EXIT_DELAY_SECONDS',
241
+ description: 'The delay before a validator can exit the set',
242
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_EXIT_DELAY_SECONDS),
243
+ },
244
+ ...omitConfigMappings(l1TxUtilsConfigMappings, ['ethereumSlotDuration']),
245
+ };
246
+
247
+ /**
248
+ * Default L1 contracts configuration derived from l1ContractsConfigMappings.
249
+ * Source of truth: spartan/environments/defaults.yml -> defaults.l1-contracts
250
+ */
251
+ export const DefaultL1ContractsConfig = getDefaultConfig(l1ContractsConfigMappings);
252
+
253
+ export const genesisStateConfigMappings: ConfigMappingsType<GenesisStateConfig> = {
254
+ testAccounts: {
255
+ env: 'TEST_ACCOUNTS',
256
+ description: 'Whether to populate the genesis state with initial fee juice for the test accounts.',
257
+ ...booleanConfigHelper(false),
258
+ },
259
+ sponsoredFPC: {
260
+ env: 'SPONSORED_FPC',
261
+ description: 'Whether to populate the genesis state with initial fee juice for the sponsored FPC.',
262
+ ...booleanConfigHelper(false),
263
+ },
264
+ prefundAddresses: {
265
+ env: 'PREFUND_ADDRESSES',
266
+ description: 'Comma-separated list of Aztec addresses to prefund with fee juice at genesis (local network only).',
267
+ parseEnv: (val: string) =>
268
+ val
269
+ .split(',')
270
+ .map(a => a.trim())
271
+ .filter(a => a.length > 0),
272
+ defaultValue: [],
97
273
  },
98
- ...l1TxUtilsConfigMappings,
99
274
  };
100
275
 
101
276
  export function getL1ContractsConfigEnvVars(): L1ContractsConfig {
102
277
  return getConfigFromMappings(l1ContractsConfigMappings);
103
278
  }
279
+
280
+ export function getGenesisStateConfigEnvVars(): GenesisStateConfig {
281
+ return getConfigFromMappings(genesisStateConfigMappings);
282
+ }
@@ -0,0 +1,157 @@
1
+ # L1 Contract Wrappers
2
+
3
+ This folder contains TypeScript wrappers for L1 contracts defined in `l1-contracts/`. These wrappers are used by the node client to interact with the rollup and related contracts on Ethereum.
4
+
5
+ ## Purpose
6
+
7
+ The goal of wrapping is to shield consumers from L1-specific and viem-specific details. Clients using these wrappers interact with domain types and branded types native to the Aztec codebase, without needing to understand viem's ABI type system or deal with raw types like `Hex` and `bigint`.
8
+
9
+ ## Type Safety
10
+
11
+ ### Explicit Return Types
12
+
13
+ Every function in the contract wrappers must declare its return type explicitly. This is critical because viem's type inference over ABI types is slow and significantly impacts IDE performance.
14
+
15
+ ```typescript
16
+ // Good: Explicit return type
17
+ async getSlotNumber(): Promise<SlotNumber> {
18
+ return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
19
+ }
20
+
21
+ // Bad: Inferred return type (slow)
22
+ async getSlotNumber() {
23
+ return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
24
+ }
25
+ ```
26
+
27
+ ### Branded and Domain Types
28
+
29
+ Use branded types and domain-specific types instead of viem's autogenerated types for both arguments and return values:
30
+
31
+ - `CheckpointNumber`, `EpochNumber`, `SlotNumber` instead of `bigint`
32
+ - `EthAddress` instead of `` `0x${string}` `` or `Hex`
33
+ - `Fr`, `Buffer32` instead of `Hex` for hashes and field elements
34
+ - Custom domain types (e.g., `CheckpointLog`, `AttesterView`) instead of raw tuples
35
+
36
+ Type conversions happen inside wrapper methods, not at the call site:
37
+
38
+ ```typescript
39
+ async getCheckpoint(checkpointNumber: CheckpointNumber): Promise<CheckpointLog> {
40
+ const result = await this.rollup.read.getCheckpoint([BigInt(checkpointNumber)]);
41
+ return {
42
+ archive: Fr.fromString(result.archive),
43
+ headerHash: Buffer32.fromString(result.headerHash),
44
+ blockCount: result.blockCount,
45
+ };
46
+ }
47
+ ```
48
+
49
+ ## Wrapper Pattern
50
+
51
+ ### Basic Structure
52
+
53
+ Each wrapper follows a consistent structure:
54
+
55
+ ```typescript
56
+ export class FooContract {
57
+ private readonly foo: GetContractReturnType<typeof FooAbi, ViemClient>;
58
+
59
+ constructor(
60
+ public readonly client: ViemClient,
61
+ address: Hex | EthAddress,
62
+ ) {
63
+ if (address instanceof EthAddress) {
64
+ address = address.toString();
65
+ }
66
+ this.foo = getContract({ address, abi: FooAbi, client });
67
+ }
68
+
69
+ public get address(): Hex {
70
+ return this.foo.address;
71
+ }
72
+
73
+ public getContract(): GetContractReturnType<typeof FooAbi, ViemClient> {
74
+ return this.foo;
75
+ }
76
+ }
77
+ ```
78
+
79
+ The raw contract is exposed via `getContract()` for cases where direct access is needed, but most consumers should use the typed wrapper methods. Relying on `getContract()` is a code smell and should be avoided.
80
+
81
+ ### Static Factory Methods
82
+
83
+ Wrappers may provide static factory methods for common initialization patterns:
84
+
85
+ - `getFromConfig(config)` - construct from configuration object
86
+ - `getFromL1ContractsValues(deployResult)` - construct from deployment result
87
+
88
+ ### Wallet Assertions
89
+
90
+ For write operations that require a wallet, use an assertion helper:
91
+
92
+ ```typescript
93
+ private assertWallet(): GetContractReturnType<typeof FooAbi, ExtendedViemWalletClient> {
94
+ if (!isExtendedClient(this.client)) {
95
+ throw new Error('Wallet client is required for this operation');
96
+ }
97
+ return this.foo as GetContractReturnType<typeof FooAbi, ExtendedViemWalletClient>;
98
+ }
99
+ ```
100
+
101
+ ## Event Handling
102
+
103
+ ### Event Log Types
104
+
105
+ Event logs are wrapped in `L1EventLog<T>` to include L1 block context:
106
+
107
+ ```typescript
108
+ type L1EventLog<T> = {
109
+ l1BlockNumber: bigint;
110
+ l1BlockHash: Buffer32;
111
+ l1TransactionHash: Hex;
112
+ args: T;
113
+ };
114
+ ```
115
+
116
+ ### Event Fetching
117
+
118
+ Methods that fetch events convert viem's raw logs to domain types:
119
+
120
+ ```typescript
121
+ async getCheckpointProposedEvents(fromBlock: bigint, toBlock: bigint): Promise<CheckpointProposedLog[]> {
122
+ const logs = await this.rollup.getEvents.CheckpointProposed({}, { fromBlock, toBlock });
123
+ return logs.map(log => ({
124
+ l1BlockNumber: log.blockNumber!,
125
+ l1BlockHash: Buffer32.fromString(log.blockHash!),
126
+ l1TransactionHash: log.transactionHash!,
127
+ args: {
128
+ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
129
+ // ... convert other fields
130
+ },
131
+ }));
132
+ }
133
+ ```
134
+
135
+ ### Event Listeners
136
+
137
+ For reactive event handling, wrapper methods convert arguments before invoking callbacks:
138
+
139
+ ```typescript
140
+ public listenToCheckpointInvalidated(
141
+ callback: (args: { checkpointNumber: CheckpointNumber }) => unknown,
142
+ ): WatchContractEventReturnType {
143
+ return this.rollup.watchEvent.CheckpointInvalidated({}, {
144
+ onLogs: logs => {
145
+ for (const log of logs) {
146
+ if (log.args.checkpointNumber !== undefined) {
147
+ callback({ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber) });
148
+ }
149
+ }
150
+ },
151
+ });
152
+ }
153
+ ```
154
+
155
+ ## Error Handling
156
+
157
+ Custom error classes in `errors.ts` extend `Error` and set `this.name` for proper error identification. Include relevant context as public readonly properties.
@@ -1,19 +1,91 @@
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; quorumReached: boolean; 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>;
25
+ /** Checks if a payload was ever submitted to governance via submitRoundWinner. */
26
+ hasPayloadBeenProposed(payload: Hex, fromBlock: bigint): Promise<boolean>;
11
27
  }
12
28
 
13
- export function encodeVote(payload: Hex): Hex {
29
+ export function encodeSignal(payload: Hex): Hex {
14
30
  return encodeFunctionData({
15
31
  abi: EmpireBaseAbi,
16
- functionName: 'vote',
32
+ functionName: 'signal',
17
33
  args: [payload],
18
34
  });
19
35
  }
36
+
37
+ export function encodeSignalWithSignature(payload: Hex, signature: Signature) {
38
+ return encodeFunctionData({
39
+ abi: EmpireBaseAbi,
40
+ functionName: 'signalWithSig',
41
+ args: [payload, signature.toViemSignature()],
42
+ });
43
+ }
44
+
45
+ /**
46
+ * Signs a signal proposal using EIP-712 typed data for use with signalWithSig
47
+ * @param walletClient - The viem wallet client to sign with
48
+ * @param payload - The payload address to signal
49
+ * @param verifyingContract - The address of the EmpireBase contract
50
+ * @param chainId - The chain ID where the contract is deployed
51
+ * @param account - The account to sign with (optional if hoisted on wallet client)
52
+ * @returns The EIP-712 signature
53
+ */
54
+ export async function signSignalWithSig(
55
+ signer: (msg: TypedDataDefinition) => Promise<Hex>,
56
+ payload: Hex,
57
+ slot: SlotNumber,
58
+ instance: Hex,
59
+ verifyingContract: Hex,
60
+ chainId: number,
61
+ ): Promise<Signature> {
62
+ const domain = {
63
+ name: 'EmpireBase',
64
+ version: '1',
65
+ chainId,
66
+ verifyingContract,
67
+ };
68
+
69
+ const types = {
70
+ EIP712Domain: [
71
+ { name: 'name', type: 'string' },
72
+ { name: 'version', type: 'string' },
73
+ { name: 'chainId', type: 'uint256' },
74
+ { name: 'verifyingContract', type: 'address' },
75
+ ],
76
+ Signal: [
77
+ { name: 'payload', type: 'address' },
78
+ { name: 'slot', type: 'uint256' },
79
+ { name: 'instance', type: 'address' },
80
+ ],
81
+ };
82
+
83
+ const message = {
84
+ payload,
85
+ slot: BigInt(slot),
86
+ instance,
87
+ };
88
+
89
+ const typedData = { domain, types, primaryType: 'Signal', message };
90
+ return Signature.fromString(await signer(typedData));
91
+ }