@aztec/ethereum 0.0.1-commit.03f7ef2 → 0.0.1-commit.08c5969dc

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 (111) hide show
  1. package/dest/config.d.ts +17 -27
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +51 -54
  4. package/dest/contracts/empire_slashing_proposer.d.ts +1 -1
  5. package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -1
  6. package/dest/contracts/empire_slashing_proposer.js +13 -15
  7. package/dest/contracts/fee_asset_handler.d.ts +6 -5
  8. package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
  9. package/dest/contracts/fee_asset_handler.js +11 -9
  10. package/dest/contracts/governance.d.ts +3 -1
  11. package/dest/contracts/governance.d.ts.map +1 -1
  12. package/dest/contracts/governance.js +11 -1
  13. package/dest/contracts/governance_proposer.d.ts +1 -1
  14. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  15. package/dest/contracts/governance_proposer.js +386 -9
  16. package/dest/contracts/inbox.d.ts +22 -1
  17. package/dest/contracts/inbox.d.ts.map +1 -1
  18. package/dest/contracts/inbox.js +36 -1
  19. package/dest/contracts/index.d.ts +3 -1
  20. package/dest/contracts/index.d.ts.map +1 -1
  21. package/dest/contracts/index.js +2 -0
  22. package/dest/contracts/log.d.ts +13 -0
  23. package/dest/contracts/log.d.ts.map +1 -0
  24. package/dest/contracts/log.js +1 -0
  25. package/dest/contracts/multicall.d.ts +1 -1
  26. package/dest/contracts/multicall.d.ts.map +1 -1
  27. package/dest/contracts/multicall.js +2 -1
  28. package/dest/contracts/outbox.d.ts +41 -0
  29. package/dest/contracts/outbox.d.ts.map +1 -0
  30. package/dest/contracts/outbox.js +86 -0
  31. package/dest/contracts/rollup.d.ts +161 -96
  32. package/dest/contracts/rollup.d.ts.map +1 -1
  33. package/dest/contracts/rollup.js +677 -132
  34. package/dest/contracts/tally_slashing_proposer.d.ts +1 -1
  35. package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -1
  36. package/dest/contracts/tally_slashing_proposer.js +8 -1
  37. package/dest/deploy_aztec_l1_contracts.d.ts +17 -2
  38. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
  39. package/dest/deploy_aztec_l1_contracts.js +111 -33
  40. package/dest/generated/l1-contracts-defaults.d.ts +30 -0
  41. package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
  42. package/dest/generated/l1-contracts-defaults.js +30 -0
  43. package/dest/l1_artifacts.d.ts +4904 -1533
  44. package/dest/l1_artifacts.d.ts.map +1 -1
  45. package/dest/l1_tx_utils/constants.d.ts +1 -1
  46. package/dest/l1_tx_utils/constants.js +2 -2
  47. package/dest/l1_tx_utils/fee-strategies/index.d.ts +3 -2
  48. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -1
  49. package/dest/l1_tx_utils/fee-strategies/index.js +2 -1
  50. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +2 -12
  51. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -1
  52. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +36 -18
  53. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +2 -11
  54. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -1
  55. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +37 -19
  56. package/dest/l1_tx_utils/fee-strategies/types.d.ts +14 -27
  57. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -1
  58. package/dest/l1_tx_utils/fee-strategies/types.js +0 -21
  59. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +2 -2
  60. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -1
  61. package/dest/l1_tx_utils/l1_fee_analyzer.js +3 -3
  62. package/dest/l1_tx_utils/l1_tx_utils.js +6 -6
  63. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +1 -5
  64. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  65. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +17 -54
  66. package/dest/publisher_manager.d.ts +3 -2
  67. package/dest/publisher_manager.d.ts.map +1 -1
  68. package/dest/publisher_manager.js +2 -2
  69. package/dest/queries.d.ts +2 -2
  70. package/dest/queries.d.ts.map +1 -1
  71. package/dest/queries.js +12 -4
  72. package/dest/test/chain_monitor.js +1 -2
  73. package/dest/test/eth_cheat_codes.d.ts +13 -1
  74. package/dest/test/eth_cheat_codes.d.ts.map +1 -1
  75. package/dest/test/rollup_cheat_codes.d.ts +5 -2
  76. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  77. package/dest/test/rollup_cheat_codes.js +19 -2
  78. package/dest/test/start_anvil.js +1 -1
  79. package/dest/utils.d.ts +2 -1
  80. package/dest/utils.d.ts.map +1 -1
  81. package/dest/utils.js +46 -0
  82. package/package.json +8 -7
  83. package/src/config.ts +62 -53
  84. package/src/contracts/README.md +157 -0
  85. package/src/contracts/empire_slashing_proposer.ts +16 -27
  86. package/src/contracts/fee_asset_handler.ts +10 -7
  87. package/src/contracts/governance.ts +10 -1
  88. package/src/contracts/governance_proposer.ts +4 -1
  89. package/src/contracts/inbox.ts +53 -1
  90. package/src/contracts/index.ts +2 -0
  91. package/src/contracts/log.ts +13 -0
  92. package/src/contracts/multicall.ts +5 -2
  93. package/src/contracts/outbox.ts +98 -0
  94. package/src/contracts/rollup.ts +348 -100
  95. package/src/contracts/tally_slashing_proposer.ts +5 -1
  96. package/src/deploy_aztec_l1_contracts.ts +117 -40
  97. package/src/generated/l1-contracts-defaults.ts +32 -0
  98. package/src/l1_tx_utils/constants.ts +2 -2
  99. package/src/l1_tx_utils/fee-strategies/index.ts +1 -1
  100. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +46 -42
  101. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +49 -45
  102. package/src/l1_tx_utils/fee-strategies/types.ts +14 -46
  103. package/src/l1_tx_utils/l1_fee_analyzer.ts +2 -3
  104. package/src/l1_tx_utils/l1_tx_utils.ts +6 -6
  105. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +23 -62
  106. package/src/publisher_manager.ts +4 -2
  107. package/src/queries.ts +11 -3
  108. package/src/test/chain_monitor.ts +1 -1
  109. package/src/test/rollup_cheat_codes.ts +21 -3
  110. package/src/test/start_anvil.ts +1 -1
  111. package/src/utils.ts +53 -0
