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

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 (105) hide show
  1. package/README.md +30 -0
  2. package/dest/bin/index.js +48 -26
  3. package/dest/cmds/authorize_action.d.ts +3 -2
  4. package/dest/cmds/authorize_action.d.ts.map +1 -1
  5. package/dest/cmds/authorize_action.js +8 -4
  6. package/dest/cmds/bridge_fee_juice.d.ts +2 -2
  7. package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
  8. package/dest/cmds/bridge_fee_juice.js +8 -7
  9. package/dest/cmds/check_tx.d.ts +4 -2
  10. package/dest/cmds/check_tx.d.ts.map +1 -1
  11. package/dest/cmds/check_tx.js +145 -6
  12. package/dest/cmds/create_account.d.ts +6 -5
  13. package/dest/cmds/create_account.d.ts.map +1 -1
  14. package/dest/cmds/create_account.js +46 -27
  15. package/dest/cmds/create_authwit.d.ts +3 -2
  16. package/dest/cmds/create_authwit.d.ts.map +1 -1
  17. package/dest/cmds/create_authwit.js +5 -5
  18. package/dest/cmds/deploy.d.ts +6 -3
  19. package/dest/cmds/deploy.d.ts.map +1 -1
  20. package/dest/cmds/deploy.js +71 -54
  21. package/dest/cmds/deploy_account.d.ts +5 -7
  22. package/dest/cmds/deploy_account.d.ts.map +1 -1
  23. package/dest/cmds/deploy_account.js +46 -29
  24. package/dest/cmds/import_test_accounts.d.ts +2 -2
  25. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  26. package/dest/cmds/import_test_accounts.js +6 -9
  27. package/dest/cmds/index.d.ts +2 -2
  28. package/dest/cmds/index.d.ts.map +1 -1
  29. package/dest/cmds/index.js +83 -115
  30. package/dest/cmds/profile.d.ts +8 -0
  31. package/dest/cmds/profile.d.ts.map +1 -0
  32. package/dest/cmds/profile.js +28 -0
  33. package/dest/cmds/register_contract.d.ts +6 -2
  34. package/dest/cmds/register_contract.d.ts.map +1 -1
  35. package/dest/cmds/register_contract.js +20 -7
  36. package/dest/cmds/register_sender.d.ts +3 -2
  37. package/dest/cmds/register_sender.d.ts.map +1 -1
  38. package/dest/cmds/send.d.ts +7 -8
  39. package/dest/cmds/send.d.ts.map +1 -1
  40. package/dest/cmds/send.js +31 -20
  41. package/dest/cmds/simulate.d.ts +6 -2
  42. package/dest/cmds/simulate.d.ts.map +1 -1
  43. package/dest/cmds/simulate.js +25 -19
  44. package/dest/storage/wallet_db.d.ts +4 -16
  45. package/dest/storage/wallet_db.d.ts.map +1 -1
  46. package/dest/storage/wallet_db.js +2 -23
  47. package/dest/utils/authorizations.d.ts +6 -0
  48. package/dest/utils/authorizations.d.ts.map +1 -0
  49. package/dest/utils/authorizations.js +28 -0
  50. package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
  51. package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
  52. package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
  53. package/dest/utils/ecdsa.d.ts +0 -2
  54. package/dest/utils/ecdsa.d.ts.map +1 -1
  55. package/dest/utils/options/fees.d.ts +20 -27
  56. package/dest/utils/options/fees.d.ts.map +1 -1
  57. package/dest/utils/options/fees.js +85 -144
  58. package/dest/utils/options/options.d.ts +8 -4
  59. package/dest/utils/options/options.d.ts.map +1 -1
  60. package/dest/utils/options/options.js +26 -14
  61. package/dest/utils/profiling.d.ts +5 -0
  62. package/dest/utils/profiling.d.ts.map +1 -0
  63. package/dest/utils/profiling.js +60 -0
  64. package/dest/utils/wallet.d.ts +35 -0
  65. package/dest/utils/wallet.d.ts.map +1 -0
  66. package/dest/utils/wallet.js +193 -0
  67. package/package.json +24 -20
  68. package/src/bin/index.ts +56 -32
  69. package/src/cmds/authorize_action.ts +15 -4
  70. package/src/cmds/bridge_fee_juice.ts +14 -11
  71. package/src/cmds/check_tx.ts +182 -5
  72. package/src/cmds/create_account.ts +55 -32
  73. package/src/cmds/create_authwit.ts +8 -4
  74. package/src/cmds/deploy.ts +79 -62
  75. package/src/cmds/deploy_account.ts +57 -28
  76. package/src/cmds/import_test_accounts.ts +7 -11
  77. package/src/cmds/index.ts +256 -220
  78. package/src/cmds/profile.ts +48 -0
  79. package/src/cmds/register_contract.ts +28 -5
  80. package/src/cmds/register_sender.ts +3 -2
  81. package/src/cmds/send.ts +31 -17
  82. package/src/cmds/simulate.ts +39 -23
  83. package/src/storage/wallet_db.ts +3 -31
  84. package/src/utils/authorizations.ts +51 -0
  85. package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
  86. package/src/utils/options/fees.ts +134 -206
  87. package/src/utils/options/options.ts +41 -19
  88. package/src/utils/profiling.ts +158 -0
  89. package/src/utils/wallet.ts +264 -0
  90. package/dest/cmds/add_authwit.d.ts +0 -4
  91. package/dest/cmds/add_authwit.d.ts.map +0 -1
  92. package/dest/cmds/add_authwit.js +0 -4
  93. package/dest/cmds/cancel_tx.d.ts +0 -11
  94. package/dest/cmds/cancel_tx.d.ts.map +0 -1
  95. package/dest/cmds/cancel_tx.js +0 -38
  96. package/dest/utils/accounts.d.ts +0 -11
  97. package/dest/utils/accounts.d.ts.map +0 -1
  98. package/dest/utils/accounts.js +0 -87
  99. package/dest/utils/pxe_wrapper.d.ts +0 -10
  100. package/dest/utils/pxe_wrapper.d.ts.map +0 -1
  101. package/dest/utils/pxe_wrapper.js +0 -21
  102. package/src/cmds/add_authwit.ts +0 -13
  103. package/src/cmds/cancel_tx.ts +0 -62
  104. package/src/utils/accounts.ts +0 -102
  105. package/src/utils/pxe_wrapper.ts +0 -26
