@gainsnetwork/sdk 1.0.0-rc1 → 1.0.0-rc11
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/tradingVariables/index.js +5 -5
- package/lib/constants.d.ts +16 -0
- package/lib/constants.js +22 -7
- package/lib/contracts/types/generated/GNSMultiCollatDiamond.d.ts +20 -7
- package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +16 -7
- package/lib/contracts/types/generated/factories/GToken__factory.d.ts +0 -7
- package/lib/contracts/types/generated/factories/GToken__factory.js +0 -4
- package/lib/contracts/utils/pairs.js +16 -0
- package/lib/markets/holdingFees/index.js +4 -4
- package/lib/trade/fees/borrowing/builder.js +1 -0
- package/lib/trade/fees/borrowing/index.d.ts +4 -2
- package/lib/trade/fees/borrowing/index.js +25 -9
- package/lib/trade/fees/borrowingV2/fetcher.d.ts +1 -0
- package/lib/trade/fees/fundingFees/converter.js +1 -1
- package/lib/trade/fees/index.d.ts +1 -0
- package/lib/trade/fees/index.js +4 -2
- package/lib/trade/fees/trading/index.js +1 -1
- package/lib/trade/pnl/index.d.ts +2 -0
- package/lib/trade/pnl/index.js +3 -2
- package/lib/trade/priceImpact/open/index.js +1 -0
- package/lib/trade/priceImpact/open/types.d.ts +1 -0
- package/lib/trade/types.d.ts +17 -1
- package/lib/trade/types.js +16 -0
- package/package.json +1 -1
- package/lib/contracts/types/generated/GFarmTradingStorageV5.d.ts +0 -1911
- package/lib/contracts/types/generated/GFarmTradingStorageV5.js +0 -2
- package/lib/contracts/types/generated/GNSBorrowingFees.d.ts +0 -1067
- package/lib/contracts/types/generated/GNSBorrowingFees.js +0 -2
- package/lib/contracts/types/generated/GNSBorrowingFeesV6_3_2.d.ts +0 -979
- package/lib/contracts/types/generated/GNSBorrowingFeesV6_3_2.js +0 -2
- package/lib/contracts/types/generated/GNSBorrowingFeesV6_4.d.ts +0 -1058
- package/lib/contracts/types/generated/GNSBorrowingFeesV6_4.js +0 -2
- package/lib/contracts/types/generated/GNSNftRewardsV6.d.ts +0 -533
- package/lib/contracts/types/generated/GNSNftRewardsV6.js +0 -2
- package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.d.ts +0 -613
- package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.js +0 -2
- package/lib/contracts/types/generated/GNSPairInfosV6_1.d.ts +0 -911
- package/lib/contracts/types/generated/GNSPairInfosV6_1.js +0 -2
- package/lib/contracts/types/generated/GNSPairsStorageV6.d.ts +0 -660
- package/lib/contracts/types/generated/GNSPairsStorageV6.js +0 -2
- package/lib/contracts/types/generated/GNSTrading.d.ts +0 -758
- package/lib/contracts/types/generated/GNSTrading.js +0 -2
- package/lib/contracts/types/generated/GNSTradingCallbacks.d.ts +0 -875
- package/lib/contracts/types/generated/GNSTradingCallbacks.js +0 -2
- package/lib/contracts/types/generated/GNSTradingCallbacksV6_3_2.d.ts +0 -806
- package/lib/contracts/types/generated/GNSTradingCallbacksV6_3_2.js +0 -2
- package/lib/contracts/types/generated/GNSTradingCallbacksV6_4.d.ts +0 -821
- package/lib/contracts/types/generated/GNSTradingCallbacksV6_4.js +0 -2
- package/lib/contracts/types/generated/GNSTradingStorage.d.ts +0 -1387
- package/lib/contracts/types/generated/GNSTradingStorage.js +0 -2
- package/lib/contracts/types/generated/GTokenV6_3_2.d.ts +0 -1838
- package/lib/contracts/types/generated/GTokenV6_3_2.js +0 -2
- package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.d.ts +0 -83
- package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.js +0 -2691
- package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_3_2__factory.d.ts +0 -88
- package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_3_2__factory.js +0 -1654
- package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_4__factory.d.ts +0 -113
- package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_4__factory.js +0 -1742
- package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.d.ts +0 -124
- package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.js +0 -1784
- package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.d.ts +0 -100
- package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.js +0 -1116
- package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.d.ts +0 -100
- package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.js +0 -1003
- package/lib/contracts/types/generated/factories/GNSPairInfosV6_1__factory.d.ts +0 -98
- package/lib/contracts/types/generated/factories/GNSPairInfosV6_1__factory.js +0 -1485
- package/lib/contracts/types/generated/factories/GNSPairsStorageV6__factory.d.ts +0 -117
- package/lib/contracts/types/generated/factories/GNSPairsStorageV6__factory.js +0 -1265
- package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_3_2__factory.d.ts +0 -82
- package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_3_2__factory.js +0 -1273
- package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_4__factory.d.ts +0 -82
- package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_4__factory.js +0 -1326
- package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.d.ts +0 -113
- package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.js +0 -1428
- package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.d.ts +0 -96
- package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.js +0 -2241
- package/lib/contracts/types/generated/factories/GNSTrading__factory.d.ts +0 -95
- package/lib/contracts/types/generated/factories/GNSTrading__factory.js +0 -1071
- package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.d.ts +0 -110
- package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.js +0 -2682
- package/lib/markets/oi/fetcher.d.ts +0 -58
- package/lib/markets/oi/fetcher.js +0 -181
- package/lib/markets/oi/validation.d.ts +0 -80
- package/lib/markets/oi/validation.js +0 -172
- package/lib/trade/fees/holdingFees/index.d.ts +0 -46
- package/lib/trade/fees/holdingFees/index.js +0 -105
- package/lib/trade/fees/holdingFees/types.d.ts +0 -23
- package/lib/trade/fees/holdingFees/types.js +0 -5
- package/lib/trade/fees/trading/holdingFees.d.ts +0 -28
- package/lib/trade/fees/trading/holdingFees.js +0 -66
- package/lib/trade/fees/trading/holdingFeesStructured.d.ts +0 -28
- package/lib/trade/fees/trading/holdingFeesStructured.js +0 -66
|
@@ -27,6 +27,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.BorrowingFee = exports.borrowingFeeUtils = exports.withinMaxGroupOi = exports.getBorrowingFee = void 0;
|
|
30
|
+
const __1 = require("../../..");
|
|
30
31
|
/**
|
|
31
32
|
* @dev Calculates borrowing fees using v1 model (block-based with groups)
|
|
32
33
|
* @dev Still actively used by markets that haven't migrated to v2
|
|
@@ -38,7 +39,7 @@ exports.BorrowingFee = exports.borrowingFeeUtils = exports.withinMaxGroupOi = ex
|
|
|
38
39
|
* @param context Context with current block, fee data, and collateral price
|
|
39
40
|
* @returns Borrowing fee in collateral tokens
|
|
40
41
|
*/
|
|
41
|
-
const getBorrowingFee = (posDai, pairIndex, long, initialAccFees, context) => {
|
|
42
|
+
const getBorrowingFee = (posDai, pairIndex, long, initialAccFees, currentPairPrice, context) => {
|
|
42
43
|
if (pairIndex === undefined) {
|
|
43
44
|
throw new Error("pairIndex is required for borrowing fee calculations");
|
|
44
45
|
}
|
|
@@ -50,12 +51,19 @@ const getBorrowingFee = (posDai, pairIndex, long, initialAccFees, context) => {
|
|
|
50
51
|
const firstPairGroup = (pairGroups === null || pairGroups === void 0 ? void 0 : pairGroups.length) > 0 ? pairGroups[0] : undefined;
|
|
51
52
|
let fee = 0;
|
|
52
53
|
if (!firstPairGroup || firstPairGroup.block > initialAccFees.block) {
|
|
53
|
-
const openInterest =
|
|
54
|
+
const openInterest = (0, __1.getPairTotalOisDynamicCollateral)(pairIndex, {
|
|
55
|
+
pairOis: context.pairOis,
|
|
56
|
+
currentPairPrice,
|
|
57
|
+
});
|
|
54
58
|
fee =
|
|
55
59
|
(!firstPairGroup
|
|
56
60
|
? getPairPendingAccFee(pairIndex, context.currentBlock, long, {
|
|
57
61
|
pairs,
|
|
58
|
-
openInterest
|
|
62
|
+
openInterest: {
|
|
63
|
+
long: openInterest.long,
|
|
64
|
+
short: openInterest.short,
|
|
65
|
+
max: context.pairOis[pairIndex].maxCollateral,
|
|
66
|
+
},
|
|
59
67
|
collateralPriceUsd: context.collateralPriceUsd,
|
|
60
68
|
})
|
|
61
69
|
: long
|
|
@@ -63,11 +71,12 @@ const getBorrowingFee = (posDai, pairIndex, long, initialAccFees, context) => {
|
|
|
63
71
|
: firstPairGroup.pairAccFeeShort) - initialAccFees.accPairFee;
|
|
64
72
|
}
|
|
65
73
|
for (let i = pairGroups.length; i > 0; i--) {
|
|
66
|
-
const { deltaGroup, deltaPair, beforeTradeOpen } = getPairGroupAccFeesDeltas(i - 1, pairGroups, initialAccFees, pairIndex, long, {
|
|
74
|
+
const { deltaGroup, deltaPair, beforeTradeOpen } = getPairGroupAccFeesDeltas(i - 1, pairGroups, initialAccFees, pairIndex, long, currentPairPrice, {
|
|
67
75
|
currentBlock: context.currentBlock,
|
|
68
76
|
groups,
|
|
69
77
|
pairs,
|
|
70
78
|
collateralPriceUsd: context.collateralPriceUsd,
|
|
79
|
+
pairOis: context.pairOis,
|
|
71
80
|
});
|
|
72
81
|
fee += Math.max(deltaGroup, deltaPair);
|
|
73
82
|
if (beforeTradeOpen) {
|
|
@@ -101,7 +110,7 @@ const getPairGroupIndex = (pairIndex, context) => {
|
|
|
101
110
|
const getPairPendingAccFees = (pairIndex, currentBlock, context) => {
|
|
102
111
|
const { pairs, openInterest: { long, short }, collateralPriceUsd, } = context;
|
|
103
112
|
const pair = pairs[pairIndex];
|
|
104
|
-
return getPendingAccFees(pair.accFeeLong, pair.accFeeShort, long, short, pair.feePerBlock, currentBlock, pair.accLastUpdatedBlock,
|
|
113
|
+
return getPendingAccFees(pair.accFeeLong, pair.accFeeShort, long, short, pair.feePerBlock, currentBlock, pair.accLastUpdatedBlock, context.openInterest.max, pair.feeExponent, pair.feePerBlockCap, collateralPriceUsd);
|
|
105
114
|
};
|
|
106
115
|
const getPairPendingAccFee = (pairIndex, currentBlock, long, context) => {
|
|
107
116
|
const { accFeeLong, accFeeShort } = getPairPendingAccFees(pairIndex, currentBlock, context);
|
|
@@ -117,20 +126,27 @@ const getGroupPendingAccFee = (groupIndex, currentBlock, long, context) => {
|
|
|
117
126
|
const { accFeeLong, accFeeShort } = getGroupPendingAccFees(groupIndex, currentBlock, context);
|
|
118
127
|
return long ? accFeeLong : accFeeShort;
|
|
119
128
|
};
|
|
120
|
-
const getPairGroupAccFeesDeltas = (i, pairGroups, initialFees, pairIndex, long, context) => {
|
|
129
|
+
const getPairGroupAccFeesDeltas = (i, pairGroups, initialFees, pairIndex, long, currentPairPrice, context) => {
|
|
121
130
|
const group = pairGroups[i];
|
|
122
131
|
const beforeTradeOpen = group.block < initialFees.block;
|
|
123
132
|
let deltaGroup, deltaPair;
|
|
124
133
|
if (i == pairGroups.length - 1) {
|
|
125
134
|
const { currentBlock, groups, pairs, collateralPriceUsd } = context;
|
|
126
|
-
const openInterest =
|
|
135
|
+
const openInterest = (0, __1.getPairTotalOisDynamicCollateral)(pairIndex, {
|
|
136
|
+
pairOis: context.pairOis,
|
|
137
|
+
currentPairPrice,
|
|
138
|
+
});
|
|
127
139
|
deltaGroup = getGroupPendingAccFee(group.groupIndex, currentBlock, long, {
|
|
128
140
|
groups,
|
|
129
141
|
collateralPriceUsd,
|
|
130
142
|
});
|
|
131
143
|
deltaPair = getPairPendingAccFee(pairIndex, currentBlock, long, {
|
|
132
144
|
pairs,
|
|
133
|
-
openInterest
|
|
145
|
+
openInterest: {
|
|
146
|
+
long: openInterest.long,
|
|
147
|
+
short: openInterest.short,
|
|
148
|
+
max: context.pairOis[pairIndex].maxCollateral,
|
|
149
|
+
},
|
|
134
150
|
collateralPriceUsd,
|
|
135
151
|
});
|
|
136
152
|
}
|
|
@@ -180,7 +196,7 @@ collateralPriceUsd) => {
|
|
|
180
196
|
const maxNetOi = maxOiUsd * maxP;
|
|
181
197
|
// Calculate the minimum acc fee delta (applies to both sides)
|
|
182
198
|
const minDelta = minNetOi > 0
|
|
183
|
-
? getPendingAccFeesDelta(blockDistance, feePerBlock,
|
|
199
|
+
? getPendingAccFeesDelta(blockDistance, feePerBlock, minNetOi, maxOiUsd, feeExponent)
|
|
184
200
|
: 0;
|
|
185
201
|
// Calculate the actual acc fee (using capped oi of 100% or less)
|
|
186
202
|
const delta = netOi > minNetOi
|
|
@@ -74,7 +74,7 @@ exports.convertPairFundingFeeDataArray = convertPairFundingFeeDataArray;
|
|
|
74
74
|
*/
|
|
75
75
|
const convertPairGlobalParams = (contractParams) => {
|
|
76
76
|
return {
|
|
77
|
-
maxSkewCollateral: Number(contractParams.maxSkewCollateral),
|
|
77
|
+
maxSkewCollateral: Number(contractParams.maxSkewCollateral) / 1e10,
|
|
78
78
|
};
|
|
79
79
|
};
|
|
80
80
|
exports.convertPairGlobalParams = convertPairGlobalParams;
|
|
@@ -6,5 +6,6 @@ export { convertTradeFeesData, convertTradeFeesDataArray, convertUiRealizedPnlDa
|
|
|
6
6
|
export { BorrowingFeeV2, borrowingFeeV2Utils, getPairPendingAccBorrowingFees as getPairPendingAccBorrowingFeesV2, getTradeBorrowingFeesCollateral as getTradeBorrowingFeesCollateralV2, getPairBorrowingFees as getPairBorrowingFeesV2, MAX_BORROWING_RATE_PER_SECOND as MAX_BORROWING_RATE_PER_SECOND_V2, BORROWING_V2_PRECISION, } from "./borrowingV2";
|
|
7
7
|
export { convertBorrowingFeeParams as convertBorrowingFeeParamsV2, convertBorrowingFeeParamsArray as convertBorrowingFeeParamsArrayV2, convertPairBorrowingFeeData as convertPairBorrowingFeeDataV2, convertPairBorrowingFeeDataArray as convertPairBorrowingFeeDataArrayV2, convertTradeInitialAccFees as convertTradeInitialAccFeesV2, convertTradeInitialAccFeesArray as convertTradeInitialAccFeesArrayV2, createBorrowingV2Context, isValidBorrowingRate as isValidBorrowingRateV2, borrowingRateToAPR as borrowingRateToAPRV2, aprToBorrowingRate as aprToBorrowingRateV2, } from "./borrowingV2/converter";
|
|
8
8
|
export { fetchBorrowingFeeParamsV2, fetchPairBorrowingFeeDataV2, fetchTradeBorrowingFeesCollateralV2, fetchPairPendingAccBorrowingFeesV2, fetchAllBorrowingV2Data, createBorrowingV2ContextFromContract, createBorrowingV2ContextFromArrays, fetchBorrowingV2DataForPairs, } from "./borrowingV2/fetcher";
|
|
9
|
+
export { buildBorrowingV2Context } from "./borrowingV2/builder";
|
|
9
10
|
export { FundingFees, getCurrentFundingVelocityPerYear, getSecondsToReachZeroRate, getAvgFundingRatePerSecondP, getLongShortAprMultiplier, getPairPendingAccFundingFees, getTradeFundingFeesCollateral, getTradeFundingFeesCollateralSimple, getTradeFundingFees, } from "./fundingFees";
|
|
10
11
|
export { convertFundingFeeParams, convertFundingFeeParamsArray, convertPairFundingFeeData, convertPairFundingFeeDataArray, convertPairGlobalParams, convertPairGlobalParamsArray, convertTradeInitialAccFundingFees, createFundingFeeContext, isValidFundingRate, fundingRateToAPR, aprToFundingRate, calculateVelocityFromSkew, FUNDING_FEES_PRECISION, } from "./fundingFees/converter";
|
package/lib/trade/fees/index.js
CHANGED
|
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
18
|
-
exports.FUNDING_FEES_PRECISION = exports.calculateVelocityFromSkew = exports.aprToFundingRate = void 0;
|
|
17
|
+
exports.isValidFundingRate = exports.createFundingFeeContext = exports.convertTradeInitialAccFundingFees = exports.convertPairGlobalParamsArray = exports.convertPairGlobalParams = exports.convertPairFundingFeeDataArray = exports.convertPairFundingFeeData = exports.convertFundingFeeParamsArray = exports.convertFundingFeeParams = exports.getTradeFundingFees = exports.getTradeFundingFeesCollateralSimple = exports.getTradeFundingFeesCollateral = exports.getPairPendingAccFundingFees = exports.getLongShortAprMultiplier = exports.getAvgFundingRatePerSecondP = exports.getSecondsToReachZeroRate = exports.getCurrentFundingVelocityPerYear = exports.FundingFees = exports.buildBorrowingV2Context = exports.fetchBorrowingV2DataForPairs = exports.createBorrowingV2ContextFromArrays = exports.createBorrowingV2ContextFromContract = exports.fetchAllBorrowingV2Data = exports.fetchPairPendingAccBorrowingFeesV2 = exports.fetchTradeBorrowingFeesCollateralV2 = exports.fetchPairBorrowingFeeDataV2 = exports.fetchBorrowingFeeParamsV2 = exports.aprToBorrowingRateV2 = exports.borrowingRateToAPRV2 = exports.isValidBorrowingRateV2 = exports.createBorrowingV2Context = exports.convertTradeInitialAccFeesArrayV2 = exports.convertTradeInitialAccFeesV2 = exports.convertPairBorrowingFeeDataArrayV2 = exports.convertPairBorrowingFeeDataV2 = exports.convertBorrowingFeeParamsArrayV2 = exports.convertBorrowingFeeParamsV2 = exports.BORROWING_V2_PRECISION = exports.MAX_BORROWING_RATE_PER_SECOND_V2 = exports.getPairBorrowingFeesV2 = exports.getTradeBorrowingFeesCollateralV2 = exports.getPairPendingAccBorrowingFeesV2 = exports.borrowingFeeV2Utils = exports.BorrowingFeeV2 = exports.encodeUiRealizedPnlData = exports.encodeTradeFeesData = exports.convertUiRealizedPnlDataArray = exports.convertUiRealizedPnlData = exports.convertTradeFeesDataArray = exports.convertTradeFeesData = void 0;
|
|
18
|
+
exports.FUNDING_FEES_PRECISION = exports.calculateVelocityFromSkew = exports.aprToFundingRate = exports.fundingRateToAPR = void 0;
|
|
19
19
|
__exportStar(require("./borrowing"), exports);
|
|
20
20
|
__exportStar(require("./tiers"), exports);
|
|
21
21
|
__exportStar(require("./trading"), exports);
|
|
@@ -58,6 +58,8 @@ Object.defineProperty(exports, "fetchAllBorrowingV2Data", { enumerable: true, ge
|
|
|
58
58
|
Object.defineProperty(exports, "createBorrowingV2ContextFromContract", { enumerable: true, get: function () { return fetcher_1.createBorrowingV2ContextFromContract; } });
|
|
59
59
|
Object.defineProperty(exports, "createBorrowingV2ContextFromArrays", { enumerable: true, get: function () { return fetcher_1.createBorrowingV2ContextFromArrays; } });
|
|
60
60
|
Object.defineProperty(exports, "fetchBorrowingV2DataForPairs", { enumerable: true, get: function () { return fetcher_1.fetchBorrowingV2DataForPairs; } });
|
|
61
|
+
var builder_1 = require("./borrowingV2/builder");
|
|
62
|
+
Object.defineProperty(exports, "buildBorrowingV2Context", { enumerable: true, get: function () { return builder_1.buildBorrowingV2Context; } });
|
|
61
63
|
// Funding Fees exports
|
|
62
64
|
var fundingFees_1 = require("./fundingFees");
|
|
63
65
|
Object.defineProperty(exports, "FundingFees", { enumerable: true, get: function () { return fundingFees_1.FundingFees; } });
|
|
@@ -137,7 +137,7 @@ const getTradePendingHoldingFeesCollateral = (trade, tradeInfo, tradeFeesData, c
|
|
|
137
137
|
// Calculate v1 borrowing fees (some markets use v1 indefinitely)
|
|
138
138
|
let borrowingFeeCollateral_old = 0;
|
|
139
139
|
if (context.borrowingV1 && context.initialAccFees) {
|
|
140
|
-
borrowingFeeCollateral_old = (0, borrowing_1.getBorrowingFee)(positionSizeCollateral, trade.pairIndex, trade.long, context.initialAccFees, context.borrowingV1);
|
|
140
|
+
borrowingFeeCollateral_old = (0, borrowing_1.getBorrowingFee)(positionSizeCollateral, trade.pairIndex, trade.long, context.initialAccFees, currentPairPrice, context.borrowingV1);
|
|
141
141
|
}
|
|
142
142
|
return {
|
|
143
143
|
fundingFeeCollateral,
|
package/lib/trade/pnl/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { Trade, TradeInfo, LiquidationParams, Fee, GlobalTradeFeeParams, TradeFe
|
|
|
6
6
|
import { ComprehensivePnlResult, GetComprehensivePnlContext } from "./types";
|
|
7
7
|
import { BorrowingFee } from "../fees/borrowing";
|
|
8
8
|
import { ContractsVersion } from "../../contracts/types";
|
|
9
|
+
import { UnifiedPairOi } from "src/markets";
|
|
9
10
|
/**
|
|
10
11
|
* @dev Gets trade realized PnL components from TradeFeesData
|
|
11
12
|
* @dev Mirrors contract's getTradeRealizedPnlCollateral function
|
|
@@ -60,6 +61,7 @@ export type GetPnlContext = {
|
|
|
60
61
|
fee: Fee;
|
|
61
62
|
globalTradeFeeParams: GlobalTradeFeeParams;
|
|
62
63
|
traderFeeMultiplier?: number;
|
|
64
|
+
pairOis: UnifiedPairOi[];
|
|
63
65
|
};
|
|
64
66
|
/**
|
|
65
67
|
* @dev Legacy PnL calculation function
|
package/lib/trade/pnl/index.js
CHANGED
|
@@ -91,7 +91,7 @@ const getComprehensivePnl = (trade, marketPrice, executionPrice, tradeInfo, cont
|
|
|
91
91
|
// Calculate position size
|
|
92
92
|
const positionSizeCollateral = trade.collateralAmount * trade.leverage;
|
|
93
93
|
// Calculate holding fees - always use getTradePendingHoldingFeesCollateral
|
|
94
|
-
const pendingHoldingFees = (0, trading_1.getTradePendingHoldingFeesCollateral)(trade, tradeInfo, context.tradeData.tradeFeesData,
|
|
94
|
+
const pendingHoldingFees = (0, trading_1.getTradePendingHoldingFeesCollateral)(trade, tradeInfo, context.tradeData.tradeFeesData, marketPrice, {
|
|
95
95
|
contractsVersion: context.core.contractsVersion,
|
|
96
96
|
currentTimestamp: context.core.currentTimestamp,
|
|
97
97
|
collateralPriceUsd: context.core.collateralPriceUsd,
|
|
@@ -206,11 +206,12 @@ const getPnl = (price, trade, _tradeInfo, initialAccFees, liquidationParams, use
|
|
|
206
206
|
context.groups &&
|
|
207
207
|
context.currentBlock !== undefined &&
|
|
208
208
|
context.collateralPriceUsd !== undefined) {
|
|
209
|
-
pnlCollat -= (0, borrowing_1.getBorrowingFee)(posCollat * trade.leverage, trade.pairIndex, trade.long, initialAccFees, {
|
|
209
|
+
pnlCollat -= (0, borrowing_1.getBorrowingFee)(posCollat * trade.leverage, trade.pairIndex, trade.long, initialAccFees, price, {
|
|
210
210
|
currentBlock: context.currentBlock,
|
|
211
211
|
groups: context.groups,
|
|
212
212
|
pairs: context.pairs,
|
|
213
213
|
collateralPriceUsd: context.collateralPriceUsd,
|
|
214
|
+
pairOis: context.pairOis,
|
|
214
215
|
});
|
|
215
216
|
}
|
|
216
217
|
let pnlPercentage = (pnlCollat / posCollat) * 100;
|
|
@@ -56,6 +56,7 @@ const getTradeOpeningPriceImpact = (input, context) => {
|
|
|
56
56
|
return {
|
|
57
57
|
priceAfterImpact,
|
|
58
58
|
percentProfitP,
|
|
59
|
+
fixedSpreadP: spreadP,
|
|
59
60
|
cumulVolPriceImpactP,
|
|
60
61
|
baseSkewPriceImpactP: skewPriceImpactObject.basePriceImpactP,
|
|
61
62
|
tradeSkewPriceImpactP: skewPriceImpactObject.tradePriceImpactP,
|
|
@@ -35,6 +35,7 @@ export type TradeOpeningPriceImpactContext = {
|
|
|
35
35
|
export type TradeOpeningPriceImpactResult = {
|
|
36
36
|
priceAfterImpact: number;
|
|
37
37
|
percentProfitP: number;
|
|
38
|
+
fixedSpreadP: number;
|
|
38
39
|
cumulVolPriceImpactP: number;
|
|
39
40
|
baseSkewPriceImpactP: number;
|
|
40
41
|
tradeSkewPriceImpactP: number;
|
package/lib/trade/types.d.ts
CHANGED
|
@@ -719,5 +719,21 @@ export declare enum PairIndex {
|
|
|
719
719
|
SBETUSD = 393,
|
|
720
720
|
PLTRUSD = 394,
|
|
721
721
|
BIDUUSD = 395,
|
|
722
|
-
ROKUUSD = 396
|
|
722
|
+
ROKUUSD = 396,
|
|
723
|
+
LMTUSD = 397,
|
|
724
|
+
RIOTUSD = 398,
|
|
725
|
+
MARAUSD = 399,
|
|
726
|
+
LOKAUSD = 400,
|
|
727
|
+
STOUSD = 401,
|
|
728
|
+
FUNUSD = 402,
|
|
729
|
+
KNCUSD = 403,
|
|
730
|
+
HUSD = 404,
|
|
731
|
+
ICNTUSD = 405,
|
|
732
|
+
NEWTUSD = 406,
|
|
733
|
+
PUMPUSD = 407,
|
|
734
|
+
SAROSUSD = 408,
|
|
735
|
+
SPKUSD = 409,
|
|
736
|
+
ERAUSD = 410,
|
|
737
|
+
BGSCUSD = 411,
|
|
738
|
+
TAGUSD = 412
|
|
723
739
|
}
|
package/lib/trade/types.js
CHANGED
|
@@ -426,4 +426,20 @@ var PairIndex;
|
|
|
426
426
|
PairIndex[PairIndex["PLTRUSD"] = 394] = "PLTRUSD";
|
|
427
427
|
PairIndex[PairIndex["BIDUUSD"] = 395] = "BIDUUSD";
|
|
428
428
|
PairIndex[PairIndex["ROKUUSD"] = 396] = "ROKUUSD";
|
|
429
|
+
PairIndex[PairIndex["LMTUSD"] = 397] = "LMTUSD";
|
|
430
|
+
PairIndex[PairIndex["RIOTUSD"] = 398] = "RIOTUSD";
|
|
431
|
+
PairIndex[PairIndex["MARAUSD"] = 399] = "MARAUSD";
|
|
432
|
+
PairIndex[PairIndex["LOKAUSD"] = 400] = "LOKAUSD";
|
|
433
|
+
PairIndex[PairIndex["STOUSD"] = 401] = "STOUSD";
|
|
434
|
+
PairIndex[PairIndex["FUNUSD"] = 402] = "FUNUSD";
|
|
435
|
+
PairIndex[PairIndex["KNCUSD"] = 403] = "KNCUSD";
|
|
436
|
+
PairIndex[PairIndex["HUSD"] = 404] = "HUSD";
|
|
437
|
+
PairIndex[PairIndex["ICNTUSD"] = 405] = "ICNTUSD";
|
|
438
|
+
PairIndex[PairIndex["NEWTUSD"] = 406] = "NEWTUSD";
|
|
439
|
+
PairIndex[PairIndex["PUMPUSD"] = 407] = "PUMPUSD";
|
|
440
|
+
PairIndex[PairIndex["SAROSUSD"] = 408] = "SAROSUSD";
|
|
441
|
+
PairIndex[PairIndex["SPKUSD"] = 409] = "SPKUSD";
|
|
442
|
+
PairIndex[PairIndex["ERAUSD"] = 410] = "ERAUSD";
|
|
443
|
+
PairIndex[PairIndex["BGSCUSD"] = 411] = "BGSCUSD";
|
|
444
|
+
PairIndex[PairIndex["TAGUSD"] = 412] = "TAGUSD";
|
|
429
445
|
})(PairIndex = exports.PairIndex || (exports.PairIndex = {}));
|