@gainsnetwork/sdk 1.3.0-rc2 → 1.3.0-rc4
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.
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @dev Mirrors contract's getTradeCumulVolPriceImpactP functionality
|
|
4
4
|
*/
|
|
5
5
|
import { PairDepthBands, DepthBandsMapping } from "./types";
|
|
6
|
-
import { LiquidationParams, OiWindows, OiWindowsSettings,
|
|
6
|
+
import { LiquidationParams, OiWindows, OiWindowsSettings, PairFactor, UserPriceImpact } from "../../types";
|
|
7
7
|
import { ContractsVersion } from "../../../contracts/types";
|
|
8
8
|
export type CumulVolContext = {
|
|
9
9
|
isOpen?: boolean;
|
|
@@ -85,13 +85,12 @@ export declare const getSpreadP: (pairSpreadP: number | undefined, isLiquidation
|
|
|
85
85
|
* @param buy True for long, false for short
|
|
86
86
|
* @param collateral Collateral amount
|
|
87
87
|
* @param leverage Position leverage
|
|
88
|
-
* @param pairDepth 1% depth values for the pair
|
|
89
88
|
* @param oiWindowsSettings OI windows configuration
|
|
90
89
|
* @param oiWindows Current OI windows data
|
|
91
90
|
* @param context Additional context for the calculation
|
|
92
91
|
* @returns Total spread + cumulative volume price impact percentage
|
|
93
92
|
*/
|
|
94
|
-
export declare const getSpreadWithCumulVolPriceImpactP: (pairSpreadP: number, buy: boolean, collateral: number, leverage: number,
|
|
93
|
+
export declare const getSpreadWithCumulVolPriceImpactP: (pairSpreadP: number, buy: boolean, collateral: number, leverage: number, context: CumulVolContext) => number;
|
|
95
94
|
/**
|
|
96
95
|
* @dev Convenience function for calculating cumulative volume price impact
|
|
97
96
|
* @dev Uses collateral and leverage instead of USD position size
|
|
@@ -105,6 +104,6 @@ export declare const getSpreadWithCumulVolPriceImpactP: (pairSpreadP: number, bu
|
|
|
105
104
|
export declare const getCumulVolPriceImpact: (buy: boolean, collateral: number, leverage: number, open: boolean, context: CumulVolContext & {
|
|
106
105
|
collateralPriceUsd: number;
|
|
107
106
|
}) => number;
|
|
108
|
-
export declare const getSpreadWithPriceImpactP: (pairSpreadP: number, buy: boolean, collateral: number, leverage: number,
|
|
107
|
+
export declare const getSpreadWithPriceImpactP: (pairSpreadP: number, buy: boolean, collateral: number, leverage: number, context: CumulVolContext) => number;
|
|
109
108
|
export { convertOiWindowsSettings, convertOiWindow, convertOiWindows, convertOiWindowsSettingsArray, } from "./converter";
|
|
110
109
|
export { buildCumulVolContext } from "./builder";
|
|
@@ -263,13 +263,12 @@ exports.getSpreadP = getSpreadP;
|
|
|
263
263
|
* @param buy True for long, false for short
|
|
264
264
|
* @param collateral Collateral amount
|
|
265
265
|
* @param leverage Position leverage
|
|
266
|
-
* @param pairDepth 1% depth values for the pair
|
|
267
266
|
* @param oiWindowsSettings OI windows configuration
|
|
268
267
|
* @param oiWindows Current OI windows data
|
|
269
268
|
* @param context Additional context for the calculation
|
|
270
269
|
* @returns Total spread + cumulative volume price impact percentage
|
|
271
270
|
*/
|
|
272
|
-
const getSpreadWithCumulVolPriceImpactP = (pairSpreadP, buy, collateral, leverage,
|
|
271
|
+
const getSpreadWithCumulVolPriceImpactP = (pairSpreadP, buy, collateral, leverage, context) => {
|
|
273
272
|
if (pairSpreadP === undefined) {
|
|
274
273
|
return 0;
|
|
275
274
|
}
|
|
@@ -278,12 +277,7 @@ const getSpreadWithCumulVolPriceImpactP = (pairSpreadP, buy, collateral, leverag
|
|
|
278
277
|
const positionSizeUsd = collateral * leverage * ((context === null || context === void 0 ? void 0 : context.collateralPriceUsd) || 1);
|
|
279
278
|
const cumulVolImpact = (0, exports.getTradeCumulVolPriceImpactP)("", // trader - not used in calculation
|
|
280
279
|
0, // pairIndex - not used in calculation
|
|
281
|
-
buy, positionSizeUsd, (context === null || context === void 0 ? void 0 : context.isPnlPositive) || false, (context === null || context === void 0 ? void 0 : context.isOpen) !== false, (context === null || context === void 0 ? void 0 : context.createdBlock) || 0,
|
|
282
|
-
oiWindows }));
|
|
283
|
-
// If no depth or OI data, return just half spread
|
|
284
|
-
if (cumulVolImpact === 0 && (!pairDepth || !oiWindowsSettings)) {
|
|
285
|
-
return pairSpreadP / 2;
|
|
286
|
-
}
|
|
280
|
+
buy, positionSizeUsd, (context === null || context === void 0 ? void 0 : context.isPnlPositive) || false, (context === null || context === void 0 ? void 0 : context.isOpen) !== false, (context === null || context === void 0 ? void 0 : context.createdBlock) || 0, context);
|
|
287
281
|
return baseSpread + cumulVolImpact;
|
|
288
282
|
};
|
|
289
283
|
exports.getSpreadWithCumulVolPriceImpactP = getSpreadWithCumulVolPriceImpactP;
|