@aztec/bot 5.0.0-nightly.20260612 → 5.0.0-nightly.20260613

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/dest/factory.d.ts CHANGED
@@ -50,21 +50,19 @@ export declare class BotFactory {
50
50
  }>;
51
51
  private setupTestContract;
52
52
  private setupAccount;
53
- private setupAccountWithPrivateKey;
54
53
  private setupTestAccount;
55
- private setupTokenWithOptionalEarlyRefuel;
56
- private setupTokenContractWithOptionalEarlyRefuel;
57
- private getTokenInstance;
54
+ private setupAccountWithPrivateKey;
58
55
  private setupToken;
59
56
  private setupTokenContract;
60
57
  private setupAmmContract;
61
58
  private fundAmm;
62
59
  private registerOrDeployContract;
60
+ /** True when the config allows bridging fee juice from L1 (fee_juice mode, an L1 RPC, and an L1 key). */
61
+ private isL1BridgingConfigured;
63
62
  private ensureFeeJuiceBalance;
64
63
  private mintTokens;
65
64
  private getOrCreateBridgeClaim;
66
65
  private bridgeL1FeeJuice;
67
- private getMinFees;
68
66
  private withNoMinTxsPerBlock;
69
67
  }
70
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ZhY3RvcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBcUJ6RCxPQUFPLEtBQUssRUFBRSx3QkFBd0IsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBSXRFLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSw4QkFBOEIsQ0FBQztBQUMzRCxPQUFPLEVBQUUsb0JBQW9CLEVBQUUsTUFBTSx1Q0FBdUMsQ0FBQztBQUM3RSxPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDL0Qs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QACpC,GAAG,EAAE,WAAW,CAAC;QACjB,MAAM,EAAE,aAAa,CAAC;QACtB,MAAM,EAAE,aAAa,CAAC;QACtB,IAAI,EAAE,SAAS,CAAC;KACjB,CAAC,CAuBD;IAED;;;OAGG;IACU,eAAe,IAAI,OAAO,CAAC;QACtC,MAAM,EAAE,cAAc,CAAC;QACvB,qBAAqB,EAAE,YAAY,CAAC;QACpC,QAAQ,EAAE,YAAY,CAAC;QACvB,IAAI,EAAE,SAAS,CAAC;QAChB,QAAQ,EAAE,wBAAwB,CAAC;QACnC,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC,CA6DD;YAEa,iBAAiB;YAWjB,YAAY;YAkBZ,gBAAgB;YAUhB,0BAA0B;YAc1B,UAAU;YAyCV,kBAAkB;YAalB,gBAAgB;YA2BhB,OAAO;YA+FP,wBAAwB;IA2BtC,yGAAyG;IACzG,OAAO,CAAC,sBAAsB;YAchB,qBAAqB;YAgCrB,UAAU;YAiDV,sBAAsB;YAwBtB,gBAAgB;YAgChB,oBAAoB;CAenC"}
package/dest/factory.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { getInitialTestAccountsData } from '@aztec/accounts/testing';
2
- import { NO_FROM } from '@aztec/aztec.js/account';
3
2
  import { BatchCall, NO_WAIT } from '@aztec/aztec.js/contracts';
4
3
  import { L1FeeJuicePortalManager } from '@aztec/aztec.js/ethereum';
5
4
  import { FeeJuicePaymentMethodWithClaim } from '@aztec/aztec.js/fee';
@@ -8,18 +7,15 @@ import { createLogger } from '@aztec/aztec.js/log';
8
7
  import { waitForL1ToL2MessageReady } from '@aztec/aztec.js/messaging';
9
8
  import { waitForTx } from '@aztec/aztec.js/node';
10
9
  import { getFeeJuiceBalance } from '@aztec/aztec.js/utils';
11
- import { ContractInitializationStatus } from '@aztec/aztec.js/wallet';
12
10
  import { createEthereumChain } from '@aztec/ethereum/chain';
13
11
  import { createExtendedL1Client } from '@aztec/ethereum/client';
14
12
  import { RollupContract } from '@aztec/ethereum/contracts';
15
13
  import { Fr } from '@aztec/foundation/curves/bn254';
16
14
  import { EthAddress } from '@aztec/foundation/eth-address';
17
- import { Timer } from '@aztec/foundation/timer';
18
15
  import { AMMContract } from '@aztec/noir-contracts.js/AMM';
19
16
  import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
20
17
  import { TokenContract } from '@aztec/noir-contracts.js/Token';
21
18
  import { TestContract } from '@aztec/noir-test-contracts.js/Test';
22
- import { GasFees, ManaUsageEstimate } from '@aztec/stdlib/gas';
23
19
  import { deriveSigningKey } from '@aztec/stdlib/keys';
24
20
  import { SupportedTokenContracts } from './config.js';
25
21
  import { seedL1ToL2Message } from './l1_to_l2_seeding.js';
@@ -27,7 +23,6 @@ import { getBalances, getPrivateBalance, isStandardTokenContract } from './utils
27
23
  const MINT_BALANCE = 1e12;
28
24
  const MIN_BALANCE = 1e3;
29
25
  const FEE_JUICE_TOP_UP_THRESHOLD = 100n * 10n ** 18n;
