@gainsnetwork/sdk 0.0.0-v10.rc14 → 0.0.0-v10.rc16

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.
@@ -386,6 +386,16 @@ export declare const pairs: {
386
386
  "BVIV/USD": string;
387
387
  "EVIV/USD": string;
388
388
  "CRCL/USD": string;
389
+ "RESOLV/USD": string;
390
+ "SQD/USD": string;
391
+ "TAIKO/USD": string;
392
+ "HOME/USD": string;
393
+ "B/USD": string;
394
+ "HUMA/USD": string;
395
+ "SBET/USD": string;
396
+ "PLTR/USD": string;
397
+ "BIDU/USD": string;
398
+ "ROKU/USD": string;
389
399
  };
390
400
  export declare const syntheticPairs: Set<string>;
391
401
  export declare const parentToSyntheticPairMap: Map<string, string>;
package/lib/constants.js CHANGED
@@ -394,6 +394,16 @@ exports.pairs = {
394
394
  "BVIV/USD": CRYPTO,
395
395
  "EVIV/USD": CRYPTO,
396
396
  "CRCL/USD": STOCKS,
397
+ "RESOLV/USD": CRYPTO,
398
+ "SQD/USD": CRYPTO,
399
+ "TAIKO/USD": CRYPTO,
400
+ "HOME/USD": CRYPTO,
401
+ "B/USD": CRYPTO,
402
+ "HUMA/USD": CRYPTO,
403
+ "SBET/USD": STOCKS,
404
+ "PLTR/USD": STOCKS,
405
+ "BIDU/USD": STOCKS,
406
+ "ROKU/USD": STOCKS,
397
407
  };
398
408
  exports.syntheticPairs = new Set([
399
409
  "BTCDEGEN/USD",
@@ -442,11 +452,12 @@ exports.stockSplits = {
442
452
  };
443
453
  exports.delistedPairIxs = new Set([
444
454
  4, 6, 15, 24, 25, 27, 28, 30, 31, 36, 48, 51, 52, 53, 54, 56, 59, 60, 61, 63,
445
- 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 95, 96, 97, 98,
446
- 99, 101, 106, 111, 113, 114, 116, 118, 120, 122, 123, 125, 127, 130, 147, 152,
455
+ 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 95, 96, 97, 98, 99,
456
+ 101, 106, 111, 113, 114, 116, 118, 120, 122, 123, 125, 127, 130, 147, 152,
447
457
  160, 163, 170, 179, 182, 183, 187, 188, 189, 190, 208, 209, 225, 229, 230,
448
458
  231, 238, 239, 241, 250, 253, 254, 258, 270, 275, 276, 278, 279, 282, 285,
449
459
  290, 294, 296, 305, 330, 349, 352, 353, 354, 355, 357, 365, 366, 384, 385,
460
+ 393, 394, 395, 396,
450
461
  ]);
451
462
  exports.delistedGroupsIxs = new Set([]);
452
463
  exports.DEFAULT_PROTECTION_CLOSE_FACTOR = 1;
@@ -22,6 +22,10 @@
22
22
  "GNS": {
23
23
  "gTokenOpenPnlFeed": "0x0000000000000000000000000000000000000000",
24
24
  "gToken": "0x0000000000000000000000000000000000000000"
25
+ },
26
+ "BTCUSD": {
27
+ "gTokenOpenPnlFeed": "0x0000000000000000000000000000000000000000",
28
+ "gToken": "0x0000000000000000000000000000000000000000"
25
29
  }
26
30
  },
27
31
  "42161": {
@@ -47,6 +51,10 @@
47
51
  "GNS": {
48
52
  "gTokenOpenPnlFeed": "0x4ca1638754Be8060E544Aca4A4F43702Be30E0D1",
49
53
  "gToken": "0x4BeeF1113F968326905224D2Ca272f3032A9a9F4"
54
+ },
55
+ "BTCUSD": {
56
+ "gTokenOpenPnlFeed": "0x0000000000000000000000000000000000000000",
57
+ "gToken": "0x0000000000000000000000000000000000000000"
50
58
  }
51
59
  },
52
60
  "421614": {
@@ -72,6 +80,10 @@
72
80
  "GNS": {
73
81
  "gTokenOpenPnlFeed": "0x68F8D4ec2EF23a15e61e1642E730b6f69fB9A5De",
74
82
  "gToken": "0x5ed4bEA869300DB39bE2a92a8B42e53453742a43"
83
+ },
84
+ "BTCUSD": {
85
+ "gTokenOpenPnlFeed": "0x0000000000000000000000000000000000000000",
86
+ "gToken": "0x0000000000000000000000000000000000000000"
75
87
  }
76
88
  },
77
89
  "8453": {
@@ -97,6 +109,10 @@
97
109
  "GNS": {
98
110
  "gTokenOpenPnlFeed": "0x0000000000000000000000000000000000000000",
99
111
  "gToken": "0x0000000000000000000000000000000000000000"
112
+ },
113
+ "BTCUSD": {
114
+ "gTokenOpenPnlFeed": "0xA22F7b92d81Dd74bE5ca5758DF3FccF0A4CB19cc",
115
+ "gToken": "0xB7Cb7cB7C3cD96e251c9bF8800B9631134BbAdc6"
100
116
  }
101
117
  },
102
118
  "33139": {
@@ -122,6 +138,10 @@
122
138
  "GNS": {
123
139
  "gTokenOpenPnlFeed": "0x0000000000000000000000000000000000000000",
124
140
  "gToken": "0x0000000000000000000000000000000000000000"
141
+ },
142
+ "BTCUSD": {
143
+ "gTokenOpenPnlFeed": "0x0000000000000000000000000000000000000000",
144
+ "gToken": "0x0000000000000000000000000000000000000000"
125
145
  }
126
146
  }
127
147
  }
