@aztec/bot 0.0.1-commit.3469e52 → 0.0.1-commit.35158ae7e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dest/amm_bot.d.ts +6 -7
  2. package/dest/amm_bot.d.ts.map +1 -1
  3. package/dest/amm_bot.js +27 -16
  4. package/dest/base_bot.d.ts +6 -6
  5. package/dest/base_bot.d.ts.map +1 -1
  6. package/dest/base_bot.js +12 -13
  7. package/dest/bot.d.ts +6 -6
  8. package/dest/bot.d.ts.map +1 -1
  9. package/dest/bot.js +8 -4
  10. package/dest/config.d.ts +32 -16
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +37 -10
  13. package/dest/cross_chain_bot.d.ts +54 -0
  14. package/dest/cross_chain_bot.d.ts.map +1 -0
  15. package/dest/cross_chain_bot.js +134 -0
  16. package/dest/factory.d.ts +20 -10
  17. package/dest/factory.d.ts.map +1 -1
  18. package/dest/factory.js +245 -73
  19. package/dest/index.d.ts +2 -1
  20. package/dest/index.d.ts.map +1 -1
  21. package/dest/index.js +1 -0
  22. package/dest/l1_to_l2_seeding.d.ts +8 -0
  23. package/dest/l1_to_l2_seeding.d.ts.map +1 -0
  24. package/dest/l1_to_l2_seeding.js +63 -0
  25. package/dest/runner.d.ts +3 -3
  26. package/dest/runner.d.ts.map +1 -1
  27. package/dest/runner.js +17 -1
  28. package/dest/store/bot_store.d.ts +30 -5
  29. package/dest/store/bot_store.d.ts.map +1 -1
  30. package/dest/store/bot_store.js +37 -6
  31. package/dest/store/index.d.ts +2 -2
  32. package/dest/store/index.d.ts.map +1 -1
  33. package/dest/utils.js +3 -3
  34. package/package.json +16 -13
  35. package/src/amm_bot.ts +26 -21
  36. package/src/base_bot.ts +11 -25
  37. package/src/bot.ts +10 -8
  38. package/src/config.ts +40 -12
  39. package/src/cross_chain_bot.ts +203 -0
  40. package/src/factory.ts +232 -67
  41. package/src/index.ts +1 -0
  42. package/src/l1_to_l2_seeding.ts +79 -0
  43. package/src/runner.ts +18 -5
  44. package/src/store/bot_store.ts +60 -5
  45. package/src/store/index.ts +1 -1
  46. package/src/utils.ts +3 -3
package/src/factory.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
2
1
  import { getInitialTestAccountsData } from '@aztec/accounts/testing';
2
+ import { NO_FROM } from '@aztec/aztec.js/account';
3
3
  import { AztecAddress } from '@aztec/aztec.js/addresses';
