@aztec/cli-wallet 0.0.1-commit.b655e406 → 0.0.1-commit.b6e433891

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 (78) hide show
  1. package/README.md +2 -2
  2. package/dest/bin/index.d.ts +2 -1
  3. package/dest/bin/index.js +20 -10
  4. package/dest/cmds/authorize_action.d.ts +2 -2
  5. package/dest/cmds/authorize_action.d.ts.map +1 -1
  6. package/dest/cmds/authorize_action.js +5 -3
  7. package/dest/cmds/bridge_fee_juice.d.ts +2 -2
  8. package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
  9. package/dest/cmds/bridge_fee_juice.js +3 -2
  10. package/dest/cmds/check_tx.d.ts +1 -1
  11. package/dest/cmds/check_tx.d.ts.map +1 -1
  12. package/dest/cmds/check_tx.js +44 -15
  13. package/dest/cmds/create_account.d.ts +4 -3
  14. package/dest/cmds/create_account.d.ts.map +1 -1
  15. package/dest/cmds/create_account.js +32 -18
  16. package/dest/cmds/create_authwit.d.ts +1 -1
  17. package/dest/cmds/create_authwit.js +1 -1
  18. package/dest/cmds/deploy.d.ts +1 -1
  19. package/dest/cmds/deploy.d.ts.map +1 -1
  20. package/dest/cmds/deploy.js +50 -24
  21. package/dest/cmds/deploy_account.d.ts +1 -1
  22. package/dest/cmds/deploy_account.d.ts.map +1 -1
  23. package/dest/cmds/deploy_account.js +31 -17
  24. package/dest/cmds/import_test_accounts.d.ts +1 -1
  25. package/dest/cmds/index.d.ts +1 -1
  26. package/dest/cmds/index.js +3 -3
  27. package/dest/cmds/profile.d.ts +1 -1
  28. package/dest/cmds/profile.js +1 -1
  29. package/dest/cmds/register_contract.d.ts +1 -1
  30. package/dest/cmds/register_sender.d.ts +1 -1
  31. package/dest/cmds/send.d.ts +2 -2
  32. package/dest/cmds/send.d.ts.map +1 -1
  33. package/dest/cmds/send.js +33 -18
  34. package/dest/cmds/simulate.d.ts +1 -1
  35. package/dest/cmds/simulate.d.ts.map +1 -1
  36. package/dest/cmds/simulate.js +4 -4
  37. package/dest/storage/wallet_db.d.ts +5 -5
  38. package/dest/storage/wallet_db.d.ts.map +1 -1
  39. package/dest/storage/wallet_db.js +47 -32
  40. package/dest/utils/authorizations.d.ts +1 -1
  41. package/dest/utils/cli_wallet_and_node_wrapper.d.ts +1 -1
  42. package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -1
  43. package/dest/utils/constants.d.ts +4 -0
  44. package/dest/utils/constants.d.ts.map +1 -0
  45. package/dest/utils/constants.js +7 -0
  46. package/dest/utils/ecdsa.d.ts +1 -1
  47. package/dest/utils/options/fees.d.ts +3 -2
  48. package/dest/utils/options/fees.d.ts.map +1 -1
  49. package/dest/utils/options/fees.js +5 -3
  50. package/dest/utils/options/index.d.ts +1 -1
  51. package/dest/utils/options/options.d.ts +1 -1
  52. package/dest/utils/options/options.js +1 -1
  53. package/dest/utils/profiling.d.ts +1 -1
  54. package/dest/utils/profiling.d.ts.map +1 -1
  55. package/dest/utils/profiling.js +9 -1
  56. package/dest/utils/wallet.d.ts +15 -10
  57. package/dest/utils/wallet.d.ts.map +1 -1
  58. package/dest/utils/wallet.js +68 -47
  59. package/package.json +17 -14
  60. package/src/bin/index.ts +18 -12
  61. package/src/cmds/authorize_action.ts +2 -2
  62. package/src/cmds/bridge_fee_juice.ts +3 -2
  63. package/src/cmds/check_tx.ts +50 -21
  64. package/src/cmds/create_account.ts +32 -20
  65. package/src/cmds/create_authwit.ts +1 -1
  66. package/src/cmds/deploy.ts +45 -23
  67. package/src/cmds/deploy_account.ts +29 -18
  68. package/src/cmds/index.ts +4 -4
  69. package/src/cmds/profile.ts +1 -1
  70. package/src/cmds/send.ts +27 -12
  71. package/src/cmds/simulate.ts +5 -8
  72. package/src/storage/wallet_db.ts +51 -38
  73. package/src/utils/cli_wallet_and_node_wrapper.ts +1 -1
  74. package/src/utils/constants.ts +4 -0
  75. package/src/utils/options/fees.ts +11 -4
  76. package/src/utils/options/options.ts +1 -1
  77. package/src/utils/profiling.ts +15 -1
  78. package/src/utils/wallet.ts +83 -62
