@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,40 +1,46 @@
1
- import { EcdsaRAccountContract, EcdsaRSSHAccountContract } from '@aztec/accounts/ecdsa';
2
- import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
3
- import { StubAccountContractArtifact, createStubAccount } from '@aztec/accounts/stub';
1
+ import { EcdsaKAccountContract, EcdsaRAccountContract, EcdsaRSSHAccountContract } from '@aztec/accounts/ecdsa';
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
- import { type Account, type AccountContract, SignerlessAccount } from '@aztec/aztec.js/account';
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
- import { Fr } from '@aztec/foundation/fields';
16
+ import { DefaultEntrypoint } from '@aztec/entrypoints/default';
17
+ import { Fr } from '@aztec/foundation/curves/bn254';
18
+ import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
15
19
  import type { LogFn } from '@aztec/foundation/log';
20
+ import type { NotesFilter } from '@aztec/pxe/client/lazy';
16
21
  import type { PXEConfig } from '@aztec/pxe/config';
17
22
  import type { PXE } from '@aztec/pxe/server';
18
23
  import { createPXE, getPXEConfig } from '@aztec/pxe/server';
24
+ import { getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry';
19
25
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
20
- import { deriveSigningKey } from '@aztec/stdlib/keys';
26
+ import type { Gas, GasUsed } from '@aztec/stdlib/gas';
21
27
  import { NoteDao } from '@aztec/stdlib/note';
22
- import type { NotesFilter } from '@aztec/stdlib/note';
23
- import type { TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
28
+ import type { SimulationOverrides, TxExecutionRequest, TxProvingResult } from '@aztec/stdlib/tx';
24
29
  import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
25
- import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
30
+ import { BaseWallet, type SimulateViaEntrypointOptions, getGasLimits } from '@aztec/wallet-sdk/base-wallet';
26
31
 
27
32
  import type { WalletDB } from '../storage/wallet_db.js';
33
+ import type { AccountType } from './constants.js';
28
34
  import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
29
- import { printGasEstimates } from './options/fees.js';
30
35
 
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;
36
+ /** Padding the CLI wallet applies to simulated gas usage when deriving declared gas limits. */
37
+ const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
35
38
 
36
39
  export class CLIWallet extends BaseWallet {
37
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>();
38
44
 
39
45
  constructor(
40
46
  pxe: PXE,
@@ -54,12 +60,55 @@ export class CLIWallet extends BaseWallet {
54
60
  ): Promise<CLIWallet> {
55
61
  const pxeConfig = Object.assign(getPXEConfig(), overridePXEConfig);
56
62
  const pxe = await createPXE(node, pxeConfig);
57
- 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);
58
92
  }
59
93
 
60
94
  override async getAccounts(): Promise<Aliased<AztecAddress>[]> {
61
95
  const accounts = (await this.db?.listAliases('accounts')) ?? [];
62
- 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);
63
112
  }
64
113
 
65
114
  private async createCancellationTxExecutionRequest(
@@ -68,17 +117,24 @@ export class CLIWallet extends BaseWallet {
68
117
  increasedFee: InteractionFeeOptions,
69
118
  ) {
70
119
  const executionPayload = ExecutionPayload.empty();
71
- 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
+ });
72
125
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
73
126
  const fromAccount = await this.getAccountFromAddress(from);
127
+ const chainInfo = await this.getChainInfo();
74
128
  const executionOptions: DefaultAccountEntrypointOptions = {
75
129
  txNonce,
76
130
  cancellable: this.cancellableTransactions,
77
- feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
131
+ // If from is an address, feeOptions include the way the account contract should handle the fee payment
132
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
78
133
  };
79
134
  return await fromAccount.createTxExecutionRequest(
80
135
  feeExecutionPayload ?? executionPayload,
81
136
  feeOptions.gasSettings,
137
+ chainInfo,
82
138
  executionOptions,
83
139
  );
84
140
  }
@@ -89,18 +145,18 @@ 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);
148
+ return await this.pxe.proveTx(cancellationTxRequest, {
149
+ scopes: this.scopesFrom(from, [], undefined),
150
+ senderForTags: from,
151
+ });
93
152
  }
94
153
 