package/src/config.ts CHANGED
@@ -1,15 +1,16 @@
1
1
  import {
2
2
  type ConfigMappingsType,
3
- // type NetworkNames,
4
3
  bigintConfigHelper,
5
4
  booleanConfigHelper,
6
5
  enumConfigHelper,
7
6
  getConfigFromMappings,
7
+ getDefaultConfig,
8
8
  numberConfigHelper,
9
9
  optionalNumberConfigHelper,
10
10
  } from '@aztec/foundation/config';
11
11
  import { EthAddress } from '@aztec/foundation/eth-address';
12
12
 
13
+ import { l1ContractsDefaultEnv } from './generated/l1-contracts-defaults.js';
13
14
  import { type L1TxUtilsConfig, l1TxUtilsConfigMappings } from './l1_tx_utils/config.js';
14
15
 
15
16
  export type GenesisStateConfig = {
@@ -32,6 +33,8 @@ export type L1ContractsConfig = {
32
33
  lagInEpochsForValidatorSet: number;
33
34
  /** The number of epochs to lag behind the current epoch for randao selection. */
34
35
  lagInEpochsForRandao: number;
36
+ /** The number of checkpoints to lag in the inbox (prevents sequencer DOS attacks). */
37
+ inboxLag: number;
35
38
  /** The number of epochs after an epoch ends that proofs are still accepted. */
36
39
  aztecProofSubmissionEpochs: number;
37
40
  /** The deposit amount for a validator */
@@ -66,118 +69,108 @@ export type L1ContractsConfig = {
66
69
  governanceProposerQuorum?: number;
67
70
  /** Governance proposing round size */
68
71
  governanceProposerRoundSize: number;
72
+ /** Governance voting duration in seconds (only for local/devnet/next-net, default 3600) */
73
+ governanceVotingDuration?: number;
69
74
  /** The mana target for the rollup */
70
75
  manaTarget: bigint;
71
76
  /** The proving cost per mana */
72
77
  provingCostPerMana: bigint;
78
+ /** The initial ETH per fee asset price (with 1e12 precision) */
79
+ initialEthPerFeeAsset: bigint;
73
80
  /** The number of seconds to wait for an exit */
74
81
  exitDelaySeconds: number;
75
82
  } & L1TxUtilsConfig;
76
83
 
77
- export const DefaultL1ContractsConfig = {
78
- ethereumSlotDuration: 12,
79
- aztecSlotDuration: 36,
80
- aztecEpochDuration: 32,
81
- aztecTargetCommitteeSize: 48,
82
- lagInEpochsForValidatorSet: 2,
83
- lagInEpochsForRandao: 2, // For PROD, this value should be > lagInEpochsForValidatorSet
84
- aztecProofSubmissionEpochs: 1, // you have a full epoch to submit a proof after the epoch to prove ends
85
- activationThreshold: 100n * 10n ** 18n,
86
- ejectionThreshold: 50n * 10n ** 18n,
87
- localEjectionThreshold: 98n * 10n ** 18n,
88
- slashAmountSmall: 10n * 10n ** 18n,
89
- slashAmountMedium: 20n * 10n ** 18n,
90
- slashAmountLarge: 50n * 10n ** 18n,
91
- slashingRoundSizeInEpochs: 4,
92
- slashingLifetimeInRounds: 5,
93
- slashingExecutionDelayInRounds: 0, // round N may be submitted in round N + 1
94
- slashingVetoer: EthAddress.ZERO,
95
- governanceProposerRoundSize: 300,
96
- manaTarget: BigInt(100e6),
97
- provingCostPerMana: BigInt(100),
98
- exitDelaySeconds: 2 * 24 * 60 * 60,
99
- slasherFlavor: 'tally' as const,
100
- slashingOffsetInRounds: 2,
101
- slashingDisableDuration: 5 * 24 * 60 * 60, // 5 days in seconds
102
- } satisfies L1ContractsConfig;
103
-
84
+ /**
85
+ * Config mappings for L1ContractsConfig.
86
+ * Default values come from generated l1-contracts-defaults.json (source: defaults.yml).
87
+ * Real deployments use forge scripts which require explicit env vars (vm.envUint).
88
+ */
104
89
  export const l1ContractsConfigMappings: ConfigMappingsType<L1ContractsConfig> = {
105
90
  ethereumSlotDuration: {
106
91
  env: 'ETHEREUM_SLOT_DURATION',
107
92
  description: 'How many seconds an L1 slot lasts.',
108
- ...numberConfigHelper(DefaultL1ContractsConfig.ethereumSlotDuration),
93
+ ...numberConfigHelper(l1ContractsDefaultEnv.ETHEREUM_SLOT_DURATION),
109
94
  },
110
95
  aztecSlotDuration: {
111
96
  env: 'AZTEC_SLOT_DURATION',
112
97
  description: 'How many seconds an L2 slots lasts (must be multiple of ethereum slot duration).',
113
- ...numberConfigHelper(DefaultL1ContractsConfig.aztecSlotDuration),
98
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLOT_DURATION),
114
99
  },
115
100
  aztecEpochDuration: {
116
101
  env: 'AZTEC_EPOCH_DURATION',
117
- description: `How many L2 slots an epoch lasts (maximum AZTEC_MAX_EPOCH_DURATION).`,
118
- ...numberConfigHelper(DefaultL1ContractsConfig.aztecEpochDuration),
102
+ description: `How many L2 slots an epoch lasts (maximum MAX_CHECKPOINTS_PER_EPOCH).`,
103
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_EPOCH_DURATION),
119
104
  },
120
105
  aztecTargetCommitteeSize: {
121
106
  env: 'AZTEC_TARGET_COMMITTEE_SIZE',
122
107
  description: 'The target validator committee size.',
123
- ...numberConfigHelper(DefaultL1ContractsConfig.aztecTargetCommitteeSize),
108
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_TARGET_COMMITTEE_SIZE),
124
109
  },