@@ -1,12 +1,189 @@
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 { UniqueNote } 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: UniqueNote, 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
+ log(` Recipient: ${toFriendlyAddress(note.recipient, artifactMap)}`);
129
+ for (const field of note.note.items) {
130
+ log(` ${field.toString()}`);
131
+ }
132
+ }
133
+
134
+ function toFriendlyAddress(address: AztecAddress, artifactMap: ArtifactMap) {
135
+ const artifact = artifactMap[address.toString()];
136
+ if (!artifact) {
137
+ return address.toString();
138
+ }
139
+
140
+ return `${artifact.name}<${address.toString()}>`;
141
+ }
142
+
143
+ async function getKnownNullifiers(wallet: CLIWallet, artifactMap: ArtifactMap) {
144
+ const knownContracts = await wallet.getContracts();
145
+ const deployerAddress = ProtocolContractAddress.ContractInstanceRegistry;
146
+ const classRegistryAddress = ProtocolContractAddress.ContractClassRegistry;
147
+ const initNullifiers: Record<string, AztecAddress> = {};
148
+ const deployNullifiers: Record<string, AztecAddress> = {};
149
+ const classNullifiers: Record<string, string> = {};
150
+ for (const contract of knownContracts) {
151
+ initNullifiers[(await siloNullifier(contract, contract.toField())).toString()] = contract;
152
+ deployNullifiers[(await siloNullifier(deployerAddress, contract.toField())).toString()] = contract;
153
+ }
154
+ for (const artifact of Object.values(artifactMap)) {
155
+ classNullifiers[(await siloNullifier(classRegistryAddress, artifact.classId)).toString()] =
156
+ `${artifact.name}Class<${artifact.classId}>`;
157
+ }
158
+ return { initNullifiers, deployNullifiers, classNullifiers };
159
+ }
160
+
161
+ type ArtifactMap = Record<string, ContractArtifactWithClassId>;
162
+ type ContractArtifactWithClassId = ContractArtifact & { classId: Fr };
163
+
164
+ async function getKnownArtifacts(wallet: CLIWallet): Promise<ArtifactMap> {
165
+ const knownContractAddresses = await wallet.getContracts();
166
+ const knownContracts = (
167
+ await Promise.all(knownContractAddresses.map(contractAddress => wallet.getContractMetadata(contractAddress)))
168
+ ).map(contractMetadata => contractMetadata.contractInstance);
169
+ const classIds = [...new Set(knownContracts.map(contract => contract?.currentContractClassId))];
170
+ const knownArtifacts = (
171
+ await Promise.all(classIds.map(classId => (classId ? wallet.getContractClassMetadata(classId) : undefined)))
172
+ ).map(contractClassMetadata =>
173
+ contractClassMetadata
174
+ ? { ...contractClassMetadata.artifact, classId: contractClassMetadata.contractClass?.id }
175
+ : undefined,
176
+ );
177
+ const map: Record<string, ContractArtifactWithClassId> = {};
178
+ for (const instance of knownContracts) {
179
+ if (instance) {
180
+ const artifact = knownArtifacts.find(a =>
181
+ a?.classId?.equals(instance.currentContractClassId),
182
+ ) as ContractArtifactWithClassId;
183
+ if (artifact) {
184
+ map[instance.address.toString()] = artifact;
185
+ }
186
+ }
11
187
  }
188
+ return map;
12
189
  }
