@aztec/cli-wallet 0.0.1-commit.9ef841308 → 0.0.1-commit.a4600f49

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 (45) hide show
  1. package/dest/bin/index.js +1 -1
  2. package/dest/cmds/check_tx.js +15 -13
  3. package/dest/cmds/create_account.d.ts +1 -1
  4. package/dest/cmds/create_account.d.ts.map +1 -1
  5. package/dest/cmds/create_account.js +6 -7
  6. package/dest/cmds/deploy.d.ts +3 -3
  7. package/dest/cmds/deploy.d.ts.map +1 -1
  8. package/dest/cmds/deploy.js +23 -21
  9. package/dest/cmds/deploy_account.js +3 -6
  10. package/dest/cmds/import_test_accounts.d.ts +1 -1
  11. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  12. package/dest/cmds/import_test_accounts.js +1 -1
  13. package/dest/cmds/index.d.ts +1 -1
  14. package/dest/cmds/index.d.ts.map +1 -1
  15. package/dest/cmds/index.js +2 -2
  16. package/dest/cmds/send.js +3 -6
  17. package/dest/cmds/simulate.d.ts +1 -1
  18. package/dest/cmds/simulate.d.ts.map +1 -1
  19. package/dest/cmds/simulate.js +2 -1
  20. package/dest/storage/wallet_db.d.ts +7 -2
  21. package/dest/storage/wallet_db.d.ts.map +1 -1
  22. package/dest/storage/wallet_db.js +14 -0
  23. package/dest/utils/constants.d.ts +2 -2
  24. package/dest/utils/constants.d.ts.map +1 -1
  25. package/dest/utils/constants.js +1 -0
  26. package/dest/utils/options/fees.d.ts +3 -2
  27. package/dest/utils/options/fees.d.ts.map +1 -1
  28. package/dest/utils/options/fees.js +34 -10
  29. package/dest/utils/wallet.d.ts +18 -5
  30. package/dest/utils/wallet.d.ts.map +1 -1
  31. package/dest/utils/wallet.js +105 -35
  32. package/package.json +16 -15
  33. package/src/bin/index.ts +1 -1
  34. package/src/cmds/check_tx.ts +17 -15
  35. package/src/cmds/create_account.ts +6 -4
  36. package/src/cmds/deploy.ts +22 -23
  37. package/src/cmds/deploy_account.ts +3 -3
  38. package/src/cmds/import_test_accounts.ts +5 -1
  39. package/src/cmds/index.ts +3 -2
  40. package/src/cmds/send.ts +3 -3
  41. package/src/cmds/simulate.ts +2 -1
  42. package/src/storage/wallet_db.ts +14 -0
  43. package/src/utils/constants.ts +7 -1
  44. package/src/utils/options/fees.ts +36 -10
  45. package/src/utils/wallet.ts +112 -37
@@ -1,5 +1,5 @@
1
1
  import { NO_FROM } from '@aztec/aztec.js/account';
