@aztec/bot 5.0.0-nightly.20260708 → 5.0.0-nightly.20260710
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ZhY3RvcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBb0J6RCxPQUFPLEtBQUssRUFBRSx3QkFBd0IsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBSXRFLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSw4QkFBOEIsQ0FBQztBQUMzRCxPQUFPLEVBQUUsb0JBQW9CLEVBQUUsTUFBTSx1Q0FBdUMsQ0FBQztBQUM3RSxPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDL0QsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLG9DQUFvQyxDQUFDO0FBR2xFLE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxjQUFjLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNqRixPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFFekQsT0FBTyxFQUFFLEtBQUssU0FBUyxFQUEyQixNQUFNLGFBQWEsQ0FBQztBQUV0RSxPQUFPLEtBQUssRUFBRSxRQUFRLEVBQUUsTUFBTSxrQkFBa0Is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alB,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
|
@@ -32,6 +32,8 @@ export class BotFactory {
|
|
|
32
32
|
aztecNodeAdmin;
|
|
33
33
|
syncChainTip;
|
|
34
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;
|
|
35
37
|
constructor(config, wallet, store, aztecNode, aztecNodeAdmin, syncChainTip){
|
|
36
38
|
this.config = config;
|
|
37
39
|
this.wallet = wallet;
|
|
@@ -40,6 +42,7 @@ export class BotFactory {
|
|
|
40
42
|
this.aztecNodeAdmin = aztecNodeAdmin;
|
|
41
43
|
this.syncChainTip = syncChainTip;
|
|
42
44
|
this.log = createLogger('bot');
|
|
45
|
+
this.noMinTxsPerBlockDepth = 0;
|
|
43
46
|
// Set fee padding on the wallet so that all transactions during setup
|
|
44
47
|
// (token deploy, minting, etc.) use the configured padding, not the default.
|
|
45
48
|
this.wallet.setMinFeePadding(config.minFeePadding);
|
|
@@ -64,11 +67,30 @@ export class BotFactory {
|
|
|
64
67
|
async setupAmm() {
|
|
65
68
|
const defaultAccountAddress = await this.setupAccount();
|
|
66
69
|
await this.ensureFeeJuiceBalance(defaultAccountAddress);
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
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);
|
|
72
94
|
this.log.info(`AMM initialized and funded`);
|
|
73
95
|
return {
|
|
74
96
|
wallet: this.wallet,
|
|
@@ -100,16 +122,30 @@ export class BotFactory {
|
|
|
100
122
|
// Fetch Rollup version (needed for Inbox L2Actor struct)
|
|
101
123
|
const rollupContract = new RollupContract(l1Client, l1ContractAddresses.rollupAddress.toString());
|
|
102
124
|
const rollupVersion = await rollupContract.getVersion();
|
|
103
|
-
//
|
|
104
|
-
|
|
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;
|
|
105
134
|
// Recover any pending messages from store (clean up stale ones first)
|
|
106
135
|
await this.store.cleanupOldPendingMessages();
|
|
107
136
|
const pendingMessages = await this.store.getUnconsumedL1ToL2Messages();
|
|
108
|
-
// 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.
|
|
109
139
|
const seedCount = Math.max(0, this.config.l1ToL2SeedCount - pendingMessages.length);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
+
]);
|
|
113
149
|
// Block until at least one message is ready
|
|
114
150
|
const allMessages = await this.store.getUnconsumedL1ToL2Messages();
|
|
115
151
|
if (allMessages.length > 0) {
|
|
@@ -130,15 +166,10 @@ export class BotFactory {
|
|
|
130
166
|
rollupVersion
|
|
131
167
|
};
|
|
132
168
|
}
|
|
133
|
-
async
|
|
134
|
-
const
|
|
169
|
+
async deployTestContract(deployer, deploy) {
|
|
170
|
+
const instance = await this.registerOrDeployContract('TestContract', deploy, {
|
|
135
171
|
from: deployer
|
|
136
|
-
};
|
|
137
|
-
const deploy = TestContract.deploy(this.wallet, {
|
|
138
|
-
salt: this.config.tokenSalt,
|
|
139
|
-
universalDeploy: true
|
|
140
172
|
});
|
|
141
|
-
const instance = await this.registerOrDeployContract('TestContract', deploy, deployOpts);
|
|
142
173
|
return TestContract.at(instance.address, this.wallet);
|
|
143
174
|
}
|
|
144
175
|
/**
|
|
@@ -233,48 +264,45 @@ export class BotFactory {
|
|
|
233
264
|
const instance = await this.registerOrDeployContract('Token - ' + name, deploy, deployOpts);
|
|
234
265
|
return TokenContract.at(instance.address, this.wallet);
|
|
235
266
|
}
|
|
236
|
-
async
|
|
237
|
-
const
|
|
267
|
+
async deployAmmContract(deployer, deploy) {
|
|
268
|
+
const instance = await this.registerOrDeployContract('AMM', deploy, {
|
|
238
269
|
from: deployer
|
|
239
|
-
};
|
|
240
|
-
const deploy = AMMContract.deploy(this.wallet, token0.address, token1.address, lpToken.address, {
|
|
241
|
-
salt,
|
|
242
|
-
universalDeploy: true
|
|
243
270
|
});
|
|
244
|
-
const instance = await this.registerOrDeployContract('AMM', deploy, deployOpts);
|
|
245
271
|
const amm = AMMContract.at(instance.address, this.wallet);
|
|
246
272
|
this.log.info(`AMM deployed at ${amm.address}`);
|
|
247
|
-
|
|
248
|
-
|
|
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({
|
|
249
278
|
from: deployer,
|
|
250
279
|
wait: {
|
|
251
280
|
timeout: this.config.txMinedWaitSeconds
|
|
252
281
|
}
|
|
253
282
|
});
|
|
254
|
-
this.log.info(`Set LP token minter to AMM txHash=${
|
|
255
|
-
this.log.info(`Liquidity token initialized`);
|
|
256
|
-
return amm;
|
|
283
|
+
this.log.info(`Set LP token minter to AMM txHash=${receipt.txHash.toString()}`);
|
|
257
284
|
}
|
|
258
|
-
async
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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) {
|
|
270
300
|
const authwitNonce = Fr.random();
|
|
271
301
|
// keep some tokens for swapping
|
|
272
302
|
const amount0Max = MINT_BALANCE / 2;
|
|
273
303
|
const amount0Min = MINT_BALANCE / 4;
|
|
274
304
|
const amount1Max = MINT_BALANCE / 2;
|
|
275
305
|
const amount1Min = MINT_BALANCE / 4;
|
|
276
|
-
const [t0Bal, t1Bal, lpBal] = await getPrivateBalances();
|
|
277
|
-
this.log.info(`Minting ${MINT_BALANCE} tokens of each BotToken0 and BotToken1. Current private balances of ${liquidityProvider}: token0=${t0Bal}, token1=${t1Bal}, lp=${lpBal}`);
|
|
278
306
|
// Add authwitnesses for the transfers in AMM::add_liquidity function
|
|
279
307
|
const token0Authwit = await this.wallet.createAuthWit(defaultAccountAddress, {
|
|
280
308
|
caller: amm.address,
|
|
@@ -284,19 +312,7 @@ export class BotFactory {
|
|
|
284
312
|
caller: amm.address,
|
|
285
313
|
call: await token1.methods.transfer_to_public_and_prepare_private_balance_increase(liquidityProvider, amm.address, amount1Max, authwitNonce).getFunctionCall()
|
|
286
314
|
});
|
|
287
|
-
const
|
|
288
|
-
token0.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
|
|
289
|
-
token1.methods.mint_to_private(liquidityProvider, MINT_BALANCE)
|
|
290
|
-
]);
|
|
291
|
-
const { receipt: mintReceipt } = await mintBatch.send({
|
|
292
|
-
from: liquidityProvider,
|
|
293
|
-
wait: {
|
|
294
|
-
timeout: this.config.txMinedWaitSeconds
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
this.log.info(`Sent mint tx: ${mintReceipt.txHash.toString()}`);
|
|
298
|
-
const addLiquidityInteraction = amm.methods.add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, authwitNonce);
|
|
299
|
-
const { receipt: addLiquidityReceipt } = await addLiquidityInteraction.send({
|
|
315
|
+
const { receipt } = await amm.methods.add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, authwitNonce).send({
|
|
300
316
|
from: liquidityProvider,
|
|
301
317
|
authWitnesses: [
|
|
302
318
|
token0Authwit,
|
|
@@ -306,10 +322,20 @@ export class BotFactory {
|
|
|
306
322
|
timeout: this.config.txMinedWaitSeconds
|
|
307
323
|
}
|
|
308
324
|
});
|
|
309
|
-
this.log.info(`Sent tx to add liquidity to the AMM: ${
|
|
325
|
+
this.log.info(`Sent tx to add liquidity to the AMM: ${receipt.txHash.toString()}`);
|
|
310
326
|
this.log.info(`Liquidity added`);
|
|
311
|
-
const [
|
|
312
|
-
|
|
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}`);
|
|
313
339
|
}
|
|
314
340
|
async registerOrDeployContract(name, deploy, deployOpts) {
|
|
315
341
|
const instance = await deploy.getInstance();
|
|
@@ -470,18 +496,37 @@ export class BotFactory {
|
|
|
470
496
|
this.log.verbose(`No node admin client or flushing not requested (not setting minTxsPerBlock to 0)`);
|
|
471
497
|
return fn();
|
|
472
498
|
}
|
|
473
|
-
const
|
|
474
|
-
this
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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
|
+
}
|
|
478
516
|
try {
|
|
517
|
+
await this.savedMinTxsPerBlock;
|
|
479
518
|
return await fn();
|
|
480
519
|
} finally{
|
|
481
|
-
this.
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
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
|
+
}
|
|
485
530
|
}
|
|
486
531
|
}
|
|
487
532
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/bot",
|
|
3
|
-
"version": "5.0.0-nightly.
|
|
3
|
+
"version": "5.0.0-nightly.20260710",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -54,20 +54,20 @@
|
|
|
54
54
|
]
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@aztec/accounts": "5.0.0-nightly.
|
|
58
|
-
"@aztec/aztec.js": "5.0.0-nightly.
|
|
59
|
-
"@aztec/entrypoints": "5.0.0-nightly.
|
|
60
|
-
"@aztec/ethereum": "5.0.0-nightly.
|
|
61
|
-
"@aztec/foundation": "5.0.0-nightly.
|
|
62
|
-
"@aztec/kv-store": "5.0.0-nightly.
|
|
63
|
-
"@aztec/l1-artifacts": "5.0.0-nightly.
|
|
64
|
-
"@aztec/noir-contracts.js": "5.0.0-nightly.
|
|
65
|
-
"@aztec/noir-protocol-circuits-types": "5.0.0-nightly.
|
|
66
|
-
"@aztec/noir-test-contracts.js": "5.0.0-nightly.
|
|
67
|
-
"@aztec/protocol-contracts": "5.0.0-nightly.
|
|
68
|
-
"@aztec/stdlib": "5.0.0-nightly.
|
|
69
|
-
"@aztec/telemetry-client": "5.0.0-nightly.
|
|
70
|
-
"@aztec/wallets": "5.0.0-nightly.
|
|
57
|
+
"@aztec/accounts": "5.0.0-nightly.20260710",
|
|
58
|
+
"@aztec/aztec.js": "5.0.0-nightly.20260710",
|
|
59
|
+
"@aztec/entrypoints": "5.0.0-nightly.20260710",
|
|
60
|
+
"@aztec/ethereum": "5.0.0-nightly.20260710",
|
|
61
|
+
"@aztec/foundation": "5.0.0-nightly.20260710",
|
|
62
|
+
"@aztec/kv-store": "5.0.0-nightly.20260710",
|
|
63
|
+
"@aztec/l1-artifacts": "5.0.0-nightly.20260710",
|
|
64
|
+
"@aztec/noir-contracts.js": "5.0.0-nightly.20260710",
|
|
65
|
+
"@aztec/noir-protocol-circuits-types": "5.0.0-nightly.20260710",
|
|
66
|
+
"@aztec/noir-test-contracts.js": "5.0.0-nightly.20260710",
|
|
67
|
+
"@aztec/protocol-contracts": "5.0.0-nightly.20260710",
|
|
68
|
+
"@aztec/stdlib": "5.0.0-nightly.20260710",
|
|
69
|
+
"@aztec/telemetry-client": "5.0.0-nightly.20260710",
|
|
70
|
+
"@aztec/wallets": "5.0.0-nightly.20260710",
|
|
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
|
@@ -45,6 +45,11 @@ const FEE_JUICE_TOP_UP_THRESHOLD = 100n * 10n ** 18n;
|
|
|
45
45
|
export class BotFactory {
|
|
46
46
|
private log = createLogger('bot');
|
|
47
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
|
+
|
|
48
53
|
constructor(
|
|
49
54
|
private readonly config: BotConfig,
|
|
50
55
|
private readonly wallet: EmbeddedWallet,
|
|
@@ -88,23 +93,35 @@ export class BotFactory {
|
|
|
88
93
|
}> {
|
|
89
94
|
const defaultAccountAddress = await this.setupAccount();
|
|
90
95
|
await this.ensureFeeJuiceBalance(defaultAccountAddress);
|
|
91
|
-
const token0 = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotToken0', 'BOT0');
|
|
92
|
-
const token1 = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotToken1', 'BOT1');
|
|
93
|
-
const liquidityToken = await this.setupTokenContract(
|
|
94
|
-
defaultAccountAddress,
|
|
95
|
-
this.config.tokenSalt,
|
|
96
|
-
'BotLPToken',
|
|
97
|
-
'BOTLP',
|
|
98
|
-
);
|
|
99
|
-
const amm = await this.setupAmmContract(
|
|
100
|
-
defaultAccountAddress,
|
|
101
|
-
this.config.tokenSalt,
|
|
102
|
-
token0,
|
|
103
|
-
token1,
|
|
104
|
-
liquidityToken,
|
|
105
|
-
);
|
|
106
96
|
|
|
107
|
-
|
|
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);
|
|
108
125
|
this.log.info(`AMM initialized and funded`);
|
|
109
126
|
|
|
110
127
|
return { wallet: this.wallet, defaultAccountAddress, amm, token0, token1, node: this.aztecNode };
|
|
@@ -142,25 +159,32 @@ export class BotFactory {
|
|
|
142
159
|
const rollupContract = new RollupContract(l1Client, l1ContractAddresses.rollupAddress.toString());
|
|
143
160
|
const rollupVersion = await rollupContract.getVersion();
|
|
144
161
|
|
|
145
|
-
//
|
|
146
|
-
|
|
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;
|
|
147
171
|
|
|
148
172
|
// Recover any pending messages from store (clean up stale ones first)
|
|
149
173
|
await this.store.cleanupOldPendingMessages();
|
|
150
174
|
const pendingMessages = await this.store.getUnconsumedL1ToL2Messages();
|
|
151
175
|
|
|
152
|
-
// 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.
|
|
153
178
|
const seedCount = Math.max(0, this.config.l1ToL2SeedCount - pendingMessages.length);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
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
|
+
]);
|
|
164
188
|
|
|
165
189
|
// Block until at least one message is ready
|
|
166
190
|
const allMessages = await this.store.getUnconsumedL1ToL2Messages();
|
|
@@ -184,10 +208,8 @@ export class BotFactory {
|
|
|
184
208
|
};
|
|
185
209
|
}
|
|
186
210
|
|
|
187
|
-
private async
|
|
188
|
-
const
|
|
189
|
-
const deploy = TestContract.deploy(this.wallet, { salt: this.config.tokenSalt, universalDeploy: true });
|
|
190
|
-
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 });
|
|
191
213
|
return TestContract.at(instance.address, this.wallet);
|
|
192
214
|
}
|
|
193
215
|
|
|
@@ -292,34 +314,37 @@ export class BotFactory {
|
|
|
292
314
|
return TokenContract.at(instance.address, this.wallet);
|
|
293
315
|
}
|
|
294
316
|
|
|
295
|
-
private async
|
|
296
|
-
|
|
297
|
-
salt: Fr,
|
|
298
|
-
token0: TokenContract,
|
|
299
|
-
token1: TokenContract,
|
|
300
|
-
lpToken: TokenContract,
|
|
301
|
-
): Promise<AMMContract> {
|
|
302
|
-
const deployOpts: DeployOptions = { from: deployer };
|
|
303
|
-
const deploy = AMMContract.deploy(this.wallet, token0.address, token1.address, lpToken.address, {
|
|
304
|
-
salt,
|
|
305
|
-
universalDeploy: true,
|
|
306
|
-
});
|
|
307
|
-
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 });
|
|
308
319
|
const amm = AMMContract.at(instance.address, this.wallet);
|
|
309
|
-
|
|
310
320
|
this.log.info(`AMM deployed at ${amm.address}`);
|
|
311
|
-
|
|
312
|
-
|
|
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({
|
|
313
328
|
from: deployer,
|
|
314
329
|
wait: { timeout: this.config.txMinedWaitSeconds },
|
|
315
330
|
});
|
|
316
|
-
this.log.info(`Set LP token minter to AMM txHash=${
|
|
317
|
-
|
|
331
|
+
this.log.info(`Set LP token minter to AMM txHash=${receipt.txHash.toString()}`);
|
|
332
|
+
}
|
|
318
333
|
|
|
319
|
-
|
|
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()}`);
|
|
320
345
|
}
|
|
321
346
|
|
|
322
|
-
private async
|
|
347
|
+
private async addAmmLiquidity(
|
|
323
348
|
defaultAccountAddress: AztecAddress,
|
|
324
349
|
liquidityProvider: AztecAddress,
|
|
325
350
|
amm: AMMContract,
|
|
@@ -327,22 +352,6 @@ export class BotFactory {
|
|
|
327
352
|
token1: TokenContract,
|
|
328
353
|
lpToken: TokenContract,
|
|
329
354
|
): Promise<void> {
|
|
330
|
-
const getPrivateBalances = () =>
|
|
331
|
-
Promise.all([
|
|
332
|
-
token0.methods
|
|
333
|
-
.balance_of_private(liquidityProvider)
|
|
334
|
-
.simulate({ from: liquidityProvider })
|
|
335
|
-
.then(r => r.result),
|
|
336
|
-
token1.methods
|
|
337
|
-
.balance_of_private(liquidityProvider)
|
|
338
|
-
.simulate({ from: liquidityProvider })
|
|
339
|
-
.then(r => r.result),
|
|
340
|
-
lpToken.methods
|
|
341
|
-
.balance_of_private(liquidityProvider)
|
|
342
|
-
.simulate({ from: liquidityProvider })
|
|
343
|
-
.then(r => r.result),
|
|
344
|
-
]);
|
|
345
|
-
|
|
346
355
|
const authwitNonce = Fr.random();
|
|
347
356
|
|
|
348
357
|
// keep some tokens for swapping
|
|
@@ -351,12 +360,6 @@ export class BotFactory {
|
|
|
351
360
|
const amount1Max = MINT_BALANCE / 2;
|
|
352
361
|
const amount1Min = MINT_BALANCE / 4;
|
|
353
362
|
|
|
354
|
-
const [t0Bal, t1Bal, lpBal] = await getPrivateBalances();
|
|
355
|
-
|
|
356
|
-
this.log.info(
|
|
357
|
-
`Minting ${MINT_BALANCE} tokens of each BotToken0 and BotToken1. Current private balances of ${liquidityProvider}: token0=${t0Bal}, token1=${t1Bal}, lp=${lpBal}`,
|
|
358
|
-
);
|
|
359
|
-
|
|
360
363
|
// Add authwitnesses for the transfers in AMM::add_liquidity function
|
|
361
364
|
const token0Authwit = await this.wallet.createAuthWit(defaultAccountAddress, {
|
|
362
365
|
caller: amm.address,
|
|
@@ -381,36 +384,33 @@ export class BotFactory {
|
|
|
381
384
|
.getFunctionCall(),
|
|
382
385
|
});
|
|
383
386
|
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
this.log.info(`Sent mint tx: ${mintReceipt.txHash.toString()}`);
|
|
394
|
-
|
|
395
|
-
const addLiquidityInteraction = amm.methods.add_liquidity(
|
|
396
|
-
amount0Max,
|
|
397
|
-
amount1Max,
|
|
398
|
-
amount0Min,
|
|
399
|
-
amount1Min,
|
|
400
|
-
authwitNonce,
|
|
401
|
-
);
|
|
402
|
-
const { receipt: addLiquidityReceipt } = await addLiquidityInteraction.send({
|
|
403
|
-
from: liquidityProvider,
|
|
404
|
-
authWitnesses: [token0Authwit, token1Authwit],
|
|
405
|
-
wait: { timeout: this.config.txMinedWaitSeconds },
|
|
406
|
-
});
|
|
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
|
+
});
|
|
407
394
|
|
|
408
|
-
this.log.info(`Sent tx to add liquidity to the AMM: ${
|
|
395
|
+
this.log.info(`Sent tx to add liquidity to the AMM: ${receipt.txHash.toString()}`);
|
|
409
396
|
this.log.info(`Liquidity added`);
|
|
410
397
|
|
|
411
|
-
const [
|
|
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
|
+
]);
|
|
412
412
|
this.log.info(
|
|
413
|
-
`Updated private balances of ${defaultAccountAddress} after minting and funding AMM: token0=${
|
|
413
|
+
`Updated private balances of ${defaultAccountAddress} after minting and funding AMM: token0=${t0Bal}, token1=${t1Bal}, lp=${lpBal}`,
|
|
414
414
|
);
|
|
415
415
|
}
|
|
416
416
|
|
|
@@ -593,19 +593,36 @@ export class BotFactory {
|
|
|
593
593
|
return claim as L2AmountClaim;
|
|
594
594
|
}
|
|
595
595
|
|
|
596
|
-
|
|
596
|
+
protected async withNoMinTxsPerBlock<T>(fn: () => Promise<T>): Promise<T> {
|
|
597
597
|
if (!this.aztecNodeAdmin || !this.config.flushSetupTransactions) {
|
|
598
598
|
this.log.verbose(`No node admin client or flushing not requested (not setting minTxsPerBlock to 0)`);
|
|
599
599
|
return fn();
|
|
600
600
|
}
|
|
601
|
-
const
|
|
602
|
-
this
|
|
603
|
-
|
|
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
|
+
}
|
|
604
614
|
try {
|
|
615
|
+
await this.savedMinTxsPerBlock;
|
|
605
616
|
return await fn();
|
|
606
617
|
} finally {
|
|
607
|
-
this.
|
|
608
|
-
|
|
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
|
+
}
|
|
609
626
|
}
|
|
610
627
|
}
|
|
611
628
|
}
|