@gainsnetwork/sdk 1.0.1-rc1 → 1.0.1-rc2
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.
|
@@ -49,25 +49,17 @@ const getCurrentFundingVelocityPerYear = (netExposureToken, netExposureUsd, skew
|
|
|
49
49
|
if (netExposureToken === 0 ||
|
|
50
50
|
skewCoefficientPerYear === 0 ||
|
|
51
51
|
absoluteVelocityPerYearCap === 0) {
|
|
52
|
-
console.log("netExposureToken", netExposureToken);
|
|
53
|
-
console.log("skewCoefficientPerYear", skewCoefficientPerYear);
|
|
54
|
-
console.log("absoluteVelocityPerYearCap", absoluteVelocityPerYearCap);
|
|
55
52
|
return 0;
|
|
56
53
|
}
|
|
57
54
|
// Check theta threshold
|
|
58
55
|
const absNetExposureUsd = Math.abs(netExposureUsd);
|
|
59
56
|
if (absNetExposureUsd < thetaThresholdUsd) {
|
|
60
|
-
console.log("absNetExposureUsd", absNetExposureUsd);
|
|
61
|
-
console.log("thetaThresholdUsd", thetaThresholdUsd);
|
|
62
57
|
return 0;
|
|
63
58
|
}
|
|
64
59
|
// Calculate absolute velocity
|
|
65
60
|
const absoluteVelocityPerYear = Math.abs(netExposureToken) * skewCoefficientPerYear;
|
|
66
61
|
// Apply cap
|
|
67
62
|
const cappedAbsoluteVelocity = Math.min(absoluteVelocityPerYear, absoluteVelocityPerYearCap);
|
|
68
|
-
console.log("absoluteVelocityPerYear", absoluteVelocityPerYear);
|
|
69
|
-
console.log("absoluteVelocityPerYearCap", absoluteVelocityPerYearCap);
|
|
70
|
-
console.log("cappedAbsoluteVelocity", cappedAbsoluteVelocity);
|
|
71
63
|
// Return with proper sign
|
|
72
64
|
return netExposureToken < 0
|
|
73
65
|
? -cappedAbsoluteVelocity
|
|
@@ -112,8 +104,6 @@ const getAvgFundingRatePerSecondP = (lastFundingRatePerSecondP, absoluteRatePerS
|
|
|
112
104
|
};
|
|
113
105
|
}
|
|
114
106
|
const ratePerSecondCap = absoluteRatePerSecondCap * (currentVelocityPerYear < 0 ? -1 : 1);
|
|
115
|
-
console.log("ratePerSecondCap", ratePerSecondCap);
|
|
116
|
-
console.log("lastFundingRatePerSecondP", lastFundingRatePerSecondP);
|
|
117
107
|
// If rate is already at cap, just return it
|
|
118
108
|
if (ratePerSecondCap === lastFundingRatePerSecondP) {
|
|
119
109
|
return {
|
|
@@ -123,7 +113,6 @@ const getAvgFundingRatePerSecondP = (lastFundingRatePerSecondP, absoluteRatePerS
|
|
|
123
113
|
}
|
|
124
114
|
const secondsToReachCap = ((ratePerSecondCap - lastFundingRatePerSecondP) * ONE_YEAR) /
|
|
125
115
|
currentVelocityPerYear;
|
|
126
|
-
console.log("secondsToReachCap", secondsToReachCap);
|
|
127
116
|
if (secondsSinceLastUpdate > secondsToReachCap) {
|
|
128
117
|
// Rate reached cap during this period
|
|
129
118
|
const currentFundingRatePerSecondP = ratePerSecondCap;
|
|
@@ -132,8 +121,6 @@ const getAvgFundingRatePerSecondP = (lastFundingRatePerSecondP, absoluteRatePerS
|
|
|
132
121
|
const avgFundingRatePerSecondP = (avgFundingRatePerSecondP_1 * secondsToReachCap +
|
|
133
122
|
ratePerSecondCap * (secondsSinceLastUpdate - secondsToReachCap)) /
|
|
134
123
|
secondsSinceLastUpdate;
|
|
135
|
-
console.log("Reached cap");
|
|
136
|
-
console.log("avgFundingRatePerSecondP", avgFundingRatePerSecondP);
|
|
137
124
|
return { avgFundingRatePerSecondP, currentFundingRatePerSecondP };
|
|
138
125
|
}
|
|
139
126
|
else {
|
|
@@ -141,9 +128,6 @@ const getAvgFundingRatePerSecondP = (lastFundingRatePerSecondP, absoluteRatePerS
|
|
|
141
128
|
const currentFundingRatePerSecondP = lastFundingRatePerSecondP +
|
|
142
129
|
(secondsSinceLastUpdate * currentVelocityPerYear) / ONE_YEAR;
|
|
143
130
|
const avgFundingRatePerSecondP = (lastFundingRatePerSecondP + currentFundingRatePerSecondP) / 2;
|
|
144
|
-
console.log("Not reached cap");
|
|
145
|
-
console.log("avgFundingRatePerSecondP", avgFundingRatePerSecondP);
|
|
146
|
-
console.log("currentFundingRatePerSecondP", currentFundingRatePerSecondP);
|
|
147
131
|
return { avgFundingRatePerSecondP, currentFundingRatePerSecondP };
|
|
148
132
|
}
|
|
149
133
|
};
|
|
@@ -201,14 +185,10 @@ const getPairPendingAccFundingFees = (params, data, currentPairPrice, pairOiToke
|
|
|
201
185
|
};
|
|
202
186
|
}
|
|
203
187
|
const secondsSinceLastUpdate = currentTimestamp - data.lastFundingUpdateTs;
|
|
204
|
-
console.log("secondsSinceLastUpdate", secondsSinceLastUpdate);
|
|
205
188
|
// Calculate current velocity
|
|
206
189
|
const currentVelocityPerYear = (0, exports.getCurrentFundingVelocityPerYear)(netExposureToken, netExposureUsd, params.skewCoefficientPerYear, params.absoluteVelocityPerYearCap, params.thetaThresholdUsd);
|
|
207
190
|
// Get average and current funding rates
|
|
208
191
|
const { avgFundingRatePerSecondP, currentFundingRatePerSecondP } = (0, exports.getAvgFundingRatePerSecondP)(data.lastFundingRatePerSecondP, params.absoluteRatePerSecondCap, currentVelocityPerYear, secondsSinceLastUpdate);
|
|
209
|
-
console.log("currentVelocityPerYear", currentVelocityPerYear);
|
|
210
|
-
console.log("avgFundingRatePerSecondP", avgFundingRatePerSecondP);
|
|
211
|
-
console.log("currentFundingRatePerSecondP", currentFundingRatePerSecondP);
|
|
212
192
|
// Check if we need to handle rate sign change
|
|
213
193
|
const rateChangedSign = params.aprMultiplierEnabled &&
|
|
214
194
|
((currentFundingRatePerSecondP > 0 && data.lastFundingRatePerSecondP < 0) ||
|
|
@@ -230,9 +210,6 @@ const getPairPendingAccFundingFees = (params, data, currentPairPrice, pairOiToke
|
|
|
230
210
|
const { longAprMultiplier: longMultiplier2, shortAprMultiplier: shortMultiplier2, } = (0, exports.getLongShortAprMultiplier)(avgFundingRatePerSecondP_2, pairOiToken.oiLongToken, pairOiToken.oiShortToken, true);
|
|
231
211
|
accFundingFeeLongP += fundingFeesDeltaP_2 * longMultiplier2;
|
|
232
212
|
accFundingFeeShortP -= fundingFeesDeltaP_2 * shortMultiplier2;
|
|
233
|
-
console.log("Rate changed sign");
|
|
234
|
-
console.log("accFundingFeeLongP", accFundingFeeLongP);
|
|
235
|
-
console.log("accFundingFeeShortP", accFundingFeeShortP);
|
|
236
213
|
}
|
|
237
214
|
else {
|
|
238
215
|
// Single period calculation
|
|
@@ -240,9 +217,6 @@ const getPairPendingAccFundingFees = (params, data, currentPairPrice, pairOiToke
|
|
|
240
217
|
const { longAprMultiplier, shortAprMultiplier } = (0, exports.getLongShortAprMultiplier)(avgFundingRatePerSecondP, pairOiToken.oiLongToken, pairOiToken.oiShortToken, params.aprMultiplierEnabled);
|
|
241
218
|
accFundingFeeLongP += fundingFeesDeltaP * longAprMultiplier;
|
|
242
219
|
accFundingFeeShortP -= fundingFeesDeltaP * shortAprMultiplier;
|
|
243
|
-
console.log("Single period calculation");
|
|
244
|
-
console.log("accFundingFeeLongP", accFundingFeeLongP);
|
|
245
|
-
console.log("accFundingFeeShortP", accFundingFeeShortP);
|
|
246
220
|
}
|
|
247
221
|
return {
|
|
248
222
|
accFundingFeeLongP,
|
|
@@ -275,12 +249,6 @@ const getTradeFundingFeesCollateral = (trade, tradeInfo, tradeFeesData, currentP
|
|
|
275
249
|
? accFundingFeeLongP
|
|
276
250
|
: accFundingFeeShortP;
|
|
277
251
|
const fundingFeeDelta = currentAccFundingFeeP - tradeFeesData.initialAccFundingFeeP;
|
|
278
|
-
console.log("currentAccFundingFeeP", currentAccFundingFeeP);
|
|
279
|
-
console.log("tradeFeesData.initialAccFundingFeeP", tradeFeesData.initialAccFundingFeeP);
|
|
280
|
-
console.log("fundingFeeDelta", fundingFeeDelta);
|
|
281
|
-
console.log("positionSizeCollateral", positionSizeCollateral);
|
|
282
|
-
console.log("trade.openPrice", trade.openPrice);
|
|
283
|
-
console.log("Final:", (positionSizeCollateral * fundingFeeDelta) / trade.openPrice / 100);
|
|
284
252
|
return (positionSizeCollateral * fundingFeeDelta) / trade.openPrice / 100;
|
|
285
253
|
};
|
|
286
254
|
exports.getTradeFundingFeesCollateral = getTradeFundingFeesCollateral;
|