@@ -5,7 +5,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
55import type { LogFn } from '@aztec/foundation/log' ;
66import type { FieldsOf } from '@aztec/foundation/types' ;
77import { 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' ;
99import type { FeeOptions } from '@aztec/wallet-sdk/base-wallet' ;
1010
1111import { 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