rubic-sdk
Version:
Simplify dApp creation
42 lines • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCrossChainGasData = void 0;
const web3_pure_1 = require("../../../../core/blockchain/web3-pure/web3-pure");
const injector_1 = require("../../../../core/injector/injector");
const convert_gas_price_1 = require("./convert-gas-price");
const getCrossChainGasData = async (trade, receiverAddress) => {
try {
const fromBlockchain = trade.from.blockchain;
const walletAddress = injector_1.Injector.web3PrivateService.getWeb3PrivateByBlockchain(fromBlockchain).address;
if (!walletAddress) {
return null;
}
const web3Public = injector_1.Injector.web3PublicService.getWeb3Public(fromBlockchain);
const tx = await trade.encode({
receiverAddress: receiverAddress,
fromAddress: walletAddress,
useCacheData: true,
skipAmountCheck: true
});
const [gasLimit, gasDetails] = await Promise.all([
web3Public.getEstimatedGasByData(walletAddress, tx.to, {
data: tx.data,
value: String(tx.value)
}),
injector_1.Injector.gasPriceApi.getGasPrice(fromBlockchain).then(gas => (0, convert_gas_price_1.convertGasDataToBN)(gas))
]);
if (!gasLimit?.isFinite()) {
return null;
}
const increasedGasLimit = web3_pure_1.Web3Pure.calculateGasMargin(gasLimit, 1.2);
return {
gasLimit: increasedGasLimit,
...gasDetails
};
}
catch {
return null;
}
};
exports.getCrossChainGasData = getCrossChainGasData;
//# sourceMappingURL=get-cross-chain-gas-data.js.map