UNPKG

rubic-sdk

Version:
100 lines 4.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChangenowCrossChainTrade = void 0; const errors_1 = require("../../../../../common/errors"); const web3_pure_1 = require("../../../../../core/blockchain/web3-pure/web3-pure"); const cross_chain_trade_type_1 = require("../../models/cross-chain-trade-type"); const rubic_proxy_contract_address_1 = require("../common/constants/rubic-proxy-contract-address"); const bridge_type_1 = require("../common/models/bridge-type"); const cross_chain_transfer_trade_1 = require("../common/cross-chain-transfer-trade/cross-chain-transfer-trade"); const changenow_cross_chain_api_service_1 = require("./services/changenow-cross-chain-api-service"); class ChangenowCrossChainTrade extends cross_chain_transfer_trade_1.CrossChainTransferTrade { /** * used in rubic-app to send as changenow_id to backend */ get changenowId() { return this.paymentInfo ? this.paymentInfo.id : ''; } get transitToken() { return this.onChainTrade ? this.onChainTrade.toTokenAmountMin : this.from; } get fromContractAddress() { if (this.isProxyTrade) { return rubic_proxy_contract_address_1.rubicProxyContractAddress[this.from.blockchain].gateway; } throw new errors_1.RubicSdkError('No contract address for changenow provider'); } get estimatedGas() { if (!this.gasData) { return null; } if (this.gasData.baseFee && this.gasData.maxPriorityFeePerGas) { return web3_pure_1.Web3Pure.fromWei(this.gasData.baseFee).plus(web3_pure_1.Web3Pure.fromWei(this.gasData.maxPriorityFeePerGas)); } if (this.gasData.gasPrice) { return web3_pure_1.Web3Pure.fromWei(this.gasData.gasPrice).multipliedBy(this.gasData.gasLimit ?? 0); } return null; } constructor(crossChainTrade, providerAddress, routePath, useProxy) { super({ ...crossChainTrade, providerAddress, useProxy, routePath, priceImpact: null }); this.type = cross_chain_trade_type_1.CROSS_CHAIN_TRADE_TYPE.CHANGENOW; this.bridgeType = bridge_type_1.BRIDGE_TYPE.CHANGENOW; this.fromCurrency = crossChainTrade.fromCurrency; this.toCurrency = crossChainTrade.toCurrency; this.onChainSubtype = crossChainTrade.onChainTrade ? { from: crossChainTrade.onChainTrade.type, to: undefined } : { from: undefined, to: undefined }; this.onChainTrade = crossChainTrade.onChainTrade; } async getPaymentInfo(receiverAddress) { const params = { fromCurrency: this.fromCurrency.ticker, toCurrency: this.toCurrency.ticker, fromNetwork: this.fromCurrency.network, toNetwork: this.toCurrency.network, fromAmount: this.transitToken.tokenAmount.toFixed(), address: receiverAddress, flow: 'standard', payload: { integratorAddress: this.providerAddress } }; const res = await changenow_cross_chain_api_service_1.ChangeNowCrossChainApiService.getSwapTx(params); return { id: res.id, depositAddress: res.payinAddress, toAmount: res.toAmount.toString(), depositExtraId: res.payinExtraId, depositExtraIdName: res.payinExtraIdName }; } getTradeAmountRatio(fromUsd) { return fromUsd.dividedBy(this.to.tokenAmount); } getTradeInfo() { return { estimatedGas: this.estimatedGas, feeInfo: this.feeInfo, priceImpact: this.priceImpact ?? null, slippage: this.onChainTrade?.slippageTolerance ? this.onChainTrade.slippageTolerance * 100 : 0, routePath: this.routePath }; } /** * @deprecated Use getTransferTrade instead */ getChangenowPostTrade(receiverAddress) { return super.getTransferTrade(receiverAddress); } } exports.ChangenowCrossChainTrade = ChangenowCrossChainTrade; //# sourceMappingURL=changenow-cross-chain-trade.js.map