Skip to content

Commit 192de2f

Browse files
spalladinoclaude
andcommitted
fix(cli-wallet): use predicted fees instead of current fees
Addresses PR #22116 review comment 11: CLI wallet was bypassing the fee prediction system by calling getCurrentMinFees directly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent cbb04c3 commit 192de2f

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

  • yarn-project/cli-wallet/src/utils/options

yarn-project/cli-wallet/src/utils/options/fees.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
55
import type { LogFn } from '@aztec/foundation/log';
66
import type { FieldsOf } from '@aztec/foundation/types';
77
import { AztecAddress } from '@aztec/stdlib/aztec-address';
8-
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
8+
import { Gas, GasFees, GasSettings, ManaUsageEstimate } from '@aztec/stdlib/gas';
99
import type { FeeOptions } from '@aztec/wallet-sdk/base-wallet';
1010

1111
import { Option } from 'commander';
@@ -257,7 +257,8 @@ export class CLIFeeArgs {
257257
) {}
258258

259259
async toUserFeeOptions(node: AztecNode, wallet: Wallet, from: AztecAddress): Promise<ParsedFeeOptions> {
260-
const maxFeesPerGas = (await node.getCurrentMinFees()).mul(1 + MIN_FEE_PADDING);
260+
const minFees = await this.getMinFees(node);
261+
const maxFeesPerGas = minFees.mul(1 + MIN_FEE_PADDING);
261262
const gasSettings = GasSettings.default({ ...this.gasSettings, maxFeesPerGas });
262263
const paymentMethod = await this.paymentMethod(wallet, from, gasSettings);
263264
return {
@@ -266,6 +267,27 @@ export class CLIFeeArgs {
266267
};
267268
}
268269

270+
/**
271+
* Returns the worst-case min fee across predicted future slots.
272+
* Falls back to getCurrentMinFees if the node doesn't support getPredictedMinFees.
273+
*/
274+
private async getMinFees(node: AztecNode): Promise<GasFees> {
275+
try {
276+
const predicted = await node.getPredictedMinFees(ManaUsageEstimate.Limit);
277+
if (predicted.length === 0) {
278+
return node.getCurrentMinFees();
279+
}
280+
return predicted.reduce((worst, fees) => (fees.feePerL2Gas > worst.feePerL2Gas ? fees : worst));
281+
} catch (err: any) {
282+
// Fallback for old nodes that don't support getPredictedMinFees.
283+
// Only fall back on method-not-found errors (JSON-RPC code -32601); rethrow others.
284+
if (err?.cause?.code === -32601 || err?.message?.includes('Method not found')) {
285+
return node.getCurrentMinFees();
286+
}
287+
throw err;
288+
}
289+
}
290+
269291
static parse(args: RawCliFeeArgs, log: LogFn, db?: WalletDB): CLIFeeArgs {
270292
const estimateOnly = !!args.estimateGasOnly;
271293
return new CLIFeeArgs(

0 commit comments

Comments
 (0)