@aztec/ethereum 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f

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 (188) hide show
  1. package/dest/client.d.ts +16 -2
  2. package/dest/client.d.ts.map +1 -1
  3. package/dest/client.js +27 -7
  4. package/dest/config.d.ts +24 -32
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +63 -62
  7. package/dest/contracts/chain_state_override.d.ts +78 -0
  8. package/dest/contracts/chain_state_override.d.ts.map +1 -0
  9. package/dest/contracts/chain_state_override.js +137 -0
  10. package/dest/contracts/fee_asset_handler.d.ts +6 -5
  11. package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
  12. package/dest/contracts/fee_asset_handler.js +11 -9
  13. package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
  14. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  15. package/dest/contracts/fee_asset_price_oracle.js +656 -0
  16. package/dest/contracts/governance.d.ts +110 -33
  17. package/dest/contracts/governance.d.ts.map +1 -1
  18. package/dest/contracts/governance.js +207 -16
  19. package/dest/contracts/governance_proposer.d.ts +33 -1
  20. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  21. package/dest/contracts/governance_proposer.js +438 -10
  22. package/dest/contracts/inbox.d.ts +22 -1
  23. package/dest/contracts/inbox.d.ts.map +1 -1
  24. package/dest/contracts/inbox.js +42 -2
  25. package/dest/contracts/index.d.ts +6 -3
  26. package/dest/contracts/index.d.ts.map +1 -1
  27. package/dest/contracts/index.js +5 -2
  28. package/dest/contracts/log.d.ts +13 -0
  29. package/dest/contracts/log.d.ts.map +1 -0
  30. package/dest/contracts/log.js +1 -0
  31. package/dest/contracts/multicall.d.ts +127 -12
  32. package/dest/contracts/multicall.d.ts.map +1 -1
  33. package/dest/contracts/multicall.js +201 -93
  34. package/dest/contracts/outbox.d.ts +58 -0
  35. package/dest/contracts/outbox.d.ts.map +1 -0
  36. package/dest/contracts/outbox.js +109 -0
  37. package/dest/contracts/registry.d.ts +3 -1
  38. package/dest/contracts/registry.d.ts.map +1 -1
  39. package/dest/contracts/registry.js +30 -1
  40. package/dest/contracts/rollup.d.ts +5409 -115
  41. package/dest/contracts/rollup.d.ts.map +1 -1
  42. package/dest/contracts/rollup.js +1027 -189
  43. package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +3 -4
  44. package/dest/contracts/slashing_proposer.d.ts.map +1 -0
  45. package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +18 -13
  46. package/dest/deploy_aztec_l1_contracts.d.ts +20 -9
  47. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
  48. package/dest/deploy_aztec_l1_contracts.js +113 -37
  49. package/dest/deploy_l1_contract.js +3 -3
  50. package/dest/generated/l1-contracts-defaults.d.ts +30 -0
  51. package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
  52. package/dest/generated/l1-contracts-defaults.js +30 -0
  53. package/dest/l1_artifacts.d.ts +18360 -16454
  54. package/dest/l1_artifacts.d.ts.map +1 -1
  55. package/dest/l1_artifacts.js +9 -24
  56. package/dest/l1_contract_addresses.d.ts +61 -65
  57. package/dest/l1_contract_addresses.d.ts.map +1 -1
  58. package/dest/l1_contract_addresses.js +101 -82
  59. package/dest/l1_reader.d.ts +5 -5
  60. package/dest/l1_reader.d.ts.map +1 -1
  61. package/dest/l1_reader.js +9 -7
  62. package/dest/l1_tx_utils/config.d.ts +7 -1
  63. package/dest/l1_tx_utils/config.d.ts.map +1 -1
  64. package/dest/l1_tx_utils/config.js +14 -1
  65. package/dest/l1_tx_utils/constants.d.ts +1 -1
  66. package/dest/l1_tx_utils/constants.js +2 -2
  67. package/dest/l1_tx_utils/factory.d.ts +18 -10
  68. package/dest/l1_tx_utils/factory.d.ts.map +1 -1
  69. package/dest/l1_tx_utils/factory.js +17 -7
  70. package/dest/l1_tx_utils/fee-strategies/index.d.ts +3 -2
  71. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -1
  72. package/dest/l1_tx_utils/fee-strategies/index.js +2 -1
  73. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +2 -12
  74. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -1
  75. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +36 -18
  76. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +2 -11
  77. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -1
  78. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +37 -19
  79. package/dest/l1_tx_utils/fee-strategies/types.d.ts +14 -27
  80. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -1
  81. package/dest/l1_tx_utils/fee-strategies/types.js +0 -21
  82. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +15 -15
  83. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -1
  84. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +9 -15
  85. package/dest/l1_tx_utils/index-blobs.d.ts +3 -3
  86. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -1
  87. package/dest/l1_tx_utils/index-blobs.js +2 -2
  88. package/dest/l1_tx_utils/index.d.ts +2 -1
  89. package/dest/l1_tx_utils/index.d.ts.map +1 -1
  90. package/dest/l1_tx_utils/index.js +1 -0
  91. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +2 -2
  92. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -1
  93. package/dest/l1_tx_utils/l1_fee_analyzer.js +3 -3
  94. package/dest/l1_tx_utils/l1_tx_utils.d.ts +26 -7
  95. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
  96. package/dest/l1_tx_utils/l1_tx_utils.js +101 -66
  97. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +1 -5
  98. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  99. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +25 -58
  100. package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
  101. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  102. package/dest/{test → l1_tx_utils}/tx_delayer.js +67 -37
  103. package/dest/publisher_manager.d.ts +21 -6
  104. package/dest/publisher_manager.d.ts.map +1 -1
  105. package/dest/publisher_manager.js +81 -7
  106. package/dest/queries.d.ts +14 -3
  107. package/dest/queries.d.ts.map +1 -1
  108. package/dest/queries.js +74 -7
  109. package/dest/test/chain_monitor.d.ts +23 -3
  110. package/dest/test/chain_monitor.d.ts.map +1 -1
  111. package/dest/test/chain_monitor.js +39 -4
  112. package/dest/test/eth_cheat_codes.d.ts +24 -4
  113. package/dest/test/eth_cheat_codes.d.ts.map +1 -1
  114. package/dest/test/eth_cheat_codes.js +17 -4
  115. package/dest/test/index.d.ts +1 -3
  116. package/dest/test/index.d.ts.map +1 -1
  117. package/dest/test/index.js +0 -2
  118. package/dest/test/rollup_cheat_codes.d.ts +34 -3
  119. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  120. package/dest/test/rollup_cheat_codes.js +75 -6
  121. package/dest/test/start_anvil.d.ts +23 -3
  122. package/dest/test/start_anvil.d.ts.map +1 -1
  123. package/dest/test/start_anvil.js +143 -29
  124. package/dest/test/upgrade_utils.js +2 -2
  125. package/dest/utils.d.ts +9 -1
  126. package/dest/utils.d.ts.map +1 -1
  127. package/dest/utils.js +81 -12
  128. package/package.json +9 -10
  129. package/src/client.ts +28 -2
  130. package/src/config.ts +81 -63
  131. package/src/contracts/README.md +157 -0
  132. package/src/contracts/chain_state_override.ts +200 -0
  133. package/src/contracts/fee_asset_handler.ts +10 -7
  134. package/src/contracts/fee_asset_price_oracle.ts +285 -0
  135. package/src/contracts/governance.ts +279 -13
  136. package/src/contracts/governance_proposer.ts +58 -2
  137. package/src/contracts/inbox.ts +62 -2
  138. package/src/contracts/index.ts +5 -2
  139. package/src/contracts/log.ts +13 -0
  140. package/src/contracts/multicall.ts +243 -102
  141. package/src/contracts/outbox.ts +128 -0
  142. package/src/contracts/registry.ts +31 -1
  143. package/src/contracts/rollup.ts +728 -148
  144. package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +16 -14
  145. package/src/deploy_aztec_l1_contracts.ts +137 -47
  146. package/src/deploy_l1_contract.ts +3 -3
  147. package/src/generated/l1-contracts-defaults.ts +32 -0
  148. package/src/l1_artifacts.ts +12 -35
  149. package/src/l1_contract_addresses.ts +120 -94
  150. package/src/l1_reader.ts +17 -10
  151. package/src/l1_tx_utils/config.ts +20 -0
  152. package/src/l1_tx_utils/constants.ts +2 -2
  153. package/src/l1_tx_utils/factory.ts +31 -31
  154. package/src/l1_tx_utils/fee-strategies/index.ts +1 -1
  155. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +46 -42
  156. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +49 -45
  157. package/src/l1_tx_utils/fee-strategies/types.ts +14 -46
  158. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +43 -54
  159. package/src/l1_tx_utils/index-blobs.ts +2 -2
  160. package/src/l1_tx_utils/index.ts +1 -0
  161. package/src/l1_tx_utils/l1_fee_analyzer.ts +2 -3
  162. package/src/l1_tx_utils/l1_tx_utils.ts +99 -48
  163. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +31 -66
  164. package/src/{test → l1_tx_utils}/tx_delayer.ts +93 -56
  165. package/src/publisher_manager.ts +107 -10
  166. package/src/queries.ts +81 -7
  167. package/src/test/chain_monitor.ts +66 -4
  168. package/src/test/eth_cheat_codes.ts +16 -4
  169. package/src/test/index.ts +0 -2
  170. package/src/test/rollup_cheat_codes.ts +82 -6
  171. package/src/test/start_anvil.ts +177 -29
  172. package/src/test/upgrade_utils.ts +2 -2
  173. package/src/utils.ts +88 -14
  174. package/dest/contracts/empire_slashing_proposer.d.ts +0 -67
  175. package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
  176. package/dest/contracts/empire_slashing_proposer.js +0 -209
  177. package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
  178. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +0 -26
  179. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +0 -1
  180. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +0 -26
  181. package/dest/test/delayed_tx_utils.d.ts +0 -13
  182. package/dest/test/delayed_tx_utils.d.ts.map +0 -1
  183. package/dest/test/delayed_tx_utils.js +0 -28
  184. package/dest/test/tx_delayer.d.ts +0 -36
  185. package/dest/test/tx_delayer.d.ts.map +0 -1
  186. package/src/contracts/empire_slashing_proposer.ts +0 -270
  187. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
  188. package/src/test/delayed_tx_utils.ts +0 -52
@@ -14,9 +14,24 @@ import {
14
14
  } from 'viem';
15
15
 
16
16
  import type { L1ContractAddresses } from '../l1_contract_addresses.js';
17
- import { createL1TxUtilsFromViemWallet } from '../l1_tx_utils/index.js';
17
+ import { createL1TxUtils } from '../l1_tx_utils/index.js';
18
18
  import { type ExtendedViemWalletClient, type ViemClient, isExtendedClient } from '../types.js';
19
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
+
20
35
  export type L1GovernanceContractAddresses = Pick<
21
36
  L1ContractAddresses,
22
37
  'governanceAddress' | 'rollupAddress' | 'registryAddress' | 'governanceProposerAddress'
@@ -34,6 +49,98 @@ export enum ProposalState {
34
49
  Expired,
35
50
  }
36
51
 
52
+ /** Vote tallies on a single proposal. Both fields are mutated by `Governance.vote`. */
53
+ export interface Ballot {
54
+ yea: bigint;
55
+ nay: bigint;
56
+ }
57
+
58
+ /**
59
+ * Snapshot of the timing/quorum parameters that govern a single proposal's lifecycle. Each proposal
60
+ * stores its own copy at creation time (see `_propose` in Governance.sol), so this snapshot is
61
+ * immutable for the lifetime of the proposal even if the global `Configuration` changes later.
62
+ */
63
+ export interface ProposalConfiguration {
64
+ votingDelay: bigint;
65
+ votingDuration: bigint;
66
+ executionDelay: bigint;
67
+ gracePeriod: bigint;
68
+ quorum: bigint;
69
+ requiredYeaMargin: bigint;
70
+ minimumVotes: bigint;
71
+ }
72
+
73
+ /** Parameters for `Governance.proposeWithLock`. Stored only in the global Configuration, never on a proposal. */
74
+ export interface ProposeWithLockConfiguration {
75
+ lockDelay: bigint;
76
+ lockAmount: bigint;
77
+ }
78
+
79
+ /**
80
+ * Live, mutable governance configuration. `proposeConfig` is the lock configuration used by
81
+ * `proposeWithLock`; the remaining fields are the same shape as `ProposalConfiguration` and are
82
+ * snapshotted onto each new proposal at creation time.
83
+ */
84
+ export interface GovernanceConfiguration extends ProposalConfiguration {
85
+ proposeConfig: ProposeWithLockConfiguration;
86
+ }
87
+
88
+ /**
89
+ * A governance proposal augmented with its live (computed) state.
90
+ *
91
+ * Mutability:
92
+ * - `config`, `payload`, `proposer`, `creation` are immutable for the lifetime of the proposal.
93
+ * - `cachedState` is the raw value stored on-chain. It is only written when a proposal is explicitly
94
+ * executed or dropped, so for time-derived terminal states (Rejected, Expired) it remains at the
95
+ * value that was current when the proposal was created.
96
+ * - `state` is the computed state returned by `Governance.getProposalState`. This is the value
97
+ * callers almost always want -- it reflects time-derived transitions that `cachedState` does not.
98
+ * - `summedBallot` is mutated by every `Governance.vote` call while the proposal is Active.
99
+ *
100
+ * Once `state` is in a terminal phase (`Executed`/`Rejected`/`Dropped`/`Expired`) the entire struct
101
+ * is provably immutable on-chain (no further votes can be cast and no state-mutating call to
102
+ * `execute`/`dropProposal` can succeed), and the wrapper memoizes it.
103
+ */
104
+ export interface Proposal {
105
+ config: ProposalConfiguration;
106
+ cachedState: ProposalState;
107
+ state: ProposalState;
108
+ payload: EthAddress;
109
+ proposer: EthAddress;
110
+ creation: bigint;
111
+ summedBallot: Ballot;
112
+ }
113
+
114
+ /** Set of `ProposalState` values for which a proposal is fully immutable on-chain. */
115
+ const TERMINAL_PROPOSAL_STATES: ReadonlySet<ProposalState> = new Set([
116
+ ProposalState.Executed,
117
+ ProposalState.Rejected,
118
+ ProposalState.Dropped,
119
+ ProposalState.Expired,
120
+ ]);
121
+
122
+ // Hard upper bound on the wall-clock lifetime of any Governance proposal, in seconds.
123
+ // Each proposal stores its own snapshot of `ProposalConfiguration` at creation time and progresses
124
+ // through Pending -> Active -> Queued -> Executable using those frozen durations
125
+ // (see `ProposalLib.{pendingThrough,activeThrough,queuedThrough,executableThrough}`). Each of those
126
+ // four durations is bounded by `ConfigurationLib.TIME_UPPER = 90 days` (validated in
127
+ // `ConfigurationLib.assertValid`), so no proposal can be live for more than 4 * 90 days regardless
128
+ // of what config it was created under. Once past this point, the proposal is guaranteed to be in a
129
+ // terminal state (Executed / Rejected / Dropped / Expired).
130
+ export const MAX_PROPOSAL_LIFETIME_SECONDS = 4n * 90n * 24n * 3600n;
131
+
132
+ /**
133
+ * Validates a number returned by an on-chain `ProposalState` enum field and narrows it to the
134
+ * `ProposalState` enum. Throws if the value is out of range.
135
+ */
136
+ function asProposalState(raw: number): ProposalState {
137
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
138
+ if (raw < 0 || raw > ProposalState.Expired) {
139
+ throw new Error(`Invalid proposal state: ${raw}`);
140
+ }
141
+ return raw as ProposalState;
142
+ }
143
+
37
144
  export function extractProposalIdFromLogs(logs: Log[]): bigint {
38
145
  const parsedLogs = parseEventLogs({
39
146
  abi: GovernanceAbi,
@@ -50,6 +157,22 @@ export function extractProposalIdFromLogs(logs: Log[]): bigint {
50
157
  export class ReadOnlyGovernanceContract {
51
158
  protected readonly governanceContract: GetContractReturnType<typeof GovernanceAbi, ViemClient>;
52
159
 
160
+ /**
161
+ * Cache of fully-resolved proposals keyed by id. We populate this lazily and only retain entries
162
+ * whose state is provably terminal -- once `cachedState` is `Executed` or `Dropped` the on-chain
163
+ * proposal struct is frozen and safe to memoize indefinitely. Other state transitions (e.g.
164
+ * Pending -> Active, or accumulating votes) leave the cache untouched and force a fresh fetch.
165
+ */
166
+ private readonly proposalCache: Map<bigint, Proposal> = new Map();
167
+
168
+ /**
169
+ * Cache of `IProposerPayload.getOriginalPayload()` results keyed by wrapper address. The wrapper
170
+ * contract's bytecode is immutable, so this mapping never changes -- a value of `undefined`
171
+ * encodes a proposal whose payload doesn't implement `getOriginalPayload` (e.g. proposeWithLock
172
+ * proposals) and should be treated as "no original".
173
+ */
174
+ private readonly originalPayloadCache: Map<Hex, Hex | undefined> = new Map();
175
+
53
176
  constructor(
54
177
  address: Hex,
55
178
  public readonly client: ViemClient,
@@ -65,21 +188,155 @@ export class ReadOnlyGovernanceContract {
65
188
  return EthAddress.fromString(await this.governanceContract.read.governanceProposer());
66
189
  }
67
190
 
68
- public getConfiguration() {
69
- return this.governanceContract.read.getConfiguration();
191
+ public async getConfiguration(): Promise<GovernanceConfiguration> {
192
+ const raw = await this.governanceContract.read.getConfiguration();
193
+ return {
194
+ proposeConfig: {
195
+ lockDelay: raw.proposeConfig.lockDelay,
196
+ lockAmount: raw.proposeConfig.lockAmount,
197
+ },
198
+ votingDelay: raw.votingDelay,
199
+ votingDuration: raw.votingDuration,
200
+ executionDelay: raw.executionDelay,
201
+ gracePeriod: raw.gracePeriod,
202
+ quorum: raw.quorum,
203
+ requiredYeaMargin: raw.requiredYeaMargin,
204
+ minimumVotes: raw.minimumVotes,
205
+ };
70
206
  }
71
207
 
72
- public getProposal(proposalId: bigint) {
73
- return this.governanceContract.read.getProposal([proposalId]);
208
+ /**
209
+ * Fetches a proposal by id together with its live state, returning the mapped {@link Proposal}
210
+ * type. Issues `getProposal` and `getProposalState` in parallel so the result carries both the
211
+ * raw stored `cachedState` and the time-derived `state` -- callers can use whichever they need
212
+ * without an extra round-trip.
213
+ *
214
+ * Backed by an in-memory cache that retains entries only when `state` is in one of the four
215
+ * terminal phases (`Executed` / `Rejected` / `Dropped` / `Expired`). At that point the entire
216
+ * proposal struct is provably immutable on-chain (no further votes can be cast and no
217
+ * state-mutating call can succeed), so caching is safe forever. Non-terminal states force a
218
+ * fresh fetch on every call so callers always see fresh `state` and `summedBallot` values.
219
+ */
220
+ public async getProposal(proposalId: bigint): Promise<Proposal> {
221
+ const cached = this.proposalCache.get(proposalId);
222
+ if (cached !== undefined) {
223
+ return cached;
224
+ }
225
+ const [raw, rawState] = await Promise.all([
226
+ this.governanceContract.read.getProposal([proposalId]),
227
+ this.governanceContract.read.getProposalState([proposalId]),
228
+ ]);
229
+ const proposal: Proposal = {
230
+ config: {
231
+ votingDelay: raw.config.votingDelay,
232
+ votingDuration: raw.config.votingDuration,
233
+ executionDelay: raw.config.executionDelay,
234
+ gracePeriod: raw.config.gracePeriod,
235
+ quorum: raw.config.quorum,
236
+ requiredYeaMargin: raw.config.requiredYeaMargin,
237
+ minimumVotes: raw.config.minimumVotes,
238
+ },
239
+ cachedState: asProposalState(raw.cachedState),
240
+ state: asProposalState(rawState),
241
+ payload: EthAddress.fromString(raw.payload),
242
+ proposer: EthAddress.fromString(raw.proposer),
243
+ creation: raw.creation,
244
+ summedBallot: { yea: raw.summedBallot.yea, nay: raw.summedBallot.nay },
245
+ };
246
+ if (TERMINAL_PROPOSAL_STATES.has(proposal.state)) {
247
+ this.proposalCache.set(proposalId, proposal);
248
+ }
249
+ return proposal;
74
250
  }
75
251
 
252
+ /**
253
+ * Returns the live state of a proposal as computed by `Governance.getProposalState`. Prefer
254
+ * {@link getProposal} when you also need any other proposal data -- it returns this same value
255
+ * via {@link Proposal.state} alongside the rest of the struct in a single round-trip.
256
+ */
76
257
  public async getProposalState(proposalId: bigint): Promise<ProposalState> {
77
- const state = await this.governanceContract.read.getProposalState([proposalId]);
78
- // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
79
- if (state < 0 || state > ProposalState.Expired) {
80
- throw new Error(`Invalid proposal state: ${state}`);
258
+ return asProposalState(await this.governanceContract.read.getProposalState([proposalId]));
259
+ }
260
+
261
+ public getProposalCount(): Promise<bigint> {
262
+ return this.governanceContract.read.proposalCount();
263
+ }
264
+
265
+ /**
266
+ * Checks whether the given original payload is currently the subject of a live (non-terminal)
267
+ * Governance proposal. Returns true only if a proposal references this payload and is still in
268
+ * Pending, Active, Queued, or Executable state. Terminal proposals (Executed, Rejected, Dropped,
269
+ * Expired) are ignored, because once a proposal reaches a terminal state the same original
270
+ * payload may legitimately be re-signaled and re-submitted via the GovernanceProposer (each round
271
+ * is independent and there is no payload-level uniqueness check on-chain).
272
+ *
273
+ * Implemented as a bounded view-call sweep over `Governance.proposals` rather than an event scan,
274
+ * because `eth_getLogs` over the full deployment history of a long-lived rollup exceeds typical
275
+ * RPC block-range caps. The number of proposals (`proposalCount`) is small in practice, and we
276
+ * walk newest -> oldest with a hard early-stop on the protocol-wide proposal lifetime cap.
277
+ */
278
+ public async hasActiveProposalWithPayload(payload: Hex): Promise<boolean> {
279
+ const proposalCount = await this.getProposalCount();
280
+ if (proposalCount === 0n) {
281
+ return false;
282
+ }
283
+
284
+ // Anything created before this cutoff is guaranteed terminal regardless of its frozen config.
285
+ const block = await this.client.getBlock();
286
+ const hardCutoff = block.timestamp - MAX_PROPOSAL_LIFETIME_SECONDS;
287
+
288
+ const target = payload.toLowerCase() as Hex;
289
+
290
+ // Proposals are append-only with monotonically non-decreasing creation timestamps, so iterating
291
+ // from newest -> oldest lets us early-stop as soon as we cross the lifetime cutoff.
292
+ for (let id = proposalCount - 1n; id >= 0n; id--) {
293
+ const proposal = await this.getProposal(id);
294
+
295
+ // Hard early-stop: every older proposal is also older than the cutoff and therefore terminal.
296
+ if (proposal.creation < hardCutoff) {
297
+ return false;
298
+ }
299
+
300
+ const original = await this.getOriginalPayload(proposal.payload);
301
+ if (original === undefined || original.toLowerCase() !== target) {
302
+ continue;
303
+ }
304
+
305
+ // The wrapper unwraps to our payload. Only treat this as "already proposed" if the proposal
306
+ // is still live -- terminal states allow re-proposing the same payload in a later round.
307
+ if (TERMINAL_PROPOSAL_STATES.has(proposal.state)) {
308
+ continue;
309
+ }
310
+
311
+ return true;
312
+ }
313
+
314
+ return false;
315
+ }
316
+
317
+ /**
318
+ * Resolves the original payload behind a `GSEPayload` wrapper. Returns `undefined` if the
319
+ * wrapper does not implement `IProposerPayload.getOriginalPayload` (e.g. proposals created via
320
+ * `Governance.proposeWithLock`, which bypass GSEPayload entirely and store the raw `IPayload`
321
+ * directly). Results are memoized indefinitely because deployed wrapper bytecode is immutable.
322
+ */
323
+ private async getOriginalPayload(wrapper: EthAddress): Promise<Hex | undefined> {
324
+ const key = wrapper.toString();
325
+ if (this.originalPayloadCache.has(key)) {
326
+ return this.originalPayloadCache.get(key);
327
+ }
328
+ let original: Hex | undefined;
329
+ try {
330
+ original = await this.client.readContract({
331
+ address: key,
332
+ abi: ProposerPayloadAbi,
333
+ functionName: 'getOriginalPayload',
334
+ });
335
+ } catch {
336
+ original = undefined;
81
337
  }
82
- return state as ProposalState;
338
+ this.originalPayloadCache.set(key, original);
339
+ return original;
83
340
  }
84
341
 
85
342
  public async awaitProposalActive({ proposalId, logger }: { proposalId: bigint; logger: Logger }) {
@@ -174,6 +431,13 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
174
431
  return this.governanceContract.read.powerAt([this.client.account.address, now.timestamp]);
175
432
  }
176
433
 
434
+ /** Returns the user's voting power for a specific proposal, checked at pendingThrough timestamp. */
435
+ public async getPowerForProposal(proposalId: bigint): Promise<bigint> {
436
+ const proposal = await this.getProposal(proposalId);
437
+ const pendingThrough = proposal.creation + proposal.config.votingDelay;
438
+ return this.governanceContract.read.powerAt([this.client.account.address, pendingThrough]);
439
+ }
440
+
177
441
  public async vote({
178
442
  proposalId,
179
443
  voteAmount,
@@ -187,10 +451,10 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
187
451
  retries: number;
188
452
  logger: Logger;
189
453
  }) {
190
- const l1TxUtils = createL1TxUtilsFromViemWallet(this.client, { logger });
454
+ const l1TxUtils = createL1TxUtils(this.client, { logger });
191
455
  const retryDelaySeconds = 12;
192
456
 
193
- voteAmount = voteAmount ?? (await this.getPower());
457
+ voteAmount = voteAmount ?? (await this.getPowerForProposal(proposalId));
194
458
 
195
459
  let success = false;
196
460
  for (let i = 0; i < retries; i++) {
@@ -204,6 +468,7 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
204
468
 
205
469
  const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
206
470
  to: this.governanceContract.address,
471
+ abi: GovernanceAbi,
207
472
  data: encodedVoteData,
208
473
  });
209
474
 
@@ -244,7 +509,7 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
244
509
  retries: number;
245
510
  logger: Logger;
246
511
  }) {
247
- const l1TxUtils = createL1TxUtilsFromViemWallet(this.client, { logger });
512
+ const l1TxUtils = createL1TxUtils(this.client, { logger });
248
513
  const retryDelaySeconds = 12;
249
514
  let success = false;
250
515
  for (let i = 0; i < retries; i++) {
@@ -258,6 +523,7 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
258
523
 
259
524
  const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
260
525
  to: this.governanceContract.address,
526
+ abi: GovernanceAbi,
261
527
  data: encodedExecuteData,
262
528
  });
263
529
 
@@ -15,11 +15,19 @@ import {
15
15
  import type { L1TxRequest, L1TxUtils } from '../l1_tx_utils/index.js';
16
16
  import type { ViemClient } from '../types.js';
17
17
  import { type IEmpireBase, encodeSignal, encodeSignalWithSignature, signSignalWithSig } from './empire_base.js';
18
- import { extractProposalIdFromLogs } from './governance.js';
18
+ import { ReadOnlyGovernanceContract, extractProposalIdFromLogs } from './governance.js';
19
19
 
20
20
  export class GovernanceProposerContract implements IEmpireBase {
21
21
  private readonly proposer: GetContractReturnType<typeof GovernanceProposerAbi, ViemClient>;
22
22
 
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
+
23
31
  constructor(
24
32
  public readonly client: ViemClient,
25
33
  address: Hex | EthAddress,
@@ -83,6 +91,7 @@ export class GovernanceProposerContract implements IEmpireBase {
83
91
  public createSignalRequest(payload: Hex): L1TxRequest {
84
92
  return {
85
93
  to: this.address.toString(),
94
+ abi: GovernanceProposerAbi,
86
95
  data: encodeSignal(payload),
87
96
  };
88
97
  }
@@ -104,10 +113,56 @@ export class GovernanceProposerContract implements IEmpireBase {
104
113
  );
105
114
  return {
106
115
  to: this.address.toString(),
116
+ abi: GovernanceProposerAbi,
107
117
  data: encodeSignalWithSignature(payload, signature),
108
118
  };
109
119
  }
110
120
 
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
+
111
166
  public async submitRoundWinner(
112
167
  round: bigint,
113
168
  l1TxUtils: L1TxUtils,
@@ -117,8 +172,9 @@ export class GovernanceProposerContract implements IEmpireBase {
117
172
  }> {
118
173
  const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
119
174
  to: this.address.toString(),
175
+ abi: GovernanceProposerAbi,
120
176
  data: encodeFunctionData({
121
- abi: this.proposer.abi,
177
+ abi: GovernanceProposerAbi,
122
178
  functionName: 'submitRoundWinner',
123
179
  args: [round],
124
180
  }),
@@ -1,4 +1,7 @@
1
- import { Buffer16 } from '@aztec/foundation/buffer';
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';
2
5
  import { EthAddress } from '@aztec/foundation/eth-address';
3
6
  import { InboxAbi } from '@aztec/l1-artifacts/InboxAbi';
4
7
 
@@ -8,8 +11,20 @@ import { getPublicClient } from '../client.js';
8
11
  import type { DeployAztecL1ContractsReturnType } from '../deploy_aztec_l1_contracts.js';
9
12
  import type { L1ReaderConfig } from '../l1_reader.js';
10
13
  import type { ViemClient } from '../types.js';
14
+ import type { L1EventLog } from './log.js';
11
15
  import { checkBlockTag } from './utils.js';
12
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
+
13
28
  export class InboxContract {
14
29
  private readonly inbox: GetContractReturnType<typeof InboxAbi, ViemClient>;
15
30
 
@@ -23,7 +38,7 @@ export class InboxContract {
23
38
 
24
39
  static getFromConfig(config: L1ReaderConfig) {
25
40
  const client = getPublicClient(config);
26
- const address = config.l1Contracts.inboxAddress.toString();
41
+ const address = config.inboxAddress.toString();
27
42
  return new InboxContract(client, address);
28
43
  }
29
44
 
@@ -45,6 +60,11 @@ export class InboxContract {
45
60
  return this.inbox;
46
61
  }
47
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
+
48
68
  public async getState(opts: { blockTag?: BlockTag; blockNumber?: bigint } = {}): Promise<InboxContractState> {
49
69
  await checkBlockTag(opts.blockNumber, this.client);
50
70
  const state = await this.inbox.read.getState(opts);
@@ -54,6 +74,46 @@ export class InboxContract {
54
74
  treeInProgress: state.inProgress,
55
75
  };
56
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
+ }
57
117
  }
58
118
 
59
119
  export type InboxContractState = {
@@ -1,14 +1,17 @@
1
+ export * from './chain_state_override.js';
1
2
  export * from './empire_base.js';
2
3
  export * from './errors.js';
3
4
  export * from './fee_asset_handler.js';
5
+ export * from './fee_asset_price_oracle.js';
4
6
  export * from './fee_juice.js';
5
7
  export * from './governance.js';
6
8
  export * from './governance_proposer.js';
7
9
  export * from './gse.js';
8
10
  export * from './inbox.js';
11
+ export * from './log.js';
9
12
  export * from './multicall.js';
13
+ export * from './outbox.js';
10
14
  export * from './registry.js';
11
15
  export * from './rollup.js';
12
- export * from './empire_slashing_proposer.js';
13
- export * from './tally_slashing_proposer.js';
16
+ export * from './slashing_proposer.js';
14
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
+ };