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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) 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 +9 -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 +144 -6
  13. package/dest/cmds/create_account.d.ts +9 -7
  14. package/dest/cmds/create_account.d.ts.map +1 -1
  15. package/dest/cmds/create_account.js +47 -28
  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 +7 -4
  20. package/dest/cmds/deploy.d.ts.map +1 -1
  21. package/dest/cmds/deploy.js +71 -54
  22. package/dest/cmds/deploy_account.d.ts +6 -8
  23. package/dest/cmds/deploy_account.d.ts.map +1 -1
  24. package/dest/cmds/deploy_account.js +46 -29
  25. package/dest/cmds/import_test_accounts.d.ts +3 -3
  26. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  27. package/dest/cmds/import_test_accounts.js +6 -9
  28. package/dest/cmds/index.d.ts +3 -3
  29. package/dest/cmds/index.d.ts.map +1 -1
  30. package/dest/cmds/index.js +83 -115
  31. package/dest/cmds/profile.d.ts +8 -0
  32. package/dest/cmds/profile.d.ts.map +1 -0
  33. package/dest/cmds/profile.js +28 -0
  34. package/dest/cmds/register_contract.d.ts +7 -3
  35. package/dest/cmds/register_contract.d.ts.map +1 -1
  36. package/dest/cmds/register_contract.js +20 -7
  37. package/dest/cmds/register_sender.d.ts +4 -3
  38. package/dest/cmds/register_sender.d.ts.map +1 -1
  39. package/dest/cmds/send.d.ts +8 -9
  40. package/dest/cmds/send.d.ts.map +1 -1
  41. package/dest/cmds/send.js +32 -21
  42. package/dest/cmds/simulate.d.ts +7 -3
  43. package/dest/cmds/simulate.d.ts.map +1 -1
  44. package/dest/cmds/simulate.js +26 -20
  45. package/dest/storage/wallet_db.d.ts +7 -19
  46. package/dest/storage/wallet_db.d.ts.map +1 -1
  47. package/dest/storage/wallet_db.js +3 -24
  48. package/dest/utils/authorizations.d.ts +6 -0
  49. package/dest/utils/authorizations.d.ts.map +1 -0
  50. package/dest/utils/authorizations.js +28 -0
  51. package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
  52. package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
  53. package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
  54. package/dest/utils/constants.d.ts +4 -0
  55. package/dest/utils/constants.d.ts.map +1 -0
  56. package/dest/utils/constants.js +7 -0
  57. package/dest/utils/ecdsa.d.ts +1 -3
  58. package/dest/utils/ecdsa.d.ts.map +1 -1
  59. package/dest/utils/options/fees.d.ts +22 -28
  60. package/dest/utils/options/fees.d.ts.map +1 -1
  61. package/dest/utils/options/fees.js +86 -145
  62. package/dest/utils/options/index.d.ts +1 -1
  63. package/dest/utils/options/options.d.ts +9 -5
  64. package/dest/utils/options/options.d.ts.map +1 -1
  65. package/dest/utils/options/options.js +26 -14
  66. package/dest/utils/profiling.d.ts +5 -0
  67. package/dest/utils/profiling.d.ts.map +1 -0
  68. package/dest/utils/profiling.js +60 -0
  69. package/dest/utils/wallet.d.ts +34 -0
  70. package/dest/utils/wallet.d.ts.map +1 -0
  71. package/dest/utils/wallet.js +188 -0
  72. package/package.json +29 -22
  73. package/src/bin/index.ts +63 -33
  74. package/src/cmds/authorize_action.ts +16 -5
  75. package/src/cmds/bridge_fee_juice.ts +16 -12
  76. package/src/cmds/check_tx.ts +181 -5
  77. package/src/cmds/create_account.ts +57 -33
  78. package/src/cmds/create_authwit.ts +9 -5
  79. package/src/cmds/deploy.ts +79 -62
  80. package/src/cmds/deploy_account.ts +57 -28
  81. package/src/cmds/import_test_accounts.ts +7 -11
  82. package/src/cmds/index.ts +256 -220
  83. package/src/cmds/profile.ts +48 -0
  84. package/src/cmds/register_contract.ts +28 -5
  85. package/src/cmds/register_sender.ts +3 -2
  86. package/src/cmds/send.ts +32 -18
  87. package/src/cmds/simulate.ts +40 -24
  88. package/src/storage/wallet_db.ts +4 -32
  89. package/src/utils/authorizations.ts +51 -0
  90. package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
  91. package/src/utils/constants.ts +4 -0
  92. package/src/utils/options/fees.ts +136 -207
  93. package/src/utils/options/options.ts +41 -19
  94. package/src/utils/profiling.ts +158 -0
  95. package/src/utils/wallet.ts +262 -0
  96. package/dest/cmds/add_authwit.d.ts +0 -4
  97. package/dest/cmds/add_authwit.d.ts.map +0 -1
  98. package/dest/cmds/add_authwit.js +0 -4
  99. package/dest/cmds/cancel_tx.d.ts +0 -11
  100. package/dest/cmds/cancel_tx.d.ts.map +0 -1
  101. package/dest/cmds/cancel_tx.js +0 -38
  102. package/dest/utils/accounts.d.ts +0 -11
  103. package/dest/utils/accounts.d.ts.map +0 -1
  104. package/dest/utils/accounts.js +0 -87
  105. package/dest/utils/pxe_wrapper.d.ts +0 -10
  106. package/dest/utils/pxe_wrapper.d.ts.map +0 -1
  107. package/dest/utils/pxe_wrapper.js +0 -21
  108. package/src/cmds/add_authwit.ts +0 -13
  109. package/src/cmds/cancel_tx.ts +0 -62
  110. package/src/utils/accounts.ts +0 -102
  111. package/src/utils/pxe_wrapper.ts +0 -26
