@aztec-labs/ethereum 6.0.0-nightly.20260829

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 (272) hide show
  1. package/README.md +3 -0
  2. package/dest/account.d.ts +2 -0
  3. package/dest/account.d.ts.map +1 -0
  4. package/dest/account.js +4 -0
  5. package/dest/chain.d.ts +25 -0
  6. package/dest/chain.d.ts.map +1 -0
  7. package/dest/chain.js +53 -0
  8. package/dest/client.d.ts +42 -0
  9. package/dest/client.d.ts.map +1 -0
  10. package/dest/client.js +104 -0
  11. package/dest/config.d.ts +103 -0
  12. package/dest/config.d.ts.map +1 -0
  13. package/dest/config.js +233 -0
  14. package/dest/constants.d.ts +4 -0
  15. package/dest/constants.d.ts.map +1 -0
  16. package/dest/constants.js +2 -0
  17. package/dest/contracts/chain_state_override.d.ts +81 -0
  18. package/dest/contracts/chain_state_override.d.ts.map +1 -0
  19. package/dest/contracts/chain_state_override.js +139 -0
  20. package/dest/contracts/empire_base.d.ts +30 -0
  21. package/dest/contracts/empire_base.d.ts.map +1 -0
  22. package/dest/contracts/empire_base.js +84 -0
  23. package/dest/contracts/errors.d.ts +7 -0
  24. package/dest/contracts/errors.d.ts.map +1 -0
  25. package/dest/contracts/errors.js +12 -0
  26. package/dest/contracts/fee_asset_handler.d.ts +20 -0
  27. package/dest/contracts/fee_asset_handler.d.ts.map +1 -0
  28. package/dest/contracts/fee_asset_handler.js +59 -0
  29. package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
  30. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  31. package/dest/contracts/fee_asset_price_oracle.js +656 -0
  32. package/dest/contracts/fee_juice.d.ts +14 -0
  33. package/dest/contracts/fee_juice.d.ts.map +1 -0
  34. package/dest/contracts/fee_juice.js +59 -0
  35. package/dest/contracts/governance.d.ts +192 -0
  36. package/dest/contracts/governance.d.ts.map +1 -0
  37. package/dest/contracts/governance.js +471 -0
  38. package/dest/contracts/governance_proposer.d.ts +63 -0
  39. package/dest/contracts/governance_proposer.d.ts.map +1 -0
  40. package/dest/contracts/governance_proposer.js +536 -0
  41. package/dest/contracts/gse.d.ts +38 -0
  42. package/dest/contracts/gse.d.ts.map +1 -0
  43. package/dest/contracts/gse.js +81 -0
  44. package/dest/contracts/inbox.d.ts +94 -0
  45. package/dest/contracts/inbox.d.ts.map +1 -0
  46. package/dest/contracts/inbox.js +141 -0
  47. package/dest/contracts/index.d.ts +18 -0
  48. package/dest/contracts/index.d.ts.map +1 -0
  49. package/dest/contracts/index.js +17 -0
  50. package/dest/contracts/log.d.ts +13 -0
  51. package/dest/contracts/log.d.ts.map +1 -0
  52. package/dest/contracts/log.js +1 -0
  53. package/dest/contracts/multicall.d.ts +138 -0
  54. package/dest/contracts/multicall.d.ts.map +1 -0
  55. package/dest/contracts/multicall.js +266 -0
  56. package/dest/contracts/outbox.d.ts +64 -0
  57. package/dest/contracts/outbox.d.ts.map +1 -0
  58. package/dest/contracts/outbox.js +113 -0
  59. package/dest/contracts/registry.d.ts +31 -0
  60. package/dest/contracts/registry.d.ts.map +1 -0
  61. package/dest/contracts/registry.js +142 -0
  62. package/dest/contracts/rollup.d.ts +5836 -0
  63. package/dest/contracts/rollup.d.ts.map +1 -0
  64. package/dest/contracts/rollup.js +1612 -0
  65. package/dest/contracts/slasher_contract.d.ts +44 -0
  66. package/dest/contracts/slasher_contract.d.ts.map +1 -0
  67. package/dest/contracts/slasher_contract.js +75 -0
  68. package/dest/contracts/slashing_proposer.d.ts +174 -0
  69. package/dest/contracts/slashing_proposer.d.ts.map +1 -0
  70. package/dest/contracts/slashing_proposer.js +755 -0
  71. package/dest/contracts/utils.d.ts +3 -0
  72. package/dest/contracts/utils.d.ts.map +1 -0
  73. package/dest/contracts/utils.js +11 -0
  74. package/dest/contracts/watch_event.d.ts +36 -0
  75. package/dest/contracts/watch_event.d.ts.map +1 -0
  76. package/dest/contracts/watch_event.js +66 -0
  77. package/dest/deploy_aztec_l1_contracts.d.ts +267 -0
  78. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  79. package/dest/deploy_aztec_l1_contracts.js +424 -0
  80. package/dest/deploy_l1_contract.d.ts +68 -0
  81. package/dest/deploy_l1_contract.d.ts.map +1 -0
  82. package/dest/deploy_l1_contract.js +312 -0
  83. package/dest/eth-signer/eth-signer.d.ts +21 -0
  84. package/dest/eth-signer/eth-signer.d.ts.map +1 -0
  85. package/dest/eth-signer/eth-signer.js +5 -0
  86. package/dest/eth-signer/index.d.ts +2 -0
  87. package/dest/eth-signer/index.d.ts.map +1 -0
  88. package/dest/eth-signer/index.js +1 -0
  89. package/dest/forwarder_proxy.d.ts +32 -0
  90. package/dest/forwarder_proxy.d.ts.map +1 -0
  91. package/dest/forwarder_proxy.js +93 -0
  92. package/dest/foundry_binary.d.ts +13 -0
  93. package/dest/foundry_binary.d.ts.map +1 -0
  94. package/dest/foundry_binary.js +52 -0
  95. package/dest/l1_artifacts.d.ts +81896 -0
  96. package/dest/l1_artifacts.d.ts.map +1 -0
  97. package/dest/l1_artifacts.js +151 -0
  98. package/dest/l1_contract_addresses.d.ts +73 -0
  99. package/dest/l1_contract_addresses.d.ts.map +1 -0
  100. package/dest/l1_contract_addresses.js +120 -0
  101. package/dest/l1_reader.d.ts +18 -0
  102. package/dest/l1_reader.d.ts.map +1 -0
  103. package/dest/l1_reader.js +35 -0
  104. package/dest/l1_tx_utils/config.d.ts +65 -0
  105. package/dest/l1_tx_utils/config.d.ts.map +1 -0
  106. package/dest/l1_tx_utils/config.js +109 -0
  107. package/dest/l1_tx_utils/constants.d.ts +12 -0
  108. package/dest/l1_tx_utils/constants.d.ts.map +1 -0
  109. package/dest/l1_tx_utils/constants.js +39 -0
  110. package/dest/l1_tx_utils/factory.d.ts +32 -0
  111. package/dest/l1_tx_utils/factory.d.ts.map +1 -0
  112. package/dest/l1_tx_utils/factory.js +22 -0
  113. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  114. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  115. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  116. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  117. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  118. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  119. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  120. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  121. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  122. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  123. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  124. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  125. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  126. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  127. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
  128. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  129. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  130. package/dest/l1_tx_utils/index-blobs.js +2 -0
  131. package/dest/l1_tx_utils/index.d.ts +13 -0
  132. package/dest/l1_tx_utils/index.d.ts.map +1 -0
  133. package/dest/l1_tx_utils/index.js +13 -0
  134. package/dest/l1_tx_utils/interfaces.d.ts +76 -0
  135. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
  136. package/dest/l1_tx_utils/interfaces.js +4 -0
  137. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +252 -0
  138. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  139. package/dest/l1_tx_utils/l1_fee_analyzer.js +568 -0
  140. package/dest/l1_tx_utils/l1_tx_utils.d.ts +113 -0
  141. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
  142. package/dest/l1_tx_utils/l1_tx_utils.js +720 -0
  143. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +83 -0
  144. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
  145. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +357 -0
  146. package/dest/l1_tx_utils/signer.d.ts +4 -0
  147. package/dest/l1_tx_utils/signer.d.ts.map +1 -0
  148. package/dest/l1_tx_utils/signer.js +16 -0
  149. package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
  150. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  151. package/dest/l1_tx_utils/tx_delayer.js +223 -0
  152. package/dest/l1_tx_utils/types.d.ts +93 -0
  153. package/dest/l1_tx_utils/types.d.ts.map +1 -0
  154. package/dest/l1_tx_utils/types.js +36 -0
  155. package/dest/l1_tx_utils/utils.d.ts +4 -0
  156. package/dest/l1_tx_utils/utils.d.ts.map +1 -0
  157. package/dest/l1_tx_utils/utils.js +14 -0
  158. package/dest/l1_types.d.ts +6 -0
  159. package/dest/l1_types.d.ts.map +1 -0
  160. package/dest/l1_types.js +1 -0
  161. package/dest/publisher_manager.d.ts +42 -0
  162. package/dest/publisher_manager.d.ts.map +1 -0
  163. package/dest/publisher_manager.js +199 -0
  164. package/dest/queries.d.ts +25 -0
  165. package/dest/queries.d.ts.map +1 -0
  166. package/dest/queries.js +144 -0
  167. package/dest/test/blob_kzg_warmup.d.ts +19 -0
  168. package/dest/test/blob_kzg_warmup.d.ts.map +1 -0
  169. package/dest/test/blob_kzg_warmup.js +64 -0
  170. package/dest/test/chain_monitor.d.ts +126 -0
  171. package/dest/test/chain_monitor.d.ts.map +1 -0
  172. package/dest/test/chain_monitor.js +314 -0
  173. package/dest/test/eth_cheat_codes.d.ts +260 -0
  174. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  175. package/dest/test/eth_cheat_codes.js +608 -0
  176. package/dest/test/eth_cheat_codes_with_state.d.ts +18 -0
  177. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -0
  178. package/dest/test/eth_cheat_codes_with_state.js +34 -0
  179. package/dest/test/index.d.ts +8 -0
  180. package/dest/test/index.d.ts.map +1 -0
  181. package/dest/test/index.js +7 -0
  182. package/dest/test/recording_rpc_server.d.ts +18 -0
  183. package/dest/test/recording_rpc_server.d.ts.map +1 -0
  184. package/dest/test/recording_rpc_server.js +68 -0
  185. package/dest/test/rollup_cheat_codes.d.ts +142 -0
  186. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  187. package/dest/test/rollup_cheat_codes.js +338 -0
  188. package/dest/test/start_anvil.d.ts +40 -0
  189. package/dest/test/start_anvil.d.ts.map +1 -0
  190. package/dest/test/start_anvil.js +210 -0
  191. package/dest/test/upgrade_utils.d.ts +12 -0
  192. package/dest/test/upgrade_utils.d.ts.map +1 -0
  193. package/dest/test/upgrade_utils.js +111 -0
  194. package/dest/types.d.ts +68 -0
  195. package/dest/types.d.ts.map +1 -0
  196. package/dest/types.js +3 -0
  197. package/dest/utils.d.ts +45 -0
  198. package/dest/utils.d.ts.map +1 -0
  199. package/dest/utils.js +260 -0
  200. package/dest/zkPassportVerifierAddress.d.ts +15 -0
  201. package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
  202. package/dest/zkPassportVerifierAddress.js +11 -0
  203. package/package.json +122 -0
  204. package/src/account.ts +5 -0
  205. package/src/chain.ts +71 -0
  206. package/src/client.ts +165 -0
  207. package/src/config.ts +342 -0
  208. package/src/constants.ts +4 -0
  209. package/src/contracts/README.md +157 -0
  210. package/src/contracts/chain_state_override.ts +203 -0
  211. package/src/contracts/empire_base.ts +89 -0
  212. package/src/contracts/errors.ts +13 -0
  213. package/src/contracts/fee_asset_handler.ts +66 -0
  214. package/src/contracts/fee_asset_price_oracle.ts +284 -0
  215. package/src/contracts/fee_juice.ts +57 -0
  216. package/src/contracts/governance.ts +597 -0
  217. package/src/contracts/governance_proposer.ts +181 -0
  218. package/src/contracts/gse.ts +105 -0
  219. package/src/contracts/inbox.ts +223 -0
  220. package/src/contracts/index.ts +17 -0
  221. package/src/contracts/log.ts +13 -0
  222. package/src/contracts/multicall.ts +298 -0
  223. package/src/contracts/outbox.ts +132 -0
  224. package/src/contracts/registry.ts +161 -0
  225. package/src/contracts/rollup.ts +1502 -0
  226. package/src/contracts/slasher_contract.ts +89 -0
  227. package/src/contracts/slashing_proposer.ts +397 -0
  228. package/src/contracts/utils.ts +14 -0
  229. package/src/contracts/watch_event.ts +109 -0
  230. package/src/deploy_aztec_l1_contracts.ts +663 -0
  231. package/src/deploy_l1_contract.ts +361 -0
  232. package/src/eth-signer/eth-signer.ts +24 -0
  233. package/src/eth-signer/index.ts +1 -0
  234. package/src/forwarder_proxy.ts +107 -0
  235. package/src/foundry_binary.ts +57 -0
  236. package/src/l1_artifacts.ts +231 -0
  237. package/src/l1_contract_addresses.ts +149 -0
  238. package/src/l1_reader.ts +57 -0
  239. package/src/l1_tx_utils/README.md +177 -0
  240. package/src/l1_tx_utils/config.ts +181 -0
  241. package/src/l1_tx_utils/constants.ts +29 -0
  242. package/src/l1_tx_utils/factory.ts +64 -0
  243. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  244. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +162 -0
  245. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +244 -0
  246. package/src/l1_tx_utils/fee-strategies/types.ts +55 -0
  247. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +107 -0
  248. package/src/l1_tx_utils/index-blobs.ts +2 -0
  249. package/src/l1_tx_utils/index.ts +15 -0
  250. package/src/l1_tx_utils/interfaces.ts +86 -0
  251. package/src/l1_tx_utils/l1_fee_analyzer.ts +874 -0
  252. package/src/l1_tx_utils/l1_tx_utils.ts +840 -0
  253. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +459 -0
  254. package/src/l1_tx_utils/signer.ts +27 -0
  255. package/src/l1_tx_utils/tx_delayer.ts +302 -0
  256. package/src/l1_tx_utils/types.ts +116 -0
  257. package/src/l1_tx_utils/utils.ts +15 -0
  258. package/src/l1_types.ts +6 -0
  259. package/src/publisher_manager.ts +239 -0
  260. package/src/queries.ts +189 -0
  261. package/src/test/blob_kzg_warmup.ts +65 -0
  262. package/src/test/chain_monitor.ts +389 -0
  263. package/src/test/eth_cheat_codes.ts +624 -0
  264. package/src/test/eth_cheat_codes_with_state.ts +38 -0
  265. package/src/test/index.ts +7 -0
  266. package/src/test/recording_rpc_server.ts +69 -0
  267. package/src/test/rollup_cheat_codes.ts +398 -0
  268. package/src/test/start_anvil.ts +255 -0
  269. package/src/test/upgrade_utils.ts +109 -0
  270. package/src/types.ts +97 -0
  271. package/src/utils.ts +344 -0
  272. package/src/zkPassportVerifierAddress.ts +15 -0
