@gainsnetwork/sdk 1.0.0-rc9 → 1.0.1-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 (50) hide show
  1. package/lib/constants.d.ts +5 -0
  2. package/lib/constants.js +5 -0
  3. package/lib/contracts/types/generated/GNSBorrowingFeesV6_3_2.d.ts +979 -0
  4. package/lib/contracts/types/generated/GNSBorrowingFeesV6_3_2.js +2 -0
  5. package/lib/contracts/types/generated/GNSBorrowingFeesV6_4.d.ts +1058 -0
  6. package/lib/contracts/types/generated/GNSBorrowingFeesV6_4.js +2 -0
  7. package/lib/contracts/types/generated/GNSMultiCollatDiamond.d.ts +7 -20
  8. package/lib/contracts/types/generated/GNSPairInfosV6_1.d.ts +911 -0
  9. package/lib/contracts/types/generated/GNSPairInfosV6_1.js +2 -0
  10. package/lib/contracts/types/generated/GNSPairsStorageV6.d.ts +660 -0
  11. package/lib/contracts/types/generated/GNSPairsStorageV6.js +2 -0
  12. package/lib/contracts/types/generated/GNSTradingCallbacksV6_3_2.d.ts +806 -0
  13. package/lib/contracts/types/generated/GNSTradingCallbacksV6_3_2.js +2 -0
  14. package/lib/contracts/types/generated/GNSTradingCallbacksV6_4.d.ts +821 -0
  15. package/lib/contracts/types/generated/GNSTradingCallbacksV6_4.js +2 -0
  16. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_3_2__factory.d.ts +88 -0
  17. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_3_2__factory.js +1654 -0
  18. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_4__factory.d.ts +113 -0
  19. package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_4__factory.js +1742 -0
  20. package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +7 -16
  21. package/lib/contracts/types/generated/factories/GNSPairInfosV6_1__factory.d.ts +98 -0
  22. package/lib/contracts/types/generated/factories/GNSPairInfosV6_1__factory.js +1485 -0
  23. package/lib/contracts/types/generated/factories/GNSPairsStorageV6__factory.d.ts +117 -0
  24. package/lib/contracts/types/generated/factories/GNSPairsStorageV6__factory.js +1265 -0
  25. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_3_2__factory.d.ts +82 -0
  26. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_3_2__factory.js +1273 -0
  27. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_4__factory.d.ts +82 -0
  28. package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_4__factory.js +1326 -0
  29. package/lib/contracts/types/generated/factories/GToken__factory.d.ts +7 -0
  30. package/lib/contracts/types/generated/factories/GToken__factory.js +4 -0
  31. package/lib/contracts/utils/pairs.js +5 -0
  32. package/lib/markets/holdingFees/index.js +1 -2
  33. package/lib/markets/oi/fetcher.d.ts +58 -0
  34. package/lib/markets/oi/fetcher.js +181 -0
  35. package/lib/markets/oi/validation.d.ts +80 -0
  36. package/lib/markets/oi/validation.js +172 -0
  37. package/lib/trade/fees/fundingFees/builder.js +5 -1
  38. package/lib/trade/fees/fundingFees/converter.js +1 -1
  39. package/lib/trade/fees/fundingFees/index.js +33 -0
  40. package/lib/trade/fees/holdingFees/index.d.ts +46 -0
  41. package/lib/trade/fees/holdingFees/index.js +105 -0
  42. package/lib/trade/fees/holdingFees/types.d.ts +23 -0
  43. package/lib/trade/fees/holdingFees/types.js +5 -0
  44. package/lib/trade/fees/trading/holdingFees.d.ts +28 -0
  45. package/lib/trade/fees/trading/holdingFees.js +66 -0
  46. package/lib/trade/fees/trading/holdingFeesStructured.d.ts +28 -0
  47. package/lib/trade/fees/trading/holdingFeesStructured.js +66 -0
  48. package/lib/trade/types.d.ts +6 -1
  49. package/lib/trade/types.js +5 -0
  50. package/package.json +1 -1
@@ -4,6 +4,7 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.buildFundingContext = void 0;
7
+ const index_1 = require("../../../markets/oi/index");
7
8
  /**
8
9
  * @dev Builds funding fees sub-context for a specific pair
9
10
  */
