@gainsnetwork/sdk 1.0.6-rc3 → 1.1.0-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.
Files changed (147) hide show
  1. package/lib/backend/globalTrades/index.js +10 -10
  2. package/lib/backend/tradingVariables/backend.types.d.ts +11 -4
  3. package/lib/backend/tradingVariables/converter.d.ts +7 -3
  4. package/lib/backend/tradingVariables/converter.js +70 -63
  5. package/lib/backend/tradingVariables/index.js +11 -7
  6. package/lib/backend/tradingVariables/types.d.ts +4 -2
  7. package/lib/contracts/addresses.js +1 -4
  8. package/lib/contracts/index.d.ts +1 -1
  9. package/lib/contracts/index.js +3 -3
  10. package/lib/contracts/types/generated/GFarmTradingStorageV5.d.ts +1911 -0
  11. package/lib/contracts/types/generated/GFarmTradingStorageV5.js +2 -0
  12. package/lib/contracts/types/generated/GNSBorrowingFees.d.ts +1067 -0
  13. package/lib/contracts/types/generated/GNSBorrowingFees.js +2 -0
  14. package/lib/contracts/types/generated/GNSBorrowingFeesV6_3_2.d.ts +979 -0
  15. package/lib/contracts/types/generated/GNSBorrowingFeesV6_3_2.js +2 -0
  16. package/lib/contracts/types/generated/GNSBorrowingFeesV6_4.d.ts +1058 -0
  17. package/lib/contracts/types/generated/GNSBorrowingFeesV6_4.js +2 -0
  18. package/lib/contracts/types/generated/GNSMultiCollatDiamond.d.ts +223 -40
  19. package/lib/contracts/types/generated/GNSNftRewardsV6.d.ts +533 -0
  20. package/lib/contracts/types/generated/GNSNftRewardsV6.js +2 -0
  21. package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.d.ts +613 -0
  22. package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.js +2 -0
  23. package/lib/contracts/types/generated/GNSPairInfosV6_1.d.ts +911 -0
  24. package/lib/contracts/types/generated/GNSPairInfosV6_1.js +2 -0
  25. package/lib/contracts/types/generated/GNSPairsStorageV6.d.ts +660 -0
  26. package/lib/contracts/types/generated/GNSPairsStorageV6.js +2 -0
  27. package/lib/contracts/types/generated/GNSTrading.d.ts +758 -0
  28. package/lib/contracts/types/generated/GNSTrading.js +2 -0
  29. package/lib/contracts/types/generated/GNSTradingCallbacks.d.ts +875 -0
  30. package/lib/contracts/types/generated/GNSTradingCallbacks.js +2 -0
  31. package/lib/contracts/types/generated/GNSTradingCallbacksV6_3_2.d.ts +806 -0
  32. package/lib/contracts/types/generated/GNSTradingCallbacksV6_3_2.js +2 -0
  33. package/lib/contracts/types/generated/GNSTradingCallbacksV6_4.d.ts +821 -0
  34. package/lib/contracts/types/generated/GNSTradingCallbacksV6_4.js +2 -0
  35. package/lib/contracts/types/generated/GNSTradingStorage.d.ts +1387 -0
  36. package/lib/contracts/types/generated/GNSTradingStorage.js +2 -0
  37. package/lib/contracts/types/generated/GTokenV6_3_2.d.ts +1838 -0
  38. package/lib/contracts/types/generated/GTokenV6_3_2.js +2 -0
  39. package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.d.ts +83 -0
  40. package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.js +2691 -0
  41. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_3_2__factory.d.ts +88 -0
  42. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_3_2__factory.js +1654 -0
  43. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_4__factory.d.ts +113 -0
  44. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_4__factory.js +1742 -0
  45. package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.d.ts +124 -0
  46. package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.js +1784 -0
  47. package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.d.ts +10 -2
  48. package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +317 -36
  49. package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.d.ts +100 -0
  50. package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.js +1116 -0
  51. package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.d.ts +100 -0
  52. package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.js +1003 -0
  53. package/lib/contracts/types/generated/factories/GNSPairInfosV6_1__factory.d.ts +98 -0
  54. package/lib/contracts/types/generated/factories/GNSPairInfosV6_1__factory.js +1485 -0
  55. package/lib/contracts/types/generated/factories/GNSPairsStorageV6__factory.d.ts +117 -0
  56. package/lib/contracts/types/generated/factories/GNSPairsStorageV6__factory.js +1265 -0
  57. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_3_2__factory.d.ts +82 -0
  58. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_3_2__factory.js +1273 -0
  59. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_4__factory.d.ts +82 -0
  60. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_4__factory.js +1326 -0
  61. package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.d.ts +113 -0
  62. package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.js +1428 -0
  63. package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.d.ts +96 -0
  64. package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.js +2241 -0
  65. package/lib/contracts/types/generated/factories/GNSTrading__factory.d.ts +95 -0
  66. package/lib/contracts/types/generated/factories/GNSTrading__factory.js +1071 -0
  67. package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.d.ts +110 -0
  68. package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.js +2682 -0
  69. package/lib/contracts/utils/borrowingFees.js +20 -9
  70. package/lib/contracts/utils/openTrades.js +20 -11
  71. package/lib/contracts/utils/pairs.d.ts +13 -2
  72. package/lib/contracts/utils/pairs.js +89 -21
  73. package/lib/index.d.ts +1 -0
  74. package/lib/index.js +1 -0
  75. package/lib/markets/forex.js +1 -1
  76. package/lib/markets/leverage/builder.js +2 -2
  77. package/lib/markets/oi/fetcher.d.ts +58 -0
  78. package/lib/markets/oi/fetcher.js +181 -0
  79. package/lib/markets/oi/validation.d.ts +80 -0
  80. package/lib/markets/oi/validation.js +172 -0
  81. package/lib/markets/price/index.d.ts +0 -1
  82. package/lib/markets/price/index.js +0 -1
  83. package/lib/markets/price/signedPrices.d.ts +7 -0
  84. package/lib/markets/price/signedPrices.js +55 -2
  85. package/lib/markets/price/types.d.ts +0 -27
  86. package/lib/pricing/depthBands/converter.d.ts +65 -0
  87. package/lib/pricing/depthBands/converter.js +155 -0
  88. package/lib/pricing/depthBands/decoder.d.ts +32 -0
  89. package/lib/pricing/depthBands/decoder.js +109 -0
  90. package/lib/pricing/depthBands/encoder.d.ts +19 -0
  91. package/lib/pricing/depthBands/encoder.js +105 -0
  92. package/lib/pricing/depthBands/index.d.ts +8 -0
  93. package/lib/pricing/depthBands/index.js +26 -0
  94. package/lib/pricing/depthBands/types.d.ts +49 -0
  95. package/lib/pricing/depthBands/types.js +10 -0
  96. package/lib/pricing/depthBands/validator.d.ts +22 -0
  97. package/lib/pricing/depthBands/validator.js +113 -0
  98. package/lib/pricing/depthBands.d.ts +39 -0
  99. package/lib/pricing/depthBands.js +92 -0
  100. package/lib/pricing/index.d.ts +4 -0
  101. package/lib/pricing/index.js +20 -0
  102. package/lib/trade/effectiveLeverage/builder.d.ts +23 -0
  103. package/lib/trade/effectiveLeverage/builder.js +30 -0
  104. package/lib/trade/fees/borrowing/builder.js +3 -2
  105. package/lib/trade/fees/borrowing/converter.js +1 -5
  106. package/lib/trade/fees/borrowing/index.js +5 -5
  107. package/lib/trade/fees/borrowingV2/builder.js +4 -3
  108. package/lib/trade/fees/borrowingV2/converter.js +1 -1
  109. package/lib/trade/fees/borrowingV2/fetcher.d.ts +0 -1
  110. package/lib/trade/fees/borrowingV2/fetcher.js +32 -26
  111. package/lib/trade/fees/borrowingV2/index.js +3 -3
  112. package/lib/trade/fees/converter.js +22 -22
  113. package/lib/trade/fees/fundingFees/builder.js +7 -6
  114. package/lib/trade/fees/fundingFees/converter.js +1 -1
  115. package/lib/trade/fees/fundingFees/fetcher.js +25 -16
  116. package/lib/trade/fees/fundingFees/index.js +3 -2
  117. package/lib/trade/fees/holdingFees/index.d.ts +46 -0
  118. package/lib/trade/fees/holdingFees/index.js +105 -0
  119. package/lib/trade/fees/holdingFees/types.d.ts +23 -0
  120. package/lib/trade/fees/holdingFees/types.js +5 -0
  121. package/lib/trade/fees/tiers/index.js +2 -1
  122. package/lib/trade/fees/trading/holdingFees.d.ts +28 -0
  123. package/lib/trade/fees/trading/holdingFees.js +66 -0
  124. package/lib/trade/fees/trading/holdingFeesStructured.d.ts +28 -0
  125. package/lib/trade/fees/trading/holdingFeesStructured.js +66 -0
  126. package/lib/trade/fees/trading/index.js +3 -5
  127. package/lib/trade/liquidation/builder.js +3 -6
  128. package/lib/trade/liquidation/index.js +6 -4
  129. package/lib/trade/oiWindows.js +2 -1
  130. package/lib/trade/pnl/builder.js +2 -1
  131. package/lib/trade/pnl/converter.js +1 -1
  132. package/lib/trade/pnl/index.js +7 -4
  133. package/lib/trade/priceImpact/close/builder.js +2 -1
  134. package/lib/trade/priceImpact/close/index.js +1 -4
  135. package/lib/trade/priceImpact/cumulVol/builder.js +11 -18
  136. package/lib/trade/priceImpact/cumulVol/converter.d.ts +63 -0
  137. package/lib/trade/priceImpact/cumulVol/converter.js +97 -1
  138. package/lib/trade/priceImpact/cumulVol/index.d.ts +3 -0
  139. package/lib/trade/priceImpact/cumulVol/index.js +123 -25
  140. package/lib/trade/priceImpact/cumulVol/types.d.ts +11 -0
  141. package/lib/trade/priceImpact/cumulVol/types.js +2 -0
  142. package/lib/trade/priceImpact/open/builder.js +2 -1
  143. package/lib/trade/priceImpact/open/index.js +1 -4
  144. package/lib/trade/priceImpact/skew/builder.js +3 -2
  145. package/lib/trade/priceImpact/skew/converter.js +1 -1
  146. package/lib/trade/priceImpact/skew/fetcher.js +33 -24
  147. package/package.json +2 -2
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.calculateTradeSkewPriceImpact = exports.fetchCollateralDecimals = exports.fetchSkewPriceImpactContext = exports.fetchPairSkewDepths = exports.fetchPairSkewDepth = exports.fetchPairOisAfterV10Token = exports.fetchPairOiAfterV10Token = void 0;
4
13
  const converter_1 = require("./converter");
