@aztec/bot 0.0.1-commit.b655e406 → 0.0.1-commit.b8a057fa

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 (52) hide show
  1. package/dest/amm_bot.d.ts +7 -7
  2. package/dest/amm_bot.d.ts.map +1 -1
  3. package/dest/amm_bot.js +30 -19
  4. package/dest/base_bot.d.ts +8 -8
  5. package/dest/base_bot.d.ts.map +1 -1
  6. package/dest/base_bot.js +26 -37
  7. package/dest/bot.d.ts +7 -6
  8. package/dest/bot.d.ts.map +1 -1
  9. package/dest/bot.js +11 -11
  10. package/dest/config.d.ts +63 -99
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +48 -21
  13. package/dest/cross_chain_bot.d.ts +56 -0
  14. package/dest/cross_chain_bot.d.ts.map +1 -0
  15. package/dest/cross_chain_bot.js +138 -0
  16. package/dest/factory.d.ts +23 -27
  17. package/dest/factory.d.ts.map +1 -1
  18. package/dest/factory.js +252 -141
  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/interface.d.ts +2 -6
  23. package/dest/interface.d.ts.map +1 -1
  24. package/dest/interface.js +30 -7
  25. package/dest/l1_to_l2_seeding.d.ts +8 -0
  26. package/dest/l1_to_l2_seeding.d.ts.map +1 -0
  27. package/dest/l1_to_l2_seeding.js +63 -0
  28. package/dest/rpc.d.ts +1 -1
  29. package/dest/runner.d.ts +4 -3
  30. package/dest/runner.d.ts.map +1 -1
  31. package/dest/runner.js +432 -32
  32. package/dest/store/bot_store.d.ts +30 -5
  33. package/dest/store/bot_store.d.ts.map +1 -1
  34. package/dest/store/bot_store.js +38 -7
  35. package/dest/store/index.d.ts +2 -2
  36. package/dest/store/index.d.ts.map +1 -1
  37. package/dest/utils.d.ts +1 -1
  38. package/dest/utils.js +3 -3
  39. package/package.json +20 -16
  40. package/src/amm_bot.ts +30 -22
  41. package/src/base_bot.ts +23 -44
  42. package/src/bot.ts +14 -12
  43. package/src/config.ts +96 -65
  44. package/src/cross_chain_bot.ts +208 -0
  45. package/src/factory.ts +302 -129
  46. package/src/index.ts +1 -0
  47. package/src/interface.ts +7 -7
  48. package/src/l1_to_l2_seeding.ts +79 -0
  49. package/src/runner.ts +41 -5
  50. package/src/store/bot_store.ts +61 -6
  51. package/src/store/index.ts +1 -1
  52. package/src/utils.ts +3 -3
