@@ -565,34 +565,39 @@ const _minutesFromNow = (minutes: number) =>
565565 * @param populatedTransaction The transaction with estimated gas from RPC.
566566 * @param resendCount The resend attempt #. Example: 2 = the transaction was initially sent, then resent once. This is the second resend attempt.
567567 */
568- export const _updateGasFees = (
568+ export function _updateGasFees (
569569 populatedTransaction : PopulatedTransaction ,
570570 resendCount : number ,
571571 overrides : SentTransaction [ "overrides" ] ,
572- ) : PopulatedTransaction => {
572+ ) : PopulatedTransaction {
573573 if ( resendCount === 0 ) {
574574 return populatedTransaction ;
575575 }
576576
577- const multiplier = BigInt ( Math . min ( 10 , resendCount * 2 ) ) ;
578-
577+ const multiplier = Math . min ( 10 , resendCount * 2 ) ;
579578 const updated = { ...populatedTransaction } ;
580579
581580 // Update gas fees (unless they were explicitly overridden).
581+ // Do not exceed MAX_GAS_PRICE_WEI.
582+ const MAX_GAS_PRICE_WEI = env . EXPERIMENTAL__MAX_GAS_PRICE_WEI ;
582583
583- if ( updated . gasPrice && ! overrides ?. gasPrice ) {
584- updated . gasPrice *= multiplier ;
584+ if ( updated . gasPrice ) {
585+ const newGasPrice = Number ( updated . gasPrice ) * multiplier ;
586+ updated . gasPrice = BigInt ( Math . min ( newGasPrice , MAX_GAS_PRICE_WEI ) ) ;
585587 }
586588 if ( updated . maxPriorityFeePerGas && ! overrides ?. maxPriorityFeePerGas ) {
587- updated . maxPriorityFeePerGas *= multiplier ;
589+ updated . maxPriorityFeePerGas *= BigInt ( multiplier ) ;
588590 }
589591 if ( updated . maxFeePerGas && ! overrides ?. maxFeePerGas ) {
590- updated . maxFeePerGas =
591- updated . maxFeePerGas * 2n + ( updated . maxPriorityFeePerGas ?? 0n ) ;
592+ const maxPriorityFeePerGas = updated . maxPriorityFeePerGas ?? 0n ;
593+ const newMaxFeePerGas = Number (
594+ updated . maxFeePerGas * 2n + maxPriorityFeePerGas ,
595+ ) ;
596+ updated . maxFeePerGas = BigInt ( Math . min ( newMaxFeePerGas , MAX_GAS_PRICE_WEI ) ) ;
592597 }
593598
594599 return updated ;
595- } ;
600+ }
596601
597602// Must be explicitly called for the worker to run on this host.
598603export const initSendTransactionWorker = ( ) => {
0 commit comments