@@ -9,16 +18,16 @@ const converter_1 = require("./converter");
9
18
  * @param pairIndex Pair index
10
19
  * @returns Promise resolving to pair OI in tokens
11
20
  */
12
- const fetchPairOiAfterV10Token = async (contract, collateralIndex, pairIndex) => {
21
+ const fetchPairOiAfterV10Token = (contract, collateralIndex, pairIndex) => __awaiter(void 0, void 0, void 0, function* () {
13
22
  try {
14
- const contractData = await contract.getPairOiAfterV10Token(collateralIndex, pairIndex);
23
+ const contractData = yield contract.getPairOiAfterV10Token(collateralIndex, pairIndex);
15
24
  return (0, converter_1.convertPairOiToken)(contractData);
16
25
  }
17
26
  catch (error) {
18
27
  console.error("Error fetching pair OI token:", error);
19
28
  throw error;
20
29
  }
21
- };
30
+ });
22
31
  exports.fetchPairOiAfterV10Token = fetchPairOiAfterV10Token;
23
32
  /**
24
33
  * @dev Fetches pair open interest in tokens for multiple pairs
@@ -27,19 +36,19 @@ exports.fetchPairOiAfterV10Token = fetchPairOiAfterV10Token;
27
36
  * @param pairIndices Array of pair indices
28
37
  * @returns Promise resolving to array of pair OI in tokens
29
38
  */
