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

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.
@@ -27,13 +27,22 @@ export declare class TradeRouter extends Router {
27
27
  * @returns Best possible sell trade of given token pair
28
28
  */
29
29
  getBestSell(assetIn: string, assetOut: string, amountIn: BigNumber | string | number): Promise<Trade>;
30
+ /**
31
+ * Calculate the amount out for best possible trade if fees are zero
32
+ *
33
+ * @param amountIn - Amount of assetIn to sell for assetOut
34
+ * @param bestRoute - Best possible trade route (sell)
35
+ * @param poolsMap - Pools map
36
+ * @returns the amount out for best possible trade if fees are zero
37
+ */
38
+ private calculateDelta0Y;
30
39
  /**
31
40
  * Calculate and return sell swaps for given path
32
41
  * - final amount of previous swap is entry to next one
33
42
  *
34
43
  * @param amountIn - Amount of assetIn to sell for assetOut
35
- * @param path - current path
36
- * @param poolsMap - pools map
44
+ * @param path - Current path
45
+ * @param poolsMap - Pools map
37
46
  * @returns Sell swaps for given path with corresponding pool pairs
38
47
  */
39
48
  private toSellSwaps;
@@ -46,14 +55,23 @@ export declare class TradeRouter extends Router {
46
55
  * @returns Best possible buy trade of given token pair
47
56
  */
48
57
  getBestBuy(assetIn: string, assetOut: string, amountOut: BigNumber | string | number): Promise<Trade>;
58
+ /**
59
+ * Calculate the amount in for best possible trade if fees are zero
60
+ *
61
+ * @param amountOut - Amount of assetOut to buy for assetIn
62
+ * @param bestRoute - Best possible trade route (buy)
63
+ * @param poolsMap - Pools map
64
+ * @returns the amount in for best possible trade if fees are zero
65
+ */
66
+ private calculateDelta0X;
49
67
  /**
50
68
  * Calculate and return buy swaps for given path
51
69
  * - final amount of previous swap is entry to next one
52
70
  * - calculation is done backwards (swaps in reversed order)
53
71
  *
54
72
  * @param amountOut - Amount of assetOut to buy for assetIn
55
- * @param path - current path
56
- * @param poolsMap - pools map
73
+ * @param path - Current path
74
+ * @param poolsMap - Pools map
57
75
  * @returns Buy swaps for given path
58
76
  */
59
77
  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.14",
4
4
  "private": false,
5
5
  "description": "Galactic SDK",
6
6
  "author": "Pavol Noha <palo@hydradx.io>",