@aztec/cli-wallet 0.0.1-commit.fcb71a6 → 0.0.1-commit.fffb133c

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 (54) hide show
  1. package/dest/bin/index.d.ts +1 -0
  2. package/dest/bin/index.js +1 -0
  3. package/dest/cmds/authorize_action.d.ts +2 -2
  4. package/dest/cmds/authorize_action.d.ts.map +1 -1
  5. package/dest/cmds/authorize_action.js +4 -2
  6. package/dest/cmds/check_tx.js +8 -5
  7. package/dest/cmds/create_account.d.ts +3 -2
  8. package/dest/cmds/create_account.d.ts.map +1 -1
  9. package/dest/cmds/create_account.js +24 -18
  10. package/dest/cmds/create_authwit.d.ts +2 -2
  11. package/dest/cmds/create_authwit.d.ts.map +1 -1
  12. package/dest/cmds/deploy.d.ts +1 -1
  13. package/dest/cmds/deploy.d.ts.map +1 -1
  14. package/dest/cmds/deploy.js +46 -23
  15. package/dest/cmds/deploy_account.d.ts +1 -1
  16. package/dest/cmds/deploy_account.d.ts.map +1 -1
  17. package/dest/cmds/deploy_account.js +24 -18
  18. package/dest/cmds/send.d.ts +2 -2
  19. package/dest/cmds/send.d.ts.map +1 -1
  20. package/dest/cmds/send.js +28 -16
  21. package/dest/cmds/simulate.d.ts +1 -1
  22. package/dest/cmds/simulate.d.ts.map +1 -1
  23. package/dest/cmds/simulate.js +3 -3
  24. package/dest/storage/wallet_db.d.ts +2 -2
  25. package/dest/storage/wallet_db.d.ts.map +1 -1
  26. package/dest/utils/constants.d.ts +4 -0
  27. package/dest/utils/constants.d.ts.map +1 -0
  28. package/dest/utils/constants.js +7 -0
  29. package/dest/utils/options/fees.js +2 -2
  30. package/dest/utils/options/options.d.ts +2 -2
  31. package/dest/utils/options/options.d.ts.map +1 -1
  32. package/dest/utils/options/options.js +1 -1
  33. package/dest/utils/profiling.d.ts +1 -1
  34. package/dest/utils/profiling.d.ts.map +1 -1
  35. package/dest/utils/profiling.js +9 -1
  36. package/dest/utils/wallet.d.ts +3 -4
  37. package/dest/utils/wallet.d.ts.map +1 -1
  38. package/dest/utils/wallet.js +25 -16
  39. package/package.json +15 -15
  40. package/src/bin/index.ts +1 -0
  41. package/src/cmds/authorize_action.ts +1 -1
  42. package/src/cmds/check_tx.ts +7 -8
  43. package/src/cmds/create_account.ts +25 -18
  44. package/src/cmds/deploy.ts +41 -22
  45. package/src/cmds/deploy_account.ts +23 -17
  46. package/src/cmds/index.ts +1 -1
  47. package/src/cmds/send.ts +22 -10
  48. package/src/cmds/simulate.ts +3 -6
  49. package/src/storage/wallet_db.ts +1 -1
  50. package/src/utils/constants.ts +4 -0
  51. package/src/utils/options/fees.ts +2 -2
  52. package/src/utils/options/options.ts +1 -1
  53. package/src/utils/profiling.ts +15 -1
  54. package/src/utils/wallet.ts +28 -11
package/src/cmds/send.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
2
  import { AuthWitness } from '@aztec/aztec.js/authorization';
3
- import { Contract, type SendInteractionOptions } from '@aztec/aztec.js/contracts';
3
+ import { Contract, NO_WAIT, type SendInteractionOptions } from '@aztec/aztec.js/contracts';
4
4
  import type { AztecNode } from '@aztec/aztec.js/node';
5
5
  import { prepTx } from '@aztec/cli/utils';
6
6
  import type { LogFn } from '@aztec/foundation/log';
@@ -46,31 +46,43 @@ export async function send(
46
46
  return;
47
47
  }
