@aztec/bot 5.0.0-private.20260318 → 5.0.0-rc.1

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.
package/src/factory.ts CHANGED
@@ -15,19 +15,19 @@ import { deriveKeys } from '@aztec/aztec.js/keys';
15
15
  import { createLogger } from '@aztec/aztec.js/log';
16
16
  import { waitForL1ToL2MessageReady } from '@aztec/aztec.js/messaging';
17
17
  import { waitForTx } from '@aztec/aztec.js/node';
18
+ import { getFeeJuiceBalance } from '@aztec/aztec.js/utils';
18
19
  import { createEthereumChain } from '@aztec/ethereum/chain';
19
20
  import { createExtendedL1Client } from '@aztec/ethereum/client';
20
21
  import { RollupContract } from '@aztec/ethereum/contracts';
21
22
  import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
22
23
  import { Fr } from '@aztec/foundation/curves/bn254';
23
24
  import { EthAddress } from '@aztec/foundation/eth-address';
24
- import { Timer } from '@aztec/foundation/timer';
25
25
  import { AMMContract } from '@aztec/noir-contracts.js/AMM';
26
26
  import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
27
27
  import { TokenContract } from '@aztec/noir-contracts.js/Token';
28
28
  import { TestContract } from '@aztec/noir-test-contracts.js/Test';
29
+ import type { BlockTag } from '@aztec/stdlib/block';
29
30
  import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
30
- import { GasSettings } from '@aztec/stdlib/gas';
31
31
  import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
32
32
  import { deriveSigningKey } from '@aztec/stdlib/keys';
33
33
  import { EmbeddedWallet } from '@aztec/wallets/embedded';
@@ -39,6 +39,7 @@ import { getBalances, getPrivateBalance, isStandardTokenContract } from './utils
39
39
 
40
40
  const MINT_BALANCE = 1e12;
41
41
  const MIN_BALANCE = 1e3;
42
+ const FEE_JUICE_TOP_UP_THRESHOLD = 100n * 10n ** 18n;
42
43
 
