diff --git a/src/executor/executor.ts b/src/executor/executor.ts index d8e9a96f..5055bc79 100644 --- a/src/executor/executor.ts +++ b/src/executor/executor.ts @@ -147,7 +147,7 @@ export class Executor { ): Promise { const newRequest = { ...transactionInfo.transactionRequest } - const gasPriceParameters = await this.gasPriceManager.latestGasPrice() + const gasPriceParameters = await this.gasPriceManager.networkGasPrice() newRequest.maxFeePerGas = maxBigInt( gasPriceParameters.maxFeePerGas, @@ -489,7 +489,7 @@ export class Executor { const wallets = Array.from(allWallets) - const gasPrice = await this.gasPriceManager.latestGasPrice() + const gasPrice = await this.gasPriceManager.networkGasPrice() const promises = wallets.map((wallet) => { flushStuckTransaction( this.config.publicClient, @@ -648,7 +648,7 @@ export class Executor { }) childLogger.debug("bundling user operation") - const gasPriceParameters = await this.gasPriceManager.latestGasPrice() + const gasPriceParameters = await this.gasPriceManager.networkGasPrice() childLogger.debug({ gasPriceParameters }, "got gas price") const nonce = await this.config.publicClient.getTransactionCount({ @@ -927,7 +927,7 @@ export class Executor { }) childLogger.debug("bundling compressed user operation") - const gasPriceParameters = await this.gasPriceManager.latestGasPrice() + const gasPriceParameters = await this.gasPriceManager.networkGasPrice() childLogger.debug({ gasPriceParameters }, "got gas price") const nonce = await this.config.publicClient.getTransactionCount({ diff --git a/src/executor/executorManager.ts b/src/executor/executorManager.ts index 6e3119b7..7e1db68c 100644 --- a/src/executor/executorManager.ts +++ b/src/executor/executorManager.ts @@ -775,7 +775,7 @@ export class ExecutorManager { await this.refreshUserOperationStatuses() // for all still not included check if needs to be replaced (based on gas price) - const gasPriceParameters = await this.gasPriceManager.latestGasPrice() + const gasPriceParameters = await this.gasPriceManager.networkGasPrice() this.logger.trace( { gasPriceParameters }, "fetched gas price parameters" diff --git a/src/executor/senderManager.ts b/src/executor/senderManager.ts index 221e2b33..59b46be7 100644 --- a/src/executor/senderManager.ts +++ b/src/executor/senderManager.ts @@ -138,7 +138,7 @@ export class SenderManager { if (Object.keys(balancesMissing).length > 0) { const { maxFeePerGas, maxPriorityFeePerGas } = - await this.gasPriceManager.latestGasPrice() + await this.gasPriceManager.networkGasPrice() if (this.config.refillHelperContract) { const instructions = [] diff --git a/src/handlers/gasPriceManager.ts b/src/handlers/gasPriceManager.ts index dfdea910..aced3850 100644 --- a/src/handlers/gasPriceManager.ts +++ b/src/handlers/gasPriceManager.ts @@ -5,7 +5,7 @@ import { } from "@alto/types" import { type Logger, maxBigInt, minBigInt, FixedStack } from "@alto/utils" import * as sentry from "@sentry/node" -import { type PublicClient, parseGwei, Block } from "viem" +import { type PublicClient, parseGwei, Block, toHex } from "viem" import { avalanche, celo, @@ -95,6 +95,7 @@ export class GasPriceManager { return baseFee } + // Returns the latest cached gasPrice. public async latestGasPrice(): Promise { const gasPrice = this.gasPriceStack.peek() @@ -105,6 +106,11 @@ export class GasPriceManager { return gasPrice } + // Actively fetches the network gasPrice instead of using the gasPriceStack cache. + public async networkGasPrice(): Promise { + return await this.innerGetGasPrice() + } + public async getMaxBaseFeePerGas(): Promise { let maxBaseFeePerGas = this.baseFeePerGasStack .toArray() diff --git a/src/utils/dataStructures/fixedStack.ts b/src/utils/dataStructures/fixedStack.ts index a5ec8817..55ff0dbb 100644 --- a/src/utils/dataStructures/fixedStack.ts +++ b/src/utils/dataStructures/fixedStack.ts @@ -18,11 +18,11 @@ export class FixedStack { this.items.push(item) } - pop(): T | null { + pop(): T | undefined { if (this.isEmpty()) { - return null + return undefined } - return this.items.pop()! + return this.items.shift() } peek(): T | null {