95
154
  override async getAccountFromAddress(address: AztecAddress) {
96
155
  let account: Account | undefined;
97
- if (address.equals(AztecAddress.ZERO)) {
98
- const chainInfo = await this.getChainInfo();
99
- account = new SignerlessAccount(chainInfo);
100
- } else if (this.accountCache.has(address.toString())) {
156
+ if (this.accountCache.has(address.toString())) {
101
157
  return this.accountCache.get(address.toString())!;
102
158
  } else {
103
- const accountManager = await this.createOrRetrieveAccount(address);
159
+ const accountManager = await this.retrieveAccount(address);
104
160
  account = await accountManager.getAccount();
105
161
  }
106
162
 
@@ -110,146 +166,195 @@ export class CLIWallet extends BaseWallet {
110
166
  return account;
111
167
  }
112
168
 
113
- private async createAccount(secret: Fr, salt: Fr, contract: AccountContract): Promise<AccountManager> {
114
- const accountManager = await AccountManager.create(this, secret, contract, salt);
115
-
116
- const instance = accountManager.getInstance();
117
- const artifact = await contract.getContractArtifact();
118
-
119
- await this.registerContract(instance, artifact, secret);
120
- this.accountCache.set(accountManager.address.toString(), await accountManager.getAccount());
121
- return accountManager;
122
- }
123
-
124
- async createOrRetrieveAccount(
125
- address?: AztecAddress,
126
- secretKey?: Fr,
127
- type: AccountType = 'schnorr',
128
- salt?: Fr,
169
+ /**
170
+ * Creates an account from freshly supplied keys. SSH accounts sign with a key held in the agent (resolved from
171
+ * `publicKey`), every other type is rooted on `signingKey`, with `secretKey` as its privacy secret.
172
+ */
173
+ async createAccount(
174
+ type: AccountType,
175
+ signingKey: GrumpkinScalar | undefined,
176
+ secretKey: Fr | undefined,
177
+ salt: Fr = Fr.ZERO,
129
178
  publicKey?: string,
130
179
  ): Promise<AccountManager> {
131
- let account;
132
-
133
- salt ??= Fr.ZERO;
180
+ const publicSigningKey =
181
+ type === 'ecdsasecp256r1ssh' ? await this.resolveSshPublicSigningKey(publicKey) : undefined;
182
+ return this.buildAccount(type, salt, signingKey, secretKey, publicSigningKey);
183
+ }
134
184
 
135
- if (this.db && address) {
136
- ({ type, secretKey, salt } = await this.db.retrieveAccount(address));
185
+ /**
186
+ * Retrieves a previously stored account by address, loading its keys, type and salt from the wallet database.
187
+ */
188
+ async retrieveAccount(address: AztecAddress): Promise<AccountManager> {
189
+ if (!this.db) {
190
+ throw new Error('Cannot retrieve an account without a wallet database');
137
191
  }
138
-
139
- if (!secretKey) {
140
- throw new Error('Cannot retrieve/create wallet without secret key');
192
+ const { type, signingKey, secretKey, salt } = await this.db.retrieveAccount(address);
193
+ if (type !== 'ecdsasecp256r1ssh' && !signingKey) {
194
+ throw new Error(
195
+ `Account ${address} has no stored signing key: it was created with an older version of aztec-wallet and is ` +
196
+ `incompatible with this one. Create a new account to continue.`,
197
+ );
141
198
  }
199
+ const publicSigningKey =
200
+ type === 'ecdsasecp256r1ssh' ? await this.db.retrieveAccountMetadata(address, 'publicSigningKey') : undefined;
201
+ return this.buildAccount(type, salt, signingKey, secretKey, publicSigningKey);
202
+ }
142
203
 
204
+ private async buildAccount(
205
+ type: AccountType,
206
+ salt: Fr,
207
+ signingKey: GrumpkinScalar | undefined,
208
+ secretKey: Fr | undefined,
209
+ publicSigningKey: Buffer | undefined,
210
+ ): Promise<AccountManager> {
143
211
  switch (type) {
144
- case 'schnorr': {
145
- account = await this.createAccount(secretKey, salt, new SchnorrAccountContract(deriveSigningKey(secretKey)));
146
- break;
147
- }
148
- case 'ecdsasecp256r1': {
149
- account = await this.createAccount(
150
- secretKey,
151
- salt,
152
- new EcdsaRAccountContract(deriveSigningKey(secretKey).toBuffer()),
153
- );
154
- break;
212
+ case 'schnorr':
213
+ case 'schnorr_initializerless':
214
+ case 'ecdsasecp256r1':
215
+ case 'ecdsasecp256k1': {
216
+ if (!signingKey || !secretKey) {
217
+ throw new Error('Cannot build account without signing key and secret key');
218
+ }
219
+ const contract =
220
+ type === 'schnorr'
221
+ ? new SchnorrAccountContract(signingKey)
222
+ : type === 'schnorr_initializerless'
223
+ ? new SchnorrInitializerlessAccountContract(signingKey)
224
+ : type === 'ecdsasecp256r1'
225
+ ? new EcdsaRAccountContract(signingKey.toBuffer())
226
+ : new EcdsaKAccountContract(signingKey.toBuffer());
227
+ return await this.materializeAccount(secretKey, salt, contract);
155
228
  }
156
229
  case 'ecdsasecp256r1ssh': {
157
- let publicSigningKey;
158
- if (this.db && address) {
159
- publicSigningKey = await this.db.retrieveAccountMetadata(address, 'publicSigningKey');
160
- } else if (publicKey) {
161
- const identities = await getIdentities();
162
- const foundIdentity = identities.find(
163
- identity => identity.type === 'ecdsa-sha2-nistp256' && identity.publicKey === publicKey,
164
- );
165
- if (!foundIdentity) {
166
- throw new Error(`Identity for public key ${publicKey} not found in the SSH agent`);
167
- }
168
- publicSigningKey = extractECDSAPublicKeyFromBase64String(foundIdentity.publicKey);
169
- } else {
170
- throw new Error('Public key must be provided for ECDSA SSH account');
230
+ if (!secretKey || !publicSigningKey) {
231
+ throw new Error('Cannot build SSH account without secret key and public signing key');
171
232
  }
172
- account = await this.createAccount(secretKey, salt, new EcdsaRSSHAccountContract(publicSigningKey));
173
- break;
233
+ return await this.materializeAccount(secretKey, salt, new EcdsaRSSHAccountContract(publicSigningKey));
174
234
  }
175
235
  default: {
176
236
  throw new Error(`Unsupported account type: ${type}`);
177
237
  }
178
238
  }
239
+ }
179
240
 
180
- return account;
241
+ private async resolveSshPublicSigningKey(publicKey: string | undefined): Promise<Buffer> {
242
+ if (!publicKey) {
243
+ throw new Error('Public key must be provided for ECDSA SSH account');
244
+ }
245
+ const identities = await getIdentities();
246
+ const foundIdentity = identities.find(
247
+ identity => identity.type === 'ecdsa-sha2-nistp256' && identity.publicKey === publicKey,
248
+ );
249
+ if (!foundIdentity) {
250
+ throw new Error(`Identity for public key ${publicKey} not found in the SSH agent`);
251
+ }
252
+ return extractECDSAPublicKeyFromBase64String(foundIdentity.publicKey);
181
253
  }
182
254
 
255
+ private async materializeAccount(secret: Fr, salt: Fr, contract: AccountContract): Promise<AccountManager> {
256
+ const accountManager = await AccountManager.create(this, secret, contract, { salt });
257
+
258
+ const instance = accountManager.getInstance();
259
+ const artifact = await contract.getContractArtifact();
260
+
261
+ await this.registerContract(instance, artifact, secret);
262
+ this.accountCache.set(accountManager.address.toString(), await accountManager.getAccount());
263
+
264
+ // Initializerless accounts have no deployment tx; their address commits to the signing public key
265
+ // (via the contract's immutablesHash, resolved by AccountManager.create) and the constructor's
266
+ // storage writes are materialized locally via a simulated "store" call here.
267
+ if (contract instanceof SchnorrInitializerlessAccountContract) {
268
+ const constructorAbi = artifact.functions.find(f => f.name === 'constructor');
269
+ if (!constructorAbi) {
270
+ throw new Error('Could not create SchnorrInitializerlessAccount: constructor ABI not found');
271
+ }
272
+ const { x, y } = await contract.getSigningPublicKey();
273
+ const storeCall = new ContractFunctionInteraction(this, instance.address, constructorAbi, [x, y]);
274
+ await storeCall.simulate({ from: instance.address });
275
+ }
276
+
277
+ return accountManager;
278
+ }
279
+
280
+ /**
281
+ * Creates a stub account that impersonates the given address, allowing kernelless simulations
282
+ * to bypass the account's authorization mechanisms via contract overrides.
283
+ * @param address - The address of the account to impersonate
284
+ * @returns The stub account, contract instance, and artifact for simulation
285
+ */
183
286
  private async getFakeAccountDataFor(address: AztecAddress) {
184
- const chainInfo = await this.getChainInfo();
185
287
  const originalAccount = await this.getAccountFromAddress(address);
186
288
  const originalAddress = originalAccount.getCompleteAddress();
187
- const { contractInstance } = await this.pxe.getContractMetadata(originalAddress.address);
289
+ const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
188
290
  if (!contractInstance) {
189
291
  throw new Error(`No contract instance found for address: ${originalAddress.address}`);
190
292
  }
191
- const stubAccount = createStubAccount(originalAddress, chainInfo);
192
- const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
193
- salt: Fr.random(),
194
- });
195
- return {
196
- account: stubAccount,
197
- instance,
198
- artifact: StubAccountContractArtifact,
199
- };
293
+ const { type } = await this.db!.retrieveAccount(address);
294
+ const stubAccount =
295
+ type === 'schnorr' || type === 'schnorr_initializerless'
296
+ ? createStubSchnorrAccount(originalAddress)
297
+ : createStubEcdsaAccount(originalAddress);
298
+ const stubClassId = this.stubClassIds.get(type);
299
+ if (!stubClassId) {
300
+ throw new Error(
301
+ `Stub class for account type '${type}' was not registered at wallet init. This is a bug — initStubClasses should cover every supported AccountType.`,
302
+ );
303
+ }
304
+ const instance = { ...contractInstance, currentContractClassId: stubClassId };
305
+ return { account: stubAccount, instance };
200
306
  }
201
307
 
202
- override async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
203
- let simulationResults;
204
- const feeOptions = opts.fee?.estimateGas
205
- ? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings)
206
- : await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
308
+ /**
309
+ * Uses a stub account for kernelless simulation, bypassing real account authorization.
310
+ * Uses DefaultEntrypoint directly for NO_FROM transactions.
311
+ */
312
+ protected override async simulateViaEntrypoint(
313
+ executionPayload: ExecutionPayload,
314
+ opts: SimulateViaEntrypointOptions,
315
+ ): Promise<TxSimulationResultWithAppOffset> {
316
+ const { from, feeOptions, additionalScopes, sendMessagesAs } = opts;
317
+ const scopes = this.scopesFrom(from, additionalScopes ?? [], sendMessagesAs);
207
318
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
208
- const executionOptions: DefaultAccountEntrypointOptions = {
209
- txNonce: Fr.random(),
210
- cancellable: this.cancellableTransactions,
211
- feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
212
- };
213
319
  const finalExecutionPayload = feeExecutionPayload
214
320
  ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
215
321
  : executionPayload;
322
+ const chainInfo = await this.getChainInfo();
216
323
 
217
- // Kernelless simulations using the multicall entrypoints are not currently supported,
218
- // since we only override proper account contracts.
219
- // TODO: allow disabling kernels even when no overrides are necessary
220
- if (opts.from.equals(AztecAddress.ZERO)) {
221
- const fromAccount = await this.getAccountFromAddress(opts.from);
222
- const txRequest = await fromAccount.createTxExecutionRequest(
223
- finalExecutionPayload,
224
- feeOptions.gasSettings,
225
- executionOptions,
226
- );
227
- simulationResults = await this.pxe.simulateTx(
228
- txRequest,
229
- true /* simulatePublic */,
230
- opts?.skipTxValidation,
231
- opts?.skipFeeEnforcement ?? true,
232
- );
324
+ let overrides: SimulationOverrides | undefined;
325
+ let txRequest: TxExecutionRequest;
326
+ if (from === NO_FROM) {
327
+ const entrypoint = new DefaultEntrypoint();
328
+ txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
233
329
  } else {
234
- const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(opts.from);
235
- const txRequest = await fromAccount.createTxExecutionRequest(
330
+ const { account, instance } = await this.getFakeAccountDataFor(from);
331
+ overrides = {
332
+ contracts: { [from.toString()]: { instance } },
333
+ };
334
+ const executionOptions: DefaultAccountEntrypointOptions = {
335
+ txNonce: Fr.random(),
336
+ cancellable: this.cancellableTransactions,
337
+ // If from is an address, feeOptions include the way the account contract should handle the fee payment
338
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
339
+ };
340
+ txRequest = await account.createTxExecutionRequest(
236
341
  finalExecutionPayload,
237
342
  feeOptions.gasSettings,
343
+ chainInfo,
238
344
  executionOptions,
239
345
  );
240
- const contractOverrides = {
241
- [opts.from.toString()]: { instance, artifact },
242
- };
243
- simulationResults = await this.pxe.simulateTx(txRequest, true /* simulatePublic */, true, true, {
244
- contracts: contractOverrides,
245
- });
246
346
  }
247
347
 
248
- if (opts.fee?.estimateGas) {
249
- const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
250
- printGasEstimates(feeOptions, limits, this.userLog);
251
- }
252
- return simulationResults;
348
+ const result = await this.pxe.simulateTx(txRequest, {
349
+ simulatePublic: true,
350
+ skipFeeEnforcement: true,
351
+ skipTxValidation: true,
352
+ overrides,
353
+ scopes,
354
+ senderForTags: this.senderForTagsFrom(from, sendMessagesAs),
355
+ });
356
+ const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
357
+ return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
253
358
  }
254
359
 
255
360
  // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
@@ -261,6 +366,12 @@ export class CLIWallet extends BaseWallet {
261
366
  // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
262
367
  // this is just a CLI wallet.
263
368
  getNotes(filter: NotesFilter): Promise<NoteDao[]> {
264
- return this.pxe.getNotes(filter);
369
+ return this.pxe.debug.getNotes(filter);
370
+ }
371
+
372
+ // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
373
+ // this is just a CLI wallet.
374
+ getContractArtifact(id: Fr) {
375
+ return this.pxe.getContractArtifact(id);
265
376
  }
266
377
  }