Created
May 20, 2024 07:30
-
-
Save oneleo/8bac154b55b2308f8e5e8d9ddf760f0c to your computer and use it in GitHub Desktop.
estimateGasLimit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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