125
110
  lagInEpochsForValidatorSet: {
126
111
  env: 'AZTEC_LAG_IN_EPOCHS_FOR_VALIDATOR_SET',
127
112
  description: 'The number of epochs to lag behind the current epoch for validator selection.',
128
- ...numberConfigHelper(DefaultL1ContractsConfig.lagInEpochsForValidatorSet),
113
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_LAG_IN_EPOCHS_FOR_VALIDATOR_SET),
129
114
  },
130
115
  lagInEpochsForRandao: {
131
116
  env: 'AZTEC_LAG_IN_EPOCHS_FOR_RANDAO',
132
117
  description: 'The number of epochs to lag behind the current epoch for randao selection.',
133
- ...numberConfigHelper(DefaultL1ContractsConfig.lagInEpochsForRandao),
118
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_LAG_IN_EPOCHS_FOR_RANDAO),
119
+ },
120
+ inboxLag: {
121
+ env: 'AZTEC_INBOX_LAG',
122
+ description: 'The number of checkpoints to lag in the inbox (prevents sequencer DOS attacks).',
123
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_INBOX_LAG),
134
124
  },
135
125
  aztecProofSubmissionEpochs: {
136
126
  env: 'AZTEC_PROOF_SUBMISSION_EPOCHS',
137
127
  description: 'The number of epochs after an epoch ends that proofs are still accepted.',
138
- ...numberConfigHelper(DefaultL1ContractsConfig.aztecProofSubmissionEpochs),
128
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_PROOF_SUBMISSION_EPOCHS),
139
129
  },
