@aztec/ethereum 1.2.1 → 2.0.0-nightly.20250813

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 (98) hide show
  1. package/dest/config.d.ts +22 -7
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +49 -14
  4. package/dest/contracts/empire_base.d.ts +12 -10
  5. package/dest/contracts/empire_base.d.ts.map +1 -1
  6. package/dest/contracts/empire_base.js +21 -16
  7. package/dest/contracts/governance.d.ts +4 -4
  8. package/dest/contracts/governance.js +2 -2
  9. package/dest/contracts/governance_proposer.d.ts +7 -7
  10. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  11. package/dest/contracts/governance_proposer.js +13 -13
  12. package/dest/contracts/gse.d.ts +29 -0
  13. package/dest/contracts/gse.d.ts.map +1 -0
  14. package/dest/contracts/gse.js +56 -0
  15. package/dest/contracts/index.d.ts +1 -0
  16. package/dest/contracts/index.d.ts.map +1 -1
  17. package/dest/contracts/index.js +1 -0
  18. package/dest/contracts/multicall.d.ts +3 -1
  19. package/dest/contracts/multicall.d.ts.map +1 -1
  20. package/dest/contracts/multicall.js +11 -2
  21. package/dest/contracts/registry.d.ts +1 -0
  22. package/dest/contracts/registry.d.ts.map +1 -1
  23. package/dest/contracts/registry.js +3 -0
  24. package/dest/contracts/rollup.d.ts +39 -5
  25. package/dest/contracts/rollup.d.ts.map +1 -1
  26. package/dest/contracts/rollup.js +92 -14
  27. package/dest/contracts/slashing_proposer.d.ts +21 -10
  28. package/dest/contracts/slashing_proposer.d.ts.map +1 -1
  29. package/dest/contracts/slashing_proposer.js +43 -23
  30. package/dest/deploy_l1_contracts.d.ts +11 -36664
  31. package/dest/deploy_l1_contracts.d.ts.map +1 -1
  32. package/dest/deploy_l1_contracts.js +92 -177
  33. package/dest/index.d.ts +1 -1
  34. package/dest/index.d.ts.map +1 -1
  35. package/dest/index.js +1 -1
  36. package/dest/l1_artifacts.d.ts +51869 -0
  37. package/dest/l1_artifacts.d.ts.map +1 -0
  38. package/dest/l1_artifacts.js +141 -0
  39. package/dest/l1_tx_utils.d.ts +4 -2
  40. package/dest/l1_tx_utils.d.ts.map +1 -1
  41. package/dest/l1_tx_utils.js +46 -21
  42. package/dest/queries.d.ts +1 -8
  43. package/dest/queries.d.ts.map +1 -1
  44. package/dest/queries.js +20 -15
  45. package/dest/test/chain_monitor.d.ts +4 -2
  46. package/dest/test/chain_monitor.d.ts.map +1 -1
  47. package/dest/test/chain_monitor.js +12 -3
  48. package/dest/test/delayed_tx_utils.js +2 -2
  49. package/dest/{eth_cheat_codes.d.ts → test/eth_cheat_codes.d.ts} +8 -4
  50. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  51. package/dest/{eth_cheat_codes.js → test/eth_cheat_codes.js} +27 -11
  52. package/dest/test/eth_cheat_codes_with_state.d.ts +1 -1
  53. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
  54. package/dest/test/eth_cheat_codes_with_state.js +1 -1
  55. package/dest/test/index.d.ts +2 -0
  56. package/dest/test/index.d.ts.map +1 -1
  57. package/dest/test/index.js +2 -0
  58. package/dest/test/rollup_cheat_codes.d.ts +81 -0
  59. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  60. package/dest/test/rollup_cheat_codes.js +234 -0
  61. package/dest/test/start_anvil.d.ts +1 -0
  62. package/dest/test/start_anvil.d.ts.map +1 -1
  63. package/dest/test/start_anvil.js +6 -1
  64. package/dest/test/tx_delayer.d.ts +8 -1
  65. package/dest/test/tx_delayer.d.ts.map +1 -1
  66. package/dest/test/tx_delayer.js +51 -11
  67. package/dest/test/upgrade_utils.d.ts.map +1 -1
  68. package/dest/test/upgrade_utils.js +1 -1
  69. package/dest/utils.d.ts +1 -0
  70. package/dest/utils.d.ts.map +1 -1
  71. package/dest/utils.js +1 -1
  72. package/package.json +5 -5
  73. package/src/config.ts +62 -18
  74. package/src/contracts/empire_base.ts +28 -19
  75. package/src/contracts/governance.ts +2 -2
  76. package/src/contracts/governance_proposer.ts +23 -15
  77. package/src/contracts/gse.ts +73 -0
  78. package/src/contracts/index.ts +1 -0
  79. package/src/contracts/multicall.ts +8 -1
  80. package/src/contracts/registry.ts +4 -0
  81. package/src/contracts/rollup.ts +115 -9
  82. package/src/contracts/slashing_proposer.ts +55 -27
  83. package/src/deploy_l1_contracts.ts +151 -238
  84. package/src/index.ts +1 -1
  85. package/src/l1_artifacts.ts +216 -0
  86. package/src/l1_tx_utils.ts +52 -26
  87. package/src/queries.ts +20 -31
  88. package/src/test/chain_monitor.ts +9 -2
  89. package/src/test/delayed_tx_utils.ts +2 -2
  90. package/src/{eth_cheat_codes.ts → test/eth_cheat_codes.ts} +20 -14
  91. package/src/test/eth_cheat_codes_with_state.ts +1 -1
  92. package/src/test/index.ts +2 -0
  93. package/src/test/rollup_cheat_codes.ts +257 -0
  94. package/src/test/start_anvil.ts +9 -1
  95. package/src/test/tx_delayer.ts +55 -9
  96. package/src/test/upgrade_utils.ts +1 -1
  97. package/src/utils.ts +1 -1
  98. package/dest/eth_cheat_codes.d.ts.map +0 -1