@@ -1,12 +1,188 @@
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 type { 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 { siloNullifier } from '@aztec/stdlib/hash';
9
+ import { NoteDao } from '@aztec/stdlib/note';
4
10
 
5
- export async function checkTx(client: PXE, txHash: TxHash, statusOnly: boolean, log: LogFn) {
11
+ import type { CLIWallet } from '../utils/wallet.js';
12
+
13
+ export async function checkTx(
14
+ wallet: CLIWallet,
15
+ aztecNode: AztecNode,
16
+ txHash: TxHash,
17
+ statusOnly: boolean,
18
+ log: LogFn,
19
+ ) {
6
20
  if (statusOnly) {
7
- const receipt = await client.getTxReceipt(txHash);
21
+ const receipt = await aztecNode.getTxReceipt(txHash);
8
22
  return receipt.status;
9
23
  } else {
10
- await inspectTx(client, txHash, log, { includeBlockInfo: true });
24
+ await inspectTx(wallet, aztecNode, txHash, log);
25
+ }
26
+ }
27
+
28
+ // 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
29
+ // dependency when dropping PXE JSON RPC Server.
30
+
31
+ async function inspectTx(wallet: CLIWallet, aztecNode: AztecNode, txHash: TxHash, log: LogFn) {
32
+ const [receipt, effectsInBlock] = await Promise.all([aztecNode.getTxReceipt(txHash), aztecNode.getTxEffect(txHash)]);
33
+ // Base tx data
34
+ log(`Tx ${txHash.toString()}`);
35
+ log(` Status: ${receipt.status} ${effectsInBlock ? `(${effectsInBlock.data.revertCode.getDescription()})` : ''}`);
36
+ if (receipt.error) {
37
+ log(` Error: ${receipt.error}`);
38
+ }
39
+
40
+ if (!effectsInBlock) {
41
+ return;
42
+ }
43
+
44
+ const effects = effectsInBlock.data;
45
+ const artifactMap = await getKnownArtifacts(wallet);
46
+
47
+ log(` Block: ${receipt.blockNumber} (${receipt.blockHash?.toString()})`);
48
+ if (receipt.transactionFee) {
49
+ log(` Fee: ${receipt.transactionFee.toString()}`);
50
+ }
51
+
52
+ // Public logs
53
+ const publicLogs = effects.publicLogs;
54
+ if (publicLogs.length > 0) {
55
+ log(' Logs:');
56
+ for (const publicLog of publicLogs) {
57
+ log(` ${publicLog.toHumanReadable()}`);
58
+ }
59
+ }
60
+
61
+ // Public data writes
62
+ const writes = effects.publicDataWrites;
63
+ if (writes.length > 0) {
64
+ log(' Public data writes:');
65
+ for (const write of writes) {
66
+ log(` Leaf ${write.leafSlot.toString()} = ${write.value.toString()}`);
67
+ }
68
+ }
69
+
70
+ // Created notes
71
+ const notes = effects.noteHashes;
72
+ if (notes.length > 0) {
73
+ log(' Created notes:');
74
+ log(` Total: ${notes.length}`);
75
+ for (const note of notes) {
76
+ log(` Note hash: ${note.toShortString()}`);
77
+ }
78
+ }
79
+
80
+ // Nullifiers
81
+ const nullifierCount = effects.nullifiers.length;
82
+ const { deployNullifiers, initNullifiers, classNullifiers } = await getKnownNullifiers(wallet, artifactMap);
83
+ if (nullifierCount > 0) {
84
+ log(' Nullifiers:');
85
+ for (const nullifier of effects.nullifiers) {
86
+ const deployed = deployNullifiers[nullifier.toString()];
87
+ const note = deployed
88
+ ? (await wallet.getNotes({ siloedNullifier: nullifier, contractAddress: deployed }))[0]
89
+ : undefined;
90
+ const initialized = initNullifiers[nullifier.toString()];
91
+ const registered = classNullifiers[nullifier.toString()];
92
+ if (nullifier.toBuffer().equals(txHash.toBuffer())) {
93
+ log(` Transaction hash nullifier ${nullifier.toShortString()}`);
94
+ } else if (note) {
95
+ inspectNote(note, artifactMap, log, `Nullifier ${nullifier.toShortString()} for note`);
96
+ } else if (deployed) {
97
+ log(
98
+ ` Contract ${toFriendlyAddress(deployed, artifactMap)} deployed via nullifier ${nullifier.toShortString()}`,
99
+ );
100
+ } else if (initialized) {
101
+ log(
102
+ ` Contract ${toFriendlyAddress(
103
+ initialized,
104
+ artifactMap,
105
+ )} initialized via nullifier ${nullifier.toShortString()}`,
106
+ );
107
+ } else if (registered) {
108
+ log(` Class ${registered} registered via nullifier ${nullifier.toShortString()}`);
109
+ } else {
110
+ log(` Unknown nullifier ${nullifier.toString()}`);
111
+ }
112
+ }
113
+ }
114
+
115
+ // L2 to L1 messages
116
+ if (effects.l2ToL1Msgs.length > 0) {
117
+ log(` L2 to L1 messages:`);
118
+ for (const msg of effects.l2ToL1Msgs) {
119
+ log(` ${msg.toString()}`);
120
+ }
121
+ }
122
+ }
123
+
124
+ function inspectNote(note: NoteDao, artifactMap: ArtifactMap, log: LogFn, text = 'Note') {
125
+ const artifact = artifactMap[note.contractAddress.toString()];
126
+ const contract = artifact?.name ?? note.contractAddress.toString();
127
+ log(` ${text} at ${contract}`);
128
+ for (const field of note.note.items) {
129
+ log(` ${field.toString()}`);
130
+ }
131
+ }
132
+
133
+ function toFriendlyAddress(address: AztecAddress, artifactMap: ArtifactMap) {
134
+ const artifact = artifactMap[address.toString()];
135
+ if (!artifact) {
136
+ return address.toString();
137
+ }
138
+
139
+ return `${artifact.name}<${address.toString()}>`;
140
+ }
141
+
142
+ async function getKnownNullifiers(wallet: CLIWallet, artifactMap: ArtifactMap) {
143
+ const knownContracts = await wallet.getContracts();
144
+ const deployerAddress = ProtocolContractAddress.ContractInstanceRegistry;
145
+ const classRegistryAddress = ProtocolContractAddress.ContractClassRegistry;
146
+ const initNullifiers: Record<string, AztecAddress> = {};
147
+ const deployNullifiers: Record<string, AztecAddress> = {};
148
+ 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;
152
+ }
153
+ for (const artifact of Object.values(artifactMap)) {
154
+ classNullifiers[(await siloNullifier(classRegistryAddress, artifact.classId)).toString()] =
155
+ `${artifact.name}Class<${artifact.classId}>`;
156
+ }
157
+ return { initNullifiers, deployNullifiers, classNullifiers };
158
+ }
159
+
160
+ type ArtifactMap = Record<string, ContractArtifactWithClassId>;
161
+ type ContractArtifactWithClassId = ContractArtifact & { classId: Fr };
162
+
163
+ async function getKnownArtifacts(wallet: CLIWallet): Promise<ArtifactMap> {
164
+ 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,
175
+ );
176
+ 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;
182
+ if (artifact) {
183
+ map[instance.address.toString()] = artifact;
184
+ }
185
+ }
11
186
  }
