@aztec/cli-wallet 0.0.0-test.1 → 0.0.1-commit.b655e406
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.js +48 -26
- package/dest/cmds/authorize_action.d.ts +3 -2
- package/dest/cmds/authorize_action.d.ts.map +1 -1
- package/dest/cmds/authorize_action.js +8 -4
- package/dest/cmds/bridge_fee_juice.d.ts +2 -2
- package/dest/cmds/bridge_fee_juice.d.ts.map +1 -1
- package/dest/cmds/bridge_fee_juice.js +8 -7
- package/dest/cmds/check_tx.d.ts +4 -2
- package/dest/cmds/check_tx.d.ts.map +1 -1
- package/dest/cmds/check_tx.js +145 -6
- package/dest/cmds/create_account.d.ts +6 -5
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +46 -27
- package/dest/cmds/create_authwit.d.ts +3 -2
- package/dest/cmds/create_authwit.d.ts.map +1 -1
- package/dest/cmds/create_authwit.js +5 -5
- package/dest/cmds/deploy.d.ts +6 -3
- package/dest/cmds/deploy.d.ts.map +1 -1
- package/dest/cmds/deploy.js +71 -54
- package/dest/cmds/deploy_account.d.ts +5 -7
- package/dest/cmds/deploy_account.d.ts.map +1 -1
- package/dest/cmds/deploy_account.js +46 -29
- package/dest/cmds/import_test_accounts.d.ts +2 -2
- 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 +2 -2
- package/dest/cmds/index.d.ts.map +1 -1
- package/dest/cmds/index.js +83 -115
- package/dest/cmds/profile.d.ts +8 -0
- package/dest/cmds/profile.d.ts.map +1 -0
- package/dest/cmds/profile.js +28 -0
- package/dest/cmds/register_contract.d.ts +6 -2
- package/dest/cmds/register_contract.d.ts.map +1 -1
- package/dest/cmds/register_contract.js +20 -7
- package/dest/cmds/register_sender.d.ts +3 -2
- package/dest/cmds/register_sender.d.ts.map +1 -1
- package/dest/cmds/send.d.ts +7 -8
- package/dest/cmds/send.d.ts.map +1 -1
- package/dest/cmds/send.js +31 -20
- package/dest/cmds/simulate.d.ts +6 -2
- package/dest/cmds/simulate.d.ts.map +1 -1
- package/dest/cmds/simulate.js +25 -19
- package/dest/storage/wallet_db.d.ts +4 -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 +6 -0
- package/dest/utils/authorizations.d.ts.map +1 -0
- package/dest/utils/authorizations.js +28 -0
- 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 +0 -2
- package/dest/utils/ecdsa.d.ts.map +1 -1
- package/dest/utils/options/fees.d.ts +20 -27
- package/dest/utils/options/fees.d.ts.map +1 -1
- package/dest/utils/options/fees.js +85 -144
- package/dest/utils/options/options.d.ts +8 -4
- package/dest/utils/options/options.d.ts.map +1 -1
- package/dest/utils/options/options.js +26 -14
- package/dest/utils/profiling.d.ts +5 -0
- package/dest/utils/profiling.d.ts.map +1 -0
- package/dest/utils/profiling.js +60 -0
- package/dest/utils/wallet.d.ts +35 -0
- package/dest/utils/wallet.d.ts.map +1 -0
- package/dest/utils/wallet.js +193 -0
- package/package.json +24 -20
- package/src/bin/index.ts +56 -32
- package/src/cmds/authorize_action.ts +15 -4
- package/src/cmds/bridge_fee_juice.ts +14 -11
- package/src/cmds/check_tx.ts +182 -5
- package/src/cmds/create_account.ts +55 -32
- package/src/cmds/create_authwit.ts +8 -4
- package/src/cmds/deploy.ts +79 -62
- package/src/cmds/deploy_account.ts +57 -28
- package/src/cmds/import_test_accounts.ts +7 -11
- package/src/cmds/index.ts +256 -220
- package/src/cmds/profile.ts +48 -0
- package/src/cmds/register_contract.ts +28 -5
- package/src/cmds/register_sender.ts +3 -2
- package/src/cmds/send.ts +31 -17
- package/src/cmds/simulate.ts +39 -23
- package/src/storage/wallet_db.ts +3 -31
- package/src/utils/authorizations.ts +51 -0
- package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
- package/src/utils/options/fees.ts +134 -206
- package/src/utils/options/options.ts +41 -19
- package/src/utils/profiling.ts +158 -0
- package/src/utils/wallet.ts +264 -0
- package/dest/cmds/add_authwit.d.ts +0 -4
- package/dest/cmds/add_authwit.d.ts.map +0 -1
- package/dest/cmds/add_authwit.js +0 -4
- 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 -38
- package/dest/utils/accounts.d.ts +0 -11
- package/dest/utils/accounts.d.ts.map +0 -1
- package/dest/utils/accounts.js +0 -87
- package/dest/utils/pxe_wrapper.d.ts +0 -10
- package/dest/utils/pxe_wrapper.d.ts.map +0 -1
- package/dest/utils/pxe_wrapper.js +0 -21
- package/src/cmds/add_authwit.ts +0 -13
- package/src/cmds/cancel_tx.ts +0 -62
- package/src/utils/accounts.ts +0 -102
- package/src/utils/pxe_wrapper.ts +0 -26
|
@@ -1,67 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
FeeJuicePaymentMethod,
|
|
5
|
-
type FeePaymentMethod,
|
|
6
|
-
type PXE,
|
|
7
|
-
type SendMethodOptions,
|
|
8
|
-
} from '@aztec/aztec.js';
|
|
1
|
+
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
2
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
3
|
+
import type { FeeOptions, Wallet } from '@aztec/aztec.js/wallet';
|
|
9
4
|
import { Fr } from '@aztec/foundation/fields';
|
|
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';
|
|
13
9
|
|
|
14
10
|
import { Option } from 'commander';
|
|
15
11
|
|
|
16
12
|
import type { WalletDB } from '../../storage/wallet_db.js';
|
|
17
|
-
import {
|
|
13
|
+
import { BASE_FEE_PADDING } from '../wallet.js';
|
|
18
14
|
import { aliasedAddressParser } from './options.js';
|
|
19
15
|
|
|
20
|
-
export type
|
|
16
|
+
export type RawCliFeeArgs = {
|
|
21
17
|
estimateGasOnly: boolean;
|
|
22
18
|
gasLimits?: string;
|
|
23
19
|
payment?: string;
|
|
24
20
|
maxFeesPerGas?: string;
|
|
25
21
|
maxPriorityFeesPerGas?: string;
|
|
26
|
-
estimateGas?: boolean;
|
|
27
22
|
};
|
|
28
23
|
|
|
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
|
-
}
|
|
24
|
+
export type ParsedFeeOptions = {
|
|
25
|
+
paymentMethod?: FeePaymentMethod;
|
|
26
|
+
gasSettings?: Partial<FieldsOf<GasSettings>>;
|
|
27
|
+
};
|
|
65
28
|
|
|
66
29
|
type OptionParams = {
|
|
67
30
|
[key: string]: { type: string; description?: string; default?: string };
|
|
@@ -77,21 +40,23 @@ function printOptionParams(params: OptionParams) {
|
|
|
77
40
|
params[name].default ? `Default: ${params[name].default}` : '',
|
|
78
41
|
].join(' '),
|
|
79
42
|
);
|
|
80
|
-
return descriptionList.length
|
|
43
|
+
return descriptionList.length
|
|
44
|
+
? `\n Parameters:\n${descriptionList.join('\n')}\nFormat: --payment ${Object.keys(params)
|
|
45
|
+
.slice(0, 3)
|
|
46
|
+
.map(name => `${name}=${params[name].type}`)} ${Object.keys(params).length > 3 ? '...' : ''}`
|
|
47
|
+
: '';
|
|
81
48
|
}
|
|
82
49
|
|
|
83
|
-
function getFeePaymentMethodParams(
|
|
84
|
-
const feePayer = allowCustomFeePayer ? { type: 'address', description: 'The account paying the fee.' } : undefined;
|
|
50
|
+
function getFeePaymentMethodParams(): OptionParams {
|
|
85
51
|
return {
|
|
86
52
|
method: {
|
|
87
53
|
type: 'name',
|
|
88
|
-
description: 'Valid values: "fee_juice", "fpc-public", "fpc-private"
|
|
54
|
+
description: 'Valid values: "fee_juice", "fpc-public", "fpc-private", "fpc-sponsored"',
|
|
89
55
|
default: 'fee_juice',
|
|
90
56
|
},
|
|
91
|
-
...(feePayer ? { feePayer } : {}),
|
|
92
57
|
asset: {
|
|
93
58
|
type: 'address',
|
|
94
|
-
description: 'The asset used for fee payment.
|
|
59
|
+
description: 'The asset used for fee payment. Required for "fpc-public" and "fpc-private".',
|
|
95
60
|
},
|
|
96
61
|
fpc: {
|
|
97
62
|
type: 'address',
|
|
@@ -113,167 +78,67 @@ function getFeePaymentMethodParams(allowCustomFeePayer: boolean): OptionParams {
|
|
|
113
78
|
type: 'bigint',
|
|
114
79
|
description: 'The index of the claim in the l1toL2Message tree.',
|
|
115
80
|
},
|
|
116
|
-
feeRecipient: {
|
|
117
|
-
type: 'string',
|
|
118
|
-
description: 'Recipient of the fee.',
|
|
119
|
-
},
|
|
120
81
|
};
|
|
121
82
|
}
|
|
122
83
|
|
|
123
|
-
function getPaymentMethodOption(
|
|
124
|
-
const params = getFeePaymentMethodParams(
|
|
125
|
-
|
|
126
|
-
return new Option(
|
|
127
|
-
`--payment <${paramList.join(',')}>`,
|
|
128
|
-
`Fee payment method and arguments.${printOptionParams(params)}`,
|
|
129
|
-
);
|
|
84
|
+
export function getPaymentMethodOption() {
|
|
85
|
+
const params = getFeePaymentMethodParams();
|
|
86
|
+
return new Option(`--payment <options>`, `Fee payment method and arguments.${printOptionParams(params)}`);
|
|
130
87
|
}
|
|
131
88
|
|
|
132
|
-
function getFeeOptions(
|
|
89
|
+
function getFeeOptions() {
|
|
133
90
|
return [
|
|
134
|
-
getPaymentMethodOption(
|
|
91
|
+
getPaymentMethodOption(),
|
|
135
92
|
new Option('--gas-limits <da=100,l2=100,teardownDA=10,teardownL2=10>', 'Gas limits for the tx.'),
|
|
136
93
|
new Option('--max-fees-per-gas <da=100,l2=100>', 'Maximum fees per gas unit for DA and L2 computation.'),
|
|
137
94
|
new Option(
|
|
138
95
|
'--max-priority-fees-per-gas <da=0,l2=0>',
|
|
139
96
|
'Maximum priority fees per gas unit for DA and L2 computation.',
|
|
140
97
|
),
|
|
141
|
-
new Option('--no-estimate-gas', 'Whether to automatically estimate gas limits for the tx.'),
|
|
142
98
|
new Option('--estimate-gas-only', 'Only report gas estimation for the tx, do not send it.'),
|
|
143
99
|
];
|
|
144
100
|
}
|
|
145
101
|
|
|
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
|
-
fee: {
|
|
161
|
-
estimateGas: this.estimateGas,
|
|
162
|
-
gasSettings: this.gasSettings,
|
|
163
|
-
paymentMethod: await this.paymentMethodFactory(sender),
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
async toDeployAccountOpts(sender: AccountWallet): Promise<DeployAccountOptions> {
|
|
169
|
-
const paymentMethod = await this.paymentMethodFactory(sender);
|
|
170
|
-
const deployWallet = await this.getDeployWallet(sender, paymentMethod);
|
|
171
|
-
return {
|
|
172
|
-
deployWallet,
|
|
173
|
-
fee: {
|
|
174
|
-
estimateGas: this.estimateGas,
|
|
175
|
-
gasSettings: this.gasSettings,
|
|
176
|
-
paymentMethod,
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
static paymentMethodOption() {
|
|
182
|
-
return getPaymentMethodOption(false);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
static getOptions() {
|
|
186
|
-
return getFeeOptions(false);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
static async fromCli(args: CliFeeArgs, pxe: PXE, log: LogFn, db?: WalletDB) {
|
|
190
|
-
const estimateOnly = args.estimateGasOnly;
|
|
191
|
-
const gasSettings = await parseGasSettings(args, pxe);
|
|
192
|
-
|
|
193
|
-
const defaultPaymentMethod = async (sender: AccountWallet) => {
|
|
194
|
-
const { FeeJuicePaymentMethod } = await import('@aztec/aztec.js/fee');
|
|
195
|
-
return new FeeJuicePaymentMethod(sender.getAddress());
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
const getDeployWallet = () => {
|
|
199
|
-
// Returns undefined. The sender's wallet will be used by default.
|
|
200
|
-
return Promise.resolve(undefined);
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
return new FeeOpts(
|
|
204
|
-
estimateOnly,
|
|
205
|
-
gasSettings,
|
|
206
|
-
args.payment ? parsePaymentMethod(args.payment, false, log, db) : defaultPaymentMethod,
|
|
207
|
-
getDeployWallet,
|
|
208
|
-
!!args.estimateGas,
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export class FeeOptsWithFeePayer extends FeeOpts {
|
|
214
|
-
static override paymentMethodOption() {
|
|
215
|
-
return getPaymentMethodOption(true);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
static override getOptions() {
|
|
219
|
-
return getFeeOptions(true);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
static override async fromCli(args: CliFeeArgs, pxe: PXE, log: LogFn, db?: WalletDB) {
|
|
223
|
-
const estimateOnly = args.estimateGasOnly;
|
|
224
|
-
const gasSettings = await parseGasSettings(args, pxe);
|
|
225
|
-
|
|
226
|
-
const defaultPaymentMethod = async (sender: AccountWallet) => {
|
|
227
|
-
const { FeeJuicePaymentMethod } = await import('@aztec/aztec.js/fee');
|
|
228
|
-
return new FeeJuicePaymentMethod(sender.getAddress());
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const getDeployWallet = async (sender: AccountWallet, paymentMethod: FeePaymentMethod) => {
|
|
232
|
-
if (paymentMethod instanceof FeeJuicePaymentMethod) {
|
|
233
|
-
const feePayer = await paymentMethod.getFeePayer();
|
|
234
|
-
if (!sender.getAddress().equals(feePayer)) {
|
|
235
|
-
return (await createOrRetrieveAccount(pxe, feePayer, db)).getWallet();
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return undefined;
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
return new FeeOptsWithFeePayer(
|
|
242
|
-
estimateOnly,
|
|
243
|
-
gasSettings,
|
|
244
|
-
args.payment ? parsePaymentMethod(args.payment, true, log, db) : defaultPaymentMethod,
|
|
245
|
-
getDeployWallet,
|
|
246
|
-
!!args.estimateGas,
|
|
247
|
-
);
|
|
248
|
-
}
|
|
102
|
+
function parseGasSettings(args: RawCliFeeArgs): Partial<FieldsOf<GasSettings>> {
|
|
103
|
+
const gasLimits = args.gasLimits ? parseGasLimits(args.gasLimits) : {};
|
|
104
|
+
const maxFeesPerGas = args.maxFeesPerGas ? parseGasFees(args.maxFeesPerGas) : undefined;
|
|
105
|
+
const maxPriorityFeesPerGas = args.maxPriorityFeesPerGas ? parseGasFees(args.maxPriorityFeesPerGas) : undefined;
|
|
106
|
+
return {
|
|
107
|
+
...gasLimits,
|
|
108
|
+
maxFeesPerGas,
|
|
109
|
+
maxPriorityFeesPerGas,
|
|
110
|
+
};
|
|
249
111
|
}
|
|
250
112
|
|
|
251
113
|
export function parsePaymentMethod(
|
|
252
114
|
payment: string,
|
|
253
|
-
allowCustomFeePayer: boolean,
|
|
254
115
|
log: LogFn,
|
|
255
116
|
db?: WalletDB,
|
|
256
|
-
): (
|
|
257
|
-
const parsed = payment.split(',').reduce(
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
117
|
+
): (wallet: Wallet, from: AztecAddress, gasSettings: GasSettings) => Promise<FeePaymentMethod | undefined> {
|
|
118
|
+
const parsed = payment.split(',').reduce(
|
|
119
|
+
(acc, item) => {
|
|
120
|
+
const [dimension, value] = item.split('=');
|
|
121
|
+
acc[dimension] = value ?? 1;
|
|
122
|
+
return acc;
|
|
123
|
+
},
|
|
124
|
+
{} as Record<string, string>,
|
|
125
|
+
);
|
|
262
126
|
|
|
263
|
-
const
|
|
127
|
+
const getFpc = () => {
|
|
264
128
|
if (!parsed.fpc) {
|
|
265
129
|
throw new Error('Missing "fpc" in payment option');
|
|
266
130
|
}
|
|
131
|
+
return aliasedAddressParser('contracts', parsed.fpc, db);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const getAsset = () => {
|
|
267
135
|
if (!parsed.asset) {
|
|
268
136
|
throw new Error('Missing "asset" in payment option');
|
|
269
137
|
}
|
|
270
|
-
|
|
271
|
-
const fpc = aliasedAddressParser('contracts', parsed.fpc, db);
|
|
272
|
-
|
|
273
|
-
return [AztecAddress.fromString(parsed.asset), fpc];
|
|
138
|
+
return AztecAddress.fromString(parsed.asset);
|
|
274
139
|
};
|
|
275
140
|
|
|
276
|
-
return async (
|
|
141
|
+
return async (wallet: Wallet, from: AztecAddress, gasSettings: GasSettings) => {
|
|
277
142
|
switch (parsed.method) {
|
|
278
143
|
case 'fee_juice': {
|
|
279
144
|
if (parsed.claim || (parsed.claimSecret && parsed.claimAmount && parsed.messageLeafIndex)) {
|
|
@@ -283,13 +148,13 @@ export function parsePaymentMethod(
|
|
|
283
148
|
amount: claimAmount,
|
|
284
149
|
secret: claimSecret,
|
|
285
150
|
leafIndex: messageLeafIndex,
|
|
286
|
-
} = await db.popBridgedFeeJuice(
|
|
151
|
+
} = await db.popBridgedFeeJuice(from, log));
|
|
287
152
|
} else {
|
|
288
153
|
({ claimAmount, claimSecret, messageLeafIndex } = parsed);
|
|
289
154
|
}
|
|
290
155
|
log(`Using Fee Juice for fee payments with claim for ${claimAmount} tokens`);
|
|
291
156
|
const { FeeJuicePaymentMethodWithClaim } = await import('@aztec/aztec.js/fee');
|
|
292
|
-
return new FeeJuicePaymentMethodWithClaim(
|
|
157
|
+
return new FeeJuicePaymentMethodWithClaim(from, {
|
|
293
158
|
claimAmount: (typeof claimAmount === 'string'
|
|
294
159
|
? Fr.fromHexString(claimAmount)
|
|
295
160
|
: new Fr(claimAmount)
|
|
@@ -298,26 +163,29 @@ export function parsePaymentMethod(
|
|
|
298
163
|
messageLeafIndex: BigInt(messageLeafIndex),
|
|
299
164
|
});
|
|
300
165
|
} else {
|
|
301
|
-
log(`Using Fee Juice for fee payment`);
|
|
302
|
-
|
|
303
|
-
const feePayer =
|
|
304
|
-
parsed.feePayer && allowCustomFeePayer
|
|
305
|
-
? aliasedAddressParser('accounts', parsed.feePayer, db)
|
|
306
|
-
: sender.getAddress();
|
|
307
|
-
return new FeeJuicePaymentMethod(feePayer);
|
|
166
|
+
log(`Using Fee Juice for fee payment with the balance of account ${from}`);
|
|
167
|
+
return;
|
|
308
168
|
}
|
|
309
169
|
}
|
|
310
170
|
case 'fpc-public': {
|
|
311
|
-
const
|
|
171
|
+
const fpc = getFpc();
|
|
172
|
+
const asset = getAsset();
|
|
312
173
|
log(`Using public fee payment with asset ${asset} via paymaster ${fpc}`);
|
|
313
174
|
const { PublicFeePaymentMethod } = await import('@aztec/aztec.js/fee');
|
|
314
|
-
return new PublicFeePaymentMethod(fpc,
|
|
175
|
+
return new PublicFeePaymentMethod(fpc, from, wallet, gasSettings);
|
|
315
176
|
}
|
|
316
177
|
case 'fpc-private': {
|
|
317
|
-
const
|
|
178
|
+
const fpc = getFpc();
|
|
179
|
+
const asset = getAsset();
|
|
318
180
|
log(`Using private fee payment with asset ${asset} via paymaster ${fpc}`);
|
|
319
181
|
const { PrivateFeePaymentMethod } = await import('@aztec/aztec.js/fee');
|
|
320
|
-
return new PrivateFeePaymentMethod(fpc,
|
|
182
|
+
return new PrivateFeePaymentMethod(fpc, from, wallet, gasSettings);
|
|
183
|
+
}
|
|
184
|
+
case 'fpc-sponsored': {
|
|
185
|
+
const sponsor = getFpc();
|
|
186
|
+
log(`Using sponsored fee payment with sponsor ${sponsor}`);
|
|
187
|
+
const { SponsoredFeePaymentMethod } = await import('@aztec/aztec.js/fee/testing');
|
|
188
|
+
return new SponsoredFeePaymentMethod(sponsor);
|
|
321
189
|
}
|
|
322
190
|
case undefined:
|
|
323
191
|
throw new Error('Missing "method" in payment option');
|
|
@@ -328,11 +196,14 @@ export function parsePaymentMethod(
|
|
|
328
196
|
}
|
|
329
197
|
|
|
330
198
|
function parseGasLimits(gasLimits: string): { gasLimits: Gas; teardownGasLimits: Gas } {
|
|
331
|
-
const parsed = gasLimits.split(',').reduce(
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
199
|
+
const parsed = gasLimits.split(',').reduce(
|
|
200
|
+
(acc, limit) => {
|
|
201
|
+
const [dimension, value] = limit.split('=');
|
|
202
|
+
acc[dimension] = parseInt(value, 10);
|
|
203
|
+
return acc;
|
|
204
|
+
},
|
|
205
|
+
{} as Record<string, number>,
|
|
206
|
+
);
|
|
336
207
|
|
|
337
208
|
const expected = ['da', 'l2', 'teardownDA', 'teardownL2'];
|
|
338
209
|
for (const dimension of expected) {
|
|
@@ -348,11 +219,14 @@ function parseGasLimits(gasLimits: string): { gasLimits: Gas; teardownGasLimits:
|
|
|
348
219
|
}
|
|
349
220
|
|
|
350
221
|
export function parseGasFees(gasFees: string): GasFees {
|
|
351
|
-
const parsed = gasFees.split(',').reduce(
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
222
|
+
const parsed = gasFees.split(',').reduce(
|
|
223
|
+
(acc, fee) => {
|
|
224
|
+
const [dimension, value] = fee.split('=');
|
|
225
|
+
acc[dimension] = parseInt(value, 10);
|
|
226
|
+
return acc;
|
|
227
|
+
},
|
|
228
|
+
{} as Record<string, number>,
|
|
229
|
+
);
|
|
356
230
|
|
|
357
231
|
const expected = ['da', 'l2'];
|
|
358
232
|
for (const dimension of expected) {
|
|
@@ -363,3 +237,57 @@ export function parseGasFees(gasFees: string): GasFees {
|
|
|
363
237
|
|
|
364
238
|
return new GasFees(parsed.da, parsed.l2);
|
|
365
239
|
}
|
|
240
|
+
export class CLIFeeArgs {
|
|
241
|
+
constructor(
|
|
242
|
+
public estimateOnly: boolean,
|
|
243
|
+
private paymentMethod: (
|
|
244
|
+
wallet: Wallet,
|
|
245
|
+
feePayer: AztecAddress,
|
|
246
|
+
gasSettings: GasSettings,
|
|
247
|
+
) => Promise<FeePaymentMethod | undefined>,
|
|
248
|
+
private gasSettings: Partial<FieldsOf<GasSettings>>,
|
|
249
|
+
) {}
|
|
250
|
+
|
|
251
|
+
async toUserFeeOptions(node: AztecNode, wallet: Wallet, from: AztecAddress): Promise<ParsedFeeOptions> {
|
|
252
|
+
const maxFeesPerGas = (await node.getCurrentBaseFees()).mul(1 + BASE_FEE_PADDING);
|
|
253
|
+
const gasSettings = GasSettings.default({ ...this.gasSettings, maxFeesPerGas });
|
|
254
|
+
const paymentMethod = await this.paymentMethod(wallet, from, gasSettings);
|
|
255
|
+
return {
|
|
256
|
+
paymentMethod,
|
|
257
|
+
gasSettings,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
static parse(args: RawCliFeeArgs, log: LogFn, db?: WalletDB): CLIFeeArgs {
|
|
262
|
+
return new CLIFeeArgs(
|
|
263
|
+
!!args.estimateGasOnly,
|
|
264
|
+
parsePaymentMethod(args.payment ?? 'method=fee_juice', log, db),
|
|
265
|
+
parseGasSettings(args),
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
static getOptions() {
|
|
270
|
+
return getFeeOptions();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Printing
|
|
275
|
+
|
|
276
|
+
export function printGasEstimates(
|
|
277
|
+
feeOpts: FeeOptions,
|
|
278
|
+
gasEstimates: Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>,
|
|
279
|
+
log: LogFn,
|
|
280
|
+
) {
|
|
281
|
+
log(`Estimated gas usage: ${formatGasEstimate(gasEstimates)}`);
|
|
282
|
+
log(`Maximum total tx fee: ${getEstimatedCost(gasEstimates, feeOpts.gasSettings.maxFeesPerGas)}`);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function formatGasEstimate(estimate: Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>) {
|
|
286
|
+
return `da=${estimate.gasLimits.daGas},l2=${estimate.gasLimits.l2Gas},teardownDA=${estimate.teardownGasLimits.daGas},teardownL2=${estimate.teardownGasLimits.l2Gas}`;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function getEstimatedCost(estimate: Pick<GasSettings, 'gasLimits' | 'teardownGasLimits'>, maxFeesPerGas: GasFees) {
|
|
290
|
+
return GasSettings.default({ ...estimate, maxFeesPerGas })
|
|
291
|
+
.getFeeLimit()
|
|
292
|
+
.toBigInt();
|
|
293
|
+
}
|
|
@@ -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,24 +30,28 @@ 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
|
-
} catch
|
|
36
|
+
} catch {
|
|
36
37
|
const prefixed = txHash.includes(':') ? txHash : `transactions:${txHash}`;
|
|
37
38
|
const rawTxHash = db ? db.tryRetrieveAlias(prefixed) : txHash;
|
|
38
39
|
return parseTxHash(rawTxHash);
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
export function aliasedAuthWitParser(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
export function aliasedAuthWitParser(witnesses: string, db?: WalletDB) {
|
|
44
|
+
const parsedWitnesses = witnesses.split(',').map(witness => {
|
|
45
|
+
try {
|
|
46
|
+
return AuthWitness.fromString(witness);
|
|
47
|
+
} catch {
|
|
48
|
+
const prefixed = witness.includes(':') ? witness : `authwits:${witness}`;
|
|
49
|
+
const rawAuthWitness = db ? db.tryRetrieveAlias(prefixed) : witness;
|
|
50
|
+
return AuthWitness.fromString(rawAuthWitness);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return parsedWitnesses;
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
export function aliasedAddressParser(defaultPrefix: AliasType, address: string, db?: WalletDB) {
|
|
@@ -79,6 +84,12 @@ export function createAccountOption(description: string, hide: boolean, db?: Wal
|
|
|
79
84
|
.argParser(address => aliasedAddressParser('accounts', address, db));
|
|
80
85
|
}
|
|
81
86
|
|
|
87
|
+
export function createAuthwitnessOption(description: string, hide: boolean, db?: WalletDB) {
|
|
88
|
+
return new Option('-aw, --auth-witness <string,...>', description)
|
|
89
|
+
.hideHelp(hide)
|
|
90
|
+
.argParser(witness => aliasedAuthWitParser(witness, db));
|
|
91
|
+
}
|
|
92
|
+
|
|
82
93
|
export function createTypeOption(mandatory: boolean) {
|
|
83
94
|
return new Option('-t, --type <string>', 'Type of account to create')
|
|
84
95
|
.choices(AccountTypes)
|
|
@@ -103,6 +114,20 @@ export function createContractAddressOption(db?: WalletDB) {
|
|
|
103
114
|
.makeOptionMandatory(true);
|
|
104
115
|
}
|
|
105
116
|
|
|
117
|
+
export function createDebugExecutionStepsDirOption() {
|
|
118
|
+
return new Option(
|
|
119
|
+
'--debug-execution-steps-dir <address>',
|
|
120
|
+
'Directory to write execution step artifacts for bb profiling/debugging.',
|
|
121
|
+
).makeOptionMandatory(false);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function createVerboseOption() {
|
|
125
|
+
return new Option(
|
|
126
|
+
'-v, --verbose',
|
|
127
|
+
'Provide timings on all executed operations (synching, simulating, proving)',
|
|
128
|
+
).default(false);
|
|
129
|
+
}
|
|
130
|
+
|
|
106
131
|
export function artifactPathParser(filePath: string, db?: WalletDB) {
|
|
107
132
|
if (filePath.includes('@')) {
|
|
108
133
|
const [pkg, contractName] = filePath.split('@');
|
|
@@ -140,18 +165,11 @@ export function createArtifactOption(db?: WalletDB) {
|
|
|
140
165
|
.makeOptionMandatory(false);
|
|
141
166
|
}
|
|
142
167
|
|
|
143
|
-
export function createProfileOption() {
|
|
144
|
-
return new Option(
|
|
145
|
-
'-p, --profile',
|
|
146
|
-
'Run the real prover and get the gate count for each function in the transaction.',
|
|
147
|
-
).default(false);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
168
|
async function contractArtifactFromWorkspace(pkg?: string, contractName?: string) {
|
|
151
169
|
const cwd = process.cwd();
|
|
152
170
|
try {
|
|
153
171
|
await stat(`${cwd}/Nargo.toml`);
|
|
154
|
-
} catch
|
|
172
|
+
} catch {
|
|
155
173
|
throw new Error(
|
|
156
174
|
'Invalid contract artifact argument provided. To use this option, command should be called from a nargo workspace',
|
|
157
175
|
);
|
|
@@ -173,3 +191,7 @@ async function contractArtifactFromWorkspace(pkg?: string, contractName?: string
|
|
|
173
191
|
}
|
|
174
192
|
return `${cwd}/${TARGET_DIR}/${bestMatch[0]}`;
|
|
175
193
|
}
|
|
194
|
+
|
|
195
|
+
export function cleanupAuthWitnesses(authWitnesses: AuthWitness[] | undefined): AuthWitness[] {
|
|
196
|
+
return authWitnesses?.filter(w => w !== undefined) ?? [];
|
|
197
|
+
}
|