@aztec/bot 0.0.1-commit.f504929 → 0.0.1-commit.f650c0a5c
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/amm_bot.js +1 -1
- package/dest/base_bot.d.ts +3 -3
- package/dest/base_bot.d.ts.map +1 -1
- package/dest/base_bot.js +12 -22
- package/dest/bot.d.ts +1 -1
- package/dest/bot.d.ts.map +1 -1
- package/dest/bot.js +1 -5
- package/dest/config.d.ts +5 -5
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +3 -4
- package/dest/cross_chain_bot.d.ts +1 -1
- package/dest/cross_chain_bot.d.ts.map +1 -1
- package/dest/cross_chain_bot.js +2 -9
- package/dest/factory.d.ts +5 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +201 -60
- package/package.json +15 -15
- package/src/amm_bot.ts +1 -1
- package/src/base_bot.ts +8 -16
- package/src/bot.ts +1 -4
- package/src/config.ts +5 -6
- package/src/cross_chain_bot.ts +2 -9
- package/src/factory.ts +211 -54
package/dest/factory.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getInitialTestAccountsData } from '@aztec/accounts/testing';
|
|
2
|
-
import {
|
|
2
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
3
3
|
import { BatchCall, NO_WAIT } from '@aztec/aztec.js/contracts';
|
|
4
4
|
import { L1FeeJuicePortalManager } from '@aztec/aztec.js/ethereum';
|
|
5
5
|
import { FeeJuicePaymentMethodWithClaim } from '@aztec/aztec.js/fee';
|
|
@@ -7,6 +7,8 @@ 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';
|
|
11
|
+
import { ContractInitializationStatus } from '@aztec/aztec.js/wallet';
|
|
10
12
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
11
13
|
import { createExtendedL1Client } from '@aztec/ethereum/client';
|
|
12
14
|
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
@@ -17,13 +19,15 @@ import { AMMContract } from '@aztec/noir-contracts.js/AMM';
|
|
|
17
19
|
import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
|
|
18
20
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
19
21
|
import { TestContract } from '@aztec/noir-test-contracts.js/Test';
|
|
20
|
-
import { GasSettings } from '@aztec/stdlib/gas';
|
|
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);
|
|
@@ -111,12 +117,7 @@ export class BotFactory {
|
|
|
111
117
|
this.log.info(`Waiting for first L1→L2 message to be ready...`);
|
|
112
118
|
const firstMsg = allMessages[0];
|
|
113
119
|
await waitForL1ToL2MessageReady(this.aztecNode, Fr.fromHexString(firstMsg.msgHash), {
|
|
114
|
-
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
115
|
-
// Use forPublicConsumption: false so we wait until the message is in the current world
|
|
116
|
-
// state. With true, it returns one block early which causes gas estimation simulation to
|
|
117
|
-
// fail since it runs against the current state.
|
|
118
|
-
// See https://linear.app/aztec-labs/issue/A-548 for details.
|
|
119
|
-
forPublicConsumption: false
|
|
120
|
+
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
120
121
|
});
|
|
121
122
|
this.log.info(`First L1→L2 message is ready`);
|
|
122
123
|
}
|
|
@@ -157,7 +158,7 @@ export class BotFactory {
|
|
|
157
158
|
const signingKey = deriveSigningKey(secret);
|
|
158
159
|
const accountManager = await this.wallet.createSchnorrAccount(secret, salt, signingKey);
|
|
159
160
|
const metadata = await this.wallet.getContractMetadata(accountManager.address);
|
|
160
|
-
if (metadata.
|
|
161
|
+
if (metadata.initializationStatus === ContractInitializationStatus.INITIALIZED) {
|
|
161
162
|
this.log.info(`Account at ${accountManager.address.toString()} already initialized`);
|
|
162
163
|
const timer = new Timer();
|
|
163
164
|
const address = accountManager.address;
|
|
@@ -170,15 +171,10 @@ export class BotFactory {
|
|
|
170
171
|
const claim = await this.getOrCreateBridgeClaim(address);
|
|
171
172
|
const paymentMethod = new FeeJuicePaymentMethodWithClaim(accountManager.address, claim);
|
|
172
173
|
const deployMethod = await accountManager.getDeployMethod();
|
|
173
|
-
const maxFeesPerGas = (await this.aztecNode.getCurrentMinFees()).mul(1 + this.config.minFeePadding);
|
|
174
|
-
const gasSettings = GasSettings.default({
|
|
175
|
-
maxFeesPerGas
|
|
176
|
-
});
|
|
177
174
|
await this.withNoMinTxsPerBlock(async ()=>{
|
|
178
175
|
const { txHash } = await deployMethod.send({
|
|
179
|
-
from:
|
|
176
|
+
from: NO_FROM,
|
|
180
177
|
fee: {
|
|
181
|
-
gasSettings,
|
|
182
178
|
paymentMethod
|
|
183
179
|
},
|
|
184
180
|
wait: NO_WAIT
|
|
@@ -200,12 +196,70 @@ export class BotFactory {
|
|
|
200
196
|
return accountManager.address;
|
|
201
197
|
}
|
|
202
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
|
+
/**
|
|
203
256
|
* Checks if the token contract is deployed and deploys it if necessary.
|
|
204
|
-
*
|
|
205
|
-
* @
|
|
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.
|
|
206
261
|
*/ async setupToken(sender) {
|
|
207
262
|
let deploy;
|
|
208
|
-
let tokenInstance;
|
|
209
263
|
const deployOpts = {
|
|
210
264
|
from: sender,
|
|
211
265
|
contractAddressSalt: this.config.tokenSalt,
|
|
@@ -214,8 +268,8 @@ export class BotFactory {
|
|
|
214
268
|
let token;
|
|
215
269
|
if (this.config.contract === SupportedTokenContracts.TokenContract) {
|
|
216
270
|
deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18);
|
|
217
|
-
|
|
218
|
-
token = TokenContract.at(
|
|
271
|
+
const instance = await deploy.getInstance(deployOpts);
|
|
272
|
+
token = TokenContract.at(instance.address, this.wallet);
|
|
219
273
|
} else if (this.config.contract === SupportedTokenContracts.PrivateTokenContract) {
|
|
220
274
|
// Generate keys for the contract since PrivateToken uses SinglePrivateMutable which requires keys
|
|
221
275
|
const tokenSecretKey = Fr.random();
|
|
@@ -225,7 +279,7 @@ export class BotFactory {
|
|
|
225
279
|
deployOpts.skipClassPublication = true;
|
|
226
280
|
deployOpts.skipInitialization = false;
|
|
227
281
|
// Register the contract with the secret key before deployment
|
|
228
|
-
tokenInstance = await deploy.getInstance(deployOpts);
|
|
282
|
+
const tokenInstance = await deploy.getInstance(deployOpts);
|
|
229
283
|
token = PrivateTokenContract.at(tokenInstance.address, this.wallet);
|
|
230
284
|
await this.wallet.registerContract(tokenInstance, PrivateTokenContract.artifact, tokenSecretKey);
|
|
231
285
|
// The contract constructor initializes private storage vars that need the contract's own nullifier key.
|
|
@@ -235,25 +289,7 @@ export class BotFactory {
|
|
|
235
289
|
} else {
|
|
236
290
|
throw new Error(`Unsupported token contract type: ${this.config.contract}`);
|
|
237
291
|
}
|
|
238
|
-
|
|
239
|
-
const metadata = await this.wallet.getContractMetadata(address);
|
|
240
|
-
if (metadata.isContractPublished) {
|
|
241
|
-
this.log.info(`Token at ${address.toString()} already deployed`);
|
|
242
|
-
await deploy.register();
|
|
243
|
-
} else {
|
|
244
|
-
this.log.info(`Deploying token contract at ${address.toString()}`);
|
|
245
|
-
const { txHash } = await deploy.send({
|
|
246
|
-
...deployOpts,
|
|
247
|
-
wait: NO_WAIT
|
|
248
|
-
});
|
|
249
|
-
this.log.info(`Sent tx for token setup with hash ${txHash.toString()}`);
|
|
250
|
-
await this.withNoMinTxsPerBlock(async ()=>{
|
|
251
|
-
await waitForTx(this.aztecNode, txHash, {
|
|
252
|
-
timeout: this.config.txMinedWaitSeconds
|
|
253
|
-
});
|
|
254
|
-
return token;
|
|
255
|
-
});
|
|
256
|
-
}
|
|
292
|
+
await this.registerOrDeployContract('token', deploy, deployOpts);
|
|
257
293
|
return token;
|
|
258
294
|
}
|
|
259
295
|
/**
|
|
@@ -280,7 +316,8 @@ export class BotFactory {
|
|
|
280
316
|
const instance = await this.registerOrDeployContract('AMM', deploy, deployOpts);
|
|
281
317
|
const amm = AMMContract.at(instance.address, this.wallet);
|
|
282
318
|
this.log.info(`AMM deployed at ${amm.address}`);
|
|
283
|
-
const
|
|
319
|
+
const setMinterInteraction = lpToken.methods.set_minter(amm.address, true);
|
|
320
|
+
const { receipt: minterReceipt } = await setMinterInteraction.send({
|
|
284
321
|
from: deployer,
|
|
285
322
|
wait: {
|
|
286
323
|
timeout: this.config.txMinedWaitSeconds
|
|
@@ -319,17 +356,19 @@ export class BotFactory {
|
|
|
319
356
|
caller: amm.address,
|
|
320
357
|
call: await token1.methods.transfer_to_public_and_prepare_private_balance_increase(liquidityProvider, amm.address, amount1Max, authwitNonce).getFunctionCall()
|
|
321
358
|
});
|
|
322
|
-
const
|
|
359
|
+
const mintBatch = new BatchCall(this.wallet, [
|
|
323
360
|
token0.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
|
|
324
361
|
token1.methods.mint_to_private(liquidityProvider, MINT_BALANCE)
|
|
325
|
-
])
|
|
362
|
+
]);
|
|
363
|
+
const { receipt: mintReceipt } = await mintBatch.send({
|
|
326
364
|
from: liquidityProvider,
|
|
327
365
|
wait: {
|
|
328
366
|
timeout: this.config.txMinedWaitSeconds
|
|
329
367
|
}
|
|
330
368
|
});
|
|
331
369
|
this.log.info(`Sent mint tx: ${mintReceipt.txHash.toString()}`);
|
|
332
|
-
const
|
|
370
|
+
const addLiquidityInteraction = amm.methods.add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, authwitNonce);
|
|
371
|
+
const { receipt: addLiquidityReceipt } = await addLiquidityInteraction.send({
|
|
333
372
|
from: liquidityProvider,
|
|
334
373
|
authWitnesses: [
|
|
335
374
|
token0Authwit,
|
|
@@ -352,24 +391,127 @@ export class BotFactory {
|
|
|
352
391
|
this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
|
|
353
392
|
await deploy.register();
|
|
354
393
|
} else {
|
|
355
|
-
|
|
356
|
-
await this.
|
|
357
|
-
|
|
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({
|
|
358
402
|
...deployOpts,
|
|
359
|
-
|
|
403
|
+
fee: {
|
|
404
|
+
estimateGas: true,
|
|
405
|
+
paymentMethod
|
|
406
|
+
}
|
|
360
407
|
});
|
|
361
|
-
this.
|
|
362
|
-
|
|
363
|
-
|
|
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()
|
|
364
413
|
});
|
|
365
|
-
|
|
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
|
+
}
|
|
366
453
|
}
|
|
367
454
|
return instance;
|
|
368
455
|
}
|
|
369
456
|
/**
|
|
370
457
|
* Mints private and public tokens for the sender if their balance is below the minimum.
|
|
371
458
|
* @param token - Token contract.
|
|
372
|
-
*/
|
|
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) {
|
|
373
515
|
const isStandardToken = isStandardTokenContract(token);
|
|
374
516
|
let privateBalance = 0n;
|
|
375
517
|
let publicBalance = 0n;
|
|
@@ -395,8 +537,9 @@ export class BotFactory {
|
|
|
395
537
|
const additionalScopes = isStandardToken ? undefined : [
|
|
396
538
|
token.address
|
|
397
539
|
];
|
|
540
|
+
const mintBatch = new BatchCall(token.wallet, calls);
|
|
398
541
|
await this.withNoMinTxsPerBlock(async ()=>{
|
|
399
|
-
const { txHash } = await
|
|
542
|
+
const { txHash } = await mintBatch.send({
|
|
400
543
|
from: minter,
|
|
401
544
|
additionalScopes,
|
|
402
545
|
wait: NO_WAIT
|
|
@@ -420,8 +563,7 @@ export class BotFactory {
|
|
|
420
563
|
try {
|
|
421
564
|
const messageHash = Fr.fromHexString(existingClaim.claim.messageHash);
|
|
422
565
|
await this.withNoMinTxsPerBlock(()=>waitForL1ToL2MessageReady(this.aztecNode, messageHash, {
|
|
423
|
-
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
424
|
-
forPublicConsumption: false
|
|
566
|
+
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
425
567
|
}));
|
|
426
568
|
return existingClaim.claim;
|
|
427
569
|
} catch (err) {
|
|
@@ -449,8 +591,7 @@ export class BotFactory {
|
|
|
449
591
|
const mintAmount = await portal.getTokenManager().getMintAmount();
|
|
450
592
|
const claim = await portal.bridgeTokensPublic(recipient, mintAmount, true);
|
|
451
593
|
await this.withNoMinTxsPerBlock(()=>waitForL1ToL2MessageReady(this.aztecNode, Fr.fromHexString(claim.messageHash), {
|
|
452
|
-
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
453
|
-
forPublicConsumption: false
|
|
594
|
+
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
454
595
|
}));
|
|
455
596
|
this.log.info(`Created a claim for ${mintAmount} L1 fee juice to ${recipient}.`, claim);
|
|
456
597
|
return claim;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/bot",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.f650c0a5c",
|
|
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": "0.0.1-commit.
|
|
58
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
59
|
-
"@aztec/entrypoints": "0.0.1-commit.
|
|
60
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
61
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
62
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
63
|
-
"@aztec/l1-artifacts": "0.0.1-commit.
|
|
64
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
65
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
66
|
-
"@aztec/noir-test-contracts.js": "0.0.1-commit.
|
|
67
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
68
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
69
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
70
|
-
"@aztec/wallets": "0.0.1-commit.
|
|
57
|
+
"@aztec/accounts": "0.0.1-commit.f650c0a5c",
|
|
58
|
+
"@aztec/aztec.js": "0.0.1-commit.f650c0a5c",
|
|
59
|
+
"@aztec/entrypoints": "0.0.1-commit.f650c0a5c",
|
|
60
|
+
"@aztec/ethereum": "0.0.1-commit.f650c0a5c",
|
|
61
|
+
"@aztec/foundation": "0.0.1-commit.f650c0a5c",
|
|
62
|
+
"@aztec/kv-store": "0.0.1-commit.f650c0a5c",
|
|
63
|
+
"@aztec/l1-artifacts": "0.0.1-commit.f650c0a5c",
|
|
64
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.f650c0a5c",
|
|
65
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.f650c0a5c",
|
|
66
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.f650c0a5c",
|
|
67
|
+
"@aztec/protocol-contracts": "0.0.1-commit.f650c0a5c",
|
|
68
|
+
"@aztec/stdlib": "0.0.1-commit.f650c0a5c",
|
|
69
|
+
"@aztec/telemetry-client": "0.0.1-commit.f650c0a5c",
|
|
70
|
+
"@aztec/wallets": "0.0.1-commit.f650c0a5c",
|
|
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/amm_bot.ts
CHANGED
|
@@ -87,7 +87,7 @@ export class AmmBot extends BaseBot {
|
|
|
87
87
|
authWitnesses: [swapAuthwit],
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
const opts =
|
|
90
|
+
const opts = this.getSendMethodOpts();
|
|
91
91
|
|
|
92
92
|
this.log.verbose(`Sending transaction`, logCtx);
|
|
93
93
|
this.log.info(`Tx. Balances: ${jsonStringify(balances)}`, { ...logCtx, balances });
|
package/src/base_bot.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
-
import {
|
|
2
|
+
import type { SendInteractionOptions } from '@aztec/aztec.js/contracts';
|
|
3
3
|
import { createLogger } from '@aztec/aztec.js/log';
|
|
4
4
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
5
5
|
import { TxHash, TxReceipt, TxStatus } from '@aztec/aztec.js/tx';
|
|
@@ -56,27 +56,19 @@ export abstract class BaseBot {
|
|
|
56
56
|
return Promise.resolve();
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
protected
|
|
60
|
-
interaction: ContractFunctionInteraction | BatchCall,
|
|
61
|
-
): Promise<SendInteractionOptions> {
|
|
59
|
+
protected getSendMethodOpts(): SendInteractionOptions {
|
|
62
60
|
const { l2GasLimit, daGasLimit, minFeePadding } = this.config;
|
|
63
61
|
|
|
64
62
|
this.wallet.setMinFeePadding(minFeePadding);
|
|
65
63
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
this.log.verbose(`Estimating gas for transaction`);
|
|
72
|
-
({ estimatedGas: gasSettings } = await interaction.simulate({
|
|
73
|
-
fee: { estimateGas: true },
|
|
74
|
-
from: this.defaultAccountAddress,
|
|
75
|
-
}));
|
|
76
|
-
}
|
|
64
|
+
const gasSettings =
|
|
65
|
+
l2GasLimit !== undefined && l2GasLimit > 0 && daGasLimit !== undefined && daGasLimit > 0
|
|
66
|
+
? { gasLimits: Gas.from({ l2Gas: l2GasLimit, daGas: daGasLimit }) }
|
|
67
|
+
: undefined;
|
|
68
|
+
|
|
77
69
|
return {
|
|
78
70
|
from: this.defaultAccountAddress,
|
|
79
|
-
fee: { gasSettings },
|
|
71
|
+
...(gasSettings ? { fee: { gasSettings } } : {}),
|
|
80
72
|
};
|
|
81
73
|
}
|
|
82
74
|
}
|
package/src/bot.ts
CHANGED
|
@@ -70,10 +70,7 @@ export class Bot extends BaseBot {
|
|
|
70
70
|
);
|
|
71
71
|
|
|
72
72
|
const batch = new BatchCall(wallet, calls);
|
|
73
|
-
const opts =
|
|
74
|
-
|
|
75
|
-
this.log.verbose(`Simulating transaction with ${calls.length}`, logCtx);
|
|
76
|
-
await batch.simulate({ from: this.defaultAccountAddress });
|
|
73
|
+
const opts = this.getSendMethodOpts();
|
|
77
74
|
|
|
78
75
|
this.log.verbose(`Sending transaction`, logCtx);
|
|
79
76
|
const { txHash } = await batch.send({ ...opts, wait: NO_WAIT });
|
package/src/config.ts
CHANGED
|
@@ -11,9 +11,9 @@ import {
|
|
|
11
11
|
secretStringConfigHelper,
|
|
12
12
|
} from '@aztec/foundation/config';
|
|
13
13
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
14
|
-
import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
|
|
15
14
|
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
16
15
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
16
|
+
import { type DataStoreConfig, dataConfigMappings } from '@aztec/stdlib/kv-store';
|
|
17
17
|
import { schemas, zodFor } from '@aztec/stdlib/schemas';
|
|
18
18
|
import type { ComponentsVersions } from '@aztec/stdlib/versioning';
|
|
19
19
|
|
|
@@ -69,9 +69,9 @@ export type BotConfig = {
|
|
|
69
69
|
maxPendingTxs: number;
|
|
70
70
|
/** Whether to flush after sending each 'setup' transaction */
|
|
71
71
|
flushSetupTransactions: boolean;
|
|
72
|
-
/** L2 gas limit for the tx (empty to
|
|
72
|
+
/** L2 gas limit for the tx (empty to let the bot's wallet estimate). */
|
|
73
73
|
l2GasLimit: number | undefined;
|
|
74
|
-
/** DA gas limit for the tx (empty to
|
|
74
|
+
/** DA gas limit for the tx (empty to let the bot's wallet estimate). */
|
|
75
75
|
daGasLimit: number | undefined;
|
|
76
76
|
/** Token contract to use */
|
|
77
77
|
contract: SupportedTokenContracts;
|
|
@@ -130,7 +130,6 @@ export const BotConfigSchema = zodFor<BotConfig>()(
|
|
|
130
130
|
l1Mnemonic: undefined,
|
|
131
131
|
l1PrivateKey: undefined,
|
|
132
132
|
senderPrivateKey: undefined,
|
|
133
|
-
dataDirectory: undefined,
|
|
134
133
|
dataStoreMapSizeKb: 1_024 * 1_024,
|
|
135
134
|
...config,
|
|
136
135
|
})),
|
|
@@ -244,12 +243,12 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
|
|
|
244
243
|
},
|
|
245
244
|
l2GasLimit: {
|
|
246
245
|
env: 'BOT_L2_GAS_LIMIT',
|
|
247
|
-
description:
|
|
246
|
+
description: "L2 gas limit for the tx (empty to let the bot's wallet estimate).",
|
|
248
247
|
...optionalNumberConfigHelper(),
|
|
249
248
|
},
|
|
250
249
|
daGasLimit: {
|
|
251
250
|
env: 'BOT_DA_GAS_LIMIT',
|
|
252
|
-
description:
|
|
251
|
+
description: "DA gas limit for the tx (empty to let the bot's wallet estimate).",
|
|
253
252
|
...optionalNumberConfigHelper(),
|
|
254
253
|
},
|
|
255
254
|
contract: {
|
package/src/cross_chain_bot.ts
CHANGED
|
@@ -137,7 +137,7 @@ export class CrossChainBot extends BaseBot {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
const batch = new BatchCall(this.wallet, calls);
|
|
140
|
-
const opts =
|
|
140
|
+
const opts = this.getSendMethodOpts();
|
|
141
141
|
|
|
142
142
|
this.log.verbose(`Sending cross-chain batch with ${calls.length} calls`, logCtx);
|
|
143
143
|
const { txHash } = await batch.send({ ...opts, wait: NO_WAIT });
|
|
@@ -175,14 +175,7 @@ export class CrossChainBot extends BaseBot {
|
|
|
175
175
|
): Promise<PendingL1ToL2Message | undefined> {
|
|
176
176
|
const now = Date.now();
|
|
177
177
|
for (const msg of pendingMessages) {
|
|
178
|
-
const ready = await isL1ToL2MessageReady(this.node, Fr.fromHexString(msg.msgHash)
|
|
179
|
-
// Use forPublicConsumption: false so we wait until blockNumber >= messageBlockNumber.
|
|
180
|
-
// With forPublicConsumption: true, the check returns true one block early (the sequencer
|
|
181
|
-
// includes L1→L2 messages before executing the block's txs), but gas estimation simulates
|
|
182
|
-
// against the current world state which doesn't yet have the message.
|
|
183
|
-
// See https://linear.app/aztec-labs/issue/A-548 for details.
|
|
184
|
-
forPublicConsumption: false,
|
|
185
|
-
});
|
|
178
|
+
const ready = await isL1ToL2MessageReady(this.node, Fr.fromHexString(msg.msgHash));
|
|
186
179
|
if (ready) {
|
|
187
180
|
return msg;
|
|
188
181
|
}
|