@aztec/cli-wallet 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0

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 (73) hide show
  1. package/dest/bin/index.js +1 -1
  2. package/dest/cmds/authorize_action.d.ts +2 -2
  3. package/dest/cmds/authorize_action.d.ts.map +1 -1
  4. package/dest/cmds/authorize_action.js +4 -2
  5. package/dest/cmds/bridge_fee_juice.d.ts +2 -2
  6. package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
  7. package/dest/cmds/bridge_fee_juice.js +3 -2
  8. package/dest/cmds/check_tx.d.ts +1 -1
  9. package/dest/cmds/check_tx.d.ts.map +1 -1
  10. package/dest/cmds/check_tx.js +57 -25
  11. package/dest/cmds/create_account.d.ts +9 -5
  12. package/dest/cmds/create_account.d.ts.map +1 -1
  13. package/dest/cmds/create_account.js +65 -32
  14. package/dest/cmds/create_authwit.d.ts +2 -2
  15. package/dest/cmds/create_authwit.d.ts.map +1 -1
  16. package/dest/cmds/deploy.d.ts +5 -4
  17. package/dest/cmds/deploy.d.ts.map +1 -1
  18. package/dest/cmds/deploy.js +65 -36
  19. package/dest/cmds/deploy_account.d.ts +4 -3
  20. package/dest/cmds/deploy_account.d.ts.map +1 -1
  21. package/dest/cmds/deploy_account.js +39 -25
  22. package/dest/cmds/get_fee_juice_balance.d.ts +5 -0
  23. package/dest/cmds/get_fee_juice_balance.d.ts.map +1 -0
  24. package/dest/cmds/get_fee_juice_balance.js +27 -0
  25. package/dest/cmds/import_test_accounts.d.ts +1 -1
  26. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  27. package/dest/cmds/import_test_accounts.js +2 -1
  28. package/dest/cmds/index.d.ts +1 -1
  29. package/dest/cmds/index.d.ts.map +1 -1
  30. package/dest/cmds/index.js +37 -20
  31. package/dest/cmds/send.d.ts +5 -4
  32. package/dest/cmds/send.d.ts.map +1 -1
  33. package/dest/cmds/send.js +33 -20
  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 -3
  37. package/dest/storage/wallet_db.d.ts +14 -6
  38. package/dest/storage/wallet_db.d.ts.map +1 -1
  39. package/dest/storage/wallet_db.js +75 -32
  40. package/dest/utils/constants.d.ts +4 -0
  41. package/dest/utils/constants.d.ts.map +1 -0
  42. package/dest/utils/constants.js +8 -0
  43. package/dest/utils/options/fees.d.ts +3 -2
  44. package/dest/utils/options/fees.d.ts.map +1 -1
  45. package/dest/utils/options/fees.js +38 -12
  46. package/dest/utils/options/options.d.ts +2 -2
  47. package/dest/utils/options/options.d.ts.map +1 -1
  48. package/dest/utils/options/options.js +6 -6
  49. package/dest/utils/profiling.d.ts +1 -1
  50. package/dest/utils/profiling.d.ts.map +1 -1
  51. package/dest/utils/profiling.js +9 -1
  52. package/dest/utils/wallet.d.ts +40 -12
  53. package/dest/utils/wallet.d.ts.map +1 -1
  54. package/dest/utils/wallet.js +194 -104
  55. package/package.json +17 -16
  56. package/src/bin/index.ts +1 -1
  57. package/src/cmds/authorize_action.ts +1 -1
  58. package/src/cmds/bridge_fee_juice.ts +3 -2
  59. package/src/cmds/check_tx.ts +63 -31
  60. package/src/cmds/create_account.ts +70 -37
  61. package/src/cmds/deploy.ts +64 -37
  62. package/src/cmds/deploy_account.ts +40 -21
  63. package/src/cmds/get_fee_juice_balance.ts +37 -0
  64. package/src/cmds/import_test_accounts.ts +12 -1
  65. package/src/cmds/index.ts +73 -17
  66. package/src/cmds/send.ts +33 -13
  67. package/src/cmds/simulate.ts +5 -7
  68. package/src/storage/wallet_db.ts +88 -39
  69. package/src/utils/constants.ts +10 -0
  70. package/src/utils/options/fees.ts +44 -12
  71. package/src/utils/options/options.ts +6 -6
  72. package/src/utils/profiling.ts +15 -1
  73. package/src/utils/wallet.ts +241 -130
