@aztec/bot 2.1.0-rc.9 → 3.0.0-devnet.2

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 (45) hide show
  1. package/dest/amm_bot.d.ts +8 -8
  2. package/dest/amm_bot.d.ts.map +1 -1
  3. package/dest/amm_bot.js +23 -20
  4. package/dest/base_bot.d.ts +10 -7
  5. package/dest/base_bot.d.ts.map +1 -1
  6. package/dest/base_bot.js +18 -18
  7. package/dest/bot.d.ts +7 -8
  8. package/dest/bot.d.ts.map +1 -1
  9. package/dest/bot.js +11 -12
  10. package/dest/config.d.ts +19 -15
  11. package/dest/config.d.ts.map +1 -1
  12. package/dest/config.js +22 -20
  13. package/dest/factory.d.ts +18 -17
  14. package/dest/factory.d.ts.map +1 -1
  15. package/dest/factory.js +122 -102
  16. package/dest/index.d.ts +1 -0
  17. package/dest/index.d.ts.map +1 -1
  18. package/dest/index.js +1 -0
  19. package/dest/interface.d.ts +1 -1
  20. package/dest/interface.d.ts.map +1 -1
  21. package/dest/interface.js +1 -1
  22. package/dest/runner.d.ts +11 -12
  23. package/dest/runner.d.ts.map +1 -1
  24. package/dest/runner.js +18 -32
  25. package/dest/store/bot_store.d.ts +44 -0
  26. package/dest/store/bot_store.d.ts.map +1 -0
  27. package/dest/store/bot_store.js +107 -0
  28. package/dest/store/index.d.ts +2 -0
  29. package/dest/store/index.d.ts.map +1 -0
  30. package/dest/store/index.js +1 -0
  31. package/dest/utils.d.ts +3 -3
  32. package/dest/utils.d.ts.map +1 -1
  33. package/dest/utils.js +5 -5
  34. package/package.json +13 -11
  35. package/src/amm_bot.ts +39 -31
  36. package/src/base_bot.ts +24 -22
  37. package/src/bot.ts +25 -14
  38. package/src/config.ts +20 -22
  39. package/src/factory.ts +138 -140
  40. package/src/index.ts +1 -0
  41. package/src/interface.ts +1 -1
  42. package/src/runner.ts +19 -23
  43. package/src/store/bot_store.ts +141 -0
  44. package/src/store/index.ts +1 -0
  45. package/src/utils.ts +10 -5
package/dest/runner.js CHANGED
@@ -4,43 +4,36 @@ function _ts_decorate(decorators, target, key, desc) {
4
4
  else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  }
7
- import { createAztecNodeClient, createLogger } from '@aztec/aztec.js';
7
+ import { createLogger } from '@aztec/aztec.js/log';
8
8
  import { omit } from '@aztec/foundation/collection';
9
9
  import { RunningPromise } from '@aztec/foundation/running-promise';
10
- import { createAztecNodeAdminClient } from '@aztec/stdlib/interfaces/client';
11
- import { makeTracedFetch, trackSpan } from '@aztec/telemetry-client';
10
+ import { trackSpan } from '@aztec/telemetry-client';
12
11
  import { AmmBot } from './amm_bot.js';
13
12
  import { Bot } from './bot.js';
