UNPKG

@alcorexchange/alcor-swap-sdk

Version:

## Installation ​​ **npm** ``` npm i @alcorexchange/alcor-swap-sdk ``` **yarn** ``` yarn add @alcorexchange/alcor-swap-sdk ``` ## Usage ### Import:

22 lines (18 loc) 748 B
const workerpool = require('workerpool') const { CurrencyAmount, Pool, Route, Trade, TradeType } = require('./build/index.js') async function processRoute(routeBuffer, splitAmount, tradeType, percent) { const route = Route.fromBuffer(routeBuffer); try { const { outputAmount } = Trade.fromRoute(route, CurrencyAmount.fromRawAmount(route.input, '10000000'), TradeType.EXACT_INPUT, 100); return { outputAmount: outputAmount.quotient.toString() }; } catch (error) { if (error.isInsufficientReservesError || error.isInsufficientInputAmountError) { return null; // Return null if trade is not possible } throw error; } } // создаем пул воркеров workerpool.worker({ processRoute: processRoute });