package/src/config.ts CHANGED
@@ -2,6 +2,7 @@ import {
2
2
  type ConfigMappingsType,
3
3
  SecretValue,
4
4
  booleanConfigHelper,
5
+ floatConfigHelper,
5
6
  getConfigFromMappings,
6
7
  getDefaultConfig,
7
8
  numberConfigHelper,
@@ -10,18 +11,21 @@ import {
10
11
  secretFrConfigHelper,
11
12
  secretStringConfigHelper,
12
13
  } from '@aztec/foundation/config';
13
- import { Fr } from '@aztec/foundation/fields';
14
- import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
14
+ import { Fr } from '@aztec/foundation/curves/bn254';
15
15
  import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
16
16
  import { protocolContractsHash } from '@aztec/protocol-contracts';
17
- import { type ZodFor, schemas } from '@aztec/stdlib/schemas';
17
+ import { type DataStoreConfig, dataConfigMappings } from '@aztec/stdlib/kv-store';
18
+ import { schemas, zodFor } from '@aztec/stdlib/schemas';
18
19
  import type { ComponentsVersions } from '@aztec/stdlib/versioning';
19
20
 
20
21
  import { z } from 'zod';
21
22
 
22
- const BotFollowChain = ['NONE', 'PENDING', 'PROVEN'] as const;
23
+ const BotFollowChain = ['NONE', 'PROPOSED', 'CHECKPOINTED', 'PROVEN'] as const;
23
24
  type BotFollowChain = (typeof BotFollowChain)[number];
24
25
 
26
+ const BotMode = ['transfer', 'amm', 'crosschain'] as const;
27
+ type BotMode = (typeof BotMode)[number];
28
+
25
29
  export enum SupportedTokenContracts {
26
30
  TokenContract = 'TokenContract',
27
31
  PrivateTokenContract = 'PrivateTokenContract',
@@ -54,8 +58,8 @@ export type BotConfig = {
54
58
  publicTransfersPerTx: number;
55
59
  /** How to handle fee payments. */
56
60
  feePaymentMethod: 'fee_juice';
57
- /** 'How much is the bot willing to overpay vs. the current base fee' */
58
- baseFeePadding: number;
61
+ /** 'How much is the bot willing to overpay vs. the current min fee' */
62
+ minFeePadding: number;
59
63
  /** True to not automatically setup or start the bot on initialization. */
60
64
  noStart: boolean;
61
65
  /** How long to wait for a tx to be mined before reporting an error. */
@@ -66,9 +70,9 @@ export type BotConfig = {
66
70
  maxPendingTxs: number;
67
71
  /** Whether to flush after sending each 'setup' transaction */
68
72
  flushSetupTransactions: boolean;
69
- /** L2 gas limit for the tx (empty to have the bot trigger an estimate gas). */
73
+ /** L2 gas limit for the tx (empty to let the bot's wallet estimate). */
70
74
  l2GasLimit: number | undefined;
71
- /** DA gas limit for the tx (empty to have the bot trigger an estimate gas). */
75
+ /** DA gas limit for the tx (empty to let the bot's wallet estimate). */
72
76
  daGasLimit: number | undefined;
73
77
  /** Token contract to use */
74
78
  contract: SupportedTokenContracts;
@@ -76,54 +80,61 @@ export type BotConfig = {
76
80
  maxConsecutiveErrors: number;
77
81
  /** Stops the bot if service becomes unhealthy */
78
82
  stopWhenUnhealthy: boolean;
79
- /** Deploy an AMM contract and do swaps instead of transfers */
80
- ammTxs: boolean;
83
+ /** Bot mode: transfer, amm, or crosschain. */
84
+ botMode: BotMode;
85
+ /** Number of L2→L1 messages per tx (crosschain mode). */
86
+ l2ToL1MessagesPerTx: number;
87
+ /** Max L1→L2 messages to keep in-flight (crosschain mode). */
88
+ l1ToL2SeedCount: number;
81
89
  } & Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb'>;
82
90
 
83
- export const BotConfigSchema = z
84
- .object({
85
- nodeUrl: z.string().optional(),
86
- nodeAdminUrl: z.string().optional(),
87
- l1RpcUrls: z.array(z.string()).optional(),
88
- l1Mnemonic: schemas.SecretValue(z.string()).optional(),
89
- l1PrivateKey: schemas.SecretValue(z.string()).optional(),
90
- l1ToL2MessageTimeoutSeconds: z.number(),
91
- senderPrivateKey: schemas.SecretValue(schemas.Fr).optional(),
92
- senderSalt: schemas.Fr.optional(),
93
- tokenSalt: schemas.Fr,
94
- txIntervalSeconds: z.number(),
95
- privateTransfersPerTx: z.number().int().nonnegative(),
96
- publicTransfersPerTx: z.number().int().nonnegative(),
97
- feePaymentMethod: z.literal('fee_juice'),
98
- baseFeePadding: z.number().int().nonnegative(),
99
- noStart: z.boolean(),
100
- txMinedWaitSeconds: z.number(),
101
- followChain: z.enum(BotFollowChain),
102
- maxPendingTxs: z.number().int().nonnegative(),
103
- flushSetupTransactions: z.boolean(),
104
- l2GasLimit: z.number().int().nonnegative().optional(),
105
- daGasLimit: z.number().int().nonnegative().optional(),
106
- contract: z.nativeEnum(SupportedTokenContracts),
107
- maxConsecutiveErrors: z.number().int().nonnegative(),
108
- stopWhenUnhealthy: z.boolean(),
109
- ammTxs: z.boolean().default(false),
110
- dataDirectory: z.string().optional(),
111
- dataStoreMapSizeKb: z.number().optional(),
112
- })
113
- .transform(config => ({
114
- nodeUrl: undefined,
115
- nodeAdminUrl: undefined,
116
- l1RpcUrls: undefined,
117
- senderSalt: undefined,
118
- l2GasLimit: undefined,
119
- daGasLimit: undefined,
120
- l1Mnemonic: undefined,
121
- l1PrivateKey: undefined,
122
- senderPrivateKey: undefined,
123
- dataDirectory: undefined,
124
- dataStoreMapSizeKb: 1_024 * 1_024,
125
- ...config,
126
- })) satisfies ZodFor<BotConfig>;
91
+ export const BotConfigSchema = zodFor<BotConfig>()(
92
+ z
93
+ .object({
94
+ nodeUrl: z.string().optional(),
95
+ nodeAdminUrl: z.string().optional(),
96
+ l1RpcUrls: z.array(z.string()).optional(),
97
+ l1Mnemonic: schemas.SecretValue(z.string()).optional(),
98
+ l1PrivateKey: schemas.SecretValue(z.string()).optional(),
99
+ l1ToL2MessageTimeoutSeconds: z.number(),
100
+ senderPrivateKey: schemas.SecretValue(schemas.Fr).optional(),
101
+ senderSalt: schemas.Fr.optional(),
102
+ tokenSalt: schemas.Fr,
103
+ txIntervalSeconds: z.number(),
104
+ privateTransfersPerTx: z.number().int().nonnegative(),
105
+ publicTransfersPerTx: z.number().int().nonnegative(),
106
+ feePaymentMethod: z.literal('fee_juice'),
107
+ minFeePadding: z.number().nonnegative(),
108
+ noStart: z.boolean(),
109
+ txMinedWaitSeconds: z.number(),
110
+ followChain: z.enum(BotFollowChain),
111
+ maxPendingTxs: z.number().int().nonnegative(),
112
+ flushSetupTransactions: z.boolean(),
113
+ l2GasLimit: z.number().int().nonnegative().optional(),
114
+ daGasLimit: z.number().int().nonnegative().optional(),
115
+ contract: z.nativeEnum(SupportedTokenContracts),
116
+ maxConsecutiveErrors: z.number().int().nonnegative(),
117
+ stopWhenUnhealthy: z.boolean(),
118
+ botMode: z.enum(BotMode).default('transfer'),
119
+ l2ToL1MessagesPerTx: z.number().int().nonnegative().default(1),
120
+ l1ToL2SeedCount: z.number().int().nonnegative().default(1),
121
+ dataDirectory: z.string().optional(),
122
+ dataStoreMapSizeKb: z.number().optional(),
123
+ })
124
+ .transform(config => ({
125
+ nodeUrl: undefined,
126
+ nodeAdminUrl: undefined,
127
+ l1RpcUrls: undefined,
128
+ senderSalt: undefined,
129
+ l2GasLimit: undefined,
130
+ daGasLimit: undefined,
131
+ l1Mnemonic: undefined,
132
+ l1PrivateKey: undefined,
133
+ senderPrivateKey: undefined,
134
+ dataStoreMapSizeKb: 1_024 * 1_024,
135
+ ...config,
136
+ })),
137
+ );
127
138
 
128
139
  export const botConfigMappings: ConfigMappingsType<BotConfig> = {
129
140
  nodeUrl: {
@@ -191,10 +202,10 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
191
202
  parseEnv: val => (val as 'fee_juice') || undefined,
192
203
  defaultValue: 'fee_juice',
193
204
  },
194
- baseFeePadding: {
195
- env: 'BOT_BASE_FEE_PADDING',
205
+ minFeePadding: {
206
+ env: 'BOT_MIN_FEE_PADDING',
196
207
  description: 'How much is the bot willing to overpay vs. the current base fee',
197
- ...numberConfigHelper(3),
208
+ ...floatConfigHelper(3),
198
209
  },
199
210
  noStart: {
200
211
  env: 'BOT_NO_START',
@@ -211,10 +222,14 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
211
222
  description: 'Which chain the bot follows',
212
223
  defaultValue: 'NONE',
213
224
  parseEnv(val) {
214
- if (!(BotFollowChain as readonly string[]).includes(val.toUpperCase())) {
225
+ const upper = val.toUpperCase();
226
+ if (upper === 'PENDING') {
227
+ return 'CHECKPOINTED';
228
+ }
229
+ if (!(BotFollowChain as readonly string[]).includes(upper)) {
215
230
  throw new Error(`Invalid value for BOT_FOLLOW_CHAIN: ${val}`);
216
231
  }
217
- return val as BotFollowChain;
232
+ return upper as BotFollowChain;
218
233
  },
219
234
  },
220
235
  maxPendingTxs: {
@@ -229,12 +244,12 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
229
244
  },
230
245
  l2GasLimit: {
231
246
  env: 'BOT_L2_GAS_LIMIT',
232
- description: 'L2 gas limit for the tx (empty to have the bot trigger an estimate gas).',
247
+ description: "L2 gas limit for the tx (empty to let the bot's wallet estimate).",
233
248
  ...optionalNumberConfigHelper(),
234
249
  },
235
250
  daGasLimit: {
236
251
  env: 'BOT_DA_GAS_LIMIT',
237
- description: 'DA gas limit for the tx (empty to have the bot trigger an estimate gas).',
252
+ description: "DA gas limit for the tx (empty to let the bot's wallet estimate).",
238
253
  ...optionalNumberConfigHelper(),
239
254
  },
240
255
  contract: {
@@ -262,10 +277,26 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
262
277
  description: 'Stops the bot if service becomes unhealthy',
263
278
  ...booleanConfigHelper(false),
264
279
  },
265
- ammTxs: {
266
- env: 'BOT_AMM_TXS',
267
- description: 'Deploy an AMM and send swaps to it',
268
- ...booleanConfigHelper(false),
280
+ botMode: {
281
+ env: 'BOT_MODE',
282
+ description: 'Bot mode: transfer, amm, or crosschain',
283
+ defaultValue: 'transfer' as BotMode,
284
+ parseEnv(val: string) {
285
+ if (!(BotMode as readonly string[]).includes(val)) {
286
+ throw new Error(`Invalid value for BOT_MODE: ${val}`);
287
+ }
288
+ return val as BotMode;
289
+ },
290
+ },
291
+ l2ToL1MessagesPerTx: {
292
+ env: 'BOT_L2_TO_L1_MESSAGES_PER_TX',
293
+ description: 'Number of L2→L1 messages per tx (crosschain mode)',
294
+ ...numberConfigHelper(1),
295
+ },
296
+ l1ToL2SeedCount: {
297
+ env: 'BOT_L1_TO_L2_SEED_COUNT',
298
+ description: 'Max L1→L2 messages to keep in-flight (crosschain mode)',
299
+ ...numberConfigHelper(1),
269
300
  },
270
301
  ...pickConfigMappings(dataConfigMappings, ['dataStoreMapSizeKb', 'dataDirectory']),
271
302
  };
@@ -0,0 +1,208 @@
1
+ /**
2
+ * CrossChainBot exercises L2->L1 and L1->L2 messaging.
3
+ *
4
+ * createAndSendTx onTxMined
5
+ * ────────────────────────────────────── ──────────────────────────────
6
+ *
7
+ * 1. SEED (fire-and-forget) 3. VERIFY L2->L1
8
+ * if store has fewer pending messages Query getTxEffect, confirm
9
+ * than seedCount and no seed is the expected L2->L1 messages
10
+ * in-flight: appeared in tx effects.
11
+ * * kick off L1 inbox tx
12
+ * * store msg on completion
13
+ *
14
+ * 2. BUILD & SEND BATCH
15
+ * Always:
16
+ * N x create_l2_to_l1_message
17
+ * (random content, fixed
18
+ * L1 recipient)
19
+ * If a ready L1->L2 msg exists:
20
+ * 1 x consume_message_from_
21
+ * arbitrary_sender_public
22
+ * delete consumed msg from store
23
+ * Send batch tx (no wait)
24
+ *
25
+ */
26
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
27
+ import { BatchCall, NO_WAIT } from '@aztec/aztec.js/contracts';
28
+ import { isL1ToL2MessageReady } from '@aztec/aztec.js/messaging';
29
+ import type { TxHash, TxReceipt } from '@aztec/aztec.js/tx';
30
+ import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
31
+ import { Fr } from '@aztec/foundation/curves/bn254';
32
+ import { EthAddress } from '@aztec/foundation/eth-address';
33
+ import type { TestContract } from '@aztec/noir-test-contracts.js/Test';
34
+ import type { BlockTag } from '@aztec/stdlib/block';
35
+ import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
36
+ import type { EmbeddedWallet } from '@aztec/wallets/embedded';
37
+
38
+ import { BaseBot } from './base_bot.js';
39
+ import type { BotConfig } from './config.js';
40
+ import { BotFactory } from './factory.js';
41
+ import { seedL1ToL2Message } from './l1_to_l2_seeding.js';
42
+ import type { BotStore, PendingL1ToL2Message } from './store/index.js';
43
+
44
+ /** Stale message threshold: messages older than this are removed. */
45
+ const STALE_MESSAGE_THRESHOLD_MS = 2 * 60 * 60 * 1000; // 2 hours
46
+
47
+ /** Bot that exercises both L2→L1 and L1→L2 cross-chain messaging. */
48
+ export class CrossChainBot extends BaseBot {
49
+ private l2ToL1Sent = 0;
50
+ private l1ToL2Consumed = 0;
51
+ private pendingSeedPromise: Promise<void> | undefined;
52
+
53
+ protected constructor(
54
+ node: AztecNode,
55
+ wallet: EmbeddedWallet,
56
+ defaultAccountAddress: AztecAddress,
57
+ private readonly contract: TestContract,
58
+ private readonly l1Client: ExtendedViemWalletClient,
59
+ private readonly l1Recipient: EthAddress,
60
+ private readonly inboxAddress: EthAddress,
61
+ private readonly rollupVersion: bigint,
62
+ private readonly store: BotStore,
63
+ config: BotConfig,
64
+ private readonly syncChainTip?: BlockTag,
65
+ ) {
66
+ super(node, wallet, defaultAccountAddress, config);
67
+ }
68
+
69
+ static async create(
70
+ config: BotConfig,
71
+ wallet: EmbeddedWallet,
72
+ aztecNode: AztecNode,
73
+ aztecNodeAdmin: AztecNodeAdmin | undefined,
74
+ store: BotStore,
75
+ syncChainTip?: BlockTag,
76
+ ): Promise<CrossChainBot> {
77
+ if (config.followChain === 'NONE') {
78
+ throw new Error(`CrossChainBot requires followChain to be set (got NONE)`);
79
+ }
80
+ const factory = new BotFactory(config, wallet, store, aztecNode, aztecNodeAdmin, syncChainTip);
81
+ const { defaultAccountAddress, contract, l1Client, rollupVersion } = await factory.setupCrossChain();
82
+ const l1Recipient = EthAddress.fromString(l1Client.account!.address);
83
+ const { l1ContractAddresses } = await aztecNode.getNodeInfo();
84
+ const inboxAddress = EthAddress.fromString(l1ContractAddresses.inboxAddress.toString());
85
+ return new CrossChainBot(
86
+ aztecNode,
87
+ wallet,
88
+ defaultAccountAddress,
89
+ contract,
90
+ l1Client,
91
+ l1Recipient,
92
+ inboxAddress,
93
+ rollupVersion,
94
+ store,
95
+ config,
96
+ syncChainTip,
97
+ );
98
+ }
99
+
100
+ protected async createAndSendTx(logCtx: object): Promise<TxHash> {
101
+ const pendingMessages = await this.store.getUnconsumedL1ToL2Messages();
102
+
103
+ // Send an L1→L2 message if we're below the threshold and not already seeding one
104
+ if (pendingMessages.length < this.config.l1ToL2SeedCount && !this.pendingSeedPromise) {
105
+ this.pendingSeedPromise = this.seedNewL1ToL2Message()
106
+ .catch(err => this.log.warn(`Failed to seed L1→L2 message: ${err}`, logCtx))
107
+ .finally(() => {
108
+ this.pendingSeedPromise = undefined;
109
+ });
110
+ }
111
+
112
+ // Build batch: always L2→L1, optionally consume L1→L2
113
+ const calls = [];
114
+
115
+ // L2→L1: create messages with random content
116
+ for (let i = 0; i < this.config.l2ToL1MessagesPerTx; i++) {
117
+ calls.push(
118
+ this.contract.methods.create_l2_to_l1_message_arbitrary_recipient_public(Fr.random(), this.l1Recipient),
119
+ );
120
+ }
121
+
122
+ // L1→L2: consume oldest ready message if available
123
+ const readyMsg = await this.getReadyL1ToL2Message(pendingMessages);
124
+ if (readyMsg) {
125
+ calls.push(
126
+ this.contract.methods.consume_message_from_arbitrary_sender_public(
127
+ Fr.fromHexString(readyMsg.content),
128
+ Fr.fromHexString(readyMsg.secret),
129
+ EthAddress.fromString(readyMsg.sender),
130
+ new Fr(BigInt(readyMsg.globalLeafIndex)),
131
+ ),
132
+ );
133
+ // Delete consumed message immediately so it works with FOLLOW_CHAIN=NONE
134
+ await this.store.deleteL1ToL2Message(readyMsg.msgHash);
135
+ this.l1ToL2Consumed++;
136
+ } else {
137
+ this.log.warn(`No ready L1→L2 message to consume`, {
138
+ ...logCtx,
139
+ pendingCount: pendingMessages.length,
140
+ });
141
+ }
142
+
143
+ const batch = new BatchCall(this.wallet, calls);
144
+ const opts = this.getSendMethodOpts();
145
+
146
+ this.log.verbose(`Sending cross-chain batch with ${calls.length} calls`, logCtx);
147
+ const { txHash } = await batch.send({ ...opts, wait: NO_WAIT });
148
+ return txHash;
149
+ }
150
+
151
+ protected override async onTxMined(receipt: TxReceipt, logCtx: object): Promise<void> {
152
+ // Verify L2→L1 messages appeared in this tx's effects
153
+ const minedReceipt = await this.node.getTxReceipt(receipt.txHash, { includeTxEffect: true });
154
+ const l2ToL1MsgsRaw = minedReceipt.txEffect?.l2ToL1Msgs;
155
+ if (l2ToL1MsgsRaw) {
156
+ const l2ToL1Msgs = l2ToL1MsgsRaw.filter(m => !m.isZero());
157
+ if (l2ToL1Msgs.length >= this.config.l2ToL1MessagesPerTx) {
158
+ this.l2ToL1Sent += l2ToL1Msgs.length;
159
+ } else {
160
+ this.log.error(`Expected ${this.config.l2ToL1MessagesPerTx} L2→L1 messages but found ${l2ToL1Msgs.length}`, {
161
+ ...logCtx,
162
+ blockNumber: receipt.blockNumber,
163
+ txHash: receipt.txHash.toString(),
164
+ });
165
+ }
166
+ }
167
+
168
+ const pendingCount = (await this.store.getUnconsumedL1ToL2Messages()).length;
169
+ this.log.info(`CrossChainBot txs mined`, {
170
+ ...logCtx,
171
+ l2ToL1Sent: this.l2ToL1Sent,
172
+ l1ToL2Consumed: this.l1ToL2Consumed,
173
+ l1ToL2Pending: pendingCount,
174
+ });
175
+ }
176
+
177
+ /** Finds the oldest pending message that is ready for consumption. */
178
+ private async getReadyL1ToL2Message(
179
+ pendingMessages: PendingL1ToL2Message[],
180
+ ): Promise<PendingL1ToL2Message | undefined> {
181
+ const now = Date.now();
182
+ for (const msg of pendingMessages) {
183
+ const ready = await isL1ToL2MessageReady(this.node, Fr.fromHexString(msg.msgHash), this.syncChainTip);
184
+ if (ready) {
185
+ return msg;
186
+ }
187
+
188
+ // Time-based stale detection: if the message is old and still not ready, remove it
189
+ if (now - msg.timestamp > STALE_MESSAGE_THRESHOLD_MS) {
190
+ await this.store.deleteL1ToL2Message(msg.msgHash);
191
+ this.log.warn(`Removed stale L1→L2 message ${msg.msgHash}`);
192
+ }
193
+ }
194
+ return undefined;
195
+ }
196
+
197
+ /** Seeds a new L1→L2 message on L1 and stores it. */
198
+ private async seedNewL1ToL2Message(): Promise<void> {
199
+ await seedL1ToL2Message(
200
+ this.l1Client,
201
+ this.inboxAddress,
202
+ this.contract.address,
203
+ this.rollupVersion,
204
+ this.store,
205
+ this.log,
206
+ );
207
+ }
208
+ }