140
130
  activationThreshold: {
141
131
  env: 'AZTEC_ACTIVATION_THRESHOLD',
142
132
  description: 'The deposit amount for a validator',
143
- ...bigintConfigHelper(DefaultL1ContractsConfig.activationThreshold),
133
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_ACTIVATION_THRESHOLD)),
144
134
  },
145
135
  ejectionThreshold: {
146
136
  env: 'AZTEC_EJECTION_THRESHOLD',
147
137
  description: 'The minimum stake for a validator.',
148
- ...bigintConfigHelper(DefaultL1ContractsConfig.ejectionThreshold),
138
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_EJECTION_THRESHOLD)),
149
139
  },
150
140
  localEjectionThreshold: {
151
141
  env: 'AZTEC_LOCAL_EJECTION_THRESHOLD',
152
142
  description:
153
143
  'The local ejection threshold for a validator. Stricter than ejectionThreshold but local to a specific rollup',
154
- ...bigintConfigHelper(DefaultL1ContractsConfig.localEjectionThreshold),
144
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_LOCAL_EJECTION_THRESHOLD)),
155
145
  },
156
146
  slashingOffsetInRounds: {
157
147
  env: 'AZTEC_SLASHING_OFFSET_IN_ROUNDS',
158
148
  description:
159
149
  'How many slashing rounds back we slash (ie when slashing in round N, we slash for offenses committed during epochs of round N-offset)',
160
- ...numberConfigHelper(DefaultL1ContractsConfig.slashingOffsetInRounds),
150
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_OFFSET_IN_ROUNDS),
161
151
  },
