@aztec/bot 0.0.1-commit.d431d1c → 0.0.1-commit.dbf9cec

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.
Files changed (44) hide show
  1. package/dest/amm_bot.d.ts +6 -7
  2. package/dest/amm_bot.d.ts.map +1 -1
  3. package/dest/amm_bot.js +5 -1
  4. package/dest/base_bot.d.ts +6 -6
  5. package/dest/base_bot.d.ts.map +1 -1
  6. package/dest/base_bot.js +12 -13
  7. package/dest/bot.d.ts +6 -6
  8. package/dest/bot.d.ts.map +1 -1
  9. package/dest/bot.js +7 -4
  10. package/dest/config.d.ts +30 -14
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +36 -8
  13. package/dest/cross_chain_bot.d.ts +54 -0
  14. package/dest/cross_chain_bot.d.ts.map +1 -0
  15. package/dest/cross_chain_bot.js +140 -0
  16. package/dest/factory.d.ts +20 -10
  17. package/dest/factory.d.ts.map +1 -1
  18. package/dest/factory.js +155 -66
  19. package/dest/index.d.ts +2 -1
  20. package/dest/index.d.ts.map +1 -1
  21. package/dest/index.js +1 -0
  22. package/dest/l1_to_l2_seeding.d.ts +8 -0
  23. package/dest/l1_to_l2_seeding.d.ts.map +1 -0
  24. package/dest/l1_to_l2_seeding.js +63 -0
  25. package/dest/runner.d.ts +3 -3
  26. package/dest/runner.d.ts.map +1 -1
  27. package/dest/runner.js +17 -1
  28. package/dest/store/bot_store.d.ts +30 -5
  29. package/dest/store/bot_store.d.ts.map +1 -1
  30. package/dest/store/bot_store.js +37 -6
  31. package/dest/store/index.d.ts +2 -2
  32. package/dest/store/index.d.ts.map +1 -1
  33. package/package.json +16 -13
  34. package/src/amm_bot.ts +7 -7
  35. package/src/base_bot.ts +11 -25
  36. package/src/bot.ts +9 -8
  37. package/src/config.ts +39 -10
  38. package/src/cross_chain_bot.ts +209 -0
  39. package/src/factory.ts +163 -51
  40. package/src/index.ts +1 -0
  41. package/src/l1_to_l2_seeding.ts +79 -0
  42. package/src/runner.ts +18 -5
  43. package/src/store/bot_store.ts +60 -5
  44. package/src/store/index.ts +1 -1
package/src/runner.ts CHANGED
@@ -4,12 +4,13 @@ import { omit } from '@aztec/foundation/collection';
4
4
  import { RunningPromise } from '@aztec/foundation/running-promise';
5
5
  import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
