@gainsnetwork/sdk 0.0.0-v10.rc2 → 0.0.0-v10.rc4
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.
- package/lib/backend/globalTrades/index.d.ts +11 -0
- package/lib/backend/globalTrades/index.js +69 -0
- package/lib/backend/index.d.ts +3 -0
- package/lib/backend/index.js +28 -0
- package/lib/backend/tradingVariables/backend.types.d.ts +312 -0
- package/lib/backend/tradingVariables/backend.types.js +2 -0
- package/lib/backend/tradingVariables/converter.d.ts +31 -0
- package/lib/backend/tradingVariables/converter.js +330 -0
- package/lib/backend/tradingVariables/index.d.ts +5 -0
- package/lib/backend/tradingVariables/index.js +95 -0
- package/lib/backend/tradingVariables/types.d.ts +109 -0
- package/lib/backend/tradingVariables/types.js +14 -0
- package/lib/constants.d.ts +10 -0
- package/lib/constants.js +11 -1
- package/lib/contracts/types/generated/GFarmTradingStorageV5.d.ts +1911 -0
- package/lib/contracts/types/generated/GFarmTradingStorageV5.js +2 -0
- package/lib/contracts/types/generated/GNSBorrowingFees.d.ts +1067 -0
- package/lib/contracts/types/generated/GNSBorrowingFees.js +2 -0
- package/lib/contracts/types/generated/GNSBorrowingFeesV6_3_2.d.ts +979 -0
- package/lib/contracts/types/generated/GNSBorrowingFeesV6_3_2.js +2 -0
- package/lib/contracts/types/generated/GNSBorrowingFeesV6_4.d.ts +1058 -0
- package/lib/contracts/types/generated/GNSBorrowingFeesV6_4.js +2 -0
- package/lib/contracts/types/generated/GNSMultiCollatDiamond.d.ts +7 -20
- package/lib/contracts/types/generated/GNSNftRewardsV6.d.ts +533 -0
- package/lib/contracts/types/generated/GNSNftRewardsV6.js +2 -0
- package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.d.ts +613 -0
- package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.js +2 -0
- package/lib/contracts/types/generated/GNSPairInfosV6_1.d.ts +911 -0
- package/lib/contracts/types/generated/GNSPairInfosV6_1.js +2 -0
- package/lib/contracts/types/generated/GNSPairsStorageV6.d.ts +660 -0
- package/lib/contracts/types/generated/GNSPairsStorageV6.js +2 -0
- package/lib/contracts/types/generated/GNSTrading.d.ts +758 -0
- package/lib/contracts/types/generated/GNSTrading.js +2 -0
- package/lib/contracts/types/generated/GNSTradingCallbacks.d.ts +875 -0
- package/lib/contracts/types/generated/GNSTradingCallbacks.js +2 -0
- package/lib/contracts/types/generated/GNSTradingCallbacksV6_3_2.d.ts +806 -0
- package/lib/contracts/types/generated/GNSTradingCallbacksV6_3_2.js +2 -0
- package/lib/contracts/types/generated/GNSTradingCallbacksV6_4.d.ts +821 -0
- package/lib/contracts/types/generated/GNSTradingCallbacksV6_4.js +2 -0
- package/lib/contracts/types/generated/GNSTradingStorage.d.ts +1387 -0
- package/lib/contracts/types/generated/GNSTradingStorage.js +2 -0
- package/lib/contracts/types/generated/GTokenV6_3_2.d.ts +1838 -0
- package/lib/contracts/types/generated/GTokenV6_3_2.js +2 -0
- package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.d.ts +83 -0
- package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.js +2691 -0
- package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_3_2__factory.d.ts +88 -0
- package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_3_2__factory.js +1654 -0
- package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_4__factory.d.ts +113 -0
- package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_4__factory.js +1742 -0
- package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.d.ts +124 -0
- package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.js +1784 -0
- package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +7 -16
- package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.d.ts +100 -0
- package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.js +1116 -0
- package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.d.ts +100 -0
- package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.js +1003 -0
- package/lib/contracts/types/generated/factories/GNSPairInfosV6_1__factory.d.ts +98 -0
- package/lib/contracts/types/generated/factories/GNSPairInfosV6_1__factory.js +1485 -0
- package/lib/contracts/types/generated/factories/GNSPairsStorageV6__factory.d.ts +117 -0
- package/lib/contracts/types/generated/factories/GNSPairsStorageV6__factory.js +1265 -0
- package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_3_2__factory.d.ts +82 -0
- package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_3_2__factory.js +1273 -0
- package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_4__factory.d.ts +82 -0
- package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_4__factory.js +1326 -0
- package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.d.ts +113 -0
- package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.js +1428 -0
- package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.d.ts +96 -0
- package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.js +2241 -0
- package/lib/contracts/types/generated/factories/GNSTrading__factory.d.ts +95 -0
- package/lib/contracts/types/generated/factories/GNSTrading__factory.js +1071 -0
- package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.d.ts +110 -0
- package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.js +2682 -0
- package/lib/contracts/types/generated/factories/GToken__factory.d.ts +7 -0
- package/lib/contracts/types/generated/factories/GToken__factory.js +4 -0
- package/lib/contracts/utils/index.d.ts +0 -3
- package/lib/contracts/utils/index.js +0 -3
- package/lib/contracts/utils/openTrades.js +14 -30
- package/lib/contracts/utils/pairs.js +10 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +5 -0
- package/lib/markets/collateral/converter.d.ts +5 -0
- package/lib/markets/collateral/converter.js +11 -0
- package/lib/markets/collateral/index.d.ts +1 -0
- package/lib/markets/collateral/index.js +17 -0
- package/lib/markets/collateral/types.d.ts +7 -0
- package/lib/markets/collateral/types.js +2 -0
- package/lib/markets/index.d.ts +2 -0
- package/lib/markets/index.js +2 -0
- package/lib/markets/oi/converter.d.ts +63 -0
- package/lib/markets/oi/converter.js +103 -0
- package/lib/markets/oi/fetcher.d.ts +58 -0
- package/lib/markets/oi/fetcher.js +181 -0
- package/lib/markets/oi/index.d.ts +10 -0
- package/lib/markets/oi/index.js +37 -0
- package/lib/markets/oi/types.d.ts +82 -0
- package/lib/markets/oi/types.js +6 -0
- package/lib/markets/oi/validation.d.ts +80 -0
- package/lib/markets/oi/validation.js +172 -0
- package/lib/trade/fees/borrowing/builder.d.ts +14 -0
- package/lib/trade/fees/borrowing/builder.js +33 -0
- package/lib/trade/fees/borrowing/index.d.ts +16 -4
- package/lib/trade/fees/borrowing/index.js +43 -18
- package/lib/trade/fees/borrowingV2/builder.d.ts +6 -0
- package/lib/trade/fees/borrowingV2/builder.js +24 -0
- package/lib/trade/fees/borrowingV2/converter.d.ts +12 -3
- package/lib/trade/fees/borrowingV2/converter.js +29 -18
- package/lib/{contracts/fetch/fees/borrowingFeesV2.d.ts → trade/fees/borrowingV2/fetcher.d.ts} +2 -3
- package/lib/{contracts/fetch/fees/borrowingFeesV2.js → trade/fees/borrowingV2/fetcher.js} +6 -14
- package/lib/trade/fees/borrowingV2/index.d.ts +6 -17
- package/lib/trade/fees/borrowingV2/index.js +10 -37
- package/lib/trade/fees/borrowingV2/types.d.ts +22 -6
- package/lib/trade/fees/converter.d.ts +48 -0
- package/lib/trade/fees/converter.js +110 -0
- package/lib/trade/fees/fundingFees/builder.d.ts +9 -0
- package/lib/trade/fees/fundingFees/builder.js +35 -0
- package/lib/{contracts/fetch/fees/fundingFees.d.ts → trade/fees/fundingFees/fetcher.d.ts} +2 -2
- package/lib/trade/fees/fundingFees/index.d.ts +13 -2
- package/lib/trade/fees/fundingFees/index.js +27 -3
- package/lib/trade/fees/fundingFees/pairContext.d.ts +33 -0
- package/lib/trade/fees/fundingFees/pairContext.js +17 -0
- package/lib/trade/fees/index.d.ts +3 -2
- package/lib/trade/fees/index.js +44 -36
- package/lib/trade/fees/tiers/converter.d.ts +54 -0
- package/lib/trade/fees/tiers/converter.js +81 -0
- package/lib/trade/fees/tiers/index.d.ts +1 -0
- package/lib/trade/fees/tiers/index.js +1 -0
- package/lib/trade/fees/trading/builder.d.ts +18 -0
- package/lib/trade/fees/trading/builder.js +20 -0
- package/lib/trade/fees/trading/holdingFees.d.ts +28 -0
- package/lib/trade/fees/trading/holdingFees.js +66 -0
- package/lib/trade/fees/trading/holdingFeesStructured.d.ts +28 -0
- package/lib/trade/fees/trading/holdingFeesStructured.js +66 -0
- package/lib/trade/fees/trading/index.d.ts +30 -2
- package/lib/trade/fees/trading/index.js +52 -1
- package/lib/trade/fees/trading/types.d.ts +9 -0
- package/lib/trade/index.d.ts +1 -1
- package/lib/trade/index.js +1 -1
- package/lib/trade/liquidation/builder.d.ts +25 -0
- package/lib/trade/liquidation/builder.js +59 -0
- package/lib/trade/liquidation/converter.d.ts +23 -0
- package/lib/trade/liquidation/converter.js +46 -0
- package/lib/trade/liquidation/index.d.ts +26 -0
- package/lib/trade/liquidation/index.js +142 -0
- package/lib/trade/liquidation/types.d.ts +59 -0
- package/lib/trade/liquidation/types.js +2 -0
- package/lib/trade/pnl/builder.d.ts +16 -0
- package/lib/trade/pnl/builder.js +44 -0
- package/lib/trade/pnl/converter.d.ts +47 -0
- package/lib/trade/pnl/converter.js +72 -0
- package/lib/trade/pnl/index.d.ts +77 -0
- package/lib/trade/pnl/index.js +270 -0
- package/lib/trade/pnl/types.d.ts +114 -0
- package/lib/trade/pnl/types.js +5 -0
- package/lib/trade/priceImpact/close/index.d.ts +21 -0
- package/lib/trade/priceImpact/close/index.js +131 -0
- package/lib/trade/priceImpact/close/types.d.ts +43 -0
- package/lib/trade/priceImpact/close/types.js +5 -0
- package/lib/trade/priceImpact/cumulVol/converter.d.ts +31 -0
- package/lib/trade/priceImpact/cumulVol/converter.js +59 -0
- package/lib/trade/priceImpact/cumulVol/index.d.ts +107 -0
- package/lib/trade/priceImpact/cumulVol/index.js +228 -0
- package/lib/trade/priceImpact/index.d.ts +6 -2
- package/lib/trade/priceImpact/index.js +30 -3
- package/lib/trade/priceImpact/open/index.d.ts +22 -0
- package/lib/trade/priceImpact/open/index.js +76 -0
- package/lib/trade/priceImpact/open/types.d.ts +41 -0
- package/lib/trade/priceImpact/open/types.js +5 -0
- package/lib/{contracts/fetch/priceImpact/skew.d.ts → trade/priceImpact/skew/fetcher.d.ts} +2 -2
- package/lib/{contracts/fetch/priceImpact/skew.js → trade/priceImpact/skew/fetcher.js} +6 -6
- package/lib/trade/priceImpact/skew/index.d.ts +1 -0
- package/lib/trade/priceImpact/skew/index.js +4 -0
- package/lib/trade/spread.d.ts +5 -18
- package/lib/trade/spread.js +17 -106
- package/lib/trade/types.d.ts +20 -8
- package/lib/trade/types.js +10 -0
- package/package.json +2 -2
- package/lib/trade/liquidation.d.ts +0 -42
- package/lib/trade/liquidation.js +0 -140
- package/lib/trade/pnl.d.ts +0 -10
- package/lib/trade/pnl.js +0 -38
- /package/lib/{contracts/fetch/fees/fundingFees.js → trade/fees/fundingFees/fetcher.js} +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
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;
|
|
@@ -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;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @dev Trading fee calculations for opening and closing positions
|
|
3
3
|
*/
|
|
4
|
-
import { Fee, PairIndex } from "../../types";
|
|
5
|
-
import {
|
|
4
|
+
import { Fee, PairIndex, Trade, TradeInfo, TradeFeesData } from "../../types";
|
|
5
|
+
import { GetBorrowingFeeContext } from "../borrowing";
|
|
6
|
+
import * as BorrowingFee from "../borrowing/types";
|
|
7
|
+
import { GetPairBorrowingFeeV2Context } from "../borrowingV2";
|
|
8
|
+
import { GetPairFundingFeeContext } from "../fundingFees/pairContext";
|
|
9
|
+
import { GetTradeFeesContext, GetLiquidationFeesContext, GetClosingFeeContext, TradeFeesBreakdown, TradeHoldingFees } from "./types";
|
|
10
|
+
import { ContractsVersion } from "../../../contracts/types";
|
|
6
11
|
/**
|
|
7
12
|
* @dev Returns the total fee for a trade in collateral tokens
|
|
8
13
|
* @dev Mirrors the contract's getTotalTradeFeesCollateral function
|
|
@@ -30,5 +35,28 @@ export declare const getTotalTradeLiqFeesCollateral: (collateralIndex: number, t
|
|
|
30
35
|
* @deprecated Use getTotalTradeFeesCollateral instead
|
|
31
36
|
*/
|
|
32
37
|
export declare const getClosingFee: (collateralAmount: number, leverage: number, pairIndex: PairIndex, pairFee: Fee | undefined, _collateralPriceUsd?: number | undefined, isCounterTrade?: boolean, trader?: string, context?: GetClosingFeeContext) => number;
|
|
38
|
+
/**
|
|
39
|
+
* @dev Context for holding fees calculation with structured sub-contexts
|
|
40
|
+
*/
|
|
41
|
+
export type GetStructuredHoldingFeesContext = {
|
|
42
|
+
contractsVersion: ContractsVersion;
|
|
43
|
+
currentTimestamp: number;
|
|
44
|
+
collateralPriceUsd: number;
|
|
45
|
+
borrowingV1?: GetBorrowingFeeContext;
|
|
46
|
+
borrowingV2?: GetPairBorrowingFeeV2Context;
|
|
47
|
+
funding?: GetPairFundingFeeContext;
|
|
48
|
+
initialAccFeesV1?: BorrowingFee.InitialAccFees;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* @dev Calculates total holding fees for a trade (funding + borrowing fees)
|
|
52
|
+
* @param trade The trade to calculate fees for
|
|
53
|
+
* @param tradeInfo Trade info containing contracts version
|
|
54
|
+
* @param tradeFeesData Trade fees data containing initial acc fees
|
|
55
|
+
* @param currentPairPrice Current pair price
|
|
56
|
+
* @param context Structured context with sub-contexts for each fee type
|
|
57
|
+
* @returns Object containing all holding fee components
|
|
58
|
+
*/
|
|
59
|
+
export declare const getTradePendingHoldingFeesCollateral: (trade: Trade, tradeInfo: TradeInfo, tradeFeesData: TradeFeesData, currentPairPrice: number, context: GetStructuredHoldingFeesContext) => TradeHoldingFees;
|
|
33
60
|
export * from "./types";
|
|
34
61
|
export * from "./converter";
|
|
62
|
+
export * from "./builder";
|
|
@@ -17,8 +17,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
17
17
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.getClosingFee = exports.getTotalTradeLiqFeesCollateral = exports.getTradeFeesCollateral = exports.getTotalTradeFeesCollateral = void 0;
|
|
20
|
+
exports.getTradePendingHoldingFeesCollateral = exports.getClosingFee = exports.getTotalTradeLiqFeesCollateral = exports.getTradeFeesCollateral = exports.getTotalTradeFeesCollateral = void 0;
|
|
21
|
+
const borrowing_1 = require("../borrowing");
|
|
22
|
+
const borrowingV2_1 = require("../borrowingV2");
|
|
23
|
+
const fundingFees_1 = require("../fundingFees");
|
|
21
24
|
const tiers_1 = require("../tiers");
|
|
25
|
+
const types_1 = require("../../../contracts/types");
|
|
22
26
|
/**
|
|
23
27
|
* @dev Returns the total fee for a trade in collateral tokens
|
|
24
28
|
* @dev Mirrors the contract's getTotalTradeFeesCollateral function
|
|
@@ -99,6 +103,53 @@ isCounterTrade = false, trader, context) => {
|
|
|
99
103
|
trader || "", pairIndex, positionSizeCollateral, isCounterTrade, context);
|
|
100
104
|
};
|
|
101
105
|
exports.getClosingFee = getClosingFee;
|
|
106
|
+
/**
|
|
107
|
+
* @dev Calculates total holding fees for a trade (funding + borrowing fees)
|
|
108
|
+
* @param trade The trade to calculate fees for
|
|
109
|
+
* @param tradeInfo Trade info containing contracts version
|
|
110
|
+
* @param tradeFeesData Trade fees data containing initial acc fees
|
|
111
|
+
* @param currentPairPrice Current pair price
|
|
112
|
+
* @param context Structured context with sub-contexts for each fee type
|
|
113
|
+
* @returns Object containing all holding fee components
|
|
114
|
+
*/
|
|
115
|
+
const getTradePendingHoldingFeesCollateral = (trade, tradeInfo, tradeFeesData, currentPairPrice, context) => {
|
|
116
|
+
const positionSizeCollateral = trade.collateralAmount * trade.leverage;
|
|
117
|
+
// Calculate funding fees (v10+ only)
|
|
118
|
+
let fundingFeeCollateral = 0;
|
|
119
|
+
if (context.contractsVersion >= types_1.ContractsVersion.V10 &&
|
|
120
|
+
context.funding &&
|
|
121
|
+
tradeFeesData.initialAccFundingFeeP !== undefined) {
|
|
122
|
+
fundingFeeCollateral = (0, fundingFees_1.getTradeFundingFeesCollateral)(trade, tradeInfo, tradeFeesData, currentPairPrice, Object.assign(Object.assign({}, context.funding), { currentTimestamp: context.currentTimestamp }));
|
|
123
|
+
}
|
|
124
|
+
// Calculate borrowing fees v2 (v10+ only)
|
|
125
|
+
let borrowingFeeCollateral = 0;
|
|
126
|
+
if (context.contractsVersion >= types_1.ContractsVersion.V10 &&
|
|
127
|
+
context.borrowingV2 &&
|
|
128
|
+
tradeFeesData.initialAccBorrowingFeeP !== undefined) {
|
|
129
|
+
borrowingFeeCollateral = (0, borrowingV2_1.getTradeBorrowingFeesCollateral)({
|
|
130
|
+
positionSizeCollateral,
|
|
131
|
+
openPrice: trade.openPrice,
|
|
132
|
+
currentPairPrice,
|
|
133
|
+
initialAccBorrowingFeeP: tradeFeesData.initialAccBorrowingFeeP,
|
|
134
|
+
currentTimestamp: context.currentTimestamp,
|
|
135
|
+
}, context.borrowingV2);
|
|
136
|
+
}
|
|
137
|
+
// Calculate v1 borrowing fees (some markets use v1 indefinitely)
|
|
138
|
+
let borrowingFeeCollateral_old = 0;
|
|
139
|
+
if (context.borrowingV1 && context.initialAccFeesV1) {
|
|
140
|
+
borrowingFeeCollateral_old = (0, borrowing_1.getBorrowingFee)(positionSizeCollateral, trade.pairIndex, trade.long, context.initialAccFeesV1, context.borrowingV1);
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
fundingFeeCollateral,
|
|
144
|
+
borrowingFeeCollateral,
|
|
145
|
+
borrowingFeeCollateral_old,
|
|
146
|
+
totalFeeCollateral: fundingFeeCollateral +
|
|
147
|
+
borrowingFeeCollateral +
|
|
148
|
+
borrowingFeeCollateral_old,
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
exports.getTradePendingHoldingFeesCollateral = getTradePendingHoldingFeesCollateral;
|
|
102
152
|
// Export types
|
|
103
153
|
__exportStar(require("./types"), exports);
|
|
104
154
|
__exportStar(require("./converter"), exports);
|
|
155
|
+
__exportStar(require("./builder"), exports);
|
|
@@ -36,4 +36,13 @@ export type GetLiquidationFeesContext = {
|
|
|
36
36
|
* @dev Legacy support
|
|
37
37
|
*/
|
|
38
38
|
export type GetClosingFeeContext = GetTradeFeesContext;
|
|
39
|
+
/**
|
|
40
|
+
* @dev Holding fees breakdown (funding + borrowing)
|
|
41
|
+
*/
|
|
42
|
+
export type TradeHoldingFees = {
|
|
43
|
+
fundingFeeCollateral: number;
|
|
44
|
+
borrowingFeeCollateral: number;
|
|
45
|
+
borrowingFeeCollateral_old: number;
|
|
46
|
+
totalFeeCollateral: number;
|
|
47
|
+
};
|
|
39
48
|
export type { GlobalTradeFeeParams };
|
package/lib/trade/index.d.ts
CHANGED
package/lib/trade/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./fees"), exports);
|
|
18
|
-
__exportStar(require("./pnl"), exports);
|
|
18
|
+
__exportStar(require("./pnl/index"), exports);
|
|
19
19
|
__exportStar(require("./spread"), exports);
|
|
20
20
|
__exportStar(require("./liquidation"), exports);
|
|
21
21
|
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
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;
|
|
@@ -0,0 +1,59 @@
|
|
|
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;
|
|
@@ -0,0 +1,23 @@
|
|
|
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;
|
|
@@ -0,0 +1,46 @@
|
|
|
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;
|
|
@@ -0,0 +1,26 @@
|
|
|
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";
|