@aztec/cli-wallet 0.75.0-commit.c03ba01a2a4122e43e90d5133ba017e54b90e9d2

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 (48) hide show
  1. package/README.md +2 -0
  2. package/dest/bin/index.js +75 -0
  3. package/dest/cmds/add_authwit.js +4 -0
  4. package/dest/cmds/add_note.js +14 -0
  5. package/dest/cmds/authorize_action.js +17 -0
  6. package/dest/cmds/bridge_fee_juice.js +52 -0
  7. package/dest/cmds/cancel_tx.js +38 -0
  8. package/dest/cmds/check_tx.js +11 -0
  9. package/dest/cmds/create_account.js +98 -0
  10. package/dest/cmds/create_authwit.js +16 -0
  11. package/dest/cmds/deploy.js +83 -0
  12. package/dest/cmds/deploy_account.js +84 -0
  13. package/dest/cmds/index.js +227 -0
  14. package/dest/cmds/register_contract.js +14 -0
  15. package/dest/cmds/register_sender.js +4 -0
  16. package/dest/cmds/send.js +49 -0
  17. package/dest/cmds/simulate.js +26 -0
  18. package/dest/storage/wallet_db.js +180 -0
  19. package/dest/utils/accounts.js +87 -0
  20. package/dest/utils/ecdsa.js +13 -0
  21. package/dest/utils/options/fees.js +189 -0
  22. package/dest/utils/options/index.js +2 -0
  23. package/dest/utils/options/options.js +122 -0
  24. package/dest/utils/pxe_wrapper.js +21 -0
  25. package/package.json +103 -0
  26. package/src/bin/index.ts +121 -0
  27. package/src/cmds/add_authwit.ts +13 -0
  28. package/src/cmds/add_note.ts +30 -0
  29. package/src/cmds/authorize_action.ts +36 -0
  30. package/src/cmds/bridge_fee_juice.ts +88 -0
  31. package/src/cmds/cancel_tx.ts +61 -0
  32. package/src/cmds/check_tx.ts +12 -0
  33. package/src/cmds/create_account.ts +120 -0
  34. package/src/cmds/create_authwit.ts +35 -0
  35. package/src/cmds/deploy.ts +113 -0
  36. package/src/cmds/deploy_account.ts +92 -0
  37. package/src/cmds/index.ts +674 -0
  38. package/src/cmds/register_contract.ts +20 -0
  39. package/src/cmds/register_sender.ts +7 -0
  40. package/src/cmds/send.ts +62 -0
  41. package/src/cmds/simulate.ts +42 -0
  42. package/src/storage/wallet_db.ts +205 -0
  43. package/src/utils/accounts.ts +102 -0
  44. package/src/utils/ecdsa.ts +15 -0
  45. package/src/utils/options/fees.ts +234 -0
  46. package/src/utils/options/index.ts +2 -0
  47. package/src/utils/options/options.ts +175 -0
  48. package/src/utils/pxe_wrapper.ts +26 -0
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # Aztec wallet Documentation
2
+
@@ -0,0 +1,75 @@
1
+ import { Fr, computeSecretHash, fileURLToPath } from '@aztec/aztec.js';
2
+ import { LOCALHOST } from '@aztec/cli/cli-utils';
3
+ import { createConsoleLogger, createLogger } from '@aztec/foundation/log';
4
+ import { AztecLmdbStore } from '@aztec/kv-store/lmdb';
5
+ import { Argument, Command, Option } from 'commander';
6
+ import { mkdirSync, readFileSync } from 'fs';
7
+ import { dirname, join, resolve } from 'path';
8
+ import { injectCommands } from '../cmds/index.js';
9
+ import { Aliases, WalletDB } from '../storage/wallet_db.js';
10
+ import { createAliasOption } from '../utils/options/index.js';
11
+ import { PXEWrapper } from '../utils/pxe_wrapper.js';
12
+ const userLog = createConsoleLogger();
13
+ const debugLogger = createLogger('wallet');
14
+ const { WALLET_DATA_DIRECTORY = '~/.aztec/wallet', PXE_PROVER = 'none' } = process.env;
15
+ function injectInternalCommands(program, log, db) {
16
+ program.command('alias').description('Aliases information for easy reference.').addArgument(new Argument('<type>', 'Type of alias to create').choices(Aliases)).argument('<key>', 'Key to alias.').argument('<value>', 'Value to assign to the alias.').action(async (type, key, value)=>{
17
+ value = db.tryRetrieveAlias(value) || value;
18
+ await db.storeAlias(type, key, value, log);
19
+ });
20
+ program.command('get-alias').description('Shows stored aliases').addArgument(new Argument('[alias]', 'Alias to retrieve')).action((alias)=>{
21
+ if (alias?.includes(':')) {
22
+ const value = db.retrieveAlias(alias);
23
+ log(value);
24
+ } else {
25
+ const aliases = db.listAliases(alias);
26
+ for (const { key, value } of aliases){
27
+ log(`${key} -> ${value}`);
28
+ }
29
+ }
30
+ });
31
+ program.command('create-secret').description('Creates an aliased secret to use in other commands').addOption(createAliasOption('Key to alias the secret with', false).makeOptionMandatory(true)).action(async (_options, command)=>{
32
+ const options = command.optsWithGlobals();
33
+ const { alias } = options;
34
+ const value = Fr.random();
35
+ const hash = computeSecretHash(value);
36
+ await db.storeAlias('secrets', alias, Buffer.from(value.toString()), log);
37
+ await db.storeAlias('secrets', `${alias}:hash`, Buffer.from(hash.toString()), log);
38
+ });
39
+ return program;
40
+ }
41
+ /** CLI wallet main entrypoint */ async function main() {
42
+ const packageJsonPath = resolve(dirname(fileURLToPath(import.meta.url)), '../../package.json');
43
+ const walletVersion = JSON.parse(readFileSync(packageJsonPath).toString()).version;
44
+ const db = WalletDB.getInstance();
45
+ const pxeWrapper = new PXEWrapper();
46
+ const program = new Command('wallet');
47
+ program.description('Aztec wallet').version(walletVersion).option('-d, --data-dir <string>', 'Storage directory for wallet data', WALLET_DATA_DIRECTORY).option('-p, --prover <string>', 'wasm|native|none', PXE_PROVER).addOption(new Option('--remote-pxe', 'Connect to an external PXE RPC server, instead of the local one').env('REMOTE_PXE').default(false).conflicts('rpc-url')).addOption(new Option('-n, --node-url <string>', 'URL of the Aztec node to connect to').env('AZTEC_NODE_URL').default(`http://${LOCALHOST}:8080`)).hook('preSubcommand', async (command)=>{
48
+ const { dataDir, remotePxe, nodeUrl, prover } = command.optsWithGlobals();
49
+ if (!remotePxe) {
50
+ debugLogger.info('Using local PXE service');
51
+ const bbBinaryPath = prover === 'native' ? resolve(dirname(fileURLToPath(import.meta.url)), '../../../../barretenberg/cpp/build/bin/bb') : undefined;
52
+ const bbWorkingDirectory = dataDir + '/bb';
53
+ const proverEnabled = prover !== 'none';
54
+ mkdirSync(bbWorkingDirectory, {
55
+ recursive: true
56
+ });
57
+ await pxeWrapper.init(nodeUrl, join(dataDir, 'pxe'), {
58
+ ...proverEnabled && {
59
+ proverEnabled,
60
+ bbBinaryPath,
61
+ bbWorkingDirectory
62
+ }
63
+ });
64
+ }
65
+ db.init(AztecLmdbStore.open(dataDir));
66
+ });
67
+ injectCommands(program, userLog, debugLogger, db, pxeWrapper);
68
+ injectInternalCommands(program, userLog, db);
69
+ await program.parseAsync(process.argv);
70
+ }
71
+ main().catch((err)=>{
72
+ debugLogger.error(`Error in command execution`);
73
+ debugLogger.error(err + '\n' + err.stack);
74
+ process.exit(1);
75
+ });
@@ -0,0 +1,4 @@
1
+ export async function addAuthwit(wallet, authwit, authorizer, log) {
2
+ await wallet.addAuthWitness(authwit);
3
+ log(`Added authorization witness from ${authorizer}`);
4
+ }
@@ -0,0 +1,14 @@
1
+ import { ExtendedNote, Note } from '@aztec/circuit-types';
2
+ import { getContractArtifact, parseFields } from '@aztec/cli/utils';
3
+ export async function addNote(wallet, address, contractAddress, noteName, storageFieldName, artifactPath, txHash, noteBody, log) {
4
+ const fields = parseFields(noteBody);
5
+ const note = new Note(fields);
6
+ const contractArtifact = await getContractArtifact(artifactPath, log);
7
+ const contractNote = contractArtifact.notes[noteName];
8
+ const storageField = contractArtifact.storageLayout[storageFieldName];
9
+ if (!contractNote) {
10
+ throw new Error(`Note ${noteName} not found in contract ${contractArtifact.name}`);
11
+ }
12
+ const extendedNote = new ExtendedNote(note, address, contractAddress, storageField.slot, contractNote.id, txHash);
13
+ await wallet.addNote(extendedNote);
14
+ }
@@ -0,0 +1,17 @@
1
+ import { Contract } from '@aztec/aztec.js';
2
+ import { prepTx } from '@aztec/cli/utils';
3
+ export async function authorizeAction(wallet, functionName, caller, functionArgsIn, contractArtifactPath, contractAddress, log) {
4
+ const { functionArgs, contractArtifact, isPrivate } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
5
+ if (isPrivate) {
6
+ throw new Error('Cannot authorize private function. To allow a third party to call a private function, please create an authorization witness via the create-authwit command');
7
+ }
8
+ const contract = await Contract.at(contractAddress, contractArtifact, wallet);
9
+ const action = contract.methods[functionName](...functionArgs);
10
+ const setAuthwitnessInteraction = await wallet.setPublicAuthWit({
11
+ caller,
12
+ action
13
+ }, true);
14
+ const witness = await setAuthwitnessInteraction.send().wait();
15
+ log(`Authorized action ${functionName} on contract ${contractAddress} for caller ${caller}`);
16
+ return witness;
17
+ }
@@ -0,0 +1,52 @@
1
+ import { L1FeeJuicePortalManager } from '@aztec/aztec.js';
2
+ import { prettyPrintJSON } from '@aztec/cli/utils';
3
+ import { createEthereumChain, createL1Clients } from '@aztec/ethereum';
4
+ import { Fr } from '@aztec/foundation/fields';
5
+ export async function bridgeL1FeeJuice(amount, recipient, pxe, l1RpcUrl, chainId, privateKey, mnemonic, mint, json, wait, interval = 60_000, log, debugLogger) {
6
+ // Prepare L1 client
7
+ const chain = createEthereumChain(l1RpcUrl, chainId);
8
+ const { publicClient, walletClient } = createL1Clients(chain.rpcUrl, privateKey ?? mnemonic, chain.chainInfo);
9
+ const { protocolContractAddresses: { feeJuice: feeJuiceAddress } } = await pxe.getPXEInfo();
10
+ // Setup portal manager
11
+ const portal = await L1FeeJuicePortalManager.new(pxe, publicClient, walletClient, debugLogger);
12
+ const { claimAmount, claimSecret, messageHash, messageLeafIndex } = await portal.bridgeTokensPublic(recipient, amount, mint);
13
+ if (json) {
14
+ const out = {
15
+ claimAmount,
16
+ claimSecret,
17
+ messageLeafIndex
18
+ };
19
+ log(prettyPrintJSON(out));
20
+ } else {
21
+ if (mint) {
22
+ log(`Minted ${claimAmount} fee juice on L1 and pushed to L2 portal`);
23
+ } else {
24
+ log(`Bridged ${claimAmount} fee juice to L2 portal`);
25
+ }
26
+ log(`claimAmount=${claimAmount},claimSecret=${claimSecret},messageHash=${messageHash},messageLeafIndex=${messageLeafIndex}\n`);
27
+ log(`Note: You need to wait for two L2 blocks before pulling them from the L2 side`);
28
+ if (wait) {
29
+ log(`This command will now continually poll every ${interval / 1000}s for the inclusion of the newly created L1 to L2 message`);
30
+ }
31
+ }
32
+ if (wait) {
33
+ const delayedCheck = (delay)=>{
34
+ return new Promise((resolve, reject)=>{
35
+ setTimeout(()=>{
36
+ void pxe.getL1ToL2MembershipWitness(feeJuiceAddress, Fr.fromHexString(messageHash), claimSecret).then((witness)=>resolve(witness)).catch((err)=>reject(err));
37
+ }, delay);
38
+ });
39
+ };
40
+ let witness;
41
+ while(!witness){
42
+ witness = await delayedCheck(interval);
43
+ if (!witness) {
44
+ log(`No L1 to L2 message found yet, checking again in ${interval / 1000}s`);
45
+ }
46
+ }
47
+ }
48
+ return [
49
+ claimSecret,
50
+ messageLeafIndex
51
+ ];
52
+ }
@@ -0,0 +1,38 @@
1
+ import { SentTx, TxStatus } from '@aztec/aztec.js';
2
+ import { GasFees, GasSettings } from '@aztec/circuits.js';
3
+ export async function cancelTx(wallet, { txHash, gasSettings: prevTxGasSettings, nonce, cancellable }, paymentMethod, increasedFees, maxFeesPerGas, log) {
4
+ const receipt = await wallet.getTxReceipt(txHash);
5
+ if (receipt.status !== TxStatus.PENDING || !cancellable) {
6
+ log(`Transaction is in status ${receipt.status} and cannot be cancelled`);
7
+ return;
8
+ }
9
+ const maxPriorityFeesPerGas = new GasFees(prevTxGasSettings.maxPriorityFeesPerGas.feePerDaGas.add(increasedFees.feePerDaGas), prevTxGasSettings.maxPriorityFeesPerGas.feePerL2Gas.add(increasedFees.feePerL2Gas));
10
+ const fee = {
11
+ paymentMethod,
12
+ gasSettings: GasSettings.from({
13
+ ...prevTxGasSettings,
14
+ maxPriorityFeesPerGas,
15
+ maxFeesPerGas: maxFeesPerGas ?? prevTxGasSettings.maxFeesPerGas
16
+ })
17
+ };
18
+ const txRequest = await wallet.createTxExecutionRequest({
19
+ calls: [],
20
+ fee,
21
+ nonce,
22
+ cancellable: true
23
+ });
24
+ const txSimulationResult = await wallet.simulateTx(txRequest, true);
25
+ const txProvingResult = await wallet.proveTx(txRequest, txSimulationResult.privateExecutionResult);
26
+ const sentTx = new SentTx(wallet, wallet.sendTx(txProvingResult.toTx()));
27
+ try {
28
+ await sentTx.wait();
29
+ log('Transaction has been cancelled');
30
+ const cancelReceipt = await sentTx.getReceipt();
31
+ log(` Tx fee: ${cancelReceipt.transactionFee}`);
32
+ log(` Status: ${cancelReceipt.status}`);
33
+ log(` Block number: ${cancelReceipt.blockNumber}`);
34
+ log(` Block hash: ${cancelReceipt.blockHash?.toString()}`);
35
+ } catch (err) {
36
+ log(`Could not cancel transaction\n ${err.message}`);
37
+ }
38
+ }
@@ -0,0 +1,11 @@
1
+ import { inspectTx } from '@aztec/cli/inspect';
2
+ export async function checkTx(client, txHash, statusOnly, log) {
3
+ if (statusOnly) {
4
+ const receipt = await client.getTxReceipt(txHash);
5
+ return receipt.status;
6
+ } else {
7
+ await inspectTx(client, txHash, log, {
8
+ includeBlockInfo: true
9
+ });
10
+ }
11
+ }
@@ -0,0 +1,98 @@
1
+ import { prettyPrintJSON } from '@aztec/cli/cli-utils';
2
+ import { Fr } from '@aztec/foundation/fields';
3
+ import { createOrRetrieveAccount } from '../utils/accounts.js';
4
+ import { printGasEstimates } from '../utils/options/fees.js';
5
+ export async function createAccount(client, accountType, secretKey, publicKey, alias, registerOnly, publicDeploy, skipInitialization, wait, feeOpts, json, debugLogger, log) {
6
+ secretKey ??= Fr.random();
7
+ const account = await createOrRetrieveAccount(client, undefined /* address, we don't have it yet */ , undefined /* db, as we want to create from scratch */ , secretKey, accountType, Fr.ZERO, publicKey);
8
+ const salt = account.getInstance().salt;
9
+ const { address, publicKeys, partialAddress } = await account.getCompleteAddress();
10
+ const out = {};
11
+ if (json) {
12
+ out.address = address;
13
+ out.publicKey = publicKeys;
14
+ if (secretKey) {
15
+ out.secretKey = secretKey;
16
+ }
17
+ out.partialAddress = partialAddress;
18
+ out.salt = salt;
19
+ out.initHash = account.getInstance().initializationHash;
20
+ out.deployer = account.getInstance().deployer;
21
+ } else {
22
+ log(`\nNew account:\n`);
23
+ log(`Address: ${address.toString()}`);
24
+ log(`Public key: 0x${publicKeys.toString()}`);
25
+ if (secretKey) {
26
+ log(`Secret key: ${secretKey.toString()}`);
27
+ }
28
+ log(`Partial address: ${partialAddress.toString()}`);
29
+ log(`Salt: ${salt.toString()}`);
30
+ log(`Init hash: ${account.getInstance().initializationHash.toString()}`);
31
+ log(`Deployer: ${account.getInstance().deployer.toString()}`);
32
+ }
33
+ let tx;
34
+ let txReceipt;
35
+ if (registerOnly) {
36
+ await account.register();
37
+ } else {
38
+ const wallet = await account.getWallet();
39
+ const sendOpts = {
40
+ ...await feeOpts.toSendOpts(wallet),
41
+ skipClassRegistration: !publicDeploy,
42
+ skipPublicDeployment: !publicDeploy,
43
+ skipInitialization: skipInitialization
44
+ };
45
+ if (feeOpts.estimateOnly) {
46
+ const gas = await (await account.getDeployMethod()).estimateGas({
47
+ ...sendOpts
48
+ });
49
+ if (json) {
50
+ out.fee = {
51
+ gasLimits: {
52
+ da: gas.gasLimits.daGas,
53
+ l2: gas.gasLimits.l2Gas
54
+ },
55
+ teardownGasLimits: {
56
+ da: gas.teardownGasLimits.daGas,
57
+ l2: gas.teardownGasLimits
58
+ }
59
+ };
60
+ } else {
61
+ printGasEstimates(feeOpts, gas, log);
62
+ }
63
+ } else {
64
+ tx = account.deploy({
65
+ ...sendOpts
66
+ });
67
+ const txHash = await tx.getTxHash();
68
+ debugLogger.debug(`Account contract tx sent with hash ${txHash}`);
69
+ out.txHash = txHash;
70
+ if (wait) {
71
+ if (!json) {
72
+ log(`\nWaiting for account contract deployment...`);
73
+ }
74
+ txReceipt = await tx.wait();
75
+ out.txReceipt = {
76
+ status: txReceipt.status,
77
+ transactionFee: txReceipt.transactionFee
78
+ };
79
+ }
80
+ }
81
+ }
82
+ if (json) {
83
+ log(prettyPrintJSON(out));
84
+ } else {
85
+ if (tx) {
86
+ log(`Deploy tx hash: ${await tx.getTxHash()}`);
87
+ }
88
+ if (txReceipt) {
89
+ log(`Deploy tx fee: ${txReceipt.transactionFee}`);
90
+ }
91
+ }
92
+ return {
93
+ alias,
94
+ address,
95
+ secretKey,
96
+ salt
97
+ };
98
+ }
@@ -0,0 +1,16 @@
1
+ import { Contract } from '@aztec/aztec.js';
2
+ import { prepTx } from '@aztec/cli/utils';
3
+ export async function createAuthwit(wallet, functionName, caller, functionArgsIn, contractArtifactPath, contractAddress, log) {
4
+ const { functionArgs, contractArtifact, isPrivate } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log);
5
+ if (!isPrivate) {
6
+ throw new Error('Cannot create an authwit for a public function. To allow a third party to call a public function, please authorize the action via the authorize-action command');
7
+ }
8
+ const contract = await Contract.at(contractAddress, contractArtifact, wallet);
9
+ const action = contract.methods[functionName](...functionArgs);
10
+ const witness = await wallet.createAuthWit({
11
+ caller,
12
+ action
13
+ });
14
+ log(`Created authorization witness for action ${functionName} on contract ${contractAddress} for caller ${caller}`);
15
+ return witness;
16
+ }
@@ -0,0 +1,83 @@
1
+ import { ContractDeployer, Fr } from '@aztec/aztec.js';
2
+ import { PublicKeys } from '@aztec/circuits.js';
3
+ import { GITHUB_TAG_PREFIX, encodeArgs, getContractArtifact } from '@aztec/cli/utils';
4
+ import { getInitializer } from '@aztec/foundation/abi';
5
+ import { printGasEstimates } from '../utils/options/fees.js';
6
+ export async function deploy(client, wallet, artifactPath, json, publicKeys, rawArgs, salt, initializer, skipPublicDeployment, skipClassRegistration, skipInitialization, universalDeploy, wait, feeOpts, debugLogger, log, logJson) {
7
+ salt ??= Fr.random();
8
+ const contractArtifact = await getContractArtifact(artifactPath, log);
9
+ const constructorArtifact = getInitializer(contractArtifact, initializer);
10
+ const nodeInfo = await client.getNodeInfo();
11
+ const expectedAztecNrVersion = `${GITHUB_TAG_PREFIX}-v${nodeInfo.nodeVersion}`;
12
+ if (contractArtifact.aztecNrVersion && contractArtifact.aztecNrVersion !== expectedAztecNrVersion) {
13
+ log(`\nWarning: Contract was compiled with a different version of Aztec.nr: ${contractArtifact.aztecNrVersion}. Consider updating Aztec.nr to ${expectedAztecNrVersion}\n`);
14
+ }
15
+ const deployer = new ContractDeployer(contractArtifact, wallet, publicKeys ?? PublicKeys.default(), initializer);
16
+ let args = [];
17
+ if (rawArgs.length > 0) {
18
+ if (!constructorArtifact) {
19
+ throw new Error(`Cannot process constructor arguments as no constructor was found`);
20
+ }
21
+ debugLogger.debug(`Input arguments: ${rawArgs.map((x)=>`"${x}"`).join(', ')}`);
22
+ args = encodeArgs(rawArgs, constructorArtifact.parameters);
23
+ debugLogger.debug(`Encoded arguments: ${args.join(', ')}`);
24
+ }
25
+ const deploy = deployer.deploy(...args);
26
+ const deployOpts = {
27
+ ...await feeOpts.toSendOpts(wallet),
28
+ contractAddressSalt: salt,
29
+ universalDeploy,
30
+ skipClassRegistration,
31
+ skipInitialization,
32
+ skipPublicDeployment
33
+ };
34
+ if (feeOpts.estimateOnly) {
35
+ const gas = await deploy.estimateGas(deployOpts);
36
+ printGasEstimates(feeOpts, gas, log);
37
+ return;
38
+ }
39
+ const tx = deploy.send(deployOpts);
40
+ const txHash = await tx.getTxHash();
41
+ debugLogger.debug(`Deploy tx sent with hash ${txHash}`);
42
+ if (wait) {
43
+ const deployed = await tx.wait();
44
+ const { address, partialAddress, instance } = deployed.contract;
45
+ if (json) {
46
+ logJson({
47
+ address: address.toString(),
48
+ partialAddress: partialAddress.toString(),
49
+ initializationHash: instance.initializationHash.toString(),
50
+ salt: salt.toString(),
51
+ transactionFee: deployed.transactionFee?.toString()
52
+ });
53
+ } else {
54
+ log(`Contract deployed at ${address.toString()}`);
55
+ log(`Contract partial address ${partialAddress.toString()}`);
56
+ log(`Contract init hash ${instance.initializationHash.toString()}`);
57
+ log(`Deployment tx hash: ${txHash.toString()}`);
58
+ log(`Deployment salt: ${salt.toString()}`);
59
+ log(`Deployment fee: ${deployed.transactionFee}`);
60
+ }
61
+ } else {
62
+ const { address, partialAddress } = deploy;
63
+ const instance = await deploy.getInstance();
64
+ if (json) {
65
+ logJson({
66
+ address: address?.toString() ?? 'N/A',
67
+ partialAddress: partialAddress?.toString() ?? 'N/A',
68
+ txHash: txHash.toString(),
69
+ initializationHash: instance.initializationHash.toString(),
70
+ salt: salt.toString(),
71
+ deployer: instance.deployer.toString()
72
+ });
73
+ } else {
74
+ log(`Contract deployed at ${address?.toString()}`);
75
+ log(`Contract partial address ${partialAddress?.toString()}`);
76
+ log(`Contract init hash ${instance.initializationHash.toString()}`);
77
+ log(`Deployment tx hash: ${txHash.toString()}`);
78
+ log(`Deployment salt: ${salt.toString()}`);
79
+ log(`Deployer: ${instance.deployer.toString()}`);
80
+ }
81
+ }
82
+ return deploy.address;
83
+ }
@@ -0,0 +1,84 @@
1
+ import { prettyPrintJSON } from '@aztec/cli/cli-utils';
2
+ import { printGasEstimates } from '../utils/options/fees.js';
3
+ export async function deployAccount(account, wait, feeOpts, json, debugLogger, log) {
4
+ const out = {};
5
+ const { address, partialAddress, publicKeys } = await account.getCompleteAddress();
6
+ const { initializationHash, deployer, salt } = account.getInstance();
7
+ const wallet = await account.getWallet();
8
+ const secretKey = wallet.getSecretKey();
9
+ if (json) {
10
+ out.address = address;
11
+ out.partialAddress = partialAddress;
12
+ out.salt = salt;
13
+ out.initHash = initializationHash;
14
+ out.deployer = deployer;
15
+ } else {
16
+ log(`\nNew account:\n`);
17
+ log(`Address: ${address.toString()}`);
18
+ log(`Public key: 0x${publicKeys.toString()}`);
19
+ if (secretKey) {
20
+ log(`Secret key: ${secretKey.toString()}`);
21
+ }
22
+ log(`Partial address: ${partialAddress.toString()}`);
23
+ log(`Salt: ${salt.toString()}`);
24
+ log(`Init hash: ${initializationHash.toString()}`);
25
+ log(`Deployer: ${deployer.toString()}`);
26
+ }
27
+ let tx;
28
+ let txReceipt;
29
+ const sendOpts = {
30
+ ...await feeOpts.toSendOpts(wallet),
31
+ skipInitialization: false
32
+ };
33
+ if (feeOpts.estimateOnly) {
34
+ const gas = await (await account.getDeployMethod()).estimateGas({
35
+ ...sendOpts
36
+ });
37
+ if (json) {
38
+ out.fee = {
39
+ gasLimits: {
40
+ da: gas.gasLimits.daGas,
41
+ l2: gas.gasLimits.l2Gas
42
+ },
43
+ teardownGasLimits: {
44
+ da: gas.teardownGasLimits.daGas,
45
+ l2: gas.teardownGasLimits
46
+ }
47
+ };
48
+ } else {
49
+ printGasEstimates(feeOpts, gas, log);
50
+ }
51
+ } else {
52
+ tx = account.deploy({
53
+ ...sendOpts
54
+ });
55
+ const txHash = await tx.getTxHash();
56
+ debugLogger.debug(`Account contract tx sent with hash ${txHash}`);
57
+ out.txHash = txHash;
58
+ if (wait) {
59
+ if (!json) {
60
+ log(`\nWaiting for account contract deployment...`);
61
+ }
62
+ txReceipt = await tx.wait();
63
+ out.txReceipt = {
64
+ status: txReceipt.status,
65
+ transactionFee: txReceipt.transactionFee
66
+ };
67
+ }
68
+ }
69
+ if (json) {
70
+ log(prettyPrintJSON(out));
71
+ } else {
72
+ if (tx) {
73
+ log(`Deploy tx hash: ${await tx.getTxHash()}`);
74
+ }
75
+ if (txReceipt) {
76
+ log(`Deploy tx fee: ${txReceipt.transactionFee}`);
77
+ }
78
+ }
79
+ return {
80
+ address,
81
+ secretKey,
82
+ salt
83
+ };
84
+ }