@aztec/cli-wallet 4.0.0-nightly.20250907 → 4.0.0-nightly.20260108
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/README.md +30 -0
- package/dest/bin/index.d.ts +1 -1
- package/dest/bin/index.js +38 -23
- package/dest/cmds/authorize_action.d.ts +4 -3
- package/dest/cmds/authorize_action.d.ts.map +1 -1
- package/dest/cmds/authorize_action.js +6 -7
- package/dest/cmds/bridge_fee_juice.d.ts +4 -4
- package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
- package/dest/cmds/bridge_fee_juice.js +9 -7
- package/dest/cmds/check_tx.d.ts +5 -3
- package/dest/cmds/check_tx.d.ts.map +1 -1
- package/dest/cmds/check_tx.js +144 -6
- package/dest/cmds/create_account.d.ts +7 -6
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +36 -48
- package/dest/cmds/create_authwit.d.ts +4 -3
- package/dest/cmds/create_authwit.d.ts.map +1 -1
- package/dest/cmds/create_authwit.js +6 -6
- package/dest/cmds/deploy.d.ts +7 -4
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +57 -46
- package/dest/cmds/deploy_account.d.ts +6 -8
- package/dest/cmds/deploy_account.d.ts.map +1 -1
- package/dest/cmds/deploy_account.js +36 -51
- package/dest/cmds/import_test_accounts.d.ts +3 -3
- package/dest/cmds/import_test_accounts.d.ts.map +1 -1
- package/dest/cmds/import_test_accounts.js +6 -9
- package/dest/cmds/index.d.ts +3 -3
- package/dest/cmds/index.d.ts.map +1 -1
- package/dest/cmds/index.js +73 -112
- package/dest/cmds/profile.d.ts +7 -4
- package/dest/cmds/profile.d.ts.map +1 -1
- package/dest/cmds/profile.js +9 -4
- package/dest/cmds/register_contract.d.ts +7 -3
- package/dest/cmds/register_contract.d.ts.map +1 -1
- package/dest/cmds/register_contract.js +5 -6
- package/dest/cmds/register_sender.d.ts +4 -3
- package/dest/cmds/register_sender.d.ts.map +1 -1
- package/dest/cmds/send.d.ts +8 -9
- package/dest/cmds/send.d.ts.map +1 -1
- package/dest/cmds/send.js +27 -24
- package/dest/cmds/simulate.d.ts +7 -4
- package/dest/cmds/simulate.d.ts.map +1 -1
- package/dest/cmds/simulate.js +9 -4
- package/dest/storage/wallet_db.d.ts +6 -16
- package/dest/storage/wallet_db.d.ts.map +1 -1
- package/dest/storage/wallet_db.js +2 -23
- package/dest/utils/authorizations.d.ts +3 -2
- package/dest/utils/authorizations.d.ts.map +1 -1
- package/dest/utils/authorizations.js +1 -1
- package/dest/utils/cli_wallet_and_node_wrapper.d.ts +12 -0
- package/dest/utils/cli_wallet_and_node_wrapper.d.ts.map +1 -0
- package/dest/utils/cli_wallet_and_node_wrapper.js +25 -0
- package/dest/utils/ecdsa.d.ts +1 -1
- package/dest/utils/options/fees.d.ts +22 -28
- package/dest/utils/options/fees.d.ts.map +1 -1
- package/dest/utils/options/fees.js +66 -133
- package/dest/utils/options/index.d.ts +1 -1
- package/dest/utils/options/options.d.ts +4 -3
- package/dest/utils/options/options.d.ts.map +1 -1
- package/dest/utils/options/options.js +1 -1
- package/dest/utils/profiling.d.ts +1 -1
- package/dest/utils/wallet.d.ts +36 -0
- package/dest/utils/wallet.d.ts.map +1 -0
- package/dest/utils/wallet.js +195 -0
- package/package.json +17 -14
- package/src/bin/index.ts +38 -31
- package/src/cmds/authorize_action.ts +14 -6
- package/src/cmds/bridge_fee_juice.ts +15 -11
- package/src/cmds/check_tx.ts +181 -5
- package/src/cmds/create_account.ts +43 -53
- package/src/cmds/create_authwit.ts +9 -5
- package/src/cmds/deploy.ts +58 -56
- package/src/cmds/deploy_account.ts +43 -51
- package/src/cmds/import_test_accounts.ts +7 -11
- package/src/cmds/index.ts +120 -206
- package/src/cmds/profile.ts +14 -6
- package/src/cmds/register_contract.ts +9 -11
- package/src/cmds/register_sender.ts +3 -2
- package/src/cmds/send.ts +22 -32
- package/src/cmds/simulate.ts +14 -6
- package/src/storage/wallet_db.ts +3 -31
- package/src/utils/authorizations.ts +3 -1
- package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
- package/src/utils/options/fees.ts +88 -178
- package/src/utils/options/options.ts +3 -2
- package/src/utils/wallet.ts +266 -0
- package/dest/cmds/cancel_tx.d.ts +0 -11
- package/dest/cmds/cancel_tx.d.ts.map +0 -1
- package/dest/cmds/cancel_tx.js +0 -43
- package/dest/utils/accounts.d.ts +0 -9
- package/dest/utils/accounts.d.ts.map +0 -1
- package/dest/utils/accounts.js +0 -61
- package/dest/utils/pxe_wrapper.d.ts +0 -12
- package/dest/utils/pxe_wrapper.d.ts.map +0 -1
- package/dest/utils/pxe_wrapper.js +0 -26
- package/src/cmds/cancel_tx.ts +0 -66
- package/src/utils/accounts.ts +0 -77
- package/src/utils/pxe_wrapper.ts +0 -32
|
@@ -1,67 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type FeePaymentMethod,
|
|
6
|
-
type PXE,
|
|
7
|
-
type SendMethodOptions,
|
|
8
|
-
} from '@aztec/aztec.js';
|
|
9
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
1
|
+
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
2
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
3
|
+
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
5
|
import type { LogFn } from '@aztec/foundation/log';
|
|
6
|
+
import type { FieldsOf } from '@aztec/foundation/types';
|
|
11
7
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
12
8
|
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
9
|
+
import type { FeeOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
13
10
|
|
|
14
11
|
import { Option } from 'commander';
|
|
15
12
|
|
|
16
13
|
import type { WalletDB } from '../../storage/wallet_db.js';
|
|
17
|
-
import {
|
|
14
|
+
import { MIN_FEE_PADDING } from '../wallet.js';
|
|
18
15
|
import { aliasedAddressParser } from './options.js';
|
|
19
16
|
|
|
20
|
-
export type
|
|
17
|
+
export type RawCliFeeArgs = {
|
|
21
18
|
estimateGasOnly: boolean;
|
|
22
19
|
gasLimits?: string;
|
|
23
20
|
payment?: string;
|
|
24
21
|
maxFeesPerGas?: string;
|
|
25
22
|
maxPriorityFeesPerGas?: string;
|
|
26
|
-
estimateGas?: boolean;
|
|
27
23
|
};
|
|
28
24
|
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
gasSettings
|
|
32
|
-
|
|
33
|
-
toDeployAccountOpts(sender: AccountWallet): Promise<DeployAccountOptions>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function printGasEstimates(
|
|
37
|
-
feeOpts: IFeeOpts,
|
|
38
|
-
gasEstimates: Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>,
|
|
39
|
-
log: LogFn,
|
|
40
|
-
) {
|
|
41
|
-
log(`Estimated gas usage: ${formatGasEstimate(gasEstimates)}`);
|
|
42
|
-
log(`Maximum total tx fee: ${getEstimatedCost(gasEstimates, feeOpts.gasSettings.maxFeesPerGas)}`);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function formatGasEstimate(estimate: Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>) {
|
|
46
|
-
return `da=${estimate.gasLimits.daGas},l2=${estimate.gasLimits.l2Gas},teardownDA=${estimate.teardownGasLimits.daGas},teardownL2=${estimate.teardownGasLimits.l2Gas}`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function getEstimatedCost(estimate: Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>, maxFeesPerGas: GasFees) {
|
|
50
|
-
return GasSettings.default({ ...estimate, maxFeesPerGas })
|
|
51
|
-
.getFeeLimit()
|
|
52
|
-
.toBigInt();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async function parseGasSettings(args: CliFeeArgs, pxe: PXE) {
|
|
56
|
-
const gasLimits = args.gasLimits ? parseGasLimits(args.gasLimits) : {};
|
|
57
|
-
const maxFeesPerGas = args.maxFeesPerGas ? parseGasFees(args.maxFeesPerGas) : await pxe.getCurrentBaseFees();
|
|
58
|
-
const maxPriorityFeesPerGas = args.maxPriorityFeesPerGas ? parseGasFees(args.maxPriorityFeesPerGas) : undefined;
|
|
59
|
-
return GasSettings.default({
|
|
60
|
-
...gasLimits,
|
|
61
|
-
maxFeesPerGas,
|
|
62
|
-
maxPriorityFeesPerGas,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
25
|
+
export type ParsedFeeOptions = {
|
|
26
|
+
paymentMethod?: FeePaymentMethod;
|
|
27
|
+
gasSettings?: Partial<FieldsOf<GasSettings>>;
|
|
28
|
+
};
|
|
65
29
|
|
|
66
30
|
type OptionParams = {
|
|
67
31
|
[key: string]: { type: string; description?: string; default?: string };
|
|
@@ -84,15 +48,13 @@ function printOptionParams(params: OptionParams) {
|
|
|
84
48
|
: '';
|
|
85
49
|
}
|
|
86
50
|
|
|
87
|
-
function getFeePaymentMethodParams(
|
|
88
|
-
const feePayer = allowCustomFeePayer ? { type: 'address', description: 'The account paying the fee.' } : undefined;
|
|
51
|
+
function getFeePaymentMethodParams(): OptionParams {
|
|
89
52
|
return {
|
|
90
53
|
method: {
|
|
91
54
|
type: 'name',
|
|
92
55
|
description: 'Valid values: "fee_juice", "fpc-public", "fpc-private", "fpc-sponsored"',
|
|
93
56
|
default: 'fee_juice',
|
|
94
57
|
},
|
|
95
|
-
...(feePayer ? { feePayer } : {}),
|
|
96
58
|
asset: {
|
|
97
59
|
type: 'address',
|
|
98
60
|
description: 'The asset used for fee payment. Required for "fpc-public" and "fpc-private".',
|
|
@@ -117,144 +79,43 @@ function getFeePaymentMethodParams(allowCustomFeePayer: boolean): OptionParams {
|
|
|
117
79
|
type: 'bigint',
|
|
118
80
|
description: 'The index of the claim in the l1toL2Message tree.',
|
|
119
81
|
},
|
|
120
|
-
feeRecipient: {
|
|
121
|
-
type: 'string',
|
|
122
|
-
description: 'Recipient of the fee.',
|
|
123
|
-
},
|
|
124
82
|
};
|
|
125
83
|
}
|
|
126
84
|
|
|
127
|
-
function getPaymentMethodOption(
|
|
128
|
-
const params = getFeePaymentMethodParams(
|
|
85
|
+
export function getPaymentMethodOption() {
|
|
86
|
+
const params = getFeePaymentMethodParams();
|
|
129
87
|
return new Option(`--payment <options>`, `Fee payment method and arguments.${printOptionParams(params)}`);
|
|
130
88
|
}
|
|
131
89
|
|
|
132
|
-
function getFeeOptions(
|
|
90
|
+
function getFeeOptions() {
|
|
133
91
|
return [
|
|
134
|
-
getPaymentMethodOption(
|
|
92
|
+
getPaymentMethodOption(),
|
|
135
93
|
new Option('--gas-limits <da=100,l2=100,teardownDA=10,teardownL2=10>', 'Gas limits for the tx.'),
|
|
136
94
|
new Option('--max-fees-per-gas <da=100,l2=100>', 'Maximum fees per gas unit for DA and L2 computation.'),
|
|
137
95
|
new Option(
|
|
138
96
|
'--max-priority-fees-per-gas <da=0,l2=0>',
|
|
139
97
|
'Maximum priority fees per gas unit for DA and L2 computation.',
|
|
140
98
|
),
|
|
141
|
-
new Option('--estimate-gas', 'Whether to automatically estimate gas limits for the tx.'),
|
|
142
99
|
new Option('--estimate-gas-only', 'Only report gas estimation for the tx, do not send it.'),
|
|
143
100
|
];
|
|
144
101
|
}
|
|
145
102
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
private estimateGas: boolean,
|
|
156
|
-
) {}
|
|
157
|
-
|
|
158
|
-
async toSendOpts(sender: AccountWallet): Promise<SendMethodOptions> {
|
|
159
|
-
return {
|
|
160
|
-
from: sender.getAddress(),
|
|
161
|
-
fee: {
|
|
162
|
-
estimateGas: this.estimateGas,
|
|
163
|
-
gasSettings: this.gasSettings,
|
|
164
|
-
paymentMethod: await this.paymentMethodFactory(sender),
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
async toDeployAccountOpts(sender: AccountWallet): Promise<DeployAccountOptions> {
|
|
170
|
-
const paymentMethod = await this.paymentMethodFactory(sender);
|
|
171
|
-
const deployWallet = await this.getDeployWallet(sender, paymentMethod);
|
|
172
|
-
return {
|
|
173
|
-
deployWallet,
|
|
174
|
-
fee: {
|
|
175
|
-
estimateGas: this.estimateGas,
|
|
176
|
-
gasSettings: this.gasSettings,
|
|
177
|
-
paymentMethod,
|
|
178
|
-
},
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
static paymentMethodOption() {
|
|
183
|
-
return getPaymentMethodOption(false);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
static getOptions() {
|
|
187
|
-
return getFeeOptions(false);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
static async fromCli(args: CliFeeArgs, pxe: PXE, log: LogFn, db?: WalletDB) {
|
|
191
|
-
const estimateOnly = args.estimateGasOnly;
|
|
192
|
-
const gasSettings = await parseGasSettings(args, pxe);
|
|
193
|
-
|
|
194
|
-
const defaultPaymentMethod = async (sender: AccountWallet) => {
|
|
195
|
-
const { FeeJuicePaymentMethod } = await import('@aztec/aztec.js/fee');
|
|
196
|
-
return new FeeJuicePaymentMethod(sender.getAddress());
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
const getDeployWallet = () => {
|
|
200
|
-
// Returns undefined. The sender's wallet will be used by default.
|
|
201
|
-
return Promise.resolve(undefined);
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
return new FeeOpts(
|
|
205
|
-
estimateOnly,
|
|
206
|
-
gasSettings,
|
|
207
|
-
args.payment ? parsePaymentMethod(args.payment, false, log, db) : defaultPaymentMethod,
|
|
208
|
-
getDeployWallet,
|
|
209
|
-
!!args.estimateGas,
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export class FeeOptsWithFeePayer extends FeeOpts {
|
|
215
|
-
static override paymentMethodOption() {
|
|
216
|
-
return getPaymentMethodOption(true);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
static override getOptions() {
|
|
220
|
-
return getFeeOptions(true);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
static override async fromCli(args: CliFeeArgs, pxe: PXE, log: LogFn, db?: WalletDB) {
|
|
224
|
-
const estimateOnly = args.estimateGasOnly;
|
|
225
|
-
const gasSettings = await parseGasSettings(args, pxe);
|
|
226
|
-
|
|
227
|
-
const defaultPaymentMethod = async (sender: AccountWallet) => {
|
|
228
|
-
const { FeeJuicePaymentMethod } = await import('@aztec/aztec.js/fee');
|
|
229
|
-
return new FeeJuicePaymentMethod(sender.getAddress());
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
const getDeployWallet = async (sender: AccountWallet, paymentMethod: FeePaymentMethod) => {
|
|
233
|
-
if (paymentMethod instanceof FeeJuicePaymentMethod) {
|
|
234
|
-
const feePayer = await paymentMethod.getFeePayer();
|
|
235
|
-
if (!sender.getAddress().equals(feePayer)) {
|
|
236
|
-
return (await createOrRetrieveAccount(pxe, feePayer, db)).getWallet();
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return undefined;
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
return new FeeOptsWithFeePayer(
|
|
243
|
-
estimateOnly,
|
|
244
|
-
gasSettings,
|
|
245
|
-
args.payment ? parsePaymentMethod(args.payment, true, log, db) : defaultPaymentMethod,
|
|
246
|
-
getDeployWallet,
|
|
247
|
-
!!args.estimateGas,
|
|
248
|
-
);
|
|
249
|
-
}
|
|
103
|
+
function parseGasSettings(args: RawCliFeeArgs): Partial<FieldsOf<GasSettings>> {
|
|
104
|
+
const gasLimits = args.gasLimits ? parseGasLimits(args.gasLimits) : {};
|
|
105
|
+
const maxFeesPerGas = args.maxFeesPerGas ? parseGasFees(args.maxFeesPerGas) : undefined;
|
|
106
|
+
const maxPriorityFeesPerGas = args.maxPriorityFeesPerGas ? parseGasFees(args.maxPriorityFeesPerGas) : undefined;
|
|
107
|
+
return {
|
|
108
|
+
...gasLimits,
|
|
109
|
+
maxFeesPerGas,
|
|
110
|
+
maxPriorityFeesPerGas,
|
|
111
|
+
};
|
|
250
112
|
}
|
|
251
113
|
|
|
252
114
|
export function parsePaymentMethod(
|
|
253
115
|
payment: string,
|
|
254
|
-
allowCustomFeePayer: boolean,
|
|
255
116
|
log: LogFn,
|
|
256
117
|
db?: WalletDB,
|
|
257
|
-
): (
|
|
118
|
+
): (wallet: Wallet, from: AztecAddress, gasSettings: GasSettings) => Promise<FeePaymentMethod | undefined> {
|
|
258
119
|
const parsed = payment.split(',').reduce(
|
|
259
120
|
(acc, item) => {
|
|
260
121
|
const [dimension, value] = item.split('=');
|
|
@@ -278,7 +139,7 @@ export function parsePaymentMethod(
|
|
|
278
139
|
return AztecAddress.fromString(parsed.asset);
|
|
279
140
|
};
|
|
280
141
|
|
|
281
|
-
return async (
|
|
142
|
+
return async (wallet: Wallet, from: AztecAddress, gasSettings: GasSettings) => {
|
|
282
143
|
switch (parsed.method) {
|
|
283
144
|
case 'fee_juice': {
|
|
284
145
|
if (parsed.claim || (parsed.claimSecret && parsed.claimAmount && parsed.messageLeafIndex)) {
|
|
@@ -288,13 +149,13 @@ export function parsePaymentMethod(
|
|
|
288
149
|
amount: claimAmount,
|
|
289
150
|
secret: claimSecret,
|
|
290
151
|
leafIndex: messageLeafIndex,
|
|
291
|
-
} = await db.popBridgedFeeJuice(
|
|
152
|
+
} = await db.popBridgedFeeJuice(from, log));
|
|
292
153
|
} else {
|
|
293
154
|
({ claimAmount, claimSecret, messageLeafIndex } = parsed);
|
|
294
155
|
}
|
|
295
156
|
log(`Using Fee Juice for fee payments with claim for ${claimAmount} tokens`);
|
|
296
157
|
const { FeeJuicePaymentMethodWithClaim } = await import('@aztec/aztec.js/fee');
|
|
297
|
-
return new FeeJuicePaymentMethodWithClaim(
|
|
158
|
+
return new FeeJuicePaymentMethodWithClaim(from, {
|
|
298
159
|
claimAmount: (typeof claimAmount === 'string'
|
|
299
160
|
? Fr.fromHexString(claimAmount)
|
|
300
161
|
: new Fr(claimAmount)
|
|
@@ -303,13 +164,8 @@ export function parsePaymentMethod(
|
|
|
303
164
|
messageLeafIndex: BigInt(messageLeafIndex),
|
|
304
165
|
});
|
|
305
166
|
} else {
|
|
306
|
-
log(`Using Fee Juice for fee payment`);
|
|
307
|
-
|
|
308
|
-
const feePayer =
|
|
309
|
-
parsed.feePayer && allowCustomFeePayer
|
|
310
|
-
? aliasedAddressParser('accounts', parsed.feePayer, db)
|
|
311
|
-
: sender.getAddress();
|
|
312
|
-
return new FeeJuicePaymentMethod(feePayer);
|
|
167
|
+
log(`Using Fee Juice for fee payment with the balance of account ${from}`);
|
|
168
|
+
return;
|
|
313
169
|
}
|
|
314
170
|
}
|
|
315
171
|
case 'fpc-public': {
|
|
@@ -317,14 +173,14 @@ export function parsePaymentMethod(
|
|
|
317
173
|
const asset = getAsset();
|
|
318
174
|
log(`Using public fee payment with asset ${asset} via paymaster ${fpc}`);
|
|
319
175
|
const { PublicFeePaymentMethod } = await import('@aztec/aztec.js/fee');
|
|
320
|
-
return new PublicFeePaymentMethod(fpc,
|
|
176
|
+
return new PublicFeePaymentMethod(fpc, from, wallet, gasSettings);
|
|
321
177
|
}
|
|
322
178
|
case 'fpc-private': {
|
|
323
179
|
const fpc = getFpc();
|
|
324
180
|
const asset = getAsset();
|
|
325
181
|
log(`Using private fee payment with asset ${asset} via paymaster ${fpc}`);
|
|
326
182
|
const { PrivateFeePaymentMethod } = await import('@aztec/aztec.js/fee');
|
|
327
|
-
return new PrivateFeePaymentMethod(fpc,
|
|
183
|
+
return new PrivateFeePaymentMethod(fpc, from, wallet, gasSettings);
|
|
328
184
|
}
|
|
329
185
|
case 'fpc-sponsored': {
|
|
330
186
|
const sponsor = getFpc();
|
|
@@ -382,3 +238,57 @@ export function parseGasFees(gasFees: string): GasFees {
|
|
|
382
238
|
|
|
383
239
|
return new GasFees(parsed.da, parsed.l2);
|
|
384
240
|
}
|
|
241
|
+
export class CLIFeeArgs {
|
|
242
|
+
constructor(
|
|
243
|
+
public estimateOnly: boolean,
|
|
244
|
+
private paymentMethod: (
|
|
245
|
+
wallet: Wallet,
|
|
246
|
+
feePayer: AztecAddress,
|
|
247
|
+
gasSettings: GasSettings,
|
|
248
|
+
) => Promise<FeePaymentMethod | undefined>,
|
|
249
|
+
private gasSettings: Partial<FieldsOf<GasSettings>>,
|
|
250
|
+
) {}
|
|
251
|
+
|
|
252
|
+
async toUserFeeOptions(node: AztecNode, wallet: Wallet, from: AztecAddress): Promise<ParsedFeeOptions> {
|
|
253
|
+
const maxFeesPerGas = (await node.getCurrentMinFees()).mul(1 + MIN_FEE_PADDING);
|
|
254
|
+
const gasSettings = GasSettings.default({ ...this.gasSettings, maxFeesPerGas });
|
|
255
|
+
const paymentMethod = await this.paymentMethod(wallet, from, gasSettings);
|
|
256
|
+
return {
|
|
257
|
+
paymentMethod,
|
|
258
|
+
gasSettings,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
static parse(args: RawCliFeeArgs, log: LogFn, db?: WalletDB): CLIFeeArgs {
|
|
263
|
+
return new CLIFeeArgs(
|
|
264
|
+
!!args.estimateGasOnly,
|
|
265
|
+
parsePaymentMethod(args.payment ?? 'method=fee_juice', log, db),
|
|
266
|
+
parseGasSettings(args),
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
static getOptions() {
|
|
271
|
+
return getFeeOptions();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Printing
|
|
276
|
+
|
|
277
|
+
export function printGasEstimates(
|
|
278
|
+
feeOpts: FeeOptions,
|
|
279
|
+
gasEstimates: Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>,
|
|
280
|
+
log: LogFn,
|
|
281
|
+
) {
|
|
282
|
+
log(`Estimated gas usage: ${formatGasEstimate(gasEstimates)}`);
|
|
283
|
+
log(`Maximum total tx fee: ${getEstimatedCost(gasEstimates, feeOpts.gasSettings.maxFeesPerGas)}`);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function formatGasEstimate(estimate: Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>) {
|
|
287
|
+
return `da=${estimate.gasLimits.daGas},l2=${estimate.gasLimits.l2Gas},teardownDA=${estimate.teardownGasLimits.daGas},teardownL2=${estimate.teardownGasLimits.l2Gas}`;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function getEstimatedCost(estimate: Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>, maxFeesPerGas: GasFees) {
|
|
291
|
+
return GasSettings.default({ ...estimate, maxFeesPerGas })
|
|
292
|
+
.getFeeLimit()
|
|
293
|
+
.toBigInt();
|
|
294
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TxHash } from '@aztec/aztec.js/tx';
|
|
1
2
|
import { parseAztecAddress, parseSecretKey, parseTxHash } from '@aztec/cli/utils';
|
|
2
3
|
import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
3
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -6,7 +7,7 @@ import { Option } from 'commander';
|
|
|
6
7
|
import { readdir, stat } from 'fs/promises';
|
|
7
8
|
|
|
8
9
|
import type { AliasType, WalletDB } from '../../storage/wallet_db.js';
|
|
9
|
-
import { AccountTypes } from '../
|
|
10
|
+
import { AccountTypes } from '../wallet.js';
|
|
10
11
|
|
|
11
12
|
const TARGET_DIR = 'target';
|
|
12
13
|
|
|
@@ -29,7 +30,7 @@ export function integerArgParser(
|
|
|
29
30
|
return parsed;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
export function aliasedTxHashParser(txHash: string, db?: WalletDB) {
|
|
33
|
+
export function aliasedTxHashParser(txHash: string, db?: WalletDB): TxHash {
|
|
33
34
|
try {
|
|
34
35
|
return parseTxHash(txHash);
|
|
35
36
|
} catch {
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { EcdsaRAccountContract, EcdsaRSSHAccountContract } from '@aztec/accounts/ecdsa';
|
|
2
|
+
import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
|
|
3
|
+
import { StubAccountContractArtifact, createStubAccount } from '@aztec/accounts/stub';
|
|
4
|
+
import { getIdentities } from '@aztec/accounts/utils';
|
|
5
|
+
import { type Account, type AccountContract, SignerlessAccount } from '@aztec/aztec.js/account';
|
|
6
|
+
import {
|
|
7
|
+
type InteractionFeeOptions,
|
|
8
|
+
getContractInstanceFromInstantiationParams,
|
|
9
|
+
getGasLimits,
|
|
10
|
+
} from '@aztec/aztec.js/contracts';
|
|
11
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
12
|
+
import { AccountManager, type Aliased, type SimulateOptions } from '@aztec/aztec.js/wallet';
|
|
13
|
+
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
14
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
15
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
16
|
+
import type { PXEConfig } from '@aztec/pxe/config';
|
|
17
|
+
import type { PXE } from '@aztec/pxe/server';
|
|
18
|
+
import { createPXE, getPXEConfig } from '@aztec/pxe/server';
|
|
19
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
20
|
+
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
21
|
+
import { NoteDao } from '@aztec/stdlib/note';
|
|
22
|
+
import type { NotesFilter } from '@aztec/stdlib/note';
|
|
23
|
+
import type { TxProvingResult, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
24
|
+
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
25
|
+
import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
|
|
26
|
+
|
|
27
|
+
import type { WalletDB } from '../storage/wallet_db.js';
|
|
28
|
+
import { extractECDSAPublicKeyFromBase64String } from './ecdsa.js';
|
|
29
|
+
import { printGasEstimates } from './options/fees.js';
|
|
30
|
+
|
|
31
|
+
export const AccountTypes = ['schnorr', 'ecdsasecp256r1', 'ecdsasecp256r1ssh', 'ecdsasecp256k1'] as const;
|
|
32
|
+
export type AccountType = (typeof AccountTypes)[number];
|
|
33
|
+
|
|
34
|
+
export const MIN_FEE_PADDING = 0.5;
|
|
35
|
+
|
|
36
|
+
export class CLIWallet extends BaseWallet {
|
|
37
|
+
private accountCache = new Map<string, Account>();
|
|
38
|
+
|
|
39
|
+
constructor(
|
|
40
|
+
pxe: PXE,
|
|
41
|
+
node: AztecNode,
|
|
42
|
+
private userLog: LogFn,
|
|
43
|
+
private db?: WalletDB,
|
|
44
|
+
) {
|
|
45
|
+
super(pxe, node);
|
|
46
|
+
this.cancellableTransactions = true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static async create(
|
|
50
|
+
node: AztecNode,
|
|
51
|
+
log: LogFn,
|
|
52
|
+
db?: WalletDB,
|
|
53
|
+
overridePXEConfig?: Partial<PXEConfig>,
|
|
54
|
+
): Promise<CLIWallet> {
|
|
55
|
+
const pxeConfig = Object.assign(getPXEConfig(), overridePXEConfig);
|
|
56
|
+
const pxe = await createPXE(node, pxeConfig);
|
|
57
|
+
return new CLIWallet(pxe, node, log, db);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
override async getAccounts(): Promise<Aliased<AztecAddress>[]> {
|
|
61
|
+
const accounts = (await this.db?.listAliases('accounts')) ?? [];
|
|
62
|
+
return Promise.resolve(accounts.map(({ key, value }) => ({ alias: value, item: AztecAddress.fromString(key) })));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private async createCancellationTxExecutionRequest(
|
|
66
|
+
from: AztecAddress,
|
|
67
|
+
txNonce: Fr,
|
|
68
|
+
increasedFee: InteractionFeeOptions,
|
|
69
|
+
) {
|
|
70
|
+
const executionPayload = ExecutionPayload.empty();
|
|
71
|
+
const feeOptions = await this.completeFeeOptions(from, executionPayload.feePayer, increasedFee.gasSettings);
|
|
72
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
73
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
74
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
75
|
+
txNonce,
|
|
76
|
+
cancellable: this.cancellableTransactions,
|
|
77
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
78
|
+
};
|
|
79
|
+
return await fromAccount.createTxExecutionRequest(
|
|
80
|
+
feeExecutionPayload ?? executionPayload,
|
|
81
|
+
feeOptions.gasSettings,
|
|
82
|
+
executionOptions,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async proveCancellationTx(
|
|
87
|
+
from: AztecAddress,
|
|
88
|
+
txNonce: Fr,
|
|
89
|
+
increasedFee: InteractionFeeOptions,
|
|
90
|
+
): Promise<TxProvingResult> {
|
|
91
|
+
const cancellationTxRequest = await this.createCancellationTxExecutionRequest(from, txNonce, increasedFee);
|
|
92
|
+
return await this.pxe.proveTx(cancellationTxRequest);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
override async getAccountFromAddress(address: AztecAddress) {
|
|
96
|
+
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())) {
|
|
101
|
+
return this.accountCache.get(address.toString())!;
|
|
102
|
+
} else {
|
|
103
|
+
const accountManager = await this.createOrRetrieveAccount(address);
|
|
104
|
+
account = await accountManager.getAccount();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!account) {
|
|
108
|
+
throw new Error(`Account not found in wallet for address: ${address}`);
|
|
109
|
+
}
|
|
110
|
+
return account;
|
|
111
|
+
}
|
|
112
|
+
|
|
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,
|
|
129
|
+
publicKey?: string,
|
|
130
|
+
): Promise<AccountManager> {
|
|
131
|
+
let account;
|
|
132
|
+
|
|
133
|
+
salt ??= Fr.ZERO;
|
|
134
|
+
|
|
135
|
+
if (this.db && address) {
|
|
136
|
+
({ type, secretKey, salt } = await this.db.retrieveAccount(address));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!secretKey) {
|
|
140
|
+
throw new Error('Cannot retrieve/create wallet without secret key');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
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;
|
|
155
|
+
}
|
|
156
|
+
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');
|
|
171
|
+
}
|
|
172
|
+
account = await this.createAccount(secretKey, salt, new EcdsaRSSHAccountContract(publicSigningKey));
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
default: {
|
|
176
|
+
throw new Error(`Unsupported account type: ${type}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return account;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private async getFakeAccountDataFor(address: AztecAddress) {
|
|
184
|
+
const chainInfo = await this.getChainInfo();
|
|
185
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
186
|
+
const originalAddress = originalAccount.getCompleteAddress();
|
|
187
|
+
const { contractInstance } = await this.pxe.getContractMetadata(originalAddress.address);
|
|
188
|
+
if (!contractInstance) {
|
|
189
|
+
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
190
|
+
}
|
|
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
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
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);
|
|
207
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
208
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
209
|
+
txNonce: Fr.random(),
|
|
210
|
+
cancellable: this.cancellableTransactions,
|
|
211
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
212
|
+
};
|
|
213
|
+
const finalExecutionPayload = feeExecutionPayload
|
|
214
|
+
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
215
|
+
: executionPayload;
|
|
216
|
+
|
|
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
|
+
);
|
|
233
|
+
} else {
|
|
234
|
+
const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(opts.from);
|
|
235
|
+
const txRequest = await fromAccount.createTxExecutionRequest(
|
|
236
|
+
finalExecutionPayload,
|
|
237
|
+
feeOptions.gasSettings,
|
|
238
|
+
executionOptions,
|
|
239
|
+
);
|
|
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
|
+
}
|
|
247
|
+
|
|
248
|
+
if (opts.fee?.estimateGas) {
|
|
249
|
+
const limits = getGasLimits(simulationResults, opts.fee?.estimatedGasPadding);
|
|
250
|
+
printGasEstimates(feeOptions, limits, this.userLog);
|
|
251
|
+
}
|
|
252
|
+
return simulationResults;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
256
|
+
// this is just a CLI wallet.
|
|
257
|
+
getContracts(): Promise<AztecAddress[]> {
|
|
258
|
+
return this.pxe.getContracts();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Exposed because of the `aztec-wallet get-tx` command. It has been decided that it's fine to keep around because
|
|
262
|
+
// this is just a CLI wallet.
|
|
263
|
+
getNotes(filter: NotesFilter): Promise<NoteDao[]> {
|
|
264
|
+
return this.pxe.debug.getNotes(filter);
|
|
265
|
+
}
|
|
266
|
+
}
|
package/dest/cmds/cancel_tx.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type AccountWalletWithSecretKey, type FeePaymentMethod, type TxHash } from '@aztec/aztec.js';
|
|
2
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
-
import type { LogFn } from '@aztec/foundation/log';
|
|
4
|
-
import { GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
5
|
-
export declare function cancelTx(wallet: AccountWalletWithSecretKey, { txHash, gasSettings: prevTxGasSettings, txNonce, cancellable, }: {
|
|
6
|
-
txHash: TxHash;
|
|
7
|
-
gasSettings: GasSettings;
|
|
8
|
-
txNonce: Fr;
|
|
9
|
-
cancellable: boolean;
|
|
10
|
-
}, paymentMethod: FeePaymentMethod, increasedFees: GasFees, maxFeesPerGas: GasFees | undefined, log: LogFn): Promise<void>;
|
|
11
|
-
//# sourceMappingURL=cancel_tx.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cancel_tx.d.ts","sourceRoot":"","sources":["../../src/cmds/cancel_tx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,KAAK,gBAAgB,EAAU,KAAK,MAAM,EAAY,MAAM,iBAAiB,CAAC;AAGxH,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIzD,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,0BAA0B,EAClC,EACE,MAAM,EACN,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EACP,WAAW,GACZ,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;IAAC,WAAW,EAAE,OAAO,CAAA;CAAE,EAClF,aAAa,EAAE,gBAAgB,EAC/B,aAAa,EAAE,OAAO,EACtB,aAAa,EAAE,OAAO,GAAG,SAAS,EAClC,GAAG,EAAE,KAAK,iBA6CX"}
|