30
- const fetchPairOisAfterV10Token = async (contract, collateralIndices, pairIndices) => {
39
+ const fetchPairOisAfterV10Token = (contract, collateralIndices, pairIndices) => __awaiter(void 0, void 0, void 0, function* () {
31
40
  if (collateralIndices.length !== pairIndices.length) {
32
41
  throw new Error("Collateral indices and pair indices arrays must have the same length");
33
42
  }
34
43
  try {
35
- const contractDataArray = await contract.getPairOisAfterV10Token(collateralIndices, pairIndices);
44
+ const contractDataArray = yield contract.getPairOisAfterV10Token(collateralIndices, pairIndices);
36
45
  return contractDataArray.map(converter_1.convertPairOiToken);
37
46
  }
38
47
  catch (error) {
39
48
  console.error("Error fetching pair OIs token:", error);
40
49
  throw error;
41
50
  }
42
- };
51
+ });
43
52
  exports.fetchPairOisAfterV10Token = fetchPairOisAfterV10Token;
44
53
  /**
45
54
  * @dev Fetches skew depth for a specific pair
@@ -48,9 +57,9 @@ exports.fetchPairOisAfterV10Token = fetchPairOisAfterV10Token;
48
57
  * @param pairIndex Pair index
49
58
  * @returns Promise resolving to normalized skew depth
50
59
  */
