From 51fdd7233f55dcaac1e8cfb6dd18401dda7404c9 Mon Sep 17 00:00:00 2001
From: mous <97399882+mouseless0x@users.noreply.github.com>
Date: Sat, 11 Jan 2025 15:28:09 +0000
Subject: [PATCH] save userOp's gasPrices when calculating PVG (#402)

* use bundler's gasPrices when calculating pvg

* revert

* calculate pvg using bundler gasPrices

---------

Co-authored-by: mouseless <97399882+mouseless-eth@users.noreply.github.com>
---
 src/utils/validation.ts | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/src/utils/validation.ts b/src/utils/validation.ts
index acfdb245..4dd0cbff 100644
--- a/src/utils/validation.ts
+++ b/src/utils/validation.ts
@@ -626,27 +626,20 @@ export async function calcOptimismPreVerificationGas(
             : gasPriceManager.getBaseFee()
     ])
 
-    if (!validate) {
-        gasPriceManager.optimismManager.saveL1FeeValue(l1Fee)
-    }
+    let l2MaxFee: bigint
+    let l2PriorityFee: bigint
 
-    if (op.maxFeePerGas <= 1n || op.maxPriorityFeePerGas <= 1n) {
-        // if user didn't provide gasPrice values, fetch current going price rate
+    if (validate) {
+        l2MaxFee = await gasPriceManager.getHighestMaxFeePerGas()
+        l2PriorityFee =
+            baseFeePerGas +
+            (await gasPriceManager.getHighestMaxPriorityFeePerGas())
+    } else {
         const gasPrices = await gasPriceManager.getGasPrice()
-        op.maxPriorityFeePerGas = gasPrices.maxPriorityFeePerGas
-        op.maxFeePerGas = gasPrices.maxFeePerGas
+        l2MaxFee = gasPrices.maxFeePerGas
+        l2PriorityFee = baseFeePerGas + gasPrices.maxPriorityFeePerGas
     }
 
-    const l2MaxFee = validate
-        ? await gasPriceManager.getHighestMaxFeePerGas()
-        : op.maxFeePerGas
-
-    const l2PriorityFee =
-        baseFeePerGas +
-        (validate
-            ? await gasPriceManager.getHighestMaxPriorityFeePerGas()
-            : op.maxPriorityFeePerGas)
-
     const l2price = minBigInt(l2MaxFee, l2PriorityFee)
 
     return staticFee + l1Fee / l2price