@aztec/aztec 0.0.0-test.1 → 0.0.1-commit.1142ef1

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 (156) hide show
  1. package/README.md +1 -1
  2. package/dest/bin/index.d.ts +1 -1
  3. package/dest/bin/index.js +23 -12
  4. package/dest/cli/aztec_start_action.d.ts +1 -1
  5. package/dest/cli/aztec_start_action.d.ts.map +1 -1
  6. package/dest/cli/aztec_start_action.js +40 -40
  7. package/dest/cli/aztec_start_options.d.ts +5 -3
  8. package/dest/cli/aztec_start_options.d.ts.map +1 -1
  9. package/dest/cli/aztec_start_options.js +143 -224
  10. package/dest/cli/cli.d.ts +1 -1
  11. package/dest/cli/cli.d.ts.map +1 -1
  12. package/dest/cli/cli.js +12 -7
  13. package/dest/cli/cmds/migrate_ha_db.d.ts +3 -0
  14. package/dest/cli/cmds/migrate_ha_db.d.ts.map +1 -0
  15. package/dest/cli/cmds/migrate_ha_db.js +27 -0
  16. package/dest/cli/cmds/start_archiver.d.ts +1 -1
  17. package/dest/cli/cmds/start_archiver.d.ts.map +1 -1
  18. package/dest/cli/cmds/start_archiver.js +20 -12
  19. package/dest/cli/cmds/start_bot.d.ts +4 -7
  20. package/dest/cli/cmds/start_bot.d.ts.map +1 -1
  21. package/dest/cli/cmds/start_bot.js +25 -14
  22. package/dest/cli/cmds/start_node.d.ts +2 -2
  23. package/dest/cli/cmds/start_node.d.ts.map +1 -1
  24. package/dest/cli/cmds/start_node.js +68 -81
  25. package/dest/cli/cmds/start_p2p_bootstrap.d.ts +1 -1
  26. package/dest/cli/cmds/start_p2p_bootstrap.d.ts.map +1 -1
  27. package/dest/cli/cmds/start_p2p_bootstrap.js +9 -4
  28. package/dest/cli/cmds/start_prover_agent.d.ts +1 -1
  29. package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -1
  30. package/dest/cli/cmds/start_prover_agent.js +33 -4
  31. package/dest/cli/cmds/start_prover_broker.d.ts +1 -1
  32. package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -1
  33. package/dest/cli/cmds/start_prover_broker.js +10 -4
  34. package/dest/cli/cmds/start_prover_node.d.ts +1 -1
  35. package/dest/cli/cmds/start_prover_node.d.ts.map +1 -1
  36. package/dest/cli/cmds/start_prover_node.js +44 -46
  37. package/dest/cli/cmds/start_txe.d.ts +1 -1
  38. package/dest/cli/index.d.ts +1 -1
  39. package/dest/cli/preload_crs.d.ts +3 -0
  40. package/dest/cli/preload_crs.d.ts.map +1 -0
  41. package/dest/cli/preload_crs.js +6 -0
  42. package/dest/cli/release_version.d.ts +2 -0
  43. package/dest/cli/release_version.d.ts.map +1 -0
  44. package/dest/cli/release_version.js +14 -0
  45. package/dest/cli/util.d.ts +38 -7
  46. package/dest/cli/util.d.ts.map +1 -1
  47. package/dest/cli/util.js +198 -28
  48. package/dest/cli/versioning.d.ts +1 -1
  49. package/dest/cli/versioning.js +3 -3
  50. package/dest/examples/token.d.ts +1 -1
  51. package/dest/examples/token.js +31 -18
  52. package/dest/examples/util.d.ts +5 -6
  53. package/dest/examples/util.d.ts.map +1 -1
  54. package/dest/examples/util.js +5 -6
  55. package/dest/index.d.ts +2 -2
  56. package/dest/index.d.ts.map +1 -1
  57. package/dest/index.js +1 -1
  58. package/dest/local-network/banana_fpc.d.ts +10 -0
  59. package/dest/local-network/banana_fpc.d.ts.map +1 -0
  60. package/dest/{sandbox → local-network}/banana_fpc.js +20 -22
  61. package/dest/local-network/index.d.ts +4 -0
  62. package/dest/local-network/index.d.ts.map +1 -0
  63. package/dest/local-network/index.js +3 -0
  64. package/dest/local-network/local-network.d.ts +72 -0
  65. package/dest/local-network/local-network.d.ts.map +1 -0
  66. package/dest/local-network/local-network.js +195 -0
  67. package/dest/local-network/sponsored_fpc.d.ts +5 -0
  68. package/dest/local-network/sponsored_fpc.d.ts.map +1 -0
  69. package/dest/local-network/sponsored_fpc.js +18 -0
  70. package/dest/mnemonic.d.ts +1 -1
  71. package/dest/splash.d.ts +1 -1
  72. package/dest/testing/anvil_test_watcher.d.ts +34 -0
  73. package/dest/testing/anvil_test_watcher.d.ts.map +1 -0
  74. package/dest/testing/anvil_test_watcher.js +144 -0
  75. package/dest/testing/cheat_codes.d.ts +41 -0
  76. package/dest/testing/cheat_codes.d.ts.map +1 -0
  77. package/dest/testing/cheat_codes.js +62 -0
  78. package/dest/testing/epoch_test_settler.d.ts +17 -0
  79. package/dest/testing/epoch_test_settler.d.ts.map +1 -0
  80. package/dest/testing/epoch_test_settler.js +52 -0
  81. package/dest/testing/index.d.ts +5 -0
  82. package/dest/testing/index.d.ts.map +1 -0
  83. package/dest/testing/index.js +4 -0
  84. package/package.json +55 -45
  85. package/scripts/aztec.sh +63 -0
  86. package/scripts/compile.sh +44 -0
  87. package/scripts/extract_function.js +47 -0
  88. package/scripts/flamegraph.sh +59 -0
  89. package/scripts/init.sh +35 -0
  90. package/scripts/new.sh +59 -0
  91. package/scripts/setup_project.sh +31 -0
  92. package/src/bin/index.ts +28 -12
  93. package/src/cli/aztec_start_action.ts +36 -38
  94. package/src/cli/aztec_start_options.ts +159 -222
  95. package/src/cli/cli.ts +20 -11
  96. package/src/cli/cmds/migrate_ha_db.ts +43 -0
  97. package/src/cli/cmds/start_archiver.ts +21 -15
  98. package/src/cli/cmds/start_bot.ts +36 -13
  99. package/src/cli/cmds/start_node.ts +91 -86
  100. package/src/cli/cmds/start_p2p_bootstrap.ts +12 -4
  101. package/src/cli/cmds/start_prover_agent.ts +24 -12
  102. package/src/cli/cmds/start_prover_broker.ts +24 -4
  103. package/src/cli/cmds/start_prover_node.ts +54 -51
  104. package/src/cli/preload_crs.ts +7 -0
  105. package/src/cli/release_version.ts +21 -0
  106. package/src/cli/util.ts +208 -34
  107. package/src/cli/versioning.ts +3 -3
  108. package/src/examples/token.ts +23 -19
  109. package/src/examples/util.ts +6 -8
  110. package/src/index.ts +5 -6
  111. package/src/{sandbox → local-network}/banana_fpc.ts +21 -26
  112. package/src/local-network/index.ts +7 -0
  113. package/src/local-network/local-network.ts +238 -0
  114. package/src/local-network/sponsored_fpc.ts +26 -0
  115. package/src/testing/anvil_test_watcher.ts +166 -0
  116. package/src/testing/cheat_codes.ts +79 -0
  117. package/src/testing/epoch_test_settler.ts +59 -0
  118. package/src/testing/index.ts +4 -0
  119. package/dest/cli/chain_l2_config.d.ts +0 -19
  120. package/dest/cli/chain_l2_config.d.ts.map +0 -1
  121. package/dest/cli/chain_l2_config.js +0 -56
  122. package/dest/cli/cmds/start_blob_sink.d.ts +0 -3
  123. package/dest/cli/cmds/start_blob_sink.d.ts.map +0 -1
  124. package/dest/cli/cmds/start_blob_sink.js +0 -17
  125. package/dest/cli/cmds/start_faucet.d.ts +0 -4
  126. package/dest/cli/cmds/start_faucet.d.ts.map +0 -1
  127. package/dest/cli/cmds/start_faucet.js +0 -20
  128. package/dest/cli/cmds/start_pxe.d.ts +0 -16
  129. package/dest/cli/cmds/start_pxe.d.ts.map +0 -1
  130. package/dest/cli/cmds/start_pxe.js +0 -95
  131. package/dest/cli/get_l1_config.d.ts +0 -7
  132. package/dest/cli/get_l1_config.d.ts.map +0 -1
  133. package/dest/cli/get_l1_config.js +0 -13
  134. package/dest/sandbox/banana_fpc.d.ts +0 -11
  135. package/dest/sandbox/banana_fpc.d.ts.map +0 -1
  136. package/dest/sandbox/index.d.ts +0 -5
  137. package/dest/sandbox/index.d.ts.map +0 -1
  138. package/dest/sandbox/index.js +0 -4
  139. package/dest/sandbox/sandbox.d.ts +0 -76
  140. package/dest/sandbox/sandbox.d.ts.map +0 -1
  141. package/dest/sandbox/sandbox.js +0 -181
  142. package/dest/sandbox/sponsored_fee_payment_method.d.ts +0 -23
  143. package/dest/sandbox/sponsored_fee_payment_method.d.ts.map +0 -1
  144. package/dest/sandbox/sponsored_fee_payment_method.js +0 -36
  145. package/dest/sandbox/sponsored_fpc.d.ts +0 -6
  146. package/dest/sandbox/sponsored_fpc.d.ts.map +0 -1
  147. package/dest/sandbox/sponsored_fpc.js +0 -26
  148. package/src/cli/chain_l2_config.ts +0 -74
  149. package/src/cli/cmds/start_blob_sink.ts +0 -31
  150. package/src/cli/cmds/start_faucet.ts +0 -34
  151. package/src/cli/cmds/start_pxe.ts +0 -129
  152. package/src/cli/get_l1_config.ts +0 -18
  153. package/src/sandbox/index.ts +0 -5
  154. package/src/sandbox/sandbox.ts +0 -229
  155. package/src/sandbox/sponsored_fee_payment_method.ts +0 -46
  156. package/src/sandbox/sponsored_fpc.ts +0 -38
