@aztec/bot 5.0.0-nightly.20260409 → 5.0.0-nightly.20260410
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 +5 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +185 -36
- package/package.json +15 -15
- package/src/factory.ts +181 -28
package/dest/factory.d.ts
CHANGED
|
@@ -51,14 +51,18 @@ export declare class BotFactory {
|
|
|
51
51
|
private setupAccount;
|
|
52
52
|
private setupAccountWithPrivateKey;
|
|
53
53
|
private setupTestAccount;
|
|
54
|
+
private setupTokenWithOptionalEarlyRefuel;
|
|
55
|
+
private setupTokenContractWithOptionalEarlyRefuel;
|
|
56
|
+
private getTokenInstance;
|
|
54
57
|
private setupToken;
|
|
55
58
|
private setupTokenContract;
|
|
56
59
|
private setupAmmContract;
|
|
57
60
|
private fundAmm;
|
|
58
61
|
private registerOrDeployContract;
|
|
62
|
+
private ensureFeeJuiceBalance;
|
|
59
63
|
private mintTokens;
|
|
60
64
|
private getOrCreateBridgeClaim;
|
|
61
65
|
private bridgeL1FeeJuice;
|
|
62
66
|
private withNoMinTxsPerBlock;
|
|
63
67
|
}
|
|
64
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
68
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ZhY3RvcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBcUJ6RCxPQUFPLEtBQUssRUFBRSx3QkFBd0IsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBSXRFLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSw4QkFBOEIsQ0FBQztBQUMzRCxPQUFPLEVBQUUsb0JBQW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EAAE,YAAY,CAAC;KACzB,CAAC,CAOD;IAEY,QAAQ,IAAI,OAAO,CAAC;QAC/B,MAAM,EAAE,cAAc,CAAC;QACvB,qBAAqB,EAAE,YAAY,CAAC;QACpC,GAAG,EAAE,WAAW,CAAC;QACjB,MAAM,EAAE,aAAa,CAAC;QACtB,MAAM,EAAE,aAAa,CAAC;QACtB,IAAI,EAAE,SAAS,CAAC;KACjB,CAAC,CA4BD;IAED;;;OAGG;IACU,eAAe,IAAI,OAAO,CAAC;QACtC,MAAM,EAAE,cAAc,CAAC;QACvB,qBAAqB,EAAE,YAAY,CAAC;QACpC,QAAQ,EAAE,YAAY,CAAC;QACvB,IAAI,EAAE,SAAS,CAAC;QAChB,QAAQ,EAAE,wBAAwB,CAAC;QACnC,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC,CA2DD;YAEa,iBAAiB;YAejB,YAAY;YAWZ,0BAA0B;YAuC1B,gBAAgB;YAehB,iCAAiC;YAcjC,yCAAyC;YAmBzC,gBAAgB;YAiChB,UAAU;YAwCV,kBAAkB;YAalB,gBAAgB;YAwBhB,OAAO;YA+FP,wBAAwB;YA6DxB,qBAAqB;YAuDrB,UAAU;YAiDV,sBAAsB;YA2BtB,gBAAgB;YA+BhB,oBAAoB;CAenC"}
|
package/dest/factory.js
CHANGED
|
@@ -7,6 +7,7 @@ import { deriveKeys } from '@aztec/aztec.js/keys';
|
|
|
7
7
|
import { createLogger } from '@aztec/aztec.js/log';
|
|
8
8
|
import { waitForL1ToL2MessageReady } from '@aztec/aztec.js/messaging';
|
|
9
9
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
10
|
+
import { getFeeJuiceBalance } from '@aztec/aztec.js/utils';
|
|
10
11
|
import { ContractInitializationStatus } from '@aztec/aztec.js/wallet';
|
|
11
12
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
12
13
|
import { createExtendedL1Client } from '@aztec/ethereum/client';
|
|
@@ -18,12 +19,15 @@ import { AMMContract } from '@aztec/noir-contracts.js/AMM';
|
|
|
18
19
|
import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
|
|
19
20
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
20
21
|
import { TestContract } from '@aztec/noir-test-contracts.js/Test';
|
|
22
|
+
import { GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
21
23
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
22
24
|
import { SupportedTokenContracts } from './config.js';
|
|
23
25
|
import { seedL1ToL2Message } from './l1_to_l2_seeding.js';
|
|
24
26
|
import { getBalances, getPrivateBalance, isStandardTokenContract } from './utils.js';
|
|
25
27
|
const MINT_BALANCE = 1e12;
|
|
26
28
|
const MIN_BALANCE = 1e3;
|
|
29
|
+
const FEE_JUICE_TOP_UP_THRESHOLD = 100n * 10n ** 18n;
|
|
30
|
+
const FEE_JUICE_TOP_UP_TARGET = 10_000n * 10n ** 18n;
|
|
27
31
|
export class BotFactory {
|
|
28
32
|
config;
|
|
29
33
|
wallet;
|
|
@@ -48,7 +52,8 @@ export class BotFactory {
|
|
|
48
52
|
*/ async setup() {
|
|
49
53
|
const defaultAccountAddress = await this.setupAccount();
|
|
50
54
|
const recipient = (await this.wallet.createSchnorrAccount(Fr.random(), Fr.random())).address;
|
|
51
|
-
const token = await this.
|
|
55
|
+
const token = await this.setupTokenWithOptionalEarlyRefuel(defaultAccountAddress);
|
|
56
|
+
await this.ensureFeeJuiceBalance(defaultAccountAddress, token);
|
|
52
57
|
await this.mintTokens(token, defaultAccountAddress);
|
|
53
58
|
return {
|
|
54
59
|
wallet: this.wallet,
|
|
@@ -60,7 +65,8 @@ export class BotFactory {
|
|
|
60
65
|
}
|
|
61
66
|
async setupAmm() {
|
|
62
67
|
const defaultAccountAddress = await this.setupAccount();
|
|
63
|
-
const token0 = await this.
|
|
68
|
+
const token0 = await this.setupTokenContractWithOptionalEarlyRefuel(defaultAccountAddress, this.config.tokenSalt, 'BotToken0', 'BOT0');
|
|
69
|
+
await this.ensureFeeJuiceBalance(defaultAccountAddress, token0);
|
|
64
70
|
const token1 = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotToken1', 'BOT1');
|
|
65
71
|
const liquidityToken = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotLPToken', 'BOTLP');
|
|
66
72
|
const amm = await this.setupAmmContract(defaultAccountAddress, this.config.tokenSalt, token0, token1, liquidityToken);
|
|
@@ -190,12 +196,70 @@ export class BotFactory {
|
|
|
190
196
|
return accountManager.address;
|
|
191
197
|
}
|
|
192
198
|
/**
|
|
199
|
+
* Setup token and refuel first: if the token already exists (restart scenario),
|
|
200
|
+
* run ensureFeeJuiceBalance before any step that might need fee juice. When deploying,
|
|
201
|
+
* use a bridge claim if balance is below threshold.
|
|
202
|
+
*/ async setupTokenWithOptionalEarlyRefuel(sender) {
|
|
203
|
+
const token = await this.getTokenInstance(sender);
|
|
204
|
+
const address = token.address;
|
|
205
|
+
const metadata = await this.wallet.getContractMetadata(address);
|
|
206
|
+
if (metadata.isContractPublished) {
|
|
207
|
+
this.log.info(`Token at ${address.toString()} already deployed, refueling before setup`);
|
|
208
|
+
await this.ensureFeeJuiceBalance(sender, token);
|
|
209
|
+
}
|
|
210
|
+
return this.setupToken(sender);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Setup token0 for AMM with refuel-first behaviour when token already exists.
|
|
214
|
+
*/ async setupTokenContractWithOptionalEarlyRefuel(deployer, contractAddressSalt, name, ticker, decimals = 18) {
|
|
215
|
+
const deployOpts = {
|
|
216
|
+
from: deployer,
|
|
217
|
+
contractAddressSalt,
|
|
218
|
+
universalDeploy: true
|
|
219
|
+
};
|
|
220
|
+
const deploy = TokenContract.deploy(this.wallet, deployer, name, ticker, decimals);
|
|
221
|
+
const instance = await deploy.getInstance(deployOpts);
|
|
222
|
+
const metadata = await this.wallet.getContractMetadata(instance.address);
|
|
223
|
+
if (metadata.isContractPublished) {
|
|
224
|
+
this.log.info(`Token ${name} at ${instance.address.toString()} already deployed, refueling before setup`);
|
|
225
|
+
const token = TokenContract.at(instance.address, this.wallet);
|
|
226
|
+
await this.ensureFeeJuiceBalance(deployer, token);
|
|
227
|
+
}
|
|
228
|
+
return this.setupTokenContract(deployer, contractAddressSalt, name, ticker, decimals);
|
|
229
|
+
}
|
|
230
|
+
async getTokenInstance(sender) {
|
|
231
|
+
const deployOpts = {
|
|
232
|
+
from: sender,
|
|
233
|
+
contractAddressSalt: this.config.tokenSalt,
|
|
234
|
+
universalDeploy: true
|
|
235
|
+
};
|
|
236
|
+
if (this.config.contract === SupportedTokenContracts.TokenContract) {
|
|
237
|
+
const deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18);
|
|
238
|
+
const instance = await deploy.getInstance(deployOpts);
|
|
239
|
+
return TokenContract.at(instance.address, this.wallet);
|
|
240
|
+
}
|
|
241
|
+
if (this.config.contract === SupportedTokenContracts.PrivateTokenContract) {
|
|
242
|
+
const tokenSecretKey = Fr.random();
|
|
243
|
+
const tokenPublicKeys = (await deriveKeys(tokenSecretKey)).publicKeys;
|
|
244
|
+
const deploy = PrivateTokenContract.deployWithPublicKeys(tokenPublicKeys, this.wallet, MINT_BALANCE, sender);
|
|
245
|
+
const instance = await deploy.getInstance({
|
|
246
|
+
...deployOpts,
|
|
247
|
+
skipInstancePublication: true,
|
|
248
|
+
skipClassPublication: true,
|
|
249
|
+
skipInitialization: false
|
|
250
|
+
});
|
|
251
|
+
return PrivateTokenContract.at(instance.address, this.wallet);
|
|
252
|
+
}
|
|
253
|
+
throw new Error(`Unsupported token contract type: ${this.config.contract}`);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
193
256
|
* Checks if the token contract is deployed and deploys it if necessary.
|
|
194
|
-
*
|
|
195
|
-
* @
|
|
257
|
+
* Uses a bridge claim for deploy when balance is below threshold to avoid failing before refuel.
|
|
258
|
+
* @param sender - Aztec address to deploy the token contract from.
|
|
259
|
+
* @param existingToken - Optional token instance when called from setupTokenWithOptionalEarlyRefuel.
|
|
260
|
+
* @returns The TokenContract or PrivateTokenContract instance.
|
|
196
261
|
*/ async setupToken(sender) {
|
|
197
262
|
let deploy;
|
|
198
|
-
let tokenInstance;
|
|
199
263
|
const deployOpts = {
|
|
200
264
|
from: sender,
|
|
201
265
|
contractAddressSalt: this.config.tokenSalt,
|
|
@@ -204,8 +268,8 @@ export class BotFactory {
|
|
|
204
268
|
let token;
|
|
205
269
|
if (this.config.contract === SupportedTokenContracts.TokenContract) {
|
|
206
270
|
deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18);
|
|
207
|
-
|
|
208
|
-
token = TokenContract.at(
|
|
271
|
+
const instance = await deploy.getInstance(deployOpts);
|
|
272
|
+
token = TokenContract.at(instance.address, this.wallet);
|
|
209
273
|
} else if (this.config.contract === SupportedTokenContracts.PrivateTokenContract) {
|
|
210
274
|
// Generate keys for the contract since PrivateToken uses SinglePrivateMutable which requires keys
|
|
211
275
|
const tokenSecretKey = Fr.random();
|
|
@@ -215,7 +279,7 @@ export class BotFactory {
|
|
|
215
279
|
deployOpts.skipClassPublication = true;
|
|
216
280
|
deployOpts.skipInitialization = false;
|
|
217
281
|
// Register the contract with the secret key before deployment
|
|
218
|
-
tokenInstance = await deploy.getInstance(deployOpts);
|
|
282
|
+
const tokenInstance = await deploy.getInstance(deployOpts);
|
|
219
283
|
token = PrivateTokenContract.at(tokenInstance.address, this.wallet);
|
|
220
284
|
await this.wallet.registerContract(tokenInstance, PrivateTokenContract.artifact, tokenSecretKey);
|
|
221
285
|
// The contract constructor initializes private storage vars that need the contract's own nullifier key.
|
|
@@ -225,25 +289,7 @@ export class BotFactory {
|
|
|
225
289
|
} else {
|
|
226
290
|
throw new Error(`Unsupported token contract type: ${this.config.contract}`);
|
|
227
291
|
}
|
|
228
|
-
|
|
229
|
-
const metadata = await this.wallet.getContractMetadata(address);
|
|
230
|
-
if (metadata.isContractPublished) {
|
|
231
|
-
this.log.info(`Token at ${address.toString()} already deployed`);
|
|
232
|
-
await deploy.register();
|
|
233
|
-
} else {
|
|
234
|
-
this.log.info(`Deploying token contract at ${address.toString()}`);
|
|
235
|
-
const { txHash } = await deploy.send({
|
|
236
|
-
...deployOpts,
|
|
237
|
-
wait: NO_WAIT
|
|
238
|
-
});
|
|
239
|
-
this.log.info(`Sent tx for token setup with hash ${txHash.toString()}`);
|
|
240
|
-
await this.withNoMinTxsPerBlock(async ()=>{
|
|
241
|
-
await waitForTx(this.aztecNode, txHash, {
|
|
242
|
-
timeout: this.config.txMinedWaitSeconds
|
|
243
|
-
});
|
|
244
|
-
return token;
|
|
245
|
-
});
|
|
246
|
-
}
|
|
292
|
+
await this.registerOrDeployContract('token', deploy, deployOpts);
|
|
247
293
|
return token;
|
|
248
294
|
}
|
|
249
295
|
/**
|
|
@@ -345,24 +391,127 @@ export class BotFactory {
|
|
|
345
391
|
this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
|
|
346
392
|
await deploy.register();
|
|
347
393
|
} else {
|
|
348
|
-
|
|
349
|
-
await this.
|
|
350
|
-
|
|
394
|
+
const sender = deployOpts.from === NO_FROM ? undefined : deployOpts.from;
|
|
395
|
+
const balance = sender ? await getFeeJuiceBalance(sender, this.aztecNode) : 0n;
|
|
396
|
+
const useClaim = sender && balance < FEE_JUICE_TOP_UP_THRESHOLD && this.config.feePaymentMethod === 'fee_juice' && !!this.config.l1RpcUrls?.length;
|
|
397
|
+
const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
|
|
398
|
+
if (useClaim && mnemonicOrPrivateKey) {
|
|
399
|
+
const claim = await this.getOrCreateBridgeClaim(sender);
|
|
400
|
+
const paymentMethod = new FeeJuicePaymentMethodWithClaim(sender, claim);
|
|
401
|
+
const { estimatedGas } = await deploy.simulate({
|
|
351
402
|
...deployOpts,
|
|
352
|
-
|
|
403
|
+
fee: {
|
|
404
|
+
estimateGas: true,
|
|
405
|
+
paymentMethod
|
|
406
|
+
}
|
|
353
407
|
});
|
|
354
|
-
this.
|
|
355
|
-
|
|
356
|
-
|
|
408
|
+
const maxFeesPerGas = (await this.aztecNode.getCurrentMinFees()).mul(1 + this.config.minFeePadding);
|
|
409
|
+
const gasSettings = GasSettings.from({
|
|
410
|
+
...estimatedGas,
|
|
411
|
+
maxFeesPerGas,
|
|
412
|
+
maxPriorityFeesPerGas: GasFees.empty()
|
|
357
413
|
});
|
|
358
|
-
|
|
414
|
+
await this.withNoMinTxsPerBlock(async ()=>{
|
|
415
|
+
const { txHash } = await deploy.send({
|
|
416
|
+
...deployOpts,
|
|
417
|
+
fee: {
|
|
418
|
+
gasSettings,
|
|
419
|
+
paymentMethod
|
|
420
|
+
},
|
|
421
|
+
wait: NO_WAIT
|
|
422
|
+
});
|
|
423
|
+
this.log.info(`Sent contract ${name} deploy tx ${txHash.toString()} (using bridge claim, balance was ${balance})`);
|
|
424
|
+
return waitForTx(this.aztecNode, txHash, {
|
|
425
|
+
timeout: this.config.txMinedWaitSeconds
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
await this.store.deleteBridgeClaim(sender);
|
|
429
|
+
} else {
|
|
430
|
+
const { estimatedGas } = await deploy.simulate({
|
|
431
|
+
...deployOpts,
|
|
432
|
+
fee: {
|
|
433
|
+
estimateGas: true
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
this.log.info(`Deploying contract ${name} at ${address.toString()}`, {
|
|
437
|
+
estimatedGas
|
|
438
|
+
});
|
|
439
|
+
await this.withNoMinTxsPerBlock(async ()=>{
|
|
440
|
+
const { txHash } = await deploy.send({
|
|
441
|
+
...deployOpts,
|
|
442
|
+
fee: {
|
|
443
|
+
gasSettings: estimatedGas
|
|
444
|
+
},
|
|
445
|
+
wait: NO_WAIT
|
|
446
|
+
});
|
|
447
|
+
this.log.info(`Sent contract ${name} setup tx with hash ${txHash.toString()}`);
|
|
448
|
+
return waitForTx(this.aztecNode, txHash, {
|
|
449
|
+
timeout: this.config.txMinedWaitSeconds
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
}
|
|
359
453
|
}
|
|
360
454
|
return instance;
|
|
361
455
|
}
|
|
362
456
|
/**
|
|
363
457
|
* Mints private and public tokens for the sender if their balance is below the minimum.
|
|
364
458
|
* @param token - Token contract.
|
|
365
|
-
*/
|
|
459
|
+
*/ /**
|
|
460
|
+
* Ensures the account has sufficient fee juice by bridging from L1 if balance is below threshold.
|
|
461
|
+
* Bridges repeatedly until balance reaches the target (10k FJ).
|
|
462
|
+
* Used on startup/restart to top up when the account has run out after previous runs.
|
|
463
|
+
*/ async ensureFeeJuiceBalance(account, token) {
|
|
464
|
+
const { feePaymentMethod, l1RpcUrls } = this.config;
|
|
465
|
+
if (feePaymentMethod !== 'fee_juice' || !l1RpcUrls?.length) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
|
|
469
|
+
if (!mnemonicOrPrivateKey) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
let balance = await getFeeJuiceBalance(account, this.aztecNode);
|
|
473
|
+
if (balance >= FEE_JUICE_TOP_UP_THRESHOLD) {
|
|
474
|
+
this.log.info(`Fee juice balance ${balance} above threshold ${FEE_JUICE_TOP_UP_THRESHOLD}, skipping top-up`);
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
this.log.info(`Fee juice balance ${balance} below threshold ${FEE_JUICE_TOP_UP_THRESHOLD}, bridging from L1 until ${FEE_JUICE_TOP_UP_TARGET}`);
|
|
478
|
+
const maxFeesPerGas = (await this.aztecNode.getCurrentMinFees()).mul(1 + this.config.minFeePadding);
|
|
479
|
+
const minimalInteraction = isStandardTokenContract(token) ? token.methods.transfer_in_public(account, account, 0n, 0) : token.methods.transfer(0n, account, account);
|
|
480
|
+
while(balance < FEE_JUICE_TOP_UP_TARGET){
|
|
481
|
+
const claim = await this.bridgeL1FeeJuice(account);
|
|
482
|
+
const paymentMethod = new FeeJuicePaymentMethodWithClaim(account, claim);
|
|
483
|
+
const { estimatedGas } = await minimalInteraction.simulate({
|
|
484
|
+
from: account,
|
|
485
|
+
fee: {
|
|
486
|
+
estimateGas: true,
|
|
487
|
+
paymentMethod
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
const gasSettings = GasSettings.from({
|
|
491
|
+
...estimatedGas,
|
|
492
|
+
maxFeesPerGas,
|
|
493
|
+
maxPriorityFeesPerGas: GasFees.empty()
|
|
494
|
+
});
|
|
495
|
+
await this.withNoMinTxsPerBlock(async ()=>{
|
|
496
|
+
const { txHash } = await minimalInteraction.send({
|
|
497
|
+
from: account,
|
|
498
|
+
fee: {
|
|
499
|
+
gasSettings,
|
|
500
|
+
paymentMethod
|
|
501
|
+
},
|
|
502
|
+
wait: NO_WAIT
|
|
503
|
+
});
|
|
504
|
+
this.log.info(`Sent fee juice top-up tx ${txHash.toString()}`);
|
|
505
|
+
return waitForTx(this.aztecNode, txHash, {
|
|
506
|
+
timeout: this.config.txMinedWaitSeconds
|
|
507
|
+
});
|
|
508
|
+
});
|
|
509
|
+
balance = await getFeeJuiceBalance(account, this.aztecNode);
|
|
510
|
+
this.log.info(`Fee juice balance after top-up: ${balance}`);
|
|
511
|
+
}
|
|
512
|
+
this.log.info(`Fee juice top-up complete for ${account.toString()}`);
|
|
513
|
+
}
|
|
514
|
+
async mintTokens(token, minter) {
|
|
366
515
|
const isStandardToken = isStandardTokenContract(token);
|
|
367
516
|
let privateBalance = 0n;
|
|
368
517
|
let publicBalance = 0n;
|
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.20260410",
|
|
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.20260410",
|
|
58
|
+
"@aztec/aztec.js": "5.0.0-nightly.20260410",
|
|
59
|
+
"@aztec/entrypoints": "5.0.0-nightly.20260410",
|
|
60
|
+
"@aztec/ethereum": "5.0.0-nightly.20260410",
|
|
61
|
+
"@aztec/foundation": "5.0.0-nightly.20260410",
|
|
62
|
+
"@aztec/kv-store": "5.0.0-nightly.20260410",
|
|
63
|
+
"@aztec/l1-artifacts": "5.0.0-nightly.20260410",
|
|
64
|
+
"@aztec/noir-contracts.js": "5.0.0-nightly.20260410",
|
|
65
|
+
"@aztec/noir-protocol-circuits-types": "5.0.0-nightly.20260410",
|
|
66
|
+
"@aztec/noir-test-contracts.js": "5.0.0-nightly.20260410",
|
|
67
|
+
"@aztec/protocol-contracts": "5.0.0-nightly.20260410",
|
|
68
|
+
"@aztec/stdlib": "5.0.0-nightly.20260410",
|
|
69
|
+
"@aztec/telemetry-client": "5.0.0-nightly.20260410",
|
|
70
|
+
"@aztec/wallets": "5.0.0-nightly.20260410",
|
|
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
|
@@ -16,6 +16,7 @@ import { deriveKeys } from '@aztec/aztec.js/keys';
|
|
|
16
16
|
import { createLogger } from '@aztec/aztec.js/log';
|
|
17
17
|
import { waitForL1ToL2MessageReady } from '@aztec/aztec.js/messaging';
|
|
18
18
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
19
|
+
import { getFeeJuiceBalance } from '@aztec/aztec.js/utils';
|
|
19
20
|
import { ContractInitializationStatus } from '@aztec/aztec.js/wallet';
|
|
20
21
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
21
22
|
import { createExtendedL1Client } from '@aztec/ethereum/client';
|
|
@@ -29,6 +30,7 @@ import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
|
|
|
29
30
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
30
31
|
import { TestContract } from '@aztec/noir-test-contracts.js/Test';
|
|
31
32
|
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
33
|
+
import { GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
32
34
|
import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
33
35
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
34
36
|
import { EmbeddedWallet } from '@aztec/wallets/embedded';
|
|
@@ -40,6 +42,8 @@ import { getBalances, getPrivateBalance, isStandardTokenContract } from './utils
|
|
|
40
42
|
|
|
41
43
|
const MINT_BALANCE = 1e12;
|
|
42
44
|
const MIN_BALANCE = 1e3;
|
|
45
|
+
const FEE_JUICE_TOP_UP_THRESHOLD = 100n * 10n ** 18n;
|
|
46
|
+
const FEE_JUICE_TOP_UP_TARGET = 10_000n * 10n ** 18n;
|
|
43
47
|
|
|
44
48
|
export class BotFactory {
|
|
45
49
|
private log = createLogger('bot');
|
|
@@ -69,7 +73,8 @@ export class BotFactory {
|
|
|
69
73
|
}> {
|
|
70
74
|
const defaultAccountAddress = await this.setupAccount();
|
|
71
75
|
const recipient = (await this.wallet.createSchnorrAccount(Fr.random(), Fr.random())).address;
|
|
72
|
-
const token = await this.
|
|
76
|
+
const token = await this.setupTokenWithOptionalEarlyRefuel(defaultAccountAddress);
|
|
77
|
+
await this.ensureFeeJuiceBalance(defaultAccountAddress, token);
|
|
73
78
|
await this.mintTokens(token, defaultAccountAddress);
|
|
74
79
|
return { wallet: this.wallet, defaultAccountAddress, token, node: this.aztecNode, recipient };
|
|
75
80
|
}
|
|
@@ -83,7 +88,13 @@ export class BotFactory {
|
|
|
83
88
|
node: AztecNode;
|
|
84
89
|
}> {
|
|
85
90
|
const defaultAccountAddress = await this.setupAccount();
|
|
86
|
-
const token0 = await this.
|
|
91
|
+
const token0 = await this.setupTokenContractWithOptionalEarlyRefuel(
|
|
92
|
+
defaultAccountAddress,
|
|
93
|
+
this.config.tokenSalt,
|
|
94
|
+
'BotToken0',
|
|
95
|
+
'BOT0',
|
|
96
|
+
);
|
|
97
|
+
await this.ensureFeeJuiceBalance(defaultAccountAddress, token0);
|
|
87
98
|
const token1 = await this.setupTokenContract(defaultAccountAddress, this.config.tokenSalt, 'BotToken1', 'BOT1');
|
|
88
99
|
const liquidityToken = await this.setupTokenContract(
|
|
89
100
|
defaultAccountAddress,
|
|
@@ -252,14 +263,79 @@ export class BotFactory {
|
|
|
252
263
|
return accountManager.address;
|
|
253
264
|
}
|
|
254
265
|
|
|
266
|
+
/**
|
|
267
|
+
* Setup token and refuel first: if the token already exists (restart scenario),
|
|
268
|
+
* run ensureFeeJuiceBalance before any step that might need fee juice. When deploying,
|
|
269
|
+
* use a bridge claim if balance is below threshold.
|
|
270
|
+
*/
|
|
271
|
+
private async setupTokenWithOptionalEarlyRefuel(sender: AztecAddress): Promise<TokenContract | PrivateTokenContract> {
|
|
272
|
+
const token = await this.getTokenInstance(sender);
|
|
273
|
+
const address = token.address;
|
|
274
|
+
const metadata = await this.wallet.getContractMetadata(address);
|
|
275
|
+
if (metadata.isContractPublished) {
|
|
276
|
+
this.log.info(`Token at ${address.toString()} already deployed, refueling before setup`);
|
|
277
|
+
await this.ensureFeeJuiceBalance(sender, token);
|
|
278
|
+
}
|
|
279
|
+
return this.setupToken(sender);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Setup token0 for AMM with refuel-first behaviour when token already exists.
|
|
284
|
+
*/
|
|
285
|
+
private async setupTokenContractWithOptionalEarlyRefuel(
|
|
286
|
+
deployer: AztecAddress,
|
|
287
|
+
contractAddressSalt: Fr,
|
|
288
|
+
name: string,
|
|
289
|
+
ticker: string,
|
|
290
|
+
decimals = 18,
|
|
291
|
+
): Promise<TokenContract> {
|
|
292
|
+
const deployOpts: DeployOptions = { from: deployer, contractAddressSalt, universalDeploy: true };
|
|
293
|
+
const deploy = TokenContract.deploy(this.wallet, deployer, name, ticker, decimals);
|
|
294
|
+
const instance = await deploy.getInstance(deployOpts);
|
|
295
|
+
const metadata = await this.wallet.getContractMetadata(instance.address);
|
|
296
|
+
if (metadata.isContractPublished) {
|
|
297
|
+
this.log.info(`Token ${name} at ${instance.address.toString()} already deployed, refueling before setup`);
|
|
298
|
+
const token = TokenContract.at(instance.address, this.wallet);
|
|
299
|
+
await this.ensureFeeJuiceBalance(deployer, token);
|
|
300
|
+
}
|
|
301
|
+
return this.setupTokenContract(deployer, contractAddressSalt, name, ticker, decimals);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
private async getTokenInstance(sender: AztecAddress): Promise<TokenContract | PrivateTokenContract> {
|
|
305
|
+
const deployOpts: DeployOptions = {
|
|
306
|
+
from: sender,
|
|
307
|
+
contractAddressSalt: this.config.tokenSalt,
|
|
308
|
+
universalDeploy: true,
|
|
309
|
+
};
|
|
310
|
+
if (this.config.contract === SupportedTokenContracts.TokenContract) {
|
|
311
|
+
const deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18);
|
|
312
|
+
const instance = await deploy.getInstance(deployOpts);
|
|
313
|
+
return TokenContract.at(instance.address, this.wallet);
|
|
314
|
+
}
|
|
315
|
+
if (this.config.contract === SupportedTokenContracts.PrivateTokenContract) {
|
|
316
|
+
const tokenSecretKey = Fr.random();
|
|
317
|
+
const tokenPublicKeys = (await deriveKeys(tokenSecretKey)).publicKeys;
|
|
318
|
+
const deploy = PrivateTokenContract.deployWithPublicKeys(tokenPublicKeys, this.wallet, MINT_BALANCE, sender);
|
|
319
|
+
const instance = await deploy.getInstance({
|
|
320
|
+
...deployOpts,
|
|
321
|
+
skipInstancePublication: true,
|
|
322
|
+
skipClassPublication: true,
|
|
323
|
+
skipInitialization: false,
|
|
324
|
+
});
|
|
325
|
+
return PrivateTokenContract.at(instance.address, this.wallet);
|
|
326
|
+
}
|
|
327
|
+
throw new Error(`Unsupported token contract type: ${this.config.contract}`);
|
|
328
|
+
}
|
|
329
|
+
|
|
255
330
|
/**
|
|
256
331
|
* Checks if the token contract is deployed and deploys it if necessary.
|
|
257
|
-
*
|
|
258
|
-
* @
|
|
332
|
+
* Uses a bridge claim for deploy when balance is below threshold to avoid failing before refuel.
|
|
333
|
+
* @param sender - Aztec address to deploy the token contract from.
|
|
334
|
+
* @param existingToken - Optional token instance when called from setupTokenWithOptionalEarlyRefuel.
|
|
335
|
+
* @returns The TokenContract or PrivateTokenContract instance.
|
|
259
336
|
*/
|
|
260
337
|
private async setupToken(sender: AztecAddress): Promise<TokenContract | PrivateTokenContract> {
|
|
261
338
|
let deploy: DeployMethod<TokenContract | PrivateTokenContract>;
|
|
262
|
-
let tokenInstance: ContractInstanceWithAddress | undefined;
|
|
263
339
|
const deployOpts: DeployOptions = {
|
|
264
340
|
from: sender,
|
|
265
341
|
contractAddressSalt: this.config.tokenSalt,
|
|
@@ -268,8 +344,8 @@ export class BotFactory {
|
|
|
268
344
|
let token: TokenContract | PrivateTokenContract;
|
|
269
345
|
if (this.config.contract === SupportedTokenContracts.TokenContract) {
|
|
270
346
|
deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18);
|
|
271
|
-
|
|
272
|
-
token = TokenContract.at(
|
|
347
|
+
const instance = await deploy.getInstance(deployOpts);
|
|
348
|
+
token = TokenContract.at(instance.address, this.wallet);
|
|
273
349
|
} else if (this.config.contract === SupportedTokenContracts.PrivateTokenContract) {
|
|
274
350
|
// Generate keys for the contract since PrivateToken uses SinglePrivateMutable which requires keys
|
|
275
351
|
const tokenSecretKey = Fr.random();
|
|
@@ -280,7 +356,7 @@ export class BotFactory {
|
|
|
280
356
|
deployOpts.skipInitialization = false;
|
|
281
357
|
|
|
282
358
|
// Register the contract with the secret key before deployment
|
|
283
|
-
tokenInstance = await deploy.getInstance(deployOpts);
|
|
359
|
+
const tokenInstance = await deploy.getInstance(deployOpts);
|
|
284
360
|
token = PrivateTokenContract.at(tokenInstance.address, this.wallet);
|
|
285
361
|
await this.wallet.registerContract(tokenInstance, PrivateTokenContract.artifact, tokenSecretKey);
|
|
286
362
|
// The contract constructor initializes private storage vars that need the contract's own nullifier key.
|
|
@@ -289,20 +365,7 @@ export class BotFactory {
|
|
|
289
365
|
throw new Error(`Unsupported token contract type: ${this.config.contract}`);
|
|
290
366
|
}
|
|
291
367
|
|
|
292
|
-
|
|
293
|
-
const metadata = await this.wallet.getContractMetadata(address);
|
|
294
|
-
if (metadata.isContractPublished) {
|
|
295
|
-
this.log.info(`Token at ${address.toString()} already deployed`);
|
|
296
|
-
await deploy.register();
|
|
297
|
-
} else {
|
|
298
|
-
this.log.info(`Deploying token contract at ${address.toString()}`);
|
|
299
|
-
const { txHash } = await deploy.send({ ...deployOpts, wait: NO_WAIT });
|
|
300
|
-
this.log.info(`Sent tx for token setup with hash ${txHash.toString()}`);
|
|
301
|
-
await this.withNoMinTxsPerBlock(async () => {
|
|
302
|
-
await waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
|
|
303
|
-
return token;
|
|
304
|
-
});
|
|
305
|
-
}
|
|
368
|
+
await this.registerOrDeployContract('token', deploy, deployOpts);
|
|
306
369
|
return token;
|
|
307
370
|
}
|
|
308
371
|
|
|
@@ -455,12 +518,42 @@ export class BotFactory {
|
|
|
455
518
|
this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
|
|
456
519
|
await deploy.register();
|
|
457
520
|
} else {
|
|
458
|
-
|
|
459
|
-
await this.
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
521
|
+
const sender = deployOpts.from === NO_FROM ? undefined : deployOpts.from;
|
|
522
|
+
const balance = sender ? await getFeeJuiceBalance(sender, this.aztecNode) : 0n;
|
|
523
|
+
const useClaim =
|
|
524
|
+
sender &&
|
|
525
|
+
balance < FEE_JUICE_TOP_UP_THRESHOLD &&
|
|
526
|
+
this.config.feePaymentMethod === 'fee_juice' &&
|
|
527
|
+
!!this.config.l1RpcUrls?.length;
|
|
528
|
+
const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
|
|
529
|
+
|
|
530
|
+
if (useClaim && mnemonicOrPrivateKey) {
|
|
531
|
+
const claim = await this.getOrCreateBridgeClaim(sender!);
|
|
532
|
+
const paymentMethod = new FeeJuicePaymentMethodWithClaim(sender!, claim);
|
|
533
|
+
const { estimatedGas } = await deploy.simulate({ ...deployOpts, fee: { estimateGas: true, paymentMethod } });
|
|
534
|
+
const maxFeesPerGas = (await this.aztecNode.getCurrentMinFees()).mul(1 + this.config.minFeePadding);
|
|
535
|
+
const gasSettings = GasSettings.from({
|
|
536
|
+
...estimatedGas!,
|
|
537
|
+
maxFeesPerGas,
|
|
538
|
+
maxPriorityFeesPerGas: GasFees.empty(),
|
|
539
|
+
});
|
|
540
|
+
await this.withNoMinTxsPerBlock(async () => {
|
|
541
|
+
const { txHash } = await deploy.send({ ...deployOpts, fee: { gasSettings, paymentMethod }, wait: NO_WAIT });
|
|
542
|
+
this.log.info(
|
|
543
|
+
`Sent contract ${name} deploy tx ${txHash.toString()} (using bridge claim, balance was ${balance})`,
|
|
544
|
+
);
|
|
545
|
+
return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
|
|
546
|
+
});
|
|
547
|
+
await this.store.deleteBridgeClaim(sender!);
|
|
548
|
+
} else {
|
|
549
|
+
const { estimatedGas } = await deploy.simulate({ ...deployOpts, fee: { estimateGas: true } });
|
|
550
|
+
this.log.info(`Deploying contract ${name} at ${address.toString()}`, { estimatedGas });
|
|
551
|
+
await this.withNoMinTxsPerBlock(async () => {
|
|
552
|
+
const { txHash } = await deploy.send({ ...deployOpts, fee: { gasSettings: estimatedGas }, wait: NO_WAIT });
|
|
553
|
+
this.log.info(`Sent contract ${name} setup tx with hash ${txHash.toString()}`);
|
|
554
|
+
return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
|
|
555
|
+
});
|
|
556
|
+
}
|
|
464
557
|
}
|
|
465
558
|
return instance;
|
|
466
559
|
}
|
|
@@ -469,6 +562,66 @@ export class BotFactory {
|
|
|
469
562
|
* Mints private and public tokens for the sender if their balance is below the minimum.
|
|
470
563
|
* @param token - Token contract.
|
|
471
564
|
*/
|
|
565
|
+
/**
|
|
566
|
+
* Ensures the account has sufficient fee juice by bridging from L1 if balance is below threshold.
|
|
567
|
+
* Bridges repeatedly until balance reaches the target (10k FJ).
|
|
568
|
+
* Used on startup/restart to top up when the account has run out after previous runs.
|
|
569
|
+
*/
|
|
570
|
+
private async ensureFeeJuiceBalance(
|
|
571
|
+
account: AztecAddress,
|
|
572
|
+
token: TokenContract | PrivateTokenContract,
|
|
573
|
+
): Promise<void> {
|
|
574
|
+
const { feePaymentMethod, l1RpcUrls } = this.config;
|
|
575
|
+
if (feePaymentMethod !== 'fee_juice' || !l1RpcUrls?.length) {
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
|
|
579
|
+
if (!mnemonicOrPrivateKey) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
let balance = await getFeeJuiceBalance(account, this.aztecNode);
|
|
584
|
+
if (balance >= FEE_JUICE_TOP_UP_THRESHOLD) {
|
|
585
|
+
this.log.info(`Fee juice balance ${balance} above threshold ${FEE_JUICE_TOP_UP_THRESHOLD}, skipping top-up`);
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
this.log.info(
|
|
590
|
+
`Fee juice balance ${balance} below threshold ${FEE_JUICE_TOP_UP_THRESHOLD}, bridging from L1 until ${FEE_JUICE_TOP_UP_TARGET}`,
|
|
591
|
+
);
|
|
592
|
+
const maxFeesPerGas = (await this.aztecNode.getCurrentMinFees()).mul(1 + this.config.minFeePadding);
|
|
593
|
+
const minimalInteraction = isStandardTokenContract(token)
|
|
594
|
+
? token.methods.transfer_in_public(account, account, 0n, 0)
|
|
595
|
+
: token.methods.transfer(0n, account, account);
|
|
596
|
+
|
|
597
|
+
while (balance < FEE_JUICE_TOP_UP_TARGET) {
|
|
598
|
+
const claim = await this.bridgeL1FeeJuice(account);
|
|
599
|
+
const paymentMethod = new FeeJuicePaymentMethodWithClaim(account, claim);
|
|
600
|
+
const { estimatedGas } = await minimalInteraction.simulate({
|
|
601
|
+
from: account,
|
|
602
|
+
fee: { estimateGas: true, paymentMethod },
|
|
603
|
+
});
|
|
604
|
+
const gasSettings = GasSettings.from({
|
|
605
|
+
...estimatedGas!,
|
|
606
|
+
maxFeesPerGas,
|
|
607
|
+
maxPriorityFeesPerGas: GasFees.empty(),
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
await this.withNoMinTxsPerBlock(async () => {
|
|
611
|
+
const { txHash } = await minimalInteraction.send({
|
|
612
|
+
from: account,
|
|
613
|
+
fee: { gasSettings, paymentMethod },
|
|
614
|
+
wait: NO_WAIT,
|
|
615
|
+
});
|
|
616
|
+
this.log.info(`Sent fee juice top-up tx ${txHash.toString()}`);
|
|
617
|
+
return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
|
|
618
|
+
});
|
|
619
|
+
balance = await getFeeJuiceBalance(account, this.aztecNode);
|
|
620
|
+
this.log.info(`Fee juice balance after top-up: ${balance}`);
|
|
621
|
+
}
|
|
622
|
+
this.log.info(`Fee juice top-up complete for ${account.toString()}`);
|
|
623
|
+
}
|
|
624
|
+
|
|
472
625
|
private async mintTokens(token: TokenContract | PrivateTokenContract, minter: AztecAddress) {
|
|
473
626
|
const isStandardToken = isStandardTokenContract(token);
|
|
474
627
|
let privateBalance = 0n;
|