@aztec/bot 3.0.0-nightly.20250921 → 3.0.0-nightly.20250923
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 +3 -6
- package/dest/amm_bot.d.ts.map +1 -1
- package/dest/amm_bot.js +3 -3
- package/dest/bot.d.ts +3 -6
- package/dest/bot.d.ts.map +1 -1
- package/dest/bot.js +3 -3
- package/dest/factory.d.ts +5 -10
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +21 -52
- package/dest/runner.d.ts +8 -11
- package/dest/runner.d.ts.map +1 -1
- package/dest/runner.js +14 -30
- package/package.json +12 -12
- package/src/amm_bot.ts +10 -5
- package/src/bot.ts +10 -5
- package/src/factory.ts +18 -56
- package/src/runner.ts +14 -21
package/dest/amm_bot.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AztecAddress, SentTx, TxReceipt, type Wallet } from '@aztec/aztec.js';
|
|
2
2
|
import type { AMMContract } from '@aztec/noir-contracts.js/AMM';
|
|
3
3
|
import type { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
4
|
-
import type { AztecNode, AztecNodeAdmin
|
|
4
|
+
import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
5
|
+
import type { TestWallet } from '@aztec/test-wallet';
|
|
5
6
|
import { BaseBot } from './base_bot.js';
|
|
6
7
|
import type { BotConfig } from './config.js';
|
|
7
8
|
type Balances = {
|
|
@@ -13,11 +14,7 @@ export declare class AmmBot extends BaseBot {
|
|
|
13
14
|
readonly token0: TokenContract;
|
|
14
15
|
readonly token1: TokenContract;
|
|
15
16
|
protected constructor(node: AztecNode, wallet: Wallet, defaultAccountAddress: AztecAddress, amm: AMMContract, token0: TokenContract, token1: TokenContract, config: BotConfig);
|
|
16
|
-
static create(config: BotConfig,
|
|
17
|
-
pxe?: PXE;
|
|
18
|
-
node?: AztecNode;
|
|
19
|
-
nodeAdmin?: AztecNodeAdmin;
|
|
20
|
-
}): Promise<AmmBot>;
|
|
17
|
+
static create(config: BotConfig, wallet: TestWallet, aztecNode: AztecNode, aztecNodeAdmin: AztecNodeAdmin | undefined): Promise<AmmBot>;
|
|
21
18
|
protected createAndSendTx(logCtx: object): Promise<SentTx>;
|
|
22
19
|
protected onTxMined(receipt: TxReceipt, logCtx: object): Promise<void>;
|
|
23
20
|
getAmmBalances(): Promise<Balances>;
|
package/dest/amm_bot.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amm_bot.d.ts","sourceRoot":"","sources":["../src/amm_bot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAM,MAAM,EAAE,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEnF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"amm_bot.d.ts","sourceRoot":"","sources":["../src/amm_bot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAM,MAAM,EAAE,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEnF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAM7C,KAAK,QAAQ,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnD,qBAAa,MAAO,SAAQ,OAAO;aAKf,GAAG,EAAE,WAAW;aAChB,MAAM,EAAE,aAAa;aACrB,MAAM,EAAE,aAAa;IANvC,SAAS,aACP,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,MAAM,EACd,qBAAqB,EAAE,YAAY,EACnB,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,aAAa,EACrC,MAAM,EAAE,SAAS;WAKN,MAAM,CACjB,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,cAAc,GAAG,SAAS,GACzC,OAAO,CAAC,MAAM,CAAC;cAUF,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;cAiDvC,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK9E,cAAc,IAAI,OAAO,CAAC,QAAQ,CAAC;IAI7B,WAAW,IAAI,OAAO,CAAC;QAAE,YAAY,EAAE,QAAQ,CAAC;QAAC,aAAa,EAAE,QAAQ,CAAC;QAAC,GAAG,EAAE,QAAQ,CAAA;KAAE,CAAC;YAQzF,mBAAmB;YAMnB,oBAAoB;CAMnC"}
|
package/dest/amm_bot.js
CHANGED
|
@@ -11,9 +11,9 @@ export class AmmBot extends BaseBot {
|
|
|
11
11
|
constructor(node, wallet, defaultAccountAddress, amm, token0, token1, config){
|
|
12
12
|
super(node, wallet, defaultAccountAddress, config), this.amm = amm, this.token0 = token0, this.token1 = token1;
|
|
13
13
|
}
|
|
14
|
-
static async create(config,
|
|
15
|
-
const {
|
|
16
|
-
return new AmmBot(
|
|
14
|
+
static async create(config, wallet, aztecNode, aztecNodeAdmin) {
|
|
15
|
+
const { defaultAccountAddress, token0, token1, amm } = await new BotFactory(config, wallet, aztecNode, aztecNodeAdmin).setupAmm();
|
|
16
|
+
return new AmmBot(aztecNode, wallet, defaultAccountAddress, amm, token0, token1, config);
|
|
17
17
|
}
|
|
18
18
|
async createAndSendTx(logCtx) {
|
|
19
19
|
const { feePaymentMethod } = this.config;
|
package/dest/bot.d.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { type AztecAddress, SentTx, type Wallet } from '@aztec/aztec.js';
|
|
2
2
|
import type { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
|
|
3
3
|
import type { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
4
|
-
import type { AztecNode, AztecNodeAdmin
|
|
4
|
+
import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
5
|
+
import type { TestWallet } from '@aztec/test-wallet';
|
|
5
6
|
import { BaseBot } from './base_bot.js';
|
|
6
7
|
import type { BotConfig } from './config.js';
|
|
7
8
|
export declare class Bot extends BaseBot {
|
|
8
9
|
readonly token: TokenContract | PrivateTokenContract;
|
|
9
10
|
readonly recipient: AztecAddress;
|
|
10
11
|
protected constructor(node: AztecNode, wallet: Wallet, defaultAccountAddress: AztecAddress, token: TokenContract | PrivateTokenContract, recipient: AztecAddress, config: BotConfig);
|
|
11
|
-
static create(config: BotConfig,
|
|
12
|
-
pxe?: PXE;
|
|
13
|
-
node?: AztecNode;
|
|
14
|
-
nodeAdmin?: AztecNodeAdmin;
|
|
15
|
-
}): Promise<Bot>;
|
|
12
|
+
static create(config: BotConfig, wallet: TestWallet, aztecNode: AztecNode, aztecNodeAdmin?: AztecNodeAdmin): Promise<Bot>;
|
|
16
13
|
updateConfig(config: Partial<BotConfig>): void;
|
|
17
14
|
protected createAndSendTx(logCtx: object): Promise<SentTx>;
|
|
18
15
|
getBalances(): Promise<{
|
package/dest/bot.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bot.d.ts","sourceRoot":"","sources":["../src/bot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAa,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEpF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"bot.d.ts","sourceRoot":"","sources":["../src/bot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAa,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEpF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAM7C,qBAAa,GAAI,SAAQ,OAAO;aAKZ,KAAK,EAAE,aAAa,GAAG,oBAAoB;aAC3C,SAAS,EAAE,YAAY;IALzC,SAAS,aACP,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,MAAM,EACd,qBAAqB,EAAE,YAAY,EACnB,KAAK,EAAE,aAAa,GAAG,oBAAoB,EAC3C,SAAS,EAAE,YAAY,EACvC,MAAM,EAAE,SAAS;WAKN,MAAM,CACjB,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,SAAS,EACpB,cAAc,CAAC,EAAE,cAAc,GAC9B,OAAO,CAAC,GAAG,CAAC;IAUR,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC;cAK9B,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA+BnD,WAAW;;;;;;;;;;CAmBzB"}
|
package/dest/bot.js
CHANGED
|
@@ -10,9 +10,9 @@ export class Bot extends BaseBot {
|
|
|
10
10
|
constructor(node, wallet, defaultAccountAddress, token, recipient, config){
|
|
11
11
|
super(node, wallet, defaultAccountAddress, config), this.token = token, this.recipient = recipient;
|
|
12
12
|
}
|
|
13
|
-
static async create(config,
|
|
14
|
-
const {
|
|
15
|
-
return new Bot(
|
|
13
|
+
static async create(config, wallet, aztecNode, aztecNodeAdmin) {
|
|
14
|
+
const { defaultAccountAddress, token, recipient } = await new BotFactory(config, wallet, aztecNode, aztecNodeAdmin).setup();
|
|
15
|
+
return new Bot(aztecNode, wallet, defaultAccountAddress, token, recipient, config);
|
|
16
16
|
}
|
|
17
17
|
updateConfig(config) {
|
|
18
18
|
this.log.info(`Updating bot config ${Object.keys(config).join(', ')}`);
|
package/dest/factory.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AztecAddress
|
|
1
|
+
import { AztecAddress } from '@aztec/aztec.js';
|
|
2
2
|
import { AMMContract } from '@aztec/noir-contracts.js/AMM';
|
|
3
3
|
import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
|
|
4
4
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
@@ -7,16 +7,11 @@ import { TestWallet } from '@aztec/test-wallet';
|
|
|
7
7
|
import { type BotConfig } from './config.js';
|
|
8
8
|
export declare class BotFactory {
|
|
9
9
|
private readonly config;
|
|
10
|
-
private
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private nodeAdmin?;
|
|
10
|
+
private readonly wallet;
|
|
11
|
+
private readonly aztecNode;
|
|
12
|
+
private readonly aztecNodeAdmin?;
|
|
14
13
|
private log;
|
|
15
|
-
constructor(config: BotConfig,
|
|
16
|
-
pxe?: PXE;
|
|
17
|
-
nodeAdmin?: AztecNodeAdmin;
|
|
18
|
-
node?: AztecNode;
|
|
19
|
-
});
|
|
14
|
+
constructor(config: BotConfig, wallet: TestWallet, aztecNode: AztecNode, aztecNodeAdmin?: AztecNodeAdmin | undefined);
|
|
20
15
|
/**
|
|
21
16
|
* Initializes a new bot by setting up the sender account, registering the recipient,
|
|
22
17
|
* deploying the token contract, and minting tokens if necessary.
|
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,EACL,YAAY,
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EAUb,MAAM,iBAAiB,CAAC;AAIzB,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,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,KAAK,SAAS,EAA2B,MAAM,aAAa,CAAC;AAMtE,qBAAa,UAAU;IAInB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IANlC,OAAO,CAAC,GAAG,CAAuB;gBAGf,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,SAAS,EACpB,cAAc,CAAC,EAAE,cAAc,YAAA;IAGlD;;;OAGG;IACU,KAAK;;;;;;;IAQL,QAAQ;;;;;;;;IAwBrB;;;OAGG;YACW,YAAY;YAWZ,0BAA0B;YAkC1B,gBAAgB;IAW9B;;OAEG;YACW,iBAAiB;IAK/B;;;;OAIG;YACW,UAAU;IA+BxB;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;YAYZ,gBAAgB;YAoBhB,OAAO;YA8EP,wBAAwB;IAkBtC;;;OAGG;YACW,UAAU;YAmCV,gBAAgB;YAgChB,oBAAoB;CAenC"}
|
package/dest/factory.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
|
|
2
2
|
import { getInitialTestAccountsData } from '@aztec/accounts/testing';
|
|
3
|
-
import { BatchCall, FeeJuicePaymentMethodWithClaim, L1FeeJuicePortalManager,
|
|
3
|
+
import { BatchCall, FeeJuicePaymentMethodWithClaim, L1FeeJuicePortalManager, createLogger, waitForL1ToL2MessageReady } from '@aztec/aztec.js';
|
|
4
4
|
import { createEthereumChain, createExtendedL1Client } from '@aztec/ethereum';
|
|
5
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
6
6
|
import { Timer } from '@aztec/foundation/timer';
|
|
@@ -8,53 +8,22 @@ import { AMMContract } from '@aztec/noir-contracts.js/AMM';
|
|
|
8
8
|
import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
|
|
9
9
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
10
10
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
11
|
-
import {
|
|
12
|
-
import { TestWallet } from '@aztec/test-wallet';
|
|
13
|
-
import { SupportedTokenContracts, getVersions } from './config.js';
|
|
11
|
+
import { SupportedTokenContracts } from './config.js';
|
|
14
12
|
import { getBalances, getPrivateBalance, isStandardTokenContract } from './utils.js';
|
|
15
13
|
const MINT_BALANCE = 1e12;
|
|
16
14
|
const MIN_BALANCE = 1e3;
|
|
17
15
|
export class BotFactory {
|
|
18
16
|
config;
|
|
19
|
-
pxe;
|
|
20
17
|
wallet;
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
aztecNode;
|
|
19
|
+
aztecNodeAdmin;
|
|
23
20
|
log;
|
|
24
|
-
constructor(config,
|
|
21
|
+
constructor(config, wallet, aztecNode, aztecNodeAdmin){
|
|
25
22
|
this.config = config;
|
|
23
|
+
this.wallet = wallet;
|
|
24
|
+
this.aztecNode = aztecNode;
|
|
25
|
+
this.aztecNodeAdmin = aztecNodeAdmin;
|
|
26
26
|
this.log = createLogger('bot');
|
|
27
|
-
if (config.flushSetupTransactions && !dependencies.nodeAdmin) {
|
|
28
|
-
throw new Error(`Either a node admin client or node admin url must be provided if transaction flushing is requested`);
|
|
29
|
-
}
|
|
30
|
-
if (config.senderPrivateKey && config.senderPrivateKey.getValue() && !dependencies.node) {
|
|
31
|
-
throw new Error(`Either a node client or node url must be provided for bridging L1 fee juice to deploy an account with private key`);
|
|
32
|
-
}
|
|
33
|
-
if (!dependencies.pxe && !config.pxeUrl) {
|
|
34
|
-
throw new Error(`Either a PXE client or a PXE URL must be provided`);
|
|
35
|
-
}
|
|
36
|
-
this.nodeAdmin = dependencies.nodeAdmin;
|
|
37
|
-
if (dependencies.pxe) {
|
|
38
|
-
this.log.info(`Using local PXE`);
|
|
39
|
-
this.pxe = dependencies.pxe;
|
|
40
|
-
} else {
|
|
41
|
-
this.log.info(`Using remote PXE at ${config.pxeUrl}`);
|
|
42
|
-
this.pxe = createPXEClient(config.pxeUrl, getVersions(), makeTracedFetch([
|
|
43
|
-
1,
|
|
44
|
-
2,
|
|
45
|
-
3
|
|
46
|
-
], false));
|
|
47
|
-
}
|
|
48
|
-
if (dependencies.node) {
|
|
49
|
-
this.node = dependencies.node;
|
|
50
|
-
} else {
|
|
51
|
-
this.node = createAztecNodeClient(config.nodeUrl, getVersions(), makeTracedFetch([
|
|
52
|
-
1,
|
|
53
|
-
2,
|
|
54
|
-
3
|
|
55
|
-
], false));
|
|
56
|
-
}
|
|
57
|
-
this.wallet = new TestWallet(this.pxe, this.node);
|
|
58
27
|
}
|
|
59
28
|
/**
|
|
60
29
|
* Initializes a new bot by setting up the sender account, registering the recipient,
|
|
@@ -68,7 +37,7 @@ export class BotFactory {
|
|
|
68
37
|
wallet: this.wallet,
|
|
69
38
|
defaultAccountAddress,
|
|
70
39
|
token,
|
|
71
|
-
node: this.
|
|
40
|
+
node: this.aztecNode,
|
|
72
41
|
recipient
|
|
73
42
|
};
|
|
74
43
|
}
|
|
@@ -86,7 +55,7 @@ export class BotFactory {
|
|
|
86
55
|
amm,
|
|
87
56
|
token0,
|
|
88
57
|
token1,
|
|
89
|
-
node: this.
|
|
58
|
+
node: this.aztecNode
|
|
90
59
|
};
|
|
91
60
|
}
|
|
92
61
|
/**
|
|
@@ -111,7 +80,7 @@ export class BotFactory {
|
|
|
111
80
|
contract: new SchnorrAccountContract(signingKey)
|
|
112
81
|
};
|
|
113
82
|
const accountManager = await this.wallet.createAccount(accountData);
|
|
114
|
-
const isInit = (await this.
|
|
83
|
+
const isInit = (await this.wallet.getContractMetadata(accountManager.getAddress())).isContractInitialized;
|
|
115
84
|
if (isInit) {
|
|
116
85
|
this.log.info(`Account at ${accountManager.getAddress().toString()} already initialized`);
|
|
117
86
|
const timer = new Timer();
|
|
@@ -152,7 +121,7 @@ export class BotFactory {
|
|
|
152
121
|
/**
|
|
153
122
|
* Registers the recipient for txs in the pxe.
|
|
154
123
|
*/ async registerRecipient() {
|
|
155
|
-
const recipient = await this.
|
|
124
|
+
const recipient = await this.wallet.registerAccount(this.config.recipientEncryptionSecret.getValue(), Fr.ONE);
|
|
156
125
|
return recipient.address;
|
|
157
126
|
}
|
|
158
127
|
/**
|
|
@@ -177,7 +146,7 @@ export class BotFactory {
|
|
|
177
146
|
throw new Error(`Unsupported token contract type: ${this.config.contract}`);
|
|
178
147
|
}
|
|
179
148
|
const address = (await deploy.getInstance(deployOpts)).address;
|
|
180
|
-
if ((await this.
|
|
149
|
+
if ((await this.wallet.getContractMetadata(address)).isContractPublished) {
|
|
181
150
|
this.log.info(`Token at ${address.toString()} already deployed`);
|
|
182
151
|
return deploy.register();
|
|
183
152
|
} else {
|
|
@@ -278,7 +247,7 @@ export class BotFactory {
|
|
|
278
247
|
}
|
|
279
248
|
async registerOrDeployContract(name, deploy, deployOpts) {
|
|
280
249
|
const address = (await deploy.getInstance(deployOpts)).address;
|
|
281
|
-
if ((await this.
|
|
250
|
+
if ((await this.wallet.getContractMetadata(address)).isContractPublished) {
|
|
282
251
|
this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
|
|
283
252
|
return deploy.register();
|
|
284
253
|
} else {
|
|
@@ -334,13 +303,13 @@ export class BotFactory {
|
|
|
334
303
|
if (!mnemonicOrPrivateKey) {
|
|
335
304
|
throw new Error('Either a mnemonic or private key of an L1 account is required to bridge the fee juice to fund the deployment of the account.');
|
|
336
305
|
}
|
|
337
|
-
const { l1ChainId } = await this.
|
|
306
|
+
const { l1ChainId } = await this.aztecNode.getNodeInfo();
|
|
338
307
|
const chain = createEthereumChain(l1RpcUrls, l1ChainId);
|
|
339
308
|
const extendedClient = createExtendedL1Client(chain.rpcUrls, mnemonicOrPrivateKey, chain.chainInfo);
|
|
340
|
-
const portal = await L1FeeJuicePortalManager.new(this.
|
|
309
|
+
const portal = await L1FeeJuicePortalManager.new(this.aztecNode, extendedClient, this.log);
|
|
341
310
|
const mintAmount = await portal.getTokenManager().getMintAmount();
|
|
342
311
|
const claim = await portal.bridgeTokensPublic(recipient, mintAmount, true);
|
|
343
|
-
await this.withNoMinTxsPerBlock(()=>waitForL1ToL2MessageReady(this.
|
|
312
|
+
await this.withNoMinTxsPerBlock(()=>waitForL1ToL2MessageReady(this.aztecNode, Fr.fromHexString(claim.messageHash), {
|
|
344
313
|
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds,
|
|
345
314
|
forPublicConsumption: false
|
|
346
315
|
}));
|
|
@@ -348,20 +317,20 @@ export class BotFactory {
|
|
|
348
317
|
return claim;
|
|
349
318
|
}
|
|
350
319
|
async withNoMinTxsPerBlock(fn) {
|
|
351
|
-
if (!this.
|
|
320
|
+
if (!this.aztecNodeAdmin || !this.config.flushSetupTransactions) {
|
|
352
321
|
this.log.verbose(`No node admin client or flushing not requested (not setting minTxsPerBlock to 0)`);
|
|
353
322
|
return fn();
|
|
354
323
|
}
|
|
355
|
-
const { minTxsPerBlock } = await this.
|
|
324
|
+
const { minTxsPerBlock } = await this.aztecNodeAdmin.getConfig();
|
|
356
325
|
this.log.warn(`Setting sequencer minTxsPerBlock to 0 from ${minTxsPerBlock} to flush setup transactions`);
|
|
357
|
-
await this.
|
|
326
|
+
await this.aztecNodeAdmin.setConfig({
|
|
358
327
|
minTxsPerBlock: 0
|
|
359
328
|
});
|
|
360
329
|
try {
|
|
361
330
|
return await fn();
|
|
362
331
|
} finally{
|
|
363
332
|
this.log.warn(`Restoring sequencer minTxsPerBlock to ${minTxsPerBlock}`);
|
|
364
|
-
await this.
|
|
333
|
+
await this.aztecNodeAdmin.setConfig({
|
|
365
334
|
minTxsPerBlock
|
|
366
335
|
});
|
|
367
336
|
}
|
package/dest/runner.d.ts
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import { type AztecNode } from '@aztec/aztec.js';
|
|
2
|
-
import {
|
|
2
|
+
import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
3
3
|
import { type TelemetryClient, type Traceable, type Tracer } from '@aztec/telemetry-client';
|
|
4
|
-
import {
|
|
4
|
+
import type { TestWallet } from '@aztec/test-wallet';
|
|
5
|
+
import type { BotConfig } from './config.js';
|
|
5
6
|
import type { BotInfo, BotRunnerApi } from './interface.js';
|
|
6
7
|
export declare class BotRunner implements BotRunnerApi, Traceable {
|
|
7
8
|
#private;
|
|
8
9
|
private config;
|
|
10
|
+
private readonly wallet;
|
|
11
|
+
private readonly aztecNode;
|
|
12
|
+
private readonly telemetry;
|
|
13
|
+
private readonly aztecNodeAdmin?;
|
|
9
14
|
private log;
|
|
10
15
|
private bot?;
|
|
11
|
-
private pxe?;
|
|
12
|
-
private node;
|
|
13
|
-
private nodeAdmin?;
|
|
14
16
|
private runningPromise;
|
|
15
17
|
private consecutiveErrors;
|
|
16
18
|
private healthy;
|
|
17
19
|
readonly tracer: Tracer;
|
|
18
|
-
constructor(config: BotConfig,
|
|
19
|
-
pxe?: PXE;
|
|
20
|
-
node?: AztecNode;
|
|
21
|
-
nodeAdmin?: AztecNodeAdmin;
|
|
22
|
-
telemetry: TelemetryClient;
|
|
23
|
-
});
|
|
20
|
+
constructor(config: BotConfig, wallet: TestWallet, aztecNode: AztecNode, telemetry: TelemetryClient, aztecNodeAdmin?: AztecNodeAdmin | undefined);
|
|
24
21
|
/** Initializes the bot if needed. Blocks until the bot setup is finished. */
|
|
25
22
|
setup(): Promise<void>;
|
|
26
23
|
private doSetup;
|
package/dest/runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAgB,MAAM,iBAAiB,CAAC;AAG/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,SAAS,EAAE,KAAK,MAAM,EAAa,MAAM,yBAAyB,CAAC;AACvG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAKrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE5D,qBAAa,SAAU,YAAW,YAAY,EAAE,SAAS;;IAUrD,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAblC,OAAO,CAAC,GAAG,CAAuB;IAClC,OAAO,CAAC,GAAG,CAAC,CAAmB;IAC/B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,OAAO,CAAQ;IAEvB,SAAgB,MAAM,EAAE,MAAM,CAAC;gBAGrB,MAAM,EAAE,SAAS,EACR,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,eAAe,EAC1B,cAAc,CAAC,EAAE,cAAc,YAAA;IAOlD,6EAA6E;IAChE,KAAK;YAOJ,OAAO;IAMrB;;;OAGG;IACU,KAAK;IAQlB;;OAEG;IACU,IAAI;IAQV,SAAS;IAIhB,0CAA0C;IACnC,SAAS;IAIhB;;;OAGG;IACU,MAAM,CAAC,MAAM,EAAE,SAAS;IAerC;;;OAGG;IACU,GAAG;IAwBhB,qDAAqD;IAC9C,SAAS;IAKhB,sCAAsC;IACzB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;CA6CzC"}
|
package/dest/runner.js
CHANGED
|
@@ -4,42 +4,34 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
4
4
|
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
}
|
|
7
|
-
import {
|
|
7
|
+
import { createLogger } from '@aztec/aztec.js';
|
|
8
8
|
import { omit } from '@aztec/foundation/collection';
|
|
9
9
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
10
|
-
import {
|
|
11
|
-
import { makeTracedFetch, trackSpan } from '@aztec/telemetry-client';
|
|
10
|
+
import { trackSpan } from '@aztec/telemetry-client';
|
|
12
11
|
import { AmmBot } from './amm_bot.js';
|
|
13
12
|
import { Bot } from './bot.js';
|
|
14
|
-
import { getVersions } from './config.js';
|
|
15
13
|
export class BotRunner {
|
|
16
14
|
config;
|
|
15
|
+
wallet;
|
|
16
|
+
aztecNode;
|
|
17
|
+
telemetry;
|
|
18
|
+
aztecNodeAdmin;
|
|
17
19
|
log;
|
|
18
20
|
bot;
|
|
19
|
-
pxe;
|
|
20
|
-
node;
|
|
21
|
-
nodeAdmin;
|
|
22
21
|
runningPromise;
|
|
23
22
|
consecutiveErrors;
|
|
24
23
|
healthy;
|
|
25
24
|
tracer;
|
|
26
|
-
constructor(config,
|
|
25
|
+
constructor(config, wallet, aztecNode, telemetry, aztecNodeAdmin){
|
|
27
26
|
this.config = config;
|
|
27
|
+
this.wallet = wallet;
|
|
28
|
+
this.aztecNode = aztecNode;
|
|
29
|
+
this.telemetry = telemetry;
|
|
30
|
+
this.aztecNodeAdmin = aztecNodeAdmin;
|
|
28
31
|
this.log = createLogger('bot');
|
|
29
32
|
this.consecutiveErrors = 0;
|
|
30
33
|
this.healthy = true;
|
|
31
|
-
this.tracer =
|
|
32
|
-
if (!dependencies.node && !config.nodeUrl) {
|
|
33
|
-
throw new Error(`Missing node URL in config or dependencies`);
|
|
34
|
-
}
|
|
35
|
-
const versions = getVersions();
|
|
36
|
-
const fetch = makeTracedFetch([
|
|
37
|
-
1,
|
|
38
|
-
2,
|
|
39
|
-
3
|
|
40
|
-
], true);
|
|
41
|
-
this.node = dependencies.node ?? createAztecNodeClient(config.nodeUrl, versions, fetch);
|
|
42
|
-
this.nodeAdmin = dependencies.nodeAdmin ?? (config.nodeAdminUrl ? createAztecNodeAdminClient(config.nodeAdminUrl, versions, fetch) : undefined);
|
|
34
|
+
this.tracer = telemetry.getTracer('Bot');
|
|
43
35
|
this.runningPromise = new RunningPromise(()=>this.#work(), this.log, config.txIntervalSeconds * 1000);
|
|
44
36
|
}
|
|
45
37
|
/** Initializes the bot if needed. Blocks until the bot setup is finished. */ async setup() {
|
|
@@ -136,15 +128,7 @@ export class BotRunner {
|
|
|
136
128
|
}
|
|
137
129
|
async #createBot() {
|
|
138
130
|
try {
|
|
139
|
-
this.bot = this.config.ammTxs ? AmmBot.create(this.config,
|
|
140
|
-
pxe: this.pxe,
|
|
141
|
-
node: this.node,
|
|
142
|
-
nodeAdmin: this.nodeAdmin
|
|
143
|
-
}) : Bot.create(this.config, {
|
|
144
|
-
pxe: this.pxe,
|
|
145
|
-
node: this.node,
|
|
146
|
-
nodeAdmin: this.nodeAdmin
|
|
147
|
-
});
|
|
131
|
+
this.bot = this.config.ammTxs ? AmmBot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin) : Bot.create(this.config, this.wallet, this.aztecNode);
|
|
148
132
|
await this.bot;
|
|
149
133
|
} catch (err) {
|
|
150
134
|
this.log.error(`Error setting up bot: ${err}`);
|
|
@@ -153,7 +137,7 @@ export class BotRunner {
|
|
|
153
137
|
}
|
|
154
138
|
async #work() {
|
|
155
139
|
if (this.config.maxPendingTxs > 0) {
|
|
156
|
-
const pendingTxCount = await this.
|
|
140
|
+
const pendingTxCount = await this.aztecNode.getPendingTxCount();
|
|
157
141
|
if (pendingTxCount >= this.config.maxPendingTxs) {
|
|
158
142
|
this.log.verbose(`Not sending bot tx since node has ${pendingTxCount} pending txs`);
|
|
159
143
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/bot",
|
|
3
|
-
"version": "3.0.0-nightly.
|
|
3
|
+
"version": "3.0.0-nightly.20250923",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -54,17 +54,17 @@
|
|
|
54
54
|
]
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@aztec/accounts": "3.0.0-nightly.
|
|
58
|
-
"@aztec/aztec.js": "3.0.0-nightly.
|
|
59
|
-
"@aztec/entrypoints": "3.0.0-nightly.
|
|
60
|
-
"@aztec/ethereum": "3.0.0-nightly.
|
|
61
|
-
"@aztec/foundation": "3.0.0-nightly.
|
|
62
|
-
"@aztec/noir-contracts.js": "3.0.0-nightly.
|
|
63
|
-
"@aztec/noir-protocol-circuits-types": "3.0.0-nightly.
|
|
64
|
-
"@aztec/protocol-contracts": "3.0.0-nightly.
|
|
65
|
-
"@aztec/stdlib": "3.0.0-nightly.
|
|
66
|
-
"@aztec/telemetry-client": "3.0.0-nightly.
|
|
67
|
-
"@aztec/test-wallet": "3.0.0-nightly.
|
|
57
|
+
"@aztec/accounts": "3.0.0-nightly.20250923",
|
|
58
|
+
"@aztec/aztec.js": "3.0.0-nightly.20250923",
|
|
59
|
+
"@aztec/entrypoints": "3.0.0-nightly.20250923",
|
|
60
|
+
"@aztec/ethereum": "3.0.0-nightly.20250923",
|
|
61
|
+
"@aztec/foundation": "3.0.0-nightly.20250923",
|
|
62
|
+
"@aztec/noir-contracts.js": "3.0.0-nightly.20250923",
|
|
63
|
+
"@aztec/noir-protocol-circuits-types": "3.0.0-nightly.20250923",
|
|
64
|
+
"@aztec/protocol-contracts": "3.0.0-nightly.20250923",
|
|
65
|
+
"@aztec/stdlib": "3.0.0-nightly.20250923",
|
|
66
|
+
"@aztec/telemetry-client": "3.0.0-nightly.20250923",
|
|
67
|
+
"@aztec/test-wallet": "3.0.0-nightly.20250923",
|
|
68
68
|
"source-map-support": "^0.5.21",
|
|
69
69
|
"tslib": "^2.4.0",
|
|
70
70
|
"zod": "^3.23.8"
|
package/src/amm_bot.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { AztecAddress, Fr, SentTx, TxReceipt, type Wallet } from '@aztec/aztec.j
|
|
|
2
2
|
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
3
3
|
import type { AMMContract } from '@aztec/noir-contracts.js/AMM';
|
|
4
4
|
import type { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
5
|
-
import type { AztecNode, AztecNodeAdmin
|
|
5
|
+
import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
6
|
+
import type { TestWallet } from '@aztec/test-wallet';
|
|
6
7
|
|
|
7
8
|
import { BaseBot } from './base_bot.js';
|
|
8
9
|
import type { BotConfig } from './config.js';
|
|
@@ -28,13 +29,17 @@ export class AmmBot extends BaseBot {
|
|
|
28
29
|
|
|
29
30
|
static async create(
|
|
30
31
|
config: BotConfig,
|
|
31
|
-
|
|
32
|
+
wallet: TestWallet,
|
|
33
|
+
aztecNode: AztecNode,
|
|
34
|
+
aztecNodeAdmin: AztecNodeAdmin | undefined,
|
|
32
35
|
): Promise<AmmBot> {
|
|
33
|
-
const {
|
|
36
|
+
const { defaultAccountAddress, token0, token1, amm } = await new BotFactory(
|
|
34
37
|
config,
|
|
35
|
-
|
|
38
|
+
wallet,
|
|
39
|
+
aztecNode,
|
|
40
|
+
aztecNodeAdmin,
|
|
36
41
|
).setupAmm();
|
|
37
|
-
return new AmmBot(
|
|
42
|
+
return new AmmBot(aztecNode, wallet, defaultAccountAddress, amm, token0, token1, config);
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
protected async createAndSendTx(logCtx: object): Promise<SentTx> {
|
package/src/bot.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { type AztecAddress, BatchCall, SentTx, type Wallet } from '@aztec/aztec.
|
|
|
2
2
|
import { times } from '@aztec/foundation/collection';
|
|
3
3
|
import type { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
|
|
4
4
|
import type { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
5
|
-
import type { AztecNode, AztecNodeAdmin
|
|
5
|
+
import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
6
|
+
import type { TestWallet } from '@aztec/test-wallet';
|
|
6
7
|
|
|
7
8
|
import { BaseBot } from './base_bot.js';
|
|
8
9
|
import type { BotConfig } from './config.js';
|
|
@@ -25,13 +26,17 @@ export class Bot extends BaseBot {
|
|
|
25
26
|
|
|
26
27
|
static async create(
|
|
27
28
|
config: BotConfig,
|
|
28
|
-
|
|
29
|
+
wallet: TestWallet,
|
|
30
|
+
aztecNode: AztecNode,
|
|
31
|
+
aztecNodeAdmin?: AztecNodeAdmin,
|
|
29
32
|
): Promise<Bot> {
|
|
30
|
-
const {
|
|
33
|
+
const { defaultAccountAddress, token, recipient } = await new BotFactory(
|
|
31
34
|
config,
|
|
32
|
-
|
|
35
|
+
wallet,
|
|
36
|
+
aztecNode,
|
|
37
|
+
aztecNodeAdmin,
|
|
33
38
|
).setup();
|
|
34
|
-
return new Bot(
|
|
39
|
+
return new Bot(aztecNode, wallet, defaultAccountAddress, token, recipient, config);
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
public updateConfig(config: Partial<BotConfig>) {
|
package/src/factory.ts
CHANGED
|
@@ -9,10 +9,7 @@ import {
|
|
|
9
9
|
type DeployOptions,
|
|
10
10
|
FeeJuicePaymentMethodWithClaim,
|
|
11
11
|
L1FeeJuicePortalManager,
|
|
12
|
-
type PXE,
|
|
13
|
-
createAztecNodeClient,
|
|
14
12
|
createLogger,
|
|
15
|
-
createPXEClient,
|
|
16
13
|
waitForL1ToL2MessageReady,
|
|
17
14
|
} from '@aztec/aztec.js';
|
|
18
15
|
import { createEthereumChain, createExtendedL1Client } from '@aztec/ethereum';
|
|
@@ -23,58 +20,23 @@ import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
|
|
|
23
20
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
24
21
|
import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
25
22
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
26
|
-
import { makeTracedFetch } from '@aztec/telemetry-client';
|
|
27
23
|
import { TestWallet } from '@aztec/test-wallet';
|
|
28
24
|
|
|
29
|
-
import { type BotConfig, SupportedTokenContracts
|
|
25
|
+
import { type BotConfig, SupportedTokenContracts } from './config.js';
|
|
30
26
|
import { getBalances, getPrivateBalance, isStandardTokenContract } from './utils.js';
|
|
31
27
|
|
|
32
28
|
const MINT_BALANCE = 1e12;
|
|
33
29
|
const MIN_BALANCE = 1e3;
|
|
34
30
|
|
|
35
31
|
export class BotFactory {
|
|
36
|
-
private pxe: PXE;
|
|
37
|
-
private wallet: TestWallet;
|
|
38
|
-
private node: AztecNode;
|
|
39
|
-
private nodeAdmin?: AztecNodeAdmin;
|
|
40
32
|
private log = createLogger('bot');
|
|
41
33
|
|
|
42
34
|
constructor(
|
|
43
35
|
private readonly config: BotConfig,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
`Either a node admin client or node admin url must be provided if transaction flushing is requested`,
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
if (config.senderPrivateKey && config.senderPrivateKey.getValue() && !dependencies.node) {
|
|
52
|
-
throw new Error(
|
|
53
|
-
`Either a node client or node url must be provided for bridging L1 fee juice to deploy an account with private key`,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
if (!dependencies.pxe && !config.pxeUrl) {
|
|
57
|
-
throw new Error(`Either a PXE client or a PXE URL must be provided`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.nodeAdmin = dependencies.nodeAdmin;
|
|
61
|
-
|
|
62
|
-
if (dependencies.pxe) {
|
|
63
|
-
this.log.info(`Using local PXE`);
|
|
64
|
-
this.pxe = dependencies.pxe;
|
|
65
|
-
} else {
|
|
66
|
-
this.log.info(`Using remote PXE at ${config.pxeUrl!}`);
|
|
67
|
-
this.pxe = createPXEClient(config.pxeUrl!, getVersions(), makeTracedFetch([1, 2, 3], false));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (dependencies.node) {
|
|
71
|
-
this.node = dependencies.node;
|
|
72
|
-
} else {
|
|
73
|
-
this.node = createAztecNodeClient(config.nodeUrl!, getVersions(), makeTracedFetch([1, 2, 3], false));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
this.wallet = new TestWallet(this.pxe, this.node);
|
|
77
|
-
}
|
|
36
|
+
private readonly wallet: TestWallet,
|
|
37
|
+
private readonly aztecNode: AztecNode,
|
|
38
|
+
private readonly aztecNodeAdmin?: AztecNodeAdmin,
|
|
39
|
+
) {}
|
|
78
40
|
|
|
79
41
|
/**
|
|
80
42
|
* Initializes a new bot by setting up the sender account, registering the recipient,
|
|
@@ -85,7 +47,7 @@ export class BotFactory {
|
|
|
85
47
|
const defaultAccountAddress = await this.setupAccount();
|
|
86
48
|
const token = await this.setupToken(defaultAccountAddress);
|
|
87
49
|
await this.mintTokens(token, defaultAccountAddress);
|
|
88
|
-
return { wallet: this.wallet, defaultAccountAddress, token, node: this.
|
|
50
|
+
return { wallet: this.wallet, defaultAccountAddress, token, node: this.aztecNode, recipient };
|
|
89
51
|
}
|
|
90
52
|
|
|
91
53
|
public async setupAmm() {
|
|
@@ -109,7 +71,7 @@ export class BotFactory {
|
|
|
109
71
|
await this.fundAmm(defaultAccountAddress, defaultAccountAddress, amm, token0, token1, liquidityToken);
|
|
110
72
|
this.log.info(`AMM initialized and funded`);
|
|
111
73
|
|
|
112
|
-
return { wallet: this.wallet, defaultAccountAddress, amm, token0, token1, node: this.
|
|
74
|
+
return { wallet: this.wallet, defaultAccountAddress, amm, token0, token1, node: this.aztecNode };
|
|
113
75
|
}
|
|
114
76
|
|
|
115
77
|
/**
|
|
@@ -136,7 +98,7 @@ export class BotFactory {
|
|
|
136
98
|
contract: new SchnorrAccountContract(signingKey!),
|
|
137
99
|
};
|
|
138
100
|
const accountManager = await this.wallet.createAccount(accountData);
|
|
139
|
-
const isInit = (await this.
|
|
101
|
+
const isInit = (await this.wallet.getContractMetadata(accountManager.getAddress())).isContractInitialized;
|
|
140
102
|
if (isInit) {
|
|
141
103
|
this.log.info(`Account at ${accountManager.getAddress().toString()} already initialized`);
|
|
142
104
|
const timer = new Timer();
|
|
@@ -176,7 +138,7 @@ export class BotFactory {
|
|
|
176
138
|
* Registers the recipient for txs in the pxe.
|
|
177
139
|
*/
|
|
178
140
|
private async registerRecipient() {
|
|
179
|
-
const recipient = await this.
|
|
141
|
+
const recipient = await this.wallet.registerAccount(this.config.recipientEncryptionSecret.getValue(), Fr.ONE);
|
|
180
142
|
return recipient.address;
|
|
181
143
|
}
|
|
182
144
|
|
|
@@ -204,7 +166,7 @@ export class BotFactory {
|
|
|
204
166
|
}
|
|
205
167
|
|
|
206
168
|
const address = (await deploy.getInstance(deployOpts)).address;
|
|
207
|
-
if ((await this.
|
|
169
|
+
if ((await this.wallet.getContractMetadata(address)).isContractPublished) {
|
|
208
170
|
this.log.info(`Token at ${address.toString()} already deployed`);
|
|
209
171
|
return deploy.register();
|
|
210
172
|
} else {
|
|
@@ -337,7 +299,7 @@ export class BotFactory {
|
|
|
337
299
|
deployOpts: DeployOptions,
|
|
338
300
|
): Promise<T> {
|
|
339
301
|
const address = (await deploy.getInstance(deployOpts)).address;
|
|
340
|
-
if ((await this.
|
|
302
|
+
if ((await this.wallet.getContractMetadata(address)).isContractPublished) {
|
|
341
303
|
this.log.info(`Contract ${name} at ${address.toString()} already deployed`);
|
|
342
304
|
return deploy.register();
|
|
343
305
|
} else {
|
|
@@ -400,16 +362,16 @@ export class BotFactory {
|
|
|
400
362
|
);
|
|
401
363
|
}
|
|
402
364
|
|
|
403
|
-
const { l1ChainId } = await this.
|
|
365
|
+
const { l1ChainId } = await this.aztecNode.getNodeInfo();
|
|
404
366
|
const chain = createEthereumChain(l1RpcUrls, l1ChainId);
|
|
405
367
|
const extendedClient = createExtendedL1Client(chain.rpcUrls, mnemonicOrPrivateKey, chain.chainInfo);
|
|
406
368
|
|
|
407
|
-
const portal = await L1FeeJuicePortalManager.new(this.
|
|
369
|
+
const portal = await L1FeeJuicePortalManager.new(this.aztecNode, extendedClient, this.log);
|
|
408
370
|
const mintAmount = await portal.getTokenManager().getMintAmount();
|
|
409
371
|
const claim = await portal.bridgeTokensPublic(recipient, mintAmount, true /* mint */);
|
|
410
372
|
|
|
411
373
|
await this.withNoMinTxsPerBlock(() =>
|
|
412
|
-
waitForL1ToL2MessageReady(this.
|
|
374
|
+
waitForL1ToL2MessageReady(this.aztecNode, Fr.fromHexString(claim.messageHash), {
|
|
413
375
|
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds,
|
|
414
376
|
forPublicConsumption: false,
|
|
415
377
|
}),
|
|
@@ -421,18 +383,18 @@ export class BotFactory {
|
|
|
421
383
|
}
|
|
422
384
|
|
|
423
385
|
private async withNoMinTxsPerBlock<T>(fn: () => Promise<T>): Promise<T> {
|
|
424
|
-
if (!this.
|
|
386
|
+
if (!this.aztecNodeAdmin || !this.config.flushSetupTransactions) {
|
|
425
387
|
this.log.verbose(`No node admin client or flushing not requested (not setting minTxsPerBlock to 0)`);
|
|
426
388
|
return fn();
|
|
427
389
|
}
|
|
428
|
-
const { minTxsPerBlock } = await this.
|
|
390
|
+
const { minTxsPerBlock } = await this.aztecNodeAdmin.getConfig();
|
|
429
391
|
this.log.warn(`Setting sequencer minTxsPerBlock to 0 from ${minTxsPerBlock} to flush setup transactions`);
|
|
430
|
-
await this.
|
|
392
|
+
await this.aztecNodeAdmin.setConfig({ minTxsPerBlock: 0 });
|
|
431
393
|
try {
|
|
432
394
|
return await fn();
|
|
433
395
|
} finally {
|
|
434
396
|
this.log.warn(`Restoring sequencer minTxsPerBlock to ${minTxsPerBlock}`);
|
|
435
|
-
await this.
|
|
397
|
+
await this.aztecNodeAdmin.setConfig({ minTxsPerBlock });
|
|
436
398
|
}
|
|
437
399
|
}
|
|
438
400
|
}
|
package/src/runner.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import { type AztecNode,
|
|
1
|
+
import { type AztecNode, createLogger } from '@aztec/aztec.js';
|
|
2
2
|
import { omit } from '@aztec/foundation/collection';
|
|
3
3
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
4
|
-
import {
|
|
5
|
-
import { type TelemetryClient, type Traceable, type Tracer,
|
|
4
|
+
import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
5
|
+
import { type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
|
|
6
|
+
import type { TestWallet } from '@aztec/test-wallet';
|
|
6
7
|
|
|
7
8
|
import { AmmBot } from './amm_bot.js';
|
|
8
9
|
import type { BaseBot } from './base_bot.js';
|
|
9
10
|
import { Bot } from './bot.js';
|
|
10
|
-
import {
|
|
11
|
+
import type { BotConfig } from './config.js';
|
|
11
12
|
import type { BotInfo, BotRunnerApi } from './interface.js';
|
|
12
13
|
|
|
13
14
|
export class BotRunner implements BotRunnerApi, Traceable {
|
|
14
15
|
private log = createLogger('bot');
|
|
15
16
|
private bot?: Promise<BaseBot>;
|
|
16
|
-
private pxe?: PXE;
|
|
17
|
-
private node: AztecNode;
|
|
18
|
-
private nodeAdmin?: AztecNodeAdmin;
|
|
19
17
|
private runningPromise: RunningPromise;
|
|
20
18
|
private consecutiveErrors = 0;
|
|
21
19
|
private healthy = true;
|
|
@@ -24,18 +22,13 @@ export class BotRunner implements BotRunnerApi, Traceable {
|
|
|
24
22
|
|
|
25
23
|
public constructor(
|
|
26
24
|
private config: BotConfig,
|
|
27
|
-
|
|
25
|
+
private readonly wallet: TestWallet,
|
|
26
|
+
private readonly aztecNode: AztecNode,
|
|
27
|
+
private readonly telemetry: TelemetryClient,
|
|
28
|
+
private readonly aztecNodeAdmin?: AztecNodeAdmin,
|
|
28
29
|
) {
|
|
29
|
-
this.tracer =
|
|
30
|
-
|
|
31
|
-
throw new Error(`Missing node URL in config or dependencies`);
|
|
32
|
-
}
|
|
33
|
-
const versions = getVersions();
|
|
34
|
-
const fetch = makeTracedFetch([1, 2, 3], true);
|
|
35
|
-
this.node = dependencies.node ?? createAztecNodeClient(config.nodeUrl!, versions, fetch);
|
|
36
|
-
this.nodeAdmin =
|
|
37
|
-
dependencies.nodeAdmin ??
|
|
38
|
-
(config.nodeAdminUrl ? createAztecNodeAdminClient(config.nodeAdminUrl, versions, fetch) : undefined);
|
|
30
|
+
this.tracer = telemetry.getTracer('Bot');
|
|
31
|
+
|
|
39
32
|
this.runningPromise = new RunningPromise(() => this.#work(), this.log, config.txIntervalSeconds * 1000);
|
|
40
33
|
}
|
|
41
34
|
|
|
@@ -150,8 +143,8 @@ export class BotRunner implements BotRunnerApi, Traceable {
|
|
|
150
143
|
async #createBot() {
|
|
151
144
|
try {
|
|
152
145
|
this.bot = this.config.ammTxs
|
|
153
|
-
? AmmBot.create(this.config,
|
|
154
|
-
: Bot.create(this.config,
|
|
146
|
+
? AmmBot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin)
|
|
147
|
+
: Bot.create(this.config, this.wallet, this.aztecNode);
|
|
155
148
|
await this.bot;
|
|
156
149
|
} catch (err) {
|
|
157
150
|
this.log.error(`Error setting up bot: ${err}`);
|
|
@@ -162,7 +155,7 @@ export class BotRunner implements BotRunnerApi, Traceable {
|
|
|
162
155
|
@trackSpan('Bot.work')
|
|
163
156
|
async #work() {
|
|
164
157
|
if (this.config.maxPendingTxs > 0) {
|
|
165
|
-
const pendingTxCount = await this.
|
|
158
|
+
const pendingTxCount = await this.aztecNode.getPendingTxCount();
|
|
166
159
|
if (pendingTxCount >= this.config.maxPendingTxs) {
|
|
167
160
|
this.log.verbose(`Not sending bot tx since node has ${pendingTxCount} pending txs`);
|
|
168
161
|
return;
|