2
- import { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
3
3
  import type { DeployOptions } from '@aztec/aztec.js/contracts';
4
4
  import { NO_WAIT } from '@aztec/aztec.js/contracts';
5
5
  import { ContractDeployer } from '@aztec/aztec.js/deployment';
@@ -36,6 +36,7 @@ export async function deploy(
36
36
  timeout: number = DEFAULT_TX_TIMEOUT_S,
37
37
  debugLogger: Logger,
38
38
  log: LogFn,
39
+ universal?: boolean,
39
40
  ) {
40
41
  const out: Record<string, any> = {};
41
42
  salt ??= Fr.random();
@@ -45,12 +46,7 @@ export async function deploy(
45
46
 
46
47
  // TODO(#12081): Add contractArtifact.noirVersion and check here (via Noir.lock)?
47
48
 
48
- const contractDeployer = new ContractDeployer(
49
- contractArtifact,
50
- wallet,
51
- publicKeys ?? PublicKeys.default(),
52
- initializer,
53
- );
49
+ const contractDeployer = new ContractDeployer(contractArtifact, wallet, initializer);
54
50
 
55
51
  let args = [];
56
52
  if (rawArgs.length > 0) {
@@ -62,13 +58,15 @@ export async function deploy(
62
58
  debugLogger.debug(`Encoded arguments: ${args.join(', ')}`);
63
59
  }
64
60
 
65
- const deployInteraction = contractDeployer.deploy(...args);
61
+ const deployInteraction = contractDeployer.deploy(args, {
62
+ salt,
63
+ publicKeys: publicKeys ?? PublicKeys.default(),
64
+ ...(universal ? { universalDeploy: true as const } : {}),
65
+ });
66
66
  const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(node, wallet, deployer);
67
67
  const deployOpts: DeployOptions = {
68
68
  fee: { gasSettings, paymentMethod },
69
69
  from: deployer ?? NO_FROM,
70
- contractAddressSalt: salt,
71
- universalDeploy: !deployer,
72
70
  skipClassPublication,
73
71
  skipInitialization,
74
72
  skipInstancePublication,
@@ -77,10 +75,10 @@ export async function deploy(
77
75
  const localStart = performance.now();
78
76
  const sim = await deployInteraction.simulate({
79
77
  ...deployOpts,
80
- fee: { ...deployOpts.fee, estimateGas: true },
78
+ includeMetadata: true,
81
79
  });
82
- // estimateGas: true guarantees these fields are present
83
- const estimatedGas = sim.estimatedGas!;
80
+ // includeMetadata: true guarantees these fields are present
81
+ const estimatedGas = await wallet.estimateGasLimits(sim.gasUsed!);
84
82
  const stats = sim.stats!;
85
83
 
86
84
  if (feeOpts.estimateOnly) {
@@ -101,8 +99,9 @@ export async function deploy(
101
99
  printProfileResult(stats, log);
102
100
  }
103
101
 
104
- const { address, partialAddress } = deployInteraction;
105
102
  const instance = await deployInteraction.getInstance();
103
+ const address = instance.address;
104
+ const partialAddress = await deployInteraction.getPartialAddress();
106
105
 
107
106
  const { txHash } = await deployInteraction.send({ ...deployOpts, wait: NO_WAIT });
108
107
  const localTimeMs = performance.now() - localStart;
@@ -115,8 +114,8 @@ export async function deploy(
115
114
  const nodeTimeMs = performance.now() - nodeStart;
116
115
 
117
116
  if (!json) {
118
- log(`Contract deployed at ${address?.toString()}`);
119
- log(`Contract partial address ${(await partialAddress)?.toString()}`);
117
+ log(`Contract deployed at ${address.toString()}`);
118
+ log(`Contract partial address ${partialAddress.toString()}`);
120
119
  log(`Contract init hash ${instance.initializationHash.toString()}`);
121
120
  log(`Deployment tx hash: ${txHash.toString()}`);
122
121
  log(`Deployment salt: ${salt.toString()}`);
@@ -126,8 +125,8 @@ export async function deploy(
126
125
  log(` Node inclusion time: ${(nodeTimeMs / 1000).toFixed(1)}s`);
127
126
  } else {
128
127
  out.contract = {
129
- address: address?.toString(),
130
- partialAddress: (await partialAddress)?.toString(),
128
+ address: address.toString(),
129
+ partialAddress: partialAddress.toString(),
131
130
  initializationHash: instance.initializationHash.toString(),
132
131
  salt: salt.toString(),
133
132
  transactionFee: receipt.transactionFee?.toString(),
@@ -135,16 +134,16 @@ export async function deploy(
135
134
  }
136
135
  } else {
137
136
  if (!json) {
138
- log(`Contract deployed at ${address?.toString()}`);
139
- log(`Contract partial address ${(await partialAddress)?.toString()}`);
137
+ log(`Contract deployed at ${address.toString()}`);
138
+ log(`Contract partial address ${partialAddress.toString()}`);
140
139
  log(`Contract init hash ${instance.initializationHash.toString()}`);
141
140
  log(`Deployment tx hash: ${txHash.toString()}`);
142
141
  log(`Deployment salt: ${salt.toString()}`);
143
142
  log(`Deployer: ${instance.deployer.toString()}`);
144
143
  } else {
145
144
  out.contract = {
146
- address: address?.toString(),
147
- partialAddress: (await partialAddress)?.toString(),
145
+ address: address.toString(),
146
+ partialAddress: partialAddress.toString(),
148
147
  initializationHash: instance.initializationHash.toString(),
149
148
  salt: salt.toString(),
150
149
  };
@@ -154,5 +153,5 @@ export async function deploy(
154
153
  if (json) {
155
154
  log(prettyPrintJSON(out));
156
155
  }
157
- return deployInteraction.address;
156
+ return await deployInteraction.getAddress();
158
157
  }
@@ -68,10 +68,10 @@ export async function deployAccount(
68
68
  const deployMethod = await account.getDeployMethod();
69
69
  const sim = await deployMethod.simulate({
70
70
  ...deployAccountOpts,
71
- fee: { ...deployAccountOpts.fee, estimateGas: true },
71
+ includeMetadata: true,
72
72
  });
73
- // estimateGas: true guarantees these fields are present
74
- const estimatedGas = sim.estimatedGas!;
73
+ // includeMetadata: true guarantees these fields are present
74
+ const estimatedGas = await wallet.estimateGasLimits(sim.gasUsed!);
75
75
  const stats = sim.stats!;
76
76
 
77
77
  if (feeOpts.estimateOnly) {
@@ -16,7 +16,11 @@ export async function importTestAccounts(wallet: CLIWallet, db: WalletDB, json:
16
16
  const secret = testAccounts[i].secret;
17
17
  const salt = new Fr(account.salt);
18
18
  const address = account.address;
19
- await db.storeAccount(address, { type: 'schnorr', secretKey: secret, salt, alias, publicKey: undefined }, log);
19
+ await db.storeAccount(
20
+ address,
21
+ { type: 'schnorr_initializerless', secretKey: secret, salt, alias, publicKey: undefined },
22
+ log,
23
+ );
20
24
 
21
25
  if (json) {
22
26
  out[alias] = {
package/src/cmds/index.ts CHANGED
@@ -297,12 +297,12 @@ export function injectCommands(
297
297
  const { wallet, node } = walletAndNodeWrapper;
298
298
  const artifactPath = await artifactPathPromise;
299
299
 
300
- debugLogger.info(`Using wallet with address ${parsedFromAddress.toString()}`);
300
+ debugLogger.info(`Using wallet with address ${parsedFromAddress?.toString() ?? '<none>'}`);
301
301
 
302
302
  const address = await deploy(
303
303
  wallet,
304
304
  node,
305
- universal ? undefined : parsedFromAddress,
305
+ parsedFromAddress,
306
306
  artifactPath,
307
307
  json,
308
308
  publicKey,
@@ -319,6 +319,7 @@ export function injectCommands(
319
319
  timeout,
320
320
  debugLogger,
321
321
  log,
322
+ universal,
322
323
  );
323
324
  if (db && address) {
324
325
  await db.storeContract(address, artifactPath, log, alias);
package/src/cmds/send.ts CHANGED
@@ -42,10 +42,10 @@ export async function send(
42
42
  const localStart = performance.now();
43
43
  const sim = await call.simulate({
44
44
  ...sendOptions,
45
- fee: { ...sendOptions.fee, estimateGas: true },
45
+ includeMetadata: true,
46
46
  });
47
- // estimateGas: true guarantees these fields are present
48
- const estimatedGas = sim.estimatedGas!;
47
+ // includeMetadata: true guarantees these fields are present
48
+ const estimatedGas = await wallet.estimateGasLimits(sim.gasUsed!);
49
49
  const stats = sim.stats!;
50
50
 
51
51
  if (feeOpts.estimateOnly) {
@@ -44,7 +44,8 @@ export async function simulate(
44
44
  if (!metadata.instance) {
45
45
  return undefined;
46
46
  }
47
- const artifact = await wallet.getContractArtifact(metadata.instance.currentContractClassId);
47
+ const classId = metadata.updatedContractClassId ?? metadata.instance.originalContractClassId;
48
+ const artifact = await wallet.getContractArtifact(classId);
48
49
  return artifact;
49
50
  },
50
51
  log,
@@ -70,6 +70,20 @@ export class WalletDB {
70
70
  return { amount: BigInt(amountStr), secret: secretStr, leafIndex: BigInt(leafIndexStr) };
71
71
  }
72
72
 
73
+ async peekBridgedFeeJuice(recipient: AztecAddress, log: LogFn) {
74
+ const stackPointer =
75
+ (await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:stackPointer`))?.readInt8() || 0;
76
+ const result = await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:${stackPointer}`);
77
+ if (!result) {
78
+ throw new Error(
79
+ `No stored fee juice available for recipient ${recipient.toString()}. Please provide claim amount and secret. Stack pointer ${stackPointer}`,
80
+ );
81
+ }
82
+ const [amountStr, secretStr, leafIndexStr] = result.toString().split(':');
83
+ log(`Peeked ${amountStr} fee juice for recipient ${recipient.toString()}. Stack pointer ${stackPointer}`);
84
+ return { amount: BigInt(amountStr), secret: secretStr, leafIndex: BigInt(leafIndexStr) };
85
+ }
86
+
73
87
  async storeAccount(
74
88
  address: AztecAddress,
75
89
  {
@@ -1,4 +1,10 @@
1
1
  export const MIN_FEE_PADDING = 0.5;
2
2
 
3
- export const AccountTypes = ['schnorr', 'ecdsasecp256r1', 'ecdsasecp256r1ssh', 'ecdsasecp256k1'] as const;
3
+ export const AccountTypes = [
4
+ 'schnorr',
5
+ 'schnorr_initializerless',
6
+ 'ecdsasecp256r1',
7
+ 'ecdsasecp256r1ssh',
8
+ 'ecdsasecp256k1',
9
+ ] as const;
4
10
  export type AccountType = (typeof AccountTypes)[number];
@@ -5,7 +5,7 @@ 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';
@@ -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 {
@@ -256,8 +257,11 @@ export class CLIFeeArgs {
256
257
  ) {}
257
258
 
258
259
  async toUserFeeOptions(node: AztecNode, wallet: Wallet, from: AztecAddress): Promise<ParsedFeeOptions> {
259
- const maxFeesPerGas = (await node.getCurrentMinFees()).mul(1 + MIN_FEE_PADDING);
260
- 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 });
261
265
  const paymentMethod = await this.paymentMethod(wallet, from, gasSettings);
262
266
  return {
263
267
  paymentMethod,
@@ -265,10 +269,32 @@ export class CLIFeeArgs {
265
269
  };
266
270
  }
267
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
+
268
293
  static parse(args: RawCliFeeArgs, log: LogFn, db?: WalletDB): CLIFeeArgs {
294
+ const estimateOnly = !!args.estimateGasOnly;
269
295
  return new CLIFeeArgs(
270
- !!args.estimateGasOnly,
271
- parsePaymentMethod(args.payment ?? 'method=fee_juice', log, db),
296
+ estimateOnly,
297
+ parsePaymentMethod(args.payment ?? 'method=fee_juice', log, db, estimateOnly),
272
298
  parseGasSettings(args),
273
299
  );
274
300
  }
@@ -294,7 +320,7 @@ function formatGasEstimate(estimate: Pick<GasSettings, 'gasLimits' | 'teardownGa
294
320
  }
295
321
 
296
322
  function getEstimatedCost(estimate: Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>, maxFeesPerGas: GasFees) {
297
- return GasSettings.default({ ...estimate, maxFeesPerGas })
323
+ return GasSettings.fallback({ ...estimate, maxFeesPerGas })
298
324
  .getFeeLimit()
299
325
  .toBigInt();
300
326
  }
@@ -1,15 +1,17 @@
1
1
  import { EcdsaRAccountContract, EcdsaRSSHAccountContract } from '@aztec/accounts/ecdsa';
2
- import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
3
- import { StubAccountContractArtifact, createStubAccount } from '@aztec/accounts/stub';
2
+ import { StubEcdsaAccountContractArtifact, createStubEcdsaAccount } from '@aztec/accounts/ecdsa/stub';
3
+ import { SchnorrAccountContract, SchnorrInitializerlessAccountContract } from '@aztec/accounts/schnorr';
4
+ import { StubSchnorrAccountContractArtifact, createStubSchnorrAccount } from '@aztec/accounts/schnorr/stub';
4
5
  import { getIdentities } from '@aztec/accounts/utils';
5
6
  import { type Account, type AccountContract, NO_FROM } from '@aztec/aztec.js/account';
6
7
  import {
8
+ ContractFunctionInteraction,
7
9
  type InteractionFeeOptions,
8
- getContractInstanceFromInstantiationParams,
9
- getGasLimits,
10
+ getContractClassFromArtifact,
10
11
  } from '@aztec/aztec.js/contracts';
11
12
  import type { AztecNode } from '@aztec/aztec.js/node';
12
- import { AccountManager, type Aliased, type SimulateOptions } from '@aztec/aztec.js/wallet';
13
+ import { AccountManager, type Aliased } from '@aztec/aztec.js/wallet';
14
+ import { TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
13
15
  import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
14
16
  import { DefaultEntrypoint } from '@aztec/entrypoints/default';
15
17
  import { Fr } from '@aztec/foundation/curves/bn254';
@@ -18,20 +20,27 @@ import type { NotesFilter } from '@aztec/pxe/client/lazy';
18
20
  import type { PXEConfig } from '@aztec/pxe/config';
19
21
  import type { PXE } from '@aztec/pxe/server';
20
22
  import { createPXE, getPXEConfig } from '@aztec/pxe/server';
23
+ import { getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry';
21
24
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
25
+ import type { Gas, GasUsed } from '@aztec/stdlib/gas';
22
26
  import { deriveSigningKey } from '@aztec/stdlib/keys';
23
27
  import { NoteDao } from '@aztec/stdlib/note';
24
- import type { SimulationOverrides, TxExecutionRequest, TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
28
+ import type { SimulationOverrides, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx';
25
29
  import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
26
- import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
30
+ import { BaseWallet, type SimulateViaEntrypointOptions, getGasLimits } from '@aztec/wallet-sdk/base-wallet';
27
31
 
28
32
  import type { WalletDB } from '../storage/wallet_db.js';
29
33
  import type { AccountType } from './constants.js';
30
34
  import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
31
- import { printGasEstimates } from './options/fees.js';
35
+
36
+ /** Padding the CLI wallet applies to simulated gas usage when deriving declared gas limits. */
37
+ const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
32
38
 
33
39
  export class CLIWallet extends BaseWallet {
34
40
  private accountCache = new Map<string, Account>();
41
+ // Stub class ids, populated on wallet startup
42
+ // to avoid redundant work per simulation
43
+ private stubClassIds = new Map<AccountType, Fr>();
35
44
 
36
45
  constructor(
37
46
  pxe: PXE,
@@ -51,12 +60,55 @@ export class CLIWallet extends BaseWallet {
51
60
  ): Promise<CLIWallet> {
52
61
  const pxeConfig = Object.assign(getPXEConfig(), overridePXEConfig);
53
62
  const pxe = await createPXE(node, pxeConfig);
54
- return new CLIWallet(pxe, node, log, db);
63
+ const wallet = new CLIWallet(pxe, node, log, db);
64
+ await wallet.initStubClasses();
65
+ await wallet.registerAuthRegistry();
66
+ return wallet;
67
+ }
68
+
69
+ private async registerAuthRegistry(): Promise<void> {
70
+ const { instance, artifact } = await getStandardAuthRegistry();
71
+ await this.pxe.registerContractClass(artifact);
72
+ await this.pxe.registerContract(instance);
73
+ }
74
+
75
+ /**
76
+ * Hashes and registers the stub class for every supported account type with PXE, populating
77
+ * stubClassIds. Called on wallet initialization.
78
+ */
79
+ private async initStubClasses(): Promise<void> {
80
+ const { id: schnorrClassId } = await getContractClassFromArtifact(StubSchnorrAccountContractArtifact);
81
+ await this.pxe.registerContractClass(StubSchnorrAccountContractArtifact);
82
+
83
+ // ecdsa stubs share the same class id
84
+ const { id: ecdsaClassId } = await getContractClassFromArtifact(StubEcdsaAccountContractArtifact);
85
+ await this.pxe.registerContractClass(StubEcdsaAccountContractArtifact);
86
+
87
+ this.stubClassIds.set('schnorr', schnorrClassId);
88
+ this.stubClassIds.set('schnorr_initializerless', schnorrClassId);
89
+ this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
90
+ this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
91
+ this.stubClassIds.set('ecdsasecp256r1ssh', ecdsaClassId);
55
92
  }
56
93
 
57
94
  override async getAccounts(): Promise<Aliased<AztecAddress>[]> {
58
95
  const accounts = (await this.db?.listAliases('accounts')) ?? [];
59
- return Promise.resolve(accounts.map(({ key, value }) => ({ alias: value, item: AztecAddress.fromString(key) })));
96
+ return Promise.resolve(
97
+ accounts.map(({ key, value }) => {
98
+ const alias = key.includes(':') ? key.slice(key.indexOf(':') + 1) : key;
99
+ return { alias, item: AztecAddress.fromStringUnsafe(value) };
100
+ }),
101
+ );
102
+ }
103
+
104
+ /**
105
+ * Derives suggested total and teardown gas limits from simulated gas usage, padded and clamped to the
106
+ * network's per-tx admission limits.
107
+ * @param gasUsed - The gas consumed during simulation (from a `simulate({ includeMetadata: true })` result).
108
+ */
109
+ async estimateGasLimits(gasUsed: GasUsed): Promise<{ gasLimits: Gas; teardownGasLimits: Gas }> {
110
+ const maxTxGasLimits = await this.getMaxTxGasLimits();
111
+ return getGasLimits(gasUsed, maxTxGasLimits, DEFAULT_ESTIMATED_GAS_PADDING);
60
112
  }
61
113
 
62
114
  private async createCancellationTxExecutionRequest(
@@ -65,7 +117,11 @@ export class CLIWallet extends BaseWallet {
65
117
  increasedFee: InteractionFeeOptions,
66
118
  ) {
67
119
  const executionPayload = ExecutionPayload.empty();
68
- const feeOptions = await this.completeFeeOptions(from, executionPayload.feePayer, increasedFee.gasSettings);
120
+ const feeOptions = await this.completeFeeOptions({
121
+ from,
122
+ feePayer: executionPayload.feePayer,
123
+ gasSettings: increasedFee.gasSettings,
124
+ });
69
125
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
70
126
  const fromAccount = await this.getAccountFromAddress(from);
71
127
  const chainInfo = await this.getChainInfo();
@@ -89,7 +145,7 @@ export class CLIWallet extends BaseWallet {
89
145
  increasedFee: InteractionFeeOptions,
90
146
  ): Promise<TxProvingResult> {
91
147
  const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
92
- return await this.pxe.proveTx(cancellationTxRequest, this.scopesFrom(from));
148
+ return await this.pxe.proveTx(cancellationTxRequest, { scopes: this.scopesFrom(from), senderForTags: from });
93
149
  }
94
150
 
95
151
  override async getAccountFromAddress(address: AztecAddress) {
@@ -108,13 +164,27 @@ export class CLIWallet extends BaseWallet {
108
164
  }
109
165
 
110
166
  private async createAccount(secret: Fr, salt: Fr, contract: AccountContract): Promise<AccountManager> {
111
- const accountManager = await AccountManager.create(this, secret, contract, salt);
167
+ const accountManager = await AccountManager.create(this, secret, contract, { salt });
112
168
 
113
169
  const instance = accountManager.getInstance();
114
170
  const artifact = await contract.getContractArtifact();
115
171
 
116
172
  await this.registerContract(instance, artifact, secret);
117
173
  this.accountCache.set(accountManager.address.toString(), await accountManager.getAccount());
174
+
175
+ // Initializerless accounts have no deployment tx; their address commits to the signing public key
176
+ // (via the contract's immutablesHash, resolved by AccountManager.create) and the constructor's
177
+ // storage writes are materialized locally via a simulated "store" call here.
178
+ if (contract instanceof SchnorrInitializerlessAccountContract) {
179
+ const constructorAbi = artifact.functions.find(f => f.name === 'constructor');
180
+ if (!constructorAbi) {
181
+ throw new Error('Could not create SchnorrInitializerlessAccount: constructor ABI not found');
182
+ }
183
+ const { x, y } = await contract.getSigningPublicKey();
184
+ const storeCall = new ContractFunctionInteraction(this, instance.address, constructorAbi, [x, y]);
185
+ await storeCall.simulate({ from: instance.address });
186
+ }
187
+
118
188
  return accountManager;
119
189
  }
120
190
 
@@ -142,6 +212,14 @@ export class CLIWallet extends BaseWallet {
142
212
  account = await this.createAccount(secretKey, salt, new SchnorrAccountContract(deriveSigningKey(secretKey)));
143
213
  break;
144
214
  }
215
+ case 'schnorr_initializerless': {
216
+ account = await this.createAccount(
217
+ secretKey,
218
+ salt,
219
+ new SchnorrInitializerlessAccountContract(deriveSigningKey(secretKey)),
220
+ );
221
+ break;
222
+ }
145
223
  case 'ecdsasecp256r1': {
146
224
  account = await this.createAccount(
147
225
  secretKey,
@@ -190,26 +268,19 @@ export class CLIWallet extends BaseWallet {
190
268
  if (!contractInstance) {
191
269
  throw new Error(`No contract instance found for address: ${originalAddress.address}`);
192
270
  }
193
- const stubAccount = createStubAccount(originalAddress);
194
- const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
195
- salt: Fr.random(),
196
- });
197
- return {
198
- account: stubAccount,
199
- instance,
200
- artifact: StubAccountContractArtifact,
201
- };
202
- }
203
-
204
- override async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
205
- const simulationResults = await super.simulateTx(executionPayload, opts);
206
-
207
- if (opts.fee?.estimateGas) {
208
- const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
209
- const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
210
- printGasEstimates(feeOptions, limits, this.userLog);
271
+ const { type } = await this.db!.retrieveAccount(address);
272
+ const stubAccount =
273
+ type === 'schnorr' || type === 'schnorr_initializerless'
274
+ ? createStubSchnorrAccount(originalAddress)
275
+ : createStubEcdsaAccount(originalAddress);
276
+ const stubClassId = this.stubClassIds.get(type);
277
+ if (!stubClassId) {
278
+ throw new Error(
279
+ `Stub class for account type '${type}' was not registered at wallet init. This is a bug — initStubClasses should cover every supported AccountType.`,
280
+ );
211
281
  }
212
- return simulationResults;
282
+ const instance = { ...contractInstance, currentContractClassId: stubClassId };
283
+ return { account: stubAccount, instance };
213
284
  }
214
285
 
215
286
  /**
@@ -219,8 +290,9 @@ export class CLIWallet extends BaseWallet {
219
290
  protected override async simulateViaEntrypoint(
220
291
  executionPayload: ExecutionPayload,
221
292
  opts: SimulateViaEntrypointOptions,
222
- ): Promise<TxSimulationResult> {
223
- const { from, feeOptions, scopes } = opts;
293
+ ): Promise<TxSimulationResultWithAppOffset> {
294
+ const { from, feeOptions, additionalScopes, sendMessagesAs } = opts;
295
+ const scopes = this.scopesFrom(from, additionalScopes);
224
296
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
225
297
  const finalExecutionPayload = feeExecutionPayload
226
298
  ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
@@ -233,9 +305,9 @@ export class CLIWallet extends BaseWallet {
233
305
  const entrypoint = new DefaultEntrypoint();
234
306
  txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
235
307
  } else {
236
- const { account, instance, artifact } = await this.getFakeAccountDataFor(from);
308
+ const { account, instance } = await this.getFakeAccountDataFor(from);
237
309
  overrides = {
238
- contracts: { [from.toString()]: { instance, artifact } },
310
+ contracts: { [from.toString()]: { instance } },
239
311
  };
240
312
  const executionOptions: DefaultAccountEntrypointOptions = {
241
313
  txNonce: Fr.random(),
@@ -251,13 +323,16 @@ export class CLIWallet extends BaseWallet {
251
323
  );
252
324
  }
253
325
 
254
- return this.pxe.simulateTx(txRequest, {
326
+ const result = await this.pxe.simulateTx(txRequest, {
255
327
  simulatePublic: true,
256
328
  skipFeeEnforcement: true,
257
329
  skipTxValidation: true,
258
330
  overrides,
259
331
  scopes,
332
+ senderForTags: this.senderForTagsFrom(from, sendMessagesAs),
260
333
  });
334
+ const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
335
+ return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
261
336
  }
262
337
 
263
338
  // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because