6
6
  import { type TelemetryClient, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
7
- import type { TestWallet } from '@aztec/test-wallet/server';
7
+ import type { EmbeddedWallet } from '@aztec/wallets/embedded';
8
8
 
9
9
  import { AmmBot } from './amm_bot.js';
10
10
  import type { BaseBot } from './base_bot.js';
11
11
  import { Bot } from './bot.js';
12
12
  import type { BotConfig } from './config.js';
13
+ import { CrossChainBot } from './cross_chain_bot.js';
13
14
  import type { BotInfo, BotRunnerApi } from './interface.js';
14
15
  import { BotStore } from './store/index.js';
15
16
 
@@ -24,7 +25,7 @@ export class BotRunner implements BotRunnerApi, Traceable {
24
25
 
25
26
  public constructor(
26
27
  private config: BotConfig,
27
- private readonly wallet: TestWallet,
28
+ private readonly wallet: EmbeddedWallet,
28
29
  private readonly aztecNode: AztecNode,
29
30
  private readonly telemetry: TelemetryClient,
30
31
  private readonly aztecNodeAdmin: AztecNodeAdmin | undefined,
@@ -146,9 +147,21 @@ export class BotRunner implements BotRunnerApi, Traceable {
146
147
 
147
148
  async #createBot() {
148
149
  try {
149
- this.bot = this.config.ammTxs
150
- ? AmmBot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store)
151
- : Bot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
150
+ switch (this.config.botMode) {
151
+ case 'crosschain':
152
+ this.bot = CrossChainBot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
153
+ break;
154
+ case 'amm':
155
+ this.bot = AmmBot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
156
+ break;
157
+ case 'transfer':
158
+ this.bot = Bot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
159
+ break;
160
+ default: {
161
+ const _exhaustive: never = this.config.botMode;
162
+ throw new Error(`Unsupported bot mode: [${_exhaustive}]`);
163
+ }
164
+ }
152
165
  await this.bot;
153
166
  } catch (err) {
154
167
  this.log.error(`Error setting up bot: ${err}`);
@@ -2,6 +2,7 @@ import { AztecAddress } from '@aztec/aztec.js/addresses';
2
2
  import type { L2AmountClaim } from '@aztec/aztec.js/ethereum';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import { type Logger, createLogger } from '@aztec/foundation/log';
5
+ import { DateProvider } from '@aztec/foundation/timer';
5
6
  import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
6
7
 
7
8
  export interface BridgeClaimData {
@@ -10,18 +11,38 @@ export interface BridgeClaimData {
10
11
  recipient: string;
11
12
  }
12
13
 
14
+ export interface PendingL1ToL2Message {
15
+ /** Random content field sent in the message. */
16
+ content: string;
17
+ /** Secret for consuming the message. */
18
+ secret: string;
19
+ /** Hash of the secret. */
20
+ secretHash: string;
21
+ /** Hash of the L1→L2 message. */
22
+ msgHash: string;
23
+ /** L1 sender address (hex). */
24
+ sender: string;
25
+ /** Global leaf index in the L1→L2 message tree. */
26
+ globalLeafIndex: string;
27
+ /** Timestamp when the message was seeded. */
28
+ timestamp: number;
29
+ }
30
+
13
31
  /**
14
32
  * Simple data store for the bot to persist L1 bridge claims.
15
33
  */
16
34
  export class BotStore {
17
35
  public static readonly SCHEMA_VERSION = 1;
18
36
  private readonly bridgeClaims: AztecAsyncMap<string, string>;
37
+ private readonly pendingL1ToL2: AztecAsyncMap<string, string>;
19
38
 
20
39
  constructor(
21
40
  private readonly store: AztecAsyncKVStore,
22
41
  private readonly log: Logger = createLogger('bot:store'),
42
+ private readonly dateProvider: DateProvider = new DateProvider(),
23
43
  ) {
24
44
  this.bridgeClaims = store.openMap<string, string>('bridge_claims');
45
+ this.pendingL1ToL2 = store.openMap<string, string>('pending_l1_to_l2');
25
46
  }
26
47
 
27
48
  /**
@@ -39,7 +60,7 @@ export class BotStore {
39
60
 
40
61
  const data = {
41
62
  claim: serializableClaim,
42
- timestamp: Date.now(),
63
+ timestamp: this.dateProvider.now(),
43
64
  recipient: recipient.toString(),
44
65
  };
45
66
 
@@ -115,7 +136,7 @@ export class BotStore {
115
136
  * Cleans up old bridge claims (older than 24 hours).
116
137
  */
117
138
  public async cleanupOldClaims(maxAgeMs: number = 24 * 60 * 60 * 1000): Promise<number> {
118
- const now = Date.now();
139
+ const now = this.dateProvider.now();
119
140
  let cleanedCount = 0;
120
141
  const entries = this.bridgeClaims.entriesAsync();
121
142
 
@@ -131,9 +152,43 @@ export class BotStore {
131
152
  return cleanedCount;
132
153
  }
133
154
 
134
- /**
135
- * Closes the store.
136
- */
155
+ /** Saves a pending L1→L2 message keyed by msgHash. */
156
+ public async savePendingL1ToL2Message(msg: PendingL1ToL2Message): Promise<void> {
157
+ await this.pendingL1ToL2.set(msg.msgHash, JSON.stringify(msg));
158
+ this.log.info(`Saved pending L1→L2 message ${msg.msgHash}`);
159
+ }
160
+
161
+ /** Returns all unconsumed pending L1→L2 messages. */
162
+ public async getUnconsumedL1ToL2Messages(): Promise<PendingL1ToL2Message[]> {
163
+ const messages: PendingL1ToL2Message[] = [];
164
+ for await (const [_, data] of this.pendingL1ToL2.entriesAsync()) {
165
+ messages.push(JSON.parse(data));
166
+ }
167
+ return messages;
168
+ }
169
+
170
+ /** Deletes a consumed L1→L2 message from the store. */
171
+ public async deleteL1ToL2Message(msgHash: string): Promise<void> {
172
+ await this.pendingL1ToL2.delete(msgHash);
173
+ this.log.info(`Deleted consumed L1→L2 message ${msgHash}`);
174
+ }
175
+
176
+ /** Cleans up pending L1→L2 messages older than maxAgeMs. */
177
+ public async cleanupOldPendingMessages(maxAgeMs: number = 24 * 60 * 60 * 1000): Promise<number> {
178
+ const now = this.dateProvider.now();
179
+ let cleanedCount = 0;
180
+ for await (const [key, data] of this.pendingL1ToL2.entriesAsync()) {
181
+ const parsed = JSON.parse(data);
182
+ if (now - parsed.timestamp > maxAgeMs) {
183
+ await this.pendingL1ToL2.delete(key);
184
+ cleanedCount++;
185
+ this.log.info(`Cleaned up old pending L1→L2 message ${key}`);
186
+ }
187
+ }
188
+ return cleanedCount;
189
+ }
190
+
191
+ /** Closes the store. */
137
192
  public async close(): Promise<void> {
138
193
  await this.store.close();
139
194
  this.log.info('Closed bot data store');
@@ -1 +1 @@
1
- export { BotStore, type BridgeClaimData } from './bot_store.js';
1
+ export { BotStore, type BridgeClaimData, type PendingL1ToL2Message } from './bot_store.js';