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

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 (53) 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 +4 -3
  4. package/dest/cmds/create_account.d.ts.map +1 -1
  5. package/dest/cmds/create_account.js +30 -28
  6. package/dest/cmds/deploy.d.ts +5 -4
  7. package/dest/cmds/deploy.d.ts.map +1 -1
  8. package/dest/cmds/deploy.js +43 -40
  9. package/dest/cmds/deploy_account.d.ts +4 -3
  10. package/dest/cmds/deploy_account.d.ts.map +1 -1
  11. package/dest/cmds/deploy_account.js +22 -22
  12. package/dest/cmds/get_fee_juice_balance.d.ts +5 -0
  13. package/dest/cmds/get_fee_juice_balance.d.ts.map +1 -0
  14. package/dest/cmds/get_fee_juice_balance.js +27 -0
  15. package/dest/cmds/import_test_accounts.d.ts +1 -1
  16. package/dest/cmds/import_test_accounts.d.ts.map +1 -1
  17. package/dest/cmds/import_test_accounts.js +1 -1
  18. package/dest/cmds/index.d.ts +1 -1
  19. package/dest/cmds/index.d.ts.map +1 -1
  20. package/dest/cmds/index.js +31 -15
  21. package/dest/cmds/send.d.ts +4 -3
  22. package/dest/cmds/send.d.ts.map +1 -1
  23. package/dest/cmds/send.js +26 -28
  24. package/dest/cmds/simulate.d.ts +1 -1
  25. package/dest/cmds/simulate.d.ts.map +1 -1
  26. package/dest/cmds/simulate.js +2 -1
  27. package/dest/storage/wallet_db.d.ts +7 -2
  28. package/dest/storage/wallet_db.d.ts.map +1 -1
  29. package/dest/storage/wallet_db.js +14 -0
  30. package/dest/utils/constants.d.ts +2 -2
  31. package/dest/utils/constants.d.ts.map +1 -1
  32. package/dest/utils/constants.js +1 -0
  33. package/dest/utils/options/fees.d.ts +3 -2
  34. package/dest/utils/options/fees.d.ts.map +1 -1
  35. package/dest/utils/options/fees.js +34 -10
  36. package/dest/utils/wallet.d.ts +19 -6
  37. package/dest/utils/wallet.d.ts.map +1 -1
  38. package/dest/utils/wallet.js +128 -63
  39. package/package.json +16 -15
  40. package/src/bin/index.ts +1 -1
  41. package/src/cmds/check_tx.ts +17 -15
  42. package/src/cmds/create_account.ts +31 -20
  43. package/src/cmds/deploy.ts +40 -35
  44. package/src/cmds/deploy_account.ts +22 -14
  45. package/src/cmds/get_fee_juice_balance.ts +37 -0
  46. package/src/cmds/import_test_accounts.ts +5 -1
  47. package/src/cmds/index.ts +59 -5
  48. package/src/cmds/send.ts +23 -18
  49. package/src/cmds/simulate.ts +2 -1
  50. package/src/storage/wallet_db.ts +14 -0
  51. package/src/utils/constants.ts +7 -1
  52. package/src/utils/options/fees.ts +36 -10
  53. package/src/utils/wallet.ts +142 -72
@@ -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,36 +1,46 @@
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
- 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';
16
+ import { DefaultEntrypoint } from '@aztec/entrypoints/default';
14
17
  import { Fr } from '@aztec/foundation/curves/bn254';
15
18
  import type { LogFn } from '@aztec/foundation/log';
16
19
  import type { NotesFilter } from '@aztec/pxe/client/lazy';
17
20
  import type { PXEConfig } from '@aztec/pxe/config';
18
21
  import type { PXE } from '@aztec/pxe/server';
19
22
  import { createPXE, getPXEConfig } from '@aztec/pxe/server';
