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