@gainsnetwork/sdk 0.2.35-rc1 → 0.2.37-rc1

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.
@@ -69,10 +69,10 @@ const fetchFees = (contracts, feeIxs) => __awaiter(void 0, void 0, void 0, funct
69
69
  const fees = yield Promise.all(feeIxs.map(pairIndex => multiCollatContract.fees(pairIndex)));
70
70
  return fees.map(fee => {
71
71
  return {
72
- openFeeP: parseFloat(fee.openFeeP.toString()) / 1e12,
73
- closeFeeP: parseFloat(fee.closeFeeP.toString()) / 1e12,
74
- triggerOrderFeeP: parseFloat(fee.triggerOrderFeeP.toString()) / 1e12,
75
- minPositionSizeUsd: parseFloat(fee.minPositionSizeUsd.toString()) / 1e18,
72
+ totalPositionSizeFeeP: parseFloat(fee.totalPositionSizeFeeP.toString()) / 1e12,
73
+ totalLiqCollateralFeeP: parseFloat(fee.totalLiqCollateralFeeP.toString()) / 1e12,
74
+ oraclePositionSizeFeeP: parseFloat(fee.oraclePositionSizeFeeP.toString()) / 1e12,
75
+ minPositionSizeUsd: parseFloat(fee.minPositionSizeUsd.toString()) / 1e3,
76
76
  };
77
77
  });
78
78
  }
@@ -22,8 +22,8 @@ const getClosingFee = (posDai, leverage, pairIndex, pairFee, collateralPriceUsd
22
22
  pairFee === undefined) {
23
23
  return 0;
24
24
  }
25
- const { closeFeeP, triggerOrderFeeP, minPositionSizeUsd } = pairFee;
26
- return ((closeFeeP + triggerOrderFeeP) *
25
+ const { totalPositionSizeFeeP, minPositionSizeUsd } = pairFee;
26
+ return (totalPositionSizeFeeP *
27
27
  feeMultiplier *
28
28
  Math.max(collateralPriceUsd && collateralPriceUsd > 0
29
29
  ? minPositionSizeUsd / collateralPriceUsd
@@ -1,17 +1,16 @@
1
- import { LiquidationParams, OiWindows, OiWindowsSettings, PairDepth } from "./types";
1
+ import { LiquidationParams, OiWindows, OiWindowsSettings, PairDepth, PairFactor } from "./types";
2
2
  import { ContractsVersion } from "../contracts/types";
3
3
  export type SpreadContext = {
4
4
  isOpen?: boolean;
5
5
  isPnlPositive?: boolean;
6
- protectionCloseFactor?: number;
7
- protectionCloseFactorBlocks?: number;
8
- cumulativeFactor?: number;
9
6
  createdBlock?: number;
10
7
  liquidationParams?: LiquidationParams | undefined;
11
8
  currentBlock?: number | undefined;
12
9
  contractsVersion?: ContractsVersion | undefined;
13
- };
10
+ protectionCloseFactorWhitelist?: boolean;
11
+ } & Partial<PairFactor>;
14
12
  export declare const getProtectionCloseFactor: (spreadCtx: SpreadContext | undefined) => number;
13
+ export declare const isProtectionCloseFactorActive: (spreadCtx: SpreadContext | undefined) => boolean | undefined;
15
14
  export declare const getCumulativeFactor: (spreadCtx: SpreadContext | undefined) => number;
16
15
  export declare const getLegacyFactor: (spreadCtx: SpreadContext | undefined) => number;
17
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");
@@ -9,23 +9,32 @@ const getProtectionCloseFactor = (spreadCtx) => {
9
9
  spreadCtx.contractsVersion === types_1.ContractsVersion.BEFORE_V9_2 ||
10
10
  spreadCtx.isOpen === undefined ||
11
11
  spreadCtx.isPnlPositive === undefined ||
12
- spreadCtx.protectionCloseFactor === undefined ||
13
- spreadCtx.protectionCloseFactorBlocks === undefined ||
14
- spreadCtx.createdBlock === undefined ||
15
- spreadCtx.currentBlock === undefined)
12
+ (0, exports.isProtectionCloseFactorActive)(spreadCtx) !== true)
16
13
  return constants_1.DEFAULT_PROTECTION_CLOSE_FACTOR;
17
- if (spreadCtx.isPnlPositive &&
18
- !spreadCtx.isOpen &&
14
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15
+ return spreadCtx.protectionCloseFactor;
16
+ };
17
+ exports.getProtectionCloseFactor = getProtectionCloseFactor;
18
+ const isProtectionCloseFactorActive = (spreadCtx) => {
19
+ if (spreadCtx === undefined ||
20
+ spreadCtx.currentBlock === undefined ||
21
+ spreadCtx.createdBlock === undefined ||
22
+ spreadCtx.protectionCloseFactorBlocks === undefined ||
23
+ spreadCtx.protectionCloseFactor === undefined) {
24
+ return undefined;
25
+ }
26
+ return (spreadCtx.isPnlPositive === true &&
27
+ spreadCtx.isOpen === false &&
19
28
  spreadCtx.protectionCloseFactor > 0 &&
20
29
  spreadCtx.currentBlock <=
21
- spreadCtx.createdBlock + spreadCtx.protectionCloseFactorBlocks) {
22
- return spreadCtx.protectionCloseFactor;
23
- }
24
- return constants_1.DEFAULT_PROTECTION_CLOSE_FACTOR;
30
+ spreadCtx.createdBlock + spreadCtx.protectionCloseFactorBlocks &&
31
+ spreadCtx.protectionCloseFactorWhitelist !== true);
25
32
  };
