UNPKG

rubic-sdk

Version:
57 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OwlToApiService = void 0; const errors_1 = require("../../../../../../common/errors"); const blockchain_1 = require("../../../../../../common/utils/blockchain"); const tx_status_1 = require("../../../../../../core/blockchain/web3-public-service/web3-public/models/tx-status"); const injector_1 = require("../../../../../../core/injector/injector"); class OwlToApiService { static async getPairInfo(srcChainId, srcTokenAddress, dstChainId, dstTokenAddress) { const { data } = await injector_1.Injector.httpClient.post(`${this.apiUrl}/get_all_pair_infos`, { category: 'Mainnet', value_include_gas_fee: true }); const pair = data.pair_infos.find(data => (0, blockchain_1.compareAddresses)(srcTokenAddress, data.from_token_address) && (0, blockchain_1.compareAddresses)(dstTokenAddress, data.to_token_address) && srcChainId.toString() === data.from_chain_id && dstChainId.toString() === data.to_chain_id); if (!pair) { throw new errors_1.NotSupportedTokensError(); } return pair; } static async getSwapInfo(p) { const { data } = await injector_1.Injector.httpClient.post(`${this.apiUrl}/get_build_tx`, { channel: 828566, from_address: p.walletAddress, to_address: p.receiverAddress, from_chain_name: p.srcChainName, to_chain_name: p.dstChainName, token_name: p.tokenSymbol, ui_value: p.amount, value_include_gas_fee: true }); if (!data.txs) { throw new errors_1.NotSupportedTokensError(); } return data; } static async getTxStatus(srcTxHash) { const { data } = await injector_1.Injector.httpClient.post(`${this.apiUrl}/get_receipt`, { from_chain_hash: srcTxHash }); if (data?.to_chain_hash) { return { status: tx_status_1.TX_STATUS.SUCCESS, hash: data.to_chain_hash }; } return { status: tx_status_1.TX_STATUS.PENDING, hash: null }; } } exports.OwlToApiService = OwlToApiService; OwlToApiService.apiUrl = 'https://owlto.finance/bridge_api/v1'; //# sourceMappingURL=owl-to-api-service.js.map