@@ -63,6 +63,7 @@ exports.COLLATERAL_TO_CHAIN_COLLATERAL_INDEX = {
63
63
  },
64
64
  [types_1.ChainId.BASE]: {
65
65
  [types_1.CollateralTypes.USDC]: 1,
66
+ [types_1.CollateralTypes.BTCUSD]: 2,
66
67
  },
67
68
  [types_1.ChainId.APECHAIN]: {
68
69
  [types_1.CollateralTypes.APE]: 1,
@@ -75,7 +76,8 @@ exports.COLLATERAL_TO_COLLATERAL_INDEX = {
75
76
  [types_1.CollateralTypes.USDC]: 3,
76
77
  [types_1.CollateralTypes.ARB]: 0,
77
78
  [types_1.CollateralTypes.APE]: 0,
78
- [types_1.CollateralTypes.GNS]: 0, // not in use
79
+ [types_1.CollateralTypes.GNS]: 0,
80
+ [types_1.CollateralTypes.BTCUSD]: 0,
79
81
  };
80
82
  __exportStar(require("./utils"), exports);
81
83
  __exportStar(require("./addresses"), exports);
@@ -16,7 +16,8 @@ export declare enum CollateralTypes {
16
16
  ARB = "ARB",
17
17
  USDC = "USDC",
18
18
  APE = "APE",
19
- GNS = "GNS"
19
+ GNS = "GNS",
20
+ BTCUSD = "BTCUSD"
20
21
  }
21
22
  export declare enum ContractsVersion {
22
23
  BEFORE_V9_2 = 0,
@@ -9,6 +9,7 @@ var CollateralTypes;
9
9
  CollateralTypes["USDC"] = "USDC";
10
10
  CollateralTypes["APE"] = "APE";
11
11
  CollateralTypes["GNS"] = "GNS";
12
+ CollateralTypes["BTCUSD"] = "BTCUSD";
12
13
  })(CollateralTypes = exports.CollateralTypes || (exports.CollateralTypes = {}));
13
14
  var ContractsVersion;
