@gainsnetwork/sdk 0.2.67-rc8 → 0.2.69

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 (136) hide show
  1. package/lib/contracts/addresses.json +20 -0
  2. package/lib/{trade/fees/borrowingV2/fetcher.d.ts → contracts/fetch/fees/borrowingFeesV2.d.ts} +3 -2
  3. package/lib/{trade/fees/borrowingV2/fetcher.js → contracts/fetch/fees/borrowingFeesV2.js} +14 -6
  4. package/lib/{trade/fees/fundingFees/fetcher.d.ts → contracts/fetch/fees/fundingFees.d.ts} +2 -2
  5. package/lib/{trade/priceImpact/skew/fetcher.d.ts → contracts/fetch/priceImpact/skew.d.ts} +2 -2
  6. package/lib/{trade/priceImpact/skew/fetcher.js → contracts/fetch/priceImpact/skew.js} +6 -6
  7. package/lib/contracts/index.js +3 -1
  8. package/lib/contracts/types/generated/GNSMultiCollatDiamond.d.ts +258 -2112
  9. package/lib/contracts/types/generated/GToken.d.ts +107 -78
  10. package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.d.ts +53 -90
  11. package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +421 -4496
  12. package/lib/contracts/types/generated/factories/GToken__factory.js +142 -65
  13. package/lib/contracts/types/index.d.ts +2 -1
  14. package/lib/contracts/types/index.js +1 -0
  15. package/lib/trade/fees/borrowingV2/converter.d.ts +3 -12
  16. package/lib/trade/fees/borrowingV2/converter.js +18 -29
  17. package/lib/trade/fees/borrowingV2/index.d.ts +17 -6
  18. package/lib/trade/fees/borrowingV2/index.js +37 -10
  19. package/lib/trade/fees/borrowingV2/types.d.ts +6 -22
  20. package/lib/trade/fees/fundingFees/index.d.ts +2 -13
  21. package/lib/trade/fees/fundingFees/index.js +3 -27
  22. package/lib/trade/fees/trading/index.d.ts +2 -30
  23. package/lib/trade/fees/trading/index.js +1 -52
  24. package/lib/trade/fees/trading/types.d.ts +0 -9
  25. package/lib/trade/priceImpact/index.d.ts +2 -6
  26. package/lib/trade/priceImpact/index.js +3 -30
  27. package/lib/trade/priceImpact/skew/index.d.ts +0 -1
  28. package/lib/trade/priceImpact/skew/index.js +0 -4
  29. package/package.json +1 -1
  30. package/lib/backend/globalTrades/index.d.ts +0 -11
  31. package/lib/backend/globalTrades/index.js +0 -69
  32. package/lib/backend/index.d.ts +0 -3
  33. package/lib/backend/index.js +0 -28
  34. package/lib/backend/tradingVariables/backend.types.d.ts +0 -312
  35. package/lib/backend/tradingVariables/backend.types.js +0 -2
  36. package/lib/backend/tradingVariables/converter.d.ts +0 -31
  37. package/lib/backend/tradingVariables/converter.js +0 -330
  38. package/lib/backend/tradingVariables/index.d.ts +0 -5
  39. package/lib/backend/tradingVariables/index.js +0 -95
  40. package/lib/backend/tradingVariables/types.d.ts +0 -109
  41. package/lib/backend/tradingVariables/types.js +0 -14
  42. package/lib/contracts/types/generated/GFarmTradingStorageV5.d.ts +0 -1911
  43. package/lib/contracts/types/generated/GFarmTradingStorageV5.js +0 -2
  44. package/lib/contracts/types/generated/GNSBorrowingFees.d.ts +0 -1067
  45. package/lib/contracts/types/generated/GNSBorrowingFees.js +0 -2
  46. package/lib/contracts/types/generated/GNSNftRewardsV6.d.ts +0 -533
  47. package/lib/contracts/types/generated/GNSNftRewardsV6.js +0 -2
  48. package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.d.ts +0 -613
  49. package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.js +0 -2
  50. package/lib/contracts/types/generated/GNSTrading.d.ts +0 -758
  51. package/lib/contracts/types/generated/GNSTrading.js +0 -2
  52. package/lib/contracts/types/generated/GNSTradingCallbacks.d.ts +0 -875
  53. package/lib/contracts/types/generated/GNSTradingCallbacks.js +0 -2
  54. package/lib/contracts/types/generated/GNSTradingStorage.d.ts +0 -1387
  55. package/lib/contracts/types/generated/GNSTradingStorage.js +0 -2
  56. package/lib/contracts/types/generated/GTokenV6_3_2.d.ts +0 -1838
  57. package/lib/contracts/types/generated/GTokenV6_3_2.js +0 -2
  58. package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.d.ts +0 -83
  59. package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.js +0 -2691
  60. package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.d.ts +0 -124
  61. package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.js +0 -1784
  62. package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.d.ts +0 -100
  63. package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.js +0 -1116
  64. package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.d.ts +0 -100
  65. package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.js +0 -1003
  66. package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.d.ts +0 -113
  67. package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.js +0 -1428
  68. package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.d.ts +0 -96
  69. package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.js +0 -2241
  70. package/lib/contracts/types/generated/factories/GNSTrading__factory.d.ts +0 -95
  71. package/lib/contracts/types/generated/factories/GNSTrading__factory.js +0 -1071
  72. package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.d.ts +0 -110
  73. package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.js +0 -2682
  74. package/lib/contracts/utils/openLimitOrders.d.ts +0 -8
  75. package/lib/contracts/utils/openLimitOrders.js +0 -88
  76. package/lib/markets/collateral/converter.d.ts +0 -5
  77. package/lib/markets/collateral/converter.js +0 -11
  78. package/lib/markets/collateral/index.d.ts +0 -1
  79. package/lib/markets/collateral/index.js +0 -17
  80. package/lib/markets/collateral/types.d.ts +0 -7
  81. package/lib/markets/collateral/types.js +0 -2
  82. package/lib/markets/oi/converter.d.ts +0 -63
  83. package/lib/markets/oi/converter.js +0 -103
  84. package/lib/markets/oi/fetcher.d.ts +0 -58
  85. package/lib/markets/oi/fetcher.js +0 -181
  86. package/lib/markets/oi/index.d.ts +0 -10
  87. package/lib/markets/oi/index.js +0 -37
  88. package/lib/markets/oi/types.d.ts +0 -82
  89. package/lib/markets/oi/types.js +0 -6
  90. package/lib/markets/oi/validation.d.ts +0 -80
  91. package/lib/markets/oi/validation.js +0 -172
  92. package/lib/trade/fees/borrowing/builder.d.ts +0 -14
  93. package/lib/trade/fees/borrowing/builder.js +0 -33
  94. package/lib/trade/fees/borrowingV2/builder.d.ts +0 -6
  95. package/lib/trade/fees/borrowingV2/builder.js +0 -24
  96. package/lib/trade/fees/converter.d.ts +0 -48
  97. package/lib/trade/fees/converter.js +0 -110
  98. package/lib/trade/fees/fundingFees/builder.d.ts +0 -9
  99. package/lib/trade/fees/fundingFees/builder.js +0 -35
  100. package/lib/trade/fees/fundingFees/pairContext.d.ts +0 -33
  101. package/lib/trade/fees/fundingFees/pairContext.js +0 -17
  102. package/lib/trade/fees/tiers/converter.d.ts +0 -54
  103. package/lib/trade/fees/tiers/converter.js +0 -81
  104. package/lib/trade/fees/trading/builder.d.ts +0 -18
  105. package/lib/trade/fees/trading/builder.js +0 -20
  106. package/lib/trade/liquidation/builder.d.ts +0 -25
  107. package/lib/trade/liquidation/builder.js +0 -59
  108. package/lib/trade/liquidation/converter.d.ts +0 -23
  109. package/lib/trade/liquidation/converter.js +0 -46
  110. package/lib/trade/liquidation/index.d.ts +0 -26
  111. package/lib/trade/liquidation/index.js +0 -142
  112. package/lib/trade/liquidation/types.d.ts +0 -59
  113. package/lib/trade/liquidation/types.js +0 -2
  114. package/lib/trade/openLimitOrder.d.ts +0 -2
  115. package/lib/trade/openLimitOrder.js +0 -23
  116. package/lib/trade/pnl/builder.d.ts +0 -16
  117. package/lib/trade/pnl/builder.js +0 -44
  118. package/lib/trade/pnl/converter.d.ts +0 -47
  119. package/lib/trade/pnl/converter.js +0 -72
  120. package/lib/trade/pnl/index.d.ts +0 -77
  121. package/lib/trade/pnl/index.js +0 -270
  122. package/lib/trade/pnl/types.d.ts +0 -114
  123. package/lib/trade/pnl/types.js +0 -5
  124. package/lib/trade/priceImpact/close/index.d.ts +0 -21
  125. package/lib/trade/priceImpact/close/index.js +0 -131
  126. package/lib/trade/priceImpact/close/types.d.ts +0 -43
  127. package/lib/trade/priceImpact/close/types.js +0 -5
  128. package/lib/trade/priceImpact/cumulVol/converter.d.ts +0 -31
  129. package/lib/trade/priceImpact/cumulVol/converter.js +0 -59
  130. package/lib/trade/priceImpact/cumulVol/index.d.ts +0 -107
  131. package/lib/trade/priceImpact/cumulVol/index.js +0 -228
  132. package/lib/trade/priceImpact/open/index.d.ts +0 -22
  133. package/lib/trade/priceImpact/open/index.js +0 -76
  134. package/lib/trade/priceImpact/open/types.d.ts +0 -41
  135. package/lib/trade/priceImpact/open/types.js +0 -5
  136. /package/lib/{trade/fees/fundingFees/fetcher.js → contracts/fetch/fees/fundingFees.js} +0 -0
