@aztec/aztec 0.0.0-test.1 → 0.0.1-commit.b655e406
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/bin/index.js +20 -12
- package/dest/cli/aztec_start_action.d.ts.map +1 -1
- package/dest/cli/aztec_start_action.js +32 -33
- package/dest/cli/aztec_start_options.d.ts +4 -2
- package/dest/cli/aztec_start_options.d.ts.map +1 -1
- package/dest/cli/aztec_start_options.js +137 -207
- package/dest/cli/cli.d.ts.map +1 -1
- package/dest/cli/cli.js +4 -0
- package/dest/cli/cmds/start_archiver.d.ts.map +1 -1
- package/dest/cli/cmds/start_archiver.js +18 -10
- package/dest/cli/cmds/start_blob_sink.d.ts.map +1 -1
- package/dest/cli/cmds/start_blob_sink.js +17 -1
- package/dest/cli/cmds/start_bot.d.ts +3 -6
- package/dest/cli/cmds/start_bot.d.ts.map +1 -1
- package/dest/cli/cmds/start_bot.js +24 -13
- package/dest/cli/cmds/start_node.d.ts +1 -1
- package/dest/cli/cmds/start_node.d.ts.map +1 -1
- package/dest/cli/cmds/start_node.js +66 -79
- package/dest/cli/cmds/start_p2p_bootstrap.d.ts.map +1 -1
- package/dest/cli/cmds/start_p2p_bootstrap.js +9 -4
- package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -1
- package/dest/cli/cmds/start_prover_agent.js +31 -2
- package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -1
- package/dest/cli/cmds/start_prover_broker.js +9 -3
- package/dest/cli/cmds/start_prover_node.d.ts.map +1 -1
- package/dest/cli/cmds/start_prover_node.js +43 -45
- package/dest/cli/preload_crs.d.ts +3 -0
- package/dest/cli/preload_crs.d.ts.map +1 -0
- package/dest/cli/preload_crs.js +6 -0
- package/dest/cli/release_version.d.ts +2 -0
- package/dest/cli/release_version.d.ts.map +1 -0
- package/dest/cli/release_version.js +14 -0
- package/dest/cli/util.d.ts +36 -5
- package/dest/cli/util.d.ts.map +1 -1
- package/dest/cli/util.js +198 -28
- package/dest/cli/versioning.js +3 -3
- package/dest/examples/token.js +31 -18
- package/dest/examples/util.d.ts +4 -5
- package/dest/examples/util.d.ts.map +1 -1
- package/dest/examples/util.js +5 -6
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/sandbox/banana_fpc.d.ts +4 -5
- package/dest/sandbox/banana_fpc.d.ts.map +1 -1
- package/dest/sandbox/banana_fpc.js +19 -21
- package/dest/sandbox/index.d.ts +2 -3
- package/dest/sandbox/index.d.ts.map +1 -1
- package/dest/sandbox/index.js +2 -3
- package/dest/sandbox/sandbox.d.ts +25 -27
- package/dest/sandbox/sandbox.d.ts.map +1 -1
- package/dest/sandbox/sandbox.js +51 -49
- package/dest/sandbox/sponsored_fpc.d.ts +3 -5
- package/dest/sandbox/sponsored_fpc.d.ts.map +1 -1
- package/dest/sandbox/sponsored_fpc.js +10 -18
- package/dest/testing/anvil_test_watcher.d.ts +34 -0
- package/dest/testing/anvil_test_watcher.d.ts.map +1 -0
- package/dest/testing/anvil_test_watcher.js +142 -0
- package/dest/testing/cheat_codes.d.ts +43 -0
- package/dest/testing/cheat_codes.d.ts.map +1 -0
- package/dest/testing/cheat_codes.js +62 -0
- package/dest/testing/index.d.ts +4 -0
- package/dest/testing/index.d.ts.map +1 -0
- package/dest/testing/index.js +3 -0
- package/package.json +47 -41
- package/src/bin/index.ts +24 -12
- package/src/cli/aztec_start_action.ts +27 -30
- package/src/cli/aztec_start_options.ts +155 -207
- package/src/cli/cli.ts +8 -0
- package/src/cli/cmds/start_archiver.ts +19 -13
- package/src/cli/cmds/start_blob_sink.ts +27 -1
- package/src/cli/cmds/start_bot.ts +35 -12
- package/src/cli/cmds/start_node.ts +89 -84
- package/src/cli/cmds/start_p2p_bootstrap.ts +12 -4
- package/src/cli/cmds/start_prover_agent.ts +22 -2
- package/src/cli/cmds/start_prover_broker.ts +23 -3
- package/src/cli/cmds/start_prover_node.ts +53 -50
- package/src/cli/preload_crs.ts +7 -0
- package/src/cli/release_version.ts +21 -0
- package/src/cli/util.ts +208 -34
- package/src/cli/versioning.ts +3 -3
- package/src/examples/token.ts +23 -19
- package/src/examples/util.ts +6 -8
- package/src/index.ts +3 -4
- package/src/sandbox/banana_fpc.ts +20 -25
- package/src/sandbox/index.ts +5 -3
- package/src/sandbox/sandbox.ts +70 -57
- package/src/sandbox/sponsored_fpc.ts +12 -25
- package/src/testing/anvil_test_watcher.ts +164 -0
- package/src/testing/cheat_codes.ts +78 -0
- package/src/testing/index.ts +3 -0
- package/dest/cli/chain_l2_config.d.ts +0 -19
- package/dest/cli/chain_l2_config.d.ts.map +0 -1
- package/dest/cli/chain_l2_config.js +0 -56
- package/dest/cli/cmds/start_faucet.d.ts +0 -4
- package/dest/cli/cmds/start_faucet.d.ts.map +0 -1
- package/dest/cli/cmds/start_faucet.js +0 -20
- package/dest/cli/cmds/start_pxe.d.ts +0 -16
- package/dest/cli/cmds/start_pxe.d.ts.map +0 -1
- package/dest/cli/cmds/start_pxe.js +0 -95
- package/dest/cli/get_l1_config.d.ts +0 -7
- package/dest/cli/get_l1_config.d.ts.map +0 -1
- package/dest/cli/get_l1_config.js +0 -13
- package/dest/sandbox/sponsored_fee_payment_method.d.ts +0 -23
- package/dest/sandbox/sponsored_fee_payment_method.d.ts.map +0 -1
- package/dest/sandbox/sponsored_fee_payment_method.js +0 -36
- package/src/cli/chain_l2_config.ts +0 -74
- package/src/cli/cmds/start_faucet.ts +0 -34
- package/src/cli/cmds/start_pxe.ts +0 -129
- package/src/cli/get_l1_config.ts +0 -18
- package/src/sandbox/sponsored_fee_payment_method.ts +0 -46
package/src/cli/util.ts
CHANGED
|
@@ -1,33 +1,75 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AztecNodeConfig } from '@aztec/aztec-node';
|
|
2
|
+
import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
3
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
4
|
+
import { AccountManager } from '@aztec/aztec.js/wallet';
|
|
5
|
+
import type { ViemClient } from '@aztec/ethereum';
|
|
2
6
|
import type { ConfigMappingsType } from '@aztec/foundation/config';
|
|
3
|
-
import type
|
|
4
|
-
import type {
|
|
7
|
+
import { type LogFn, createLogger } from '@aztec/foundation/log';
|
|
8
|
+
import type { SharedNodeConfig } from '@aztec/node-lib/config';
|
|
9
|
+
import type { ProverConfig } from '@aztec/stdlib/interfaces/server';
|
|
10
|
+
import { UpdateChecker } from '@aztec/stdlib/update-checker';
|
|
11
|
+
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
12
|
+
import type { TestWallet } from '@aztec/test-wallet/server';
|
|
5
13
|
|
|
6
14
|
import chalk from 'chalk';
|
|
7
15
|
import type { Command } from 'commander';
|
|
8
16
|
|
|
9
17
|
import { type AztecStartOption, aztecStartOptions } from './aztec_start_options.js';
|
|
10
18
|
|
|
19
|
+
export const enum ExitCode {
|
|
20
|
+
SUCCESS = 0,
|
|
21
|
+
ERROR = 1,
|
|
22
|
+
ROLLUP_UPGRADE = 78, // EX_CONFIG from FreeBSD (https://man.freebsd.org/cgi/man.cgi?query=sysexits)
|
|
23
|
+
VERSION_UPGRADE = 79, // prev + 1 because there's nothing better
|
|
24
|
+
// 128 + int(SIGNAL)
|
|
25
|
+
SIGHUP = 129,
|
|
26
|
+
SIGINT = 130,
|
|
27
|
+
SIGQUIT = 131,
|
|
28
|
+
SIGTERM = 143,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let shutdownPromise: Promise<never> | undefined;
|
|
32
|
+
export function shutdown(logFn: LogFn, exitCode: ExitCode, cb?: Array<() => Promise<void>>): Promise<never> {
|
|
33
|
+
if (shutdownPromise) {
|
|
34
|
+
logFn('Already shutting down.');
|
|
35
|
+
return shutdownPromise;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
logFn('Shutting down...', { exitCode });
|
|
39
|
+
if (cb) {
|
|
40
|
+
shutdownPromise = Promise.allSettled(cb).then(() => process.exit(exitCode));
|
|
41
|
+
} else {
|
|
42
|
+
// synchronously shuts down the process
|
|
43
|
+
// no need to set shutdownPromise on this branch of the if statement because no more code will be executed
|
|
44
|
+
process.exit(exitCode);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return shutdownPromise;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function isShuttingDown(): boolean {
|
|
51
|
+
return shutdownPromise !== undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
11
54
|
export const installSignalHandlers = (logFn: LogFn, cb?: Array<() => Promise<void>>) => {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
process.once('SIGTERM', shutdown);
|
|
55
|
+
const signals = [
|
|
56
|
+
['SIGINT', ExitCode.SIGINT],
|
|
57
|
+
['SIGTERM', ExitCode.SIGTERM],
|
|
58
|
+
['SIGHUP', ExitCode.SIGHUP],
|
|
59
|
+
['SIQUIT', ExitCode.SIGQUIT],
|
|
60
|
+
] as const;
|
|
61
|
+
|
|
62
|
+
for (const [signal, exitCode] of signals) {
|
|
63
|
+
process.removeAllListeners(signal);
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
65
|
+
process.once(signal, () => shutdown(logFn, exitCode, cb));
|
|
66
|
+
}
|
|
25
67
|
};
|
|
26
68
|
|
|
27
69
|
/**
|
|
28
70
|
* Creates logs for the initial accounts
|
|
29
71
|
* @param accounts - The initial accounts
|
|
30
|
-
* @param
|
|
72
|
+
* @param wallet - A TestWallet instance to get the registered accounts
|
|
31
73
|
* @returns A string array containing the initial accounts details
|
|
32
74
|
*/
|
|
33
75
|
export async function createAccountLogs(
|
|
@@ -41,13 +83,13 @@ export async function createAccountLogs(
|
|
|
41
83
|
*/
|
|
42
84
|
secretKey: Fr;
|
|
43
85
|
}[],
|
|
44
|
-
|
|
86
|
+
wallet: TestWallet,
|
|
45
87
|
) {
|
|
46
|
-
const registeredAccounts = await
|
|
88
|
+
const registeredAccounts = await wallet.getAccounts();
|
|
47
89
|
const accountLogStrings = [`Initial Accounts:\n\n`];
|
|
48
90
|
for (const accountWithSecretKey of accountsWithSecretKeys) {
|
|
49
91
|
const completeAddress = await accountWithSecretKey.account.getCompleteAddress();
|
|
50
|
-
if (registeredAccounts.find(a => a.equals(completeAddress))) {
|
|
92
|
+
if (registeredAccounts.find(a => a.item.equals(completeAddress.address))) {
|
|
51
93
|
accountLogStrings.push(` Address: ${completeAddress.address.toString()}\n`);
|
|
52
94
|
accountLogStrings.push(` Partial Address: ${completeAddress.partialAddress.toString()}\n`);
|
|
53
95
|
accountLogStrings.push(` Secret Key: ${accountWithSecretKey.secretKey.toString()}\n`);
|
|
@@ -102,18 +144,32 @@ export function formatHelpLine(
|
|
|
102
144
|
|
|
103
145
|
const getDefaultOrEnvValue = (opt: AztecStartOption) => {
|
|
104
146
|
let val;
|
|
105
|
-
|
|
106
|
-
if
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
147
|
+
|
|
148
|
+
// if the option is set in the environment, use that
|
|
149
|
+
if (opt.env) {
|
|
150
|
+
val = process.env[opt.env];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// if we have fallback env vars, check those
|
|
154
|
+
if (!val && opt.fallback && opt.fallback.length > 0) {
|
|
155
|
+
for (const fallback of opt.fallback) {
|
|
156
|
+
val = process.env[fallback];
|
|
157
|
+
if (val) {
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
110
160
|
}
|
|
111
|
-
// if no env variable, use the default value
|
|
112
|
-
} else if (opt.defaultValue) {
|
|
113
|
-
val = opt.defaultValue;
|
|
114
161
|
}
|
|
115
162
|
|
|
116
|
-
return
|
|
163
|
+
// if we have a value, optionally parse it and return
|
|
164
|
+
if (val) {
|
|
165
|
+
if (opt.parseVal) {
|
|
166
|
+
return opt.parseVal(val);
|
|
167
|
+
}
|
|
168
|
+
return val;
|
|
169
|
+
} else if (opt.defaultValue !== undefined) {
|
|
170
|
+
return opt.defaultValue;
|
|
171
|
+
}
|
|
172
|
+
return undefined;
|
|
117
173
|
};
|
|
118
174
|
|
|
119
175
|
// Function to add options dynamically
|
|
@@ -121,7 +177,7 @@ export const addOptions = (cmd: Command, options: AztecStartOption[]) => {
|
|
|
121
177
|
options.forEach(opt => {
|
|
122
178
|
cmd.option(
|
|
123
179
|
opt.flag,
|
|
124
|
-
`${opt.description} (default: ${opt.defaultValue}) ($${opt.
|
|
180
|
+
`${opt.description} (default: ${opt.defaultValue}) ($${opt.env})`,
|
|
125
181
|
opt.parseVal ? opt.parseVal : val => val,
|
|
126
182
|
getDefaultOrEnvValue(opt),
|
|
127
183
|
);
|
|
@@ -137,10 +193,11 @@ export const printAztecStartHelpText = () => {
|
|
|
137
193
|
helpTextLines.push('');
|
|
138
194
|
|
|
139
195
|
aztecStartOptions[category].forEach(opt => {
|
|
140
|
-
const defaultValueText =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
196
|
+
const defaultValueText =
|
|
197
|
+
opt.defaultValue || (Array.isArray(opt.defaultValue) && opt.defaultValue.length > 0)
|
|
198
|
+
? `(default: ${opt.printDefault ? opt.printDefault(opt.defaultValue) : opt.defaultValue})`
|
|
199
|
+
: '';
|
|
200
|
+
const envVarText = opt.env ? `($${opt.env})` : '';
|
|
144
201
|
const flagText = `${opt.flag}`;
|
|
145
202
|
|
|
146
203
|
const paddedText = formatHelpLine(flagText, defaultValueText, envVarText, maxFlagLength, maxDefaultLength);
|
|
@@ -214,3 +271,120 @@ export const extractRelevantOptions = <T>(
|
|
|
214
271
|
|
|
215
272
|
return relevantOptions;
|
|
216
273
|
};
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Downloads just enough points to be able to verify Chonk proofs.
|
|
277
|
+
* @param opts - Whether proof are to be verifier
|
|
278
|
+
* @param log - Logging function
|
|
279
|
+
*/
|
|
280
|
+
export async function preloadCrsDataForVerifying(
|
|
281
|
+
{ realProofs }: Pick<AztecNodeConfig, 'realProofs'>,
|
|
282
|
+
log: LogFn,
|
|
283
|
+
): Promise<void> {
|
|
284
|
+
if (realProofs) {
|
|
285
|
+
const { Crs, GrumpkinCrs } = await import('@aztec/bb.js');
|
|
286
|
+
await Promise.all([Crs.new(2 ** 1, undefined, log), GrumpkinCrs.new(2 ** 16 + 1, undefined, log)]);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Downloads enough points to be able to prove every server-side circuit
|
|
292
|
+
* @param opts - Whether real proof are to be generated
|
|
293
|
+
* @param log - Logging function
|
|
294
|
+
*/
|
|
295
|
+
export async function preloadCrsDataForServerSideProving(
|
|
296
|
+
{ realProofs }: Pick<ProverConfig, 'realProofs'>,
|
|
297
|
+
log: LogFn,
|
|
298
|
+
): Promise<void> {
|
|
299
|
+
if (realProofs) {
|
|
300
|
+
const { Crs, GrumpkinCrs } = await import('@aztec/bb.js');
|
|
301
|
+
await Promise.all([Crs.new(2 ** 25 + 1, undefined, log), GrumpkinCrs.new(2 ** 18 + 1, undefined, log)]);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export async function setupUpdateMonitor(
|
|
306
|
+
autoUpdateMode: SharedNodeConfig['autoUpdate'],
|
|
307
|
+
updatesLocation: URL,
|
|
308
|
+
followsCanonicalRollup: boolean,
|
|
309
|
+
publicClient: ViemClient,
|
|
310
|
+
registryContractAddress: EthAddress,
|
|
311
|
+
signalHandlers: Array<() => Promise<void>>,
|
|
312
|
+
updateNodeConfig?: (config: object) => Promise<void>,
|
|
313
|
+
) {
|
|
314
|
+
const logger = createLogger('update-check');
|
|
315
|
+
const checker = await UpdateChecker.new({
|
|
316
|
+
baseURL: updatesLocation,
|
|
317
|
+
publicClient,
|
|
318
|
+
registryContractAddress,
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
322
|
+
checker.on('newRollupVersion', async ({ latestVersion, currentVersion }) => {
|
|
323
|
+
if (isShuttingDown()) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// if node follows canonical rollup then this is equivalent to a config update
|
|
328
|
+
if (!followsCanonicalRollup) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (autoUpdateMode === 'config' || autoUpdateMode === 'config-and-version') {
|
|
333
|
+
logger.info(`New rollup version detected. Please restart the node`, { latestVersion, currentVersion });
|
|
334
|
+
await shutdown(logger.info, ExitCode.ROLLUP_UPGRADE, signalHandlers);
|
|
335
|
+
} else if (autoUpdateMode === 'notify') {
|
|
336
|
+
logger.warn(`New rollup detected. Please restart the node`, { latestVersion, currentVersion });
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
341
|
+
checker.on('newNodeVersion', async ({ latestVersion, currentVersion }) => {
|
|
342
|
+
if (isShuttingDown()) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (autoUpdateMode === 'config-and-version') {
|
|
346
|
+
logger.info(`New node version detected. Please update and restart the node`, { latestVersion, currentVersion });
|
|
347
|
+
await shutdown(logger.info, ExitCode.VERSION_UPGRADE, signalHandlers);
|
|
348
|
+
} else if (autoUpdateMode === 'notify') {
|
|
349
|
+
logger.info(`New node version detected. Please update and restart the node`, { latestVersion, currentVersion });
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
354
|
+
checker.on('updateNodeConfig', async config => {
|
|
355
|
+
if (isShuttingDown()) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if ((autoUpdateMode === 'config' || autoUpdateMode === 'config-and-version') && updateNodeConfig) {
|
|
360
|
+
logger.warn(`Config change detected. Updating node`, config);
|
|
361
|
+
try {
|
|
362
|
+
await updateNodeConfig(config);
|
|
363
|
+
} catch (err) {
|
|
364
|
+
logger.warn('Failed to update config', { err });
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
// don't notify on these config changes
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
checker.on('updatePublicTelemetryConfig', config => {
|
|
371
|
+
if (autoUpdateMode === 'config' || autoUpdateMode === 'config-and-version') {
|
|
372
|
+
logger.warn(`Public telemetry config change detected. Updating telemetry client`, config);
|
|
373
|
+
try {
|
|
374
|
+
const publicIncludeMetrics: unknown = (config as any).publicIncludeMetrics;
|
|
375
|
+
if (Array.isArray(publicIncludeMetrics) && publicIncludeMetrics.every(m => typeof m === 'string')) {
|
|
376
|
+
getTelemetryClient().setExportedPublicTelemetry(publicIncludeMetrics);
|
|
377
|
+
}
|
|
378
|
+
const publicMetricsCollectFrom: unknown = (config as any).publicMetricsCollectFrom;
|
|
379
|
+
if (Array.isArray(publicMetricsCollectFrom) && publicMetricsCollectFrom.every(m => typeof m === 'string')) {
|
|
380
|
+
getTelemetryClient().setPublicTelemetryCollectFrom(publicMetricsCollectFrom);
|
|
381
|
+
}
|
|
382
|
+
} catch (err) {
|
|
383
|
+
logger.warn('Failed to update config', { err });
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
// don't notify on these config changes
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
checker.start();
|
|
390
|
+
}
|
package/src/cli/versioning.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
2
|
-
import {
|
|
2
|
+
import { protocolContractsHash } from '@aztec/protocol-contracts';
|
|
3
3
|
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
4
4
|
import { type ComponentsVersions, getComponentsVersionsFromConfig } from '@aztec/stdlib/versioning';
|
|
5
5
|
|
|
6
6
|
export function getVersions(config?: ChainConfig): Partial<ComponentsVersions> {
|
|
7
7
|
return config
|
|
8
|
-
? getComponentsVersionsFromConfig(config,
|
|
8
|
+
? getComponentsVersionsFromConfig(config, protocolContractsHash, getVKTreeRoot())
|
|
9
9
|
: {
|
|
10
10
|
l2CircuitsVkTreeRoot: getVKTreeRoot().toString(),
|
|
11
|
-
|
|
11
|
+
l2ProtocolContractsHash: protocolContractsHash.toString(),
|
|
12
12
|
};
|
|
13
13
|
}
|
package/src/examples/token.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getInitialTestAccountsData } from '@aztec/accounts/testing';
|
|
2
|
+
import { createAztecNodeClient } from '@aztec/aztec.js/node';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
5
|
+
import { TestWallet } from '@aztec/test-wallet/server';
|
|
5
6
|
|
|
6
7
|
const logger = createLogger('example:token');
|
|
7
8
|
|
|
8
|
-
const
|
|
9
|
+
const nodeUrl = 'http://localhost:8080';
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
+
const node = createAztecNodeClient(nodeUrl);
|
|
11
12
|
|
|
12
13
|
const ALICE_MINT_BALANCE = 333n;
|
|
13
14
|
const TRANSFER_AMOUNT = 33n;
|
|
@@ -18,39 +19,42 @@ const TRANSFER_AMOUNT = 33n;
|
|
|
18
19
|
async function main() {
|
|
19
20
|
logger.info('Running token contract test on HTTP interface.');
|
|
20
21
|
|
|
21
|
-
const
|
|
22
|
-
const alice = aliceWallet.getCompleteAddress();
|
|
23
|
-
const bob = bobWallet.getCompleteAddress();
|
|
22
|
+
const wallet = await TestWallet.create(node);
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
// During sandbox setup we deploy a few accounts. Below we add them to our wallet.
|
|
25
|
+
const [aliceInitialAccountData, bobInitialAccountData] = await getInitialTestAccountsData();
|
|
26
|
+
await wallet.createSchnorrAccount(aliceInitialAccountData.secret, aliceInitialAccountData.salt);
|
|
27
|
+
await wallet.createSchnorrAccount(bobInitialAccountData.secret, bobInitialAccountData.salt);
|
|
28
|
+
|
|
29
|
+
const alice = aliceInitialAccountData.address;
|
|
30
|
+
const bob = bobInitialAccountData.address;
|
|
31
|
+
|
|
32
|
+
logger.info(`Fetched Alice and Bob accounts: ${alice.toString()}, ${bob.toString()}`);
|
|
26
33
|
|
|
27
34
|
logger.info('Deploying Token...');
|
|
28
|
-
const token = await TokenContract.deploy(
|
|
35
|
+
const token = await TokenContract.deploy(wallet, alice, 'TokenName', 'TokenSymbol', 18)
|
|
36
|
+
.send({ from: alice })
|
|
37
|
+
.deployed();
|
|
29
38
|
logger.info('Token deployed');
|
|
30
39
|
|
|
31
|
-
// Create the contract abstraction and link it to Alice's and Bob's wallet for future signing
|
|
32
|
-
const tokenAlice = await TokenContract.at(token.address, aliceWallet);
|
|
33
|
-
const tokenBob = await TokenContract.at(token.address, bobWallet);
|
|
34
|
-
|
|
35
40
|
// Mint tokens to Alice
|
|
36
41
|
logger.info(`Minting ${ALICE_MINT_BALANCE} more coins to Alice...`);
|
|
37
|
-
|
|
38
|
-
await tokenAlice.methods.mint_to_private(from, aliceWallet.getAddress(), ALICE_MINT_BALANCE).send().wait();
|
|
42
|
+
await token.methods.mint_to_private(alice, ALICE_MINT_BALANCE).send({ from: alice }).wait();
|
|
39
43
|
|
|
40
44
|
logger.info(`${ALICE_MINT_BALANCE} tokens were successfully minted by Alice and transferred to private`);
|
|
41
45
|
|
|
42
|
-
const balanceAfterMint = await
|
|
46
|
+
const balanceAfterMint = await token.methods.balance_of_private(alice).simulate({ from: alice });
|
|
43
47
|
logger.info(`Tokens successfully minted. New Alice's balance: ${balanceAfterMint}`);
|
|
44
48
|
|
|
45
49
|
// We will now transfer tokens from Alice to Bob
|
|
46
50
|
logger.info(`Transferring ${TRANSFER_AMOUNT} tokens from Alice to Bob...`);
|
|
47
|
-
await
|
|
51
|
+
await token.methods.transfer(bob, TRANSFER_AMOUNT).send({ from: alice }).wait();
|
|
48
52
|
|
|
49
53
|
// Check the new balances
|
|
50
|
-
const aliceBalance = await
|
|
54
|
+
const aliceBalance = await token.methods.balance_of_private(alice).simulate({ from: alice });
|
|
51
55
|
logger.info(`Alice's balance ${aliceBalance}`);
|
|
52
56
|
|
|
53
|
-
const bobBalance = await
|
|
57
|
+
const bobBalance = await token.methods.balance_of_private(bob).simulate({ from: bob });
|
|
54
58
|
logger.info(`Bob's balance ${bobBalance}`);
|
|
55
59
|
}
|
|
56
60
|
|
package/src/examples/util.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EthAddress } from '@aztec/aztec.js';
|
|
2
|
-
import type {
|
|
1
|
+
import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import type { ExtendedViemWalletClient } from '@aztec/ethereum';
|
|
3
3
|
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
4
4
|
|
|
5
5
|
import type { Abi, Narrow } from 'abitype';
|
|
@@ -7,27 +7,25 @@ import type { Hex } from 'viem';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Helper function to deploy ETH contracts.
|
|
10
|
-
* @param
|
|
11
|
-
* @param publicClient - A viem PublicClient.
|
|
10
|
+
* @param l1Client - A viem WalletClient extended with public actions.
|
|
12
11
|
* @param abi - The ETH contract's ABI (as abitype's Abi).
|
|
13
12
|
* @param bytecode - The ETH contract's bytecode.
|
|
14
13
|
* @param args - Constructor arguments for the contract.
|
|
15
14
|
* @returns The ETH address the contract was deployed to.
|
|
16
15
|
*/
|
|
17
16
|
export async function deployL1Contract(
|
|
18
|
-
|
|
19
|
-
publicClient: ViemPublicClient,
|
|
17
|
+
l1Client: ExtendedViemWalletClient,
|
|
20
18
|
abi: Narrow<Abi | readonly unknown[]>,
|
|
21
19
|
bytecode: Hex,
|
|
22
20
|
args: readonly unknown[] = [],
|
|
23
21
|
): Promise<EthAddress> {
|
|
24
|
-
const hash = await
|
|
22
|
+
const hash = await l1Client.deployContract({
|
|
25
23
|
abi,
|
|
26
24
|
bytecode,
|
|
27
25
|
args,
|
|
28
26
|
});
|
|
29
27
|
|
|
30
|
-
const receipt = await
|
|
28
|
+
const receipt = await l1Client.waitForTransactionReceipt({ hash });
|
|
31
29
|
const contractAddress = receipt.contractAddress;
|
|
32
30
|
if (!contractAddress) {
|
|
33
31
|
throw new Error(`No contract address found in receipt: ${jsonStringify(receipt)}`);
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export {
|
|
2
2
|
createSandbox,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
SponsoredFeePaymentMethod,
|
|
3
|
+
registerDeployedBananaCoinInWalletAndGetAddress,
|
|
4
|
+
registerDeployedBananaFPCInWalletAndGetAddress,
|
|
5
|
+
registerDeployedSponsoredFPCInWalletAndGetAddress,
|
|
7
6
|
} from './sandbox/index.js';
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { type InitialAccountData,
|
|
2
|
-
import type { Wallet } from '@aztec/aztec.js';
|
|
1
|
+
import { type InitialAccountData, getInitialTestAccountsData } from '@aztec/accounts/testing';
|
|
2
|
+
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
3
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
4
|
import type { LogFn } from '@aztec/foundation/log';
|
|
5
5
|
import { FPCContract } from '@aztec/noir-contracts.js/FPC';
|
|
6
6
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
7
7
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
-
import { type ContractInstanceWithAddress,
|
|
9
|
-
import type { PXE } from '@aztec/stdlib/interfaces/client';
|
|
8
|
+
import { type ContractInstanceWithAddress, getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
|
|
10
9
|
|
|
11
10
|
const BANANA_COIN_SALT = new Fr(0);
|
|
12
11
|
const bananaCoinArgs = {
|
|
@@ -23,7 +22,7 @@ function getBananaAdmin(initialAccounts: InitialAccountData[]): AztecAddress {
|
|
|
23
22
|
|
|
24
23
|
async function getBananaCoinInstance(initialAccounts: InitialAccountData[]): Promise<ContractInstanceWithAddress> {
|
|
25
24
|
const admin = getBananaAdmin(initialAccounts);
|
|
26
|
-
return await
|
|
25
|
+
return await getContractInstanceFromInstantiationParams(TokenContract.artifact, {
|
|
27
26
|
constructorArgs: [admin, bananaCoinArgs.name, bananaCoinArgs.symbol, bananaCoinArgs.decimal],
|
|
28
27
|
salt: BANANA_COIN_SALT,
|
|
29
28
|
});
|
|
@@ -36,7 +35,7 @@ export async function getBananaCoinAddress(initialAccounts: InitialAccountData[]
|
|
|
36
35
|
async function getBananaFPCInstance(initialAccounts: InitialAccountData[]): Promise<ContractInstanceWithAddress> {
|
|
37
36
|
const bananaCoin = await getBananaCoinAddress(initialAccounts);
|
|
38
37
|
const admin = getBananaAdmin(initialAccounts);
|
|
39
|
-
return await
|
|
38
|
+
return await getContractInstanceFromInstantiationParams(FPCContract.artifact, {
|
|
40
39
|
constructorArgs: [bananaCoin, admin],
|
|
41
40
|
salt: BANANA_FPC_SALT,
|
|
42
41
|
});
|
|
@@ -46,15 +45,15 @@ export async function getBananaFPCAddress(initialAccounts: InitialAccountData[])
|
|
|
46
45
|
return (await getBananaFPCInstance(initialAccounts)).address;
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
export async function setupBananaFPC(initialAccounts: InitialAccountData[],
|
|
48
|
+
export async function setupBananaFPC(initialAccounts: InitialAccountData[], wallet: Wallet, log: LogFn) {
|
|
50
49
|
const bananaCoinAddress = await getBananaCoinAddress(initialAccounts);
|
|
51
50
|
const admin = getBananaAdmin(initialAccounts);
|
|
52
51
|
const [bananaCoin, fpc] = await Promise.all([
|
|
53
|
-
TokenContract.deploy(
|
|
54
|
-
.send({ contractAddressSalt: BANANA_COIN_SALT, universalDeploy: true })
|
|
52
|
+
TokenContract.deploy(wallet, admin, bananaCoinArgs.name, bananaCoinArgs.symbol, bananaCoinArgs.decimal)
|
|
53
|
+
.send({ from: admin, contractAddressSalt: BANANA_COIN_SALT, universalDeploy: true })
|
|
55
54
|
.deployed(),
|
|
56
|
-
FPCContract.deploy(
|
|
57
|
-
.send({ contractAddressSalt: BANANA_FPC_SALT, universalDeploy: true })
|
|
55
|
+
FPCContract.deploy(wallet, bananaCoinAddress, admin)
|
|
56
|
+
.send({ from: admin, contractAddressSalt: BANANA_FPC_SALT, universalDeploy: true })
|
|
58
57
|
.deployed(),
|
|
59
58
|
]);
|
|
60
59
|
|
|
@@ -62,22 +61,18 @@ export async function setupBananaFPC(initialAccounts: InitialAccountData[], depl
|
|
|
62
61
|
log(`FPC: ${fpc.address}`);
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
export async function
|
|
66
|
-
const initialAccounts = await
|
|
67
|
-
const bananaCoin = await
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
return bananaCoin;
|
|
64
|
+
export async function registerDeployedBananaCoinInWalletAndGetAddress(wallet: Wallet) {
|
|
65
|
+
const initialAccounts = await getInitialTestAccountsData();
|
|
66
|
+
const bananaCoin = await getBananaCoinInstance(initialAccounts);
|
|
67
|
+
// The following is no-op if the contract is already registered
|
|
68
|
+
await wallet.registerContract(bananaCoin, TokenContract.artifact);
|
|
69
|
+
return bananaCoin.address;
|
|
73
70
|
}
|
|
74
71
|
|
|
75
|
-
export async function
|
|
76
|
-
const initialAccounts = await
|
|
72
|
+
export async function registerDeployedBananaFPCInWalletAndGetAddress(wallet: Wallet) {
|
|
73
|
+
const initialAccounts = await getInitialTestAccountsData();
|
|
77
74
|
const fpc = await getBananaFPCInstance(initialAccounts);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
throw new Error('BananaFPC not deployed.');
|
|
81
|
-
}
|
|
75
|
+
// The following is no-op if the contract is already registered
|
|
76
|
+
await wallet.registerContract(fpc, FPCContract.artifact);
|
|
82
77
|
return fpc.address;
|
|
83
78
|
}
|
package/src/sandbox/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './sandbox.js';
|
|
2
2
|
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export {
|
|
4
|
+
registerDeployedBananaCoinInWalletAndGetAddress,
|
|
5
|
+
registerDeployedBananaFPCInWalletAndGetAddress,
|
|
6
|
+
} from './banana_fpc.js';
|
|
7
|
+
export { registerDeployedSponsoredFPCInWalletAndGetAddress } from './sponsored_fpc.js';
|