@devasher/kuru-sdk
Version:
Ethers v6 SDK to interact with Kuru (forked from @kuru-labs/kuru-sdk)
48 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const ethers_1 = require("ethers");
async function buildTransactionRequest({ from, to, signer, data, value, txOptions, }) {
const tx = {
to,
from,
data,
value,
...((txOptions === null || txOptions === void 0 ? void 0 : txOptions.nonce) !== undefined && { nonce: txOptions.nonce }),
...((txOptions === null || txOptions === void 0 ? void 0 : txOptions.gasLimit) && { gasLimit: txOptions.gasLimit }),
...((txOptions === null || txOptions === void 0 ? void 0 : txOptions.gasPrice) && { gasPrice: txOptions.gasPrice }),
...((txOptions === null || txOptions === void 0 ? void 0 : txOptions.maxFeePerGas) && {
maxFeePerGas: txOptions.maxFeePerGas,
}),
...((txOptions === null || txOptions === void 0 ? void 0 : txOptions.maxPriorityFeePerGas) && {
maxPriorityFeePerGas: txOptions.maxPriorityFeePerGas,
}),
};
console.log('estimateGas', tx.gasLimit);
console.log('gasPrice', tx.gasPrice);
const [gasLimit, baseGasPrice] = await Promise.all([
!tx.gasLimit
? signer.estimateGas({
...tx,
gasPrice: (0, ethers_1.parseUnits)('1', 'gwei'),
})
: Promise.resolve(tx.gasLimit),
!tx.gasPrice && !tx.maxFeePerGas && signer.provider
? signer.provider.getFeeData().then((fee) => fee.gasPrice)
: Promise.resolve(undefined),
]);
if (!tx.gasLimit) {
tx.gasLimit = gasLimit;
}
if (!tx.gasPrice && !tx.maxFeePerGas && baseGasPrice) {
if (txOptions === null || txOptions === void 0 ? void 0 : txOptions.priorityFee) {
const priorityFeeWei = (0, ethers_1.parseUnits)(txOptions.priorityFee.toString(), 'gwei');
tx.gasPrice = baseGasPrice + priorityFeeWei;
}
else {
tx.gasPrice = baseGasPrice;
}
}
return tx;
}
exports.default = buildTransactionRequest;
//# sourceMappingURL=txConfig.js.map