@@ -0,0 +1,257 @@
1
+ import { RollupContract, type ViemPublicClient } from '@aztec/ethereum';
2
+ import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
3
+ import { EthAddress } from '@aztec/foundation/eth-address';
4
+ import { createLogger } from '@aztec/foundation/log';
5
+ import type { TestDateProvider } from '@aztec/foundation/timer';
6
+ import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
7
+
8
+ import {
9
+ type GetContractReturnType,
10
+ type Hex,
11
+ createPublicClient,
12
+ fallback,
13
+ getContract,
14
+ hexToBigInt,
15
+ http,
16
+ } from 'viem';
17
+ import { foundry } from 'viem/chains';
18
+
19
+ import { EthCheatCodes } from './eth_cheat_codes.js';
20
+
21
+ /** Cheat codes for the L1 rollup contract. */
22
+ export class RollupCheatCodes {
23
+ private client: ViemPublicClient;
24
+ private rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>;
25
+
26
+ private logger = createLogger('aztecjs:cheat_codes');
27
+
28
+ constructor(
29
+ private ethCheatCodes: EthCheatCodes,
30
+ addresses: Pick<L1ContractAddresses, 'rollupAddress'>,
31
+ ) {
32
+ this.client = createPublicClient({
33
+ chain: foundry,
34
+ transport: fallback(ethCheatCodes.rpcUrls.map(url => http(url))),
35
+ });
36
+ this.rollup = getContract({
37
+ abi: RollupAbi,
38
+ address: addresses.rollupAddress.toString(),
39
+ client: this.client,
40
+ });
41
+ }
42
+
43
+ static create(rpcUrls: string[], addresses: Pick<L1ContractAddresses, 'rollupAddress'>): RollupCheatCodes {
44
+ const ethCheatCodes = new EthCheatCodes(rpcUrls);
45
+ return new RollupCheatCodes(ethCheatCodes, addresses);
46
+ }
47
+
48
+ /** Returns the current slot */
49
+ public async getSlot() {
50
+ const ts = BigInt((await this.client.getBlock()).timestamp);
51
+ return await this.rollup.read.getSlotAt([ts]);
52
+ }
53
+
54
+ /** Returns the current epoch */
55
+ public async getEpoch() {
56
+ const slotNumber = await this.getSlot();
57
+ return await this.rollup.read.getEpochAtSlot([slotNumber]);
58
+ }
59
+
60
+ /**
61
+ * Returns the pending and proven chain tips
62
+ * @returns The pending and proven chain tips
63
+ */
64
+ public async getTips(): Promise<{
65
+ /** The pending chain tip */ pending: bigint;
66
+ /** The proven chain tip */ proven: bigint;
67
+ }> {
68
+ const res = await this.rollup.read.getTips();
69
+ return {
70
+ pending: res.pendingBlockNumber,
71
+ proven: res.provenBlockNumber,
72
+ };
73
+ }
74
+
75
+ /**
76
+ * Logs the current state of the rollup contract.
77
+ */
78
+ public async debugRollup() {
79
+ const rollup = new RollupContract(this.client, this.rollup.address);
80
+ const pendingNum = await rollup.getBlockNumber();
81
+ const provenNum = await rollup.getProvenBlockNumber();
82
+ const validators = await rollup.getAttesters();
83
+ const committee = await rollup.getCurrentEpochCommittee();
84
+ const archive = await rollup.archive();
85
+ const slot = await this.getSlot();
86
+ const epochNum = await rollup.getEpochNumberForSlotNumber(slot);
87
+
88
+ this.logger.info(`Pending block num: ${pendingNum}`);
89
+ this.logger.info(`Proven block num: ${provenNum}`);
90
+ this.logger.info(`Validators: ${validators.map(v => v.toString()).join(', ')}`);
91
+ this.logger.info(`Committee: ${committee?.map(v => v.toString()).join(', ')}`);
92
+ this.logger.info(`Archive: ${archive}`);
93
+ this.logger.info(`Epoch num: ${epochNum}`);
94
+ this.logger.info(`Slot: ${slot}`);
95
+ }
96
+
97
+ /** Fetches the epoch and slot duration config from the rollup contract */
98
+ public async getConfig(): Promise<{
99
+ /** Epoch duration */ epochDuration: bigint;
100
+ /** Slot duration */ slotDuration: bigint;
101
+ }> {
102
+ const [epochDuration, slotDuration] = await Promise.all([
103
+ this.rollup.read.getEpochDuration(),
104
+ this.rollup.read.getSlotDuration(),
105
+ ]);
106
+ return { epochDuration, slotDuration };
107
+ }
108
+
109
+ /**
110
+ * Advances time to the beginning of the given epoch
111
+ * @param epoch - The epoch to advance to
112
+ * @param opts - Options
113
+ */
114
+ public async advanceToEpoch(
115
+ epoch: bigint,
116
+ opts: {
117
+ /** Optional test date provider to update with the epoch timestamp */
118
+ updateDateProvider?: TestDateProvider;
119
+ } = {},
120
+ ) {
121
+ const { epochDuration: slotsInEpoch } = await this.getConfig();
122
+ const timestamp = await this.rollup.read.getTimestampForSlot([epoch * slotsInEpoch]);
123
+ try {
124
+ await this.ethCheatCodes.warp(Number(timestamp), { ...opts, silent: true, resetBlockInterval: true });
125
+ this.logger.warn(`Warped to epoch ${epoch}`);
126
+ } catch (err) {
127
+ this.logger.warn(`Warp to epoch ${epoch} failed: ${err}`);
128
+ }
129
+ return timestamp;
130
+ }
131
+
132
+ /** Warps time in L1 until the next epoch */
133
+ public async advanceToNextEpoch() {
134
+ const slot = await this.getSlot();
135
+ const { epochDuration, slotDuration } = await this.getConfig();
136
+ const slotsUntilNextEpoch = epochDuration - (slot % epochDuration) + 1n;
137
+ const timeToNextEpoch = slotsUntilNextEpoch * slotDuration;
138
+ const l1Timestamp = BigInt((await this.client.getBlock()).timestamp);
139
+ await this.ethCheatCodes.warp(Number(l1Timestamp + timeToNextEpoch), { silent: true, resetBlockInterval: true });
140
+ this.logger.warn(`Advanced to next epoch`);
141
+ }
142
+
143
+ /** Warps time in L1 until the beginning of the next slot. */
144
+ public async advanceToNextSlot() {
145
+ const currentSlot = await this.getSlot();
146
+ const timestamp = await this.rollup.read.getTimestampForSlot([currentSlot + 1n]);
147
+ await this.ethCheatCodes.warp(Number(timestamp), { silent: true, resetBlockInterval: true });
148
+ this.logger.warn(`Advanced to slot ${currentSlot + 1n}`);
149
+ return [timestamp, currentSlot + 1n];
150
+ }
151
+
152
+ /**
153
+ * Warps time in L1 equivalent to however many slots.
154
+ * @param howMany - The number of slots to advance.
155
+ */
156
+ public async advanceSlots(howMany: number) {
157
+ const l1Timestamp = (await this.client.getBlock()).timestamp;
158
+ const slotDuration = await this.rollup.read.getSlotDuration();
159
+ const timeToWarp = BigInt(howMany) * slotDuration;
160
+ await this.ethCheatCodes.warp(l1Timestamp + timeToWarp, { silent: true, resetBlockInterval: true });
161
+ const [slot, epoch] = await Promise.all([this.getSlot(), this.getEpoch()]);
162
+ this.logger.warn(`Advanced ${howMany} slots up to slot ${slot} in epoch ${epoch}`);
163
+ }
164
+
165
+ /**
166
+ * Marks the specified block (or latest if none) as proven
167
+ * @param maybeBlockNumber - The block number to mark as proven (defaults to latest pending)
168
+ */
169
+ public markAsProven(maybeBlockNumber?: number | bigint) {
170
+ return this.ethCheatCodes.execWithPausedAnvil(async () => {
171
+ const tipsBefore = await this.getTips();
172
+ const { pending, proven } = tipsBefore;
173
+
174
+ let blockNumber = maybeBlockNumber;
175
+ if (blockNumber === undefined || blockNumber > pending) {
176
+ blockNumber = pending;
177
+ }
178
+ if (blockNumber <= proven) {
179
+ this.logger.debug(`Block ${blockNumber} is already proven`);
180
+ return;
181
+ }
182
+
183
+ // @note @LHerskind this is heavily dependent on the storage layout and size of values
184
+ // The rollupStore is a struct and if the size of elements or the struct changes, this can break
185
+ const provenBlockNumberSlot = hexToBigInt(RollupContract.stfStorageSlot);
186
+
187
+ // Need to pack it as a single 32 byte word
188
+ const newValue = (BigInt(tipsBefore.pending) << 128n) | BigInt(blockNumber);
189
+ await this.ethCheatCodes.store(EthAddress.fromString(this.rollup.address), provenBlockNumberSlot, newValue);
190
+
191
+ const tipsAfter = await this.getTips();
192
+ if (tipsAfter.pending < tipsAfter.proven) {
193
+ throw new Error('Overwrote pending tip to a block in the past');
194
+ }
195
+
196
+ this.logger.info(
197
+ `Proven tip moved: ${tipsBefore.proven} -> ${tipsAfter.proven}. Pending tip: ${tipsAfter.pending}.`,
198
+ );
199
+ });
200
+ }
201
+
202
+ /**
203
+ * Executes an action impersonated as the owner of the Rollup contract.
204
+ * @param action - The action to execute
205
+ */
206
+ public async asOwner(
207
+ action: (owner: Hex, rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>) => Promise<void>,
208
+ ) {
209
+ const owner = await this.rollup.read.owner();
210
+ await this.ethCheatCodes.startImpersonating(owner);
211
+ await action(owner, this.rollup);
212
+ await this.ethCheatCodes.stopImpersonating(owner);
213
+ }
214
+
215
+ /**
216
+ * Sets up the epoch.
217
+ */
218
+ public async setupEpoch() {
219
+ // Doesn't need to be done as owner, but the functionality is here...
220
+ await this.asOwner(async (account, rollup) => {
221
+ const hash = await rollup.write.setupEpoch({ account });
222
+ await this.client.waitForTransactionReceipt({ hash });
223
+ this.logger.warn(`Setup epoch`);
224
+ });
225
+ }
226
+
227
+ /** Directly calls the L1 gas fee oracle. */
228
+ public async updateL1GasFeeOracle() {
229
+ await this.asOwner(async (account, rollup) => {
230
+ const hash = await rollup.write.updateL1GasFeeOracle({ account, chain: this.client.chain });
231
+ await this.client.waitForTransactionReceipt({ hash });
232
+ this.logger.warn(`Updated L1 gas fee oracle`);
233
+ });
234
+ }
235
+
236
+ /**
237
+ * Bumps proving cost per mana.
238
+ * @param bumper - Callback to calculate the new proving cost per mana based on current value.
239
+ */
240
+ public async bumpProvingCostPerMana(bumper: (before: bigint) => bigint) {
241
+ const currentCost = await this.rollup.read.getProvingCostPerManaInEth();
242
+ const newCost = bumper(currentCost);
243
+ await this.setProvingCostPerMana(newCost);
244
+ }
245
+
246
+ /**
247
+ * Directly updates proving cost per mana.
248
+ * @param ethValue - The new proving cost per mana in ETH
249
+ */
250
+ public async setProvingCostPerMana(ethValue: bigint) {
251
+ await this.asOwner(async (account, rollup) => {
252
+ const hash = await rollup.write.setProvingCostPerMana([ethValue], { account, chain: this.client.chain });
253
+ await this.client.waitForTransactionReceipt({ hash });
254
+ this.logger.warn(`Updated proving cost per mana to ${ethValue}`);
255
+ });
256
+ }
257
+ }
@@ -1,3 +1,4 @@
1
+ import { createLogger } from '@aztec/foundation/log';
1
2
  import { makeBackoff, retry } from '@aztec/foundation/retry';
