@aztec/aztec 0.0.0-test.0

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 (122) hide show
  1. package/README.md +57 -0
  2. package/dest/bin/index.d.ts +3 -0
  3. package/dest/bin/index.d.ts.map +1 -0
  4. package/dest/bin/index.js +46 -0
  5. package/dest/cli/aztec_start_action.d.ts +3 -0
  6. package/dest/cli/aztec_start_action.d.ts.map +1 -0
  7. package/dest/cli/aztec_start_action.js +108 -0
  8. package/dest/cli/aztec_start_options.d.ts +15 -0
  9. package/dest/cli/aztec_start_options.d.ts.map +1 -0
  10. package/dest/cli/aztec_start_options.js +348 -0
  11. package/dest/cli/chain_l2_config.d.ts +19 -0
  12. package/dest/cli/chain_l2_config.d.ts.map +1 -0
  13. package/dest/cli/chain_l2_config.js +56 -0
  14. package/dest/cli/cli.d.ts +9 -0
  15. package/dest/cli/cli.d.ts.map +1 -0
  16. package/dest/cli/cli.js +33 -0
  17. package/dest/cli/cmds/start_archiver.d.ts +9 -0
  18. package/dest/cli/cmds/start_archiver.d.ts.map +1 -0
  19. package/dest/cli/cmds/start_archiver.js +42 -0
  20. package/dest/cli/cmds/start_blob_sink.d.ts +3 -0
  21. package/dest/cli/cmds/start_blob_sink.d.ts.map +1 -0
  22. package/dest/cli/cmds/start_blob_sink.js +17 -0
  23. package/dest/cli/cmds/start_bot.d.ts +11 -0
  24. package/dest/cli/cmds/start_bot.d.ts.map +1 -0
  25. package/dest/cli/cmds/start_bot.js +31 -0
  26. package/dest/cli/cmds/start_faucet.d.ts +4 -0
  27. package/dest/cli/cmds/start_faucet.d.ts.map +1 -0
  28. package/dest/cli/cmds/start_faucet.js +20 -0
  29. package/dest/cli/cmds/start_node.d.ts +7 -0
  30. package/dest/cli/cmds/start_node.d.ts.map +1 -0
  31. package/dest/cli/cmds/start_node.js +131 -0
  32. package/dest/cli/cmds/start_p2p_bootstrap.d.ts +6 -0
  33. package/dest/cli/cmds/start_p2p_bootstrap.d.ts.map +1 -0
  34. package/dest/cli/cmds/start_p2p_bootstrap.js +26 -0
  35. package/dest/cli/cmds/start_prover_agent.d.ts +4 -0
  36. package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -0
  37. package/dest/cli/cmds/start_prover_agent.js +41 -0
  38. package/dest/cli/cmds/start_prover_broker.d.ts +9 -0
  39. package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -0
  40. package/dest/cli/cmds/start_prover_broker.js +31 -0
  41. package/dest/cli/cmds/start_prover_node.d.ts +7 -0
  42. package/dest/cli/cmds/start_prover_node.d.ts.map +1 -0
  43. package/dest/cli/cmds/start_prover_node.js +110 -0
  44. package/dest/cli/cmds/start_pxe.d.ts +16 -0
  45. package/dest/cli/cmds/start_pxe.d.ts.map +1 -0
  46. package/dest/cli/cmds/start_pxe.js +95 -0
  47. package/dest/cli/cmds/start_txe.d.ts +3 -0
  48. package/dest/cli/cmds/start_txe.d.ts.map +1 -0
  49. package/dest/cli/cmds/start_txe.js +11 -0
  50. package/dest/cli/get_l1_config.d.ts +7 -0
  51. package/dest/cli/get_l1_config.d.ts.map +1 -0
  52. package/dest/cli/get_l1_config.js +13 -0
  53. package/dest/cli/index.d.ts +2 -0
  54. package/dest/cli/index.d.ts.map +1 -0
  55. package/dest/cli/index.js +1 -0
  56. package/dest/cli/util.d.ts +46 -0
  57. package/dest/cli/util.d.ts.map +1 -0
  58. package/dest/cli/util.js +154 -0
  59. package/dest/cli/versioning.d.ts +4 -0
  60. package/dest/cli/versioning.d.ts.map +1 -0
  61. package/dest/cli/versioning.js +9 -0
  62. package/dest/examples/token.d.ts +2 -0
  63. package/dest/examples/token.d.ts.map +1 -0
  64. package/dest/examples/token.js +46 -0
  65. package/dest/examples/util.d.ts +20 -0
  66. package/dest/examples/util.d.ts.map +1 -0
  67. package/dest/examples/util.js +31 -0
  68. package/dest/index.d.ts +2 -0
  69. package/dest/index.d.ts.map +1 -0
  70. package/dest/index.js +1 -0
  71. package/dest/mnemonic.d.ts +2 -0
  72. package/dest/mnemonic.d.ts.map +1 -0
  73. package/dest/mnemonic.js +1 -0
  74. package/dest/sandbox/banana_fpc.d.ts +11 -0
  75. package/dest/sandbox/banana_fpc.d.ts.map +1 -0
  76. package/dest/sandbox/banana_fpc.js +79 -0
  77. package/dest/sandbox/index.d.ts +5 -0
  78. package/dest/sandbox/index.d.ts.map +1 -0
  79. package/dest/sandbox/index.js +4 -0
  80. package/dest/sandbox/sandbox.d.ts +76 -0
  81. package/dest/sandbox/sandbox.d.ts.map +1 -0
  82. package/dest/sandbox/sandbox.js +181 -0
  83. package/dest/sandbox/sponsored_fee_payment_method.d.ts +23 -0
  84. package/dest/sandbox/sponsored_fee_payment_method.d.ts.map +1 -0
  85. package/dest/sandbox/sponsored_fee_payment_method.js +36 -0
  86. package/dest/sandbox/sponsored_fpc.d.ts +6 -0
  87. package/dest/sandbox/sponsored_fpc.d.ts.map +1 -0
  88. package/dest/sandbox/sponsored_fpc.js +26 -0
  89. package/dest/splash.d.ts +3 -0
  90. package/dest/splash.d.ts.map +1 -0
  91. package/dest/splash.js +2 -0
  92. package/package.json +118 -0
  93. package/src/bin/index.ts +54 -0
  94. package/src/cli/aztec_start_action.ts +114 -0
  95. package/src/cli/aztec_start_options.ts +371 -0
  96. package/src/cli/chain_l2_config.ts +74 -0
  97. package/src/cli/cli.ts +48 -0
  98. package/src/cli/cmds/start_archiver.ts +55 -0
  99. package/src/cli/cmds/start_blob_sink.ts +31 -0
  100. package/src/cli/cmds/start_bot.ts +49 -0
  101. package/src/cli/cmds/start_faucet.ts +34 -0
  102. package/src/cli/cmds/start_node.ts +151 -0
  103. package/src/cli/cmds/start_p2p_bootstrap.ts +29 -0
  104. package/src/cli/cmds/start_prover_agent.ts +68 -0
  105. package/src/cli/cmds/start_prover_broker.ts +46 -0
  106. package/src/cli/cmds/start_prover_node.ts +121 -0
  107. package/src/cli/cmds/start_pxe.ts +129 -0
  108. package/src/cli/cmds/start_txe.ts +15 -0
  109. package/src/cli/get_l1_config.ts +18 -0
  110. package/src/cli/index.ts +1 -0
  111. package/src/cli/util.ts +216 -0
  112. package/src/cli/versioning.ts +13 -0
  113. package/src/examples/token.ts +65 -0
  114. package/src/examples/util.ts +45 -0
  115. package/src/index.ts +7 -0
  116. package/src/mnemonic.ts +1 -0
  117. package/src/sandbox/banana_fpc.ts +83 -0
  118. package/src/sandbox/index.ts +5 -0
  119. package/src/sandbox/sandbox.ts +229 -0
  120. package/src/sandbox/sponsored_fee_payment_method.ts +46 -0
  121. package/src/sandbox/sponsored_fpc.ts +38 -0
  122. package/src/splash.ts +10 -0
