@etherspot/prime-sdk
Version:
Etherspot Prime (Account Abstraction) SDK
25 lines (24 loc) • 1.09 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getGasFee = void 0;
const ethers_1 = require("ethers");
const constants_1 = require("./constants");
async function getGasFee(provider) {
try {
const [fee, block] = await provider.send('eth_maxPriorityFeePerGas', []);
if (ethers_1.BigNumber.from(0).eq(fee)) {
throw new Error('failed to get priorityFeePerGas');
}
const tip = ethers_1.ethers.BigNumber.from(fee);
const buffer = tip.div(100).mul(constants_1.bufferPercent);
const maxPriorityFeePerGas = tip.add(buffer);
const maxFeePerGas = block.baseFeePerGas != null ? block.baseFeePerGas.mul(2).add(maxPriorityFeePerGas) : maxPriorityFeePerGas;
return { maxFeePerGas, maxPriorityFeePerGas };
}
catch (err) {
console.warn("getGas: eth_maxPriorityFeePerGas failed, falling back to legacy gas price.");
const gas = await provider.getGasPrice();
return { maxFeePerGas: gas, maxPriorityFeePerGas: gas };
}
}
exports.getGasFee = getGasFee;
;