@aztec/bot 0.0.1-commit.3e3d0c9cd → 0.0.1-commit.3f296a7d2
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 +1 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +105 -18
- package/package.json +15 -15
- package/src/factory.ts +69 -26
package/dest/factory.d.ts
CHANGED
|
@@ -61,4 +61,4 @@ export declare class BotFactory {
|
|
|
61
61
|
private bridgeL1FeeJuice;
|
|
62
62
|
private withNoMinTxsPerBlock;
|
|
63
63
|
}
|
|
64
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
64
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ZhY3RvcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBb0J6RCxPQUFPLEtBQUssRUFBRSx3QkFBd0IsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBSXRFLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSw4QkFBOEIsQ0FBQztBQUMzRCxPQUFPLEVBQUUsb0JBQW9CLEVBQUUsTUFBTSx1Q0FBdUMsQ0FBQztBQUM3RSxPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDL0QsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLG9DQUFvQyxDQUFDO0FBR2xFLE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxjQUFjLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUVqRixPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFFekQsT0FBTyxFQUFFLEtBQUssU0FBU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DLENBc0JEO0lBRUQ7OztPQUdHO0lBQ1UsZUFBZSxJQUFJLE9BQU8sQ0FBQztRQUN0QyxNQUFNLEVBQUUsY0FBYyxDQUFDO1FBQ3ZCLHFCQUFxQixFQUFFLFlBQVksQ0FBQztRQUNwQyxRQUFRLEVBQUUsWUFBWSxDQUFDO1FBQ3ZCLElBQUksRUFBRSxTQUFTLENBQUM7UUFDaEIsUUFBUSxFQUFFLHdCQUF3QixDQUFDO1FBQ25DLGFBQWEsRUFBRSxNQUFNLENBQUM7S0FDdkIsQ0FBQyxDQTJERDtZQUVhLGlCQUFpQjtZQWVqQixZQUFZO1lBV1osMEJBQTBCO1lBOEMxQixnQkFBZ0I7WUFlaEIsVUFBVTtZQXVEVixrQkFBa0I7WUFhbEIsZ0JBQWdCO1lBK0JoQixPQUFPO1lBNEdQLHdCQUF3QjtZQTJCeEIsVUFBVTtZQW1EVixzQkFBc0I7WUEyQnRCLGdCQUFnQjtZQStCaEIsb0JBQW9CO0NBZW5DIn0=
|
package/dest/factory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAoBzD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAItE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAGlE,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjF,OAAO,EAAE,cA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C,CA2DD;YAEa,iBAAiB;YAejB,YAAY;YAWZ,0BAA0B;YA8C1B,gBAAgB;YAehB,UAAU;YAuDV,kBAAkB;YAalB,gBAAgB;YA+BhB,OAAO;YA4GP,wBAAwB;YA2BxB,UAAU;YAmDV,sBAAsB;YA2BtB,gBAAgB;YA+BhB,oBAAoB;CAenC"}
|
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,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 { ContractInitializationStatus } from '@aztec/aztec.js/wallet';
|
|
10
11
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
11
12
|
import { createExtendedL1Client } from '@aztec/ethereum/client';
|
|
12
13
|
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
@@ -17,7 +18,7 @@ import { AMMContract } from '@aztec/noir-contracts.js/AMM';
|
|
|
17
18
|
import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
|
|
18
19
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
19
20
|
import { TestContract } from '@aztec/noir-test-contracts.js/Test';
|
|
20
|
-
import { GasSettings } from '@aztec/stdlib/gas';
|
|
21
|
+
import { GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
21
22
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
22
23
|
import { SupportedTokenContracts } from './config.js';
|
|
23
24
|
import { seedL1ToL2Message } from './l1_to_l2_seeding.js';
|
|
@@ -152,7 +153,7 @@ export class BotFactory {
|
|
|
152
153
|
const signingKey = deriveSigningKey(secret);
|
|
153
154
|
const accountManager = await this.wallet.createSchnorrAccount(secret, salt, signingKey);
|
|
154
155
|
const metadata = await this.wallet.getContractMetadata(accountManager.address);
|
|
155
|
-
if (metadata.
|
|
156
|
+
if (metadata.initializationStatus === ContractInitializationStatus.INITIALIZED) {
|
|
156
157
|
this.log.info(`Account at ${accountManager.address.toString()} already initialized`);
|
|
157
158
|
const timer = new Timer();
|
|
158
159
|
const address = accountManager.address;
|
|
@@ -166,19 +167,30 @@ export class BotFactory {
|
|
|
166
167
|
const paymentMethod = new FeeJuicePaymentMethodWithClaim(accountManager.address, claim);
|
|
167
168
|
const deployMethod = await accountManager.getDeployMethod();
|
|
168
169
|
const maxFeesPerGas = (await this.aztecNode.getCurrentMinFees()).mul(1 + this.config.minFeePadding);
|
|
169
|
-
const
|
|
170
|
-
|
|
170
|
+
const { estimatedGas } = await deployMethod.simulate({
|
|
171
|
+
from: NO_FROM,
|
|
172
|
+
fee: {
|
|
173
|
+
estimateGas: true,
|
|
174
|
+
paymentMethod
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
const gasSettings = GasSettings.from({
|
|
178
|
+
...estimatedGas,
|
|
179
|
+
maxFeesPerGas,
|
|
180
|
+
maxPriorityFeesPerGas: GasFees.empty()
|
|
171
181
|
});
|
|
172
182
|
await this.withNoMinTxsPerBlock(async ()=>{
|
|
173
183
|
const { txHash } = await deployMethod.send({
|
|
174
|
-
from:
|
|
184
|
+
from: NO_FROM,
|
|
175
185
|
fee: {
|
|
176
186
|
gasSettings,
|
|
177
187
|
paymentMethod
|
|
178
188
|
},
|
|
179
189
|
wait: NO_WAIT
|
|
180
190
|
});
|
|
181
|
-
this.log.info(`Sent tx for account deployment with hash ${txHash.toString()}
|
|
191
|
+
this.log.info(`Sent tx for account deployment with hash ${txHash.toString()}`, {
|
|
192
|
+
gasSettings
|
|
193
|
+
});
|
|
182
194
|
return waitForTx(this.aztecNode, txHash, {
|
|
183
195
|
timeout: this.config.txMinedWaitSeconds
|
|
184
196
|
});
|
|
@@ -237,11 +249,22 @@ export class BotFactory {
|
|
|
237
249
|
await deploy.register();
|
|
238
250
|
} else {
|
|
239
251
|
this.log.info(`Deploying token contract at ${address.toString()}`);
|
|
252
|
+
const { estimatedGas } = await deploy.simulate({
|
|
253
|
+
...deployOpts,
|
|
254
|
+
fee: {
|
|
255
|
+
estimateGas: true
|
|
256
|
+
}
|
|
257
|
+
});
|
|
240
258
|
const { txHash } = await deploy.send({
|
|
241
259
|
...deployOpts,
|
|
260
|
+
fee: {
|
|
261
|
+
gasSettings: estimatedGas
|
|
262
|
+
},
|
|
242
263
|
wait: NO_WAIT
|
|
243
264
|
});
|
|
244
|
-
this.log.info(`Sent tx for token setup with hash ${txHash.toString()}
|
|
265
|
+
this.log.info(`Sent tx for token setup with hash ${txHash.toString()}`, {
|
|
266
|
+
estimatedGas
|
|
267
|
+
});
|
|
245
268
|
await this.withNoMinTxsPerBlock(async ()=>{
|
|
246
269
|
await waitForTx(this.aztecNode, txHash, {
|
|
247
270
|
timeout: this.config.txMinedWaitSeconds
|
|
@@ -275,13 +298,25 @@ export class BotFactory {
|
|
|
275
298
|
const instance = await this.registerOrDeployContract('AMM', deploy, deployOpts);
|
|
276
299
|
const amm = AMMContract.at(instance.address, this.wallet);
|
|
277
300
|
this.log.info(`AMM deployed at ${amm.address}`);
|
|
278
|
-
const
|
|
301
|
+
const setMinterInteraction = lpToken.methods.set_minter(amm.address, true);
|
|
302
|
+
const { estimatedGas: setMinterGas } = await setMinterInteraction.simulate({
|
|
279
303
|
from: deployer,
|
|
304
|
+
fee: {
|
|
305
|
+
estimateGas: true
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
const { receipt: minterReceipt } = await setMinterInteraction.send({
|
|
309
|
+
from: deployer,
|
|
310
|
+
fee: {
|
|
311
|
+
gasSettings: setMinterGas
|
|
312
|
+
},
|
|
280
313
|
wait: {
|
|
281
314
|
timeout: this.config.txMinedWaitSeconds
|
|
282
315
|
}
|
|
283
316
|
});
|
|
284
|
-
this.log.info(`Set LP token minter to AMM txHash=${minterReceipt.txHash.toString()}
|
|
317
|
+
this.log.info(`Set LP token minter to AMM txHash=${minterReceipt.txHash.toString()}`, {
|
|
318
|
+
estimatedGas: setMinterGas
|
|
319
|
+
});
|
|
285
320
|
this.log.info(`Liquidity token initialized`);
|
|
286
321
|
return amm;
|
|
287
322
|
}
|
|
@@ -314,18 +349,44 @@ export class BotFactory {
|
|
|
314
349
|
caller: amm.address,
|
|
315
350
|
call: await token1.methods.transfer_to_public_and_prepare_private_balance_increase(liquidityProvider, amm.address, amount1Max, authwitNonce).getFunctionCall()
|
|
316
351
|
});
|
|
317
|
-
const
|
|
352
|
+
const mintBatch = new BatchCall(this.wallet, [
|
|
318
353
|
token0.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
|
|
319
354
|
token1.methods.mint_to_private(liquidityProvider, MINT_BALANCE)
|
|
320
|
-
])
|
|
355
|
+
]);
|
|
356
|
+
const { estimatedGas: mintGas } = await mintBatch.simulate({
|
|
357
|
+
from: liquidityProvider,
|
|
358
|
+
fee: {
|
|
359
|
+
estimateGas: true
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
const { receipt: mintReceipt } = await mintBatch.send({
|
|
321
363
|
from: liquidityProvider,
|
|
364
|
+
fee: {
|
|
365
|
+
gasSettings: mintGas
|
|
366
|
+
},
|
|
322
367
|
wait: {
|
|
323
368
|
timeout: this.config.txMinedWaitSeconds
|
|
324
369
|
}
|
|
325
370
|
});
|
|
326
|
-
this.log.info(`Sent mint tx: ${mintReceipt.txHash.toString()}
|
|
327
|
-
|
|
371
|
+
this.log.info(`Sent mint tx: ${mintReceipt.txHash.toString()}`, {
|
|
372
|
+
estimatedGas: mintGas
|
|
373
|
+
});
|
|
374
|
+
const addLiquidityInteraction = amm.methods.add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, authwitNonce);
|
|
375
|
+
const { estimatedGas: addLiquidityGas } = await addLiquidityInteraction.simulate({
|
|
328
376
|
from: liquidityProvider,
|
|
377
|
+
fee: {
|
|
378
|
+
estimateGas: true
|
|
379
|
+
},
|
|
380
|
+
authWitnesses: [
|
|
381
|
+
token0Authwit,
|
|
382
|
+
token1Authwit
|
|
383
|
+
]
|
|
384
|
+
});
|
|
385
|
+
const { receipt: addLiquidityReceipt } = await addLiquidityInteraction.send({
|
|
386
|
+
from: liquidityProvider,
|
|
387
|
+
fee: {
|
|
388
|
+
gasSettings: addLiquidityGas
|
|
389
|
+
},
|
|
329
390
|
authWitnesses: [
|
|
330
391
|
token0Authwit,
|
|
331
392
|
token1Authwit
|
|
@@ -334,7 +395,9 @@ export class BotFactory {
|
|
|
334
395
|
timeout: this.config.txMinedWaitSeconds
|
|
335
396
|
}
|
|
336
397
|
});
|
|
337
|
-
this.log.info(`Sent tx to add liquidity to the AMM: ${addLiquidityReceipt.txHash.toString()}
|
|
398
|
+
this.log.info(`Sent tx to add liquidity to the AMM: ${addLiquidityReceipt.txHash.toString()}`, {
|
|
399
|
+
estimatedGas: addLiquidityGas
|
|
400
|
+
});
|
|
338
401
|
this.log.info(`Liquidity added`);
|
|
339
402
|
const [newT0Bal, newT1Bal, newLPBal] = await getPrivateBalances();
|
|
340
403
|
this.log.info(`Updated private balances of ${defaultAccountAddress} after minting and funding AMM: token0=${newT0Bal}, token1=${newT1Bal}, lp=${newLPBal}`);
|
|
@@ -347,10 +410,21 @@ export class BotFactory {
|
|
|
347
410
|
this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
|
|
348
411
|
await deploy.register();
|
|
349
412
|
} else {
|
|
350
|
-
|
|
413
|
+
const { estimatedGas } = await deploy.simulate({
|
|
414
|
+
...deployOpts,
|
|
415
|
+
fee: {
|
|
416
|
+
estimateGas: true
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
this.log.info(`Deploying contract ${name} at ${address.toString()}`, {
|
|
420
|
+
estimatedGas
|
|
421
|
+
});
|
|
351
422
|
await this.withNoMinTxsPerBlock(async ()=>{
|
|
352
423
|
const { txHash } = await deploy.send({
|
|
353
424
|
...deployOpts,
|
|
425
|
+
fee: {
|
|
426
|
+
gasSettings: estimatedGas
|
|
427
|
+
},
|
|
354
428
|
wait: NO_WAIT
|
|
355
429
|
});
|
|
356
430
|
this.log.info(`Sent contract ${name} setup tx with hash ${txHash.toString()}`);
|
|
@@ -390,13 +464,26 @@ export class BotFactory {
|
|
|
390
464
|
const additionalScopes = isStandardToken ? undefined : [
|
|
391
465
|
token.address
|
|
392
466
|
];
|
|
467
|
+
const mintBatch = new BatchCall(token.wallet, calls);
|
|
468
|
+
const { estimatedGas } = await mintBatch.simulate({
|
|
469
|
+
from: minter,
|
|
470
|
+
fee: {
|
|
471
|
+
estimateGas: true
|
|
472
|
+
},
|
|
473
|
+
additionalScopes
|
|
474
|
+
});
|
|
393
475
|
await this.withNoMinTxsPerBlock(async ()=>{
|
|
394
|
-
const { txHash } = await
|
|
476
|
+
const { txHash } = await mintBatch.send({
|
|
395
477
|
from: minter,
|
|
396
478
|
additionalScopes,
|
|
479
|
+
fee: {
|
|
480
|
+
gasSettings: estimatedGas
|
|
481
|
+
},
|
|
397
482
|
wait: NO_WAIT
|
|
398
483
|
});
|
|
399
|
-
this.log.info(`Sent token mint tx with hash ${txHash.toString()}
|
|
484
|
+
this.log.info(`Sent token mint tx with hash ${txHash.toString()}`, {
|
|
485
|
+
estimatedGas
|
|
486
|
+
});
|
|
400
487
|
return waitForTx(this.aztecNode, txHash, {
|
|
401
488
|
timeout: this.config.txMinedWaitSeconds
|
|
402
489
|
});
|
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.3f296a7d2",
|
|
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.3f296a7d2",
|
|
58
|
+
"@aztec/aztec.js": "0.0.1-commit.3f296a7d2",
|
|
59
|
+
"@aztec/entrypoints": "0.0.1-commit.3f296a7d2",
|
|
60
|
+
"@aztec/ethereum": "0.0.1-commit.3f296a7d2",
|
|
61
|
+
"@aztec/foundation": "0.0.1-commit.3f296a7d2",
|
|
62
|
+
"@aztec/kv-store": "0.0.1-commit.3f296a7d2",
|
|
63
|
+
"@aztec/l1-artifacts": "0.0.1-commit.3f296a7d2",
|
|
64
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.3f296a7d2",
|
|
65
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.3f296a7d2",
|
|
66
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.3f296a7d2",
|
|
67
|
+
"@aztec/protocol-contracts": "0.0.1-commit.3f296a7d2",
|
|
68
|
+
"@aztec/stdlib": "0.0.1-commit.3f296a7d2",
|
|
69
|
+
"@aztec/telemetry-client": "0.0.1-commit.3f296a7d2",
|
|
70
|
+
"@aztec/wallets": "0.0.1-commit.3f296a7d2",
|
|
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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getInitialTestAccountsData } from '@aztec/accounts/testing';
|
|
2
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
2
3
|
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
3
4
|
import {
|
|
4
5
|
BatchCall,
|
|
@@ -15,6 +16,7 @@ import { deriveKeys } from '@aztec/aztec.js/keys';
|
|
|
15
16
|
import { createLogger } from '@aztec/aztec.js/log';
|
|
16
17
|
import { waitForL1ToL2MessageReady } from '@aztec/aztec.js/messaging';
|
|
17
18
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
19
|
+
import { ContractInitializationStatus } from '@aztec/aztec.js/wallet';
|
|
18
20
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
19
21
|
import { createExtendedL1Client } from '@aztec/ethereum/client';
|
|
20
22
|
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
@@ -27,7 +29,7 @@ import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
|
|
|
27
29
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
28
30
|
import { TestContract } from '@aztec/noir-test-contracts.js/Test';
|
|
29
31
|
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
30
|
-
import { GasSettings } from '@aztec/stdlib/gas';
|
|
32
|
+
import { GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
31
33
|
import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
32
34
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
33
35
|
import { EmbeddedWallet } from '@aztec/wallets/embedded';
|
|
@@ -207,7 +209,7 @@ export class BotFactory {
|
|
|
207
209
|
const signingKey = deriveSigningKey(secret);
|
|
208
210
|
const accountManager = await this.wallet.createSchnorrAccount(secret, salt, signingKey);
|
|
209
211
|
const metadata = await this.wallet.getContractMetadata(accountManager.address);
|
|
210
|
-
if (metadata.
|
|
212
|
+
if (metadata.initializationStatus === ContractInitializationStatus.INITIALIZED) {
|
|
211
213
|
this.log.info(`Account at ${accountManager.address.toString()} already initialized`);
|
|
212
214
|
const timer = new Timer();
|
|
213
215
|
const address = accountManager.address;
|
|
@@ -223,15 +225,20 @@ export class BotFactory {
|
|
|
223
225
|
const paymentMethod = new FeeJuicePaymentMethodWithClaim(accountManager.address, claim);
|
|
224
226
|
const deployMethod = await accountManager.getDeployMethod();
|
|
225
227
|
const maxFeesPerGas = (await this.aztecNode.getCurrentMinFees()).mul(1 + this.config.minFeePadding);
|
|
226
|
-
|
|
228
|
+
|
|
229
|
+
const { estimatedGas } = await deployMethod.simulate({
|
|
230
|
+
from: NO_FROM,
|
|
231
|
+
fee: { estimateGas: true, paymentMethod },
|
|
232
|
+
});
|
|
233
|
+
const gasSettings = GasSettings.from({ ...estimatedGas!, maxFeesPerGas, maxPriorityFeesPerGas: GasFees.empty() });
|
|
227
234
|
|
|
228
235
|
await this.withNoMinTxsPerBlock(async () => {
|
|
229
236
|
const { txHash } = await deployMethod.send({
|
|
230
|
-
from:
|
|
237
|
+
from: NO_FROM,
|
|
231
238
|
fee: { gasSettings, paymentMethod },
|
|
232
239
|
wait: NO_WAIT,
|
|
233
240
|
});
|
|
234
|
-
this.log.info(`Sent tx for account deployment with hash ${txHash.toString()}
|
|
241
|
+
this.log.info(`Sent tx for account deployment with hash ${txHash.toString()}`, { gasSettings });
|
|
235
242
|
return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
|
|
236
243
|
});
|
|
237
244
|
this.log.info(`Account deployed at ${address}`);
|
|
@@ -297,8 +304,9 @@ export class BotFactory {
|
|
|
297
304
|
await deploy.register();
|
|
298
305
|
} else {
|
|
299
306
|
this.log.info(`Deploying token contract at ${address.toString()}`);
|
|
300
|
-
const {
|
|
301
|
-
|
|
307
|
+
const { estimatedGas } = await deploy.simulate({ ...deployOpts, fee: { estimateGas: true } });
|
|
308
|
+
const { txHash } = await deploy.send({ ...deployOpts, fee: { gasSettings: estimatedGas }, wait: NO_WAIT });
|
|
309
|
+
this.log.info(`Sent tx for token setup with hash ${txHash.toString()}`, { estimatedGas });
|
|
302
310
|
await this.withNoMinTxsPerBlock(async () => {
|
|
303
311
|
await waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
|
|
304
312
|
return token;
|
|
@@ -338,10 +346,19 @@ export class BotFactory {
|
|
|
338
346
|
const amm = AMMContract.at(instance.address, this.wallet);
|
|
339
347
|
|
|
340
348
|
this.log.info(`AMM deployed at ${amm.address}`);
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
349
|
+
const setMinterInteraction = lpToken.methods.set_minter(amm.address, true);
|
|
350
|
+
const { estimatedGas: setMinterGas } = await setMinterInteraction.simulate({
|
|
351
|
+
from: deployer,
|
|
352
|
+
fee: { estimateGas: true },
|
|
353
|
+
});
|
|
354
|
+
const { receipt: minterReceipt } = await setMinterInteraction.send({
|
|
355
|
+
from: deployer,
|
|
356
|
+
fee: { gasSettings: setMinterGas },
|
|
357
|
+
wait: { timeout: this.config.txMinedWaitSeconds },
|
|
358
|
+
});
|
|
359
|
+
this.log.info(`Set LP token minter to AMM txHash=${minterReceipt.txHash.toString()}`, {
|
|
360
|
+
estimatedGas: setMinterGas,
|
|
361
|
+
});
|
|
345
362
|
this.log.info(`Liquidity token initialized`);
|
|
346
363
|
|
|
347
364
|
return amm;
|
|
@@ -409,22 +426,44 @@ export class BotFactory {
|
|
|
409
426
|
.getFunctionCall(),
|
|
410
427
|
});
|
|
411
428
|
|
|
412
|
-
const
|
|
429
|
+
const mintBatch = new BatchCall(this.wallet, [
|
|
413
430
|
token0.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
|
|
414
431
|
token1.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
|
|
415
|
-
])
|
|
432
|
+
]);
|
|
433
|
+
const { estimatedGas: mintGas } = await mintBatch.simulate({
|
|
434
|
+
from: liquidityProvider,
|
|
435
|
+
fee: { estimateGas: true },
|
|
436
|
+
});
|
|
437
|
+
const { receipt: mintReceipt } = await mintBatch.send({
|
|
438
|
+
from: liquidityProvider,
|
|
439
|
+
fee: { gasSettings: mintGas },
|
|
440
|
+
wait: { timeout: this.config.txMinedWaitSeconds },
|
|
441
|
+
});
|
|
416
442
|
|
|
417
|
-
this.log.info(`Sent mint tx: ${mintReceipt.txHash.toString()}
|
|
443
|
+
this.log.info(`Sent mint tx: ${mintReceipt.txHash.toString()}`, { estimatedGas: mintGas });
|
|
418
444
|
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
445
|
+
const addLiquidityInteraction = amm.methods.add_liquidity(
|
|
446
|
+
amount0Max,
|
|
447
|
+
amount1Max,
|
|
448
|
+
amount0Min,
|
|
449
|
+
amount1Min,
|
|
450
|
+
authwitNonce,
|
|
451
|
+
);
|
|
452
|
+
const { estimatedGas: addLiquidityGas } = await addLiquidityInteraction.simulate({
|
|
453
|
+
from: liquidityProvider,
|
|
454
|
+
fee: { estimateGas: true },
|
|
455
|
+
authWitnesses: [token0Authwit, token1Authwit],
|
|
456
|
+
});
|
|
457
|
+
const { receipt: addLiquidityReceipt } = await addLiquidityInteraction.send({
|
|
458
|
+
from: liquidityProvider,
|
|
459
|
+
fee: { gasSettings: addLiquidityGas },
|
|
460
|
+
authWitnesses: [token0Authwit, token1Authwit],
|
|
461
|
+
wait: { timeout: this.config.txMinedWaitSeconds },
|
|
462
|
+
});
|
|
426
463
|
|
|
427
|
-
this.log.info(`Sent tx to add liquidity to the AMM: ${addLiquidityReceipt.txHash.toString()}
|
|
464
|
+
this.log.info(`Sent tx to add liquidity to the AMM: ${addLiquidityReceipt.txHash.toString()}`, {
|
|
465
|
+
estimatedGas: addLiquidityGas,
|
|
466
|
+
});
|
|
428
467
|
this.log.info(`Liquidity added`);
|
|
429
468
|
|
|
430
469
|
const [newT0Bal, newT1Bal, newLPBal] = await getPrivateBalances();
|
|
@@ -445,9 +484,10 @@ export class BotFactory {
|
|
|
445
484
|
this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
|
|
446
485
|
await deploy.register();
|
|
447
486
|
} else {
|
|
448
|
-
|
|
487
|
+
const { estimatedGas } = await deploy.simulate({ ...deployOpts, fee: { estimateGas: true } });
|
|
488
|
+
this.log.info(`Deploying contract ${name} at ${address.toString()}`, { estimatedGas });
|
|
449
489
|
await this.withNoMinTxsPerBlock(async () => {
|
|
450
|
-
const { txHash } = await deploy.send({ ...deployOpts, wait: NO_WAIT });
|
|
490
|
+
const { txHash } = await deploy.send({ ...deployOpts, fee: { gasSettings: estimatedGas }, wait: NO_WAIT });
|
|
451
491
|
this.log.info(`Sent contract ${name} setup tx with hash ${txHash.toString()}`);
|
|
452
492
|
return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
|
|
453
493
|
});
|
|
@@ -491,13 +531,16 @@ export class BotFactory {
|
|
|
491
531
|
|
|
492
532
|
// PrivateToken's mint accesses contract-level private storage vars (admin, total_supply).
|
|
493
533
|
const additionalScopes = isStandardToken ? undefined : [token.address];
|
|
534
|
+
const mintBatch = new BatchCall(token.wallet, calls);
|
|
535
|
+
const { estimatedGas } = await mintBatch.simulate({ from: minter, fee: { estimateGas: true }, additionalScopes });
|
|
494
536
|
await this.withNoMinTxsPerBlock(async () => {
|
|
495
|
-
const { txHash } = await
|
|
537
|
+
const { txHash } = await mintBatch.send({
|
|
496
538
|
from: minter,
|
|
497
539
|
additionalScopes,
|
|
540
|
+
fee: { gasSettings: estimatedGas },
|
|
498
541
|
wait: NO_WAIT,
|
|
499
542
|
});
|
|
500
|
-
this.log.info(`Sent token mint tx with hash ${txHash.toString()}
|
|
543
|
+
this.log.info(`Sent token mint tx with hash ${txHash.toString()}`, { estimatedGas });
|
|
501
544
|
return waitForTx(this.aztecNode, txHash, { timeout: this.config.txMinedWaitSeconds });
|
|
502
545
|
});
|
|
503
546
|
}
|