@aztec/bot 0.0.1-commit.8c0b8ff → 0.0.1-commit.8cb2d04d8
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/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +1 -2
- package/dest/factory.d.ts +6 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +205 -41
- package/package.json +15 -15
- package/src/config.ts +1 -2
- package/src/factory.ts +219 -41
package/dest/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ConfigMappingsType, SecretValue } from '@aztec/foundation/config';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import { type DataStoreConfig } from '@aztec/kv-store
|
|
3
|
+
import { type DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
4
4
|
import type { ComponentsVersions } from '@aztec/stdlib/versioning';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
declare const BotFollowChain: readonly ["NONE", "PROPOSED", "CHECKPOINTED", "PROVEN"];
|
|
@@ -176,6 +176,7 @@ export declare const BotConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
176
176
|
botMode: "amm" | "crosschain" | "transfer";
|
|
177
177
|
l2ToL1MessagesPerTx: number;
|
|
178
178
|
l1ToL2SeedCount: number;
|
|
179
|
+
dataDirectory?: string | undefined;
|
|
179
180
|
nodeUrl: string | undefined;
|
|
180
181
|
nodeAdminUrl: string | undefined;
|
|
181
182
|
l1RpcUrls: string[] | undefined;
|
|
@@ -185,7 +186,6 @@ export declare const BotConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
185
186
|
l1Mnemonic: SecretValue<string> | undefined;
|
|
186
187
|
l1PrivateKey: SecretValue<string> | undefined;
|
|
187
188
|
senderPrivateKey: SecretValue<Fr> | undefined;
|
|
188
|
-
dataDirectory: string | undefined;
|
|
189
189
|
dataStoreMapSizeKb: number;
|
|
190
190
|
}, {
|
|
191
191
|
nodeUrl?: string | undefined;
|
|
@@ -223,4 +223,4 @@ export declare function getBotConfigFromEnv(): BotConfig;
|
|
|
223
223
|
export declare function getBotDefaultConfig(): BotConfig;
|
|
224
224
|
export declare function getVersions(): Partial<ComponentsVersions>;
|
|
225
225
|
export {};
|
|
226
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
226
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFDTCxLQUFLLGtCQUFrQixFQUN2QixXQUFXLEVBU1osTUFBTSwwQkFBMEIsQ0FBQztBQUNsQyxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFHcEQsT0FBTyxFQUFFLEtBQUssZUFBZSxFQUFzQixNQUFNLHdCQUF3QixDQUFDO0FBRWxGLE9BQU8sS0FBSyxFQUFFLGtCQUFrQixFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFFbkUsT0FBTyxFQUFFLENBQUMsRUFBRSxNQUFNLEtBQUssQ0FBQztBQUV4QixRQUFBLE1BQU0sY0FBYyx5REFBMEQsQ0FBQztBQUMvRSxLQUFLLGNBQWMsR0FBRyxDQUFDLE9BQU8sY0FBYyxDQUFDLENBQUMsTUFBTSxDQUFDLENBQUM7QUFFdEQsUUFBQSxNQUFNLE9BQU8sNENBQTZDLENBQUM7QUFDM0QsS0FBSyxPQUFPLEdBQUcsQ0FBQyxPQUFPLE9BQU8sQ0FBQyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0FBRXhDLG9CQUFZLHVCQUF1QjtJQUNqQyxhQUFhLGtCQUFrQjtJQUMvQixvQkFBb0IseUJBQXlCO0NBQzlDO0FBRUQsTUFBTSxNQUFNLFNBQV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QsQ0FBQztBQUVGLHdCQUFnQixtQkFBbUIsSUFBSSxTQUFTLENBRS9DO0FBRUQsd0JBQWdCLG1CQUFtQixJQUFJLFNBQVMsQ0FFL0M7QUFFRCx3QkFBZ0IsV0FBVyxJQUFJLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxDQUt6RCJ9
|
package/dest/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,WAAW,EASZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,WAAW,EASZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAGpD,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,wBAAwB,CAAC;AAElF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,cAAc,yDAA0D,CAAC;AAC/E,KAAK,cAAc,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtD,QAAA,MAAM,OAAO,4CAA6C,CAAC;AAC3D,KAAK,OAAO,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAExC,oBAAY,uBAAuB;IACjC,aAAa,kBAAkB;IAC/B,oBAAoB,yBAAyB;CAC9C;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,4EAA4E;IAC5E,YAAY,EAAE,MAAM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O,CAAC;IACjB,2DAAyD;IACzD,mBAAmB,EAAE,MAAM,CAAC;IAC5B,gEAA8D;IAC9D,eAAe,EAAE,MAAM,CAAC;CACzB,GAAG,IAAI,CAAC,eAAe,EAAE,eAAe,GAAG,oBAAoB,CAAC,CAAC;AAElE,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8C3B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,kBAAkB,CAAC,SAAS,CAmK3D,CAAC;AAEF,wBAAgB,mBAAmB,IAAI,SAAS,CAE/C;AAED,wBAAgB,mBAAmB,IAAI,SAAS,CAE/C;AAED,wBAAgB,WAAW,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAKzD"}
|
package/dest/config.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { booleanConfigHelper, getConfigFromMappings, getDefaultConfig, numberConfigHelper, optionalNumberConfigHelper, pickConfigMappings, secretFrConfigHelper, secretStringConfigHelper } from '@aztec/foundation/config';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import { dataConfigMappings } from '@aztec/kv-store/config';
|
|
4
3
|
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
5
4
|
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
5
|
+
import { dataConfigMappings } from '@aztec/stdlib/kv-store';
|
|
6
6
|
import { schemas, zodFor } from '@aztec/stdlib/schemas';
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
const BotFollowChain = [
|
|
@@ -61,7 +61,6 @@ export const BotConfigSchema = zodFor()(z.object({
|
|
|
61
61
|
l1Mnemonic: undefined,
|
|
62
62
|
l1PrivateKey: undefined,
|
|
63
63
|
senderPrivateKey: undefined,
|
|
64
|
-
dataDirectory: undefined,
|
|
65
64
|
dataStoreMapSizeKb: 1_024 * 1_024,
|
|
66
65
|
...config
|
|
67
66
|
})));
|
package/dest/factory.d.ts
CHANGED
|
@@ -51,14 +51,19 @@ 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;
|
|
66
|
+
private getMinFees;
|
|
62
67
|
private withNoMinTxsPerBlock;
|
|
63
68
|
}
|
|
64
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
69
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ZhY3RvcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBcUJ6RCxPQUFPLEtBQUssRUFBRSx3QkFBd0IsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBSXRFLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSw4QkFBOEIsQ0FBQztBQUMzRCxPQUFPLEVBQUUsb0JBQW9CLEVBQUUsTUFBTSx1Q0FBdUMsQ0FBQztBQUM3RSxPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sZ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BSSxPQUFPLENBQUM7UUFDL0IsTUFBTSxFQUFFLGNBQWMsQ0FBQztRQUN2QixxQkFBcUIsRUFBRSxZQUFZLENBQUM7UUFDcEMsR0FBRyxFQUFFLFdBQVcsQ0FBQztRQUNqQixNQUFNLEVBQUUsYUFBYSxDQUFDO1FBQ3RCLE1BQU0sRUFBRSxhQUFhLENBQUM7UUFDdEIsSUFBSSxFQUFFLFNBQVMsQ0FBQztLQUNqQixDQUFDLENBNEJEO0lBRUQ7OztPQUdHO0lBQ1UsZUFBZSxJQUFJLE9BQU8sQ0FBQztRQUN0QyxNQUFNLEVBQUUsY0FBYyxDQUFDO1FBQ3ZCLHFCQUFxQixFQUFFLFlBQVksQ0FBQztRQUNwQyxRQUFRLEVBQUUsWUFBWSxDQUFDO1FBQ3ZCLElBQUksRUFBRSxTQUFTLENBQUM7UUFDaEIsUUFBUSxFQUFFLHdCQUF3QixDQUFDO1FBQ25DLGFBQWEsRUFBRSxNQUFNLENBQUM7S0FDdkIsQ0FBQyxDQTJERDtZQUVhLGlCQUFpQjtZQWVqQixZQUFZO1lBV1osMEJBQTBCO1lBdUMxQixnQkFBZ0I7WUFlaEIsaUNBQWlDO1lBY2pDLHlDQUF5QztZQW1CekMsZ0JBQWdCO1lBaUNoQixVQUFVO1lBd0NWLGtCQUFrQjtZQWFsQixnQkFBZ0I7WUF3QmhCLE9BQU87WUErRlAsd0JBQXdCO1lBNkR4QixxQkFBcUI7WUF1RHJCLFVBQVU7WUFpRFYsc0JBQXNCO1lBMkJ0QixnQkFBZ0I7WUFnQ2hCLFVBQVU7WUFZVixvQkFBb0I7Q0FlbkMifQ==
|
package/dest/factory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":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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;YAgChB,UAAU;YAYV,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, 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);
|
|
@@ -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
|
/**
|
|
@@ -270,7 +316,8 @@ export class BotFactory {
|
|
|
270
316
|
const instance = await this.registerOrDeployContract('AMM', deploy, deployOpts);
|
|
271
317
|
const amm = AMMContract.at(instance.address, this.wallet);
|
|
272
318
|
this.log.info(`AMM deployed at ${amm.address}`);
|
|
273
|
-
const
|
|
319
|
+
const setMinterInteraction = lpToken.methods.set_minter(amm.address, true);
|
|
320
|
+
const { receipt: minterReceipt } = await setMinterInteraction.send({
|
|
274
321
|
from: deployer,
|
|
275
322
|
wait: {
|
|
276
323
|
timeout: this.config.txMinedWaitSeconds
|
|
@@ -309,17 +356,19 @@ export class BotFactory {
|
|
|
309
356
|
caller: amm.address,
|
|
310
357
|
call: await token1.methods.transfer_to_public_and_prepare_private_balance_increase(liquidityProvider, amm.address, amount1Max, authwitNonce).getFunctionCall()
|
|
311
358
|
});
|
|
312
|
-
const
|
|
359
|
+
const mintBatch = new BatchCall(this.wallet, [
|
|
313
360
|
token0.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
|
|
314
361
|
token1.methods.mint_to_private(liquidityProvider, MINT_BALANCE)
|
|
315
|
-
])
|
|
362
|
+
]);
|
|
363
|
+
const { receipt: mintReceipt } = await mintBatch.send({
|
|
316
364
|
from: liquidityProvider,
|
|
317
365
|
wait: {
|
|
318
366
|
timeout: this.config.txMinedWaitSeconds
|
|
319
367
|
}
|
|
320
368
|
});
|
|
321
369
|
this.log.info(`Sent mint tx: ${mintReceipt.txHash.toString()}`);
|
|
322
|
-
const
|
|
370
|
+
const addLiquidityInteraction = amm.methods.add_liquidity(amount0Max, amount1Max, amount0Min, amount1Min, authwitNonce);
|
|
371
|
+
const { receipt: addLiquidityReceipt } = await addLiquidityInteraction.send({
|
|
323
372
|
from: liquidityProvider,
|
|
324
373
|
authWitnesses: [
|
|
325
374
|
token0Authwit,
|
|
@@ -342,24 +391,127 @@ export class BotFactory {
|
|
|
342
391
|
this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
|
|
343
392
|
await deploy.register();
|
|
344
393
|
} else {
|
|
345
|
-
|
|
346
|
-
await this.
|
|
347
|
-
|
|
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({
|
|
348
402
|
...deployOpts,
|
|
349
|
-
|
|
403
|
+
fee: {
|
|
404
|
+
estimateGas: true,
|
|
405
|
+
paymentMethod
|
|
406
|
+
}
|
|
350
407
|
});
|
|
351
|
-
this.
|
|
352
|
-
|
|
353
|
-
|
|
408
|
+
const maxFeesPerGas = (await this.getMinFees()).mul(1 + this.config.minFeePadding);
|
|
409
|
+
const gasSettings = GasSettings.from({
|
|
410
|
+
...estimatedGas,
|
|
411
|
+
maxFeesPerGas,
|
|
412
|
+
maxPriorityFeesPerGas: GasFees.empty()
|
|
354
413
|
});
|
|
355
|
-
|
|
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
|
+
}
|
|
356
453
|
}
|
|
357
454
|
return instance;
|
|
358
455
|
}
|
|
359
456
|
/**
|
|
360
457
|
* Mints private and public tokens for the sender if their balance is below the minimum.
|
|
361
458
|
* @param token - Token contract.
|
|
362
|
-
*/
|
|
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.getMinFees()).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) {
|
|
363
515
|
const isStandardToken = isStandardTokenContract(token);
|
|
364
516
|
let privateBalance = 0n;
|
|
365
517
|
let publicBalance = 0n;
|
|
@@ -385,8 +537,9 @@ export class BotFactory {
|
|
|
385
537
|
const additionalScopes = isStandardToken ? undefined : [
|
|
386
538
|
token.address
|
|
387
539
|
];
|
|
540
|
+
const mintBatch = new BatchCall(token.wallet, calls);
|
|
388
541
|
await this.withNoMinTxsPerBlock(async ()=>{
|
|
389
|
-
const { txHash } = await
|
|
542
|
+
const { txHash } = await mintBatch.send({
|
|
390
543
|
from: minter,
|
|
391
544
|
additionalScopes,
|
|
392
545
|
wait: NO_WAIT
|
|
@@ -443,6 +596,17 @@ export class BotFactory {
|
|
|
443
596
|
this.log.info(`Created a claim for ${mintAmount} L1 fee juice to ${recipient}.`, claim);
|
|
444
597
|
return claim;
|
|
445
598
|
}
|
|
599
|
+
/** Returns worst-case min fees across predicted slots, with fallback to current min fees. */ async getMinFees() {
|
|
600
|
+
try {
|
|
601
|
+
const predicted = await this.aztecNode.getPredictedMinFees(ManaUsageEstimate.Limit);
|
|
602
|
+
if (predicted.length === 0) {
|
|
603
|
+
return this.aztecNode.getCurrentMinFees();
|
|
604
|
+
}
|
|
605
|
+
return predicted.reduce((worst, fees)=>fees.feePerL2Gas > worst.feePerL2Gas ? fees : worst);
|
|
606
|
+
} catch {
|
|
607
|
+
return this.aztecNode.getCurrentMinFees();
|
|
608
|
+
}
|
|
609
|
+
}
|
|
446
610
|
async withNoMinTxsPerBlock(fn) {
|
|
447
611
|
if (!this.aztecNodeAdmin || !this.config.flushSetupTransactions) {
|
|
448
612
|
this.log.verbose(`No node admin client or flushing not requested (not setting minTxsPerBlock to 0)`);
|
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.8cb2d04d8",
|
|
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.8cb2d04d8",
|
|
58
|
+
"@aztec/aztec.js": "0.0.1-commit.8cb2d04d8",
|
|
59
|
+
"@aztec/entrypoints": "0.0.1-commit.8cb2d04d8",
|
|
60
|
+
"@aztec/ethereum": "0.0.1-commit.8cb2d04d8",
|
|
61
|
+
"@aztec/foundation": "0.0.1-commit.8cb2d04d8",
|
|
62
|
+
"@aztec/kv-store": "0.0.1-commit.8cb2d04d8",
|
|
63
|
+
"@aztec/l1-artifacts": "0.0.1-commit.8cb2d04d8",
|
|
64
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.8cb2d04d8",
|
|
65
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.8cb2d04d8",
|
|
66
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.8cb2d04d8",
|
|
67
|
+
"@aztec/protocol-contracts": "0.0.1-commit.8cb2d04d8",
|
|
68
|
+
"@aztec/stdlib": "0.0.1-commit.8cb2d04d8",
|
|
69
|
+
"@aztec/telemetry-client": "0.0.1-commit.8cb2d04d8",
|
|
70
|
+
"@aztec/wallets": "0.0.1-commit.8cb2d04d8",
|
|
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/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
|
|
|
@@ -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
|
})),
|
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, ManaUsageEstimate } 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
|
|
|
@@ -337,9 +400,11 @@ export class BotFactory {
|
|
|
337
400
|
const amm = AMMContract.at(instance.address, this.wallet);
|
|
338
401
|
|
|
339
402
|
this.log.info(`AMM deployed at ${amm.address}`);
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
|
|
403
|
+
const setMinterInteraction = lpToken.methods.set_minter(amm.address, true);
|
|
404
|
+
const { receipt: minterReceipt } = await setMinterInteraction.send({
|
|
405
|
+
from: deployer,
|
|
406
|
+
wait: { timeout: this.config.txMinedWaitSeconds },
|
|
407
|
+
});
|
|
343
408
|
this.log.info(`Set LP token minter to AMM txHash=${minterReceipt.txHash.toString()}`);
|
|
344
409
|
this.log.info(`Liquidity token initialized`);
|
|
345
410
|
|
|
@@ -408,20 +473,29 @@ export class BotFactory {
|
|
|
408
473
|
.getFunctionCall(),
|
|
409
474
|
});
|
|
410
475
|
|
|
411
|
-
const
|
|
476
|
+
const mintBatch = new BatchCall(this.wallet, [
|
|
412
477
|
token0.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
|
|
413
478
|
token1.methods.mint_to_private(liquidityProvider, MINT_BALANCE),
|
|
414
|
-
])
|
|
479
|
+
]);
|
|
480
|
+
const { receipt: mintReceipt } = await mintBatch.send({
|
|
481
|
+
from: liquidityProvider,
|
|
482
|
+
wait: { timeout: this.config.txMinedWaitSeconds },
|
|
483
|
+
});
|
|
415
484
|
|
|
416
485
|
this.log.info(`Sent mint tx: ${mintReceipt.txHash.toString()}`);
|
|
417
486
|
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
487
|
+
const addLiquidityInteraction = amm.methods.add_liquidity(
|
|
488
|
+
amount0Max,
|
|
489
|
+
amount1Max,
|
|
490
|
+
amount0Min,
|
|
491
|
+
amount1Min,
|
|
492
|
+
authwitNonce,
|
|
493
|
+
);
|
|
494
|
+
const { receipt: addLiquidityReceipt } = await addLiquidityInteraction.send({
|
|
495
|
+
from: liquidityProvider,
|
|
496
|
+
authWitnesses: [token0Authwit, token1Authwit],
|
|
497
|
+
wait: { timeout: this.config.txMinedWaitSeconds },
|
|
498
|
+
});
|
|
425
499
|
|
|
426
500
|
this.log.info(`Sent tx to add liquidity to the AMM: ${addLiquidityReceipt.txHash.toString()}`);
|
|
427
501
|
this.log.info(`Liquidity added`);
|
|
@@ -444,12 +518,42 @@ export class BotFactory {
|
|
|
444
518
|
this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
|
|
445
519
|
await deploy.register();
|
|
446
520
|
} else {
|
|
447
|
-
|
|
448
|
-
await this.
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
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.getMinFees()).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
|
+
}
|
|
453
557
|
}
|
|
454
558
|
return instance;
|
|
455
559
|
}
|
|
@@ -458,6 +562,66 @@ export class BotFactory {
|
|
|
458
562
|
* Mints private and public tokens for the sender if their balance is below the minimum.
|
|
459
563
|
* @param token - Token contract.
|
|
460
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.getMinFees()).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
|
+
|
|
461
625
|
private async mintTokens(token: TokenContract | PrivateTokenContract, minter: AztecAddress) {
|
|
462
626
|
const isStandardToken = isStandardTokenContract(token);
|
|
463
627
|
let privateBalance = 0n;
|
|
@@ -490,8 +654,9 @@ export class BotFactory {
|
|
|
490
654
|
|
|
491
655
|
// PrivateToken's mint accesses contract-level private storage vars (admin, total_supply).
|
|
492
656
|
const additionalScopes = isStandardToken ? undefined : [token.address];
|
|
657
|
+
const mintBatch = new BatchCall(token.wallet, calls);
|
|
493
658
|
await this.withNoMinTxsPerBlock(async () => {
|
|
494
|
-
const { txHash } = await
|
|
659
|
+
const { txHash } = await mintBatch.send({
|
|
495
660
|
from: minter,
|
|
496
661
|
additionalScopes,
|
|
497
662
|
wait: NO_WAIT,
|
|
@@ -564,6 +729,19 @@ export class BotFactory {
|
|
|
564
729
|
return claim as L2AmountClaim;
|
|
565
730
|
}
|
|
566
731
|
|
|
732
|
+
/** Returns worst-case min fees across predicted slots, with fallback to current min fees. */
|
|
733
|
+
private async getMinFees(): Promise<GasFees> {
|
|
734
|
+
try {
|
|
735
|
+
const predicted = await this.aztecNode.getPredictedMinFees(ManaUsageEstimate.Limit);
|
|
736
|
+
if (predicted.length === 0) {
|
|
737
|
+
return this.aztecNode.getCurrentMinFees();
|
|
738
|
+
}
|
|
739
|
+
return predicted.reduce((worst, fees) => (fees.feePerL2Gas > worst.feePerL2Gas ? fees : worst));
|
|
740
|
+
} catch {
|
|
741
|
+
return this.aztecNode.getCurrentMinFees();
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
567
745
|
private async withNoMinTxsPerBlock<T>(fn: () => Promise<T>): Promise<T> {
|
|
568
746
|
if (!this.aztecNodeAdmin || !this.config.flushSetupTransactions) {
|
|
569
747
|
this.log.verbose(`No node admin client or flushing not requested (not setting minTxsPerBlock to 0)`);
|