From 7cf7a0166641bbd28ae20e136d25777da1a2dc26 Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Thu, 9 Jan 2025 13:29:03 +0000 Subject: [PATCH 1/2] use highest gasValues when validating --- src/handlers/gasPriceManager.ts | 21 +++++++++++++++++++++ src/utils/validation.ts | 12 +++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/handlers/gasPriceManager.ts b/src/handlers/gasPriceManager.ts index 40618c20..ac903a5b 100644 --- a/src/handlers/gasPriceManager.ts +++ b/src/handlers/gasPriceManager.ts @@ -432,6 +432,27 @@ export class GasPriceManager { return maxBaseFeePerGas } + public async getHighestMaxFeePerGas(): Promise { + let highestMaxFeePerGas = this.maxFeePerGasQueue.getMaxValue() + if (!highestMaxFeePerGas) { + const gasPrice = await this.getGasPrice() + highestMaxFeePerGas = gasPrice.maxFeePerGas + } + + return highestMaxFeePerGas + } + + public async getHighestMaxPriorityFeePerGas(): Promise { + let highestMaxPriorityFeePerGas = + this.maxPriorityFeePerGasQueue.getMaxValue() + if (!highestMaxPriorityFeePerGas) { + const gasPrice = await this.getGasPrice() + highestMaxPriorityFeePerGas = gasPrice.maxPriorityFeePerGas + } + + return highestMaxPriorityFeePerGas + } + private async getMinMaxFeePerGas(): Promise { let minMaxFeePerGas = this.maxFeePerGasQueue.getMinValue() if (!minMaxFeePerGas) { diff --git a/src/utils/validation.ts b/src/utils/validation.ts index a29cdb59..386735b2 100644 --- a/src/utils/validation.ts +++ b/src/utils/validation.ts @@ -628,9 +628,15 @@ export async function calcOptimismPreVerificationGas( op.maxFeePerGas = gasPrices.maxFeePerGas } - const l2MaxFee = op.maxFeePerGas - - const l2PriorityFee = baseFeePerGas + op.maxPriorityFeePerGas + const l2MaxFee = validate + ? await gasPriceManager.getHighestMaxFeePerGas() + : op.maxFeePerGas + + const l2PriorityFee = + baseFeePerGas + + (validate + ? await gasPriceManager.getHighestMaxPriorityFeePerGas() + : op.maxPriorityFeePerGas) const l2price = minBigInt(l2MaxFee, l2PriorityFee) From 8a12743cd45c58898504e0d89cc5cf7d6fd6b8a4 Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Thu, 9 Jan 2025 20:55:34 +0000 Subject: [PATCH 2/2] use getL1FeeMin --- src/handlers/gasPriceManager.ts | 3 +++ src/handlers/optimismManager.ts | 17 +++++++++++++++++ src/utils/validation.ts | 8 +++++++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/handlers/optimismManager.ts diff --git a/src/handlers/gasPriceManager.ts b/src/handlers/gasPriceManager.ts index 40618c20..22eeed52 100644 --- a/src/handlers/gasPriceManager.ts +++ b/src/handlers/gasPriceManager.ts @@ -18,6 +18,7 @@ import type { AltoConfig } from "../createConfig" import { SlidingWindowTimedQueue } from "../utils/slidingWindowTimedQueue" import { ArbitrumManager } from "./arbitrumGasPriceManager" import { MantleManager } from "./mantleGasPriceManager" +import { OptimismManager } from "./optimismManager" enum ChainId { Goerli = 5, @@ -48,6 +49,7 @@ export class GasPriceManager { public arbitrumManager: ArbitrumManager public mantleManager: MantleManager + public optimismManager: OptimismManager constructor(config: AltoConfig) { this.config = config @@ -79,6 +81,7 @@ export class GasPriceManager { this.arbitrumManager = new ArbitrumManager(queueValidity) this.mantleManager = new MantleManager(queueValidity) + this.optimismManager = new OptimismManager(queueValidity) } public init() { diff --git a/src/handlers/optimismManager.ts b/src/handlers/optimismManager.ts new file mode 100644 index 00000000..12b5d033 --- /dev/null +++ b/src/handlers/optimismManager.ts @@ -0,0 +1,17 @@ +import { SlidingWindowTimedQueue } from "../utils/slidingWindowTimedQueue" + +export class OptimismManager { + private l1FeeQueue: SlidingWindowTimedQueue + + constructor(queueValidity: number) { + this.l1FeeQueue = new SlidingWindowTimedQueue(queueValidity) + } + + public getMinL1Fee() { + return this.l1FeeQueue.getMinValue() || 1n + } + + public saveL1FeeValue(l1Fee: bigint) { + this.l1FeeQueue.saveValue(l1Fee) + } +} diff --git a/src/utils/validation.ts b/src/utils/validation.ts index a29cdb59..6ae8ca01 100644 --- a/src/utils/validation.ts +++ b/src/utils/validation.ts @@ -615,12 +615,18 @@ export async function calcOptimismPreVerificationGas( }) const [l1Fee, baseFeePerGas] = await Promise.all([ - opGasPriceOracle.read.getL1Fee([serializedTx]), + validate + ? gasPriceManager.optimismManager.getMinL1Fee() + : opGasPriceOracle.read.getL1Fee([serializedTx]), validate ? gasPriceManager.getMaxBaseFeePerGas() : gasPriceManager.getBaseFee() ]) + if (!validate) { + gasPriceManager.optimismManager.saveL1FeeValue(l1Fee) + } + if (op.maxFeePerGas <= 1n || op.maxPriorityFeePerGas <= 1n) { // if user didn't provide gasPrice values, fetch current going price rate const gasPrices = await gasPriceManager.getGasPrice()