@aztec/cli-wallet 0.0.0-test.1 → 0.0.1-commit.017a351

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 (115) hide show
  1. package/README.md +30 -0
  2. package/dest/bin/index.d.ts +2 -1
  3. package/dest/bin/index.js +58 -26
  4. package/dest/cmds/authorize_action.d.ts +4 -3
  5. package/dest/cmds/authorize_action.d.ts.map +1 -1
  6. package/dest/cmds/authorize_action.js +11 -5
  7. package/dest/cmds/bridge_fee_juice.d.ts +4 -4
  8. package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
  9. package/dest/cmds/bridge_fee_juice.js +10 -8
  10. package/dest/cmds/check_tx.d.ts +5 -3
  11. package/dest/cmds/check_tx.d.ts.map +1 -1
  12. package/dest/cmds/check_tx.js +174 -6
  13. package/dest/cmds/create_account.d.ts +10 -7
  14. package/dest/cmds/create_account.d.ts.map +1 -1
  15. package/dest/cmds/create_account.js +74 -38
  16. package/dest/cmds/create_authwit.d.ts +4 -3
  17. package/dest/cmds/create_authwit.d.ts.map +1 -1
  18. package/dest/cmds/create_authwit.js +6 -6
  19. package/dest/cmds/deploy.d.ts +8 -4
  20. package/dest/cmds/deploy.d.ts.map +1 -1
  21. package/dest/cmds/deploy.js +108 -59
  22. package/dest/cmds/deploy_account.d.ts +7 -8
  23. package/dest/cmds/deploy_account.d.ts.map +1 -1
  24. package/dest/cmds/deploy_account.js +70 -36
  25. package/dest/cmds/get_fee_juice_balance.d.ts +5 -0
  26. package/dest/cmds/get_fee_juice_balance.d.ts.map +1 -0
  27. package/dest/cmds/get_fee_juice_balance.js +27 -0
  28. package/dest/cmds/import_test_accounts.d.ts +3 -3
  29. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  30. package/dest/cmds/import_test_accounts.js +6 -9
  31. package/dest/cmds/index.d.ts +3 -3
  32. package/dest/cmds/index.d.ts.map +1 -1
  33. package/dest/cmds/index.js +99 -115
  34. package/dest/cmds/profile.d.ts +8 -0
  35. package/dest/cmds/profile.d.ts.map +1 -0
  36. package/dest/cmds/profile.js +28 -0
  37. package/dest/cmds/register_contract.d.ts +7 -3
  38. package/dest/cmds/register_contract.d.ts.map +1 -1
  39. package/dest/cmds/register_contract.js +20 -7
  40. package/dest/cmds/register_sender.d.ts +4 -3
  41. package/dest/cmds/register_sender.d.ts.map +1 -1
  42. package/dest/cmds/send.d.ts +9 -9
  43. package/dest/cmds/send.d.ts.map +1 -1
  44. package/dest/cmds/send.js +54 -27
  45. package/dest/cmds/simulate.d.ts +7 -3
  46. package/dest/cmds/simulate.d.ts.map +1 -1
  47. package/dest/cmds/simulate.js +26 -20
  48. package/dest/storage/wallet_db.d.ts +12 -19
  49. package/dest/storage/wallet_db.d.ts.map +1 -1
  50. package/dest/storage/wallet_db.js +63 -55
  51. package/dest/utils/authorizations.d.ts +6 -0
  52. package/dest/utils/authorizations.d.ts.map +1 -0
  53. package/dest/utils/authorizations.js +28 -0
  54. package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
  55. package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
  56. package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
  57. package/dest/utils/constants.d.ts +4 -0
  58. package/dest/utils/constants.d.ts.map +1 -0
  59. package/dest/utils/constants.js +7 -0
  60. package/dest/utils/ecdsa.d.ts +1 -3
  61. package/dest/utils/ecdsa.d.ts.map +1 -1
  62. package/dest/utils/options/fees.d.ts +23 -28
  63. package/dest/utils/options/fees.d.ts.map +1 -1
  64. package/dest/utils/options/fees.js +112 -148
  65. package/dest/utils/options/index.d.ts +1 -1
  66. package/dest/utils/options/options.d.ts +9 -5
  67. package/dest/utils/options/options.d.ts.map +1 -1
  68. package/dest/utils/options/options.js +26 -14
  69. package/dest/utils/profiling.d.ts +5 -0
  70. package/dest/utils/profiling.d.ts.map +1 -0
  71. package/dest/utils/profiling.js +68 -0
  72. package/dest/utils/wallet.d.ts +44 -0
  73. package/dest/utils/wallet.d.ts.map +1 -0
  74. package/dest/utils/wallet.js +263 -0
  75. package/package.json +31 -23
  76. package/src/bin/index.ts +63 -33
  77. package/src/cmds/authorize_action.ts +16 -5
  78. package/src/cmds/bridge_fee_juice.ts +16 -12
  79. package/src/cmds/check_tx.ts +212 -5
  80. package/src/cmds/create_account.ts +89 -45
  81. package/src/cmds/create_authwit.ts +9 -5
  82. package/src/cmds/deploy.ts +115 -71
  83. package/src/cmds/deploy_account.ts +84 -36
  84. package/src/cmds/get_fee_juice_balance.ts +37 -0
  85. package/src/cmds/import_test_accounts.ts +7 -11
  86. package/src/cmds/index.ts +312 -222
  87. package/src/cmds/profile.ts +48 -0
  88. package/src/cmds/register_contract.ts +28 -5
  89. package/src/cmds/register_sender.ts +3 -2
  90. package/src/cmds/send.ts +59 -25
  91. package/src/cmds/simulate.ts +37 -24
  92. package/src/storage/wallet_db.ts +67 -68
  93. package/src/utils/authorizations.ts +51 -0
  94. package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
  95. package/src/utils/constants.ts +4 -0
  96. package/src/utils/options/fees.ts +169 -210
  97. package/src/utils/options/options.ts +41 -19
  98. package/src/utils/profiling.ts +172 -0
  99. package/src/utils/wallet.ts +330 -0
  100. package/dest/cmds/add_authwit.d.ts +0 -4
  101. package/dest/cmds/add_authwit.d.ts.map +0 -1
  102. package/dest/cmds/add_authwit.js +0 -4
  103. package/dest/cmds/cancel_tx.d.ts +0 -11
  104. package/dest/cmds/cancel_tx.d.ts.map +0 -1
  105. package/dest/cmds/cancel_tx.js +0 -38
  106. package/dest/utils/accounts.d.ts +0 -11
  107. package/dest/utils/accounts.d.ts.map +0 -1
  108. package/dest/utils/accounts.js +0 -87
  109. package/dest/utils/pxe_wrapper.d.ts +0 -10
  110. package/dest/utils/pxe_wrapper.d.ts.map +0 -1
  111. package/dest/utils/pxe_wrapper.js +0 -21
  112. package/src/cmds/add_authwit.ts +0 -13
  113. package/src/cmds/cancel_tx.ts +0 -62
  114. package/src/utils/accounts.ts +0 -102
  115. package/src/utils/pxe_wrapper.ts +0 -26
