@owlprotocol/contracts-account-abstraction
Version:
ERC4337 Account Abstraction support for deploying relevant smart contracts and interacting with UserOps.
40 lines (39 loc) • 1.13 kB
JavaScript
import { estimateFeesPerGas } from "viem/actions";
import { getAction } from "viem/utils";
async function getUserOperationGasPrice(client) {
const eip1559 = client.eip1559 ?? client.chain?.custom?.eip1559 ?? false;
const gasPrice = await getAction(
client,
estimateFeesPerGas,
"estimateFeesPerGas"
)({
type: eip1559 === false ? "legacy" : "eip1559",
chain: client.chain
});
if (gasPrice.gasPrice) {
const userOperationGasPrice = {
maxFeePerGas: gasPrice.gasPrice,
maxPriorityFeePerGas: gasPrice.gasPrice
};
return {
slow: userOperationGasPrice,
standard: userOperationGasPrice,
fast: userOperationGasPrice
};
} else if (gasPrice.maxFeePerGas && gasPrice.maxPriorityFeePerGas) {
const userOperationGasPrice = {
maxFeePerGas: gasPrice.maxFeePerGas,
maxPriorityFeePerGas: gasPrice.maxPriorityFeePerGas
};
return {
slow: userOperationGasPrice,
standard: userOperationGasPrice,
fast: userOperationGasPrice
};
} else {
throw new Error("Invalid gas fee estimate");
}
}
export {
getUserOperationGasPrice
};