48
48
 
49
- const tx = call.send({ ...sendOptions, fee: { ...sendOptions.fee, gasSettings: estimatedGas } });
50
49
  if (verbose) {
51
50
  printProfileResult(stats!, log);
52
51
  }
53
52
 
54
- const txHash = await tx.getTxHash();
55
- log(`\nTransaction hash: ${txHash.toString()}`);
56
53
  if (wait) {
57
54
  try {
58
- await tx.wait({ timeout: DEFAULT_TX_TIMEOUT_S });
55
+ const receipt = await call.send({
56
+ ...sendOptions,
57
+ fee: { ...sendOptions.fee, gasSettings: estimatedGas },
58
+ wait: { timeout: DEFAULT_TX_TIMEOUT_S },
59
+ });
59
60
 
61
+ const txHash = receipt.txHash;
62
+ log(`\nTransaction hash: ${txHash.toString()}`);
60
63
  log('Transaction has been mined');
61
-
62
- const receipt = await tx.getReceipt();
63
64
  log(` Tx fee: ${receipt.transactionFee}`);
64
65
  log(` Status: ${receipt.status}`);
65
66
  log(` Block number: ${receipt.blockNumber}`);
66
67
  log(` Block hash: ${receipt.blockHash?.toString()}`);
68
+
69
+ return {
70
+ txHash,
71
+ };
67
72
  } catch (err: any) {
68
73
  log(`Transaction failed\n ${err.message}`);
74
+ throw err;
69
75
  }
70
76
  } else {
77
+ const txHash = await call.send({
78
+ ...sendOptions,
79
+ fee: { ...sendOptions.fee, gasSettings: estimatedGas },
80
+ wait: NO_WAIT,
81
+ });
82
+ log(`\nTransaction hash: ${txHash.toString()}`);
71
83
  log('Transaction pending. Check status with check-tx');
84
+ return {
85
+ txHash,
86
+ };
72
87
  }
73
- return {
74
- txHash,
75
- };
76
88
  }