162
152
  slasherFlavor: {
163
153
  env: 'AZTEC_SLASHER_FLAVOR',
164
154
  description: 'Type of slasher proposer (empire, tally, or none)',
165
- ...enumConfigHelper(['empire', 'tally', 'none'] as const, DefaultL1ContractsConfig.slasherFlavor),
155
+ ...enumConfigHelper(
156
+ ['empire', 'tally', 'none'] as const,
157
+ l1ContractsDefaultEnv.AZTEC_SLASHER_FLAVOR as 'empire' | 'tally' | 'none',
158
+ ),
166
159
  },
167
160
  slashAmountSmall: {
168
161
  env: 'AZTEC_SLASH_AMOUNT_SMALL',
169
162
  description: 'Small slashing amount for light offenses',
170
- ...bigintConfigHelper(DefaultL1ContractsConfig.slashAmountSmall),
163
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_SLASH_AMOUNT_SMALL)),
171
164
  },
172
165
  slashAmountMedium: {
173
166
  env: 'AZTEC_SLASH_AMOUNT_MEDIUM',
174
167
  description: 'Medium slashing amount for moderate offenses',
175
- ...bigintConfigHelper(DefaultL1ContractsConfig.slashAmountMedium),
168
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_SLASH_AMOUNT_MEDIUM)),
176
169
  },
177
170
  slashAmountLarge: {
178
171
  env: 'AZTEC_SLASH_AMOUNT_LARGE',
179
172
  description: 'Large slashing amount for severe offenses',
180
- ...bigintConfigHelper(DefaultL1ContractsConfig.slashAmountLarge),
173
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_SLASH_AMOUNT_LARGE)),
181
174
  },
182
175
  slashingQuorum: {
183
176
  env: 'AZTEC_SLASHING_QUORUM',
@@ -187,28 +180,28 @@ export const l1ContractsConfigMappings: ConfigMappingsType<L1ContractsConfig> =
187
180
  slashingRoundSizeInEpochs: {
188
181
  env: 'AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS',
189
182
  description: 'The slashing round size',
190
- ...numberConfigHelper(DefaultL1ContractsConfig.slashingRoundSizeInEpochs),
183
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS),
191
184
  },
192
185
  slashingLifetimeInRounds: {
193
186
  env: 'AZTEC_SLASHING_LIFETIME_IN_ROUNDS',
194
187
  description: 'The slashing lifetime in rounds',
195
- ...numberConfigHelper(DefaultL1ContractsConfig.slashingLifetimeInRounds),
188
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_LIFETIME_IN_ROUNDS),
196
189
  },
197
190
  slashingExecutionDelayInRounds: {
198
191
  env: 'AZTEC_SLASHING_EXECUTION_DELAY_IN_ROUNDS',
199
192
  description: 'The slashing execution delay in rounds',
200
- ...numberConfigHelper(DefaultL1ContractsConfig.slashingExecutionDelayInRounds),
193
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_EXECUTION_DELAY_IN_ROUNDS),
201
194
  },
202
195
  slashingVetoer: {
203
196
  env: 'AZTEC_SLASHING_VETOER',
204
197
  description: 'The slashing vetoer',
205
198
  parseEnv: (val: string) => EthAddress.fromString(val),
206
- defaultValue: DefaultL1ContractsConfig.slashingVetoer,
199
+ defaultValue: EthAddress.fromString(l1ContractsDefaultEnv.AZTEC_SLASHING_VETOER),
207
200
  },
208
201
  slashingDisableDuration: {
209
202
  env: 'AZTEC_SLASHING_DISABLE_DURATION',
210
203
  description: 'How long slashing can be disabled for in seconds when vetoer disables it',
211
- ...numberConfigHelper(DefaultL1ContractsConfig.slashingDisableDuration),
204
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_DISABLE_DURATION),
212
205
  },
