@gainsnetwork/sdk 0.2.62-rc1 → 0.2.63-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.
@@ -1,11 +1,12 @@
1
1
  import { GetBorrowingFeeContext, BorrowingFee } from "./fees";
2
- import { Fee, LiquidationParams, Trade } from "./types";
2
+ import { Fee, LiquidationParams, Trade, UserPriceImpact } from "./types";
3
3
  import { ContractsVersion } from "../contracts/types";
4
4
  export type GetLiquidationPriceContext = GetBorrowingFeeContext & {
5
5
  liquidationParams: LiquidationParams | undefined;
6
6
  pairSpreadP: number | undefined;
7
7
  collateralPriceUsd: number | undefined;
8
8
  contractsVersion: ContractsVersion | undefined;
9
+ userPriceImpact?: UserPriceImpact | undefined;
9
10
  };
10
11
  export declare const getLiquidationPrice: (trade: Trade, fee: Fee, initialAccFees: BorrowingFee.InitialAccFees, context: GetLiquidationPriceContext) => number;
11
12
  export declare const getLiqPnlThresholdP: (liquidationParams: LiquidationParams | undefined, leverage: number | undefined) => number;
@@ -5,7 +5,7 @@ const fees_1 = require("./fees");
5
5
  const spread_1 = require("./spread");
6
6
  const types_1 = require("../contracts/types");