@@ -1,17 +1,17 @@
1
1
  import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
2
2
  import type { AztecNode } from '@aztec/aztec.js/node';
3
3
  import type { Wallet } from '@aztec/aztec.js/wallet';
4
- import { Fr } from '@aztec/foundation/fields';
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
- import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
8
+ import { Gas, GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
9
9
  import type { FeeOptions } from '@aztec/wallet-sdk/base-wallet';
10
10
 
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 = {
@@ -115,6 +115,7 @@ export function parsePaymentMethod(
115
115
  payment: string,
116
116
  log: LogFn,
117
117
  db?: WalletDB,
118
+ estimateOnly?: boolean,
118
119
  ): (wallet: Wallet, from: AztecAddress, gasSettings: GasSettings) => Promise<FeePaymentMethod | undefined> {
119
120
  const parsed = payment.split(',').reduce(
120
121
  (acc, item) => {
@@ -136,7 +137,7 @@ export function parsePaymentMethod(
136
137
  if (!parsed.asset) {
137
138
  throw new Error('Missing "asset" in payment option');
138
139
  }
139
- return AztecAddress.fromString(parsed.asset);
140
+ return AztecAddress.fromStringUnsafe(parsed.asset);
140
141
  };
141
142
 
142
143
  return async (wallet: Wallet, from: AztecAddress, gasSettings: GasSettings) => {
@@ -149,7 +150,7 @@ export function parsePaymentMethod(
149
150
  amount: claimAmount,
150
151
  secret: claimSecret,
151
152
  leafIndex: messageLeafIndex,
152
- } = await db.popBridgedFeeJuice(from, log));
153
+ } = estimateOnly ? await db.peekBridgedFeeJuice(from, log) : await db.popBridgedFeeJuice(from, log));
153
154
  } else {
154
155
  ({ claimAmount, claimSecret, messageLeafIndex } = parsed);
155
156
  }
@@ -157,10 +158,10 @@ export function parsePaymentMethod(
157
158
  const { FeeJuicePaymentMethodWithClaim } = await import('@aztec/aztec.js/fee');
158
159
  return new FeeJuicePaymentMethodWithClaim(from, {
159
160
  claimAmount: (typeof claimAmount === 'string'
160
- ? Fr.fromHexString(claimAmount)
161
+ ? Fr.fromString(claimAmount)
161
162
  : new Fr(claimAmount)
162
163
  ).toBigInt(),
163
- claimSecret: Fr.fromHexString(claimSecret),
164
+ claimSecret: typeof claimSecret === 'string' ? Fr.fromString(claimSecret) : claimSecret,
164
165
  messageLeafIndex: BigInt(messageLeafIndex),
165
166
  });
166
167
  } else {
@@ -171,6 +172,9 @@ export function parsePaymentMethod(
171
172
  case 'fpc-public': {
172
173
  const fpc = getFpc();
173
174
  const asset = getAsset();
175
+ log(
176
+ `WARNING: fpc-public is deprecated and will not work on mainnet alpha. Use fee_juice or fpc-sponsored instead.`,
177
+ );
174
178
  log(`Using public fee payment with asset ${asset} via paymaster ${fpc}`);
175
179
  const { PublicFeePaymentMethod } = await import('@aztec/aztec.js/fee');
176
180
  return new PublicFeePaymentMethod(fpc, from, wallet, gasSettings);
@@ -178,6 +182,9 @@ export function parsePaymentMethod(
178
182
  case 'fpc-private': {
179
183
  const fpc = getFpc();
180
184
  const asset = getAsset();
185
+ log(
186
+ `WARNING: fpc-private is deprecated and will not work on mainnet alpha. Use fee_juice or fpc-sponsored instead.`,
187
+ );
181
188
  log(`Using private fee payment with asset ${asset} via paymaster ${fpc}`);
182
189
  const { PrivateFeePaymentMethod } = await import('@aztec/aztec.js/fee');
183
190
  return new PrivateFeePaymentMethod(fpc, from, wallet, gasSettings);
@@ -250,8 +257,11 @@ export class CLIFeeArgs {
250
257
  ) {}
251
258
 
252
259
  async toUserFeeOptions(node: AztecNode, wallet: Wallet, from: AztecAddress): Promise<ParsedFeeOptions> {
253
- const maxFeesPerGas = (await node.getCurrentBaseFees()).mul(1 + BASE_FEE_PADDING);
254
- const gasSettings = GasSettings.default({ ...this.gasSettings, maxFeesPerGas });
260
+ const minFees = await this.getMinFees(node);
261
+ const maxFeesPerGas = minFees.mul(1 + MIN_FEE_PADDING);
262
+ const { txsLimits } = await node.getNodeInfo();
263
+ const gasLimits = this.gasSettings.gasLimits ?? Gas.from(txsLimits.gas);
264
+ const gasSettings = GasSettings.fallback({ ...this.gasSettings, gasLimits, maxFeesPerGas });
255
265
  const paymentMethod = await this.paymentMethod(wallet, from, gasSettings);
256
266
  return {
257
267
  paymentMethod,
@@ -259,10 +269,32 @@ export class CLIFeeArgs {
259
269
  };
260
270
  }
261
271
 
272
+ /**
273
+ * Returns the worst-case min fee across predicted future slots.
274
+ * Falls back to getCurrentMinFees if the node doesn't support getPredictedMinFees.
275
+ */
276
+ private async getMinFees(node: AztecNode): Promise<GasFees> {
277
+ try {
278
+ const predicted = await node.getPredictedMinFees(ManaUsageEstimate.Limit);
279
+ if (predicted.length === 0) {
280
+ return node.getCurrentMinFees();
281
+ }
282
+ return predicted.reduce((worst, fees) => (fees.feePerL2Gas > worst.feePerL2Gas ? fees : worst));
283
+ } catch (err: any) {
284
+ // Fallback for old nodes that don't support getPredictedMinFees.
285
+ // Only fall back on method-not-found errors (JSON-RPC code -32601); rethrow others.
286
+ if (err?.cause?.code === -32601 || err?.message?.includes('Method not found')) {
287
+ return node.getCurrentMinFees();
288
+ }
289
+ throw err;
290
+ }
291
+ }
292
+
262
293
  static parse(args: RawCliFeeArgs, log: LogFn, db?: WalletDB): CLIFeeArgs {
294
+ const estimateOnly = !!args.estimateGasOnly;
263
295
  return new CLIFeeArgs(
264
- !!args.estimateGasOnly,
265
- parsePaymentMethod(args.payment ?? 'method=fee_juice', log, db),
296
+ estimateOnly,
297
+ parsePaymentMethod(args.payment ?? 'method=fee_juice', log, db, estimateOnly),
266
298
  parseGasSettings(args),
267
299
  );
268
300
  }
@@ -288,7 +320,7 @@ function formatGasEstimate(estimate: Pick<GasSettings, 'gasLimits' | 'teardownGa
288
320
  }
289
321
 
290
322
  function getEstimatedCost(estimate: Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>, maxFeesPerGas: GasFees) {
291
- return GasSettings.default({ ...estimate, maxFeesPerGas })
323
+ return GasSettings.fallback({ ...estimate, maxFeesPerGas })
292
324
  .getFeeLimit()
293
325
  .toBigInt();
294
326
  }
@@ -1,5 +1,5 @@
1
1
  import { TxHash } from '@aztec/aztec.js/tx';
2
- import { parseAztecAddress, parseSecretKey, parseTxHash } from '@aztec/cli/utils';
2
+ import { parseAztecAddress, parseSigningKey, parseTxHash } from '@aztec/cli/utils';
3
3
  import { AuthWitness } from '@aztec/stdlib/auth-witness';
4
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
 
@@ -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
 
@@ -64,13 +64,13 @@ export function aliasedAddressParser(defaultPrefix: AliasType, address: string,
64
64
  }
65
65
  }
66
66
 
67
- export function aliasedSecretKeyParser(sk: string, db?: WalletDB) {
67
+ export function aliasedSigningKeyParser(sk: string, db?: WalletDB) {
68
68
  if (sk.startsWith('0x')) {
69
- return parseSecretKey(sk);
69
+ return parseSigningKey(sk);
70
70
  } else {
71
- const prefixed = `${sk.startsWith('accounts') ? '' : 'accounts'}:${sk.endsWith(':sk') ? sk : `${sk}:sk`}`;
71
+ const prefixed = `${sk.startsWith('accounts') ? '' : 'accounts'}:${sk.endsWith(':signing') ? sk : `${sk}:signing`}`;
72
72
  const rawSk = db ? db.tryRetrieveAlias(prefixed) : sk;
73
- return parseSecretKey(rawSk);
73
+ return parseSigningKey(rawSk);
74
74
  }
75
75
  }
76
76
 
@@ -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)));