@@ -16,6 +17,9 @@ const buildFundingContext = (globalTradingVariables, collateralIndex, pairIndex,
16
17
  const params = (_a = collateral.pairFundingFees.params) === null || _a === void 0 ? void 0 : _a[pairIndex];
17
18
  const data = (_b = collateral.pairFundingFees.data) === null || _b === void 0 ? void 0 : _b[pairIndex];
18
19
  const pairOi = (_c = collateral.pairOis) === null || _c === void 0 ? void 0 : _c[pairIndex];
20
+ const netExposureToken = (0, index_1.getPairV10OiTokenSkewCollateral)(pairIndex, {
21
+ pairOis: collateral.pairOis,
22
+ });
19
23
  if (!params || !data) {
20
24
  return undefined;
21
25
  }
@@ -29,7 +33,7 @@ const buildFundingContext = (globalTradingVariables, collateralIndex, pairIndex,
29
33
  }
30
34
  : undefined,
31
35
  currentTimestamp,
32
- // TODO: Add net exposure when available
36
+ netExposureToken,
33
37
  };
34
38
  };
35
39
  exports.buildFundingContext = buildFundingContext;
@@ -74,7 +74,7 @@ exports.convertPairFundingFeeDataArray = convertPairFundingFeeDataArray;
74
74
  */
75
75
  const convertPairGlobalParams = (contractParams) => {
76
76
  return {
77
- maxSkewCollateral: Number(contractParams.maxSkewCollateral),
77
+ maxSkewCollateral: Number(contractParams.maxSkewCollateral) / 1e10,
78
78
  };
79
79
  };
80
80
  exports.convertPairGlobalParams = convertPairGlobalParams;
@@ -49,17 +49,25 @@ const getCurrentFundingVelocityPerYear = (netExposureToken, netExposureUsd, skew
49
49
  if (netExposureToken === 0 ||
50
50
  skewCoefficientPerYear === 0 ||
51
51
  absoluteVelocityPerYearCap === 0) {
52
+ console.log("netExposureToken", netExposureToken);
53
+ console.log("skewCoefficientPerYear", skewCoefficientPerYear);
54
+ console.log("absoluteVelocityPerYearCap", absoluteVelocityPerYearCap);
52
55
  return 0;
53
56
  }
54
57
  // Check theta threshold
55
58
  const absNetExposureUsd = Math.abs(netExposureUsd);
56
59
  if (absNetExposureUsd < thetaThresholdUsd) {
60
+ console.log("absNetExposureUsd", absNetExposureUsd);
61
+ console.log("thetaThresholdUsd", thetaThresholdUsd);
57
62
  return 0;
58
63
  }
59
64
  // Calculate absolute velocity
60
65
  const absoluteVelocityPerYear = Math.abs(netExposureToken) * skewCoefficientPerYear;
61
66
  // Apply cap
62
67
  const cappedAbsoluteVelocity = Math.min(absoluteVelocityPerYear, absoluteVelocityPerYearCap);
68
+ console.log("absoluteVelocityPerYear", absoluteVelocityPerYear);
69
+ console.log("absoluteVelocityPerYearCap", absoluteVelocityPerYearCap);
70
+ console.log("cappedAbsoluteVelocity", cappedAbsoluteVelocity);
63
71
  // Return with proper sign
64
72
  return netExposureToken < 0
65
73
  ? -cappedAbsoluteVelocity
@@ -104,6 +112,8 @@ const getAvgFundingRatePerSecondP = (lastFundingRatePerSecondP, absoluteRatePerS
104
112
  };
105
113
  }
106
114
  const ratePerSecondCap = absoluteRatePerSecondCap * (currentVelocityPerYear < 0 ? -1 : 1);
115
+ console.log("ratePerSecondCap", ratePerSecondCap);
116
+ console.log("lastFundingRatePerSecondP", lastFundingRatePerSecondP);
107
117
  // If rate is already at cap, just return it
