@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,17 +0,0 @@
1
- "use strict";
2
- /**
3
- * @dev Pair-specific funding fee types and utilities
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getPairPendingAccFundingFees = void 0;
7
- const index_1 = require("./index");
8
- /**
9
- * @dev Calculate pending accumulated funding fees for a pair using pair-specific context
10
- * @param currentPairPrice Current price of the pair
11
- * @param context Pair-specific funding context
12
- * @returns Pending accumulated funding fees
13
- */
14
- const getPairPendingAccFundingFees = (currentPairPrice, context) => {
15
- return (0, index_1.getPairPendingAccFundingFees)(context.params, context.data, currentPairPrice, context.pairOi || { oiLongToken: 0, oiShortToken: 0 }, context.netExposureToken || 0, context.netExposureUsd || 0, context.currentTimestamp);
16
- };
17
- exports.getPairPendingAccFundingFees = getPairPendingAccFundingFees;
@@ -1,54 +0,0 @@
1
- /**
2
- * @dev Converters for fee tier data between contract and SDK formats
3
- * @dev All BigNumber values are normalized to floats with appropriate precision
4
- */
5
- import { IFeeTiers } from "../../../contracts/types/generated/GNSMultiCollatDiamond";
6
- import { FeeTier, TraderInfo, TraderEnrollment } from "./types";
7
- /**
8
- * @dev Converts contract fee tier data to SDK format
9
- * @param contractData Contract FeeTier struct
10
- * @returns Normalized fee tier data
11
- */
12
- export declare const convertFeeTier: (contractData: IFeeTiers.FeeTierStructOutput) => FeeTier;
13
- /**
14
- * @dev Converts array of fee tiers from contract format
15
- * @param contractDataArray Array of contract FeeTier structs
16
- * @returns Array of normalized fee tiers
17
- */
18
- export declare const convertFeeTierArray: (contractDataArray: IFeeTiers.FeeTierStructOutput[]) => FeeTier[];
19
- /**
20
- * @dev Converts contract trader info to SDK format
21
- * @param contractData Contract TraderInfo struct
22
- * @returns Normalized trader info
23
- */
24
- export declare const convertTraderInfo: (contractData: IFeeTiers.TraderInfoStructOutput) => TraderInfo;
25
- /**
26
- * @dev Converts contract trader enrollment to SDK format
27
- * @param contractData Contract TraderEnrollment struct
28
- * @returns Normalized trader enrollment
29
- */
30
- export declare const convertTraderEnrollment: (contractData: IFeeTiers.TraderEnrollmentStructOutput) => TraderEnrollment;
31
- /**
32
- * @dev Converts the complete fee tiers configuration from contract format
33
- * @param tiers Array of fee tiers from contract
34
- * @param groupVolumeMultipliers Array of group volume multipliers
35
- * @param currentDay Current day from contract
36
- * @returns Complete fee tiers configuration
37
- */
38
- export declare const convertFeeTiersConfig: (tiers: IFeeTiers.FeeTierStructOutput[], groupVolumeMultipliers: readonly bigint[], currentDay: bigint) => {
39
- tiers: FeeTier[];
40
- groupVolumeMultipliers: number[];
41
- currentDay: number;
42
- };
43
- /**
44
- * @dev Converts trader's fee tier data from contract format
45
- * @param traderInfo Trader info from contract
46
- * @param traderDailyInfo Array of daily points info
47
- * @param traderEnrollment Enrollment status from contract
48
- * @returns Complete trader fee tier data
49
- */
50
- export declare const convertTraderFeeTiersData: (traderInfo: IFeeTiers.TraderInfoStructOutput, traderDailyInfo: readonly bigint[], traderEnrollment: IFeeTiers.TraderEnrollmentStructOutput) => {
51
- traderInfo: TraderInfo;
52
- dailyPoints: number[];
53
- traderEnrollment: TraderEnrollment;
54
- };
@@ -1,81 +0,0 @@
1
- "use strict";
2
- /**
3
- * @dev Converters for fee tier data between contract and SDK formats
4
- * @dev All BigNumber values are normalized to floats with appropriate precision
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.convertTraderFeeTiersData = exports.convertFeeTiersConfig = exports.convertTraderEnrollment = exports.convertTraderInfo = exports.convertFeeTierArray = exports.convertFeeTier = void 0;
8
- /**
9
- * @dev Converts contract fee tier data to SDK format
10
- * @param contractData Contract FeeTier struct
11
- * @returns Normalized fee tier data
12
- */
13
- const convertFeeTier = (contractData) => {
14
- return {
15
- feeMultiplier: Number(contractData.feeMultiplier) / 1e3,
16
- pointsThreshold: Number(contractData.pointsThreshold) / 1e18, // Points in 1e18 precision
17
- };
18
- };
19
- exports.convertFeeTier = convertFeeTier;
20
- /**
21
- * @dev Converts array of fee tiers from contract format
22
- * @param contractDataArray Array of contract FeeTier structs
23
- * @returns Array of normalized fee tiers
24
- */
25
- const convertFeeTierArray = (contractDataArray) => {
26
- return contractDataArray.map(exports.convertFeeTier);
27
- };
28
- exports.convertFeeTierArray = convertFeeTierArray;
29
- /**
30
- * @dev Converts contract trader info to SDK format
31
- * @param contractData Contract TraderInfo struct
32
- * @returns Normalized trader info
33
- */
34
- const convertTraderInfo = (contractData) => {
35
- return {
36
- lastDayUpdated: Number(contractData.lastDayUpdated),
37
- trailingPoints: Number(contractData.trailingPoints) / 1e18, // Points in 1e18 precision
38
- };
39
- };
40
- exports.convertTraderInfo = convertTraderInfo;
41
- /**
42
- * @dev Converts contract trader enrollment to SDK format
43
- * @param contractData Contract TraderEnrollment struct
44
- * @returns Normalized trader enrollment
45
- */
46
- const convertTraderEnrollment = (contractData) => {
47
- return {
48
- status: Number(contractData.status),
49
- };
50
- };
51
- exports.convertTraderEnrollment = convertTraderEnrollment;
52
- /**
53
- * @dev Converts the complete fee tiers configuration from contract format
54
- * @param tiers Array of fee tiers from contract
55
- * @param groupVolumeMultipliers Array of group volume multipliers
56
- * @param currentDay Current day from contract
57
- * @returns Complete fee tiers configuration
58
- */
59
- const convertFeeTiersConfig = (tiers, groupVolumeMultipliers, currentDay) => {
60
- return {
61
- tiers: (0, exports.convertFeeTierArray)(tiers),
62
- groupVolumeMultipliers: groupVolumeMultipliers.map(m => Number(m) / 1e3),
63
- currentDay: Number(currentDay),
64
- };
65
- };
66
- exports.convertFeeTiersConfig = convertFeeTiersConfig;
67
- /**
68
- * @dev Converts trader's fee tier data from contract format
69
- * @param traderInfo Trader info from contract
70
- * @param traderDailyInfo Array of daily points info
71
- * @param traderEnrollment Enrollment status from contract
72
- * @returns Complete trader fee tier data
73
- */
74
- const convertTraderFeeTiersData = (traderInfo, traderDailyInfo, traderEnrollment) => {
75
- return {
76
- traderInfo: (0, exports.convertTraderInfo)(traderInfo),
77
- dailyPoints: traderDailyInfo.map(points => Number(points) / 1e18),
78
- traderEnrollment: (0, exports.convertTraderEnrollment)(traderEnrollment),
79
- };
80
- };
81
- exports.convertTraderFeeTiersData = convertTraderFeeTiersData;
@@ -1,18 +0,0 @@
1
- /**
2
- * @dev Trading fees context builder module
3
- * @dev Provides builder functions for creating trading fee contexts
4
- */
5
- import { Fee, GlobalTradeFeeParams } from "../../types";
6
- import { GlobalTradingVariablesType } from "src/backend/tradingVariables/types";
7
- /**
8
- * @dev Sub-context for trading fees
9
- */
10
- export type TradingFeesSubContext = {
11
- fee: Fee;
12
- globalTradeFeeParams: GlobalTradeFeeParams;
13
- traderFeeMultiplier?: number;
14
- };
15
- /**
16
- * @dev Builds trading fees sub-context
17
- */
18
- export declare const buildTradingFeesContext: (globalTradingVariables: GlobalTradingVariablesType, pairIndex: number, traderFeeMultiplier?: number) => TradingFeesSubContext;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- /**
3
- * @dev Trading fees context builder module
4
- * @dev Provides builder functions for creating trading fee contexts
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.buildTradingFeesContext = void 0;
8
- /**
9
- * @dev Builds trading fees sub-context
10
- */
11
- const buildTradingFeesContext = (globalTradingVariables, pairIndex, traderFeeMultiplier) => {
12
- const { fees, pairs, globalTradeFeeParams } = globalTradingVariables;
13
- const feeIndex = pairs[pairIndex].feeIndex;
14
- return {
15
- fee: fees[feeIndex],
16
- globalTradeFeeParams: globalTradeFeeParams,
17
- traderFeeMultiplier,
18
- };
19
- };
20
- exports.buildTradingFeesContext = buildTradingFeesContext;
@@ -1,25 +0,0 @@
1
- /**
2
- * @dev Liquidation price context builder module
3
- * @dev Provides builder functions for creating liquidation price contexts
4
- */
5
- import { GlobalTradingVariablesType } from "../../backend/tradingVariables/types";
6
- import { TradeContainer, UserPriceImpact } from "../types";
7
- import { GetLiquidationPriceContext } from "./types";
8
- /**
9
- * @dev Builds a complete context for liquidation price calculations
10
- * @param globalTradingVariables The transformed global trading variables from backend
11
- * @param tradeContainer Full trade container with trade, tradeInfo, fees data and liquidation params
12
- * @param additionalParams Additional parameters not available in trading variables
13
- * @returns Complete context ready for getLiquidationPrice
14
- */
15
- export declare const buildLiquidationPriceContext: (globalTradingVariables: GlobalTradingVariablesType, tradeContainer: TradeContainer, additionalParams: {
16
- currentBlock: number;
17
- currentTimestamp: number;
18
- currentPairPrice: number;
19
- spreadP: number;
20
- traderFeeMultiplier?: number;
21
- additionalFeeCollateral?: number;
22
- partialCloseMultiplier?: number;
23
- beforeOpened?: boolean;
24
- userPriceImpact?: UserPriceImpact;
25
- }) => GetLiquidationPriceContext;
@@ -1,59 +0,0 @@
1
- "use strict";
2
- /**
3
- * @dev Liquidation price context builder module
4
- * @dev Provides builder functions for creating liquidation price contexts
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.buildLiquidationPriceContext = void 0;
8
- const builder_1 = require("../fees/borrowing/builder");
9
- const builder_2 = require("../fees/borrowingV2/builder");
10
- const builder_3 = require("../fees/fundingFees/builder");
11
- const builder_4 = require("../fees/trading/builder");
12
- /**
13
- * @dev Builds a complete context for liquidation price calculations
14
- * @param globalTradingVariables The transformed global trading variables from backend
15
- * @param tradeContainer Full trade container with trade, tradeInfo, fees data and liquidation params
16
- * @param additionalParams Additional parameters not available in trading variables
17
- * @returns Complete context ready for getLiquidationPrice
18
- */
19
- const buildLiquidationPriceContext = (globalTradingVariables, tradeContainer, additionalParams) => {
20
- var _a;
21
- const { trade, tradeInfo } = tradeContainer;
22
- const collateralIndex = trade.collateralIndex || 1;
23
- const collateral = globalTradingVariables.collaterals[collateralIndex - 1];
24
- if (!tradeContainer.liquidationParams) {
25
- throw new Error("Liquidation params are required for liquidation price calculation");
26
- }
27
- return {
28
- // Core shared context
29
- core: {
30
- currentBlock: additionalParams.currentBlock,
31
- currentTimestamp: additionalParams.currentTimestamp,
32
- collateralPriceUsd: ((_a = collateral.prices) === null || _a === void 0 ? void 0 : _a.collateralPriceUsd) || 1,
33
- contractsVersion: tradeInfo.contractsVersion,
34
- spreadP: additionalParams.spreadP,
35
- },
36
- // Build sub-contexts using dedicated builders
37
- borrowingV1: (0, builder_1.buildBorrowingV1Context)(globalTradingVariables, collateralIndex, additionalParams.currentBlock),
38
- borrowingV2: (0, builder_2.buildBorrowingV2Context)(globalTradingVariables, collateralIndex, trade.pairIndex, additionalParams.currentTimestamp),
39
- funding: (0, builder_3.buildFundingContext)(globalTradingVariables, collateralIndex, trade.pairIndex, additionalParams.currentTimestamp),
40
- trading: (0, builder_4.buildTradingFeesContext)(globalTradingVariables, trade.pairIndex, additionalParams.traderFeeMultiplier),
41
- // Trade-specific data
42
- tradeData: {
43
- tradeInfo,
44
- tradeFeesData: tradeContainer.tradeFeesData,
45
- liquidationParams: tradeContainer.liquidationParams,
46
- initialAccFeesV1: tradeContainer.initialAccFees,
47
- },
48
- // Additional parameters for liquidation calculation
49
- liquidationSpecific: {
50
- currentPairPrice: additionalParams.currentPairPrice,
51
- additionalFeeCollateral: additionalParams.additionalFeeCollateral || 0,
52
- partialCloseMultiplier: additionalParams.partialCloseMultiplier || 1,
53
- beforeOpened: additionalParams.beforeOpened || false,
54
- isCounterTrade: trade.isCounterTrade || false,
55
- userPriceImpact: additionalParams.userPriceImpact,
56
- },
57
- };
58
- };
59
- exports.buildLiquidationPriceContext = buildLiquidationPriceContext;
@@ -1,23 +0,0 @@
1
- /**
2
- * @dev Converters for liquidation data between contract and SDK formats
3
- */
4
- import { IPairsStorage } from "../../contracts/types/generated/GNSMultiCollatDiamond";
5
- import { LiquidationParams } from "../types";
6
- /**
7
- * @dev Converts contract liquidation params to SDK format
8
- * @param params Group liquidation params from contract
9
- * @returns Normalized liquidation params
10
- */
11
- export declare const convertLiquidationParams: (params: IPairsStorage.GroupLiquidationParamsStructOutput) => LiquidationParams;
12
- /**
13
- * @dev Converts array of liquidation params from contract
14
- * @param paramsArray Array of group liquidation params
15
- * @returns Array of normalized liquidation params
16
- */
17
- export declare const convertLiquidationParamsArray: (paramsArray: IPairsStorage.GroupLiquidationParamsStructOutput[]) => LiquidationParams[];
18
- /**
19
- * @dev Converts liquidation params to contract format (for encoding)
20
- * @param params SDK liquidation params
21
- * @returns Contract-formatted liquidation params
22
- */
23
- export declare const encodeLiquidationParams: (params: LiquidationParams) => IPairsStorage.GroupLiquidationParamsStruct;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- /**
3
- * @dev Converters for liquidation data between contract and SDK formats
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.encodeLiquidationParams = exports.convertLiquidationParamsArray = exports.convertLiquidationParams = void 0;
7
- /**
8
- * @dev Converts contract liquidation params to SDK format
9
- * @param params Group liquidation params from contract
10
- * @returns Normalized liquidation params
11
- */
12
- const convertLiquidationParams = (params) => {
13
- const ONCHAIN_LIQ_THRESHOLD = 0.9;
14
- return {
15
- maxLiqSpreadP: Number(params.maxLiqSpreadP) / 1e10 / 100,
16
- startLiqThresholdP: Number(params.startLiqThresholdP) / 1e10 / 100 || ONCHAIN_LIQ_THRESHOLD,
17
- endLiqThresholdP: Number(params.endLiqThresholdP) / 1e10 / 100 || ONCHAIN_LIQ_THRESHOLD,
18
- startLeverage: Number(params.startLeverage) / 1e3,
19
- endLeverage: Number(params.endLeverage) / 1e3, // 1e3 → float
20
- };
21
- };
22
- exports.convertLiquidationParams = convertLiquidationParams;
23
- /**
24
- * @dev Converts array of liquidation params from contract
25
- * @param paramsArray Array of group liquidation params
26
- * @returns Array of normalized liquidation params
27
- */
28
- const convertLiquidationParamsArray = (paramsArray) => {
29
- return paramsArray.map(exports.convertLiquidationParams);
30
- };
31
- exports.convertLiquidationParamsArray = convertLiquidationParamsArray;
32
- /**
33
- * @dev Converts liquidation params to contract format (for encoding)
34
- * @param params SDK liquidation params
35
- * @returns Contract-formatted liquidation params
36
- */
37
- const encodeLiquidationParams = (params) => {
38
- return {
39
- maxLiqSpreadP: Math.round(params.maxLiqSpreadP * 100 * 1e10),
40
- startLiqThresholdP: Math.round(params.startLiqThresholdP * 100 * 1e10),
41
- endLiqThresholdP: Math.round(params.endLiqThresholdP * 100 * 1e10),
42
- startLeverage: Math.round(params.startLeverage * 1e3),
43
- endLeverage: Math.round(params.endLeverage * 1e3), // float → 1e3
44
- };
45
- };
46
- exports.encodeLiquidationParams = encodeLiquidationParams;
@@ -1,26 +0,0 @@
1
- /**
2
- * @dev Main export file for liquidation module
3
- */
4
- import { Trade, LiquidationParams } from "..";
5
- import { GetLiquidationPriceContext } from "./types";
6
- /**
7
- * @dev Calculate liquidation price with structured context
8
- * @param trade The trade to calculate liquidation price for
9
- * @param context Structured context with all required data
10
- * @returns Liquidation price
11
- */
12
- export declare const getLiquidationPrice: (trade: Trade, context: GetLiquidationPriceContext) => number;
13
- export declare const getLiqPnlThresholdP: (liquidationParams: LiquidationParams | undefined, leverage: number | undefined) => number;
14
- /**
15
- * @dev Simplified wrapper for getTradeLiquidationPrice
16
- * @dev Mirrors the contract's simplified overload
17
- * @param trade The trade to calculate liquidation price for
18
- * @param additionalFeeCollateral Additional fees to consider
19
- * @param currentPairPrice Current pair price
20
- * @param context Context with all required data
21
- * @returns Liquidation price
22
- */
23
- export declare const getTradeLiquidationPriceSimple: (trade: Trade, additionalFeeCollateral: number, currentPairPrice: number, context: GetLiquidationPriceContext) => number;
24
- export { convertLiquidationParams, convertLiquidationParamsArray, encodeLiquidationParams, } from "./converter";
25
- export * from "./types";
26
- export * from "./builder";
@@ -1,142 +0,0 @@
1
- "use strict";
2
- /**
3
- * @dev Main export file for liquidation module
4
- */
5
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = { enumerable: true, get: function() { return m[k]; } };
10
- }
11
- Object.defineProperty(o, k2, desc);
12
- }) : (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- o[k2] = m[k];
15
- }));
16
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.encodeLiquidationParams = exports.convertLiquidationParamsArray = exports.convertLiquidationParams = exports.getTradeLiquidationPriceSimple = exports.getLiqPnlThresholdP = exports.getLiquidationPrice = void 0;
21
- const types_1 = require("../../contracts/types");
22
- const __1 = require("..");
23
- /**
24
- * @dev Calculate liquidation price with structured context
25
- * @param trade The trade to calculate liquidation price for
26
- * @param context Structured context with all required data
27
- * @returns Liquidation price
28
- */
29
- const getLiquidationPrice = (trade, context) => {
30
- var _a, _b, _c;
31
- // Extract legacy parameters from structured context
32
- const { currentPairPrice, additionalFeeCollateral, partialCloseMultiplier, beforeOpened, } = context.liquidationSpecific;
33
- // 1. Calculate liquidation fees
34
- const closingFee = (0, __1.getTotalTradeLiqFeesCollateral)(trade.collateralIndex, trade.user, trade.pairIndex, trade.collateralAmount, {
35
- totalLiqCollateralFeeP: ((_a = context.tradeData.liquidationParams) === null || _a === void 0 ? void 0 : _a.endLiqThresholdP) || 0.9,
36
- globalTradeFeeParams: context.trading.globalTradeFeeParams,
37
- traderFeeMultiplier: context.trading.traderFeeMultiplier,
38
- });
39
- // 2. Calculate holding fees and realized PnL
40
- let holdingFeesTotal = 0;
41
- let totalRealizedPnlCollateral = 0;
42
- if (!beforeOpened && context.tradeData.tradeFeesData && currentPairPrice) {
43
- // V10 data available - calculate full holding fees
44
- const holdingFees = (0, __1.getTradePendingHoldingFeesCollateral)(trade, context.tradeData.tradeInfo, context.tradeData.tradeFeesData, currentPairPrice, {
45
- contractsVersion: context.core.contractsVersion,
46
- currentTimestamp: context.core.currentTimestamp,
47
- collateralPriceUsd: context.core.collateralPriceUsd,
48
- borrowingV1: context.borrowingV1,
49
- borrowingV2: context.borrowingV2,
50
- funding: context.funding,
51
- initialAccFeesV1: context.tradeData.initialAccFeesV1,
52
- });
53
- holdingFeesTotal = holdingFees.totalFeeCollateral;
54
- // Calculate total realized PnL (realized PnL minus realized trading fees)
55
- totalRealizedPnlCollateral =
56
- context.tradeData.tradeFeesData.realizedPnlCollateral -
57
- context.tradeData.tradeFeesData.realizedTradingFeesCollateral;
58
- }
59
- else if (!beforeOpened &&
60
- context.borrowingV1 &&
61
- context.tradeData.initialAccFeesV1) {
62
- // Markets using v1 borrowing fees model
63
- holdingFeesTotal = (0, __1.getBorrowingFee)(trade.collateralAmount * trade.leverage, trade.pairIndex, trade.long, context.tradeData.initialAccFeesV1, context.borrowingV1);
64
- }
65
- // 3. Apply unified formula for all trades
66
- const totalFeesCollateral = closingFee +
67
- (holdingFeesTotal - totalRealizedPnlCollateral) * partialCloseMultiplier +
68
- additionalFeeCollateral;
69
- // 4. Calculate liquidation threshold
70
- const liqThresholdP = (0, exports.getLiqPnlThresholdP)(context.tradeData.liquidationParams, trade.leverage);
71
- // 5. Calculate liquidation price distance
72
- const collateralLiqNegativePnl = trade.collateralAmount * liqThresholdP;
73
- let liqPriceDistance = (trade.openPrice * (collateralLiqNegativePnl - totalFeesCollateral)) /
74
- trade.collateralAmount /
75
- trade.leverage;
76
- // 6. Apply closing spread for v9.2+
77
- if (context.core.contractsVersion >= types_1.ContractsVersion.V9_2 &&
78
- ((((_b = context.tradeData.liquidationParams) === null || _b === void 0 ? void 0 : _b.maxLiqSpreadP) !== undefined &&
79
- context.tradeData.liquidationParams.maxLiqSpreadP > 0) ||
80
- (((_c = context.liquidationSpecific.userPriceImpact) === null || _c === void 0 ? void 0 : _c.fixedSpreadP) !==
81
- undefined &&
82
- context.liquidationSpecific.userPriceImpact.fixedSpreadP > 0))) {
83
- const closingSpreadP = (0, __1.getSpreadP)(context.core.spreadP, true, context.tradeData.liquidationParams, context.liquidationSpecific.userPriceImpact);
84
- liqPriceDistance -= trade.openPrice * closingSpreadP;
85
- }
86
- // 7. Calculate final liquidation price
87
- return trade.long
88
- ? Math.max(trade.openPrice - liqPriceDistance, 0)
89
- : Math.max(trade.openPrice + liqPriceDistance, 0);
90
- };
91
- exports.getLiquidationPrice = getLiquidationPrice;
92
- const getLiqPnlThresholdP = (liquidationParams, leverage) => {
93
- if (liquidationParams === undefined ||
94
- leverage === undefined ||
95
- liquidationParams.maxLiqSpreadP === 0 ||
96
- liquidationParams.startLiqThresholdP === 0 ||
97
- liquidationParams.endLiqThresholdP === 0 ||
98
- liquidationParams.startLeverage === 0 ||
99
- liquidationParams.endLeverage === 0) {
100
- return 0.9;
101
- }
102
- if (leverage < liquidationParams.startLeverage) {
103
- return liquidationParams.startLiqThresholdP;
104
- }
105
- if (leverage > liquidationParams.endLeverage) {
106
- return liquidationParams.endLiqThresholdP;
107
- }
108
- if (liquidationParams.startLiqThresholdP === liquidationParams.endLiqThresholdP) {
109
- return liquidationParams.endLiqThresholdP;
110
- }
111
- return (liquidationParams.startLiqThresholdP -
112
- ((leverage - liquidationParams.startLeverage) *
113
- (liquidationParams.startLiqThresholdP -
114
- liquidationParams.endLiqThresholdP)) /
115
- (liquidationParams.endLeverage - liquidationParams.startLeverage));
116
- };
117
- exports.getLiqPnlThresholdP = getLiqPnlThresholdP;
118
- /**
119
- * @dev Simplified wrapper for getTradeLiquidationPrice
120
- * @dev Mirrors the contract's simplified overload
121
- * @param trade The trade to calculate liquidation price for
122
- * @param additionalFeeCollateral Additional fees to consider
123
- * @param currentPairPrice Current pair price
124
- * @param context Context with all required data
125
- * @returns Liquidation price
126
- */
127
- const getTradeLiquidationPriceSimple = (trade, additionalFeeCollateral, currentPairPrice, context) => {
128
- // Build complete context with additional parameters
129
- const fullContext = Object.assign(Object.assign({}, context), { liquidationSpecific: Object.assign(Object.assign({}, context.liquidationSpecific), { currentPairPrice,
130
- additionalFeeCollateral, partialCloseMultiplier: 1, beforeOpened: false, isCounterTrade: trade.isCounterTrade || false }) });
131
- return (0, exports.getLiquidationPrice)(trade, fullContext);
132
- };
133
- exports.getTradeLiquidationPriceSimple = getTradeLiquidationPriceSimple;
134
- // Converters
135
- var converter_1 = require("./converter");
136
- Object.defineProperty(exports, "convertLiquidationParams", { enumerable: true, get: function () { return converter_1.convertLiquidationParams; } });
137
- Object.defineProperty(exports, "convertLiquidationParamsArray", { enumerable: true, get: function () { return converter_1.convertLiquidationParamsArray; } });
138
- Object.defineProperty(exports, "encodeLiquidationParams", { enumerable: true, get: function () { return converter_1.encodeLiquidationParams; } });
139
- // Types
140
- __exportStar(require("./types"), exports);
141
- // Builder
142
- __exportStar(require("./builder"), exports);
@@ -1,59 +0,0 @@
1
- import { GetBorrowingFeeContext, BorrowingFee } from "./../fees";
2
- import { LiquidationParams, UserPriceImpact, TradeFeesData, TradeInfo } from "./../types";
3
- import { ContractsVersion } from "../../contracts/types";
4
- import { GetPairBorrowingFeeV2Context } from "../fees/borrowingV2";
5
- import { GetPairFundingFeeContext } from "../fees/fundingFees";
6
- import { TradingFeesSubContext } from "../fees/trading/builder";
7
- /**
8
- * @dev Input parameters for getTradeLiquidationPrice
9
- * @dev Mirrors the contract's LiqPriceInput struct
10
- */
11
- export type LiqPriceInput = {
12
- collateralIndex: number;
13
- trader: string;
14
- pairIndex: number;
15
- index: number;
16
- openPrice: number;
17
- long: boolean;
18
- collateral: number;
19
- leverage: number;
20
- additionalFeeCollateral: number;
21
- liquidationParams: LiquidationParams;
22
- currentPairPrice: number;
23
- isCounterTrade: boolean;
24
- partialCloseMultiplier: number;
25
- beforeOpened: boolean;
26
- };
27
- /**
28
- * @dev Structured context for liquidation price calculations
29
- * @dev Follows the same pattern as GetComprehensivePnlContext
30
- */
31
- export type GetLiquidationPriceContext = {
32
- core: {
33
- currentBlock: number;
34
- currentTimestamp: number;
35
- collateralPriceUsd: number;
36
- contractsVersion: ContractsVersion;
37
- spreadP: number;
38
- };
39
- borrowingV1?: GetBorrowingFeeContext;
40
- borrowingV2?: GetPairBorrowingFeeV2Context;
41
- funding?: GetPairFundingFeeContext;
42
- trading: TradingFeesSubContext & {
43
- userPriceImpact?: UserPriceImpact;
44
- };
45
- tradeData: {
46
- tradeInfo: TradeInfo;
47
- tradeFeesData: TradeFeesData;
48
- liquidationParams: LiquidationParams;
49
- initialAccFeesV1?: BorrowingFee.InitialAccFees;
50
- };
51
- liquidationSpecific: {
52
- currentPairPrice: number;
53
- additionalFeeCollateral: number;
54
- partialCloseMultiplier: number;
55
- beforeOpened: boolean;
56
- isCounterTrade: boolean;
57
- userPriceImpact?: UserPriceImpact;
58
- };
59
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- import { LimitOrder, Pair, PairDepth, OiWindowsSettings, OiWindows } from "./types";
2
- export declare const getFulfillmentPrice: (order: LimitOrder, pair: Pair, pairDepth: PairDepth, oiWindowsSettings?: OiWindowsSettings, oiWindows?: OiWindows) => number;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFulfillmentPrice = void 0;
4
- const spread_1 = require("./spread");
5
- const types_1 = require("./types");
6
- const getFulfillmentPrice = (order, pair, pairDepth, oiWindowsSettings, oiWindows) => {
7
- if (!order || !pair) {
8
- return 0;
9
- }
10
- // Get spread percentage
11
- const spreadWithPriceImpactP = (0, spread_1.getSpreadWithPriceImpactP)(pair.spreadP, order.buy, order.positionSize, order.leverage, pairDepth, oiWindowsSettings, oiWindows);
12
- if (spreadWithPriceImpactP === 0) {
13
- return 0;
14
- }
15
- const askingPrice = (order.buy && order.type === types_1.OpenLimitOrderType.REVERSAL) ||
16
- (!order.buy && order.type === types_1.OpenLimitOrderType.MOMENTUM)
17
- ? order.maxPrice
18
- : order.minPrice;
19
- return order.buy
20
- ? askingPrice * (1 + spreadWithPriceImpactP)
21
- : askingPrice * (1 - spreadWithPriceImpactP);
22
- };
23
- exports.getFulfillmentPrice = getFulfillmentPrice;
@@ -1,16 +0,0 @@
1
- import { TradeContainer } from "../types";
2
- import { GlobalTradingVariablesType } from "src/backend/tradingVariables/types";
3
- import { GetComprehensivePnlContext } from "./types";
4
- /**
5
- * @dev Builds a complete context for comprehensive PnL calculations
6
- * @dev Uses sub-context builders to create properly scoped contexts
7
- * @param globalTradingVariables The transformed global trading variables from backend
8
- * @param tradeContainer Full trade container with trade, tradeInfo, fees data and liquidation params
9
- * @param additionalParams Additional parameters not available in trading variables
10
- * @returns Complete context ready for getComprehensivePnl
11
- */
12
- export declare const buildComprehensivePnlContext: (globalTradingVariables: GlobalTradingVariablesType, tradeContainer: TradeContainer, additionalParams: {
13
- currentBlock: number;
14
- currentTimestamp: number;
15
- traderFeeMultiplier?: number;
16
- }) => GetComprehensivePnlContext;