Skip to content

Commit

Permalink
No need to have complete userOp succeed
Browse files Browse the repository at this point in the history
  • Loading branch information
plusminushalf committed Nov 19, 2023
1 parent 10f6f98 commit bb62a3b
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions packages/utils/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
getFunctionSelector,
serializeTransaction,
toBytes,
toHex
toHex,
bytesToHex
} from "viem"

export interface GasOverheads {
Expand Down Expand Up @@ -193,14 +194,27 @@ const getL1FeeAbi = [
}
] as const

// Assuming you have a function to generate random bytes
function randomBytes(length: number): Uint8Array {
const bytes = new Uint8Array(length)
window.crypto.getRandomValues(bytes)
return bytes
}

export async function calcOptimismPreVerificationGas(
publicClient: PublicClient<Transport, Chain | undefined>,
op: UserOperation,
entryPoint: Address,
staticFee: bigint
_staticFee: bigint
) {
const randomDataUserOp: UserOperation = {
...op,
signature: bytesToHex(randomBytes(op.signature.length)),
paymasterAndData: bytesToHex(randomBytes(op.paymasterAndData.length))
}

const selector = getFunctionSelector(EntryPointAbi[27])
const paramData = encodeAbiParameters(EntryPointAbi[27].inputs, [[op], entryPoint])
const paramData = encodeAbiParameters(EntryPointAbi[27].inputs, [[randomDataUserOp], entryPoint])
const data = concat([selector, paramData])

const latestBlock = await publicClient.getBlock()
Expand Down Expand Up @@ -237,7 +251,7 @@ export async function calcOptimismPreVerificationGas(

const l2price = l2MaxFee < l2PriorityFee ? l2MaxFee : l2PriorityFee

return staticFee + l1Fee / l2price
return l1Fee / l2price
}

const getArbitrumL1FeeAbi = [
Expand Down Expand Up @@ -326,17 +340,20 @@ export function parseViemError(err: unknown) {
const e = err.cause
if (e instanceof NonceTooLowError) {
return e
} else if (e instanceof FeeCapTooLowError) {
}
if (e instanceof FeeCapTooLowError) {
return e
} else if (e instanceof InsufficientFundsError) {
}
if (e instanceof InsufficientFundsError) {
return e
} else if (e instanceof IntrinsicGasTooLowError) {
}
if (e instanceof IntrinsicGasTooLowError) {
return e
} else if (e instanceof ContractFunctionRevertedError) {
}
if (e instanceof ContractFunctionRevertedError) {
return e
}
return
} else {
return
}
return
}

0 comments on commit bb62a3b

Please sign in to comment.