rubic-sdk
Version:
Simplify dApp creation
66 lines • 3.02 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CrossChainProvider = void 0;
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const errors_1 = require("../../../../../common/utils/errors");
const blockchains_info_1 = require("../../../../../core/blockchain/utils/blockchains-info/blockchains-info");
const injector_1 = require("../../../../../core/injector/injector");
class CrossChainProvider {
static parseError(err) {
return (0, errors_1.parseError)(err, 'Cannot calculate cross-chain trade');
}
get httpClient() {
return injector_1.Injector.httpClient;
}
areSupportedBlockchains(fromBlockchain, toBlockchain) {
return (this.isSupportedBlockchain(fromBlockchain) && this.isSupportedBlockchain(toBlockchain));
}
getFromWeb3Public(fromBlockchain) {
return injector_1.Injector.web3PublicService.getWeb3Public(fromBlockchain);
}
getWalletAddress(blockchain) {
return injector_1.Injector.web3PrivateService.getWeb3PrivateByBlockchain(blockchain).address;
}
/**
* Gets fee information.
* @param _fromBlockchain Source network blockchain.
* @param _providerAddress Integrator address.
* @param _percentFeeToken Protocol fee token.
* @param _useProxy Use rubic proxy or not.
* @param _contractAbi Rubic Proxy contract abi.
* @protected
* @internal
*/
async getFeeInfo(_fromBlockchain, _providerAddress, _percentFeeToken, _useProxy, _contractAbi) {
return {};
}
async getGasData(from, gasData = {}) {
try {
if (!gasData.gasLimit && !gasData.totalGas)
return null;
if (!blockchains_info_1.BlockchainsInfo.isEvmBlockchainName(from.blockchain))
return null;
const gasPriceInfo = await injector_1.Injector.gasPriceApi.getGasPrice(from.blockchain);
return {
...(gasData.totalGas && { totalGas: new bignumber_js_1.default(gasData.totalGas) }),
...(gasData.gasLimit && { gasLimit: new bignumber_js_1.default(gasData.gasLimit) }),
...(gasPriceInfo.gasPrice && { gasPrice: new bignumber_js_1.default(gasPriceInfo.gasPrice) }),
...(gasPriceInfo.baseFee && { baseFee: new bignumber_js_1.default(gasPriceInfo.baseFee) }),
...(gasPriceInfo.maxFeePerGas && {
maxFeePerGas: new bignumber_js_1.default(gasPriceInfo.maxFeePerGas)
}),
...(gasPriceInfo.maxPriorityFeePerGas && {
maxPriorityFeePerGas: new bignumber_js_1.default(gasPriceInfo.maxPriorityFeePerGas)
})
};
}
catch {
return null;
}
}
}
exports.CrossChainProvider = CrossChainProvider;
//# sourceMappingURL=cross-chain-provider.js.map