@gainsnetwork/sdk 0.2.61-rc2 → 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.
- package/lib/constants.d.ts +6 -0
- package/lib/constants.js +9 -1
- package/lib/contracts/types/generated/GNSMultiCollatDiamond.d.ts +311 -47
- package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.d.ts +45 -36
- package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +669 -47
- package/lib/contracts/utils/pairs.js +6 -0
- package/lib/trade/liquidation.d.ts +2 -1
- package/lib/trade/liquidation.js +6 -4
- package/lib/trade/spread.d.ts +3 -2
- package/lib/trade/spread.js +17 -9
- package/lib/trade/types.d.ts +11 -1
- package/lib/trade/types.js +6 -0
- package/package.json +1 -1
|
@@ -469,4 +469,10 @@ const PAIR_INDEX_TO_DESCRIPTION = {
|
|
|
469
469
|
[types_1.PairIndex.PARTIUSD]: "Particle Network to US Dollar",
|
|
470
470
|
[types_1.PairIndex.SIRENUSD]: "Siren to US Dollar",
|
|
471
471
|
[types_1.PairIndex.BANANAS31]: "Banana For Scale to US Dollar",
|
|
472
|
+
[types_1.PairIndex.HYPERUSD]: "Hyperlane to US Dollar",
|
|
473
|
+
[types_1.PairIndex.PROMPTUSD]: "Wayfinder to US Dollar",
|
|
474
|
+
[types_1.PairIndex.RFCUSD]: "Retard Finder Coin to US Dollar",
|
|
475
|
+
[types_1.PairIndex.WCTUSD]: "WalletConnect Token to US Dollar",
|
|
476
|
+
[types_1.PairIndex.BIGTIMEUSD]: "Big Time to US Dollar",
|
|
477
|
+
[types_1.PairIndex.BABYUSD]: "Babylon to US Dollar",
|
|
472
478
|
};
|
|
@@ -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;
|
package/lib/trade/liquidation.js
CHANGED
|
@@ -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
|
-
|
|
20
|
-
|
|
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
|
package/lib/trade/spread.d.ts
CHANGED
|
@@ -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;
|
package/lib/trade/spread.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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 &&
|
package/lib/trade/types.d.ts
CHANGED
|
@@ -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,
|
|
@@ -582,5 +586,11 @@ export declare enum PairIndex {
|
|
|
582
586
|
NILUSD = 360,
|
|
583
587
|
PARTIUSD = 361,
|
|
584
588
|
SIRENUSD = 362,
|
|
585
|
-
BANANAS31 = 363
|
|
589
|
+
BANANAS31 = 363,
|
|
590
|
+
HYPERUSD = 364,
|
|
591
|
+
PROMPTUSD = 365,
|
|
592
|
+
RFCUSD = 366,
|
|
593
|
+
WCTUSD = 367,
|
|
594
|
+
BIGTIMEUSD = 368,
|
|
595
|
+
BABYUSD = 369
|
|
586
596
|
}
|
package/lib/trade/types.js
CHANGED
|
@@ -393,4 +393,10 @@ var PairIndex;
|
|
|
393
393
|
PairIndex[PairIndex["PARTIUSD"] = 361] = "PARTIUSD";
|
|
394
394
|
PairIndex[PairIndex["SIRENUSD"] = 362] = "SIRENUSD";
|
|
395
395
|
PairIndex[PairIndex["BANANAS31"] = 363] = "BANANAS31";
|
|
396
|
+
PairIndex[PairIndex["HYPERUSD"] = 364] = "HYPERUSD";
|
|
397
|
+
PairIndex[PairIndex["PROMPTUSD"] = 365] = "PROMPTUSD";
|
|
398
|
+
PairIndex[PairIndex["RFCUSD"] = 366] = "RFCUSD";
|
|
399
|
+
PairIndex[PairIndex["WCTUSD"] = 367] = "WCTUSD";
|
|
400
|
+
PairIndex[PairIndex["BIGTIMEUSD"] = 368] = "BIGTIMEUSD";
|
|
401
|
+
PairIndex[PairIndex["BABYUSD"] = 369] = "BABYUSD";
|
|
396
402
|
})(PairIndex = exports.PairIndex || (exports.PairIndex = {}));
|