51
- const fetchPairSkewDepth = async (contract, collateralIndex, pairIndex) => {
60
+ const fetchPairSkewDepth = (contract, collateralIndex, pairIndex) => __awaiter(void 0, void 0, void 0, function* () {
52
61
  try {
53
- const contractDepth = await contract.getPairSkewDepth(collateralIndex, pairIndex);
62
+ const contractDepth = yield contract.getPairSkewDepth(collateralIndex, pairIndex);
54
63
  // Token depths are always 1e18 precision
55
64
  return (0, converter_1.convertSkewDepth)(contractDepth.toString());
56
65
  }
@@ -58,7 +67,7 @@ const fetchPairSkewDepth = async (contract, collateralIndex, pairIndex) => {
58
67
  console.error("Error fetching skew depth:", error);
59
68
  throw error;
60
69
  }
61
- };
70
+ });
62
71
  exports.fetchPairSkewDepth = fetchPairSkewDepth;
63
72
  /**
64
73
  * @dev Fetches skew depths for multiple pairs
@@ -67,12 +76,12 @@ exports.fetchPairSkewDepth = fetchPairSkewDepth;
67
76
  * @param pairIndices Array of pair indices
68
77
  * @returns Promise resolving to array of normalized skew depths
69
78
  */
70
- const fetchPairSkewDepths = async (contract, collateralIndices, pairIndices) => {
79
+ const fetchPairSkewDepths = (contract, collateralIndices, pairIndices) => __awaiter(void 0, void 0, void 0, function* () {
71
80
  if (collateralIndices.length !== pairIndices.length) {
72
81
  throw new Error("All input arrays must have the same length");
73
82
  }
74
83
  try {
75
- const contractDepths = await contract.getPairSkewDepths(collateralIndices, pairIndices);
84
+ const contractDepths = yield contract.getPairSkewDepths(collateralIndices, pairIndices);
76
85
  // Token depths are always 1e18 precision
77
86
  return contractDepths.map(depth => (0, converter_1.convertSkewDepth)(depth.toString()));
78
87
  }
@@ -80,7 +89,7 @@ const fetchPairSkewDepths = async (contract, collateralIndices, pairIndices) =>
80
89
  console.error("Error fetching skew depths:", error);
81
90
  throw error;
82
91
  }
83
- };
92
+ });
84
93
  exports.fetchPairSkewDepths = fetchPairSkewDepths;
85
94
  /**
86
95
  * @dev Fetches skew price impact context for a single pair
@@ -89,10 +98,10 @@ exports.fetchPairSkewDepths = fetchPairSkewDepths;
89
98
  * @param pairIndex Pair index
90
99
  * @returns Promise resolving to skew price impact context
91
100
  */
