UNPKG

rubic-sdk-next

Version:
50 lines 2.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ApiCrossChainTransferTrade = void 0; const core_1 = require("@cryptorubic/core"); const bignumber_js_1 = __importDefault(require("bignumber.js")); const cross_chain_transfer_trade_1 = require("../../../cross-chain/calculation-manager/providers/common/cross-chain-transfer-trade/cross-chain-transfer-trade"); class ApiCrossChainTransferTrade extends cross_chain_transfer_trade_1.CrossChainTransferTrade { constructor(tradeParams) { super(tradeParams.apiQuote.integratorAddress, tradeParams.routePath, null, tradeParams.from, tradeParams.to, core_1.Token.fromWei(tradeParams.apiResponse.estimate.destinationWeiMinAmount, tradeParams.to.decimals), null, tradeParams.feeInfo, tradeParams.from.calculatePriceImpactPercent(tradeParams.to), tradeParams.apiQuote, tradeParams.apiResponse); this.onChainSubtype = { from: undefined, to: undefined }; this.type = tradeParams.apiResponse.providerType; this.bridgeType = tradeParams.apiResponse.providerType; } getTradeInfo() { return { estimatedGas: this.estimatedGas, feeInfo: this.feeInfo, priceImpact: this.priceImpact ?? null, slippage: this.onChainTrade?.slippageTolerance ? this.onChainTrade.slippageTolerance * 100 : 0, routePath: this.routePath }; } async getPaymentInfo(receiverAddress, testMode, fromAddress, refundAddress) { const swapRequestData = { ...this.apiQuote, receiver: receiverAddress, id: this.apiResponse.id, enableChecks: !testMode, ...(fromAddress && { fromAddress }), ...(refundAddress && { refundAddress }) }; const { estimate, transaction } = await this.fetchSwapData(swapRequestData); const amount = estimate.destinationTokenAmount; this.actualTokenAmount = new bignumber_js_1.default(amount); return { toAmount: amount, id: transaction.exchangeId, depositAddress: transaction.depositAddress, depositExtraId: transaction.extraFields?.value, depositExtraIdName: transaction.extraFields?.name }; } } exports.ApiCrossChainTransferTrade = ApiCrossChainTransferTrade; //# sourceMappingURL=api-cross-chain-transfer-trade.js.map