@aztec/cli-wallet 5.0.0-private.20260319 → 5.0.0-rc.1
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.
- package/dest/bin/index.js +1 -1
- package/dest/cmds/check_tx.js +7 -7
- package/dest/cmds/create_account.d.ts +4 -3
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +30 -28
- package/dest/cmds/deploy.d.ts +5 -4
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +43 -40
- package/dest/cmds/deploy_account.d.ts +4 -3
- package/dest/cmds/deploy_account.d.ts.map +1 -1
- package/dest/cmds/deploy_account.js +22 -22
- package/dest/cmds/get_fee_juice_balance.d.ts +5 -0
- package/dest/cmds/get_fee_juice_balance.d.ts.map +1 -0
- package/dest/cmds/get_fee_juice_balance.js +27 -0
- package/dest/cmds/import_test_accounts.d.ts +1 -1
- package/dest/cmds/import_test_accounts.d.ts.map +1 -1
- package/dest/cmds/import_test_accounts.js +1 -1
- package/dest/cmds/index.d.ts +1 -1
- package/dest/cmds/index.d.ts.map +1 -1
- package/dest/cmds/index.js +31 -15
- package/dest/cmds/send.d.ts +4 -3
- package/dest/cmds/send.d.ts.map +1 -1
- package/dest/cmds/send.js +26 -28
- package/dest/storage/wallet_db.d.ts +7 -2
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +14 -0
- package/dest/utils/constants.d.ts +2 -2
- package/dest/utils/constants.d.ts.map +1 -1
- package/dest/utils/constants.js +1 -0
- package/dest/utils/options/fees.d.ts +3 -2
- package/dest/utils/options/fees.d.ts.map +1 -1
- package/dest/utils/options/fees.js +33 -9
- package/dest/utils/wallet.d.ts +19 -6
- package/dest/utils/wallet.d.ts.map +1 -1
- package/dest/utils/wallet.js +130 -63
- package/package.json +16 -15
- package/src/bin/index.ts +1 -1
- package/src/cmds/check_tx.ts +6 -5
- package/src/cmds/create_account.ts +31 -20
- package/src/cmds/deploy.ts +40 -35
- package/src/cmds/deploy_account.ts +22 -14
- package/src/cmds/get_fee_juice_balance.ts +37 -0
- package/src/cmds/import_test_accounts.ts +5 -1
- package/src/cmds/index.ts +59 -5
- package/src/cmds/send.ts +23 -18
- package/src/storage/wallet_db.ts +14 -0
- package/src/utils/constants.ts +7 -1
- package/src/utils/options/fees.ts +35 -9
- package/src/utils/wallet.ts +141 -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) => {
|
|
@@ -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.
|
|
161
|
+
? Fr.fromString(claimAmount)
|
|
161
162
|
: new Fr(claimAmount)
|
|
162
163
|
).toBigInt(),
|
|
163
|
-
claimSecret: Fr.
|
|
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
|
|
260
|
-
const
|
|
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
|
-
|
|
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.
|
|
323
|
+
return GasSettings.fallback({ ...estimate, maxFeesPerGas })
|
|
298
324
|
.getFeeLimit()
|
|
299
325
|
.toBigInt();
|
|
300
326
|
}
|
package/src/utils/wallet.ts
CHANGED
|
@@ -1,36 +1,46 @@
|
|
|
1
1
|
import { EcdsaRAccountContract, EcdsaRSSHAccountContract } from '@aztec/accounts/ecdsa';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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,
|
|
6
|
+
import { type Account, type AccountContract, NO_FROM } from '@aztec/aztec.js/account';
|
|
6
7
|
import {
|
|
8
|
+
ContractFunctionInteraction,
|
|
7
9
|
type InteractionFeeOptions,
|
|
8
|
-
|
|
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
|
|
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,
|
|
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
|
-
|
|
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,54 @@ 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
|
-
|
|
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.registerContract({ instance, artifact });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Hashes and registers the stub class for every supported account type with PXE, populating
|
|
76
|
+
* stubClassIds. Called on wallet initialization.
|
|
77
|
+
*/
|
|
78
|
+
private async initStubClasses(): Promise<void> {
|
|
79
|
+
const { id: schnorrClassId } = await getContractClassFromArtifact(StubSchnorrAccountContractArtifact);
|
|
80
|
+
await this.pxe.registerContractClass(StubSchnorrAccountContractArtifact);
|
|
81
|
+
|
|
82
|
+
// ecdsa stubs share the same class id
|
|
83
|
+
const { id: ecdsaClassId } = await getContractClassFromArtifact(StubEcdsaAccountContractArtifact);
|
|
84
|
+
await this.pxe.registerContractClass(StubEcdsaAccountContractArtifact);
|
|
85
|
+
|
|
86
|
+
this.stubClassIds.set('schnorr', schnorrClassId);
|
|
87
|
+
this.stubClassIds.set('schnorr_initializerless', schnorrClassId);
|
|
88
|
+
this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
|
|
89
|
+
this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
|
|
90
|
+
this.stubClassIds.set('ecdsasecp256r1ssh', ecdsaClassId);
|
|
54
91
|
}
|
|
55
92
|
|
|
56
93
|
override async getAccounts(): Promise<Aliased<AztecAddress>[]> {
|
|
57
94
|
const accounts = (await this.db?.listAliases('accounts')) ?? [];
|
|
58
|
-
return Promise.resolve(
|
|
95
|
+
return Promise.resolve(
|
|
96
|
+
accounts.map(({ key, value }) => {
|
|
97
|
+
const alias = key.includes(':') ? key.slice(key.indexOf(':') + 1) : key;
|
|
98
|
+
return { alias, item: AztecAddress.fromString(value) };
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Derives suggested total and teardown gas limits from simulated gas usage, padded and clamped to the
|
|
105
|
+
* network's per-tx admission limits.
|
|
106
|
+
* @param gasUsed - The gas consumed during simulation (from a `simulate({ includeMetadata: true })` result).
|
|
107
|
+
*/
|
|
108
|
+
async estimateGasLimits(gasUsed: GasUsed): Promise<{ gasLimits: Gas; teardownGasLimits: Gas }> {
|
|
109
|
+
const maxTxGasLimits = await this.getMaxTxGasLimits();
|
|
110
|
+
return getGasLimits(gasUsed, maxTxGasLimits, DEFAULT_ESTIMATED_GAS_PADDING);
|
|
59
111
|
}
|
|
60
112
|
|
|
61
113
|
private async createCancellationTxExecutionRequest(
|
|
@@ -64,14 +116,19 @@ export class CLIWallet extends BaseWallet {
|
|
|
64
116
|
increasedFee: InteractionFeeOptions,
|
|
65
117
|
) {
|
|
66
118
|
const executionPayload = ExecutionPayload.empty();
|
|
67
|
-
const feeOptions = await this.completeFeeOptions(
|
|
119
|
+
const feeOptions = await this.completeFeeOptions({
|
|
120
|
+
from,
|
|
121
|
+
feePayer: executionPayload.feePayer,
|
|
122
|
+
gasSettings: increasedFee.gasSettings,
|
|
123
|
+
});
|
|
68
124
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
69
125
|
const fromAccount = await this.getAccountFromAddress(from);
|
|
70
126
|
const chainInfo = await this.getChainInfo();
|
|
71
127
|
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
72
128
|
txNonce,
|
|
73
129
|
cancellable: this.cancellableTransactions,
|
|
74
|
-
|
|
130
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
131
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
75
132
|
};
|
|
76
133
|
return await fromAccount.createTxExecutionRequest(
|
|
77
134
|
feeExecutionPayload ?? executionPayload,
|
|
@@ -87,14 +144,12 @@ export class CLIWallet extends BaseWallet {
|
|
|
87
144
|
increasedFee: InteractionFeeOptions,
|
|
88
145
|
): Promise<TxProvingResult> {
|
|
89
146
|
const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
|
|
90
|
-
return await this.pxe.proveTx(cancellationTxRequest, this.scopesFrom(from));
|
|
147
|
+
return await this.pxe.proveTx(cancellationTxRequest, { scopes: this.scopesFrom(from), senderForTags: from });
|
|
91
148
|
}
|
|
92
149
|
|
|
93
150
|
override async getAccountFromAddress(address: AztecAddress) {
|
|
94
151
|
let account: Account | undefined;
|
|
95
|
-
if (address.
|
|
96
|
-
account = new SignerlessAccount();
|
|
97
|
-
} else if (this.accountCache.has(address.toString())) {
|
|
152
|
+
if (this.accountCache.has(address.toString())) {
|
|
98
153
|
return this.accountCache.get(address.toString())!;
|
|
99
154
|
} else {
|
|
100
155
|
const accountManager = await this.createOrRetrieveAccount(address);
|
|
@@ -108,13 +163,27 @@ export class CLIWallet extends BaseWallet {
|
|
|
108
163
|
}
|
|
109
164
|
|
|
110
165
|
private async createAccount(secret: Fr, salt: Fr, contract: AccountContract): Promise<AccountManager> {
|
|
111
|
-
const accountManager = await AccountManager.create(this, secret, contract, salt);
|
|
166
|
+
const accountManager = await AccountManager.create(this, secret, contract, { salt });
|
|
112
167
|
|
|
113
168
|
const instance = accountManager.getInstance();
|
|
114
169
|
const artifact = await contract.getContractArtifact();
|
|
115
170
|
|
|
116
171
|
await this.registerContract(instance, artifact, secret);
|
|
117
172
|
this.accountCache.set(accountManager.address.toString(), await accountManager.getAccount());
|
|
173
|
+
|
|
174
|
+
// Initializerless accounts have no deployment tx; their address commits to the signing public key
|
|
175
|
+
// (via the contract's immutablesHash, resolved by AccountManager.create) and the constructor's
|
|
176
|
+
// storage writes are materialized locally via a simulated "store" call here.
|
|
177
|
+
if (contract instanceof SchnorrInitializerlessAccountContract) {
|
|
178
|
+
const constructorAbi = artifact.functions.find(f => f.name === 'constructor');
|
|
179
|
+
if (!constructorAbi) {
|
|
180
|
+
throw new Error('Could not create SchnorrInitializerlessAccount: constructor ABI not found');
|
|
181
|
+
}
|
|
182
|
+
const { x, y } = await contract.getSigningPublicKey();
|
|
183
|
+
const storeCall = new ContractFunctionInteraction(this, instance.address, constructorAbi, [x, y]);
|
|
184
|
+
await storeCall.simulate({ from: instance.address });
|
|
185
|
+
}
|
|
186
|
+
|
|
118
187
|
return accountManager;
|
|
119
188
|
}
|
|
120
189
|
|
|
@@ -142,6 +211,14 @@ export class CLIWallet extends BaseWallet {
|
|
|
142
211
|
account = await this.createAccount(secretKey, salt, new SchnorrAccountContract(deriveSigningKey(secretKey)));
|
|
143
212
|
break;
|
|
144
213
|
}
|
|
214
|
+
case 'schnorr_initializerless': {
|
|
215
|
+
account = await this.createAccount(
|
|
216
|
+
secretKey,
|
|
217
|
+
salt,
|
|
218
|
+
new SchnorrInitializerlessAccountContract(deriveSigningKey(secretKey)),
|
|
219
|
+
);
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
145
222
|
case 'ecdsasecp256r1': {
|
|
146
223
|
account = await this.createAccount(
|
|
147
224
|
secretKey,
|
|
@@ -185,84 +262,76 @@ export class CLIWallet extends BaseWallet {
|
|
|
185
262
|
*/
|
|
186
263
|
private async getFakeAccountDataFor(address: AztecAddress) {
|
|
187
264
|
const originalAccount = await this.getAccountFromAddress(address);
|
|
188
|
-
|
|
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();
|
|
265
|
+
const originalAddress = originalAccount.getCompleteAddress();
|
|
195
266
|
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
196
267
|
if (!contractInstance) {
|
|
197
268
|
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
198
269
|
}
|
|
199
|
-
const
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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);
|
|
270
|
+
const { type } = await this.db!.retrieveAccount(address);
|
|
271
|
+
const stubAccount =
|
|
272
|
+
type === 'schnorr' || type === 'schnorr_initializerless'
|
|
273
|
+
? createStubSchnorrAccount(originalAddress)
|
|
274
|
+
: createStubEcdsaAccount(originalAddress);
|
|
275
|
+
const stubClassId = this.stubClassIds.get(type);
|
|
276
|
+
if (!stubClassId) {
|
|
277
|
+
throw new Error(
|
|
278
|
+
`Stub class for account type '${type}' was not registered at wallet init. This is a bug — initStubClasses should cover every supported AccountType.`,
|
|
279
|
+
);
|
|
217
280
|
}
|
|
218
|
-
|
|
281
|
+
const instance = { ...contractInstance, currentContractClassId: stubClassId };
|
|
282
|
+
return { account: stubAccount, instance };
|
|
219
283
|
}
|
|
220
284
|
|
|
221
285
|
/**
|
|
222
286
|
* Uses a stub account for kernelless simulation, bypassing real account authorization.
|
|
223
|
-
*
|
|
287
|
+
* Uses DefaultEntrypoint directly for NO_FROM transactions.
|
|
224
288
|
*/
|
|
225
289
|
protected override async simulateViaEntrypoint(
|
|
226
290
|
executionPayload: ExecutionPayload,
|
|
227
291
|
opts: SimulateViaEntrypointOptions,
|
|
228
|
-
): Promise<
|
|
229
|
-
const { from, feeOptions,
|
|
230
|
-
|
|
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
|
-
|
|
292
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
293
|
+
const { from, feeOptions, additionalScopes, sendMessagesAs } = opts;
|
|
294
|
+
const scopes = this.scopesFrom(from, additionalScopes);
|
|
242
295
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
243
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
244
|
-
txNonce: Fr.random(),
|
|
245
|
-
cancellable: this.cancellableTransactions,
|
|
246
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
247
|
-
};
|
|
248
296
|
const finalExecutionPayload = feeExecutionPayload
|
|
249
297
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
250
298
|
: executionPayload;
|
|
251
|
-
|
|
252
299
|
const chainInfo = await this.getChainInfo();
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
300
|
+
|
|
301
|
+
let overrides: SimulationOverrides | undefined;
|
|
302
|
+
let txRequest: TxExecutionRequest;
|
|
303
|
+
if (from === NO_FROM) {
|
|
304
|
+
const entrypoint = new DefaultEntrypoint();
|
|
305
|
+
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
306
|
+
} else {
|
|
307
|
+
const { account, instance } = await this.getFakeAccountDataFor(from);
|
|
308
|
+
overrides = {
|
|
309
|
+
contracts: { [from.toString()]: { instance } },
|
|
310
|
+
};
|
|
311
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
312
|
+
txNonce: Fr.random(),
|
|
313
|
+
cancellable: this.cancellableTransactions,
|
|
314
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
315
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
316
|
+
};
|
|
317
|
+
txRequest = await account.createTxExecutionRequest(
|
|
318
|
+
finalExecutionPayload,
|
|
319
|
+
feeOptions.gasSettings,
|
|
320
|
+
chainInfo,
|
|
321
|
+
executionOptions,
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
260
326
|
simulatePublic: true,
|
|
261
327
|
skipFeeEnforcement: true,
|
|
262
328
|
skipTxValidation: true,
|
|
263
329
|
overrides,
|
|
264
330
|
scopes,
|
|
331
|
+
senderForTags: this.senderForTagsFrom(from, sendMessagesAs),
|
|
265
332
|
});
|
|
333
|
+
const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
|
|
334
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
266
335
|
}
|
|
267
336
|
|
|
268
337
|
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|