@gainsnetwork/sdk 1.4.0-rc1 → 1.4.2-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 (142) hide show
  1. package/lib/backend/globalTrades/index.js +10 -10
  2. package/lib/backend/tradingVariables/converter.js +57 -57
  3. package/lib/backend/tradingVariables/index.js +6 -7
  4. package/lib/constants.js +2 -2
  5. package/lib/contracts/addresses.js +4 -1
  6. package/lib/contracts/index.d.ts +1 -1
  7. package/lib/contracts/index.js +3 -3
  8. package/lib/contracts/types/generated/GFarmTradingStorageV5.d.ts +1911 -0
  9. package/lib/contracts/types/generated/GFarmTradingStorageV5.js +2 -0
  10. package/lib/contracts/types/generated/GNSBorrowingFees.d.ts +1067 -0
  11. package/lib/contracts/types/generated/GNSBorrowingFees.js +2 -0
  12. package/lib/contracts/types/generated/GNSBorrowingFeesV6_3_2.d.ts +979 -0
  13. package/lib/contracts/types/generated/GNSBorrowingFeesV6_3_2.js +2 -0
  14. package/lib/contracts/types/generated/GNSBorrowingFeesV6_4.d.ts +1058 -0
  15. package/lib/contracts/types/generated/GNSBorrowingFeesV6_4.js +2 -0
  16. package/lib/contracts/types/generated/GNSMultiCollatDiamond.d.ts +386 -260
  17. package/lib/contracts/types/generated/GNSNftRewardsV6.d.ts +533 -0
  18. package/lib/contracts/types/generated/GNSNftRewardsV6.js +2 -0
  19. package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.d.ts +613 -0
  20. package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.js +2 -0
  21. package/lib/contracts/types/generated/GNSPairInfosV6_1.d.ts +911 -0
  22. package/lib/contracts/types/generated/GNSPairInfosV6_1.js +2 -0
  23. package/lib/contracts/types/generated/GNSPairsStorageV6.d.ts +660 -0
  24. package/lib/contracts/types/generated/GNSPairsStorageV6.js +2 -0
  25. package/lib/contracts/types/generated/GNSTrading.d.ts +758 -0
  26. package/lib/contracts/types/generated/GNSTrading.js +2 -0
  27. package/lib/contracts/types/generated/GNSTradingCallbacks.d.ts +875 -0
  28. package/lib/contracts/types/generated/GNSTradingCallbacks.js +2 -0
  29. package/lib/contracts/types/generated/GNSTradingCallbacksV6_3_2.d.ts +806 -0
  30. package/lib/contracts/types/generated/GNSTradingCallbacksV6_3_2.js +2 -0
  31. package/lib/contracts/types/generated/GNSTradingCallbacksV6_4.d.ts +821 -0
  32. package/lib/contracts/types/generated/GNSTradingCallbacksV6_4.js +2 -0
  33. package/lib/contracts/types/generated/GNSTradingStorage.d.ts +1387 -0
  34. package/lib/contracts/types/generated/GNSTradingStorage.js +2 -0
  35. package/lib/contracts/types/generated/GTokenV6_3_2.d.ts +1838 -0
  36. package/lib/contracts/types/generated/GTokenV6_3_2.js +2 -0
  37. package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.d.ts +83 -0
  38. package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.js +2691 -0
  39. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_3_2__factory.d.ts +88 -0
  40. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_3_2__factory.js +1654 -0
  41. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_4__factory.d.ts +113 -0
  42. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_4__factory.js +1742 -0
  43. package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.d.ts +124 -0
  44. package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.js +1784 -0
  45. package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.d.ts +2 -10
  46. package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +1621 -219
  47. package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.d.ts +100 -0
  48. package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.js +1116 -0
  49. package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.d.ts +100 -0
  50. package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.js +1003 -0
  51. package/lib/contracts/types/generated/factories/GNSPairInfosV6_1__factory.d.ts +98 -0
  52. package/lib/contracts/types/generated/factories/GNSPairInfosV6_1__factory.js +1485 -0
  53. package/lib/contracts/types/generated/factories/GNSPairsStorageV6__factory.d.ts +117 -0
  54. package/lib/contracts/types/generated/factories/GNSPairsStorageV6__factory.js +1265 -0
  55. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_3_2__factory.d.ts +82 -0
  56. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_3_2__factory.js +1273 -0
  57. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_4__factory.d.ts +82 -0
  58. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_4__factory.js +1326 -0
  59. package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.d.ts +113 -0
  60. package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.js +1428 -0
  61. package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.d.ts +96 -0
  62. package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.js +2241 -0
  63. package/lib/contracts/types/generated/factories/GNSTrading__factory.d.ts +95 -0
  64. package/lib/contracts/types/generated/factories/GNSTrading__factory.js +1071 -0
  65. package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.d.ts +110 -0
  66. package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.js +2682 -0
  67. package/lib/contracts/utils/borrowingFees.js +9 -20
  68. package/lib/contracts/utils/openTrades.js +11 -20
  69. package/lib/contracts/utils/pairs.js +12 -21
  70. package/lib/markets/forex.js +1 -1
  71. package/lib/markets/leverage/builder.js +2 -2
  72. package/lib/markets/oi/fetcher.d.ts +58 -0
  73. package/lib/markets/oi/fetcher.js +181 -0
  74. package/lib/markets/oi/validation.d.ts +80 -0
  75. package/lib/markets/oi/validation.js +172 -0
  76. package/lib/markets/price/index.d.ts +1 -0
  77. package/lib/markets/price/index.js +1 -0
  78. package/lib/markets/price/signedPrices.d.ts +36 -0
  79. package/lib/markets/price/signedPrices.js +181 -0
  80. package/lib/markets/price/types.d.ts +27 -0
  81. package/lib/pricing/depthBands/converter.d.ts +65 -0
  82. package/lib/pricing/depthBands/converter.js +155 -0
  83. package/lib/pricing/depthBands/decoder.d.ts +32 -0
  84. package/lib/pricing/depthBands/decoder.js +109 -0
  85. package/lib/pricing/depthBands/encoder.d.ts +19 -0
  86. package/lib/pricing/depthBands/encoder.js +105 -0
  87. package/lib/pricing/depthBands/index.d.ts +8 -0
  88. package/lib/pricing/depthBands/index.js +26 -0
  89. package/lib/pricing/depthBands/types.d.ts +49 -0
  90. package/lib/pricing/depthBands/types.js +10 -0
  91. package/lib/pricing/depthBands/validator.d.ts +22 -0
  92. package/lib/pricing/depthBands/validator.js +113 -0
  93. package/lib/pricing/depthBands.d.ts +39 -0
  94. package/lib/pricing/depthBands.js +94 -0
  95. package/lib/pricing/index.d.ts +4 -0
  96. package/lib/pricing/index.js +20 -0
  97. package/lib/trade/effectiveLeverage/builder.d.ts +23 -0
  98. package/lib/trade/effectiveLeverage/builder.js +30 -0
  99. package/lib/trade/fees/borrowing/builder.js +2 -3
  100. package/lib/trade/fees/borrowing/converter.js +5 -1
  101. package/lib/trade/fees/borrowing/index.js +5 -5
  102. package/lib/trade/fees/borrowingV2/builder.js +3 -4
  103. package/lib/trade/fees/borrowingV2/converter.js +1 -1
  104. package/lib/trade/fees/borrowingV2/fetcher.js +26 -32
  105. package/lib/trade/fees/borrowingV2/index.js +3 -3
  106. package/lib/trade/fees/converter.js +22 -22
  107. package/lib/trade/fees/fundingFees/builder.js +6 -7
  108. package/lib/trade/fees/fundingFees/converter.js +1 -1
  109. package/lib/trade/fees/fundingFees/fetcher.js +16 -25
  110. package/lib/trade/fees/fundingFees/index.js +2 -3
  111. package/lib/trade/fees/holdingFees/index.d.ts +46 -0
  112. package/lib/trade/fees/holdingFees/index.js +105 -0
  113. package/lib/trade/fees/holdingFees/types.d.ts +23 -0
  114. package/lib/trade/fees/holdingFees/types.js +5 -0
  115. package/lib/trade/fees/tiers/index.js +1 -2
  116. package/lib/trade/fees/trading/holdingFees.d.ts +28 -0
  117. package/lib/trade/fees/trading/holdingFees.js +66 -0
  118. package/lib/trade/fees/trading/holdingFeesStructured.d.ts +28 -0
  119. package/lib/trade/fees/trading/holdingFeesStructured.js +66 -0
  120. package/lib/trade/fees/trading/index.js +5 -3
  121. package/lib/trade/liquidation/builder.js +1 -2
  122. package/lib/trade/liquidation/index.js +4 -6
  123. package/lib/trade/oiWindows.js +1 -2
  124. package/lib/trade/pnl/builder.js +1 -2
  125. package/lib/trade/pnl/converter.js +1 -1
  126. package/lib/trade/pnl/index.js +4 -7
  127. package/lib/trade/priceImpact/close/builder.js +1 -2
  128. package/lib/trade/priceImpact/close/index.js +4 -1
  129. package/lib/trade/priceImpact/cumulVol/builder.js +18 -10
  130. package/lib/trade/priceImpact/cumulVol/index.js +21 -16
  131. package/lib/trade/priceImpact/cumulVol/types.d.ts +11 -0
  132. package/lib/trade/priceImpact/cumulVol/types.js +2 -0
  133. package/lib/trade/priceImpact/open/builder.js +1 -2
  134. package/lib/trade/priceImpact/open/index.js +4 -1
  135. package/lib/trade/priceImpact/skew/builder.js +2 -3
  136. package/lib/trade/priceImpact/skew/converter.js +1 -1
  137. package/lib/trade/priceImpact/skew/fetcher.js +24 -33
  138. package/package.json +2 -2
  139. package/lib/trade/liquidation.d.ts +0 -12
  140. package/lib/trade/liquidation.js +0 -55
  141. package/lib/trade/pnl.d.ts +0 -10
  142. package/lib/trade/pnl.js +0 -33
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildTradeEffectiveLeverageContext = void 0;
4
+ const __1 = require("..");
5
+ /**
6
+ * @dev Builds a complete context for effective leverage calculations
7
+ * @dev Uses the closing price impact context builder as a sub-context
8
+ * @param globalTradingVariables The transformed global trading variables from backend
9
+ * @param collateralIndex The collateral index (1-based)
10
+ * @param pairIndex The pair index
11
+ * @param tradeInfo Trade information including createdBlock
12
+ * @param additionalParams Additional parameters for price impact calculations
13
+ * @returns Complete context ready for getTradeNewEffectiveLeverage
14
+ */
15
+ const buildTradeEffectiveLeverageContext = (globalTradingVariables, collateralIndex, pairIndex, tradeInfo, additionalParams) => {
16
+ var _a;
17
+ // Build the closing price impact context which we'll use for PnL calculations
18
+ const closingPriceImpactContext = (0, __1.buildTradeClosingPriceImpactContext)(globalTradingVariables, collateralIndex, pairIndex, tradeInfo, additionalParams);
19
+ if (!closingPriceImpactContext) {
20
+ return undefined;
21
+ }
22
+ // Extract base spread from pairs data
23
+ const pairs = globalTradingVariables.pairs;
24
+ const baseSpreadP = ((_a = pairs === null || pairs === void 0 ? void 0 : pairs[pairIndex]) === null || _a === void 0 ? void 0 : _a.spreadP) || 0;
25
+ return {
26
+ closingPriceImpactContext,
27
+ baseSpreadP,
28
+ };
29
+ };
30
+ exports.buildTradeEffectiveLeverageContext = buildTradeEffectiveLeverageContext;
@@ -13,9 +13,8 @@ exports.buildBorrowingV1Context = void 0;
13
13
  * @returns Full borrowing context with all pairs and groups or undefined if data not available