23
+ import { getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry';
20
24
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
25
+ import type { Gas, GasUsed } from '@aztec/stdlib/gas';
21
26
  import { deriveSigningKey } from '@aztec/stdlib/keys';
22
27
  import { NoteDao } from '@aztec/stdlib/note';
23
- import type { SimulationOverrides, 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, type SimulateViaEntrypointOptions } 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';
28
33
  import type { AccountType } from './constants.js';
29
34
  import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
30
- 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;
31
38
 
32
39
  export class CLIWallet extends BaseWallet {
33
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>();
34
44
 
35
45
  constructor(
36
46
  pxe: PXE,
@@ -50,12 +60,55 @@ export class CLIWallet extends BaseWallet {
50
60
  ): Promise<CLIWallet> {
51
61
  const pxeConfig = Object.assign(getPXEConfig(), overridePXEConfig);
52
62
  const pxe = await createPXE(node, pxeConfig);
53
- 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);
54
92
  }
55
93
 
56
94
  override async getAccounts(): Promise<Aliased<AztecAddress>[]> {
57
95
  const accounts = (await this.db?.listAliases('accounts')) ?? [];
58
- 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);
59
112
  }
60
113
 
61
114
  private async createCancellationTxExecutionRequest(
@@ -64,14 +117,19 @@ export class CLIWallet extends BaseWallet {
64
117
  increasedFee: InteractionFeeOptions,
65
118
  ) {
66
119
  const executionPayload = ExecutionPayload.empty();
67
- 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
+ });
68
125
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
69
126
  const fromAccount = await this.getAccountFromAddress(from);
70
127
  const chainInfo = await this.getChainInfo();
71
128
  const executionOptions: DefaultAccountEntrypointOptions = {
72
129
  txNonce,
73
130
  cancellable: this.cancellableTransactions,
74
- 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!,
75
133
  };
76
134
  return await fromAccount.createTxExecutionRequest(
77
135
  feeExecutionPayload ?? executionPayload,
@@ -87,14 +145,12 @@ export class CLIWallet extends BaseWallet {
87
145
  increasedFee: InteractionFeeOptions,
88
146
  ): Promise<TxProvingResult> {
89
147
  const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
90
- return await this.pxe.proveTx(cancellationTxRequest, this.scopesFrom(from));
148
+ return await this.pxe.proveTx(cancellationTxRequest, { scopes: this.scopesFrom(from), senderForTags: from });
91
149
  }
92
150
 
93
151
  override async getAccountFromAddress(address: AztecAddress) {
94
152
  let account: Account | undefined;
95
- if (address.equals(AztecAddress.ZERO)) {
96
- account = new SignerlessAccount();
97
- } else if (this.accountCache.has(address.toString())) {
153
+ if (this.accountCache.has(address.toString())) {
98
154
  return this.accountCache.get(address.toString())!;
99
155
  } else {
100
156
  const accountManager = await this.createOrRetrieveAccount(address);
@@ -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,
@@ -185,84 +263,76 @@ export class CLIWallet extends BaseWallet {
185
263
  */
186
264
  private async getFakeAccountDataFor(address: AztecAddress) {
187
265
  const originalAccount = await this.getAccountFromAddress(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();
266
+ const originalAddress = originalAccount.getCompleteAddress();
195
267
  const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
196
268
  if (!contractInstance) {
197
269
  throw new Error(`No contract instance found for address: ${originalAddress.address}`);
198
270
  }
199
- const stubAccount = createStubAccount(originalAddress);
200
- const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
201
- salt: Fr.random(),
202
- });
203
- return {
204
- account: stubAccount,
205
- instance,
206
- artifact: StubAccountContractArtifact,
207
- };
208
- }
209
-
210
- override async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
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);
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
+ );
217
281
  }
218
- return simulationResults;
282
+ const instance = { ...contractInstance, currentContractClassId: stubClassId };
283
+ return { account: stubAccount, instance };
219
284
  }
220
285
 
221
286
  /**
222
287
  * Uses a stub account for kernelless simulation, bypassing real account authorization.
223
- * Falls through to the standard entrypoint path for SignerlessAccount (ZERO address).
288
+ * Uses DefaultEntrypoint directly for NO_FROM transactions.
224
289
  */
225
290
  protected override async simulateViaEntrypoint(
226
291
  executionPayload: ExecutionPayload,
227
292
  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
-
293
+ ): Promise<TxSimulationResultWithAppOffset> {
294
+ const { from, feeOptions, additionalScopes, sendMessagesAs } = opts;
295
+ const scopes = this.scopesFrom(from, additionalScopes);
242
296
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
243
- const executionOptions: DefaultAccountEntrypointOptions = {
244
- txNonce: Fr.random(),
245
- cancellable: this.cancellableTransactions,
246
- feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
247
- };
248
297
  const finalExecutionPayload = feeExecutionPayload
249
298
  ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
250
299
  : executionPayload;
251
-
252
300
  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, {
301
+
302
+ let overrides: SimulationOverrides | undefined;
303
+ let txRequest: TxExecutionRequest;
304
+ if (from === NO_FROM) {
305
+ const entrypoint = new DefaultEntrypoint();
306
+ txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
307
+ } else {
308
+ const { account, instance } = await this.getFakeAccountDataFor(from);
309
+ overrides = {
310
+ contracts: { [from.toString()]: { instance } },
311
+ };
312
+ const executionOptions: DefaultAccountEntrypointOptions = {
313
+ txNonce: Fr.random(),
314
+ cancellable: this.cancellableTransactions,
315
+ // If from is an address, feeOptions include the way the account contract should handle the fee payment
316
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
317
+ };
318
+ txRequest = await account.createTxExecutionRequest(
319
+ finalExecutionPayload,
320
+ feeOptions.gasSettings,
321
+ chainInfo,
322
+ executionOptions,
323
+ );
324
+ }
325
+
326
+ const result = await this.pxe.simulateTx(txRequest, {
260
327
  simulatePublic: true,
261
328
  skipFeeEnforcement: true,
262
329
  skipTxValidation: true,
263
330
  overrides,
264
331
  scopes,
332
+ senderForTags: this.senderForTagsFrom(from, sendMessagesAs),
265
333
  });
334
+ const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
335
+ return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
266
336
  }
267
337
 
268
338
  // Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because