108
118
  if (ratePerSecondCap === lastFundingRatePerSecondP) {
109
119
  return {
@@ -113,6 +123,7 @@ const getAvgFundingRatePerSecondP = (lastFundingRatePerSecondP, absoluteRatePerS
113
123
  }
114
124
  const secondsToReachCap = ((ratePerSecondCap - lastFundingRatePerSecondP) * ONE_YEAR) /
115
125
  currentVelocityPerYear;
126
+ console.log("secondsToReachCap", secondsToReachCap);
116
127
  if (secondsSinceLastUpdate > secondsToReachCap) {
117
128
  // Rate reached cap during this period
118
129
  const currentFundingRatePerSecondP = ratePerSecondCap;
@@ -121,6 +132,8 @@ const getAvgFundingRatePerSecondP = (lastFundingRatePerSecondP, absoluteRatePerS
121
132
  const avgFundingRatePerSecondP = (avgFundingRatePerSecondP_1 * secondsToReachCap +
122
133
  ratePerSecondCap * (secondsSinceLastUpdate - secondsToReachCap)) /
123
134
  secondsSinceLastUpdate;
135
+ console.log("Reached cap");
136
+ console.log("avgFundingRatePerSecondP", avgFundingRatePerSecondP);
124
137
  return { avgFundingRatePerSecondP, currentFundingRatePerSecondP };
125
138
  }
126
139
  else {
@@ -128,6 +141,9 @@ const getAvgFundingRatePerSecondP = (lastFundingRatePerSecondP, absoluteRatePerS
128
141
  const currentFundingRatePerSecondP = lastFundingRatePerSecondP +
129
142
  (secondsSinceLastUpdate * currentVelocityPerYear) / ONE_YEAR;
130
143
  const avgFundingRatePerSecondP = (lastFundingRatePerSecondP + currentFundingRatePerSecondP) / 2;
144
+ console.log("Not reached cap");
145
+ console.log("avgFundingRatePerSecondP", avgFundingRatePerSecondP);
146
+ console.log("currentFundingRatePerSecondP", currentFundingRatePerSecondP);
131
147
  return { avgFundingRatePerSecondP, currentFundingRatePerSecondP };
132
148
  }
133
149
  };
@@ -185,10 +201,14 @@ const getPairPendingAccFundingFees = (params, data, currentPairPrice, pairOiToke
185
201
  };
186
202
  }
187
203
  const secondsSinceLastUpdate = currentTimestamp - data.lastFundingUpdateTs;
204
+ console.log("secondsSinceLastUpdate", secondsSinceLastUpdate);
188
205
  // Calculate current velocity
189
206
  const currentVelocityPerYear = (0, exports.getCurrentFundingVelocityPerYear)(netExposureToken, netExposureUsd, params.skewCoefficientPerYear, params.absoluteVelocityPerYearCap, params.thetaThresholdUsd);
190
207
  // Get average and current funding rates
191
208
  const { avgFundingRatePerSecondP, currentFundingRatePerSecondP } = (0, exports.getAvgFundingRatePerSecondP)(data.lastFundingRatePerSecondP, params.absoluteRatePerSecondCap, currentVelocityPerYear, secondsSinceLastUpdate);
209
+ console.log("currentVelocityPerYear", currentVelocityPerYear);
210
+ console.log("avgFundingRatePerSecondP", avgFundingRatePerSecondP);
211
+ console.log("currentFundingRatePerSecondP", currentFundingRatePerSecondP);
192
212
  // Check if we need to handle rate sign change
193
213
  const rateChangedSign = params.aprMultiplierEnabled &&
194
214
  ((currentFundingRatePerSecondP > 0 && data.lastFundingRatePerSecondP < 0) ||
@@ -210,6 +230,9 @@ const getPairPendingAccFundingFees = (params, data, currentPairPrice, pairOiToke
210
230
  const { longAprMultiplier: longMultiplier2, shortAprMultiplier: shortMultiplier2, } = (0, exports.getLongShortAprMultiplier)(avgFundingRatePerSecondP_2, pairOiToken.oiLongToken, pairOiToken.oiShortToken, true);
211
231
  accFundingFeeLongP += fundingFeesDeltaP_2 * longMultiplier2;
212
232
  accFundingFeeShortP -= fundingFeesDeltaP_2 * shortMultiplier2;
233
+ console.log("Rate changed sign");
234
+ console.log("accFundingFeeLongP", accFundingFeeLongP);
235
+ console.log("accFundingFeeShortP", accFundingFeeShortP);
213
236
  }
214
237
  else {
215
238
  // Single period calculation
@@ -217,6 +240,9 @@ const getPairPendingAccFundingFees = (params, data, currentPairPrice, pairOiToke
217
240
  const { longAprMultiplier, shortAprMultiplier } = (0, exports.getLongShortAprMultiplier)(avgFundingRatePerSecondP, pairOiToken.oiLongToken, pairOiToken.oiShortToken, params.aprMultiplierEnabled);
218
241
  accFundingFeeLongP += fundingFeesDeltaP * longAprMultiplier;
219
242
  accFundingFeeShortP -= fundingFeesDeltaP * shortAprMultiplier;
243
+ console.log("Single period calculation");
244
+ console.log("accFundingFeeLongP", accFundingFeeLongP);
245
+ console.log("accFundingFeeShortP", accFundingFeeShortP);
220
246
  }
221
247
  return {
222
248
  accFundingFeeLongP,
@@ -238,6 +264,7 @@ const getTradeFundingFeesCollateral = (trade, tradeInfo, tradeFeesData, currentP
238
264
  if (tradeInfo.contractsVersion < types_1.ContractsVersion.V10) {
239
265
  return 0;
240
266
  }
267
+ context.netExposureUsd = (context.netExposureToken || 0) * currentPairPrice;
241
268
  const positionSizeCollateral = trade.collateralAmount * trade.leverage;
242
269
  if (!context.params.fundingFeesEnabled) {
243
270
  return 0;
@@ -248,6 +275,12 @@ const getTradeFundingFeesCollateral = (trade, tradeInfo, tradeFeesData, currentP
248
275
  ? accFundingFeeLongP
249
276
  : accFundingFeeShortP;
250
277
  const fundingFeeDelta = currentAccFundingFeeP - tradeFeesData.initialAccFundingFeeP;
278
+ console.log("currentAccFundingFeeP", currentAccFundingFeeP);
279
+ console.log("tradeFeesData.initialAccFundingFeeP", tradeFeesData.initialAccFundingFeeP);
280
+ console.log("fundingFeeDelta", fundingFeeDelta);
281
+ console.log("positionSizeCollateral", positionSizeCollateral);
282
+ console.log("trade.openPrice", trade.openPrice);
283
+ console.log("Final:", (positionSizeCollateral * fundingFeeDelta) / trade.openPrice / 100);
251
284
  return (positionSizeCollateral * fundingFeeDelta) / trade.openPrice / 100;
252
285
  };
253
286
  exports.getTradeFundingFeesCollateral = getTradeFundingFeesCollateral;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @dev Holding fees calculation utilities for v10+ markets
3
+ * @dev Combines funding fees and borrowing v2 fees
4
+ */
5
+ import { FundingFeeParams, PairFundingFeeData, PairOiAfterV10 } from "../fundingFees/types";
6
+ import { BorrowingFeeParams, PairBorrowingFeeData } from "../borrowingV2/types";
7
+ export type HoldingFeeRates = {
8
+ longHourlyRate: number;
9
+ shortHourlyRate: number;
10
+ fundingFeeLongHourlyRate: number;
11
+ fundingFeeShortHourlyRate: number;
12
+ borrowingFeeHourlyRate: number;
13
+ currentFundingRatePerSecondP: number;
14
+ currentBorrowingRatePerSecondP: number;
15
+ };
16
+ export type GetPairHoldingFeeRatesInput = {
17
+ fundingParams: FundingFeeParams;
18
+ fundingData: PairFundingFeeData;
19
+ pairOiToken: PairOiAfterV10;
20
+ netExposureToken: number;
21
+ netExposureUsd: number;
22
+ borrowingParams: BorrowingFeeParams | null;
23
+ borrowingData: PairBorrowingFeeData | null;
24
+ currentPairPrice: number;
25
+ currentTimestamp: number;
26
+ };
27
+ /**
28
+ * @dev Calculates current holding fee rates per hour for display
29
+ * @param input Input parameters for calculation
30
+ * @returns Holding fee rates per hour with breakdown
31
+ */
32
+ export declare const getPairHoldingFeeRates: (input: GetPairHoldingFeeRatesInput) => HoldingFeeRates;
33
+ /**
34
+ * @dev Converts a per-second rate to annual percentage rate (APR)
35
+ * @param ratePerSecond Rate per second
36
+ * @returns Annual percentage rate
37
+ */
38
+ export declare const convertRatePerSecondToAPR: (ratePerSecond: number) => number;
39
+ /**
40
+ * @dev Formats a holding fee rate for display
41
+ * @param rate Hourly rate (can be negative)
42
+ * @param decimals Number of decimal places
43
+ * @returns Formatted string with sign
44
+ */
45
+ export declare const formatHoldingFeeRate: (rate: number, decimals?: number) => string;
46
+ export * as HoldingFees from "./types";
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ /**
3
+ * @dev Holding fees calculation utilities for v10+ markets
4
+ * @dev Combines funding fees and borrowing v2 fees
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || function (mod) {
23
+ if (mod && mod.__esModule) return mod;
24
+ var result = {};
25
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
26
+ __setModuleDefault(result, mod);
27
+ return result;
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.HoldingFees = exports.formatHoldingFeeRate = exports.convertRatePerSecondToAPR = exports.getPairHoldingFeeRates = void 0;
31
+ const fundingFees_1 = require("../fundingFees");
32
+ const SECONDS_PER_HOUR = 3600;
33
+ const SECONDS_PER_YEAR = 365 * 24 * 60 * 60;
34
+ const PERCENTAGE_PRECISION = 100;
35
+ /**
36
+ * @dev Calculates current holding fee rates per hour for display
37
+ * @param input Input parameters for calculation
38
+ * @returns Holding fee rates per hour with breakdown
39
+ */
40
+ const getPairHoldingFeeRates = (input) => {
41
+ const { fundingParams, fundingData, pairOiToken, netExposureToken, netExposureUsd, borrowingParams, borrowingData, currentPairPrice, currentTimestamp, } = input;
42
+ // Calculate funding fee rates
43
+ let fundingFeeLongHourlyRate = 0;
44
+ let fundingFeeShortHourlyRate = 0;
45
+ let currentFundingRatePerSecondP = 0;
46
+ if (fundingParams.fundingFeesEnabled) {
47
+ // Get current funding rate
48
+ const pendingFunding = (0, fundingFees_1.getPairPendingAccFundingFees)(fundingParams, fundingData, currentPairPrice, pairOiToken, netExposureToken, netExposureUsd, currentTimestamp);
49
+ currentFundingRatePerSecondP = pendingFunding.currentFundingRatePerSecondP;
50
+ // Get APR multipliers
51
+ const { longAprMultiplier, shortAprMultiplier } = (0, fundingFees_1.getLongShortAprMultiplier)(currentFundingRatePerSecondP, pairOiToken.oiLongToken, pairOiToken.oiShortToken, fundingParams.aprMultiplierEnabled);
52
+ // Calculate hourly rates
53
+ // Funding rate * seconds per hour * current price * APR multiplier / 100
54
+ const baseHourlyRate = (currentFundingRatePerSecondP * SECONDS_PER_HOUR * currentPairPrice) /
55
+ PERCENTAGE_PRECISION;
56
+ // Long side pays when rate is positive, earns when negative
57
+ fundingFeeLongHourlyRate = baseHourlyRate * longAprMultiplier;
58
+ // Short side is opposite
59
+ fundingFeeShortHourlyRate = -baseHourlyRate * shortAprMultiplier;
60
+ }
61
+ // Calculate borrowing v2 rates
62
+ let borrowingFeeHourlyRate = 0;
63
+ let currentBorrowingRatePerSecondP = 0;
64
+ if (borrowingParams && borrowingData) {
65
+ currentBorrowingRatePerSecondP = borrowingParams.borrowingRatePerSecondP;
66
+ // Borrowing rate * seconds per hour * current price / 100
67
+ borrowingFeeHourlyRate =
68
+ (currentBorrowingRatePerSecondP * SECONDS_PER_HOUR * currentPairPrice) /
69
+ PERCENTAGE_PRECISION;
70
+ }
71
+ // Total holding fees (funding can be negative/positive, borrowing always positive cost)
72
+ const longHourlyRate = fundingFeeLongHourlyRate + borrowingFeeHourlyRate;
73
+ const shortHourlyRate = fundingFeeShortHourlyRate + borrowingFeeHourlyRate;
74
+ return {
75
+ longHourlyRate,
76
+ shortHourlyRate,
77
+ fundingFeeLongHourlyRate,
78
+ fundingFeeShortHourlyRate,
79
+ borrowingFeeHourlyRate,
80
+ currentFundingRatePerSecondP,
81
+ currentBorrowingRatePerSecondP,
82
+ };
83
+ };
84
+ exports.getPairHoldingFeeRates = getPairHoldingFeeRates;
85
+ /**
86
+ * @dev Converts a per-second rate to annual percentage rate (APR)
87
+ * @param ratePerSecond Rate per second
88
+ * @returns Annual percentage rate
89
+ */
90
+ const convertRatePerSecondToAPR = (ratePerSecond) => {
91
+ return ratePerSecond * SECONDS_PER_YEAR * PERCENTAGE_PRECISION;
92
+ };
93
+ exports.convertRatePerSecondToAPR = convertRatePerSecondToAPR;
94
+ /**
95
+ * @dev Formats a holding fee rate for display
96
+ * @param rate Hourly rate (can be negative)
97
+ * @param decimals Number of decimal places
98
+ * @returns Formatted string with sign
99
+ */
100
+ const formatHoldingFeeRate = (rate, decimals = 4) => {
101
+ const sign = rate > 0 ? "+" : "";
102
+ return `${sign}${rate.toFixed(decimals)}%`;
103
+ };
104
+ exports.formatHoldingFeeRate = formatHoldingFeeRate;
105
+ exports.HoldingFees = __importStar(require("./types"));
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @dev Type definitions for holding fees (funding + borrowing v2)
3
+ */
4
+ export interface HoldingFeeRates {
5
+ longHourlyRate: number;
6
+ shortHourlyRate: number;
7
+ fundingFeeLongHourlyRate: number;
8
+ fundingFeeShortHourlyRate: number;
9
+ borrowingFeeHourlyRate: number;
10
+ currentFundingRatePerSecondP: number;
11
+ currentBorrowingRatePerSecondP: number;
12
+ }
13
+ export interface GetPairHoldingFeeRatesInput {
14
+ fundingParams: import("../fundingFees/types").FundingFeeParams;
15
+ fundingData: import("../fundingFees/types").PairFundingFeeData;
16
+ pairOiToken: import("../fundingFees/types").PairOiAfterV10;
17
+ netExposureToken: number;
18
+ netExposureUsd: number;
19
+ borrowingParams: import("../borrowingV2/types").BorrowingFeeParams | null;
20
+ borrowingData: import("../borrowingV2/types").PairBorrowingFeeData | null;
21
+ currentPairPrice: number;
22
+ currentTimestamp: number;
23
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ /**
3
+ * @dev Type definitions for holding fees (funding + borrowing v2)
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @dev Holding fees calculation for structured contexts
3
+ */
4
+ import { Trade, TradeInfo, TradeFeesData } from "../../types";
5
+ import { TradeHoldingFees } from "./types";
6
+ import { ContractsVersion } from "../../../contracts/types";
7
+ import type { BorrowingV1SubContext, BorrowingV2SubContext, FundingFeesSubContext } from "../../pnl";
8
+ /**
9
+ * @dev Context for holding fees calculation with structured sub-contexts
10
+ */
11
+ export type GetStructuredHoldingFeesContext = {
12
+ contractsVersion: ContractsVersion;
13
+ currentTimestamp: number;
14
+ collateralPriceUsd: number;
15
+ borrowingV1?: BorrowingV1SubContext;
16
+ borrowingV2?: BorrowingV2SubContext;
17
+ funding?: FundingFeesSubContext;
18
+ };
19
+ /**
20
+ * @dev Calculates total holding fees using structured context
21
+ * @param trade The trade to calculate fees for
22
+ * @param tradeInfo Trade info containing contracts version
23
+ * @param tradeFeesData Trade fees data containing initial acc fees
24
+ * @param currentPairPrice Current pair price
25
+ * @param context Structured context with sub-contexts for each fee type
26
+ * @returns Object containing all holding fee components
27
+ */
28
+ export declare const getTradePendingHoldingFeesCollateralStructured: (trade: Trade, tradeInfo: TradeInfo, tradeFeesData: TradeFeesData, currentPairPrice: number, context: GetStructuredHoldingFeesContext) => TradeHoldingFees;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ /**
3
+ * @dev Holding fees calculation for structured contexts
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getTradePendingHoldingFeesCollateralStructured = void 0;
7
+ const types_1 = require("../../../contracts/types");
8
+ const borrowing_1 = require("../borrowing");
9
+ const borrowingV2_1 = require("../borrowingV2");
10
+ const pairContext_1 = require("../fundingFees/pairContext");
11
+ /**
12
+ * @dev Calculates total holding fees using structured context
13
+ * @param trade The trade to calculate fees for
14
+ * @param tradeInfo Trade info containing contracts version
15
+ * @param tradeFeesData Trade fees data containing initial acc fees
16
+ * @param currentPairPrice Current pair price
17
+ * @param context Structured context with sub-contexts for each fee type
18
+ * @returns Object containing all holding fee components
19
+ */
20
+ const getTradePendingHoldingFeesCollateralStructured = (trade, tradeInfo, tradeFeesData, currentPairPrice, context) => {
21
+ const positionSizeCollateral = trade.collateralAmount * trade.leverage;
22
+ // Calculate funding fees (v10+ only)
23
+ let fundingFeeCollateral = 0;
24
+ if (context.contractsVersion >= types_1.ContractsVersion.V10 &&
25
+ context.funding &&
26
+ tradeFeesData.initialAccFundingFeeP !== undefined) {
27
+ fundingFeeCollateral = (0, pairContext_1.getPairTradeFundingFeesCollateral)({
28
+ positionSizeCollateral,
29
+ openPrice: trade.openPrice,
30
+ long: trade.long,
31
+ currentPairPrice,
32
+ initialAccFundingFeeP: tradeFeesData.initialAccFundingFeeP,
33
+ }, context.funding // TODO: Fix types once funding types are properly imported
34
+ );
35
+ }
36
+ // Calculate borrowing fees v2
37
+ let borrowingFeeCollateral = 0;
38
+ if (context.borrowingV2 && tradeFeesData.initialAccBorrowingFeeP !== undefined) {
39
+ borrowingFeeCollateral = (0, borrowingV2_1.getPairTradeBorrowingFeesCollateral)({
40
+ positionSizeCollateral,
41
+ openPrice: trade.openPrice,
42
+ currentPairPrice,
43
+ initialAccBorrowingFeeP: tradeFeesData.initialAccBorrowingFeeP,
44
+ currentTimestamp: context.currentTimestamp,
45
+ }, context.borrowingV2);
46
+ }
47
+ // Calculate v1 borrowing fees (some markets use v1 indefinitely)
48
+ let borrowingFeeCollateral_old = 0;
49
+ if (context.borrowingV1) {
50
+ borrowingFeeCollateral_old = (0, borrowing_1.getPairBorrowingFee)(positionSizeCollateral, trade.long, context.borrowingV1.initialAccFees || { accPairFee: 0, accGroupFee: 0, block: 0 }, {
51
+ currentBlock: context.borrowingV1.currentBlock,
52
+ group: context.borrowingV1.group,
53
+ pair: context.borrowingV1.pair,
54
+ collateralPriceUsd: context.collateralPriceUsd,
55
+ });
56
+ }
57
+ return {
58
+ fundingFeeCollateral,
59
+ borrowingFeeCollateral,
60
+ borrowingFeeCollateral_old,
61
+ totalFeeCollateral: fundingFeeCollateral +
62
+ borrowingFeeCollateral +
63
+ borrowingFeeCollateral_old,
64
+ };
65
+ };
66
+ exports.getTradePendingHoldingFeesCollateralStructured = getTradePendingHoldingFeesCollateralStructured;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @dev Holding fees calculation for structured contexts
3
+ */
4
+ import { Trade, TradeInfo, TradeFeesData } from "../../types";
5
+ import { TradeHoldingFees } from "./types";
6
+ import { ContractsVersion } from "../../../contracts/types";
7
+ import type { BorrowingV1SubContext, BorrowingV2SubContext, FundingFeesSubContext } from "../../pnl";
8
+ /**
9
+ * @dev Context for holding fees calculation with structured sub-contexts
10
+ */
11
+ export type GetStructuredHoldingFeesContext = {
12
+ contractsVersion: ContractsVersion;
13
+ currentTimestamp: number;
14
+ collateralPriceUsd: number;
15
+ borrowingV1?: BorrowingV1SubContext;
16
+ borrowingV2?: BorrowingV2SubContext;
17
+ funding?: FundingFeesSubContext;
18
+ };
19
+ /**
20
+ * @dev Calculates total holding fees using structured context
21
+ * @param trade The trade to calculate fees for
22
+ * @param tradeInfo Trade info containing contracts version
23
+ * @param tradeFeesData Trade fees data containing initial acc fees
24
+ * @param currentPairPrice Current pair price
25
+ * @param context Structured context with sub-contexts for each fee type
26
+ * @returns Object containing all holding fee components
27
+ */
28
+ export declare const getTradePendingHoldingFeesCollateralStructured: (trade: Trade, tradeInfo: TradeInfo, tradeFeesData: TradeFeesData, currentPairPrice: number, context: GetStructuredHoldingFeesContext) => TradeHoldingFees;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ /**
3
+ * @dev Holding fees calculation for structured contexts
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getTradePendingHoldingFeesCollateralStructured = void 0;
7
+ const types_1 = require("../../../contracts/types");
8
+ const borrowing_1 = require("../borrowing");
9
+ const borrowingV2_1 = require("../borrowingV2");
10
+ const fundingFees_1 = require("../fundingFees");
11
+ /**
12
+ * @dev Calculates total holding fees using structured context
13
+ * @param trade The trade to calculate fees for
14
+ * @param tradeInfo Trade info containing contracts version
15
+ * @param tradeFeesData Trade fees data containing initial acc fees
16
+ * @param currentPairPrice Current pair price
17
+ * @param context Structured context with sub-contexts for each fee type
18
+ * @returns Object containing all holding fee components
19
+ */
20
+ const getTradePendingHoldingFeesCollateralStructured = (trade, tradeInfo, tradeFeesData, currentPairPrice, context) => {
21
+ const positionSizeCollateral = trade.collateralAmount * trade.leverage;
22
+ // Calculate funding fees (v10+ only)
23
+ let fundingFeeCollateral = 0;
24
+ if (context.contractsVersion >= types_1.ContractsVersion.V10 &&
25
+ context.funding &&
26
+ tradeFeesData.initialAccFundingFeeP !== undefined) {
27
+ fundingFeeCollateral = (0, fundingFees_1.getTradeFundingFeesCollateral)(trade, tradeInfo, tradeFeesData, currentPairPrice, Object.assign(Object.assign({}, context.funding), { currentTimestamp: context.currentTimestamp }) // TODO: Fix types once funding types are properly imported
28
+ );
29
+ }
30
+ // Calculate borrowing fees v2
31
+ let borrowingFeeCollateral = 0;
32
+ if (context.borrowingV2 &&
33
+ tradeFeesData.initialAccBorrowingFeeP !== undefined) {
34
+ borrowingFeeCollateral = (0, borrowingV2_1.getTradeBorrowingFeesCollateral)({
35
+ positionSizeCollateral,
36
+ openPrice: trade.openPrice,
37
+ currentPairPrice,
38
+ initialAccBorrowingFeeP: tradeFeesData.initialAccBorrowingFeeP,
39
+ currentTimestamp: context.currentTimestamp,
40
+ }, context.borrowingV2);
41
+ }
42
+ // Calculate v1 borrowing fees (some markets use v1 indefinitely)
43
+ let borrowingFeeCollateral_old = 0;
44
+ if (context.borrowingV1) {
45
+ borrowingFeeCollateral_old = (0, borrowing_1.getBorrowingFee)(positionSizeCollateral, undefined, // pairIndex not needed for pair-specific context
46
+ trade.long, context.borrowingV1.initialAccFees || {
47
+ accPairFee: 0,
48
+ accGroupFee: 0,
49
+ block: 0,
50
+ }, {
51
+ currentBlock: context.borrowingV1.currentBlock,
52
+ group: context.borrowingV1.group,
53
+ pair: context.borrowingV1.pair,
54
+ collateralPriceUsd: context.collateralPriceUsd,
55
+ });
56
+ }
57
+ return {
58
+ fundingFeeCollateral,
59
+ borrowingFeeCollateral,
60
+ borrowingFeeCollateral_old,
61
+ totalFeeCollateral: fundingFeeCollateral +
62
+ borrowingFeeCollateral +
63
+ borrowingFeeCollateral_old,
64
+ };
65
+ };
66
+ exports.getTradePendingHoldingFeesCollateralStructured = getTradePendingHoldingFeesCollateralStructured;
@@ -730,5 +730,10 @@ export declare enum PairIndex {
730
730
  HUSD = 404,
731
731
  ICNTUSD = 405,
732
732
  NEWTUSD = 406,
733
- PUMPUSD = 407
733
+ PUMPUSD = 407,
734
+ SAROSUSD = 408,
735
+ SPKUSD = 409,
736
+ ERAUSD = 410,
737
+ BGSCUSD = 411,
738
+ TAGUSD = 412
734
739
  }
@@ -437,4 +437,9 @@ var PairIndex;
437
437
  PairIndex[PairIndex["ICNTUSD"] = 405] = "ICNTUSD";
438
438
  PairIndex[PairIndex["NEWTUSD"] = 406] = "NEWTUSD";
439
439
  PairIndex[PairIndex["PUMPUSD"] = 407] = "PUMPUSD";
440
+ PairIndex[PairIndex["SAROSUSD"] = 408] = "SAROSUSD";
441
+ PairIndex[PairIndex["SPKUSD"] = 409] = "SPKUSD";
442
+ PairIndex[PairIndex["ERAUSD"] = 410] = "ERAUSD";
443
+ PairIndex[PairIndex["BGSCUSD"] = 411] = "BGSCUSD";
444
+ PairIndex[PairIndex["TAGUSD"] = 412] = "TAGUSD";
440
445
  })(PairIndex = exports.PairIndex || (exports.PairIndex = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gainsnetwork/sdk",
3
- "version": "1.0.0-rc9",
3
+ "version": "1.0.1-rc1",
4
4
  "description": "Gains Network SDK",
5
5
  "main": "./lib/index.js",
6
6
  "files": [