Skip to content

Instantly share code, notes, and snippets.

@oneleo
Created May 20, 2024 07:30
Show Gist options
  • Save oneleo/8bac154b55b2308f8e5e8d9ddf760f0c to your computer and use it in GitHub Desktop.
Save oneleo/8bac154b55b2308f8e5e8d9ddf760f0c to your computer and use it in GitHub Desktop.
estimateGasLimit
// ...
function UserOperationConfirmation(props: { userOpLog: UserOperationLog }) {
// ...
// TODO: Put it into a dedicated module
const estimateGasFee = async () => {
const fee = await provider.getFeeData()
const gasPriceWithBuffer = (fee.gasPrice * 120n) / 100n
// TODO: maxFeePerGas and maxPriorityFeePerGas too low error
return {
maxFeePerGas: gasPriceWithBuffer,
maxPriorityFeePerGas: gasPriceWithBuffer
}
}
const estimateGasLimit = async () => {
const fee: {
callGasLimit: bigint
verificationGasLimit: bigint
preVerificationGas: bigint
} = await provider.send(WaalletRpcMethod.eth_estimateUserOperationGas, [
userOp.data()
])
const callGasLimitWithBuffer =
(number.toBigInt(fee.callGasLimit) * 300n) / 100n
const verificationGasLimitWithBuffer =
(number.toBigInt(fee.verificationGasLimit) * 300n) / 100n
const preVerificationGasWithBuffer =
(number.toBigInt(fee.preVerificationGas) * 300n) / 100n
return {
callGasLimit: callGasLimitWithBuffer,
verificationGasLimit: verificationGasLimitWithBuffer,
preVerificationGas: preVerificationGasWithBuffer
}
}
const onPaymentOptionSelected = async (o: PaymentOption) => {
// ...
userOp.setGasFee(await estimateGasFee())
userOp.setGasLimit(await estimateGasLimit())
// ...
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment