@aztec/bot 0.0.1-commit.181e2d196 → 0.0.1-commit.189eedb3
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.d.ts +2 -2
- package/dest/amm_bot.d.ts.map +1 -1
- package/dest/amm_bot.js +24 -17
- package/dest/base_bot.d.ts +4 -4
- 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 +3 -6
- package/dest/config.d.ts +31 -82
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +3 -4
- package/dest/cross_chain_bot.d.ts +2 -2
- package/dest/cross_chain_bot.d.ts.map +1 -1
- package/dest/cross_chain_bot.js +10 -13
- package/dest/factory.d.ts +6 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +241 -84
- package/dest/interface.d.ts +2 -6
- package/dest/interface.d.ts.map +1 -1
- package/dest/interface.js +30 -7
- package/dest/utils.js +3 -3
- package/package.json +16 -16
- package/src/amm_bot.ts +22 -17
- package/src/base_bot.ts +10 -17
- package/src/bot.ts +3 -5
- package/src/config.ts +5 -6
- package/src/cross_chain_bot.ts +9 -14
- package/src/factory.ts +255 -78
- package/src/interface.ts +7 -7
- package/src/utils.ts +3 -3
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, ManaUsageEstimate } 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
|
}
|
|
@@ -131,11 +132,12 @@ export class BotFactory {
|
|
|
131
132
|
}
|
|
132
133
|
async setupTestContract(deployer) {
|
|
133
134
|
const deployOpts = {
|
|
134
|
-
from: deployer
|
|
135
|
-
contractAddressSalt: this.config.tokenSalt,
|
|
136
|
-
universalDeploy: true
|
|
135
|
+
from: deployer
|
|
137
136
|
};
|
|
138
|
-
const deploy = TestContract.deploy(this.wallet
|
|
137
|
+
const deploy = TestContract.deploy(this.wallet, {
|
|
138
|
+
salt: this.config.tokenSalt,
|
|
139
|
+
universalDeploy: true
|
|
140
|
+
});
|
|
139
141
|
const instance = await this.registerOrDeployContract('TestContract', deploy, deployOpts);
|
|
140
142
|
return TestContract.at(instance.address, this.wallet);
|
|
141
143
|
}
|
|
@@ -157,7 +159,7 @@ export class BotFactory {
|
|
|
157
159
|
const signingKey = deriveSigningKey(secret);
|
|
158
160
|
const accountManager = await this.wallet.createSchnorrAccount(secret, salt, signingKey);
|
|
159
161
|
const metadata = await this.wallet.getContractMetadata(accountManager.address);
|
|
160
|
-
if (metadata.
|
|
162
|
+
if (metadata.initializationStatus === ContractInitializationStatus.INITIALIZED) {
|
|
161
163
|
this.log.info(`Account at ${accountManager.address.toString()} already initialized`);
|
|
162
164
|
const timer = new Timer();
|
|
163
165
|
const address = accountManager.address;
|
|
@@ -170,15 +172,10 @@ export class BotFactory {
|
|
|
170
172
|
const claim = await this.getOrCreateBridgeClaim(address);
|
|
171
173
|
const paymentMethod = new FeeJuicePaymentMethodWithClaim(accountManager.address, claim);
|
|
172
174
|
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
175
|
await this.withNoMinTxsPerBlock(async ()=>{
|
|
178
|
-
const txHash = await deployMethod.send({
|
|
179
|
-
from:
|
|
176
|
+
const { txHash } = await deployMethod.send({
|
|
177
|
+
from: NO_FROM,
|
|
180
178
|
fee: {
|
|
181
|
-
gasSettings,
|
|
182
179
|
paymentMethod
|
|
183
180
|
},
|
|
184
181
|
wait: NO_WAIT
|
|
@@ -200,32 +197,92 @@ export class BotFactory {
|
|
|
200
197
|
return accountManager.address;
|
|
201
198
|
}
|
|
202
199
|
/**
|
|
200
|
+
* Setup token and refuel first: if the token already exists (restart scenario),
|
|
201
|
+
* run ensureFeeJuiceBalance before any step that might need fee juice. When deploying,
|
|
202
|
+
* use a bridge claim if balance is below threshold.
|
|
203
|
+
*/ async setupTokenWithOptionalEarlyRefuel(sender) {
|
|
204
|
+
const token = await this.getTokenInstance(sender);
|
|
205
|
+
const address = token.address;
|
|
206
|
+
const metadata = await this.wallet.getContractMetadata(address);
|
|
207
|
+
if (metadata.isContractPublished) {
|
|
208
|
+
this.log.info(`Token at ${address.toString()} already deployed, refueling before setup`);
|
|
209
|
+
await this.ensureFeeJuiceBalance(sender, token);
|
|
210
|
+
}
|
|
211
|
+
return this.setupToken(sender);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Setup token0 for AMM with refuel-first behaviour when token already exists.
|
|
215
|
+
*/ async setupTokenContractWithOptionalEarlyRefuel(deployer, salt, name, ticker, decimals = 18) {
|
|
216
|
+
const deploy = TokenContract.deploy(this.wallet, deployer, name, ticker, decimals, {
|
|
217
|
+
salt,
|
|
218
|
+
universalDeploy: true
|
|
219
|
+
});
|
|
220
|
+
const instance = await deploy.getInstance();
|
|
221
|
+
const metadata = await this.wallet.getContractMetadata(instance.address);
|
|
222
|
+
if (metadata.isContractPublished) {
|
|
223
|
+
this.log.info(`Token ${name} at ${instance.address.toString()} already deployed, refueling before setup`);
|
|
224
|
+
const token = TokenContract.at(instance.address, this.wallet);
|
|
225
|
+
await this.ensureFeeJuiceBalance(deployer, token);
|
|
226
|
+
}
|
|
227
|
+
return this.setupTokenContract(deployer, salt, name, ticker, decimals);
|
|
228
|
+
}
|
|
229
|
+
async getTokenInstance(sender) {
|
|
230
|
+
const salt = this.config.tokenSalt;
|
|
231
|
+
if (this.config.contract === SupportedTokenContracts.TokenContract) {
|
|
232
|
+
const deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18, {
|
|
233
|
+
salt,
|
|
234
|
+
universalDeploy: true
|
|
235
|
+
});
|
|
236
|
+
const instance = await deploy.getInstance();
|
|
237
|
+
return TokenContract.at(instance.address, this.wallet);
|
|
238
|
+
}
|
|
239
|
+
if (this.config.contract === SupportedTokenContracts.PrivateTokenContract) {
|
|
240
|
+
const tokenSecretKey = Fr.random();
|
|
241
|
+
const tokenPublicKeys = (await deriveKeys(tokenSecretKey)).publicKeys;
|
|
242
|
+
const deploy = PrivateTokenContract.deploy(this.wallet, MINT_BALANCE, sender, {
|
|
243
|
+
salt,
|
|
244
|
+
universalDeploy: true,
|
|
245
|
+
publicKeys: tokenPublicKeys
|
|
246
|
+
});
|
|
247
|
+
const instance = await deploy.getInstance();
|
|
248
|
+
return PrivateTokenContract.at(instance.address, this.wallet);
|
|
249
|
+
}
|
|
250
|
+
throw new Error(`Unsupported token contract type: ${this.config.contract}`);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
203
253
|
* Checks if the token contract is deployed and deploys it if necessary.
|
|
204
|
-
*
|
|
205
|
-
* @
|
|
254
|
+
* Uses a bridge claim for deploy when balance is below threshold to avoid failing before refuel.
|
|
255
|
+
* @param sender - Aztec address to deploy the token contract from.
|
|
256
|
+
* @param existingToken - Optional token instance when called from setupTokenWithOptionalEarlyRefuel.
|
|
257
|
+
* @returns The TokenContract or PrivateTokenContract instance.
|
|
206
258
|
*/ async setupToken(sender) {
|
|
207
259
|
let deploy;
|
|
208
|
-
|
|
260
|
+
const salt = this.config.tokenSalt;
|
|
209
261
|
const deployOpts = {
|
|
210
|
-
from: sender
|
|
211
|
-
contractAddressSalt: this.config.tokenSalt,
|
|
212
|
-
universalDeploy: true
|
|
262
|
+
from: sender
|
|
213
263
|
};
|
|
214
264
|
let token;
|
|
215
265
|
if (this.config.contract === SupportedTokenContracts.TokenContract) {
|
|
216
|
-
deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18
|
|
217
|
-
|
|
218
|
-
|
|
266
|
+
deploy = TokenContract.deploy(this.wallet, sender, 'BotToken', 'BOT', 18, {
|
|
267
|
+
salt,
|
|
268
|
+
universalDeploy: true
|
|
269
|
+
});
|
|
270
|
+
const instance = await deploy.getInstance();
|
|
271
|
+
token = TokenContract.at(instance.address, this.wallet);
|
|
219
272
|
} else if (this.config.contract === SupportedTokenContracts.PrivateTokenContract) {
|
|
220
273
|
// Generate keys for the contract since PrivateToken uses SinglePrivateMutable which requires keys
|
|
221
274
|
const tokenSecretKey = Fr.random();
|
|
222
275
|
const tokenPublicKeys = (await deriveKeys(tokenSecretKey)).publicKeys;
|
|
223
|
-
deploy = PrivateTokenContract.
|
|
276
|
+
deploy = PrivateTokenContract.deploy(this.wallet, MINT_BALANCE, sender, {
|
|
277
|
+
salt,
|
|
278
|
+
universalDeploy: true,
|
|
279
|
+
publicKeys: tokenPublicKeys
|
|
280
|
+
});
|
|
224
281
|
deployOpts.skipInstancePublication = true;
|
|
225
282
|
deployOpts.skipClassPublication = true;
|
|
226
283
|
deployOpts.skipInitialization = false;
|
|
227
284
|
// Register the contract with the secret key before deployment
|
|
228
|
-
tokenInstance = await deploy.getInstance(
|
|
285
|
+
const tokenInstance = await deploy.getInstance();
|
|
229
286
|
token = PrivateTokenContract.at(tokenInstance.address, this.wallet);
|
|
230
287
|
await this.wallet.registerContract(tokenInstance, PrivateTokenContract.artifact, tokenSecretKey);
|
|
231
288
|
// The contract constructor initializes private storage vars that need the contract's own nullifier key.
|
|
@@ -235,52 +292,37 @@ export class BotFactory {
|
|
|
235
292
|
} else {
|
|
236
293
|
throw new Error(`Unsupported token contract type: ${this.config.contract}`);
|
|
237
294
|
}
|
|
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
|
-
}
|
|
295
|
+
await this.registerOrDeployContract('token', deploy, deployOpts);
|
|
257
296
|
return token;
|
|
258
297
|
}
|
|
259
298
|
/**
|
|
260
299
|
* Checks if the token contract is deployed and deploys it if necessary.
|
|
261
300
|
* @param wallet - Wallet to deploy the token contract from.
|
|
262
301
|
* @returns The TokenContract instance.
|
|
263
|
-
*/ async setupTokenContract(deployer,
|
|
302
|
+
*/ async setupTokenContract(deployer, salt, name, ticker, decimals = 18) {
|
|
264
303
|
const deployOpts = {
|
|
265
|
-
from: deployer
|
|
266
|
-
contractAddressSalt,
|
|
267
|
-
universalDeploy: true
|
|
304
|
+
from: deployer
|
|
268
305
|
};
|
|
269
|
-
const deploy = TokenContract.deploy(this.wallet, deployer, name, ticker, decimals
|
|
306
|
+
const deploy = TokenContract.deploy(this.wallet, deployer, name, ticker, decimals, {
|
|
307
|
+
salt,
|
|
308
|
+
universalDeploy: true
|
|
309
|
+
});
|
|
270
310
|
const instance = await this.registerOrDeployContract('Token - ' + name, deploy, deployOpts);
|
|
271
311
|
return TokenContract.at(instance.address, this.wallet);
|
|
272
312
|
}
|
|
273
|
-
async setupAmmContract(deployer,
|
|
313
|
+
async setupAmmContract(deployer, salt, token0, token1, lpToken) {
|
|
274
314
|
const deployOpts = {
|
|
275
|
-
from: deployer
|
|
276
|
-
contractAddressSalt,
|
|
277
|
-
universalDeploy: true
|
|
315
|
+
from: deployer
|
|
278
316
|
};
|
|
279
|
-
const deploy = AMMContract.deploy(this.wallet, token0.address, token1.address, lpToken.address
|
|
317
|
+
const deploy = AMMContract.deploy(this.wallet, token0.address, token1.address, lpToken.address, {
|
|
318
|
+
salt,
|
|
319
|
+
universalDeploy: true
|
|
320
|
+
});
|
|
280
321
|
const instance = await this.registerOrDeployContract('AMM', deploy, deployOpts);
|
|
281
322
|
const amm = AMMContract.at(instance.address, this.wallet);
|
|
282
323
|
this.log.info(`AMM deployed at ${amm.address}`);
|
|
283
|
-
const
|
|
324
|
+
const setMinterInteraction = lpToken.methods.set_minter(amm.address, true);
|
|
325
|
+
const { receipt: minterReceipt } = await setMinterInteraction.send({
|
|
284
326
|
from: deployer,
|
|
285
327
|
wait: {
|
|
286
328
|
timeout: this.config.txMinedWaitSeconds
|
|
@@ -294,13 +336,13 @@ export class BotFactory {
|
|
|
294
336
|
const getPrivateBalances = ()=>Promise.all([
|
|
295
337
|
token0.methods.balance_of_private(liquidityProvider).simulate({
|
|
296
338
|
from: liquidityProvider
|
|
297
|
-
}),
|
|
339
|
+
}).then((r)=>r.result),
|
|
298
340
|
token1.methods.balance_of_private(liquidityProvider).simulate({
|
|
299
341
|
from: liquidityProvider
|
|
300
|
-
}),
|
|
342
|
+
}).then((r)=>r.result),
|
|
301
343
|
lpToken.methods.balance_of_private(liquidityProvider).simulate({
|
|
302
344
|
from: liquidityProvider
|
|
303
|
-
})
|
|
345
|
+
}).then((r)=>r.result)
|
|
304
346
|
]);
|
|
305
347
|
const authwitNonce = Fr.random();
|
|
306
348
|
// keep some tokens for swapping
|
|
@@ -319,17 +361,19 @@ export class BotFactory {
|
|
|
319
361
|
caller: amm.address,
|
|
320
362
|
call: await token1.methods.transfer_to_public_and_prepare_private_balance_increase(liquidityProvider, amm.address, amount1Max, authwitNonce).getFunctionCall()
|
|
321
363
|
});
|
|
322
|
-
const
|
|
364
|
+
const mintBatch = new BatchCall(this.wallet, [
|
|
323
365
|
token0.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
|
|
324
366
|
token1.methods.mint_to_private(liquidityProvider, MINT_BALANCE)
|
|
325
|
-
])
|
|
367
|
+
]);
|
|
368
|
+
const { receipt: mintReceipt } = await mintBatch.send({
|
|
326
369
|
from: liquidityProvider,
|
|
327
370
|
wait: {
|
|
328
371
|
timeout: this.config.txMinedWaitSeconds
|
|
329
372
|
}
|
|
330
373
|
});
|
|
331
374
|
this.log.info(`Sent mint tx: ${mintReceipt.txHash.toString()}`);
|
|
332
|
-
const
|
|
375
|
+
const addLiquidityInteraction = amm.methods.add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, authwitNonce);
|
|
376
|
+
const { receipt: addLiquidityReceipt } = await addLiquidityInteraction.send({
|
|
333
377
|
from: liquidityProvider,
|
|
334
378
|
authWitnesses: [
|
|
335
379
|
token0Authwit,
|
|
@@ -345,31 +389,134 @@ export class BotFactory {
|
|
|
345
389
|
this.log.info(`Updated private balances of ${defaultAccountAddress} after minting and funding AMM: token0=${newT0Bal}, token1=${newT1Bal}, lp=${newLPBal}`);
|
|
346
390
|
}
|
|
347
391
|
async registerOrDeployContract(name, deploy, deployOpts) {
|
|
348
|
-
const instance = await deploy.getInstance(
|
|
392
|
+
const instance = await deploy.getInstance();
|
|
349
393
|
const address = instance.address;
|
|
350
394
|
const metadata = await this.wallet.getContractMetadata(address);
|
|
351
395
|
if (metadata.isContractPublished) {
|
|
352
396
|
this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
|
|
353
397
|
await deploy.register();
|
|
354
398
|
} else {
|
|
355
|
-
|
|
356
|
-
await this.
|
|
357
|
-
|
|
399
|
+
const sender = deployOpts.from === NO_FROM ? undefined : deployOpts.from;
|
|
400
|
+
const balance = sender ? await getFeeJuiceBalance(sender, this.aztecNode) : 0n;
|
|
401
|
+
const useClaim = sender && balance < FEE_JUICE_TOP_UP_THRESHOLD && this.config.feePaymentMethod === 'fee_juice' && !!this.config.l1RpcUrls?.length;
|
|
402
|
+
const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
|
|
403
|
+
if (useClaim && mnemonicOrPrivateKey) {
|
|
404
|
+
const claim = await this.getOrCreateBridgeClaim(sender);
|
|
405
|
+
const paymentMethod = new FeeJuicePaymentMethodWithClaim(sender, claim);
|
|
406
|
+
const { estimatedGas } = await deploy.simulate({
|
|
358
407
|
...deployOpts,
|
|
359
|
-
|
|
408
|
+
fee: {
|
|
409
|
+
estimateGas: true,
|
|
410
|
+
paymentMethod
|
|
411
|
+
}
|
|
360
412
|
});
|
|
361
|
-
this.
|
|
362
|
-
|
|
363
|
-
|
|
413
|
+
const maxFeesPerGas = (await this.getMinFees()).mul(1 + this.config.minFeePadding);
|
|
414
|
+
const gasSettings = GasSettings.from({
|
|
415
|
+
...estimatedGas,
|
|
416
|
+
maxFeesPerGas,
|
|
417
|
+
maxPriorityFeesPerGas: GasFees.empty()
|
|
364
418
|
});
|
|
365
|
-
|
|
419
|
+
await this.withNoMinTxsPerBlock(async ()=>{
|
|
420
|
+
const { txHash } = await deploy.send({
|
|
421
|
+
...deployOpts,
|
|
422
|
+
fee: {
|
|
423
|
+
gasSettings,
|
|
424
|
+
paymentMethod
|
|
425
|
+
},
|
|
426
|
+
wait: NO_WAIT
|
|
427
|
+
});
|
|
428
|
+
this.log.info(`Sent contract ${name} deploy tx ${txHash.toString()} (using bridge claim, balance was ${balance})`);
|
|
429
|
+
return waitForTx(this.aztecNode, txHash, {
|
|
430
|
+
timeout: this.config.txMinedWaitSeconds
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
await this.store.deleteBridgeClaim(sender);
|
|
434
|
+
} else {
|
|
435
|
+
const { estimatedGas } = await deploy.simulate({
|
|
436
|
+
...deployOpts,
|
|
437
|
+
fee: {
|
|
438
|
+
estimateGas: true
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
this.log.info(`Deploying contract ${name} at ${address.toString()}`, {
|
|
442
|
+
estimatedGas
|
|
443
|
+
});
|
|
444
|
+
await this.withNoMinTxsPerBlock(async ()=>{
|
|
445
|
+
const { txHash } = await deploy.send({
|
|
446
|
+
...deployOpts,
|
|
447
|
+
fee: {
|
|
448
|
+
gasSettings: estimatedGas
|
|
449
|
+
},
|
|
450
|
+
wait: NO_WAIT
|
|
451
|
+
});
|
|
452
|
+
this.log.info(`Sent contract ${name} setup tx with hash ${txHash.toString()}`);
|
|
453
|
+
return waitForTx(this.aztecNode, txHash, {
|
|
454
|
+
timeout: this.config.txMinedWaitSeconds
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
}
|
|
366
458
|
}
|
|
367
459
|
return instance;
|
|
368
460
|
}
|
|
369
461
|
/**
|
|
370
462
|
* Mints private and public tokens for the sender if their balance is below the minimum.
|
|
371
463
|
* @param token - Token contract.
|
|
372
|
-
*/
|
|
464
|
+
*/ /**
|
|
465
|
+
* Ensures the account has sufficient fee juice by bridging from L1 if balance is below threshold.
|
|
466
|
+
* Bridges repeatedly until balance reaches the target (10k FJ).
|
|
467
|
+
* Used on startup/restart to top up when the account has run out after previous runs.
|
|
468
|
+
*/ async ensureFeeJuiceBalance(account, token) {
|
|
469
|
+
const { feePaymentMethod, l1RpcUrls } = this.config;
|
|
470
|
+
if (feePaymentMethod !== 'fee_juice' || !l1RpcUrls?.length) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
|
|
474
|
+
if (!mnemonicOrPrivateKey) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
let balance = await getFeeJuiceBalance(account, this.aztecNode);
|
|
478
|
+
if (balance >= FEE_JUICE_TOP_UP_THRESHOLD) {
|
|
479
|
+
this.log.info(`Fee juice balance ${balance} above threshold ${FEE_JUICE_TOP_UP_THRESHOLD}, skipping top-up`);
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
this.log.info(`Fee juice balance ${balance} below threshold ${FEE_JUICE_TOP_UP_THRESHOLD}, bridging from L1 until ${FEE_JUICE_TOP_UP_TARGET}`);
|
|
483
|
+
const maxFeesPerGas = (await this.getMinFees()).mul(1 + this.config.minFeePadding);
|
|
484
|
+
const minimalInteraction = isStandardTokenContract(token) ? token.methods.transfer_in_public(account, account, 0n, 0) : token.methods.transfer(0n, account, account);
|
|
485
|
+
while(balance < FEE_JUICE_TOP_UP_TARGET){
|
|
486
|
+
const claim = await this.bridgeL1FeeJuice(account);
|
|
487
|
+
const paymentMethod = new FeeJuicePaymentMethodWithClaim(account, claim);
|
|
488
|
+
const { estimatedGas } = await minimalInteraction.simulate({
|
|
489
|
+
from: account,
|
|
490
|
+
fee: {
|
|
491
|
+
estimateGas: true,
|
|
492
|
+
paymentMethod
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
const gasSettings = GasSettings.from({
|
|
496
|
+
...estimatedGas,
|
|
497
|
+
maxFeesPerGas,
|
|
498
|
+
maxPriorityFeesPerGas: GasFees.empty()
|
|
499
|
+
});
|
|
500
|
+
await this.withNoMinTxsPerBlock(async ()=>{
|
|
501
|
+
const { txHash } = await minimalInteraction.send({
|
|
502
|
+
from: account,
|
|
503
|
+
fee: {
|
|
504
|
+
gasSettings,
|
|
505
|
+
paymentMethod
|
|
506
|
+
},
|
|
507
|
+
wait: NO_WAIT
|
|
508
|
+
});
|
|
509
|
+
this.log.info(`Sent fee juice top-up tx ${txHash.toString()}`);
|
|
510
|
+
return waitForTx(this.aztecNode, txHash, {
|
|
511
|
+
timeout: this.config.txMinedWaitSeconds
|
|
512
|
+
});
|
|
513
|
+
});
|
|
514
|
+
balance = await getFeeJuiceBalance(account, this.aztecNode);
|
|
515
|
+
this.log.info(`Fee juice balance after top-up: ${balance}`);
|
|
516
|
+
}
|
|
517
|
+
this.log.info(`Fee juice top-up complete for ${account.toString()}`);
|
|
518
|
+
}
|
|
519
|
+
async mintTokens(token, minter) {
|
|
373
520
|
const isStandardToken = isStandardTokenContract(token);
|
|
374
521
|
let privateBalance = 0n;
|
|
375
522
|
let publicBalance = 0n;
|
|
@@ -395,8 +542,9 @@ export class BotFactory {
|
|
|
395
542
|
const additionalScopes = isStandardToken ? undefined : [
|
|
396
543
|
token.address
|
|
397
544
|
];
|
|
545
|
+
const mintBatch = new BatchCall(token.wallet, calls);
|
|
398
546
|
await this.withNoMinTxsPerBlock(async ()=>{
|
|
399
|
-
const txHash = await
|
|
547
|
+
const { txHash } = await mintBatch.send({
|
|
400
548
|
from: minter,
|
|
401
549
|
additionalScopes,
|
|
402
550
|
wait: NO_WAIT
|
|
@@ -420,8 +568,7 @@ export class BotFactory {
|
|
|
420
568
|
try {
|
|
421
569
|
const messageHash = Fr.fromHexString(existingClaim.claim.messageHash);
|
|
422
570
|
await this.withNoMinTxsPerBlock(()=>waitForL1ToL2MessageReady(this.aztecNode, messageHash, {
|
|
423
|
-
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
424
|
-
forPublicConsumption: false
|
|
571
|
+
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
425
572
|
}));
|
|
426
573
|
return existingClaim.claim;
|
|
427
574
|
} catch (err) {
|
|
@@ -449,12 +596,22 @@ export class BotFactory {
|
|
|
449
596
|
const mintAmount = await portal.getTokenManager().getMintAmount();
|
|
450
597
|
const claim = await portal.bridgeTokensPublic(recipient, mintAmount, true);
|
|
451
598
|
await this.withNoMinTxsPerBlock(()=>waitForL1ToL2MessageReady(this.aztecNode, Fr.fromHexString(claim.messageHash), {
|
|
452
|
-
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
453
|
-
forPublicConsumption: false
|
|
599
|
+
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds
|
|
454
600
|
}));
|
|
455
601
|
this.log.info(`Created a claim for ${mintAmount} L1 fee juice to ${recipient}.`, claim);
|
|
456
602
|
return claim;
|
|
457
603
|
}
|
|
604
|
+
/** Returns worst-case min fees across predicted slots, with fallback to current min fees. */ async getMinFees() {
|
|
605
|
+
try {
|
|
606
|
+
const predicted = await this.aztecNode.getPredictedMinFees(ManaUsageEstimate.Limit);
|
|
607
|
+
if (predicted.length === 0) {
|
|
608
|
+
return this.aztecNode.getCurrentMinFees();
|
|
609
|
+
}
|
|
610
|
+
return predicted.reduce((worst, fees)=>fees.feePerL2Gas > worst.feePerL2Gas ? fees : worst);
|
|
611
|
+
} catch {
|
|
612
|
+
return this.aztecNode.getCurrentMinFees();
|
|
613
|
+
}
|
|
614
|
+
}
|
|
458
615
|
async withNoMinTxsPerBlock(fn) {
|
|
459
616
|
if (!this.aztecNodeAdmin || !this.config.flushSetupTransactions) {
|
|
460
617
|
this.log.verbose(`No node admin client or flushing not requested (not setting minTxsPerBlock to 0)`);
|
package/dest/interface.d.ts
CHANGED
|
@@ -4,11 +4,7 @@ import { z } from 'zod';
|
|
|
4
4
|
import { type BotConfig } from './config.js';
|
|
5
5
|
export declare const BotInfoSchema: z.ZodObject<{
|
|
6
6
|
botAddress: import("@aztec/stdlib/schemas").ZodFor<AztecAddress>;
|
|
7
|
-
},
|
|
8
|
-
botAddress: AztecAddress;
|
|
9
|
-
}, {
|
|
10
|
-
botAddress?: any;
|
|
11
|
-
}>;
|
|
7
|
+
}, z.core.$strip>;
|
|
12
8
|
export type BotInfo = z.infer<typeof BotInfoSchema>;
|
|
13
9
|
export interface BotRunnerApi {
|
|
14
10
|
start(): Promise<void>;
|
|
@@ -20,4 +16,4 @@ export interface BotRunnerApi {
|
|
|
20
16
|
update(config: BotConfig): Promise<void>;
|
|
21
17
|
}
|
|
22
18
|
export declare const BotRunnerApiSchema: ApiSchemaFor<BotRunnerApi>;
|
|
23
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW50ZXJmYWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW50ZXJmYWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQUN6RCxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUUxRCxPQUFPLEVBQUUsQ0FBQyxFQUFFLE1BQU0sS0FBSyxDQUFDO0FBRXhCLE9BQU8sRUFBRSxLQUFLLFNBQVMsRUFBbUIsTUFBTSxhQUFhLENBQUM7QUFFOUQsZUFBTyxNQUFNLGFBQWE7O2lCQUV4QixDQUFDO0FBRUgsTUFBTSxNQUFNLE9BQU8sR0FBRyxDQUFDLENBQUMsS0FBSyxDQUFDLE9BQU8sYUFBYSxDQUFDLENBQUM7QUFFcEQsTUFBTSxXQUFXLFlBQVk7SUFDM0IsS0FBSyxJQUFJLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQztJQUN2QixJQUFJLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0lBQ3RCLEdBQUcsSUFBSSxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7SUFDckIsS0FBSyxJQUFJLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQztJQUN2QixTQUFTLElBQUksT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFDO0lBQ2hDLE9BQU8sSUFBSSxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7SUFDNUIsTUFBTSxDQUFDLE1BQU0sRUFBRSxTQUFTLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0NBQzFDO0FBRUQsZUFBTyxNQUFNLGtCQUFrQixFQUFFLFlBQVksQ0FBQyxZQUFZLENBUXpELENBQUMifQ==
|
package/dest/interface.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,aAAa,CAAC;AAE9D,eAAO,MAAM,aAAa
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,aAAa,CAAC;AAE9D,eAAO,MAAM,aAAa;;iBAExB,CAAC;AAEH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAEpD,MAAM,WAAW,YAAY;IAC3B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5B,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C;AAED,eAAO,MAAM,kBAAkB,EAAE,YAAY,CAAC,YAAY,CAQzD,CAAC"}
|
package/dest/interface.js
CHANGED
|
@@ -5,11 +5,34 @@ export const BotInfoSchema = z.object({
|
|
|
5
5
|
botAddress: AztecAddress.schema
|
|
6
6
|
});
|
|
7
7
|
export const BotRunnerApiSchema = {
|
|
8
|
-
start: z.function(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
start: z.function({
|
|
9
|
+
input: z.tuple([]),
|
|
10
|
+
output: z.void()
|
|
11
|
+
}),
|
|
12
|
+
stop: z.function({
|
|
13
|
+
input: z.tuple([]),
|
|
14
|
+
output: z.void()
|
|
15
|
+
}),
|
|
16
|
+
run: z.function({
|
|
17
|
+
input: z.tuple([]),
|
|
18
|
+
output: z.void()
|
|
19
|
+
}),
|
|
20
|
+
setup: z.function({
|
|
21
|
+
input: z.tuple([]),
|
|
22
|
+
output: z.void()
|
|
23
|
+
}),
|
|
24
|
+
getInfo: z.function({
|
|
25
|
+
input: z.tuple([]),
|
|
26
|
+
output: BotInfoSchema
|
|
27
|
+
}),
|
|
28
|
+
getConfig: z.function({
|
|
29
|
+
input: z.tuple([]),
|
|
30
|
+
output: BotConfigSchema
|
|
31
|
+
}),
|
|
32
|
+
update: z.function({
|
|
33
|
+
input: z.tuple([
|
|
34
|
+
BotConfigSchema
|
|
35
|
+
]),
|
|
36
|
+
output: z.void()
|
|
37
|
+
})
|
|
15
38
|
};
|
package/dest/utils.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* @param who - Address to get the balance for.
|
|
5
5
|
* @returns - Private and public token balances as bigints.
|
|
6
6
|
*/ export async function getBalances(token, who, from) {
|
|
7
|
-
const privateBalance = await token.methods.balance_of_private(who).simulate({
|
|
7
|
+
const { result: privateBalance } = await token.methods.balance_of_private(who).simulate({
|
|
8
8
|
from: from ?? who
|
|
9
9
|
});
|
|
10
|
-
const publicBalance = await token.methods.balance_of_public(who).simulate({
|
|
10
|
+
const { result: publicBalance } = await token.methods.balance_of_public(who).simulate({
|
|
11
11
|
from: from ?? who
|
|
12
12
|
});
|
|
13
13
|
return {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
export async function getPrivateBalance(token, who, from) {
|
|
19
|
-
const privateBalance = await token.methods.get_balance(who).simulate({
|
|
19
|
+
const { result: privateBalance } = await token.methods.get_balance(who).simulate({
|
|
20
20
|
from: from ?? who
|
|
21
21
|
});
|
|
22
22
|
return privateBalance;
|
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.189eedb3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -54,24 +54,24 @@
|
|
|
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.189eedb3",
|
|
58
|
+
"@aztec/aztec.js": "0.0.1-commit.189eedb3",
|
|
59
|
+
"@aztec/entrypoints": "0.0.1-commit.189eedb3",
|
|
60
|
+
"@aztec/ethereum": "0.0.1-commit.189eedb3",
|
|
61
|
+
"@aztec/foundation": "0.0.1-commit.189eedb3",
|
|
62
|
+
"@aztec/kv-store": "0.0.1-commit.189eedb3",
|
|
63
|
+
"@aztec/l1-artifacts": "0.0.1-commit.189eedb3",
|
|
64
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.189eedb3",
|
|
65
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.189eedb3",
|
|
66
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.189eedb3",
|
|
67
|
+
"@aztec/protocol-contracts": "0.0.1-commit.189eedb3",
|
|
68
|
+
"@aztec/stdlib": "0.0.1-commit.189eedb3",
|
|
69
|
+
"@aztec/telemetry-client": "0.0.1-commit.189eedb3",
|
|
70
|
+
"@aztec/wallets": "0.0.1-commit.189eedb3",
|
|
71
71
|
"source-map-support": "^0.5.21",
|
|
72
72
|
"tslib": "^2.4.0",
|
|
73
73
|
"viem": "npm:@aztec/viem@2.38.2",
|
|
74
|
-
"zod": "^
|
|
74
|
+
"zod": "^4"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@jest/globals": "^30.0.0",
|