@gainsnetwork/sdk 1.4.0-rc1 → 1.4.2-rc1
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.js +10 -10
- package/lib/backend/tradingVariables/converter.js +57 -57
- package/lib/backend/tradingVariables/index.js +6 -7
- package/lib/constants.js +2 -2
- package/lib/contracts/addresses.js +4 -1
- package/lib/contracts/index.d.ts +1 -1
- package/lib/contracts/index.js +3 -3
- 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 +386 -260
- 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.d.ts +2 -10
- package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +1621 -219
- 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/utils/borrowingFees.js +9 -20
- package/lib/contracts/utils/openTrades.js +11 -20
- package/lib/contracts/utils/pairs.js +12 -21
- package/lib/markets/forex.js +1 -1
- package/lib/markets/leverage/builder.js +2 -2
- package/lib/markets/oi/fetcher.d.ts +58 -0
- package/lib/markets/oi/fetcher.js +181 -0
- package/lib/markets/oi/validation.d.ts +80 -0
- package/lib/markets/oi/validation.js +172 -0
- package/lib/markets/price/index.d.ts +1 -0
- package/lib/markets/price/index.js +1 -0
- package/lib/markets/price/signedPrices.d.ts +36 -0
- package/lib/markets/price/signedPrices.js +181 -0
- package/lib/markets/price/types.d.ts +27 -0
- package/lib/pricing/depthBands/converter.d.ts +65 -0
- package/lib/pricing/depthBands/converter.js +155 -0
- package/lib/pricing/depthBands/decoder.d.ts +32 -0
- package/lib/pricing/depthBands/decoder.js +109 -0
- package/lib/pricing/depthBands/encoder.d.ts +19 -0
- package/lib/pricing/depthBands/encoder.js +105 -0
- package/lib/pricing/depthBands/index.d.ts +8 -0
- package/lib/pricing/depthBands/index.js +26 -0
- package/lib/pricing/depthBands/types.d.ts +49 -0
- package/lib/pricing/depthBands/types.js +10 -0
- package/lib/pricing/depthBands/validator.d.ts +22 -0
- package/lib/pricing/depthBands/validator.js +113 -0
- package/lib/pricing/depthBands.d.ts +39 -0
- package/lib/pricing/depthBands.js +94 -0
- package/lib/pricing/index.d.ts +4 -0
- package/lib/pricing/index.js +20 -0
- package/lib/trade/effectiveLeverage/builder.d.ts +23 -0
- package/lib/trade/effectiveLeverage/builder.js +30 -0
- package/lib/trade/fees/borrowing/builder.js +2 -3
- package/lib/trade/fees/borrowing/converter.js +5 -1
- package/lib/trade/fees/borrowing/index.js +5 -5
- package/lib/trade/fees/borrowingV2/builder.js +3 -4
- package/lib/trade/fees/borrowingV2/converter.js +1 -1
- package/lib/trade/fees/borrowingV2/fetcher.js +26 -32
- package/lib/trade/fees/borrowingV2/index.js +3 -3
- package/lib/trade/fees/converter.js +22 -22
- package/lib/trade/fees/fundingFees/builder.js +6 -7
- package/lib/trade/fees/fundingFees/converter.js +1 -1
- package/lib/trade/fees/fundingFees/fetcher.js +16 -25
- package/lib/trade/fees/fundingFees/index.js +2 -3
- package/lib/trade/fees/holdingFees/index.d.ts +46 -0
- package/lib/trade/fees/holdingFees/index.js +105 -0
- package/lib/trade/fees/holdingFees/types.d.ts +23 -0
- package/lib/trade/fees/holdingFees/types.js +5 -0
- package/lib/trade/fees/tiers/index.js +1 -2
- 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.js +5 -3
- package/lib/trade/liquidation/builder.js +1 -2
- package/lib/trade/liquidation/index.js +4 -6
- package/lib/trade/oiWindows.js +1 -2
- package/lib/trade/pnl/builder.js +1 -2
- package/lib/trade/pnl/converter.js +1 -1
- package/lib/trade/pnl/index.js +4 -7
- package/lib/trade/priceImpact/close/builder.js +1 -2
- package/lib/trade/priceImpact/close/index.js +4 -1
- package/lib/trade/priceImpact/cumulVol/builder.js +18 -10
- package/lib/trade/priceImpact/cumulVol/index.js +21 -16
- package/lib/trade/priceImpact/cumulVol/types.d.ts +11 -0
- package/lib/trade/priceImpact/cumulVol/types.js +2 -0
- package/lib/trade/priceImpact/open/builder.js +1 -2
- package/lib/trade/priceImpact/open/index.js +4 -1
- package/lib/trade/priceImpact/skew/builder.js +2 -3
- package/lib/trade/priceImpact/skew/converter.js +1 -1
- package/lib/trade/priceImpact/skew/fetcher.js +24 -33
- package/package.json +2 -2
- package/lib/trade/liquidation.d.ts +0 -12
- package/lib/trade/liquidation.js +0 -55
- package/lib/trade/pnl.d.ts +0 -10
- package/lib/trade/pnl.js +0 -33
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.fetchAllPairAndGroupBorrowingFees = exports.fetchGroupBorrowingFees = exports.fetchAllPairBorrowingFees = exports.getBorrowingGroupName = void 0;
|
|
13
4
|
const trade_1 = require("../../trade");
|
|
@@ -31,24 +22,22 @@ const getBorrowingGroupName = (groupIndex) => {
|
|
|
31
22
|
return groupNamesByIndex[groupIndex - 1] || "Unknown";
|
|
32
23
|
};
|
|
33
24
|
exports.getBorrowingGroupName = getBorrowingGroupName;
|
|
34
|
-
const fetchAllPairBorrowingFees = (contract, collateralIndex) =>
|
|
35
|
-
const [pairs, pairOi, pairGroups] =
|
|
36
|
-
const feeCaps =
|
|
25
|
+
const fetchAllPairBorrowingFees = async (contract, collateralIndex) => {
|
|
26
|
+
const [pairs, pairOi, pairGroups] = await contract.getAllBorrowingPairs(collateralIndex);
|
|
27
|
+
const feeCaps = await contract.getBorrowingPairFeePerBlockCaps(collateralIndex, [...Array(pairs.length).keys()]);
|
|
37
28
|
return (0, trade_1.convertPairBorrowingFees)([pairs, pairOi, pairGroups, feeCaps]);
|
|
38
|
-
}
|
|
29
|
+
};
|
|
39
30
|
exports.fetchAllPairBorrowingFees = fetchAllPairBorrowingFees;
|
|
40
|
-
const fetchGroupBorrowingFees = (contract, collateralIndex, groupIxs) =>
|
|
41
|
-
return (0, trade_1.convertGroupBorrowingFees)(yield contract.getBorrowingGroups(collateralIndex, groupIxs));
|
|
42
|
-
});
|
|
31
|
+
const fetchGroupBorrowingFees = async (contract, collateralIndex, groupIxs) => (0, trade_1.convertGroupBorrowingFees)(await contract.getBorrowingGroups(collateralIndex, groupIxs));
|
|
43
32
|
exports.fetchGroupBorrowingFees = fetchGroupBorrowingFees;
|
|
44
|
-
const fetchAllPairAndGroupBorrowingFees = (contract, collateralIndex) =>
|
|
45
|
-
const pairs =
|
|
33
|
+
const fetchAllPairAndGroupBorrowingFees = async (contract, collateralIndex) => {
|
|
34
|
+
const pairs = await (0, exports.fetchAllPairBorrowingFees)(contract, collateralIndex);
|
|
46
35
|
const groupIxs = [
|
|
47
36
|
...new Set(pairs
|
|
48
37
|
.map(value => value.groups.map(value => value.groupIndex))
|
|
49
38
|
.reduce((acc, value) => acc.concat(value), [])),
|
|
50
39
|
].sort((a, b) => a - b);
|
|
51
|
-
const groups =
|
|
40
|
+
const groups = await (0, exports.fetchGroupBorrowingFees)(contract, collateralIndex, groupIxs);
|
|
52
41
|
return { pairs, groups };
|
|
53
|
-
}
|
|
42
|
+
};
|
|
54
43
|
exports.fetchAllPairAndGroupBorrowingFees = fetchAllPairAndGroupBorrowingFees;
|
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.fetchOpenPairTradesRaw = exports.fetchOpenPairTrades = void 0;
|
|
13
4
|
const ethcall_1 = require("ethcall");
|
|
14
5
|
const trade_1 = require("../../trade");
|
|
15
|
-
const fetchOpenPairTrades = (contracts, overrides = {}) =>
|
|
16
|
-
const rawTrades =
|
|
17
|
-
const collaterals =
|
|
6
|
+
const fetchOpenPairTrades = async (contracts, overrides = {}) => {
|
|
7
|
+
const rawTrades = await (0, exports.fetchOpenPairTradesRaw)(contracts, overrides);
|
|
8
|
+
const collaterals = await contracts.gnsMultiCollatDiamond.getCollaterals();
|
|
18
9
|
const collateralConfigs = collaterals.map(c => ({
|
|
19
10
|
collateral: c.collateral,
|
|
20
11
|
isActive: c.isActive,
|
|
@@ -22,10 +13,10 @@ const fetchOpenPairTrades = (contracts, overrides = {}) => __awaiter(void 0, voi
|
|
|
22
13
|
precisionDelta: parseFloat(c.precisionDelta.toString()),
|
|
23
14
|
}));
|
|
24
15
|
return rawTrades.map(rawTrade => _prepareTradeContainer(rawTrade.trade, rawTrade.tradeInfo, rawTrade.liquidationParams, rawTrade.initialAccFees, rawTrade.tradeFeesData, rawTrade.uiRealizedPnlData, collateralConfigs[parseInt(rawTrade.trade.collateralIndex.toString()) - 1]));
|
|
25
|
-
}
|
|
16
|
+
};
|
|
26
17
|
exports.fetchOpenPairTrades = fetchOpenPairTrades;
|
|
27
18
|
// @todo rename
|
|
28
|
-
const fetchOpenPairTradesRaw = (contracts, overrides = {}) =>
|
|
19
|
+
const fetchOpenPairTradesRaw = async (contracts, overrides = {}) => {
|
|
29
20
|
if (!contracts) {
|
|
30
21
|
return [];
|
|
31
22
|
}
|
|
@@ -39,13 +30,13 @@ const fetchOpenPairTradesRaw = (contracts, overrides = {}) => __awaiter(void 0,
|
|
|
39
30
|
]),
|
|
40
31
|
};
|
|
41
32
|
if (useMulticall) {
|
|
42
|
-
|
|
33
|
+
await multicallCtx.provider.init(multiCollatDiamondContract.provider);
|
|
43
34
|
}
|
|
44
35
|
let allOpenPairTrades = [];
|
|
45
36
|
let running = true;
|
|
46
37
|
let offset = 0;
|
|
47
38
|
while (running) {
|
|
48
|
-
const [trades, tradeInfos, tradeLiquidationParams] =
|
|
39
|
+
const [trades, tradeInfos, tradeLiquidationParams] = await Promise.all([
|
|
49
40
|
multiCollatDiamondContract.getAllTrades(offset, offset + batchSize),
|
|
50
41
|
multiCollatDiamondContract.getAllTradeInfos(offset, offset + batchSize),
|
|
51
42
|
multiCollatDiamondContract.getAllTradesLiquidationParams(offset, offset + batchSize),
|
|
@@ -85,7 +76,7 @@ const fetchOpenPairTradesRaw = (contracts, overrides = {}) => __awaiter(void 0,
|
|
|
85
76
|
uiRealizedPnlData: undefined,
|
|
86
77
|
};
|
|
87
78
|
});
|
|
88
|
-
const [tradeFeesData, uiRealizedPnlData] =
|
|
79
|
+
const [tradeFeesData, uiRealizedPnlData] = await Promise.all([
|
|
89
80
|
multiCollatDiamondContract.getTradeFeesDataArray(...fundingFeesCallParams),
|
|
90
81
|
includeUIRealizedPnlData
|
|
91
82
|
? multiCollatDiamondContract.getTradeUiRealizedPnlDataArray(...fundingFeesCallParams)
|
|
@@ -100,13 +91,13 @@ const fetchOpenPairTradesRaw = (contracts, overrides = {}) => __awaiter(void 0,
|
|
|
100
91
|
.map(({ collateralIndex, user, index }) => (useMulticall
|
|
101
92
|
? multicallCtx.diamond
|
|
102
93
|
: multiCollatDiamondContract).getBorrowingInitialAccFees(collateralIndex, user, index));
|
|
103
|
-
const initialAccFees =
|
|
94
|
+
const initialAccFees = await (useMulticall
|
|
104
95
|
? multicallCtx.provider.all(initialAccFeesPromises)
|
|
105
96
|
: Promise.all(initialAccFeesPromises));
|
|
106
97
|
initialAccFees.forEach((accFees, ix) => {
|
|
107
98
|
openTrades[ix].initialAccFees = accFees;
|
|
108
99
|
openTrades[ix].tradeFeesData = tradeFeesData[ix];
|
|
109
|
-
openTrades[ix].uiRealizedPnlData = uiRealizedPnlData
|
|
100
|
+
openTrades[ix].uiRealizedPnlData = uiRealizedPnlData?.[ix];
|
|
110
101
|
});
|
|
111
102
|
allOpenPairTrades = allOpenPairTrades.concat(openTrades);
|
|
112
103
|
offset += batchSize + 1;
|
|
@@ -119,7 +110,7 @@ const fetchOpenPairTradesRaw = (contracts, overrides = {}) => __awaiter(void 0,
|
|
|
119
110
|
console.error(`Unexpected error while fetching open pair trades!`);
|
|
120
111
|
throw error;
|
|
121
112
|
}
|
|
122
|
-
}
|
|
113
|
+
};
|
|
123
114
|
exports.fetchOpenPairTradesRaw = fetchOpenPairTradesRaw;
|
|
124
115
|
const _prepareTradeContainer = (trade, tradeInfo, tradeLiquidationParams, tradeInitialAccFees, tradeFeesData, uiRealizedPnlData, collateralConfig) => {
|
|
125
116
|
const precision = collateralConfig.precision;
|
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getPairDescription = exports.fetchOpenInterest = exports.fetchFees = exports.fetchPairDepths = exports.fetchPairs = void 0;
|
|
13
4
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
14
5
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
15
6
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
16
7
|
const types_1 = require("../../trade/types");
|
|
17
|
-
const fetchPairs = (contracts, pairIxs) =>
|
|
8
|
+
const fetchPairs = async (contracts, pairIxs) => {
|
|
18
9
|
if (!contracts) {
|
|
19
10
|
return [];
|
|
20
11
|
}
|
|
21
12
|
const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
|
|
22
13
|
try {
|
|
23
|
-
const pairs =
|
|
14
|
+
const pairs = await Promise.all(pairIxs.map(pairIndex => multiCollatContract.pairs(pairIndex)));
|
|
24
15
|
return pairs.map((pair, index) => {
|
|
25
16
|
return {
|
|
26
17
|
name: pair.from + "/" + pair.to,
|
|
@@ -38,15 +29,15 @@ const fetchPairs = (contracts, pairIxs) => __awaiter(void 0, void 0, void 0, fun
|
|
|
38
29
|
console.error(`Unexpected error while fetching pairs!`);
|
|
39
30
|
throw error;
|
|
40
31
|
}
|
|
41
|
-
}
|
|
32
|
+
};
|
|
42
33
|
exports.fetchPairs = fetchPairs;
|
|
43
|
-
const fetchPairDepths = (contracts, pairIxs) =>
|
|
34
|
+
const fetchPairDepths = async (contracts, pairIxs) => {
|
|
44
35
|
if (!contracts) {
|
|
45
36
|
return [];
|
|
46
37
|
}
|
|
47
38
|
const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
|
|
48
39
|
try {
|
|
49
|
-
const pairParams =
|
|
40
|
+
const pairParams = await multiCollatContract.getPairDepths(pairIxs);
|
|
50
41
|
return pairParams.map(pair => {
|
|
51
42
|
return {
|
|
52
43
|
onePercentDepthAboveUsd: parseFloat(pair.onePercentDepthAboveUsd.toString()),
|
|
@@ -58,15 +49,15 @@ const fetchPairDepths = (contracts, pairIxs) => __awaiter(void 0, void 0, void 0
|
|
|
58
49
|
console.error(`Unexpected error while fetching pairs!`);
|
|
59
50
|
throw error;
|
|
60
51
|
}
|
|
61
|
-
}
|
|
52
|
+
};
|
|
62
53
|
exports.fetchPairDepths = fetchPairDepths;
|
|
63
|
-
const fetchFees = (contracts, feeIxs) =>
|
|
54
|
+
const fetchFees = async (contracts, feeIxs) => {
|
|
64
55
|
if (!contracts) {
|
|
65
56
|
return [];
|
|
66
57
|
}
|
|
67
58
|
const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
|
|
68
59
|
try {
|
|
69
|
-
const fees =
|
|
60
|
+
const fees = await Promise.all(feeIxs.map(pairIndex => multiCollatContract.fees(pairIndex)));
|
|
70
61
|
return fees.map(fee => {
|
|
71
62
|
return {
|
|
72
63
|
totalPositionSizeFeeP: parseFloat(fee.totalPositionSizeFeeP.toString()) / 1e12,
|
|
@@ -80,13 +71,13 @@ const fetchFees = (contracts, feeIxs) => __awaiter(void 0, void 0, void 0, funct
|
|
|
80
71
|
console.error(`Unexpected error while fetching pairs!`);
|
|
81
72
|
throw error;
|
|
82
73
|
}
|
|
83
|
-
}
|
|
74
|
+
};
|
|
84
75
|
exports.fetchFees = fetchFees;
|
|
85
|
-
const fetchOpenInterest = (contracts, collateralIndex, pairIxs) =>
|
|
76
|
+
const fetchOpenInterest = async (contracts, collateralIndex, pairIxs) => {
|
|
86
77
|
if (pairIxs.length === 0) {
|
|
87
78
|
return [];
|
|
88
79
|
}
|
|
89
|
-
const openInterests = (
|
|
80
|
+
const openInterests = (await contracts.gnsMultiCollatDiamond.getAllBorrowingPairs(collateralIndex))[1];
|
|
90
81
|
return pairIxs.map(pairIndex => {
|
|
91
82
|
const openInterest = openInterests[pairIndex];
|
|
92
83
|
if (!openInterest) {
|
|
@@ -98,7 +89,7 @@ const fetchOpenInterest = (contracts, collateralIndex, pairIxs) => __awaiter(voi
|
|
|
98
89
|
max: parseFloat(openInterest[2].toString()) / 1e10,
|
|
99
90
|
};
|
|
100
91
|
});
|
|
101
|
-
}
|
|
92
|
+
};
|
|
102
93
|
exports.fetchOpenInterest = fetchOpenInterest;
|
|
103
94
|
const getPairDescription = (pairIndex) => {
|
|
104
95
|
return PAIR_INDEX_TO_DESCRIPTION[pairIndex] || "";
|
package/lib/markets/forex.js
CHANGED
|
@@ -33,7 +33,7 @@ const isForexLowLiquidity = (timestampToCheck, pair) => {
|
|
|
33
33
|
const hour = now.hour;
|
|
34
34
|
const minute = now.minute;
|
|
35
35
|
const isInDST = now.isInDST;
|
|
36
|
-
const groupIndex = pair
|
|
36
|
+
const groupIndex = pair?.groupIndex;
|
|
37
37
|
if (groupIndex && extendedLowLiqGroupIds.includes(+groupIndex)) {
|
|
38
38
|
return ((isInDST &&
|
|
39
39
|
((hour == 14 && minute >= 45) || (hour >= 15 && hour < 21))) ||
|
|
@@ -18,8 +18,8 @@ const buildMarketLeverageRestrictionsContext = (globalTradingVariables, pairInde
|
|
|
18
18
|
return {
|
|
19
19
|
groupMinLeverage: group.minLeverage,
|
|
20
20
|
groupMaxLeverage: group.maxLeverage,
|
|
21
|
-
pairMaxLeverage: pairMaxLeverages
|
|
22
|
-
counterTradeSettings: counterTradeSettings
|
|
21
|
+
pairMaxLeverage: pairMaxLeverages?.[pairIndex],
|
|
22
|
+
counterTradeSettings: counterTradeSettings?.[pairIndex],
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
exports.buildMarketLeverageRestrictionsContext = buildMarketLeverageRestrictionsContext;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dev Fetchers for retrieving OI data from contracts
|
|
3
|
+
* @dev Consolidates the three OI storage systems into unified format
|
|
4
|
+
*/
|
|
5
|
+
import { ethers } from "ethers";
|
|
6
|
+
import { ChainId } from "../../contracts/types";
|
|
7
|
+
import { UnifiedPairOi } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* @dev Fetches all OI data for a single pair
|
|
10
|
+
* @param chainId Target chain
|
|
11
|
+
* @param collateralIndex Collateral type
|
|
12
|
+
* @param pairIndex Trading pair
|
|
13
|
+
* @param signer Ethers signer
|
|
14
|
+
* @returns Unified PairOi structure with all OI data
|
|
15
|
+
*/
|
|
16
|
+
export declare function fetchPairOi(chainId: ChainId, collateralIndex: number, pairIndex: number, signer: ethers.Signer): Promise<UnifiedPairOi>;
|
|
17
|
+
/**
|
|
18
|
+
* @dev Fetches OI data for multiple pairs efficiently
|
|
19
|
+
* @param chainId Target chain
|
|
20
|
+
* @param collateralIndex Collateral type
|
|
21
|
+
* @param pairIndices Array of trading pairs
|
|
22
|
+
* @param signer Ethers signer
|
|
23
|
+
* @returns Array of unified PairOi structures
|
|
24
|
+
*/
|
|
25
|
+
export declare function fetchMultiplePairOi(chainId: ChainId, collateralIndex: number, pairIndices: number[], signer: ethers.Signer): Promise<UnifiedPairOi[]>;
|
|
26
|
+
/**
|
|
27
|
+
* @dev Creates OI context for fee calculations
|
|
28
|
+
* @param chainId Target chain
|
|
29
|
+
* @param collateralIndex Collateral type
|
|
30
|
+
* @param pairIndex Trading pair
|
|
31
|
+
* @param signer Ethers signer
|
|
32
|
+
* @returns OI data formatted for SDK calculations
|
|
33
|
+
*/
|
|
34
|
+
export declare function createOiContext(chainId: ChainId, collateralIndex: number, pairIndex: number, signer: ethers.Signer): Promise<{
|
|
35
|
+
pairOi: UnifiedPairOi;
|
|
36
|
+
currentPrice: number;
|
|
37
|
+
computed: {
|
|
38
|
+
totalDynamicOi: {
|
|
39
|
+
long: number;
|
|
40
|
+
short: number;
|
|
41
|
+
};
|
|
42
|
+
totalStaticOi: {
|
|
43
|
+
long: number;
|
|
44
|
+
short: number;
|
|
45
|
+
};
|
|
46
|
+
skew: number;
|
|
47
|
+
};
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* @dev Fetches only the OI data needed for specific use cases
|
|
51
|
+
* @param chainId Target chain
|
|
52
|
+
* @param collateralIndex Collateral type
|
|
53
|
+
* @param pairIndex Trading pair
|
|
54
|
+
* @param useCase Which OI systems to fetch
|
|
55
|
+
* @param signer Ethers signer
|
|
56
|
+
* @returns Partial OI data based on use case
|
|
57
|
+
*/
|
|
58
|
+
export declare function fetchOiForUseCase(chainId: ChainId, collateralIndex: number, pairIndex: number, useCase: "skew" | "funding" | "borrowingV1" | "limits", signer: ethers.Signer): Promise<Partial<UnifiedPairOi>>;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @dev Fetchers for retrieving OI data from contracts
|
|
4
|
+
* @dev Consolidates the three OI storage systems into unified format
|
|
5
|
+
*/
|
|
6
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.fetchOiForUseCase = exports.createOiContext = exports.fetchMultiplePairOi = exports.fetchPairOi = void 0;
|
|
17
|
+
const ethers_1 = require("ethers");
|
|
18
|
+
const contracts_1 = require("../../contracts");
|
|
19
|
+
const generated_1 = require("../../contracts/types/generated");
|
|
20
|
+
const converter_1 = require("./converter");
|
|
21
|
+
/**
|
|
22
|
+
* @dev Fetches all OI data for a single pair
|
|
23
|
+
* @param chainId Target chain
|
|
24
|
+
* @param collateralIndex Collateral type
|
|
25
|
+
* @param pairIndex Trading pair
|
|
26
|
+
* @param signer Ethers signer
|
|
27
|
+
* @returns Unified PairOi structure with all OI data
|
|
28
|
+
*/
|
|
29
|
+
function fetchPairOi(chainId, collateralIndex, pairIndex, signer) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const addresses = (0, contracts_1.getContractAddressesForChain)(chainId);
|
|
32
|
+
const diamond = generated_1.GNSMultiCollatDiamond__factory.connect(addresses.gnsMultiCollatDiamond, signer);
|
|
33
|
+
// Fetch all three OI types in parallel
|
|
34
|
+
const [beforeV10Raw, afterV10Collateral, afterV10Token, maxOi, collateral] = yield Promise.all([
|
|
35
|
+
diamond.getPairOisBeforeV10Collateral(collateralIndex, pairIndex),
|
|
36
|
+
diamond.getPairOiAfterV10Collateral(collateralIndex, pairIndex),
|
|
37
|
+
diamond.getPairOiAfterV10Token(collateralIndex, pairIndex),
|
|
38
|
+
diamond.getPairMaxOi(collateralIndex, pairIndex),
|
|
39
|
+
diamond.getCollateral(collateralIndex),
|
|
40
|
+
]);
|
|
41
|
+
// Convert the beforeV10 format to match expected structure
|
|
42
|
+
const beforeV10 = {
|
|
43
|
+
long: beforeV10Raw.longOi,
|
|
44
|
+
short: beforeV10Raw.shortOi,
|
|
45
|
+
max: maxOi,
|
|
46
|
+
__placeholder: ethers_1.ethers.BigNumber.from(0),
|
|
47
|
+
};
|
|
48
|
+
return (0, converter_1.convertPairOi)(beforeV10, afterV10Collateral, afterV10Token, Number(collateral.precision));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.fetchPairOi = fetchPairOi;
|
|
52
|
+
/**
|
|
53
|
+
* @dev Fetches OI data for multiple pairs efficiently
|
|
54
|
+
* @param chainId Target chain
|
|
55
|
+
* @param collateralIndex Collateral type
|
|
56
|
+
* @param pairIndices Array of trading pairs
|
|
57
|
+
* @param signer Ethers signer
|
|
58
|
+
* @returns Array of unified PairOi structures
|
|
59
|
+
*/
|
|
60
|
+
function fetchMultiplePairOi(chainId, collateralIndex, pairIndices, signer) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const addresses = (0, contracts_1.getContractAddressesForChain)(chainId);
|
|
63
|
+
const diamond = generated_1.GNSMultiCollatDiamond__factory.connect(addresses.gnsMultiCollatDiamond, signer);
|
|
64
|
+
// Get collateral precision once
|
|
65
|
+
const collateral = yield diamond.getCollateral(collateralIndex);
|
|
66
|
+
const precision = Number(collateral.precision);
|
|
67
|
+
// Batch fetch all OI data
|
|
68
|
+
const promises = pairIndices.map((pairIndex) => __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const [beforeV10Raw, afterV10Collateral, afterV10Token, maxOi] = yield Promise.all([
|
|
70
|
+
diamond.getPairOisBeforeV10Collateral(collateralIndex, pairIndex),
|
|
71
|
+
diamond.getPairOiAfterV10Collateral(collateralIndex, pairIndex),
|
|
72
|
+
diamond.getPairOiAfterV10Token(collateralIndex, pairIndex),
|
|
73
|
+
diamond.getPairMaxOi(collateralIndex, pairIndex),
|
|
74
|
+
]);
|
|
75
|
+
// Convert the beforeV10 format to match expected structure
|
|
76
|
+
const beforeV10 = {
|
|
77
|
+
long: beforeV10Raw.longOi,
|
|
78
|
+
short: beforeV10Raw.shortOi,
|
|
79
|
+
max: maxOi,
|
|
80
|
+
__placeholder: ethers_1.ethers.BigNumber.from(0),
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
beforeV10: beforeV10,
|
|
84
|
+
collateral: afterV10Collateral,
|
|
85
|
+
token: afterV10Token,
|
|
86
|
+
};
|
|
87
|
+
}));
|
|
88
|
+
const results = yield Promise.all(promises);
|
|
89
|
+
return (0, converter_1.convertPairOiArray)(results, precision);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
exports.fetchMultiplePairOi = fetchMultiplePairOi;
|
|
93
|
+
/**
|
|
94
|
+
* @dev Creates OI context for fee calculations
|
|
95
|
+
* @param chainId Target chain
|
|
96
|
+
* @param collateralIndex Collateral type
|
|
97
|
+
* @param pairIndex Trading pair
|
|
98
|
+
* @param signer Ethers signer
|
|
99
|
+
* @returns OI data formatted for SDK calculations
|
|
100
|
+
*/
|
|
101
|
+
function createOiContext(chainId, collateralIndex, pairIndex, signer) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
// Fetch OI data
|
|
104
|
+
const pairOi = yield fetchPairOi(chainId, collateralIndex, pairIndex, signer);
|
|
105
|
+
// For now, use a placeholder price - in real usage, this would come from price feeds
|
|
106
|
+
// The actual price should be fetched from the price aggregator or oracle
|
|
107
|
+
const currentPrice = 1; // Placeholder - replace with actual price fetching
|
|
108
|
+
// Compute derived values
|
|
109
|
+
const totalDynamicOi = {
|
|
110
|
+
long: pairOi.beforeV10Collateral.long + pairOi.token.long * currentPrice,
|
|
111
|
+
short: pairOi.beforeV10Collateral.short + pairOi.token.short * currentPrice,
|
|
112
|
+
};
|
|
113
|
+
const totalStaticOi = {
|
|
114
|
+
long: pairOi.beforeV10Collateral.long + pairOi.collateral.long,
|
|
115
|
+
short: pairOi.beforeV10Collateral.short + pairOi.collateral.short,
|
|
116
|
+
};
|
|
117
|
+
const skew = pairOi.token.long - pairOi.token.short;
|
|
118
|
+
return {
|
|
119
|
+
pairOi,
|
|
120
|
+
currentPrice,
|
|
121
|
+
computed: {
|
|
122
|
+
totalDynamicOi,
|
|
123
|
+
totalStaticOi,
|
|
124
|
+
skew,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
exports.createOiContext = createOiContext;
|
|
130
|
+
/**
|
|
131
|
+
* @dev Fetches only the OI data needed for specific use cases
|
|
132
|
+
* @param chainId Target chain
|
|
133
|
+
* @param collateralIndex Collateral type
|
|
134
|
+
* @param pairIndex Trading pair
|
|
135
|
+
* @param useCase Which OI systems to fetch
|
|
136
|
+
* @param signer Ethers signer
|
|
137
|
+
* @returns Partial OI data based on use case
|
|
138
|
+
*/
|
|
139
|
+
function fetchOiForUseCase(chainId, collateralIndex, pairIndex, useCase, signer) {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
const addresses = (0, contracts_1.getContractAddressesForChain)(chainId);
|
|
142
|
+
const diamond = generated_1.GNSMultiCollatDiamond__factory.connect(addresses.gnsMultiCollatDiamond, signer);
|
|
143
|
+
switch (useCase) {
|
|
144
|
+
case "skew":
|
|
145
|
+
case "funding": {
|
|
146
|
+
// Only need token OI
|
|
147
|
+
const tokenOi = yield diamond.getPairOiAfterV10Token(collateralIndex, pairIndex);
|
|
148
|
+
return {
|
|
149
|
+
token: (0, converter_1.convertTokenOi)(tokenOi),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
case "borrowingV1": {
|
|
153
|
+
// Need beforeV10 and token (for dynamic calculation)
|
|
154
|
+
const [beforeV10Raw, tokenOi, collateral, maxOi] = yield Promise.all([
|
|
155
|
+
diamond.getPairOisBeforeV10Collateral(collateralIndex, pairIndex),
|
|
156
|
+
diamond.getPairOiAfterV10Token(collateralIndex, pairIndex),
|
|
157
|
+
diamond.getCollateral(collateralIndex),
|
|
158
|
+
diamond.getPairMaxOi(collateralIndex, pairIndex),
|
|
159
|
+
]);
|
|
160
|
+
// Convert the beforeV10 format to match expected structure
|
|
161
|
+
const beforeV10 = {
|
|
162
|
+
long: beforeV10Raw.longOi,
|
|
163
|
+
short: beforeV10Raw.shortOi,
|
|
164
|
+
max: maxOi,
|
|
165
|
+
__placeholder: ethers_1.ethers.BigNumber.from(0),
|
|
166
|
+
};
|
|
167
|
+
return {
|
|
168
|
+
beforeV10Collateral: (0, converter_1.convertBeforeV10Collateral)(beforeV10, Number(collateral.precision)),
|
|
169
|
+
token: (0, converter_1.convertTokenOi)(tokenOi),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
case "limits": {
|
|
173
|
+
// Need all OI for limit checks
|
|
174
|
+
return fetchPairOi(chainId, collateralIndex, pairIndex, signer);
|
|
175
|
+
}
|
|
176
|
+
default:
|
|
177
|
+
throw new Error(`Unknown use case: ${String(useCase)}`);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
exports.fetchOiForUseCase = fetchOiForUseCase;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dev OI Validation module
|
|
3
|
+
* @dev Provides validation functions for Open Interest limits
|
|
4
|
+
*/
|
|
5
|
+
import { UnifiedPairOi } from "./types";
|
|
6
|
+
import * as BorrowingFee from "../../trade/fees/borrowing/types";
|
|
7
|
+
import { PairIndex } from "../../trade/types";
|
|
8
|
+
/**
|
|
9
|
+
* @dev Check if a position would exceed per-pair OI limits
|
|
10
|
+
* @param pairOi Current OI data for the pair
|
|
11
|
+
* @param long Whether the position is long
|
|
12
|
+
* @param positionSizeCollateral Position size in collateral
|
|
13
|
+
* @param currentPrice Current collateral price in USD (required for dynamic OI)
|
|
14
|
+
* @returns true if within limits, false if would exceed
|
|
15
|
+
*/
|
|
16
|
+
export declare const withinMaxPairOi: (pairOi: UnifiedPairOi, long: boolean, positionSizeCollateral: number, currentPrice: number) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* @dev Calculate dynamic OI for a specific side
|
|
19
|
+
* @param pairOi OI data for the pair
|
|
20
|
+
* @param currentPrice Current collateral price in USD
|
|
21
|
+
* @param long Whether to calculate for long side
|
|
22
|
+
* @returns Dynamic OI in collateral value
|
|
23
|
+
*/
|
|
24
|
+
export declare const calculateDynamicOi: (pairOi: UnifiedPairOi, currentPrice: number, long: boolean) => number;
|
|
25
|
+
/**
|
|
26
|
+
* @dev Calculate remaining OI capacity for a side
|
|
27
|
+
* @param pairOi OI data for the pair
|
|
28
|
+
* @param currentPrice Current collateral price in USD
|
|
29
|
+
* @param long Whether to calculate for long side
|
|
30
|
+
* @returns Remaining capacity in collateral (0 if unlimited)
|
|
31
|
+
*/
|
|
32
|
+
export declare const getRemainingOiCapacity: (pairOi: UnifiedPairOi, currentPrice: number, long: boolean) => number;
|
|
33
|
+
/**
|
|
34
|
+
* @dev Updated group OI validation using dynamic OI
|
|
35
|
+
* @param pairIndex Index of the trading pair
|
|
36
|
+
* @param long Whether the position is long
|
|
37
|
+
* @param positionSizeCollateral Position size in collateral
|
|
38
|
+
* @param currentPrice Current collateral price in USD
|
|
39
|
+
* @param context Context with groups, pairs, and OI data
|
|
40
|
+
* @returns true if within group limits, false if would exceed
|
|
41
|
+
*/
|
|
42
|
+
export declare const withinMaxGroupOiDynamic: (pairIndex: PairIndex, long: boolean, positionSizeCollateral: number, currentPrice: number, context: {
|
|
43
|
+
groups: BorrowingFee.Group[];
|
|
44
|
+
pairs: BorrowingFee.Pair[];
|
|
45
|
+
pairOis: UnifiedPairOi[];
|
|
46
|
+
}) => boolean;
|
|
47
|
+
/**
|
|
48
|
+
* @dev Calculate total dynamic OI for a group
|
|
49
|
+
* @param groupIndex Index of the group
|
|
50
|
+
* @param currentPrice Current collateral price in USD
|
|
51
|
+
* @param context Context with pairs and OI data
|
|
52
|
+
* @returns Total dynamic OI for the group
|
|
53
|
+
*/
|
|
54
|
+
export declare const getGroupDynamicOi: (groupIndex: number, currentPrice: number, context: {
|
|
55
|
+
pairs: BorrowingFee.Pair[];
|
|
56
|
+
pairOis: UnifiedPairOi[];
|
|
57
|
+
}) => {
|
|
58
|
+
long: number;
|
|
59
|
+
short: number;
|
|
60
|
+
total: number;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* @dev Check both pair and group OI limits
|
|
64
|
+
* @param pairIndex Index of the trading pair
|
|
65
|
+
* @param long Whether the position is long
|
|
66
|
+
* @param positionSizeCollateral Position size in collateral
|
|
67
|
+
* @param currentPrice Current collateral price in USD
|
|
68
|
+
* @param context Full context with all required data
|
|
69
|
+
* @returns Object with validation results
|
|
70
|
+
*/
|
|
71
|
+
export declare const validateOiLimits: (pairIndex: PairIndex, long: boolean, positionSizeCollateral: number, currentPrice: number, context: {
|
|
72
|
+
groups: BorrowingFee.Group[];
|
|
73
|
+
pairs: BorrowingFee.Pair[];
|
|
74
|
+
pairOis: UnifiedPairOi[];
|
|
75
|
+
}) => {
|
|
76
|
+
withinPairLimit: boolean;
|
|
77
|
+
withinGroupLimit: boolean;
|
|
78
|
+
pairRemainingCapacity: number;
|
|
79
|
+
groupRemainingCapacity: number;
|
|
80
|
+
};
|