213
206
  governanceProposerQuorum: {
214
207
  env: 'AZTEC_GOVERNANCE_PROPOSER_QUORUM',
@@ -218,26 +211,42 @@ export const l1ContractsConfigMappings: ConfigMappingsType<L1ContractsConfig> =
218
211
  governanceProposerRoundSize: {
219
212
  env: 'AZTEC_GOVERNANCE_PROPOSER_ROUND_SIZE',
220
213
  description: 'The governance proposing round size',
221
- ...numberConfigHelper(DefaultL1ContractsConfig.governanceProposerRoundSize),
214
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_GOVERNANCE_PROPOSER_ROUND_SIZE),
215
+ },
216
+ governanceVotingDuration: {
217
+ env: 'AZTEC_GOVERNANCE_VOTING_DURATION',
218
+ description: 'Governance voting duration in seconds (only for local/devnet/next-net)',
219
+ ...numberConfigHelper(3600), // 1 hour default, not in generated defaults as it's deployment-time only
222
220
  },
223
221
  manaTarget: {
224
222
  env: 'AZTEC_MANA_TARGET',
225
223
  description: 'The mana target for the rollup',
226
- ...bigintConfigHelper(DefaultL1ContractsConfig.manaTarget),
224
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_MANA_TARGET)),
227
225
  },
228
226
  provingCostPerMana: {
229
227
  env: 'AZTEC_PROVING_COST_PER_MANA',
230
228
  description: 'The proving cost per mana',
231
- ...bigintConfigHelper(DefaultL1ContractsConfig.provingCostPerMana),
229
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_PROVING_COST_PER_MANA)),
230
+ },
231
+ initialEthPerFeeAsset: {
232
+ env: 'AZTEC_INITIAL_ETH_PER_FEE_ASSET',
233
+ description: 'The initial ETH per fee asset price (with 1e12 precision)',
234
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_INITIAL_ETH_PER_FEE_ASSET)),
232
235
  },
233
236
  exitDelaySeconds: {
234
237
  env: 'AZTEC_EXIT_DELAY_SECONDS',
235
238
  description: 'The delay before a validator can exit the set',
236
- ...numberConfigHelper(DefaultL1ContractsConfig.exitDelaySeconds),
239
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_EXIT_DELAY_SECONDS),
237
240
  },
238
241
  ...l1TxUtilsConfigMappings,
239
242
  };
240
243
 
