@aztec/bot 0.0.1-commit.08c5969dc → 0.0.1-commit.0c875d939
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/config.d.ts +24 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +28 -5
- package/dest/cross_chain_bot.d.ts +54 -0
- package/dest/cross_chain_bot.d.ts.map +1 -0
- package/dest/cross_chain_bot.js +140 -0
- package/dest/factory.d.ts +16 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +68 -0
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/l1_to_l2_seeding.d.ts +8 -0
- package/dest/l1_to_l2_seeding.d.ts.map +1 -0
- package/dest/l1_to_l2_seeding.js +63 -0
- package/dest/runner.d.ts +1 -1
- package/dest/runner.d.ts.map +1 -1
- package/dest/runner.js +17 -1
- package/dest/store/bot_store.d.ts +30 -5
- package/dest/store/bot_store.d.ts.map +1 -1
- package/dest/store/bot_store.js +37 -6
- package/dest/store/index.d.ts +2 -2
- package/dest/store/index.d.ts.map +1 -1
- package/package.json +16 -13
- package/src/config.ts +32 -7
- package/src/cross_chain_bot.ts +209 -0
- package/src/factory.ts +94 -1
- package/src/index.ts +1 -0
- package/src/l1_to_l2_seeding.ts +79 -0
- package/src/runner.ts +16 -3
- package/src/store/bot_store.ts +60 -5
- package/src/store/index.ts +1 -1
package/dest/runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,SAAS,EAAE,KAAK,MAAM,EAAa,MAAM,yBAAyB,CAAC;AAC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C1C,KAAK,EAAE,QAAQ,EAKjC;IAED,6EAA6E;IAChE,KAAK,kBAIjB;YAGa,OAAO;IAMrB;;;OAGG;IACU,KAAK,kBAMjB;IAED;;OAEG;IACU,IAAI,kBAOhB;IAEM,SAAS,YAEf;IAED,0CAA0C;IACnC,SAAS,YAEf;IAED;;;OAGG;IACU,MAAM,CAAC,MAAM,EAAE,SAAS,iBAapC;IAED;;;OAGG;IACU,GAAG,kBAsBf;IAED,qDAAqD;IAC9C,SAAS,uBAGf;IAED,sCAAsC;IACzB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAMvC;CAmDF"}
|
package/dest/runner.js
CHANGED
|
@@ -377,6 +377,7 @@ import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
|
377
377
|
import { trackSpan } from '@aztec/telemetry-client';
|
|
378
378
|
import { AmmBot } from './amm_bot.js';
|
|
379
379
|
import { Bot } from './bot.js';
|
|
380
|
+
import { CrossChainBot } from './cross_chain_bot.js';
|
|
380
381
|
_dec = trackSpan('Bot.setup'), _dec1 = trackSpan('Bot.work');
|
|
381
382
|
export class BotRunner {
|
|
382
383
|
config;
|
|
@@ -535,7 +536,22 @@ export class BotRunner {
|
|
|
535
536
|
}
|
|
536
537
|
async #createBot() {
|
|
537
538
|
try {
|
|
538
|
-
|
|
539
|
+
switch(this.config.botMode){
|
|
540
|
+
case 'crosschain':
|
|
541
|
+
this.bot = CrossChainBot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
|
|
542
|
+
break;
|
|
543
|
+
case 'amm':
|
|
544
|
+
this.bot = AmmBot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
|
|
545
|
+
break;
|
|
546
|
+
case 'transfer':
|
|
547
|
+
this.bot = Bot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
|
|
548
|
+
break;
|
|
549
|
+
default:
|
|
550
|
+
{
|
|
551
|
+
const _exhaustive = this.config.botMode;
|
|
552
|
+
throw new Error(`Unsupported bot mode: [${_exhaustive}]`);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
539
555
|
await this.bot;
|
|
540
556
|
} catch (err) {
|
|
541
557
|
this.log.error(`Error setting up bot: ${err}`);
|
|
@@ -1,21 +1,40 @@
|
|
|
1
1
|
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
2
|
import type { L2AmountClaim } from '@aztec/aztec.js/ethereum';
|
|
3
3
|
import { type Logger } from '@aztec/foundation/log';
|
|
4
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
4
5
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
5
6
|
export interface BridgeClaimData {
|
|
6
7
|
claim: L2AmountClaim;
|
|
7
8
|
timestamp: number;
|
|
8
9
|
recipient: string;
|
|
9
10
|
}
|
|
11
|
+
export interface PendingL1ToL2Message {
|
|
12
|
+
/** Random content field sent in the message. */
|
|
13
|
+
content: string;
|
|
14
|
+
/** Secret for consuming the message. */
|
|
15
|
+
secret: string;
|
|
16
|
+
/** Hash of the secret. */
|
|
17
|
+
secretHash: string;
|
|
18
|
+
/** Hash of the L1→L2 message. */
|
|
19
|
+
msgHash: string;
|
|
20
|
+
/** L1 sender address (hex). */
|
|
21
|
+
sender: string;
|
|
22
|
+
/** Global leaf index in the L1→L2 message tree. */
|
|
23
|
+
globalLeafIndex: string;
|
|
24
|
+
/** Timestamp when the message was seeded. */
|
|
25
|
+
timestamp: number;
|
|
26
|
+
}
|
|
10
27
|
/**
|
|
11
28
|
* Simple data store for the bot to persist L1 bridge claims.
|
|
12
29
|
*/
|
|
13
30
|
export declare class BotStore {
|
|
14
31
|
private readonly store;
|
|
15
32
|
private readonly log;
|
|
33
|
+
private readonly dateProvider;
|
|
16
34
|
static readonly SCHEMA_VERSION = 1;
|
|
17
35
|
private readonly bridgeClaims;
|
|
18
|
-
|
|
36
|
+
private readonly pendingL1ToL2;
|
|
37
|
+
constructor(store: AztecAsyncKVStore, log?: Logger, dateProvider?: DateProvider);
|
|
19
38
|
/**
|
|
20
39
|
* Saves a bridge claim for a recipient.
|
|
21
40
|
*/
|
|
@@ -36,9 +55,15 @@ export declare class BotStore {
|
|
|
36
55
|
* Cleans up old bridge claims (older than 24 hours).
|
|
37
56
|
*/
|
|
38
57
|
cleanupOldClaims(maxAgeMs?: number): Promise<number>;
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
|
|
58
|
+
/** Saves a pending L1→L2 message keyed by msgHash. */
|
|
59
|
+
savePendingL1ToL2Message(msg: PendingL1ToL2Message): Promise<void>;
|
|
60
|
+
/** Returns all unconsumed pending L1→L2 messages. */
|
|
61
|
+
getUnconsumedL1ToL2Messages(): Promise<PendingL1ToL2Message[]>;
|
|
62
|
+
/** Deletes a consumed L1→L2 message from the store. */
|
|
63
|
+
deleteL1ToL2Message(msgHash: string): Promise<void>;
|
|
64
|
+
/** Cleans up pending L1→L2 messages older than maxAgeMs. */
|
|
65
|
+
cleanupOldPendingMessages(maxAgeMs?: number): Promise<number>;
|
|
66
|
+
/** Closes the store. */
|
|
42
67
|
close(): Promise<void>;
|
|
43
68
|
}
|
|
44
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
69
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYm90X3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3RvcmUvYm90X3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQUN6RCxPQUFPLEtBQUssRUFBRSxhQUFhLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUU5RCxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFDbEUsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLHlCQUF5QixDQUFDO0F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@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
3
4
|
/**
|
|
4
5
|
* Simple data store for the bot to persist L1 bridge claims.
|
|
5
6
|
*/ export class BotStore {
|
|
6
7
|
store;
|
|
7
8
|
log;
|
|
9
|
+
dateProvider;
|
|
8
10
|
static SCHEMA_VERSION = 1;
|
|
9
11
|
bridgeClaims;
|
|
10
|
-
|
|
12
|
+
pendingL1ToL2;
|
|
13
|
+
constructor(store, log = createLogger('bot:store'), dateProvider = new DateProvider()){
|
|
11
14
|
this.store = store;
|
|
12
15
|
this.log = log;
|
|
16
|
+
this.dateProvider = dateProvider;
|
|
13
17
|
this.bridgeClaims = store.openMap('bridge_claims');
|
|
18
|
+
this.pendingL1ToL2 = store.openMap('pending_l1_to_l2');
|
|
14
19
|
}
|
|
15
20
|
/**
|
|
16
21
|
* Saves a bridge claim for a recipient.
|
|
@@ -25,7 +30,7 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
25
30
|
};
|
|
26
31
|
const data = {
|
|
27
32
|
claim: serializableClaim,
|
|
28
|
-
timestamp:
|
|
33
|
+
timestamp: this.dateProvider.now(),
|
|
29
34
|
recipient: recipient.toString()
|
|
30
35
|
};
|
|
31
36
|
await this.bridgeClaims.set(recipient.toString(), JSON.stringify(data));
|
|
@@ -85,7 +90,7 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
85
90
|
/**
|
|
86
91
|
* Cleans up old bridge claims (older than 24 hours).
|
|
87
92
|
*/ async cleanupOldClaims(maxAgeMs = 24 * 60 * 60 * 1000) {
|
|
88
|
-
const now =
|
|
93
|
+
const now = this.dateProvider.now();
|
|
89
94
|
let cleanedCount = 0;
|
|
90
95
|
const entries = this.bridgeClaims.entriesAsync();
|
|
91
96
|
for await (const [key, data] of entries){
|
|
@@ -98,9 +103,35 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
98
103
|
}
|
|
99
104
|
return cleanedCount;
|
|
100
105
|
}
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
|
|
106
|
+
/** Saves a pending L1→L2 message keyed by msgHash. */ async savePendingL1ToL2Message(msg) {
|
|
107
|
+
await this.pendingL1ToL2.set(msg.msgHash, JSON.stringify(msg));
|
|
108
|
+
this.log.info(`Saved pending L1→L2 message ${msg.msgHash}`);
|
|
109
|
+
}
|
|
110
|
+
/** Returns all unconsumed pending L1→L2 messages. */ async getUnconsumedL1ToL2Messages() {
|
|
111
|
+
const messages = [];
|
|
112
|
+
for await (const [_, data] of this.pendingL1ToL2.entriesAsync()){
|
|
113
|
+
messages.push(JSON.parse(data));
|
|
114
|
+
}
|
|
115
|
+
return messages;
|
|
116
|
+
}
|
|
117
|
+
/** Deletes a consumed L1→L2 message from the store. */ async deleteL1ToL2Message(msgHash) {
|
|
118
|
+
await this.pendingL1ToL2.delete(msgHash);
|
|
119
|
+
this.log.info(`Deleted consumed L1→L2 message ${msgHash}`);
|
|
120
|
+
}
|
|
121
|
+
/** Cleans up pending L1→L2 messages older than maxAgeMs. */ async cleanupOldPendingMessages(maxAgeMs = 24 * 60 * 60 * 1000) {
|
|
122
|
+
const now = this.dateProvider.now();
|
|
123
|
+
let cleanedCount = 0;
|
|
124
|
+
for await (const [key, data] of this.pendingL1ToL2.entriesAsync()){
|
|
125
|
+
const parsed = JSON.parse(data);
|
|
126
|
+
if (now - parsed.timestamp > maxAgeMs) {
|
|
127
|
+
await this.pendingL1ToL2.delete(key);
|
|
128
|
+
cleanedCount++;
|
|
129
|
+
this.log.info(`Cleaned up old pending L1→L2 message ${key}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return cleanedCount;
|
|
133
|
+
}
|
|
134
|
+
/** Closes the store. */ async close() {
|
|
104
135
|
await this.store.close();
|
|
105
136
|
this.log.info('Closed bot data store');
|
|
106
137
|
}
|
package/dest/store/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { BotStore, type BridgeClaimData } from './bot_store.js';
|
|
2
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
1
|
+
export { BotStore, type BridgeClaimData, type PendingL1ToL2Message } from './bot_store.js';
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yZS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsUUFBUSxFQUFFLEtBQUssZUFBZSxFQUFFLEtBQUssb0JBQW9CLEVBQUUsTUFBTSxnQkFBZ0IsQ0FBQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,KAAK,oBAAoB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/bot",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.0c875d939",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -54,20 +54,23 @@
|
|
|
54
54
|
]
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@aztec/accounts": "0.0.1-commit.
|
|
58
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
59
|
-
"@aztec/entrypoints": "0.0.1-commit.
|
|
60
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
61
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
62
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
63
|
-
"@aztec/
|
|
64
|
-
"@aztec/noir-
|
|
65
|
-
"@aztec/protocol-
|
|
66
|
-
"@aztec/
|
|
67
|
-
"@aztec/
|
|
68
|
-
"@aztec/
|
|
57
|
+
"@aztec/accounts": "0.0.1-commit.0c875d939",
|
|
58
|
+
"@aztec/aztec.js": "0.0.1-commit.0c875d939",
|
|
59
|
+
"@aztec/entrypoints": "0.0.1-commit.0c875d939",
|
|
60
|
+
"@aztec/ethereum": "0.0.1-commit.0c875d939",
|
|
61
|
+
"@aztec/foundation": "0.0.1-commit.0c875d939",
|
|
62
|
+
"@aztec/kv-store": "0.0.1-commit.0c875d939",
|
|
63
|
+
"@aztec/l1-artifacts": "0.0.1-commit.0c875d939",
|
|
64
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.0c875d939",
|
|
65
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.0c875d939",
|
|
66
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.0c875d939",
|
|
67
|
+
"@aztec/protocol-contracts": "0.0.1-commit.0c875d939",
|
|
68
|
+
"@aztec/stdlib": "0.0.1-commit.0c875d939",
|
|
69
|
+
"@aztec/telemetry-client": "0.0.1-commit.0c875d939",
|
|
70
|
+
"@aztec/wallets": "0.0.1-commit.0c875d939",
|
|
69
71
|
"source-map-support": "^0.5.21",
|
|
70
72
|
"tslib": "^2.4.0",
|
|
73
|
+
"viem": "npm:@aztec/viem@2.38.2",
|
|
71
74
|
"zod": "^3.23.8"
|
|
72
75
|
},
|
|
73
76
|
"devDependencies": {
|
package/src/config.ts
CHANGED
|
@@ -22,6 +22,9 @@ import { z } from 'zod';
|
|
|
22
22
|
const BotFollowChain = ['NONE', 'PROPOSED', 'CHECKPOINTED', 'PROVEN'] as const;
|
|
23
23
|
type BotFollowChain = (typeof BotFollowChain)[number];
|
|
24
24
|
|
|
25
|
+
const BotMode = ['transfer', 'amm', 'crosschain'] as const;
|
|
26
|
+
type BotMode = (typeof BotMode)[number];
|
|
27
|
+
|
|
25
28
|
export enum SupportedTokenContracts {
|
|
26
29
|
TokenContract = 'TokenContract',
|
|
27
30
|
PrivateTokenContract = 'PrivateTokenContract',
|
|
@@ -76,8 +79,12 @@ export type BotConfig = {
|
|
|
76
79
|
maxConsecutiveErrors: number;
|
|
77
80
|
/** Stops the bot if service becomes unhealthy */
|
|
78
81
|
stopWhenUnhealthy: boolean;
|
|
79
|
-
/**
|
|
80
|
-
|
|
82
|
+
/** Bot mode: transfer, amm, or crosschain. */
|
|
83
|
+
botMode: BotMode;
|
|
84
|
+
/** Number of L2→L1 messages per tx (crosschain mode). */
|
|
85
|
+
l2ToL1MessagesPerTx: number;
|
|
86
|
+
/** Max L1→L2 messages to keep in-flight (crosschain mode). */
|
|
87
|
+
l1ToL2SeedCount: number;
|
|
81
88
|
} & Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb'>;
|
|
82
89
|
|
|
83
90
|
export const BotConfigSchema = zodFor<BotConfig>()(
|
|
@@ -107,7 +114,9 @@ export const BotConfigSchema = zodFor<BotConfig>()(
|
|
|
107
114
|
contract: z.nativeEnum(SupportedTokenContracts),
|
|
108
115
|
maxConsecutiveErrors: z.number().int().nonnegative(),
|
|
109
116
|
stopWhenUnhealthy: z.boolean(),
|
|
110
|
-
|
|
117
|
+
botMode: z.enum(BotMode).default('transfer'),
|
|
118
|
+
l2ToL1MessagesPerTx: z.number().int().nonnegative().default(1),
|
|
119
|
+
l1ToL2SeedCount: z.number().int().nonnegative().default(1),
|
|
111
120
|
dataDirectory: z.string().optional(),
|
|
112
121
|
dataStoreMapSizeKb: z.number().optional(),
|
|
113
122
|
})
|
|
@@ -268,10 +277,26 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
|
|
|
268
277
|
description: 'Stops the bot if service becomes unhealthy',
|
|
269
278
|
...booleanConfigHelper(false),
|
|
270
279
|
},
|
|
271
|
-
|
|
272
|
-
env: '
|
|
273
|
-
description: '
|
|
274
|
-
|
|
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),
|
|
275
300
|
},
|
|
276
301
|
...pickConfigMappings(dataConfigMappings, ['dataStoreMapSizeKb', 'dataDirectory']),
|
|
277
302
|
};
|
|
@@ -0,0 +1,209 @@
|
|
|
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 { 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 { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
35
|
+
import type { EmbeddedWallet } from '@aztec/wallets/embedded';
|
|
36
|
+
|
|
37
|
+
import { BaseBot } from './base_bot.js';
|
|
38
|
+
import type { BotConfig } from './config.js';
|
|
39
|
+
import { BotFactory } from './factory.js';
|
|
40
|
+
import { seedL1ToL2Message } from './l1_to_l2_seeding.js';
|
|
41
|
+
import type { BotStore, PendingL1ToL2Message } from './store/index.js';
|
|
42
|
+
|
|
43
|
+
/** Stale message threshold: messages older than this are removed. */
|
|
44
|
+
const STALE_MESSAGE_THRESHOLD_MS = 2 * 60 * 60 * 1000; // 2 hours
|
|
45
|
+
|
|
46
|
+
/** Bot that exercises both L2→L1 and L1→L2 cross-chain messaging. */
|
|
47
|
+
export class CrossChainBot extends BaseBot {
|
|
48
|
+
private l2ToL1Sent = 0;
|
|
49
|
+
private l1ToL2Consumed = 0;
|
|
50
|
+
private pendingSeedPromise: Promise<void> | undefined;
|
|
51
|
+
|
|
52
|
+
protected constructor(
|
|
53
|
+
node: AztecNode,
|
|
54
|
+
wallet: EmbeddedWallet,
|
|
55
|
+
defaultAccountAddress: AztecAddress,
|
|
56
|
+
private readonly contract: TestContract,
|
|
57
|
+
private readonly l1Client: ExtendedViemWalletClient,
|
|
58
|
+
private readonly l1Recipient: EthAddress,
|
|
59
|
+
private readonly inboxAddress: EthAddress,
|
|
60
|
+
private readonly rollupVersion: bigint,
|
|
61
|
+
private readonly store: BotStore,
|
|
62
|
+
config: BotConfig,
|
|
63
|
+
) {
|
|
64
|
+
super(node, wallet, defaultAccountAddress, config);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static async create(
|
|
68
|
+
config: BotConfig,
|
|
69
|
+
wallet: EmbeddedWallet,
|
|
70
|
+
aztecNode: AztecNode,
|
|
71
|
+
aztecNodeAdmin: AztecNodeAdmin | undefined,
|
|
72
|
+
store: BotStore,
|
|
73
|
+
): Promise<CrossChainBot> {
|
|
74
|
+
if (config.followChain === 'NONE') {
|
|
75
|
+
throw new Error(`CrossChainBot requires followChain to be set (got NONE)`);
|
|
76
|
+
}
|
|
77
|
+
const factory = new BotFactory(config, wallet, store, aztecNode, aztecNodeAdmin);
|
|
78
|
+
const { defaultAccountAddress, contract, l1Client, rollupVersion } = await factory.setupCrossChain();
|
|
79
|
+
const l1Recipient = EthAddress.fromString(l1Client.account!.address);
|
|
80
|
+
const { l1ContractAddresses } = await aztecNode.getNodeInfo();
|
|
81
|
+
const inboxAddress = EthAddress.fromString(l1ContractAddresses.inboxAddress.toString());
|
|
82
|
+
return new CrossChainBot(
|
|
83
|
+
aztecNode,
|
|
84
|
+
wallet,
|
|
85
|
+
defaultAccountAddress,
|
|
86
|
+
contract,
|
|
87
|
+
l1Client,
|
|
88
|
+
l1Recipient,
|
|
89
|
+
inboxAddress,
|
|
90
|
+
rollupVersion,
|
|
91
|
+
store,
|
|
92
|
+
config,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
protected async createAndSendTx(logCtx: object): Promise<TxHash> {
|
|
97
|
+
const pendingMessages = await this.store.getUnconsumedL1ToL2Messages();
|
|
98
|
+
|
|
99
|
+
// Send an L1→L2 message if we're below the threshold and not already seeding one
|
|
100
|
+
if (pendingMessages.length < this.config.l1ToL2SeedCount && !this.pendingSeedPromise) {
|
|
101
|
+
this.pendingSeedPromise = this.seedNewL1ToL2Message()
|
|
102
|
+
.catch(err => this.log.warn(`Failed to seed L1→L2 message: ${err}`, logCtx))
|
|
103
|
+
.finally(() => {
|
|
104
|
+
this.pendingSeedPromise = undefined;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Build batch: always L2→L1, optionally consume L1→L2
|
|
109
|
+
const calls = [];
|
|
110
|
+
|
|
111
|
+
// L2→L1: create messages with random content
|
|
112
|
+
for (let i = 0; i < this.config.l2ToL1MessagesPerTx; i++) {
|
|
113
|
+
calls.push(
|
|
114
|
+
this.contract.methods.create_l2_to_l1_message_arbitrary_recipient_public(Fr.random(), this.l1Recipient),
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// L1→L2: consume oldest ready message if available
|
|
119
|
+
const readyMsg = await this.getReadyL1ToL2Message(pendingMessages);
|
|
120
|
+
if (readyMsg) {
|
|
121
|
+
calls.push(
|
|
122
|
+
this.contract.methods.consume_message_from_arbitrary_sender_public(
|
|
123
|
+
Fr.fromHexString(readyMsg.content),
|
|
124
|
+
Fr.fromHexString(readyMsg.secret),
|
|
125
|
+
EthAddress.fromString(readyMsg.sender),
|
|
126
|
+
new Fr(BigInt(readyMsg.globalLeafIndex)),
|
|
127
|
+
),
|
|
128
|
+
);
|
|
129
|
+
// Delete consumed message immediately so it works with FOLLOW_CHAIN=NONE
|
|
130
|
+
await this.store.deleteL1ToL2Message(readyMsg.msgHash);
|
|
131
|
+
this.l1ToL2Consumed++;
|
|
132
|
+
} else {
|
|
133
|
+
this.log.warn(`No ready L1→L2 message to consume`, {
|
|
134
|
+
...logCtx,
|
|
135
|
+
pendingCount: pendingMessages.length,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const batch = new BatchCall(this.wallet, calls);
|
|
140
|
+
const opts = await this.getSendMethodOpts(batch);
|
|
141
|
+
|
|
142
|
+
this.log.verbose(`Sending cross-chain batch with ${calls.length} calls`, logCtx);
|
|
143
|
+
return batch.send({ ...opts, wait: NO_WAIT });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
protected override async onTxMined(receipt: TxReceipt, logCtx: object): Promise<void> {
|
|
147
|
+
// Verify L2→L1 messages appeared in this tx's effects
|
|
148
|
+
const indexed = await this.node.getTxEffect(receipt.txHash);
|
|
149
|
+
if (indexed) {
|
|
150
|
+
const l2ToL1Msgs = indexed.data.l2ToL1Msgs.filter(m => !m.isZero());
|
|
151
|
+
if (l2ToL1Msgs.length >= this.config.l2ToL1MessagesPerTx) {
|
|
152
|
+
this.l2ToL1Sent += l2ToL1Msgs.length;
|
|
153
|
+
} else {
|
|
154
|
+
this.log.error(`Expected ${this.config.l2ToL1MessagesPerTx} L2→L1 messages but found ${l2ToL1Msgs.length}`, {
|
|
155
|
+
...logCtx,
|
|
156
|
+
blockNumber: receipt.blockNumber,
|
|
157
|
+
txHash: receipt.txHash.toString(),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const pendingCount = (await this.store.getUnconsumedL1ToL2Messages()).length;
|
|
163
|
+
this.log.info(`CrossChainBot txs mined`, {
|
|
164
|
+
...logCtx,
|
|
165
|
+
l2ToL1Sent: this.l2ToL1Sent,
|
|
166
|
+
l1ToL2Consumed: this.l1ToL2Consumed,
|
|
167
|
+
l1ToL2Pending: pendingCount,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Finds the oldest pending message that is ready for consumption. */
|
|
172
|
+
private async getReadyL1ToL2Message(
|
|
173
|
+
pendingMessages: PendingL1ToL2Message[],
|
|
174
|
+
): Promise<PendingL1ToL2Message | undefined> {
|
|
175
|
+
const now = Date.now();
|
|
176
|
+
for (const msg of pendingMessages) {
|
|
177
|
+
const ready = await isL1ToL2MessageReady(this.node, Fr.fromHexString(msg.msgHash), {
|
|
178
|
+
// Use forPublicConsumption: false so we wait until blockNumber >= messageBlockNumber.
|
|
179
|
+
// With forPublicConsumption: true, the check returns true one block early (the sequencer
|
|
180
|
+
// includes L1→L2 messages before executing the block's txs), but gas estimation simulates
|
|
181
|
+
// against the current world state which doesn't yet have the message.
|
|
182
|
+
// See https://linear.app/aztec-labs/issue/A-548 for details.
|
|
183
|
+
forPublicConsumption: false,
|
|
184
|
+
});
|
|
185
|
+
if (ready) {
|
|
186
|
+
return msg;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Time-based stale detection: if the message is old and still not ready, remove it
|
|
190
|
+
if (now - msg.timestamp > STALE_MESSAGE_THRESHOLD_MS) {
|
|
191
|
+
await this.store.deleteL1ToL2Message(msg.msgHash);
|
|
192
|
+
this.log.warn(`Removed stale L1→L2 message ${msg.msgHash}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Seeds a new L1→L2 message on L1 and stores it. */
|
|
199
|
+
private async seedNewL1ToL2Message(): Promise<void> {
|
|
200
|
+
await seedL1ToL2Message(
|
|
201
|
+
this.l1Client,
|
|
202
|
+
this.inboxAddress,
|
|
203
|
+
this.contract.address,
|
|
204
|
+
this.rollupVersion,
|
|
205
|
+
this.store,
|
|
206
|
+
this.log,
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
}
|
package/src/factory.ts
CHANGED
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
type DeployOptions,
|
|
9
9
|
NO_WAIT,
|
|
10
10
|
} from '@aztec/aztec.js/contracts';
|
|
11
|
-
import { L1FeeJuicePortalManager } from '@aztec/aztec.js/ethereum';
|
|
12
11
|
import type { L2AmountClaim } from '@aztec/aztec.js/ethereum';
|
|
12
|
+
import { L1FeeJuicePortalManager } from '@aztec/aztec.js/ethereum';
|
|
13
13
|
import { FeeJuicePaymentMethodWithClaim } from '@aztec/aztec.js/fee';
|
|
14
14
|
import { deriveKeys } from '@aztec/aztec.js/keys';
|
|
15
15
|
import { createLogger } from '@aztec/aztec.js/log';
|
|
@@ -17,11 +17,15 @@ import { waitForL1ToL2MessageReady } from '@aztec/aztec.js/messaging';
|
|
|
17
17
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
18
18
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
19
19
|
import { createExtendedL1Client } from '@aztec/ethereum/client';
|
|
20
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
21
|
+
import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
|
|
20
22
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
23
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
21
24
|
import { Timer } from '@aztec/foundation/timer';
|
|
22
25
|
import { AMMContract } from '@aztec/noir-contracts.js/AMM';
|
|
23
26
|
import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
|
|
24
27
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
28
|
+
import { TestContract } from '@aztec/noir-test-contracts.js/Test';
|
|
25
29
|
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
26
30
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
27
31
|
import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
@@ -29,6 +33,7 @@ import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
|
29
33
|
import { EmbeddedWallet } from '@aztec/wallets/embedded';
|
|
30
34
|
|
|
31
35
|
import { type BotConfig, SupportedTokenContracts } from './config.js';
|
|
36
|
+
import { seedL1ToL2Message } from './l1_to_l2_seeding.js';
|
|
32
37
|
import type { BotStore } from './store/index.js';
|
|
33
38
|
import { getBalances, getPrivateBalance, isStandardTokenContract } from './utils.js';
|
|
34
39
|
|
|
@@ -95,6 +100,94 @@ export class BotFactory {
|
|
|
95
100
|
return { wallet: this.wallet, defaultAccountAddress, amm, token0, token1, node: this.aztecNode };
|
|
96
101
|
}
|
|
97
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Initializes the cross-chain bot by deploying TestContract, creating an L1 client,
|
|
105
|
+
* seeding initial L1→L2 messages, and waiting for the first to be ready.
|
|
106
|
+
*/
|
|
107
|
+
public async setupCrossChain(): Promise<{
|
|
108
|
+
wallet: EmbeddedWallet;
|
|
109
|
+
defaultAccountAddress: AztecAddress;
|
|
110
|
+
contract: TestContract;
|
|
111
|
+
node: AztecNode;
|
|
112
|
+
l1Client: ExtendedViemWalletClient;
|
|
113
|
+
rollupVersion: bigint;
|
|
114
|
+
}> {
|
|
115
|
+
const defaultAccountAddress = await this.setupAccount();
|
|
116
|
+
|
|
117
|
+
// Create L1 client (same pattern as bridgeL1FeeJuice)
|
|
118
|
+
const l1RpcUrls = this.config.l1RpcUrls;
|
|
119
|
+
if (!l1RpcUrls?.length) {
|
|
120
|
+
throw new Error('L1 RPC URLs required for cross-chain bot');
|
|
121
|
+
}
|
|
122
|
+
const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
|
|
123
|
+
if (!mnemonicOrPrivateKey) {
|
|
124
|
+
throw new Error('L1 mnemonic or private key required for cross-chain bot');
|
|
125
|
+
}
|
|
126
|
+
const { l1ChainId, l1ContractAddresses } = await this.aztecNode.getNodeInfo();
|
|
127
|
+
const chain = createEthereumChain(l1RpcUrls, l1ChainId);
|
|
128
|
+
const l1Client = createExtendedL1Client(chain.rpcUrls, mnemonicOrPrivateKey, chain.chainInfo);
|
|
129
|
+
|
|
130
|
+
// Fetch Rollup version (needed for Inbox L2Actor struct)
|
|
131
|
+
const rollupContract = new RollupContract(l1Client, l1ContractAddresses.rollupAddress.toString());
|
|
132
|
+
const rollupVersion = await rollupContract.getVersion();
|
|
133
|
+
|
|
134
|
+
// Deploy TestContract
|
|
135
|
+
const contract = await this.setupTestContract(defaultAccountAddress);
|
|
136
|
+
|
|
137
|
+
// Recover any pending messages from store (clean up stale ones first)
|
|
138
|
+
await this.store.cleanupOldPendingMessages();
|
|
139
|
+
const pendingMessages = await this.store.getUnconsumedL1ToL2Messages();
|
|
140
|
+
|
|
141
|
+
// Seed initial L1→L2 messages if pipeline is empty
|
|
142
|
+
const seedCount = Math.max(0, this.config.l1ToL2SeedCount - pendingMessages.length);
|
|
143
|
+
for (let i = 0; i < seedCount; i++) {
|
|
144
|
+
await seedL1ToL2Message(
|
|
145
|
+
l1Client,
|
|
146
|
+
EthAddress.fromString(l1ContractAddresses.inboxAddress.toString()),
|
|
147
|
+
contract.address,
|
|
148
|
+
rollupVersion,
|
|
149
|
+
this.store,
|
|
150
|
+
this.log,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Block until at least one message is ready
|
|
155
|
+
const allMessages = await this.store.getUnconsumedL1ToL2Messages();
|
|
156
|
+
if (allMessages.length > 0) {
|
|
157
|
+
this.log.info(`Waiting for first L1→L2 message to be ready...`);
|
|
158
|
+
const firstMsg = allMessages[0];
|
|
159
|
+
await waitForL1ToL2MessageReady(this.aztecNode, Fr.fromHexString(firstMsg.msgHash), {
|
|
160
|
+
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds,
|
|
161
|
+
// Use forPublicConsumption: false so we wait until the message is in the current world
|
|
162
|
+
// state. With true, it returns one block early which causes gas estimation simulation to
|
|
163
|
+
// fail since it runs against the current state.
|
|
164
|
+
// See https://linear.app/aztec-labs/issue/A-548 for details.
|
|
165
|
+
forPublicConsumption: false,
|
|
166
|
+
});
|
|
167
|
+
this.log.info(`First L1→L2 message is ready`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
wallet: this.wallet,
|
|
172
|
+
defaultAccountAddress,
|
|
173
|
+
contract,
|
|
174
|
+
node: this.aztecNode,
|
|
175
|
+
l1Client,
|
|
176
|
+
rollupVersion,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private async setupTestContract(deployer: AztecAddress): Promise<TestContract> {
|
|
181
|
+
const deployOpts: DeployOptions = {
|
|
182
|
+
from: deployer,
|
|
183
|
+
contractAddressSalt: this.config.tokenSalt,
|
|
184
|
+
universalDeploy: true,
|
|
185
|
+
};
|
|
186
|
+
const deploy = TestContract.deploy(this.wallet);
|
|
187
|
+
const instance = await this.registerOrDeployContract('TestContract', deploy, deployOpts);
|
|
188
|
+
return TestContract.at(instance.address, this.wallet);
|
|
189
|
+
}
|
|
190
|
+
|
|
98
191
|
/**
|
|
99
192
|
* Checks if the sender account contract is initialized, and initializes it if necessary.
|
|
100
193
|
* @returns The sender wallet.
|