14
14
  */
15
15
  const buildBorrowingV1Context = (globalTradingVariables, collateralIndex, currentBlock) => {
16
- var _a;
17
16
  const collateral = globalTradingVariables.collaterals[collateralIndex - 1];
18
- if (!(collateral === null || collateral === void 0 ? void 0 : collateral.pairBorrowingFees) || !(collateral === null || collateral === void 0 ? void 0 : collateral.groupBorrowingFees)) {
17
+ if (!collateral?.pairBorrowingFees || !collateral?.groupBorrowingFees) {
19
18
  return undefined;
20
19
  }
21
20
  const pairs = collateral.pairBorrowingFees;
@@ -27,7 +26,7 @@ const buildBorrowingV1Context = (globalTradingVariables, collateralIndex, curren
27
26
  currentBlock,
28
27
  pairs,
29
28
  groups,
30
- collateralPriceUsd: ((_a = collateral.prices) === null || _a === void 0 ? void 0 : _a.collateralPriceUsd) || 1,
29
+ collateralPriceUsd: collateral.prices?.collateralPriceUsd || 1,
31
30
  pairOis: collateral.pairOis,
32
31
  };
33
32
  };
@@ -14,7 +14,11 @@ const convertPairGroupBorrowingFee = (pairGroup) => ({
14
14
  block: pairGroup.block,
15
15
  });
16
16
  exports.convertPairGroupBorrowingFee = convertPairGroupBorrowingFee;
17
- const convertPairBorrowingFee = (pair, pairOi, pairGroup, feeCap) => (Object.assign(Object.assign({}, (0, exports.convertGroupBorrowingData)(pair, pairOi)), { groups: pairGroup.map(value => (0, exports.convertPairGroupBorrowingFee)(value)), feePerBlockCap: (0, exports.convertFeePerBlockCap)(feeCap) }));
17
+ const convertPairBorrowingFee = (pair, pairOi, pairGroup, feeCap) => ({
18
+ ...(0, exports.convertGroupBorrowingData)(pair, pairOi),
19
+ groups: pairGroup.map(value => (0, exports.convertPairGroupBorrowingFee)(value)),
20
+ feePerBlockCap: (0, exports.convertFeePerBlockCap)(feeCap),
21
+ });
18
22
  exports.convertPairBorrowingFee = convertPairBorrowingFee;
19
23
  const convertPairBorrowingFees = ([pairs, pairOi, pairGroups, feeCaps]) => pairs.map((value, ix) => (0, exports.convertPairBorrowingFee)(value, pairOi[ix], pairGroups[ix], feeCaps[ix]));
20
24
  exports.convertPairBorrowingFees = convertPairBorrowingFees;
@@ -48,7 +48,7 @@ const getBorrowingFee = (posDai, pairIndex, long, initialAccFees, currentPairPri
48
48
  return 0;
49
49
  }
50
50
  const pairGroups = pairs[pairIndex].groups;
51
- const firstPairGroup = (pairGroups === null || pairGroups === void 0 ? void 0 : pairGroups.length) > 0 ? pairGroups[0] : undefined;
51
+ const firstPairGroup = pairGroups?.length > 0 ? pairGroups[0] : undefined;
52
52
  let fee = 0;
53
53
  if (!firstPairGroup || firstPairGroup.block > initialAccFees.block) {
54
54
  const openInterest = (0, __1.getPairTotalOisDynamicCollateral)(pairIndex, {
@@ -215,13 +215,13 @@ collateralPriceUsd) => {
215
215
  };
216
216
  const getPendingAccFeesDelta = (blockDistance, feePerBlock, netOi, maxOi, feeExponent) => {
217
217
  return maxOi > 0 && feeExponent > 0
218
- ? feePerBlock * blockDistance * Math.pow((netOi / maxOi), feeExponent)
218
+ ? feePerBlock * blockDistance * (netOi / maxOi) ** feeExponent
219
219
  : 0;
220
220
  };
221
221
  const getFeePerBlockCaps = (cap) => {
222
222
  return {
223
- minP: (cap === null || cap === void 0 ? void 0 : cap.minP) || 0,
224
- maxP: (cap === null || cap === void 0 ? void 0 : cap.maxP) && cap.maxP > 0 ? cap.maxP : 1,
223
+ minP: cap?.minP || 0,
224
+ maxP: cap?.maxP && cap.maxP > 0 ? cap.maxP : 1,
225
225
  };
226
226
  };
227
227
  const getBorrowingDataActiveFeePerBlock = (val) => {
@@ -231,7 +231,7 @@ const getBorrowingDataActiveFeePerBlock = (val) => {
231
231
  // If minP > 0 then netOi has to be at least minP * maxOi
232
232
  // If maxP > 0 then netOi cannot be more than maxP * maxOi
233
233
  const effectiveOi = Math.min(Math.max(Math.abs(long - short), max * minP), max * maxP);
234
- return val.feePerBlock * Math.pow((effectiveOi / max), val.feeExponent);
234
+ return val.feePerBlock * (effectiveOi / max) ** val.feeExponent;
235
235
  };
236
236
  const getActiveFeePerBlock = (pair, group) => {
237
237
  const pairFeePerBlock = getBorrowingDataActiveFeePerBlock(pair);
@@ -5,13 +5,12 @@ exports.buildBorrowingV2Context = void 0;
5
5
  * @dev Builds borrowing v2 sub-context for a specific pair
6
6
  */
7
7
  const buildBorrowingV2Context = (globalTradingVariables, collateralIndex, pairIndex, currentTimestamp) => {
8
- var _a, _b;
9
8
  const collateral = globalTradingVariables.collaterals[collateralIndex - 1];
10
- if (!(collateral === null || collateral === void 0 ? void 0 : collateral.pairBorrowingFeesV2)) {
9
+ if (!collateral?.pairBorrowingFeesV2) {
11
10
  return undefined;
12
11
  }
13
- const params = (_a = collateral.pairBorrowingFeesV2.params) === null || _a === void 0 ? void 0 : _a[pairIndex];
14
- const data = (_b = collateral.pairBorrowingFeesV2.data) === null || _b === void 0 ? void 0 : _b[pairIndex];
12
+ const params = collateral.pairBorrowingFeesV2.params?.[pairIndex];
13
+ const data = collateral.pairBorrowingFeesV2.data?.[pairIndex];
15
14
  if (!params || !data) {
16
15
  return undefined;
17
16
  }
@@ -116,7 +116,7 @@ exports.aprToBorrowingRate = aprToBorrowingRate;
116
116
  */
117
117
  const createCollateralScopedBorrowingContext = (collateralBorrowingData, currentTimestamp) => {
118
118
  const context = {
119
- currentTimestamp: currentTimestamp !== null && currentTimestamp !== void 0 ? currentTimestamp : Math.floor(Date.now() / 1000),
119
+ currentTimestamp: currentTimestamp ?? Math.floor(Date.now() / 1000),
120
120
  borrowingParams: {},
121
121
  borrowingData: {},
122
122
  };
@@ -1,13 +1,4 @@
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
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.fetchBorrowingV2DataForPairs = exports.createBorrowingV2ContextFromArrays = exports.createBorrowingV2ContextFromContract = exports.fetchAllBorrowingV2Data = exports.fetchPairPendingAccBorrowingFeesV2 = exports.fetchTradeBorrowingFeesCollateralV2 = exports.fetchPairBorrowingFeeDataV2 = exports.fetchBorrowingFeeParamsV2 = void 0;
13
4
  const converter_1 = require("./converter");
@@ -18,19 +9,19 @@ const converter_1 = require("./converter");
18
9
  * @param pairIndices Array of pair indices
19
10
  * @returns Promise resolving to array of borrowing fee parameters
20
11
  */
21
- const fetchBorrowingFeeParamsV2 = (contract, collateralIndices, pairIndices) => __awaiter(void 0, void 0, void 0, function* () {
12
+ const fetchBorrowingFeeParamsV2 = async (contract, collateralIndices, pairIndices) => {
22
13
  if (collateralIndices.length !== pairIndices.length) {
23
14
  throw new Error("Collateral indices and pair indices arrays must have the same length");
24
15
  }
25
16
  try {
26
- const contractParams = yield contract.getPairBorrowingFeeParams(collateralIndices, pairIndices);
17
+ const contractParams = await contract.getPairBorrowingFeeParams(collateralIndices, pairIndices);
27
18
  return (0, converter_1.convertBorrowingFeeParamsArray)(contractParams);
28
19
  }
29
20
  catch (error) {
30
21
  console.error("Error fetching borrowing fee params v2:", error);
31
22
  throw error;
32
23
  }
33
- });
24
+ };
34
25
  exports.fetchBorrowingFeeParamsV2 = fetchBorrowingFeeParamsV2;
35
26
  /**
36
27
  * @dev Fetches pair borrowing fee data v2 for specific pairs
@@ -39,19 +30,19 @@ exports.fetchBorrowingFeeParamsV2 = fetchBorrowingFeeParamsV2;
39
30
  * @param pairIndices Array of pair indices
40
31
  * @returns Promise resolving to array of pair borrowing fee data
41
32
  */
42
- const fetchPairBorrowingFeeDataV2 = (contract, collateralIndices, pairIndices) => __awaiter(void 0, void 0, void 0, function* () {
33
+ const fetchPairBorrowingFeeDataV2 = async (contract, collateralIndices, pairIndices) => {
43
34
  if (collateralIndices.length !== pairIndices.length) {
44
35
  throw new Error("Collateral indices and pair indices arrays must have the same length");
45
36
  }
46
37
  try {
47
- const contractData = yield contract.getPairBorrowingFeeData(collateralIndices, pairIndices);
38
+ const contractData = await contract.getPairBorrowingFeeData(collateralIndices, pairIndices);
48
39
  return (0, converter_1.convertPairBorrowingFeeDataArray)(contractData);
49
40
  }
50
41
  catch (error) {
51
42
  console.error("Error fetching pair borrowing fee data v2:", error);
52
43
  throw error;
53
44
  }
54
- });
45
+ };
55
46
  exports.fetchPairBorrowingFeeDataV2 = fetchPairBorrowingFeeDataV2;
56
47
  /**
57
48
  * @dev Fetches borrowing fees in collateral tokens for a specific trade
@@ -61,9 +52,9 @@ exports.fetchPairBorrowingFeeDataV2 = fetchPairBorrowingFeeDataV2;
61
52
  * @param currentPairPrice Current price of the trading pair (1e6 precision)
62
53
  * @returns Promise resolving to borrowing fees in collateral tokens
63
54
  */
64
- const fetchTradeBorrowingFeesCollateralV2 = (contract, trader, index, currentPairPrice) => __awaiter(void 0, void 0, void 0, function* () {
55
+ const fetchTradeBorrowingFeesCollateralV2 = async (contract, trader, index, currentPairPrice) => {
65
56
  try {
66
- const feesCollateral = yield contract.getTradeBorrowingFeesCollateral(trader, index, currentPairPrice);
57
+ const feesCollateral = await contract.getTradeBorrowingFeesCollateral(trader, index, currentPairPrice);
67
58
  // Convert BigNumber to normalized float
68
59
  // Note: Collateral precision varies by chain, but contract returns proper precision
69
60
  return parseFloat(feesCollateral.toString());
@@ -72,7 +63,7 @@ const fetchTradeBorrowingFeesCollateralV2 = (contract, trader, index, currentPai
72
63
  console.error("Error fetching trade borrowing fees collateral v2:", error);
73
64
  throw error;
74
65
  }
75
- });
66
+ };
76
67
  exports.fetchTradeBorrowingFeesCollateralV2 = fetchTradeBorrowingFeesCollateralV2;
77
68
  /**
78
69
  * @dev Fetches pending accumulated borrowing fees for a specific pair
@@ -82,9 +73,9 @@ exports.fetchTradeBorrowingFeesCollateralV2 = fetchTradeBorrowingFeesCollateralV
82
73
  * @param currentPairPrice Current price of the trading pair (1e6 precision)
83
74
  * @returns Promise resolving to pending accumulated borrowing fee
84
75
  */
85
- const fetchPairPendingAccBorrowingFeesV2 = (contract, collateralIndex, pairIndex, currentPairPrice) => __awaiter(void 0, void 0, void 0, function* () {
76
+ const fetchPairPendingAccBorrowingFeesV2 = async (contract, collateralIndex, pairIndex, currentPairPrice) => {
86
77
  try {
87
- const accBorrowingFeeP = yield contract.getPairPendingAccBorrowingFees(collateralIndex, pairIndex, currentPairPrice);
78
+ const accBorrowingFeeP = await contract.getPairPendingAccBorrowingFees(collateralIndex, pairIndex, currentPairPrice);
88
79
  // Convert BigNumber to normalized float
89
80
  return parseFloat(accBorrowingFeeP.toString()) / 1e20;
90
81
  }
@@ -92,7 +83,7 @@ const fetchPairPendingAccBorrowingFeesV2 = (contract, collateralIndex, pairIndex
92
83
  console.error("Error fetching pair pending acc borrowing fees v2:", error);
93
84
  throw error;
94
85
  }
95
- });
86
+ };
96
87
  exports.fetchPairPendingAccBorrowingFeesV2 = fetchPairPendingAccBorrowingFeesV2;
97
88
  /**
98
89
  * @dev Convenience function to fetch all borrowing v2 data for specific pairs
@@ -101,11 +92,11 @@ exports.fetchPairPendingAccBorrowingFeesV2 = fetchPairPendingAccBorrowingFeesV2;
101
92
  * @param pairIndices Array of pair indices
102
93
  * @returns Promise resolving to complete borrowing v2 data set
103
94
  */
104
- const fetchAllBorrowingV2Data = (contract, collateralIndex, pairIndices) => __awaiter(void 0, void 0, void 0, function* () {
95
+ const fetchAllBorrowingV2Data = async (contract, collateralIndex, pairIndices) => {
105
96
  const collateralIndices = new Array(pairIndices.length).fill(collateralIndex);
106
97
  try {
107
98
  // Fetch both parameters and data in parallel
108
- const [params, data] = yield Promise.all([
99
+ const [params, data] = await Promise.all([
109
100
  (0, exports.fetchBorrowingFeeParamsV2)(contract, collateralIndices, pairIndices),
110
101
  (0, exports.fetchPairBorrowingFeeDataV2)(contract, collateralIndices, pairIndices),
111
102
  ]);
@@ -117,7 +108,7 @@ const fetchAllBorrowingV2Data = (contract, collateralIndex, pairIndices) => __aw
117
108
  console.error("Error fetching all borrowing v2 data:", error);
118
109
  throw error;
119
110
  }
120
- });
111
+ };
121
112
  exports.fetchAllBorrowingV2Data = fetchAllBorrowingV2Data;
122
113
  /**
123
114
  * @dev Creates a complete borrowing v2 context from contract data
@@ -127,10 +118,13 @@ exports.fetchAllBorrowingV2Data = fetchAllBorrowingV2Data;
127
118
  * @param currentTimestamp Optional current timestamp for calculations
128
119
  * @returns Promise resolving to complete borrowing v2 context
129
120
  */
130
- const createBorrowingV2ContextFromContract = (contract, collateralIndex, pairIndices, currentTimestamp) => __awaiter(void 0, void 0, void 0, function* () {
131
- const { context } = yield (0, exports.fetchAllBorrowingV2Data)(contract, collateralIndex, pairIndices);
132
- return Object.assign(Object.assign({}, context), { currentTimestamp: currentTimestamp !== null && currentTimestamp !== void 0 ? currentTimestamp : Math.floor(Date.now() / 1000) });
133
- });
121
+ const createBorrowingV2ContextFromContract = async (contract, collateralIndex, pairIndices, currentTimestamp) => {
122
+ const { context } = await (0, exports.fetchAllBorrowingV2Data)(contract, collateralIndex, pairIndices);
123
+ return {
124
+ ...context,
125
+ currentTimestamp: currentTimestamp ?? Math.floor(Date.now() / 1000),
126
+ };
127
+ };
134
128
  exports.createBorrowingV2ContextFromContract = createBorrowingV2ContextFromContract;
135
129
  /**
136
130
  * @dev Helper function to create context from already fetched arrays
@@ -143,7 +137,7 @@ exports.createBorrowingV2ContextFromContract = createBorrowingV2ContextFromContr
143
137
  */
144
138
  const createBorrowingV2ContextFromArrays = (collateralIndices, pairIndices, params, data, currentTimestamp) => {
145
139
  const context = {
146
- currentTimestamp: currentTimestamp !== null && currentTimestamp !== void 0 ? currentTimestamp : Math.floor(Date.now() / 1000),
140
+ currentTimestamp: currentTimestamp ?? Math.floor(Date.now() / 1000),
147
141
  borrowingParams: {},
148
142
  borrowingData: {},
149
143
  };
@@ -164,13 +158,13 @@ exports.createBorrowingV2ContextFromArrays = createBorrowingV2ContextFromArrays;
164
158
  * @param pairIndices Array of pair indices (must match collateralIndices length)
165
159
  * @returns Promise resolving to complete borrowing v2 context
166
160
  */
167
- const fetchBorrowingV2DataForPairs = (contract, collateralIndices, pairIndices) => __awaiter(void 0, void 0, void 0, function* () {
161
+ const fetchBorrowingV2DataForPairs = async (contract, collateralIndices, pairIndices) => {
168
162
  if (collateralIndices.length !== pairIndices.length) {
169
163
  throw new Error("Collateral indices and pair indices arrays must have the same length");
170
164
  }
171
165
  try {
172
166
  // Fetch both parameters and data in parallel
173
- const [params, data] = yield Promise.all([
167
+ const [params, data] = await Promise.all([
174
168
  (0, exports.fetchBorrowingFeeParamsV2)(contract, collateralIndices, pairIndices),
175
169
  (0, exports.fetchPairBorrowingFeeDataV2)(contract, collateralIndices, pairIndices),
176
170
  ]);
@@ -181,5 +175,5 @@ const fetchBorrowingV2DataForPairs = (contract, collateralIndices, pairIndices)
181
175
  console.error("Error fetching borrowing v2 data for pairs:", error);
182
176
  throw error;
183
177
  }
184
- });
178
+ };
185
179
  exports.fetchBorrowingV2DataForPairs = fetchBorrowingV2DataForPairs;
@@ -48,7 +48,7 @@ exports.BORROWING_V2_PRECISION = {
48
48
  * @returns Updated accumulated borrowing fee (1e20 precision)
49
49
  */
50
50
  const getPairPendingAccBorrowingFees = (params, data, currentPairPrice, currentTimestamp) => {
51
- const timestamp = currentTimestamp !== null && currentTimestamp !== void 0 ? currentTimestamp : Math.floor(Date.now() / 1000);
51
+ const timestamp = currentTimestamp ?? Math.floor(Date.now() / 1000);
52
52
  // Calculate time elapsed since last update
53
53
  const timeElapsed = Math.max(0, timestamp - data.lastBorrowingUpdateTs);
54
54
  // If no time elapsed, return current accumulated fee
@@ -74,7 +74,7 @@ const getTradeBorrowingFeesCollateral = (input, context) => {
74
74
  return 0;
75
75
  }
76
76
  // Calculate current accumulated borrowing fees
77
- const currentAccBorrowingFeeP = (0, exports.getPairPendingAccBorrowingFees)(params, data, currentPairPrice, currentTimestamp !== null && currentTimestamp !== void 0 ? currentTimestamp : context.currentTimestamp);
77
+ const currentAccBorrowingFeeP = (0, exports.getPairPendingAccBorrowingFees)(params, data, currentPairPrice, currentTimestamp ?? context.currentTimestamp);
78
78
  // Calculate borrowing fees for this trade
79
79
  // Formula: (positionSizeCollateral * (currentAccFee - initialAccFee)) / openPrice / 100
80
80
  const feeDeltaP = currentAccBorrowingFeeP - initialAccBorrowingFeeP;
@@ -96,7 +96,7 @@ const getPairBorrowingFees = (input, context) => {
96
96
  if (!params || !data) {
97
97
  return 0;
98
98
  }
99
- return (0, exports.getPairPendingAccBorrowingFees)(params, data, currentPairPrice, currentTimestamp !== null && currentTimestamp !== void 0 ? currentTimestamp : context.currentTimestamp);
99
+ return (0, exports.getPairPendingAccBorrowingFees)(params, data, currentPairPrice, currentTimestamp ?? context.currentTimestamp);
100
100
  };
101
101
  exports.getPairBorrowingFees = getPairBorrowingFees;
102
102
  /**
@@ -16,14 +16,14 @@ const convertTradeFeesData = (data, collateralConfig) => {
16
16
  const decimals = collateralConfig.decimals || 18;
17
17
  return {
18
18
  realizedTradingFeesCollateral: parseFloat(data.realizedTradingFeesCollateral.toString()) /
19
- Math.pow(10, decimals),
20
- realizedPnlCollateral: parseFloat(data.realizedPnlCollateral.toString()) / Math.pow(10, decimals),
19
+ 10 ** decimals,
20
+ realizedPnlCollateral: parseFloat(data.realizedPnlCollateral.toString()) / 10 ** decimals,
21
21
  manuallyRealizedNegativePnlCollateral: parseFloat(data.manuallyRealizedNegativePnlCollateral.toString()) /
22
- Math.pow(10, decimals),
22
+ 10 ** decimals,
23
23
  alreadyTransferredNegativePnlCollateral: parseFloat(data.alreadyTransferredNegativePnlCollateral.toString()) /
24
- Math.pow(10, decimals),
24
+ 10 ** decimals,
25
25
  virtualAvailableCollateralInDiamond: parseFloat(data.virtualAvailableCollateralInDiamond.toString()) /
26
- Math.pow(10, decimals),
26
+ 10 ** decimals,
27
27
  initialAccFundingFeeP: parseFloat(data.initialAccFundingFeeP.toString()) /
28
28
  converter_1.FUNDING_FEES_PRECISION.ACC_FUNDING_FEE_P,
29
29
  initialAccBorrowingFeeP: parseFloat(data.initialAccBorrowingFeeP.toString()) /
@@ -51,16 +51,16 @@ const convertUiRealizedPnlData = (data, collateralConfig) => {
51
51
  const decimals = collateralConfig.decimals || 18;
52
52
  return {
53
53
  realizedTradingFeesCollateral: parseFloat(data.realizedTradingFeesCollateral.toString()) /
54
- Math.pow(10, decimals),
54
+ 10 ** decimals,
55
55
  realizedOldBorrowingFeesCollateral: parseFloat(data.realizedOldBorrowingFeesCollateral.toString()) /
56
- Math.pow(10, decimals),
56
+ 10 ** decimals,
57
57
  realizedNewBorrowingFeesCollateral: parseFloat(data.realizedNewBorrowingFeesCollateral.toString()) /
58
- Math.pow(10, decimals),
58
+ 10 ** decimals,
59
59
  realizedFundingFeesCollateral: parseFloat(data.realizedFundingFeesCollateral.toString()) /
60
- Math.pow(10, decimals),
60
+ 10 ** decimals,
61
61
  realizedPnlPartialCloseCollateral: parseFloat(data.realizedPnlPartialCloseCollateral.toString()) /
62
- Math.pow(10, decimals),
63
- pnlWithdrawnCollateral: parseFloat(data.pnlWithdrawnCollateral.toString()) / Math.pow(10, decimals),
62
+ 10 ** decimals,
63
+ pnlWithdrawnCollateral: parseFloat(data.pnlWithdrawnCollateral.toString()) / 10 ** decimals,
64
64
  };
65
65
  };
66
66
  exports.convertUiRealizedPnlData = convertUiRealizedPnlData;
@@ -83,11 +83,11 @@ exports.convertUiRealizedPnlDataArray = convertUiRealizedPnlDataArray;
83
83
  const encodeTradeFeesData = (data, collateralConfig) => {
84
84
  const decimals = collateralConfig.decimals || 18;
85
85
  return {
86
- realizedTradingFeesCollateral: Math.round(data.realizedTradingFeesCollateral * Math.pow(10, decimals)),
87
- realizedPnlCollateral: Math.round(data.realizedPnlCollateral * Math.pow(10, decimals)),
88
- manuallyRealizedNegativePnlCollateral: Math.round(data.manuallyRealizedNegativePnlCollateral * Math.pow(10, decimals)),
89
- alreadyTransferredNegativePnlCollateral: Math.round(data.alreadyTransferredNegativePnlCollateral * Math.pow(10, decimals)),
90
- virtualAvailableCollateralInDiamond: Math.round(data.virtualAvailableCollateralInDiamond * Math.pow(10, decimals)),
86
+ realizedTradingFeesCollateral: Math.round(data.realizedTradingFeesCollateral * 10 ** decimals),
87
+ realizedPnlCollateral: Math.round(data.realizedPnlCollateral * 10 ** decimals),
88
+ manuallyRealizedNegativePnlCollateral: Math.round(data.manuallyRealizedNegativePnlCollateral * 10 ** decimals),
89
+ alreadyTransferredNegativePnlCollateral: Math.round(data.alreadyTransferredNegativePnlCollateral * 10 ** decimals),
90
+ virtualAvailableCollateralInDiamond: Math.round(data.virtualAvailableCollateralInDiamond * 10 ** decimals),
91
91
  __placeholder: 0,
92
92
  initialAccFundingFeeP: Math.round(data.initialAccFundingFeeP * converter_1.FUNDING_FEES_PRECISION.ACC_FUNDING_FEE_P),
93
93
  initialAccBorrowingFeeP: Math.round(data.initialAccBorrowingFeeP * borrowingV2_1.BORROWING_V2_PRECISION.ACC_FEE),
@@ -103,12 +103,12 @@ exports.encodeTradeFeesData = encodeTradeFeesData;
103
103
  const encodeUiRealizedPnlData = (data, collateralConfig) => {
104
104
  const decimals = collateralConfig.decimals || 18;
105
105
  return {
106
- realizedTradingFeesCollateral: Math.round(data.realizedTradingFeesCollateral * Math.pow(10, decimals)),
107
- realizedOldBorrowingFeesCollateral: Math.round(data.realizedOldBorrowingFeesCollateral * Math.pow(10, decimals)),
108
- realizedNewBorrowingFeesCollateral: Math.round(data.realizedNewBorrowingFeesCollateral * Math.pow(10, decimals)),
109
- realizedFundingFeesCollateral: Math.round(data.realizedFundingFeesCollateral * Math.pow(10, decimals)),
110
- realizedPnlPartialCloseCollateral: Math.round(data.realizedPnlPartialCloseCollateral * Math.pow(10, decimals)),
111
- pnlWithdrawnCollateral: Math.round(data.pnlWithdrawnCollateral * Math.pow(10, decimals)),
106
+ realizedTradingFeesCollateral: Math.round(data.realizedTradingFeesCollateral * 10 ** decimals),
107
+ realizedOldBorrowingFeesCollateral: Math.round(data.realizedOldBorrowingFeesCollateral * 10 ** decimals),
108
+ realizedNewBorrowingFeesCollateral: Math.round(data.realizedNewBorrowingFeesCollateral * 10 ** decimals),
109
+ realizedFundingFeesCollateral: Math.round(data.realizedFundingFeesCollateral * 10 ** decimals),
110
+ realizedPnlPartialCloseCollateral: Math.round(data.realizedPnlPartialCloseCollateral * 10 ** decimals),
111
+ pnlWithdrawnCollateral: Math.round(data.pnlWithdrawnCollateral * 10 ** decimals),
112
112
  };
113
113
  };
114
114
  exports.encodeUiRealizedPnlData = encodeUiRealizedPnlData;
@@ -9,14 +9,13 @@ const index_1 = require("../../../markets/oi/index");
9
9
  * @dev Builds funding fees sub-context for a specific pair
10
10
  */
11
11
  const buildFundingContext = (globalTradingVariables, collateralIndex, pairIndex, currentTimestamp) => {
12
- var _a, _b, _c, _d, _e;
13
12
  const collateral = globalTradingVariables.collaterals[collateralIndex - 1];
14
- if (!(collateral === null || collateral === void 0 ? void 0 : collateral.pairFundingFees)) {
13
+ if (!collateral?.pairFundingFees) {
15
14
  return undefined;
16
15
  }
17
- const params = (_a = collateral.pairFundingFees.params) === null || _a === void 0 ? void 0 : _a[pairIndex];
18
- const data = (_b = collateral.pairFundingFees.data) === null || _b === void 0 ? void 0 : _b[pairIndex];
19
- const pairOi = (_c = collateral.pairOis) === null || _c === void 0 ? void 0 : _c[pairIndex];
16
+ const params = collateral.pairFundingFees.params?.[pairIndex];
17
+ const data = collateral.pairFundingFees.data?.[pairIndex];
18
+ const pairOi = collateral.pairOis?.[pairIndex];
20
19
  const netExposureToken = (0, index_1.getPairV10OiTokenSkewCollateral)(pairIndex, {
21
20
  pairOis: collateral.pairOis,
22
21
  });
@@ -28,8 +27,8 @@ const buildFundingContext = (globalTradingVariables, collateralIndex, pairIndex,
28
27
  data,
29
28
  pairOi: pairOi
30
29
  ? {
31
- oiLongToken: ((_d = pairOi.token) === null || _d === void 0 ? void 0 : _d.long) || 0,
32
- oiShortToken: ((_e = pairOi.token) === null || _e === void 0 ? void 0 : _e.short) || 0,
30
+ oiLongToken: pairOi.token?.long || 0,
31
+ oiShortToken: pairOi.token?.short || 0,
33
32
  }
34
33
  : undefined,
35
34
  currentTimestamp,
@@ -111,7 +111,7 @@ exports.convertTradeInitialAccFundingFees = convertTradeInitialAccFundingFees;
111
111
  */
112
112
  const createFundingFeeContext = (collateralIndices, pairIndices, params, data, globalParams, currentTimestamp) => {
113
113
  const context = {
114
- currentTimestamp: currentTimestamp !== null && currentTimestamp !== void 0 ? currentTimestamp : Math.floor(Date.now() / 1000),
114
+ currentTimestamp: currentTimestamp ?? Math.floor(Date.now() / 1000),
115
115
  fundingParams: {},
116
116
  fundingData: {},
117
117
  globalParams: globalParams ? {} : undefined,
@@ -1,13 +1,4 @@
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
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.collateralToContractFormat = exports.priceToContractFormat = exports.fetchPairPendingAccFundingFeesBatch = exports.fetchTradeFeesDataBatch = exports.fetchTradeFeesData = exports.fetchTradeFundingFeesCollateral = exports.fetchPairPendingAccFundingFees = void 0;
13
4
  /**
@@ -18,9 +9,9 @@ exports.collateralToContractFormat = exports.priceToContractFormat = exports.fet
18
9
  * @param currentPairPrice Current pair price (1e10)
19
10
  * @returns Promise resolving to accumulated funding fees and current rate
20
11
  */
21
- const fetchPairPendingAccFundingFees = (contract, collateralIndex, pairIndex, currentPairPrice) => __awaiter(void 0, void 0, void 0, function* () {
12
+ const fetchPairPendingAccFundingFees = async (contract, collateralIndex, pairIndex, currentPairPrice) => {
22
13
  try {
23
- const result = yield contract.getPairPendingAccFundingFees(collateralIndex, pairIndex, currentPairPrice);
14
+ const result = await contract.getPairPendingAccFundingFees(collateralIndex, pairIndex, currentPairPrice);
24
15
  return {
25
16
  accFundingFeeLongP: Number(result.accFundingFeeLongP) / 1e20,
26
17
  accFundingFeeShortP: Number(result.accFundingFeeShortP) / 1e20,
@@ -31,7 +22,7 @@ const fetchPairPendingAccFundingFees = (contract, collateralIndex, pairIndex, cu
31
22
  console.error("Error fetching pair pending acc funding fees:", error);
32
23
  throw error;
33
24
  }
34
- });
25
+ };
35
26
  exports.fetchPairPendingAccFundingFees = fetchPairPendingAccFundingFees;
36
27
  /**
37
28
  * @dev Fetches funding fees for a specific trade in collateral tokens
@@ -41,9 +32,9 @@ exports.fetchPairPendingAccFundingFees = fetchPairPendingAccFundingFees;
41
32
  * @param currentPairPrice Current pair price (1e10)
42
33
  * @returns Promise resolving to funding fee in collateral tokens
43
34
  */
44
- const fetchTradeFundingFeesCollateral = (contract, trader, index, currentPairPrice) => __awaiter(void 0, void 0, void 0, function* () {
35
+ const fetchTradeFundingFeesCollateral = async (contract, trader, index, currentPairPrice) => {
45
36
  try {
46
- const fundingFeeCollateral = yield contract.getTradeFundingFeesCollateral(trader, index, currentPairPrice);
37
+ const fundingFeeCollateral = await contract.getTradeFundingFeesCollateral(trader, index, currentPairPrice);
47
38
  // Convert from BigNumber to number (collateral precision already applied)
48
39
  return Number(fundingFeeCollateral);
49
40
  }
@@ -51,7 +42,7 @@ const fetchTradeFundingFeesCollateral = (contract, trader, index, currentPairPri
51
42
  console.error("Error fetching trade funding fees:", error);
52
43
  throw error;
53
44
  }
54
- });
45
+ };
55
46
  exports.fetchTradeFundingFeesCollateral = fetchTradeFundingFeesCollateral;
56
47
  /**
57
48
  * @dev Fetches trade fees data for a specific trade
@@ -60,9 +51,9 @@ exports.fetchTradeFundingFeesCollateral = fetchTradeFundingFeesCollateral;
60
51
  * @param index Trade index
61
52
  * @returns Promise resolving to trade fees data
62
53
  */
63
- const fetchTradeFeesData = (contract, trader, index) => __awaiter(void 0, void 0, void 0, function* () {
54
+ const fetchTradeFeesData = async (contract, trader, index) => {
64
55
  try {
65
- const feesData = yield contract.getTradeFeesData(trader, index);
56
+ const feesData = await contract.getTradeFeesData(trader, index);
66
57
  return {
67
58
  accPerOiLong: Number(feesData.initialAccFundingFeeP) / 1e20,
68
59
  accPerOiShort: Number(feesData.initialAccFundingFeeP) / 1e20,
@@ -73,7 +64,7 @@ const fetchTradeFeesData = (contract, trader, index) => __awaiter(void 0, void 0
73
64
  console.error("Error fetching trade fees data:", error);
74
65
  throw error;
75
66
  }
76
- });
67
+ };
77
68
  exports.fetchTradeFeesData = fetchTradeFeesData;
78
69
  /**
79
70
  * @dev Fetches trade fees data for multiple trades
@@ -82,12 +73,12 @@ exports.fetchTradeFeesData = fetchTradeFeesData;
82
73
  * @param indices Array of trade indices
83
74
  * @returns Promise resolving to array of trade fees data
84
75
  */
85
- const fetchTradeFeesDataBatch = (contract, traders, indices) => __awaiter(void 0, void 0, void 0, function* () {
76
+ const fetchTradeFeesDataBatch = async (contract, traders, indices) => {
86
77
  if (traders.length !== indices.length) {
87
78
  throw new Error("Traders and indices arrays must have the same length");
88
79
  }
89
80
  try {
90
- const feesDatas = yield contract.getTradeFeesDataArray(traders, indices);
81
+ const feesDatas = await contract.getTradeFeesDataArray(traders, indices);
91
82
  return feesDatas.map(feesData => ({
92
83
  accPerOiLong: Number(feesData.initialAccFundingFeeP) / 1e20,
93
84
  accPerOiShort: Number(feesData.initialAccFundingFeeP) / 1e20,
@@ -98,7 +89,7 @@ const fetchTradeFeesDataBatch = (contract, traders, indices) => __awaiter(void 0
98
89
  console.error("Error fetching trade fees data batch:", error);
99
90
  throw error;
100
91
  }
101
- });
92
+ };
102
93
  exports.fetchTradeFeesDataBatch = fetchTradeFeesDataBatch;
103
94
  /**
104
95
  * @dev Fetches pending accumulated funding fees for multiple pairs
@@ -108,7 +99,7 @@ exports.fetchTradeFeesDataBatch = fetchTradeFeesDataBatch;
108
99
  * @param currentPairPrices Array of current pair prices (1e10)
109
100
  * @returns Promise resolving to array of accumulated funding fees
110
101
  */
111
- const fetchPairPendingAccFundingFeesBatch = (contract, collateralIndices, pairIndices, currentPairPrices) => __awaiter(void 0, void 0, void 0, function* () {
102
+ const fetchPairPendingAccFundingFeesBatch = async (contract, collateralIndices, pairIndices, currentPairPrices) => {
112
103
  if (collateralIndices.length !== pairIndices.length ||
113
104
  pairIndices.length !== currentPairPrices.length) {
114
105
  throw new Error("All input arrays must have the same length");
@@ -116,7 +107,7 @@ const fetchPairPendingAccFundingFeesBatch = (contract, collateralIndices, pairIn
116
107
  try {
117
108
  // Fetch all in parallel
118
109
  const promises = collateralIndices.map((collateralIndex, i) => contract.getPairPendingAccFundingFees(collateralIndex, pairIndices[i], currentPairPrices[i]));
119
- const results = yield Promise.all(promises);
110
+ const results = await Promise.all(promises);
120
111
  return results.map(result => ({
121
112
  accFundingFeeLongP: Number(result.accFundingFeeLongP) / 1e20,
122
113
  accFundingFeeShortP: Number(result.accFundingFeeShortP) / 1e20,
@@ -127,7 +118,7 @@ const fetchPairPendingAccFundingFeesBatch = (contract, collateralIndices, pairIn
127
118
  console.error("Error fetching pair pending acc funding fees batch:", error);
128
119
  throw error;
129
120
  }
130
- });
121
+ };
131
122
  exports.fetchPairPendingAccFundingFeesBatch = fetchPairPendingAccFundingFeesBatch;
132
123
  /**
133
124
  * @dev Helper to convert price from number to contract format
@@ -145,6 +136,6 @@ exports.priceToContractFormat = priceToContractFormat;
145
136
  * @returns Amount in contract format
146
137
  */
147
138
  const collateralToContractFormat = (amount, decimals) => {
148
- return BigInt(Math.round(amount * Math.pow(10, decimals)));
139
+ return BigInt(Math.round(amount * 10 ** decimals));
149
140
  };
150
141
  exports.collateralToContractFormat = collateralToContractFormat;
@@ -259,10 +259,9 @@ exports.getTradeFundingFeesCollateral = getTradeFundingFeesCollateral;
259
259
  * @returns Complete funding fee calculation result
260
260
  */
261
261
  const getTradeFundingFees = (input, context) => {
262
- var _a, _b;
263
262
  // Get params and data from context
264
- const params = (_a = context.fundingParams[input.collateralIndex]) === null || _a === void 0 ? void 0 : _a[input.pairIndex];
265
- const data = (_b = context.fundingData[input.collateralIndex]) === null || _b === void 0 ? void 0 : _b[input.pairIndex];
263
+ const params = context.fundingParams[input.collateralIndex]?.[input.pairIndex];
264
+ const data = context.fundingData[input.collateralIndex]?.[input.pairIndex];
266
265
  if (!params || !data) {
267
266
  throw new Error(`Missing funding fee data for collateral ${input.collateralIndex} pair ${input.pairIndex}`);
268
267
  }