@gainsnetwork/sdk 0.2.33-rc3 → 0.2.33-rc5

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.
package/lib/constants.js CHANGED
@@ -327,8 +327,8 @@ exports.stockSplits = {
327
327
  exports.delistedPairIxs = new Set([
328
328
  6, 31, 36, 45, 48, 51, 54, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
329
329
  71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
330
- 97, 99, 101, 106, 108, 52, 131, 147, 160, 179, 182, 183, 190, 229, 163, 155,
331
- 15, 170, 239, 254, 230, 4, 275, 282, 283, 284, 285,
330
+ 97, 99, 101, 106, 108, 52, 131, 147, 160, 179, 182, 183, 190, 229, 163, 15,
331
+ 170, 239, 254, 230, 4, 275,
332
332
  ]);
333
333
  exports.delistedGroupsIxs = new Set([6, 7]);
334
334
  exports.DEFAULT_PROTECTION_CLOSE_FACTOR = 1;
@@ -22,7 +22,6 @@ const getClosingFee = (posDai, leverage, pairIndex, pairFee, collateralPriceUsd
22
22
  pairFee === undefined) {
23
23
  return 0;
24
24
  }
25
- // @todo check
26
25
  const { totalPositionSizeFeeP, minPositionSizeUsd } = pairFee;
27
26
  return (totalPositionSizeFeeP *
28
27
  feeMultiplier *
@@ -10,6 +10,7 @@ export type SpreadContext = {
10
10
  protectionCloseFactorWhitelist?: boolean;
11
11
  } & Partial<PairFactor>;
12
12
  export declare const getProtectionCloseFactor: (spreadCtx: SpreadContext | undefined) => number;
13
+ export declare const isProtectionCloseFactorActive: (spreadCtx: SpreadContext | undefined) => boolean | undefined;
13
14
  export declare const getCumulativeFactor: (spreadCtx: SpreadContext | undefined) => number;
14
15
  export declare const getLegacyFactor: (spreadCtx: SpreadContext | undefined) => number;
15
16
  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;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSpreadP = exports.getSpreadWithPriceImpactP = exports.getLegacyFactor = exports.getCumulativeFactor = exports.getProtectionCloseFactor = void 0;
3
+ exports.getSpreadP = exports.getSpreadWithPriceImpactP = exports.getLegacyFactor = exports.getCumulativeFactor = exports.isProtectionCloseFactorActive = 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");
@@ -13,18 +13,29 @@ const getProtectionCloseFactor = (spreadCtx) => {
13
13
  spreadCtx.protectionCloseFactorBlocks === undefined ||
14
14
  spreadCtx.createdBlock === undefined ||
15
15
  spreadCtx.currentBlock === undefined ||
16
- spreadCtx.protectionCloseFactorWhitelist === true)
16
+ spreadCtx.protectionCloseFactorWhitelist === true // if trader is whitelisted, protection close factor is always 1
17
+ )
17
18
  return constants_1.DEFAULT_PROTECTION_CLOSE_FACTOR;
18
19
  if (spreadCtx.isPnlPositive &&
19
20
  !spreadCtx.isOpen &&
20
21
  spreadCtx.protectionCloseFactor > 0 &&
21
- spreadCtx.currentBlock <=
22
- spreadCtx.createdBlock + spreadCtx.protectionCloseFactorBlocks) {
22
+ (0, exports.isProtectionCloseFactorActive)(spreadCtx) === true) {
23
23
  return spreadCtx.protectionCloseFactor;
24
24
  }
25
25
  return constants_1.DEFAULT_PROTECTION_CLOSE_FACTOR;
26
26
  };
27
27
  exports.getProtectionCloseFactor = getProtectionCloseFactor;
28
+ const isProtectionCloseFactorActive = (spreadCtx) => {
29
+ if (spreadCtx === undefined ||
30
+ spreadCtx.currentBlock === undefined ||
31
+ spreadCtx.createdBlock === undefined ||
32
+ spreadCtx.protectionCloseFactorBlocks === undefined) {
33
+ return undefined;
34
+ }
35
+ return (spreadCtx.currentBlock <=
36
+ spreadCtx.createdBlock + spreadCtx.protectionCloseFactorBlocks);
37
+ };
38
+ exports.isProtectionCloseFactorActive = isProtectionCloseFactorActive;
28
39
  const getCumulativeFactor = (spreadCtx) => {
29
40
  if (spreadCtx === undefined ||
30
41
  spreadCtx.cumulativeFactor === undefined ||
@@ -38,14 +49,21 @@ const getLegacyFactor = (spreadCtx) => {
38
49
  return (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.contractsVersion) === types_1.ContractsVersion.BEFORE_V9_2 ? 1 : 2;
39
50
  };
40
51
  exports.getLegacyFactor = getLegacyFactor;
41
- // @todo
42
52
  const getSpreadWithPriceImpactP = (pairSpreadP, buy, collateral, leverage, pairDepth, oiWindowsSettings, oiWindows, spreadCtx) => {
43
53
  if (pairSpreadP === undefined) {
44
54
  return 0;
45
55
  }
56
+ if (
46
57
  // No spread or price impact when closing pre-v9.2 trades
47
- if ((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === false &&
48
- (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.contractsVersion) === types_1.ContractsVersion.BEFORE_V9_2) {
58
+ ((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === false &&
59
+ (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.contractsVersion) === types_1.ContractsVersion.BEFORE_V9_2) ||
60
+ // No spread or price impact for opens when `pair.exemptOnOpen` is true
61
+ ((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === true && (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.exemptOnOpen) === true) ||
62
+ // No spread or price impact for closes after `protectionCloseFactor` has expired
63
+ // when `pair.exemptAfterProtectionCloseFactor` is true
64
+ ((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === false &&
65
+ (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.exemptAfterProtectionCloseFactor) === true &&
66
+ (0, exports.isProtectionCloseFactorActive)(spreadCtx) === false)) {
49
67
  return 0;
50
68
  }
51
69
  const onePercentDepth = buy
@@ -64,7 +82,6 @@ const getSpreadWithPriceImpactP = (pairSpreadP, buy, collateral, leverage, pairD
64
82
  if (!onePercentDepth || activeOi === undefined || collateral === undefined) {
65
83
  return pairSpreadP / 2;
66
84
  }
67
- // @todo implement exemptOnOpen && exemptAfterProtectionCloseFactor
68
85
  return ((0, exports.getSpreadP)(pairSpreadP) +
69
86
  ((activeOi * (0, exports.getCumulativeFactor)(spreadCtx) + (collateral * leverage) / 2) /
70
87
  onePercentDepth /
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gainsnetwork/sdk",
3
- "version": "0.2.33-rc3",
3
+ "version": "0.2.33-rc5",
4
4
  "description": "Gains Network SDK",
5
5
  "main": "./lib/index.js",
6
6
  "files": [