@aztec/bot 0.76.4 → 0.77.0-testnet-ignition.21

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/runner.js CHANGED
@@ -1,163 +1,158 @@
1
- import { __classPrivateFieldGet, __classPrivateFieldIn, __esDecorate, __runInitializers, __setFunctionName } from "tslib";
1
+ function _ts_decorate(decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ }
2
7
  import { createAztecNodeClient, createLogger } from '@aztec/aztec.js';
3
8
  import { RunningPromise } from '@aztec/foundation/running-promise';
4
9
  import { makeTracedFetch, trackSpan } from '@aztec/telemetry-client';
5
10
  import { Bot } from './bot.js';
6
11
  import { getVersions } from './config.js';
7
- let BotRunner = (() => {
8
- var _BotRunner_instances, _a, _BotRunner_createBot, _BotRunner_work_get;
9
- let _instanceExtraInitializers = [];
10
- let _doSetup_decorators;
11
- let _private_work_decorators;
12
- let _private_work_descriptor;
13
- return _a = class BotRunner {
14
- constructor(config, dependencies) {
15
- _BotRunner_instances.add(this);
16
- this.config = (__runInitializers(this, _instanceExtraInitializers), config);
17
- this.log = createLogger('bot');
18
- this.consecutiveErrors = 0;
19
- this.healthy = true;
20
- this.tracer = dependencies.telemetry.getTracer('Bot');
21
- this.pxe = dependencies.pxe;
22
- if (!dependencies.node && !config.nodeUrl) {
23
- throw new Error(`Missing node URL in config or dependencies`);
24
- }
25
- this.node =
26
- dependencies.node ?? createAztecNodeClient(config.nodeUrl, getVersions(), makeTracedFetch([1, 2, 3], true));
27
- this.runningPromise = new RunningPromise(() => __classPrivateFieldGet(this, _BotRunner_instances, "a", _BotRunner_work_get).call(this), this.log, config.txIntervalSeconds * 1000);
12
+ export class BotRunner {
13
+ config;
14
+ log;
15
+ bot;
16
+ pxe;
17
+ node;
18
+ runningPromise;
19
+ consecutiveErrors;
20
+ healthy;
21
+ tracer;
22
+ constructor(config, dependencies){
23
+ this.config = config;
24
+ this.log = createLogger('bot');
25
+ this.consecutiveErrors = 0;
26
+ this.healthy = true;
27
+ this.tracer = dependencies.telemetry.getTracer('Bot');
28
+ this.pxe = dependencies.pxe;
29
+ if (!dependencies.node && !config.nodeUrl) {
30
+ throw new Error(`Missing node URL in config or dependencies`);
31
+ }
32
+ this.node = dependencies.node ?? createAztecNodeClient(config.nodeUrl, getVersions(), makeTracedFetch([
33
+ 1,
34
+ 2,
35
+ 3
36
+ ], true));
37
+ this.runningPromise = new RunningPromise(()=>this.#work(), this.log, config.txIntervalSeconds * 1000);
38
+ }
39
+ /** Initializes the bot if needed. Blocks until the bot setup is finished. */ async setup() {
40
+ if (!this.bot) {
41
+ await this.doSetup();
42
+ }
43
+ }
44
+ async doSetup() {
45
+ this.log.verbose(`Setting up bot`);
46
+ await this.#createBot();
47
+ this.log.info(`Bot set up completed`);
48
+ }
49
+ /**
50
+ * Initializes the bot if needed and starts sending txs at regular intervals.
51
+ * Blocks until the bot setup is finished.
52
+ */ async start() {
53
+ await this.setup();
54
+ if (!this.runningPromise.isRunning()) {
55
+ this.log.info(`Starting bot with interval of ${this.config.txIntervalSeconds}s`);
56
+ this.runningPromise.start();
57
+ }
58
+ }
59
+ /**
60
+ * Stops sending txs. Returns once all ongoing txs are finished.
61
+ */ async stop() {
62
+ if (this.runningPromise.isRunning()) {
63
+ this.log.verbose(`Stopping bot`);
64
+ await this.runningPromise.stop();
65
+ }
66
+ this.log.info(`Stopped bot`);
67
+ }
68
+ isHealthy() {
69
+ return this.runningPromise.isRunning() && this.healthy;
70
+ }
71
+ /** Returns whether the bot is running. */ isRunning() {
72
+ return this.runningPromise.isRunning();
73
+ }
74
+ /**
75
+ * Updates the bot config and recreates the bot. Will stop and restart the bot automatically if it was
76
+ * running when this method was called. Blocks until the new bot is set up.
77
+ */ async update(config) {
78
+ this.log.verbose(`Updating bot config`);
79
+ const wasRunning = this.isRunning();
80
+ if (wasRunning) {
81
+ await this.stop();
82
+ }
83
+ this.config = {
84
+ ...this.config,
85
+ ...config
86
+ };
87
+ this.runningPromise.setPollingIntervalMS(this.config.txIntervalSeconds * 1000);
88
+ await this.#createBot();
89
+ this.log.info(`Bot config updated`);
90
+ if (wasRunning) {
91
+ await this.start();
92
+ }
93
+ }
94
+ /**
95
+ * Triggers a single iteration of the bot. Requires the bot to be initialized.
96
+ * Blocks until the run is finished.
97
+ */ async run() {
98
+ if (!this.bot) {
99
+ this.log.error(`Trying to run with uninitialized bot`);
100
+ throw new Error(`Bot is not initialized`);
101
+ }
102
+ let bot;
103
+ try {
104
+ bot = await this.bot;
105
+ } catch (err) {
106
+ this.log.error(`Error awaiting bot set up: ${err}`);
107
+ throw err;
108
+ }
109
+ try {
110
+ await bot.run();
111
+ this.consecutiveErrors = 0;
112
+ } catch (err) {
113
+ this.consecutiveErrors += 1;
114
+ this.log.error(`Error running bot consecutiveCount=${this.consecutiveErrors}: ${err}`);
115
+ throw err;
116
+ }
117
+ }
118
+ /** Returns the current configuration for the bot. */ getConfig() {
119
+ return Promise.resolve(this.config);
120
+ }
121
+ async #createBot() {
122
+ try {
123
+ this.bot = Bot.create(this.config, {
124
+ pxe: this.pxe,
125
+ node: this.node
126
+ });
127
+ await this.bot;
128
+ } catch (err) {
129
+ this.log.error(`Error setting up bot: ${err}`);
130
+ throw err;
131
+ }
132
+ }
133
+ async #work() {
134
+ if (this.config.maxPendingTxs > 0) {
135
+ const pendingTxs = await this.node.getPendingTxs();
136
+ if (pendingTxs.length >= this.config.maxPendingTxs) {
137
+ this.log.verbose(`Not sending bot tx since node has ${pendingTxs.length} pending txs`);
138
+ return;
28
139
  }
29
- /** Initializes the bot if needed. Blocks until the bot setup is finished. */
30
- async setup() {
31
- if (!this.bot) {
32
- await this.doSetup();
33
- }
140
+ }
141
+ try {
142
+ await this.run();
143
+ } catch (err) {
144
+ // Already logged in run()
145
+ if (this.config.maxConsecutiveErrors > 0 && this.consecutiveErrors >= this.config.maxConsecutiveErrors) {
146
+ this.log.error(`Too many errors bot is unhealthy`);
147
+ this.healthy = false;
34
148
  }
35
- async doSetup() {
36
- this.log.verbose(`Setting up bot`);
37
- await __classPrivateFieldGet(this, _BotRunner_instances, "m", _BotRunner_createBot).call(this);
38
- this.log.info(`Bot set up completed`);
39
- }
40
- /**
41
- * Initializes the bot if needed and starts sending txs at regular intervals.
42
- * Blocks until the bot setup is finished.
43
- */
44
- async start() {
45
- await this.setup();
46
- if (!this.runningPromise.isRunning()) {
47
- this.log.info(`Starting bot with interval of ${this.config.txIntervalSeconds}s`);
48
- this.runningPromise.start();
49
- }
50
- }
51
- /**
52
- * Stops sending txs. Returns once all ongoing txs are finished.
53
- */
54
- async stop() {
55
- if (this.runningPromise.isRunning()) {
56
- this.log.verbose(`Stopping bot`);
57
- await this.runningPromise.stop();
58
- }
59
- this.log.info(`Stopped bot`);
60
- }
61
- isHealthy() {
62
- return this.runningPromise.isRunning() && this.healthy;
63
- }
64
- /** Returns whether the bot is running. */
65
- isRunning() {
66
- return this.runningPromise.isRunning();
67
- }
68
- /**
69
- * Updates the bot config and recreates the bot. Will stop and restart the bot automatically if it was
70
- * running when this method was called. Blocks until the new bot is set up.
71
- */
72
- async update(config) {
73
- this.log.verbose(`Updating bot config`);
74
- const wasRunning = this.isRunning();
75
- if (wasRunning) {
76
- await this.stop();
77
- }
78
- this.config = { ...this.config, ...config };
79
- this.runningPromise.setPollingIntervalMS(this.config.txIntervalSeconds * 1000);
80
- await __classPrivateFieldGet(this, _BotRunner_instances, "m", _BotRunner_createBot).call(this);
81
- this.log.info(`Bot config updated`);
82
- if (wasRunning) {
83
- await this.start();
84
- }
85
- }
86
- /**
87
- * Triggers a single iteration of the bot. Requires the bot to be initialized.
88
- * Blocks until the run is finished.
89
- */
90
- async run() {
91
- if (!this.bot) {
92
- this.log.error(`Trying to run with uninitialized bot`);
93
- throw new Error(`Bot is not initialized`);
94
- }
95
- let bot;
96
- try {
97
- bot = await this.bot;
98
- }
99
- catch (err) {
100
- this.log.error(`Error awaiting bot set up: ${err}`);
101
- throw err;
102
- }
103
- try {
104
- await bot.run();
105
- this.consecutiveErrors = 0;
106
- }
107
- catch (err) {
108
- this.consecutiveErrors += 1;
109
- this.log.error(`Error running bot consecutiveCount=${this.consecutiveErrors}: ${err}`);
110
- throw err;
111
- }
112
- }
113
- /** Returns the current configuration for the bot. */
114
- getConfig() {
115
- return Promise.resolve(this.config);
116
- }
117
- },
118
- _BotRunner_instances = new WeakSet(),
119
- _BotRunner_createBot = async function _BotRunner_createBot() {
120
- try {
121
- this.bot = Bot.create(this.config, { pxe: this.pxe, node: this.node });
122
- await this.bot;
123
- }
124
- catch (err) {
125
- this.log.error(`Error setting up bot: ${err}`);
126
- throw err;
127
- }
128
- },
129
- _BotRunner_work_get = function _BotRunner_work_get() { return _private_work_descriptor.value; },
130
- (() => {
131
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
132
- _doSetup_decorators = [trackSpan('Bot.setup')];
133
- _private_work_decorators = [trackSpan('Bot.work')];
134
- __esDecorate(_a, null, _doSetup_decorators, { kind: "method", name: "doSetup", static: false, private: false, access: { has: obj => "doSetup" in obj, get: obj => obj.doSetup }, metadata: _metadata }, null, _instanceExtraInitializers);
135
- __esDecorate(_a, _private_work_descriptor = { value: __setFunctionName(async function () {
136
- if (this.config.maxPendingTxs > 0) {
137
- const pendingTxs = await this.node.getPendingTxs();
138
- if (pendingTxs.length >= this.config.maxPendingTxs) {
139
- this.log.verbose(`Not sending bot tx since node has ${pendingTxs.length} pending txs`);
140
- return;
141
- }
142
- }
143
- try {
144
- await this.run();
145
- }
146
- catch (err) {
147
- // Already logged in run()
148
- if (this.config.maxConsecutiveErrors > 0 && this.consecutiveErrors >= this.config.maxConsecutiveErrors) {
149
- this.log.error(`Too many errors bot is unhealthy`);
150
- this.healthy = false;
151
- }
152
- }
153
- if (!this.healthy && this.config.stopWhenUnhealthy) {
154
- this.log.fatal(`Stopping bot due to errors`);
155
- process.exit(1); // workaround docker not restarting the container if its unhealthy. We have to exit instead
156
- }
157
- }, "#work") }, _private_work_decorators, { kind: "method", name: "#work", static: false, private: true, access: { has: obj => __classPrivateFieldIn(_BotRunner_instances, obj), get: obj => __classPrivateFieldGet(obj, _BotRunner_instances, "a", _BotRunner_work_get) }, metadata: _metadata }, null, _instanceExtraInitializers);
158
- if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
159
- })(),
160
- _a;
161
- })();
162
- export { BotRunner };
163
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicnVubmVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3J1bm5lci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsT0FBTyxFQUE0QixxQkFBcUIsRUFBRSxZQUFZLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQztBQUNoRyxPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0sbUNBQW1DLENBQUM7QUFDbkUsT0FBTyxFQUFxRCxlQUFlLEVBQUUsU0FBUyxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFFeEgsT0FBTyxFQUFFLEdBQUcsRUFBRSxNQUFNLFVBQVUsQ0FBQztBQUMvQixPQUFPLEVBQWtCLFdBQVcsRUFBRSxNQUFNLGFBQWEsQ0FBQztJQUc3QyxTQUFTOzs7Ozs7c0JBQVQsU0FBUztZQVdwQixZQUNVLE1BQWlCLEVBQ3pCLFlBQXlFOztnQkFEakUsV0FBTSxJQVpMLG1EQUFTLEVBWVYsTUFBTSxFQUFXO2dCQVhu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BQyxvQkFBb0IsR0FBRyxDQUFDLElBQUksSUFBSSxDQUFDLGlCQUFpQixJQUFJLElBQUksQ0FBQyxNQUFNLENBQUMsb0JBQW9CLEVBQUUsQ0FBQzs0QkFDdkcsSUFBSSxDQUFDLEdBQUcsQ0FBQyxLQUFLLENBQUMsa0NBQWtDLENBQUMsQ0FBQzs0QkFDbkQsSUFBSSxDQUFDLE9BQU8sR0FBRyxLQUFLLENBQUM7d0JBQ3ZCLENBQUM7b0JBQ0gsQ0FBQztvQkFFRCxJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sSUFBSSxJQUFJLENBQUMsTUFBTSxDQUFDLGlCQUFpQixFQUFFLENBQUM7d0JBQ25ELElBQUksQ0FBQyxHQUFHLENBQUMsS0FBSyxDQUFDLDRCQUE0QixDQUFDLENBQUM7d0JBQzdDLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQywyRkFBMkY7b0JBQzlHLENBQUM7Z0JBQ0gsQ0FBQyxVQUFBLHlUQUFBOzs7OztTQTdKVSxTQUFTIn0=
149
+ }
150
+ if (!this.healthy && this.config.stopWhenUnhealthy) {
151
+ this.log.fatal(`Stopping bot due to errors`);
152
+ process.exit(1); // workaround docker not restarting the container if its unhealthy. We have to exit instead
153
+ }
154
+ }
155
+ }
156
+ _ts_decorate([
157
+ trackSpan('Bot.setup')
158
+ ], BotRunner.prototype, "doSetup", null);
package/dest/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { type AztecAddress } from '@aztec/circuits.js';
2
- import { type EasyPrivateTokenContract } from '@aztec/noir-contracts.js/EasyPrivateToken';
3
- import { type TokenContract } from '@aztec/noir-contracts.js/Token';
1
+ import type { EasyPrivateTokenContract } from '@aztec/noir-contracts.js/EasyPrivateToken';
2
+ import type { TokenContract } from '@aztec/noir-contracts.js/Token';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  /**
5
5
  * Gets the private and public balance of the given token for the given address.
6
6
  * @param token - Token contract.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AAC1F,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAEpE;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,aAAa,EACpB,GAAG,EAAE,YAAY,GAChB,OAAO,CAAC;IAAE,cAAc,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,CAI5D;AAED,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,wBAAwB,EAAE,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAG3G;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,aAAa,GAAG,wBAAwB,GAAG,KAAK,IAAI,aAAa,CAE/G"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AAC1F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,aAAa,EACpB,GAAG,EAAE,YAAY,GAChB,OAAO,CAAC;IAAE,cAAc,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,CAI5D;AAED,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,wBAAwB,EAAE,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAG3G;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,aAAa,GAAG,wBAAwB,GAAG,KAAK,IAAI,aAAa,CAE/G"}
package/dest/utils.js CHANGED
@@ -3,11 +3,13 @@
3
3
  * @param token - Token contract.
4
4
  * @param who - Address to get the balance for.
5
5
  * @returns - Private and public token balances as bigints.
6
- */
7
- export async function getBalances(token, who) {
6
+ */ export async function getBalances(token, who) {
8
7
  const privateBalance = await token.methods.balance_of_private(who).simulate();
9
8
  const publicBalance = await token.methods.balance_of_public(who).simulate();
10
- return { privateBalance, publicBalance };
9
+ return {
10
+ privateBalance,
11
+ publicBalance
12
+ };
11
13
  }
12
14
  export async function getPrivateBalance(token, who) {
13
15
  const privateBalance = await token.methods.get_balance(who).simulate();
@@ -16,4 +18,3 @@ export async function getPrivateBalance(token, who) {
16
18
  export function isStandardTokenContract(token) {
17
19
  return 'mint_to_public' in token.methods;
18
20
  }
19
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvdXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSUE7Ozs7O0dBS0c7QUFDSCxNQUFNLENBQUMsS0FBSyxVQUFVLFdBQVcsQ0FDL0IsS0FBb0IsRUFDcEIsR0FBaUI7SUFFakIsTUFBTSxjQUFjLEdBQUcsTUFBTSxLQUFLLENBQUMsT0FBTyxDQUFDLGtCQUFrQixDQUFDLEdBQUcsQ0FBQyxDQUFDLFFBQVEsRUFBRSxDQUFDO0lBQzlFLE1BQU0sYUFBYSxHQUFHLE1BQU0sS0FBSyxDQUFDLE9BQU8sQ0FBQyxpQkFBaUIsQ0FBQyxHQUFHLENBQUMsQ0FBQyxRQUFRLEVBQUUsQ0FBQztJQUM1RSxPQUFPLEVBQUUsY0FBYyxFQUFFLGFBQWEsRUFBRSxDQUFDO0FBQzNDLENBQUM7QUFFRCxNQUFNLENBQUMsS0FBSyxVQUFVLGlCQUFpQixDQUFDLEtBQStCLEVBQUUsR0FBaUI7SUFDeEYsTUFBTSxjQUFjLEdBQUcsTUFBTSxLQUFLLENBQUMsT0FBTyxDQUFDLFdBQVcsQ0FBQyxHQUFHLENBQUMsQ0FBQyxRQUFRLEVBQUUsQ0FBQztJQUN2RSxPQUFPLGNBQWMsQ0FBQztBQUN4QixDQUFDO0FBRUQsTUFBTSxVQUFVLHVCQUF1QixDQUFDLEtBQStDO0lBQ3JGLE9BQU8sZ0JBQWdCLElBQUksS0FBSyxDQUFDLE9BQU8sQ0FBQztBQUMzQyxDQUFDIn0=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/bot",
3
- "version": "0.76.4",
3
+ "version": "0.77.0-testnet-ignition.21",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -16,7 +16,7 @@
16
16
  "formatting": "run -T prettier --check ./src && run -T eslint ./src",
17
17
  "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
18
18
  "bb": "node --no-warnings ./dest/bb/index.js",
19
- "test": "HARDWARE_CONCURRENCY=${HARDWARE_CONCURRENCY:-16} RAYON_NUM_THREADS=${RAYON_NUM_THREADS:-4} NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
19
+ "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
20
20
  },
21
21
  "jest": {
22
22
  "moduleNameMapper": {
@@ -46,23 +46,22 @@
46
46
  "reporters": [
47
47
  "default"
48
48
  ],
49
- "testTimeout": 30000,
49
+ "testTimeout": 120000,
50
50
  "setupFiles": [
51
51
  "../../foundation/src/jest/setup.mjs"
52
52
  ]
53
53
  },
54
54
  "dependencies": {
55
- "@aztec/accounts": "0.76.4",
56
- "@aztec/aztec.js": "0.76.4",
57
- "@aztec/circuit-types": "0.76.4",
58
- "@aztec/circuits.js": "0.76.4",
59
- "@aztec/entrypoints": "0.76.4",
60
- "@aztec/foundation": "0.76.4",
61
- "@aztec/noir-contracts.js": "0.76.4",
62
- "@aztec/noir-protocol-circuits-types": "0.76.4",
63
- "@aztec/protocol-contracts": "0.76.4",
64
- "@aztec/telemetry-client": "0.76.4",
65
- "@aztec/types": "0.76.4",
55
+ "@aztec/accounts": "0.77.0-testnet-ignition.21",
56
+ "@aztec/aztec.js": "0.77.0-testnet-ignition.21",
57
+ "@aztec/entrypoints": "0.77.0-testnet-ignition.21",
58
+ "@aztec/ethereum": "0.77.0-testnet-ignition.21",
59
+ "@aztec/foundation": "0.77.0-testnet-ignition.21",
60
+ "@aztec/noir-contracts.js": "0.77.0-testnet-ignition.21",
61
+ "@aztec/noir-protocol-circuits-types": "0.77.0-testnet-ignition.21",
62
+ "@aztec/protocol-contracts": "0.77.0-testnet-ignition.21",
63
+ "@aztec/stdlib": "0.77.0-testnet-ignition.21",
64
+ "@aztec/telemetry-client": "0.77.0-testnet-ignition.21",
66
65
  "source-map-support": "^0.5.21",
67
66
  "tslib": "^2.4.0",
68
67
  "zod": "^3.23.8"
package/src/bot.ts CHANGED
@@ -2,18 +2,18 @@ import {
2
2
  type AztecAddress,
3
3
  BatchCall,
4
4
  FeeJuicePaymentMethod,
5
- NoFeePaymentMethod,
6
5
  type SendMethodOptions,
7
6
  type Wallet,
8
7
  createLogger,
9
8
  } from '@aztec/aztec.js';
10
- import { type AztecNode, type FunctionCall, type PXE } from '@aztec/circuit-types';
11
- import { Gas } from '@aztec/circuits.js';
12
9
  import { timesParallel } from '@aztec/foundation/collection';
13
- import { type EasyPrivateTokenContract } from '@aztec/noir-contracts.js/EasyPrivateToken';
14
- import { type TokenContract } from '@aztec/noir-contracts.js/Token';
10
+ import type { EasyPrivateTokenContract } from '@aztec/noir-contracts.js/EasyPrivateToken';
11
+ import type { TokenContract } from '@aztec/noir-contracts.js/Token';
12
+ import type { FunctionCall } from '@aztec/stdlib/abi';
13
+ import { Gas } from '@aztec/stdlib/gas';
14
+ import type { AztecNode, PXE } from '@aztec/stdlib/interfaces/client';
15
15
 
16
- import { type BotConfig } from './config.js';
16
+ import type { BotConfig } from './config.js';
17
17
  import { BotFactory } from './factory.js';
18
18
  import { getBalances, getPrivateBalance, isStandardTokenContract } from './utils.js';
19
19
 
@@ -132,9 +132,8 @@ export class Bot {
132
132
 
133
133
  private getSendMethodOpts(): SendMethodOptions {
134
134
  const sender = this.wallet.getAddress();
135
- const { feePaymentMethod, l2GasLimit, daGasLimit, skipPublicSimulation } = this.config;
136
- const paymentMethod =
137
- feePaymentMethod === 'fee_juice' ? new FeeJuicePaymentMethod(sender) : new NoFeePaymentMethod();
135
+ const { l2GasLimit, daGasLimit, skipPublicSimulation } = this.config;
136
+ const paymentMethod = new FeeJuicePaymentMethod(sender);
138
137
 
139
138
  let gasSettings, estimateGas;
140
139
  if (l2GasLimit !== undefined && l2GasLimit > 0 && daGasLimit !== undefined && daGasLimit > 0) {
package/src/config.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { type ComponentsVersions } from '@aztec/circuit-types';
2
- import { Fr } from '@aztec/circuits.js';
3
1
  import {
4
2
  type ConfigMappingsType,
5
3
  booleanConfigHelper,
@@ -8,9 +6,11 @@ import {
8
6
  numberConfigHelper,
9
7
  optionalNumberConfigHelper,
10
8
  } from '@aztec/foundation/config';
11
- import { type ZodFor, schemas } from '@aztec/foundation/schemas';
12
- import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks';
9
+ import { Fr } from '@aztec/foundation/fields';
10
+ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
13
11
  import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
12
+ import { type ZodFor, schemas } from '@aztec/stdlib/schemas';
13
+ import type { ComponentsVersions } from '@aztec/stdlib/versioning';
14
14
 
15
15
  import { z } from 'zod';
16
16
 
@@ -27,8 +27,14 @@ export type BotConfig = {
27
27
  nodeUrl: string | undefined;
28
28
  /** URL to the PXE for sending txs, or undefined if an in-proc PXE is used. */
29
29
  pxeUrl: string | undefined;
30
+ /** Url of the ethereum host. */
31
+ l1RpcUrls: string[] | undefined;
32
+ /** The mnemonic for the account to bridge fee juice from L1. */
33
+ l1Mnemonic: string | undefined;
34
+ /** The private key for the account to bridge fee juice from L1. */
35
+ l1PrivateKey: string | undefined;
30
36
  /** Signing private key for the sender account. */
31
- senderPrivateKey: Fr;
37
+ senderPrivateKey: Fr | undefined;
32
38
  /** Encryption secret for a recipient account. */
33
39
  recipientEncryptionSecret: Fr;
34
40
  /** Salt for the token contract deployment. */
@@ -40,7 +46,7 @@ export type BotConfig = {
40
46
  /** How many public token transfers are executed per tx. */
41
47
  publicTransfersPerTx: number;
42
48
  /** How to handle fee payments. */
43
- feePaymentMethod: 'fee_juice' | 'none';
49
+ feePaymentMethod: 'fee_juice';
44
50
  /** True to not automatically setup or start the bot on initialization. */
45
51
  noStart: boolean;
46
52
  /** How long to wait for a tx to be mined before reporting an error. */
@@ -69,13 +75,16 @@ export const BotConfigSchema = z
69
75
  .object({
70
76
  nodeUrl: z.string().optional(),
71
77
  pxeUrl: z.string().optional(),
72
- senderPrivateKey: schemas.Fr,
78
+ l1RpcUrls: z.array(z.string()).optional(),
79
+ l1Mnemonic: z.string().optional(),
80
+ l1PrivateKey: z.string().optional(),
81
+ senderPrivateKey: schemas.Fr.optional(),
73
82
  recipientEncryptionSecret: schemas.Fr,
74
83
  tokenSalt: schemas.Fr,
75
84
  txIntervalSeconds: z.number(),
76
85
  privateTransfersPerTx: z.number(),
77
86
  publicTransfersPerTx: z.number(),
78
- feePaymentMethod: z.union([z.literal('fee_juice'), z.literal('none')]),
87
+ feePaymentMethod: z.literal('fee_juice'),
79
88
  noStart: z.boolean(),
80
89
  txMinedWaitSeconds: z.number(),
81
90
  followChain: z.enum(BotFollowChain),
@@ -91,6 +100,10 @@ export const BotConfigSchema = z
91
100
  .transform(config => ({
92
101
  nodeUrl: undefined,
93
102
  pxeUrl: undefined,
103
+ l1RpcUrls: undefined,
104
+ l1Mnemonic: undefined,
105
+ l1PrivateKey: undefined,
106
+ senderPrivateKey: undefined,
94
107
  l2GasLimit: undefined,
95
108
  daGasLimit: undefined,
96
109
  ...config,
@@ -105,11 +118,23 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
105
118
  env: 'BOT_PXE_URL',
106
119
  description: 'URL to the PXE for sending txs, or undefined if an in-proc PXE is used.',
107
120
  },
121
+ l1RpcUrls: {
122
+ env: 'ETHEREUM_HOSTS',
123
+ description: 'URL of the ethereum host.',
124
+ parseEnv: (val: string) => val.split(',').map(url => url.trim()),
125
+ },
126
+ l1Mnemonic: {
127
+ env: 'BOT_L1_MNEMONIC',
128
+ description: 'The mnemonic for the account to bridge fee juice from L1.',
129
+ },
130
+ l1PrivateKey: {
131
+ env: 'BOT_L1_PRIVATE_KEY',
132
+ description: 'The private key for the account to bridge fee juice from L1.',
133
+ },
108
134
  senderPrivateKey: {
109
135
  env: 'BOT_PRIVATE_KEY',
110
136
  description: 'Signing private key for the sender account.',
111
- parseEnv: (val: string) => Fr.fromHexString(val),
112
- defaultValue: Fr.random(),
137
+ parseEnv: (val: string) => (val ? Fr.fromHexString(val) : undefined),
113
138
  },
114
139
  recipientEncryptionSecret: {
115
140
  env: 'BOT_RECIPIENT_ENCRYPTION_SECRET',
@@ -140,9 +165,9 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
140
165
  },
141
166
  feePaymentMethod: {
142
167
  env: 'BOT_FEE_PAYMENT_METHOD',
143
- description: 'How to handle fee payments. (Options: fee_juice, none)',
144
- parseEnv: val => (val as 'fee_juice' | 'none') || undefined,
145
- defaultValue: 'none',
168
+ description: 'How to handle fee payments. (Options: fee_juice)',
169
+ parseEnv: val => (val as 'fee_juice') || undefined,
170
+ defaultValue: 'fee_juice',
146
171
  },
147
172
  noStart: {
148
173
  env: 'BOT_NO_START',