@aztec/cli-wallet 0.0.1-commit.f295ac2 → 0.0.1-commit.f504929
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/cmds/authorize_action.d.ts +2 -2
- package/dest/cmds/authorize_action.d.ts.map +1 -1
- package/dest/cmds/authorize_action.js +4 -2
- package/dest/cmds/check_tx.js +6 -2
- package/dest/cmds/create_account.d.ts +1 -1
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +31 -17
- package/dest/cmds/deploy.d.ts +1 -1
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +50 -24
- package/dest/cmds/deploy_account.d.ts +1 -1
- package/dest/cmds/deploy_account.d.ts.map +1 -1
- package/dest/cmds/deploy_account.js +31 -17
- package/dest/cmds/index.js +1 -1
- package/dest/cmds/send.d.ts +1 -1
- package/dest/cmds/send.d.ts.map +1 -1
- package/dest/cmds/send.js +32 -17
- package/dest/storage/wallet_db.d.ts +1 -1
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +46 -31
- package/dest/utils/wallet.d.ts +8 -3
- package/dest/utils/wallet.d.ts.map +1 -1
- package/dest/utils/wallet.js +48 -33
- package/package.json +14 -14
- package/src/cmds/authorize_action.ts +1 -1
- package/src/cmds/check_tx.ts +5 -2
- package/src/cmds/create_account.ts +29 -18
- package/src/cmds/deploy.ts +45 -23
- package/src/cmds/deploy_account.ts +29 -18
- package/src/cmds/index.ts +1 -1
- package/src/cmds/send.ts +26 -11
- package/src/cmds/simulate.ts +1 -1
- package/src/storage/wallet_db.ts +49 -36
- package/src/utils/wallet.ts +70 -48
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { NO_WAIT } from '@aztec/aztec.js/contracts';
|
|
2
3
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
3
4
|
import type { DeployAccountOptions } from '@aztec/aztec.js/wallet';
|
|
4
5
|
import { prettyPrintJSON } from '@aztec/cli/cli-utils';
|
|
5
6
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
7
|
+
import type { TxHash, TxReceipt } from '@aztec/stdlib/tx';
|
|
6
8
|
|
|
7
9
|
import { DEFAULT_TX_TIMEOUT_S } from '../utils/cli_wallet_and_node_wrapper.js';
|
|
8
10
|
import type { CLIFeeArgs } from '../utils/options/fees.js';
|
|
@@ -45,8 +47,8 @@ export async function deployAccount(
|
|
|
45
47
|
log(`Init hash: ${initializationHash.toString()}`);
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
let
|
|
49
|
-
let txReceipt;
|
|
50
|
+
let txHash: TxHash | undefined;
|
|
51
|
+
let txReceipt: TxReceipt | undefined;
|
|
50
52
|
const { paymentMethod, gasSettings } = await feeOpts.toUserFeeOptions(aztecNode, wallet, address);
|
|
51
53
|
|
|
52
54
|
const delegatedDeployment = deployer && !account.address.equals(deployer);
|
|
@@ -61,10 +63,13 @@ export async function deployAccount(
|
|
|
61
63
|
};
|
|
62
64
|
|
|
63
65
|
const deployMethod = await account.getDeployMethod();
|
|
64
|
-
const
|
|
66
|
+
const sim = await deployMethod.simulate({
|
|
65
67
|
...deployAccountOpts,
|
|
66
68
|
fee: { ...deployAccountOpts.fee, estimateGas: true },
|
|
67
69
|
});
|
|
70
|
+
// estimateGas: true guarantees these fields are present
|
|
71
|
+
const estimatedGas = sim.estimatedGas!;
|
|
72
|
+
const stats = sim.stats!;
|
|
68
73
|
|
|
69
74
|
if (feeOpts.estimateOnly) {
|
|
70
75
|
if (json) {
|
|
@@ -80,7 +85,14 @@ export async function deployAccount(
|
|
|
80
85
|
};
|
|
81
86
|
}
|
|
82
87
|
} else {
|
|
83
|
-
|
|
88
|
+
if (verbose) {
|
|
89
|
+
printProfileResult(stats, log);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!json) {
|
|
93
|
+
log(`\nWaiting for account contract deployment...`);
|
|
94
|
+
}
|
|
95
|
+
const sendOpts = {
|
|
84
96
|
...deployAccountOpts,
|
|
85
97
|
fee: deployAccountOpts.fee
|
|
86
98
|
? {
|
|
@@ -88,31 +100,30 @@ export async function deployAccount(
|
|
|
88
100
|
gasSettings: estimatedGas,
|
|
89
101
|
}
|
|
90
102
|
: undefined,
|
|
91
|
-
}
|
|
92
|
-
if (verbose) {
|
|
93
|
-
printProfileResult(stats, log);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const txHash = await tx.getTxHash();
|
|
97
|
-
debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
|
|
98
|
-
out.txHash = txHash;
|
|
103
|
+
};
|
|
99
104
|
if (wait) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
const { receipt } = await deployMethod.send({
|
|
106
|
+
...sendOpts,
|
|
107
|
+
wait: { timeout: DEFAULT_TX_TIMEOUT_S, returnReceipt: true },
|
|
108
|
+
});
|
|
109
|
+
txReceipt = receipt;
|
|
110
|
+
txHash = receipt.txHash;
|
|
104
111
|
out.txReceipt = {
|
|
105
112
|
status: txReceipt.status,
|
|
106
113
|
transactionFee: txReceipt.transactionFee,
|
|
107
114
|
};
|
|
115
|
+
} else {
|
|
116
|
+
({ txHash } = await deployMethod.send({ ...sendOpts, wait: NO_WAIT }));
|
|
108
117
|
}
|
|
118
|
+
debugLogger.debug(`Account contract tx sent with hash ${txHash.toString()}`);
|
|
119
|
+
out.txHash = txHash;
|
|
109
120
|
}
|
|
110
121
|
|
|
111
122
|
if (json) {
|
|
112
123
|
log(prettyPrintJSON(out));
|
|
113
124
|
} else {
|
|
114
|
-
if (
|
|
115
|
-
log(`Deploy tx hash: ${
|
|
125
|
+
if (txHash) {
|
|
126
|
+
log(`Deploy tx hash: ${txHash.toString()}`);
|
|
116
127
|
}
|
|
117
128
|
if (txReceipt) {
|
|
118
129
|
log(`Deploy tx fee: ${txReceipt.transactionFee}`);
|
package/src/cmds/index.ts
CHANGED
|
@@ -63,7 +63,7 @@ export function injectCommands(
|
|
|
63
63
|
const createAccountCommand = program
|
|
64
64
|
.command('create-account')
|
|
65
65
|
.description(
|
|
66
|
-
'Creates an aztec account that can be used for sending transactions. Registers the account on the PXE and deploys an account contract. Uses a Schnorr
|
|
66
|
+
'Creates an aztec account that can be used for sending transactions. Registers the account on the PXE and deploys an account contract. Uses a Schnorr account which uses an immutable key for authentication.',
|
|
67
67
|
)
|
|
68
68
|
.summary('Creates an aztec account that can be used for sending transactions.')
|
|
69
69
|
.addOption(createAccountOption('Alias or address of the account performing the deployment', !db, db))
|
package/src/cmds/send.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
2
|
import { AuthWitness } from '@aztec/aztec.js/authorization';
|
|
3
|
-
import { Contract, type SendInteractionOptions } from '@aztec/aztec.js/contracts';
|
|
3
|
+
import { Contract, NO_WAIT, type SendInteractionOptions } from '@aztec/aztec.js/contracts';
|
|
4
4
|
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
5
5
|
import { prepTx } from '@aztec/cli/utils';
|
|
6
6
|
import type { LogFn } from '@aztec/foundation/log';
|
|
@@ -37,40 +37,55 @@ export async function send(
|
|
|
37
37
|
authWitnesses,
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
const
|
|
40
|
+
const sim = await call.simulate({
|
|
41
41
|
...sendOptions,
|
|
42
42
|
fee: { ...sendOptions.fee, estimateGas: true },
|
|
43
43
|
});
|
|
44
|
+
// estimateGas: true guarantees these fields are present
|
|
45
|
+
const estimatedGas = sim.estimatedGas!;
|
|
46
|
+
const stats = sim.stats!;
|
|
44
47
|
|
|
45
48
|
if (feeOpts.estimateOnly) {
|
|
46
49
|
return;
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
const tx = call.send({ ...sendOptions, fee: { ...sendOptions.fee, gasSettings: estimatedGas } });
|
|
50
52
|
if (verbose) {
|
|
51
53
|
printProfileResult(stats!, log);
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
const txHash = await tx.getTxHash();
|
|
55
|
-
log(`\nTransaction hash: ${txHash.toString()}`);
|
|
56
56
|
if (wait) {
|
|
57
57
|
try {
|
|
58
|
-
await
|
|
58
|
+
const { receipt } = await call.send({
|
|
59
|
+
...sendOptions,
|
|
60
|
+
fee: { ...sendOptions.fee, gasSettings: estimatedGas },
|
|
61
|
+
wait: { timeout: DEFAULT_TX_TIMEOUT_S },
|
|
62
|
+
});
|
|
59
63
|
|
|
64
|
+
const txHash = receipt.txHash;
|
|
65
|
+
log(`\nTransaction hash: ${txHash.toString()}`);
|
|
60
66
|
log('Transaction has been mined');
|
|
61
|
-
|
|
62
|
-
const receipt = await tx.getReceipt();
|
|
63
67
|
log(` Tx fee: ${receipt.transactionFee}`);
|
|
64
68
|
log(` Status: ${receipt.status}`);
|
|
65
69
|
log(` Block number: ${receipt.blockNumber}`);
|
|
66
70
|
log(` Block hash: ${receipt.blockHash?.toString()}`);
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
txHash,
|
|
74
|
+
};
|
|
67
75
|
} catch (err: any) {
|
|
68
76
|
log(`Transaction failed\n ${err.message}`);
|
|
77
|
+
throw err;
|
|
69
78
|
}
|
|
70
79
|
} else {
|
|
80
|
+
const { txHash } = await call.send({
|
|
81
|
+
...sendOptions,
|
|
82
|
+
fee: { ...sendOptions.fee, gasSettings: estimatedGas },
|
|
83
|
+
wait: NO_WAIT,
|
|
84
|
+
});
|
|
85
|
+
log(`\nTransaction hash: ${txHash.toString()}`);
|
|
71
86
|
log('Transaction pending. Check status with check-tx');
|
|
87
|
+
return {
|
|
88
|
+
txHash,
|
|
89
|
+
};
|
|
72
90
|
}
|
|
73
|
-
return {
|
|
74
|
-
txHash,
|
|
75
|
-
};
|
|
76
91
|
}
|
package/src/cmds/simulate.ts
CHANGED
|
@@ -38,7 +38,7 @@ export async function simulate(
|
|
|
38
38
|
});
|
|
39
39
|
if (verbose) {
|
|
40
40
|
await printAuthorizations(
|
|
41
|
-
simulationResult.offchainEffects
|
|
41
|
+
simulationResult.offchainEffects,
|
|
42
42
|
async (address: AztecAddress) => {
|
|
43
43
|
const metadata = await wallet.getContractMetadata(address);
|
|
44
44
|
if (!metadata.instance) {
|
package/src/storage/wallet_db.ts
CHANGED
|
@@ -12,6 +12,7 @@ export const Aliases = ['accounts', 'contracts', 'artifacts', 'secrets', 'transa
|
|
|
12
12
|
export type AliasType = (typeof Aliases)[number];
|
|
13
13
|
|
|
14
14
|
export class WalletDB {
|
|
15
|
+
#store!: AztecAsyncKVStore;
|
|
15
16
|
#accounts!: AztecAsyncMap<string, Buffer>;
|
|
16
17
|
#aliases!: AztecAsyncMap<string, Buffer>;
|
|
17
18
|
#bridgedFeeJuice!: AztecAsyncMap<string, Buffer>;
|
|
@@ -29,6 +30,7 @@ export class WalletDB {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
async init(store: AztecAsyncKVStore) {
|
|
33
|
+
this.#store = store;
|
|
32
34
|
this.#accounts = store.openMap('accounts');
|
|
33
35
|
this.#aliases = store.openMap('aliases');
|
|
34
36
|
this.#bridgedFeeJuice = store.openMap('bridgedFeeJuice');
|
|
@@ -41,14 +43,17 @@ export class WalletDB {
|
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
async pushBridgedFeeJuice(recipient: AztecAddress, secret: Fr, amount: bigint, leafIndex: bigint, log: LogFn) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
await this.#store.transactionAsync(async () => {
|
|
47
|
+
let stackPointer =
|
|
48
|
+
(await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:stackPointer`))?.readInt8() || 0;
|
|
49
|
+
stackPointer++;
|
|
50
|
+
await this.#bridgedFeeJuice.set(
|
|
51
|
+
`${recipient.toString()}:${stackPointer}`,
|
|
52
|
+
Buffer.from(`${amount.toString()}:${secret.toString()}:${leafIndex.toString()}`),
|
|
53
|
+
);
|
|
54
|
+
await this.#bridgedFeeJuice.set(`${recipient.toString()}:stackPointer`, Buffer.from([stackPointer]));
|
|
55
|
+
log(`Pushed ${amount} fee juice for recipient ${recipient.toString()}. Stack pointer ${stackPointer}`);
|
|
56
|
+
});
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
async popBridgedFeeJuice(recipient: AztecAddress, log: LogFn) {
|
|
@@ -76,19 +81,24 @@ export class WalletDB {
|
|
|
76
81
|
}: { type: AccountType; secretKey: Fr; salt: Fr; alias: string | undefined; publicKey: string | undefined },
|
|
77
82
|
log: LogFn,
|
|
78
83
|
) {
|
|
79
|
-
|
|
80
|
-
await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
|
|
81
|
-
}
|
|
82
|
-
await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
|
|
83
|
-
await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
|
|
84
|
-
await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
|
|
84
|
+
let publicSigningKey: Buffer | undefined;
|
|
85
85
|
if (type === 'ecdsasecp256r1ssh' && publicKey) {
|
|
86
|
-
|
|
87
|
-
await this.storeAccountMetadata(address, 'publicSigningKey', publicSigningKey);
|
|
86
|
+
publicSigningKey = extractECDSAPublicKeyFromBase64String(publicKey);
|
|
88
87
|
}
|
|
89
|
-
await this.#aliases.set('accounts:last', Buffer.from(address.toString()));
|
|
90
|
-
log(`Account stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
91
88
|
|
|
89
|
+
await this.#store.transactionAsync(async () => {
|
|
90
|
+
if (alias) {
|
|
91
|
+
await this.#aliases.set(`accounts:${alias}`, Buffer.from(address.toString()));
|
|
92
|
+
}
|
|
93
|
+
await this.#accounts.set(`${address.toString()}:type`, Buffer.from(type));
|
|
94
|
+
await this.#accounts.set(`${address.toString()}:sk`, secretKey.toBuffer());
|
|
95
|
+
await this.#accounts.set(`${address.toString()}:salt`, salt.toBuffer());
|
|
96
|
+
if (publicSigningKey) {
|
|
97
|
+
await this.#accounts.set(`${address.toString()}:publicSigningKey`, publicSigningKey);
|
|
98
|
+
}
|
|
99
|
+
await this.#aliases.set('accounts:last', Buffer.from(address.toString()));
|
|
100
|
+
});
|
|
101
|
+
log(`Account stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
92
102
|
await this.refreshAliasCache();
|
|
93
103
|
}
|
|
94
104
|
|
|
@@ -100,35 +110,38 @@ export class WalletDB {
|
|
|
100
110
|
}
|
|
101
111
|
|
|
102
112
|
async storeContract(address: AztecAddress, artifactPath: string, log: LogFn, alias?: string) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
await this.#store.transactionAsync(async () => {
|
|
114
|
+
if (alias) {
|
|
115
|
+
await this.#aliases.set(`contracts:${alias}`, Buffer.from(address.toString()));
|
|
116
|
+
await this.#aliases.set(`artifacts:${alias}`, Buffer.from(artifactPath));
|
|
117
|
+
}
|
|
118
|
+
await this.#aliases.set(`contracts:last`, Buffer.from(address.toString()));
|
|
119
|
+
await this.#aliases.set(`artifacts:last`, Buffer.from(artifactPath));
|
|
120
|
+
await this.#aliases.set(`artifacts:${address.toString()}`, Buffer.from(artifactPath));
|
|
121
|
+
});
|
|
110
122
|
log(`Contract stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
111
|
-
|
|
112
123
|
await this.refreshAliasCache();
|
|
113
124
|
}
|
|
114
125
|
|
|
115
126
|
async storeAuthwitness(authWit: AuthWitness, log: LogFn, alias?: string) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
127
|
+
await this.#store.transactionAsync(async () => {
|
|
128
|
+
if (alias) {
|
|
129
|
+
await this.#aliases.set(`authwits:${alias}`, Buffer.from(authWit.toString()));
|
|
130
|
+
}
|
|
131
|
+
await this.#aliases.set(`authwits:last`, Buffer.from(authWit.toString()));
|
|
132
|
+
});
|
|
120
133
|
log(`Authorization witness stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
121
|
-
|
|
122
134
|
await this.refreshAliasCache();
|
|
123
135
|
}
|
|
124
136
|
|
|
125
137
|
async storeTx({ txHash }: { txHash: TxHash }, log: LogFn, alias?: string) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
await this.#store.transactionAsync(async () => {
|
|
139
|
+
if (alias) {
|
|
140
|
+
await this.#aliases.set(`transactions:${alias}`, Buffer.from(txHash.toString()));
|
|
141
|
+
}
|
|
142
|
+
await this.#aliases.set(`transactions:last`, Buffer.from(txHash.toString()));
|
|
143
|
+
});
|
|
130
144
|
log(`Transaction hash stored in database with alias${alias ? `es last & ${alias}` : ' last'}`);
|
|
131
|
-
|
|
132
145
|
await this.refreshAliasCache();
|
|
133
146
|
}
|
|
134
147
|
|
package/src/utils/wallet.ts
CHANGED
|
@@ -13,16 +13,16 @@ import { AccountManager, type Aliased, type SimulateOptions } from '@aztec/aztec
|
|
|
13
13
|
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
14
14
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
15
15
|
import type { LogFn } from '@aztec/foundation/log';
|
|
16
|
+
import type { AccessScopes, NotesFilter } from '@aztec/pxe/client/lazy';
|
|
16
17
|
import type { PXEConfig } from '@aztec/pxe/config';
|
|
17
18
|
import type { PXE } from '@aztec/pxe/server';
|
|
18
19
|
import { createPXE, getPXEConfig } from '@aztec/pxe/server';
|
|
19
20
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
20
21
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
21
22
|
import { NoteDao } from '@aztec/stdlib/note';
|
|
22
|
-
import type { NotesFilter } from '@aztec/stdlib/note';
|
|
23
23
|
import type { TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
24
24
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
25
|
-
import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
|
|
25
|
+
import { BaseWallet, type FeeOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
26
26
|
|
|
27
27
|
import type { WalletDB } from '../storage/wallet_db.js';
|
|
28
28
|
import type { AccountType } from './constants.js';
|
|
@@ -67,6 +67,7 @@ export class CLIWallet extends BaseWallet {
|
|
|
67
67
|
const feeOptions = await this.completeFeeOptions(from, executionPayload.feePayer, increasedFee.gasSettings);
|
|
68
68
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
69
69
|
const fromAccount = await this.getAccountFromAddress(from);
|
|
70
|
+
const chainInfo = await this.getChainInfo();
|
|
70
71
|
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
71
72
|
txNonce,
|
|
72
73
|
cancellable: this.cancellableTransactions,
|
|
@@ -75,6 +76,7 @@ export class CLIWallet extends BaseWallet {
|
|
|
75
76
|
return await fromAccount.createTxExecutionRequest(
|
|
76
77
|
feeExecutionPayload ?? executionPayload,
|
|
77
78
|
feeOptions.gasSettings,
|
|
79
|
+
chainInfo,
|
|
78
80
|
executionOptions,
|
|
79
81
|
);
|
|
80
82
|
}
|
|
@@ -85,14 +87,13 @@ export class CLIWallet extends BaseWallet {
|
|
|
85
87
|
increasedFee: InteractionFeeOptions,
|
|
86
88
|
): Promise<TxProvingResult> {
|
|
87
89
|
const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
|
|
88
|
-
return await this.pxe.proveTx(cancellationTxRequest);
|
|
90
|
+
return await this.pxe.proveTx(cancellationTxRequest, this.scopesFrom(from));
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
override async getAccountFromAddress(address: AztecAddress) {
|
|
92
94
|
let account: Account | undefined;
|
|
93
95
|
if (address.equals(AztecAddress.ZERO)) {
|
|
94
|
-
|
|
95
|
-
account = new SignerlessAccount(chainInfo);
|
|
96
|
+
account = new SignerlessAccount();
|
|
96
97
|
} else if (this.accountCache.has(address.toString())) {
|
|
97
98
|
return this.accountCache.get(address.toString())!;
|
|
98
99
|
} else {
|
|
@@ -176,15 +177,26 @@ export class CLIWallet extends BaseWallet {
|
|
|
176
177
|
return account;
|
|
177
178
|
}
|
|
178
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Creates a stub account that impersonates the given address, allowing kernelless simulations
|
|
182
|
+
* to bypass the account's authorization mechanisms via contract overrides.
|
|
183
|
+
* @param address - The address of the account to impersonate
|
|
184
|
+
* @returns The stub account, contract instance, and artifact for simulation
|
|
185
|
+
*/
|
|
179
186
|
private async getFakeAccountDataFor(address: AztecAddress) {
|
|
180
|
-
const chainInfo = await this.getChainInfo();
|
|
181
187
|
const originalAccount = await this.getAccountFromAddress(address);
|
|
182
|
-
|
|
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();
|
|
183
195
|
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
184
196
|
if (!contractInstance) {
|
|
185
197
|
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
186
198
|
}
|
|
187
|
-
const stubAccount = createStubAccount(originalAddress
|
|
199
|
+
const stubAccount = createStubAccount(originalAddress);
|
|
188
200
|
const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
|
|
189
201
|
salt: Fr.random(),
|
|
190
202
|
});
|
|
@@ -196,10 +208,39 @@ export class CLIWallet extends BaseWallet {
|
|
|
196
208
|
}
|
|
197
209
|
|
|
198
210
|
override async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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);
|
|
217
|
+
}
|
|
218
|
+
return simulationResults;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Uses a stub account for kernelless simulation, bypassing real account authorization.
|
|
223
|
+
* Falls through to the standard entrypoint path for SignerlessAccount (ZERO address).
|
|
224
|
+
*/
|
|
225
|
+
protected override async simulateViaEntrypoint(
|
|
226
|
+
executionPayload: ExecutionPayload,
|
|
227
|
+
from: AztecAddress,
|
|
228
|
+
feeOptions: FeeOptions,
|
|
229
|
+
scopes: AccessScopes,
|
|
230
|
+
skipTxValidation?: boolean,
|
|
231
|
+
skipFeeEnforcement?: boolean,
|
|
232
|
+
): Promise<TxSimulationResult> {
|
|
233
|
+
if (from.equals(AztecAddress.ZERO)) {
|
|
234
|
+
return super.simulateViaEntrypoint(
|
|
235
|
+
executionPayload,
|
|
236
|
+
from,
|
|
237
|
+
feeOptions,
|
|
238
|
+
scopes,
|
|
239
|
+
skipTxValidation,
|
|
240
|
+
skipFeeEnforcement,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
203
244
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
204
245
|
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
205
246
|
txNonce: Fr.random(),
|
|
@@ -210,42 +251,23 @@ export class CLIWallet extends BaseWallet {
|
|
|
210
251
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
211
252
|
: executionPayload;
|
|
212
253
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(opts.from);
|
|
231
|
-
const txRequest = await fromAccount.createTxExecutionRequest(
|
|
232
|
-
finalExecutionPayload,
|
|
233
|
-
feeOptions.gasSettings,
|
|
234
|
-
executionOptions,
|
|
235
|
-
);
|
|
236
|
-
const contractOverrides = {
|
|
237
|
-
[opts.from.toString()]: { instance, artifact },
|
|
238
|
-
};
|
|
239
|
-
simulationResults = await this.pxe.simulateTx(txRequest, true /* simulatePublic */, true, true, {
|
|
240
|
-
contracts: contractOverrides,
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (opts.fee?.estimateGas) {
|
|
245
|
-
const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
|
|
246
|
-
printGasEstimates(feeOptions, limits, this.userLog);
|
|
247
|
-
}
|
|
248
|
-
return simulationResults;
|
|
254
|
+
const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(from);
|
|
255
|
+
const chainInfo = await this.getChainInfo();
|
|
256
|
+
const txRequest = await fromAccount.createTxExecutionRequest(
|
|
257
|
+
finalExecutionPayload,
|
|
258
|
+
feeOptions.gasSettings,
|
|
259
|
+
chainInfo,
|
|
260
|
+
executionOptions,
|
|
261
|
+
);
|
|
262
|
+
return this.pxe.simulateTx(txRequest, {
|
|
263
|
+
simulatePublic: true,
|
|
264
|
+
skipFeeEnforcement: true,
|
|
265
|
+
skipTxValidation: true,
|
|
266
|
+
overrides: {
|
|
267
|
+
contracts: { [from.toString()]: { instance, artifact } },
|
|
268
|
+
},
|
|
269
|
+
scopes,
|
|
270
|
+
});
|
|
249
271
|
}
|
|
250
272
|
|
|
251
273
|
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|