@@ -41,14 +41,11 @@ export async function simulate(
41
41
  simulationResult.offchainEffects!,
42
42
  async (address: AztecAddress) => {
43
43
  const metadata = await wallet.getContractMetadata(address);
44
- if (!metadata.contractInstance) {
44
+ if (!metadata.instance) {
45
45
  return undefined;
46
46
  }
47
- const classMetadata = await wallet.getContractClassMetadata(
48
- metadata.contractInstance.currentContractClassId,
49
- true,
50
- );
51
- return classMetadata.artifact;
47
+ const artifact = await wallet.getContractArtifact(metadata.instance.currentContractClassId);
48
+ return artifact;
52
49
  },
53
50
  log,
54
51
  );
@@ -5,8 +5,8 @@ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
5
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
6
  import type { TxHash } from '@aztec/stdlib/tx';
7
7
 
8
+ import type { AccountType } from '../utils/constants.js';
8
9
  import { extractECDSAPublicKeyFromBase64String } from '../utils/ecdsa.js';
9
- import type { AccountType } from '../utils/wallet.js';
10
10
 
11
11
  export const Aliases = ['accounts', 'contracts', 'artifacts', 'secrets', 'transactions', 'authwits'] as const;
12
12
  export type AliasType = (typeof Aliases)[number];
@@ -0,0 +1,4 @@
1
+ export const MIN_FEE_PADDING = 0.5;
2
+
3
+ export const AccountTypes = ['schnorr', 'ecdsasecp256r1', 'ecdsasecp256r1ssh', 'ecdsasecp256k1'] as const;
4
+ export type AccountType = (typeof AccountTypes)[number];
@@ -11,7 +11,7 @@ import type { FeeOptions } from '@aztec/wallet-sdk/base-wallet';
11
11
  import { Option } from 'commander';
12
12
 
13
13
  import type { WalletDB } from '../../storage/wallet_db.js';
14
- import { BASE_FEE_PADDING } from '../wallet.js';
14
+ import { MIN_FEE_PADDING } from '../constants.js';
15
15
  import { aliasedAddressParser } from './options.js';
16
16
 
17
17
  export type RawCliFeeArgs = {
@@ -250,7 +250,7 @@ export class CLIFeeArgs {
250
250
  ) {}
251
251
 
252
252
  async toUserFeeOptions(node: AztecNode, wallet: Wallet, from: AztecAddress): Promise<ParsedFeeOptions> {
253
- const maxFeesPerGas = (await node.getCurrentBaseFees()).mul(1 + BASE_FEE_PADDING);
253
+ const maxFeesPerGas = (await node.getCurrentMinFees()).mul(1 + MIN_FEE_PADDING);
254
254
  const gasSettings = GasSettings.default({ ...this.gasSettings, maxFeesPerGas });
255
255
  const paymentMethod = await this.paymentMethod(wallet, from, gasSettings);
256
256
  return {
@@ -7,7 +7,7 @@ import { Option } from 'commander';
7
7
  import { readdir, stat } from 'fs/promises';
8
8
 
9
9
  import type { AliasType, WalletDB } from '../../storage/wallet_db.js';
10
- import { AccountTypes } from '../wallet.js';
10
+ import { AccountTypes } from '../constants.js';
11
11
 
12
12
  const TARGET_DIR = 'target';
13
13
 
@@ -95,7 +95,7 @@ export function printProfileResult(
95
95
 
96
96
  if (stats.nodeRPCCalls) {
97
97
  log(format('\nRPC calls:\n'));
98
- for (const [method, { times }] of Object.entries(stats.nodeRPCCalls)) {
98
+ for (const [method, { times }] of Object.entries(stats.nodeRPCCalls.perMethod)) {
99
99
  const calls = times.length;
100
100
  const total = times.reduce((acc, time) => acc + time, 0);
101
101
  const avg = total / calls;
@@ -112,6 +112,20 @@ export function printProfileResult(
112
112
  ),
113
113
  );
114
114
  }
115
+
116
+ const { roundTrips } = stats.nodeRPCCalls;
117
+ log(format('\nRound trips (actual blocking waits):\n'));
118
+ log(format('Round trips:'.padEnd(25), `${roundTrips.roundTrips}`.padStart(COLUMN_MAX_WIDTH)));
119
+ log(
120
+ format(
121
+ 'Total blocking time:'.padEnd(25),
122
+ `${roundTrips.totalBlockingTime.toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH),
123
+ ),
124
+ );
125
+ if (roundTrips.roundTrips > 0) {
126
+ const avgRoundTrip = roundTrips.totalBlockingTime / roundTrips.roundTrips;
127
+ log(format('Avg round trip:'.padEnd(25), `${avgRoundTrip.toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH)));
128
+ }
115
129
  }
116
130
 
117
131
  log(format('\nSync time:'.padEnd(25), `${timings.sync?.toFixed(2)}ms`.padStart(16)));
@@ -25,14 +25,10 @@ import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
25
25
  import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
26
26
 
27
27
  import type { WalletDB } from '../storage/wallet_db.js';
28
+ import type { AccountType } from './constants.js';
28
29
  import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
29
30
  import { printGasEstimates } from './options/fees.js';
30
31
 
31
- export const AccountTypes = ['schnorr', 'ecdsasecp256r1', 'ecdsasecp256r1ssh', 'ecdsasecp256k1'] as const;
32
- export type AccountType = (typeof AccountTypes)[number];
33
-
34
- export const BASE_FEE_PADDING = 0.5;
35
-
36
32
  export class CLIWallet extends BaseWallet {
37
33
  private accountCache = new Map<string, Account>();
38
34
 
@@ -71,6 +67,7 @@ export class CLIWallet extends BaseWallet {
71
67
  const feeOptions = await this.completeFeeOptions(from, executionPayload.feePayer, increasedFee.gasSettings);
72
68
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
73
69
  const fromAccount = await this.getAccountFromAddress(from);
70
+ const chainInfo = await this.getChainInfo();
74
71
  const executionOptions: DefaultAccountEntrypointOptions = {
75
72
  txNonce,
76
73
  cancellable: this.cancellableTransactions,
@@ -79,6 +76,7 @@ export class CLIWallet extends BaseWallet {
79
76
  return await fromAccount.createTxExecutionRequest(
80
77
  feeExecutionPayload ?? executionPayload,
81
78
  feeOptions.gasSettings,
79
+ chainInfo,
82
80
  executionOptions,
83
81
  );
84
82
  }
@@ -95,8 +93,7 @@ export class CLIWallet extends BaseWallet {
95
93
  override async getAccountFromAddress(address: AztecAddress) {
96
94
  let account: Account | undefined;
97
95
  if (address.equals(AztecAddress.ZERO)) {
98
- const chainInfo = await this.getChainInfo();
99
- account = new SignerlessAccount(chainInfo);
96
+ account = new SignerlessAccount();
100
97
  } else if (this.accountCache.has(address.toString())) {
101
98
  return this.accountCache.get(address.toString())!;
102
99
  } else {
@@ -180,15 +177,26 @@ export class CLIWallet extends BaseWallet {
180
177
  return account;
181
178
  }
182
179
 
180
+ /**
181
+ * Creates a stub account that impersonates the given address, allowing kernelless simulations
182
+ * to bypass the account's authorization mechanisms via contract overrides.
183
+ * @param address - The address of the account to impersonate
184
+ * @returns The stub account, contract instance, and artifact for simulation
185
+ */
183
186
  private async getFakeAccountDataFor(address: AztecAddress) {
184
- const chainInfo = await this.getChainInfo();
185
187
  const originalAccount = await this.getAccountFromAddress(address);
186
- const originalAddress = originalAccount.getCompleteAddress();
187
- const { contractInstance } = await this.pxe.getContractMetadata(originalAddress.address);
188
+ // Account contracts can only be overridden if they have an associated address
189
+ // Overwriting SignerlessAccount is not supported, and does not really make sense
190
+ // since it has no authorization mechanism.
191
+ if (originalAccount instanceof SignerlessAccount) {
192
+ throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
193
+ }
194
+ const originalAddress = (originalAccount as Account).getCompleteAddress();
195
+ const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
188
196
  if (!contractInstance) {
189
197
  throw new Error(`No contract instance found for address: ${originalAddress.address}`);
190
198
  }
191
- const stubAccount = createStubAccount(originalAddress, chainInfo);
199
+ const stubAccount = createStubAccount(originalAddress);
192
200
  const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
193
201
  salt: Fr.random(),
194
202
  });
@@ -205,6 +213,7 @@ export class CLIWallet extends BaseWallet {
205
213
  ? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings)
206
214
  : await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
207
215
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
216
+ const chainInfo = await this.getChainInfo();
208
217
  const executionOptions: DefaultAccountEntrypointOptions = {
209
218
  txNonce: Fr.random(),
210
219
  cancellable: this.cancellableTransactions,
@@ -222,6 +231,7 @@ export class CLIWallet extends BaseWallet {
222
231
  const txRequest = await fromAccount.createTxExecutionRequest(
223
232
  finalExecutionPayload,
224
233
  feeOptions.gasSettings,
234
+ chainInfo,
225
235
  executionOptions,
226
236
  );
227
237
  simulationResults = await this.pxe.simulateTx(
@@ -235,6 +245,7 @@ export class CLIWallet extends BaseWallet {
235
245
  const txRequest = await fromAccount.createTxExecutionRequest(
236
246
  finalExecutionPayload,
237
247
  feeOptions.gasSettings,
248
+ chainInfo,
238
249
  executionOptions,
239
250
  );
240
251
  const contractOverrides = {
@@ -263,4 +274,10 @@ export class CLIWallet extends BaseWallet {
263
274
  getNotes(filter: NotesFilter): Promise<NoteDao[]> {
264
275
  return this.pxe.debug.getNotes(filter);
265
276
  }
277
+
278
+ // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
279
+ // this is just a CLI wallet.
280
+ getContractArtifact(id: Fr) {
281
+ return this.pxe.getContractArtifact(id);
282
+ }
266
283
  }