187
+ return map;
12
188
  }
@@ -1,38 +1,45 @@
1
- import type { DeployAccountOptions, PXE } from '@aztec/aztec.js';
1
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import type { AztecNode } from '@aztec/aztec.js/node';
3
+ import type { DeployAccountOptions } from '@aztec/aztec.js/wallet';
2
4
  import { prettyPrintJSON } from '@aztec/cli/cli-utils';
3
- import { Fr } from '@aztec/foundation/fields';
5
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
6
  import type { LogFn, Logger } from '@aztec/foundation/log';
5
7
 
6
- import { type AccountType, createOrRetrieveAccount } from '../utils/accounts.js';
7
- import { type IFeeOpts, printGasEstimates } from '../utils/options/fees.js';
8
+ import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
9
+ import type { AccountType } from '../utils/constants.js';
10
+ import { CLIFeeArgs } from '../utils/options/fees.js';
11
+ import { printProfileResult } from '../utils/profiling.js';
12
+ import { CLIWallet } from '../utils/wallet.js';
8
13
 
9
14
  export async function createAccount(
10
- client: PXE,
15
+ wallet: CLIWallet,
16
+ aztecNode: AztecNode,
11
17
  accountType: AccountType,
12
18
  secretKey: Fr | undefined,
13
19
  publicKey: string | undefined,
14
20
  alias: string | undefined,
21
+ deployer: AztecAddress | undefined,
15
22
  registerOnly: boolean,
16
- publicDeploy: boolean,
17
23
  skipInitialization: boolean,
24
+ publicDeploy: boolean,
25
+ registerClass: boolean,
18
26
  wait: boolean,
19
- feeOpts: IFeeOpts,
27
+ feeOpts: CLIFeeArgs,
20
28
  json: boolean,
29
+ verbose: boolean,
21
30
  debugLogger: Logger,
22
31
  log: LogFn,
23
32
  ) {
24
33
  secretKey ??= Fr.random();
25
34
 
26
- const account = await createOrRetrieveAccount(
27
- client,
35
+ const account = await wallet.createOrRetrieveAccount(
28
36
  undefined /* address, we don't have it yet */,
29
- undefined /* db, as we want to create from scratch */,
30
37
  secretKey,
31
38
  accountType,
32
39
  Fr.ZERO,
33
40
  publicKey,
34
41
  );
35
- const salt = account.getInstance().salt;
42
+ const { salt } = account.getInstance();
36
43
  const { address, publicKeys, partialAddress } = await account.getCompleteAddress();
37
44
 
38
45
  const out: Record<string, any> = {};
@@ -45,7 +52,6 @@ export async function createAccount(
45
52
  out.partialAddress = partialAddress;
46
53
  out.salt = salt;
47
54
  out.initHash = account.getInstance().initializationHash;
48
- out.deployer = account.getInstance().deployer;
49
55
  } else {
50
56
  log(`\nNew account:\n`);
51
57
  log(`Address: ${address.toString()}`);
@@ -56,47 +62,65 @@ export async function createAccount(
56
62
  log(`Partial address: ${partialAddress.toString()}`);
57
63
  log(`Salt: ${salt.toString()}`);
58
64
  log(`Init hash: ${account.getInstance().initializationHash.toString()}`);
59
- log(`Deployer: ${account.getInstance().deployer.toString()}`);
60
65
  }
61
66
 
62
67
  let tx;
63
68
  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)),
69
+ if (!registerOnly) {
70
+ const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(aztecNode, wallet, address);
71
+
72
+ const delegatedDeployment = deployer && !account.address.equals(deployer);
73
+ const from = delegatedDeployment ? deployer : AztecAddress.ZERO;
74
+
75
+ const deployAccountOpts: DeployAccountOptions = {
76
+ skipClassPublication: !registerClass,
77
+ skipInstancePublication: !publicDeploy,
78
+ skipInitialization,
79
+ from,
80
+ fee: { paymentMethod, gasSettings },
73
81
  };
82
+
83
+ const deployMethod = await account.getDeployMethod();
84
+ const { estimatedGas, stats } = await deployMethod.simulate({
85
+ ...deployAccountOpts,
86
+ fee: { ...deployAccountOpts.fee, estimateGas: true },
87
+ });
88
+
74
89
  if (feeOpts.estimateOnly) {
75
- const gas = await (await account.getDeployMethod(deployOpts.deployWallet)).estimateGas(deployOpts);
76
90
  if (json) {
77
91
  out.fee = {
78
92
  gasLimits: {
79
- da: gas.gasLimits.daGas,
80
- l2: gas.gasLimits.l2Gas,
93
+ da: estimatedGas.gasLimits.daGas,
94
+ l2: estimatedGas.gasLimits.l2Gas,
81
95
  },
82
96
  teardownGasLimits: {
83
- da: gas.teardownGasLimits.daGas,
84
- l2: gas.teardownGasLimits,
97
+ da: estimatedGas.teardownGasLimits.daGas,
98
+ l2: estimatedGas.teardownGasLimits,
85
99
  },
86
100
  };
87
- } else {
88
- printGasEstimates(feeOpts, gas, log);
89
101
  }
90
102
  } else {
91
- tx = account.deploy(deployOpts);
103
+ tx = deployMethod.send({
104
+ ...deployAccountOpts,
105
+ fee: deployAccountOpts.fee
106
+ ? {
107
+ ...deployAccountOpts.fee,
108
+ gasSettings: estimatedGas,
109
+ }
110
+ : undefined,
111
+ });
112
+ if (verbose) {
113
+ printProfileResult(stats, log);
114
+ }
115
+
92
116
  const txHash = await tx.getTxHash();
93
- debugLogger.debug(`Account contract tx sent with hash ${txHash}`);
117
+ debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
94
118
  out.txHash = txHash;
95
119
  if (wait) {
96
120
  if (!json) {
97
121
  log(`\nWaiting for account contract deployment...`);
98
122
  }
99
- txReceipt = await tx.wait();
123
+ txReceipt = await tx.wait({ timeout: DEFAULT_TX_TIMEOUT_S });
100
124
  out.txReceipt = {
101
125
  status: txReceipt.status,
102
126
  transactionFee: txReceipt.transactionFee,
@@ -109,7 +133,7 @@ export async function createAccount(
109
133
  log(prettyPrintJSON(out));
110
134
  } else {
111
135
  if (tx) {
112
- log(`Deploy tx hash: ${await tx.getTxHash()}`);
136
+ log(`Deploy tx hash: ${(await tx.getTxHash()).toString()}`);
113
137
  }
114
138
  if (txReceipt) {
115
139
  log(`Deploy tx fee: ${txReceipt.transactionFee}`);
@@ -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
 
@@ -1,43 +1,52 @@
1
- import { type AccountWalletWithSecretKey, ContractDeployer, type DeployMethod, Fr, type PXE } from '@aztec/aztec.js';
2
- import { GITHUB_TAG_PREFIX, encodeArgs, getContractArtifact } from '@aztec/cli/utils';
1
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import type { DeployOptions } from '@aztec/aztec.js/contracts';
3
+ import { ContractDeployer } from '@aztec/aztec.js/deployment';
4
+ import { Fr } from '@aztec/aztec.js/fields';
5
+ import type { AztecNode } from '@aztec/aztec.js/node';
6
+ import { encodeArgs, getContractArtifact, prettyPrintJSON } from '@aztec/cli/utils';
3
7
  import type { LogFn, Logger } from '@aztec/foundation/log';
4
- import { getInitializer } from '@aztec/stdlib/abi';
8
+ import { getAllFunctionAbis, getInitializer } from '@aztec/stdlib/abi';
5
9
  import { PublicKeys } from '@aztec/stdlib/keys';
6
10
 
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 { CLIFeeArgs } from '../utils/options/fees.js';
13
+ import { printProfileResult } from '../utils/profiling.js';
14
+ import type { CLIWallet } from '../utils/wallet.js';
8
15
 
9
16
  export async function deploy(
10
- client: PXE,
11
- wallet: AccountWalletWithSecretKey,
17
+ wallet: CLIWallet,
18
+ node: AztecNode,
19
+ deployer: AztecAddress,
12
20
  artifactPath: string,
13
21
  json: boolean,
14
22
  publicKeys: PublicKeys | undefined,
15
23
  rawArgs: any[],
16
24
  salt: Fr | undefined,
17
25
  initializer: string | undefined,
18
- skipPublicDeployment: boolean,
19
- skipClassRegistration: boolean,
26
+ skipInstancePublication: boolean,
27
+ skipClassPublication: boolean,
20
28
  skipInitialization: boolean | undefined,
21
- universalDeploy: boolean | undefined,
22
29
  wait: boolean,
23
- feeOpts: IFeeOpts,
30
+ feeOpts: CLIFeeArgs,
31
+ verbose: boolean,
32
+ timeout: number = DEFAULT_TX_TIMEOUT_S,
24
33
  debugLogger: Logger,
25
34
  log: LogFn,
26
- logJson: (output: any) => void,
27
35
  ) {
36
+ const out: Record<string, any> = {};
28
37
  salt ??= Fr.random();
29
38
  const contractArtifact = await getContractArtifact(artifactPath, log);
30
- const constructorArtifact = getInitializer(contractArtifact, initializer);
39
+ const hasInitializer = getAllFunctionAbis(contractArtifact).some(fn => fn.isInitializer);
40
+ const constructorArtifact = hasInitializer ? getInitializer(contractArtifact, initializer) : undefined;
31
41
 
32
- const nodeInfo = await client.getNodeInfo();
33
- const expectedAztecNrVersion = `${GITHUB_TAG_PREFIX}-v${nodeInfo.nodeVersion}`;
34
- if (contractArtifact.aztecNrVersion && contractArtifact.aztecNrVersion !== expectedAztecNrVersion) {
35
- log(
36
- `\nWarning: Contract was compiled with a different version of Aztec.nr: ${contractArtifact.aztecNrVersion}. Consider updating Aztec.nr to ${expectedAztecNrVersion}\n`,
37
- );
38
- }
42
+ // TODO(#12081): Add contractArtifact.noirVersion and check here (via Noir.lock)?
39
43
 
40
- const deployer = new ContractDeployer(contractArtifact, wallet, publicKeys ?? PublicKeys.default(), initializer);
44
+ const contractDeployer = new ContractDeployer(
45
+ contractArtifact,
46
+ wallet,
47
+ publicKeys ?? PublicKeys.default(),
48
+ initializer,
49
+ );
41
50
 
42
51
  let args = [];
43
52
  if (rawArgs.length > 0) {
@@ -49,65 +58,73 @@ export async function deploy(
49
58
  debugLogger.debug(`Encoded arguments: ${args.join(', ')}`);
50
59
  }
51
60
 
52
- const deploy = deployer.deploy(...args);
53
- const deployOpts: Parameters<DeployMethod['send']>[0] = {
54
- ...(await feeOpts.toSendOpts(wallet)),
61
+ const deploy = contractDeployer.deploy(...args);
62
+ const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, deployer);
63
+ const deployOpts: DeployOptions = {
64
+ fee: { gasSettings, paymentMethod },
65
+ from: deployer ?? AztecAddress.ZERO,
55
66
  contractAddressSalt: salt,
56
- universalDeploy,
57
- skipClassRegistration,
67
+ universalDeploy: !deployer,
68
+ skipClassPublication,
58
69
  skipInitialization,
59
- skipPublicDeployment,
70
+ skipInstancePublication,
60
71
  };
61
72
 
62
- if (feeOpts.estimateOnly) {
63
- const gas = await deploy.estimateGas(deployOpts);
64
- printGasEstimates(feeOpts, gas, log);
65
- return;
66
- }
67
-
68
- const tx = deploy.send(deployOpts);
73
+ const { estimatedGas, stats } = await deploy.simulate({
74
+ ...deployOpts,
75
+ fee: { ...deployOpts.fee, estimateGas: true },
76
+ });
69
77
 
70
- const txHash = await tx.getTxHash();
71
- debugLogger.debug(`Deploy tx sent with hash ${txHash}`);
72
- if (wait) {
73
- const deployed = await tx.wait();
74
- const { address, partialAddress, instance } = deployed.contract;
78
+ if (feeOpts.estimateOnly) {
75
79
  if (json) {
76
- logJson({
77
- address: address.toString(),
78
- partialAddress: (await partialAddress).toString(),
79
- initializationHash: instance.initializationHash.toString(),
80
- salt: salt.toString(),
81
- transactionFee: deployed.transactionFee?.toString(),
82
- });
83
- } else {
84
- log(`Contract deployed at ${address.toString()}`);
85
- log(`Contract partial address ${(await partialAddress).toString()}`);
86
- log(`Contract init hash ${instance.initializationHash.toString()}`);
87
- log(`Deployment tx hash: ${txHash.toString()}`);
88
- log(`Deployment salt: ${salt.toString()}`);
89
- log(`Deployment fee: ${deployed.transactionFee}`);
80
+ out.fee = {
81
+ gasLimits: {
82
+ da: estimatedGas.gasLimits.daGas,
83
+ l2: estimatedGas.gasLimits.l2Gas,
84
+ },
85
+ teardownGasLimits: {
86
+ da: estimatedGas.teardownGasLimits.daGas,
87
+ l2: estimatedGas.teardownGasLimits,
88
+ },
89
+ };
90
90
  }
91
91
  } else {
92
+ const tx = deploy.send(deployOpts);
93
+ if (verbose) {
94
+ printProfileResult(stats, log);
95
+ }
96
+
97
+ const txHash = await tx.getTxHash();
98
+ debugLogger.debug(`Deploy tx sent with hash ${txHash.toString()}`);
99
+ out.hash = txHash;
92
100
  const { address, partialAddress } = deploy;
93
101
  const instance = await deploy.getInstance();
94
- if (json) {
95
- logJson({
96
- address: address?.toString() ?? 'N/A',
97
- partialAddress: (await partialAddress)?.toString() ?? 'N/A',
98
- txHash: txHash.toString(),
99
- initializationHash: instance.initializationHash.toString(),
100
- salt: salt.toString(),
101
- deployer: instance.deployer.toString(),
102
- });
103
- } else {
102
+ if (!json) {
104
103
  log(`Contract deployed at ${address?.toString()}`);
105
104
  log(`Contract partial address ${(await partialAddress)?.toString()}`);
106
105
  log(`Contract init hash ${instance.initializationHash.toString()}`);
107
106
  log(`Deployment tx hash: ${txHash.toString()}`);
108
107
  log(`Deployment salt: ${salt.toString()}`);
109
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
+ };
110
116
  }
117
+ if (wait) {
118
+ const deployed = await tx.wait({ timeout });
119
+ if (!json) {
120
+ log(`Transaction fee: ${deployed.transactionFee?.toString()}`);
121
+ } else {
122
+ out.contract.transactionFee = deployed.transactionFee?.toString();
123
+ }
124
+ }
125
+ }
126
+ if (json) {
127
+ log(prettyPrintJSON(out));
111
128
  }
112
129
  return deploy.address;
113
130
  }