@aztec/bot 0.0.1-commit.858058eac → 0.0.1-commit.85d7d01
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/base_bot.d.ts +1 -1
- package/dest/base_bot.d.ts.map +1 -1
- package/dest/base_bot.js +9 -10
- package/dest/bot.js +2 -2
- package/dest/config.d.ts +30 -14
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +36 -8
- 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 +77 -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/base_bot.ts +6 -16
- package/src/bot.ts +2 -2
- package/src/config.ts +39 -10
- package/src/cross_chain_bot.ts +209 -0
- package/src/factory.ts +99 -2
- 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/factory.js
CHANGED
|
@@ -9,14 +9,18 @@ import { waitForL1ToL2MessageReady } from '@aztec/aztec.js/messaging';
|
|
|
9
9
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
10
10
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
11
11
|
import { createExtendedL1Client } from '@aztec/ethereum/client';
|
|
12
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
12
13
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
14
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
13
15
|
import { Timer } from '@aztec/foundation/timer';
|
|
14
16
|
import { AMMContract } from '@aztec/noir-contracts.js/AMM';
|
|
15
17
|
import { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
|
|
16
18
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
19
|
+
import { TestContract } from '@aztec/noir-test-contracts.js/Test';
|
|
17
20
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
18
21
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
19
22
|
import { SupportedTokenContracts } from './config.js';
|
|
23
|
+
import { seedL1ToL2Message } from './l1_to_l2_seeding.js';
|
|
20
24
|
import { getBalances, getPrivateBalance, isStandardTokenContract } from './utils.js';
|
|
21
25
|
const MINT_BALANCE = 1e12;
|
|
22
26
|
const MIN_BALANCE = 1e3;
|
|
@@ -69,6 +73,70 @@ export class BotFactory {
|
|
|
69
73
|
};
|
|
70
74
|
}
|
|
71
75
|
/**
|
|
76
|
+
* Initializes the cross-chain bot by deploying TestContract, creating an L1 client,
|
|
77
|
+
* seeding initial L1→L2 messages, and waiting for the first to be ready.
|
|
78
|
+
*/ async setupCrossChain() {
|
|
79
|
+
const defaultAccountAddress = await this.setupAccount();
|
|
80
|
+
// Create L1 client (same pattern as bridgeL1FeeJuice)
|
|
81
|
+
const l1RpcUrls = this.config.l1RpcUrls;
|
|
82
|
+
if (!l1RpcUrls?.length) {
|
|
83
|
+
throw new Error('L1 RPC URLs required for cross-chain bot');
|
|
84
|
+
}
|
|
85
|
+
const mnemonicOrPrivateKey = this.config.l1PrivateKey?.getValue() ?? this.config.l1Mnemonic?.getValue();
|
|
86
|
+
if (!mnemonicOrPrivateKey) {
|
|
87
|
+
throw new Error('L1 mnemonic or private key required for cross-chain bot');
|
|
88
|
+
}
|
|
89
|
+
const { l1ChainId, l1ContractAddresses } = await this.aztecNode.getNodeInfo();
|
|
90
|
+
const chain = createEthereumChain(l1RpcUrls, l1ChainId);
|
|
91
|
+
const l1Client = createExtendedL1Client(chain.rpcUrls, mnemonicOrPrivateKey, chain.chainInfo);
|
|
92
|
+
// Fetch Rollup version (needed for Inbox L2Actor struct)
|
|
93
|
+
const rollupContract = new RollupContract(l1Client, l1ContractAddresses.rollupAddress.toString());
|
|
94
|
+
const rollupVersion = await rollupContract.getVersion();
|
|
95
|
+
// Deploy TestContract
|
|
96
|
+
const contract = await this.setupTestContract(defaultAccountAddress);
|
|
97
|
+
// Recover any pending messages from store (clean up stale ones first)
|
|
98
|
+
await this.store.cleanupOldPendingMessages();
|
|
99
|
+
const pendingMessages = await this.store.getUnconsumedL1ToL2Messages();
|
|
100
|
+
// Seed initial L1→L2 messages if pipeline is empty
|
|
101
|
+
const seedCount = Math.max(0, this.config.l1ToL2SeedCount - pendingMessages.length);
|
|
102
|
+
for(let i = 0; i < seedCount; i++){
|
|
103
|
+
await seedL1ToL2Message(l1Client, EthAddress.fromString(l1ContractAddresses.inboxAddress.toString()), contract.address, rollupVersion, this.store, this.log);
|
|
104
|
+
}
|
|
105
|
+
// Block until at least one message is ready
|
|
106
|
+
const allMessages = await this.store.getUnconsumedL1ToL2Messages();
|
|
107
|
+
if (allMessages.length > 0) {
|
|
108
|
+
this.log.info(`Waiting for first L1→L2 message to be ready...`);
|
|
109
|
+
const firstMsg = allMessages[0];
|
|
110
|
+
await waitForL1ToL2MessageReady(this.aztecNode, Fr.fromHexString(firstMsg.msgHash), {
|
|
111
|
+
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds,
|
|
112
|
+
// Use forPublicConsumption: false so we wait until the message is in the current world
|
|
113
|
+
// state. With true, it returns one block early which causes gas estimation simulation to
|
|
114
|
+
// fail since it runs against the current state.
|
|
115
|
+
// See https://linear.app/aztec-labs/issue/A-548 for details.
|
|
116
|
+
forPublicConsumption: false
|
|
117
|
+
});
|
|
118
|
+
this.log.info(`First L1→L2 message is ready`);
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
wallet: this.wallet,
|
|
122
|
+
defaultAccountAddress,
|
|
123
|
+
contract,
|
|
124
|
+
node: this.aztecNode,
|
|
125
|
+
l1Client,
|
|
126
|
+
rollupVersion
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
async setupTestContract(deployer) {
|
|
130
|
+
const deployOpts = {
|
|
131
|
+
from: deployer,
|
|
132
|
+
contractAddressSalt: this.config.tokenSalt,
|
|
133
|
+
universalDeploy: true
|
|
134
|
+
};
|
|
135
|
+
const deploy = TestContract.deploy(this.wallet);
|
|
136
|
+
const instance = await this.registerOrDeployContract('TestContract', deploy, deployOpts);
|
|
137
|
+
return TestContract.at(instance.address, this.wallet);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
72
140
|
* Checks if the sender account contract is initialized, and initializes it if necessary.
|
|
73
141
|
* @returns The sender wallet.
|
|
74
142
|
*/ async setupAccount() {
|
|
@@ -157,6 +225,10 @@ export class BotFactory {
|
|
|
157
225
|
tokenInstance = await deploy.getInstance(deployOpts);
|
|
158
226
|
token = PrivateTokenContract.at(tokenInstance.address, this.wallet);
|
|
159
227
|
await this.wallet.registerContract(tokenInstance, PrivateTokenContract.artifact, tokenSecretKey);
|
|
228
|
+
// The contract constructor initializes private storage vars that need the contract's own nullifier key.
|
|
229
|
+
deployOpts.additionalScopes = [
|
|
230
|
+
tokenInstance.address
|
|
231
|
+
];
|
|
160
232
|
} else {
|
|
161
233
|
throw new Error(`Unsupported token contract type: ${this.config.contract}`);
|
|
162
234
|
}
|
|
@@ -316,9 +388,14 @@ export class BotFactory {
|
|
|
316
388
|
this.log.info(`Skipping minting as ${minter.toString()} has enough tokens`);
|
|
317
389
|
return;
|
|
318
390
|
}
|
|
391
|
+
// PrivateToken's mint accesses contract-level private storage vars (admin, total_supply).
|
|
392
|
+
const additionalScopes = isStandardToken ? undefined : [
|
|
393
|
+
token.address
|
|
394
|
+
];
|
|
319
395
|
await this.withNoMinTxsPerBlock(async ()=>{
|
|
320
396
|
const txHash = await new BatchCall(token.wallet, calls).send({
|
|
321
397
|
from: minter,
|
|
398
|
+
additionalScopes,
|
|
322
399
|
wait: NO_WAIT
|
|
323
400
|
});
|
|
324
401
|
this.log.info(`Sent token mint tx with hash ${txHash.toString()}`);
|
package/dest/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { Bot } from './bot.js';
|
|
2
2
|
export { AmmBot } from './amm_bot.js';
|
|
3
|
+
export { CrossChainBot } from './cross_chain_bot.js';
|
|
3
4
|
export { BotRunner } from './runner.js';
|
|
4
5
|
export { BotStore } from './store/bot_store.js';
|
|
5
6
|
export { type BotConfig, getBotConfigFromEnv, getBotDefaultConfig, botConfigMappings, SupportedTokenContracts, } from './config.js';
|
|
6
7
|
export { getBotRunnerApiHandler } from './rpc.js';
|
|
7
8
|
export * from './interface.js';
|
|
8
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsR0FBRyxFQUFFLE1BQU0sVUFBVSxDQUFDO0FBQy9CLE9BQU8sRUFBRSxNQUFNLEVBQUUsTUFBTSxjQUFjLENBQUM7QUFDdEMsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQ3JELE9BQU8sRUFBRSxTQUFTLEVBQUUsTUFBTSxhQUFhLENBQUM7QUFDeEMsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQ2hELE9BQU8sRUFDTCxLQUFLLFNBQVMsRUFDZCxtQkFBbUIsRUFDbkIsbUJBQW1CLEVBQ25CLGlCQUFpQixFQUNqQix1QkFBdUIsR0FDeEIsTUFBTSxhQUFhLENBQUM7QUFDckIsT0FBTyxFQUFFLHNCQUFzQixFQUFFLE1BQU0sVUFBVSxDQUFDO0FBQ2xELGNBQWMsZ0JBQWdCLENBQUMifQ==
|
package/dest/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EACL,KAAK,SAAS,EACd,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAClD,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EACL,KAAK,SAAS,EACd,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAClD,cAAc,gBAAgB,CAAC"}
|
package/dest/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { Bot } from './bot.js';
|
|
2
2
|
export { AmmBot } from './amm_bot.js';
|
|
3
|
+
export { CrossChainBot } from './cross_chain_bot.js';
|
|
3
4
|
export { BotRunner } from './runner.js';
|
|
4
5
|
export { BotStore } from './store/bot_store.js';
|
|
5
6
|
export { getBotConfigFromEnv, getBotDefaultConfig, botConfigMappings, SupportedTokenContracts } from './config.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
4
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import type { BotStore, PendingL1ToL2Message } from './store/index.js';
|
|
6
|
+
/** Sends an L1→L2 message via the Inbox contract and stores it. */
|
|
7
|
+
export declare function seedL1ToL2Message(l1Client: ExtendedViemWalletClient, inboxAddress: EthAddress, l2Recipient: AztecAddress, rollupVersion: bigint, store: BotStore, log: Logger): Promise<PendingL1ToL2Message>;
|
|
8
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDFfdG9fbDJfc2VlZGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2wxX3RvX2wyX3NlZWRpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUd0RSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDM0QsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFFcEQsT0FBTyxLQUFLLEVBQUUsWUFBWSxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFJaEUsT0FBTyxLQUFLLEVBQUUsUUFBUSxFQUFFLG9CQUFvQixFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFdkUscUVBQW1FO0FBQ25FLHdCQUFzQixpQkFBaUIsQ0FDckMsUUFBUSxFQUFFLHdCQUF3QixFQUNsQyxZQUFZLEVBQUUsVUFBVSxFQUN4QixXQUFXLEVBQUUsWUFBWSxFQUN6QixhQUFhLEVBQUUsTUFBTSxFQUNyQixLQUFLLEVBQUUsUUFBUSxFQUNmLEdBQUcsRUFBRSxNQUFNLEdBQ1YsT0FBTyxDQUFDLG9CQUFvQixDQUFDLENBeUQvQiJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"l1_to_l2_seeding.d.ts","sourceRoot":"","sources":["../src/l1_to_l2_seeding.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAGtE,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAIhE,OAAO,KAAK,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAEvE,qEAAmE;AACnE,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,wBAAwB,EAClC,YAAY,EAAE,UAAU,EACxB,WAAW,EAAE,YAAY,EACzB,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,QAAQ,EACf,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,oBAAoB,CAAC,CAyD/B"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { generateClaimSecret } from '@aztec/aztec.js/ethereum';
|
|
2
|
+
import { compactArray } from '@aztec/foundation/collection';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
+
import { InboxAbi } from '@aztec/l1-artifacts';
|
|
5
|
+
import { decodeEventLog, getContract } from 'viem';
|
|
6
|
+
/** Sends an L1→L2 message via the Inbox contract and stores it. */ export async function seedL1ToL2Message(l1Client, inboxAddress, l2Recipient, rollupVersion, store, log) {
|
|
7
|
+
log.info('Seeding L1→L2 message');
|
|
8
|
+
const [secret, secretHash] = await generateClaimSecret(log);
|
|
9
|
+
const content = Fr.random();
|
|
10
|
+
const inbox = getContract({
|
|
11
|
+
address: inboxAddress.toString(),
|
|
12
|
+
abi: InboxAbi,
|
|
13
|
+
client: l1Client
|
|
14
|
+
});
|
|
15
|
+
const txHash = await inbox.write.sendL2Message([
|
|
16
|
+
{
|
|
17
|
+
actor: l2Recipient.toString(),
|
|
18
|
+
version: rollupVersion
|
|
19
|
+
},
|
|
20
|
+
content.toString(),
|
|
21
|
+
secretHash.toString()
|
|
22
|
+
], {
|
|
23
|
+
gas: 1_000_000n
|
|
24
|
+
});
|
|
25
|
+
log.info(`L1→L2 message sent in tx ${txHash}`);
|
|
26
|
+
const txReceipt = await l1Client.waitForTransactionReceipt({
|
|
27
|
+
hash: txHash
|
|
28
|
+
});
|
|
29
|
+
if (txReceipt.status !== 'success') {
|
|
30
|
+
throw new Error(`L1→L2 message tx failed: ${txHash}`);
|
|
31
|
+
}
|
|
32
|
+
// Extract MessageSent event
|
|
33
|
+
const messageSentLogs = compactArray(txReceipt.logs.filter((l)=>l.address.toLowerCase() === inboxAddress.toString().toLowerCase()).map((l)=>{
|
|
34
|
+
try {
|
|
35
|
+
return decodeEventLog({
|
|
36
|
+
abi: InboxAbi,
|
|
37
|
+
eventName: 'MessageSent',
|
|
38
|
+
data: l.data,
|
|
39
|
+
topics: l.topics
|
|
40
|
+
});
|
|
41
|
+
} catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}));
|
|
45
|
+
if (messageSentLogs.length !== 1) {
|
|
46
|
+
throw new Error(`Expected 1 MessageSent event, got ${messageSentLogs.length}`);
|
|
47
|
+
}
|
|
48
|
+
const event = messageSentLogs[0];
|
|
49
|
+
const msgHash = event.args.hash;
|
|
50
|
+
const globalLeafIndex = event.args.index;
|
|
51
|
+
const msg = {
|
|
52
|
+
content: content.toString(),
|
|
53
|
+
secret: secret.toString(),
|
|
54
|
+
secretHash: secretHash.toString(),
|
|
55
|
+
msgHash,
|
|
56
|
+
sender: l1Client.account.address,
|
|
57
|
+
globalLeafIndex: globalLeafIndex.toString(),
|
|
58
|
+
timestamp: Date.now()
|
|
59
|
+
};
|
|
60
|
+
await store.savePendingL1ToL2Message(msg);
|
|
61
|
+
log.info(`Seeded L1→L2 message msgHash=${msg.msgHash}`);
|
|
62
|
+
return msg;
|
|
63
|
+
}
|
package/dest/runner.d.ts
CHANGED
|
@@ -50,4 +50,4 @@ export declare class BotRunner implements BotRunnerApi, Traceable {
|
|
|
50
50
|
/** Returns the bot sender address. */
|
|
51
51
|
getInfo(): Promise<BotInfo>;
|
|
52
52
|
}
|
|
53
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
53
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicnVubmVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvcnVubmVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBR3RELE9BQU8sS0FBSyxFQUFFLGNBQWMsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ3RFLE9BQU8sRUFBRSxLQUFLLGVBQWUsRUFBRSxLQUFLLFNBQVMsRUFBRSxLQUFLLE1BQU0sRUFBYSxNQUFNLHlCQUF5QixDQUFDO0FBQ3ZHLE9BQU8sS0FBSyxFQUFFLGNBQWMsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBSzlELE9BQU8sS0FBSyxFQUFFLFNBQVMs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FBMEM7SUFDbkMsU0FBUyxZQUVmO0lBRUQ7OztPQUdHO0lBQ1UsTUFBTSxDQUFDLE1BQU0sRUFBRSxTQUFTLGlCQWFwQztJQUVEOzs7T0FHRztJQUNVLEdBQUcsa0JBc0JmO0lBRUQscURBQXFEO0lBQzlDLFNBQVMsdUJBR2Y7SUFFRCxzQ0FBc0M7SUFDekIsT0FBTyxJQUFJLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FNdkM7Q0FtREYifQ==
|
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;AACvG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAK9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
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;AACvG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAK9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,qBAAa,SAAU,YAAW,YAAY,EAAE,SAAS;;IAUrD,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,KAAK;IAdxB,OAAO,CAAC,GAAG,CAAuB;IAClC,OAAO,CAAC,GAAG,CAAC,CAAmB;IAC/B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,OAAO,CAAQ;IAEvB,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,YACU,MAAM,EAAE,SAAS,EACR,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,eAAe,EAC1B,cAAc,EAAE,cAAc,GAAG,SAAS,EAC1C,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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYm90X3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3RvcmUvYm90X3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQUN6RCxPQUFPLEtBQUssRUFBRSxhQUFhLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUU5RCxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFDbEUsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBQ3ZELE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFpQixNQUFNLGlCQUFpQixDQUFDO0FBRXhFLE1BQU0sV0FBVyxlQUFlO0lBQzlCLEtBQUssRUFBRSxhQUFhLENBQUM7SUFDckIsU0FBUyxFQUFFLE1BQU0sQ0FBQztJQUNsQixTQUFTLEVBQUUsTUFBTSxDQUFDO0NBQ25CO0FBRUQsTUFBTSxXQUFXLG9CQUFvQjtJQUNuQyxnREFBZ0Q7SUFDaEQsT0FBTyxFQUFFLE1BQU0sQ0FBQztJQUNoQix3Q0FBd0M7SUFDeEMsTUFBTSxFQUFFLE1BQU0sQ0FBQztJQUNmLDBCQUEwQjtJQUMxQixVQUFVLEVBQUUsTUFBTSxDQUFDO0lBQ25CLG1DQUFpQztJQUNqQyxPQUFPLEVBQUUsTUFBTSxDQUFDO0lBQ2hCLCtCQUErQjtJQUMvQixNQUFNLEVBQUUsTUFBTSxDQUFDO0lBQ2YscURBQ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BQXdCLENBQUMsR0FBRyxFQUFFLG9CQUFvQixHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FHOUU7SUFFRCx1REFBcUQ7SUFDeEMsMkJBQTJCLElBQUksT0FBTyxDQUFDLG9CQUFvQixFQUFFLENBQUMsQ0FNMUU7SUFFRCx5REFBdUQ7SUFDMUMsbUJBQW1CLENBQUMsT0FBTyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBRy9EO0lBRUQsOERBQTREO0lBQy9DLHlCQUF5QixDQUFDLFFBQVEsR0FBRSxNQUE0QixHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FZOUY7SUFFRCx3QkFBd0I7SUFDWCxLQUFLLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQUdsQztDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bot_store.d.ts","sourceRoot":"","sources":["../../src/store/bot_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AAExE,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,aAAa,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,QAAQ;
|
|
1
|
+
{"version":3,"file":"bot_store.d.ts","sourceRoot":"","sources":["../../src/store/bot_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,KAAK,MAAM,EAAgB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,CAAC,CAGrE;IAED;;OAEG;IACU,kBAAkB,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC,CAwB5D;IAED;;OAEG;IACU,gBAAgB,CAAC,QAAQ,GAAE,MAA4B,GAAG,OAAO,CAAC,MAAM,CAAC,CAerF;IAED,wDAAsD;IACzC,wBAAwB,CAAC,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9E;IAED,uDAAqD;IACxC,2BAA2B,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAM1E;IAED,yDAAuD;IAC1C,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG/D;IAED,8DAA4D;IAC/C,yBAAyB,CAAC,QAAQ,GAAE,MAA4B,GAAG,OAAO,CAAC,MAAM,CAAC,CAY9F;IAED,wBAAwB;IACX,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAGlC;CACF"}
|
package/dest/store/bot_store.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
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.85d7d01",
|
|
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.85d7d01",
|
|
58
|
+
"@aztec/aztec.js": "0.0.1-commit.85d7d01",
|
|
59
|
+
"@aztec/entrypoints": "0.0.1-commit.85d7d01",
|
|
60
|
+
"@aztec/ethereum": "0.0.1-commit.85d7d01",
|
|
61
|
+
"@aztec/foundation": "0.0.1-commit.85d7d01",
|
|
62
|
+
"@aztec/kv-store": "0.0.1-commit.85d7d01",
|
|
63
|
+
"@aztec/l1-artifacts": "0.0.1-commit.85d7d01",
|
|
64
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.85d7d01",
|
|
65
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.85d7d01",
|
|
66
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.85d7d01",
|
|
67
|
+
"@aztec/protocol-contracts": "0.0.1-commit.85d7d01",
|
|
68
|
+
"@aztec/stdlib": "0.0.1-commit.85d7d01",
|
|
69
|
+
"@aztec/telemetry-client": "0.0.1-commit.85d7d01",
|
|
70
|
+
"@aztec/wallets": "0.0.1-commit.85d7d01",
|
|
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/base_bot.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
-
import {
|
|
3
|
-
BatchCall,
|
|
4
|
-
ContractFunctionInteraction,
|
|
5
|
-
type SendInteractionOptions,
|
|
6
|
-
waitForProven,
|
|
7
|
-
} from '@aztec/aztec.js/contracts';
|
|
2
|
+
import { BatchCall, ContractFunctionInteraction, type SendInteractionOptions } from '@aztec/aztec.js/contracts';
|
|
8
3
|
import { createLogger } from '@aztec/aztec.js/log';
|
|
9
4
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
10
|
-
import { TxHash, TxReceipt } from '@aztec/aztec.js/tx';
|
|
5
|
+
import { TxHash, TxReceipt, TxStatus } from '@aztec/aztec.js/tx';
|
|
11
6
|
import { Gas } from '@aztec/stdlib/gas';
|
|
12
7
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
13
8
|
import type { EmbeddedWallet } from '@aztec/wallets/embedded';
|
|
@@ -29,8 +24,8 @@ export abstract class BaseBot {
|
|
|
29
24
|
|
|
30
25
|
public async run(): Promise<TxReceipt | TxHash> {
|
|
31
26
|
this.attempts++;
|
|
32
|
-
const logCtx = { runId: Date.now() * 1000 + Math.floor(Math.random() * 1000) };
|
|
33
27
|
const { followChain, txMinedWaitSeconds } = this.config;
|
|
28
|
+
const logCtx = { runId: Date.now() * 1000 + Math.floor(Math.random() * 1000), followChain, txMinedWaitSeconds };
|
|
34
29
|
|
|
35
30
|
this.log.verbose(`Creating tx`, logCtx);
|
|
36
31
|
const txHash = await this.createAndSendTx(logCtx);
|
|
@@ -40,14 +35,9 @@ export abstract class BaseBot {
|
|
|
40
35
|
return txHash;
|
|
41
36
|
}
|
|
42
37
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
);
|
|
47
|
-
const receipt = await waitForTx(this.node, txHash, { timeout: txMinedWaitSeconds });
|
|
48
|
-
if (followChain === 'PROVEN') {
|
|
49
|
-
await waitForProven(this.node, receipt, { provenTimeout: txMinedWaitSeconds });
|
|
50
|
-
}
|
|
38
|
+
const waitForStatus = TxStatus[followChain];
|
|
39
|
+
this.log.verbose(`Awaiting tx ${txHash.toString()} to be on the ${followChain} chain`, logCtx);
|
|
40
|
+
const receipt = await waitForTx(this.node, txHash, { timeout: txMinedWaitSeconds, waitForStatus });
|
|
51
41
|
this.successes++;
|
|
52
42
|
this.log.info(
|
|
53
43
|
`Tx #${this.attempts} ${receipt.txHash} successfully mined in block ${receipt.blockNumber} (stats: ${this.successes}/${this.attempts} success)`,
|
package/src/bot.ts
CHANGED
|
@@ -83,7 +83,7 @@ export class Bot extends BaseBot {
|
|
|
83
83
|
if (isStandardTokenContract(this.token)) {
|
|
84
84
|
return {
|
|
85
85
|
sender: await getBalances(this.token, this.defaultAccountAddress),
|
|
86
|
-
recipient: await getBalances(this.token, this.recipient
|
|
86
|
+
recipient: await getBalances(this.token, this.recipient),
|
|
87
87
|
};
|
|
88
88
|
} else {
|
|
89
89
|
return {
|
|
@@ -92,7 +92,7 @@ export class Bot extends BaseBot {
|
|
|
92
92
|
publicBalance: 0n,
|
|
93
93
|
},
|
|
94
94
|
recipient: {
|
|
95
|
-
privateBalance: await getPrivateBalance(this.token, this.recipient
|
|
95
|
+
privateBalance: await getPrivateBalance(this.token, this.recipient),
|
|
96
96
|
publicBalance: 0n,
|
|
97
97
|
},
|
|
98
98
|
};
|
package/src/config.ts
CHANGED
|
@@ -19,9 +19,12 @@ import type { ComponentsVersions } from '@aztec/stdlib/versioning';
|
|
|
19
19
|
|
|
20
20
|
import { z } from 'zod';
|
|
21
21
|
|
|
22
|
-
const BotFollowChain = ['NONE', '
|
|
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
|
})
|
|
@@ -213,10 +222,14 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
|
|
|
213
222
|
description: 'Which chain the bot follows',
|
|
214
223
|
defaultValue: 'NONE',
|
|
215
224
|
parseEnv(val) {
|
|
216
|
-
|
|
225
|
+
const upper = val.toUpperCase();
|
|
226
|
+
if (upper === 'PENDING') {
|
|
227
|
+
return 'CHECKPOINTED';
|
|
228
|
+
}
|
|
229
|
+
if (!(BotFollowChain as readonly string[]).includes(upper)) {
|
|
217
230
|
throw new Error(`Invalid value for BOT_FOLLOW_CHAIN: ${val}`);
|
|
218
231
|
}
|
|
219
|
-
return
|
|
232
|
+
return upper as BotFollowChain;
|
|
220
233
|
},
|
|
221
234
|
},
|
|
222
235
|
maxPendingTxs: {
|
|
@@ -264,10 +277,26 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
|
|
|
264
277
|
description: 'Stops the bot if service becomes unhealthy',
|
|
265
278
|
...booleanConfigHelper(false),
|
|
266
279
|
},
|
|
267
|
-
|
|
268
|
-
env: '
|
|
269
|
-
description: '
|
|
270
|
-
|
|
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),
|
|
271
300
|
},
|
|
272
301
|
...pickConfigMappings(dataConfigMappings, ['dataStoreMapSizeKb', 'dataDirectory']),
|
|
273
302
|
};
|