92
- const fetchSkewPriceImpactContext = async (contract, collateralIndex, pairIndex) => {
101
+ const fetchSkewPriceImpactContext = (contract, collateralIndex, pairIndex) => __awaiter(void 0, void 0, void 0, function* () {
93
102
  try {
94
103
  // Fetch OI data and skew depth in parallel
95
- const [pairOiToken, skewDepth] = await Promise.all([
104
+ const [pairOiToken, skewDepth] = yield Promise.all([
96
105
  (0, exports.fetchPairOiAfterV10Token)(contract, collateralIndex, pairIndex),
97
106
  (0, exports.fetchPairSkewDepth)(contract, collateralIndex, pairIndex),
98
107
  ]);
@@ -105,7 +114,7 @@ const fetchSkewPriceImpactContext = async (contract, collateralIndex, pairIndex)
105
114
  console.error("Error fetching skew price impact context:", error);
106
115
  throw error;
107
116
  }
108
- };
117
+ });
109
118
  exports.fetchSkewPriceImpactContext = fetchSkewPriceImpactContext;
110
119
  /**
111
120
  * @dev Fetches collateral decimals for given collateral indices
@@ -113,16 +122,16 @@ exports.fetchSkewPriceImpactContext = fetchSkewPriceImpactContext;
113
122
  * @param collateralIndices Array of collateral indices
114
123
  * @returns Promise resolving to array of decimals
115
124
  */
116
- const fetchCollateralDecimals = async (contract, collateralIndices) => {
125
+ const fetchCollateralDecimals = (contract, collateralIndices) => __awaiter(void 0, void 0, void 0, function* () {
117
126
  try {
118
127
  // Get unique collateral indices to minimize calls
119
128
  const uniqueIndices = [...new Set(collateralIndices)];
120
129
  // Fetch collateral info for unique indices
121
- const promises = uniqueIndices.map(async (index) => {
122
- const collateral = await contract.getCollateral(index);
130
+ const promises = uniqueIndices.map((index) => __awaiter(void 0, void 0, void 0, function* () {
131
+ const collateral = yield contract.getCollateral(index);
123
132
  return { index, decimals: Number(collateral.precision) };
124
- });
125
- const collateralData = await Promise.all(promises);
133
+ }));
134
+ const collateralData = yield Promise.all(promises);
126
135
  // Create a map for quick lookup
127
136
  const decimalsMap = new Map(collateralData.map(data => [data.index, data.decimals]));
128
137
  // Return decimals in the same order as input
@@ -133,7 +142,7 @@ const fetchCollateralDecimals = async (contract, collateralIndices) => {
133
142
  console.error("Error fetching collateral decimals:", error);
134
143
  throw error;
135
144
  }
136
- };
145
+ });
137
146
  exports.fetchCollateralDecimals = fetchCollateralDecimals;
138
147
  /**
139
148
  * @dev Calculates skew price impact for a trade using contract call
@@ -145,9 +154,9 @@ exports.fetchCollateralDecimals = fetchCollateralDecimals;
145
154
  * @param open Whether trade is opening
146
155
  * @returns Promise resolving to price impact percentage (1e10)
147
156
  */
148
- const calculateTradeSkewPriceImpact = async (contract, collateralIndex, pairIndex, long, positionSizeToken, open) => {
157
+ const calculateTradeSkewPriceImpact = (contract, collateralIndex, pairIndex, long, positionSizeToken, open) => __awaiter(void 0, void 0, void 0, function* () {
149
158
  try {
150
- const priceImpactP = await contract.getTradeSkewPriceImpactP(collateralIndex, pairIndex, long, BigInt(Math.round(positionSizeToken * 1e18)), // Convert to 1e18 precision
159
+ const priceImpactP = yield contract.getTradeSkewPriceImpactP(collateralIndex, pairIndex, long, BigInt(Math.round(positionSizeToken * 1e18)), // Convert to 1e18 precision
151
160
  open);
152
161
  // Convert from int256 1e10 to percentage
153
162
  return Number(priceImpactP) / 1e10;
@@ -156,5 +165,5 @@ const calculateTradeSkewPriceImpact = async (contract, collateralIndex, pairInde
156
165
  console.error("Error calculating trade skew price impact:", error);
157
166
  throw error;
158
167
  }
159
- };
168
+ });
160
169
  exports.calculateTradeSkewPriceImpact = calculateTradeSkewPriceImpact;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gainsnetwork/sdk",
3
- "version": "1.0.6-rc3",
3
+ "version": "1.1.0-rc1",
4
4
  "description": "Gains Network SDK",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -24,7 +24,7 @@
24
24
  "url": "git+git@github.com:GainsNetwork-org/sdk.git"
25
25
  },
26
26
  "engines": {
27
- "node": ">=14.0"
27
+ "node": ">=12.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@typechain/ethers-v5": "^10.1.1",