14
15
  (function (ContractsVersion) {
@@ -492,4 +492,14 @@ const PAIR_INDEX_TO_DESCRIPTION = {
492
492
  [types_1.PairIndex.BVIVUSD]: "Bitcoin Volmex Implied Volatility 30 Day Index to US Dollar",
493
493
  [types_1.PairIndex.EVIVUSD]: "Ethereum Volmex Implied Volatility 30 Day Index to US Dollar",
494
494
  [types_1.PairIndex.CRCLUSD]: "Circle Internet Group to US Dollar",
495
+ [types_1.PairIndex.RESOLVUSD]: "Resolv to US Dollar",
496
+ [types_1.PairIndex.SQDUSD]: "Subsquid to US Dollar",
497
+ [types_1.PairIndex.TAIKOUSD]: "Taiko to US Dollar",
498
+ [types_1.PairIndex.HOMEUSD]: "Defi App to US Dollar",
499
+ [types_1.PairIndex.BUSD]: "BUILDon to US Dollar",
500
+ [types_1.PairIndex.HUMAUSD]: "Huma Finance to US Dollar",
501
+ [types_1.PairIndex.SBETUSD]: "Sharplink Gaming Inc to US Dollar",
502
+ [types_1.PairIndex.PLTRUSD]: "Palantir Technologies to US Dollar",
503
+ [types_1.PairIndex.BIDUUSD]: "Baidu to US Dollar",
504
+ [types_1.PairIndex.ROKUUSD]: "Roku to US Dollar",
495
505
  };
@@ -19,7 +19,6 @@ export type GetBorrowingFeeContext = {
19
19
  */
20
20
  export declare const getBorrowingFee: (posDai: number, pairIndex: PairIndex | undefined, long: boolean, initialAccFees: BorrowingFee.InitialAccFees, context: GetBorrowingFeeContext) => number;
21
21
  /**
22
- * @deprecated Use withinMaxGroupOiDynamic from @gains-network/sdk/markets/oi instead
23
22
  * @dev This function uses static OI which doesn't reflect current market values
24
23
  * @dev The v10 contracts use dynamic OI (beforeV10 + afterV10Token * currentPrice)
25
24
  */
@@ -78,7 +78,6 @@ const getBorrowingFee = (posDai, pairIndex, long, initialAccFees, context) => {
78
78
  };
79
79
  exports.getBorrowingFee = getBorrowingFee;
80
80
  /**
81
- * @deprecated Use withinMaxGroupOiDynamic from @gains-network/sdk/markets/oi instead
82
81
  * @dev This function uses static OI which doesn't reflect current market values
83
82
  * @dev The v10 contracts use dynamic OI (beforeV10 + afterV10Token * currentPrice)
84
83
  */
@@ -8,6 +8,8 @@ exports.getTradeClosingPriceImpactAtOracle = exports.getTradeClosingPriceImpact
8
8
  const cumulVol_1 = require("../cumulVol");
9
9
  const skew_1 = require("../skew");
10
10
  const types_1 = require("../../../contracts/types");
11
+ const pnl_1 = require("../../pnl");
12
+ const __1 = require("../");
11
13
  // Export builder
12
14
  var builder_1 = require("./builder");
13
15
  Object.defineProperty(exports, "buildTradeClosingPriceImpactContext", { enumerable: true, get: function () { return builder_1.buildTradeClosingPriceImpactContext; } });
@@ -63,29 +65,16 @@ const getTradeClosingPriceImpact = (input, context) => {
63
65
  false, // closing
64
66
  context.tradeInfo.lastPosIncreaseBlock || context.tradeInfo.createdBlock, context.cumulVolContext);
65
67
  // Calculate price with conservative impact
66
- const priceWithImpact = input.trade.long
67
- ? input.currentPairPrice *
68
- (1 - (fixedSpreadP + cumulVolPriceImpactP) / 100)
69
- : input.currentPairPrice /
70
- (1 - (fixedSpreadP + cumulVolPriceImpactP) / 100);
71
- // Calculate trade value in collateral
72
- // For long: value = positionSizeToken * priceWithImpact
73
- // For short: value = positionSizeToken / priceWithImpact * openPrice^2 / currentPrice
74
- if (positionSizeToken > 0) {
75
- if (input.trade.long) {
76
- tradeValueCollateralNoFactor = positionSizeToken * priceWithImpact;
77
- }
78
- else {
79
- // Short calculation: profit from price decrease
80
- const pnlFactor = (2 * input.trade.openPrice - priceWithImpact) / input.trade.openPrice;
81
- tradeValueCollateralNoFactor = input.positionSizeCollateral * pnlFactor;
82
- }
83
- }
84
- else {
85
- tradeValueCollateralNoFactor = input.positionSizeCollateral;
86
- }
87
- // Determine actual PnL
88
- const isPnlPositive = tradeValueCollateralNoFactor > input.trade.collateralAmount;
68
+ const priceWithImpact = (0, __1.getPriceAfterImpact)(input.currentPairPrice, fixedSpreadP + cumulVolPriceImpactP);
69
+ // Calculate PnL percentage using the proper function
70
+ const pnlPercent = (0, pnl_1.getPnlPercent)(input.trade.openPrice, priceWithImpact, input.trade.long, input.trade.leverage);
71
+ // Calculate trade value using getTradeValue function
72
+ // Note: We don't include fees here as this is the raw trade value
73
+ tradeValueCollateralNoFactor = (0, pnl_1.getTradeValue)(input.trade.collateralAmount, pnlPercent, 0 // No fees for raw trade value calculation
74
+ );
75
+ // Determine actual PnL from the calculated percentage
76
+ const isPnlPositive = pnlPercent > 0;
77
+ console.log("isPnlPositive", isPnlPositive);
89
78
  // Second pass: Recalculate with actual PnL if positive
90
79
  if (isPnlPositive) {
91
80
  cumulVolPriceImpactP = (0, cumulVol_1.getTradeCumulVolPriceImpactP)(input.trade.user, input.pairIndex, input.trade.long, positionSizeUsd, true, // Positive PnL
@@ -110,10 +99,8 @@ const getTradeClosingPriceImpact = (input, context) => {
110
99
  // Total price impact (all components)
111
100
  const totalPriceImpactP = fixedSpreadP + cumulVolPriceImpactP + skewPriceImpactP;
112
101
  // Calculate final price after all impacts
113
- // For closing: longs get worse price when impact is positive, shorts get better
114
- const priceAfterImpact = input.trade.long
115
- ? input.currentPairPrice * (1 - totalPriceImpactP / 100)
116
- : input.currentPairPrice / (1 - totalPriceImpactP / 100);
102
+ // The direction is already handled by getFixedSpreadP (reverses for closing)
103
+ const priceAfterImpact = (0, __1.getPriceAfterImpact)(input.currentPairPrice, totalPriceImpactP);
117
104
  return {
118
105
  positionSizeToken,
119
106
  fixedSpreadP,
@@ -43,6 +43,13 @@ const isProtectionCloseFactorActive = (context) => {
43
43
  context.protectionCloseFactor === undefined) {
44
44
  return undefined;
45
45
  }
46
+ console.log("context.isPnlPositive", context.isPnlPositive);
47
+ console.log("context.isOpen", context.isOpen);
48
+ console.log("context.protectionCloseFactor", context.protectionCloseFactor);
49
+ console.log("context.currentBlock", context.currentBlock);
50
+ console.log("context.createdBlock", context.createdBlock);
51
+ console.log("context.protectionCloseFactorBlocks", context.protectionCloseFactorBlocks);
52
+ console.log("context.protectionCloseFactorWhitelist", context.protectionCloseFactorWhitelist);
46
53
  return (context.isPnlPositive === true &&
47
54
  context.isOpen === false &&
48
55
  context.protectionCloseFactor > 0 &&
@@ -88,7 +95,7 @@ exports.getLegacyFactor = getLegacyFactor;
88
95
  * @returns Cumulative volume price impact percentage (not including spread)
89
96
  */
90
97
  const getTradeCumulVolPriceImpactP = (trader, pairIndex, long, tradeOpenInterestUsd, isPnlPositive, open, lastPosIncreaseBlock, context) => {
91
- var _a, _b, _c, _d;
98
+ var _a, _b;
92
99
  // Update context with passed parameters
93
100
  const updatedContext = Object.assign(Object.assign({}, context), { isOpen: open, isPnlPositive: isPnlPositive, createdBlock: context.createdBlock || lastPosIncreaseBlock });
94
101
  if (
@@ -103,15 +110,15 @@ const getTradeCumulVolPriceImpactP = (trader, pairIndex, long, tradeOpenInterest
103
110
  (0, exports.isProtectionCloseFactorActive)(updatedContext) !== true)) {
104
111
  return 0;
105
112
  }
106
- const onePercentDepth = long
107
- ? // if `long`
108
- open
109
- ? (_a = context.pairDepth) === null || _a === void 0 ? void 0 : _a.onePercentDepthAboveUsd
110
- : (_b = context.pairDepth) === null || _b === void 0 ? void 0 : _b.onePercentDepthBelowUsd
111
- : // if `short`
112
- open
113
- ? (_c = context.pairDepth) === null || _c === void 0 ? void 0 : _c.onePercentDepthBelowUsd
114
- : (_d = context.pairDepth) === null || _d === void 0 ? void 0 : _d.onePercentDepthAboveUsd;
113
+ // Calculate trade skew direction (matches Solidity logic)
114
+ const tradePositiveSkew = (long && open) || (!long && !open);
115
+ const tradeSkewMultiplier = tradePositiveSkew ? 1 : -1;
116
+ // Select depth based on trade direction
117
+ // For positive skew (long open or short close), use depth above
118
+ // For negative skew (short open or long close), use depth below
119
+ const onePercentDepth = tradePositiveSkew
120
+ ? (_a = context.pairDepth) === null || _a === void 0 ? void 0 : _a.onePercentDepthAboveUsd
121
+ : (_b = context.pairDepth) === null || _b === void 0 ? void 0 : _b.onePercentDepthBelowUsd;
115
122
  let activeOi = undefined;
116
123
  if (context.oiWindowsSettings !== undefined) {
117
124
  activeOi = (0, oiWindows_1.getActiveOi)((0, oiWindows_1.getCurrentOiWindowId)(context.oiWindowsSettings), context.oiWindowsSettings.windowsCount, context.oiWindows, open ? long : !long);
@@ -119,11 +126,21 @@ const getTradeCumulVolPriceImpactP = (trader, pairIndex, long, tradeOpenInterest
119
126
  if (!onePercentDepth || activeOi === undefined) {
120
127
  return 0;
121
128
  }
122
- const finalPriceImpactP = ((activeOi * (0, exports.getCumulativeFactor)(updatedContext) +
123
- tradeOpenInterestUsd / 2) /
129
+ // Apply trade skew multiplier to match Solidity's signed calculation
130
+ const signedActiveOi = activeOi * tradeSkewMultiplier;
131
+ const signedTradeOi = tradeOpenInterestUsd * tradeSkewMultiplier;
132
+ // Calculate impact with proper signs (matching Solidity's _getTradePriceImpactP)
133
+ const finalPriceImpactP = ((signedActiveOi * (0, exports.getCumulativeFactor)(updatedContext) +
134
+ signedTradeOi / 2) /
124
135
  onePercentDepth /
125
136
  (0, exports.getLegacyFactor)(updatedContext)) *
126
137
  (0, exports.getProtectionCloseFactor)(updatedContext);
138
+ console.log("signedActiveOi", signedActiveOi);
139
+ console.log("getCumulativeFactor", (0, exports.getCumulativeFactor)(updatedContext));
140
+ console.log("signedTradeOi", signedTradeOi);
141
+ console.log("onePercentDepth", onePercentDepth);
142
+ console.log("getLegacyFactor", (0, exports.getLegacyFactor)(updatedContext));
143
+ console.log("getProtectionCloseFactor", (0, exports.getProtectionCloseFactor)(updatedContext));
127
144
  return finalPriceImpactP;
128
145
  };
129
146
  exports.getTradeCumulVolPriceImpactP = getTradeCumulVolPriceImpactP;
@@ -2,6 +2,14 @@
2
2
  * @dev Main price impact module
3
3
  * @dev Exports cumulative volume, skew, and combined opening/closing price impact functionality
4
4
  */
5
+ /**
6
+ * @dev Calculates price after impact using the same formula as the Solidity contract
7
+ * @dev Mirrors contract's getPriceAfterImpact function
8
+ * @param oraclePrice Base oracle price (no decimals requirement)
9
+ * @param totalPriceImpactP Total price impact percentage (can be positive or negative)
10
+ * @returns Price after impact has been applied
11
+ */
12
+ export declare const getPriceAfterImpact: (oraclePrice: number, totalPriceImpactP: number) => number;
5
13
  export { getTradeOpeningPriceImpact, getTradeOpeningPriceImpactAtMarket, buildTradeOpeningPriceImpactContext, TradeOpeningPriceImpactInput, TradeOpeningPriceImpactContext, TradeOpeningPriceImpactResult, } from "./open";
6
14
  export { getTradeClosingPriceImpact, getTradeClosingPriceImpactAtOracle, buildTradeClosingPriceImpactContext, TradeClosingPriceImpactInput, TradeClosingPriceImpactContext, TradeClosingPriceImpactResult, } from "./close";
7
15
  export { getTradeCumulVolPriceImpactP, getCumulVolPriceImpact, // Convenience function
@@ -4,7 +4,23 @@
4
4
  * @dev Exports cumulative volume, skew, and combined opening/closing price impact functionality
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.buildSkewPriceImpactContext = exports.convertPairSkewDepths = exports.convertSkewDepth = exports.convertPairOiCollateralArray = exports.convertPairOiCollateral = exports.convertPairOiTokenArray = exports.convertPairOiToken = exports.SkewPriceImpact = exports.calculatePartialSizeToken = exports.getTradeSkewPriceImpactWithChecks = exports.getTradeSkewPriceImpact = exports.calculateSkewPriceImpactP = exports.getTradeSkewDirection = exports.getNetSkewCollateral = exports.getNetSkewToken = exports.buildCumulVolContext = exports.convertOiWindowsSettingsArray = exports.convertOiWindows = exports.convertOiWindow = exports.convertOiWindowsSettings = exports.getSpreadP = exports.getFixedSpreadP = exports.getLegacyFactor = exports.getCumulativeFactor = exports.isProtectionCloseFactorActive = exports.getProtectionCloseFactor = exports.getSpreadWithPriceImpactP = exports.getSpreadWithCumulVolPriceImpactP = exports.getCumulVolPriceImpact = exports.getTradeCumulVolPriceImpactP = exports.buildTradeClosingPriceImpactContext = exports.getTradeClosingPriceImpactAtOracle = exports.getTradeClosingPriceImpact = exports.buildTradeOpeningPriceImpactContext = exports.getTradeOpeningPriceImpactAtMarket = exports.getTradeOpeningPriceImpact = void 0;
7
+ exports.buildSkewPriceImpactContext = exports.convertPairSkewDepths = exports.convertSkewDepth = exports.convertPairOiCollateralArray = exports.convertPairOiCollateral = exports.convertPairOiTokenArray = exports.convertPairOiToken = exports.SkewPriceImpact = exports.calculatePartialSizeToken = exports.getTradeSkewPriceImpactWithChecks = exports.getTradeSkewPriceImpact = exports.calculateSkewPriceImpactP = exports.getTradeSkewDirection = exports.getNetSkewCollateral = exports.getNetSkewToken = exports.buildCumulVolContext = exports.convertOiWindowsSettingsArray = exports.convertOiWindows = exports.convertOiWindow = exports.convertOiWindowsSettings = exports.getSpreadP = exports.getFixedSpreadP = exports.getLegacyFactor = exports.getCumulativeFactor = exports.isProtectionCloseFactorActive = exports.getProtectionCloseFactor = exports.getSpreadWithPriceImpactP = exports.getSpreadWithCumulVolPriceImpactP = exports.getCumulVolPriceImpact = exports.getTradeCumulVolPriceImpactP = exports.buildTradeClosingPriceImpactContext = exports.getTradeClosingPriceImpactAtOracle = exports.getTradeClosingPriceImpact = exports.buildTradeOpeningPriceImpactContext = exports.getTradeOpeningPriceImpactAtMarket = exports.getTradeOpeningPriceImpact = exports.getPriceAfterImpact = void 0;
8
+ /**
9
+ * @dev Calculates price after impact using the same formula as the Solidity contract
10
+ * @dev Mirrors contract's getPriceAfterImpact function
11
+ * @param oraclePrice Base oracle price (no decimals requirement)
12
+ * @param totalPriceImpactP Total price impact percentage (can be positive or negative)
13
+ * @returns Price after impact has been applied
14
+ */
15
+ const getPriceAfterImpact = (oraclePrice, totalPriceImpactP) => {
16
+ // Match Solidity: price = oraclePrice + (oraclePrice * totalPriceImpactP / 100)
17
+ const priceAfterImpact = oraclePrice * (1 + totalPriceImpactP / 100);
18
+ if (priceAfterImpact <= 0) {
19
+ throw new Error("Price after impact must be positive");
20
+ }
21
+ return priceAfterImpact;
22
+ };
23
+ exports.getPriceAfterImpact = getPriceAfterImpact;
8
24
  // Export trade opening price impact functionality
9
25
  var open_1 = require("./open");
10
26
  // Core functions
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.getTradeOpeningPriceImpactAtMarket = exports.getTradeOpeningPriceImpact = exports.buildTradeOpeningPriceImpactContext = void 0;
8
8
  const cumulVol_1 = require("../cumulVol");
9
9
  const skew_1 = require("../skew");
10
+ const __1 = require("../");
10
11
  // Export builder
11
12
  var builder_1 = require("./builder");
12
13
  Object.defineProperty(exports, "buildTradeOpeningPriceImpactContext", { enumerable: true, get: function () { return builder_1.buildTradeOpeningPriceImpactContext; } });
@@ -44,18 +45,12 @@ const getTradeOpeningPriceImpact = (input, context) => {
44
45
  // Total price impact (signed - can be positive or negative)
45
46
  // Spread is always positive, impacts can be negative
46
47
  const totalPriceImpactP = spreadP + cumulVolPriceImpactP + skewPriceImpactP;
47
- // Calculate final price after impact
48
- // For longs: price increases with positive impact
49
- // For shorts: price decreases with positive impact
50
- const priceImpactFactor = 1 + totalPriceImpactP / 100;
51
- const priceAfterImpact = input.long
52
- ? input.openPrice * priceImpactFactor
53
- : input.openPrice / priceImpactFactor;
48
+ // Calculate final price after impact using the same formula as Solidity
49
+ const priceAfterImpact = (0, __1.getPriceAfterImpact)(input.openPrice, totalPriceImpactP);
54
50
  // Calculate percent profit from impact
55
- // Positive when trader benefits, negative when trader loses
56
- const percentProfitP = input.long
57
- ? -totalPriceImpactP // Long loses when price goes up
58
- : totalPriceImpactP; // Short gains when price goes up
51
+ // For longs: negative impact = profit (price goes down, good for buyer)
52
+ // For shorts: positive impact = profit (price goes up, good for seller)
53
+ const percentProfitP = -totalPriceImpactP;
59
54
  return {
60
55
  priceAfterImpact,
61
56
  priceImpactP: Math.abs(totalPriceImpactP),
@@ -629,5 +629,15 @@ export declare enum PairIndex {
629
629
  LPTUSD = 383,
630
630
  BVIVUSD = 384,
631
631
  EVIVUSD = 385,
632
- CRCLUSD = 386
632
+ CRCLUSD = 386,
633
+ RESOLVUSD = 387,
634
+ SQDUSD = 388,
635
+ TAIKOUSD = 389,
636
+ HOMEUSD = 390,
637
+ BUSD = 391,
638
+ HUMAUSD = 392,
639
+ SBETUSD = 393,
640
+ PLTRUSD = 394,
641
+ BIDUUSD = 395,
642
+ ROKUUSD = 396
633
643
  }
@@ -416,4 +416,14 @@ var PairIndex;
416
416
  PairIndex[PairIndex["BVIVUSD"] = 384] = "BVIVUSD";
417
417
  PairIndex[PairIndex["EVIVUSD"] = 385] = "EVIVUSD";
418
418
  PairIndex[PairIndex["CRCLUSD"] = 386] = "CRCLUSD";
419
+ PairIndex[PairIndex["RESOLVUSD"] = 387] = "RESOLVUSD";
420
+ PairIndex[PairIndex["SQDUSD"] = 388] = "SQDUSD";
421
+ PairIndex[PairIndex["TAIKOUSD"] = 389] = "TAIKOUSD";
422
+ PairIndex[PairIndex["HOMEUSD"] = 390] = "HOMEUSD";
423
+ PairIndex[PairIndex["BUSD"] = 391] = "BUSD";
424
+ PairIndex[PairIndex["HUMAUSD"] = 392] = "HUMAUSD";
425
+ PairIndex[PairIndex["SBETUSD"] = 393] = "SBETUSD";
426
+ PairIndex[PairIndex["PLTRUSD"] = 394] = "PLTRUSD";
427
+ PairIndex[PairIndex["BIDUUSD"] = 395] = "BIDUUSD";
428
+ PairIndex[PairIndex["ROKUUSD"] = 396] = "ROKUUSD";
419
429
  })(PairIndex = exports.PairIndex || (exports.PairIndex = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gainsnetwork/sdk",
3
- "version": "0.0.0-v10.rc14",
3
+ "version": "0.0.0-v10.rc16",
4
4
  "description": "Gains Network SDK",
5
5
  "main": "./lib/index.js",
6
6
  "files": [