@@ -1,16 +1,17 @@
1
1
  import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
2
2
  import type { AztecNode } from '@aztec/aztec.js/node';
3
- import type { FeeOptions, Wallet } from '@aztec/aztec.js/wallet';
4
- import { Fr } from '@aztec/foundation/fields';
3
+ import type { Wallet } from '@aztec/aztec.js/wallet';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import type { LogFn } from '@aztec/foundation/log';
6
6
  import type { FieldsOf } from '@aztec/foundation/types';
7
7
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
8
8
  import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
9
+ import type { FeeOptions } from '@aztec/wallet-sdk/base-wallet';
9
10
 
10
11
  import { Option } from 'commander';
11
12
 
12
13
  import type { WalletDB } from '../../storage/wallet_db.js';
13
- import { BASE_FEE_PADDING } from '../wallet.js';
14
+ import { MIN_FEE_PADDING } from '../constants.js';
14
15
  import { aliasedAddressParser } from './options.js';
15
16
 
16
17
  export type RawCliFeeArgs = {
@@ -170,6 +171,9 @@ export function parsePaymentMethod(
170
171
  case 'fpc-public': {
171
172
  const fpc = getFpc();
172
173
  const asset = getAsset();
174
+ log(
175
+ `WARNING: fpc-public is deprecated and will not work on mainnet alpha. Use fee_juice or fpc-sponsored instead.`,
176
+ );
173
177
  log(`Using public fee payment with asset ${asset} via paymaster ${fpc}`);
174
178
  const { PublicFeePaymentMethod } = await import('@aztec/aztec.js/fee');
175
179
  return new PublicFeePaymentMethod(fpc, from, wallet, gasSettings);
@@ -177,6 +181,9 @@ export function parsePaymentMethod(
177
181
  case 'fpc-private': {
178
182
  const fpc = getFpc();
179
183
  const asset = getAsset();
184
+ log(
185
+ `WARNING: fpc-private is deprecated and will not work on mainnet alpha. Use fee_juice or fpc-sponsored instead.`,
186
+ );
180
187
  log(`Using private fee payment with asset ${asset} via paymaster ${fpc}`);
181
188
  const { PrivateFeePaymentMethod } = await import('@aztec/aztec.js/fee');
182
189
  return new PrivateFeePaymentMethod(fpc, from, wallet, gasSettings);
@@ -249,7 +256,7 @@ export class CLIFeeArgs {
249
256
  ) {}
250
257
 
251
258
  async toUserFeeOptions(node: AztecNode, wallet: Wallet, from: AztecAddress): Promise<ParsedFeeOptions> {
252
- const maxFeesPerGas = (await node.getCurrentBaseFees()).mul(1 + BASE_FEE_PADDING);
259
+ const maxFeesPerGas = (await node.getCurrentMinFees()).mul(1 + MIN_FEE_PADDING);
253
260
  const gasSettings = GasSettings.default({ ...this.gasSettings, maxFeesPerGas });
254
261
  const paymentMethod = await this.paymentMethod(wallet, from, gasSettings);
255
262
  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)));
@@ -9,29 +9,26 @@ import {
9
9
  getGasLimits,
10
10
  } from '@aztec/aztec.js/contracts';
11
11
  import type { AztecNode } from '@aztec/aztec.js/node';
12
- import { UniqueNote } from '@aztec/aztec.js/note';
13
- import { AccountManager, type Aliased, BaseWallet, type SimulateOptions } from '@aztec/aztec.js/wallet';
12
+ import { AccountManager, type Aliased, type SimulateOptions } from '@aztec/aztec.js/wallet';
14
13
  import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
15
- import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/entrypoints/payload';
16
- import { Fr } from '@aztec/foundation/fields';
14
+ import { Fr } from '@aztec/foundation/curves/bn254';
17
15
  import type { LogFn } from '@aztec/foundation/log';
16
+ import type { NotesFilter } from '@aztec/pxe/client/lazy';
18
17
  import type { PXEConfig } from '@aztec/pxe/config';
19
18
  import type { PXE } from '@aztec/pxe/server';
20
19
  import { createPXE, getPXEConfig } from '@aztec/pxe/server';
21
20
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
22
21
  import { deriveSigningKey } from '@aztec/stdlib/keys';
23
- import type { NotesFilter } from '@aztec/stdlib/note';
24
- import type { TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
22
+ import { NoteDao } from '@aztec/stdlib/note';
23
+ import type { SimulationOverrides, TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
24
+ import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
25
+ import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
25
26
 
26
27
  import type { WalletDB } from '../storage/wallet_db.js';
28
+ import type { AccountType } from './constants.js';
27
29
  import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
28
30
  import { printGasEstimates } from './options/fees.js';
29
31
 
30
- export const AccountTypes = ['schnorr', 'ecdsasecp256r1', 'ecdsasecp256r1ssh', 'ecdsasecp256k1'] as const;
31
- export type AccountType = (typeof AccountTypes)[number];
32
-
33
- export const BASE_FEE_PADDING = 0.5;
34
-
35
32
  export class CLIWallet extends BaseWallet {
36
33
  private accountCache = new Map<string, Account>();
37
34
 
@@ -66,17 +63,20 @@ export class CLIWallet extends BaseWallet {
66
63
  txNonce: Fr,
67
64
  increasedFee: InteractionFeeOptions,
68
65
  ) {
69
- const feeOptions = await this.getDefaultFeeOptions(from, increasedFee);
66
+ const executionPayload = ExecutionPayload.empty();
67
+ const feeOptions = await this.completeFeeOptions(from, executionPayload.feePayer, increasedFee.gasSettings);
70
68
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
71
69
  const fromAccount = await this.getAccountFromAddress(from);
70
+ const chainInfo = await this.getChainInfo();
72
71
  const executionOptions: DefaultAccountEntrypointOptions = {
73
72
  txNonce,
74
73
  cancellable: this.cancellableTransactions,
75
74
  feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
76
75
  };
77
76
  return await fromAccount.createTxExecutionRequest(
78
- feeExecutionPayload ?? ExecutionPayload.empty(),
77
+ feeExecutionPayload ?? executionPayload,
79
78
  feeOptions.gasSettings,
79
+ chainInfo,
80
80
  executionOptions,
81
81
  );
82
82
  }
@@ -87,14 +87,13 @@ export class CLIWallet extends BaseWallet {
87
87
  increasedFee: InteractionFeeOptions,
88
88
  ): Promise<TxProvingResult> {
89
89
  const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
90
- return await this.pxe.proveTx(cancellationTxRequest);
90
+ return await this.pxe.proveTx(cancellationTxRequest, this.scopesFrom(from));
91
91
  }
92
92
 
93
93
  override async getAccountFromAddress(address: AztecAddress) {
94
94
  let account: Account | undefined;
95
95
  if (address.equals(AztecAddress.ZERO)) {
96
- const chainInfo = await this.getChainInfo();
97
- account = new SignerlessAccount(chainInfo);
96
+ account = new SignerlessAccount();
98
97
  } else if (this.accountCache.has(address.toString())) {
99
98
  return this.accountCache.get(address.toString())!;
100
99
  } else {
@@ -178,15 +177,26 @@ export class CLIWallet extends BaseWallet {
178
177
  return account;
179
178
  }
180
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
+ */
181
186
  private async getFakeAccountDataFor(address: AztecAddress) {
182
- const chainInfo = await this.getChainInfo();
183
187
  const originalAccount = await this.getAccountFromAddress(address);
184
- const originalAddress = originalAccount.getCompleteAddress();
185
- 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);
186
196
  if (!contractInstance) {
187
197
  throw new Error(`No contract instance found for address: ${originalAddress.address}`);
188
198
  }
189
- const stubAccount = createStubAccount(originalAddress, chainInfo);
199
+ const stubAccount = createStubAccount(originalAddress);
190
200
  const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
191
201
  salt: Fr.random(),
192
202
  });
@@ -198,10 +208,37 @@ export class CLIWallet extends BaseWallet {
198
208
  }
199
209
 
200
210
  override async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
201
- let simulationResults;
202
- const feeOptions = opts.fee?.estimateGas
203
- ? await this.getFeeOptionsForGasEstimation(opts.from, opts.fee)
204
- : await this.getDefaultFeeOptions(opts.from, opts.fee);
211
+ const simulationResults = await super.simulateTx(executionPayload, opts);
212
+
213
+ if (opts.fee?.estimateGas) {
214
+ const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
215
+ const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
216
+ printGasEstimates(feeOptions, limits, this.userLog);
217
+ }
218
+ return simulationResults;
219
+ }
220
+
221
+ /**
222
+ * Uses a stub account for kernelless simulation, bypassing real account authorization.
223
+ * Falls through to the standard entrypoint path for SignerlessAccount (ZERO address).
224
+ */
225
+ protected override async simulateViaEntrypoint(
226
+ executionPayload: ExecutionPayload,
227
+ opts: SimulateViaEntrypointOptions,
228
+ ): Promise<TxSimulationResult> {
229
+ const { from, feeOptions, scopes } = opts;
230
+ let overrides: SimulationOverrides | undefined;
231
+ let fromAccount: Account;
232
+ if (!from.equals(AztecAddress.ZERO)) {
233
+ const { account, instance, artifact } = await this.getFakeAccountDataFor(from);
234
+ fromAccount = account;
235
+ overrides = {
236
+ contracts: { [from.toString()]: { instance, artifact } },
237
+ };
238
+ } else {
239
+ fromAccount = await this.getAccountFromAddress(from);
240
+ }
241
+
205
242
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
206
243
  const executionOptions: DefaultAccountEntrypointOptions = {
207
244
  txNonce: Fr.random(),
@@ -212,42 +249,20 @@ export class CLIWallet extends BaseWallet {
212
249
  ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
213
250
  : executionPayload;
214
251
 
215
- // Kernelless simulations using the multicall entrypoints are not currently supported,
216
- // since we only override proper account contracts.
217
- // TODO: allow disabling kernels even when no overrides are necessary
218
- if (opts.from.equals(AztecAddress.ZERO)) {
219
- const fromAccount = await this.getAccountFromAddress(opts.from);
220
- const txRequest = await fromAccount.createTxExecutionRequest(
221
- finalExecutionPayload,
222
- feeOptions.gasSettings,
223
- executionOptions,
224
- );
225
- simulationResults = await this.pxe.simulateTx(
226
- txRequest,
227
- true /* simulatePublic */,
228
- opts?.skipTxValidation,
229
- opts?.skipFeeEnforcement ?? true,
230
- );
231
- } else {
232
- const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(opts.from);
233
- const txRequest = await fromAccount.createTxExecutionRequest(
234
- finalExecutionPayload,
235
- feeOptions.gasSettings,
236
- executionOptions,
237
- );
238
- const contractOverrides = {
239
- [opts.from.toString()]: { instance, artifact },
240
- };
241
- simulationResults = await this.pxe.simulateTx(txRequest, true /* simulatePublic */, true, true, {
242
- contracts: contractOverrides,
243
- });
244
- }
245
-
246
- if (opts.fee?.estimateGas) {
247
- const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
248
- printGasEstimates(feeOptions, limits, this.userLog);
249
- }
250
- return simulationResults;
252
+ const chainInfo = await this.getChainInfo();
253
+ const txRequest = await fromAccount.createTxExecutionRequest(
254
+ finalExecutionPayload,
255
+ feeOptions.gasSettings,
256
+ chainInfo,
257
+ executionOptions,
258
+ );
259
+ return this.pxe.simulateTx(txRequest, {
260
+ simulatePublic: true,
261
+ skipFeeEnforcement: true,
262
+ skipTxValidation: true,
263
+ overrides,
264
+ scopes,
265
+ });
251
266
  }
252
267
 
253
268
  // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
@@ -258,7 +273,13 @@ export class CLIWallet extends BaseWallet {
258
273
 
259
274
  // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
260
275
  // this is just a CLI wallet.
261
- getNotes(filter: NotesFilter): Promise<UniqueNote[]> {
262
- return this.pxe.getNotes(filter);
276
+ getNotes(filter: NotesFilter): Promise<NoteDao[]> {
277
+ return this.pxe.debug.getNotes(filter);
278
+ }
279
+
280
+ // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
281
+ // this is just a CLI wallet.
282
+ getContractArtifact(id: Fr) {
283
+ return this.pxe.getContractArtifact(id);
263
284
  }
264
285
  }