@@ -1,9 +1,15 @@
1
- import { type AccountWalletWithSecretKey, type AztecAddress, Contract } from '@aztec/aztec.js';
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { SetPublicAuthwitContractInteraction } from '@aztec/aztec.js/authorization';
3
+ import { Contract } from '@aztec/aztec.js/contracts';
4
+ import type { Wallet } from '@aztec/aztec.js/wallet';
2
5
  import { prepTx } from '@aztec/cli/utils';
3
6
  import type { LogFn } from '@aztec/foundation/log';
4
7
 
8
+ import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
9
+
5
10
  export async function authorizeAction(
6
- wallet: AccountWalletWithSecretKey,
11
+ wallet: Wallet,
12
+ from: AztecAddress,
7
13
  functionName: string,
8
14
  caller: AztecAddress,
9
15
  functionArgsIn: any[],
@@ -24,11 +30,16 @@ export async function authorizeAction(
24
30
  );
25
31
  }
26
32
 
27
- const contract = await Contract.at(contractAddress, contractArtifact, wallet);
33
+ const contract = Contract.at(contractAddress, contractArtifact, wallet);
28
34
  const action = contract.methods[functionName](...functionArgs);
29
35
 
30
- const setAuthwitnessInteraction = await wallet.setPublicAuthWit({ caller, action }, true);
31
- const witness = await setAuthwitnessInteraction.send().wait();
36
+ const setAuthwitnessInteraction = await SetPublicAuthwitContractInteraction.create(
37
+ wallet,
38
+ from,
39
+ { caller, action },
40
+ true,
41
+ );
42
+ const witness = await setAuthwitnessInteraction.send({ wait: { timeout: DEFAULT_TX_TIMEOUT_S } });
32
43
 
