@aztec/cli 2.0.3 → 2.1.0-rc.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.
@@ -0,0 +1,79 @@
1
+ import { NetworkConfigMapSchema } from '@aztec/foundation/config';
2
+ import { readFile } from 'fs/promises';
3
+ import { join } from 'path';
4
+ import { cachedFetch } from './cached_fetch.js';
5
+ import { enrichEthAddressVar, enrichVar } from './enrich_env.js';
6
+ const DEFAULT_CONFIG_URL = 'https://raw.githubusercontent.com/AztecProtocol/networks/refs/heads/main/network_config.json';
7
+ const NETWORK_CONFIG_CACHE_DURATION_MS = 60 * 60 * 1000; // 1 hour
8
+ /**
9
+ * Fetches remote network configuration from GitHub with caching support.
10
+ * Uses the reusable cachedFetch utility.
11
+ *
12
+ * @param networkName - The network name to fetch config for
13
+ * @param cacheDir - Optional cache directory for storing fetched config
14
+ * @returns Remote configuration for the specified network, or undefined if not found/error
15
+ */ export async function getNetworkConfig(networkName, cacheDir) {
16
+ let url;
17
+ const configLocation = process.env.NETWORK_CONFIG_LOCATION || DEFAULT_CONFIG_URL;
18
+ if (!configLocation) {
19
+ return undefined;
20
+ }
21
+ try {
22
+ if (configLocation.includes('://')) {
23
+ url = new URL(configLocation);
24
+ } else {
25
+ url = new URL(`file://${configLocation}`);
26
+ }
27
+ } catch {
28
+ /* no-op */ }
29
+ if (!url) {
30
+ return undefined;
31
+ }
32
+ try {
33
+ let rawConfig;
34
+ if (url.protocol === 'http:' || url.protocol === 'https:') {
35
+ rawConfig = await cachedFetch(url.href, {
36
+ cacheDurationMs: NETWORK_CONFIG_CACHE_DURATION_MS,
37
+ cacheFile: cacheDir ? join(cacheDir, networkName, 'network_config.json') : undefined
38
+ });
39
+ } else if (url.protocol === 'file:') {
40
+ rawConfig = JSON.parse(await readFile(url.pathname, 'utf-8'));
41
+ } else {
42
+ throw new Error('Unsupported Aztec network config protocol: ' + url.href);
43
+ }
44
+ if (!rawConfig) {
45
+ return undefined;
46
+ }
47
+ const networkConfigMap = NetworkConfigMapSchema.parse(rawConfig);
48
+ if (networkName in networkConfigMap) {
49
+ return networkConfigMap[networkName];
50
+ } else {
51
+ return undefined;
52
+ }
53
+ } catch {
54
+ return undefined;
55
+ }
56
+ }
57
+ /**
58
+ * Enriches environment variables with remote network configuration.
59
+ * This function is called before node config initialization to set env vars
60
+ * from the remote config, following the same pattern as enrichEnvironmentWithChainConfig().
61
+ *
62
+ * @param networkName - The network name to fetch remote config for
63
+ */ export async function enrichEnvironmentWithNetworkConfig(networkName) {
64
+ if (networkName === 'local') {
65
+ return; // No remote config for local development
66
+ }
67
+ const cacheDir = process.env.DATA_DIRECTORY ? join(process.env.DATA_DIRECTORY, 'cache') : undefined;
68
+ const networkConfig = await getNetworkConfig(networkName, cacheDir);
69
+ if (!networkConfig) {
70
+ return;
71
+ }
72
+ enrichVar('BOOTSTRAP_NODES', networkConfig.bootnodes.join(','));
73
+ enrichVar('L1_CHAIN_ID', String(networkConfig.l1ChainId));
74
+ enrichVar('SYNC_SNAPSHOTS_URLS', networkConfig.snapshots.join(','));
75
+ enrichEthAddressVar('REGISTRY_CONTRACT_ADDRESS', networkConfig.registryAddress.toString());
76
+ if (networkConfig.feeAssetHandlerAddress) {
77
+ enrichEthAddressVar('FEE_ASSET_HANDLER_CONTRACT_ADDRESS', networkConfig.feeAssetHandlerAddress.toString());
78
+ }
79
+ }
@@ -18,7 +18,7 @@ export declare function getFunctionAbi(artifact: ContractArtifact, fnName: strin
18
18
  * @param privateKey - The private key to be used in contract deployment.
19
19
  * @param mnemonic - The mnemonic to be used in contract deployment.
20
20
  */
21
- export declare function deployAztecContracts(rpcUrls: string[], chainId: number, privateKey: string | undefined, mnemonic: string, mnemonicIndex: number, salt: number | undefined, initialValidators: Operator[], genesisArchiveRoot: Fr, feeJuicePortalInitialBalance: bigint, acceleratedTestDeployments: boolean, config: L1ContractsConfig, realVerifier: boolean, createVerificationJson: string | false, debugLogger: Logger): Promise<DeployL1ContractsReturnType>;
21
+ export declare function deployAztecContracts(rpcUrls: string[], chainId: number, privateKey: string | undefined, mnemonic: string, mnemonicIndex: number, salt: number | undefined, initialValidators: Operator[], genesisArchiveRoot: Fr, feeJuicePortalInitialBalance: bigint, acceleratedTestDeployments: boolean, config: L1ContractsConfig, existingToken: EthAddress | undefined, realVerifier: boolean, createVerificationJson: string | false, debugLogger: Logger): Promise<DeployL1ContractsReturnType>;
22
22
  export declare function deployNewRollupContracts(registryAddress: EthAddress, rpcUrls: string[], chainId: number, privateKey: string | undefined, mnemonic: string, mnemonicIndex: number, salt: number | undefined, initialValidators: Operator[], genesisArchiveRoot: Fr, feeJuicePortalInitialBalance: bigint, config: L1ContractsConfig, realVerifier: boolean, logger: Logger): Promise<{
23
23
  rollup: RollupContract;
24
24
  slashFactoryAddress: EthAddress;
@@ -1 +1 @@
1
- {"version":3,"file":"aztec.d.ts","sourceRoot":"","sources":["../../src/utils/aztec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAIjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,KAAK,2BAA2B,EAChC,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,cAAc,EACf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAShE;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAMtF;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE,MAAM,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,CAUtE;AAKD;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,oBAAoB,EAAE,MAAM,iBAyB9E"}
@@ -25,7 +25,7 @@ import { encodeArgs } from './encoding.js';
25
25
  * @param chainId - The chain ID of the L1 host.
26
26
  * @param privateKey - The private key to be used in contract deployment.
27
27
  * @param mnemonic - The mnemonic to be used in contract deployment.
28
- */ export async function deployAztecContracts(rpcUrls, chainId, privateKey, mnemonic, mnemonicIndex, salt, initialValidators, genesisArchiveRoot, feeJuicePortalInitialBalance, acceleratedTestDeployments, config, realVerifier, createVerificationJson, debugLogger) {
28
+ */ export async function deployAztecContracts(rpcUrls, chainId, privateKey, mnemonic, mnemonicIndex, salt, initialValidators, genesisArchiveRoot, feeJuicePortalInitialBalance, acceleratedTestDeployments, config, existingToken, realVerifier, createVerificationJson, debugLogger) {
29
29
  const { createEthereumChain, deployL1Contracts } = await import('@aztec/ethereum');
30
30
  const { mnemonicToAccount, privateKeyToAccount } = await import('viem/accounts');
31
31
  const account = !privateKey ? mnemonicToAccount(mnemonic, {
@@ -42,6 +42,7 @@ import { encodeArgs } from './encoding.js';
42
42
  acceleratedTestDeployments,
43
43
  feeJuicePortalInitialBalance,
44
44
  realVerifier,
45
+ existingTokenAddress: existingToken,
45
46
  ...config
46
47
  }, config, createVerificationJson);
47
48
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/cli",
3
- "version": "2.0.3",
3
+ "version": "2.1.0-rc.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./contracts": "./dest/cmds/contracts/index.js",
@@ -70,17 +70,17 @@
70
70
  ]
71
71
  },
72
72
  "dependencies": {
73
- "@aztec/archiver": "2.0.3",
74
- "@aztec/aztec.js": "2.0.3",
75
- "@aztec/constants": "2.0.3",
76
- "@aztec/entrypoints": "2.0.3",
77
- "@aztec/ethereum": "2.0.3",
78
- "@aztec/foundation": "2.0.3",
79
- "@aztec/l1-artifacts": "2.0.3",
80
- "@aztec/node-lib": "2.0.3",
81
- "@aztec/p2p": "2.0.3",
82
- "@aztec/stdlib": "2.0.3",
83
- "@aztec/world-state": "2.0.3",
73
+ "@aztec/archiver": "2.1.0-rc.2",
74
+ "@aztec/aztec.js": "2.1.0-rc.2",
75
+ "@aztec/constants": "2.1.0-rc.2",
76
+ "@aztec/entrypoints": "2.1.0-rc.2",
77
+ "@aztec/ethereum": "2.1.0-rc.2",
78
+ "@aztec/foundation": "2.1.0-rc.2",
79
+ "@aztec/l1-artifacts": "2.1.0-rc.2",
80
+ "@aztec/node-lib": "2.1.0-rc.2",
81
+ "@aztec/p2p": "2.1.0-rc.2",
82
+ "@aztec/stdlib": "2.1.0-rc.2",
83
+ "@aztec/world-state": "2.1.0-rc.2",
84
84
  "@iarna/toml": "^2.2.5",
85
85
  "@libp2p/peer-id-factory": "^3.0.4",
86
86
  "commander": "^12.1.0",
@@ -92,8 +92,8 @@
92
92
  "viem": "2.23.7"
93
93
  },
94
94
  "devDependencies": {
95
- "@aztec/accounts": "2.0.3",
96
- "@aztec/protocol-contracts": "2.0.3",
95
+ "@aztec/accounts": "2.1.0-rc.2",
96
+ "@aztec/protocol-contracts": "2.1.0-rc.2",
97
97
  "@jest/globals": "^30.0.0",
98
98
  "@types/jest": "^30.0.0",
99
99
  "@types/lodash.chunk": "^4.2.9",
@@ -109,15 +109,15 @@
109
109
  "typescript": "^5.3.3"
110
110
  },
111
111
  "peerDependencies": {
112
- "@aztec/accounts": "2.0.3",
113
- "@aztec/bb-prover": "2.0.3",
114
- "@aztec/ethereum": "2.0.3",
115
- "@aztec/l1-artifacts": "2.0.3",
116
- "@aztec/noir-contracts.js": "2.0.3",
117
- "@aztec/noir-protocol-circuits-types": "2.0.3",
118
- "@aztec/noir-test-contracts.js": "2.0.3",
119
- "@aztec/protocol-contracts": "2.0.3",
120
- "@aztec/stdlib": "2.0.3"
112
+ "@aztec/accounts": "2.1.0-rc.2",
113
+ "@aztec/bb-prover": "2.1.0-rc.2",
114
+ "@aztec/ethereum": "2.1.0-rc.2",
115
+ "@aztec/l1-artifacts": "2.1.0-rc.2",
116
+ "@aztec/noir-contracts.js": "2.1.0-rc.2",
117
+ "@aztec/noir-protocol-circuits-types": "2.1.0-rc.2",
118
+ "@aztec/noir-test-contracts.js": "2.1.0-rc.2",
119
+ "@aztec/protocol-contracts": "2.1.0-rc.2",
120
+ "@aztec/stdlib": "2.1.0-rc.2"
121
121
  },
122
122
  "files": [
123
123
  "dest",
@@ -22,6 +22,7 @@ export async function deployL1Contracts(
22
22
  createVerificationJson: string | false,
23
23
  initialValidators: EthAddress[],
24
24
  realVerifier: boolean,
25
+ existingToken: EthAddress | undefined,
25
26
  log: LogFn,
26
27
  debugLogger: Logger,
27
28
  ) {
@@ -50,6 +51,7 @@ export async function deployL1Contracts(
50
51
  fundingNeeded,
51
52
  acceleratedTestDeployments,
52
53
  config,
54
+ existingToken,
53
55
  realVerifier,
54
56
  createVerificationJson,
55
57
  debugLogger,
@@ -48,6 +48,7 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: Logger
48
48
  .option('--sponsored-fpc', 'Populate genesis state with a testing sponsored FPC contract')
49
49
  .option('--accelerated-test-deployments', 'Fire and forget deployment transactions, use in testing only', false)
50
50
  .option('--real-verifier', 'Deploy the real verifier', false)
51
+ .option('--existing-token <address>', 'Use an existing ERC20 for both fee and staking', parseEthereumAddress)
51
52
  .option('--create-verification-json [path]', 'Create JSON file for etherscan contract verification', false)
52
53
  .action(async options => {
53
54
  const { deployL1Contracts } = await import('./deploy_l1_contracts.js');
@@ -68,6 +69,7 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: Logger
68
69
  options.createVerificationJson,
69
70
  initialValidators,
70
71
  options.realVerifier,
72
+ options.existingToken,
71
73
  log,
72
74
  debugLogger,
73
75
  );
@@ -96,7 +96,7 @@ export async function addL1Validator({
96
96
 
97
97
  const registrationTuple = await gse.makeRegistrationTuple(blsSecretKey);
98
98
 
99
- const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client, debugLogger);
99
+ const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client, { logger: debugLogger });
100
100
  const proofParamsObj = ZkPassportProofParams.fromBuffer(proofParams);
101
101
  const merkleProofArray = merkleProof.map(proof => addLeadingHex(proof));
102
102
 
@@ -172,7 +172,7 @@ export async function addL1ValidatorViaRollup({
172
172
 
173
173
  const registrationTuple = await gse.makeRegistrationTuple(blsSecretKey);
174
174
 
175
- const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client, debugLogger);
175
+ const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client, { logger: debugLogger });
176
176
 
177
177
  const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
178
178
  to: rollupAddress.toString(),
@@ -219,7 +219,7 @@ export async function removeL1Validator({
219
219
  const account = getAccount(privateKey, mnemonic);
220
220
  const chain = createEthereumChain(rpcUrls, chainId);
221
221
  const l1Client = createExtendedL1Client(rpcUrls, account, chain.chainInfo);
222
- const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client, debugLogger);
222
+ const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client, { logger: debugLogger });
223
223
 
224
224
  dualLog(`Removing validator ${validatorAddress.toString()} from rollup ${rollupAddress.toString()}`);
225
225
  const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
@@ -246,7 +246,7 @@ export async function pruneRollup({
246
246
  const account = getAccount(privateKey, mnemonic);
247
247
  const chain = createEthereumChain(rpcUrls, chainId);
248
248
  const l1Client = createExtendedL1Client(rpcUrls, account, chain.chainInfo);
249
- const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client, debugLogger);
249
+ const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client, { logger: debugLogger });
250
250
 
251
251
  dualLog(`Trying prune`);
252
252
  const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
@@ -308,7 +308,7 @@ export async function debugRollup({ rpcUrls, chainId, rollupAddress, log }: Roll
308
308
  log(`Committee: ${committee?.map(v => v.toString()).join(', ')}`);
309
309
  const archive = await rollup.archive();
310
310
  log(`Archive: ${archive}`);
311
- const epochNum = await rollup.getEpochNumber();
311
+ const epochNum = await rollup.getCurrentEpochNumber();
312
312
  log(`Current epoch: ${epochNum}`);
313
313
  const slot = await rollup.getSlotNumber();
314
314
  log(`Current slot: ${slot}`);
@@ -0,0 +1,67 @@
1
+ import { createLogger } from '@aztec/aztec.js';
2
+
3
+ import { mkdir, readFile, stat, writeFile } from 'fs/promises';
4
+ import { dirname } from 'path';
5
+
6
+ export interface CachedFetchOptions {
7
+ /** Cache duration in milliseconds */
8
+ cacheDurationMs: number;
9
+ /** The cache file */
10
+ cacheFile?: string;
11
+ }
12
+
13
+ /**
14
+ * Fetches data from a URL with file-based caching support.
15
+ * This utility can be used by both remote config and bootnodes fetching.
16
+ *
17
+ * @param url - The URL to fetch from
18
+ * @param networkName - Network name for cache directory structure
19
+ * @param options - Caching and error handling options
20
+ * @param cacheDir - Optional cache directory (defaults to no caching)
21
+ * @returns The fetched and parsed JSON data, or undefined if fetch fails and throwOnError is false
22
+ */
23
+ export async function cachedFetch<T = any>(
24
+ url: string,
25
+ options: CachedFetchOptions,
26
+ fetch = globalThis.fetch,
27
+ log = createLogger('cached_fetch'),
28
+ ): Promise<T | undefined> {
29
+ const { cacheDurationMs, cacheFile } = options;
30
+
31
+ // Try to read from cache first
32
+ try {
33
+ if (cacheFile) {
34
+ const info = await stat(cacheFile);
35
+ if (info.mtimeMs + cacheDurationMs > Date.now()) {
36
+ const cachedData = JSON.parse(await readFile(cacheFile, 'utf-8'));
37
+ return cachedData;
38
+ }
39
+ }
40
+ } catch {
41
+ log.trace('Failed to read data from cache');
42
+ }
43
+
44
+ try {
45
+ const response = await fetch(url);
46
+ if (!response.ok) {
47
+ log.warn(`Failed to fetch from ${url}: ${response.status} ${response.statusText}`);
48
+ return undefined;
49
+ }
50
+
51
+ const data = await response.json();
52
+
53
+ try {
54
+ if (cacheFile) {
55
+ await mkdir(dirname(cacheFile), { recursive: true });
56
+ await writeFile(cacheFile, JSON.stringify(data), 'utf-8');
57
+ }
58
+ } catch (err) {
59
+ log.warn('Failed to cache data on disk: ' + cacheFile, { cacheFile, err });
60
+ }
61
+
62
+ return data;
63
+ } catch (err) {
64
+ log.warn(`Failed to fetch from ${url}`, { err });
65
+ return undefined;
66
+ }
67
+ }