43
44
  export class BotFactory {
44
45
  private log = createLogger('bot');
@@ -49,6 +50,7 @@ export class BotFactory {
49
50
  private readonly store: BotStore,
50
51
  private readonly aztecNode: AztecNode,
51
52
  private readonly aztecNodeAdmin?: AztecNodeAdmin,
53
+ private readonly syncChainTip?: BlockTag,
52
54
  ) {
53
55
  // Set fee padding on the wallet so that all transactions during setup
54
56
  // (token deploy, minting, etc.) use the configured padding, not the default.
@@ -68,6 +70,7 @@ export class BotFactory {
68
70
  }> {
69
71
  const defaultAccountAddress = await this.setupAccount();
70
72
  const recipient = (await this.wallet.createSchnorrAccount(Fr.random(), Fr.random())).address;
73
+ await this.ensureFeeJuiceBalance(defaultAccountAddress);
71
74
  const token = await this.setupToken(defaultAccountAddress);
72
75
  await this.mintTokens(token, defaultAccountAddress);
73
76
  return { wallet: this.wallet, defaultAccountAddress, token, node: this.aztecNode, recipient };
@@ -82,6 +85,7 @@ export class BotFactory {
82
85
  node: AztecNode;
83
86
  }> {
84
87
  const defaultAccountAddress = await this.setupAccount();
88
+ await this.ensureFeeJuiceBalance(defaultAccountAddress);
85
89
  const token0 = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotToken0', 'BOT0');
86
90
  const token1 = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotToken1', 'BOT1');
87
91
  const liquidityToken = await this.setupTokenContract(
@@ -117,6 +121,7 @@ export class BotFactory {
117
121
  rollupVersion: bigint;
118
122
  }> {
119
123
  const defaultAccountAddress = await this.setupAccount();
124
+ await this.ensureFeeJuiceBalance(defaultAccountAddress);
120
125
 
121
126
  // Create L1 client (same pattern as bridgeL1FeeJuice)
122
127
  const l1RpcUrls = this.config.l1RpcUrls;
@@ -135,7 +140,7 @@ export class BotFactory {
135
140
  const rollupContract = new RollupContract(l1Client, l1ContractAddresses.rollupAddress.toString());
136
141
  const rollupVersion = await rollupContract.getVersion();
137
142
 
138
- // Deploy TestContract
143
+ // Deploy TestContract (pays from the standing balance funded above).
139
144
  const contract = await this.setupTestContract(defaultAccountAddress);
140
145
 
141
146
  // Recover any pending messages from store (clean up stale ones first)
@@ -162,6 +167,7 @@ export class BotFactory {
162
167
  const firstMsg = allMessages[0];
163
168
  await waitForL1ToL2MessageReady(this.aztecNode, Fr.fromHexString(firstMsg.msgHash), {
164
169
  timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds,
170
+ chainTip: this.syncChainTip,
165
171
  });
166
172
  this.log.info(`First L1→L2 message is ready`);
167
173
  }
@@ -177,12 +183,8 @@ export class BotFactory {
177
183
  }
178
184
 
179
185
  private async setupTestContract(deployer: AztecAddress): Promise<TestContract> {
180
- const deployOpts: DeployOptions = {
181
- from: deployer,
182
- contractAddressSalt: this.config.tokenSalt,
183
- universalDeploy: true,
184
- };
185
- const deploy = TestContract.deploy(this.wallet);
186
+ const deployOpts: DeployOptions = { from: deployer };
187
+ const deploy = TestContract.deploy(this.wallet, { salt: this.config.tokenSalt, universalDeploy: true });
186
188
  const instance = await this.registerOrDeployContract('TestContract', deploy, deployOpts);
187
189
  return TestContract.at(instance.address, this.wallet);
188
190
  }
@@ -202,50 +204,16 @@ export class BotFactory {
202
204
  }
203
205
  }
204
206
 
205
- private async setupAccountWithPrivateKey(secret: Fr) {
206
- const salt = this.config.senderSalt ?? Fr.ONE;
207
- const signingKey = deriveSigningKey(secret);
208
- const accountManager = await this.wallet.createSchnorrAccount(secret, salt, signingKey);
209
- const metadata = await this.wallet.getContractMetadata(accountManager.address);
210
- if (metadata.isContractInitialized) {
211
- this.log.info(`Account at ${accountManager.address.toString()} already initialized`);
212
- const timer = new Timer();
213
- const address = accountManager.address;
214
- this.log.info(`Account at ${address} registered. duration=${timer.ms()}`);
215
- await this.store.deleteBridgeClaim(address);
216
- return address;
217
- } else {
218
- const address = accountManager.address;
219
- this.log.info(`Deploying account at ${address}`);
220
-
221
- const claim = await this.getOrCreateBridgeClaim(address);
222
-
223
- const paymentMethod = new FeeJuicePaymentMethodWithClaim(accountManager.address, claim);
224
- const deployMethod = await accountManager.getDeployMethod();
225
- const maxFeesPerGas = (await this.aztecNode.getCurrentMinFees()).mul(1 + this.config.minFeePadding);
226
- const gasSettings = GasSettings.default({ maxFeesPerGas });
227
-
228
- await this.withNoMinTxsPerBlock(async () => {
229
- const { txHash } = await deployMethod.send({
230
- from: AztecAddress.ZERO,
231
- fee: { gasSettings, paymentMethod },
232
- wait: NO_WAIT,
233
- });
234
- this.log.info(`Sent tx for account deployment with hash ${txHash.toString()}`);
235
- return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
236
- });
237
- this.log.info(`Account deployed at ${address}`);
238
-
239
- // Clean up the consumed bridge claim
240
- await this.store.deleteBridgeClaim(address);
241
-
242
- return accountManager.address;
243
- }
244
- }
245
-
207
+ /**
208
+ * Keyless fallback for tests and local dev: reuses the first genesis test account, whose address is
209
+ * pre-funded with fee juice via `initialFundedAccounts`. The test accounts are initializerless, so this
210
+ * must create an initializerless account for the address to match the funded one. Production bots set a
211
+ * sender private key and fund the resulting initializerless account from L1 instead; see
212
+ * setupAccountWithPrivateKey.
213
+ */
246
214
  private async setupTestAccount() {
247
215
  const [initialAccountData] = await getInitialTestAccountsData();
248
- const accountManager = await this.wallet.createSchnorrAccount(
216
+ const accountManager = await this.wallet.createSchnorrInitializerlessAccount(
249
217
  initialAccountData.secret,
250
218
  initialAccountData.salt,
251
219
  initialAccountData.signingKey,
@@ -253,35 +221,44 @@ export class BotFactory {
253
221
  return accountManager.address;
254
222
  }
255
223
 
224
+ private async setupAccountWithPrivateKey(secret: Fr) {
225
+ const salt = this.config.senderSalt ?? Fr.ONE;
226
+ const signingKey = deriveSigningKey(secret);
227
+ const accountManager = await this.wallet.createSchnorrInitializerlessAccount(secret, salt, signingKey);
228
+ return accountManager.address;
229
+ }
230
+
256
231
  /**
257
232
  * Checks if the token contract is deployed and deploys it if necessary.
258
- * @param wallet - Wallet to deploy the token contract from.
259
- * @returns The TokenContract instance.
233
+ * Uses a bridge claim for deploy when balance is below threshold to avoid failing before refuel.
234
+ * @param sender - Aztec address to deploy the token contract from.
235
+ * @param existingToken - Optional token instance when called from setupTokenWithOptionalEarlyRefuel.
236
+ * @returns The TokenContract or PrivateTokenContract instance.
260
237
  */
261
238
  private async setupToken(sender: AztecAddress): Promise<TokenContract | PrivateTokenContract> {
262
239
  let deploy: DeployMethod<TokenContract | PrivateTokenContract>;
263
- let tokenInstance: ContractInstanceWithAddress | undefined;
264
- const deployOpts: DeployOptions = {
265
- from: sender,
266
- contractAddressSalt: this.config.tokenSalt,
267
- universalDeploy: true,
268
- };
240
+ const salt = this.config.tokenSalt;
241
+ const deployOpts: DeployOptions = { from: sender };
269
242
  let token: TokenContract | PrivateTokenContract;
270
243
  if (this.config.contract === SupportedTokenContracts.TokenContract) {
271
- deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18);
272
- tokenInstance = await deploy.getInstance(deployOpts);
273
- token = TokenContract.at(tokenInstance.address, this.wallet);
244
+ deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18, { salt, universalDeploy: true });
245
+ const instance = await deploy.getInstance();
246
+ token = TokenContract.at(instance.address, this.wallet);
274
247
  } else if (this.config.contract === SupportedTokenContracts.PrivateTokenContract) {
275
248
  // Generate keys for the contract since PrivateToken uses SinglePrivateMutable which requires keys
276
249
  const tokenSecretKey = Fr.random();
277
250
  const tokenPublicKeys = (await deriveKeys(tokenSecretKey)).publicKeys;
278
- deploy = PrivateTokenContract.deployWithPublicKeys(tokenPublicKeys, this.wallet, MINT_BALANCE, sender);
251
+ deploy = PrivateTokenContract.deploy(this.wallet, MINT_BALANCE, sender, {
252
+ salt,
253
+ universalDeploy: true,
254
+ publicKeys: tokenPublicKeys,
255
+ });
279
256
  deployOpts.skipInstancePublication = true;
280
257
  deployOpts.skipClassPublication = true;
281
258
  deployOpts.skipInitialization = false;
282
259
 
283
260
  // Register the contract with the secret key before deployment
284
- tokenInstance = await deploy.getInstance(deployOpts);
261
+ const tokenInstance = await deploy.getInstance();
285
262
  token = PrivateTokenContract.at(tokenInstance.address, this.wallet);
286
263
  await this.wallet.registerContract(tokenInstance, PrivateTokenContract.artifact, tokenSecretKey);
287
264
  // The contract constructor initializes private storage vars that need the contract's own nullifier key.
@@ -290,20 +267,7 @@ export class BotFactory {
290
267
  throw new Error(`Unsupported token contract type: ${this.config.contract}`);
291
268
  }
292
269
 
293
- const address = tokenInstance?.address ?? (await deploy.getInstance(deployOpts)).address;
294
- const metadata = await this.wallet.getContractMetadata(address);
295
- if (metadata.isContractPublished) {
296
- this.log.info(`Token at ${address.toString()} already deployed`);
297
- await deploy.register();
298
- } else {
299
- this.log.info(`Deploying token contract at ${address.toString()}`);
300
- const { txHash } = await deploy.send({ ...deployOpts, wait: NO_WAIT });
301
- this.log.info(`Sent tx for token setup with hash ${txHash.toString()}`);
302
- await this.withNoMinTxsPerBlock(async () => {
303
- await waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
304
- return token;
305
- });
306
- }
270
+ await this.registerOrDeployContract('token', deploy, deployOpts);
307
271
  return token;
308
272
  }
309
273
 
@@ -314,33 +278,38 @@ export class BotFactory {
314
278
  */
315
279
  private async setupTokenContract(
316
280
  deployer: AztecAddress,
317
- contractAddressSalt: Fr,
281
+ salt: Fr,
318
282
  name: string,
319
283
  ticker: string,
320
284
  decimals = 18,
321
285
  ): Promise<TokenContract> {
322
- const deployOpts: DeployOptions = { from: deployer, contractAddressSalt, universalDeploy: true };
323
- const deploy = TokenContract.deploy(this.wallet, deployer, name, ticker, decimals);
286
+ const deployOpts: DeployOptions = { from: deployer };
287
+ const deploy = TokenContract.deploy(this.wallet, deployer, name, ticker, decimals, { salt, universalDeploy: true });
324
288
  const instance = await this.registerOrDeployContract('Token - ' + name, deploy, deployOpts);
325
289
  return TokenContract.at(instance.address, this.wallet);
326
290
  }
327
291
 
328
292
  private async setupAmmContract(
329
293
  deployer: AztecAddress,
330
- contractAddressSalt: Fr,
294
+ salt: Fr,
331
295
  token0: TokenContract,
332
296
  token1: TokenContract,
333
297
  lpToken: TokenContract,
334
298
  ): Promise<AMMContract> {
335
- const deployOpts: DeployOptions = { from: deployer, contractAddressSalt, universalDeploy: true };
336
- const deploy = AMMContract.deploy(this.wallet, token0.address, token1.address, lpToken.address);
299
+ const deployOpts: DeployOptions = { from: deployer };
300
+ const deploy = AMMContract.deploy(this.wallet, token0.address, token1.address, lpToken.address, {
301
+ salt,
302
+ universalDeploy: true,
303
+ });
337
304
  const instance = await this.registerOrDeployContract('AMM', deploy, deployOpts);
338
305
  const amm = AMMContract.at(instance.address, this.wallet);
339
306
 
340
307
  this.log.info(`AMM deployed at ${amm.address}`);
341
- const { receipt: minterReceipt } = await lpToken.methods
342
- .set_minter(amm.address, true)
343
- .send({ from: deployer, wait: { timeout: this.config.txMinedWaitSeconds } });
308
+ const setMinterInteraction = lpToken.methods.set_minter(amm.address, true);
309
+ const { receipt: minterReceipt } = await setMinterInteraction.send({
310
+ from: deployer,
311
+ wait: { timeout: this.config.txMinedWaitSeconds },
312
+ });
344
313
  this.log.info(`Set LP token minter to AMM txHash=${minterReceipt.txHash.toString()}`);
345
314
  this.log.info(`Liquidity token initialized`);
346
315
 
@@ -409,20 +378,29 @@ export class BotFactory {
409
378
  .getFunctionCall(),
410
379
  });
411
380
 
412
- const { receipt: mintReceipt } = await new BatchCall(this.wallet, [
381
+ const mintBatch = new BatchCall(this.wallet, [
413
382
  token0.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
414
383
  token1.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
415
- ]).send({ from: liquidityProvider, wait: { timeout: this.config.txMinedWaitSeconds } });
384
+ ]);
385
+ const { receipt: mintReceipt } = await mintBatch.send({
386
+ from: liquidityProvider,
387
+ wait: { timeout: this.config.txMinedWaitSeconds },
388
+ });
416
389
 
417
390
  this.log.info(`Sent mint tx: ${mintReceipt.txHash.toString()}`);
418
391
 
419
- const { receipt: addLiquidityReceipt } = await amm.methods
420
- .add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, authwitNonce)
421
- .send({
422
- from: liquidityProvider,
423
- authWitnesses: [token0Authwit, token1Authwit],
424
- wait: { timeout: this.config.txMinedWaitSeconds },
425
- });
392
+ const addLiquidityInteraction = amm.methods.add_liquidity(
393
+ amount0Max,
394
+ amount1Max,
395
+ amount0Min,
396
+ amount1Min,
397
+ authwitNonce,
398
+ );
399
+ const { receipt: addLiquidityReceipt } = await addLiquidityInteraction.send({
400
+ from: liquidityProvider,
401
+ authWitnesses: [token0Authwit, token1Authwit],
402
+ wait: { timeout: this.config.txMinedWaitSeconds },
403
+ });
426
404
 
427
405
  this.log.info(`Sent tx to add liquidity to the AMM: ${addLiquidityReceipt.txHash.toString()}`);
428
406
  this.log.info(`Liquidity added`);
@@ -438,27 +416,75 @@ export class BotFactory {
438
416
  deploy: DeployMethod<T>,
439
417
  deployOpts: DeployOptions,
440
418
  ): Promise<ContractInstanceWithAddress> {
441
- const instance = await deploy.getInstance(deployOpts);
419
+ const instance = await deploy.getInstance();
442
420
  const address = instance.address;
443
421
  const metadata = await this.wallet.getContractMetadata(address);
444
422
  if (metadata.isContractPublished) {
445
423
  this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
446
424
  await deploy.register();
447
- } else {
448
- this.log.info(`Deploying contract ${name} at ${address.toString()}`);
449
- await this.withNoMinTxsPerBlock(async () => {
450
- const { txHash } = await deploy.send({ ...deployOpts, wait: NO_WAIT });
451
- this.log.info(`Sent contract ${name} setup tx with hash ${txHash.toString()}`);
452
- return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
453
- });
425
+ return instance;
454
426
  }
427
+
428
+ // Setup always runs ensureFeeJuiceBalance before any deploy, so the account pays from its standing
429
+ // balance here. No manual gas estimation: the embedded wallet simulates before sending and derives
430
+ // the gas limits and padded maxFeesPerGas itself.
431
+ this.log.info(`Deploying contract ${name} at ${address.toString()}`);
432
+ await this.withNoMinTxsPerBlock(async () => {
433
+ const { txHash } = await deploy.send({ ...deployOpts, wait: NO_WAIT });
434
+ this.log.info(`Sent contract ${name} deploy tx ${txHash.toString()}`);
435
+ return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
436
+ });
437
+
455
438
  return instance;
456
439
  }
457
440
 
441
+ /** True when the config allows bridging fee juice from L1 (fee_juice mode, an L1 RPC, and an L1 key). */
442
+ private isL1BridgingConfigured(): boolean {
443
+ const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
444
+ return this.config.feePaymentMethod === 'fee_juice' && !!this.config.l1RpcUrls?.length && !!mnemonicOrPrivateKey;
445
+ }
446
+
458
447
  /**
459
- * Mints private and public tokens for the sender if their balance is below the minimum.
460
- * @param token - Token contract.
448
+ * Ensures the account holds enough fee juice before any other setup step. The account starts empty
449
+ * (initializerless accounts have no deployment tx) and the runtime loop pays fees from this balance and
450
+ * never refuels itself, so every flow funds the account up front. Bridges claims from L1 and consumes
451
+ * each with a claim-only tx until the balance clears the threshold, working from a zero (fresh run) or
452
+ * drained (restart) balance. Each bridge mints a fixed amount well above the threshold, so this is a
453
+ * single bridge in practice. No-op when L1 bridging is not configured or the balance is already above
454
+ * the threshold.
461
455
  */
456
+ private async ensureFeeJuiceBalance(account: AztecAddress): Promise<void> {
457
+ if (!this.isL1BridgingConfigured()) {
458
+ return;
459
+ }
460
+
461
+ let balance = await getFeeJuiceBalance(account, this.aztecNode);
462
+ if (balance >= FEE_JUICE_TOP_UP_THRESHOLD) {
463
+ this.log.info(`Fee juice balance ${balance} above threshold ${FEE_JUICE_TOP_UP_THRESHOLD}, skipping top-up`);
464
+ return;
465
+ }
466
+
467
+ this.log.info(`Fee juice balance ${balance} below threshold ${FEE_JUICE_TOP_UP_THRESHOLD}, bridging from L1`);
468
+
469
+ while (balance < FEE_JUICE_TOP_UP_THRESHOLD) {
470
+ // Persist the claim before consuming it: if the top-up tx fails or the bot crashes mid-loop, the
471
+ // next run reuses the pending claim instead of bridging again (and wasting the bridged funds).
472
+ const claim = await this.getOrCreateBridgeClaim(account);
473
+ const paymentMethod = new FeeJuicePaymentMethodWithClaim(account, claim);
474
+
475
+ await this.withNoMinTxsPerBlock(async () => {
476
+ const executionPayload = await paymentMethod.getExecutionPayload();
477
+ const { txHash } = await this.wallet.sendTx(executionPayload, { from: account, wait: NO_WAIT });
478
+ this.log.info(`Sent fee juice top-up tx ${txHash.toString()}`);
479
+ return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
480
+ });
481
+ await this.store.deleteBridgeClaim(account);
482
+ balance = await getFeeJuiceBalance(account, this.aztecNode);
483
+ this.log.info(`Fee juice balance after top-up: ${balance}`);
484
+ }
485
+ this.log.info(`Fee juice top-up complete for ${account.toString()}`);
486
+ }
487
+
462
488
  private async mintTokens(token: TokenContract | PrivateTokenContract, minter: AztecAddress) {
463
489
  const isStandardToken = isStandardTokenContract(token);
464
490
  let privateBalance = 0n;
@@ -491,8 +517,9 @@ export class BotFactory {
491
517
 
492
518
  // PrivateToken's mint accesses contract-level private storage vars (admin, total_supply).
493
519
  const additionalScopes = isStandardToken ? undefined : [token.address];
520
+ const mintBatch = new BatchCall(token.wallet, calls);
494
521
  await this.withNoMinTxsPerBlock(async () => {
495
- const { txHash } = await new BatchCall(token.wallet, calls).send({
522
+ const { txHash } = await mintBatch.send({
496
523
  from: minter,
497
524
  additionalScopes,
498
525
  wait: NO_WAIT,
@@ -503,22 +530,20 @@ export class BotFactory {
503
530
  }
504
531
 
505
532
  /**
506
- * Gets or creates a bridge claim for the recipient.
507
- * Checks if a claim already exists in the store and reuses it if valid.
508
- * Only creates a new bridge if fee juice balance is below threshold.
533
+ * Returns a usable bridge claim for the recipient, reusing a persisted one when its L1→L2 message is
534
+ * still available (resuming a top-up that failed or crashed before the claim was consumed) and bridging
535
+ * a fresh claim otherwise. The caller deletes the claim from the store once it has been consumed.
509
536
  */
510
537
  private async getOrCreateBridgeClaim(recipient: AztecAddress): Promise<L2AmountClaim> {
511
- // Check if we have an existing claim in the store
512
538
  const existingClaim = await this.store.getBridgeClaim(recipient);
513
539
  if (existingClaim) {
514
540
  this.log.info(`Found existing bridge claim for ${recipient.toString()}, checking validity...`);
515
-
516
- // Check if the message is ready on L2
517
541
  try {
518
542
  const messageHash = Fr.fromHexString(existingClaim.claim.messageHash);
519
543
  await this.withNoMinTxsPerBlock(() =>
520
544
  waitForL1ToL2MessageReady(this.aztecNode, messageHash, {
521
545
  timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds,
546
+ chainTip: this.syncChainTip,
522
547
  }),
523
548
  );
524
549
  return existingClaim.claim;
@@ -530,7 +555,6 @@ export class BotFactory {
530
555
 
531
556
  const claim = await this.bridgeL1FeeJuice(recipient);
532
557
  await this.store.saveBridgeClaim(recipient, claim);
533
-
534
558
  return claim;
535
559
  }
536
560
 
@@ -557,6 +581,7 @@ export class BotFactory {
557
581
  await this.withNoMinTxsPerBlock(() =>
558
582
  waitForL1ToL2MessageReady(this.aztecNode, Fr.fromHexString(claim.messageHash), {
559
583
  timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds,
584
+ chainTip: this.syncChainTip,
560
585
  }),
561
586
  );
562
587
 
package/src/interface.ts CHANGED
@@ -22,11 +22,11 @@ export interface BotRunnerApi {
22
22
  }
23
23
 
24
24
  export const BotRunnerApiSchema: ApiSchemaFor<BotRunnerApi> = {
25
- start: z.function().args().returns(z.void()),
26
- stop: z.function().args().returns(z.void()),
27
- run: z.function().args().returns(z.void()),
28
- setup: z.function().args().returns(z.void()),
29
- getInfo: z.function().args().returns(BotInfoSchema),
30
- getConfig: z.function().args().returns(BotConfigSchema),
31
- update: z.function().args(BotConfigSchema).returns(z.void()),
25
+ start: z.function({ input: z.tuple([]), output: z.void() }),
26
+ stop: z.function({ input: z.tuple([]), output: z.void() }),
27
+ run: z.function({ input: z.tuple([]), output: z.void() }),
28
+ setup: z.function({ input: z.tuple([]), output: z.void() }),
29
+ getInfo: z.function({ input: z.tuple([]), output: BotInfoSchema }),
30
+ getConfig: z.function({ input: z.tuple([]), output: BotConfigSchema }),
31
+ update: z.function({ input: z.tuple([BotConfigSchema]), output: z.void() }),
32
32
  };
package/src/runner.ts CHANGED
@@ -2,6 +2,7 @@ import { createLogger } from '@aztec/aztec.js/log';
2
2
  import type { AztecNode } from '@aztec/aztec.js/node';
3
3
  import { omit } from '@aztec/foundation/collection';
4
4
  import { RunningPromise } from '@aztec/foundation/running-promise';
5
+ import type { BlockTag } from '@aztec/stdlib/block';
5
6
  import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
6
7
  import { type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
7
8
  import type { EmbeddedWallet } from '@aztec/wallets/embedded';
@@ -30,6 +31,7 @@ export class BotRunner implements BotRunnerApi, Traceable {
30
31
  private readonly telemetry: TelemetryClient,
31
32
  private readonly aztecNodeAdmin: AztecNodeAdmin | undefined,
32
33
  private readonly store: BotStore,
34
+ private readonly syncChainTip?: BlockTag,
33
35
  ) {
34
36
  this.tracer = telemetry.getTracer('Bot');
35
37
 
@@ -149,13 +151,34 @@ export class BotRunner implements BotRunnerApi, Traceable {
149
151
  try {
150
152
  switch (this.config.botMode) {
151
153
  case 'crosschain':
152
- this.bot = CrossChainBot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
154
+ this.bot = CrossChainBot.create(
155
+ this.config,
156
+ this.wallet,
157
+ this.aztecNode,
158
+ this.aztecNodeAdmin,
159
+ this.store,
160
+ this.syncChainTip,
161
+ );
153
162
  break;
154
163
  case 'amm':
155
- this.bot = AmmBot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
164
+ this.bot = AmmBot.create(
165
+ this.config,
166
+ this.wallet,
167
+ this.aztecNode,
168
+ this.aztecNodeAdmin,
169
+ this.store,
170
+ this.syncChainTip,
171
+ );
156
172
  break;
157
173
  case 'transfer':
158
- this.bot = Bot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
174
+ this.bot = Bot.create(
175
+ this.config,
176
+ this.wallet,
177
+ this.aztecNode,
178
+ this.aztecNodeAdmin,
179
+ this.store,
180
+ this.syncChainTip,
181
+ );
159
182
  break;
160
183
  default: {
161
184
  const _exhaustive: never = this.config.botMode;