@gainsnetwork/sdk 0.2.12-rc7 → 0.2.12-rc8

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.
@@ -1,4 +1,4 @@
1
1
  import { Fee, PairIndex } from "../types";
2
- export declare const getClosingFee: (posDai: number, leverage: number, pairIndex: PairIndex, pairFee: Fee | undefined) => number;
2
+ export declare const getClosingFee: (posDai: number, leverage: number, pairIndex: PairIndex, pairFee: Fee | undefined, collateralPriceUsd?: number) => number;
3
3
  export * from "./borrowing";
4
4
  export * from "./tiers";
@@ -15,15 +15,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.getClosingFee = void 0;
18
- const getClosingFee = (posDai, leverage, pairIndex, pairFee) => {
18
+ const getClosingFee = (posDai, leverage, pairIndex, pairFee, collateralPriceUsd) => {
19
19
  if (posDai === undefined ||
20
20
  leverage === undefined ||
21
21
  pairIndex === undefined ||
22
22
  pairFee === undefined) {
23
23
  return 0;
24
24
  }
25
- const { closeFeeP, triggerOrderFeeP } = pairFee;
26
- return (closeFeeP + triggerOrderFeeP) * posDai * leverage;
25
+ const { closeFeeP, triggerOrderFeeP, minPositionSizeUsd } = pairFee;
26
+ return ((closeFeeP + triggerOrderFeeP) *
27
+ Math.max(collateralPriceUsd && collateralPriceUsd > 0
28
+ ? minPositionSizeUsd / collateralPriceUsd
29
+ : 0, posDai * leverage));
27
30
  };
28
31
  exports.getClosingFee = getClosingFee;
29
32
  __exportStar(require("./borrowing"), exports);
@@ -3,6 +3,7 @@ import { Fee, LiquidationParams, Trade } from "./types";
3
3
  export type GetLiquidationPriceContext = GetBorrowingFeeContext & {
4
4
  liquidationParams: LiquidationParams | undefined;
5
5
  pairSpreadP: number | undefined;
6
+ collateralPriceUsd: number | undefined;
6
7
  };
7
8
  export declare const getLiquidationPrice: (trade: Trade, fee: Fee, initialAccFees: BorrowingFee.InitialAccFees, context: GetLiquidationPriceContext) => number;
8
9
  export declare const getLiqPnlThresholdP: (liquidationParams: LiquidationParams | undefined, leverage: number | undefined) => number;
@@ -5,7 +5,7 @@ const fees_1 = require("./fees");
5
5
  const spread_1 = require("./spread");
6
6
  const getLiquidationPrice = (trade, fee, initialAccFees, context) => {
7
7
  var _a;
8
- const closingFee = (0, fees_1.getClosingFee)(trade.collateralAmount, trade.leverage, trade.pairIndex, fee);
8
+ const closingFee = (0, fees_1.getClosingFee)(trade.collateralAmount, trade.leverage, trade.pairIndex, fee, context.collateralPriceUsd);
9
9
  const borrowingFee = (0, fees_1.getBorrowingFee)(trade.collateralAmount * trade.leverage, trade.pairIndex, trade.long, initialAccFees, context);
10
10
  const liqThresholdP = (0, exports.getLiqPnlThresholdP)(context.liquidationParams, trade.leverage);
11
11
  let liqPriceDistance = (trade.openPrice *
@@ -3,5 +3,6 @@ import { Fee, LiquidationParams, Trade, TradeInfo, TradeInitialAccFees } from ".
3
3
  export type GetPnlContext = GetBorrowingFeeContext & {
4
4
  fee: Fee | undefined;
5
5
  maxGainP: number | undefined;
6
+ collateralPriceUsd: number | undefined;
6
7
  };
7
8
  export declare const getPnl: (price: number | undefined, trade: Trade, tradeInfo: TradeInfo, initialAccFees: TradeInitialAccFees, liquidationParams: LiquidationParams, useFees: boolean, context: GetPnlContext) => number[] | undefined;
package/lib/trade/pnl.js CHANGED
@@ -25,7 +25,7 @@ const getPnl = (price, trade, tradeInfo, initialAccFees, liquidationParams, useF
25
25
  pnlPercentage = -100;
26
26
  }
27
27
  else {
28
- pnlCollat -= (0, fees_1.getClosingFee)(posCollat, trade.leverage, trade.pairIndex, fee);
28
+ pnlCollat -= (0, fees_1.getClosingFee)(posCollat, trade.leverage, trade.pairIndex, fee, context.collateralPriceUsd);
29
29
  pnlPercentage = (pnlCollat / posCollat) * 100;
30
30
  }
31
31
  pnlPercentage = pnlPercentage < -100 ? -100 : pnlPercentage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gainsnetwork/sdk",
3
- "version": "0.2.12-rc7",
3
+ "version": "0.2.12-rc8",
4
4
  "description": "Gains Network SDK",
5
5
  "main": "./lib/index.js",
6
6
  "files": [