@aztec/cli 2.0.3 → 2.1.0-rc.1

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,102 @@
1
+ import { type NetworkConfig, NetworkConfigMapSchema, type NetworkNames } from '@aztec/foundation/config';
2
+
3
+ import { readFile } from 'fs/promises';
4
+ import { join } from 'path';
5
+
6
+ import { cachedFetch } from './cached_fetch.js';
7
+ import { enrichEthAddressVar, enrichVar } from './enrich_env.js';
8
+
9
+ const DEFAULT_CONFIG_URL =
10
+ 'https://raw.githubusercontent.com/AztecProtocol/networks/refs/heads/main/network_config.json';
11
+ const NETWORK_CONFIG_CACHE_DURATION_MS = 60 * 60 * 1000; // 1 hour
12
+
13
+ /**
14
+ * Fetches remote network configuration from GitHub with caching support.
15
+ * Uses the reusable cachedFetch utility.
16
+ *
17
+ * @param networkName - The network name to fetch config for
18
+ * @param cacheDir - Optional cache directory for storing fetched config
19
+ * @returns Remote configuration for the specified network, or undefined if not found/error
20
+ */
21
+ export async function getNetworkConfig(
22
+ networkName: NetworkNames,
23
+ cacheDir?: string,
24
+ ): Promise<NetworkConfig | undefined> {
25
+ let url: URL | undefined;
26
+ const configLocation = process.env.NETWORK_CONFIG_LOCATION || DEFAULT_CONFIG_URL;
27
+
28
+ if (!configLocation) {
29
+ return undefined;
30
+ }
31
+
32
+ try {
33
+ if (configLocation.includes('://')) {
34
+ url = new URL(configLocation);
35
+ } else {
36
+ url = new URL(`file://${configLocation}`);
37
+ }
38
+ } catch {
39
+ /* no-op */
40
+ }
41
+
42
+ if (!url) {
43
+ return undefined;
44
+ }
45
+
46
+ try {
47
+ let rawConfig: any;
48
+
49
+ if (url.protocol === 'http:' || url.protocol === 'https:') {
50
+ rawConfig = await cachedFetch(url.href, {
51
+ cacheDurationMs: NETWORK_CONFIG_CACHE_DURATION_MS,
52
+ cacheFile: cacheDir ? join(cacheDir, networkName, 'network_config.json') : undefined,
53
+ });
54
+ } else if (url.protocol === 'file:') {
55
+ rawConfig = JSON.parse(await readFile(url.pathname, 'utf-8'));
56
+ } else {
57
+ throw new Error('Unsupported Aztec network config protocol: ' + url.href);
58
+ }
59
+
60
+ if (!rawConfig) {
61
+ return undefined;
62
+ }
63
+
64
+ const networkConfigMap = NetworkConfigMapSchema.parse(rawConfig);
65
+ if (networkName in networkConfigMap) {
66
+ return networkConfigMap[networkName];
67
+ } else {
68
+ return undefined;
69
+ }
70
+ } catch {
71
+ return undefined;
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Enriches environment variables with remote network configuration.
77
+ * This function is called before node config initialization to set env vars
78
+ * from the remote config, following the same pattern as enrichEnvironmentWithChainConfig().
79
+ *
80
+ * @param networkName - The network name to fetch remote config for
81
+ */
82
+ export async function enrichEnvironmentWithNetworkConfig(networkName: NetworkNames) {
83
+ if (networkName === 'local') {
84
+ return; // No remote config for local development
85
+ }
86
+
87
+ const cacheDir = process.env.DATA_DIRECTORY ? join(process.env.DATA_DIRECTORY, 'cache') : undefined;
88
+ const networkConfig = await getNetworkConfig(networkName, cacheDir);
89
+
90
+ if (!networkConfig) {
91
+ return;
92
+ }
93
+
94
+ enrichVar('BOOTSTRAP_NODES', networkConfig.bootnodes.join(','));
95
+ enrichVar('L1_CHAIN_ID', String(networkConfig.l1ChainId));
96
+ enrichVar('SYNC_SNAPSHOTS_URL', networkConfig.snapshots.join(','));
97
+
98
+ enrichEthAddressVar('REGISTRY_CONTRACT_ADDRESS', networkConfig.registryAddress.toString());
99
+ if (networkConfig.feeAssetHandlerAddress) {
100
+ enrichEthAddressVar('FEE_ASSET_HANDLER_CONTRACT_ADDRESS', networkConfig.feeAssetHandlerAddress.toString());
101
+ }
102
+ }
@@ -57,6 +57,7 @@ export async function deployAztecContracts(
57
57
  feeJuicePortalInitialBalance: bigint,
58
58
  acceleratedTestDeployments: boolean,
59
59
  config: L1ContractsConfig,
60
+ existingToken: EthAddress | undefined,
60
61
  realVerifier: boolean,
61
62
  createVerificationJson: string | false,
62
63
  debugLogger: Logger,
@@ -85,6 +86,7 @@ export async function deployAztecContracts(
85
86
  acceleratedTestDeployments,
86
87
  feeJuicePortalInitialBalance,
87
88
  realVerifier,
89
+ existingTokenAddress: existingToken,
88
90
  ...config,
89
91
  },
90
92
  config,