@aztec/cli-wallet 0.0.1-fake-ceab37513c → 0.0.2-commit.217f559981
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 +2 -1
- package/dest/bin/index.js +39 -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 +8 -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 +148 -6
- package/dest/cmds/create_account.d.ts +8 -6
- package/dest/cmds/create_account.d.ts.map +1 -1
- package/dest/cmds/create_account.js +56 -62
- 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 +84 -50
- 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 +56 -65
- 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 +46 -31
- package/dest/cmds/simulate.d.ts +7 -4
- package/dest/cmds/simulate.d.ts.map +1 -1
- package/dest/cmds/simulate.js +12 -7
- 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 +48 -54
- 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/constants.d.ts +4 -0
- package/dest/utils/constants.d.ts.map +1 -0
- package/dest/utils/constants.js +7 -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 +3 -2
- 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/profiling.d.ts.map +1 -1
- package/dest/utils/profiling.js +9 -1
- package/dest/utils/wallet.d.ts +40 -0
- package/dest/utils/wallet.d.ts.map +1 -0
- package/dest/utils/wallet.js +208 -0
- package/package.json +17 -14
- package/src/bin/index.ts +39 -31
- package/src/cmds/authorize_action.ts +14 -6
- package/src/cmds/bridge_fee_juice.ts +15 -11
- package/src/cmds/check_tx.ts +180 -5
- package/src/cmds/create_account.ts +63 -66
- package/src/cmds/create_authwit.ts +9 -5
- package/src/cmds/deploy.ts +82 -61
- package/src/cmds/deploy_account.ts +62 -64
- 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 +42 -40
- package/src/cmds/simulate.ts +17 -12
- package/src/storage/wallet_db.ts +52 -67
- package/src/utils/authorizations.ts +3 -1
- package/src/utils/cli_wallet_and_node_wrapper.ts +35 -0
- package/src/utils/constants.ts +4 -0
- package/src/utils/options/fees.ts +88 -178
- package/src/utils/options/options.ts +3 -2
- package/src/utils/profiling.ts +15 -1
- package/src/utils/wallet.ts +290 -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 '../constants.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 '../constants.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 {
|
package/src/utils/profiling.ts
CHANGED
|
@@ -95,7 +95,7 @@ export function printProfileResult(
|
|
|
95
95
|
|
|
96
96
|
if (stats.nodeRPCCalls) {
|
|
97
97
|
log(format('\nRPC calls:\n'));
|
|
98
|
-
for (const [method, { times }] of Object.entries(stats.nodeRPCCalls)) {
|
|
98
|
+
for (const [method, { times }] of Object.entries(stats.nodeRPCCalls.perMethod)) {
|
|
99
99
|
const calls = times.length;
|
|
100
100
|
const total = times.reduce((acc, time) => acc + time, 0);
|
|
101
101
|
const avg = total / calls;
|
|
@@ -112,6 +112,20 @@ export function printProfileResult(
|
|
|
112
112
|
),
|
|
113
113
|
);
|
|
114
114
|
}
|
|
115
|
+
|
|
116
|
+
const { roundTrips } = stats.nodeRPCCalls;
|
|
117
|
+
log(format('\nRound trips (actual blocking waits):\n'));
|
|
118
|
+
log(format('Round trips:'.padEnd(25), `${roundTrips.roundTrips}`.padStart(COLUMN_MAX_WIDTH)));
|
|
119
|
+
log(
|
|
120
|
+
format(
|
|
121
|
+
'Total blocking time:'.padEnd(25),
|
|
122
|
+
`${roundTrips.totalBlockingTime.toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH),
|
|
123
|
+
),
|
|
124
|
+
);
|
|
125
|
+
if (roundTrips.roundTrips > 0) {
|
|
126
|
+
const avgRoundTrip = roundTrips.totalBlockingTime / roundTrips.roundTrips;
|
|
127
|
+
log(format('Avg round trip:'.padEnd(25), `${avgRoundTrip.toFixed(2)}ms`.padStart(COLUMN_MAX_WIDTH)));
|
|
128
|
+
}
|
|
115
129
|
}
|
|
116
130
|
|
|
117
131
|
log(format('\nSync time:'.padEnd(25), `${timings.sync?.toFixed(2)}ms`.padStart(16)));
|