@aut-labs/sdk
Version:
The TS/JS SDK package aims to make it easy for frontends/backends to integrate with Aut Smart Contracts
52 lines • 2.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOverrides = void 0;
const logger_1 = require("./logger");
const logger = (0, logger_1.getLogger)();
const getOverrides = async (signer, percentageIncrease = 4000, gasLimit = 4000000, maxPriorityFeePerGas = 1500000000) => {
const provider = signer.provider;
let _maxPriorityFeePerGas = BigInt(maxPriorityFeePerGas); // 1.5 Gwei
let gasPrice = BigInt(0);
// Try to get fee data
try {
const feeData = await provider.getFeeData();
if (feeData.maxFeePerGas == null || feeData.maxPriorityFeePerGas == null) {
gasPrice = BigInt(feeData.gasPrice);
}
else {
_maxPriorityFeePerGas = BigInt(feeData.maxPriorityFeePerGas);
}
}
catch (error) {
logger.warn("Fee data could not be retrieved, using default values:", error);
}
const percentageMultiplier = BigInt(100 + percentageIncrease);
const hundred = BigInt(100);
let adjustedMaxPriorityFeePerGas = (_maxPriorityFeePerGas * percentageMultiplier) / hundred;
let adjustedMaxFeePerGas = adjustedMaxPriorityFeePerGas;
if (gasPrice > BigInt(0)) {
adjustedMaxFeePerGas = (gasPrice * percentageMultiplier) / hundred;
adjustedMaxPriorityFeePerGas = adjustedMaxFeePerGas;
}
else {
const latestBlock = await provider.getBlock("latest");
const baseFeePerGas = BigInt(latestBlock.baseFeePerGas || 0);
adjustedMaxFeePerGas = baseFeePerGas + adjustedMaxPriorityFeePerGas;
// Ensure adjustedMaxFeePerGas is at least baseFeePerGas + adjustedMaxPriorityFeePerGas
const minRequiredMaxFeePerGas = baseFeePerGas + adjustedMaxPriorityFeePerGas;
if (adjustedMaxFeePerGas < minRequiredMaxFeePerGas) {
adjustedMaxFeePerGas = minRequiredMaxFeePerGas;
}
}
const overrides = {
maxPriorityFeePerGas: adjustedMaxPriorityFeePerGas,
maxFeePerGas: adjustedMaxFeePerGas,
gasLimit: BigInt(gasLimit)
};
for (const key in overrides) {
logger.log(`${key}: ${overrides[key].toString()}`);
}
return overrides;
};
exports.getOverrides = getOverrides;
//# sourceMappingURL=transaction-overrides.js.map