Skip to content

Commit

Permalink
save only op gas values
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless0x committed Jan 11, 2025
1 parent f96b8d3 commit 8ae5f1b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
36 changes: 19 additions & 17 deletions src/handlers/optimismManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@ import { Address, maxUint256 } from "viem"
import { SlidingWindowTimedQueue } from "../utils/slidingWindowTimedQueue"

class GasQueues {
private l2PriorityFeeQueue: SlidingWindowTimedQueue
private l2MaxFeeQueue: SlidingWindowTimedQueue
private opMaxPriorityFeeQueue: SlidingWindowTimedQueue
private opMaxFeeQueue: SlidingWindowTimedQueue
public lastAccessed: number

constructor(queueValidity: number) {
this.lastAccessed = Date.now()
this.l2PriorityFeeQueue = new SlidingWindowTimedQueue(queueValidity)
this.l2MaxFeeQueue = new SlidingWindowTimedQueue(queueValidity)
this.opMaxPriorityFeeQueue = new SlidingWindowTimedQueue(queueValidity)
this.opMaxFeeQueue = new SlidingWindowTimedQueue(queueValidity)
}

private access() {
this.lastAccessed = Date.now()
}

public getMaxL2PriorityFee() {
public getHighestMaxPriorityFee() {
this.access()
return this.l2PriorityFeeQueue.getMaxValue()
return this.opMaxPriorityFeeQueue.getMaxValue()
}

public getMaxL2MaxFee() {
public getHighestMaxFee() {
this.access()
return this.l2MaxFeeQueue.getMaxValue()
return this.opMaxFeeQueue.getMaxValue()
}

public saveValues(values: { l2MaxFee: bigint; l2PriorityFee: bigint }) {
public saveValues(values: { opMaxFee: bigint; opMaxPriorityFee: bigint }) {
this.access()
this.l2MaxFeeQueue.saveValue(values.l2MaxFee)
this.l2PriorityFeeQueue.saveValue(values.l2PriorityFee)
this.opMaxFeeQueue.saveValue(values.opMaxFee)
this.opMaxPriorityFeeQueue.saveValue(values.opMaxPriorityFee)
}
}

Expand Down Expand Up @@ -71,12 +71,14 @@ export class OptimismManager {
return this.l1FeeQueue.getMinValue() || 1n
}

public getMaxL2PriorityFee(sender: Address) {
return this.getOrCreate(sender)?.getMaxL2PriorityFee() || maxUint256
public getHighestMaxPriorityFee(sender: Address) {
return (
this.getOrCreate(sender)?.getHighestMaxPriorityFee() || maxUint256
)
}

public getMaxL2MaxFee(sender: Address) {
return this.getOrCreate(sender)?.getMaxL2MaxFee() || maxUint256
public getHighestMaxFee(sender: Address) {
return this.getOrCreate(sender)?.getHighestMaxFee() || maxUint256
}

public saveOptimismValues({
Expand All @@ -87,8 +89,8 @@ export class OptimismManager {
l1Fee: bigint
sender: Address
values: {
l2MaxFee: bigint
l2PriorityFee: bigint
opMaxFee: bigint
opMaxPriorityFee: bigint
}
}) {
this.l1FeeQueue.saveValue(l1Fee)
Expand Down
12 changes: 6 additions & 6 deletions src/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,19 +636,19 @@ export async function calcOptimismPreVerificationGas(
let l2MaxFee
let l2PriorityFee
if (validate) {
l2MaxFee = gasPriceManager.optimismManager.getMaxL2MaxFee(op.sender)
l2PriorityFee = gasPriceManager.optimismManager.getMaxL2PriorityFee(
op.sender
)
l2MaxFee = gasPriceManager.optimismManager.getHighestMaxFee(op.sender)
l2PriorityFee =
baseFeePerGas +
gasPriceManager.optimismManager.getHighestMaxPriorityFee(op.sender)
} else {
l2MaxFee = op.maxFeePerGas
l2PriorityFee = baseFeePerGas + op.maxPriorityFeePerGas
gasPriceManager.optimismManager.saveOptimismValues({
l1Fee,
sender: op.sender,
values: {
l2MaxFee,
l2PriorityFee
opMaxFee: op.maxFeePerGas,
opMaxPriorityFee: op.maxPriorityFeePerGas
}
})
}
Expand Down

0 comments on commit 8ae5f1b

Please sign in to comment.