@gainsnetwork/sdk 0.2.67-rc7 → 0.2.68
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/contracts/addresses.json +20 -0
- package/lib/contracts/fetch/fees/borrowingFeesV2.d.ts +76 -0
- package/lib/contracts/fetch/fees/borrowingFeesV2.js +193 -0
- package/lib/contracts/fetch/fees/fundingFees.d.ts +66 -0
- package/lib/contracts/fetch/fees/fundingFees.js +150 -0
- package/lib/contracts/fetch/priceImpact/skew.d.ts +63 -0
- package/lib/contracts/fetch/priceImpact/skew.js +168 -0
- package/lib/contracts/index.js +3 -1
- package/lib/contracts/types/index.d.ts +2 -1
- package/lib/contracts/types/index.js +1 -0
- package/lib/trade/fees/borrowingV2/converter.d.ts +66 -0
- package/lib/trade/fees/borrowingV2/converter.js +121 -0
- package/lib/trade/fees/borrowingV2/index.d.ts +59 -0
- package/lib/trade/fees/borrowingV2/index.js +139 -0
- package/lib/trade/fees/borrowingV2/types.d.ts +79 -0
- package/lib/trade/fees/borrowingV2/types.js +5 -0
- package/lib/trade/fees/fundingFees/converter.d.ts +102 -0
- package/lib/trade/fees/fundingFees/converter.js +196 -0
- package/lib/trade/fees/fundingFees/index.d.ts +135 -0
- package/lib/trade/fees/fundingFees/index.js +322 -0
- package/lib/trade/fees/fundingFees/types.d.ts +77 -0
- package/lib/trade/fees/fundingFees/types.js +5 -0
- package/lib/trade/fees/trading/converter.d.ts +30 -0
- package/lib/trade/fees/trading/converter.js +43 -0
- package/lib/trade/fees/trading/index.d.ts +34 -0
- package/lib/trade/fees/trading/index.js +104 -0
- package/lib/trade/fees/trading/types.d.ts +39 -0
- package/lib/trade/fees/trading/types.js +5 -0
- package/lib/trade/priceImpact/index.d.ts +8 -0
- package/lib/trade/priceImpact/index.js +32 -0
- package/lib/trade/priceImpact/skew/converter.d.ts +77 -0
- package/lib/trade/priceImpact/skew/converter.js +171 -0
- package/lib/trade/priceImpact/skew/index.d.ts +57 -0
- package/lib/trade/priceImpact/skew/index.js +175 -0
- package/lib/trade/priceImpact/skew/types.d.ts +55 -0
- package/lib/trade/priceImpact/skew/types.js +5 -0
- package/lib/trade/utils.d.ts +18 -0
- package/lib/trade/utils.js +30 -0
- package/package.json +1 -1
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @dev Funding fees calculations for v10+ trades
|
|
4
|
+
* @dev Based on skew-based funding rate model with velocity and APR multipliers
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
+
if (mod && mod.__esModule) return mod;
|
|
24
|
+
var result = {};
|
|
25
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
+
__setModuleDefault(result, mod);
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.FundingFees = exports.getTradeFundingFeesCollateralSimple = exports.getTradeFundingFees = exports.getTradeFundingFeesCollateral = exports.getPairPendingAccFundingFees = exports.getLongShortAprMultiplier = exports.getAvgFundingRatePerSecondP = exports.getSecondsToReachZeroRate = exports.getCurrentFundingVelocityPerYear = void 0;
|
|
31
|
+
// Constants from contract
|
|
32
|
+
const FUNDING_APR_MULTIPLIER_CAP = 100; // Smaller side can earn up to 100x more APR
|
|
33
|
+
const ONE_YEAR = 365 * 24 * 60 * 60; // 1 year in seconds
|
|
34
|
+
/**
|
|
35
|
+
* @dev Calculates current funding velocity per year based on skew
|
|
36
|
+
* @param netExposureToken Net exposure (long - short) in tokens
|
|
37
|
+
* @param netExposureUsd Net exposure in USD
|
|
38
|
+
* @param skewCoefficientPerYear Skew coefficient per year from params
|
|
39
|
+
* @param absoluteVelocityPerYearCap Cap on velocity per year
|
|
40
|
+
* @param thetaThresholdUsd Minimum exposure USD to start charging funding fees
|
|
41
|
+
* @returns Current yearly funding velocity
|
|
42
|
+
*/
|
|
43
|
+
const getCurrentFundingVelocityPerYear = (netExposureToken, netExposureUsd, skewCoefficientPerYear, absoluteVelocityPerYearCap, thetaThresholdUsd) => {
|
|
44
|
+
// If no exposure or skew coefficient 0 or velocity cap 0, velocity is 0
|
|
45
|
+
if (netExposureToken === 0 ||
|
|
46
|
+
skewCoefficientPerYear === 0 ||
|
|
47
|
+
absoluteVelocityPerYearCap === 0) {
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
// Check theta threshold
|
|
51
|
+
const absNetExposureUsd = Math.abs(netExposureUsd);
|
|
52
|
+
if (absNetExposureUsd < thetaThresholdUsd) {
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
// Calculate absolute velocity
|
|
56
|
+
const absoluteVelocityPerYear = Math.abs(netExposureToken) * skewCoefficientPerYear;
|
|
57
|
+
// Apply cap
|
|
58
|
+
const cappedAbsoluteVelocity = Math.min(absoluteVelocityPerYear, absoluteVelocityPerYearCap);
|
|
59
|
+
// Return with proper sign
|
|
60
|
+
return netExposureToken < 0
|
|
61
|
+
? -cappedAbsoluteVelocity
|
|
62
|
+
: cappedAbsoluteVelocity;
|
|
63
|
+
};
|
|
64
|
+
exports.getCurrentFundingVelocityPerYear = getCurrentFundingVelocityPerYear;
|
|
65
|
+
/**
|
|
66
|
+
* @dev Calculates seconds until funding rate reaches zero
|
|
67
|
+
* @param lastFundingRatePerSecondP Last funding rate per second
|
|
68
|
+
* @param currentVelocityPerYear Current velocity per year
|
|
69
|
+
* @returns Seconds until rate reaches zero
|
|
70
|
+
*/
|
|
71
|
+
const getSecondsToReachZeroRate = (lastFundingRatePerSecondP, currentVelocityPerYear) => {
|
|
72
|
+
if (currentVelocityPerYear === 0) {
|
|
73
|
+
throw new Error("Velocity cannot be zero when calculating time to reach zero rate");
|
|
74
|
+
}
|
|
75
|
+
const secondsToReachZeroRate = (-lastFundingRatePerSecondP * ONE_YEAR) / currentVelocityPerYear;
|
|
76
|
+
if (secondsToReachZeroRate < 0) {
|
|
77
|
+
throw new Error("Invalid calculation: seconds to reach zero rate cannot be negative");
|
|
78
|
+
}
|
|
79
|
+
return secondsToReachZeroRate;
|
|
80
|
+
};
|
|
81
|
+
exports.getSecondsToReachZeroRate = getSecondsToReachZeroRate;
|
|
82
|
+
/**
|
|
83
|
+
* @dev Calculates average and current funding rate per second
|
|
84
|
+
* @param lastFundingRatePerSecondP Last funding rate per second
|
|
85
|
+
* @param absoluteRatePerSecondCap Absolute cap on funding rate per second
|
|
86
|
+
* @param currentVelocityPerYear Current velocity per year
|
|
87
|
+
* @param secondsSinceLastUpdate Seconds elapsed since last update
|
|
88
|
+
* @returns Average and current funding rate per second
|
|
89
|
+
*/
|
|
90
|
+
const getAvgFundingRatePerSecondP = (lastFundingRatePerSecondP, absoluteRatePerSecondCap, currentVelocityPerYear, secondsSinceLastUpdate) => {
|
|
91
|
+
// If cap is 0, there are no funding fees
|
|
92
|
+
if (absoluteRatePerSecondCap === 0) {
|
|
93
|
+
return { avgFundingRatePerSecondP: 0, currentFundingRatePerSecondP: 0 };
|
|
94
|
+
}
|
|
95
|
+
// If velocity is 0 or no time elapsed, funding rate is still the same
|
|
96
|
+
if (currentVelocityPerYear === 0 || secondsSinceLastUpdate === 0) {
|
|
97
|
+
return {
|
|
98
|
+
avgFundingRatePerSecondP: lastFundingRatePerSecondP,
|
|
99
|
+
currentFundingRatePerSecondP: lastFundingRatePerSecondP,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const ratePerSecondCap = absoluteRatePerSecondCap * (currentVelocityPerYear < 0 ? -1 : 1);
|
|
103
|
+
// If rate is already at cap, just return it
|
|
104
|
+
if (ratePerSecondCap === lastFundingRatePerSecondP) {
|
|
105
|
+
return {
|
|
106
|
+
avgFundingRatePerSecondP: ratePerSecondCap,
|
|
107
|
+
currentFundingRatePerSecondP: ratePerSecondCap,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const secondsToReachCap = ((ratePerSecondCap - lastFundingRatePerSecondP) * ONE_YEAR) /
|
|
111
|
+
currentVelocityPerYear;
|
|
112
|
+
if (secondsSinceLastUpdate > secondsToReachCap) {
|
|
113
|
+
// Rate reached cap during this period
|
|
114
|
+
const currentFundingRatePerSecondP = ratePerSecondCap;
|
|
115
|
+
// Weighted average: time to cap at average rate + time at cap
|
|
116
|
+
const avgFundingRatePerSecondP_1 = (lastFundingRatePerSecondP + ratePerSecondCap) / 2;
|
|
117
|
+
const avgFundingRatePerSecondP = (avgFundingRatePerSecondP_1 * secondsToReachCap +
|
|
118
|
+
ratePerSecondCap * (secondsSinceLastUpdate - secondsToReachCap)) /
|
|
119
|
+
secondsSinceLastUpdate;
|
|
120
|
+
return { avgFundingRatePerSecondP, currentFundingRatePerSecondP };
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
// Rate didn't reach cap
|
|
124
|
+
const currentFundingRatePerSecondP = lastFundingRatePerSecondP +
|
|
125
|
+
(secondsSinceLastUpdate * currentVelocityPerYear) / ONE_YEAR;
|
|
126
|
+
const avgFundingRatePerSecondP = (lastFundingRatePerSecondP + currentFundingRatePerSecondP) / 2;
|
|
127
|
+
return { avgFundingRatePerSecondP, currentFundingRatePerSecondP };
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
exports.getAvgFundingRatePerSecondP = getAvgFundingRatePerSecondP;
|
|
131
|
+
/**
|
|
132
|
+
* @dev Calculates APR multipliers for long and short sides based on OI ratio
|
|
133
|
+
* @param avgFundingRatePerSecondP Average funding rate per second
|
|
134
|
+
* @param pairOiLongToken Long OI in tokens
|
|
135
|
+
* @param pairOiShortToken Short OI in tokens
|
|
136
|
+
* @param aprMultiplierEnabled Whether APR multiplier is enabled
|
|
137
|
+
* @returns Long and short APR multipliers
|
|
138
|
+
*/
|
|
139
|
+
const getLongShortAprMultiplier = (avgFundingRatePerSecondP, pairOiLongToken, pairOiShortToken, aprMultiplierEnabled) => {
|
|
140
|
+
// If funding rate is 0, multipliers don't matter
|
|
141
|
+
if (avgFundingRatePerSecondP === 0) {
|
|
142
|
+
return { longAprMultiplier: 1, shortAprMultiplier: 1 };
|
|
143
|
+
}
|
|
144
|
+
const longsEarned = avgFundingRatePerSecondP < 0;
|
|
145
|
+
let longAprMultiplier = 1;
|
|
146
|
+
let shortAprMultiplier = 1;
|
|
147
|
+
if (aprMultiplierEnabled) {
|
|
148
|
+
if (longsEarned && pairOiLongToken > 0) {
|
|
149
|
+
longAprMultiplier = pairOiShortToken / pairOiLongToken;
|
|
150
|
+
}
|
|
151
|
+
else if (!longsEarned && pairOiShortToken > 0) {
|
|
152
|
+
shortAprMultiplier = pairOiLongToken / pairOiShortToken;
|
|
153
|
+
}
|
|
154
|
+
// Apply cap
|
|
155
|
+
longAprMultiplier = Math.min(longAprMultiplier, FUNDING_APR_MULTIPLIER_CAP);
|
|
156
|
+
shortAprMultiplier = Math.min(shortAprMultiplier, FUNDING_APR_MULTIPLIER_CAP);
|
|
157
|
+
}
|
|
158
|
+
return { longAprMultiplier, shortAprMultiplier };
|
|
159
|
+
};
|
|
160
|
+
exports.getLongShortAprMultiplier = getLongShortAprMultiplier;
|
|
161
|
+
/**
|
|
162
|
+
* @dev Calculates pending accumulated funding fees for a pair
|
|
163
|
+
* @param params Funding fee parameters
|
|
164
|
+
* @param data Current funding fee data
|
|
165
|
+
* @param currentPairPrice Current pair price
|
|
166
|
+
* @param pairOiToken Pair OI after v10
|
|
167
|
+
* @param netExposureToken Net exposure in tokens
|
|
168
|
+
* @param netExposureUsd Net exposure in USD
|
|
169
|
+
* @param currentTimestamp Current timestamp
|
|
170
|
+
* @returns Pending accumulated funding fees and current rate
|
|
171
|
+
*/
|
|
172
|
+
const getPairPendingAccFundingFees = (params, data, currentPairPrice, pairOiToken, netExposureToken, netExposureUsd, currentTimestamp) => {
|
|
173
|
+
let accFundingFeeLongP = data.accFundingFeeLongP;
|
|
174
|
+
let accFundingFeeShortP = data.accFundingFeeShortP;
|
|
175
|
+
// If funding fees are disabled, return current values
|
|
176
|
+
if (!params.fundingFeesEnabled) {
|
|
177
|
+
return {
|
|
178
|
+
accFundingFeeLongP,
|
|
179
|
+
accFundingFeeShortP,
|
|
180
|
+
currentFundingRatePerSecondP: data.lastFundingRatePerSecondP,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const secondsSinceLastUpdate = currentTimestamp - data.lastFundingUpdateTs;
|
|
184
|
+
// Calculate current velocity
|
|
185
|
+
const currentVelocityPerYear = (0, exports.getCurrentFundingVelocityPerYear)(netExposureToken, netExposureUsd, params.skewCoefficientPerYear, params.absoluteVelocityPerYearCap, params.thetaThresholdUsd);
|
|
186
|
+
// Get average and current funding rates
|
|
187
|
+
const { avgFundingRatePerSecondP, currentFundingRatePerSecondP } = (0, exports.getAvgFundingRatePerSecondP)(data.lastFundingRatePerSecondP, params.absoluteRatePerSecondCap, currentVelocityPerYear, secondsSinceLastUpdate);
|
|
188
|
+
// Check if we need to handle rate sign change
|
|
189
|
+
const rateChangedSign = params.aprMultiplierEnabled &&
|
|
190
|
+
((currentFundingRatePerSecondP > 0 && data.lastFundingRatePerSecondP < 0) ||
|
|
191
|
+
(currentFundingRatePerSecondP < 0 && data.lastFundingRatePerSecondP > 0));
|
|
192
|
+
if (rateChangedSign) {
|
|
193
|
+
// Split calculation into two periods: before and after sign change
|
|
194
|
+
// 1. From last update to rate = 0
|
|
195
|
+
const secondsToReachZeroRate = (0, exports.getSecondsToReachZeroRate)(data.lastFundingRatePerSecondP, currentVelocityPerYear);
|
|
196
|
+
const avgFundingRatePerSecondP_1 = data.lastFundingRatePerSecondP / 2;
|
|
197
|
+
const fundingFeesDeltaP_1 = avgFundingRatePerSecondP_1 * secondsToReachZeroRate * currentPairPrice;
|
|
198
|
+
const { longAprMultiplier: longMultiplier1, shortAprMultiplier: shortMultiplier1, } = (0, exports.getLongShortAprMultiplier)(avgFundingRatePerSecondP_1, pairOiToken.oiLongToken, pairOiToken.oiShortToken, true);
|
|
199
|
+
accFundingFeeLongP += fundingFeesDeltaP_1 * longMultiplier1;
|
|
200
|
+
accFundingFeeShortP -= fundingFeesDeltaP_1 * shortMultiplier1;
|
|
201
|
+
// 2. From rate = 0 to current rate
|
|
202
|
+
const avgFundingRatePerSecondP_2 = currentFundingRatePerSecondP / 2;
|
|
203
|
+
const fundingFeesDeltaP_2 = avgFundingRatePerSecondP_2 *
|
|
204
|
+
(secondsSinceLastUpdate - secondsToReachZeroRate) *
|
|
205
|
+
currentPairPrice;
|
|
206
|
+
const { longAprMultiplier: longMultiplier2, shortAprMultiplier: shortMultiplier2, } = (0, exports.getLongShortAprMultiplier)(avgFundingRatePerSecondP_2, pairOiToken.oiLongToken, pairOiToken.oiShortToken, true);
|
|
207
|
+
accFundingFeeLongP += fundingFeesDeltaP_2 * longMultiplier2;
|
|
208
|
+
accFundingFeeShortP -= fundingFeesDeltaP_2 * shortMultiplier2;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
// Single period calculation
|
|
212
|
+
const fundingFeesDeltaP = avgFundingRatePerSecondP * secondsSinceLastUpdate * currentPairPrice;
|
|
213
|
+
const { longAprMultiplier, shortAprMultiplier } = (0, exports.getLongShortAprMultiplier)(avgFundingRatePerSecondP, pairOiToken.oiLongToken, pairOiToken.oiShortToken, params.aprMultiplierEnabled);
|
|
214
|
+
accFundingFeeLongP += fundingFeesDeltaP * longAprMultiplier;
|
|
215
|
+
accFundingFeeShortP -= fundingFeesDeltaP * shortAprMultiplier;
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
accFundingFeeLongP,
|
|
219
|
+
accFundingFeeShortP,
|
|
220
|
+
currentFundingRatePerSecondP,
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
exports.getPairPendingAccFundingFees = getPairPendingAccFundingFees;
|
|
224
|
+
/**
|
|
225
|
+
* @dev Calculates funding fees for a specific trade (SDK version following contract pattern)
|
|
226
|
+
* @param trade Trade parameters (collateral amount, leverage, open price, long/short, collateralIndex, pairIndex)
|
|
227
|
+
* @param tradeInfo Trade info (contracts version)
|
|
228
|
+
* @param tradeFeesData Trade fees data containing initial acc funding fee
|
|
229
|
+
* @param currentPairPrice Current pair price
|
|
230
|
+
* @param context Optional context with funding fee data (if not provided, uses simple calculation)
|
|
231
|
+
* @returns Funding fee in collateral tokens
|
|
232
|
+
*/
|
|
233
|
+
const getTradeFundingFeesCollateral = (trade, tradeInfo, tradeFeesData, currentPairPrice, context) => {
|
|
234
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
235
|
+
// Funding fees are only charged on post-v10 trades
|
|
236
|
+
if (tradeInfo.contractsVersion < 10) {
|
|
237
|
+
return 0;
|
|
238
|
+
}
|
|
239
|
+
const positionSizeCollateral = trade.collateralAmount * trade.leverage;
|
|
240
|
+
// If we have full context, calculate current accumulated funding fee
|
|
241
|
+
if (context &&
|
|
242
|
+
trade.collateralIndex !== undefined &&
|
|
243
|
+
trade.pairIndex !== undefined) {
|
|
244
|
+
const params = (_a = context.fundingParams[trade.collateralIndex]) === null || _a === void 0 ? void 0 : _a[trade.pairIndex];
|
|
245
|
+
const data = (_b = context.fundingData[trade.collateralIndex]) === null || _b === void 0 ? void 0 : _b[trade.pairIndex];
|
|
246
|
+
const pairOi = (_d = (_c = context.pairOiAfterV10) === null || _c === void 0 ? void 0 : _c[trade.collateralIndex]) === null || _d === void 0 ? void 0 : _d[trade.pairIndex];
|
|
247
|
+
const netExposureToken = ((_f = (_e = context.netExposureToken) === null || _e === void 0 ? void 0 : _e[trade.collateralIndex]) === null || _f === void 0 ? void 0 : _f[trade.pairIndex]) || 0;
|
|
248
|
+
const netExposureUsd = ((_h = (_g = context.netExposureUsd) === null || _g === void 0 ? void 0 : _g[trade.collateralIndex]) === null || _h === void 0 ? void 0 : _h[trade.pairIndex]) || 0;
|
|
249
|
+
if (params && data && pairOi) {
|
|
250
|
+
// Calculate pending accumulated fees
|
|
251
|
+
const { accFundingFeeLongP, accFundingFeeShortP } = (0, exports.getPairPendingAccFundingFees)(params, data, currentPairPrice, pairOi, netExposureToken, netExposureUsd, context.currentTimestamp);
|
|
252
|
+
const currentAccFundingFeeP = trade.long
|
|
253
|
+
? accFundingFeeLongP
|
|
254
|
+
: accFundingFeeShortP;
|
|
255
|
+
const fundingFeeDelta = currentAccFundingFeeP - tradeFeesData.initialAccFundingFeeP;
|
|
256
|
+
return (positionSizeCollateral * fundingFeeDelta) / trade.openPrice;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return 0; // Cannot calculate without proper context
|
|
260
|
+
};
|
|
261
|
+
exports.getTradeFundingFeesCollateral = getTradeFundingFeesCollateral;
|
|
262
|
+
/**
|
|
263
|
+
* @dev Main function to calculate funding fees for a trade within context
|
|
264
|
+
* @param context Funding fee context with params and data
|
|
265
|
+
* @param collateralIndex Collateral index
|
|
266
|
+
* @param pairIndex Pair index
|
|
267
|
+
* @param trade Trade details
|
|
268
|
+
* @param tradeInfo Trade info (contracts version)
|
|
269
|
+
* @param initialAccFundingFeeP Initial accumulated funding fee
|
|
270
|
+
* @param currentPairPrice Current pair price
|
|
271
|
+
* @param pairOiToken Pair OI after v10
|
|
272
|
+
* @param netExposureToken Net exposure in tokens
|
|
273
|
+
* @param netExposureUsd Net exposure in USD
|
|
274
|
+
* @returns Complete funding fee calculation result
|
|
275
|
+
*/
|
|
276
|
+
const getTradeFundingFees = (context, collateralIndex, pairIndex, trade, tradeInfo, initialAccFundingFeeP, currentPairPrice, pairOiToken, netExposureToken, netExposureUsd) => {
|
|
277
|
+
var _a, _b;
|
|
278
|
+
// Get params and data from context
|
|
279
|
+
const params = (_a = context.fundingParams[collateralIndex]) === null || _a === void 0 ? void 0 : _a[pairIndex];
|
|
280
|
+
const data = (_b = context.fundingData[collateralIndex]) === null || _b === void 0 ? void 0 : _b[pairIndex];
|
|
281
|
+
if (!params || !data) {
|
|
282
|
+
throw new Error(`Missing funding fee data for collateral ${collateralIndex} pair ${pairIndex}`);
|
|
283
|
+
}
|
|
284
|
+
// Calculate pending accumulated fees
|
|
285
|
+
const { accFundingFeeLongP, accFundingFeeShortP } = (0, exports.getPairPendingAccFundingFees)(params, data, currentPairPrice, pairOiToken, netExposureToken, netExposureUsd, context.currentTimestamp);
|
|
286
|
+
const currentAccFundingFeeP = trade.long
|
|
287
|
+
? accFundingFeeLongP
|
|
288
|
+
: accFundingFeeShortP;
|
|
289
|
+
// Calculate funding fee in collateral
|
|
290
|
+
const fundingFeeCollateral = (0, exports.getTradeFundingFeesCollateralSimple)(trade, tradeInfo, initialAccFundingFeeP, currentAccFundingFeeP);
|
|
291
|
+
// Calculate funding fee as percentage
|
|
292
|
+
const fundingFeeP = trade.collateralAmount > 0
|
|
293
|
+
? (fundingFeeCollateral / trade.collateralAmount) * 100
|
|
294
|
+
: 0;
|
|
295
|
+
return {
|
|
296
|
+
fundingFeeCollateral,
|
|
297
|
+
fundingFeeP,
|
|
298
|
+
currentAccFundingFeeP,
|
|
299
|
+
initialAccFundingFeeP,
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
exports.getTradeFundingFees = getTradeFundingFees;
|
|
303
|
+
/**
|
|
304
|
+
* @dev Simple version of getTradeFundingFeesCollateral for backward compatibility
|
|
305
|
+
* @param trade Trade parameters
|
|
306
|
+
* @param tradeInfo Trade info with contracts version
|
|
307
|
+
* @param initialAccFundingFeeP Initial accumulated funding fee
|
|
308
|
+
* @param currentAccFundingFeeP Current accumulated funding fee
|
|
309
|
+
* @returns Funding fee in collateral tokens
|
|
310
|
+
*/
|
|
311
|
+
const getTradeFundingFeesCollateralSimple = (trade, tradeInfo, initialAccFundingFeeP, currentAccFundingFeeP) => {
|
|
312
|
+
// Funding fees are only charged on post-v10 trades
|
|
313
|
+
if (tradeInfo.contractsVersion < 10) {
|
|
314
|
+
return 0;
|
|
315
|
+
}
|
|
316
|
+
const positionSizeCollateral = trade.collateralAmount * trade.leverage;
|
|
317
|
+
const fundingFeeDelta = currentAccFundingFeeP - initialAccFundingFeeP;
|
|
318
|
+
return (positionSizeCollateral * fundingFeeDelta) / trade.openPrice;
|
|
319
|
+
};
|
|
320
|
+
exports.getTradeFundingFeesCollateralSimple = getTradeFundingFeesCollateralSimple;
|
|
321
|
+
// Export namespace for types
|
|
322
|
+
exports.FundingFees = __importStar(require("./types"));
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dev Funding fees types for v10+ trades
|
|
3
|
+
*/
|
|
4
|
+
export type FundingFeeParams = {
|
|
5
|
+
skewCoefficientPerYear: number;
|
|
6
|
+
absoluteVelocityPerYearCap: number;
|
|
7
|
+
absoluteRatePerSecondCap: number;
|
|
8
|
+
thetaThresholdUsd: number;
|
|
9
|
+
fundingFeesEnabled: boolean;
|
|
10
|
+
aprMultiplierEnabled: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type PairFundingFeeData = {
|
|
13
|
+
accFundingFeeLongP: number;
|
|
14
|
+
accFundingFeeShortP: number;
|
|
15
|
+
lastFundingRatePerSecondP: number;
|
|
16
|
+
lastFundingUpdateTs: number;
|
|
17
|
+
};
|
|
18
|
+
export type PairGlobalParams = {
|
|
19
|
+
maxSkewCollateral: number;
|
|
20
|
+
};
|
|
21
|
+
export type TradeInitialAccFundingFees = {
|
|
22
|
+
initialAccFundingFeeP: number;
|
|
23
|
+
};
|
|
24
|
+
export type PairAccumulatedFees = {
|
|
25
|
+
accPerOiLong: number;
|
|
26
|
+
accPerOiShort: number;
|
|
27
|
+
lastUpdateBlock: number;
|
|
28
|
+
};
|
|
29
|
+
export type TradeInitialAccFees = {
|
|
30
|
+
accPerOiLong: number;
|
|
31
|
+
accPerOiShort: number;
|
|
32
|
+
openBlock: number;
|
|
33
|
+
};
|
|
34
|
+
export type PairOiAfterV10 = {
|
|
35
|
+
oiLongToken: number;
|
|
36
|
+
oiShortToken: number;
|
|
37
|
+
};
|
|
38
|
+
export type FundingRateCalculation = {
|
|
39
|
+
pairOiToken: PairOiAfterV10;
|
|
40
|
+
netExposureToken: number;
|
|
41
|
+
netExposureUsd: number;
|
|
42
|
+
currentVelocityPerYear: number;
|
|
43
|
+
avgFundingRatePerSecondP: number;
|
|
44
|
+
currentFundingRatePerSecondP: number;
|
|
45
|
+
secondsSinceLastUpdate: number;
|
|
46
|
+
longAprMultiplier: number;
|
|
47
|
+
shortAprMultiplier: number;
|
|
48
|
+
};
|
|
49
|
+
export type GetFundingFeeContext = {
|
|
50
|
+
currentTimestamp: number;
|
|
51
|
+
fundingParams: {
|
|
52
|
+
[collateralIndex: number]: {
|
|
53
|
+
[pairIndex: number]: FundingFeeParams;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
fundingData: {
|
|
57
|
+
[collateralIndex: number]: {
|
|
58
|
+
[pairIndex: number]: PairFundingFeeData;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
globalParams?: {
|
|
62
|
+
[collateralIndex: number]: {
|
|
63
|
+
[pairIndex: number]: PairGlobalParams;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
export type TradeFundingFeeResult = {
|
|
68
|
+
fundingFeeCollateral: number;
|
|
69
|
+
fundingFeeP: number;
|
|
70
|
+
currentAccFundingFeeP: number;
|
|
71
|
+
initialAccFundingFeeP: number;
|
|
72
|
+
};
|
|
73
|
+
export type PairPendingAccFundingFeesResult = {
|
|
74
|
+
accFundingFeeLongP: number;
|
|
75
|
+
accFundingFeeShortP: number;
|
|
76
|
+
currentFundingRatePerSecondP: number;
|
|
77
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dev Converters for trading fee data between contract and SDK formats
|
|
3
|
+
*/
|
|
4
|
+
import { CounterTradeSettings } from "../../types";
|
|
5
|
+
import { GlobalTradeFeeParams } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* @dev Converts contract counter trade settings to SDK format
|
|
8
|
+
* @param feeRateMultiplier Fee rate multiplier from contract (1e3 precision)
|
|
9
|
+
* @param maxLeverage Max leverage from contract (1e3 precision)
|
|
10
|
+
* @returns Normalized counter trade settings
|
|
11
|
+
*/
|
|
12
|
+
export declare const convertCounterTradeSettings: (feeRateMultiplier: number, maxLeverage: number) => CounterTradeSettings;
|
|
13
|
+
/**
|
|
14
|
+
* @dev Converts array of counter trade fee rate multipliers from contract
|
|
15
|
+
* @param multipliers Array of fee rate multipliers (1e3 precision)
|
|
16
|
+
* @returns Array of normalized multipliers
|
|
17
|
+
*/
|
|
18
|
+
export declare const convertCounterTradeFeeRateMultipliers: (multipliers: number[]) => number[];
|
|
19
|
+
/**
|
|
20
|
+
* @dev Converts global trade fee params from contract to SDK format
|
|
21
|
+
* @param contractParams Global trade fee params from contract
|
|
22
|
+
* @returns Normalized global trade fee params
|
|
23
|
+
*/
|
|
24
|
+
export declare const convertGlobalTradeFeeParams: (contractParams: {
|
|
25
|
+
referralFeeP: number;
|
|
26
|
+
govFeeP: number;
|
|
27
|
+
triggerOrderFeeP: number;
|
|
28
|
+
gnsOtcFeeP: number;
|
|
29
|
+
gTokenFeeP: number;
|
|
30
|
+
}) => GlobalTradeFeeParams;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @dev Converters for trading fee data between contract and SDK formats
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.convertGlobalTradeFeeParams = exports.convertCounterTradeFeeRateMultipliers = exports.convertCounterTradeSettings = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @dev Converts contract counter trade settings to SDK format
|
|
9
|
+
* @param feeRateMultiplier Fee rate multiplier from contract (1e3 precision)
|
|
10
|
+
* @param maxLeverage Max leverage from contract (1e3 precision)
|
|
11
|
+
* @returns Normalized counter trade settings
|
|
12
|
+
*/
|
|
13
|
+
const convertCounterTradeSettings = (feeRateMultiplier, maxLeverage) => {
|
|
14
|
+
return {
|
|
15
|
+
feeRateMultiplier: feeRateMultiplier / 1000,
|
|
16
|
+
maxLeverage: maxLeverage / 1000, // 1e3 → float
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
exports.convertCounterTradeSettings = convertCounterTradeSettings;
|
|
20
|
+
/**
|
|
21
|
+
* @dev Converts array of counter trade fee rate multipliers from contract
|
|
22
|
+
* @param multipliers Array of fee rate multipliers (1e3 precision)
|
|
23
|
+
* @returns Array of normalized multipliers
|
|
24
|
+
*/
|
|
25
|
+
const convertCounterTradeFeeRateMultipliers = (multipliers) => {
|
|
26
|
+
return multipliers.map(m => m / 1000);
|
|
27
|
+
};
|
|
28
|
+
exports.convertCounterTradeFeeRateMultipliers = convertCounterTradeFeeRateMultipliers;
|
|
29
|
+
/**
|
|
30
|
+
* @dev Converts global trade fee params from contract to SDK format
|
|
31
|
+
* @param contractParams Global trade fee params from contract
|
|
32
|
+
* @returns Normalized global trade fee params
|
|
33
|
+
*/
|
|
34
|
+
const convertGlobalTradeFeeParams = (contractParams) => {
|
|
35
|
+
return {
|
|
36
|
+
referralFeeP: contractParams.referralFeeP / 1e10 / 100,
|
|
37
|
+
govFeeP: contractParams.govFeeP / 1e10 / 100,
|
|
38
|
+
triggerOrderFeeP: contractParams.triggerOrderFeeP / 1e10 / 100,
|
|
39
|
+
gnsOtcFeeP: contractParams.gnsOtcFeeP / 1e10 / 100,
|
|
40
|
+
gTokenFeeP: contractParams.gTokenFeeP / 1e10 / 100,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
exports.convertGlobalTradeFeeParams = convertGlobalTradeFeeParams;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dev Trading fee calculations for opening and closing positions
|
|
3
|
+
*/
|
|
4
|
+
import { Fee, PairIndex } from "../../types";
|
|
5
|
+
import { GetTradeFeesContext, GetLiquidationFeesContext, GetClosingFeeContext, TradeFeesBreakdown } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* @dev Returns the total fee for a trade in collateral tokens
|
|
8
|
+
* @dev Mirrors the contract's getTotalTradeFeesCollateral function
|
|
9
|
+
* @param collateralIndex Collateral index (not used in calculation, for consistency)
|
|
10
|
+
* @param trader Trader address (for fee tier lookup)
|
|
11
|
+
* @param pairIndex Index of the trading pair
|
|
12
|
+
* @param positionSizeCollateral Position size in collateral tokens
|
|
13
|
+
* @param isCounterTrade Whether the trade is a counter trade
|
|
14
|
+
* @param context Context containing fee parameters and settings
|
|
15
|
+
* @returns Total fee in collateral tokens
|
|
16
|
+
*/
|
|
17
|
+
export declare const getTotalTradeFeesCollateral: (collateralIndex: number, trader: string, pairIndex: PairIndex, positionSizeCollateral: number, isCounterTrade: boolean, context: GetTradeFeesContext) => number;
|
|
18
|
+
/**
|
|
19
|
+
* @dev Returns the fee breakdown for a trade
|
|
20
|
+
* @dev Mirrors the contract's getTradeFeesCollateral function
|
|
21
|
+
*/
|
|
22
|
+
export declare const getTradeFeesCollateral: (collateralIndex: number, trader: string, pairIndex: PairIndex, positionSizeCollateral: number, isCounterTrade: boolean, context: GetTradeFeesContext) => TradeFeesBreakdown;
|
|
23
|
+
/**
|
|
24
|
+
* @dev Returns total liquidation fee for a trade in collateral tokens
|
|
25
|
+
* @dev Mirrors the contract's getTotalTradeLiqFeesCollateral function
|
|
26
|
+
*/
|
|
27
|
+
export declare const getTotalTradeLiqFeesCollateral: (collateralIndex: number, trader: string, pairIndex: PairIndex, collateralAmount: number, context: GetLiquidationFeesContext) => number;
|
|
28
|
+
/**
|
|
29
|
+
* @dev Legacy function for backward compatibility
|
|
30
|
+
* @deprecated Use getTotalTradeFeesCollateral instead
|
|
31
|
+
*/
|
|
32
|
+
export declare const getClosingFee: (collateralAmount: number, leverage: number, pairIndex: PairIndex, pairFee: Fee | undefined, _collateralPriceUsd?: number | undefined, isCounterTrade?: boolean, trader?: string, context?: GetClosingFeeContext) => number;
|
|
33
|
+
export * from "./types";
|
|
34
|
+
export * from "./converter";
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @dev Trading fee calculations for opening and closing positions
|
|
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.getClosingFee = exports.getTotalTradeLiqFeesCollateral = exports.getTradeFeesCollateral = exports.getTotalTradeFeesCollateral = void 0;
|
|
21
|
+
const tiers_1 = require("../tiers");
|
|
22
|
+
/**
|
|
23
|
+
* @dev Returns the total fee for a trade in collateral tokens
|
|
24
|
+
* @dev Mirrors the contract's getTotalTradeFeesCollateral function
|
|
25
|
+
* @param collateralIndex Collateral index (not used in calculation, for consistency)
|
|
26
|
+
* @param trader Trader address (for fee tier lookup)
|
|
27
|
+
* @param pairIndex Index of the trading pair
|
|
28
|
+
* @param positionSizeCollateral Position size in collateral tokens
|
|
29
|
+
* @param isCounterTrade Whether the trade is a counter trade
|
|
30
|
+
* @param context Context containing fee parameters and settings
|
|
31
|
+
* @returns Total fee in collateral tokens
|
|
32
|
+
*/
|
|
33
|
+
const getTotalTradeFeesCollateral = (collateralIndex, trader, pairIndex, positionSizeCollateral, isCounterTrade, context) => {
|
|
34
|
+
var _a;
|
|
35
|
+
const { fee, collateralPriceUsd } = context;
|
|
36
|
+
const { totalPositionSizeFeeP, minPositionSizeUsd } = fee;
|
|
37
|
+
// Get counter trade fee rate multiplier (default 1 = 1x)
|
|
38
|
+
const counterTradeFeeRateMultiplier = isCounterTrade && ((_a = context.counterTradeSettings) === null || _a === void 0 ? void 0 : _a[pairIndex])
|
|
39
|
+
? context.counterTradeSettings[pairIndex].feeRateMultiplier
|
|
40
|
+
: 1;
|
|
41
|
+
// Apply counter trade multiplier to position size
|
|
42
|
+
const adjustedPositionSizeCollateral = positionSizeCollateral * counterTradeFeeRateMultiplier;
|
|
43
|
+
// Calculate minimum position size in collateral
|
|
44
|
+
const minPositionSizeCollateral = minPositionSizeUsd / collateralPriceUsd;
|
|
45
|
+
// Use max of adjusted position size and minimum position size
|
|
46
|
+
const positionSizeBasis = Math.max(adjustedPositionSizeCollateral, minPositionSizeCollateral);
|
|
47
|
+
// Calculate raw fee
|
|
48
|
+
const rawFee = totalPositionSizeFeeP * positionSizeBasis;
|
|
49
|
+
// Apply trader fee tier if available
|
|
50
|
+
return (0, tiers_1.calculateFeeAmount)(trader, rawFee, context.traderFeeMultiplier);
|
|
51
|
+
};
|
|
52
|
+
exports.getTotalTradeFeesCollateral = getTotalTradeFeesCollateral;
|
|
53
|
+
/**
|
|
54
|
+
* @dev Returns the fee breakdown for a trade
|
|
55
|
+
* @dev Mirrors the contract's getTradeFeesCollateral function
|
|
56
|
+
*/
|
|
57
|
+
const getTradeFeesCollateral = (collateralIndex, trader, pairIndex, positionSizeCollateral, isCounterTrade, context) => {
|
|
58
|
+
const totalFees = (0, exports.getTotalTradeFeesCollateral)(collateralIndex, trader, pairIndex, positionSizeCollateral, isCounterTrade, context);
|
|
59
|
+
const { globalTradeFeeParams } = context;
|
|
60
|
+
const totalP = globalTradeFeeParams.referralFeeP +
|
|
61
|
+
globalTradeFeeParams.govFeeP +
|
|
62
|
+
globalTradeFeeParams.triggerOrderFeeP +
|
|
63
|
+
globalTradeFeeParams.gnsOtcFeeP +
|
|
64
|
+
globalTradeFeeParams.gTokenFeeP;
|
|
65
|
+
// Distribute fees proportionally
|
|
66
|
+
return {
|
|
67
|
+
referralFeeCollateral: (totalFees * globalTradeFeeParams.referralFeeP) / totalP,
|
|
68
|
+
govFeeCollateral: (totalFees * globalTradeFeeParams.govFeeP) / totalP,
|
|
69
|
+
triggerFeeCollateral: (totalFees * globalTradeFeeParams.triggerOrderFeeP) / totalP,
|
|
70
|
+
gnsOtcFeeCollateral: (totalFees * globalTradeFeeParams.gnsOtcFeeP) / totalP,
|
|
71
|
+
gTokenFeeCollateral: (totalFees * globalTradeFeeParams.gTokenFeeP) / totalP,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
exports.getTradeFeesCollateral = getTradeFeesCollateral;
|
|
75
|
+
/**
|
|
76
|
+
* @dev Returns total liquidation fee for a trade in collateral tokens
|
|
77
|
+
* @dev Mirrors the contract's getTotalTradeLiqFeesCollateral function
|
|
78
|
+
*/
|
|
79
|
+
const getTotalTradeLiqFeesCollateral = (collateralIndex, trader, pairIndex, collateralAmount, context) => {
|
|
80
|
+
const { totalLiqCollateralFeeP } = context;
|
|
81
|
+
// Calculate raw liquidation fee
|
|
82
|
+
const rawFee = collateralAmount * totalLiqCollateralFeeP;
|
|
83
|
+
// Apply trader fee tier if available
|
|
84
|
+
return (0, tiers_1.calculateFeeAmount)(trader, rawFee, context.traderFeeMultiplier);
|
|
85
|
+
};
|
|
86
|
+
exports.getTotalTradeLiqFeesCollateral = getTotalTradeLiqFeesCollateral;
|
|
87
|
+
/**
|
|
88
|
+
* @dev Legacy function for backward compatibility
|
|
89
|
+
* @deprecated Use getTotalTradeFeesCollateral instead
|
|
90
|
+
*/
|
|
91
|
+
const getClosingFee = (collateralAmount, leverage, pairIndex, pairFee,
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
93
|
+
_collateralPriceUsd = 0, // Kept for backward compatibility
|
|
94
|
+
isCounterTrade = false, trader, context) => {
|
|
95
|
+
if (!pairFee || !context)
|
|
96
|
+
return 0;
|
|
97
|
+
const positionSizeCollateral = collateralAmount * leverage;
|
|
98
|
+
return (0, exports.getTotalTradeFeesCollateral)(0, // collateralIndex not used
|
|
99
|
+
trader || "", pairIndex, positionSizeCollateral, isCounterTrade, context);
|
|
100
|
+
};
|
|
101
|
+
exports.getClosingFee = getClosingFee;
|
|
102
|
+
// Export types
|
|
103
|
+
__exportStar(require("./types"), exports);
|
|
104
|
+
__exportStar(require("./converter"), exports);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dev Types for trading fee calculations (open/close position fees)
|
|
3
|
+
*/
|
|
4
|
+
import { Fee, CounterTradeSettings, GlobalTradeFeeParams } from "../../types";
|
|
5
|
+
/**
|
|
6
|
+
* @dev Breakdown of trading fees into components
|
|
7
|
+
*/
|
|
8
|
+
export type TradeFeesBreakdown = {
|
|
9
|
+
referralFeeCollateral: number;
|
|
10
|
+
govFeeCollateral: number;
|
|
11
|
+
triggerFeeCollateral: number;
|
|
12
|
+
gnsOtcFeeCollateral: number;
|
|
13
|
+
gTokenFeeCollateral: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* @dev Context for calculating trading fees
|
|
17
|
+
*/
|
|
18
|
+
export type GetTradeFeesContext = {
|
|
19
|
+
fee: Fee;
|
|
20
|
+
collateralPriceUsd: number;
|
|
21
|
+
globalTradeFeeParams: GlobalTradeFeeParams;
|
|
22
|
+
counterTradeSettings?: {
|
|
23
|
+
[pairIndex: number]: CounterTradeSettings;
|
|
24
|
+
};
|
|
25
|
+
traderFeeMultiplier?: number;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* @dev Context for calculating liquidation fees
|
|
29
|
+
*/
|
|
30
|
+
export type GetLiquidationFeesContext = {
|
|
31
|
+
totalLiqCollateralFeeP: number;
|
|
32
|
+
globalTradeFeeParams: GlobalTradeFeeParams;
|
|
33
|
+
traderFeeMultiplier?: number;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* @dev Legacy support
|
|
37
|
+
*/
|
|
38
|
+
export type GetClosingFeeContext = GetTradeFeesContext;
|
|
39
|
+
export type { GlobalTradeFeeParams };
|