@gainsnetwork/sdk 0.0.0-v10.rc1 → 0.0.0-v10.rc3

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.
Files changed (176) hide show
  1. package/lib/backend/globalTrades/index.d.ts +11 -0
  2. package/lib/backend/globalTrades/index.js +69 -0
  3. package/lib/backend/index.d.ts +2 -0
  4. package/lib/backend/index.js +18 -0
  5. package/lib/backend/tradingVariables/backend.types.d.ts +312 -0
  6. package/lib/backend/tradingVariables/backend.types.js +2 -0
  7. package/lib/backend/tradingVariables/converter.d.ts +30 -0
  8. package/lib/backend/tradingVariables/converter.js +329 -0
  9. package/lib/backend/tradingVariables/index.d.ts +3 -0
  10. package/lib/backend/tradingVariables/index.js +78 -0
  11. package/lib/backend/tradingVariables/types.d.ts +109 -0
  12. package/lib/backend/tradingVariables/types.js +14 -0
  13. package/lib/constants.d.ts +8 -1
  14. package/lib/constants.js +8 -1
  15. package/lib/contracts/fetch/fees/borrowingFeesV2.d.ts +75 -0
  16. package/lib/contracts/fetch/fees/borrowingFeesV2.js +193 -0
  17. package/lib/contracts/fetch/fees/fundingFees.d.ts +66 -0
  18. package/lib/contracts/fetch/fees/fundingFees.js +150 -0
  19. package/lib/contracts/fetch/priceImpact/skew.d.ts +63 -0
  20. package/lib/contracts/fetch/priceImpact/skew.js +168 -0
  21. package/lib/contracts/types/generated/GFarmTradingStorageV5.d.ts +1911 -0
  22. package/lib/contracts/types/generated/GFarmTradingStorageV5.js +2 -0
  23. package/lib/contracts/types/generated/GNSBorrowingFees.d.ts +1067 -0
  24. package/lib/contracts/types/generated/GNSBorrowingFees.js +2 -0
  25. package/lib/contracts/types/generated/GNSBorrowingFeesV6_3_2.d.ts +979 -0
  26. package/lib/contracts/types/generated/GNSBorrowingFeesV6_3_2.js +2 -0
  27. package/lib/contracts/types/generated/GNSBorrowingFeesV6_4.d.ts +1058 -0
  28. package/lib/contracts/types/generated/GNSBorrowingFeesV6_4.js +2 -0
  29. package/lib/contracts/types/generated/GNSNftRewardsV6.d.ts +533 -0
  30. package/lib/contracts/types/generated/GNSNftRewardsV6.js +2 -0
  31. package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.d.ts +613 -0
  32. package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.js +2 -0
  33. package/lib/contracts/types/generated/GNSPairInfosV6_1.d.ts +911 -0
  34. package/lib/contracts/types/generated/GNSPairInfosV6_1.js +2 -0
  35. package/lib/contracts/types/generated/GNSPairsStorageV6.d.ts +660 -0
  36. package/lib/contracts/types/generated/GNSPairsStorageV6.js +2 -0
  37. package/lib/contracts/types/generated/GNSTrading.d.ts +758 -0
  38. package/lib/contracts/types/generated/GNSTrading.js +2 -0
  39. package/lib/contracts/types/generated/GNSTradingCallbacks.d.ts +875 -0
  40. package/lib/contracts/types/generated/GNSTradingCallbacks.js +2 -0
  41. package/lib/contracts/types/generated/GNSTradingCallbacksV6_3_2.d.ts +806 -0
  42. package/lib/contracts/types/generated/GNSTradingCallbacksV6_3_2.js +2 -0
  43. package/lib/contracts/types/generated/GNSTradingCallbacksV6_4.d.ts +821 -0
  44. package/lib/contracts/types/generated/GNSTradingCallbacksV6_4.js +2 -0
  45. package/lib/contracts/types/generated/GNSTradingStorage.d.ts +1387 -0
  46. package/lib/contracts/types/generated/GNSTradingStorage.js +2 -0
  47. package/lib/contracts/types/generated/GTokenV6_3_2.d.ts +1838 -0
  48. package/lib/contracts/types/generated/GTokenV6_3_2.js +2 -0
  49. package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.d.ts +83 -0
  50. package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.js +2691 -0
  51. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_3_2__factory.d.ts +88 -0
  52. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_3_2__factory.js +1654 -0
  53. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_4__factory.d.ts +113 -0
  54. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_4__factory.js +1742 -0
  55. package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.d.ts +124 -0
  56. package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.js +1784 -0
  57. package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.d.ts +100 -0
  58. package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.js +1116 -0
  59. package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.d.ts +100 -0
  60. package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.js +1003 -0
  61. package/lib/contracts/types/generated/factories/GNSPairInfosV6_1__factory.d.ts +98 -0
  62. package/lib/contracts/types/generated/factories/GNSPairInfosV6_1__factory.js +1485 -0
  63. package/lib/contracts/types/generated/factories/GNSPairsStorageV6__factory.d.ts +117 -0
  64. package/lib/contracts/types/generated/factories/GNSPairsStorageV6__factory.js +1265 -0
  65. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_3_2__factory.d.ts +82 -0
  66. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_3_2__factory.js +1273 -0
  67. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_4__factory.d.ts +82 -0
  68. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_4__factory.js +1326 -0
  69. package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.d.ts +113 -0
  70. package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.js +1428 -0
  71. package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.d.ts +96 -0
  72. package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.js +2241 -0
  73. package/lib/contracts/types/generated/factories/GNSTrading__factory.d.ts +95 -0
  74. package/lib/contracts/types/generated/factories/GNSTrading__factory.js +1071 -0
  75. package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.d.ts +110 -0
  76. package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.js +2682 -0
  77. package/lib/contracts/types/index.d.ts +2 -1
  78. package/lib/contracts/types/index.js +1 -0
  79. package/lib/contracts/utils/openTrades.d.ts +1 -0
  80. package/lib/contracts/utils/openTrades.js +94 -56
  81. package/lib/contracts/utils/pairs.js +7 -0
  82. package/lib/index.d.ts +1 -0
  83. package/lib/index.js +1 -0
  84. package/lib/markets/collateral/converter.d.ts +5 -0
  85. package/lib/markets/collateral/converter.js +11 -0
  86. package/lib/markets/collateral/index.d.ts +1 -0
  87. package/lib/markets/collateral/index.js +17 -0
  88. package/lib/markets/collateral/types.d.ts +7 -0
  89. package/lib/markets/collateral/types.js +2 -0
  90. package/lib/markets/index.d.ts +2 -0
  91. package/lib/markets/index.js +2 -0
  92. package/lib/markets/oi/converter.d.ts +63 -0
  93. package/lib/markets/oi/converter.js +103 -0
  94. package/lib/markets/oi/fetcher.d.ts +58 -0
  95. package/lib/markets/oi/fetcher.js +181 -0
  96. package/lib/markets/oi/index.d.ts +10 -0
  97. package/lib/markets/oi/index.js +37 -0
  98. package/lib/markets/oi/types.d.ts +82 -0
  99. package/lib/markets/oi/types.js +6 -0
  100. package/lib/markets/oi/validation.d.ts +80 -0
  101. package/lib/markets/oi/validation.js +172 -0
  102. package/lib/trade/fees/borrowing/index.d.ts +22 -1
  103. package/lib/trade/fees/borrowing/index.js +39 -13
  104. package/lib/trade/fees/borrowingV2/converter.d.ts +66 -0
  105. package/lib/trade/fees/borrowingV2/converter.js +121 -0
  106. package/lib/trade/fees/borrowingV2/fetcher.d.ts +75 -0
  107. package/lib/trade/fees/borrowingV2/fetcher.js +193 -0
  108. package/lib/trade/fees/borrowingV2/index.d.ts +60 -0
  109. package/lib/trade/fees/borrowingV2/index.js +140 -0
  110. package/lib/trade/fees/borrowingV2/types.d.ts +79 -0
  111. package/lib/trade/fees/borrowingV2/types.js +5 -0
  112. package/lib/trade/fees/converter.d.ts +48 -0
  113. package/lib/trade/fees/converter.js +110 -0
  114. package/lib/trade/fees/fundingFees/converter.d.ts +102 -0
  115. package/lib/trade/fees/fundingFees/converter.js +196 -0
  116. package/lib/trade/fees/fundingFees/fetcher.d.ts +66 -0
  117. package/lib/trade/fees/fundingFees/fetcher.js +150 -0
  118. package/lib/trade/fees/fundingFees/index.d.ts +136 -0
  119. package/lib/trade/fees/fundingFees/index.js +326 -0
  120. package/lib/trade/fees/fundingFees/types.d.ts +77 -0
  121. package/lib/trade/fees/fundingFees/types.js +5 -0
  122. package/lib/trade/fees/index.d.ts +7 -2
  123. package/lib/trade/fees/index.js +67 -16
  124. package/lib/trade/fees/tiers/converter.d.ts +54 -0
  125. package/lib/trade/fees/tiers/converter.js +81 -0
  126. package/lib/trade/fees/tiers/index.d.ts +18 -0
  127. package/lib/trade/fees/tiers/index.js +45 -1
  128. package/lib/trade/fees/trading/converter.d.ts +30 -0
  129. package/lib/trade/fees/trading/converter.js +43 -0
  130. package/lib/trade/fees/trading/index.d.ts +54 -0
  131. package/lib/trade/fees/trading/index.js +147 -0
  132. package/lib/trade/fees/trading/types.d.ts +48 -0
  133. package/lib/trade/fees/trading/types.js +5 -0
  134. package/lib/trade/index.d.ts +3 -2
  135. package/lib/trade/index.js +3 -2
  136. package/lib/trade/liquidation/converter.d.ts +23 -0
  137. package/lib/trade/liquidation/converter.js +46 -0
  138. package/lib/trade/liquidation/index.d.ts +31 -0
  139. package/lib/trade/liquidation/index.js +187 -0
  140. package/lib/trade/liquidation/types.d.ts +44 -0
  141. package/lib/trade/liquidation/types.js +2 -0
  142. package/lib/trade/pnl/converter.d.ts +47 -0
  143. package/lib/trade/pnl/converter.js +72 -0
  144. package/lib/trade/pnl/index.d.ts +86 -0
  145. package/lib/trade/pnl/index.js +201 -0
  146. package/lib/trade/pnl/types.d.ts +86 -0
  147. package/lib/trade/pnl/types.js +5 -0
  148. package/lib/trade/priceImpact/close/index.d.ts +21 -0
  149. package/lib/trade/priceImpact/close/index.js +131 -0
  150. package/lib/trade/priceImpact/close/types.d.ts +43 -0
  151. package/lib/trade/priceImpact/close/types.js +5 -0
  152. package/lib/trade/priceImpact/cumulVol/converter.d.ts +31 -0
  153. package/lib/trade/priceImpact/cumulVol/converter.js +59 -0
  154. package/lib/trade/priceImpact/cumulVol/index.d.ts +107 -0
  155. package/lib/trade/priceImpact/cumulVol/index.js +228 -0
  156. package/lib/trade/priceImpact/index.d.ts +12 -0
  157. package/lib/trade/priceImpact/index.js +59 -0
  158. package/lib/trade/priceImpact/open/index.d.ts +22 -0
  159. package/lib/trade/priceImpact/open/index.js +76 -0
  160. package/lib/trade/priceImpact/open/types.d.ts +41 -0
  161. package/lib/trade/priceImpact/open/types.js +5 -0
  162. package/lib/trade/priceImpact/skew/converter.d.ts +77 -0
  163. package/lib/trade/priceImpact/skew/converter.js +171 -0
  164. package/lib/trade/priceImpact/skew/fetcher.d.ts +63 -0
  165. package/lib/trade/priceImpact/skew/fetcher.js +168 -0
  166. package/lib/trade/priceImpact/skew/index.d.ts +58 -0
  167. package/lib/trade/priceImpact/skew/index.js +179 -0
  168. package/lib/trade/priceImpact/skew/types.d.ts +55 -0
  169. package/lib/trade/priceImpact/skew/types.js +5 -0
  170. package/lib/trade/spread.d.ts +5 -18
  171. package/lib/trade/spread.js +17 -106
  172. package/lib/trade/types.d.ts +34 -9
  173. package/lib/trade/types.js +7 -0
  174. package/lib/trade/utils.d.ts +18 -0
  175. package/lib/trade/utils.js +30 -0
  176. package/package.json +2 -1
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @dev Skew price impact types for v10+ trades
3
+ */
4
+ export type PairOiToken = {
5
+ oiLongToken: number;
6
+ oiShortToken: number;
7
+ };
8
+ export type PairOiCollateral = {
9
+ oiLongCollateral: number;
10
+ oiShortCollateral: number;
11
+ };
12
+ export type SkewDepth = {
13
+ collateralIndex: number;
14
+ pairIndex: number;
15
+ depth: number;
16
+ };
17
+ export type SkewPriceImpactInput = {
18
+ collateralIndex: number;
19
+ pairIndex: number;
20
+ long: boolean;
21
+ open: boolean;
22
+ positionSizeToken: number;
23
+ };
24
+ export type SkewPriceImpactResult = {
25
+ priceImpactP: number;
26
+ netSkewToken: number;
27
+ netSkewCollateral: number;
28
+ tradeDirection: "increase" | "decrease" | "neutral";
29
+ };
30
+ export type SkewPriceImpactContext = {
31
+ skewDepths: {
32
+ [collateralIndex: number]: {
33
+ [pairIndex: number]: number;
34
+ };
35
+ };
36
+ pairOiTokens: {
37
+ [collateralIndex: number]: {
38
+ [pairIndex: number]: PairOiToken;
39
+ };
40
+ };
41
+ };
42
+ export type TradeSkewParams = {
43
+ collateralIndex: number;
44
+ pairIndex: number;
45
+ long: boolean;
46
+ open: boolean;
47
+ positionSizeCollateral: number;
48
+ currentPrice: number;
49
+ contractsVersion: number;
50
+ isCounterTrade?: boolean;
51
+ };
52
+ export type PositionSizeResult = {
53
+ positionSizeToken: number;
54
+ positionSizeCollateral: number;
55
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ /**
3
+ * @dev Skew price impact types for v10+ trades
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,18 +1,5 @@
1
- import { LiquidationParams, OiWindows, OiWindowsSettings, PairDepth, PairFactor, UserPriceImpact } from "./types";
2
- import { ContractsVersion } from "../contracts/types";
3
- export type SpreadContext = {
4
- isOpen?: boolean;
5
- isPnlPositive?: boolean;
6
- createdBlock?: number;
7
- liquidationParams?: LiquidationParams | undefined;
8
- currentBlock?: number | undefined;
9
- contractsVersion?: ContractsVersion | undefined;
10
- protectionCloseFactorWhitelist?: boolean;
11
- userPriceImpact?: UserPriceImpact | undefined;
12
- } & Partial<PairFactor>;
13
- export declare const getProtectionCloseFactor: (spreadCtx: SpreadContext | undefined) => number;
14
- export declare const isProtectionCloseFactorActive: (spreadCtx: SpreadContext | undefined) => boolean | undefined;
15
- export declare const getCumulativeFactor: (spreadCtx: SpreadContext | undefined) => number;
16
- export declare const getLegacyFactor: (spreadCtx: SpreadContext | undefined) => number;
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;
18
- export declare const getSpreadP: (pairSpreadP: number | undefined, isLiquidation?: boolean | undefined, liquidationParams?: LiquidationParams | undefined, userPriceImpact?: UserPriceImpact | undefined) => number;
1
+ /**
2
+ * @dev Pure spread calculations without price impact
3
+ * @dev For price impact calculations, see priceImpact module
4
+ */
5
+ export { getSpreadWithPriceImpactP, getSpreadWithCumulVolPriceImpactP, getTradeCumulVolPriceImpactP, getCumulVolPriceImpact, getProtectionCloseFactor, isProtectionCloseFactorActive, getCumulativeFactor, getLegacyFactor, getFixedSpreadP, getSpreadP, CumulVolContext as SpreadContext, } from "./priceImpact/cumulVol";
@@ -1,108 +1,19 @@
1
1
  "use strict";
2
+ /**
3
+ * @dev Pure spread calculations without price impact
4
+ * @dev For price impact calculations, see priceImpact module
5
+ */
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSpreadP = exports.getSpreadWithPriceImpactP = exports.getLegacyFactor = exports.getCumulativeFactor = exports.isProtectionCloseFactorActive = exports.getProtectionCloseFactor = void 0;
4
- const oiWindows_1 = require("./oiWindows");
5
- const constants_1 = require("../constants");
6
- const types_1 = require("../contracts/types");
7
- const getProtectionCloseFactor = (spreadCtx) => {
8
- var _a;
9
- const protectionCloseFactor = spreadCtx === undefined ||
10
- spreadCtx.contractsVersion === types_1.ContractsVersion.BEFORE_V9_2 ||
11
- spreadCtx.isOpen === undefined ||
12
- spreadCtx.isPnlPositive === undefined ||
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;
22
- };
23
- exports.getProtectionCloseFactor = getProtectionCloseFactor;
24
- const isProtectionCloseFactorActive = (spreadCtx) => {
25
- if (spreadCtx === undefined ||
26
- spreadCtx.currentBlock === undefined ||
27
- spreadCtx.createdBlock === undefined ||
28
- spreadCtx.protectionCloseFactorBlocks === undefined ||
29
- spreadCtx.protectionCloseFactor === undefined) {
30
- return undefined;
31
- }
32
- return (spreadCtx.isPnlPositive === true &&
33
- spreadCtx.isOpen === false &&
34
- spreadCtx.protectionCloseFactor > 0 &&
35
- spreadCtx.currentBlock <=
36
- spreadCtx.createdBlock + spreadCtx.protectionCloseFactorBlocks &&
37
- spreadCtx.protectionCloseFactorWhitelist !== true);
38
- };
39
- exports.isProtectionCloseFactorActive = isProtectionCloseFactorActive;
40
- const getCumulativeFactor = (spreadCtx) => {
41
- if (spreadCtx === undefined ||
42
- spreadCtx.cumulativeFactor === undefined ||
43
- spreadCtx.cumulativeFactor === 0) {
44
- return constants_1.DEFAULT_CUMULATIVE_FACTOR;
45
- }
46
- return spreadCtx.cumulativeFactor;
47
- };
48
- exports.getCumulativeFactor = getCumulativeFactor;
49
- const getLegacyFactor = (spreadCtx) => {
50
- return (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.contractsVersion) === types_1.ContractsVersion.BEFORE_V9_2 ? 1 : 2;
51
- };
52
- exports.getLegacyFactor = getLegacyFactor;
53
- const getSpreadWithPriceImpactP = (pairSpreadP, buy, collateral, leverage, pairDepth, oiWindowsSettings, oiWindows, spreadCtx) => {
54
- if (pairSpreadP === undefined) {
55
- return 0;
56
- }
57
- if (
58
- // No spread or price impact when closing pre-v9.2 trades
59
- ((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === false &&
60
- (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.contractsVersion) === types_1.ContractsVersion.BEFORE_V9_2) ||
61
- // No spread or price impact for opens when `pair.exemptOnOpen` is true
62
- ((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === true && (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.exemptOnOpen) === true) ||
63
- // No spread or price impact for closes after `protectionCloseFactor` has expired
64
- // when `pair.exemptAfterProtectionCloseFactor` is true
65
- ((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === false &&
66
- (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.exemptAfterProtectionCloseFactor) === true &&
67
- (0, exports.isProtectionCloseFactorActive)(spreadCtx) !== true)) {
68
- return 0;
69
- }
70
- const onePercentDepth = buy
71
- ? // if `long`
72
- (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) !== false // assumes it's an open unless it's explicitly false
73
- ? pairDepth === null || pairDepth === void 0 ? void 0 : pairDepth.onePercentDepthAboveUsd
74
- : pairDepth === null || pairDepth === void 0 ? void 0 : pairDepth.onePercentDepthBelowUsd
75
- : // if `short`
76
- (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) !== false
77
- ? pairDepth === null || pairDepth === void 0 ? void 0 : pairDepth.onePercentDepthBelowUsd
78
- : pairDepth === null || pairDepth === void 0 ? void 0 : pairDepth.onePercentDepthAboveUsd;
79
- let activeOi = undefined;
80
- if (oiWindowsSettings !== undefined) {
81
- activeOi = (0, oiWindows_1.getActiveOi)((0, oiWindows_1.getCurrentOiWindowId)(oiWindowsSettings), oiWindowsSettings.windowsCount, oiWindows, (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) !== false ? buy : !buy);
82
- }
83
- if (!onePercentDepth || activeOi === undefined || collateral === undefined) {
84
- return pairSpreadP / 2;
85
- }
86
- return ((0, exports.getSpreadP)(pairSpreadP, undefined, undefined, spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.userPriceImpact) +
87
- ((activeOi * (0, exports.getCumulativeFactor)(spreadCtx) + (collateral * leverage) / 2) /
88
- onePercentDepth /
89
- 100 /
90
- (0, exports.getLegacyFactor)(spreadCtx)) *
91
- (0, exports.getProtectionCloseFactor)(spreadCtx));
92
- };
93
- exports.getSpreadWithPriceImpactP = getSpreadWithPriceImpactP;
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)) {
98
- return 0;
99
- }
100
- const spreadP = pairSpreadP / 2 + fixedSpreadP;
101
- return isLiquidation === true &&
102
- liquidationParams !== undefined &&
103
- liquidationParams.maxLiqSpreadP > 0 &&
104
- spreadP > liquidationParams.maxLiqSpreadP
105
- ? liquidationParams.maxLiqSpreadP
106
- : spreadP;
107
- };
108
- exports.getSpreadP = getSpreadP;
7
+ exports.getSpreadP = exports.getFixedSpreadP = exports.getLegacyFactor = exports.getCumulativeFactor = exports.isProtectionCloseFactorActive = exports.getProtectionCloseFactor = exports.getCumulVolPriceImpact = exports.getTradeCumulVolPriceImpactP = exports.getSpreadWithCumulVolPriceImpactP = exports.getSpreadWithPriceImpactP = void 0;
8
+ // Re-export from priceImpact/cumulVol for backward compatibility
9
+ var cumulVol_1 = require("./priceImpact/cumulVol");
10
+ Object.defineProperty(exports, "getSpreadWithPriceImpactP", { enumerable: true, get: function () { return cumulVol_1.getSpreadWithPriceImpactP; } });
11
+ Object.defineProperty(exports, "getSpreadWithCumulVolPriceImpactP", { enumerable: true, get: function () { return cumulVol_1.getSpreadWithCumulVolPriceImpactP; } });
12
+ Object.defineProperty(exports, "getTradeCumulVolPriceImpactP", { enumerable: true, get: function () { return cumulVol_1.getTradeCumulVolPriceImpactP; } });
13
+ Object.defineProperty(exports, "getCumulVolPriceImpact", { enumerable: true, get: function () { return cumulVol_1.getCumulVolPriceImpact; } });
14
+ Object.defineProperty(exports, "getProtectionCloseFactor", { enumerable: true, get: function () { return cumulVol_1.getProtectionCloseFactor; } });
15
+ Object.defineProperty(exports, "isProtectionCloseFactorActive", { enumerable: true, get: function () { return cumulVol_1.isProtectionCloseFactorActive; } });
16
+ Object.defineProperty(exports, "getCumulativeFactor", { enumerable: true, get: function () { return cumulVol_1.getCumulativeFactor; } });
17
+ Object.defineProperty(exports, "getLegacyFactor", { enumerable: true, get: function () { return cumulVol_1.getLegacyFactor; } });
18
+ Object.defineProperty(exports, "getFixedSpreadP", { enumerable: true, get: function () { return cumulVol_1.getFixedSpreadP; } });
19
+ Object.defineProperty(exports, "getSpreadP", { enumerable: true, get: function () { return cumulVol_1.getSpreadP; } });
@@ -1,14 +1,37 @@
1
- import { ITradingStorage, IBorrowingFees, IPairsStorage } from "../contracts/types/generated/GNSMultiCollatDiamond";
1
+ import { ITradingStorage, IBorrowingFees, IPairsStorage, IFundingFees } from "../contracts/types/generated/GNSMultiCollatDiamond";
2
2
  import { BorrowingFee } from "./fees/borrowing";
3
3
  import { FeeTier, TraderEnrollment, TraderInfo } from "./fees/tiers/types";
4
4
  export type PairIndexes = {
5
5
  [key: string]: PairIndex;
6
6
  };
7
+ export type TradeFeesData = {
8
+ realizedTradingFeesCollateral: number;
9
+ realizedPnlCollateral: number;
10
+ manuallyRealizedNegativePnlCollateral: number;
11
+ alreadyTransferredNegativePnlCollateral: number;
12
+ virtualAvailableCollateralInDiamond: number;
13
+ initialAccFundingFeeP: number;
14
+ initialAccBorrowingFeeP: number;
15
+ };
16
+ export type UiRealizedPnlData = {
17
+ realizedTradingFeesCollateral: number;
18
+ realizedOldBorrowingFeesCollateral: number;
19
+ realizedNewBorrowingFeesCollateral: number;
20
+ realizedFundingFeesCollateral: number;
21
+ realizedPnlPartialCloseCollateral: number;
22
+ pnlWithdrawnCollateral: number;
23
+ };
24
+ export type CounterTradeSettings = {
25
+ maxLeverage: number;
26
+ feeRateMultiplier: number;
27
+ };
7
28
  export type TradeContainer = {
8
29
  trade: Trade;
9
30
  tradeInfo: TradeInfo;
10
31
  liquidationParams: LiquidationParams;
11
32
  initialAccFees: TradeInitialAccFees;
33
+ tradeFeesData?: TradeFeesData;
34
+ uiRealizedPnlData?: UiRealizedPnlData;
12
35
  receivedAt?: number;
13
36
  };
14
37
  export type Trade = {
@@ -145,6 +168,8 @@ export type TradeContainerRaw = {
145
168
  tradeInfo: ITradingStorage.TradeInfoStruct;
146
169
  liquidationParams: IPairsStorage.GroupLiquidationParamsStruct;
147
170
  initialAccFees: IBorrowingFees.BorrowingInitialAccFeesStruct;
171
+ tradeFeesData: IFundingFees.TradeFeesDataStruct;
172
+ uiRealizedPnlData?: IFundingFees.UiRealizedPnlDataStruct;
148
173
  };
149
174
  export type OiWindowsSettings = {
150
175
  startTs: number;
@@ -159,13 +184,6 @@ export type OiWindow = PairOi;
159
184
  export type OiWindows = {
160
185
  [key: string]: OiWindow;
161
186
  };
162
- export type CollateralConfig = {
163
- collateral: string;
164
- isActive: boolean;
165
- precision: number;
166
- precisionDelta: number;
167
- decimals?: number;
168
- };
169
187
  export type FeeTiers = {
170
188
  tiers: FeeTier[];
171
189
  multipliers: number[];
@@ -594,5 +612,12 @@ export declare enum PairIndex {
594
612
  RFCUSD = 366,
595
613
  WCTUSD = 367,
596
614
  BIGTIMEUSD = 368,
597
- BABYUSD = 369
615
+ BABYUSD = 369,
616
+ COOKIEUSD = 370,
617
+ KMNOUSD = 371,
618
+ INITUSD = 372,
619
+ SYRUPUSD = 373,
620
+ SIGNUSD = 374,
621
+ ZORAUSD = 375,
622
+ COINUSD = 376
598
623
  }
@@ -399,4 +399,11 @@ var PairIndex;
399
399
  PairIndex[PairIndex["WCTUSD"] = 367] = "WCTUSD";
400
400
  PairIndex[PairIndex["BIGTIMEUSD"] = 368] = "BIGTIMEUSD";
401
401
  PairIndex[PairIndex["BABYUSD"] = 369] = "BABYUSD";
402
+ PairIndex[PairIndex["COOKIEUSD"] = 370] = "COOKIEUSD";
403
+ PairIndex[PairIndex["KMNOUSD"] = 371] = "KMNOUSD";
404
+ PairIndex[PairIndex["INITUSD"] = 372] = "INITUSD";
405
+ PairIndex[PairIndex["SYRUPUSD"] = 373] = "SYRUPUSD";
406
+ PairIndex[PairIndex["SIGNUSD"] = 374] = "SIGNUSD";
407
+ PairIndex[PairIndex["ZORAUSD"] = 375] = "ZORAUSD";
408
+ PairIndex[PairIndex["COINUSD"] = 376] = "COINUSD";
402
409
  })(PairIndex = exports.PairIndex || (exports.PairIndex = {}));
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @dev Trade-specific utility functions
3
+ * @dev Common calculations and conversions used across trading modules
4
+ */
5
+ /**
6
+ * @dev Converts position size from collateral to tokens
7
+ * @param positionSizeCollateral Position size in collateral tokens
8
+ * @param currentPrice Current pair price
9
+ * @returns Position size in tokens
10
+ */
11
+ export declare const calculatePositionSizeToken: (positionSizeCollateral: number, currentPrice: number) => number;
12
+ /**
13
+ * @dev Converts position size from tokens to collateral
14
+ * @param positionSizeToken Position size in tokens
15
+ * @param currentPrice Current pair price
16
+ * @returns Position size in collateral tokens
17
+ */
18
+ export declare const calculatePositionSizeCollateral: (positionSizeToken: number, currentPrice: number) => number;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ /**
3
+ * @dev Trade-specific utility functions
4
+ * @dev Common calculations and conversions used across trading modules
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.calculatePositionSizeCollateral = exports.calculatePositionSizeToken = void 0;
8
+ /**
9
+ * @dev Converts position size from collateral to tokens
10
+ * @param positionSizeCollateral Position size in collateral tokens
11
+ * @param currentPrice Current pair price
12
+ * @returns Position size in tokens
13
+ */
14
+ const calculatePositionSizeToken = (positionSizeCollateral, currentPrice) => {
15
+ if (currentPrice === 0) {
16
+ throw new Error("Current price cannot be zero");
17
+ }
18
+ return positionSizeCollateral / currentPrice;
19
+ };
20
+ exports.calculatePositionSizeToken = calculatePositionSizeToken;
21
+ /**
22
+ * @dev Converts position size from tokens to collateral
23
+ * @param positionSizeToken Position size in tokens
24
+ * @param currentPrice Current pair price
25
+ * @returns Position size in collateral tokens
26
+ */
27
+ const calculatePositionSizeCollateral = (positionSizeToken, currentPrice) => {
28
+ return positionSizeToken * currentPrice;
29
+ };
30
+ exports.calculatePositionSizeCollateral = calculatePositionSizeCollateral;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gainsnetwork/sdk",
3
- "version": "0.0.0-v10.rc1",
3
+ "version": "0.0.0-v10.rc3",
4
4
  "description": "Gains Network SDK",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -98,6 +98,7 @@
98
98
  },
99
99
  "dependencies": {
100
100
  "@ethersproject/providers": "^5.7.2",
101
+ "@gainsnetwork/contests": "^0.0.1",
101
102
  "ethcall": "^4.8.13",
102
103
  "ethers": "^5.7.2",
103
104
  "luxon": "^3.2.0"