@@ -0,0 +1,216 @@
1
+ import type { AccountManager, Fr } from '@aztec/aztec.js';
2
+ import type { ConfigMappingsType } from '@aztec/foundation/config';
3
+ import type { LogFn } from '@aztec/foundation/log';
4
+ import type { PXEService } from '@aztec/pxe/server';
5
+
6
+ import chalk from 'chalk';
7
+ import type { Command } from 'commander';
8
+
9
+ import { type AztecStartOption, aztecStartOptions } from './aztec_start_options.js';
10
+
11
+ export const installSignalHandlers = (logFn: LogFn, cb?: Array<() => Promise<void>>) => {
12
+ const shutdown = async () => {
13
+ logFn('Shutting down...');
14
+ if (cb) {
15
+ await Promise.all(cb);
16
+ }
17
+ process.exit(0);
18
+ };
19
+ process.removeAllListeners('SIGINT');
20
+ process.removeAllListeners('SIGTERM');
21
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
22
+ process.once('SIGINT', shutdown);
23
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
24
+ process.once('SIGTERM', shutdown);
25
+ };
26
+
27
+ /**
28
+ * Creates logs for the initial accounts
29
+ * @param accounts - The initial accounts
30
+ * @param pxe - A PXE instance to get the registered accounts
31
+ * @returns A string array containing the initial accounts details
32
+ */
33
+ export async function createAccountLogs(
34
+ accountsWithSecretKeys: {
35
+ /**
36
+ * The account object
37
+ */
38
+ account: AccountManager;
39
+ /**
40
+ * The secret key of the account
41
+ */
42
+ secretKey: Fr;
43
+ }[],
44
+ pxe: PXEService,
45
+ ) {
46
+ const registeredAccounts = await pxe.getRegisteredAccounts();
47
+ const accountLogStrings = [`Initial Accounts:\n\n`];
48
+ for (const accountWithSecretKey of accountsWithSecretKeys) {
49
+ const completeAddress = await accountWithSecretKey.account.getCompleteAddress();
50
+ if (registeredAccounts.find(a => a.equals(completeAddress))) {
51
+ accountLogStrings.push(` Address: ${completeAddress.address.toString()}\n`);
52
+ accountLogStrings.push(` Partial Address: ${completeAddress.partialAddress.toString()}\n`);
53
+ accountLogStrings.push(` Secret Key: ${accountWithSecretKey.secretKey.toString()}\n`);
54
+ accountLogStrings.push(
55
+ ` Master nullifier public key: ${completeAddress.publicKeys.masterNullifierPublicKey.toString()}\n`,
56
+ );
57
+ accountLogStrings.push(
58
+ ` Master incoming viewing public key: ${completeAddress.publicKeys.masterIncomingViewingPublicKey.toString()}\n\n`,
59
+ );
60
+ accountLogStrings.push(
61
+ ` Master outgoing viewing public key: ${completeAddress.publicKeys.masterOutgoingViewingPublicKey.toString()}\n\n`,
62
+ );
63
+ accountLogStrings.push(
64
+ ` Master tagging public key: ${completeAddress.publicKeys.masterTaggingPublicKey.toString()}\n\n`,
65
+ );
66
+ }
67
+ }
68
+ return accountLogStrings;
69
+ }
70
+
71
+ export function getMaxLengths(sections: { [key: string]: AztecStartOption[] }): [number, number] {
72
+ let maxFlagLength = 0;
73
+ let maxDefaultLength = 0;
74
+
75
+ Object.values(sections).forEach(options => {
76
+ options.forEach(option => {
77
+ if (option.flag.length > maxFlagLength) {
78
+ maxFlagLength = option.flag.length;
79
+ }
80
+ const defaultLength = option.defaultValue ? option.defaultValue.length : 0;
81
+ if (defaultLength > maxDefaultLength) {
82
+ maxDefaultLength = defaultLength;
83
+ }
84
+ });
85
+ });
86
+
87
+ return [maxFlagLength + 1, maxDefaultLength + 1];
88
+ }
89
+
90
+ export function formatHelpLine(
91
+ option: string,
92
+ defaultValue: string,
93
+ envVar: string,
94
+ maxOptionLength: number,
95
+ maxDefaultLength: number,
96
+ ): string {
97
+ const paddedOption = option.padEnd(maxOptionLength + 2, ' ');
98
+ const paddedDefault = defaultValue.padEnd(maxDefaultLength + 2, ' ');
99
+
100
+ return `${chalk.cyan(paddedOption)}${chalk.yellow(paddedDefault)}${chalk.green(envVar)}`;
101
+ }
102
+
103
+ const getDefaultOrEnvValue = (opt: AztecStartOption) => {
104
+ let val;
105
+ // if the option is set in the environment, use that & parse it
106
+ if (opt.envVar && process.env[opt.envVar]) {
107
+ val = process.env[opt.envVar];
108
+ if (val && opt.parseVal) {
109
+ return opt.parseVal(val);
110
+ }
111
+ // if no env variable, use the default value
112
+ } else if (opt.defaultValue) {
113
+ val = opt.defaultValue;
114
+ }
115
+
116
+ return val;
117
+ };
118
+
119
+ // Function to add options dynamically
120
+ export const addOptions = (cmd: Command, options: AztecStartOption[]) => {
121
+ options.forEach(opt => {
122
+ cmd.option(
123
+ opt.flag,
124
+ `${opt.description} (default: ${opt.defaultValue}) ($${opt.envVar})`,
125
+ opt.parseVal ? opt.parseVal : val => val,
126
+ getDefaultOrEnvValue(opt),
127
+ );
128
+ });
129
+ };
130
+
131
+ export const printAztecStartHelpText = () => {
132
+ const helpTextLines: string[] = [''];
133
+ const [maxFlagLength, maxDefaultLength] = getMaxLengths(aztecStartOptions);
134
+
135
+ Object.keys(aztecStartOptions).forEach(category => {
136
+ helpTextLines.push(chalk.bold.blue(` ${category}`));
137
+ helpTextLines.push('');
138
+
139
+ aztecStartOptions[category].forEach(opt => {
140
+ const defaultValueText = opt.defaultValue
141
+ ? `(default: ${opt.printDefault ? opt.printDefault(opt.defaultValue) : opt.defaultValue})`
142
+ : '';
143
+ const envVarText = opt.envVar ? `($${opt.envVar})` : '';
144
+ const flagText = `${opt.flag}`;
145
+
146
+ const paddedText = formatHelpLine(flagText, defaultValueText, envVarText, maxFlagLength, maxDefaultLength);
147
+
148
+ helpTextLines.push(` ${paddedText}`);
149
+ helpTextLines.push(` ${chalk.white(opt.description)}`);
150
+ helpTextLines.push('');
151
+ });
152
+ });
153
+
154
+ return helpTextLines.join('\n');
155
+ };
156
+
157
+ /**
158
+ * Extracts namespaced options from a key-value map.
159
+ * @param options - Key-value map of options.
160
+ * @param namespace - The namespace to extract.
161
+ * @returns Key-value map of namespaced options.
162
+ */
163
+ export const extractNamespacedOptions = (options: Record<string, any>, namespace: string) => {
164
+ const extract = `${namespace}.`;
165
+ const namespacedOptions: Record<string, any> = {};
166
+ for (const key in options) {
167
+ if (key.startsWith(extract)) {
168
+ namespacedOptions[key.replace(extract, '')] = options[key];
169
+ }
170
+ }
171
+ return namespacedOptions;
172
+ };
173
+
174
+ /**
175
+ * Extracts relevant options from a key-value map.
176
+ * @template T - The type of the relevant options.
177
+ * @param options - Key-value map of options.
178
+ * @param mappings - The mappings to extract.
179
+ * @param namespace - The namespace to extract for.
180
+ * @returns Key-value map of relevant options.
181
+ */
182
+ export const extractRelevantOptions = <T>(
183
+ options: Record<string, any>,
184
+ mappings: ConfigMappingsType<T>,
185
+ namespace: string,
186
+ ): T => {
187
+ const relevantOptions: T = {} as T;
188
+
189
+ // Iterate over each key in the options
190
+ Object.keys(options).forEach(optionKey => {
191
+ const keyParts = optionKey.split('.');
192
+ const optionNamespace = keyParts.length > 1 ? keyParts[0] : '';
193
+ const mainKey = keyParts.length > 1 ? keyParts[1] : keyParts[0];
194
+
195
+ // Check if the key exists in the mappings
196
+ if (mainKey in mappings) {
197
+ // Check for duplicates in the options
198
+ const duplicates = Object.keys(options).filter(optKey => {
199
+ const optKeyParts = optKey.split('.');
200
+ return optKeyParts[1] === mainKey || optKeyParts[0] === mainKey;
201
+ });
202
+
203
+ // If duplicates are found, use the namespace to differentiate
204
+ if (duplicates.length > 1) {
205
+ if (namespace === optionNamespace) {
206
+ relevantOptions[mainKey as keyof T] = options[optionKey];
207
+ }
208
+ } else {
209
+ // If no duplicates, extract the value without considering the namespace
210
+ relevantOptions[mainKey as keyof T] = options[optionKey];
211
+ }
212
+ }
213
+ });
214
+
215
+ return relevantOptions;
216
+ };
@@ -0,0 +1,13 @@
1
+ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
2
+ import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
3
+ import type { ChainConfig } from '@aztec/stdlib/config';
4
+ import { type ComponentsVersions, getComponentsVersionsFromConfig } from '@aztec/stdlib/versioning';
5
+
6
+ export function getVersions(config?: ChainConfig): Partial<ComponentsVersions> {
7
+ return config
8
+ ? getComponentsVersionsFromConfig(config, protocolContractTreeRoot, getVKTreeRoot())
9
+ : {
10
+ l2CircuitsVkTreeRoot: getVKTreeRoot().toString(),
11
+ l2ProtocolContractsTreeRoot: protocolContractTreeRoot.toString(),
12
+ };
13
+ }
@@ -0,0 +1,65 @@
1
+ import { getDeployedTestAccountsWallets } from '@aztec/accounts/testing';
2
+ import { createPXEClient } from '@aztec/aztec.js';
3
+ import { createLogger } from '@aztec/foundation/log';
4
+ import { TokenContract } from '@aztec/noir-contracts.js/Token';
5
+
6
+ const logger = createLogger('example:token');
7
+
8
+ const url = 'http://localhost:8080';
9
+
10
+ const pxe = createPXEClient(url);
11
+
12
+ const ALICE_MINT_BALANCE = 333n;
13
+ const TRANSFER_AMOUNT = 33n;
14
+
15
+ /**
16
+ * Main function.
17
+ */
18
+ async function main() {
19
+ logger.info('Running token contract test on HTTP interface.');
20
+
21
+ const [aliceWallet, bobWallet] = await getDeployedTestAccountsWallets(pxe);
22
+ const alice = aliceWallet.getCompleteAddress();
23
+ const bob = bobWallet.getCompleteAddress();
24
+
25
+ logger.info(`Fetched Alice and Bob accounts: ${alice.address.toString()}, ${bob.address.toString()}`);
26
+
27
+ logger.info('Deploying Token...');
28
+ const token = await TokenContract.deploy(aliceWallet, alice, 'TokenName', 'TokenSymbol', 18).send().deployed();
29
+ logger.info('Token deployed');
30
+
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
+ // Mint tokens to Alice
36
+ logger.info(`Minting ${ALICE_MINT_BALANCE} more coins to Alice...`);
37
+ const from = aliceWallet.getAddress(); // we are setting from to Alice here because we need a sender to calculate the tag
38
+ await tokenAlice.methods.mint_to_private(from, aliceWallet.getAddress(), ALICE_MINT_BALANCE).send().wait();
39
+
40
+ logger.info(`${ALICE_MINT_BALANCE} tokens were successfully minted by Alice and transferred to private`);
41
+
42
+ const balanceAfterMint = await tokenAlice.methods.balance_of_private(alice).simulate();
43
+ logger.info(`Tokens successfully minted. New Alice's balance: ${balanceAfterMint}`);
44
+
45
+ // We will now transfer tokens from Alice to Bob
46
+ logger.info(`Transferring ${TRANSFER_AMOUNT} tokens from Alice to Bob...`);
47
+ await tokenAlice.methods.transfer(bob, TRANSFER_AMOUNT).send().wait();
48
+
49
+ // Check the new balances
50
+ const aliceBalance = await tokenAlice.methods.balance_of_private(alice).simulate();
51
+ logger.info(`Alice's balance ${aliceBalance}`);
52
+
53
+ const bobBalance = await tokenBob.methods.balance_of_private(bob).simulate();
54
+ logger.info(`Bob's balance ${bobBalance}`);
55
+ }
56
+
57
+ main()
58
+ .then(() => {
59
+ logger.info('Finished running successfully.');
60
+ process.exit(0);
61
+ })
62
+ .catch(err => {
63
+ logger.error('Error in main fn: ', err);
64
+ process.exit(1);
65
+ });
@@ -0,0 +1,45 @@
1
+ import { EthAddress } from '@aztec/aztec.js';
2
+ import type { ViemPublicClient, ViemWalletClient } from '@aztec/ethereum';
3
+ import { jsonStringify } from '@aztec/foundation/json-rpc';
4
+
5
+ import type { Abi, Narrow } from 'abitype';
6
+ import type { Hex } from 'viem';
7
+
8
+ /**
9
+ * Helper function to deploy ETH contracts.
10
+ * @param walletClient - A viem WalletClient.
11
+ * @param publicClient - A viem PublicClient.
12
+ * @param abi - The ETH contract's ABI (as abitype's Abi).
13
+ * @param bytecode - The ETH contract's bytecode.
14
+ * @param args - Constructor arguments for the contract.
15
+ * @returns The ETH address the contract was deployed to.
16
+ */
17
+ export async function deployL1Contract(
18
+ walletClient: ViemWalletClient,
19
+ publicClient: ViemPublicClient,
20
+ abi: Narrow<Abi | readonly unknown[]>,
21
+ bytecode: Hex,
22
+ args: readonly unknown[] = [],
23
+ ): Promise<EthAddress> {
24
+ const hash = await walletClient.deployContract({
25
+ abi,
26
+ bytecode,
27
+ args,
28
+ });
29
+
30
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
31
+ const contractAddress = receipt.contractAddress;
32
+ if (!contractAddress) {
33
+ throw new Error(`No contract address found in receipt: ${jsonStringify(receipt)}`);
34
+ }
35
+
36
+ return EthAddress.fromString(receipt.contractAddress!);
37
+ }
38
+
39
+ /**
40
+ * Sleep for a given number of milliseconds.
41
+ * @param ms - the number of milliseconds to sleep for
42
+ */
43
+ export function delay(ms: number): Promise<void> {
44
+ return new Promise<void>(resolve => setTimeout(resolve, ms));
45
+ }
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export {
2
+ createSandbox,
3
+ getDeployedBananaCoinAddress,
4
+ getDeployedBananaFPCAddress,
5
+ getDeployedSponsoredFPCAddress,
6
+ SponsoredFeePaymentMethod,
7
+ } from './sandbox/index.js';
@@ -0,0 +1 @@
1
+ export const DefaultMnemonic = 'test test test test test test test test test test test junk';
@@ -0,0 +1,83 @@
1
+ import { type InitialAccountData, getInitialTestAccounts } from '@aztec/accounts/testing';
2
+ import type { Wallet } from '@aztec/aztec.js';
3
+ import { Fr } from '@aztec/foundation/fields';
4
+ import type { LogFn } from '@aztec/foundation/log';
5
+ import { FPCContract } from '@aztec/noir-contracts.js/FPC';
6
+ import { TokenContract } from '@aztec/noir-contracts.js/Token';
7
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
8
+ import { type ContractInstanceWithAddress, getContractInstanceFromDeployParams } from '@aztec/stdlib/contract';
9
+ import type { PXE } from '@aztec/stdlib/interfaces/client';
10
+
11
+ const BANANA_COIN_SALT = new Fr(0);
12
+ const bananaCoinArgs = {
13
+ name: 'BC',
14
+ symbol: 'BC',
15
+ decimal: 18n,
16
+ };
17
+
18
+ const BANANA_FPC_SALT = new Fr(0);
19
+
20
+ function getBananaAdmin(initialAccounts: InitialAccountData[]): AztecAddress {
21
+ return initialAccounts[0]?.address ?? AztecAddress.ZERO;
22
+ }
23
+
24
+ async function getBananaCoinInstance(initialAccounts: InitialAccountData[]): Promise<ContractInstanceWithAddress> {
25
+ const admin = getBananaAdmin(initialAccounts);
26
+ return await getContractInstanceFromDeployParams(TokenContract.artifact, {
27
+ constructorArgs: [admin, bananaCoinArgs.name, bananaCoinArgs.symbol, bananaCoinArgs.decimal],
28
+ salt: BANANA_COIN_SALT,
29
+ });
30
+ }
31
+
32
+ export async function getBananaCoinAddress(initialAccounts: InitialAccountData[]) {
33
+ return (await getBananaCoinInstance(initialAccounts)).address;
34
+ }
35
+
36
+ async function getBananaFPCInstance(initialAccounts: InitialAccountData[]): Promise<ContractInstanceWithAddress> {
37
+ const bananaCoin = await getBananaCoinAddress(initialAccounts);
38
+ const admin = getBananaAdmin(initialAccounts);
39
+ return await getContractInstanceFromDeployParams(FPCContract.artifact, {
40
+ constructorArgs: [bananaCoin, admin],
41
+ salt: BANANA_FPC_SALT,
42
+ });
43
+ }
44
+
45
+ export async function getBananaFPCAddress(initialAccounts: InitialAccountData[]) {
46
+ return (await getBananaFPCInstance(initialAccounts)).address;
47
+ }
48
+
49
+ export async function setupBananaFPC(initialAccounts: InitialAccountData[], deployer: Wallet, log: LogFn) {
50
+ const bananaCoinAddress = await getBananaCoinAddress(initialAccounts);
51
+ const admin = getBananaAdmin(initialAccounts);
52
+ const [bananaCoin, fpc] = await Promise.all([
53
+ TokenContract.deploy(deployer, admin, bananaCoinArgs.name, bananaCoinArgs.symbol, bananaCoinArgs.decimal)
54
+ .send({ contractAddressSalt: BANANA_COIN_SALT, universalDeploy: true })
55
+ .deployed(),
56
+ FPCContract.deploy(deployer, bananaCoinAddress, admin)
57
+ .send({ contractAddressSalt: BANANA_FPC_SALT, universalDeploy: true })
58
+ .deployed(),
59
+ ]);
60
+
61
+ log(`BananaCoin: ${bananaCoin.address}`);
62
+ log(`FPC: ${fpc.address}`);
63
+ }
64
+
65
+ export async function getDeployedBananaCoinAddress(pxe: PXE) {
66
+ const initialAccounts = await getInitialTestAccounts();
67
+ const bananaCoin = await getBananaCoinAddress(initialAccounts);
68
+ const contracts = await pxe.getContracts();
69
+ if (!contracts.find(c => c.equals(bananaCoin))) {
70
+ throw new Error('BananaCoin not deployed.');
71
+ }
72
+ return bananaCoin;
73
+ }
74
+
75
+ export async function getDeployedBananaFPCAddress(pxe: PXE) {
76
+ const initialAccounts = await getInitialTestAccounts();
77
+ const fpc = await getBananaFPCInstance(initialAccounts);
78
+ const contracts = await pxe.getContracts();
79
+ if (!contracts.find(c => c.equals(fpc.address))) {
80
+ throw new Error('BananaFPC not deployed.');
81
+ }
82
+ return fpc.address;
83
+ }
@@ -0,0 +1,5 @@
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';
@@ -0,0 +1,229 @@
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
+ }