@galacticcouncil/sdk 0.0.1-beta.13 → 0.0.1-beta.15

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.
@@ -18,6 +18,13 @@ export declare class TradeRouter extends Router {
18
18
  * @returns Spot price for given path
19
19
  */
20
20
  private getSpotPrice;
21
+ /**
22
+ * Check whether trade is direct or not
23
+ *
24
+ * @param swaps - Trade route
25
+ * @returns true if direct trade, otherwise false
26
+ */
27
+ private isDirectTrade;
21
28
  /**
22
29
  * Calculate and return best possible sell trade for assetIn>assetOut
23
30
  *
@@ -27,13 +34,22 @@ export declare class TradeRouter extends Router {
27
34
  * @returns Best possible sell trade of given token pair
28
35
  */
29
36
  getBestSell(assetIn: string, assetOut: string, amountIn: BigNumber | string | number): Promise<Trade>;
37
+ /**
38
+ * Calculate the amount out for best possible trade if fees are zero
39
+ *
40
+ * @param amountIn - Amount of assetIn to sell for assetOut
41
+ * @param bestRoute - Best possible trade route (sell)
42
+ * @param poolsMap - Pools map
43
+ * @returns the amount out for best possible trade if fees are zero
44
+ */
45
+ private calculateDelta0Y;
30
46
  /**
31
47
  * Calculate and return sell swaps for given path
32
48
  * - final amount of previous swap is entry to next one
33
49
  *
34
50
  * @param amountIn - Amount of assetIn to sell for assetOut
35
- * @param path - current path
36
- * @param poolsMap - pools map
51
+ * @param path - Current path
52
+ * @param poolsMap - Pools map
37
53
  * @returns Sell swaps for given path with corresponding pool pairs
38
54
  */
39
55
  private toSellSwaps;
@@ -46,14 +62,23 @@ export declare class TradeRouter extends Router {
46
62
  * @returns Best possible buy trade of given token pair
47
63
  */
48
64
  getBestBuy(assetIn: string, assetOut: string, amountOut: BigNumber | string | number): Promise<Trade>;
65
+ /**
66
+ * Calculate the amount in for best possible trade if fees are zero
67
+ *
68
+ * @param amountOut - Amount of assetOut to buy for assetIn
69
+ * @param bestRoute - Best possible trade route (buy)
70
+ * @param poolsMap - Pools map
71
+ * @returns the amount in for best possible trade if fees are zero
72
+ */
73
+ private calculateDelta0X;
49
74
  /**
50
75
  * Calculate and return buy swaps for given path
51
76
  * - final amount of previous swap is entry to next one
52
77
  * - calculation is done backwards (swaps in reversed order)
53
78
  *
54
79
  * @param amountOut - Amount of assetOut to buy for assetIn
55
- * @param path - current path
56
- * @param poolsMap - pools map
80
+ * @param path - Current path
81
+ * @param poolsMap - Pools map
57
82
  * @returns Buy swaps for given path
58
83
  */
59
84
  private toBuySwaps;
@@ -99,6 +99,8 @@ export interface Trade extends Humanizer {
99
99
  amountIn: BigNumber;
100
100
  amountOut: BigNumber;
101
101
  spotPrice: BigNumber;
102
+ tradeFee: BigNumber;
103
+ tradeFeePct: number;
102
104
  priceImpactPct: number;
103
105
  swaps: Swap[];
104
106
  toTx(tradeLimit: BigNumber): Transaction;
@@ -11,3 +11,23 @@ import { BigNumber } from './bignumber';
11
11
  * @returns Price impact percentage
12
12
  */
13
13
  export declare function calculatePriceImpact(amount: BigNumber, decimals: number, spotPrice: BigNumber, calculatedAmount: BigNumber): BigNumber;
14
+ /**
15
+ * The total fee paid for a ‘sell’ transaction
16
+ * Suppose the trader is selling X for Y
17
+ *
18
+ * fee = 1 - (deltaY / delta0Y)
19
+ *
20
+ * @param delta0Y - the amount out if fees are zero
21
+ * @param deltaY - the amount out if the existing nonzero fees are included in the calculation
22
+ */
23
+ export declare function calculateSellFee(delta0Y: BigNumber, deltaY: BigNumber): BigNumber;
24
+ /**
25
+ * The total fee paid for a buy transaction
26
+ * Suppose the trader is buying Y using X
27
+ *
28
+ * fee = (deltaX / delta0X) - 1
29
+ *
30
+ * @param delta0X - the amount in if fees are zero
31
+ * @param deltaX - the amount in, inclusive of fees
32
+ */
33
+ export declare function calculateBuyFee(delta0X: BigNumber, deltaX: BigNumber): BigNumber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacticcouncil/sdk",
3
- "version": "0.0.1-beta.13",
3
+ "version": "0.0.1-beta.15",
4
4
  "private": false,
5
5
  "description": "Galactic SDK",
6
6
  "author": "Pavol Noha <palo@hydradx.io>",