7
7
  const getLiquidationPrice = (trade, fee, initialAccFees, context) => {
8
- var _a;
8
+ var _a, _b;
9
9
  const closingFee = (0, fees_1.getClosingFee)(trade.collateralAmount, trade.leverage, trade.pairIndex, fee, context.collateralPriceUsd);
10
10
  const borrowingFee = (0, fees_1.getBorrowingFee)(trade.collateralAmount * trade.leverage, trade.pairIndex, trade.long, initialAccFees, context);
11
11
  const liqThresholdP = (0, exports.getLiqPnlThresholdP)(context.liquidationParams, trade.leverage);
@@ -15,9 +15,11 @@ const getLiquidationPrice = (trade, fee, initialAccFees, context) => {
15
15
  trade.leverage;
16
16
  if ((context === null || context === void 0 ? void 0 : context.contractsVersion) !== undefined &&
17
17
  context.contractsVersion >= types_1.ContractsVersion.V9_2 &&
18
- ((_a = context === null || context === void 0 ? void 0 : context.liquidationParams) === null || _a === void 0 ? void 0 : _a.maxLiqSpreadP) !== undefined &&
19
- context.liquidationParams.maxLiqSpreadP > 0) {
20
- const closingSpreadP = (0, spread_1.getSpreadP)(context.pairSpreadP, true, context.liquidationParams);
18
+ ((((_a = context === null || context === void 0 ? void 0 : context.liquidationParams) === null || _a === void 0 ? void 0 : _a.maxLiqSpreadP) !== undefined &&
19
+ context.liquidationParams.maxLiqSpreadP > 0) ||
20
+ (((_b = context === null || context === void 0 ? void 0 : context.userPriceImpact) === null || _b === void 0 ? void 0 : _b.fixedSpreadP) !== undefined &&
21
+ context.userPriceImpact.fixedSpreadP > 0))) {
22
+ const closingSpreadP = (0, spread_1.getSpreadP)(context.pairSpreadP, true, context.liquidationParams, context.userPriceImpact);
21
23
  liqPriceDistance -= trade.openPrice * closingSpreadP;
22
24
  }
23
25
  return trade.long
@@ -1,4 +1,4 @@
1
- import { LiquidationParams, OiWindows, OiWindowsSettings, PairDepth, PairFactor } from "./types";
1
+ import { LiquidationParams, OiWindows, OiWindowsSettings, PairDepth, PairFactor, UserPriceImpact } from "./types";
2
2
  import { ContractsVersion } from "../contracts/types";
3
3
  export type SpreadContext = {
4
4
  isOpen?: boolean;
@@ -8,10 +8,11 @@ export type SpreadContext = {
8
8
  currentBlock?: number | undefined;
9
9
  contractsVersion?: ContractsVersion | undefined;
10
10
  protectionCloseFactorWhitelist?: boolean;
11
+ userPriceImpact?: UserPriceImpact | undefined;
11
12
  } & Partial<PairFactor>;
12
13
  export declare const getProtectionCloseFactor: (spreadCtx: SpreadContext | undefined) => number;
13
14
  export declare const isProtectionCloseFactorActive: (spreadCtx: SpreadContext | undefined) => boolean | undefined;
14
15
  export declare const getCumulativeFactor: (spreadCtx: SpreadContext | undefined) => number;
15
16
  export declare const getLegacyFactor: (spreadCtx: SpreadContext | undefined) => number;
16
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;
17
- export declare const getSpreadP: (pairSpreadP: number | undefined, isLiquidation?: boolean | undefined, liquidationParams?: LiquidationParams | undefined) => number;
18
+ export declare const getSpreadP: (pairSpreadP: number | undefined, isLiquidation?: boolean | undefined, liquidationParams?: LiquidationParams | undefined, userPriceImpact?: UserPriceImpact | undefined) => number;
@@ -5,14 +5,20 @@ const oiWindows_1 = require("./oiWindows");
5
5
  const constants_1 = require("../constants");
6
6
  const types_1 = require("../contracts/types");
7
7
  const getProtectionCloseFactor = (spreadCtx) => {
8
- if (spreadCtx === undefined ||
8
+ var _a;
9
+ const protectionCloseFactor = spreadCtx === undefined ||
9
10
  spreadCtx.contractsVersion === types_1.ContractsVersion.BEFORE_V9_2 ||
10
11
  spreadCtx.isOpen === undefined ||
11
12
  spreadCtx.isPnlPositive === undefined ||
12
- (0, exports.isProtectionCloseFactorActive)(spreadCtx) !== true)
13
- return constants_1.DEFAULT_PROTECTION_CLOSE_FACTOR;
14
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15
- return spreadCtx.protectionCloseFactor;
13
+ spreadCtx.protectionCloseFactor === undefined ||
14
+ (0, exports.isProtectionCloseFactorActive)(spreadCtx) !== true
15
+ ? constants_1.DEFAULT_PROTECTION_CLOSE_FACTOR
16
+ : spreadCtx.protectionCloseFactor;
17
+ const protectionCloseFactorMultiplier = ((_a = spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.userPriceImpact) === null || _a === void 0 ? void 0 : _a.cumulVolPriceImpactMultiplier) !== undefined &&
18
+ spreadCtx.userPriceImpact.cumulVolPriceImpactMultiplier > 0
19
+ ? spreadCtx.userPriceImpact.cumulVolPriceImpactMultiplier
20
+ : 1;
21
+ return protectionCloseFactor * protectionCloseFactorMultiplier;
16
22
  };
17
23
  exports.getProtectionCloseFactor = getProtectionCloseFactor;
18
24
  const isProtectionCloseFactorActive = (spreadCtx) => {
@@ -77,7 +83,7 @@ const getSpreadWithPriceImpactP = (pairSpreadP, buy, collateral, leverage, pairD
77
83
  if (!onePercentDepth || activeOi === undefined || collateral === undefined) {
78
84
  return pairSpreadP / 2;
79
85
  }
80
- return ((0, exports.getSpreadP)(pairSpreadP) +
86
+ return ((0, exports.getSpreadP)(pairSpreadP, undefined, undefined, spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.userPriceImpact) +
81
87
  ((activeOi * (0, exports.getCumulativeFactor)(spreadCtx) + (collateral * leverage) / 2) /
82
88
  onePercentDepth /
83
89
  100 /
@@ -85,11 +91,13 @@ const getSpreadWithPriceImpactP = (pairSpreadP, buy, collateral, leverage, pairD
85
91
  (0, exports.getProtectionCloseFactor)(spreadCtx));
86
92
  };
87
93
  exports.getSpreadWithPriceImpactP = getSpreadWithPriceImpactP;
88
- const getSpreadP = (pairSpreadP, isLiquidation, liquidationParams) => {
89
- if (pairSpreadP === undefined || pairSpreadP === 0) {
94
+ const getSpreadP = (pairSpreadP, isLiquidation, liquidationParams, userPriceImpact) => {
95
+ var _a;
96
+ const fixedSpreadP = (_a = userPriceImpact === null || userPriceImpact === void 0 ? void 0 : userPriceImpact.fixedSpreadP) !== null && _a !== void 0 ? _a : 0;
97
+ if (pairSpreadP === undefined || (pairSpreadP === 0 && fixedSpreadP === 0)) {
90
98
  return 0;
91
99
  }
92
- const spreadP = pairSpreadP / 2;
100
+ const spreadP = pairSpreadP / 2 + fixedSpreadP;
93
101
  return isLiquidation === true &&
94
102
  liquidationParams !== undefined &&
95
103
  liquidationParams.maxLiqSpreadP > 0 &&
@@ -185,6 +185,10 @@ export type PairFactor = {
185
185
  exemptOnOpen: boolean;
186
186
  exemptAfterProtectionCloseFactor: boolean;
187
187
  };
188
+ export type UserPriceImpact = {
189
+ cumulVolPriceImpactMultiplier: number;
190
+ fixedSpreadP: number;
191
+ };
188
192
  export declare enum PendingOrderType {
189
193
  MARKET_OPEN = 0,
190
194
  MARKET_CLOSE = 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gainsnetwork/sdk",
3
- "version": "0.2.62-rc1",
3
+ "version": "0.2.63-rc1",
4
4
  "description": "Gains Network SDK",
5
5
  "main": "./lib/index.js",
6
6
  "files": [