UNPKG

rubic-sdk

Version:
56 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CoffeSwapTrade = void 0; const errors_1 = require("../../../../../../common/utils/errors"); const web3_pure_1 = require("../../../../../../core/blockchain/web3-pure/web3-pure"); const on_chain_trade_type_1 = require("../../common/models/on-chain-trade-type"); const ton_on_chain_trade_1 = require("../../common/on-chain-trade/ton-on-chain-trade/ton-on-chain-trade"); const coffee_swap_api_service_1 = require("./services/coffee-swap-api-service"); class CoffeSwapTrade extends ton_on_chain_trade_1.TonOnChainTrade { constructor(tradeStruct, providerAddress) { super(tradeStruct, providerAddress); this.type = on_chain_trade_type_1.ON_CHAIN_TRADE_TYPE.COFFEE_SWAP; this.txSteps = tradeStruct.txSteps; } async swap(options = {}) { let transactionHash; const onTransactionHash = (hash) => { if (options.onConfirm) { options.onConfirm(hash); } transactionHash = hash; }; await this.checkWalletState(options?.testMode); await this.makePreSwapChecks({ fromAddress: this.walletAddress, receiverAddress: options.receiverAddress, skipAmountCheck: this.skipAmountCheck, ...(options?.referrer && { referrer: options?.referrer }) }); const tonConfigs = await this.encodeDirect(); try { await this.web3Private.sendTransaction({ onTransactionHash, messages: tonConfigs }); return transactionHash; } catch (err) { throw (0, errors_1.parseError)(err); } } async encodeDirect() { const tonConfigs = await coffee_swap_api_service_1.CoffeeSwapApiService.fetchTonEncodedConfigs(this.walletAddress, this.slippageTolerance, this.txSteps); return tonConfigs; } async calculateOutputAmount(options) { const newQuote = await coffee_swap_api_service_1.CoffeeSwapApiService.fetchQuote({ srcToken: this.from, dstToken: this.to, walletAddress: options.fromAddress }); return web3_pure_1.Web3Pure.toWei(newQuote.output_amount, this.to.decimals); } } exports.CoffeSwapTrade = CoffeSwapTrade; //# sourceMappingURL=coffe-swap-on-chain-trade.js.map