@etherspot/remote-signer
Version:
Etherspot Permissioned Signer SDK - signs the UserOp with SessionKey and sends it to the Bundler
41 lines (39 loc) • 1.2 kB
JavaScript
import {
BigNumber
} from "./chunk-Q4Z2NTL2.mjs";
import {
bufferPercent
} from "./chunk-FIVOBZYI.mjs";
// src/sdk/common/getGasFee.ts
async function getGasFee(publicClient) {
try {
const gasFeeResponse = await publicClient.request(
{
method: "eth_maxPriorityFeePerGas",
params: []
}
);
if (!gasFeeResponse) {
throw new Error("failed to get priorityFeePerGas");
}
const [fee, block] = gasFeeResponse;
if (BigNumber.from(0).eq(fee)) {
throw new Error("failed to get priorityFeePerGas");
}
const tip = BigNumber.from(fee);
const buffer = tip.div(100).mul(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 publicClient.getGasPrice();
return { maxFeePerGas: gas, maxPriorityFeePerGas: gas };
}
}
export {
getGasFee
};
//# sourceMappingURL=chunk-SKQVU7ST.mjs.map