14
- import { getVersions } from './config.js';
15
13
  export class BotRunner {
16
14
  config;
15
+ wallet;
16
+ aztecNode;
17
+ telemetry;
18
+ aztecNodeAdmin;
19
+ store;
17
20
  log;
18
21
  bot;
19
- pxe;
20
- node;
21
- nodeAdmin;
22
22
  runningPromise;
23
23
  consecutiveErrors;
24
24
  healthy;
25
25
  tracer;
26
- constructor(config, dependencies){
26
+ constructor(config, wallet, aztecNode, telemetry, aztecNodeAdmin, store){
27
27
  this.config = config;
28
+ this.wallet = wallet;
29
+ this.aztecNode = aztecNode;
30
+ this.telemetry = telemetry;
31
+ this.aztecNodeAdmin = aztecNodeAdmin;
32
+ this.store = store;
28
33
  this.log = createLogger('bot');
29
34
  this.consecutiveErrors = 0;
30
35
  this.healthy = true;
31
- this.tracer = dependencies.telemetry.getTracer('Bot');
32
- this.pxe = dependencies.pxe;
33
- if (!dependencies.node && !config.nodeUrl) {
34
- throw new Error(`Missing node URL in config or dependencies`);
35
- }
36
- const versions = getVersions();
37
- const fetch = makeTracedFetch([
38
- 1,
39
- 2,
40
- 3
41
- ], true);
42
- this.node = dependencies.node ?? createAztecNodeClient(config.nodeUrl, versions, fetch);
43
- this.nodeAdmin = dependencies.nodeAdmin ?? (config.nodeAdminUrl ? createAztecNodeAdminClient(config.nodeAdminUrl, versions, fetch) : undefined);
36
+ this.tracer = telemetry.getTracer('Bot');
44
37
  this.runningPromise = new RunningPromise(()=>this.#work(), this.log, config.txIntervalSeconds * 1000);
45
38
  }
46
39
  /** Initializes the bot if needed. Blocks until the bot setup is finished. */ async setup() {
@@ -70,6 +63,7 @@ export class BotRunner {
70
63
  this.log.verbose(`Stopping bot`);
71
64
  await this.runningPromise.stop();
72
65
  }
66
+ await this.store.close();
73
67
  this.log.info(`Stopped bot`);
74
68
  }
75
69
  isHealthy() {
@@ -130,22 +124,14 @@ export class BotRunner {
130
124
  if (!this.bot) {
131
125
  throw new Error(`Bot is not initialized`);
132
126
  }
133
- const botAddress = await this.bot.then((b)=>b.wallet.getAddress());
127
+ const botAddress = await this.bot.then((b)=>b.defaultAccountAddress);
134
128
  return {
135
129
  botAddress
136
130
  };
137
131
  }
138
132
  async #createBot() {
139
133
  try {
140
- this.bot = this.config.ammTxs ? AmmBot.create(this.config, {
141
- pxe: this.pxe,
142
- node: this.node,
143
- nodeAdmin: this.nodeAdmin
144
- }) : Bot.create(this.config, {
145
- pxe: this.pxe,
146
- node: this.node,
147
- nodeAdmin: this.nodeAdmin
148
- });
134
+ this.bot = this.config.ammTxs ? AmmBot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store) : Bot.create(this.config, this.wallet, this.aztecNode, this.aztecNodeAdmin, this.store);
149
135
  await this.bot;
150
136
  } catch (err) {
151
137
  this.log.error(`Error setting up bot: ${err}`);
@@ -154,7 +140,7 @@ export class BotRunner {
154
140
  }
155
141
  async #work() {
156
142
  if (this.config.maxPendingTxs > 0) {
157
- const pendingTxCount = await this.node.getPendingTxCount();
143
+ const pendingTxCount = await this.aztecNode.getPendingTxCount();
158
144
  if (pendingTxCount >= this.config.maxPendingTxs) {
159
145
  this.log.verbose(`Not sending bot tx since node has ${pendingTxCount} pending txs`);
160
146
  return;
@@ -0,0 +1,44 @@
1
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import type { L2AmountClaim } from '@aztec/aztec.js/ethereum';
3
+ import { type Logger } from '@aztec/foundation/log';
4
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
5
+ export interface BridgeClaimData {
6
+ claim: L2AmountClaim;
7
+ timestamp: number;
8
+ recipient: string;
9
+ }
10
+ /**
11
+ * Simple data store for the bot to persist L1 bridge claims.
12
+ */
13
+ export declare class BotStore {
14
+ private readonly store;
15
+ private readonly log;
16
+ static readonly SCHEMA_VERSION = 1;
17
+ private readonly bridgeClaims;
18
+ constructor(store: AztecAsyncKVStore, log?: Logger);
19
+ /**
20
+ * Saves a bridge claim for a recipient.
21
+ */
22
+ saveBridgeClaim(recipient: AztecAddress, claim: L2AmountClaim): Promise<void>;
23
+ /**
24
+ * Gets a bridge claim for a recipient if it exists.
25
+ */
26
+ getBridgeClaim(recipient: AztecAddress): Promise<BridgeClaimData | undefined>;
27
+ /**
28
+ * Deletes a bridge claim for a recipient.
29
+ */
30
+ deleteBridgeClaim(recipient: AztecAddress): Promise<void>;
31
+ /**
32
+ * Gets all stored bridge claims.
33
+ */
34
+ getAllBridgeClaims(): Promise<BridgeClaimData[]>;
35
+ /**
36
+ * Cleans up old bridge claims (older than 24 hours).
37
+ */
38
+ cleanupOldClaims(maxAgeMs?: number): Promise<number>;
39
+ /**
40
+ * Closes the store.
41
+ */
42
+ close(): Promise<void>;
43
+ }
44
+ //# sourceMappingURL=bot_store.d.ts.map
@@ -0,0 +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;IAKjB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,GAAG;IALtB,gBAAuB,cAAc,KAAK;IAC1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgC;gBAG1C,KAAK,EAAE,iBAAiB,EACxB,GAAG,GAAE,MAAkC;IAK1D;;OAEG;IACU,eAAe,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB1F;;OAEG;IACU,cAAc,CAAC,SAAS,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAwB1F;;OAEG;IACU,iBAAiB,CAAC,SAAS,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAKtE;;OAEG;IACU,kBAAkB,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IA0B7D;;OAEG;IACU,gBAAgB,CAAC,QAAQ,GAAE,MAA4B,GAAG,OAAO,CAAC,MAAM,CAAC;IAiBtF;;OAEG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAIpC"}
@@ -0,0 +1,107 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ /**
4
+ * Simple data store for the bot to persist L1 bridge claims.
5
+ */ export class BotStore {
6
+ store;
7
+ log;
8
+ static SCHEMA_VERSION = 1;
9
+ bridgeClaims;
10
+ constructor(store, log = createLogger('bot:store')){
11
+ this.store = store;
12
+ this.log = log;
13
+ this.bridgeClaims = store.openMap('bridge_claims');
14
+ }
15
+ /**
16
+ * Saves a bridge claim for a recipient.
17
+ */ async saveBridgeClaim(recipient, claim) {
18
+ // Convert Fr fields and BigInts to strings for JSON serialization
19
+ const serializableClaim = {
20
+ claimAmount: claim.claimAmount.toString(),
21
+ claimSecret: claim.claimSecret.toString(),
22
+ claimSecretHash: claim.claimSecretHash.toString(),
23
+ messageHash: claim.messageHash,
24
+ messageLeafIndex: claim.messageLeafIndex.toString()
25
+ };
26
+ const data = {
27
+ claim: serializableClaim,
28
+ timestamp: Date.now(),
29
+ recipient: recipient.toString()
30
+ };
31
+ await this.bridgeClaims.set(recipient.toString(), JSON.stringify(data));
32
+ this.log.info(`Saved bridge claim for ${recipient.toString()}`);
33
+ }
34
+ /**
35
+ * Gets a bridge claim for a recipient if it exists.
36
+ */ async getBridgeClaim(recipient) {
37
+ const data = await this.bridgeClaims.getAsync(recipient.toString());
38
+ if (!data) {
39
+ return undefined;
40
+ }
41
+ const parsed = JSON.parse(data);
42
+ // Reconstruct L2AmountClaim from serialized data
43
+ const claim = {
44
+ claimAmount: BigInt(parsed.claim.claimAmount),
45
+ claimSecret: Fr.fromString(parsed.claim.claimSecret),
46
+ claimSecretHash: Fr.fromString(parsed.claim.claimSecretHash),
47
+ messageHash: parsed.claim.messageHash,
48
+ messageLeafIndex: BigInt(parsed.claim.messageLeafIndex)
49
+ };
50
+ return {
51
+ claim,
52
+ timestamp: parsed.timestamp,
53
+ recipient: parsed.recipient
54
+ };
55
+ }
56
+ /**
57
+ * Deletes a bridge claim for a recipient.
58
+ */ async deleteBridgeClaim(recipient) {
59
+ await this.bridgeClaims.delete(recipient.toString());
60
+ this.log.info(`Deleted bridge claim for ${recipient.toString()}`);
61
+ }
62
+ /**
63
+ * Gets all stored bridge claims.
64
+ */ async getAllBridgeClaims() {
65
+ const claims = [];
66
+ const entries = this.bridgeClaims.entriesAsync();
67
+ for await (const [_, data] of entries){
68
+ const parsed = JSON.parse(data);
69
+ // Reconstruct L2AmountClaim from serialized data
70
+ const claim = {
71
+ claimAmount: BigInt(parsed.claim.claimAmount),
72
+ claimSecret: Fr.fromString(parsed.claim.claimSecret),
73
+ claimSecretHash: Fr.fromString(parsed.claim.claimSecretHash),
74
+ messageHash: parsed.claim.messageHash,
75
+ messageLeafIndex: BigInt(parsed.claim.messageLeafIndex)
76
+ };
77
+ claims.push({
78
+ claim,
79
+ timestamp: parsed.timestamp,
80
+ recipient: parsed.recipient
81
+ });
82
+ }
83
+ return claims;
84
+ }
85
+ /**
86
+ * Cleans up old bridge claims (older than 24 hours).
87
+ */ async cleanupOldClaims(maxAgeMs = 24 * 60 * 60 * 1000) {
88
+ const now = Date.now();
89
+ let cleanedCount = 0;
90
+ const entries = this.bridgeClaims.entriesAsync();
91
+ for await (const [key, data] of entries){
92
+ const parsed = JSON.parse(data);
93
+ if (now - parsed.timestamp > maxAgeMs) {
94
+ await this.bridgeClaims.delete(key);
95
+ cleanedCount++;
96
+ this.log.info(`Cleaned up old bridge claim for ${parsed.recipient}`);
97
+ }
98
+ }
99
+ return cleanedCount;
100
+ }
101
+ /**
102
+ * Closes the store.
103
+ */ async close() {
104
+ await this.store.close();
105
+ this.log.info('Closed bot data store');
106
+ }
107
+ }
@@ -0,0 +1,2 @@
1
+ export { BotStore, type BridgeClaimData } from './bot_store.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1 @@
1
+ export { BotStore } from './bot_store.js';
package/dest/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ContractBase } from '@aztec/aztec.js';
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';
@@ -9,11 +9,11 @@ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
9
9
  * @param who - Address to get the balance for.
10
10
  * @returns - Private and public token balances as bigints.
11
11
  */
12
- export declare function getBalances(token: TokenContract, who: AztecAddress): Promise<{
12
+ export declare function getBalances(token: TokenContract, who: AztecAddress, from?: AztecAddress): Promise<{
13
13
  privateBalance: bigint;
14
14
  publicBalance: bigint;
15
15
  }>;
16
- export declare function getPrivateBalance(token: PrivateTokenContract, who: AztecAddress): Promise<bigint>;
16
+ export declare function getPrivateBalance(token: PrivateTokenContract, who: AztecAddress, from?: AztecAddress): Promise<bigint>;
17
17
  export declare function isStandardTokenContract(token: ContractBase): token is TokenContract;
18
18
  export declare function isAMMContract(contract: ContractBase): contract is AMMContract;
19
19
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,aAAa,EACpB,GAAG,EAAE,YAAY,GAChB,OAAO,CAAC;IAAE,cAAc,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,CAI5D;AAED,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,oBAAoB,EAAE,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAGvG;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,IAAI,aAAa,CAEnF;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,YAAY,GAAG,QAAQ,IAAI,WAAW,CAE7E"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,aAAa,EACpB,GAAG,EAAE,YAAY,EACjB,IAAI,CAAC,EAAE,YAAY,GAClB,OAAO,CAAC;IAAE,cAAc,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,CAI5D;AAED,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,oBAAoB,EAC3B,GAAG,EAAE,YAAY,EACjB,IAAI,CAAC,EAAE,YAAY,GAClB,OAAO,CAAC,MAAM,CAAC,CAGjB;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,IAAI,aAAa,CAEnF;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,YAAY,GAAG,QAAQ,IAAI,WAAW,CAE7E"}
package/dest/utils.js CHANGED
@@ -3,21 +3,21 @@
3
3
  * @param token - Token contract.
4
4
  * @param who - Address to get the balance for.
5
5
  * @returns - Private and public token balances as bigints.
6
- */ export async function getBalances(token, who) {
6
+ */ export async function getBalances(token, who, from) {
7
7
  const privateBalance = await token.methods.balance_of_private(who).simulate({
8
- from: who
8
+ from: from ?? who
9
9
  });
10
10
  const publicBalance = await token.methods.balance_of_public(who).simulate({
11
- from: who
11
+ from: from ?? who
12
12
  });
13
13
  return {
14
14
  privateBalance,
15
15
  publicBalance
16
16
  };
17
17
  }
18
- export async function getPrivateBalance(token, who) {
18
+ export async function getPrivateBalance(token, who, from) {
19
19
  const privateBalance = await token.methods.get_balance(who).simulate({
20
- from: who
20
+ from: from ?? who
21
21
  });
22
22
  return privateBalance;
23
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/bot",
3
- "version": "2.1.0-rc.9",
3
+ "version": "3.0.0-devnet.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -54,16 +54,18 @@
54
54
  ]
55
55
  },
56
56
  "dependencies": {
57
- "@aztec/accounts": "2.1.0-rc.9",
58
- "@aztec/aztec.js": "2.1.0-rc.9",
59
- "@aztec/entrypoints": "2.1.0-rc.9",
60
- "@aztec/ethereum": "2.1.0-rc.9",
61
- "@aztec/foundation": "2.1.0-rc.9",
62
- "@aztec/noir-contracts.js": "2.1.0-rc.9",
63
- "@aztec/noir-protocol-circuits-types": "2.1.0-rc.9",
64
- "@aztec/protocol-contracts": "2.1.0-rc.9",
65
- "@aztec/stdlib": "2.1.0-rc.9",
66
- "@aztec/telemetry-client": "2.1.0-rc.9",
57
+ "@aztec/accounts": "3.0.0-devnet.2",
58
+ "@aztec/aztec.js": "3.0.0-devnet.2",
59
+ "@aztec/entrypoints": "3.0.0-devnet.2",
60
+ "@aztec/ethereum": "3.0.0-devnet.2",
61
+ "@aztec/foundation": "3.0.0-devnet.2",
62
+ "@aztec/kv-store": "3.0.0-devnet.2",
63
+ "@aztec/noir-contracts.js": "3.0.0-devnet.2",
64
+ "@aztec/noir-protocol-circuits-types": "3.0.0-devnet.2",
65
+ "@aztec/protocol-contracts": "3.0.0-devnet.2",
66
+ "@aztec/stdlib": "3.0.0-devnet.2",
67
+ "@aztec/telemetry-client": "3.0.0-devnet.2",
68
+ "@aztec/test-wallet": "3.0.0-devnet.2",
67
69
  "source-map-support": "^0.5.21",
68
70
  "tslib": "^2.4.0",
69
71
  "zod": "^3.23.8"
package/src/amm_bot.ts CHANGED
@@ -1,12 +1,17 @@
1
- import { AztecAddress, Fr, SentTx, TxReceipt, type Wallet } from '@aztec/aztec.js';
1
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { SentTx } from '@aztec/aztec.js/contracts';
3
+ import { Fr } from '@aztec/aztec.js/fields';
4
+ import { TxReceipt } from '@aztec/aztec.js/tx';
2
5
  import { jsonStringify } from '@aztec/foundation/json-rpc';
3
6
  import type { AMMContract } from '@aztec/noir-contracts.js/AMM';
4
7
  import type { TokenContract } from '@aztec/noir-contracts.js/Token';
5
- import type { AztecNode, AztecNodeAdmin, PXE } from '@aztec/stdlib/interfaces/client';
8
+ import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
9
+ import type { TestWallet } from '@aztec/test-wallet/server';
6
10
 
7
11
  import { BaseBot } from './base_bot.js';
8
12
  import type { BotConfig } from './config.js';
9
13
  import { BotFactory } from './factory.js';
14
+ import type { BotStore } from './store/index.js';
10
15
 
11
16
  const TRANSFER_BASE_AMOUNT = 1_000;
12
17
  const TRANSFER_VARIANCE = 200;
@@ -15,26 +20,32 @@ type Balances = { token0: bigint; token1: bigint };
15
20
 
16
21
  export class AmmBot extends BaseBot {
17
22
  protected constructor(
18
- pxe: PXE,
19
- wallet: Wallet,
23
+ node: AztecNode,
24
+ wallet: TestWallet,
20
25
  defaultAccountAddress: AztecAddress,
21
26
  public readonly amm: AMMContract,
22
27
  public readonly token0: TokenContract,
23
28
  public readonly token1: TokenContract,
24
29
  config: BotConfig,
25
30
  ) {
26
- super(pxe, wallet, defaultAccountAddress, config);
31
+ super(node, wallet, defaultAccountAddress, config);
27
32
  }
28
33
 
29
34
  static async create(
30
35
  config: BotConfig,
31
- dependencies: { pxe?: PXE; node?: AztecNode; nodeAdmin?: AztecNodeAdmin },
36
+ wallet: TestWallet,
37
+ aztecNode: AztecNode,
38
+ aztecNodeAdmin: AztecNodeAdmin | undefined,
39
+ store: BotStore,
32
40
  ): Promise<AmmBot> {
33
- const { pxe, wallet, defaultAccountAddress, token0, token1, amm } = await new BotFactory(
41
+ const { defaultAccountAddress, token0, token1, amm } = await new BotFactory(
34
42
  config,
35
- dependencies,
43
+ wallet,
44
+ store,
45
+ aztecNode,
46
+ aztecNodeAdmin,
36
47
  ).setupAmm();
37
- return new AmmBot(pxe, wallet, defaultAccountAddress, amm, token0, token1, config);
48
+ return new AmmBot(aztecNode, wallet, defaultAccountAddress, amm, token0, token1, config);
38
49
  }
39
50
 
40
51
  protected async createAndSendTx(logCtx: object): Promise<SentTx> {
@@ -53,9 +64,11 @@ export class AmmBot extends BaseBot {
53
64
 
54
65
  const [tokenIn, tokenOut] = Math.random() < 0.5 ? [token0, token1] : [token1, token0];
55
66
 
56
- const swapAuthwit = await wallet.createAuthWit({
67
+ const swapAuthwit = await wallet.createAuthWit(this.defaultAccountAddress, {
57
68
  caller: amm.address,
58
- action: tokenIn.methods.transfer_to_public(this.defaultAccountAddress, amm.address, amountIn, authwitNonce),
69
+ call: await tokenIn.methods
70
+ .transfer_to_public(this.defaultAccountAddress, amm.address, amountIn, authwitNonce)
71
+ .getFunctionCall(),
59
72
  });
60
73
 
61
74
  const amountOutMin = await amm.methods
@@ -66,22 +79,17 @@ export class AmmBot extends BaseBot {
66
79
  )
67
80
  .simulate({ from: this.defaultAccountAddress });
68
81
 
69
- const swapExactTokensInteraction = amm.methods.swap_exact_tokens_for_tokens(
70
- tokenIn.address,
71
- tokenOut.address,
72
- amountIn,
73
- amountOutMin,
74
- authwitNonce,
75
- );
82
+ const swapExactTokensInteraction = amm.methods
83
+ .swap_exact_tokens_for_tokens(tokenIn.address, tokenOut.address, amountIn, amountOutMin, authwitNonce)
84
+ .with({
85
+ authWitnesses: [swapAuthwit],
86
+ });
76
87
 
77
- const opts = this.getSendMethodOpts(swapAuthwit);
78
-
79
- this.log.verbose(`Proving transaction`, logCtx);
80
- const tx = await swapExactTokensInteraction.prove(opts);
88
+ const opts = await this.getSendMethodOpts(swapExactTokensInteraction);
81
89
 
90
+ this.log.verbose(`Sending transaction`, logCtx);
82
91
  this.log.info(`Tx. Balances: ${jsonStringify(balances)}`, { ...logCtx, balances });
83
-
84
- return tx.send();
92
+ return swapExactTokensInteraction.send(opts);
85
93
  }
86
94
 
87
95
  protected override async onTxMined(receipt: TxReceipt, logCtx: object): Promise<void> {
@@ -97,20 +105,20 @@ export class AmmBot extends BaseBot {
97
105
  return {
98
106
  senderPublic: await this.getPublicBalanceFor(this.defaultAccountAddress),
99
107
  senderPrivate: await this.getPrivateBalanceFor(this.defaultAccountAddress),
100
- amm: await this.getPublicBalanceFor(this.amm.address),
108
+ amm: await this.getPublicBalanceFor(this.amm.address, this.defaultAccountAddress),
101
109
  };
102
110
  }
103
111
 
104
- private async getPublicBalanceFor(address: AztecAddress): Promise<Balances> {
112
+ private async getPublicBalanceFor(address: AztecAddress, from?: AztecAddress): Promise<Balances> {
105
113
  return {
106
- token0: await this.token0.methods.balance_of_public(address).simulate({ from: address }),
107
- token1: await this.token1.methods.balance_of_public(address).simulate({ from: address }),
114
+ token0: await this.token0.methods.balance_of_public(address).simulate({ from: from ?? address }),
115
+ token1: await this.token1.methods.balance_of_public(address).simulate({ from: from ?? address }),
108
116
  };
109
117
  }
110
- private async getPrivateBalanceFor(address: AztecAddress): Promise<Balances> {
118
+ private async getPrivateBalanceFor(address: AztecAddress, from?: AztecAddress): Promise<Balances> {
111
119
  return {
112
- token0: await this.token0.methods.balance_of_private(address).simulate({ from: address }),
113
- token1: await this.token1.methods.balance_of_private(address).simulate({ from: address }),
120
+ token0: await this.token0.methods.balance_of_private(address).simulate({ from: from ?? address }),
121
+ token1: await this.token1.methods.balance_of_private(address).simulate({ from: from ?? address }),
114
122
  };
115
123
  }
116
124
  }
package/src/base_bot.ts CHANGED
@@ -1,17 +1,16 @@
1
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
1
2
  import {
2
- AuthWitness,
3
- AztecAddress,
4
- FeeJuicePaymentMethod,
5
- type SendMethodOptions,
3
+ BatchCall,
4
+ ContractFunctionInteraction,
5
+ type SendInteractionOptions,
6
6
  SentTx,
7
- TxHash,
8
- TxReceipt,
9
- type Wallet,
10
- createLogger,
11
7
  waitForProven,
12
- } from '@aztec/aztec.js';
8
+ } from '@aztec/aztec.js/contracts';
9
+ import { createLogger } from '@aztec/aztec.js/log';
10
+ import { TxHash, TxReceipt } from '@aztec/aztec.js/tx';
13
11
  import { Gas } from '@aztec/stdlib/gas';
14
- import type { PXE } from '@aztec/stdlib/interfaces/client';
12
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
13
+ import type { TestWallet } from '@aztec/test-wallet/server';
15
14
 
16
15
  import type { BotConfig } from './config.js';
17
16
 
@@ -22,8 +21,8 @@ export abstract class BaseBot {
22
21
  protected successes: number = 0;
23
22
 
24
23
  protected constructor(
25
- public readonly pxe: PXE,
26
- public readonly wallet: Wallet,
24
+ public readonly node: AztecNode,
25
+ public readonly wallet: TestWallet,
27
26
  public readonly defaultAccountAddress: AztecAddress,
28
27
  public config: BotConfig,
29
28
  ) {}
@@ -51,7 +50,7 @@ export abstract class BaseBot {
51
50
  timeout: txMinedWaitSeconds,
52
51
  });
53
52
  if (followChain === 'PROVEN') {
54
- await waitForProven(this.pxe, receipt, { provenTimeout: txMinedWaitSeconds });
53
+ await waitForProven(this.node, receipt, { provenTimeout: txMinedWaitSeconds });
55
54
  }
56
55
  this.successes++;
57
56
  this.log.info(
@@ -71,24 +70,27 @@ export abstract class BaseBot {
71
70
  return Promise.resolve();
72
71
  }
73
72
 
74
- protected getSendMethodOpts(...authWitnesses: AuthWitness[]): SendMethodOptions {
75
- const { l2GasLimit, daGasLimit } = this.config;
76
- const paymentMethod = new FeeJuicePaymentMethod(this.defaultAccountAddress);
73
+ protected async getSendMethodOpts(
74
+ interaction: ContractFunctionInteraction | BatchCall,
75
+ ): Promise<SendInteractionOptions> {
76
+ const { l2GasLimit, daGasLimit, baseFeePadding } = this.config;
77
77
 
78
- let gasSettings, estimateGas;
78
+ this.wallet.setBaseFeePadding(baseFeePadding);
79
+
80
+ let gasSettings;
79
81
  if (l2GasLimit !== undefined && l2GasLimit > 0 && daGasLimit !== undefined && daGasLimit > 0) {
80
82
  gasSettings = { gasLimits: Gas.from({ l2Gas: l2GasLimit, daGas: daGasLimit }) };
81
- estimateGas = false;
82
83
  this.log.verbose(`Using gas limits ${l2GasLimit} L2 gas ${daGasLimit} DA gas`);
83
84
  } else {
84
- estimateGas = true;
85
85
  this.log.verbose(`Estimating gas for transaction`);
86
+ ({ estimatedGas: gasSettings } = await interaction.simulate({
87
+ fee: { estimateGas: true },
88
+ from: this.defaultAccountAddress,
89
+ }));
86
90
  }
87
- const baseFeePadding = 2; // Send 3x the current base fee
88
91
  return {
89
92
  from: this.defaultAccountAddress,
90
- fee: { estimateGas, paymentMethod, gasSettings, baseFeePadding },
91
- authWitnesses,
93
+ fee: { gasSettings },
92
94
  };
93
95
  }
94
96
  }
package/src/bot.ts CHANGED
@@ -1,34 +1,46 @@
1
- import { type AztecAddress, BatchCall, SentTx, type Wallet } from '@aztec/aztec.js';
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { BatchCall, SentTx } from '@aztec/aztec.js/contracts';
2
3
  import { times } from '@aztec/foundation/collection';
3
4
  import type { PrivateTokenContract } from '@aztec/noir-contracts.js/PrivateToken';
4
5
  import type { TokenContract } from '@aztec/noir-contracts.js/Token';
5
- import type { AztecNode, AztecNodeAdmin, PXE } from '@aztec/stdlib/interfaces/client';
6
+ import type { AztecNode, AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
7
+ import type { TestWallet } from '@aztec/test-wallet/server';
6
8
 
7
9
  import { BaseBot } from './base_bot.js';
8
10
  import type { BotConfig } from './config.js';
9
11
  import { BotFactory } from './factory.js';
12
+ import type { BotStore } from './store/index.js';
10
13
  import { getBalances, getPrivateBalance, isStandardTokenContract } from './utils.js';
11
14
 
12
15
  const TRANSFER_AMOUNT = 1;
13
16
 
14
17
  export class Bot extends BaseBot {
15
18
  protected constructor(
16
- pxe: PXE,
17
- wallet: Wallet,
19
+ node: AztecNode,
20
+ wallet: TestWallet,
18
21
  defaultAccountAddress: AztecAddress,
19
22
  public readonly token: TokenContract | PrivateTokenContract,
20
23
  public readonly recipient: AztecAddress,
21
24
  config: BotConfig,
22
25
  ) {
23
- super(pxe, wallet, defaultAccountAddress, config);
26
+ super(node, wallet, defaultAccountAddress, config);
24
27
  }
25
28
 
26
29
  static async create(
27
30
  config: BotConfig,
28
- dependencies: { pxe?: PXE; node?: AztecNode; nodeAdmin?: AztecNodeAdmin },
31
+ wallet: TestWallet,
32
+ aztecNode: AztecNode,
33
+ aztecNodeAdmin: AztecNodeAdmin | undefined,
34
+ store: BotStore,
29
35
  ): Promise<Bot> {
30
- const { pxe, wallet, defaultAccountAddress, token, recipient } = await new BotFactory(config, dependencies).setup();
31
- return new Bot(pxe, wallet, defaultAccountAddress, token, recipient, config);
36
+ const { defaultAccountAddress, token, recipient } = await new BotFactory(
37
+ config,
38
+ wallet,
39
+ store,
40
+ aztecNode,
41
+ aztecNodeAdmin,
42
+ ).setup();
43
+ return new Bot(aztecNode, wallet, defaultAccountAddress, token, recipient, config);
32
44
  }
33
45
 
34
46
  public updateConfig(config: Partial<BotConfig>) {
@@ -56,22 +68,21 @@ export class Bot extends BaseBot {
56
68
  token.methods.transfer(TRANSFER_AMOUNT, this.defaultAccountAddress, recipient),
57
69
  );
58
70
 
59
- const opts = this.getSendMethodOpts();
60
71
  const batch = new BatchCall(wallet, calls);
72
+ const opts = await this.getSendMethodOpts(batch);
61
73
 
62
74
  this.log.verbose(`Simulating transaction with ${calls.length}`, logCtx);
63
75
  await batch.simulate({ from: this.defaultAccountAddress });
64
76
 
65
- this.log.verbose(`Proving transaction`, logCtx);
66
- const provenTx = await batch.prove(opts);
67
- return provenTx.send();
77
+ this.log.verbose(`Sending transaction`, logCtx);
78
+ return batch.send(opts);
68
79
  }
69
80
 
70
81
  public async getBalances() {
71
82
  if (isStandardTokenContract(this.token)) {
72
83
  return {
73
84
  sender: await getBalances(this.token, this.defaultAccountAddress),
74
- recipient: await getBalances(this.token, this.recipient),
85
+ recipient: await getBalances(this.token, this.recipient, this.defaultAccountAddress),
75
86
  };
76
87
  } else {
77
88
  return {
@@ -80,7 +91,7 @@ export class Bot extends BaseBot {
80
91
  publicBalance: 0n,
81
92
  },
82
93
  recipient: {
83
- privateBalance: await getPrivateBalance(this.token, this.recipient),
94
+ privateBalance: await getPrivateBalance(this.token, this.recipient, this.defaultAccountAddress),
84
95
  publicBalance: 0n,
85
96
  },
86
97
  };