4
4
  import {
5
5
  BatchCall,
@@ -7,27 +7,35 @@ import {
7
7
  ContractFunctionInteraction,
8
8
  type DeployMethod,
9
9
  type DeployOptions,
10
+ NO_WAIT,
10
11
  } from '@aztec/aztec.js/contracts';
11
- import { L1FeeJuicePortalManager } from '@aztec/aztec.js/ethereum';
12
12
  import type { L2AmountClaim } from '@aztec/aztec.js/ethereum';
13
+ import { L1FeeJuicePortalManager } from '@aztec/aztec.js/ethereum';
13
14
  import { FeeJuicePaymentMethodWithClaim } from '@aztec/aztec.js/fee';
14
15
  import { deriveKeys } from '@aztec/aztec.js/keys';
15
16
  import { createLogger } from '@aztec/aztec.js/log';
16
17
  import { waitForL1ToL2MessageReady } from '@aztec/aztec.js/messaging';
18
+ import { waitForTx } from '@aztec/aztec.js/node';
19
+ import { ContractInitializationStatus } from '@aztec/aztec.js/wallet';
17
20
  import { createEthereumChain } from '@aztec/ethereum/chain';
18
21
  import { createExtendedL1Client } from '@aztec/ethereum/client';
22
+ import { RollupContract } from '@aztec/ethereum/contracts';
23
+ import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
19
24
  import { Fr } from '@aztec/foundation/curves/bn254';
25
+ import { EthAddress } from '@aztec/foundation/eth-address';
20
26
  import { Timer } from '@aztec/foundation/timer';
21
27
  import { AMMContract } from '@aztec/noir-contracts.js/AMM';
22
28
  import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
23
29
  import { TokenContract } from '@aztec/noir-contracts.js/Token';
30
+ import { TestContract } from '@aztec/noir-test-contracts.js/Test';
24
31
  import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
25
- import { GasSettings } from '@aztec/stdlib/gas';
32
+ import { GasFees, GasSettings } from '@aztec/stdlib/gas';
26
33
  import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
27
34
  import { deriveSigningKey } from '@aztec/stdlib/keys';
28
- import { TestWallet } from '@aztec/test-wallet/server';
35
+ import { EmbeddedWallet } from '@aztec/wallets/embedded';
29
36
 
30
37
  import { type BotConfig, SupportedTokenContracts } from './config.js';
38
+ import { seedL1ToL2Message } from './l1_to_l2_seeding.js';
31
39
  import type { BotStore } from './store/index.js';
32
40
  import { getBalances, getPrivateBalance, isStandardTokenContract } from './utils.js';
33
41
 
@@ -39,32 +47,36 @@ export class BotFactory {
39
47
 
40
48
  constructor(
41
49
  private readonly config: BotConfig,
42
- private readonly wallet: TestWallet,
50
+ private readonly wallet: EmbeddedWallet,
43
51
  private readonly store: BotStore,
44
52
  private readonly aztecNode: AztecNode,
45
53
  private readonly aztecNodeAdmin?: AztecNodeAdmin,
46
- ) {}
54
+ ) {
55
+ // Set fee padding on the wallet so that all transactions during setup
56
+ // (token deploy, minting, etc.) use the configured padding, not the default.
57
+ this.wallet.setMinFeePadding(config.minFeePadding);
58
+ }
47
59
 
48
60
  /**
49
61
  * Initializes a new bot by setting up the sender account, registering the recipient,
50
62
  * deploying the token contract, and minting tokens if necessary.
51
63
  */
52
64
  public async setup(): Promise<{
53
- wallet: TestWallet;
65
+ wallet: EmbeddedWallet;
54
66
  defaultAccountAddress: AztecAddress;
55
67
  token: TokenContract | PrivateTokenContract;
56
68
  node: AztecNode;
57
69
  recipient: AztecAddress;
58
70
  }> {
59
71
  const defaultAccountAddress = await this.setupAccount();
60
- const recipient = (await this.wallet.createAccount()).address;
72
+ const recipient = (await this.wallet.createSchnorrAccount(Fr.random(), Fr.random())).address;
61
73
  const token = await this.setupToken(defaultAccountAddress);
62
74
  await this.mintTokens(token, defaultAccountAddress);
63
75
  return { wallet: this.wallet, defaultAccountAddress, token, node: this.aztecNode, recipient };
64
76
  }
65
77
 
66
78
  public async setupAmm(): Promise<{
67
- wallet: TestWallet;
79
+ wallet: EmbeddedWallet;
68
80
  defaultAccountAddress: AztecAddress;
69
81
  amm: AMMContract;
70
82
  token0: TokenContract;
@@ -94,6 +106,89 @@ export class BotFactory {
94
106
  return { wallet: this.wallet, defaultAccountAddress, amm, token0, token1, node: this.aztecNode };
95
107
  }
96
108
 
109
+ /**
110
+ * Initializes the cross-chain bot by deploying TestContract, creating an L1 client,
111
+ * seeding initial L1→L2 messages, and waiting for the first to be ready.
112
+ */
113
+ public async setupCrossChain(): Promise<{
114
+ wallet: EmbeddedWallet;
115
+ defaultAccountAddress: AztecAddress;
116
+ contract: TestContract;
117
+ node: AztecNode;
118
+ l1Client: ExtendedViemWalletClient;
119
+ rollupVersion: bigint;
120
+ }> {
121
+ const defaultAccountAddress = await this.setupAccount();
122
+
123
+ // Create L1 client (same pattern as bridgeL1FeeJuice)
124
+ const l1RpcUrls = this.config.l1RpcUrls;
125
+ if (!l1RpcUrls?.length) {
126
+ throw new Error('L1 RPC URLs required for cross-chain bot');
127
+ }
128
+ const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
129
+ if (!mnemonicOrPrivateKey) {
130
+ throw new Error('L1 mnemonic or private key required for cross-chain bot');
131
+ }
132
+ const { l1ChainId, l1ContractAddresses } = await this.aztecNode.getNodeInfo();
133
+ const chain = createEthereumChain(l1RpcUrls, l1ChainId);
134
+ const l1Client = createExtendedL1Client(chain.rpcUrls, mnemonicOrPrivateKey, chain.chainInfo);
135
+
136
+ // Fetch Rollup version (needed for Inbox L2Actor struct)
137
+ const rollupContract = new RollupContract(l1Client, l1ContractAddresses.rollupAddress.toString());
138
+ const rollupVersion = await rollupContract.getVersion();
139
+
140
+ // Deploy TestContract
141
+ const contract = await this.setupTestContract(defaultAccountAddress);
142
+
143
+ // Recover any pending messages from store (clean up stale ones first)
144
+ await this.store.cleanupOldPendingMessages();
145
+ const pendingMessages = await this.store.getUnconsumedL1ToL2Messages();
146
+
147
+ // Seed initial L1→L2 messages if pipeline is empty
148
+ const seedCount = Math.max(0, this.config.l1ToL2SeedCount - pendingMessages.length);
149
+ for (let i = 0; i < seedCount; i++) {
150
+ await seedL1ToL2Message(
151
+ l1Client,
152
+ EthAddress.fromString(l1ContractAddresses.inboxAddress.toString()),
153
+ contract.address,
154
+ rollupVersion,
155
+ this.store,
156
+ this.log,
157
+ );
158
+ }
159
+
160
+ // Block until at least one message is ready
161
+ const allMessages = await this.store.getUnconsumedL1ToL2Messages();
162
+ if (allMessages.length > 0) {
163
+ this.log.info(`Waiting for first L1→L2 message to be ready...`);
164
+ const firstMsg = allMessages[0];
165
+ await waitForL1ToL2MessageReady(this.aztecNode, Fr.fromHexString(firstMsg.msgHash), {
166
+ timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds,
167
+ });
168
+ this.log.info(`First L1→L2 message is ready`);
169
+ }
170
+
171
+ return {
172
+ wallet: this.wallet,
173
+ defaultAccountAddress,
174
+ contract,
175
+ node: this.aztecNode,
176
+ l1Client,
177
+ rollupVersion,
178
+ };
179
+ }
180
+
181
+ private async setupTestContract(deployer: AztecAddress): Promise<TestContract> {
182
+ const deployOpts: DeployOptions = {
183
+ from: deployer,
184
+ contractAddressSalt: this.config.tokenSalt,
185
+ universalDeploy: true,
186
+ };
187
+ const deploy = TestContract.deploy(this.wallet);
188
+ const instance = await this.registerOrDeployContract('TestContract', deploy, deployOpts);
189
+ return TestContract.at(instance.address, this.wallet);
190
+ }
191
+
97
192
  /**
98
193
  * Checks if the sender account contract is initialized, and initializes it if necessary.
99
194
  * @returns The sender wallet.
@@ -112,14 +207,9 @@ export class BotFactory {
112
207
  private async setupAccountWithPrivateKey(secret: Fr) {
113
208
  const salt = this.config.senderSalt ?? Fr.ONE;
114
209
  const signingKey = deriveSigningKey(secret);
115
- const accountData = {
116
- secret,
117
- salt,
118
- contract: new SchnorrAccountContract(signingKey!),
119
- };
120
- const accountManager = await this.wallet.createAccount(accountData);
210
+ const accountManager = await this.wallet.createSchnorrAccount(secret, salt, signingKey);
121
211
  const metadata = await this.wallet.getContractMetadata(accountManager.address);
122
- if (metadata.isContractInitialized) {
212
+ if (metadata.initializationStatus === ContractInitializationStatus.INITIALIZED) {
123
213
  this.log.info(`Account at ${accountManager.address.toString()} already initialized`);
124
214
  const timer = new Timer();
125
215
  const address = accountManager.address;
@@ -135,11 +225,22 @@ export class BotFactory {
135
225
  const paymentMethod = new FeeJuicePaymentMethodWithClaim(accountManager.address, claim);
136
226
  const deployMethod = await accountManager.getDeployMethod();
137
227
  const maxFeesPerGas = (await this.aztecNode.getCurrentMinFees()).mul(1 + this.config.minFeePadding);
138
- const gasSettings = GasSettings.default({ maxFeesPerGas });
139
- const sentTx = deployMethod.send({ from: AztecAddress.ZERO, fee: { gasSettings, paymentMethod } });
140
- const txHash = await sentTx.getTxHash();
141
- this.log.info(`Sent tx for account deployment with hash ${txHash.toString()}`);
142
- await this.withNoMinTxsPerBlock(() => sentTx.wait({ timeout: this.config.txMinedWaitSeconds }));
228
+
229
+ const { estimatedGas } = await deployMethod.simulate({
230
+ from: NO_FROM,
231
+ fee: { estimateGas: true, paymentMethod },
232
+ });
233
+ const gasSettings = GasSettings.from({ ...estimatedGas!, maxFeesPerGas, maxPriorityFeesPerGas: GasFees.empty() });
234
+
235
+ await this.withNoMinTxsPerBlock(async () => {
236
+ const { txHash } = await deployMethod.send({
237
+ from: NO_FROM,
238
+ fee: { gasSettings, paymentMethod },
239
+ wait: NO_WAIT,
240
+ });
241
+ this.log.info(`Sent tx for account deployment with hash ${txHash.toString()}`, { gasSettings });
242
+ return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
243
+ });
143
244
  this.log.info(`Account deployed at ${address}`);
144
245
 
145
246
  // Clean up the consumed bridge claim
@@ -151,12 +252,11 @@ export class BotFactory {
151
252
 
152
253
  private async setupTestAccount() {
153
254
  const [initialAccountData] = await getInitialTestAccountsData();
154
- const accountData = {
155
- secret: initialAccountData.secret,
156
- salt: initialAccountData.salt,
157
- contract: new SchnorrAccountContract(initialAccountData.signingKey),
158
- };
159
- const accountManager = await this.wallet.createAccount(accountData);
255
+ const accountManager = await this.wallet.createSchnorrAccount(
256
+ initialAccountData.secret,
257
+ initialAccountData.salt,
258
+ initialAccountData.signingKey,
259
+ );
160
260
  return accountManager.address;
161
261
  }
162
262
 
@@ -173,8 +273,11 @@ export class BotFactory {
173
273
  contractAddressSalt: this.config.tokenSalt,
174
274
  universalDeploy: true,
175
275
  };
276
+ let token: TokenContract | PrivateTokenContract;
176
277
  if (this.config.contract === SupportedTokenContracts.TokenContract) {
177
278
  deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18);
279
+ tokenInstance = await deploy.getInstance(deployOpts);
280
+ token = TokenContract.at(tokenInstance.address, this.wallet);
178
281
  } else if (this.config.contract === SupportedTokenContracts.PrivateTokenContract) {
179
282
  // Generate keys for the contract since PrivateToken uses SinglePrivateMutable which requires keys
180
283
  const tokenSecretKey = Fr.random();
@@ -186,7 +289,10 @@ export class BotFactory {
186
289
 
187
290
  // Register the contract with the secret key before deployment
188
291
  tokenInstance = await deploy.getInstance(deployOpts);
292
+ token = PrivateTokenContract.at(tokenInstance.address, this.wallet);
189
293
  await this.wallet.registerContract(tokenInstance, PrivateTokenContract.artifact, tokenSecretKey);
294
+ // The contract constructor initializes private storage vars that need the contract's own nullifier key.
295
+ deployOpts.additionalScopes = [tokenInstance.address];
190
296
  } else {
191
297
  throw new Error(`Unsupported token contract type: ${this.config.contract}`);
192
298
  }
@@ -195,14 +301,18 @@ export class BotFactory {
195
301
  const metadata = await this.wallet.getContractMetadata(address);
196
302
  if (metadata.isContractPublished) {
197
303
  this.log.info(`Token at ${address.toString()} already deployed`);
198
- return deploy.register();
304
+ await deploy.register();
199
305
  } else {
200
306
  this.log.info(`Deploying token contract at ${address.toString()}`);
201
- const sentTx = deploy.send(deployOpts);
202
- const txHash = await sentTx.getTxHash();
203
- this.log.info(`Sent tx for token setup with hash ${txHash.toString()}`);
204
- return this.withNoMinTxsPerBlock(() => sentTx.deployed({ timeout: this.config.txMinedWaitSeconds }));
307
+ const { estimatedGas } = await deploy.simulate({ ...deployOpts, fee: { estimateGas: true } });
308
+ const { txHash } = await deploy.send({ ...deployOpts, fee: { gasSettings: estimatedGas }, wait: NO_WAIT });
309
+ this.log.info(`Sent tx for token setup with hash ${txHash.toString()}`, { estimatedGas });
310
+ await this.withNoMinTxsPerBlock(async () => {
311
+ await waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
312
+ return token;
313
+ });
205
314
  }
315
+ return token;
206
316
  }
207
317
 
208
318
  /**
@@ -210,7 +320,7 @@ export class BotFactory {
210
320
  * @param wallet - Wallet to deploy the token contract from.
211
321
  * @returns The TokenContract instance.
212
322
  */
213
- private setupTokenContract(
323
+ private async setupTokenContract(
214
324
  deployer: AztecAddress,
215
325
  contractAddressSalt: Fr,
216
326
  name: string,
@@ -219,7 +329,8 @@ export class BotFactory {
219
329
  ): Promise<TokenContract> {
220
330
  const deployOpts: DeployOptions = { from: deployer, contractAddressSalt, universalDeploy: true };
221
331
  const deploy = TokenContract.deploy(this.wallet, deployer, name, ticker, decimals);
222
- return this.registerOrDeployContract('Token - ' + name, deploy, deployOpts);
332
+ const instance = await this.registerOrDeployContract('Token - ' + name, deploy, deployOpts);
333
+ return TokenContract.at(instance.address, this.wallet);
223
334
  }
224
335
 
225
336
  private async setupAmmContract(
@@ -231,12 +342,23 @@ export class BotFactory {
231
342
  ): Promise<AMMContract> {
232
343
  const deployOpts: DeployOptions = { from: deployer, contractAddressSalt, universalDeploy: true };
233
344
  const deploy = AMMContract.deploy(this.wallet, token0.address, token1.address, lpToken.address);
234
- const amm = await this.registerOrDeployContract('AMM', deploy, deployOpts);
345
+ const instance = await this.registerOrDeployContract('AMM', deploy, deployOpts);
346
+ const amm = AMMContract.at(instance.address, this.wallet);
235
347
 
236
348
  this.log.info(`AMM deployed at ${amm.address}`);
237
- const minterTx = lpToken.methods.set_minter(amm.address, true).send({ from: deployer });
238
- this.log.info(`Set LP token minter to AMM txHash=${(await minterTx.getTxHash()).toString()}`);
239
- await minterTx.wait({ timeout: this.config.txMinedWaitSeconds });
349
+ const setMinterInteraction = lpToken.methods.set_minter(amm.address, true);
350
+ const { estimatedGas: setMinterGas } = await setMinterInteraction.simulate({
351
+ from: deployer,
352
+ fee: { estimateGas: true },
353
+ });
354
+ const { receipt: minterReceipt } = await setMinterInteraction.send({
355
+ from: deployer,
356
+ fee: { gasSettings: setMinterGas },
357
+ wait: { timeout: this.config.txMinedWaitSeconds },
358
+ });
359
+ this.log.info(`Set LP token minter to AMM txHash=${minterReceipt.txHash.toString()}`, {
360
+ estimatedGas: setMinterGas,
361
+ });
240
362
  this.log.info(`Liquidity token initialized`);
241
363
 
242
364
  return amm;
@@ -252,9 +374,18 @@ export class BotFactory {
252
374
  ): Promise<void> {
253
375
  const getPrivateBalances = () =>
254
376
  Promise.all([
255
- token0.methods.balance_of_private(liquidityProvider).simulate({ from: liquidityProvider }),
256
- token1.methods.balance_of_private(liquidityProvider).simulate({ from: liquidityProvider }),
257
- lpToken.methods.balance_of_private(liquidityProvider).simulate({ from: liquidityProvider }),
377
+ token0.methods
378
+ .balance_of_private(liquidityProvider)
379
+ .simulate({ from: liquidityProvider })
380
+ .then(r => r.result),
381
+ token1.methods
382
+ .balance_of_private(liquidityProvider)
383
+ .simulate({ from: liquidityProvider })
384
+ .then(r => r.result),
385
+ lpToken.methods
386
+ .balance_of_private(liquidityProvider)
387
+ .simulate({ from: liquidityProvider })
388
+ .then(r => r.result),
258
389
  ]);
259
390
 
260
391
  const authwitNonce = Fr.random();
@@ -295,23 +426,44 @@ export class BotFactory {
295
426
  .getFunctionCall(),
296
427
  });
297
428
 
298
- const mintTx = new BatchCall(this.wallet, [
429
+ const mintBatch = new BatchCall(this.wallet, [
299
430
  token0.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
300
431
  token1.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
301
- ]).send({ from: liquidityProvider });
432
+ ]);
433
+ const { estimatedGas: mintGas } = await mintBatch.simulate({
434
+ from: liquidityProvider,
435
+ fee: { estimateGas: true },
436
+ });
437
+ const { receipt: mintReceipt } = await mintBatch.send({
438
+ from: liquidityProvider,
439
+ fee: { gasSettings: mintGas },
440
+ wait: { timeout: this.config.txMinedWaitSeconds },
441
+ });
302
442
 
303
- this.log.info(`Sent mint tx: ${(await mintTx.getTxHash()).toString()}`);
304
- await mintTx.wait({ timeout: this.config.txMinedWaitSeconds });
443
+ this.log.info(`Sent mint tx: ${mintReceipt.txHash.toString()}`, { estimatedGas: mintGas });
305
444
 
306
- const addLiquidityTx = amm.methods
307
- .add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, authwitNonce)
308
- .send({
309
- from: liquidityProvider,
310
- authWitnesses: [token0Authwit, token1Authwit],
311
- });
445
+ const addLiquidityInteraction = amm.methods.add_liquidity(
446
+ amount0Max,
447
+ amount1Max,
448
+ amount0Min,
449
+ amount1Min,
450
+ authwitNonce,
451
+ );
452
+ const { estimatedGas: addLiquidityGas } = await addLiquidityInteraction.simulate({
453
+ from: liquidityProvider,
454
+ fee: { estimateGas: true },
455
+ authWitnesses: [token0Authwit, token1Authwit],
456
+ });
457
+ const { receipt: addLiquidityReceipt } = await addLiquidityInteraction.send({
458
+ from: liquidityProvider,
459
+ fee: { gasSettings: addLiquidityGas },
460
+ authWitnesses: [token0Authwit, token1Authwit],
461
+ wait: { timeout: this.config.txMinedWaitSeconds },
462
+ });
312
463
 
313
- this.log.info(`Sent tx to add liquidity to the AMM: ${(await addLiquidityTx.getTxHash()).toString()}`);
314
- await addLiquidityTx.wait({ timeout: this.config.txMinedWaitSeconds });
464
+ this.log.info(`Sent tx to add liquidity to the AMM: ${addLiquidityReceipt.txHash.toString()}`, {
465
+ estimatedGas: addLiquidityGas,
466
+ });
315
467
  this.log.info(`Liquidity added`);
316
468
 
317
469
  const [newT0Bal, newT1Bal, newLPBal] = await getPrivateBalances();
@@ -324,19 +476,23 @@ export class BotFactory {
324
476
  name: string,
325
477
  deploy: DeployMethod<T>,
326
478
  deployOpts: DeployOptions,
327
- ): Promise<T> {
328
- const address = (await deploy.getInstance(deployOpts)).address;
479
+ ): Promise<ContractInstanceWithAddress> {
480
+ const instance = await deploy.getInstance(deployOpts);
481
+ const address = instance.address;
329
482
  const metadata = await this.wallet.getContractMetadata(address);
330
483
  if (metadata.isContractPublished) {
331
484
  this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
332
- return deploy.register();
485
+ await deploy.register();
333
486
  } else {
334
- this.log.info(`Deploying contract ${name} at ${address.toString()}`);
335
- const sentTx = deploy.send(deployOpts);
336
- const txHash = await sentTx.getTxHash();
337
- this.log.info(`Sent contract ${name} setup tx with hash ${txHash.toString()}`);
338
- return this.withNoMinTxsPerBlock(() => sentTx.deployed({ timeout: this.config.txMinedWaitSeconds }));
487
+ const { estimatedGas } = await deploy.simulate({ ...deployOpts, fee: { estimateGas: true } });
488
+ this.log.info(`Deploying contract ${name} at ${address.toString()}`, { estimatedGas });
489
+ await this.withNoMinTxsPerBlock(async () => {
490
+ const { txHash } = await deploy.send({ ...deployOpts, fee: { gasSettings: estimatedGas }, wait: NO_WAIT });
491
+ this.log.info(`Sent contract ${name} setup tx with hash ${txHash.toString()}`);
492
+ return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
493
+ });
339
494
  }
495
+ return instance;
340
496
  }
341
497
 
342
498
  /**
@@ -372,10 +528,21 @@ export class BotFactory {
372
528
  this.log.info(`Skipping minting as ${minter.toString()} has enough tokens`);
373
529
  return;
374
530
  }
375
- const sentTx = new BatchCall(token.wallet, calls).send({ from: minter });
376
- const txHash = await sentTx.getTxHash();
377
- this.log.info(`Sent token mint tx with hash ${txHash.toString()}`);
378
- await this.withNoMinTxsPerBlock(() => sentTx.wait({ timeout: this.config.txMinedWaitSeconds }));
531
+
532
+ // PrivateToken's mint accesses contract-level private storage vars (admin, total_supply).
533
+ const additionalScopes = isStandardToken ? undefined : [token.address];
534
+ const mintBatch = new BatchCall(token.wallet, calls);
535
+ const { estimatedGas } = await mintBatch.simulate({ from: minter, fee: { estimateGas: true }, additionalScopes });
536
+ await this.withNoMinTxsPerBlock(async () => {
537
+ const { txHash } = await mintBatch.send({
538
+ from: minter,
539
+ additionalScopes,
540
+ fee: { gasSettings: estimatedGas },
541
+ wait: NO_WAIT,
542
+ });
543
+ this.log.info(`Sent token mint tx with hash ${txHash.toString()}`, { estimatedGas });
544
+ return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
545
+ });
379
546
  }
380
547
 
381
548
  /**
@@ -395,7 +562,6 @@ export class BotFactory {
395
562
  await this.withNoMinTxsPerBlock(() =>
396
563
  waitForL1ToL2MessageReady(this.aztecNode, messageHash, {
397
564
  timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds,
398
- forPublicConsumption: false,
399
565
  }),
400
566
  );
401
567
  return existingClaim.claim;
@@ -434,7 +600,6 @@ export class BotFactory {
434
600
  await this.withNoMinTxsPerBlock(() =>
435
601
  waitForL1ToL2MessageReady(this.aztecNode, Fr.fromHexString(claim.messageHash), {
436
602
  timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds,
437
- forPublicConsumption: false,
438
603
  }),
439
604
  );
440
605
 
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { Bot } from './bot.js';
2
2
  export { AmmBot } from './amm_bot.js';
3
+ export { CrossChainBot } from './cross_chain_bot.js';
3
4
  export { BotRunner } from './runner.js';
4
5
  export { BotStore } from './store/bot_store.js';
5
6
  export {
@@ -0,0 +1,79 @@
1
+ import { generateClaimSecret } from '@aztec/aztec.js/ethereum';
2
+ import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
3
+ import { compactArray } from '@aztec/foundation/collection';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
+ import { EthAddress } from '@aztec/foundation/eth-address';
6
+ import type { Logger } from '@aztec/foundation/log';
7
+ import { InboxAbi } from '@aztec/l1-artifacts';
8
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
9
+
10
+ import { decodeEventLog, getContract } from 'viem';
11
+
12
+ import type { BotStore, PendingL1ToL2Message } from './store/index.js';
13
+
14
+ /** Sends an L1→L2 message via the Inbox contract and stores it. */
15
+ export async function seedL1ToL2Message(
16
+ l1Client: ExtendedViemWalletClient,
17
+ inboxAddress: EthAddress,
18
+ l2Recipient: AztecAddress,
19
+ rollupVersion: bigint,
20
+ store: BotStore,
21
+ log: Logger,
22
+ ): Promise<PendingL1ToL2Message> {
23
+ log.info('Seeding L1→L2 message');
24
+ const [secret, secretHash] = await generateClaimSecret(log);
25
+ const content = Fr.random();
26
+
27
+ const inbox = getContract({
28
+ address: inboxAddress.toString(),
29
+ abi: InboxAbi,
30
+ client: l1Client,
31
+ });
32
+
33
+ const txHash = await inbox.write.sendL2Message(
34
+ [{ actor: l2Recipient.toString(), version: rollupVersion }, content.toString(), secretHash.toString()],
35
+ { gas: 1_000_000n },
36
+ );
37
+ log.info(`L1→L2 message sent in tx ${txHash}`);
38
+
39
+ const txReceipt = await l1Client.waitForTransactionReceipt({ hash: txHash });
40
+ if (txReceipt.status !== 'success') {
41
+ throw new Error(`L1→L2 message tx failed: ${txHash}`);
42
+ }
43
+
44
+ // Extract MessageSent event
45
+ const messageSentLogs = compactArray(
46
+ txReceipt.logs
47
+ .filter(l => l.address.toLowerCase() === inboxAddress.toString().toLowerCase())
48
+ .map(l => {
49
+ try {
50
+ return decodeEventLog({ abi: InboxAbi, eventName: 'MessageSent', data: l.data, topics: l.topics });
51
+ } catch {
52
+ return undefined;
53
+ }
54
+ }),
55
+ );
56
+
57
+ if (messageSentLogs.length !== 1) {
58
+ throw new Error(`Expected 1 MessageSent event, got ${messageSentLogs.length}`);
59
+ }
60
+
61
+ const event = messageSentLogs[0];
62
+
63
+ const msgHash = event.args.hash;
64
+ const globalLeafIndex = event.args.index;
65
+
66
+ const msg: PendingL1ToL2Message = {
67
+ content: content.toString(),
68
+ secret: secret.toString(),
69
+ secretHash: secretHash.toString(),
70
+ msgHash,
71
+ sender: l1Client.account!.address,
72
+ globalLeafIndex: globalLeafIndex.toString(),
73
+ timestamp: Date.now(),
74
+ };
75
+
76
+ await store.savePendingL1ToL2Message(msg);
77
+ log.info(`Seeded L1→L2 message msgHash=${msg.msgHash}`);
78
+ return msg;
79
+ }
package/src/runner.ts CHANGED
@@ -4,12 +4,13 @@ import { omit } from '@aztec/foundation/collection';
4
4
  import { RunningPromise } from '@aztec/foundation/running-promise';
5
5
  import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
6
6
  import { type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
7
- import type { TestWallet } from '@aztec/test-wallet/server';
7
+ import type { EmbeddedWallet } from '@aztec/wallets/embedded';
8
8
 
9
9
  import { AmmBot } from './amm_bot.js';
10
10
  import type { BaseBot } from './base_bot.js';
11
11
  import { Bot } from './bot.js';
12
12
  import type { BotConfig } from './config.js';
13
+ import { CrossChainBot } from './cross_chain_bot.js';
13
14
  import type { BotInfo, BotRunnerApi } from './interface.js';
14
15
  import { BotStore } from './store/index.js';
15
16
 
@@ -24,7 +25,7 @@ export class BotRunner implements BotRunnerApi, Traceable {
24
25
 
25
26
  public constructor(
26
27
  private config: BotConfig,
27
- private readonly wallet: TestWallet,
28
+ private readonly wallet: EmbeddedWallet,
28
29
  private readonly aztecNode: AztecNode,
29
30
  private readonly telemetry: TelemetryClient,
30
31
  private readonly aztecNodeAdmin: AztecNodeAdmin | undefined,
@@ -146,9 +147,21 @@ export class BotRunner implements BotRunnerApi, Traceable {
146
147
 
147
148
  async #createBot() {
148
149
  try {
149
- this.bot = this.config.ammTxs
150
- ? AmmBot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store)
151
- : Bot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
150
+ switch (this.config.botMode) {
151
+ case 'crosschain':
152
+ this.bot = CrossChainBot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
153
+ break;
154
+ case 'amm':
155
+ this.bot = AmmBot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
156
+ break;
157
+ case 'transfer':
158
+ this.bot = Bot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
159
+ break;
160
+ default: {
161
+ const _exhaustive: never = this.config.botMode;
162
+ throw new Error(`Unsupported bot mode: [${_exhaustive}]`);
163
+ }
164
+ }
152
165
  await this.bot;
153
166
  } catch (err) {
154
167
  this.log.error(`Error setting up bot: ${err}`);