244
+ /**
245
+ * Default L1 contracts configuration derived from l1ContractsConfigMappings.
246
+ * Source of truth: spartan/environments/defaults.yml -> defaults.l1-contracts
247
+ */
248
+ export const DefaultL1ContractsConfig = getDefaultConfig(l1ContractsConfigMappings);
249
+
241
250
  export const genesisStateConfigMappings: ConfigMappingsType<GenesisStateConfig> = {
242
251
  testAccounts: {
243
252
  env: 'TEST_ACCOUNTS',
@@ -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.
@@ -6,7 +6,6 @@ import { EmpireSlashingProposerAbi } from '@aztec/l1-artifacts/EmpireSlashingPro
6
6
 
7
7
  import EventEmitter from 'events';
8
8
  import {
9
- type EncodeFunctionDataParameters,
10
9
  type GetContractReturnType,
11
10
  type Hex,
12
11
  type Log,
@@ -100,6 +99,7 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
100
99
  public createSignalRequest(payload: Hex): L1TxRequest {
101
100
  return {
102
101
  to: this.address.toString(),
102
+ abi: EmpireSlashingProposerAbi,
103
103
  data: encodeSignal(payload),
104
104
  };
105
105
  }
@@ -121,6 +121,7 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
121
121
  );
122
122
  return {
123
123
  to: this.address.toString(),
124
+ abi: EmpireSlashingProposerAbi,
124
125
  data: encodeSignalWithSignature(payload, signature),
125
126
  };
126
127
  }
@@ -180,6 +181,7 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
180
181
  public buildExecuteRoundRequest(round: bigint): L1TxRequest {
181
182
  return {
182
183
  to: this.address.toString(),
184
+ abi: EmpireSlashingProposerAbi,
183
185
  data: encodeFunctionData({
184
186
  abi: EmpireSlashingProposerAbi,
185
187
  functionName: 'submitRoundWinner',
@@ -222,24 +224,13 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
222
224
  if (typeof round === 'number') {
223
225
  round = BigInt(round);
224
226
  }
225
- const args: EncodeFunctionDataParameters<typeof EmpireSlashingProposerAbi, 'submitRoundWinner'> = {
226
- abi: EmpireSlashingProposerAbi,
227
- functionName: 'submitRoundWinner',
228
- args: [round],
229
- };
230
- const data = encodeFunctionData(args);
227
+ const request = this.buildExecuteRoundRequest(round);
231
228
  const response = await txUtils
232
- .sendAndMonitorTransaction(
233
- {
234
- to: this.address.toString(),
235
- data,
236
- },
237
- {
238
- // Gas estimation is way off for this, likely because we are creating the contract/selector to call
239
- // for the actual slashing dynamically.
240
- gasLimitBufferPercentage: 50, // +50% gas
241
- },
242
- )
229
+ .sendAndMonitorTransaction(request, {
230
+ // Gas estimation is way off for this, likely because we are creating the contract/selector to call
231
+ // for the actual slashing dynamically.
232
+ gasLimitBufferPercentage: 50, // +50% gas
233
+ })
243
234
  .catch(err => {
244
235
  if (err instanceof FormattedViemError && err.message.includes('ProposalAlreadyExecuted')) {
245
236
  throw new ProposalAlreadyExecutedError(round);
@@ -248,15 +239,13 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
248
239
  });
249
240
 
250
241
  if (response.receipt.status === 'reverted') {
251
- const error = await txUtils.tryGetErrorFromRevertedTx(
252
- data,
253
- {
254
- ...args,
255
- address: this.address.toString(),
256
- },
257
- undefined,
258
- [],
259
- );
242
+ const args = {
243
+ abi: EmpireSlashingProposerAbi,
244
+ functionName: 'submitRoundWinner' as const,
245
+ args: [round] as const,
246
+ address: this.address.toString(),
247
+ };
248
+ const error = await txUtils.tryGetErrorFromRevertedTx(request.data!, args, undefined, []);
260
249
  if (error?.includes('ProposalAlreadyExecuted')) {
261
250
  throw new ProposalAlreadyExecutedError(round);
262
251
  }
@@ -4,13 +4,14 @@ import { FeeAssetHandlerAbi } from '@aztec/l1-artifacts/FeeAssetHandlerAbi';
4
4
  import { type Hex, encodeFunctionData, getContract } from 'viem';
5
5
 
6
6
  import type { L1TxUtils } from '../l1_tx_utils/index.js';
7
+ import type { ViemClient } from '../types.js';
7
8
 
8
9
  export class FeeAssetHandlerContract {
9
10
  public address: EthAddress;
10
11
 
11
12
  constructor(
13
+ public readonly client: ViemClient,
12
14
  address: Hex | EthAddress,
13
- public readonly txUtils: L1TxUtils,
14
15
  ) {
15
16
  if (address instanceof EthAddress) {
16
17
  address = address.toString();
@@ -22,7 +23,7 @@ export class FeeAssetHandlerContract {
22
23
  const contract = getContract({
23
24
  abi: FeeAssetHandlerAbi,
24
25
  address: this.address.toString(),
25
- client: this.txUtils.client,
26
+ client: this.client,
26
27
  });
27
28
  return EthAddress.fromString(await contract.read.owner());
28
29
  }
@@ -31,17 +32,18 @@ export class FeeAssetHandlerContract {
31
32
  const contract = getContract({
32
33
  abi: FeeAssetHandlerAbi,
33
34
  address: this.address.toString(),
34
- client: this.txUtils.client,
35
+ client: this.client,
35
36
  });
36
37
  return contract.read.mintAmount();
37
38
  }
38
39
 
39
- public mint(recipient: Hex | EthAddress) {
40
+ public mint(txUtils: L1TxUtils, recipient: Hex | EthAddress) {
40
41
  if (recipient instanceof EthAddress) {
41
42
  recipient = recipient.toString();
42
43
  }
43
- return this.txUtils.sendAndMonitorTransaction({
44
+ return txUtils.sendAndMonitorTransaction({
44
45
  to: this.address.toString(),
46
+ abi: FeeAssetHandlerAbi,
45
47
  data: encodeFunctionData({
46
48
  abi: FeeAssetHandlerAbi,
47
49
  functionName: 'mint',
@@ -50,9 +52,10 @@ export class FeeAssetHandlerContract {
50
52
  });
51
53
  }
52
54
 
53
- public setMintAmount(amount: bigint) {
54
- return this.txUtils.sendAndMonitorTransaction({
55
+ public setMintAmount(txUtils: L1TxUtils, amount: bigint) {
56
+ return txUtils.sendAndMonitorTransaction({
55
57
  to: this.address.toString(),
58
+ abi: FeeAssetHandlerAbi,
56
59
  data: encodeFunctionData({
57
60
  abi: FeeAssetHandlerAbi,
58
61
  functionName: 'setMintAmount',
@@ -174,6 +174,13 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
174
174
  return this.governanceContract.read.powerAt([this.client.account.address, now.timestamp]);
175
175
  }
176
176
 
177
+ /** Returns the user's voting power for a specific proposal, checked at pendingThrough timestamp. */
178
+ public async getPowerForProposal(proposalId: bigint): Promise<bigint> {
179
+ const proposal = await this.getProposal(proposalId);
180
+ const pendingThrough = proposal.creation + proposal.config.votingDelay;
181
+ return this.governanceContract.read.powerAt([this.client.account.address, pendingThrough]);
182
+ }
183
+
177
184
  public async vote({
178
185
  proposalId,
179
186
  voteAmount,
@@ -190,7 +197,7 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
190
197
  const l1TxUtils = createL1TxUtilsFromViemWallet(this.client, { logger });
191
198
  const retryDelaySeconds = 12;
192
199
 
193
- voteAmount = voteAmount ?? (await this.getPower());
200
+ voteAmount = voteAmount ?? (await this.getPowerForProposal(proposalId));
194
201
 
195
202
  let success = false;
196
203
  for (let i = 0; i < retries; i++) {
@@ -204,6 +211,7 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
204
211
 
205
212
  const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
206
213
  to: this.governanceContract.address,
214
+ abi: GovernanceAbi,
207
215
  data: encodedVoteData,
208
216
  });
209
217
 
@@ -258,6 +266,7 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
258
266
 
259
267
  const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
260
268
  to: this.governanceContract.address,
269
+ abi: GovernanceAbi,
261
270
  data: encodedExecuteData,
262
271
  });
263
272
 
@@ -83,6 +83,7 @@ export class GovernanceProposerContract implements IEmpireBase {
83
83
  public createSignalRequest(payload: Hex): L1TxRequest {
84
84
  return {
85
85
  to: this.address.toString(),
86
+ abi: GovernanceProposerAbi,
86
87
  data: encodeSignal(payload),
87
88
  };
88
89
  }
@@ -104,6 +105,7 @@ export class GovernanceProposerContract implements IEmpireBase {
104
105
  );
105
106
  return {
106
107
  to: this.address.toString(),
108
+ abi: GovernanceProposerAbi,
107
109
  data: encodeSignalWithSignature(payload, signature),
108
110
  };
109
111
  }
@@ -117,8 +119,9 @@ export class GovernanceProposerContract implements IEmpireBase {
117
119
  }> {
118
120
  const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
119
121
  to: this.address.toString(),
122
+ abi: GovernanceProposerAbi,
120
123
  data: encodeFunctionData({
121
- abi: this.proposer.abi,
124
+ abi: GovernanceProposerAbi,
122
125
  functionName: 'submitRoundWinner',
123
126
  args: [round],
124
127
  }),