@gainsnetwork/sdk 0.2.12-rc11 → 0.2.12-rc13

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.
@@ -254,6 +254,8 @@ export declare const pairs: {
254
254
  "DEGEN/USD": string;
255
255
  "SLERF/USD": string;
256
256
  "UXLINK/USD": string;
257
+ "AVAIL/USD": string;
258
+ "BANANA/USD": string;
257
259
  };
258
260
  export declare const getAssetClassFromGroupIndex: (groupIndex: number) => string | undefined;
259
261
  export declare const tickerChanges: {
@@ -283,3 +285,4 @@ export declare const stockSplits: {
283
285
  export declare const delistedPairIxs: Set<number>;
284
286
  export declare const delistedGroupsIxs: Set<number>;
285
287
  export declare const DEFAULT_PROTECTION_CLOSE_FACTOR = 1;
288
+ export declare const DEFAULT_CUMULATIVE_FACTOR = 1;
package/lib/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_PROTECTION_CLOSE_FACTOR = exports.delistedGroupsIxs = exports.delistedPairIxs = exports.stockSplits = exports.tickerChanges = exports.getAssetClassFromGroupIndex = exports.pairs = void 0;
3
+ exports.DEFAULT_CUMULATIVE_FACTOR = exports.DEFAULT_PROTECTION_CLOSE_FACTOR = exports.delistedGroupsIxs = exports.delistedPairIxs = exports.stockSplits = exports.tickerChanges = exports.getAssetClassFromGroupIndex = exports.pairs = void 0;
4
4
  const CRYPTO = "crypto";
5
5
  const FOREX = "forex";
6
6
  const STOCKS = "stocks";
@@ -262,10 +262,13 @@ exports.pairs = {
262
262
  "DEGEN/USD": CRYPTO,
263
263
  "SLERF/USD": CRYPTO,
264
264
  "UXLINK/USD": CRYPTO,
265
+ "AVAIL/USD": CRYPTO,
266
+ "BANANA/USD": CRYPTO,
265
267
  };
266
268
  const getAssetClassFromGroupIndex = (groupIndex) => {
267
269
  switch (groupIndex) {
268
270
  case 0:
271
+ case 10:
269
272
  return CRYPTO;
270
273
  case 1:
271
274
  case 8:
@@ -296,7 +299,8 @@ exports.delistedPairIxs = new Set([
296
299
  6, 31, 36, 42, 45, 48, 51, 54, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
297
300
  70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
298
301
  89, 97, 99, 101, 106, 108, 52, 131, 147, 160, 179, 182, 183, 190, 229, 163,
299
- 155, 15, 170, 239, 251, 252, 253, 254,
302
+ 155, 15, 170, 239, 254, 230,
300
303
  ]);
301
304
  exports.delistedGroupsIxs = new Set([6, 7]);
302
305
  exports.DEFAULT_PROTECTION_CLOSE_FACTOR = 1;
306
+ exports.DEFAULT_CUMULATIVE_FACTOR = 1;
@@ -360,4 +360,6 @@ const PAIR_INDEX_TO_DESCRIPTION = {
360
360
  [types_1.PairIndex.DEGENUSD]: "Degen to US Dollar",
361
361
  [types_1.PairIndex.SLERFUSD]: "Slerf to US Dollar",
362
362
  [types_1.PairIndex.UXLINKUSD]: "UXLINK to US Dollar",
363
+ [types_1.PairIndex.AVAILUSD]: "Avail to US Dollar",
364
+ [types_1.PairIndex.BANANAUSD]: "Banana Gun to US Dollar",
363
365
  };
@@ -36,8 +36,8 @@ const isForexLowLiquidity = (timestampToCheck, pair) => {
36
36
  const groupIndex = pair === null || pair === void 0 ? void 0 : pair.groupIndex;
37
37
  if (groupIndex && extendedLowLiqGroupIds.includes(+groupIndex)) {
38
38
  return ((isInDST &&
39
- ((hour == 15 && minute >= 15) || (hour >= 16 && hour < 21))) ||
40
- (!isInDST && ((hour == 16 && minute >= 15) || (hour >= 17 && hour < 22))));
39
+ ((hour == 14 && minute >= 45) || (hour >= 15 && hour < 21))) ||
40
+ (!isInDST && ((hour == 15 && minute >= 45) || (hour >= 16 && hour < 22))));
41
41
  }
42
42
  return ((isInDST && ((hour == 15 && minute >= 45) || (hour >= 16 && hour < 19))) ||
43
43
  (!isInDST && ((hour == 16 && minute >= 45) || (hour >= 17 && hour < 20))));
@@ -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, collateralPriceUsd?: number) => number;
2
+ export declare const getClosingFee: (posDai: number, leverage: number, pairIndex: PairIndex, pairFee: Fee | undefined, collateralPriceUsd?: number | undefined, feeMultiplier?: number | undefined) => number;
3
3
  export * from "./borrowing";
4
4
  export * from "./tiers";
@@ -15,7 +15,7 @@ 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, collateralPriceUsd) => {
18
+ const getClosingFee = (posDai, leverage, pairIndex, pairFee, collateralPriceUsd = 0, feeMultiplier = 1) => {
19
19
  if (posDai === undefined ||
20
20
  leverage === undefined ||
21
21
  pairIndex === undefined ||
@@ -24,6 +24,7 @@ const getClosingFee = (posDai, leverage, pairIndex, pairFee, collateralPriceUsd)
24
24
  }
25
25
  const { closeFeeP, triggerOrderFeeP, minPositionSizeUsd } = pairFee;
26
26
  return ((closeFeeP + triggerOrderFeeP) *
27
+ feeMultiplier *
27
28
  Math.max(collateralPriceUsd && collateralPriceUsd > 0
28
29
  ? minPositionSizeUsd / collateralPriceUsd
29
30
  : 0, posDai * leverage));
@@ -6,5 +6,6 @@ export type GetPnlContext = GetBorrowingFeeContext & {
6
6
  maxGainP: number | undefined;
7
7
  collateralPriceUsd: number | undefined;
8
8
  contractsVersion: ContractsVersion | undefined;
9
+ feeMultiplier: number | undefined;
9
10
  };
10
11
  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
@@ -26,7 +26,7 @@ const getPnl = (price, trade, tradeInfo, initialAccFees, liquidationParams, useF
26
26
  pnlPercentage = -100;
27
27
  }
28
28
  else {
29
- pnlCollat -= (0, fees_1.getClosingFee)(posCollat, trade.leverage, trade.pairIndex, fee, context.collateralPriceUsd);
29
+ pnlCollat -= (0, fees_1.getClosingFee)(posCollat, trade.leverage, trade.pairIndex, fee, context.collateralPriceUsd, context.feeMultiplier);
30
30
  pnlPercentage = (pnlCollat / posCollat) * 100;
31
31
  }
32
32
  pnlPercentage = pnlPercentage < -100 ? -100 : pnlPercentage;
@@ -5,11 +5,14 @@ export type SpreadContext = {
5
5
  isPnlPositive?: boolean;
6
6
  protectionCloseFactor?: number;
7
7
  protectionCloseFactorBlocks?: number;
8
+ cumulativeFactor?: number;
8
9
  createdBlock?: number;
9
10
  liquidationParams?: LiquidationParams | undefined;
10
- currentBlock: number | undefined;
11
- contractsVersion: ContractsVersion | undefined;
11
+ currentBlock?: number | undefined;
12
+ contractsVersion?: ContractsVersion | undefined;
12
13
  };
13
14
  export declare const getProtectionCloseFactor: (spreadCtx: SpreadContext | undefined) => number;
15
+ export declare const getCumulativeFactor: (spreadCtx: SpreadContext | undefined) => number;
16
+ export declare const getLegacyFactor: (spreadCtx: SpreadContext | undefined) => number;
14
17
  export declare const getSpreadWithPriceImpactP: (pairSpreadP: number, buy: boolean, collateral: number, leverage: number, pairDepth: PairDepth | undefined, oiWindowsSettings?: OiWindowsSettings | undefined, oiWindows?: OiWindows | undefined, spreadCtx?: SpreadContext | undefined) => number;
15
18
  export declare const getSpreadP: (pairSpreadP: number | undefined, isLiquidation?: boolean | undefined, liquidationParams?: LiquidationParams | undefined) => number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSpreadP = exports.getSpreadWithPriceImpactP = exports.getProtectionCloseFactor = void 0;
3
+ exports.getSpreadP = exports.getSpreadWithPriceImpactP = exports.getLegacyFactor = exports.getCumulativeFactor = exports.getProtectionCloseFactor = void 0;
4
4
  const oiWindows_1 = require("./oiWindows");
5
5
  const constants_1 = require("../constants");
6
6
  const types_1 = require("../contracts/types");
@@ -24,6 +24,17 @@ const getProtectionCloseFactor = (spreadCtx) => {
24
24
  return constants_1.DEFAULT_PROTECTION_CLOSE_FACTOR;
25
25
  };
26
26
  exports.getProtectionCloseFactor = getProtectionCloseFactor;
27
+ const getCumulativeFactor = (spreadCtx) => {
28
+ if (spreadCtx === undefined || spreadCtx.cumulativeFactor === undefined) {
29
+ return constants_1.DEFAULT_CUMULATIVE_FACTOR;
30
+ }
31
+ return spreadCtx.cumulativeFactor;
32
+ };
33
+ exports.getCumulativeFactor = getCumulativeFactor;
34
+ const getLegacyFactor = (spreadCtx) => {
35
+ return (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.contractsVersion) === types_1.ContractsVersion.BEFORE_V9_2 ? 1 : 2;
36
+ };
37
+ exports.getLegacyFactor = getLegacyFactor;
27
38
  const getSpreadWithPriceImpactP = (pairSpreadP, buy, collateral, leverage, pairDepth, oiWindowsSettings, oiWindows, spreadCtx) => {
28
39
  if (pairSpreadP === undefined) {
29
40
  return 0;
@@ -50,7 +61,10 @@ const getSpreadWithPriceImpactP = (pairSpreadP, buy, collateral, leverage, pairD
50
61
  return pairSpreadP / 2;
51
62
  }
52
63
  return ((0, exports.getSpreadP)(pairSpreadP) +
53
- ((activeOi + (collateral * leverage) / 2) / onePercentDepth / 100 / 2) *
64
+ ((activeOi * (0, exports.getCumulativeFactor)(spreadCtx) + (collateral * leverage) / 2) /
65
+ onePercentDepth /
66
+ 100 /
67
+ (0, exports.getLegacyFactor)(spreadCtx)) *
54
68
  (0, exports.getProtectionCloseFactor)(spreadCtx));
55
69
  };
56
70
  exports.getSpreadWithPriceImpactP = getSpreadWithPriceImpactP;
@@ -460,5 +460,7 @@ export declare enum PairIndex {
460
460
  MEWUSD = 251,
461
461
  DEGENUSD = 252,
462
462
  SLERFUSD = 253,
463
- UXLINKUSD = 254
463
+ UXLINKUSD = 254,
464
+ AVAILUSD = 255,
465
+ BANANAUSD = 256
464
466
  }
@@ -284,4 +284,6 @@ var PairIndex;
284
284
  PairIndex[PairIndex["DEGENUSD"] = 252] = "DEGENUSD";
285
285
  PairIndex[PairIndex["SLERFUSD"] = 253] = "SLERFUSD";
286
286
  PairIndex[PairIndex["UXLINKUSD"] = 254] = "UXLINKUSD";
287
+ PairIndex[PairIndex["AVAILUSD"] = 255] = "AVAILUSD";
288
+ PairIndex[PairIndex["BANANAUSD"] = 256] = "BANANAUSD";
287
289
  })(PairIndex = exports.PairIndex || (exports.PairIndex = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gainsnetwork/sdk",
3
- "version": "0.2.12-rc11",
3
+ "version": "0.2.12-rc13",
4
4
  "description": "Gains Network SDK",
5
5
  "main": "./lib/index.js",
6
6
  "files": [