@aztec/bot 0.0.1-commit.d6f2b3f94 → 0.0.1-commit.db765a8

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 (46) hide show
  1. package/dest/amm_bot.d.ts +4 -4
  2. package/dest/amm_bot.d.ts.map +1 -1
  3. package/dest/amm_bot.js +23 -16
  4. package/dest/base_bot.d.ts +4 -4
  5. package/dest/base_bot.d.ts.map +1 -1
  6. package/dest/base_bot.js +9 -10
  7. package/dest/bot.d.ts +4 -4
  8. package/dest/bot.d.ts.map +1 -1
  9. package/dest/bot.js +4 -3
  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 +141 -0
  16. package/dest/factory.d.ts +20 -5
  17. package/dest/factory.d.ts.map +1 -1
  18. package/dest/factory.js +93 -24
  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/dest/utils.js +3 -3
  34. package/package.json +16 -13
  35. package/src/amm_bot.ts +23 -18
  36. package/src/base_bot.ts +8 -18
  37. package/src/bot.ts +7 -6
  38. package/src/config.ts +39 -10
  39. package/src/cross_chain_bot.ts +210 -0
  40. package/src/factory.ts +137 -30
  41. package/src/index.ts +1 -0
  42. package/src/l1_to_l2_seeding.ts +79 -0
  43. package/src/runner.ts +18 -5
  44. package/src/store/bot_store.ts +60 -5
  45. package/src/store/index.ts +1 -1
  46. package/src/utils.ts +3 -3
@@ -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';
package/src/utils.ts CHANGED
@@ -15,8 +15,8 @@ export async function getBalances(
15
15
  who: AztecAddress,
16
16
  from?: AztecAddress,
17
17
  ): Promise<{ privateBalance: bigint; publicBalance: bigint }> {
18
- const privateBalance = await token.methods.balance_of_private(who).simulate({ from: from ?? who });
19
- const publicBalance = await token.methods.balance_of_public(who).simulate({ from: from ?? who });
18
+ const { result: privateBalance } = await token.methods.balance_of_private(who).simulate({ from: from ?? who });
19
+ const { result: publicBalance } = await token.methods.balance_of_public(who).simulate({ from: from ?? who });
20
20
  return { privateBalance, publicBalance };
21
21
  }
22
22
 
@@ -25,7 +25,7 @@ export async function getPrivateBalance(
25
25
  who: AztecAddress,
26
26
  from?: AztecAddress,
27
27
  ): Promise<bigint> {
28
- const privateBalance = await token.methods.get_balance(who).simulate({ from: from ?? who });
28
+ const { result: privateBalance } = await token.methods.get_balance(who).simulate({ from: from ?? who });
29
29
  return privateBalance;
30
30
  }
31
31