@aztec/cli-wallet 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0

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 (73) hide show
  1. package/dest/bin/index.js +1 -1
  2. package/dest/cmds/authorize_action.d.ts +2 -2
  3. package/dest/cmds/authorize_action.d.ts.map +1 -1
  4. package/dest/cmds/authorize_action.js +4 -2
  5. package/dest/cmds/bridge_fee_juice.d.ts +2 -2
  6. package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
  7. package/dest/cmds/bridge_fee_juice.js +3 -2
  8. package/dest/cmds/check_tx.d.ts +1 -1
  9. package/dest/cmds/check_tx.d.ts.map +1 -1
  10. package/dest/cmds/check_tx.js +57 -25
  11. package/dest/cmds/create_account.d.ts +9 -5
  12. package/dest/cmds/create_account.d.ts.map +1 -1
  13. package/dest/cmds/create_account.js +65 -32
  14. package/dest/cmds/create_authwit.d.ts +2 -2
  15. package/dest/cmds/create_authwit.d.ts.map +1 -1
  16. package/dest/cmds/deploy.d.ts +5 -4
  17. package/dest/cmds/deploy.d.ts.map +1 -1
  18. package/dest/cmds/deploy.js +65 -36
  19. package/dest/cmds/deploy_account.d.ts +4 -3
  20. package/dest/cmds/deploy_account.d.ts.map +1 -1
  21. package/dest/cmds/deploy_account.js +39 -25
  22. package/dest/cmds/get_fee_juice_balance.d.ts +5 -0
  23. package/dest/cmds/get_fee_juice_balance.d.ts.map +1 -0
  24. package/dest/cmds/get_fee_juice_balance.js +27 -0
  25. package/dest/cmds/import_test_accounts.d.ts +1 -1
  26. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  27. package/dest/cmds/import_test_accounts.js +2 -1
  28. package/dest/cmds/index.d.ts +1 -1
  29. package/dest/cmds/index.d.ts.map +1 -1
  30. package/dest/cmds/index.js +37 -20
  31. package/dest/cmds/send.d.ts +5 -4
  32. package/dest/cmds/send.d.ts.map +1 -1
  33. package/dest/cmds/send.js +33 -20
  34. package/dest/cmds/simulate.d.ts +1 -1
  35. package/dest/cmds/simulate.d.ts.map +1 -1
  36. package/dest/cmds/simulate.js +4 -3
  37. package/dest/storage/wallet_db.d.ts +14 -6
  38. package/dest/storage/wallet_db.d.ts.map +1 -1
  39. package/dest/storage/wallet_db.js +75 -32
  40. package/dest/utils/constants.d.ts +4 -0
  41. package/dest/utils/constants.d.ts.map +1 -0
  42. package/dest/utils/constants.js +8 -0
  43. package/dest/utils/options/fees.d.ts +3 -2
  44. package/dest/utils/options/fees.d.ts.map +1 -1
  45. package/dest/utils/options/fees.js +38 -12
  46. package/dest/utils/options/options.d.ts +2 -2
  47. package/dest/utils/options/options.d.ts.map +1 -1
  48. package/dest/utils/options/options.js +6 -6
  49. package/dest/utils/profiling.d.ts +1 -1
  50. package/dest/utils/profiling.d.ts.map +1 -1
  51. package/dest/utils/profiling.js +9 -1
  52. package/dest/utils/wallet.d.ts +40 -12
  53. package/dest/utils/wallet.d.ts.map +1 -1
  54. package/dest/utils/wallet.js +194 -104
  55. package/package.json +17 -16
  56. package/src/bin/index.ts +1 -1
  57. package/src/cmds/authorize_action.ts +1 -1
  58. package/src/cmds/bridge_fee_juice.ts +3 -2
  59. package/src/cmds/check_tx.ts +63 -31
  60. package/src/cmds/create_account.ts +70 -37
  61. package/src/cmds/deploy.ts +64 -37
  62. package/src/cmds/deploy_account.ts +40 -21
  63. package/src/cmds/get_fee_juice_balance.ts +37 -0
  64. package/src/cmds/import_test_accounts.ts +12 -1
  65. package/src/cmds/index.ts +73 -17
  66. package/src/cmds/send.ts +33 -13
  67. package/src/cmds/simulate.ts +5 -7
  68. package/src/storage/wallet_db.ts +88 -39
  69. package/src/utils/constants.ts +10 -0
  70. package/src/utils/options/fees.ts +44 -12
  71. package/src/utils/options/options.ts +6 -6
  72. package/src/utils/profiling.ts +15 -1
  73. package/src/utils/wallet.ts +241 -130
