@gainsnetwork/sdk 0.2.17-rc1 → 0.2.17-rc2

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.
@@ -5,6 +5,7 @@ export type GetBorrowingFeeContext = {
5
5
  groups: BorrowingFee.Group[];
6
6
  pairs: BorrowingFee.Pair[];
7
7
  openInterest: OpenInterest;
8
+ feeMultiplier: number | undefined;
8
9
  };
9
10
  export declare const getBorrowingFee: (posDai: number, pairIndex: PairIndex, long: boolean, initialAccFees: BorrowingFee.InitialAccFees, context: GetBorrowingFeeContext) => number;
10
11
  export declare const withinMaxGroupOi: (pairIndex: PairIndex, long: boolean, positionSizeCollateral: number, context: {
@@ -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, feeMultiplier?: 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, feeMultiplier = 1) => {
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) * feeMultiplier *
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);
@@ -1,3 +1,6 @@
1
1
  import { GetBorrowingFeeContext, BorrowingFee } from "./fees";
2
2
  import { Fee, Trade } from "./types";
3
- export declare const getLiquidationPrice: (trade: Trade, fee: Fee, initialAccFees: BorrowingFee.InitialAccFees, context: GetBorrowingFeeContext) => number;
3
+ export type GetLiquidationPriceContext = GetBorrowingFeeContext & {
4
+ collateralPriceUsd: number | undefined;
5
+ };
6
+ export declare const getLiquidationPrice: (trade: Trade, fee: Fee, initialAccFees: BorrowingFee.InitialAccFees, context: GetLiquidationPriceContext) => number;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLiquidationPrice = void 0;
4
4
  const fees_1 = require("./fees");
5
5
  const getLiquidationPrice = (trade, fee, initialAccFees, context) => {
6
- const closingFee = (0, fees_1.getClosingFee)(trade.collateralAmount, trade.leverage, trade.pairIndex, fee);
6
+ const closingFee = (0, fees_1.getClosingFee)(trade.collateralAmount, trade.leverage, trade.pairIndex, fee, context.collateralPriceUsd, context.feeMultiplier);
7
7
  const borrowingFee = (0, fees_1.getBorrowingFee)(trade.collateralAmount * trade.leverage, trade.pairIndex, trade.long, initialAccFees, context);
8
8
  const liqPriceDistance = (trade.openPrice *
9
9
  (trade.collateralAmount * 0.9 - (borrowingFee + closingFee))) /
@@ -3,5 +3,6 @@ import { Fee, Trade, TradeInfo, TradeInitialAccFees } from "./types";
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, useFees: boolean, context: GetPnlContext) => number[] | undefined;
package/lib/trade/pnl.js CHANGED
@@ -23,7 +23,7 @@ const getPnl = (price, trade, tradeInfo, initialAccFees, useFees, context) => {
23
23
  pnlPercentage = -100;
24
24
  }
25
25
  else {
26
- pnlCollat -= (0, fees_1.getClosingFee)(posCollat, trade.leverage, trade.pairIndex, fee);
26
+ pnlCollat -= (0, fees_1.getClosingFee)(posCollat, trade.leverage, trade.pairIndex, fee, context.collateralPriceUsd, context.feeMultiplier);
27
27
  pnlPercentage = (pnlCollat / posCollat) * 100;
28
28
  }
29
29
  pnlPercentage = pnlPercentage < -100 ? -100 : pnlPercentage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gainsnetwork/sdk",
3
- "version": "0.2.17-rc1",
3
+ "version": "0.2.17-rc2",
4
4
  "description": "Gains Network SDK",
5
5
  "main": "./lib/index.js",
6
6
  "files": [