@@ -0,0 +1,57 @@
1
+ import { TestERC20Abi as FeeJuiceAbi } from '@aztec/l1-artifacts/TestERC20Abi';
2
+
3
+ import { EthAddress } from '@aztec-labs/foundation/eth-address';
4
+ import { type GetContractReturnType, type Hex, getContract } from 'viem';
5
+
6
+ import { type ExtendedViemWalletClient, type ViemClient, isExtendedClient } from '../types.js';
7
+
8
+ export class FeeJuiceContract {
9
+ private readonly feeJuiceContract: GetContractReturnType<typeof FeeJuiceAbi, ViemClient>;
10
+
11
+ constructor(
12
+ address: Hex | EthAddress,
13
+ public readonly client: ViemClient,
14
+ ) {
15
+ if (address instanceof EthAddress) {
16
+ address = address.toString();
17
+ }
18
+ this.feeJuiceContract = getContract({ address, abi: FeeJuiceAbi, client });
19
+ }
20
+
21
+ public get address() {
22
+ return EthAddress.fromString(this.feeJuiceContract.address);
23
+ }
24
+
25
+ public async getOwner(): Promise<EthAddress> {
26
+ return EthAddress.fromString(await this.feeJuiceContract.read.owner());
27
+ }
28
+
29
+ private assertWalletFeeJuice(): GetContractReturnType<typeof FeeJuiceAbi, ExtendedViemWalletClient> {
30
+ if (!isExtendedClient(this.client)) {
31
+ throw new Error('Wallet client is required for this operation');
32
+ }
33
+ return this.feeJuiceContract as GetContractReturnType<typeof FeeJuiceAbi, ExtendedViemWalletClient>;
34
+ }
35
+
36
+ public async mint(to: Hex, amount: bigint) {
37
+ const walletFeeJuice = this.assertWalletFeeJuice();
38
+ const tx = await walletFeeJuice.write.mint([to, amount]);
39
+ const receipt = await this.client.waitForTransactionReceipt({ hash: tx });
40
+
41
+ if (receipt.status === 'success') {
42
+ return;
43
+ }
44
+ throw new Error('Mint failed');
45
+ }
46
+
47
+ public async approve(spender: Hex, amount: bigint) {
48
+ const walletFeeJuice = this.assertWalletFeeJuice();
49
+ const tx = await walletFeeJuice.write.approve([spender, amount]);
50
+ const receipt = await this.client.waitForTransactionReceipt({ hash: tx });
51
+
52
+ if (receipt.status === 'success') {
53
+ return;
54
+ }
55
+ throw new Error('Approve failed');
56
+ }
57
+ }
@@ -0,0 +1,597 @@
1
+ import { GovernanceAbi } from '@aztec/l1-artifacts/GovernanceAbi';
2
+
3
+ import { EthAddress } from '@aztec-labs/foundation/eth-address';
4
+ import type { Logger } from '@aztec-labs/foundation/log';
5
+ import { sleep } from '@aztec-labs/foundation/sleep';
6
+ import {
7
+ type EncodeFunctionDataParameters,
8
+ type GetContractReturnType,
9
+ type Hex,
10
+ type Log,
11
+ encodeFunctionData,
12
+ getContract,
13
+ parseEventLogs,
14
+ } from 'viem';
15
+
16
+ import type { L1ContractAddresses } from '../l1_contract_addresses.js';
17
+ import { createL1TxUtils } from '../l1_tx_utils/index.js';
18
+ import { type ExtendedViemWalletClient, type ViemClient, isExtendedClient } from '../types.js';
19
+
20
+ // Minimal ABI for IProposerPayload (`l1-contracts/src/governance/interfaces/IProposerPayload.sol`).
21
+ // The GovernanceProposer wraps every original payload in a GSEPayload before submitting it to
22
+ // Governance, so `Proposal.payload` on the Governance contract is the wrapper address rather than
23
+ // the original. We only need `getOriginalPayload` to recover the underlying payload, so we inline
24
+ // the ABI here instead of generating a full artifact.
25
+ const ProposerPayloadAbi = [
26
+ {
27
+ type: 'function',
28
+ name: 'getOriginalPayload',
29
+ inputs: [],
30
+ outputs: [{ type: 'address' }],
31
+ stateMutability: 'view',
32
+ },
33
+ ] as const;
34
+
35
+ export type L1GovernanceContractAddresses = Pick<
36
+ L1ContractAddresses,
37
+ 'governanceAddress' | 'rollupAddress' | 'registryAddress' | 'governanceProposerAddress'
38
+ >;
39
+
40
+ // NOTE: Must be kept in sync with IGovernance.ProposalState in l1-contracts
41
+ export enum ProposalState {
42
+ Pending,
43
+ Active,
44
+ Queued,
45
+ Executable,
46
+ Rejected,
47
+ Executed,
48
+ Droppable,
49
+ Dropped,
50
+ Expired,
51
+ }
52
+
53
+ /**
54
+ * Outcome of {@link ReadOnlyGovernanceContract.getPayloadProposalStatus} for a queried payload.
55
+ * - `'live'`: a proposal referencing the payload is still progressing (Pending/Active/Queued/
56
+ * Executable) or is `Droppable`, so signalling for it again is redundant or premature.
57
+ * - `'executed'`: no live proposal references the payload, but one was already executed within the
58
+ * bounded lookback (or a prior sweep observed the execution and memoized it).
59
+ * - `'none'`: no live or executed proposal references the payload within the bounded lookback.
60
+ */
61
+ export type PayloadProposalStatus = 'live' | 'executed' | 'none';
62
+
63
+ /** Vote tallies on a single proposal. Both fields are mutated by `Governance.vote`. */
64
+ export interface Ballot {
65
+ yea: bigint;
66
+ nay: bigint;
67
+ }
68
+
69
+ /**
70
+ * Snapshot of the timing/quorum parameters that govern a single proposal's lifecycle. Each proposal
71
+ * stores its own copy at creation time (see `_propose` in Governance.sol), so this snapshot is
72
+ * immutable for the lifetime of the proposal even if the global `Configuration` changes later.
73
+ */
74
+ export interface ProposalConfiguration {
75
+ votingDelay: bigint;
76
+ votingDuration: bigint;
77
+ executionDelay: bigint;
78
+ gracePeriod: bigint;
79
+ quorum: bigint;
80
+ requiredYeaMargin: bigint;
81
+ minimumVotes: bigint;
82
+ }
83
+
84
+ /** Parameters for `Governance.proposeWithLock`. Stored only in the global Configuration, never on a proposal. */
85
+ export interface ProposeWithLockConfiguration {
86
+ lockDelay: bigint;
87
+ lockAmount: bigint;
88
+ }
89
+
90
+ /**
91
+ * Live, mutable governance configuration. `proposeConfig` is the lock configuration used by
92
+ * `proposeWithLock`; the remaining fields are the same shape as `ProposalConfiguration` and are
93
+ * snapshotted onto each new proposal at creation time.
94
+ */
95
+ export interface GovernanceConfiguration extends ProposalConfiguration {
96
+ proposeConfig: ProposeWithLockConfiguration;
97
+ }
98
+
99
+ /**
100
+ * A governance proposal augmented with its live (computed) state.
101
+ *
102
+ * Mutability:
103
+ * - `config`, `payload`, `proposer`, `creation` are immutable for the lifetime of the proposal.
104
+ * - `cachedState` is the raw value stored on-chain. It is only written when a proposal is explicitly
105
+ * executed or dropped, so for time-derived terminal states (Rejected, Expired) it remains at the
106
+ * value that was current when the proposal was created.
107
+ * - `state` is the computed state returned by `Governance.getProposalState`. This is the value
108
+ * callers almost always want -- it reflects time-derived transitions that `cachedState` does not.
109
+ * - `summedBallot` is mutated by every `Governance.vote` call while the proposal is Active.
110
+ *
111
+ * Once `state` is in a terminal phase (`Executed`/`Rejected`/`Dropped`/`Expired`) the entire struct
112
+ * is provably immutable on-chain (no further votes can be cast and no state-mutating call to
113
+ * `execute`/`dropProposal` can succeed), and the wrapper memoizes it.
114
+ */
115
+ export interface Proposal {
116
+ config: ProposalConfiguration;
117
+ cachedState: ProposalState;
118
+ state: ProposalState;
119
+ payload: EthAddress;
120
+ proposer: EthAddress;
121
+ creation: bigint;
122
+ summedBallot: Ballot;
123
+ }
124
+
125
+ /** Set of `ProposalState` values for which a proposal is fully immutable on-chain. */
126
+ const TERMINAL_PROPOSAL_STATES: ReadonlySet<ProposalState> = new Set([
127
+ ProposalState.Executed,
128
+ ProposalState.Rejected,
129
+ ProposalState.Dropped,
130
+ ProposalState.Expired,
131
+ ]);
132
+
133
+ // Set of `ProposalState` values in which a proposal is still progressing towards execution.
134
+ // `Droppable` is deliberately excluded: it is neither live (it cannot progress on its own) nor
135
+ // terminal (it can resume its lifecycle if the governanceProposer is restored), so it is handled
136
+ // separately and is never memoized as immutable.
137
+ const LIVE_PROPOSAL_STATES: ReadonlySet<ProposalState> = new Set([
138
+ ProposalState.Pending,
139
+ ProposalState.Active,
140
+ ProposalState.Queued,
141
+ ProposalState.Executable,
142
+ ]);
143
+
144
+ // Hard upper bound on the wall-clock lifetime of any Governance proposal, in seconds.
145
+ // Each proposal stores its own snapshot of `ProposalConfiguration` at creation time and progresses
146
+ // through Pending -> Active -> Queued -> Executable using those frozen durations
147
+ // (see `ProposalLib.{pendingThrough,activeThrough,queuedThrough,executableThrough}`). Each of those
148
+ // four durations is bounded by `ConfigurationLib.TIME_UPPER = 90 days` (validated in
149
+ // `ConfigurationLib.assertValid`), so no proposal can be live for more than 4 * 90 days regardless
150
+ // of what config it was created under. Once past this point, the proposal is guaranteed to be in a
151
+ // terminal state (Executed / Rejected / Dropped / Expired).
152
+ export const MAX_PROPOSAL_LIFETIME_SECONDS = 4n * 90n * 24n * 3600n;
153
+
154
+ /**
155
+ * Validates a number returned by an on-chain `ProposalState` enum field and narrows it to the
156
+ * `ProposalState` enum. Throws if the value is out of range.
157
+ */
158
+ function asProposalState(raw: number): ProposalState {
159
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
160
+ if (raw < 0 || raw > ProposalState.Expired) {
161
+ throw new Error(`Invalid proposal state: ${raw}`);
162
+ }
163
+ return raw as ProposalState;
164
+ }
165
+
166
+ export function extractProposalIdFromLogs(logs: Log[]): bigint {
167
+ const parsedLogs = parseEventLogs({
168
+ abi: GovernanceAbi,
169
+ logs: logs,
170
+ eventName: 'Proposed',
171
+ });
172
+
173
+ if (parsedLogs.length === 0) {
174
+ throw new Error('Proposal log not found');
175
+ }
176
+ return parsedLogs[0].args.proposalId;
177
+ }
178
+
179
+ export class ReadOnlyGovernanceContract {
180
+ protected readonly governanceContract: GetContractReturnType<typeof GovernanceAbi, ViemClient>;
181
+
182
+ /**
183
+ * Cache of fully-resolved proposals keyed by id. We populate this lazily and only retain entries
184
+ * whose state is provably terminal -- once `cachedState` is `Executed` or `Dropped` the on-chain
185
+ * proposal struct is frozen and safe to memoize indefinitely. Other state transitions (e.g.
186
+ * Pending -> Active, or accumulating votes) leave the cache untouched and force a fresh fetch.
187
+ */
188
+ private readonly proposalCache: Map<bigint, Proposal> = new Map();
189
+
190
+ /**
191
+ * Cache of `IProposerPayload.getOriginalPayload()` results keyed by wrapper address. The wrapper
192
+ * contract's bytecode is immutable, so this mapping never changes -- a value of `undefined`
193
+ * encodes a proposal whose payload doesn't implement `getOriginalPayload` (e.g. proposeWithLock
194
+ * proposals) and should be treated as "no original".
195
+ */
196
+ private readonly originalPayloadCache: Map<Hex, Hex | undefined> = new Map();
197
+
198
+ /**
199
+ * Payloads (lowercased hex) observed as the subject of an `Executed` Governance proposal. Execution
200
+ * is immutable on-chain, so this verdict never expires within a process. It restores the
201
+ * `'executed'` classification for payloads whose executed proposal has since aged past the bounded
202
+ * lookback below. Lost on restart, at which point the bounded-lookback limitation applies again.
203
+ */
204
+ private readonly executedPayloads: Set<string> = new Set();
205
+
206
+ constructor(
207
+ address: Hex,
208
+ public readonly client: ViemClient,
209
+ ) {
210
+ this.governanceContract = getContract({ address, abi: GovernanceAbi, client: client });
211
+ }
212
+
213
+ public get address() {
214
+ return EthAddress.fromString(this.governanceContract.address);
215
+ }
216
+
217
+ public async getGovernanceProposerAddress() {
218
+ return EthAddress.fromString(await this.governanceContract.read.governanceProposer());
219
+ }
220
+
221
+ public async getConfiguration(): Promise<GovernanceConfiguration> {
222
+ const raw = await this.governanceContract.read.getConfiguration();
223
+ return {
224
+ proposeConfig: {
225
+ lockDelay: raw.proposeConfig.lockDelay,
226
+ lockAmount: raw.proposeConfig.lockAmount,
227
+ },
228
+ votingDelay: raw.votingDelay,
229
+ votingDuration: raw.votingDuration,
230
+ executionDelay: raw.executionDelay,
231
+ gracePeriod: raw.gracePeriod,
232
+ quorum: raw.quorum,
233
+ requiredYeaMargin: raw.requiredYeaMargin,
234
+ minimumVotes: raw.minimumVotes,
235
+ };
236
+ }
237
+
238
+ /**
239
+ * Fetches a proposal by id together with its live state, returning the mapped {@link Proposal}
240
+ * type. Issues `getProposal` and `getProposalState` in parallel so the result carries both the
241
+ * raw stored `cachedState` and the time-derived `state` -- callers can use whichever they need
242
+ * without an extra round-trip.
243
+ *
244
+ * Backed by an in-memory cache that retains entries only when `state` is in one of the four
245
+ * terminal phases (`Executed` / `Rejected` / `Dropped` / `Expired`). At that point the entire
246
+ * proposal struct is provably immutable on-chain (no further votes can be cast and no
247
+ * state-mutating call can succeed), so caching is safe forever. Non-terminal states force a
248
+ * fresh fetch on every call so callers always see fresh `state` and `summedBallot` values.
249
+ */
250
+ public async getProposal(proposalId: bigint): Promise<Proposal> {
251
+ const cached = this.proposalCache.get(proposalId);
252
+ if (cached !== undefined) {
253
+ return cached;
254
+ }
255
+ const [raw, rawState] = await Promise.all([
256
+ this.governanceContract.read.getProposal([proposalId]),
257
+ this.governanceContract.read.getProposalState([proposalId]),
258
+ ]);
259
+ const proposal: Proposal = {
260
+ config: {
261
+ votingDelay: raw.config.votingDelay,
262
+ votingDuration: raw.config.votingDuration,
263
+ executionDelay: raw.config.executionDelay,
264
+ gracePeriod: raw.config.gracePeriod,
265
+ quorum: raw.config.quorum,
266
+ requiredYeaMargin: raw.config.requiredYeaMargin,
267
+ minimumVotes: raw.config.minimumVotes,
268
+ },
269
+ cachedState: asProposalState(raw.cachedState),
270
+ state: asProposalState(rawState),
271
+ payload: EthAddress.fromString(raw.payload),
272
+ proposer: EthAddress.fromString(raw.proposer),
273
+ creation: raw.creation,
274
+ summedBallot: { yea: raw.summedBallot.yea, nay: raw.summedBallot.nay },
275
+ };
276
+ if (TERMINAL_PROPOSAL_STATES.has(proposal.state)) {
277
+ this.proposalCache.set(proposalId, proposal);
278
+ }
279
+ return proposal;
280
+ }
281
+
282
+ /**
283
+ * Returns the live state of a proposal as computed by `Governance.getProposalState`. Prefer
284
+ * {@link getProposal} when you also need any other proposal data -- it returns this same value
285
+ * via {@link Proposal.state} alongside the rest of the struct in a single round-trip.
286
+ */
287
+ public async getProposalState(proposalId: bigint): Promise<ProposalState> {
288
+ return asProposalState(await this.governanceContract.read.getProposalState([proposalId]));
289
+ }
290
+
291
+ public getProposalCount(): Promise<bigint> {
292
+ return this.governanceContract.read.proposalCount();
293
+ }
294
+
295
+ /**
296
+ * Classifies the given original payload against the Governance proposal history. Distinguishes a
297
+ * payload that is still the subject of a live proposal (`'live'`) from one whose proposal was
298
+ * already executed (`'executed'`) from one that has no relevant proposal (`'none'`), so callers can
299
+ * stop re-signalling an executed payload while still re-signalling one whose proposal was merely
300
+ * rejected/dropped/expired (each GovernanceProposer round is independent and there is no
301
+ * payload-level uniqueness check on-chain).
302
+ *
303
+ * A proposal matches the payload either directly (its stored `payload` equals the target, as for
304
+ * `proposeWithLock` proposals) or via its `GSEPayload` wrapper unwrapping to the target. `'live'`
305
+ * (including `Droppable`) takes precedence over `'executed'`, so a payload re-submitted while a
306
+ * prior execution is still in the lookback window reads as `'live'`.
307
+ *
308
+ * Implemented as a bounded view-call sweep over `Governance.proposals` rather than an event scan,
309
+ * because `eth_getLogs` over the full deployment history of a long-lived rollup exceeds typical
310
+ * RPC block-range caps. The number of proposals (`proposalCount`) is small in practice, and we
311
+ * walk newest -> oldest with a hard early-stop on the protocol-wide proposal lifetime cap. This
312
+ * makes the `'executed'` verdict a *bounded lookback* rather than permanent suppression: a proposal
313
+ * executed longer ago than the lifetime cap is only reported once it has been observed and
314
+ * memoized in-process (memo is lost on restart).
315
+ */
316
+ public async getPayloadProposalStatus(payload: Hex): Promise<PayloadProposalStatus> {
317
+ const target = payload.toLowerCase() as Hex;
318
+
319
+ const proposalCount = await this.getProposalCount();
320
+ if (proposalCount === 0n) {
321
+ return this.executedPayloads.has(target) ? 'executed' : 'none';
322
+ }
323
+
324
+ // Anything created before this cutoff is guaranteed terminal regardless of its frozen config.
325
+ const block = await this.client.getBlock();
326
+ const hardCutoff = block.timestamp - MAX_PROPOSAL_LIFETIME_SECONDS;
327
+
328
+ // Proposals are append-only with monotonically non-decreasing creation timestamps, so iterating
329
+ // from newest -> oldest lets us early-stop as soon as we cross the lifetime cutoff.
330
+ for (let id = proposalCount - 1n; id >= 0n; id--) {
331
+ const proposal = await this.getProposal(id);
332
+
333
+ // Hard early-stop: every older proposal is also older than the cutoff and therefore terminal.
334
+ if (proposal.creation < hardCutoff) {
335
+ break;
336
+ }
337
+
338
+ const proposalPayload = proposal.payload.toString().toLowerCase();
339
+ const original = await this.getOriginalPayload(proposal.payload);
340
+ const matches = proposalPayload === target || (original !== undefined && original.toLowerCase() === target);
341
+ if (!matches) {
342
+ continue;
343
+ }
344
+
345
+ // A live or Droppable proposal blocks re-signalling and wins over any executed one.
346
+ if (LIVE_PROPOSAL_STATES.has(proposal.state) || proposal.state === ProposalState.Droppable) {
347
+ return 'live';
348
+ }
349
+
350
+ if (proposal.state === ProposalState.Executed) {
351
+ this.executedPayloads.add(target);
352
+ }
353
+
354
+ // Rejected/Dropped/Expired proposals allow re-proposing the same payload; keep scanning.
355
+ }
356
+
357
+ return this.executedPayloads.has(target) ? 'executed' : 'none';
358
+ }
359
+
360
+ /**
361
+ * Resolves the original payload behind a `GSEPayload` wrapper. Returns `undefined` if the
362
+ * wrapper does not implement `IProposerPayload.getOriginalPayload` (e.g. proposals created via
363
+ * `Governance.proposeWithLock`, which bypass GSEPayload entirely and store the raw `IPayload`
364
+ * directly). Results are memoized indefinitely because deployed wrapper bytecode is immutable.
365
+ */
366
+ private async getOriginalPayload(wrapper: EthAddress): Promise<Hex | undefined> {
367
+ const key = wrapper.toString();
368
+ if (this.originalPayloadCache.has(key)) {
369
+ return this.originalPayloadCache.get(key);
370
+ }
371
+ let original: Hex | undefined;
372
+ try {
373
+ original = await this.client.readContract({
374
+ address: key,
375
+ abi: ProposerPayloadAbi,
376
+ functionName: 'getOriginalPayload',
377
+ });
378
+ } catch {
379
+ original = undefined;
380
+ }
381
+ this.originalPayloadCache.set(key, original);
382
+ return original;
383
+ }
384
+
385
+ public async awaitProposalActive({ proposalId, logger }: { proposalId: bigint; logger: Logger }) {
386
+ const state = await this.getProposalState(proposalId);
387
+ if (state === ProposalState.Active) {
388
+ return;
389
+ } else if (state !== ProposalState.Pending) {
390
+ throw new Error(`Proposal ${proposalId} is in state [${state}]: it will never be active`);
391
+ } else {
392
+ const proposal = await this.getProposal(proposalId);
393
+ const startOfActive = proposal.creation + proposal.config.votingDelay;
394
+ const block = await this.client.getBlock();
395
+ // Add 12 seconds to the time to make sure we don't vote too early
396
+ const secondsToActive = Number(startOfActive - block.timestamp) + 12;
397
+ const now = new Date();
398
+ logger.info(`
399
+ The time is ${now.toISOString()}.
400
+ The proposal will be active at ${new Date(Number(startOfActive) * 1000).toISOString()}.
401
+ Waiting ${secondsToActive} seconds for proposal to be active.
402
+ `);
403
+ await sleep(secondsToActive * 1000);
404
+ }
405
+ }
406
+
407
+ public async awaitProposalExecutable({ proposalId, logger }: { proposalId: bigint; logger: Logger }) {
408
+ const state = await this.getProposalState(proposalId);
409
+ if (state === ProposalState.Executable) {
410
+ return;
411
+ } else if (
412
+ ![ProposalState.Pending, ProposalState.Active, ProposalState.Queued, ProposalState.Executable].includes(state)
413
+ ) {
414
+ throw new Error(`Proposal ${proposalId} is in state [${state}]: it will never be executable`);
415
+ } else {
416
+ const proposal = await this.getProposal(proposalId);
417
+ const startOfExecutable =
418
+ proposal.creation +
419
+ proposal.config.votingDelay +
420
+ proposal.config.votingDuration +
421
+ proposal.config.executionDelay;
422
+ const block = await this.client.getBlock();
423
+ const secondsToExecutable = Number(startOfExecutable - block.timestamp) + 12;
424
+ const now = new Date();
425
+ logger.info(`
426
+ The time is ${now.toISOString()}.
427
+ The proposal will be executable at ${new Date(Number(startOfExecutable) * 1000).toISOString()}.
428
+ Waiting ${secondsToExecutable} seconds for proposal to be executable.
429
+ `);
430
+ await sleep(secondsToExecutable * 1000);
431
+ }
432
+ }
433
+ }
434
+
435
+ export class GovernanceContract extends ReadOnlyGovernanceContract {
436
+ protected override readonly governanceContract: GetContractReturnType<typeof GovernanceAbi, ExtendedViemWalletClient>;
437
+
438
+ constructor(
439
+ address: Hex | EthAddress,
440
+ public override readonly client: ExtendedViemWalletClient,
441
+ ) {
442
+ if (address instanceof EthAddress) {
443
+ address = address.toString();
444
+ }
445
+ super(address, client);
446
+ if (!isExtendedClient(client)) {
447
+ throw new Error('GovernanceContract has to be instantiated with a wallet client.');
448
+ }
449
+ this.governanceContract = getContract({ address, abi: GovernanceAbi, client });
450
+ }
451
+
452
+ public async deposit(onBehalfOf: Hex, amount: bigint) {
453
+ const depositTx = await this.governanceContract.write.deposit([onBehalfOf, amount]);
454
+ await this.client.waitForTransactionReceipt({ hash: depositTx });
455
+ }
456
+
457
+ public async proposeWithLock({
458
+ payloadAddress,
459
+ withdrawAddress,
460
+ }: {
461
+ payloadAddress: Hex;
462
+ withdrawAddress: Hex;
463
+ }): Promise<bigint> {
464
+ const proposeTx = await this.governanceContract.write.proposeWithLock([payloadAddress, withdrawAddress]);
465
+ const receipt = await this.client.waitForTransactionReceipt({ hash: proposeTx });
466
+ if (receipt.status !== 'success') {
467
+ throw new Error(`Proposal failed: ${receipt.status}`);
468
+ }
469
+ return extractProposalIdFromLogs(receipt.logs);
470
+ }
471
+
472
+ public async getPower(): Promise<bigint> {
473
+ const now = await this.client.getBlock();
474
+ return this.governanceContract.read.powerAt([this.client.account.address, now.timestamp]);
475
+ }
476
+
477
+ /** Returns the user's voting power for a specific proposal, checked at pendingThrough timestamp. */
478
+ public async getPowerForProposal(proposalId: bigint): Promise<bigint> {
479
+ const proposal = await this.getProposal(proposalId);
480
+ const pendingThrough = proposal.creation + proposal.config.votingDelay;
481
+ return this.governanceContract.read.powerAt([this.client.account.address, pendingThrough]);
482
+ }
483
+
484
+ public async vote({
485
+ proposalId,
486
+ voteAmount,
487
+ inFavor,
488
+ retries = 10,
489
+ logger,
490
+ }: {
491
+ proposalId: bigint;
492
+ voteAmount: bigint | undefined;
493
+ inFavor: boolean;
494
+ retries: number;
495
+ logger: Logger;
496
+ }) {
497
+ const l1TxUtils = createL1TxUtils(this.client, { logger });
498
+ const retryDelaySeconds = 12;
499
+
500
+ voteAmount = voteAmount ?? (await this.getPowerForProposal(proposalId));
501
+
502
+ let success = false;
503
+ for (let i = 0; i < retries; i++) {
504
+ try {
505
+ const voteFunctionData: EncodeFunctionDataParameters<typeof GovernanceAbi, 'vote'> = {
506
+ abi: GovernanceAbi,
507
+ functionName: 'vote',
508
+ args: [proposalId, voteAmount, inFavor],
509
+ };
510
+ const encodedVoteData = encodeFunctionData(voteFunctionData);
511
+
512
+ const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
513
+ to: this.governanceContract.address,
514
+ abi: GovernanceAbi,
515
+ data: encodedVoteData,
516
+ });
517
+
518
+ if (receipt.status === 'success') {
519
+ success = true;
520
+ break;
521
+ } else {
522
+ const args = {
523
+ ...voteFunctionData,
524
+ address: this.governanceContract.address,
525
+ };
526
+ const errorMsg = await l1TxUtils.tryGetErrorFromRevertedTx(encodedVoteData, args, undefined, []);
527
+ logger.error(`Error voting on proposal ${proposalId}: ${errorMsg}`);
528
+ }
529
+ } catch (error) {
530
+ logger.error(`Error voting on proposal ${proposalId}: ${error}`);
531
+ }
532
+
533
+ logger.info(`Retrying vote on proposal ${proposalId} in ${retryDelaySeconds} seconds`);
534
+ await sleep(retryDelaySeconds * 1000);
535
+ }
536
+ if (!success) {
537
+ throw new Error(`Failed to vote on proposal ${proposalId} after ${retries} retries`);
538
+ }
539
+ logger.info(`Voted [${inFavor ? 'yea' : 'nay'}] on proposal [${proposalId}]`);
540
+ const proposal = await this.getProposal(proposalId);
541
+ logger.info(`Proposal [${proposalId}] has cached state [${proposal.cachedState}]`);
542
+ logger.info(`Proposal [${proposalId}] has summedBallot yea [${proposal.summedBallot.yea}]`);
543
+ logger.info(`Proposal [${proposalId}] has summedBallot nay [${proposal.summedBallot.nay}]`);
544
+ }
545
+
546
+ public async executeProposal({
547
+ proposalId,
548
+ retries = 10,
549
+ logger,
550
+ }: {
551
+ proposalId: bigint;
552
+ retries: number;
553
+ logger: Logger;
554
+ }) {
555
+ const l1TxUtils = createL1TxUtils(this.client, { logger });
556
+ const retryDelaySeconds = 12;
557
+ let success = false;
558
+ for (let i = 0; i < retries; i++) {
559
+ try {
560
+ const executeFunctionData: EncodeFunctionDataParameters<typeof GovernanceAbi, 'execute'> = {
561
+ abi: GovernanceAbi,
562
+ functionName: 'execute',
563
+ args: [proposalId],
564
+ };
565
+ const encodedExecuteData = encodeFunctionData(executeFunctionData);
566
+
567
+ const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
568
+ to: this.governanceContract.address,
569
+ abi: GovernanceAbi,
570
+ data: encodedExecuteData,
571
+ });
572
+
573
+ if (receipt.status === 'success') {
574
+ success = true;
575
+ break;
576
+ } else {
577
+ const args = {
578
+ ...executeFunctionData,
579
+ address: this.governanceContract.address,
580
+ };
581
+ const errorMsg = await l1TxUtils.tryGetErrorFromRevertedTx(encodedExecuteData, args, undefined, []);
582
+ logger.error(`Error executing proposal ${proposalId}: ${errorMsg}`);
583
+ }
584
+ } catch (error) {
585
+ logger.error(`Error executing proposal ${proposalId}: ${error}`);
586
+ }
587
+
588
+ logger.info(`Retrying execute proposal ${proposalId} in ${retryDelaySeconds} seconds`);
589
+ await sleep(retryDelaySeconds * 1000);
590
+ }
591
+ if (!success) {
592
+ throw new Error(`Failed to execute proposal ${proposalId} after ${retries} retries`);
593
+ } else {
594
+ logger.info(`Executed proposal ${proposalId}`);
595
+ }
596
+ }
597
+ }