@gainsnetwork/sdk 0.2.33-rc4 → 0.2.33-rc6

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.
@@ -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,30 @@ 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
+ spreadCtx.protectionCloseFactorWhitelist !== true);
38
+ };
39
+ exports.isProtectionCloseFactorActive = isProtectionCloseFactorActive;
28
40
  const getCumulativeFactor = (spreadCtx) => {
29
41
  if (spreadCtx === undefined ||
30
42
  spreadCtx.cumulativeFactor === undefined ||
@@ -38,14 +50,21 @@ const getLegacyFactor = (spreadCtx) => {
38
50
  return (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.contractsVersion) === types_1.ContractsVersion.BEFORE_V9_2 ? 1 : 2;
39
51
  };
40
52
  exports.getLegacyFactor = getLegacyFactor;
41
- // @todo
42
53
  const getSpreadWithPriceImpactP = (pairSpreadP, buy, collateral, leverage, pairDepth, oiWindowsSettings, oiWindows, spreadCtx) => {
43
54
  if (pairSpreadP === undefined) {
44
55
  return 0;
45
56
  }
57
+ if (
46
58
  // 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) {
59
+ ((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === false &&
60
+ (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.contractsVersion) === types_1.ContractsVersion.BEFORE_V9_2) ||
61
+ // No spread or price impact for opens when `pair.exemptOnOpen` is true
62
+ ((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === true && (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.exemptOnOpen) === true) ||
63
+ // No spread or price impact for closes after `protectionCloseFactor` has expired
64
+ // when `pair.exemptAfterProtectionCloseFactor` is true
65
+ ((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === false &&
66
+ (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.exemptAfterProtectionCloseFactor) === true &&
67
+ (0, exports.isProtectionCloseFactorActive)(spreadCtx) === false)) {
49
68
  return 0;
50
69
  }
51
70
  const onePercentDepth = buy
@@ -64,7 +83,6 @@ const getSpreadWithPriceImpactP = (pairSpreadP, buy, collateral, leverage, pairD
64
83
  if (!onePercentDepth || activeOi === undefined || collateral === undefined) {
65
84
  return pairSpreadP / 2;
66
85
  }
67
- // @todo implement exemptOnOpen && exemptAfterProtectionCloseFactor
68
86
  return ((0, exports.getSpreadP)(pairSpreadP) +
69
87
  ((activeOi * (0, exports.getCumulativeFactor)(spreadCtx) + (collateral * leverage) / 2) /
70
88
  onePercentDepth /
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gainsnetwork/sdk",
3
- "version": "0.2.33-rc4",
3
+ "version": "0.2.33-rc6",
4
4
  "description": "Gains Network SDK",
5
5
  "main": "./lib/index.js",
6
6
  "files": [