@aztec/bot 6.0.0-nightly.20260723 → 6.0.0-nightly.20260725

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
@@ -16,6 +16,10 @@ export declare class BotFactory {
16
16
  private readonly aztecNodeAdmin?;
17
17
  private readonly syncChainTip?;
18
18
  private log;
19
+ /** Number of in-flight withNoMinTxsPerBlock calls; see that method for why they are counted. */
20
+ private noMinTxsPerBlockDepth;
21
+ /** Set by the first withNoMinTxsPerBlock entrant; resolves to the minTxsPerBlock value to restore. */
22
+ private savedMinTxsPerBlock?;
19
23
  constructor(config: BotConfig, wallet: EmbeddedWallet, store: BotStore, aztecNode: AztecNode, aztecNodeAdmin?: AztecNodeAdmin | undefined, syncChainTip?: "checkpointed" | "finalized" | "latest" | "proposed" | "proven" | undefined);
20
24
  /**
21
25
  * Initializes a new bot by setting up the sender account, registering the recipient,
@@ -48,14 +52,16 @@ export declare class BotFactory {
48
52
  l1Client: ExtendedViemWalletClient;
49
53
  rollupVersion: bigint;
50
54
  }>;
51
- private setupTestContract;
55
+ private deployTestContract;
52
56
  private setupAccount;
53
57
  private setupTestAccount;
54
58
  private setupAccountWithPrivateKey;
55
59
  private setupToken;
56
60
  private setupTokenContract;
57
- private setupAmmContract;
58
- private fundAmm;
61
+ private deployAmmContract;
62
+ private grantLpTokenMinter;
63
+ private mintAmmLiquidity;
64
+ private addAmmLiquidity;
59
65
  private registerOrDeployContract;
60
66
  /** True when the config allows bridging fee juice from L1 (fee_juice mode, an L1 RPC, and an L1 key). */
61
67
  private isL1BridgingConfigured;
@@ -63,6 +69,6 @@ export declare class BotFactory {
63
69
  private mintTokens;
64
70
  private getOrCreateBridgeClaim;
65
71
  private bridgeL1FeeJuice;
66
- private withNoMinTxsPerBlock;
72
+ protected withNoMinTxsPerBlock<T>(fn: () => Promise<T>): Promise<T>;
67
73
  }
68
- //# sourceMappingURL=data:application/json;base64,eyJ2ZX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CAAC;QACnC,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC,CAoED;YAEa,kBAAkB;YASlB,YAAY;YAkBZ,gBAAgB;YAUhB,0BAA0B;YAe1B,UAAU;YAyCV,kBAAkB;YAalB,iBAAiB;YASjB,kBAAkB;YAQlB,gBAAgB;YAahB,eAAe;YAsEf,wBAAwB;IA2BtC,yGAAyG;IACzG,OAAO,CAAC,sBAAsB;YAchB,qBAAqB;YAgCrB,UAAU;YAiDV,sBAAsB;YAwBtB,gBAAgB;IAgC9B,UAAgB,oBAAoB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CA+BxE;CACF"}
package/dest/factory.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { getInitialTestAccountsData } from '@aztec/accounts/testing';
2
+ import { deriveSecretKeyFromSigningKey } from '@aztec/accounts/utils';
2
3
  import { BatchCall, NO_WAIT } from '@aztec/aztec.js/contracts';
3
4
  import { L1FeeJuicePortalManager } from '@aztec/aztec.js/ethereum';
4
5
  import { FeeJuicePaymentMethodWithClaim } from '@aztec/aztec.js/fee';
@@ -11,12 +12,12 @@ import { createEthereumChain } from '@aztec/ethereum/chain';
11
12
  import { createExtendedL1Client } from '@aztec/ethereum/client';
12
13
  import { RollupContract } from '@aztec/ethereum/contracts';
13
14
  import { Fr } from '@aztec/foundation/curves/bn254';
15
+ import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
14
16
  import { EthAddress } from '@aztec/foundation/eth-address';
15
17
  import { AMMContract } from '@aztec/noir-contracts.js/AMM';
16
18
  import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
17
19
  import { TokenContract } from '@aztec/noir-contracts.js/Token';
18
20
  import { TestContract } from '@aztec/noir-test-contracts.js/Test';
19
- import { deriveSigningKey } from '@aztec/stdlib/keys';
20
21
  import { SupportedTokenContracts } from './config.js';
21
22
  import { seedL1ToL2Message } from './l1_to_l2_seeding.js';
22
23
  import { getBalances, getPrivateBalance, isStandardTokenContract } from './utils.js';
@@ -31,6 +32,8 @@ export class BotFactory {
31
32
  aztecNodeAdmin;
32
33
  syncChainTip;
33
34
  log;
35
+ /** Number of in-flight withNoMinTxsPerBlock calls; see that method for why they are counted. */ noMinTxsPerBlockDepth;
36
+ /** Set by the first withNoMinTxsPerBlock entrant; resolves to the minTxsPerBlock value to restore. */ savedMinTxsPerBlock;
34
37
  constructor(config, wallet, store, aztecNode, aztecNodeAdmin, syncChainTip){
35
38
  this.config = config;
36
39
  this.wallet = wallet;
@@ -39,6 +42,7 @@ export class BotFactory {
39
42
  this.aztecNodeAdmin = aztecNodeAdmin;
40
43
  this.syncChainTip = syncChainTip;
41
44
  this.log = createLogger('bot');
45
+ this.noMinTxsPerBlockDepth = 0;
42
46
  // Set fee padding on the wallet so that all transactions during setup
43
47
  // (token deploy, minting, etc.) use the configured padding, not the default.
44
48
  this.wallet.setMinFeePadding(config.minFeePadding);
@@ -48,7 +52,7 @@ export class BotFactory {
48
52
  * deploying the token contract, and minting tokens if necessary.
49
53
  */ async setup() {
50
54
  const defaultAccountAddress = await this.setupAccount();
51
- const recipient = (await this.wallet.createSchnorrAccount(Fr.random(), Fr.random())).address;
55
+ const recipient = (await this.wallet.createSchnorrAccount(Fr.random(), Fr.random(), GrumpkinScalar.random())).address;
52
56
  await this.ensureFeeJuiceBalance(defaultAccountAddress);
53
57
  const token = await this.setupToken(defaultAccountAddress);
54
58
  await this.mintTokens(token, defaultAccountAddress);
@@ -63,11 +67,30 @@ export class BotFactory {
63
67
  async setupAmm() {
64
68
  const defaultAccountAddress = await this.setupAccount();
65
69
  await this.ensureFeeJuiceBalance(defaultAccountAddress);
66
- const token0 = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotToken0', 'BOT0');
67
- const token1 = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotToken1', 'BOT1');
68
- const liquidityToken = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotLPToken', 'BOTLP');
69
- const amm = await this.setupAmmContract(defaultAccountAddress, this.config.tokenSalt, token0, token1, liquidityToken);
70
- await this.fundAmm(defaultAccountAddress, defaultAccountAddress, amm, token0, token1, liquidityToken);
70
+ const salt = this.config.tokenSalt;
71
+ // token0, token1 and the LP token are independent contracts with no shared state, so deploy them
72
+ // concurrently rather than one slot at a time.
73
+ const [token0, token1, liquidityToken] = await Promise.all([
74
+ this.setupTokenContract(defaultAccountAddress, salt, 'BotToken0', 'BOT0'),
75
+ this.setupTokenContract(defaultAccountAddress, salt, 'BotToken1', 'BOT1'),
76
+ this.setupTokenContract(defaultAccountAddress, salt, 'BotLPToken', 'BOTLP')
77
+ ]);
78
+ const ammDeploy = AMMContract.deploy(this.wallet, token0.address, token1.address, liquidityToken.address, {
79
+ salt,
80
+ universalDeploy: true
81
+ });
82
+ const ammAddress = (await ammDeploy.getInstance()).address;
83
+ // The AMM constructor only stores the (already-derived) token addresses, and set_minter only records
84
+ // the AMM address on the LP token: neither reads the other's on-chain state, so the AMM deploy, the
85
+ // LP-minter grant, and the token0/token1 mints are mutually independent and run concurrently.
86
+ const [amm] = await Promise.all([
87
+ this.deployAmmContract(defaultAccountAddress, ammDeploy),
88
+ this.grantLpTokenMinter(defaultAccountAddress, liquidityToken, ammAddress),
89
+ this.mintAmmLiquidity(defaultAccountAddress, token0, token1)
90
+ ]);
91
+ // add_liquidity spends the minted token0/token1 balances and mints LP tokens, so it must follow both
92
+ // the mints and the minter grant, and target the deployed AMM.
93
+ await this.addAmmLiquidity(defaultAccountAddress, defaultAccountAddress, amm, token0, token1, liquidityToken);
71
94
  this.log.info(`AMM initialized and funded`);
72
95
  return {
73
96
  wallet: this.wallet,
@@ -99,16 +122,30 @@ export class BotFactory {
99
122
  // Fetch Rollup version (needed for Inbox L2Actor struct)
100
123
  const rollupContract = new RollupContract(l1Client, l1ContractAddresses.rollupAddress.toString());
101
124
  const rollupVersion = await rollupContract.getVersion();
102
- // Deploy TestContract (pays from the standing balance funded above).
103
- const contract = await this.setupTestContract(defaultAccountAddress);
125
+ // Derive the TestContract address up front (deterministic from the salt). Seeding L1→L2 messages only
126
+ // needs the L2 recipient address — the messages are queued on L1 and don't require the L2 contract to
127
+ // exist yet (they're consumed later, after setup completes) — so the deploy (an L2 tx paying from the
128
+ // standing balance funded above) and the L1 seeding run concurrently.
129
+ const testContractDeploy = TestContract.deploy(this.wallet, {
130
+ salt: this.config.tokenSalt,
131
+ universalDeploy: true
132
+ });
133
+ const contractAddress = (await testContractDeploy.getInstance()).address;
104
134
  // Recover any pending messages from store (clean up stale ones first)
105
135
  await this.store.cleanupOldPendingMessages();
106
136
  const pendingMessages = await this.store.getUnconsumedL1ToL2Messages();
107
- // Seed initial L1→L2 messages if pipeline is empty
137
+ // Seed initial L1→L2 messages if pipeline is empty. The seeds are sent one at a time: they share the
138
+ // bot's L1 account, so concurrent sends would race on the L1 nonce.
108
139
  const seedCount = Math.max(0, this.config.l1ToL2SeedCount - pendingMessages.length);
109
- for(let i = 0; i < seedCount; i++){
110
- await seedL1ToL2Message(l1Client, EthAddress.fromString(l1ContractAddresses.inboxAddress.toString()), contract.address, rollupVersion, this.store, this.log);
111
- }
140
+ const inboxAddress = EthAddress.fromString(l1ContractAddresses.inboxAddress.toString());
141
+ const [contract] = await Promise.all([
142
+ this.deployTestContract(defaultAccountAddress, testContractDeploy),
143
+ (async ()=>{
144
+ for(let i = 0; i < seedCount; i++){
145
+ await seedL1ToL2Message(l1Client, inboxAddress, contractAddress, rollupVersion, this.store, this.log);
146
+ }
147
+ })()
148
+ ]);
112
149
  // Block until at least one message is ready
113
150
  const allMessages = await this.store.getUnconsumedL1ToL2Messages();
114
151
  if (allMessages.length > 0) {
@@ -129,15 +166,10 @@ export class BotFactory {
129
166
  rollupVersion
130
167
  };
131
168
  }
132
- async setupTestContract(deployer) {
133
- const deployOpts = {
169
+ async deployTestContract(deployer, deploy) {
170
+ const instance = await this.registerOrDeployContract('TestContract', deploy, {
134
171
  from: deployer
135
- };
136
- const deploy = TestContract.deploy(this.wallet, {
137
- salt: this.config.tokenSalt,
138
- universalDeploy: true
139
172
  });
140
- const instance = await this.registerOrDeployContract('TestContract', deploy, deployOpts);
141
173
  return TestContract.at(instance.address, this.wallet);
142
174
  }
143
175
  /**
@@ -164,9 +196,10 @@ export class BotFactory {
164
196
  const accountManager = await this.wallet.createSchnorrInitializerlessAccount(initialAccountData.secret, initialAccountData.salt, initialAccountData.signingKey);
165
197
  return accountManager.address;
166
198
  }
167
- async setupAccountWithPrivateKey(secret) {
199
+ async setupAccountWithPrivateKey(privateKey) {
168
200
  const salt = this.config.senderSalt ?? Fr.ONE;
169
- const signingKey = deriveSigningKey(secret);
201
+ const signingKey = GrumpkinScalar.fromBuffer(privateKey.toBuffer());
202
+ const secret = await deriveSecretKeyFromSigningKey(signingKey);
170
203
  const accountManager = await this.wallet.createSchnorrInitializerlessAccount(secret, salt, signingKey);
171
204
  return accountManager.address;
172
205
  }
@@ -231,48 +264,45 @@ export class BotFactory {
231
264
  const instance = await this.registerOrDeployContract('Token - ' + name, deploy, deployOpts);
232
265
  return TokenContract.at(instance.address, this.wallet);
233
266
  }
234
- async setupAmmContract(deployer, salt, token0, token1, lpToken) {
235
- const deployOpts = {
267
+ async deployAmmContract(deployer, deploy) {
268
+ const instance = await this.registerOrDeployContract('AMM', deploy, {
236
269
  from: deployer
237
- };
238
- const deploy = AMMContract.deploy(this.wallet, token0.address, token1.address, lpToken.address, {
239
- salt,
240
- universalDeploy: true
241
270
  });
242
- const instance = await this.registerOrDeployContract('AMM', deploy, deployOpts);
243
271
  const amm = AMMContract.at(instance.address, this.wallet);
244
272
  this.log.info(`AMM deployed at ${amm.address}`);
245
- const setMinterInteraction = lpToken.methods.set_minter(amm.address, true);
246
- const { receipt: minterReceipt } = await setMinterInteraction.send({
273
+ return amm;
274
+ }
275
+ /** Grants the AMM minting rights over the LP token. set_minter only records the address, so it does not
276
+ * require the AMM contract to be deployed first. */ async grantLpTokenMinter(deployer, lpToken, amm) {
277
+ const { receipt } = await lpToken.methods.set_minter(amm, true).send({
247
278
  from: deployer,
248
279
  wait: {
249
280
  timeout: this.config.txMinedWaitSeconds
250
281
  }
251
282
  });
252
- this.log.info(`Set LP token minter to AMM txHash=${minterReceipt.txHash.toString()}`);
253
- this.log.info(`Liquidity token initialized`);
254
- return amm;
283
+ this.log.info(`Set LP token minter to AMM txHash=${receipt.txHash.toString()}`);
255
284
  }
256
- async fundAmm(defaultAccountAddress, liquidityProvider, amm, token0, token1, lpToken) {
257
- const getPrivateBalances = ()=>Promise.all([
258
- token0.methods.balance_of_private(liquidityProvider).simulate({
259
- from: liquidityProvider
260
- }).then((r)=>r.result),
261
- token1.methods.balance_of_private(liquidityProvider).simulate({
262
- from: liquidityProvider
263
- }).then((r)=>r.result),
264
- lpToken.methods.balance_of_private(liquidityProvider).simulate({
265
- from: liquidityProvider
266
- }).then((r)=>r.result)
267
- ]);
285
+ async mintAmmLiquidity(minter, token0, token1) {
286
+ this.log.info(`Minting ${MINT_BALANCE} tokens of each BotToken0 and BotToken1 for ${minter}`);
287
+ const mintBatch = new BatchCall(this.wallet, [
288
+ token0.methods.mint_to_private(minter, MINT_BALANCE),
289
+ token1.methods.mint_to_private(minter, MINT_BALANCE)
290
+ ]);
291
+ const { receipt } = await mintBatch.send({
292
+ from: minter,
293
+ wait: {
294
+ timeout: this.config.txMinedWaitSeconds
295
+ }
296
+ });
297
+ this.log.info(`Sent mint tx: ${receipt.txHash.toString()}`);
298
+ }
299
+ async addAmmLiquidity(defaultAccountAddress, liquidityProvider, amm, token0, token1, lpToken) {
268
300
  const authwitNonce = Fr.random();
269
301
  // keep some tokens for swapping
270
302
  const amount0Max = MINT_BALANCE / 2;
271
303
  const amount0Min = MINT_BALANCE / 4;
272
304
  const amount1Max = MINT_BALANCE / 2;
273
305
  const amount1Min = MINT_BALANCE / 4;
274
- const [t0Bal, t1Bal, lpBal] = await getPrivateBalances();
275
- this.log.info(`Minting ${MINT_BALANCE} tokens of each BotToken0 and BotToken1. Current private balances of ${liquidityProvider}: token0=${t0Bal}, token1=${t1Bal}, lp=${lpBal}`);
276
306
  // Add authwitnesses for the transfers in AMM::add_liquidity function
277
307
  const token0Authwit = await this.wallet.createAuthWit(defaultAccountAddress, {
278
308
  caller: amm.address,
@@ -282,19 +312,7 @@ export class BotFactory {
282
312
  caller: amm.address,
283
313
  call: await token1.methods.transfer_to_public_and_prepare_private_balance_increase(liquidityProvider, amm.address, amount1Max, authwitNonce).getFunctionCall()
284
314
  });
285
- const mintBatch = new BatchCall(this.wallet, [
286
- token0.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
287
- token1.methods.mint_to_private(liquidityProvider, MINT_BALANCE)
288
- ]);
289
- const { receipt: mintReceipt } = await mintBatch.send({
290
- from: liquidityProvider,
291
- wait: {
292
- timeout: this.config.txMinedWaitSeconds
293
- }
294
- });
295
- this.log.info(`Sent mint tx: ${mintReceipt.txHash.toString()}`);
296
- const addLiquidityInteraction = amm.methods.add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, authwitNonce);
297
- const { receipt: addLiquidityReceipt } = await addLiquidityInteraction.send({
315
+ const { receipt } = await amm.methods.add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, authwitNonce).send({
298
316
  from: liquidityProvider,
299
317
  authWitnesses: [
300
318
  token0Authwit,
@@ -304,10 +322,20 @@ export class BotFactory {
304
322
  timeout: this.config.txMinedWaitSeconds
305
323
  }
306
324
  });
307
- this.log.info(`Sent tx to add liquidity to the AMM: ${addLiquidityReceipt.txHash.toString()}`);
325
+ this.log.info(`Sent tx to add liquidity to the AMM: ${receipt.txHash.toString()}`);
308
326
  this.log.info(`Liquidity added`);
309
- const [newT0Bal, newT1Bal, newLPBal] = await getPrivateBalances();
310
- this.log.info(`Updated private balances of ${defaultAccountAddress} after minting and funding AMM: token0=${newT0Bal}, token1=${newT1Bal}, lp=${newLPBal}`);
327
+ const [t0Bal, t1Bal, lpBal] = await Promise.all([
328
+ token0.methods.balance_of_private(liquidityProvider).simulate({
329
+ from: liquidityProvider
330
+ }).then((r)=>r.result),
331
+ token1.methods.balance_of_private(liquidityProvider).simulate({
332
+ from: liquidityProvider
333
+ }).then((r)=>r.result),
334
+ lpToken.methods.balance_of_private(liquidityProvider).simulate({
335
+ from: liquidityProvider
336
+ }).then((r)=>r.result)
337
+ ]);
338
+ this.log.info(`Updated private balances of ${defaultAccountAddress} after minting and funding AMM: token0=${t0Bal}, token1=${t1Bal}, lp=${lpBal}`);
311
339
  }
312
340
  async registerOrDeployContract(name, deploy, deployOpts) {
313
341
  const instance = await deploy.getInstance();
@@ -468,18 +496,37 @@ export class BotFactory {
468
496
  this.log.verbose(`No node admin client or flushing not requested (not setting minTxsPerBlock to 0)`);
469
497
  return fn();
470
498
  }
471
- const { minTxsPerBlock } = await this.aztecNodeAdmin.getConfig();
472
- this.log.warn(`Setting sequencer minTxsPerBlock to 0 from ${minTxsPerBlock} to flush setup transactions`);
473
- await this.aztecNodeAdmin.setConfig({
474
- minTxsPerBlock: 0
475
- });
499
+ const aztecNodeAdmin = this.aztecNodeAdmin;
500
+ // Setup steps run concurrently, so this wrapper can be re-entered while another call is in flight.
501
+ // Reference-count the entrants: the first saves the current value and zeroes it, the last restores it.
502
+ // A naive save/zero/restore per call could interleave, with a late entrant reading the already-zeroed
503
+ // value and "restoring" 0 at the end.
504
+ if (this.noMinTxsPerBlockDepth++ === 0) {
505
+ this.savedMinTxsPerBlock = (async ()=>{
506
+ const { minTxsPerBlock } = await aztecNodeAdmin.getConfig();
507
+ this.log.warn(`Setting sequencer minTxsPerBlock to 0 from ${minTxsPerBlock} to flush setup transactions`);
508
+ await aztecNodeAdmin.setConfig({
509
+ minTxsPerBlock: 0
510
+ });
511
+ return {
512
+ minTxsPerBlock
513
+ };
514
+ })();
515
+ }
476
516
  try {
517
+ await this.savedMinTxsPerBlock;
477
518
  return await fn();
478
519
  } finally{
479
- this.log.warn(`Restoring sequencer minTxsPerBlock to ${minTxsPerBlock}`);
480
- await this.aztecNodeAdmin.setConfig({
481
- minTxsPerBlock
482
- });
520
+ if (--this.noMinTxsPerBlockDepth === 0) {
521
+ // If saving/zeroing itself failed there is nothing to restore.
522
+ const saved = await this.savedMinTxsPerBlock.catch(()=>undefined);
523
+ if (saved) {
524
+ this.log.warn(`Restoring sequencer minTxsPerBlock to ${saved.minTxsPerBlock}`);
525
+ await aztecNodeAdmin.setConfig({
526
+ minTxsPerBlock: saved.minTxsPerBlock
527
+ });
528
+ }
529
+ }
483
530
  }
484
531
  }
485
532
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/bot",
3
- "version": "6.0.0-nightly.20260723",
3
+ "version": "6.0.0-nightly.20260725",
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": "6.0.0-nightly.20260723",
58
- "@aztec/aztec.js": "6.0.0-nightly.20260723",
59
- "@aztec/entrypoints": "6.0.0-nightly.20260723",
60
- "@aztec/ethereum": "6.0.0-nightly.20260723",
61
- "@aztec/foundation": "6.0.0-nightly.20260723",
62
- "@aztec/kv-store": "6.0.0-nightly.20260723",
63
- "@aztec/l1-artifacts": "6.0.0-nightly.20260723",
64
- "@aztec/noir-contracts.js": "6.0.0-nightly.20260723",
65
- "@aztec/noir-protocol-circuits-types": "6.0.0-nightly.20260723",
66
- "@aztec/noir-test-contracts.js": "6.0.0-nightly.20260723",
67
- "@aztec/protocol-contracts": "6.0.0-nightly.20260723",
68
- "@aztec/stdlib": "6.0.0-nightly.20260723",
69
- "@aztec/telemetry-client": "6.0.0-nightly.20260723",
70
- "@aztec/wallets": "6.0.0-nightly.20260723",
57
+ "@aztec/accounts": "6.0.0-nightly.20260725",
58
+ "@aztec/aztec.js": "6.0.0-nightly.20260725",
59
+ "@aztec/entrypoints": "6.0.0-nightly.20260725",
60
+ "@aztec/ethereum": "6.0.0-nightly.20260725",
61
+ "@aztec/foundation": "6.0.0-nightly.20260725",
62
+ "@aztec/kv-store": "6.0.0-nightly.20260725",
63
+ "@aztec/l1-artifacts": "6.0.0-nightly.20260725",
64
+ "@aztec/noir-contracts.js": "6.0.0-nightly.20260725",
65
+ "@aztec/noir-protocol-circuits-types": "6.0.0-nightly.20260725",
66
+ "@aztec/noir-test-contracts.js": "6.0.0-nightly.20260725",
67
+ "@aztec/protocol-contracts": "6.0.0-nightly.20260725",
68
+ "@aztec/stdlib": "6.0.0-nightly.20260725",
69
+ "@aztec/telemetry-client": "6.0.0-nightly.20260725",
70
+ "@aztec/wallets": "6.0.0-nightly.20260725",
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,4 +1,5 @@
1
1
  import { getInitialTestAccountsData } from '@aztec/accounts/testing';
2
+ import { deriveSecretKeyFromSigningKey } from '@aztec/accounts/utils';
2
3
  import { AztecAddress } from '@aztec/aztec.js/addresses';
3
4
  import {
4
5
  BatchCall,
@@ -21,6 +22,7 @@ import { createExtendedL1Client } from '@aztec/ethereum/client';
21
22
  import { RollupContract } from '@aztec/ethereum/contracts';
22
23
  import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
23
24
  import { Fr } from '@aztec/foundation/curves/bn254';
25
+ import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
24
26
  import { EthAddress } from '@aztec/foundation/eth-address';
25
27
  import { AMMContract } from '@aztec/noir-contracts.js/AMM';
26
28
  import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
@@ -29,7 +31,6 @@ import { TestContract } from '@aztec/noir-test-contracts.js/Test';
29
31
  import type { BlockTag } from '@aztec/stdlib/block';
30
32
  import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
31
33
  import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
32
- import { deriveSigningKey } from '@aztec/stdlib/keys';
33
34
  import { EmbeddedWallet } from '@aztec/wallets/embedded';
34
35
 
35
36
  import { type BotConfig, SupportedTokenContracts } from './config.js';
@@ -44,6 +45,11 @@ const FEE_JUICE_TOP_UP_THRESHOLD = 100n * 10n ** 18n;
44
45
  export class BotFactory {
45
46
  private log = createLogger('bot');
46
47
 
48
+ /** Number of in-flight withNoMinTxsPerBlock calls; see that method for why they are counted. */
49
+ private noMinTxsPerBlockDepth = 0;
50
+ /** Set by the first withNoMinTxsPerBlock entrant; resolves to the minTxsPerBlock value to restore. */
51
+ private savedMinTxsPerBlock?: Promise<{ minTxsPerBlock?: number }>;
52
+
47
53
  constructor(
48
54
  private readonly config: BotConfig,
49
55
  private readonly wallet: EmbeddedWallet,
@@ -69,7 +75,8 @@ export class BotFactory {
69
75
  recipient: AztecAddress;
70
76
  }> {
71
77
  const defaultAccountAddress = await this.setupAccount();
72
- const recipient = (await this.wallet.createSchnorrAccount(Fr.random(), Fr.random())).address;
78
+ const recipient = (await this.wallet.createSchnorrAccount(Fr.random(), Fr.random(), GrumpkinScalar.random()))
79
+ .address;
73
80
  await this.ensureFeeJuiceBalance(defaultAccountAddress);
74
81
  const token = await this.setupToken(defaultAccountAddress);
75
82
  await this.mintTokens(token, defaultAccountAddress);
@@ -86,23 +93,35 @@ export class BotFactory {
86
93
  }> {
87
94
  const defaultAccountAddress = await this.setupAccount();
88
95
  await this.ensureFeeJuiceBalance(defaultAccountAddress);
89
- const token0 = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotToken0', 'BOT0');
90
- const token1 = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotToken1', 'BOT1');
91
- const liquidityToken = await this.setupTokenContract(
92
- defaultAccountAddress,
93
- this.config.tokenSalt,
94
- 'BotLPToken',
95
- 'BOTLP',
96
- );
97
- const amm = await this.setupAmmContract(
98
- defaultAccountAddress,
99
- this.config.tokenSalt,
100
- token0,
101
- token1,
102
- liquidityToken,
103
- );
104
96
 
105
- await this.fundAmm(defaultAccountAddress, defaultAccountAddress, amm, token0, token1, liquidityToken);
97
+ const salt = this.config.tokenSalt;
98
+
99
+ // token0, token1 and the LP token are independent contracts with no shared state, so deploy them
100
+ // concurrently rather than one slot at a time.
101
+ const [token0, token1, liquidityToken] = await Promise.all([
102
+ this.setupTokenContract(defaultAccountAddress, salt, 'BotToken0', 'BOT0'),
103
+ this.setupTokenContract(defaultAccountAddress, salt, 'BotToken1', 'BOT1'),
104
+ this.setupTokenContract(defaultAccountAddress, salt, 'BotLPToken', 'BOTLP'),
105
+ ]);
106
+
107
+ const ammDeploy = AMMContract.deploy(this.wallet, token0.address, token1.address, liquidityToken.address, {
108
+ salt,
109
+ universalDeploy: true,
110
+ });
111
+ const ammAddress = (await ammDeploy.getInstance()).address;
112
+
113
+ // The AMM constructor only stores the (already-derived) token addresses, and set_minter only records
114
+ // the AMM address on the LP token: neither reads the other's on-chain state, so the AMM deploy, the
115
+ // LP-minter grant, and the token0/token1 mints are mutually independent and run concurrently.
116
+ const [amm] = await Promise.all([
117
+ this.deployAmmContract(defaultAccountAddress, ammDeploy),
118
+ this.grantLpTokenMinter(defaultAccountAddress, liquidityToken, ammAddress),
119
+ this.mintAmmLiquidity(defaultAccountAddress, token0, token1),
120
+ ]);
121
+
122
+ // add_liquidity spends the minted token0/token1 balances and mints LP tokens, so it must follow both
123
+ // the mints and the minter grant, and target the deployed AMM.
124
+ await this.addAmmLiquidity(defaultAccountAddress, defaultAccountAddress, amm, token0, token1, liquidityToken);
106
125
  this.log.info(`AMM initialized and funded`);
107
126
 
108
127
  return { wallet: this.wallet, defaultAccountAddress, amm, token0, token1, node: this.aztecNode };
@@ -140,25 +159,32 @@ export class BotFactory {
140
159
  const rollupContract = new RollupContract(l1Client, l1ContractAddresses.rollupAddress.toString());
141
160
  const rollupVersion = await rollupContract.getVersion();
142
161
 
143
- // Deploy TestContract (pays from the standing balance funded above).
144
- const contract = await this.setupTestContract(defaultAccountAddress);
162
+ // Derive the TestContract address up front (deterministic from the salt). Seeding L1→L2 messages only
163
+ // needs the L2 recipient address — the messages are queued on L1 and don't require the L2 contract to
164
+ // exist yet (they're consumed later, after setup completes) — so the deploy (an L2 tx paying from the
165
+ // standing balance funded above) and the L1 seeding run concurrently.
166
+ const testContractDeploy = TestContract.deploy(this.wallet, {
167
+ salt: this.config.tokenSalt,
168
+ universalDeploy: true,
169
+ });
170
+ const contractAddress = (await testContractDeploy.getInstance()).address;
145
171
 
146
172
  // Recover any pending messages from store (clean up stale ones first)
147
173
  await this.store.cleanupOldPendingMessages();
148
174
  const pendingMessages = await this.store.getUnconsumedL1ToL2Messages();
149
175
 
150
- // Seed initial L1→L2 messages if pipeline is empty
176
+ // Seed initial L1→L2 messages if pipeline is empty. The seeds are sent one at a time: they share the
177
+ // bot's L1 account, so concurrent sends would race on the L1 nonce.
151
178
  const seedCount = Math.max(0, this.config.l1ToL2SeedCount - pendingMessages.length);
152
- for (let i = 0; i < seedCount; i++) {
153
- await seedL1ToL2Message(
154
- l1Client,
155
- EthAddress.fromString(l1ContractAddresses.inboxAddress.toString()),
156
- contract.address,
157
- rollupVersion,
158
- this.store,
159
- this.log,
160
- );
161
- }
179
+ const inboxAddress = EthAddress.fromString(l1ContractAddresses.inboxAddress.toString());
180
+ const [contract] = await Promise.all([
181
+ this.deployTestContract(defaultAccountAddress, testContractDeploy),
182
+ (async () => {
183
+ for (let i = 0; i < seedCount; i++) {
184
+ await seedL1ToL2Message(l1Client, inboxAddress, contractAddress, rollupVersion, this.store, this.log);
185
+ }
186
+ })(),
187
+ ]);
162
188
 
163
189
  // Block until at least one message is ready
164
190
  const allMessages = await this.store.getUnconsumedL1ToL2Messages();
@@ -182,10 +208,8 @@ export class BotFactory {
182
208
  };
183
209
  }
184
210
 
185
- private async setupTestContract(deployer: AztecAddress): Promise<TestContract> {
186
- const deployOpts: DeployOptions = { from: deployer };
187
- const deploy = TestContract.deploy(this.wallet, { salt: this.config.tokenSalt, universalDeploy: true });
188
- const instance = await this.registerOrDeployContract('TestContract', deploy, deployOpts);
211
+ private async deployTestContract(deployer: AztecAddress, deploy: DeployMethod<TestContract>): Promise<TestContract> {
212
+ const instance = await this.registerOrDeployContract('TestContract', deploy, { from: deployer });
189
213
  return TestContract.at(instance.address, this.wallet);
190
214
  }
191
215
 
@@ -221,9 +245,10 @@ export class BotFactory {
221
245
  return accountManager.address;
222
246
  }
223
247
 
224
- private async setupAccountWithPrivateKey(secret: Fr) {
248
+ private async setupAccountWithPrivateKey(privateKey: Fr) {
225
249
  const salt = this.config.senderSalt ?? Fr.ONE;
226
- const signingKey = deriveSigningKey(secret);
250
+ const signingKey = GrumpkinScalar.fromBuffer(privateKey.toBuffer());
251
+ const secret = await deriveSecretKeyFromSigningKey(signingKey);
227
252
  const accountManager = await this.wallet.createSchnorrInitializerlessAccount(secret, salt, signingKey);
228
253
  return accountManager.address;
229
254
  }
@@ -289,34 +314,37 @@ export class BotFactory {
289
314
  return TokenContract.at(instance.address, this.wallet);
290
315
  }
291
316
 
292
- private async setupAmmContract(
293
- deployer: AztecAddress,
294
- salt: Fr,
295
- token0: TokenContract,
296
- token1: TokenContract,
297
- lpToken: TokenContract,
298
- ): Promise<AMMContract> {
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
- });
304
- const instance = await this.registerOrDeployContract('AMM', deploy, deployOpts);
317
+ private async deployAmmContract(deployer: AztecAddress, deploy: DeployMethod<AMMContract>): Promise<AMMContract> {
318
+ const instance = await this.registerOrDeployContract('AMM', deploy, { from: deployer });
305
319
  const amm = AMMContract.at(instance.address, this.wallet);
306
-
307
320
  this.log.info(`AMM deployed at ${amm.address}`);
308
- const setMinterInteraction = lpToken.methods.set_minter(amm.address, true);
309
- const { receipt: minterReceipt } = await setMinterInteraction.send({
321
+ return amm;
322
+ }
323
+
324
+ /** Grants the AMM minting rights over the LP token. set_minter only records the address, so it does not
325
+ * require the AMM contract to be deployed first. */
326
+ private async grantLpTokenMinter(deployer: AztecAddress, lpToken: TokenContract, amm: AztecAddress): Promise<void> {
327
+ const { receipt } = await lpToken.methods.set_minter(amm, true).send({
310
328
  from: deployer,
311
329
  wait: { timeout: this.config.txMinedWaitSeconds },
312
330
  });
313
- this.log.info(`Set LP token minter to AMM txHash=${minterReceipt.txHash.toString()}`);
314
- this.log.info(`Liquidity token initialized`);
331
+ this.log.info(`Set LP token minter to AMM txHash=${receipt.txHash.toString()}`);
332
+ }
315
333
 
316
- return amm;
334
+ private async mintAmmLiquidity(minter: AztecAddress, token0: TokenContract, token1: TokenContract): Promise<void> {
335
+ this.log.info(`Minting ${MINT_BALANCE} tokens of each BotToken0 and BotToken1 for ${minter}`);
336
+ const mintBatch = new BatchCall(this.wallet, [
337
+ token0.methods.mint_to_private(minter, MINT_BALANCE),
338
+ token1.methods.mint_to_private(minter, MINT_BALANCE),
339
+ ]);
340
+ const { receipt } = await mintBatch.send({
341
+ from: minter,
342
+ wait: { timeout: this.config.txMinedWaitSeconds },
343
+ });
344
+ this.log.info(`Sent mint tx: ${receipt.txHash.toString()}`);
317
345
  }
318
346
 
319
- private async fundAmm(
347
+ private async addAmmLiquidity(
320
348
  defaultAccountAddress: AztecAddress,
321
349
  liquidityProvider: AztecAddress,
322
350
  amm: AMMContract,
@@ -324,22 +352,6 @@ export class BotFactory {
324
352
  token1: TokenContract,
325
353
  lpToken: TokenContract,
326
354
  ): Promise<void> {
327
- const getPrivateBalances = () =>
328
- Promise.all([
329
- token0.methods
330
- .balance_of_private(liquidityProvider)
331
- .simulate({ from: liquidityProvider })
332
- .then(r => r.result),
333
- token1.methods
334
- .balance_of_private(liquidityProvider)
335
- .simulate({ from: liquidityProvider })
336
- .then(r => r.result),
337
- lpToken.methods
338
- .balance_of_private(liquidityProvider)
339
- .simulate({ from: liquidityProvider })
340
- .then(r => r.result),
341
- ]);
342
-
343
355
  const authwitNonce = Fr.random();
344
356
 
345
357
  // keep some tokens for swapping
@@ -348,12 +360,6 @@ export class BotFactory {
348
360
  const amount1Max = MINT_BALANCE / 2;
349
361
  const amount1Min = MINT_BALANCE / 4;
350
362
 
351
- const [t0Bal, t1Bal, lpBal] = await getPrivateBalances();
352
-
353
- this.log.info(
354
- `Minting ${MINT_BALANCE} tokens of each BotToken0 and BotToken1. Current private balances of ${liquidityProvider}: token0=${t0Bal}, token1=${t1Bal}, lp=${lpBal}`,
355
- );
356
-
357
363
  // Add authwitnesses for the transfers in AMM::add_liquidity function
358
364
  const token0Authwit = await this.wallet.createAuthWit(defaultAccountAddress, {
359
365
  caller: amm.address,
@@ -378,36 +384,33 @@ export class BotFactory {
378
384
  .getFunctionCall(),
379
385
  });
380
386
 
381
- const mintBatch = new BatchCall(this.wallet, [
382
- token0.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
383
- token1.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
384
- ]);
385
- const { receipt: mintReceipt } = await mintBatch.send({
386
- from: liquidityProvider,
387
- wait: { timeout: this.config.txMinedWaitSeconds },
388
- });
389
-
390
- this.log.info(`Sent mint tx: ${mintReceipt.txHash.toString()}`);
391
-
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
- });
387
+ const { receipt } = await amm.methods
388
+ .add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, authwitNonce)
389
+ .send({
390
+ from: liquidityProvider,
391
+ authWitnesses: [token0Authwit, token1Authwit],
392
+ wait: { timeout: this.config.txMinedWaitSeconds },
393
+ });
404
394
 
405
- this.log.info(`Sent tx to add liquidity to the AMM: ${addLiquidityReceipt.txHash.toString()}`);
395
+ this.log.info(`Sent tx to add liquidity to the AMM: ${receipt.txHash.toString()}`);
406
396
  this.log.info(`Liquidity added`);
407
397
 
408
- const [newT0Bal, newT1Bal, newLPBal] = await getPrivateBalances();
398
+ const [t0Bal, t1Bal, lpBal] = await Promise.all([
399
+ token0.methods
400
+ .balance_of_private(liquidityProvider)
401
+ .simulate({ from: liquidityProvider })
402
+ .then(r => r.result),
403
+ token1.methods
404
+ .balance_of_private(liquidityProvider)
405
+ .simulate({ from: liquidityProvider })
406
+ .then(r => r.result),
407
+ lpToken.methods
408
+ .balance_of_private(liquidityProvider)
409
+ .simulate({ from: liquidityProvider })
410
+ .then(r => r.result),
411
+ ]);
409
412
  this.log.info(
410
- `Updated private balances of ${defaultAccountAddress} after minting and funding AMM: token0=${newT0Bal}, token1=${newT1Bal}, lp=${newLPBal}`,
413
+ `Updated private balances of ${defaultAccountAddress} after minting and funding AMM: token0=${t0Bal}, token1=${t1Bal}, lp=${lpBal}`,
411
414
  );
412
415
  }
413
416
 
@@ -590,19 +593,36 @@ export class BotFactory {
590
593
  return claim as L2AmountClaim;
591
594
  }
592
595
 
593
- private async withNoMinTxsPerBlock<T>(fn: () => Promise<T>): Promise<T> {
596
+ protected async withNoMinTxsPerBlock<T>(fn: () => Promise<T>): Promise<T> {
594
597
  if (!this.aztecNodeAdmin || !this.config.flushSetupTransactions) {
595
598
  this.log.verbose(`No node admin client or flushing not requested (not setting minTxsPerBlock to 0)`);
596
599
  return fn();
597
600
  }
598
- const { minTxsPerBlock } = await this.aztecNodeAdmin.getConfig();
599
- this.log.warn(`Setting sequencer minTxsPerBlock to 0 from ${minTxsPerBlock} to flush setup transactions`);
600
- await this.aztecNodeAdmin.setConfig({ minTxsPerBlock: 0 });
601
+ const aztecNodeAdmin = this.aztecNodeAdmin;
602
+ // Setup steps run concurrently, so this wrapper can be re-entered while another call is in flight.
603
+ // Reference-count the entrants: the first saves the current value and zeroes it, the last restores it.
604
+ // A naive save/zero/restore per call could interleave, with a late entrant reading the already-zeroed
605
+ // value and "restoring" 0 at the end.
606
+ if (this.noMinTxsPerBlockDepth++ === 0) {
607
+ this.savedMinTxsPerBlock = (async () => {
608
+ const { minTxsPerBlock } = await aztecNodeAdmin.getConfig();
609
+ this.log.warn(`Setting sequencer minTxsPerBlock to 0 from ${minTxsPerBlock} to flush setup transactions`);
610
+ await aztecNodeAdmin.setConfig({ minTxsPerBlock: 0 });
611
+ return { minTxsPerBlock };
612
+ })();
613
+ }
601
614
  try {
615
+ await this.savedMinTxsPerBlock;
602
616
  return await fn();
603
617
  } finally {
604
- this.log.warn(`Restoring sequencer minTxsPerBlock to ${minTxsPerBlock}`);
605
- await this.aztecNodeAdmin.setConfig({ minTxsPerBlock });
618
+ if (--this.noMinTxsPerBlockDepth === 0) {
619
+ // If saving/zeroing itself failed there is nothing to restore.
620
+ const saved = await this.savedMinTxsPerBlock!.catch(() => undefined);
621
+ if (saved) {
622
+ this.log.warn(`Restoring sequencer minTxsPerBlock to ${saved.minTxsPerBlock}`);
623
+ await aztecNodeAdmin.setConfig({ minTxsPerBlock: saved.minTxsPerBlock });
624
+ }
625
+ }
606
626
  }
607
627
  }
608
628
  }