2
3
  import { fileURLToPath } from '@aztec/foundation/url';
3
4
 
@@ -11,11 +12,13 @@ export async function startAnvil(
11
12
  opts: {
12
13
  port?: number;
13
14
  l1BlockTime?: number;
15
+ log?: boolean;
14
16
  captureMethodCalls?: boolean;
15
17
  accounts?: number;
16
18
  } = {},
17
19
  ): Promise<{ anvil: Anvil; methodCalls?: string[]; rpcUrl: string; stop: () => Promise<void> }> {
18
20
  const anvilBinary = resolve(dirname(fileURLToPath(import.meta.url)), '../../', 'scripts/anvil_kill_wrapper.sh');
21
+ const logger = opts.log ? createLogger('ethereum:anvil') : undefined;
19
22
  const methodCalls = opts.captureMethodCalls ? ([] as string[]) : undefined;
20
23
 
21
24
  let port: number | undefined;
@@ -35,13 +38,18 @@ export async function startAnvil(
35
38
 
36
39
  // Listen to the anvil output to get the port.
37
40
  const removeHandler = anvil.on('message', (message: string) => {
41
+ logger?.debug(message.trim());
42
+
38
43
  methodCalls?.push(...(message.match(/eth_[^\s]+/g) || []));
39
44
  if (port === undefined && message.includes('Listening on')) {
40
45
  port = parseInt(message.match(/Listening on ([^:]+):(\d+)/)![2]);
41
46
  }
42
47
  });
43
48
  await anvil.start();
44
- removeHandler();
49
+ if (!logger && !opts.captureMethodCalls) {
50
+ removeHandler();
51
+ }
52
+
45
53
  return anvil;
46
54
  },
47
55
  'Start anvil',
@@ -1,6 +1,7 @@
1
1
  import { omit } from '@aztec/foundation/collection';
2
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
3
  import { retryUntil } from '@aztec/foundation/retry';
4
+ import type { DateProvider } from '@aztec/foundation/timer';
4
5
 
5
6
  import { inspect } from 'util';
6
7
  import {
@@ -71,13 +72,24 @@ export interface Delayer {
71
72
  pauseNextTxUntilTimestamp(l1Timestamp: number | bigint | undefined): void;
72
73
  /** Delays the next tx to be sent indefinitely. */
73
74
  cancelNextTx(): void;
75
+ /**
76
+ * Sets max inclusion time into slot. If more than this many seconds have passed
77
+ * since the last L1 block was mined, then any tx will not be mined in the current
78
+ * L1 slot but will be deferred for the next one.
79
+ */
80
+ setMaxInclusionTimeIntoSlot(seconds: number | bigint | undefined): void;
74
81
  }
75
82
 
76
83
  class DelayerImpl implements Delayer {
77
- constructor(opts: { ethereumSlotDuration: bigint | number }) {
84
+ private logger = createLogger('ethereum:tx_delayer');
85
+ constructor(
86
+ public dateProvider: DateProvider,
87
+ opts: { ethereumSlotDuration: bigint | number },
88
+ ) {
78
89
  this.ethereumSlotDuration = BigInt(opts.ethereumSlotDuration);
79
90
  }
80
91
 
92
+ public maxInclusionTimeIntoSlot: number | undefined = undefined;
81
93
  public ethereumSlotDuration: bigint;
82
94
  public nextWait: { l1Timestamp: bigint } | { l1BlockNumber: bigint } | { indefinitely: true } | undefined = undefined;
83
95
  public sentTxHashes: Hex[] = [];
@@ -102,6 +114,10 @@ class DelayerImpl implements Delayer {
102
114
  cancelNextTx() {
103
115
  this.nextWait = { indefinitely: true };
104
116
  }
117
+
118
+ setMaxInclusionTimeIntoSlot(seconds: number | undefined) {
119
+ this.maxInclusionTimeIntoSlot = seconds;
120
+ }
105
121
  }
106
122
 
107
123
  /**
@@ -111,13 +127,14 @@ class DelayerImpl implements Delayer {
111
127
  */
112
128
  export function withDelayer<T extends ViemClient>(
113
129
  client: T,
130
+ dateProvider: DateProvider,
114
131
  opts: { ethereumSlotDuration: bigint | number },
115
132
  ): { client: T; delayer: Delayer } {
116
133
  if (!isExtendedClient(client)) {
117
134
  throw new Error('withDelayer has to be instantiated with a wallet viem client.');
118
135
  }
119
136
  const logger = createLogger('ethereum:tx_delayer');
120
- const delayer = new DelayerImpl(opts);
137
+ const delayer = new DelayerImpl(dateProvider, opts);
121
138
 
122
139
  const extended = client
123
140
  // Tweak sendRawTransaction so it uses the delay defined in the delayer.
@@ -126,13 +143,19 @@ export function withDelayer<T extends ViemClient>(
126
143
  // but we do not use them in our codebase at all.
127
144
  .extend(client => ({
128
145
  async sendRawTransaction(...args) {
146
+ let wait: Promise<unknown> | undefined;
147
+ let txHash: Hex | undefined;
148
+
149
+ const { serializedTransaction } = args[0];
150
+ const publicClient = client as unknown as PublicClient;
151
+
129
152
  if (delayer.nextWait !== undefined) {
153
+ // Check if we have been instructed to delay the next tx.
130
154
  const waitUntil = delayer.nextWait;
131
155
  delayer.nextWait = undefined;
132
156
 
133
157
  // Compute the tx hash manually so we emulate sendRawTransaction response
134
- const { serializedTransaction } = args[0];
135
- const txHash = computeTxHash(serializedTransaction);
158
+ txHash = computeTxHash(serializedTransaction);
136
159
 
137
160
  // Cancel tx outright if instructed
138
161
  if ('indefinitely' in waitUntil && waitUntil.indefinitely) {
@@ -141,8 +164,8 @@ export function withDelayer<T extends ViemClient>(
141
164
  return Promise.resolve(txHash);
142
165
  }
143
166
 
144
- const publicClient = client as unknown as PublicClient;
145
- const wait =
167
+ // Or wait until the desired block number or timestamp
168
+ wait =
146
169
  'l1BlockNumber' in waitUntil
147
170
  ? waitUntilBlock(publicClient, waitUntil.l1BlockNumber - 1n, logger)
148
171
  : 'l1Timestamp' in waitUntil
@@ -153,7 +176,31 @@ export function withDelayer<T extends ViemClient>(
153
176
  argsLen: args.length,
154
177
  ...omit(parseTransaction(serializedTransaction), 'data', 'sidecars'),
155
178
  });
179
+ } else if (delayer.maxInclusionTimeIntoSlot !== undefined) {
180
+ // Check if we need to delay txs sent too close to the end of the slot.
181
+ const currentBlock = await publicClient.getBlock({ includeTransactions: false });
182
+ const { timestamp: lastBlockTimestamp, number } = currentBlock;
183
+ const now = delayer.dateProvider.now();
184
+
185
+ txHash = computeTxHash(serializedTransaction);
186
+ const logData = {
187
+ ...omit(parseTransaction(serializedTransaction), 'data', 'sidecars'),
188
+ lastBlockTimestamp,
189
+ now,
190
+ maxInclusionTimeIntoSlot: delayer.maxInclusionTimeIntoSlot,
191
+ };
192
+
193
+ if (now / 1000 - Number(lastBlockTimestamp) > delayer.maxInclusionTimeIntoSlot) {
194
+ // If the last block was mined more than `maxInclusionTimeIntoSlot` seconds ago, then we cannot include
195
+ // any txs in the current slot, so we delay the tx until the next slot.
196
+ logger.info(`Delaying inclusion of tx ${txHash} until the next slot since it was sent too late`, logData);
197
+ wait = waitUntilBlock(publicClient, number + 1n, logger);
198
+ } else {
199
+ logger.debug(`Immediately sending tx ${txHash} as it was received early enough in the slot`, logData);
200
+ }
201
+ }
156
202
 
203
+ if (wait !== undefined) {
157
204
  // Do not await here so we can return the tx hash immediately as if it had been sent on the spot.
158
205
  // Instead, delay it so it lands on the desired block number or timestamp, assuming anvil will
159
206
  // mine it immediately.
@@ -166,12 +213,11 @@ export function withDelayer<T extends ViemClient>(
166
213
  computedTxHash: txHash,
167
214
  });
168
215
  }
169
- logger.info(`Sent previously delayed tx ${clientTxHash} to land on ${inspect(waitUntil)}`);
216
+ logger.info(`Sent previously delayed tx ${clientTxHash}`);
170
217
  delayer.sentTxHashes.push(clientTxHash);
171
218
  })
172
219
  .catch(err => logger.error(`Error sending tx after delay`, err));
173
-
174
- return Promise.resolve(txHash);
220
+ return Promise.resolve(txHash!);
175
221
  } else {
176
222
  const txHash = await client.sendRawTransaction(...args);
177
223
  logger.verbose(`Sent tx immediately ${txHash}`);
@@ -5,10 +5,10 @@ import { TestERC20Abi as StakingAssetAbi } from '@aztec/l1-artifacts/TestERC20Ab
5
5
  import { type GetContractReturnType, type PrivateKeyAccount, getContract } from 'viem';
6
6
 
7
7
  import { extractProposalIdFromLogs } from '../contracts/governance.js';
8
- import { EthCheatCodes } from '../eth_cheat_codes.js';
9
8
  import type { L1ContractAddresses } from '../l1_contract_addresses.js';
10
9
  import { L1TxUtils } from '../l1_tx_utils.js';
11
10
  import type { ExtendedViemWalletClient, ViemPublicClient } from '../types.js';
11
+ import { EthCheatCodes } from './eth_cheat_codes.js';
12
12
 
13
13
  export async function executeGovernanceProposal(
14
14
  proposalId: bigint,
package/src/utils.ts CHANGED
@@ -50,7 +50,7 @@ export function extractEvent<
50
50
  return event;
51
51
  }
52
52
 
53
- function tryExtractEvent<
53
+ export function tryExtractEvent<
54
54
  const TAbi extends Abi | readonly unknown[],
55
55
  TEventName extends ContractEventName<TAbi>,
56
56
  TEventType = DecodeEventLogReturnType<TAbi, TEventName, Hex[], undefined, true>,
@@ -1 +0,0 @@
1
- {"version":3,"file":"eth_cheat_codes.d.ts","sourceRoot":"","sources":["../src/eth_cheat_codes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAGhE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,KAAK,GAAG,EAAsC,MAAM,MAAM,CAAC;AAIpE;;GAEG;AACH,qBAAa,aAAa;IAGtB;;OAEG;IACI,OAAO,EAAE,MAAM,EAAE;IACxB;;OAEG;IACI,MAAM;IATf,OAAO,CAAC,YAAY,CAAmB;;IAErC;;OAEG;IACI,OAAO,EAAE,MAAM,EAAE;IACxB;;OAEG;IACI,MAAM,yCAAuC;IAOhD,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE;IAS3C;;;OAGG;IACU,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC;IAU7C;;;OAGG;IACU,WAAW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