@alcorexchange/alcor-swap-sdk 1.0.20 → 1.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -495,8 +495,11 @@ class Trade {
495
495
  for (const route of routes) {
496
496
  const freshPools = route.pools.map(p => poolsMap.get(p.id));
497
497
  const trade = yield Trade.fromRoute(new route_1.Route([...freshPools], route.input, route.output), currencyAmountIn, internalConstants_1.TradeType.EXACT_INPUT);
498
- if (!trade.inputAmount.greaterThan(0) || !trade.priceImpact.greaterThan(0))
498
+ // FIXME! Sorting bug multiple pools
499
+ if (!trade.inputAmount.greaterThan(0) || !trade.priceImpact.greaterThan(0)) {
500
+ console.log('continue trade', (0, utils_1.parseTrade)(trade));
499
501
  continue;
502
+ }
500
503
  (0, utils_1.sortedInsert)(bestTrades, trade, maxNumResults, tradeComparator);
501
504
  }
502
505
  return bestTrades;
@@ -510,8 +513,10 @@ class Trade {
510
513
  for (const route of routes) {
511
514
  const freshPools = route.pools.map(p => poolsMap.get(p.id));
512
515
  const trade = yield Trade.fromRoute(new route_1.Route([...freshPools], route.input, route.output), currencyAmountOut, internalConstants_1.TradeType.EXACT_OUTPUT);
513
- if (!trade.inputAmount.greaterThan(0) || !trade.priceImpact.greaterThan(0))
516
+ if (!trade.inputAmount.greaterThan(0) || !trade.priceImpact.greaterThan(0)) {
517
+ console.log('continue trade', (0, utils_1.parseTrade)(trade));
514
518
  continue;
519
+ }
515
520
  (0, utils_1.sortedInsert)(bestTrades, trade, maxNumResults, tradeComparator);
516
521
  }
517
522
  return bestTrades;
@@ -0,0 +1,13 @@
1
+ export declare function parseTrade(trade: any): {
2
+ input: any;
3
+ output: any;
4
+ minReceived: any;
5
+ maxSent: any;
6
+ priceImpact: any;
7
+ memo: string;
8
+ route: any;
9
+ executionPrice: {
10
+ numerator: any;
11
+ denominator: any;
12
+ };
13
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseTrade = void 0;
4
+ const entities_1 = require("../entities");
5
+ const internalConstants_1 = require("../internalConstants");
6
+ function parseTrade(trade) {
7
+ // Parse Trade into api format object
8
+ const slippage = new entities_1.Percent(3, 100); // 0.3%
9
+ const receiver = '<receiver>';
10
+ const tradeType = trade.tradeType == internalConstants_1.TradeType.EXACT_INPUT ? 'swapexactin' : 'swapexactout';
11
+ const route = trade.route.pools.map(p => p.id);
12
+ const maxSent = trade.inputAmount;
13
+ const minReceived = trade.minimumAmountOut(slippage);
14
+ const memo = `${tradeType}#${route.join(',')}#${receiver}#${minReceived.toExtendedAsset()}#0`;
15
+ const result = {
16
+ input: trade.inputAmount.toFixed(),
17
+ output: trade.outputAmount.toFixed(),
18
+ minReceived: minReceived.toFixed(),
19
+ maxSent: maxSent.toFixed(),
20
+ priceImpact: trade.priceImpact.toSignificant(2),
21
+ memo,
22
+ route,
23
+ executionPrice: {
24
+ numerator: trade.executionPrice.numerator.toString(),
25
+ denominator: trade.executionPrice.denominator.toString()
26
+ }
27
+ };
28
+ return result;
29
+ }
30
+ exports.parseTrade = parseTrade;
@@ -13,3 +13,4 @@ export * from "./priceTickConversions";
13
13
  export * from "./sqrtPriceMath";
14
14
  export * from "./sortedInsert";
15
15
  export * from "./computeAllRoutes";
16
+ export * from "./common";
@@ -29,3 +29,4 @@ __exportStar(require("./priceTickConversions"), exports);
29
29
  __exportStar(require("./sqrtPriceMath"), exports);
30
30
  __exportStar(require("./sortedInsert"), exports);
31
31
  __exportStar(require("./computeAllRoutes"), exports);
32
+ __exportStar(require("./common"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alcorexchange/alcor-swap-sdk",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -2,7 +2,7 @@ import invariant from 'tiny-invariant'
2
2
 
3
3
  import { Currency } from './currency'
4
4
  import { Fraction, Percent, Price, CurrencyAmount } from './fractions'
5
- import { sortedInsert } from '../utils'
5
+ import { sortedInsert, parseTrade } from '../utils'
6
6
  import { Token } from './token'
7
7
  import { ONE, ZERO, TradeType } from '../internalConstants'
8
8
  import { Pool } from './pool'
@@ -718,7 +718,11 @@ export class Trade<TInput extends Currency, TOutput extends Currency, TTradeType
718
718
  TradeType.EXACT_INPUT
719
719
  )
720
720
 
721
- if (!trade.inputAmount.greaterThan(0) || !trade.priceImpact.greaterThan(0)) continue
721
+ // FIXME! Sorting bug multiple pools
722
+ if (!trade.inputAmount.greaterThan(0) || !trade.priceImpact.greaterThan(0)) {
723
+ console.log('continue trade', parseTrade(trade))
724
+ continue
725
+ }
722
726
 
723
727
  sortedInsert(
724
728
  bestTrades,
@@ -750,7 +754,10 @@ export class Trade<TInput extends Currency, TOutput extends Currency, TTradeType
750
754
  TradeType.EXACT_OUTPUT
751
755
  )
752
756
 
753
- if (!trade.inputAmount.greaterThan(0) || !trade.priceImpact.greaterThan(0)) continue
757
+ if (!trade.inputAmount.greaterThan(0) || !trade.priceImpact.greaterThan(0)) {
758
+ console.log('continue trade', parseTrade(trade))
759
+ continue
760
+ }
754
761
 
755
762
  sortedInsert(
756
763
  bestTrades,
@@ -0,0 +1,32 @@
1
+ import { Percent } from "../entities"
2
+ import { TradeType } from "../internalConstants"
3
+
4
+ export function parseTrade(trade) {
5
+ // Parse Trade into api format object
6
+ const slippage = new Percent(3, 100) // 0.3%
7
+ const receiver = '<receiver>'
8
+
9
+ const tradeType = trade.tradeType == TradeType.EXACT_INPUT ? 'swapexactin' : 'swapexactout'
10
+
11
+ const route = trade.route.pools.map(p => p.id)
12
+ const maxSent = trade.inputAmount
13
+ const minReceived = trade.minimumAmountOut(slippage)
14
+ const memo = `${tradeType}#${route.join(',')}#${receiver}#${minReceived.toExtendedAsset()}#0`
15
+
16
+ const result = {
17
+ input: trade.inputAmount.toFixed(),
18
+ output: trade.outputAmount.toFixed(),
19
+ minReceived: minReceived.toFixed(),
20
+ maxSent: maxSent.toFixed(),
21
+ priceImpact: trade.priceImpact.toSignificant(2),
22
+ memo,
23
+ route,
24
+ executionPrice: {
25
+ numerator: trade.executionPrice.numerator.toString(),
26
+ denominator: trade.executionPrice.denominator.toString()
27
+ }
28
+ }
29
+
30
+ return result
31
+ }
32
+
@@ -13,3 +13,4 @@ export * from "./priceTickConversions";
13
13
  export * from "./sqrtPriceMath";
14
14
  export * from "./sortedInsert";
15
15
  export * from "./computeAllRoutes";
16
+ export * from "./common";