@@ -1,82 +0,0 @@
1
- /**
2
- * @dev Consolidated OI types for unified Open Interest management
3
- * @dev Represents the three OI storage systems in Gains Network v10
4
- */
5
- /**
6
- * @dev Unified pair OI structure combining all storage systems
7
- */
8
- export interface UnifiedPairOi {
9
- /**
10
- * @dev Maximum allowed OI in collateral (applies to combined OI)
11
- */
12
- maxCollateral: number;
13
- /**
14
- * @dev Pre-v10 trades OI stored in collateral amounts
15
- * @dev Static values from when positions were opened
16
- */
17
- beforeV10Collateral: {
18
- long: number;
19
- short: number;
20
- };
21
- /**
22
- * @dev Post-v10 trades OI stored in collateral amounts
23
- * @dev Initial collateral values when positions were opened
24
- * @dev Used for administrative operations and static calculations
25
- */
26
- collateral: {
27
- long: number;
28
- short: number;
29
- };
30
- /**
31
- * @dev Post-v10 trades OI stored in token amounts
32
- * @dev Used for dynamic calculations (multiply by current price)
33
- * @dev Powers skew impact and funding fees
34
- */
35
- token: {
36
- long: number;
37
- short: number;
38
- };
39
- }
40
- /**
41
- * @dev Group OI remains unchanged - only used by borrowing v1
42
- * @dev Re-export existing type for consistency
43
- */
44
- export { OpenInterest as GroupOi } from "../../trade/types";
45
- /**
46
- * @dev Metadata describing which OI systems are used by different features
47
- * @dev Helps consumers understand OI usage patterns
48
- */
49
- export interface OiUsageMetadata {
50
- borrowingV1: Array<"beforeV10Collateral" | "token">;
51
- fundingFees: Array<"token">;
52
- skewImpact: Array<"token">;
53
- maxPairOi: Array<"beforeV10Collateral" | "token">;
54
- maxGroupOi: Array<"beforeV10Collateral" | "token">;
55
- maxSkew: Array<"token">;
56
- }
57
- /**
58
- * @dev Helper type for computed OI values
59
- */
60
- export interface ComputedOi {
61
- /**
62
- * @dev Total OI using static values: beforeV10Collateral + collateral
63
- * @dev Used for administrative operations
64
- */
65
- totalStaticCollateral: {
66
- long: number;
67
- short: number;
68
- };
69
- /**
70
- * @dev Total OI using dynamic values: beforeV10Collateral + (token * price)
71
- * @dev Used for real-time calculations like fees
72
- */
73
- totalDynamicCollateral: {
74
- long: number;
75
- short: number;
76
- };
77
- /**
78
- * @dev Net skew in tokens (v10+ only)
79
- * @dev Positive = more longs, negative = more shorts
80
- */
81
- skewToken: number;
82
- }
@@ -1,6 +0,0 @@
1
- "use strict";
2
- /**
3
- * @dev Consolidated OI types for unified Open Interest management
4
- * @dev Represents the three OI storage systems in Gains Network v10
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,80 +0,0 @@
1
- /**
2
- * @dev OI Validation module
3
- * @dev Provides validation functions for Open Interest limits
4
- */
5
- import { UnifiedPairOi } from "./types";
6
- import * as BorrowingFee from "../../trade/fees/borrowing/types";
7
- import { PairIndex } from "../../trade/types";
8
- /**
9
- * @dev Check if a position would exceed per-pair OI limits
10
- * @param pairOi Current OI data for the pair
11
- * @param long Whether the position is long
12
- * @param positionSizeCollateral Position size in collateral
13
- * @param currentPrice Current collateral price in USD (required for dynamic OI)
14
- * @returns true if within limits, false if would exceed
15
- */
16
- export declare const withinMaxPairOi: (pairOi: UnifiedPairOi, long: boolean, positionSizeCollateral: number, currentPrice: number) => boolean;
17
- /**
18
- * @dev Calculate dynamic OI for a specific side
19
- * @param pairOi OI data for the pair
20
- * @param currentPrice Current collateral price in USD
21
- * @param long Whether to calculate for long side
22
- * @returns Dynamic OI in collateral value
23
- */
24
- export declare const calculateDynamicOi: (pairOi: UnifiedPairOi, currentPrice: number, long: boolean) => number;
25
- /**
26
- * @dev Calculate remaining OI capacity for a side
27
- * @param pairOi OI data for the pair
28
- * @param currentPrice Current collateral price in USD
29
- * @param long Whether to calculate for long side
30
- * @returns Remaining capacity in collateral (0 if unlimited)
31
- */
32
- export declare const getRemainingOiCapacity: (pairOi: UnifiedPairOi, currentPrice: number, long: boolean) => number;
33
- /**
34
- * @dev Updated group OI validation using dynamic OI
35
- * @param pairIndex Index of the trading pair
36
- * @param long Whether the position is long
37
- * @param positionSizeCollateral Position size in collateral
38
- * @param currentPrice Current collateral price in USD
39
- * @param context Context with groups, pairs, and OI data
40
- * @returns true if within group limits, false if would exceed
41
- */
42
- export declare const withinMaxGroupOiDynamic: (pairIndex: PairIndex, long: boolean, positionSizeCollateral: number, currentPrice: number, context: {
43
- groups: BorrowingFee.Group[];
44
- pairs: BorrowingFee.Pair[];
45
- pairOis: UnifiedPairOi[];
46
- }) => boolean;
47
- /**
48
- * @dev Calculate total dynamic OI for a group
49
- * @param groupIndex Index of the group
50
- * @param currentPrice Current collateral price in USD
51
- * @param context Context with pairs and OI data
52
- * @returns Total dynamic OI for the group
53
- */
54
- export declare const getGroupDynamicOi: (groupIndex: number, currentPrice: number, context: {
55
- pairs: BorrowingFee.Pair[];
56
- pairOis: UnifiedPairOi[];
57
- }) => {
58
- long: number;
59
- short: number;
60
- total: number;
61
- };
62
- /**
63
- * @dev Check both pair and group OI limits
64
- * @param pairIndex Index of the trading pair
65
- * @param long Whether the position is long
66
- * @param positionSizeCollateral Position size in collateral
67
- * @param currentPrice Current collateral price in USD
68
- * @param context Full context with all required data
69
- * @returns Object with validation results
70
- */
71
- export declare const validateOiLimits: (pairIndex: PairIndex, long: boolean, positionSizeCollateral: number, currentPrice: number, context: {
72
- groups: BorrowingFee.Group[];
73
- pairs: BorrowingFee.Pair[];
74
- pairOis: UnifiedPairOi[];
75
- }) => {
76
- withinPairLimit: boolean;
77
- withinGroupLimit: boolean;
78
- pairRemainingCapacity: number;
79
- groupRemainingCapacity: number;
80
- };
@@ -1,172 +0,0 @@
1
- "use strict";
2
- /**
3
- * @dev OI Validation module
4
- * @dev Provides validation functions for Open Interest limits
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.validateOiLimits = exports.getGroupDynamicOi = exports.withinMaxGroupOiDynamic = exports.getRemainingOiCapacity = exports.calculateDynamicOi = exports.withinMaxPairOi = void 0;
8
- const converter_1 = require("./converter");
9
- /**
10
- * @dev Check if a position would exceed per-pair OI limits
11
- * @param pairOi Current OI data for the pair
12
- * @param long Whether the position is long
13
- * @param positionSizeCollateral Position size in collateral
14
- * @param currentPrice Current collateral price in USD (required for dynamic OI)
15
- * @returns true if within limits, false if would exceed
16
- */
17
- const withinMaxPairOi = (pairOi, long, positionSizeCollateral, currentPrice) => {
18
- // If maxCollateral is 0, unlimited OI allowed
19
- if (pairOi.maxCollateral === 0) {
20
- return true;
21
- }
22
- // Calculate current dynamic OI
23
- const computed = (0, converter_1.computeOiValues)(pairOi, currentPrice);
24
- const currentOi = long
25
- ? computed.totalDynamicCollateral.long
26
- : computed.totalDynamicCollateral.short;
27
- // Check if adding position would exceed max
28
- const newOi = currentOi + positionSizeCollateral;
29
- return newOi <= pairOi.maxCollateral;
30
- };
31
- exports.withinMaxPairOi = withinMaxPairOi;
32
- /**
33
- * @dev Calculate dynamic OI for a specific side
34
- * @param pairOi OI data for the pair
35
- * @param currentPrice Current collateral price in USD
36
- * @param long Whether to calculate for long side
37
- * @returns Dynamic OI in collateral value
38
- */
39
- const calculateDynamicOi = (pairOi, currentPrice, long) => {
40
- const computed = (0, converter_1.computeOiValues)(pairOi, currentPrice);
41
- return long
42
- ? computed.totalDynamicCollateral.long
43
- : computed.totalDynamicCollateral.short;
44
- };
45
- exports.calculateDynamicOi = calculateDynamicOi;
46
- /**
47
- * @dev Calculate remaining OI capacity for a side
48
- * @param pairOi OI data for the pair
49
- * @param currentPrice Current collateral price in USD
50
- * @param long Whether to calculate for long side
51
- * @returns Remaining capacity in collateral (0 if unlimited)
52
- */
53
- const getRemainingOiCapacity = (pairOi, currentPrice, long) => {
54
- // If maxCollateral is 0, unlimited capacity
55
- if (pairOi.maxCollateral === 0) {
56
- return 0; // Indicates unlimited
57
- }
58
- const dynamicOi = (0, exports.calculateDynamicOi)(pairOi, currentPrice, long);
59
- const remaining = pairOi.maxCollateral - dynamicOi;
60
- // Return 0 if already at or over capacity
61
- return Math.max(0, remaining);
62
- };
63
- exports.getRemainingOiCapacity = getRemainingOiCapacity;
64
- /**
65
- * @dev Updated group OI validation using dynamic OI
66
- * @param pairIndex Index of the trading pair
67
- * @param long Whether the position is long
68
- * @param positionSizeCollateral Position size in collateral
69
- * @param currentPrice Current collateral price in USD
70
- * @param context Context with groups, pairs, and OI data
71
- * @returns true if within group limits, false if would exceed
72
- */
73
- const withinMaxGroupOiDynamic = (pairIndex, long, positionSizeCollateral, currentPrice, context) => {
74
- const pair = context.pairs[pairIndex];
75
- if (!pair)
76
- return false;
77
- // Get group index from first group in pair's groups array
78
- const groupIndex = pair.groups.length > 0 ? pair.groups[0].groupIndex : 0;
79
- const group = context.groups[groupIndex];
80
- if (!group)
81
- return false;
82
- // If maxOi is 0, unlimited OI allowed
83
- if (group.oi.max === 0) {
84
- return true;
85
- }
86
- // Calculate total dynamic OI for all pairs in group
87
- let totalGroupOi = 0;
88
- context.pairs.forEach((p, idx) => {
89
- const pGroupIndex = p.groups.length > 0 ? p.groups[0].groupIndex : 0;
90
- if (pGroupIndex === groupIndex && context.pairOis[idx]) {
91
- const pairOi = context.pairOis[idx];
92
- const computed = (0, converter_1.computeOiValues)(pairOi, currentPrice);
93
- // Add both long and short OI for the pair
94
- totalGroupOi +=
95
- computed.totalDynamicCollateral.long +
96
- computed.totalDynamicCollateral.short;
97
- }
98
- });
99
- // Check if adding position would exceed group max
100
- const newTotalOi = totalGroupOi + positionSizeCollateral;
101
- return newTotalOi <= group.oi.max;
102
- };
103
- exports.withinMaxGroupOiDynamic = withinMaxGroupOiDynamic;
104
- /**
105
- * @dev Calculate total dynamic OI for a group
106
- * @param groupIndex Index of the group
107
- * @param currentPrice Current collateral price in USD
108
- * @param context Context with pairs and OI data
109
- * @returns Total dynamic OI for the group
110
- */
111
- const getGroupDynamicOi = (groupIndex, currentPrice, context) => {
112
- let longOi = 0;
113
- let shortOi = 0;
114
- context.pairs.forEach((p, idx) => {
115
- const pGroupIndex = p.groups.length > 0 ? p.groups[0].groupIndex : 0;
116
- if (pGroupIndex === groupIndex && context.pairOis[idx]) {
117
- const pairOi = context.pairOis[idx];
118
- const computed = (0, converter_1.computeOiValues)(pairOi, currentPrice);
119
- longOi += computed.totalDynamicCollateral.long;
120
- shortOi += computed.totalDynamicCollateral.short;
121
- }
122
- });
123
- return {
124
- long: longOi,
125
- short: shortOi,
126
- total: longOi + shortOi,
127
- };
128
- };
129
- exports.getGroupDynamicOi = getGroupDynamicOi;
130
- /**
131
- * @dev Check both pair and group OI limits
132
- * @param pairIndex Index of the trading pair
133
- * @param long Whether the position is long
134
- * @param positionSizeCollateral Position size in collateral
135
- * @param currentPrice Current collateral price in USD
136
- * @param context Full context with all required data
137
- * @returns Object with validation results
138
- */
139
- const validateOiLimits = (pairIndex, long, positionSizeCollateral, currentPrice, context) => {
140
- const pairOi = context.pairOis[pairIndex];
141
- if (!pairOi) {
142
- return {
143
- withinPairLimit: false,
144
- withinGroupLimit: false,
145
- pairRemainingCapacity: 0,
146
- groupRemainingCapacity: 0,
147
- };
148
- }
149
- // Check pair limits
150
- const withinPairLimit = (0, exports.withinMaxPairOi)(pairOi, long, positionSizeCollateral, currentPrice);
151
- const pairRemainingCapacity = (0, exports.getRemainingOiCapacity)(pairOi, currentPrice, long);
152
- // Check group limits
153
- const withinGroupLimit = (0, exports.withinMaxGroupOiDynamic)(pairIndex, long, positionSizeCollateral, currentPrice, context);
154
- // Calculate group remaining capacity
155
- const pair = context.pairs[pairIndex];
156
- let groupRemainingCapacity = 0;
157
- if (pair) {
158
- const groupIndex = pair.groups.length > 0 ? pair.groups[0].groupIndex : 0;
159
- const group = context.groups[groupIndex];
160
- if (group && group.oi.max > 0) {
161
- const groupOi = (0, exports.getGroupDynamicOi)(groupIndex, currentPrice, context);
162
- groupRemainingCapacity = Math.max(0, group.oi.max - groupOi.total);
163
- }
164
- }
165
- return {
166
- withinPairLimit,
167
- withinGroupLimit,
168
- pairRemainingCapacity,
169
- groupRemainingCapacity,
170
- };
171
- };
172
- exports.validateOiLimits = validateOiLimits;
@@ -1,14 +0,0 @@
1
- /**
2
- * @dev Context builder for borrowing v1 fees
3
- */
4
- import { GlobalTradingVariablesType } from "../../../backend/tradingVariables/types";
5
- import { GetBorrowingFeeContext } from "./index";
6
- /**
7
- * @dev Builds borrowing v1 context from global trading variables
8
- * @dev Returns full array-based context required for v1 borrowing fee calculations
9
- * @param globalTradingVariables The transformed global trading variables from backend
10
- * @param collateralIndex Collateral index (1-based)
11
- * @param currentBlock Current block number
12
- * @returns Full borrowing context with all pairs and groups or undefined if data not available
13
- */
14
- export declare const buildBorrowingV1Context: (globalTradingVariables: GlobalTradingVariablesType, collateralIndex: number, currentBlock: number) => GetBorrowingFeeContext | undefined;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- /**
3
- * @dev Context builder for borrowing v1 fees
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.buildBorrowingV1Context = void 0;
7
- /**
8
- * @dev Builds borrowing v1 context from global trading variables
9
- * @dev Returns full array-based context required for v1 borrowing fee calculations
10
- * @param globalTradingVariables The transformed global trading variables from backend
11
- * @param collateralIndex Collateral index (1-based)
12
- * @param currentBlock Current block number
13
- * @returns Full borrowing context with all pairs and groups or undefined if data not available
14
- */
15
- const buildBorrowingV1Context = (globalTradingVariables, collateralIndex, currentBlock) => {
16
- var _a;
17
- 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)) {
19
- return undefined;
20
- }
21
- const pairs = collateral.pairBorrowingFees;
22
- const groups = collateral.groupBorrowingFees;
23
- if (pairs.length === 0 || groups.length === 0) {
24
- return undefined;
25
- }
26
- return {
27
- currentBlock,
28
- pairs,
29
- groups,
30
- collateralPriceUsd: ((_a = collateral.prices) === null || _a === void 0 ? void 0 : _a.collateralPriceUsd) || 1,
31
- };
32
- };
33
- exports.buildBorrowingV1Context = buildBorrowingV1Context;
@@ -1,6 +0,0 @@
1
- import { GlobalTradingVariablesType } from "../../../backend/tradingVariables/types";
2
- import { GetPairBorrowingFeeV2Context } from "./types";
3
- /**
4
- * @dev Builds borrowing v2 sub-context for a specific pair
5
- */
6
- export declare const buildBorrowingV2Context: (globalTradingVariables: GlobalTradingVariablesType, collateralIndex: number, pairIndex: number, currentTimestamp: number) => GetPairBorrowingFeeV2Context | undefined;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildBorrowingV2Context = void 0;
4
- /**
5
- * @dev Builds borrowing v2 sub-context for a specific pair
6
- */
7
- const buildBorrowingV2Context = (globalTradingVariables, collateralIndex, pairIndex, currentTimestamp) => {
8
- var _a, _b;
9
- const collateral = globalTradingVariables.collaterals[collateralIndex - 1];
10
- if (!(collateral === null || collateral === void 0 ? void 0 : collateral.pairBorrowingFeesV2)) {
11
- return undefined;
12
- }
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];
15
- if (!params || !data) {
16
- return undefined;
17
- }
18
- return {
19
- params,
20
- data,
21
- currentTimestamp,
22
- };
23
- };
24
- exports.buildBorrowingV2Context = buildBorrowingV2Context;
@@ -1,48 +0,0 @@
1
- /**
2
- * @dev Converters for fee data between contract and SDK formats
3
- */
4
- import { IFundingFees } from "../../contracts/types/generated/GNSMultiCollatDiamond";
5
- import { TradeFeesData, UiRealizedPnlData } from "../types";
6
- import { CollateralConfig } from "../../markets/collateral/types";
7
- /**
8
- * @dev Converts contract TradeFeesData to SDK format
9
- * @param data Trade fees data from contract
10
- * @param collateralConfig Config for the collateral (contains decimals)
11
- * @returns Normalized trade fees data
12
- */
13
- export declare const convertTradeFeesData: (data: IFundingFees.TradeFeesDataStructOutput, collateralConfig: CollateralConfig) => TradeFeesData;
14
- /**
15
- * @dev Converts array of TradeFeesData from contract
16
- * @param dataArray Array of trade fees data
17
- * @param collateralConfig Config for the collateral
18
- * @returns Array of normalized trade fees data
19
- */
20
- export declare const convertTradeFeesDataArray: (dataArray: IFundingFees.TradeFeesDataStructOutput[], collateralConfig: CollateralConfig) => TradeFeesData[];
21
- /**
22
- * @dev Converts contract UiRealizedPnlData to SDK format
23
- * @param data UI realized PnL data from contract
24
- * @param collateralConfig Config for the collateral (contains decimals)
25
- * @returns Normalized UI realized PnL data
26
- */
27
- export declare const convertUiRealizedPnlData: (data: IFundingFees.UiRealizedPnlDataStructOutput, collateralConfig: CollateralConfig) => UiRealizedPnlData;
28
- /**
29
- * @dev Converts array of UiRealizedPnlData from contract
30
- * @param dataArray Array of UI realized PnL data
31
- * @param collateralConfig Config for the collateral
32
- * @returns Array of normalized UI realized PnL data
33
- */
34
- export declare const convertUiRealizedPnlDataArray: (dataArray: IFundingFees.UiRealizedPnlDataStructOutput[], collateralConfig: CollateralConfig) => UiRealizedPnlData[];
35
- /**
36
- * @dev Converts TradeFeesData to contract format (for encoding)
37
- * @param data SDK trade fees data
38
- * @param collateralConfig Config for the collateral
39
- * @returns Contract-formatted trade fees data
40
- */
41
- export declare const encodeTradeFeesData: (data: TradeFeesData, collateralConfig: CollateralConfig) => IFundingFees.TradeFeesDataStruct;
42
- /**
43
- * @dev Converts UiRealizedPnlData to contract format (for encoding)
44
- * @param data SDK UI realized PnL data
45
- * @param collateralConfig Config for the collateral
46
- * @returns Contract-formatted UI realized PnL data
47
- */
48
- export declare const encodeUiRealizedPnlData: (data: UiRealizedPnlData, collateralConfig: CollateralConfig) => IFundingFees.UiRealizedPnlDataStruct;
@@ -1,110 +0,0 @@
1
- "use strict";
2
- /**
3
- * @dev Converters for fee data between contract and SDK formats
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.encodeUiRealizedPnlData = exports.encodeTradeFeesData = exports.convertUiRealizedPnlDataArray = exports.convertUiRealizedPnlData = exports.convertTradeFeesDataArray = exports.convertTradeFeesData = void 0;
7
- /**
8
- * @dev Converts contract TradeFeesData to SDK format
9
- * @param data Trade fees data from contract
10
- * @param collateralConfig Config for the collateral (contains decimals)
11
- * @returns Normalized trade fees data
12
- */
13
- const convertTradeFeesData = (data, collateralConfig) => {
14
- const decimals = collateralConfig.decimals || 18;
15
- return {
16
- realizedTradingFeesCollateral: parseFloat(data.realizedTradingFeesCollateral.toString()) /
17
- Math.pow(10, decimals),
18
- realizedPnlCollateral: parseFloat(data.realizedPnlCollateral.toString()) / Math.pow(10, decimals),
19
- manuallyRealizedNegativePnlCollateral: parseFloat(data.manuallyRealizedNegativePnlCollateral.toString()) /
20
- Math.pow(10, decimals),
21
- alreadyTransferredNegativePnlCollateral: parseFloat(data.alreadyTransferredNegativePnlCollateral.toString()) /
22
- Math.pow(10, decimals),
23
- virtualAvailableCollateralInDiamond: parseFloat(data.virtualAvailableCollateralInDiamond.toString()) /
24
- Math.pow(10, decimals),
25
- initialAccFundingFeeP: parseFloat(data.initialAccFundingFeeP.toString()) / 1e10,
26
- initialAccBorrowingFeeP: parseFloat(data.initialAccBorrowingFeeP.toString()) / 1e10,
27
- };
28
- };
29
- exports.convertTradeFeesData = convertTradeFeesData;
30
- /**
31
- * @dev Converts array of TradeFeesData from contract
32
- * @param dataArray Array of trade fees data
33
- * @param collateralConfig Config for the collateral
34
- * @returns Array of normalized trade fees data
35
- */
36
- const convertTradeFeesDataArray = (dataArray, collateralConfig) => {
37
- return dataArray.map(data => (0, exports.convertTradeFeesData)(data, collateralConfig));
38
- };
39
- exports.convertTradeFeesDataArray = convertTradeFeesDataArray;
40
- /**
41
- * @dev Converts contract UiRealizedPnlData to SDK format
42
- * @param data UI realized PnL data from contract
43
- * @param collateralConfig Config for the collateral (contains decimals)
44
- * @returns Normalized UI realized PnL data
45
- */
46
- const convertUiRealizedPnlData = (data, collateralConfig) => {
47
- const decimals = collateralConfig.decimals || 18;
48
- return {
49
- realizedTradingFeesCollateral: parseFloat(data.realizedTradingFeesCollateral.toString()) /
50
- Math.pow(10, decimals),
51
- realizedOldBorrowingFeesCollateral: parseFloat(data.realizedOldBorrowingFeesCollateral.toString()) /
52
- Math.pow(10, decimals),
53
- realizedNewBorrowingFeesCollateral: parseFloat(data.realizedNewBorrowingFeesCollateral.toString()) /
54
- Math.pow(10, decimals),
55
- realizedFundingFeesCollateral: parseFloat(data.realizedFundingFeesCollateral.toString()) /
56
- Math.pow(10, decimals),
57
- realizedPnlPartialCloseCollateral: parseFloat(data.realizedPnlPartialCloseCollateral.toString()) /
58
- Math.pow(10, decimals),
59
- pnlWithdrawnCollateral: parseFloat(data.pnlWithdrawnCollateral.toString()) / Math.pow(10, decimals),
60
- };
61
- };
62
- exports.convertUiRealizedPnlData = convertUiRealizedPnlData;
63
- /**
64
- * @dev Converts array of UiRealizedPnlData from contract
65
- * @param dataArray Array of UI realized PnL data
66
- * @param collateralConfig Config for the collateral
67
- * @returns Array of normalized UI realized PnL data
68
- */
69
- const convertUiRealizedPnlDataArray = (dataArray, collateralConfig) => {
70
- return dataArray.map(data => (0, exports.convertUiRealizedPnlData)(data, collateralConfig));
71
- };
72
- exports.convertUiRealizedPnlDataArray = convertUiRealizedPnlDataArray;
73
- /**
74
- * @dev Converts TradeFeesData to contract format (for encoding)
75
- * @param data SDK trade fees data
76
- * @param collateralConfig Config for the collateral
77
- * @returns Contract-formatted trade fees data
78
- */
79
- const encodeTradeFeesData = (data, collateralConfig) => {
80
- const decimals = collateralConfig.decimals || 18;
81
- return {
82
- realizedTradingFeesCollateral: Math.round(data.realizedTradingFeesCollateral * Math.pow(10, decimals)),
83
- realizedPnlCollateral: Math.round(data.realizedPnlCollateral * Math.pow(10, decimals)),
84
- manuallyRealizedNegativePnlCollateral: Math.round(data.manuallyRealizedNegativePnlCollateral * Math.pow(10, decimals)),
85
- alreadyTransferredNegativePnlCollateral: Math.round(data.alreadyTransferredNegativePnlCollateral * Math.pow(10, decimals)),
86
- virtualAvailableCollateralInDiamond: Math.round(data.virtualAvailableCollateralInDiamond * Math.pow(10, decimals)),
87
- __placeholder: 0,
88
- initialAccFundingFeeP: Math.round(data.initialAccFundingFeeP * 1e10),
89
- initialAccBorrowingFeeP: Math.round(data.initialAccBorrowingFeeP * 1e10),
90
- };
91
- };
92
- exports.encodeTradeFeesData = encodeTradeFeesData;
93
- /**
94
- * @dev Converts UiRealizedPnlData to contract format (for encoding)
95
- * @param data SDK UI realized PnL data
96
- * @param collateralConfig Config for the collateral
97
- * @returns Contract-formatted UI realized PnL data
98
- */
99
- const encodeUiRealizedPnlData = (data, collateralConfig) => {
100
- const decimals = collateralConfig.decimals || 18;
101
- return {
102
- realizedTradingFeesCollateral: Math.round(data.realizedTradingFeesCollateral * Math.pow(10, decimals)),
103
- realizedOldBorrowingFeesCollateral: Math.round(data.realizedOldBorrowingFeesCollateral * Math.pow(10, decimals)),
104
- realizedNewBorrowingFeesCollateral: Math.round(data.realizedNewBorrowingFeesCollateral * Math.pow(10, decimals)),
105
- realizedFundingFeesCollateral: Math.round(data.realizedFundingFeesCollateral * Math.pow(10, decimals)),
106
- realizedPnlPartialCloseCollateral: Math.round(data.realizedPnlPartialCloseCollateral * Math.pow(10, decimals)),
107
- pnlWithdrawnCollateral: Math.round(data.pnlWithdrawnCollateral * Math.pow(10, decimals)),
108
- };
109
- };
110
- exports.encodeUiRealizedPnlData = encodeUiRealizedPnlData;
@@ -1,9 +0,0 @@
1
- /**
2
- * @dev Builder functions for funding fees context
3
- */
4
- import { GlobalTradingVariablesType } from "../../../backend/tradingVariables/types";
5
- import { GetPairFundingFeeContext } from "./pairContext";
6
- /**
7
- * @dev Builds funding fees sub-context for a specific pair
8
- */
9
- export declare const buildFundingContext: (globalTradingVariables: GlobalTradingVariablesType, collateralIndex: number, pairIndex: number, currentTimestamp: number) => GetPairFundingFeeContext | undefined;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- /**
3
- * @dev Builder functions for funding fees context
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.buildFundingContext = void 0;
7
- /**
8
- * @dev Builds funding fees sub-context for a specific pair
9
- */
10
- const buildFundingContext = (globalTradingVariables, collateralIndex, pairIndex, currentTimestamp) => {
11
- var _a, _b, _c, _d, _e;
12
- const collateral = globalTradingVariables.collaterals[collateralIndex - 1];
13
- if (!(collateral === null || collateral === void 0 ? void 0 : collateral.pairFundingFees)) {
14
- return undefined;
15
- }
16
- const params = (_a = collateral.pairFundingFees.params) === null || _a === void 0 ? void 0 : _a[pairIndex];
17
- const data = (_b = collateral.pairFundingFees.data) === null || _b === void 0 ? void 0 : _b[pairIndex];
18
- const pairOi = (_c = collateral.pairOis) === null || _c === void 0 ? void 0 : _c[pairIndex];
19
- if (!params || !data) {
20
- return undefined;
21
- }
22
- return {
23
- params,
24
- data,
25
- pairOi: pairOi
26
- ? {
27
- oiLongToken: ((_d = pairOi.token) === null || _d === void 0 ? void 0 : _d.long) || 0,
28
- oiShortToken: ((_e = pairOi.token) === null || _e === void 0 ? void 0 : _e.short) || 0,
29
- }
30
- : undefined,
31
- currentTimestamp,
32
- // TODO: Add net exposure when available
33
- };
34
- };
35
- exports.buildFundingContext = buildFundingContext;
@@ -1,33 +0,0 @@
1
- /**
2
- * @dev Pair-specific funding fee types and utilities
3
- */
4
- import { FundingFeeParams, PairFundingFeeData, PairGlobalParams, PairOiAfterV10, PairPendingAccFundingFeesResult } from "./types";
5
- /**
6
- * @dev Context for pair-specific funding fee calculations
7
- */
8
- export type GetPairFundingFeeContext = {
9
- currentTimestamp: number;
10
- params: FundingFeeParams;
11
- data: PairFundingFeeData;
12
- globalParams?: PairGlobalParams;
13
- pairOi?: PairOiAfterV10;
14
- netExposureToken?: number;
15
- netExposureUsd?: number;
16
- };
17
- /**
18
- * @dev Input for pair-specific trade funding fee calculation
19
- */
20
- export type PairTradeFundingFeeInput = {
21
- positionSizeCollateral: number;
22
- openPrice: number;
23
- long: boolean;
24
- currentPairPrice: number;
25
- initialAccFundingFeeP: number;
26
- };
27
- /**
28
- * @dev Calculate pending accumulated funding fees for a pair using pair-specific context
29
- * @param currentPairPrice Current price of the pair
30
- * @param context Pair-specific funding context
31
- * @returns Pending accumulated funding fees
32
- */
33
- export declare const getPairPendingAccFundingFees: (currentPairPrice: number, context: GetPairFundingFeeContext) => PairPendingAccFundingFeesResult;