30
- const FEE_JUICE_TOP_UP_TARGET = 10_000n * 10n ** 18n;
31
26
  export class BotFactory {
32
27
  config;
33
28
  wallet;
@@ -54,8 +49,8 @@ export class BotFactory {
54
49
  */ async setup() {
55
50
  const defaultAccountAddress = await this.setupAccount();
56
51
  const recipient = (await this.wallet.createSchnorrAccount(Fr.random(), Fr.random())).address;
57
- const token = await this.setupTokenWithOptionalEarlyRefuel(defaultAccountAddress);
58
- await this.ensureFeeJuiceBalance(defaultAccountAddress, token);
52
+ await this.ensureFeeJuiceBalance(defaultAccountAddress);
53
+ const token = await this.setupToken(defaultAccountAddress);
59
54
  await this.mintTokens(token, defaultAccountAddress);
60
55
  return {
61
56
  wallet: this.wallet,
@@ -67,8 +62,8 @@ export class BotFactory {
67
62
  }
68
63
  async setupAmm() {
69
64
  const defaultAccountAddress = await this.setupAccount();
70
- const token0 = await this.setupTokenContractWithOptionalEarlyRefuel(defaultAccountAddress, this.config.tokenSalt, 'BotToken0', 'BOT0');
71
- await this.ensureFeeJuiceBalance(defaultAccountAddress, token0);
65
+ await this.ensureFeeJuiceBalance(defaultAccountAddress);
66
+ const token0 = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotToken0', 'BOT0');
72
67
  const token1 = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotToken1', 'BOT1');
73
68
  const liquidityToken = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotLPToken', 'BOTLP');
74
69
  const amm = await this.setupAmmContract(defaultAccountAddress, this.config.tokenSalt, token0, token1, liquidityToken);
@@ -88,6 +83,7 @@ export class BotFactory {
88
83
  * seeding initial L1→L2 messages, and waiting for the first to be ready.
89
84
  */ async setupCrossChain() {
90
85
  const defaultAccountAddress = await this.setupAccount();
86
+ await this.ensureFeeJuiceBalance(defaultAccountAddress);
91
87
  // Create L1 client (same pattern as bridgeL1FeeJuice)
92
88
  const l1RpcUrls = this.config.l1RpcUrls;
93
89
  if (!l1RpcUrls?.length) {
@@ -103,7 +99,7 @@ export class BotFactory {
103
99
  // Fetch Rollup version (needed for Inbox L2Actor struct)
104
100
  const rollupContract = new RollupContract(l1Client, l1ContractAddresses.rollupAddress.toString());
105
101
  const rollupVersion = await rollupContract.getVersion();
106
- // Deploy TestContract
102
+ // Deploy TestContract (pays from the standing balance funded above).
107
103
  const contract = await this.setupTestContract(defaultAccountAddress);
108
104
  // Recover any pending messages from store (clean up stale ones first)
109
105
  await this.store.cleanupOldPendingMessages();
@@ -157,102 +153,24 @@ export class BotFactory {
157
153
  return await this.setupTestAccount();
158
154
  }
159
155
  }
156
+ /**
157
+ * Keyless fallback for tests and local dev: reuses the first genesis test account, whose address is
158
+ * pre-funded with fee juice via `initialFundedAccounts`. The test accounts are initializerless, so this
159
+ * must create an initializerless account for the address to match the funded one. Production bots set a
160
+ * sender private key and fund the resulting initializerless account from L1 instead; see
161
+ * setupAccountWithPrivateKey.
162
+ */ async setupTestAccount() {
163
+ const [initialAccountData] = await getInitialTestAccountsData();
164
+ const accountManager = await this.wallet.createSchnorrInitializerlessAccount(initialAccountData.secret, initialAccountData.salt, initialAccountData.signingKey);
165
+ return accountManager.address;
166
+ }
160
167
  async setupAccountWithPrivateKey(secret) {
161
168
  const salt = this.config.senderSalt ?? Fr.ONE;
162
169
  const signingKey = deriveSigningKey(secret);
163
- const accountManager = await this.wallet.createSchnorrAccount(secret, salt, signingKey);
164
- const metadata = await this.wallet.getContractMetadata(accountManager.address);
165
- if (metadata.initializationStatus === ContractInitializationStatus.INITIALIZED) {
166
- this.log.info(`Account at ${accountManager.address.toString()} already initialized`);
167
- const timer = new Timer();
168
- const address = accountManager.address;
169
- this.log.info(`Account at ${address} registered. duration=${timer.ms()}`);
170
- await this.store.deleteBridgeClaim(address);
171
- return address;
172
- } else {
173
- const address = accountManager.address;
174
- this.log.info(`Deploying account at ${address}`);
175
- const claim = await this.getOrCreateBridgeClaim(address);
176
- const paymentMethod = new FeeJuicePaymentMethodWithClaim(accountManager.address, claim);
177
- const deployMethod = await accountManager.getDeployMethod();
178
- await this.withNoMinTxsPerBlock(async ()=>{
179
- const { txHash } = await deployMethod.send({
180
- from: NO_FROM,
181
- fee: {
182
- paymentMethod
183
- },
184
- wait: NO_WAIT
185
- });
186
- this.log.info(`Sent tx for account deployment with hash ${txHash.toString()}`);
187
- return waitForTx(this.aztecNode, txHash, {
188
- timeout: this.config.txMinedWaitSeconds
189
- });
190
- });
191
- this.log.info(`Account deployed at ${address}`);
192
- // Clean up the consumed bridge claim
193
- await this.store.deleteBridgeClaim(address);
194
- return accountManager.address;
195
- }
196
- }
197
- async setupTestAccount() {
198
- const [initialAccountData] = await getInitialTestAccountsData();
199
- const accountManager = await this.wallet.createSchnorrAccount(initialAccountData.secret, initialAccountData.salt, initialAccountData.signingKey);
170
+ const accountManager = await this.wallet.createSchnorrInitializerlessAccount(secret, salt, signingKey);
200
171
  return accountManager.address;
201
172
  }
202
173
  /**
203
- * Setup token and refuel first: if the token already exists (restart scenario),
204
- * run ensureFeeJuiceBalance before any step that might need fee juice. When deploying,
205
- * use a bridge claim if balance is below threshold.
206
- */ async setupTokenWithOptionalEarlyRefuel(sender) {
207
- const token = await this.getTokenInstance(sender);
208
- const address = token.address;
209
- const metadata = await this.wallet.getContractMetadata(address);
210
- if (metadata.isContractPublished) {
211
- this.log.info(`Token at ${address.toString()} already deployed, refueling before setup`);
212
- await this.ensureFeeJuiceBalance(sender, token);
213
- }
214
- return this.setupToken(sender);
215
- }
216
- /**
217
- * Setup token0 for AMM with refuel-first behaviour when token already exists.
218
- */ async setupTokenContractWithOptionalEarlyRefuel(deployer, salt, name, ticker, decimals = 18) {
219
- const deploy = TokenContract.deploy(this.wallet, deployer, name, ticker, decimals, {
220
- salt,
221
- universalDeploy: true
222
- });
223
- const instance = await deploy.getInstance();
224
- const metadata = await this.wallet.getContractMetadata(instance.address);
225
- if (metadata.isContractPublished) {
226
- this.log.info(`Token ${name} at ${instance.address.toString()} already deployed, refueling before setup`);
227
- const token = TokenContract.at(instance.address, this.wallet);
228
- await this.ensureFeeJuiceBalance(deployer, token);
229
- }
230
- return this.setupTokenContract(deployer, salt, name, ticker, decimals);
231
- }
232
- async getTokenInstance(sender) {
233
- const salt = this.config.tokenSalt;
234
- if (this.config.contract === SupportedTokenContracts.TokenContract) {
235
- const deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18, {
236
- salt,
237
- universalDeploy: true
238
- });
239
- const instance = await deploy.getInstance();
240
- return TokenContract.at(instance.address, this.wallet);
241
- }
242
- if (this.config.contract === SupportedTokenContracts.PrivateTokenContract) {
243
- const tokenSecretKey = Fr.random();
244
- const tokenPublicKeys = (await deriveKeys(tokenSecretKey)).publicKeys;
245
- const deploy = PrivateTokenContract.deploy(this.wallet, MINT_BALANCE, sender, {
246
- salt,
247
- universalDeploy: true,
248
- publicKeys: tokenPublicKeys
249
- });
250
- const instance = await deploy.getInstance();
251
- return PrivateTokenContract.at(instance.address, this.wallet);
252
- }
253
- throw new Error(`Unsupported token contract type: ${this.config.contract}`);
254
- }
255
- /**
256
174
  * Checks if the token contract is deployed and deploys it if necessary.
257
175
  * Uses a bridge claim for deploy when balance is below threshold to avoid failing before refuel.
258
176
  * @param sender - Aztec address to deploy the token contract from.
@@ -398,68 +316,38 @@ export class BotFactory {
398
316
  if (metadata.isContractPublished) {
399
317
  this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
400
318
  await deploy.register();
401
- } else {
402
- const sender = deployOpts.from === NO_FROM ? undefined : deployOpts.from;
403
- const balance = sender ? await getFeeJuiceBalance(sender, this.aztecNode) : 0n;
404
- const useClaim = sender && balance < FEE_JUICE_TOP_UP_THRESHOLD && this.config.feePaymentMethod === 'fee_juice' && !!this.config.l1RpcUrls?.length;
405
- const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
406
- if (useClaim && mnemonicOrPrivateKey) {
407
- const claim = await this.getOrCreateBridgeClaim(sender);
408
- const paymentMethod = new FeeJuicePaymentMethodWithClaim(sender, claim);
409
- const maxFeesPerGas = (await this.getMinFees()).mul(1 + this.config.minFeePadding);
410
- // Leave gas limits unset so the wallet derives them from its own simulation and clamps to the
411
- // network's per-tx admission limits.
412
- const gasSettings = {
413
- maxFeesPerGas,
414
- maxPriorityFeesPerGas: GasFees.empty()
415
- };
416
- await this.withNoMinTxsPerBlock(async ()=>{
417
- const { txHash } = await deploy.send({
418
- ...deployOpts,
419
- fee: {
420
- gasSettings,
421
- paymentMethod
422
- },
423
- wait: NO_WAIT
424
- });
425
- this.log.info(`Sent contract ${name} deploy tx ${txHash.toString()} (using bridge claim, balance was ${balance})`);
426
- return waitForTx(this.aztecNode, txHash, {
427
- timeout: this.config.txMinedWaitSeconds
428
- });
429
- });
430
- await this.store.deleteBridgeClaim(sender);
431
- } else {
432
- this.log.info(`Deploying contract ${name} at ${address.toString()}`);
433
- // Gas limits are left unset so the wallet derives them from its own simulation and clamps to the
434
- // network's per-tx admission limits.
435
- await this.withNoMinTxsPerBlock(async ()=>{
436
- const { txHash } = await deploy.send({
437
- ...deployOpts,
438
- wait: NO_WAIT
439
- });
440
- this.log.info(`Sent contract ${name} setup tx with hash ${txHash.toString()}`);
441
- return waitForTx(this.aztecNode, txHash, {
442
- timeout: this.config.txMinedWaitSeconds
443
- });
444
- });
445
- }
319
+ return instance;
446
320
  }
321
+ // Setup always runs ensureFeeJuiceBalance before any deploy, so the account pays from its standing
322
+ // balance here. No manual gas estimation: the embedded wallet simulates before sending and derives
323
+ // the gas limits and padded maxFeesPerGas itself.
324
+ this.log.info(`Deploying contract ${name} at ${address.toString()}`);
325
+ await this.withNoMinTxsPerBlock(async ()=>{
326
+ const { txHash } = await deploy.send({
327
+ ...deployOpts,
328
+ wait: NO_WAIT
329
+ });
330
+ this.log.info(`Sent contract ${name} deploy tx ${txHash.toString()}`);
331
+ return waitForTx(this.aztecNode, txHash, {
332
+ timeout: this.config.txMinedWaitSeconds
333
+ });
334
+ });
447
335
  return instance;
448
336
  }
449
- /**
450
- * Mints private and public tokens for the sender if their balance is below the minimum.
451
- * @param token - Token contract.
452
- */ /**
453
- * Ensures the account has sufficient fee juice by bridging from L1 if balance is below threshold.
454
- * Bridges repeatedly until balance reaches the target (10k FJ).
455
- * Used on startup/restart to top up when the account has run out after previous runs.
456
- */ async ensureFeeJuiceBalance(account, token) {
457
- const { feePaymentMethod, l1RpcUrls } = this.config;
458
- if (feePaymentMethod !== 'fee_juice' || !l1RpcUrls?.length) {
459
- return;
460
- }
337
+ /** True when the config allows bridging fee juice from L1 (fee_juice mode, an L1 RPC, and an L1 key). */ isL1BridgingConfigured() {
461
338
  const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
462
- if (!mnemonicOrPrivateKey) {
339
+ return this.config.feePaymentMethod === 'fee_juice' && !!this.config.l1RpcUrls?.length && !!mnemonicOrPrivateKey;
340
+ }
341
+ /**
342
+ * Ensures the account holds enough fee juice before any other setup step. The account starts empty
343
+ * (initializerless accounts have no deployment tx) and the runtime loop pays fees from this balance and
344
+ * never refuels itself, so every flow funds the account up front. Bridges claims from L1 and consumes
345
+ * each with a claim-only tx until the balance clears the threshold, working from a zero (fresh run) or
346
+ * drained (restart) balance. Each bridge mints a fixed amount well above the threshold, so this is a
347
+ * single bridge in practice. No-op when L1 bridging is not configured or the balance is already above
348
+ * the threshold.
349
+ */ async ensureFeeJuiceBalance(account) {
350
+ if (!this.isL1BridgingConfigured()) {
463
351
  return;
464
352
  }
465
353
  let balance = await getFeeJuiceBalance(account, this.aztecNode);
@@ -467,25 +355,16 @@ export class BotFactory {
467
355
  this.log.info(`Fee juice balance ${balance} above threshold ${FEE_JUICE_TOP_UP_THRESHOLD}, skipping top-up`);
468
356
  return;
469
357
  }
470
- this.log.info(`Fee juice balance ${balance} below threshold ${FEE_JUICE_TOP_UP_THRESHOLD}, bridging from L1 until ${FEE_JUICE_TOP_UP_TARGET}`);
471
- const maxFeesPerGas = (await this.getMinFees()).mul(1 + this.config.minFeePadding);
472
- const minimalInteraction = isStandardTokenContract(token) ? token.methods.transfer_in_public(account, account, 0n, 0) : token.methods.transfer(0n, account, account);
473
- while(balance < FEE_JUICE_TOP_UP_TARGET){
474
- const claim = await this.bridgeL1FeeJuice(account);
358
+ this.log.info(`Fee juice balance ${balance} below threshold ${FEE_JUICE_TOP_UP_THRESHOLD}, bridging from L1`);
359
+ while(balance < FEE_JUICE_TOP_UP_THRESHOLD){
360
+ // Persist the claim before consuming it: if the top-up tx fails or the bot crashes mid-loop, the
361
+ // next run reuses the pending claim instead of bridging again (and wasting the bridged funds).
362
+ const claim = await this.getOrCreateBridgeClaim(account);
475
363
  const paymentMethod = new FeeJuicePaymentMethodWithClaim(account, claim);
476
- // Leave gas limits unset so the wallet derives them from its own simulation and clamps to the
477
- // network's per-tx admission limits.
478
- const gasSettings = {
479
- maxFeesPerGas,
480
- maxPriorityFeesPerGas: GasFees.empty()
481
- };
482
364
  await this.withNoMinTxsPerBlock(async ()=>{
483
- const { txHash } = await minimalInteraction.send({
365
+ const executionPayload = await paymentMethod.getExecutionPayload();
366
+ const { txHash } = await this.wallet.sendTx(executionPayload, {
484
367
  from: account,
485
- fee: {
486
- gasSettings,
487
- paymentMethod
488
- },
489
368
  wait: NO_WAIT
490
369
  });
491
370
  this.log.info(`Sent fee juice top-up tx ${txHash.toString()}`);
@@ -493,6 +372,7 @@ export class BotFactory {
493
372
  timeout: this.config.txMinedWaitSeconds
494
373
  });
495
374
  });
375
+ await this.store.deleteBridgeClaim(account);
496
376
  balance = await getFeeJuiceBalance(account, this.aztecNode);
497
377
  this.log.info(`Fee juice balance after top-up: ${balance}`);
498
378
  }
@@ -538,15 +418,13 @@ export class BotFactory {
538
418
  });
539
419
  }
540
420
  /**
541
- * Gets or creates a bridge claim for the recipient.
542
- * Checks if a claim already exists in the store and reuses it if valid.
543
- * Only creates a new bridge if fee juice balance is below threshold.
421
+ * Returns a usable bridge claim for the recipient, reusing a persisted one when its L1→L2 message is
422
+ * still available (resuming a top-up that failed or crashed before the claim was consumed) and bridging
423
+ * a fresh claim otherwise. The caller deletes the claim from the store once it has been consumed.
544
424
  */ async getOrCreateBridgeClaim(recipient) {
545
- // Check if we have an existing claim in the store
546
425
  const existingClaim = await this.store.getBridgeClaim(recipient);
547
426
  if (existingClaim) {
548
427
  this.log.info(`Found existing bridge claim for ${recipient.toString()}, checking validity...`);
549
- // Check if the message is ready on L2
550
428
  try {
551
429
  const messageHash = Fr.fromHexString(existingClaim.claim.messageHash);
552
430
  await this.withNoMinTxsPerBlock(()=>waitForL1ToL2MessageReady(this.aztecNode, messageHash, {
@@ -585,17 +463,6 @@ export class BotFactory {
585
463
  this.log.info(`Created a claim for ${mintAmount} L1 fee juice to ${recipient}.`, claim);
586
464
  return claim;
587
465
  }
588
- /** Returns worst-case min fees across predicted slots, with fallback to current min fees. */ async getMinFees() {
589
- try {
590
- const predicted = await this.aztecNode.getPredictedMinFees(ManaUsageEstimate.Limit);
591
- if (predicted.length === 0) {
592
- return this.aztecNode.getCurrentMinFees();
593
- }
594
- return predicted.reduce((worst, fees)=>fees.feePerL2Gas > worst.feePerL2Gas ? fees : worst);
595
- } catch {
596
- return this.aztecNode.getCurrentMinFees();
597
- }
598
- }
599
466
  async withNoMinTxsPerBlock(fn) {
600
467
  if (!this.aztecNodeAdmin || !this.config.flushSetupTransactions) {
601
468
  this.log.verbose(`No node admin client or flushing not requested (not setting minTxsPerBlock to 0)`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/bot",
3
- "version": "5.0.0-nightly.20260612",
3
+ "version": "5.0.0-nightly.20260613",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -54,20 +54,20 @@
54
54
  ]
55
55
  },
56
56
  "dependencies": {
57
- "@aztec/accounts": "5.0.0-nightly.20260612",
58
- "@aztec/aztec.js": "5.0.0-nightly.20260612",
59
- "@aztec/entrypoints": "5.0.0-nightly.20260612",
60
- "@aztec/ethereum": "5.0.0-nightly.20260612",
61
- "@aztec/foundation": "5.0.0-nightly.20260612",
62
- "@aztec/kv-store": "5.0.0-nightly.20260612",
63
- "@aztec/l1-artifacts": "5.0.0-nightly.20260612",
64
- "@aztec/noir-contracts.js": "5.0.0-nightly.20260612",
65
- "@aztec/noir-protocol-circuits-types": "5.0.0-nightly.20260612",
66
- "@aztec/noir-test-contracts.js": "5.0.0-nightly.20260612",
67
- "@aztec/protocol-contracts": "5.0.0-nightly.20260612",
68
- "@aztec/stdlib": "5.0.0-nightly.20260612",
69
- "@aztec/telemetry-client": "5.0.0-nightly.20260612",
70
- "@aztec/wallets": "5.0.0-nightly.20260612",
57
+ "@aztec/accounts": "5.0.0-nightly.20260613",
58
+ "@aztec/aztec.js": "5.0.0-nightly.20260613",
59
+ "@aztec/entrypoints": "5.0.0-nightly.20260613",
60
+ "@aztec/ethereum": "5.0.0-nightly.20260613",
61
+ "@aztec/foundation": "5.0.0-nightly.20260613",
62
+ "@aztec/kv-store": "5.0.0-nightly.20260613",
63
+ "@aztec/l1-artifacts": "5.0.0-nightly.20260613",
64
+ "@aztec/noir-contracts.js": "5.0.0-nightly.20260613",
65
+ "@aztec/noir-protocol-circuits-types": "5.0.0-nightly.20260613",
66
+ "@aztec/noir-test-contracts.js": "5.0.0-nightly.20260613",
67
+ "@aztec/protocol-contracts": "5.0.0-nightly.20260613",
68
+ "@aztec/stdlib": "5.0.0-nightly.20260613",
69
+ "@aztec/telemetry-client": "5.0.0-nightly.20260613",
70
+ "@aztec/wallets": "5.0.0-nightly.20260613",
71
71
  "source-map-support": "^0.5.21",
72
72
  "tslib": "^2.4.0",
73
73
  "viem": "npm:@aztec/viem@2.38.2",
package/src/factory.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { getInitialTestAccountsData } from '@aztec/accounts/testing';
2
- import { NO_FROM } from '@aztec/aztec.js/account';
3
2
  import { AztecAddress } from '@aztec/aztec.js/addresses';
4
3
  import {
5
4
  BatchCall,
@@ -17,21 +16,18 @@ import { createLogger } from '@aztec/aztec.js/log';
17
16
  import { waitForL1ToL2MessageReady } from '@aztec/aztec.js/messaging';
18
17
  import { waitForTx } from '@aztec/aztec.js/node';
19
18
  import { getFeeJuiceBalance } from '@aztec/aztec.js/utils';
20
- import { ContractInitializationStatus } from '@aztec/aztec.js/wallet';
21
19
  import { createEthereumChain } from '@aztec/ethereum/chain';
22
20
  import { createExtendedL1Client } from '@aztec/ethereum/client';
23
21
  import { RollupContract } from '@aztec/ethereum/contracts';
24
22
  import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
25
23
  import { Fr } from '@aztec/foundation/curves/bn254';
26
24
  import { EthAddress } from '@aztec/foundation/eth-address';
27
- import { Timer } from '@aztec/foundation/timer';
28
25
  import { AMMContract } from '@aztec/noir-contracts.js/AMM';
29
26
  import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
30
27
  import { TokenContract } from '@aztec/noir-contracts.js/Token';
31
28
  import { TestContract } from '@aztec/noir-test-contracts.js/Test';
32
29
  import type { BlockTag } from '@aztec/stdlib/block';
33
30
  import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
34
- import { GasFees, ManaUsageEstimate } from '@aztec/stdlib/gas';
35
31
  import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
36
32
  import { deriveSigningKey } from '@aztec/stdlib/keys';
37
33
  import { EmbeddedWallet } from '@aztec/wallets/embedded';
@@ -44,7 +40,6 @@ import { getBalances, getPrivateBalance, isStandardTokenContract } from './utils
44
40
  const MINT_BALANCE = 1e12;
45
41
  const MIN_BALANCE = 1e3;
46
42
  const FEE_JUICE_TOP_UP_THRESHOLD = 100n * 10n ** 18n;
47
- const FEE_JUICE_TOP_UP_TARGET = 10_000n * 10n ** 18n;
48
43
 
49
44
  export class BotFactory {
50
45
  private log = createLogger('bot');
@@ -75,8 +70,8 @@ export class BotFactory {
75
70
  }> {
76
71
  const defaultAccountAddress = await this.setupAccount();
77
72
  const recipient = (await this.wallet.createSchnorrAccount(Fr.random(), Fr.random())).address;
78
- const token = await this.setupTokenWithOptionalEarlyRefuel(defaultAccountAddress);
79
- await this.ensureFeeJuiceBalance(defaultAccountAddress, token);
73
+ await this.ensureFeeJuiceBalance(defaultAccountAddress);
74
+ const token = await this.setupToken(defaultAccountAddress);
80
75
  await this.mintTokens(token, defaultAccountAddress);
81
76
  return { wallet: this.wallet, defaultAccountAddress, token, node: this.aztecNode, recipient };
82
77
  }
@@ -90,13 +85,8 @@ export class BotFactory {
90
85
  node: AztecNode;
91
86
  }> {
92
87
  const defaultAccountAddress = await this.setupAccount();
93
- const token0 = await this.setupTokenContractWithOptionalEarlyRefuel(
94
- defaultAccountAddress,
95
- this.config.tokenSalt,
96
- 'BotToken0',
97
- 'BOT0',
98
- );
99
- await this.ensureFeeJuiceBalance(defaultAccountAddress, token0);
88
+ await this.ensureFeeJuiceBalance(defaultAccountAddress);
89
+ const token0 = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotToken0', 'BOT0');
100
90
  const token1 = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotToken1', 'BOT1');
101
91
  const liquidityToken = await this.setupTokenContract(
102
92
  defaultAccountAddress,
@@ -131,6 +121,7 @@ export class BotFactory {
131
121
  rollupVersion: bigint;
132
122
  }> {
133
123
  const defaultAccountAddress = await this.setupAccount();
124
+ await this.ensureFeeJuiceBalance(defaultAccountAddress);
134
125
 
135
126
  // Create L1 client (same pattern as bridgeL1FeeJuice)
136
127
  const l1RpcUrls = this.config.l1RpcUrls;
@@ -149,7 +140,7 @@ export class BotFactory {
149
140
  const rollupContract = new RollupContract(l1Client, l1ContractAddresses.rollupAddress.toString());
150
141
  const rollupVersion = await rollupContract.getVersion();
151
142
 
152
- // Deploy TestContract
143
+ // Deploy TestContract (pays from the standing balance funded above).
153
144
  const contract = await this.setupTestContract(defaultAccountAddress);
154
145
 
155
146
  // Recover any pending messages from store (clean up stale ones first)
@@ -213,48 +204,16 @@ export class BotFactory {
213
204
  }
214
205
  }
215
206
 
216
- private async setupAccountWithPrivateKey(secret: Fr) {
217
- const salt = this.config.senderSalt ?? Fr.ONE;
218
- const signingKey = deriveSigningKey(secret);
219
- const accountManager = await this.wallet.createSchnorrAccount(secret, salt, signingKey);
220
- const metadata = await this.wallet.getContractMetadata(accountManager.address);
221
- if (metadata.initializationStatus === ContractInitializationStatus.INITIALIZED) {
222
- this.log.info(`Account at ${accountManager.address.toString()} already initialized`);
223
- const timer = new Timer();
224
- const address = accountManager.address;
225
- this.log.info(`Account at ${address} registered. duration=${timer.ms()}`);
226
- await this.store.deleteBridgeClaim(address);
227
- return address;
228
- } else {
229
- const address = accountManager.address;
230
- this.log.info(`Deploying account at ${address}`);
231
-
232
- const claim = await this.getOrCreateBridgeClaim(address);
233
-
234
- const paymentMethod = new FeeJuicePaymentMethodWithClaim(accountManager.address, claim);
235
- const deployMethod = await accountManager.getDeployMethod();
236
-
237
- await this.withNoMinTxsPerBlock(async () => {
238
- const { txHash } = await deployMethod.send({
239
- from: NO_FROM,
240
- fee: { paymentMethod },
241
- wait: NO_WAIT,
242
- });
243
- this.log.info(`Sent tx for account deployment with hash ${txHash.toString()}`);
244
- return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
245
- });
246
- this.log.info(`Account deployed at ${address}`);
247
-
248
- // Clean up the consumed bridge claim
249
- await this.store.deleteBridgeClaim(address);
250
-
251
- return accountManager.address;
252
- }
253
- }
254
-
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
+ */
255
214
  private async setupTestAccount() {
256
215
  const [initialAccountData] = await getInitialTestAccountsData();
257
- const accountManager = await this.wallet.createSchnorrAccount(
216
+ const accountManager = await this.wallet.createSchnorrInitializerlessAccount(
258
217
  initialAccountData.secret,
259
218
  initialAccountData.salt,
260
219
  initialAccountData.signingKey,
@@ -262,62 +221,11 @@ export class BotFactory {
262
221
  return accountManager.address;
263
222
  }
264
223
 
265
- /**
266
- * Setup token and refuel first: if the token already exists (restart scenario),
267
- * run ensureFeeJuiceBalance before any step that might need fee juice. When deploying,
268
- * use a bridge claim if balance is below threshold.
269
- */
270
- private async setupTokenWithOptionalEarlyRefuel(sender: AztecAddress): Promise<TokenContract | PrivateTokenContract> {
271
- const token = await this.getTokenInstance(sender);
272
- const address = token.address;
273
- const metadata = await this.wallet.getContractMetadata(address);
274
- if (metadata.isContractPublished) {
275
- this.log.info(`Token at ${address.toString()} already deployed, refueling before setup`);
276
- await this.ensureFeeJuiceBalance(sender, token);
277
- }
278
- return this.setupToken(sender);
279
- }
280
-
281
- /**
282
- * Setup token0 for AMM with refuel-first behaviour when token already exists.
283
- */
284
- private async setupTokenContractWithOptionalEarlyRefuel(
285
- deployer: AztecAddress,
286
- salt: Fr,
287
- name: string,
288
- ticker: string,
289
- decimals = 18,
290
- ): Promise<TokenContract> {
291
- const deploy = TokenContract.deploy(this.wallet, deployer, name, ticker, decimals, { salt, universalDeploy: true });
292
- const instance = await deploy.getInstance();
293
- const metadata = await this.wallet.getContractMetadata(instance.address);
294
- if (metadata.isContractPublished) {
295
- this.log.info(`Token ${name} at ${instance.address.toString()} already deployed, refueling before setup`);
296
- const token = TokenContract.at(instance.address, this.wallet);
297
- await this.ensureFeeJuiceBalance(deployer, token);
298
- }
299
- return this.setupTokenContract(deployer, salt, name, ticker, decimals);
300
- }
301
-
302
- private async getTokenInstance(sender: AztecAddress): Promise<TokenContract | PrivateTokenContract> {
303
- const salt = this.config.tokenSalt;
304
- if (this.config.contract === SupportedTokenContracts.TokenContract) {
305
- const deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18, { salt, universalDeploy: true });
306
- const instance = await deploy.getInstance();
307
- return TokenContract.at(instance.address, this.wallet);
308
- }
309
- if (this.config.contract === SupportedTokenContracts.PrivateTokenContract) {
310
- const tokenSecretKey = Fr.random();
311
- const tokenPublicKeys = (await deriveKeys(tokenSecretKey)).publicKeys;
312
- const deploy = PrivateTokenContract.deploy(this.wallet, MINT_BALANCE, sender, {
313
- salt,
314
- universalDeploy: true,
315
- publicKeys: tokenPublicKeys,
316
- });
317
- const instance = await deploy.getInstance();
318
- return PrivateTokenContract.at(instance.address, this.wallet);
319
- }
320
- throw new Error(`Unsupported token contract type: ${this.config.contract}`);
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;
321
229
  }
322
230
 
323
231
  /**
@@ -514,67 +422,39 @@ export class BotFactory {
514
422
  if (metadata.isContractPublished) {
515
423
  this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
516
424
  await deploy.register();
517
- } else {
518
- const sender = deployOpts.from === NO_FROM ? undefined : deployOpts.from;
519
- const balance = sender ? await getFeeJuiceBalance(sender, this.aztecNode) : 0n;
520
- const useClaim =
521
- sender &&
522
- balance < FEE_JUICE_TOP_UP_THRESHOLD &&
523
- this.config.feePaymentMethod === 'fee_juice' &&
524
- !!this.config.l1RpcUrls?.length;
525
- const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
526
-
527
- if (useClaim && mnemonicOrPrivateKey) {
528
- const claim = await this.getOrCreateBridgeClaim(sender!);
529
- const paymentMethod = new FeeJuicePaymentMethodWithClaim(sender!, claim);
530
- const maxFeesPerGas = (await this.getMinFees()).mul(1 + this.config.minFeePadding);
531
- // Leave gas limits unset so the wallet derives them from its own simulation and clamps to the
532
- // network's per-tx admission limits.
533
- const gasSettings = {
534
- maxFeesPerGas,
535
- maxPriorityFeesPerGas: GasFees.empty(),
536
- };
537
- await this.withNoMinTxsPerBlock(async () => {
538
- const { txHash } = await deploy.send({ ...deployOpts, fee: { gasSettings, paymentMethod }, wait: NO_WAIT });
539
- this.log.info(
540
- `Sent contract ${name} deploy tx ${txHash.toString()} (using bridge claim, balance was ${balance})`,
541
- );
542
- return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
543
- });
544
- await this.store.deleteBridgeClaim(sender!);
545
- } else {
546
- this.log.info(`Deploying contract ${name} at ${address.toString()}`);
547
- // Gas limits are left unset so the wallet derives them from its own simulation and clamps to the
548
- // network's per-tx admission limits.
549
- await this.withNoMinTxsPerBlock(async () => {
550
- const { txHash } = await deploy.send({ ...deployOpts, wait: NO_WAIT });
551
- this.log.info(`Sent contract ${name} setup tx with hash ${txHash.toString()}`);
552
- return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
553
- });
554
- }
425
+ return instance;
555
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
+
556
438
  return instance;
557
439
  }
558
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
+
559
447
  /**
560
- * Mints private and public tokens for the sender if their balance is below the minimum.
561
- * @param token - Token contract.
562
- */
563
- /**
564
- * Ensures the account has sufficient fee juice by bridging from L1 if balance is below threshold.
565
- * Bridges repeatedly until balance reaches the target (10k FJ).
566
- * Used on startup/restart to top up when the account has run out after previous runs.
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.
567
455
  */
568
- private async ensureFeeJuiceBalance(
569
- account: AztecAddress,
570
- token: TokenContract | PrivateTokenContract,
571
- ): Promise<void> {
572
- const { feePaymentMethod, l1RpcUrls } = this.config;
573
- if (feePaymentMethod !== 'fee_juice' || !l1RpcUrls?.length) {
574
- return;
575
- }
576
- const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
577
- if (!mnemonicOrPrivateKey) {
456
+ private async ensureFeeJuiceBalance(account: AztecAddress): Promise<void> {
457
+ if (!this.isL1BridgingConfigured()) {
578
458
  return;
579
459
  }
580
460
 
@@ -584,33 +464,21 @@ export class BotFactory {
584
464
  return;
585
465
  }
586
466
 
587
- this.log.info(
588
- `Fee juice balance ${balance} below threshold ${FEE_JUICE_TOP_UP_THRESHOLD}, bridging from L1 until ${FEE_JUICE_TOP_UP_TARGET}`,
589
- );
590
- const maxFeesPerGas = (await this.getMinFees()).mul(1 + this.config.minFeePadding);
591
- const minimalInteraction = isStandardTokenContract(token)
592
- ? token.methods.transfer_in_public(account, account, 0n, 0)
593
- : token.methods.transfer(0n, account, account);
467
+ this.log.info(`Fee juice balance ${balance} below threshold ${FEE_JUICE_TOP_UP_THRESHOLD}, bridging from L1`);
594
468
 
595
- while (balance < FEE_JUICE_TOP_UP_TARGET) {
596
- const claim = await this.bridgeL1FeeJuice(account);
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);
597
473
  const paymentMethod = new FeeJuicePaymentMethodWithClaim(account, claim);
598
- // Leave gas limits unset so the wallet derives them from its own simulation and clamps to the
599
- // network's per-tx admission limits.
600
- const gasSettings = {
601
- maxFeesPerGas,
602
- maxPriorityFeesPerGas: GasFees.empty(),
603
- };
604
474
 
605
475
  await this.withNoMinTxsPerBlock(async () => {
606
- const { txHash } = await minimalInteraction.send({
607
- from: account,
608
- fee: { gasSettings, paymentMethod },
609
- wait: NO_WAIT,
610
- });
476
+ const executionPayload = await paymentMethod.getExecutionPayload();
477
+ const { txHash } = await this.wallet.sendTx(executionPayload, { from: account, wait: NO_WAIT });
611
478
  this.log.info(`Sent fee juice top-up tx ${txHash.toString()}`);
612
479
  return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
613
480
  });
481
+ await this.store.deleteBridgeClaim(account);
614
482
  balance = await getFeeJuiceBalance(account, this.aztecNode);
615
483
  this.log.info(`Fee juice balance after top-up: ${balance}`);
616
484
  }
@@ -662,17 +530,14 @@ export class BotFactory {
662
530
  }
663
531
 
664
532
  /**
665
- * Gets or creates a bridge claim for the recipient.
666
- * Checks if a claim already exists in the store and reuses it if valid.
667
- * 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.
668
536
  */
669
537
  private async getOrCreateBridgeClaim(recipient: AztecAddress): Promise<L2AmountClaim> {
670
- // Check if we have an existing claim in the store
671
538
  const existingClaim = await this.store.getBridgeClaim(recipient);
672
539
  if (existingClaim) {
673
540
  this.log.info(`Found existing bridge claim for ${recipient.toString()}, checking validity...`);
674
-
675
- // Check if the message is ready on L2
676
541
  try {
677
542
  const messageHash = Fr.fromHexString(existingClaim.claim.messageHash);
678
543
  await this.withNoMinTxsPerBlock(() =>
@@ -690,7 +555,6 @@ export class BotFactory {
690
555
 
691
556
  const claim = await this.bridgeL1FeeJuice(recipient);
692
557
  await this.store.saveBridgeClaim(recipient, claim);
693
-
694
558
  return claim;
695
559
  }
696
560
 
@@ -726,19 +590,6 @@ export class BotFactory {
726
590
  return claim as L2AmountClaim;
727
591
  }
728
592
 
729
- /** Returns worst-case min fees across predicted slots, with fallback to current min fees. */
730
- private async getMinFees(): Promise<GasFees> {
731
- try {
732
- const predicted = await this.aztecNode.getPredictedMinFees(ManaUsageEstimate.Limit);
733
- if (predicted.length === 0) {
734
- return this.aztecNode.getCurrentMinFees();
735
- }
736
- return predicted.reduce((worst, fees) => (fees.feePerL2Gas > worst.feePerL2Gas ? fees : worst));
737
- } catch {
738
- return this.aztecNode.getCurrentMinFees();
739
- }
740
- }
741
-
742
593
  private async withNoMinTxsPerBlock<T>(fn: () => Promise<T>): Promise<T> {
743
594
  if (!this.aztecNodeAdmin || !this.config.flushSetupTransactions) {
744
595
  this.log.verbose(`No node admin client or flushing not requested (not setting minTxsPerBlock to 0)`);