@gainsnetwork/sdk 1.0.6-rc3 → 1.1.0-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/backend.types.d.ts +11 -4
- package/lib/backend/tradingVariables/converter.d.ts +7 -3
- package/lib/backend/tradingVariables/converter.js +70 -63
- package/lib/backend/tradingVariables/index.js +11 -7
- package/lib/backend/tradingVariables/types.d.ts +4 -2
- package/lib/contracts/addresses.js +1 -4
- 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 +223 -40
- 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 +10 -2
- package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +317 -36
- 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 +20 -9
- package/lib/contracts/utils/openTrades.js +20 -11
- package/lib/contracts/utils/pairs.d.ts +13 -2
- package/lib/contracts/utils/pairs.js +89 -21
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- 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 +0 -1
- package/lib/markets/price/index.js +0 -1
- package/lib/markets/price/signedPrices.d.ts +7 -0
- package/lib/markets/price/signedPrices.js +55 -2
- package/lib/markets/price/types.d.ts +0 -27
- 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 +92 -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 +3 -2
- package/lib/trade/fees/borrowing/converter.js +1 -5
- package/lib/trade/fees/borrowing/index.js +5 -5
- package/lib/trade/fees/borrowingV2/builder.js +4 -3
- package/lib/trade/fees/borrowingV2/converter.js +1 -1
- package/lib/trade/fees/borrowingV2/fetcher.d.ts +0 -1
- package/lib/trade/fees/borrowingV2/fetcher.js +32 -26
- package/lib/trade/fees/borrowingV2/index.js +3 -3
- package/lib/trade/fees/converter.js +22 -22
- package/lib/trade/fees/fundingFees/builder.js +7 -6
- package/lib/trade/fees/fundingFees/converter.js +1 -1
- package/lib/trade/fees/fundingFees/fetcher.js +25 -16
- package/lib/trade/fees/fundingFees/index.js +3 -2
- 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 +2 -1
- 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 +3 -5
- package/lib/trade/liquidation/builder.js +3 -6
- package/lib/trade/liquidation/index.js +6 -4
- package/lib/trade/oiWindows.js +2 -1
- package/lib/trade/pnl/builder.js +2 -1
- package/lib/trade/pnl/converter.js +1 -1
- package/lib/trade/pnl/index.js +7 -4
- package/lib/trade/priceImpact/close/builder.js +2 -1
- package/lib/trade/priceImpact/close/index.js +1 -4
- package/lib/trade/priceImpact/cumulVol/builder.js +11 -18
- package/lib/trade/priceImpact/cumulVol/converter.d.ts +63 -0
- package/lib/trade/priceImpact/cumulVol/converter.js +97 -1
- package/lib/trade/priceImpact/cumulVol/index.d.ts +3 -0
- package/lib/trade/priceImpact/cumulVol/index.js +123 -25
- 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 +2 -1
- package/lib/trade/priceImpact/open/index.js +1 -4
- package/lib/trade/priceImpact/skew/builder.js +3 -2
- package/lib/trade/priceImpact/skew/converter.js +1 -1
- package/lib/trade/priceImpact/skew/fetcher.js +33 -24
- package/package.json +2 -2
|
@@ -1,4 +1,13 @@
|
|
|
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.fetchAllPairAndGroupBorrowingFees = exports.fetchGroupBorrowingFees = exports.fetchAllPairBorrowingFees = exports.getBorrowingGroupName = void 0;
|
|
4
13
|
const trade_1 = require("../../trade");
|
|
@@ -22,22 +31,24 @@ const getBorrowingGroupName = (groupIndex) => {
|
|
|
22
31
|
return groupNamesByIndex[groupIndex - 1] || "Unknown";
|
|
23
32
|
};
|
|
24
33
|
exports.getBorrowingGroupName = getBorrowingGroupName;
|
|
25
|
-
const fetchAllPairBorrowingFees =
|
|
26
|
-
const [pairs, pairOi, pairGroups] =
|
|
27
|
-
const feeCaps =
|
|
34
|
+
const fetchAllPairBorrowingFees = (contract, collateralIndex) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
const [pairs, pairOi, pairGroups] = yield contract.getAllBorrowingPairs(collateralIndex);
|
|
36
|
+
const feeCaps = yield contract.getBorrowingPairFeePerBlockCaps(collateralIndex, [...Array(pairs.length).keys()]);
|
|
28
37
|
return (0, trade_1.convertPairBorrowingFees)([pairs, pairOi, pairGroups, feeCaps]);
|
|
29
|
-
};
|
|
38
|
+
});
|
|
30
39
|
exports.fetchAllPairBorrowingFees = fetchAllPairBorrowingFees;
|
|
31
|
-
const fetchGroupBorrowingFees =
|
|
40
|
+
const fetchGroupBorrowingFees = (contract, collateralIndex, groupIxs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
return (0, trade_1.convertGroupBorrowingFees)(yield contract.getBorrowingGroups(collateralIndex, groupIxs));
|
|
42
|
+
});
|
|
32
43
|
exports.fetchGroupBorrowingFees = fetchGroupBorrowingFees;
|
|
33
|
-
const fetchAllPairAndGroupBorrowingFees =
|
|
34
|
-
const pairs =
|
|
44
|
+
const fetchAllPairAndGroupBorrowingFees = (contract, collateralIndex) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
const pairs = yield (0, exports.fetchAllPairBorrowingFees)(contract, collateralIndex);
|
|
35
46
|
const groupIxs = [
|
|
36
47
|
...new Set(pairs
|
|
37
48
|
.map(value => value.groups.map(value => value.groupIndex))
|
|
38
49
|
.reduce((acc, value) => acc.concat(value), [])),
|
|
39
50
|
].sort((a, b) => a - b);
|
|
40
|
-
const groups =
|
|
51
|
+
const groups = yield (0, exports.fetchGroupBorrowingFees)(contract, collateralIndex, groupIxs);
|
|
41
52
|
return { pairs, groups };
|
|
42
|
-
};
|
|
53
|
+
});
|
|
43
54
|
exports.fetchAllPairAndGroupBorrowingFees = fetchAllPairAndGroupBorrowingFees;
|
|
@@ -1,11 +1,20 @@
|
|
|
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.fetchOpenPairTradesRaw = exports.fetchOpenPairTrades = void 0;
|
|
4
13
|
const ethcall_1 = require("ethcall");
|
|
5
14
|
const trade_1 = require("../../trade");
|
|
6
|
-
const fetchOpenPairTrades =
|
|
7
|
-
const rawTrades =
|
|
8
|
-
const collaterals =
|
|
15
|
+
const fetchOpenPairTrades = (contracts, overrides = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const rawTrades = yield (0, exports.fetchOpenPairTradesRaw)(contracts, overrides);
|
|
17
|
+
const collaterals = yield contracts.gnsMultiCollatDiamond.getCollaterals();
|
|
9
18
|
const collateralConfigs = collaterals.map(c => ({
|
|
10
19
|
collateral: c.collateral,
|
|
11
20
|
isActive: c.isActive,
|
|
@@ -13,10 +22,10 @@ const fetchOpenPairTrades = async (contracts, overrides = {}) => {
|
|
|
13
22
|
precisionDelta: parseFloat(c.precisionDelta.toString()),
|
|
14
23
|
}));
|
|
15
24
|
return rawTrades.map(rawTrade => _prepareTradeContainer(rawTrade.trade, rawTrade.tradeInfo, rawTrade.liquidationParams, rawTrade.initialAccFees, rawTrade.tradeFeesData, rawTrade.uiRealizedPnlData, collateralConfigs[parseInt(rawTrade.trade.collateralIndex.toString()) - 1]));
|
|
16
|
-
};
|
|
25
|
+
});
|
|
17
26
|
exports.fetchOpenPairTrades = fetchOpenPairTrades;
|
|
18
27
|
// @todo rename
|
|
19
|
-
const fetchOpenPairTradesRaw =
|
|
28
|
+
const fetchOpenPairTradesRaw = (contracts, overrides = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
29
|
if (!contracts) {
|
|
21
30
|
return [];
|
|
22
31
|
}
|
|
@@ -30,13 +39,13 @@ const fetchOpenPairTradesRaw = async (contracts, overrides = {}) => {
|
|
|
30
39
|
]),
|
|
31
40
|
};
|
|
32
41
|
if (useMulticall) {
|
|
33
|
-
|
|
42
|
+
yield multicallCtx.provider.init(multiCollatDiamondContract.provider);
|
|
34
43
|
}
|
|
35
44
|
let allOpenPairTrades = [];
|
|
36
45
|
let running = true;
|
|
37
46
|
let offset = 0;
|
|
38
47
|
while (running) {
|
|
39
|
-
const [trades, tradeInfos, tradeLiquidationParams] =
|
|
48
|
+
const [trades, tradeInfos, tradeLiquidationParams] = yield Promise.all([
|
|
40
49
|
multiCollatDiamondContract.getAllTrades(offset, offset + batchSize),
|
|
41
50
|
multiCollatDiamondContract.getAllTradeInfos(offset, offset + batchSize),
|
|
42
51
|
multiCollatDiamondContract.getAllTradesLiquidationParams(offset, offset + batchSize),
|
|
@@ -76,7 +85,7 @@ const fetchOpenPairTradesRaw = async (contracts, overrides = {}) => {
|
|
|
76
85
|
uiRealizedPnlData: undefined,
|
|
77
86
|
};
|
|
78
87
|
});
|
|
79
|
-
const [tradeFeesData, uiRealizedPnlData] =
|
|
88
|
+
const [tradeFeesData, uiRealizedPnlData] = yield Promise.all([
|
|
80
89
|
multiCollatDiamondContract.getTradeFeesDataArray(...fundingFeesCallParams),
|
|
81
90
|
includeUIRealizedPnlData
|
|
82
91
|
? multiCollatDiamondContract.getTradeUiRealizedPnlDataArray(...fundingFeesCallParams)
|
|
@@ -91,13 +100,13 @@ const fetchOpenPairTradesRaw = async (contracts, overrides = {}) => {
|
|
|
91
100
|
.map(({ collateralIndex, user, index }) => (useMulticall
|
|
92
101
|
? multicallCtx.diamond
|
|
93
102
|
: multiCollatDiamondContract).getBorrowingInitialAccFees(collateralIndex, user, index));
|
|
94
|
-
const initialAccFees =
|
|
103
|
+
const initialAccFees = yield (useMulticall
|
|
95
104
|
? multicallCtx.provider.all(initialAccFeesPromises)
|
|
96
105
|
: Promise.all(initialAccFeesPromises));
|
|
97
106
|
initialAccFees.forEach((accFees, ix) => {
|
|
98
107
|
openTrades[ix].initialAccFees = accFees;
|
|
99
108
|
openTrades[ix].tradeFeesData = tradeFeesData[ix];
|
|
100
|
-
openTrades[ix].uiRealizedPnlData = uiRealizedPnlData
|
|
109
|
+
openTrades[ix].uiRealizedPnlData = uiRealizedPnlData === null || uiRealizedPnlData === void 0 ? void 0 : uiRealizedPnlData[ix];
|
|
101
110
|
});
|
|
102
111
|
allOpenPairTrades = allOpenPairTrades.concat(openTrades);
|
|
103
112
|
offset += batchSize + 1;
|
|
@@ -110,7 +119,7 @@ const fetchOpenPairTradesRaw = async (contracts, overrides = {}) => {
|
|
|
110
119
|
console.error(`Unexpected error while fetching open pair trades!`);
|
|
111
120
|
throw error;
|
|
112
121
|
}
|
|
113
|
-
};
|
|
122
|
+
});
|
|
114
123
|
exports.fetchOpenPairTradesRaw = fetchOpenPairTradesRaw;
|
|
115
124
|
const _prepareTradeContainer = (trade, tradeInfo, tradeLiquidationParams, tradeInitialAccFees, tradeFeesData, uiRealizedPnlData, collateralConfig) => {
|
|
116
125
|
const precision = collateralConfig.precision;
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import { Pair, Fee, OpenInterest,
|
|
1
|
+
import { Pair, Fee, OpenInterest, PairIndex } from "../../trade/types";
|
|
2
2
|
import { Contracts } from "../../contracts/types";
|
|
3
3
|
export declare const fetchPairs: (contracts: Contracts, pairIxs: PairIndex[]) => Promise<Pair[]>;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const fetchPairDepthBands: (contracts: Contracts, pairIxs: number[]) => Promise<any[]>;
|
|
5
|
+
export declare const fetchPairDepthBandsDecoded: (contracts: Contracts, pairIxs: number[]) => Promise<{
|
|
6
|
+
totalDepthAboveUsd: number[];
|
|
7
|
+
totalDepthBelowUsd: number[];
|
|
8
|
+
bandsAbove: number[][];
|
|
9
|
+
bandsBelow: number[][];
|
|
10
|
+
}>;
|
|
11
|
+
export declare const fetchDepthBandsMapping: (contracts: Contracts) => Promise<{
|
|
12
|
+
slot1: string;
|
|
13
|
+
slot2: string;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const fetchDepthBandsMappingDecoded: (contracts: Contracts) => Promise<number[]>;
|
|
5
16
|
export declare const fetchFees: (contracts: Contracts, feeIxs: PairIndex[]) => Promise<Fee[]>;
|
|
6
17
|
export declare const fetchOpenInterest: (contracts: Contracts, collateralIndex: number, pairIxs: number[]) => Promise<OpenInterest[]>;
|
|
7
18
|
export declare const getPairDescription: (pairIndex: PairIndex) => string;
|
|
@@ -1,17 +1,26 @@
|
|
|
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPairDescription = exports.fetchOpenInterest = exports.fetchFees = exports.
|
|
12
|
+
exports.getPairDescription = exports.fetchOpenInterest = exports.fetchFees = exports.fetchDepthBandsMappingDecoded = exports.fetchDepthBandsMapping = exports.fetchPairDepthBandsDecoded = exports.fetchPairDepthBands = exports.fetchPairs = void 0;
|
|
4
13
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
5
14
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
6
15
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
7
16
|
const types_1 = require("../../trade/types");
|
|
8
|
-
const fetchPairs =
|
|
17
|
+
const fetchPairs = (contracts, pairIxs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
9
18
|
if (!contracts) {
|
|
10
19
|
return [];
|
|
11
20
|
}
|
|
12
21
|
const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
|
|
13
22
|
try {
|
|
14
|
-
const pairs =
|
|
23
|
+
const pairs = yield Promise.all(pairIxs.map(pairIndex => multiCollatContract.pairs(pairIndex)));
|
|
15
24
|
return pairs.map((pair, index) => {
|
|
16
25
|
return {
|
|
17
26
|
name: pair.from + "/" + pair.to,
|
|
@@ -29,35 +38,94 @@ const fetchPairs = async (contracts, pairIxs) => {
|
|
|
29
38
|
console.error(`Unexpected error while fetching pairs!`);
|
|
30
39
|
throw error;
|
|
31
40
|
}
|
|
32
|
-
};
|
|
41
|
+
});
|
|
33
42
|
exports.fetchPairs = fetchPairs;
|
|
34
|
-
const
|
|
43
|
+
const fetchPairDepthBands = (contracts, pairIxs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
if (!contracts || pairIxs.length === 0) {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
|
|
48
|
+
try {
|
|
49
|
+
// Returns array of PairDepthBands structs (encoded slots)
|
|
50
|
+
// Using quoted signature for overloaded function
|
|
51
|
+
const depthBands = yield multiCollatContract["getPairDepthBands(uint256[])"](pairIxs);
|
|
52
|
+
return depthBands;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error(`Unexpected error while fetching pair depth bands!`);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
exports.fetchPairDepthBands = fetchPairDepthBands;
|
|
60
|
+
const fetchPairDepthBandsDecoded = (contracts, pairIxs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
if (!contracts || pairIxs.length === 0) {
|
|
62
|
+
return {
|
|
63
|
+
totalDepthAboveUsd: [],
|
|
64
|
+
totalDepthBelowUsd: [],
|
|
65
|
+
bandsAbove: [],
|
|
66
|
+
bandsBelow: [],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
|
|
70
|
+
try {
|
|
71
|
+
// Returns decoded values
|
|
72
|
+
// Using quoted signature for overloaded function
|
|
73
|
+
const [totalDepthAboveUsd, totalDepthBelowUsd, bandsAbove, bandsBelow] = yield multiCollatContract["getPairDepthBandsDecoded(uint256[])"](pairIxs);
|
|
74
|
+
return {
|
|
75
|
+
totalDepthAboveUsd: totalDepthAboveUsd.map((v) => parseFloat(v.toString())),
|
|
76
|
+
totalDepthBelowUsd: totalDepthBelowUsd.map((v) => parseFloat(v.toString())),
|
|
77
|
+
bandsAbove: bandsAbove.map((bands) => bands.map((b) => parseInt(b.toString()))),
|
|
78
|
+
bandsBelow: bandsBelow.map((bands) => bands.map((b) => parseInt(b.toString()))),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
console.error(`Unexpected error while fetching decoded pair depth bands!`);
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
exports.fetchPairDepthBandsDecoded = fetchPairDepthBandsDecoded;
|
|
87
|
+
const fetchDepthBandsMapping = (contracts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
|
+
if (!contracts) {
|
|
89
|
+
return { slot1: "0", slot2: "0" };
|
|
90
|
+
}
|
|
91
|
+
const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
|
|
92
|
+
try {
|
|
93
|
+
// Returns two uint256 slots
|
|
94
|
+
const [slot1, slot2] = yield multiCollatContract.getDepthBandsMapping();
|
|
95
|
+
return {
|
|
96
|
+
slot1: slot1.toString(),
|
|
97
|
+
slot2: slot2.toString(),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
console.error(`Unexpected error while fetching depth bands mapping!`);
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
exports.fetchDepthBandsMapping = fetchDepthBandsMapping;
|
|
106
|
+
const fetchDepthBandsMappingDecoded = (contracts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
107
|
if (!contracts) {
|
|
36
108
|
return [];
|
|
37
109
|
}
|
|
38
110
|
const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
|
|
39
111
|
try {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
onePercentDepthAboveUsd: parseFloat(pair.onePercentDepthAboveUsd.toString()),
|
|
44
|
-
onePercentDepthBelowUsd: parseFloat(pair.onePercentDepthBelowUsd.toString()),
|
|
45
|
-
};
|
|
46
|
-
});
|
|
112
|
+
// Returns array of 30 uint16 values
|
|
113
|
+
const bands = yield multiCollatContract.getDepthBandsMappingDecoded();
|
|
114
|
+
return bands.map((b) => parseInt(b.toString()));
|
|
47
115
|
}
|
|
48
116
|
catch (error) {
|
|
49
|
-
console.error(`Unexpected error while fetching
|
|
117
|
+
console.error(`Unexpected error while fetching decoded depth bands mapping!`);
|
|
50
118
|
throw error;
|
|
51
119
|
}
|
|
52
|
-
};
|
|
53
|
-
exports.
|
|
54
|
-
const fetchFees =
|
|
120
|
+
});
|
|
121
|
+
exports.fetchDepthBandsMappingDecoded = fetchDepthBandsMappingDecoded;
|
|
122
|
+
const fetchFees = (contracts, feeIxs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
123
|
if (!contracts) {
|
|
56
124
|
return [];
|
|
57
125
|
}
|
|
58
126
|
const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
|
|
59
127
|
try {
|
|
60
|
-
const fees =
|
|
128
|
+
const fees = yield Promise.all(feeIxs.map(pairIndex => multiCollatContract.fees(pairIndex)));
|
|
61
129
|
return fees.map(fee => {
|
|
62
130
|
return {
|
|
63
131
|
totalPositionSizeFeeP: parseFloat(fee.totalPositionSizeFeeP.toString()) / 1e12,
|
|
@@ -71,13 +139,13 @@ const fetchFees = async (contracts, feeIxs) => {
|
|
|
71
139
|
console.error(`Unexpected error while fetching pairs!`);
|
|
72
140
|
throw error;
|
|
73
141
|
}
|
|
74
|
-
};
|
|
142
|
+
});
|
|
75
143
|
exports.fetchFees = fetchFees;
|
|
76
|
-
const fetchOpenInterest =
|
|
144
|
+
const fetchOpenInterest = (contracts, collateralIndex, pairIxs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
145
|
if (pairIxs.length === 0) {
|
|
78
146
|
return [];
|
|
79
147
|
}
|
|
80
|
-
const openInterests = (
|
|
148
|
+
const openInterests = (yield contracts.gnsMultiCollatDiamond.getAllBorrowingPairs(collateralIndex))[1];
|
|
81
149
|
return pairIxs.map(pairIndex => {
|
|
82
150
|
const openInterest = openInterests[pairIndex];
|
|
83
151
|
if (!openInterest) {
|
|
@@ -89,7 +157,7 @@ const fetchOpenInterest = async (contracts, collateralIndex, pairIxs) => {
|
|
|
89
157
|
max: parseFloat(openInterest[2].toString()) / 1e10,
|
|
90
158
|
};
|
|
91
159
|
});
|
|
92
|
-
};
|
|
160
|
+
});
|
|
93
161
|
exports.fetchOpenInterest = fetchOpenInterest;
|
|
94
162
|
const getPairDescription = (pairIndex) => {
|
|
95
163
|
return PAIR_INDEX_TO_DESCRIPTION[pairIndex] || "";
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -22,6 +22,7 @@ __exportStar(require("./constants"), exports);
|
|
|
22
22
|
__exportStar(require("./utils"), exports);
|
|
23
23
|
__exportStar(require("./vault"), exports);
|
|
24
24
|
__exportStar(require("./backend"), exports);
|
|
25
|
+
__exportStar(require("./pricing"), exports);
|
|
25
26
|
// Not sure why this is needed, but it is. Barrel imports are not working.
|
|
26
27
|
__exportStar(require("./trade/fees/borrowing/index"), exports);
|
|
27
28
|
// Export ContractsVersion for frontend usage
|
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 === null || pair === void 0 ? void 0 : 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 === null || pairMaxLeverages === void 0 ? void 0 : pairMaxLeverages[pairIndex],
|
|
22
|
+
counterTradeSettings: counterTradeSettings === null || counterTradeSettings === void 0 ? void 0 : 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;
|