@@ -1,11 +1,15 @@
1
1
  import type { ContractArtifact } from '@aztec/aztec.js/abi';
2
- import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
3
3
  import { Fr } from '@aztec/aztec.js/fields';
4
4
  import type { AztecNode } from '@aztec/aztec.js/node';
5
5
  import { ProtocolContractAddress } from '@aztec/aztec.js/protocol';
6
6
  import type { TxHash } from '@aztec/aztec.js/tx';
7
7
  import type { LogFn } from '@aztec/foundation/log';
8
- import { siloNullifier } from '@aztec/stdlib/hash';
8
+ import {
9
+ computeSiloedPrivateInitializationNullifier,
10
+ computeSiloedPublicInitializationNullifier,
11
+ siloNullifier,
12
+ } from '@aztec/stdlib/hash';
9
13
  import { NoteDao } from '@aztec/stdlib/note';
10
14
 
11
15
  import type { CLIWallet } from '../utils/wallet.js';
@@ -29,19 +33,22 @@ export async function checkTx(
29
33
  // dependency when dropping PXE JSON RPC Server.
30
34
 
31
35
  async function inspectTx(wallet: CLIWallet, aztecNode: AztecNode, txHash: TxHash, log: LogFn) {
32
- const [receipt, effectsInBlock] = await Promise.all([aztecNode.getTxReceipt(txHash), aztecNode.getTxEffect(txHash)]);
36
+ const receipt = await aztecNode.getTxReceipt(txHash, { includeTxEffect: true });
33
37
  // Base tx data
34
38
  log(`Tx ${txHash.toString()}`);
35
- log(` Status: ${receipt.status} ${effectsInBlock ? `(${effectsInBlock.data.revertCode.getDescription()})` : ''}`);
39
+ log(` Status: ${receipt.status}`);
40
+ if (receipt.executionResult) {
41
+ log(` Execution result: ${receipt.executionResult}`);
42
+ }
36
43
  if (receipt.error) {
37
44
  log(` Error: ${receipt.error}`);
38
45
  }
39
46
 
40
- if (!effectsInBlock) {
47
+ if (!receipt.isMined() || !receipt.txEffect) {
41
48
  return;
42
49
  }
43
50
 
44
- const effects = effectsInBlock.data;
51
+ const effects = receipt.txEffect;
45
52
  const artifactMap = await getKnownArtifacts(wallet);
46
53
 
47
54
  log(` Block: ${receipt.blockNumber} (${receipt.blockHash?.toString()})`);
@@ -80,12 +87,13 @@ async function inspectTx(wallet: CLIWallet, aztecNode: AztecNode, txHash: TxHash
80
87
  // Nullifiers
81
88
  const nullifierCount = effects.nullifiers.length;
82
89
  const { deployNullifiers, initNullifiers, classNullifiers } = await getKnownNullifiers(wallet, artifactMap);
90
+ const accounts = (await wallet.getAccounts()).map(a => a.item);
83
91
  if (nullifierCount > 0) {
84
92
  log(' Nullifiers:');
85
93
  for (const nullifier of effects.nullifiers) {
86
94
  const deployed = deployNullifiers[nullifier.toString()];
87
95
  const note = deployed
88
- ? (await wallet.getNotes({ siloedNullifier: nullifier, contractAddress: deployed }))[0]
96
+ ? (await wallet.getNotes({ siloedNullifier: nullifier, contractAddress: deployed, scopes: accounts }))[0]
89
97
  : undefined;
90
98
  const initialized = initNullifiers[nullifier.toString()];
91
99
  const registered = classNullifiers[nullifier.toString()];
@@ -141,46 +149,70 @@ function toFriendlyAddress(address: AztecAddress, artifactMap: ArtifactMap) {
141
149
 
142
150
  async function getKnownNullifiers(wallet: CLIWallet, artifactMap: ArtifactMap) {
143
151
  const knownContracts = await wallet.getContracts();
144
- const deployerAddress = ProtocolContractAddress.ContractInstanceRegistry;
145
- const classRegistryAddress = ProtocolContractAddress.ContractClassRegistry;
152
+
153
+ const [contractResults, classResults] = await Promise.all([
154
+ Promise.all(knownContracts.map(contract => getContractNullifiers(wallet, contract))),
155
+ Promise.all(Object.values(artifactMap).map(artifact => getClassNullifier(artifact))),
156
+ ]);
157
+
146
158
  const initNullifiers: Record<string, AztecAddress> = {};
147
159
  const deployNullifiers: Record<string, AztecAddress> = {};
148
160
  const classNullifiers: Record<string, string> = {};
149
- for (const contract of knownContracts) {
150
- initNullifiers[(await siloNullifier(contract, contract.toField())).toString()] = contract;
151
- deployNullifiers[(await siloNullifier(deployerAddress, contract.toField())).toString()] = contract;
161
+
162
+ for (const { contract, deployNullifier, privateInitNullifier, publicInitNullifier } of contractResults) {
163
+ deployNullifiers[deployNullifier.toString()] = contract;
164
+ if (privateInitNullifier) {
165
+ initNullifiers[privateInitNullifier.toString()] = contract;
166
+ }
167
+ initNullifiers[publicInitNullifier.toString()] = contract;
152
168
  }
153
- for (const artifact of Object.values(artifactMap)) {
154
- classNullifiers[(await siloNullifier(classRegistryAddress, artifact.classId)).toString()] =
155
- `${artifact.name}Class<${artifact.classId}>`;
169
+ for (const { nullifier, label } of classResults) {
170
+ classNullifiers[nullifier.toString()] = label;
156
171
  }
172
+
157
173
  return { initNullifiers, deployNullifiers, classNullifiers };
158
174
  }
159
175
 
176
+ async function getContractNullifiers(wallet: CLIWallet, contract: AztecAddress) {
177
+ const deployerAddress = ProtocolContractAddress.ContractInstanceRegistry;
178
+ const deployNullifier = await siloNullifier(deployerAddress, contract.toField());
179
+
180
+ const metadata = await wallet.getContractMetadata(contract);
181
+ const privateInitNullifier = metadata.instance
182
+ ? await computeSiloedPrivateInitializationNullifier(contract, metadata.instance.initializationHash)
183
+ : undefined;
184
+ const publicInitNullifier = await computeSiloedPublicInitializationNullifier(contract);
185
+
186
+ return { contract, deployNullifier, privateInitNullifier, publicInitNullifier };
187
+ }
188
+
189
+ async function getClassNullifier(artifact: ContractArtifactWithClassId) {
190
+ const classRegistryAddress = ProtocolContractAddress.ContractClassRegistry;
191
+ const nullifier = await siloNullifier(classRegistryAddress, artifact.classId);
192
+ return { nullifier, label: `${artifact.name}Class<${artifact.classId}>` };
193
+ }
194
+
160
195
  type ArtifactMap = Record<string, ContractArtifactWithClassId>;
161
196
  type ContractArtifactWithClassId = ContractArtifact & { classId: Fr };
162
197
 
163
198
  async function getKnownArtifacts(wallet: CLIWallet): Promise<ArtifactMap> {
164
199
  const knownContractAddresses = await wallet.getContracts();
165
- const knownContracts = (
166
- await Promise.all(knownContractAddresses.map(contractAddress => wallet.getContractMetadata(contractAddress)))
167
- ).map(contractMetadata => contractMetadata.contractInstance);
168
- const classIds = [...new Set(knownContracts.map(contract => contract?.currentContractClassId))];
169
- const knownArtifacts = (
170
- await Promise.all(classIds.map(classId => (classId ? wallet.getContractClassMetadata(classId) : undefined)))
171
- ).map(contractClassMetadata =>
172
- contractClassMetadata
173
- ? { ...contractClassMetadata.artifact, classId: contractClassMetadata.contractClass?.id }
174
- : undefined,
200
+ const knownContracts = await Promise.all(
201
+ knownContractAddresses.map(contractAddress => wallet.getContractMetadata(contractAddress)),
175
202
  );
203
+ const classIdFor = (metadata: (typeof knownContracts)[number]): Fr | undefined =>
204
+ metadata.updatedContractClassId ?? metadata.instance?.originalContractClassId;
205
+ const classIds = [...new Set(knownContracts.map(classIdFor))];
206
+ const knownArtifacts = (
207
+ await Promise.all(classIds.map(classId => (classId ? wallet.getContractArtifact(classId) : undefined)))
208
+ ).map((artifact, index) => (artifact ? { ...artifact, classId: classIds[index] } : undefined));
176
209
  const map: Record<string, ContractArtifactWithClassId> = {};
177
- for (const instance of knownContracts) {
178
- if (instance) {
179
- const artifact = knownArtifacts.find(a =>
180
- a?.classId?.equals(instance.currentContractClassId),
181
- ) as ContractArtifactWithClassId;
210
+ for (const metadata of knownContracts) {
211
+ const classId = classIdFor(metadata);
212
+ if (metadata.instance && classId) {
213
+ const artifact = knownArtifacts.find(a => a?.classId?.equals(classId)) as ContractArtifactWithClassId;
182
214
  if (artifact) {
183
- map[instance.address.toString()] = artifact;
215
+ map[metadata.instance.address.toString()] = artifact;
184
216
  }
185
217
  }
186
218
  }
@@ -1,20 +1,27 @@
1
+ import { deriveSecretKeyFromSigningKey } from '@aztec/accounts/utils';
2
+ import { NO_FROM } from '@aztec/aztec.js/account';
1
3
  import { AztecAddress } from '@aztec/aztec.js/addresses';
2
- import type { AztecNode } from '@aztec/aztec.js/node';
4
+ import { NO_WAIT } from '@aztec/aztec.js/contracts';
5
+ import { type AztecNode, waitForTx } from '@aztec/aztec.js/node';
3
6
  import type { DeployAccountOptions } from '@aztec/aztec.js/wallet';
4
7
  import { prettyPrintJSON } from '@aztec/cli/cli-utils';
5
- import { Fr } from '@aztec/foundation/fields';
8
+ import { Fr } from '@aztec/foundation/curves/bn254';
9
+ import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
6
10
  import type { LogFn, Logger } from '@aztec/foundation/log';
11
+ import { type TxHash, type TxReceipt, TxStatus } from '@aztec/stdlib/tx';
7
12
 
8
13
  import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
14
+ import type { AccountType } from '../utils/constants.js';
9
15
  import { CLIFeeArgs } from '../utils/options/fees.js';
10
16
  import { printProfileResult } from '../utils/profiling.js';
11
- import { type AccountType, CLIWallet } from '../utils/wallet.js';
17
+ import { CLIWallet } from '../utils/wallet.js';
12
18
 
13
19
  export async function createAccount(
14
20
  wallet: CLIWallet,
15
21
  aztecNode: AztecNode,
16
22
  accountType: AccountType,
17
- secretKey: Fr | undefined,
23
+ signingKey: GrumpkinScalar | undefined,
24
+ salt: Fr | undefined,
18
25
  publicKey: string | undefined,
19
26
  alias: string | undefined,
20
27
  deployer: AztecAddress | undefined,
@@ -24,52 +31,63 @@ export async function createAccount(
24
31
  registerClass: boolean,
25
32
  wait: boolean,
26
33
  feeOpts: CLIFeeArgs,
34
+ waitForStatus: TxStatus,
27
35
  json: boolean,
28
36
  verbose: boolean,
29
37
  debugLogger: Logger,
30
38
  log: LogFn,
31
39
  ) {
32
- secretKey ??= Fr.random();
33
-
34
- const account = await wallet.createOrRetrieveAccount(
35
- undefined /* address, we don't have it yet */,
36
- secretKey,
37
- accountType,
38
- Fr.ZERO,
39
- publicKey,
40
- );
41
- const { salt } = account.getInstance();
40
+ let secretKey: Fr;
41
+ if (accountType === 'ecdsasecp256r1ssh') {
42
+ // SSH accounts sign with a key held in the agent, and so we cannot derive their privacy secret key from it. Instead
43
+ // we pick a random value.
44
+ secretKey = Fr.random();
45
+ } else {
46
+ signingKey ??= GrumpkinScalar.random();
47
+ secretKey = await deriveSecretKeyFromSigningKey(signingKey);
48
+ }
49
+
50
+ const account = await wallet.createAccount(accountType, signingKey, secretKey, salt, publicKey);
51
+ const instanceSalt = account.getInstance().salt;
42
52
  const { address, publicKeys, partialAddress } = await account.getCompleteAddress();
43
53
 
44
54
  const out: Record<string, any> = {};
45
55
  if (json) {
46
56
  out.address = address;
47
57
  out.publicKey = publicKeys;
58
+ if (signingKey) {
59
+ out.signingKey = signingKey;
60
+ }
48
61
  if (secretKey) {
49
62
  out.secretKey = secretKey;
50
63
  }
51
64
  out.partialAddress = partialAddress;
52
- out.salt = salt;
65
+ out.salt = instanceSalt;
53
66
  out.initHash = account.getInstance().initializationHash;
54
67
  } else {
55
68
  log(`\nNew account:\n`);
56
69
  log(`Address: ${address.toString()}`);
57
70
  log(`Public key: ${publicKeys.toString()}`);
71
+ if (signingKey) {
72
+ log(`Signing key: ${signingKey.toString()}`);
73
+ }
58
74
  if (secretKey) {
59
75
  log(`Secret key: ${secretKey.toString()}`);
60
76
  }
61
77
  log(`Partial address: ${partialAddress.toString()}`);
62
- log(`Salt: ${salt.toString()}`);
78
+ log(`Salt: ${instanceSalt.toString()}`);
63
79
  log(`Init hash: ${account.getInstance().initializationHash.toString()}`);
64
80
  }
65
81
 
66
- let tx;
67
- let txReceipt;
68
- if (!registerOnly) {
82
+ let txHash: TxHash | undefined;
83
+ let txReceipt: TxReceipt | undefined;
84
+ // Initializerless accounts have no deployment tx — creating one only registers it locally — so there is
85
+ // nothing to deploy on-chain.
86
+ if (!registerOnly && accountType !== 'schnorr_initializerless') {
69
87
  const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(aztecNode, wallet, address);
70
88
 
71
89
  const delegatedDeployment = deployer && !account.address.equals(deployer);
72
- const from = delegatedDeployment ? deployer : AztecAddress.ZERO;
90
+ const from = delegatedDeployment ? deployer : NO_FROM;
73
91
 
74
92
  const deployAccountOpts: DeployAccountOptions = {
75
93
  skipClassPublication: !registerClass,
@@ -79,11 +97,15 @@ export async function createAccount(
79
97
  fee: { paymentMethod, gasSettings },
80
98
  };
81
99
 
100
+ const localStart = performance.now();
82
101
  const deployMethod = await account.getDeployMethod();
83
- const { estimatedGas, stats } = await deployMethod.simulate({
102
+ const sim = await deployMethod.simulate({
84
103
  ...deployAccountOpts,
85
- fee: { ...deployAccountOpts.fee, estimateGas: true },
104
+ includeMetadata: true,
86
105
  });
106
+ // includeMetadata: true guarantees these fields are present
107
+ const estimatedGas = await wallet.estimateGasLimits(sim.gasUsed!);
108
+ const stats = sim.stats!;
87
109
 
88
110
  if (feeOpts.estimateOnly) {
89
111
  if (json) {
@@ -99,7 +121,14 @@ export async function createAccount(
99
121
  };
100
122
  }
101
123
  } else {
102
- tx = deployMethod.send({
124
+ if (verbose) {
125
+ printProfileResult(stats, log);
126
+ }
127
+
128
+ if (!json) {
129
+ log(`\nWaiting for account contract deployment...`);
130
+ }
131
+ const sendOpts = {
103
132
  ...deployAccountOpts,
104
133
  fee: deployAccountOpts.fee
105
134
  ? {
@@ -107,37 +136,41 @@ export async function createAccount(
107
136
  gasSettings: estimatedGas,
108
137
  }
109
138
  : undefined,
110
- });
111
- if (verbose) {
112
- printProfileResult(stats, log);
113
- }
139
+ };
140
+
141
+ ({ txHash } = await deployMethod.send({ ...sendOpts, wait: NO_WAIT }));
142
+ const localTimeMs = performance.now() - localStart;
114
143
 
115
- const txHash = await tx.getTxHash();
116
- debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
117
- out.txHash = txHash;
118
144
  if (wait) {
119
- if (!json) {
120
- log(`\nWaiting for account contract deployment...`);
121
- }
122
- txReceipt = await tx.wait({ timeout: DEFAULT_TX_TIMEOUT_S });
145
+ const nodeStart = performance.now();
146
+ txReceipt = await waitForTx(aztecNode, txHash, { timeout: DEFAULT_TX_TIMEOUT_S, waitForStatus });
147
+ const nodeTimeMs = performance.now() - nodeStart;
148
+
123
149
  out.txReceipt = {
124
150
  status: txReceipt.status,
125
151
  transactionFee: txReceipt.transactionFee,
126
152
  };
153
+
154
+ if (!json) {
155
+ log(` Local processing time: ${(localTimeMs / 1000).toFixed(1)}s`);
156
+ log(` Node inclusion time: ${(nodeTimeMs / 1000).toFixed(1)}s`);
157
+ }
127
158
  }
159
+ debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
160
+ out.txHash = txHash;
128
161
  }
129
162
  }
130
163
 
131
164
  if (json) {
132
165
  log(prettyPrintJSON(out));
133
166
  } else {
134
- if (tx) {
135
- log(`Deploy tx hash: ${(await tx.getTxHash()).toString()}`);
167
+ if (txHash) {
168
+ log(`Deploy tx hash: ${txHash.toString()}`);
136
169
  }
137
170
  if (txReceipt) {
138
171
  log(`Deploy tx fee: ${txReceipt.transactionFee}`);
139
172
  }
140
173
  }
141
174
 
142
- return { alias, address, secretKey, salt };
175
+ return { alias, address, signingKey, secretKey, salt: instanceSalt };
143
176
  }
@@ -1,12 +1,15 @@
1
- import { AztecAddress } from '@aztec/aztec.js/addresses';
1
+ import { NO_FROM } from '@aztec/aztec.js/account';
2
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
3
  import type { DeployOptions } from '@aztec/aztec.js/contracts';
4
+ import { NO_WAIT } from '@aztec/aztec.js/contracts';
3
5
  import { ContractDeployer } from '@aztec/aztec.js/deployment';
4
6
  import { Fr } from '@aztec/aztec.js/fields';
5
- import type { AztecNode } from '@aztec/aztec.js/node';
7
+ import { type AztecNode, waitForTx } from '@aztec/aztec.js/node';
6
8
  import { encodeArgs, getContractArtifact, prettyPrintJSON } from '@aztec/cli/utils';
7
9
  import type { LogFn, Logger } from '@aztec/foundation/log';
8
10
  import { getAllFunctionAbis, getInitializer } from '@aztec/stdlib/abi';
9
11
  import { PublicKeys } from '@aztec/stdlib/keys';
12
+ import type { TxStatus } from '@aztec/stdlib/tx';
10
13
 
11
14
  import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
12
15
  import { CLIFeeArgs } from '../utils/options/fees.js';
@@ -28,10 +31,12 @@ export async function deploy(
28
31
  skipInitialization: boolean | undefined,
29
32
  wait: boolean,
30
33
  feeOpts: CLIFeeArgs,
34
+ waitForStatus: TxStatus,
31
35
  verbose: boolean,
32
36
  timeout: number = DEFAULT_TX_TIMEOUT_S,
33
37
  debugLogger: Logger,
34
38
  log: LogFn,
39
+ universal?: boolean,
35
40
  ) {
36
41
  const out: Record<string, any> = {};
37
42
  salt ??= Fr.random();
@@ -41,12 +46,7 @@ export async function deploy(
41
46
 
42
47
  // TODO(#12081): Add contractArtifact.noirVersion and check here (via Noir.lock)?
43
48
 
44
- const contractDeployer = new ContractDeployer(
45
- contractArtifact,
46
- wallet,
47
- publicKeys ?? PublicKeys.default(),
48
- initializer,
49
- );
49
+ const contractDeployer = new ContractDeployer(contractArtifact, wallet, initializer);
50
50
 
51
51
  let args = [];
52
52
  if (rawArgs.length > 0) {
@@ -58,22 +58,28 @@ export async function deploy(
58
58
  debugLogger.debug(`Encoded arguments: ${args.join(', ')}`);
59
59
  }
60
60
 
61
- const deploy = contractDeployer.deploy(...args);
61
+ const deployInteraction = contractDeployer.deploy(args, {
62
+ salt,
63
+ publicKeys: publicKeys ?? PublicKeys.default(),
64
+ ...(universal ? { universalDeploy: true as const } : {}),
65
+ });
62
66
  const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, deployer);
63
67
  const deployOpts: DeployOptions = {
64
68
  fee: { gasSettings, paymentMethod },
65
- from: deployer ?? AztecAddress.ZERO,
66
- contractAddressSalt: salt,
67
- universalDeploy: !deployer,
69
+ from: deployer ?? NO_FROM,
68
70
  skipClassPublication,
69
71
  skipInitialization,
70
72
  skipInstancePublication,
71
73
  };
72
74
 
73
- const { estimatedGas, stats } = await deploy.simulate({
75
+ const localStart = performance.now();
76
+ const sim = await deployInteraction.simulate({
74
77
  ...deployOpts,
75
- fee: { ...deployOpts.fee, estimateGas: true },
78
+ includeMetadata: true,
76
79
  });
80
+ // includeMetadata: true guarantees these fields are present
81
+ const estimatedGas = await wallet.estimateGasLimits(sim.gasUsed!);
82
+ const stats = sim.stats!;
77
83
 
78
84
  if (feeOpts.estimateOnly) {
79
85
  if (json) {
@@ -89,42 +95,63 @@ export async function deploy(
89
95
  };
90
96
  }
91
97
  } else {
92
- const tx = deploy.send(deployOpts);
93
98
  if (verbose) {
94
99
  printProfileResult(stats, log);
95
100
  }
96
101
 
97
- const txHash = await tx.getTxHash();
102
+ const instance = await deployInteraction.getInstance();
103
+ const address = instance.address;
104
+ const partialAddress = await deployInteraction.getPartialAddress();
105
+
106
+ const { txHash } = await deployInteraction.send({ ...deployOpts, wait: NO_WAIT });
107
+ const localTimeMs = performance.now() - localStart;
98
108
  debugLogger.debug(`Deploy tx sent with hash ${txHash.toString()}`);
99
109
  out.hash = txHash;
100
- const { address, partialAddress } = deploy;
101
- const instance = await deploy.getInstance();
102
- if (!json) {
103
- log(`Contract deployed at ${address?.toString()}`);
104
- log(`Contract partial address ${(await partialAddress)?.toString()}`);
105
- log(`Contract init hash ${instance.initializationHash.toString()}`);
106
- log(`Deployment tx hash: ${txHash.toString()}`);
107
- log(`Deployment salt: ${salt.toString()}`);
108
- log(`Deployer: ${instance.deployer.toString()}`);
109
- } else {
110
- out.contract = {
111
- address: address?.toString(),
112
- partialAddress: (await partialAddress)?.toString(),
113
- initializationHash: instance.initializationHash.toString(),
114
- salt: salt.toString(),
115
- };
116
- }
110
+
117
111
  if (wait) {
118
- const deployed = await tx.wait({ timeout });
112
+ const nodeStart = performance.now();
113
+ const receipt = await waitForTx(node, txHash, { timeout, waitForStatus });
114
+ const nodeTimeMs = performance.now() - nodeStart;
115
+
116
+ if (!json) {
117
+ log(`Contract deployed at ${address.toString()}`);
118
+ log(`Contract partial address ${partialAddress.toString()}`);
119
+ log(`Contract init hash ${instance.initializationHash.toString()}`);
120
+ log(`Deployment tx hash: ${txHash.toString()}`);
121
+ log(`Deployment salt: ${salt.toString()}`);
122
+ log(`Deployer: ${instance.deployer.toString()}`);
123
+ log(`Transaction fee: ${receipt.transactionFee?.toString()}`);
124
+ log(` Local processing time: ${(localTimeMs / 1000).toFixed(1)}s`);
125
+ log(` Node inclusion time: ${(nodeTimeMs / 1000).toFixed(1)}s`);
126
+ } else {
127
+ out.contract = {
128
+ address: address.toString(),
129
+ partialAddress: partialAddress.toString(),
130
+ initializationHash: instance.initializationHash.toString(),
131
+ salt: salt.toString(),
132
+ transactionFee: receipt.transactionFee?.toString(),
133
+ };
134
+ }
135
+ } else {
119
136
  if (!json) {
120
- log(`Transaction fee: ${deployed.transactionFee?.toString()}`);
137
+ log(`Contract deployed at ${address.toString()}`);
138
+ log(`Contract partial address ${partialAddress.toString()}`);
139
+ log(`Contract init hash ${instance.initializationHash.toString()}`);
140
+ log(`Deployment tx hash: ${txHash.toString()}`);
141
+ log(`Deployment salt: ${salt.toString()}`);
142
+ log(`Deployer: ${instance.deployer.toString()}`);
121
143
  } else {
122
- out.contract.transactionFee = deployed.transactionFee?.toString();
144
+ out.contract = {
145
+ address: address.toString(),
146
+ partialAddress: partialAddress.toString(),
147
+ initializationHash: instance.initializationHash.toString(),
148
+ salt: salt.toString(),
149
+ };
123
150
  }
124
151
  }
125
152
  }
126
153
  if (json) {
127
154
  log(prettyPrintJSON(out));
128
155
  }
129
- return deploy.address;
156
+ return await deployInteraction.getAddress();
130
157
  }
@@ -1,8 +1,11 @@
1
+ import { NO_FROM } from '@aztec/aztec.js/account';
1
2
  import { AztecAddress } from '@aztec/aztec.js/addresses';
2
- import type { AztecNode } from '@aztec/aztec.js/node';
3
+ import { NO_WAIT } from '@aztec/aztec.js/contracts';
4
+ import { type AztecNode, waitForTx } from '@aztec/aztec.js/node';
3
5
  import type { DeployAccountOptions } from '@aztec/aztec.js/wallet';
4
6
  import { prettyPrintJSON } from '@aztec/cli/cli-utils';
5
7
  import type { LogFn, Logger } from '@aztec/foundation/log';
8
+ import type { TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
6
9
 
7
10
  import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
8
11
  import type { CLIFeeArgs } from '../utils/options/fees.js';
@@ -19,6 +22,7 @@ export async function deployAccount(
19
22
  publicDeploy: boolean,
20
23
  skipInitialization: boolean,
21
24
  feeOpts: CLIFeeArgs,
25
+ waitForStatus: TxStatus,
22
26
  json: boolean,
23
27
  verbose: boolean,
24
28
  debugLogger: Logger,
@@ -26,7 +30,7 @@ export async function deployAccount(
26
30
  ) {
27
31
  const out: Record<string, any> = {};
28
32
 
29
- const account = await wallet.createOrRetrieveAccount(address);
33
+ const account = await wallet.retrieveAccount(address);
30
34
  const { partialAddress, publicKeys } = await account.getCompleteAddress();
31
35
  const { initializationHash, salt } = account.getInstance();
32
36
 
@@ -45,12 +49,12 @@ export async function deployAccount(
45
49
  log(`Init hash: ${initializationHash.toString()}`);
46
50
  }
47
51
 
48
- let tx;
49
- let txReceipt;
52
+ let txHash: TxHash | undefined;
53
+ let txReceipt: TxReceipt | undefined;
50
54
  const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(aztecNode, wallet, address);
51
55
 
52
56
  const delegatedDeployment = deployer && !account.address.equals(deployer);
53
- const from = delegatedDeployment ? deployer : AztecAddress.ZERO;
57
+ const from = delegatedDeployment ? deployer : NO_FROM;
54
58
 
55
59
  const deployAccountOpts: DeployAccountOptions = {
56
60
  skipClassPublication: !registerClass,
@@ -60,11 +64,15 @@ export async function deployAccount(
60
64
  fee: { paymentMethod, gasSettings },
61
65
  };
62
66
 
67
+ const localStart = performance.now();
63
68
  const deployMethod = await account.getDeployMethod();
64
- const { estimatedGas, stats } = await deployMethod.simulate({
69
+ const sim = await deployMethod.simulate({
65
70
  ...deployAccountOpts,
66
- fee: { ...deployAccountOpts.fee, estimateGas: true },
71
+ includeMetadata: true,
67
72
  });
73
+ // includeMetadata: true guarantees these fields are present
74
+ const estimatedGas = await wallet.estimateGasLimits(sim.gasUsed!);
75
+ const stats = sim.stats!;
68
76
 
69
77
  if (feeOpts.estimateOnly) {
70
78
  if (json) {
@@ -80,7 +88,14 @@ export async function deployAccount(
80
88
  };
81
89
  }
82
90
  } else {
83
- tx = deployMethod.send({
91
+ if (verbose) {
92
+ printProfileResult(stats, log);
93
+ }
94
+
95
+ if (!json) {
96
+ log(`\nWaiting for account contract deployment...`);
97
+ }
98
+ const sendOpts = {
84
99
  ...deployAccountOpts,
85
100
  fee: deployAccountOpts.fee
86
101
  ? {
@@ -88,31 +103,35 @@ export async function deployAccount(
88
103
  gasSettings: estimatedGas,
89
104
  }
90
105
  : undefined,
91
- });
92
- if (verbose) {
93
- printProfileResult(stats, log);
94
- }
106
+ };
107
+
108
+ ({ txHash } = await deployMethod.send({ ...sendOpts, wait: NO_WAIT }));
109
+ const localTimeMs = performance.now() - localStart;
95
110
 
96
- const txHash = await tx.getTxHash();
97
- debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
98
- out.txHash = txHash;
99
111
  if (wait) {
100
- if (!json) {
101
- log(`\nWaiting for account contract deployment...`);
102
- }
103
- txReceipt = await tx.wait({ timeout: DEFAULT_TX_TIMEOUT_S });
112
+ const nodeStart = performance.now();
113
+ txReceipt = await waitForTx(aztecNode, txHash, { timeout: DEFAULT_TX_TIMEOUT_S, waitForStatus });
114
+ const nodeTimeMs = performance.now() - nodeStart;
115
+
104
116
  out.txReceipt = {
105
117
  status: txReceipt.status,
106
118
  transactionFee: txReceipt.transactionFee,
107
119
  };
120
+
121
+ if (!json) {
122
+ log(` Local processing time: ${(localTimeMs / 1000).toFixed(1)}s`);
123
+ log(` Node inclusion time: ${(nodeTimeMs / 1000).toFixed(1)}s`);
124
+ }
108
125
  }
126
+ debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
127
+ out.txHash = txHash;
109
128
  }
110
129
 
111
130
  if (json) {
112
131
  log(prettyPrintJSON(out));
113
132
  } else {
114
- if (tx) {
115
- log(`Deploy tx hash: ${(await tx.getTxHash()).toString()}`);
133
+ if (txHash) {
134
+ log(`Deploy tx hash: ${txHash.toString()}`);
116
135
  }
117
136
  if (txReceipt) {
118
137
  log(`Deploy tx fee: ${txReceipt.transactionFee}`);