@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.
- package/build/entities/trade.js +7 -2
- package/build/utils/common.d.ts +13 -0
- package/build/utils/common.js +30 -0
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.js +1 -0
- package/package.json +1 -1
- package/src/entities/trade.ts +10 -3
- package/src/utils/common.ts +32 -0
- package/src/utils/index.ts +1 -0
package/build/entities/trade.js
CHANGED
|
@@ -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
|
-
|
|
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,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;
|
package/build/utils/index.d.ts
CHANGED
package/build/utils/index.js
CHANGED
package/package.json
CHANGED
package/src/entities/trade.ts
CHANGED
|
@@ -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
|
-
|
|
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))
|
|
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
|
+
|
package/src/utils/index.ts
CHANGED