@@ -1,74 +0,0 @@
1
- export type NetworkNames = 'testnet-ignition';
2
-
3
- export type L2ChainConfig = {
4
- l1ChainId: number;
5
- ethereumSlotDuration: number;
6
- aztecSlotDuration: number;
7
- aztecEpochDuration: number;
8
- aztecProofSubmissionWindow: number;
9
- testAccounts: boolean;
10
- p2pEnabled: boolean;
11
- p2pBootstrapNodes: string[];
12
- registryAddress: string;
13
- seqMinTxsPerBlock: number;
14
- seqMaxTxsPerBlock: number;
15
- };
16
-
17
- export const testnetIgnitionL2ChainConfig: L2ChainConfig = {
18
- l1ChainId: 11155111,
19
- ethereumSlotDuration: 12,
20
- aztecSlotDuration: 36,
21
- aztecEpochDuration: 32,
22
- aztecProofSubmissionWindow: 64,
23
- testAccounts: true,
24
- p2pEnabled: true,
25
- p2pBootstrapNodes: [],
26
- registryAddress: '0x12b3ebc176a1646b911391eab3760764f2e05fe3',
27
- seqMinTxsPerBlock: 0,
28
- seqMaxTxsPerBlock: 0,
29
- };
30
-
31
- export async function getBootnodes(networkName: NetworkNames) {
32
- const url = `http://static.aztec.network/${networkName}/bootnodes.json`;
33
- const response = await fetch(url);
34
- if (!response.ok) {
35
- throw new Error(`Failed to fetch basic contract addresses from ${url}`);
36
- }
37
- const json = await response.json();
38
- return json['bootnodes'];
39
- }
40
-
41
- export async function getL2ChainConfig(networkName: NetworkNames): Promise<L2ChainConfig | undefined> {
42
- if (networkName === 'testnet-ignition') {
43
- const config = { ...testnetIgnitionL2ChainConfig };
44
- config.p2pBootstrapNodes = await getBootnodes(networkName);
45
- return config;
46
- }
47
- return undefined;
48
- }
49
-
50
- function enrichVar(envVar: string, value: string) {
51
- // Don't override
52
- if (process.env[envVar]) {
53
- return;
54
- }
55
- process.env[envVar] = value;
56
- }
57
-
58
- export async function enrichEnvironmentWithChainConfig(networkName: NetworkNames) {
59
- const config = await getL2ChainConfig(networkName);
60
- if (!config) {
61
- throw new Error(`Unknown network name: ${networkName}`);
62
- }
63
- enrichVar('ETHEREUM_SLOT_DURATION', config.ethereumSlotDuration.toString());
64
- enrichVar('AZTEC_SLOT_DURATION', config.aztecSlotDuration.toString());
65
- enrichVar('AZTEC_EPOCH_DURATION', config.aztecEpochDuration.toString());
66
- enrichVar('AZTEC_PROOF_SUBMISSION_WINDOW', config.aztecProofSubmissionWindow.toString());
67
- enrichVar('P2P_BOOTSTRAP_NODES', config.p2pBootstrapNodes.join(','));
68
- enrichVar('TEST_ACCOUNTS', config.testAccounts.toString());
69
- enrichVar('P2P_ENABLED', config.p2pEnabled.toString());
70
- enrichVar('L1_CHAIN_ID', config.l1ChainId.toString());
71
- enrichVar('REGISTRY_CONTRACT_ADDRESS', config.registryAddress);
72
- enrichVar('SEQ_MIN_TX_PER_BLOCK', config.seqMinTxsPerBlock.toString());
73
- enrichVar('SEQ_MAX_TX_PER_BLOCK', config.seqMaxTxsPerBlock.toString());
74
- }
@@ -1,31 +0,0 @@
1
- import {
2
- type BlobSinkConfig,
3
- blobSinkConfigMappings,
4
- createBlobSinkServer,
5
- getBlobSinkConfigFromEnv,
6
- } from '@aztec/blob-sink/server';
7
- import type { LogFn } from '@aztec/foundation/log';
8
- import { getConfigEnvVars as getTelemetryClientConfig, initTelemetryClient } from '@aztec/telemetry-client';
9
-
10
- import { extractRelevantOptions } from '../util.js';
11
-
12
- export async function startBlobSink(options: any, signalHandlers: (() => Promise<void>)[], userLog: LogFn) {
13
- if (options.prover || options.node || options.sequencer || options.pxe || options.p2pBootstrap || options.txe) {
14
- userLog(
15
- `Starting a blob sink with --node, --sequencer, --pxe, --p2p-bootstrap, --prover or --txe is not supported.`,
16
- );
17
- process.exit(1);
18
- }
19
-
20
- const blobSinkConfig = {
21
- ...getBlobSinkConfigFromEnv(), // get default config from env
22
- ...extractRelevantOptions<BlobSinkConfig>(options, blobSinkConfigMappings, 'blobSink'), // override with command line options
23
- };
24
-
25
- const telemetry = initTelemetryClient(getTelemetryClientConfig());
26
-
27
- const blobSink = await createBlobSinkServer(blobSinkConfig, telemetry);
28
- signalHandlers.push(blobSink.stop.bind(blobSink));
29
-
30
- await blobSink.start();
31
- }
@@ -1,34 +0,0 @@
1
- import {
2
- Faucet,
3
- FaucetSchema,
4
- createFaucetHttpServer,
5
- faucetConfigMapping,
6
- getFaucetConfigFromEnv,
7
- } from '@aztec/aztec-faucet';
8
- import type { NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
9
- import type { LogFn } from '@aztec/foundation/log';
10
-
11
- import { extractNamespacedOptions, extractRelevantOptions } from '../util.js';
12
-
13
- export async function startFaucet(
14
- options: any,
15
- signalHandlers: (() => Promise<void>)[],
16
- services: NamespacedApiHandlers,
17
- log: LogFn,
18
- ) {
19
- const faucetOptions = extractNamespacedOptions(options, 'faucet');
20
- const config = {
21
- ...getFaucetConfigFromEnv(),
22
- ...extractRelevantOptions(options, faucetConfigMapping, 'faucet'),
23
- };
24
-
25
- const faucet = await Faucet.create(config);
26
- if (faucetOptions.apiServer) {
27
- const httpServer = createFaucetHttpServer(faucet);
28
- httpServer.listen(faucetOptions.apiServerPort);
29
- signalHandlers.push(() => new Promise(res => httpServer.close(() => res())));
30
- log(`Faucet now running on port: ${faucetOptions.apiServerPort}`);
31
- }
32
-
33
- services.faucet = [faucet, FaucetSchema];
34
- }
@@ -1,129 +0,0 @@
1
- import {
2
- AztecAddress,
3
- type ContractArtifact,
4
- type ContractInstanceWithAddress,
5
- Fr,
6
- PublicKeys,
7
- getContractClassFromArtifact,
8
- } from '@aztec/aztec.js';
9
- import { getContractArtifact } from '@aztec/cli/cli-utils';
10
- import type { NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
11
- import type { LogFn } from '@aztec/foundation/log';
12
- import {
13
- type CliPXEOptions,
14
- type PXEService,
15
- type PXEServiceConfig,
16
- allPxeConfigMappings,
17
- createPXEService,
18
- } from '@aztec/pxe/server';
19
- import { type AztecNode, PXESchema, createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
20
- import { L2BasicContractsMap, Network } from '@aztec/stdlib/network';
21
- import { makeTracedFetch } from '@aztec/telemetry-client';
22
-
23
- import { extractRelevantOptions } from '../util.js';
24
- import { getVersions } from '../versioning.js';
25
-
26
- export type { PXEServiceConfig, CliPXEOptions };
27
-
28
- const contractAddressesUrl = 'http://static.aztec.network';
29
-
30
- export async function startPXE(
31
- options: any,
32
- signalHandlers: (() => Promise<void>)[],
33
- services: NamespacedApiHandlers,
34
- userLog: LogFn,
35
- ): Promise<{ pxe: PXEService; config: PXEServiceConfig & CliPXEOptions }> {
36
- return await addPXE(options, signalHandlers, services, userLog, {});
37
- }
38
-
39
- function isValidNetwork(value: any): value is Network {
40
- return Object.values(Network).includes(value);
41
- }
42
-
43
- async function fetchBasicContractAddresses(url: string) {
44
- const response = await fetch(url);
45
- if (!response.ok) {
46
- throw new Error(`Failed to fetch basic contract addresses from ${url}`);
47
- }
48
- return response.json();
49
- }
50
-
51
- export async function addPXE(
52
- options: any,
53
- signalHandlers: (() => Promise<void>)[],
54
- services: NamespacedApiHandlers,
55
- userLog: LogFn,
56
- deps: { node?: AztecNode } = {},
57
- ): Promise<{ pxe: PXEService; config: PXEServiceConfig & CliPXEOptions }> {
58
- const pxeConfig = extractRelevantOptions<PXEServiceConfig & CliPXEOptions>(options, allPxeConfigMappings, 'pxe');
59
-
60
- let nodeUrl;
61
- if (pxeConfig.network) {
62
- if (isValidNetwork(pxeConfig.network)) {
63
- if (!pxeConfig.apiKey && !pxeConfig.nodeUrl) {
64
- userLog(`API Key or Aztec Node URL is required to connect to ${pxeConfig.network}`);
65
- process.exit(1);
66
- } else if (pxeConfig.apiKey) {
67
- nodeUrl = `https://api.aztec.network/${pxeConfig.network}/aztec-node-1/${pxeConfig.apiKey}`;
68
- } else if (pxeConfig.nodeUrl) {
69
- nodeUrl = pxeConfig.nodeUrl;
70
- }
71
- } else {
72
- userLog(`Network ${pxeConfig.network} is not supported`);
73
- process.exit(1);
74
- }
75
- } else {
76
- nodeUrl = pxeConfig.nodeUrl;
77
- }
78
- if (!nodeUrl && !deps.node && !pxeConfig.network) {
79
- userLog('Aztec Node URL (nodeUrl | AZTEC_NODE_URL) option is required to start PXE without --node option');
80
- process.exit(1);
81
- }
82
-
83
- const node = deps.node ?? createAztecNodeClient(nodeUrl!, getVersions(pxeConfig), makeTracedFetch([1, 2, 3], true));
84
- const pxe = await createPXEService(node, pxeConfig as PXEServiceConfig);
85
-
86
- // register basic contracts
87
- if (pxeConfig.network) {
88
- userLog(`Registering basic contracts for ${pxeConfig.network}`);
89
- const basicContractsInfo = await fetchBasicContractAddresses(
90
- `${contractAddressesUrl}/${pxeConfig.network}/basic_contracts.json`,
91
- );
92
- const l2Contracts: Record<
93
- string,
94
- { name: string; address: AztecAddress; initHash: Fr; salt: Fr; artifact: ContractArtifact }
95
- > = {};
96
- for (const [key, artifactName] of Object.entries(L2BasicContractsMap[pxeConfig.network as Network])) {
97
- l2Contracts[key] = {
98
- name: key,
99
- address: AztecAddress.fromString(basicContractsInfo[key].address),
100
- initHash: Fr.fromHexString(basicContractsInfo[key].initHash),
101
- salt: Fr.fromHexString(basicContractsInfo[key].salt),
102
- artifact: await getContractArtifact(artifactName, userLog),
103
- };
104
- }
105
-
106
- await Promise.all(
107
- Object.values(l2Contracts).map(async ({ name, address, artifact, initHash, salt }) => {
108
- const contractClass = await getContractClassFromArtifact(artifact!);
109
- const instance: ContractInstanceWithAddress = {
110
- version: 1,
111
- salt,
112
- initializationHash: initHash,
113
- address,
114
- deployer: AztecAddress.ZERO,
115
- currentContractClassId: contractClass.id,
116
- originalContractClassId: contractClass.id,
117
- publicKeys: PublicKeys.default(),
118
- };
119
- userLog(`Registering ${name} at ${address.toString()}`);
120
- await pxe.registerContract({ artifact, instance });
121
- }),
122
- );
123
- }
124
-
125
- // Add PXE to services list
126
- services.pxe = [pxe, PXESchema];
127
-
128
- return { pxe, config: pxeConfig };
129
- }
@@ -1,18 +0,0 @@
1
- import { type L1ContractAddresses, RegistryContract, getL1ContractsConfig, getPublicClient } from '@aztec/ethereum';
2
- import type { EthAddress } from '@aztec/foundation/eth-address';
3
-
4
- export async function getL1Config(
5
- registryAddress: EthAddress,
6
- l1RpcUrls: string[],
7
- l1ChainId: number,
8
- ): Promise<{ addresses: L1ContractAddresses; config: Awaited<ReturnType<typeof getL1ContractsConfig>> }> {
9
- const publicClient = getPublicClient({ l1RpcUrls, l1ChainId });
10
- const addresses = await RegistryContract.collectAddresses(publicClient, registryAddress, 'canonical');
11
-
12
- const config = await getL1ContractsConfig(publicClient, addresses);
13
-
14
- return {
15
- addresses,
16
- config,
17
- };
18
- }
@@ -1,5 +0,0 @@
1
- export * from './sandbox.js';
2
-
3
- export { getDeployedBananaCoinAddress, getDeployedBananaFPCAddress } from './banana_fpc.js';
4
- export { getDeployedSponsoredFPCAddress } from './sponsored_fpc.js';
5
- export { SponsoredFeePaymentMethod } from './sponsored_fee_payment_method.js';
@@ -1,229 +0,0 @@
1
- #!/usr/bin/env -S node --no-warnings
2
- import { getSchnorrWallet } from '@aztec/accounts/schnorr';
3
- import { deployFundedSchnorrAccounts, getInitialTestAccounts } from '@aztec/accounts/testing';
4
- import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node';
5
- import { AnvilTestWatcher, EthCheatCodes, SignerlessWallet } from '@aztec/aztec.js';
6
- import { type BlobSinkClientInterface, createBlobSinkClient } from '@aztec/blob-sink/client';
7
- import { setupCanonicalL2FeeJuice } from '@aztec/cli/setup-contracts';
8
- import { GENESIS_ARCHIVE_ROOT, GENESIS_BLOCK_HASH } from '@aztec/constants';
9
- import {
10
- NULL_KEY,
11
- createEthereumChain,
12
- deployL1Contracts,
13
- getL1ContractsConfigEnvVars,
14
- waitForPublicClient,
15
- } from '@aztec/ethereum';
16
- import { Fr } from '@aztec/foundation/fields';
17
- import { type LogFn, createLogger } from '@aztec/foundation/log';
18
- import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
19
- import { ProtocolContractAddress, protocolContractTreeRoot } from '@aztec/protocol-contracts';
20
- import { type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe/server';
21
- import type { AztecNode } from '@aztec/stdlib/interfaces/client';
22
- import type { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
23
- import {
24
- type TelemetryClient,
25
- getConfigEnvVars as getTelemetryClientConfig,
26
- initTelemetryClient,
27
- } from '@aztec/telemetry-client';
28
- import { getGenesisValues } from '@aztec/world-state/testing';
29
-
30
- import { type HDAccount, type PrivateKeyAccount, createPublicClient, fallback, http as httpViemTransport } from 'viem';
31
- import { mnemonicToAccount } from 'viem/accounts';
32
- import { foundry } from 'viem/chains';
33
-
34
- import { createAccountLogs } from '../cli/util.js';
35
- import { DefaultMnemonic } from '../mnemonic.js';
36
- import { getBananaFPCAddress, setupBananaFPC } from './banana_fpc.js';
37
- import { getSponsoredFPCAddress, setupSponsoredFPC } from './sponsored_fpc.js';
38
-
39
- const logger = createLogger('sandbox');
40
-
41
- const localAnvil = foundry;
42
-
43
- /**
44
- * Function to deploy our L1 contracts to the sandbox L1
45
- * @param aztecNodeConfig - The Aztec Node Config
46
- * @param hdAccount - Account for publishing L1 contracts
47
- */
48
- export async function deployContractsToL1(
49
- aztecNodeConfig: AztecNodeConfig,
50
- hdAccount: HDAccount | PrivateKeyAccount,
51
- contractDeployLogger = logger,
52
- opts: { assumeProvenThroughBlockNumber?: number; salt?: number; genesisArchiveRoot?: Fr; genesisBlockHash?: Fr } = {},
53
- ) {
54
- const chain =
55
- aztecNodeConfig.l1RpcUrls.length > 0
56
- ? createEthereumChain(aztecNodeConfig.l1RpcUrls, aztecNodeConfig.l1ChainId)
57
- : { chainInfo: localAnvil };
58
-
59
- await waitForPublicClient(aztecNodeConfig);
60
-
61
- const l1Contracts = await deployL1Contracts(
62
- aztecNodeConfig.l1RpcUrls,
63
- hdAccount,
64
- chain.chainInfo,
65
- contractDeployLogger,
66
- {
67
- ...getL1ContractsConfigEnvVars(), // TODO: We should not need to be loading config from env again, caller should handle this
68
- ...aztecNodeConfig,
69
- l2FeeJuiceAddress: ProtocolContractAddress.FeeJuice.toField(),
70
- vkTreeRoot: getVKTreeRoot(),
71
- protocolContractTreeRoot,
72
- genesisArchiveRoot: opts.genesisArchiveRoot ?? new Fr(GENESIS_ARCHIVE_ROOT),
73
- genesisBlockHash: opts.genesisBlockHash ?? new Fr(GENESIS_BLOCK_HASH),
74
- salt: opts.salt,
75
- },
76
- );
77
-
78
- aztecNodeConfig.l1Contracts = l1Contracts.l1ContractAddresses;
79
-
80
- return aztecNodeConfig.l1Contracts;
81
- }
82
-
83
- /** Sandbox settings. */
84
- export type SandboxConfig = AztecNodeConfig & {
85
- /** Mnemonic used to derive the L1 deployer private key.*/
86
- l1Mnemonic: string;
87
- /** Salt used to deploy L1 contracts.*/
88
- l1Salt: string;
89
- /** Whether to expose PXE service on sandbox start.*/
90
- noPXE: boolean;
91
- /** Whether to deploy test accounts on sandbox start.*/
92
- testAccounts: boolean;
93
- };
94
-
95
- /**
96
- * Create and start a new Aztec Node and PXE. Deploys L1 contracts.
97
- * Does not start any HTTP services nor populate any initial accounts.
98
- * @param config - Optional Sandbox settings.
99
- */
100
- export async function createSandbox(config: Partial<SandboxConfig> = {}, userLog: LogFn) {
101
- // sandbox is meant for test envs. We should only need one l1RpcUrl
102
- const l1RpcUrl = config.l1RpcUrls?.[0];
103
- if (!l1RpcUrl) {
104
- throw new Error('An L1 RPC URL is required');
105
- }
106
- if ((config.l1RpcUrls?.length || 0) > 1) {
107
- logger.warn(`Multiple L1 RPC URLs provided. Sandbox will only use the first one: ${l1RpcUrl}`);
108
- }
109
- const aztecNodeConfig: AztecNodeConfig = { ...getConfigEnvVars(), ...config };
110
- const hdAccount = mnemonicToAccount(config.l1Mnemonic || DefaultMnemonic);
111
- if (!aztecNodeConfig.publisherPrivateKey || aztecNodeConfig.publisherPrivateKey === NULL_KEY) {
112
- const privKey = hdAccount.getHdKey().privateKey;
113
- aztecNodeConfig.publisherPrivateKey = `0x${Buffer.from(privKey!).toString('hex')}`;
114
- }
115
- if (!aztecNodeConfig.validatorPrivateKey || aztecNodeConfig.validatorPrivateKey === NULL_KEY) {
116
- const privKey = hdAccount.getHdKey().privateKey;
117
- aztecNodeConfig.validatorPrivateKey = `0x${Buffer.from(privKey!).toString('hex')}`;
118
- }
119
-
120
- const initialAccounts = await (async () => {
121
- if (config.testAccounts) {
122
- if (aztecNodeConfig.p2pEnabled) {
123
- userLog(`Not setting up test accounts as we are connecting to a network`);
124
- } else if (config.noPXE) {
125
- userLog(`Not setting up test accounts as we are not exposing a PXE`);
126
- } else {
127
- return await getInitialTestAccounts();
128
- }
129
- }
130
- return [];
131
- })();
132
-
133
- const bananaFPC = await getBananaFPCAddress(initialAccounts);
134
- const sponsoredFPC = await getSponsoredFPCAddress();
135
- const fundedAddresses = initialAccounts.length
136
- ? [...initialAccounts.map(a => a.address), bananaFPC, sponsoredFPC]
137
- : [];
138
- const { genesisArchiveRoot, genesisBlockHash, prefilledPublicData } = await getGenesisValues(fundedAddresses);
139
-
140
- let watcher: AnvilTestWatcher | undefined = undefined;
141
- if (!aztecNodeConfig.p2pEnabled) {
142
- const l1ContractAddresses = await deployContractsToL1(aztecNodeConfig, hdAccount, undefined, {
143
- assumeProvenThroughBlockNumber: Number.MAX_SAFE_INTEGER,
144
- genesisArchiveRoot,
145
- genesisBlockHash,
146
- salt: config.l1Salt ? parseInt(config.l1Salt) : undefined,
147
- });
148
-
149
- const chain =
150
- aztecNodeConfig.l1RpcUrls.length > 0
151
- ? createEthereumChain([l1RpcUrl], aztecNodeConfig.l1ChainId)
152
- : { chainInfo: localAnvil };
153
-
154
- const publicClient = createPublicClient({
155
- chain: chain.chainInfo,
156
- transport: fallback([httpViemTransport(l1RpcUrl)]) as any,
157
- });
158
-
159
- watcher = new AnvilTestWatcher(new EthCheatCodes([l1RpcUrl]), l1ContractAddresses.rollupAddress, publicClient);
160
- watcher.setIsSandbox(true);
161
- await watcher.start();
162
- }
163
-
164
- const telemetry = initTelemetryClient(getTelemetryClientConfig());
165
- // Create a local blob sink client inside the sandbox, no http connectivity
166
- const blobSinkClient = createBlobSinkClient();
167
- const node = await createAztecNode(aztecNodeConfig, { telemetry, blobSinkClient }, { prefilledPublicData });
168
- const pxe = await createAztecPXE(node);
169
-
170
- await setupCanonicalL2FeeJuice(
171
- new SignerlessWallet(pxe),
172
- aztecNodeConfig.l1Contracts.feeJuicePortalAddress,
173
- undefined,
174
- logger.info,
175
- );
176
-
177
- if (initialAccounts.length) {
178
- userLog('Setting up funded test accounts...');
179
- const accounts = await deployFundedSchnorrAccounts(pxe, initialAccounts);
180
- const accountsWithSecrets = accounts.map((account, i) => ({
181
- account,
182
- secretKey: initialAccounts[i].secret,
183
- }));
184
- const accLogs = await createAccountLogs(accountsWithSecrets, pxe);
185
- userLog(accLogs.join(''));
186
-
187
- const deployer = await getSchnorrWallet(pxe, initialAccounts[0].address, initialAccounts[0].signingKey);
188
- await setupBananaFPC(initialAccounts, deployer, userLog);
189
- await setupSponsoredFPC(deployer, userLog);
190
- }
191
-
192
- const stop = async () => {
193
- await node.stop();
194
- await watcher?.stop();
195
- };
196
-
197
- return { node, pxe, stop };
198
- }
199
-
200
- /**
201
- * Create and start a new Aztec RPC HTTP Server
202
- * @param config - Optional Aztec node settings.
203
- */
204
- export async function createAztecNode(
205
- config: Partial<AztecNodeConfig> = {},
206
- deps: { telemetry?: TelemetryClient; blobSinkClient?: BlobSinkClientInterface } = {},
207
- options: { prefilledPublicData?: PublicDataTreeLeaf[] } = {},
208
- ) {
209
- // TODO(#12272): will clean this up. This is criminal.
210
- const { l1Contracts, ...rest } = getConfigEnvVars();
211
- const aztecNodeConfig: AztecNodeConfig = {
212
- ...rest,
213
- ...config,
214
- l1Contracts: { ...l1Contracts, ...config.l1Contracts },
215
- };
216
- logger.info('createAztecNode', aztecNodeConfig);
217
- const node = await AztecNodeService.createAndSync(aztecNodeConfig, deps, options);
218
- return node;
219
- }
220
-
221
- /**
222
- * Create and start a new Aztec PXE HTTP Server
223
- * @param config - Optional PXE settings.
224
- */
225
- export async function createAztecPXE(node: AztecNode, config: Partial<PXEServiceConfig> = {}) {
226
- const pxeServiceConfig: PXEServiceConfig = { ...getPXEServiceConfig(), ...config };
227
- const pxe = await createPXEService(node, pxeServiceConfig);
228
- return pxe;
229
- }
@@ -1,46 +0,0 @@
1
- import type { FeePaymentMethod } from '@aztec/aztec.js';
2
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
- import { type FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
4
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import type { PXE } from '@aztec/stdlib/interfaces/client';
6
-
7
- import { getDeployedSponsoredFPCAddress } from './sponsored_fpc.js';
8
-
9
- /**
10
- * A payment method that uses the SponsoredFPCContract to pay the fee unconditionally.
11
- */
12
- export class SponsoredFeePaymentMethod implements FeePaymentMethod {
13
- constructor(
14
- /**
15
- * Contract which will pay the fee.
16
- */
17
- private paymentContract: AztecAddress,
18
- ) {}
19
-
20
- static async new(pxe: PXE) {
21
- const sponsoredFPC = await getDeployedSponsoredFPCAddress(pxe);
22
- return new SponsoredFeePaymentMethod(sponsoredFPC);
23
- }
24
-
25
- getAsset(): Promise<AztecAddress> {
26
- return Promise.resolve(ProtocolContractAddress.FeeJuice);
27
- }
28
-
29
- getFeePayer(): Promise<AztecAddress> {
30
- return Promise.resolve(this.paymentContract);
31
- }
32
-
33
- async getFunctionCalls(): Promise<FunctionCall[]> {
34
- return [
35
- {
36
- name: 'sponsor_unconditionally',
37
- to: this.paymentContract,
38
- selector: await FunctionSelector.fromSignature('sponsor_unconditionally()'),
39
- type: FunctionType.PRIVATE,
40
- isStatic: false,
41
- args: [],
42
- returnTypes: [],
43
- },
44
- ];
45
- }
46
- }
@@ -1,38 +0,0 @@
1
- import {
2
- type ContractInstanceWithAddress,
3
- Fr,
4
- type PXE,
5
- type Wallet,
6
- getContractInstanceFromDeployParams,
7
- } from '@aztec/aztec.js';
8
- import type { LogFn } from '@aztec/foundation/log';
9
- import { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC';
10
-
11
- const SPONSORED_FPC_SALT = new Fr(0);
12
-
13
- async function getSponsoredFPCInstance(): Promise<ContractInstanceWithAddress> {
14
- return await getContractInstanceFromDeployParams(SponsoredFPCContract.artifact, {
15
- salt: SPONSORED_FPC_SALT,
16
- });
17
- }
18
-
19
- export async function getSponsoredFPCAddress() {
20
- return (await getSponsoredFPCInstance()).address;
21
- }
22
-
23
- export async function setupSponsoredFPC(deployer: Wallet, log: LogFn) {
24
- const deployed = await SponsoredFPCContract.deploy(deployer)
25
- .send({ contractAddressSalt: SPONSORED_FPC_SALT, universalDeploy: true })
26
- .deployed();
27
-
28
- log(`SponsoredFPC: ${deployed.address}`);
29
- }
30
-
31
- export async function getDeployedSponsoredFPCAddress(pxe: PXE) {
32
- const fpc = await getSponsoredFPCAddress();
33
- const contracts = await pxe.getContracts();
34
- if (!contracts.find(c => c.equals(fpc))) {
35
- throw new Error('SponsoredFPC not deployed.');
36
- }
37
- return fpc;
38
- }