@aztec/bot 4.0.0-nightly.20250907 → 4.0.0-nightly.20260108
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/amm_bot.d.ts +9 -9
- package/dest/amm_bot.d.ts.map +1 -1
- package/dest/amm_bot.js +23 -20
- package/dest/base_bot.d.ts +11 -8
- package/dest/base_bot.d.ts.map +1 -1
- package/dest/base_bot.js +18 -18
- package/dest/bot.d.ts +8 -9
- package/dest/bot.d.ts.map +1 -1
- package/dest/bot.js +11 -12
- package/dest/config.d.ts +53 -50
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +27 -25
- package/dest/factory.d.ts +14 -32
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +137 -115
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/interface.d.ts +2 -2
- package/dest/interface.d.ts.map +1 -1
- package/dest/interface.js +1 -1
- package/dest/rpc.d.ts +1 -1
- package/dest/runner.d.ts +12 -13
- package/dest/runner.d.ts.map +1 -1
- package/dest/runner.js +429 -61
- package/dest/store/bot_store.d.ts +44 -0
- package/dest/store/bot_store.d.ts.map +1 -0
- package/dest/store/bot_store.js +107 -0
- package/dest/store/index.d.ts +2 -0
- package/dest/store/index.d.ts.map +1 -0
- package/dest/store/index.js +1 -0
- package/dest/utils.d.ts +4 -4
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +5 -5
- package/package.json +16 -13
- package/src/amm_bot.ts +39 -31
- package/src/base_bot.ts +24 -22
- package/src/bot.ts +25 -14
- package/src/config.ts +64 -64
- package/src/factory.ts +172 -157
- package/src/index.ts +1 -0
- package/src/interface.ts +1 -1
- package/src/runner.ts +19 -23
- package/src/store/bot_store.ts +141 -0
- package/src/store/index.ts +1 -0
- package/src/utils.ts +10 -5
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import type { L2AmountClaim } from '@aztec/aztec.js/ethereum';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
6
|
+
|
|
7
|
+
export interface BridgeClaimData {
|
|
8
|
+
claim: L2AmountClaim;
|
|
9
|
+
timestamp: number;
|
|
10
|
+
recipient: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Simple data store for the bot to persist L1 bridge claims.
|
|
15
|
+
*/
|
|
16
|
+
export class BotStore {
|
|
17
|
+
public static readonly SCHEMA_VERSION = 1;
|
|
18
|
+
private readonly bridgeClaims: AztecAsyncMap<string, string>;
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
private readonly store: AztecAsyncKVStore,
|
|
22
|
+
private readonly log: Logger = createLogger('bot:store'),
|
|
23
|
+
) {
|
|
24
|
+
this.bridgeClaims = store.openMap<string, string>('bridge_claims');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Saves a bridge claim for a recipient.
|
|
29
|
+
*/
|
|
30
|
+
public async saveBridgeClaim(recipient: AztecAddress, claim: L2AmountClaim): Promise<void> {
|
|
31
|
+
// Convert Fr fields and BigInts to strings for JSON serialization
|
|
32
|
+
const serializableClaim = {
|
|
33
|
+
claimAmount: claim.claimAmount.toString(),
|
|
34
|
+
claimSecret: claim.claimSecret.toString(),
|
|
35
|
+
claimSecretHash: claim.claimSecretHash.toString(),
|
|
36
|
+
messageHash: claim.messageHash,
|
|
37
|
+
messageLeafIndex: claim.messageLeafIndex.toString(),
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const data = {
|
|
41
|
+
claim: serializableClaim,
|
|
42
|
+
timestamp: Date.now(),
|
|
43
|
+
recipient: recipient.toString(),
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
await this.bridgeClaims.set(recipient.toString(), JSON.stringify(data));
|
|
47
|
+
this.log.info(`Saved bridge claim for ${recipient.toString()}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Gets a bridge claim for a recipient if it exists.
|
|
52
|
+
*/
|
|
53
|
+
public async getBridgeClaim(recipient: AztecAddress): Promise<BridgeClaimData | undefined> {
|
|
54
|
+
const data = await this.bridgeClaims.getAsync(recipient.toString());
|
|
55
|
+
if (!data) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const parsed = JSON.parse(data);
|
|
60
|
+
|
|
61
|
+
// Reconstruct L2AmountClaim from serialized data
|
|
62
|
+
const claim: L2AmountClaim = {
|
|
63
|
+
claimAmount: BigInt(parsed.claim.claimAmount),
|
|
64
|
+
claimSecret: Fr.fromString(parsed.claim.claimSecret),
|
|
65
|
+
claimSecretHash: Fr.fromString(parsed.claim.claimSecretHash),
|
|
66
|
+
messageHash: parsed.claim.messageHash,
|
|
67
|
+
messageLeafIndex: BigInt(parsed.claim.messageLeafIndex),
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
claim,
|
|
72
|
+
timestamp: parsed.timestamp,
|
|
73
|
+
recipient: parsed.recipient,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Deletes a bridge claim for a recipient.
|
|
79
|
+
*/
|
|
80
|
+
public async deleteBridgeClaim(recipient: AztecAddress): Promise<void> {
|
|
81
|
+
await this.bridgeClaims.delete(recipient.toString());
|
|
82
|
+
this.log.info(`Deleted bridge claim for ${recipient.toString()}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Gets all stored bridge claims.
|
|
87
|
+
*/
|
|
88
|
+
public async getAllBridgeClaims(): Promise<BridgeClaimData[]> {
|
|
89
|
+
const claims: BridgeClaimData[] = [];
|
|
90
|
+
const entries = this.bridgeClaims.entriesAsync();
|
|
91
|
+
|
|
92
|
+
for await (const [_, data] of entries) {
|
|
93
|
+
const parsed = JSON.parse(data);
|
|
94
|
+
|
|
95
|
+
// Reconstruct L2AmountClaim from serialized data
|
|
96
|
+
const claim: L2AmountClaim = {
|
|
97
|
+
claimAmount: BigInt(parsed.claim.claimAmount),
|
|
98
|
+
claimSecret: Fr.fromString(parsed.claim.claimSecret),
|
|
99
|
+
claimSecretHash: Fr.fromString(parsed.claim.claimSecretHash),
|
|
100
|
+
messageHash: parsed.claim.messageHash,
|
|
101
|
+
messageLeafIndex: BigInt(parsed.claim.messageLeafIndex),
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
claims.push({
|
|
105
|
+
claim,
|
|
106
|
+
timestamp: parsed.timestamp,
|
|
107
|
+
recipient: parsed.recipient,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return claims;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Cleans up old bridge claims (older than 24 hours).
|
|
116
|
+
*/
|
|
117
|
+
public async cleanupOldClaims(maxAgeMs: number = 24 * 60 * 60 * 1000): Promise<number> {
|
|
118
|
+
const now = Date.now();
|
|
119
|
+
let cleanedCount = 0;
|
|
120
|
+
const entries = this.bridgeClaims.entriesAsync();
|
|
121
|
+
|
|
122
|
+
for await (const [key, data] of entries) {
|
|
123
|
+
const parsed = JSON.parse(data);
|
|
124
|
+
if (now - parsed.timestamp > maxAgeMs) {
|
|
125
|
+
await this.bridgeClaims.delete(key);
|
|
126
|
+
cleanedCount++;
|
|
127
|
+
this.log.info(`Cleaned up old bridge claim for ${parsed.recipient}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return cleanedCount;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Closes the store.
|
|
136
|
+
*/
|
|
137
|
+
public async close(): Promise<void> {
|
|
138
|
+
await this.store.close();
|
|
139
|
+
this.log.info('Closed bot data store');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BotStore, type BridgeClaimData } from './bot_store.js';
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ContractBase } from '@aztec/aztec.js/contracts';
|
|
2
2
|
import type { AMMContract } from '@aztec/noir-contracts.js/AMM';
|
|
3
3
|
import type { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
|
|
4
4
|
import type { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
@@ -13,14 +13,19 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
|
13
13
|
export async function getBalances(
|
|
14
14
|
token: TokenContract,
|
|
15
15
|
who: AztecAddress,
|
|
16
|
+
from?: AztecAddress,
|
|
16
17
|
): Promise<{ privateBalance: bigint; publicBalance: bigint }> {
|
|
17
|
-
const privateBalance = await token.methods.balance_of_private(who).simulate({ from: who });
|
|
18
|
-
const publicBalance = await token.methods.balance_of_public(who).simulate({ from: who });
|
|
18
|
+
const privateBalance = await token.methods.balance_of_private(who).simulate({ from: from ?? who });
|
|
19
|
+
const publicBalance = await token.methods.balance_of_public(who).simulate({ from: from ?? who });
|
|
19
20
|
return { privateBalance, publicBalance };
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
export async function getPrivateBalance(
|
|
23
|
-
|
|
23
|
+
export async function getPrivateBalance(
|
|
24
|
+
token: PrivateTokenContract,
|
|
25
|
+
who: AztecAddress,
|
|
26
|
+
from?: AztecAddress,
|
|
27
|
+
): Promise<bigint> {
|
|
28
|
+
const privateBalance = await token.methods.get_balance(who).simulate({ from: from ?? who });
|
|
24
29
|
return privateBalance;
|
|
25
30
|
}
|
|
26
31
|
|