@aztec/bot 3.0.0-canary.a9708bd → 3.0.0-devnet.3
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 +8 -8
- package/dest/amm_bot.d.ts.map +1 -1
- package/dest/amm_bot.js +23 -20
- package/dest/base_bot.d.ts +10 -7
- package/dest/base_bot.d.ts.map +1 -1
- package/dest/base_bot.js +18 -18
- package/dest/bot.d.ts +7 -8
- package/dest/bot.d.ts.map +1 -1
- package/dest/bot.js +11 -12
- package/dest/config.d.ts +32 -28
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +29 -23
- package/dest/factory.d.ts +18 -18
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +126 -113
- package/dest/index.d.ts +1 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/interface.d.ts +1 -1
- package/dest/interface.d.ts.map +1 -1
- package/dest/interface.js +1 -1
- package/dest/runner.d.ts +11 -12
- package/dest/runner.d.ts.map +1 -1
- package/dest/runner.js +18 -32
- 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 +3 -3
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +5 -5
- package/package.json +13 -11
- package/src/amm_bot.ts +39 -31
- package/src/base_bot.ts +24 -22
- package/src/bot.ts +25 -14
- package/src/config.ts +31 -29
- package/src/factory.ts +144 -153
- 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
package/src/bot.ts
CHANGED
|
@@ -1,34 +1,46 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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
|
-
|
|
17
|
-
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(
|
|
26
|
+
super(node, wallet, defaultAccountAddress, config);
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
static async create(
|
|
27
30
|
config: BotConfig,
|
|
28
|
-
|
|
31
|
+
wallet: TestWallet,
|
|
32
|
+
aztecNode: AztecNode,
|
|
33
|
+
aztecNodeAdmin: AztecNodeAdmin | undefined,
|
|
34
|
+
store: BotStore,
|
|
29
35
|
): Promise<Bot> {
|
|
30
|
-
const {
|
|
31
|
-
|
|
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(`
|
|
66
|
-
|
|
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
|
};
|
package/src/config.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type ConfigMappingsType,
|
|
3
|
-
|
|
3
|
+
SecretValue,
|
|
4
4
|
booleanConfigHelper,
|
|
5
5
|
getConfigFromMappings,
|
|
6
6
|
getDefaultConfig,
|
|
7
7
|
numberConfigHelper,
|
|
8
8
|
optionalNumberConfigHelper,
|
|
9
|
+
pickConfigMappings,
|
|
9
10
|
secretFrConfigHelper,
|
|
10
11
|
secretStringConfigHelper,
|
|
11
12
|
} from '@aztec/foundation/config';
|
|
12
13
|
import { Fr } from '@aztec/foundation/fields';
|
|
14
|
+
import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
|
|
13
15
|
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
14
|
-
import {
|
|
16
|
+
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
15
17
|
import { type ZodFor, schemas } from '@aztec/stdlib/schemas';
|
|
16
18
|
import type { ComponentsVersions } from '@aztec/stdlib/versioning';
|
|
17
19
|
|
|
@@ -30,22 +32,18 @@ export type BotConfig = {
|
|
|
30
32
|
nodeUrl: string | undefined;
|
|
31
33
|
/** The URL to the Aztec node admin API to force-flush txs if configured. */
|
|
32
34
|
nodeAdminUrl: string | undefined;
|
|
33
|
-
/** URL to the PXE for sending txs, or undefined if an in-proc PXE is used. */
|
|
34
|
-
pxeUrl: string | undefined;
|
|
35
35
|
/** Url of the ethereum host. */
|
|
36
36
|
l1RpcUrls: string[] | undefined;
|
|
37
37
|
/** The mnemonic for the account to bridge fee juice from L1. */
|
|
38
|
-
l1Mnemonic: SecretValue<string | undefined
|
|
38
|
+
l1Mnemonic: SecretValue<string> | undefined;
|
|
39
39
|
/** The private key for the account to bridge fee juice from L1. */
|
|
40
|
-
l1PrivateKey: SecretValue<string | undefined
|
|
40
|
+
l1PrivateKey: SecretValue<string> | undefined;
|
|
41
41
|
/** How long to wait for L1 to L2 messages to become available on L2 */
|
|
42
42
|
l1ToL2MessageTimeoutSeconds: number;
|
|
43
43
|
/** Signing private key for the sender account. */
|
|
44
|
-
senderPrivateKey: SecretValue<Fr | undefined
|
|
44
|
+
senderPrivateKey: SecretValue<Fr> | undefined;
|
|
45
45
|
/** Optional salt to use to instantiate the sender account */
|
|
46
46
|
senderSalt: Fr | undefined;
|
|
47
|
-
/** Encryption secret for a recipient account. */
|
|
48
|
-
recipientEncryptionSecret: SecretValue<Fr>;
|
|
49
47
|
/** Salt for the token contract instantiation. */
|
|
50
48
|
tokenSalt: Fr;
|
|
51
49
|
/** Every how many seconds should a new tx be sent. */
|
|
@@ -56,6 +54,8 @@ export type BotConfig = {
|
|
|
56
54
|
publicTransfersPerTx: number;
|
|
57
55
|
/** How to handle fee payments. */
|
|
58
56
|
feePaymentMethod: 'fee_juice';
|
|
57
|
+
/** 'How much is the bot willing to overpay vs. the current base fee' */
|
|
58
|
+
baseFeePadding: number;
|
|
59
59
|
/** True to not automatically setup or start the bot on initialization. */
|
|
60
60
|
noStart: boolean;
|
|
61
61
|
/** How long to wait for a tx to be mined before reporting an error. */
|
|
@@ -78,25 +78,24 @@ export type BotConfig = {
|
|
|
78
78
|
stopWhenUnhealthy: boolean;
|
|
79
79
|
/** Deploy an AMM contract and do swaps instead of transfers */
|
|
80
80
|
ammTxs: boolean;
|
|
81
|
-
}
|
|
81
|
+
} & Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb'>;
|
|
82
82
|
|
|
83
83
|
export const BotConfigSchema = z
|
|
84
84
|
.object({
|
|
85
85
|
nodeUrl: z.string().optional(),
|
|
86
86
|
nodeAdminUrl: z.string().optional(),
|
|
87
|
-
pxeUrl: z.string().optional(),
|
|
88
87
|
l1RpcUrls: z.array(z.string()).optional(),
|
|
89
|
-
l1Mnemonic: schemas.SecretValue(z.string().optional()
|
|
90
|
-
l1PrivateKey: schemas.SecretValue(z.string().optional()
|
|
88
|
+
l1Mnemonic: schemas.SecretValue(z.string()).optional(),
|
|
89
|
+
l1PrivateKey: schemas.SecretValue(z.string()).optional(),
|
|
91
90
|
l1ToL2MessageTimeoutSeconds: z.number(),
|
|
92
|
-
senderPrivateKey: schemas.SecretValue(schemas.Fr.optional()
|
|
91
|
+
senderPrivateKey: schemas.SecretValue(schemas.Fr).optional(),
|
|
93
92
|
senderSalt: schemas.Fr.optional(),
|
|
94
|
-
recipientEncryptionSecret: schemas.SecretValue(schemas.Fr),
|
|
95
93
|
tokenSalt: schemas.Fr,
|
|
96
94
|
txIntervalSeconds: z.number(),
|
|
97
95
|
privateTransfersPerTx: z.number().int().nonnegative(),
|
|
98
96
|
publicTransfersPerTx: z.number().int().nonnegative(),
|
|
99
97
|
feePaymentMethod: z.literal('fee_juice'),
|
|
98
|
+
baseFeePadding: z.number().int().nonnegative(),
|
|
100
99
|
noStart: z.boolean(),
|
|
101
100
|
txMinedWaitSeconds: z.number(),
|
|
102
101
|
followChain: z.enum(BotFollowChain),
|
|
@@ -108,15 +107,21 @@ export const BotConfigSchema = z
|
|
|
108
107
|
maxConsecutiveErrors: z.number().int().nonnegative(),
|
|
109
108
|
stopWhenUnhealthy: z.boolean(),
|
|
110
109
|
ammTxs: z.boolean().default(false),
|
|
110
|
+
dataDirectory: z.string().optional(),
|
|
111
|
+
dataStoreMapSizeKb: z.number().optional(),
|
|
111
112
|
})
|
|
112
113
|
.transform(config => ({
|
|
113
114
|
nodeUrl: undefined,
|
|
114
115
|
nodeAdminUrl: undefined,
|
|
115
|
-
pxeUrl: undefined,
|
|
116
116
|
l1RpcUrls: undefined,
|
|
117
117
|
senderSalt: undefined,
|
|
118
118
|
l2GasLimit: undefined,
|
|
119
119
|
daGasLimit: undefined,
|
|
120
|
+
l1Mnemonic: undefined,
|
|
121
|
+
l1PrivateKey: undefined,
|
|
122
|
+
senderPrivateKey: undefined,
|
|
123
|
+
dataDirectory: undefined,
|
|
124
|
+
dataStoreMapSizeKb: 1_024 * 1_024,
|
|
120
125
|
...config,
|
|
121
126
|
})) satisfies ZodFor<BotConfig>;
|
|
122
127
|
|
|
@@ -129,10 +134,6 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
|
|
|
129
134
|
env: 'AZTEC_NODE_ADMIN_URL',
|
|
130
135
|
description: 'The URL to the Aztec node admin API to force-flush txs if configured.',
|
|
131
136
|
},
|
|
132
|
-
pxeUrl: {
|
|
133
|
-
env: 'BOT_PXE_URL',
|
|
134
|
-
description: 'URL to the PXE for sending txs, or undefined if an in-proc PXE is used.',
|
|
135
|
-
},
|
|
136
137
|
l1RpcUrls: {
|
|
137
138
|
env: 'ETHEREUM_HOSTS',
|
|
138
139
|
description: 'URL of the ethereum host.',
|
|
@@ -151,7 +152,7 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
|
|
|
151
152
|
l1ToL2MessageTimeoutSeconds: {
|
|
152
153
|
env: 'BOT_L1_TO_L2_TIMEOUT_SECONDS',
|
|
153
154
|
description: 'How long to wait for L1 to L2 messages to become available on L2',
|
|
154
|
-
...numberConfigHelper(
|
|
155
|
+
...numberConfigHelper(3600),
|
|
155
156
|
},
|
|
156
157
|
senderPrivateKey: {
|
|
157
158
|
env: 'BOT_PRIVATE_KEY',
|
|
@@ -160,17 +161,12 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
|
|
|
160
161
|
},
|
|
161
162
|
senderSalt: {
|
|
162
163
|
env: 'BOT_ACCOUNT_SALT',
|
|
163
|
-
description: 'The salt to use to
|
|
164
|
+
description: 'The salt to use to deploy the sender account.',
|
|
164
165
|
parseEnv: (val: string) => (val ? Fr.fromHexString(val) : undefined),
|
|
165
166
|
},
|
|
166
|
-
recipientEncryptionSecret: {
|
|
167
|
-
env: 'BOT_RECIPIENT_ENCRYPTION_SECRET',
|
|
168
|
-
description: 'Encryption secret for a recipient account.',
|
|
169
|
-
...secretFrConfigHelper(Fr.fromHexString('0xcafecafe')),
|
|
170
|
-
},
|
|
171
167
|
tokenSalt: {
|
|
172
168
|
env: 'BOT_TOKEN_SALT',
|
|
173
|
-
description: '
|
|
169
|
+
description: 'The salt to use to deploy the token contract.',
|
|
174
170
|
parseEnv: (val: string) => Fr.fromHexString(val),
|
|
175
171
|
defaultValue: Fr.fromHexString('1'),
|
|
176
172
|
},
|
|
@@ -195,6 +191,11 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
|
|
|
195
191
|
parseEnv: val => (val as 'fee_juice') || undefined,
|
|
196
192
|
defaultValue: 'fee_juice',
|
|
197
193
|
},
|
|
194
|
+
baseFeePadding: {
|
|
195
|
+
env: 'BOT_BASE_FEE_PADDING',
|
|
196
|
+
description: 'How much is the bot willing to overpay vs. the current base fee',
|
|
197
|
+
...numberConfigHelper(3),
|
|
198
|
+
},
|
|
198
199
|
noStart: {
|
|
199
200
|
env: 'BOT_NO_START',
|
|
200
201
|
description: 'True to not automatically setup or start the bot on initialization.',
|
|
@@ -266,6 +267,7 @@ export const botConfigMappings: ConfigMappingsType<BotConfig> = {
|
|
|
266
267
|
description: 'Deploy an AMM and send swaps to it',
|
|
267
268
|
...booleanConfigHelper(false),
|
|
268
269
|
},
|
|
270
|
+
...pickConfigMappings(dataConfigMappings, ['dataStoreMapSizeKb', 'dataDirectory']),
|
|
269
271
|
};
|
|
270
272
|
|
|
271
273
|
export function getBotConfigFromEnv(): BotConfig {
|
|
@@ -278,7 +280,7 @@ export function getBotDefaultConfig(): BotConfig {
|
|
|
278
280
|
|
|
279
281
|
export function getVersions(): Partial<ComponentsVersions> {
|
|
280
282
|
return {
|
|
281
|
-
|
|
283
|
+
l2ProtocolContractsHash: protocolContractsHash.toString(),
|
|
282
284
|
l2CircuitsVkTreeRoot: getVKTreeRoot().toString(),
|
|
283
285
|
};
|
|
284
286
|
}
|