1- import { type Job , type Processor , Worker } from "bullmq" ;
1+ import { Worker , type Job , type Processor } from "bullmq" ;
22import assert from "node:assert" ;
33import superjson from "superjson" ;
44import {
5- type Hex ,
65 getAddress ,
76 getContract ,
87 readContract ,
98 toSerializableTransaction ,
9+ type Hex ,
1010} from "thirdweb" ;
1111import { stringify } from "thirdweb/utils" ;
1212import {
13- type UserOperation ,
1413 bundleUserOp ,
1514 createAndSignUserOp ,
15+ type UserOperation ,
1616} from "thirdweb/wallets/smart" ;
1717import { getContractAddress } from "viem" ;
1818import { TransactionDB } from "../../db/transactions/db" ;
@@ -33,6 +33,7 @@ import {
3333 prettifyError ,
3434 prettifyTransactionError ,
3535} from "../../utils/error" ;
36+ import { clamp } from "../../utils/math" ;
3637import { getChecksumAddress } from "../../utils/primitiveTypes" ;
3738import { recordMetrics } from "../../utils/prometheus" ;
3839import { redis } from "../../utils/redis/redis" ;
@@ -48,8 +49,8 @@ import { reportUsage } from "../../utils/usage";
4849import { MineTransactionQueue } from "../queues/mineTransactionQueue" ;
4950import { logWorkerExceptions } from "../queues/queues" ;
5051import {
51- type SendTransactionData ,
5252 SendTransactionQueue ,
53+ type SendTransactionData ,
5354} from "../queues/sendTransactionQueue" ;
5455
5556/**
@@ -400,18 +401,20 @@ const _resendTransaction = async (
400401 } ,
401402 } ) ;
402403
403- // Double gas fee settings if they were not provded in `overrides`.
404+ // Double the gas fee settings each attempt up to 10x.
405+ // Do not update gas if overrides were provided.
406+ const gasMultiple = BigInt ( clamp ( job . attemptsMade * 2 , { min : 2 , max : 10 } ) ) ;
404407 if ( populatedTransaction . gasPrice ) {
405- populatedTransaction . gasPrice *= 2n ;
408+ populatedTransaction . gasPrice *= gasMultiple ;
406409 }
407410 if ( populatedTransaction . maxFeePerGas && ! overrides ?. maxFeePerGas ) {
408- populatedTransaction . maxFeePerGas *= 2n ;
411+ populatedTransaction . maxFeePerGas *= gasMultiple ;
409412 }
410413 if (
411414 populatedTransaction . maxPriorityFeePerGas &&
412415 ! overrides ?. maxPriorityFeePerGas
413416 ) {
414- populatedTransaction . maxPriorityFeePerGas *= 2n ;
417+ populatedTransaction . maxPriorityFeePerGas *= gasMultiple ;
415418 }
416419
417420 job . log ( `Populated transaction: ${ stringify ( populatedTransaction ) } ` ) ;
0 commit comments