26
- exports.getProtectionCloseFactor = getProtectionCloseFactor;
33
+ exports.isProtectionCloseFactorActive = isProtectionCloseFactorActive;
27
34
  const getCumulativeFactor = (spreadCtx) => {
28
- if (spreadCtx === undefined || spreadCtx.cumulativeFactor === undefined || spreadCtx.cumulativeFactor === 0) {
35
+ if (spreadCtx === undefined ||
36
+ spreadCtx.cumulativeFactor === undefined ||
37
+ spreadCtx.cumulativeFactor === 0) {
29
38
  return constants_1.DEFAULT_CUMULATIVE_FACTOR;
30
39
  }
31
40
  return spreadCtx.cumulativeFactor;
@@ -39,9 +48,17 @@ const getSpreadWithPriceImpactP = (pairSpreadP, buy, collateral, leverage, pairD
39
48
  if (pairSpreadP === undefined) {
40
49
  return 0;
41
50
  }
51
+ if (
42
52
  // No spread or price impact when closing pre-v9.2 trades
43
- if ((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === false &&
44
- (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.contractsVersion) === types_1.ContractsVersion.BEFORE_V9_2) {
53
+ ((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === false &&
54
+ (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.contractsVersion) === types_1.ContractsVersion.BEFORE_V9_2) ||
55
+ // No spread or price impact for opens when `pair.exemptOnOpen` is true
56
+ ((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === true && (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.exemptOnOpen) === true) ||
57
+ // No spread or price impact for closes after `protectionCloseFactor` has expired
58
+ // when `pair.exemptAfterProtectionCloseFactor` is true
59
+ ((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === false &&
60
+ (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.exemptAfterProtectionCloseFactor) === true &&
61
+ (0, exports.isProtectionCloseFactorActive)(spreadCtx) !== true)) {
45
62
  return 0;
46
63
  }
47
64
  const onePercentDepth = buy
@@ -48,10 +48,17 @@ export type TradingGroup = {
48
48
  name: string;
49
49
  };
50
50
  export type Fee = {
51
- openFeeP: number;
52
- closeFeeP: number;
51
+ totalPositionSizeFeeP: number;
52
+ totalLiqCollateralFeeP: number;
53
+ oraclePositionSizeFeeP: number;
53
54
  minPositionSizeUsd: number;
55
+ };
56
+ export type GlobalTradeFeeParams = {
57
+ referralFeeP: number;
58
+ govFeeP: number;
54
59
  triggerOrderFeeP: number;
60
+ gnsOtcFeeP: number;
61
+ gTokenFeeP: number;
55
62
  };
56
63
  export type PairDepth = {
57
64
  onePercentDepthAboveUsd: number;
@@ -169,11 +176,14 @@ export type TraderFeeTiers = {
169
176
  outboundPoints: number;
170
177
  lastDayUpdatedPoints: number;
171
178
  expiredPoints: number[];
179
+ unclaimedPoints: number;
172
180
  };
173
181
  export type PairFactor = {
174
182
  cumulativeFactor: number;
175
183
  protectionCloseFactor: number;
176
184
  protectionCloseFactorBlocks: number;
185
+ exemptOnOpen: boolean;
186
+ exemptAfterProtectionCloseFactor: boolean;
177
187
  };
178
188
  export declare enum PendingOrderType {
179
189
  MARKET_OPEN = 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gainsnetwork/sdk",
3
- "version": "0.2.35-rc1",
3
+ "version": "0.2.37-rc1",
4
4
  "description": "Gains Network SDK",
5
5
  "main": "./lib/index.js",
6
6
  "files": [