UNPKG

rubic-sdk

Version:
52 lines 2.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StonfiOnChainTrade = void 0; const errors_1 = require("../../../../../../common/utils/errors"); 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 stonfi_api_service_1 = require("./services/stonfi-api-service"); const stonfi_swap_service_1 = require("./services/stonfi-swap-service"); class StonfiOnChainTrade extends ton_on_chain_trade_1.TonOnChainTrade { constructor() { super(...arguments); this.type = on_chain_trade_type_1.ON_CHAIN_TRADE_TYPE.STONFI; this.stonfiSwapService = new stonfi_swap_service_1.StonfiSwapService(); } 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 tonEncodedConfig = await this.encodeDirect(); try { await this.web3Private.sendTransaction({ onTransactionHash, messages: [tonEncodedConfig] }); return transactionHash; } catch (err) { throw (0, errors_1.parseError)(err); } } async encodeDirect() { const tonConfig = this.stonfiSwapService.getTxParams(this.from, this.to, this.walletAddress, this.toTokenAmountMin.stringWeiAmount); return tonConfig; } async calculateOutputAmount(_options) { const { amountOutWei } = await stonfi_api_service_1.StonfiApiService.makeQuoteRequest(this.from, this.to, this.slippageTolerance); return amountOutWei; } } exports.StonfiOnChainTrade = StonfiOnChainTrade; //# sourceMappingURL=stonfi-on-chain-trade.js.map