33
44
  log(`Authorized action ${functionName} on contract ${contractAddress} for caller ${caller}`);
34
45
 
@@ -1,14 +1,18 @@
1
- import { L1FeeJuicePortalManager, type PXE } from '@aztec/aztec.js';
1
+ import { L1FeeJuicePortalManager } from '@aztec/aztec.js/ethereum';
2
+ import type { AztecNode } from '@aztec/aztec.js/node';
3
+ import { ProtocolContractAddress } from '@aztec/aztec.js/protocol';
2
4
  import { prettyPrintJSON } from '@aztec/cli/utils';
3
- import { createEthereumChain, createL1Clients } from '@aztec/ethereum';
4
- import { Fr } from '@aztec/foundation/fields';
5
+ import { createEthereumChain } from '@aztec/ethereum/chain';
6
+ import { createExtendedL1Client } from '@aztec/ethereum/client';
7
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
8
  import type { LogFn, Logger } from '@aztec/foundation/log';
6
9
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
10
+ import { getNonNullifiedL1ToL2MessageWitness } from '@aztec/stdlib/messaging';
7
11
 
8
12
  export async function bridgeL1FeeJuice(
9
13
  amount: bigint,
10
14
  recipient: AztecAddress,
11
- pxe: PXE,
15
+ node: AztecNode,
12
16
  l1RpcUrls: string[],
13
17
  chainId: number,
14
18
  privateKey: string | undefined,
@@ -22,14 +26,10 @@ export async function bridgeL1FeeJuice(
22
26
  ) {
23
27
  // Prepare L1 client
24
28
  const chain = createEthereumChain(l1RpcUrls, chainId);
25
- const { publicClient, walletClient } = createL1Clients(chain.rpcUrls, privateKey ?? mnemonic, chain.chainInfo);
26
-
27
- const {
28
- protocolContractAddresses: { feeJuice: feeJuiceAddress },
29
- } = await pxe.getPXEInfo();
29
+ const client = createExtendedL1Client(chain.rpcUrls, privateKey ?? mnemonic, chain.chainInfo);
30
30
 
31
31
  // Setup portal manager
32
- const portal = await L1FeeJuicePortalManager.new(pxe, publicClient, walletClient, debugLogger);
32
+ const portal = await L1FeeJuicePortalManager.new(node, client, debugLogger);
33
33
  const { claimAmount, claimSecret, messageHash, messageLeafIndex } = await portal.bridgeTokensPublic(
34
34
  recipient,
35
35
  amount,
@@ -66,8 +66,12 @@ export async function bridgeL1FeeJuice(
66
66
  const delayedCheck = (delay: number) => {
67
67
  return new Promise((resolve, reject) => {
68
68
  setTimeout(() => {
69
- void pxe
70
- .getL1ToL2MembershipWitness(feeJuiceAddress, Fr.fromHexString(messageHash), claimSecret)
69
+ void getNonNullifiedL1ToL2MessageWitness(
70
+ node,
71
+ ProtocolContractAddress.FeeJuice,
72
+ Fr.fromHexString(messageHash),
73
+ claimSecret,
74
+ )
71
75
  .then(witness => resolve(witness))
72
76
  .catch(err => reject(err));
73
77
  }, delay);
@@ -1,12 +1,219 @@
1
- import type { PXE, TxHash } from '@aztec/aztec.js';
2
- import { inspectTx } from '@aztec/cli/inspect';
1
+ import type { ContractArtifact } from '@aztec/aztec.js/abi';
2
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
3
+ import { Fr } from '@aztec/aztec.js/fields';
4
+ import type { AztecNode } from '@aztec/aztec.js/node';
5
+ import { ProtocolContractAddress } from '@aztec/aztec.js/protocol';
6
+ import type { TxHash } from '@aztec/aztec.js/tx';
3
7
  import type { LogFn } from '@aztec/foundation/log';
8
+ import {
9
+ computeSiloedPrivateInitializationNullifier,
10
+ computeSiloedPublicInitializationNullifier,
11
+ siloNullifier,
12
+ } from '@aztec/stdlib/hash';
13
+ import { NoteDao } from '@aztec/stdlib/note';
4
14
 
5
- export async function checkTx(client: PXE, txHash: TxHash, statusOnly: boolean, log: LogFn) {
15
+ import type { CLIWallet } from '../utils/wallet.js';
16
+
17
+ export async function checkTx(
18
+ wallet: CLIWallet,
19
+ aztecNode: AztecNode,
20
+ txHash: TxHash,
21
+ statusOnly: boolean,
22
+ log: LogFn,
23
+ ) {
6
24
  if (statusOnly) {
7
- const receipt = await client.getTxReceipt(txHash);
25
+ const receipt = await aztecNode.getTxReceipt(txHash);
8
26
  return receipt.status;
9
27
  } else {
10
- await inspectTx(client, txHash, log, { includeBlockInfo: true });
28
+ await inspectTx(wallet, aztecNode, txHash, log);
29
+ }
30
+ }
31
+
32
+ // The rest of the code here was copied over here from CLI because in CLI I needed to prune the inspect function of the PXE
33
+ // dependency when dropping PXE JSON RPC Server.
34
+
35
+ async function inspectTx(wallet: CLIWallet, aztecNode: AztecNode, txHash: TxHash, log: LogFn) {
36
+ const receipt = await aztecNode.getTxReceipt(txHash, { includeTxEffect: true });
37
+ // Base tx data
38
+ log(`Tx ${txHash.toString()}`);
39
+ log(` Status: ${receipt.status}`);
40
+ if (receipt.executionResult) {
41
+ log(` Execution result: ${receipt.executionResult}`);
42
+ }
43
+ if (receipt.error) {
44
+ log(` Error: ${receipt.error}`);
45
+ }
46
+
47
+ if (!receipt.isMined() || !receipt.txEffect) {
48
+ return;
49
+ }
50
+
51
+ const effects = receipt.txEffect;
52
+ const artifactMap = await getKnownArtifacts(wallet);
53
+
54
+ log(` Block: ${receipt.blockNumber} (${receipt.blockHash?.toString()})`);
55
+ if (receipt.transactionFee) {
56
+ log(` Fee: ${receipt.transactionFee.toString()}`);
57
+ }
58
+
59
+ // Public logs
60
+ const publicLogs = effects.publicLogs;
61
+ if (publicLogs.length > 0) {
62
+ log(' Logs:');
63
+ for (const publicLog of publicLogs) {
64
+ log(` ${publicLog.toHumanReadable()}`);
65
+ }
66
+ }
67
+
68
+ // Public data writes
69
+ const writes = effects.publicDataWrites;
70
+ if (writes.length > 0) {
71
+ log(' Public data writes:');
72
+ for (const write of writes) {
73
+ log(` Leaf ${write.leafSlot.toString()} = ${write.value.toString()}`);
74
+ }
75
+ }
76
+
77
+ // Created notes
78
+ const notes = effects.noteHashes;
79
+ if (notes.length > 0) {
80
+ log(' Created notes:');
81
+ log(` Total: ${notes.length}`);
82
+ for (const note of notes) {
83
+ log(` Note hash: ${note.toShortString()}`);
84
+ }
85
+ }
86
+
87
+ // Nullifiers
88
+ const nullifierCount = effects.nullifiers.length;
89
+ const { deployNullifiers, initNullifiers, classNullifiers } = await getKnownNullifiers(wallet, artifactMap);
90
+ const accounts = (await wallet.getAccounts()).map(a => a.item);
91
+ if (nullifierCount > 0) {
92
+ log(' Nullifiers:');
93
+ for (const nullifier of effects.nullifiers) {
94
+ const deployed = deployNullifiers[nullifier.toString()];
95
+ const note = deployed
96
+ ? (await wallet.getNotes({ siloedNullifier: nullifier, contractAddress: deployed, scopes: accounts }))[0]
97
+ : undefined;
98
+ const initialized = initNullifiers[nullifier.toString()];
99
+ const registered = classNullifiers[nullifier.toString()];
100
+ if (nullifier.toBuffer().equals(txHash.toBuffer())) {
101
+ log(` Transaction hash nullifier ${nullifier.toShortString()}`);
102
+ } else if (note) {
103
+ inspectNote(note, artifactMap, log, `Nullifier ${nullifier.toShortString()} for note`);
104
+ } else if (deployed) {
105
+ log(
106
+ ` Contract ${toFriendlyAddress(deployed, artifactMap)} deployed via nullifier ${nullifier.toShortString()}`,
107
+ );
108
+ } else if (initialized) {
109
+ log(
110
+ ` Contract ${toFriendlyAddress(
111
+ initialized,
112
+ artifactMap,
113
+ )} initialized via nullifier ${nullifier.toShortString()}`,
114
+ );
115
+ } else if (registered) {
116
+ log(` Class ${registered} registered via nullifier ${nullifier.toShortString()}`);
117
+ } else {
118
+ log(` Unknown nullifier ${nullifier.toString()}`);
119
+ }
120
+ }
121
+ }
122
+
123
+ // L2 to L1 messages
124
+ if (effects.l2ToL1Msgs.length > 0) {
125
+ log(` L2 to L1 messages:`);
126
+ for (const msg of effects.l2ToL1Msgs) {
127
+ log(` ${msg.toString()}`);
128
+ }
129
+ }
130
+ }
131
+
132
+ function inspectNote(note: NoteDao, artifactMap: ArtifactMap, log: LogFn, text = 'Note') {
133
+ const artifact = artifactMap[note.contractAddress.toString()];
134
+ const contract = artifact?.name ?? note.contractAddress.toString();
135
+ log(` ${text} at ${contract}`);
136
+ for (const field of note.note.items) {
137
+ log(` ${field.toString()}`);
138
+ }
139
+ }
140
+
141
+ function toFriendlyAddress(address: AztecAddress, artifactMap: ArtifactMap) {
142
+ const artifact = artifactMap[address.toString()];
143
+ if (!artifact) {
144
+ return address.toString();
145
+ }
146
+
147
+ return `${artifact.name}<${address.toString()}>`;
148
+ }
149
+
150
+ async function getKnownNullifiers(wallet: CLIWallet, artifactMap: ArtifactMap) {
151
+ const knownContracts = await wallet.getContracts();
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
+
158
+ const initNullifiers: Record<string, AztecAddress> = {};
159
+ const deployNullifiers: Record<string, AztecAddress> = {};
160
+ const classNullifiers: Record<string, string> = {};
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;
168
+ }
169
+ for (const { nullifier, label } of classResults) {
170
+ classNullifiers[nullifier.toString()] = label;
171
+ }
172
+
173
+ return { initNullifiers, deployNullifiers, classNullifiers };
174
+ }
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
+
195
+ type ArtifactMap = Record<string, ContractArtifactWithClassId>;
196
+ type ContractArtifactWithClassId = ContractArtifact & { classId: Fr };
197
+
198
+ async function getKnownArtifacts(wallet: CLIWallet): Promise<ArtifactMap> {
199
+ const knownContractAddresses = await wallet.getContracts();
200
+ const knownContracts = (
201
+ await Promise.all(knownContractAddresses.map(contractAddress => wallet.getContractMetadata(contractAddress)))
202
+ ).map(contractMetadata => contractMetadata.instance);
203
+ const classIds = [...new Set(knownContracts.map(contract => contract?.currentContractClassId))];
204
+ const knownArtifacts = (
205
+ await Promise.all(classIds.map(classId => (classId ? wallet.getContractArtifact(classId) : undefined)))
206
+ ).map((artifact, index) => (artifact ? { ...artifact, classId: classIds[index] } : undefined));
207
+ const map: Record<string, ContractArtifactWithClassId> = {};
208
+ for (const instance of knownContracts) {
209
+ if (instance) {
210
+ const artifact = knownArtifacts.find(a =>
211
+ a?.classId?.equals(instance.currentContractClassId),
212
+ ) as ContractArtifactWithClassId;
213
+ if (artifact) {
214
+ map[instance.address.toString()] = artifact;
215
+ }
216
+ }
11
217
  }
218
+ return map;
12
219
  }
@@ -1,38 +1,50 @@
1
- import type { DeployAccountOptions, PXE } from '@aztec/aztec.js';
1
+ import { NO_FROM } from '@aztec/aztec.js/account';
2
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
3
+ import { NO_WAIT } from '@aztec/aztec.js/contracts';
4
+ import { type AztecNode, waitForTx } from '@aztec/aztec.js/node';
5
+ import type { DeployAccountOptions } from '@aztec/aztec.js/wallet';
2
6
  import { prettyPrintJSON } from '@aztec/cli/cli-utils';
3
- import { Fr } from '@aztec/foundation/fields';
7
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
8
  import type { LogFn, Logger } from '@aztec/foundation/log';
9
+ import { type TxHash, type TxReceipt, TxStatus } from '@aztec/stdlib/tx';
5
10
 
6
- import { type AccountType, createOrRetrieveAccount } from '../utils/accounts.js';
7
- import { type IFeeOpts, printGasEstimates } from '../utils/options/fees.js';
11
+ import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
12
+ import type { AccountType } from '../utils/constants.js';
13
+ import { CLIFeeArgs } from '../utils/options/fees.js';
14
+ import { printProfileResult } from '../utils/profiling.js';
15
+ import { CLIWallet } from '../utils/wallet.js';
8
16
 
9
17
  export async function createAccount(
10
- client: PXE,
18
+ wallet: CLIWallet,
19
+ aztecNode: AztecNode,
11
20
  accountType: AccountType,
12
21
  secretKey: Fr | undefined,
22
+ salt: Fr | undefined,
13
23
  publicKey: string | undefined,
14
24
  alias: string | undefined,
25
+ deployer: AztecAddress | undefined,
15
26
  registerOnly: boolean,
16
- publicDeploy: boolean,
17
27
  skipInitialization: boolean,
28
+ publicDeploy: boolean,
29
+ registerClass: boolean,
18
30
  wait: boolean,
19
- feeOpts: IFeeOpts,
31
+ feeOpts: CLIFeeArgs,
32
+ waitForStatus: TxStatus,
20
33
  json: boolean,
34
+ verbose: boolean,
21
35
  debugLogger: Logger,
22
36
  log: LogFn,
23
37
  ) {
24
38
  secretKey ??= Fr.random();
25
39
 
26
- const account = await createOrRetrieveAccount(
27
- client,
40
+ const account = await wallet.createOrRetrieveAccount(
28
41
  undefined /* address, we don't have it yet */,
29
- undefined /* db, as we want to create from scratch */,
30
42
  secretKey,
31
43
  accountType,
32
- Fr.ZERO,
44
+ salt,
33
45
  publicKey,
34
46
  );
35
- const salt = account.getInstance().salt;
47
+ const instanceSalt = account.getInstance().salt;
36
48
  const { address, publicKeys, partialAddress } = await account.getCompleteAddress();
37
49
 
38
50
  const out: Record<string, any> = {};
@@ -43,9 +55,8 @@ export async function createAccount(
43
55
  out.secretKey = secretKey;
44
56
  }
45
57
  out.partialAddress = partialAddress;
46
- out.salt = salt;
58
+ out.salt = instanceSalt;
47
59
  out.initHash = account.getInstance().initializationHash;
48
- out.deployer = account.getInstance().deployer;
49
60
  } else {
50
61
  log(`\nNew account:\n`);
51
62
  log(`Address: ${address.toString()}`);
@@ -54,67 +65,100 @@ export async function createAccount(
54
65
  log(`Secret key: ${secretKey.toString()}`);
55
66
  }
56
67
  log(`Partial address: ${partialAddress.toString()}`);
57
- log(`Salt: ${salt.toString()}`);
68
+ log(`Salt: ${instanceSalt.toString()}`);
58
69
  log(`Init hash: ${account.getInstance().initializationHash.toString()}`);
59
- log(`Deployer: ${account.getInstance().deployer.toString()}`);
60
70
  }
61
71
 
62
- let tx;
63
- let txReceipt;
64
- if (registerOnly) {
65
- await account.register();
66
- } else {
67
- const wallet = await account.getWallet();
68
- const deployOpts: DeployAccountOptions = {
69
- skipClassRegistration: !publicDeploy,
70
- skipPublicDeployment: !publicDeploy,
71
- skipInitialization: skipInitialization,
72
- ...(await feeOpts.toDeployAccountOpts(wallet)),
72
+ let txHash: TxHash | undefined;
73
+ let txReceipt: TxReceipt | undefined;
74
+ if (!registerOnly) {
75
+ const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(aztecNode, wallet, address);
76
+
77
+ const delegatedDeployment = deployer && !account.address.equals(deployer);
78
+ const from = delegatedDeployment ? deployer : NO_FROM;
79
+
80
+ const deployAccountOpts: DeployAccountOptions = {
81
+ skipClassPublication: !registerClass,
82
+ skipInstancePublication: !publicDeploy,
83
+ skipInitialization,
84
+ from,
85
+ fee: { paymentMethod, gasSettings },
73
86
  };
87
+
88
+ const localStart = performance.now();
89
+ const deployMethod = await account.getDeployMethod();
90
+ const sim = await deployMethod.simulate({
91
+ ...deployAccountOpts,
92
+ fee: { ...deployAccountOpts.fee, estimateGas: true },
93
+ });
94
+ // estimateGas: true guarantees these fields are present
95
+ const estimatedGas = sim.estimatedGas!;
96
+ const stats = sim.stats!;
97
+
74
98
  if (feeOpts.estimateOnly) {
75
- const gas = await (await account.getDeployMethod(deployOpts.deployWallet)).estimateGas(deployOpts);
76
99
  if (json) {
77
100
  out.fee = {
78
101
  gasLimits: {
79
- da: gas.gasLimits.daGas,
80
- l2: gas.gasLimits.l2Gas,
102
+ da: estimatedGas.gasLimits.daGas,
103
+ l2: estimatedGas.gasLimits.l2Gas,
81
104
  },
82
105
  teardownGasLimits: {
83
- da: gas.teardownGasLimits.daGas,
84
- l2: gas.teardownGasLimits,
106
+ da: estimatedGas.teardownGasLimits.daGas,
107
+ l2: estimatedGas.teardownGasLimits,
85
108
  },
86
109
  };
87
- } else {
88
- printGasEstimates(feeOpts, gas, log);
89
110
  }
90
111
  } else {
91
- tx = account.deploy(deployOpts);
92
- const txHash = await tx.getTxHash();
93
- debugLogger.debug(`Account contract tx sent with hash ${txHash}`);
94
- out.txHash = txHash;
112
+ if (verbose) {
113
+ printProfileResult(stats, log);
114
+ }
115
+
116
+ if (!json) {
117
+ log(`\nWaiting for account contract deployment...`);
118
+ }
119
+ const sendOpts = {
120
+ ...deployAccountOpts,
121
+ fee: deployAccountOpts.fee
122
+ ? {
123
+ ...deployAccountOpts.fee,
124
+ gasSettings: estimatedGas,
125
+ }
126
+ : undefined,
127
+ };
128
+
129
+ ({ txHash } = await deployMethod.send({ ...sendOpts, wait: NO_WAIT }));
130
+ const localTimeMs = performance.now() - localStart;
131
+
95
132
  if (wait) {
96
- if (!json) {
97
- log(`\nWaiting for account contract deployment...`);
98
- }
99
- txReceipt = await tx.wait();
133
+ const nodeStart = performance.now();
134
+ txReceipt = await waitForTx(aztecNode, txHash, { timeout: DEFAULT_TX_TIMEOUT_S, waitForStatus });
135
+ const nodeTimeMs = performance.now() - nodeStart;
136
+
100
137
  out.txReceipt = {
101
138
  status: txReceipt.status,
102
139
  transactionFee: txReceipt.transactionFee,
103
140
  };
141
+
142
+ if (!json) {
143
+ log(` Local processing time: ${(localTimeMs / 1000).toFixed(1)}s`);
144
+ log(` Node inclusion time: ${(nodeTimeMs / 1000).toFixed(1)}s`);
145
+ }
104
146
  }
147
+ debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
148
+ out.txHash = txHash;
105
149
  }
106
150
  }
107
151
 
108
152
  if (json) {
109
153
  log(prettyPrintJSON(out));
110
154
  } else {
111
- if (tx) {
112
- log(`Deploy tx hash: ${await tx.getTxHash()}`);
155
+ if (txHash) {
156
+ log(`Deploy tx hash: ${txHash.toString()}`);
113
157
  }
114
158
  if (txReceipt) {
115
159
  log(`Deploy tx fee: ${txReceipt.transactionFee}`);
116
160
  }
117
161
  }
118
162
 
119
- return { alias, address, secretKey, salt };
163
+ return { alias, address, secretKey, salt: instanceSalt };
120
164
  }
@@ -1,9 +1,13 @@
1
- import { type AccountWalletWithSecretKey, type AztecAddress, Contract } from '@aztec/aztec.js';
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { Contract } from '@aztec/aztec.js/contracts';
2
3
  import { prepTx } from '@aztec/cli/utils';
3
4
  import type { LogFn } from '@aztec/foundation/log';
4
5
 
6
+ import type { CLIWallet } from '../utils/wallet.js';
7
+
5
8
  export async function createAuthwit(
6
- wallet: AccountWalletWithSecretKey,
9
+ wallet: CLIWallet,
10
+ from: AztecAddress,
7
11
  functionName: string,
8
12
  caller: AztecAddress,
9
13
  functionArgsIn: any[],
@@ -24,10 +28,10 @@ export async function createAuthwit(
24
28
  );
25
29
  }
26
30
 
27
- const contract = await Contract.at(contractAddress, contractArtifact, wallet);
28
- const action = contract.methods[functionName](...functionArgs);
31
+ const contract = Contract.at(contractAddress, contractArtifact, wallet);
32
+ const call = await contract.methods[functionName](...functionArgs).getFunctionCall();
29
33
 
30
- const witness = await wallet.createAuthWit({ caller, action });
34
+ const witness = await wallet.createAuthWit(from, { caller, call });
31
35
 
32
36
  log(`Created authorization witness for action ${functionName} on contract ${contractAddress} for caller ${caller}`);
33
37