UNPKG

rubic-sdk

Version:
64 lines 2.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RangoBitcoinCrossChainTrade = void 0; const errors_1 = require("../../../../../../common/errors"); const bitcoin_cross_chain_trade_1 = require("../../common/bitcoin-cross-chain-trade/bitcoin-cross-chain-trade"); const cross_chain_trade_type_1 = require("../../../models/cross-chain-trade-type"); const bridge_type_1 = require("../../common/models/bridge-type"); const rango_cross_chain_api_service_1 = require("../services/rango-cross-chain-api-service"); class RangoBitcoinCrossChainTrade extends bitcoin_cross_chain_trade_1.BitcoinCrossChainTrade { get fromBlockchain() { return this.from.blockchain; } get fromContractAddress() { throw new Error('Method not supported'); } get methodName() { throw new Error('Method not supported'); } constructor(params) { super(params.providerAddress, params.routePath, params.useProxy); this.type = cross_chain_trade_type_1.CROSS_CHAIN_TRADE_TYPE.RANGO; this.isAggregator = true; this.onChainSubtype = { from: undefined, to: undefined }; this.bridgeType = bridge_type_1.BRIDGE_TYPE.RANGO; this.to = params.crossChainTrade.to; this.from = params.crossChainTrade.from; this.toTokenAmountMin = params.crossChainTrade.toTokenAmountMin; this.feeInfo = params.crossChainTrade.feeInfo; this.gasData = params.crossChainTrade.gasData; this.priceImpact = params.crossChainTrade.priceImpact; this.slippage = params.crossChainTrade.slippage; this.swapQueryParams = params.crossChainTrade.swapQueryParams; this.bridgeType = params.crossChainTrade.bridgeSubtype || bridge_type_1.BRIDGE_TYPE.RANGO; this.memo = params.crossChainTrade.memo; } async getTransactionConfigAndAmount(receiverAddress) { const { route, tx, error, requestId } = await rango_cross_chain_api_service_1.RangoCrossChainApiService.getSwapTransaction({ ...this.swapQueryParams, toAddress: receiverAddress || this.swapQueryParams.toAddress }); this.rangoRequestId = requestId; if (!route || !tx) { throw new errors_1.RubicSdkError('Invalid data after sending swap request. Error text:' + error); } const { recipientAddress, memo } = tx; const config = { value: this.from.stringWeiAmount, to: recipientAddress, data: memo }; return { config, amount: route.outputAmount }; } getTradeInfo() { return { estimatedGas: this.estimatedGas, feeInfo: this.feeInfo, priceImpact: this.priceImpact || null, slippage: this.slippage * 100, routePath: this.routePath }; } } exports.RangoBitcoinCrossChainTrade = RangoBitcoinCrossChainTrade; //# sourceMappingURL=rango-bitcoin-cross-chain-trade.js.map