@@ -1,38 +1,44 @@
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
5
  import { Fr } from '@aztec/foundation/fields';
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 { CLIFeeArgs } from '../utils/options/fees.js';
10
+ import { printProfileResult } from '../utils/profiling.js';
11
+ import { type AccountType, CLIWallet } from '../utils/wallet.js';
8
12
 
9
13
  export async function createAccount(
10
- client: PXE,
14
+ wallet: CLIWallet,
15
+ aztecNode: AztecNode,
11
16
  accountType: AccountType,
12
17
  secretKey: Fr | undefined,
13
18
  publicKey: string | undefined,
14
19
  alias: string | undefined,
20
+ deployer: AztecAddress | undefined,
15
21
  registerOnly: boolean,
16
- publicDeploy: boolean,
17
22
  skipInitialization: boolean,
23
+ publicDeploy: boolean,
24
+ registerClass: boolean,
18
25
  wait: boolean,
19
- feeOpts: IFeeOpts,
26
+ feeOpts: CLIFeeArgs,
20
27
  json: boolean,
28
+ verbose: boolean,
21
29
  debugLogger: Logger,
22
30
  log: LogFn,
23
31
  ) {
24
32
  secretKey ??= Fr.random();
25
33
 
26
- const account = await createOrRetrieveAccount(
27
- client,
34
+ const account = await wallet.createOrRetrieveAccount(
28
35
  undefined /* address, we don't have it yet */,
29
- undefined /* db, as we want to create from scratch */,
30
36
  secretKey,
31
37
  accountType,
32
38
  Fr.ZERO,
33
39
  publicKey,
34
40
  );
35
- const salt = account.getInstance().salt;
41
+ const { salt } = account.getInstance();
36
42
  const { address, publicKeys, partialAddress } = await account.getCompleteAddress();
37
43
 
38
44
  const out: Record<string, any> = {};
@@ -45,7 +51,6 @@ export async function createAccount(
45
51
  out.partialAddress = partialAddress;
46
52
  out.salt = salt;
47
53
  out.initHash = account.getInstance().initializationHash;
48
- out.deployer = account.getInstance().deployer;
49
54
  } else {
50
55
  log(`\nNew account:\n`);
51
56
  log(`Address: ${address.toString()}`);
@@ -56,47 +61,65 @@ export async function createAccount(
56
61
  log(`Partial address: ${partialAddress.toString()}`);
57
62
  log(`Salt: ${salt.toString()}`);
58
63
  log(`Init hash: ${account.getInstance().initializationHash.toString()}`);
59
- log(`Deployer: ${account.getInstance().deployer.toString()}`);
60
64
  }
61
65
 
62
66
  let tx;
63
67
  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)),
68
+ if (!registerOnly) {
69
+ const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(aztecNode, wallet, address);
70
+
71
+ const delegatedDeployment = deployer && !account.address.equals(deployer);
72
+ const from = delegatedDeployment ? deployer : AztecAddress.ZERO;
73
+
74
+ const deployAccountOpts: DeployAccountOptions = {
75
+ skipClassPublication: !registerClass,
76
+ skipInstancePublication: !publicDeploy,
77
+ skipInitialization,
78
+ from,
79
+ fee: { paymentMethod, gasSettings },
73
80
  };
81
+
82
+ const deployMethod = await account.getDeployMethod();
83
+ const { estimatedGas, stats } = await deployMethod.simulate({
84
+ ...deployAccountOpts,
85
+ fee: { ...deployAccountOpts.fee, estimateGas: true },
86
+ });
87
+
74
88
  if (feeOpts.estimateOnly) {
75
- const gas = await (await account.getDeployMethod(deployOpts.deployWallet)).estimateGas(deployOpts);
76
89
  if (json) {
77
90
  out.fee = {
78
91
  gasLimits: {
79
- da: gas.gasLimits.daGas,
80
- l2: gas.gasLimits.l2Gas,
92
+ da: estimatedGas.gasLimits.daGas,
93
+ l2: estimatedGas.gasLimits.l2Gas,
81
94
  },
82
95
  teardownGasLimits: {
83
- da: gas.teardownGasLimits.daGas,
84
- l2: gas.teardownGasLimits,
96
+ da: estimatedGas.teardownGasLimits.daGas,
97
+ l2: estimatedGas.teardownGasLimits,
85
98
  },
86
99
  };
87
- } else {
88
- printGasEstimates(feeOpts, gas, log);
89
100
  }
90
101
  } else {
91
- tx = account.deploy(deployOpts);
102
+ tx = deployMethod.send({
103
+ ...deployAccountOpts,
104
+ fee: deployAccountOpts.fee
105
+ ? {
106
+ ...deployAccountOpts.fee,
107
+ gasSettings: estimatedGas,
108
+ }
109
+ : undefined,
110
+ });
111
+ if (verbose) {
112
+ printProfileResult(stats, log);
113
+ }
114
+
92
115
  const txHash = await tx.getTxHash();
93
- debugLogger.debug(`Account contract tx sent with hash ${txHash}`);
116
+ debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
94
117
  out.txHash = txHash;
95
118
  if (wait) {
96
119
  if (!json) {
97
120
  log(`\nWaiting for account contract deployment...`);
98
121
  }
99
- txReceipt = await tx.wait();
122
+ txReceipt = await tx.wait({ timeout: DEFAULT_TX_TIMEOUT_S });
100
123
  out.txReceipt = {
101
124
  status: txReceipt.status,
102
125
  transactionFee: txReceipt.transactionFee,
@@ -109,7 +132,7 @@ export async function createAccount(
109
132
  log(prettyPrintJSON(out));
110
133
  } else {
111
134
  if (tx) {
112
- log(`Deploy tx hash: ${await tx.getTxHash()}`);
135
+ log(`Deploy tx hash: ${(await tx.getTxHash()).toString()}`);
113
136
  }
114
137
  if (txReceipt) {
115
138
  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[],
@@ -25,9 +29,9 @@ export async function createAuthwit(
25
29
  }
26
30
 
27
31
  const contract = await Contract.at(contractAddress, contractArtifact, wallet);
28
- const action = contract.methods[functionName](...functionArgs);
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
  }