@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
|
@@ -25,11 +25,11 @@ const transformGlobalTrades = (rawTrades, pairs, currentAddress, collaterals) =>
|
|
|
25
25
|
_allLimitOrders.set(t.trade.user, new Map());
|
|
26
26
|
}
|
|
27
27
|
const traderMap_all = _allLimitOrders.get(t.trade.user);
|
|
28
|
-
if (traderMap_all
|
|
29
|
-
traderMap_all
|
|
28
|
+
if ((traderMap_all === null || traderMap_all === void 0 ? void 0 : traderMap_all.get(t.trade.pairIndex)) === undefined) {
|
|
29
|
+
traderMap_all === null || traderMap_all === void 0 ? void 0 : traderMap_all.set(t.trade.pairIndex, new Map());
|
|
30
30
|
}
|
|
31
|
-
const traderPairMap_all = traderMap_all
|
|
32
|
-
traderPairMap_all
|
|
31
|
+
const traderPairMap_all = traderMap_all === null || traderMap_all === void 0 ? void 0 : traderMap_all.get(t.trade.pairIndex);
|
|
32
|
+
traderPairMap_all === null || traderPairMap_all === void 0 ? void 0 : traderPairMap_all.set(t.trade.index, t);
|
|
33
33
|
if (t.trade.user.toUpperCase() !== currentAddress.toUpperCase()) {
|
|
34
34
|
continue;
|
|
35
35
|
}
|
|
@@ -37,7 +37,7 @@ const transformGlobalTrades = (rawTrades, pairs, currentAddress, collaterals) =>
|
|
|
37
37
|
_limitOrders.set(t.trade.pairIndex, new Map());
|
|
38
38
|
}
|
|
39
39
|
const traderPairMap = _limitOrders.get(t.trade.pairIndex);
|
|
40
|
-
traderPairMap
|
|
40
|
+
traderPairMap === null || traderPairMap === void 0 ? void 0 : traderPairMap.set(t.trade.index, t);
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
43
|
const t = r[s];
|
|
@@ -45,11 +45,11 @@ const transformGlobalTrades = (rawTrades, pairs, currentAddress, collaterals) =>
|
|
|
45
45
|
_allTrades.set(t.trade.user, new Map());
|
|
46
46
|
}
|
|
47
47
|
const traderMap_all = _allTrades.get(t.trade.user);
|
|
48
|
-
if (traderMap_all
|
|
49
|
-
traderMap_all
|
|
48
|
+
if ((traderMap_all === null || traderMap_all === void 0 ? void 0 : traderMap_all.get(t.trade.pairIndex)) === undefined) {
|
|
49
|
+
traderMap_all === null || traderMap_all === void 0 ? void 0 : traderMap_all.set(t.trade.pairIndex, new Map());
|
|
50
50
|
}
|
|
51
|
-
const traderPairMap_all = traderMap_all
|
|
52
|
-
traderPairMap_all
|
|
51
|
+
const traderPairMap_all = traderMap_all === null || traderMap_all === void 0 ? void 0 : traderMap_all.get(t.trade.pairIndex);
|
|
52
|
+
traderPairMap_all === null || traderPairMap_all === void 0 ? void 0 : traderPairMap_all.set(t.trade.index, t);
|
|
53
53
|
if (t.trade.user.toUpperCase() !== currentAddress.toUpperCase()) {
|
|
54
54
|
continue;
|
|
55
55
|
}
|
|
@@ -57,7 +57,7 @@ const transformGlobalTrades = (rawTrades, pairs, currentAddress, collaterals) =>
|
|
|
57
57
|
_trades.set(t.trade.pairIndex, new Map());
|
|
58
58
|
}
|
|
59
59
|
const traderPairMap = _trades.get(t.trade.pairIndex);
|
|
60
|
-
traderPairMap
|
|
60
|
+
traderPairMap === null || traderPairMap === void 0 ? void 0 : traderPairMap.set(t.trade.index, t);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
returnObject.trades = _trades;
|
|
@@ -96,9 +96,15 @@ export interface GroupOpenInterestBackend {
|
|
|
96
96
|
short: string;
|
|
97
97
|
max: string;
|
|
98
98
|
}
|
|
99
|
-
export interface
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
export interface PairDepthBandsBackend {
|
|
100
|
+
aboveSlot1: string;
|
|
101
|
+
aboveSlot2: string;
|
|
102
|
+
belowSlot1: string;
|
|
103
|
+
belowSlot2: string;
|
|
104
|
+
}
|
|
105
|
+
export interface DepthBandsMappingBackend {
|
|
106
|
+
slot1: string;
|
|
107
|
+
slot2: string;
|
|
102
108
|
}
|
|
103
109
|
export interface PairBorrowingFeesBackendPairGroup {
|
|
104
110
|
groupIndex: string;
|
|
@@ -159,6 +165,7 @@ export interface GlobalTradingVariablesBackend {
|
|
|
159
165
|
groups: TradingGroupBackend[];
|
|
160
166
|
fees: FeeBackend[];
|
|
161
167
|
pairInfos: PairInfosBackend;
|
|
168
|
+
depthBandsMapping: DepthBandsMappingBackend;
|
|
162
169
|
collaterals: CollateralBackend[];
|
|
163
170
|
sssTokenBalance: string;
|
|
164
171
|
sssLegacyTokenBalance: string;
|
|
@@ -239,7 +246,7 @@ export interface CollateralBackend {
|
|
|
239
246
|
}
|
|
240
247
|
export interface PairInfosBackend {
|
|
241
248
|
maxLeverages: string[];
|
|
242
|
-
|
|
249
|
+
pairDepthBands: PairDepthBandsBackend[];
|
|
243
250
|
pairFactors: PairFactorBackend[];
|
|
244
251
|
}
|
|
245
252
|
export type TraderInfoBackend = {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { ContestLeaderboardBackendEntry, ContestLeaderboardEntry } from "@gainsnetwork/contests";
|
|
2
|
-
import { BorrowingFee, CollateralConfig, Fee, FeeTiers, GlobalTradeFeeParams, OiWindows, OiWindowsSettings, OpenInterest, Pair,
|
|
3
|
-
import {
|
|
2
|
+
import { BorrowingFee, CollateralConfig, Fee, FeeTiers, GlobalTradeFeeParams, OiWindows, OiWindowsSettings, OpenInterest, Pair, PairOi, Trade, TradeContainer, TradeInfo, TradeInitialAccFees, TraderFeeTiers, TradingGroup, PairFactor, convertLiquidationParams } from "../../";
|
|
3
|
+
import { convertPairDepthBandsFromSlots } from "../../trade/priceImpact/cumulVol/converter";
|
|
4
|
+
import { BorrowingFeePerBlockCapBackend, CollateralBackend, FeeBackend, FeeTiersBackend, GlobalTradeFeeParamsBackend, OiWindowsBackend, OiWindowsSettingsBackend, OpenInterestBackend, PairBackend, PairDepthBandsBackend, DepthBandsMappingBackend, PairFactorBackend, PairOiBackend, PairParamsBorrowingFeesBackend, TradeBackend, TradeContainerBackend, TradeInfoBackend, TradeInitialAccFeesBackend, TraderFeeTiersBackend, TradingGroupBackend } from "./backend.types";
|
|
4
5
|
import { TradingVariablesCollateral } from "./types";
|
|
5
6
|
export declare const convertFees: (fees: FeeBackend[]) => Fee[];
|
|
6
7
|
export declare const convertCollaterals: (collaterals: CollateralBackend[]) => TradingVariablesCollateral[];
|
|
7
8
|
export declare const convertOpenInterests: (interests: OpenInterestBackend[]) => OpenInterest[];
|
|
8
|
-
export declare const
|
|
9
|
+
export declare const convertPairDepthBands: (pairDepthBands: PairDepthBandsBackend[]) => ReturnType<typeof convertPairDepthBandsFromSlots>[];
|
|
10
|
+
export declare const convertDepthBandsMapping: (mapping: DepthBandsMappingBackend) => {
|
|
11
|
+
bands: number[];
|
|
12
|
+
};
|
|
9
13
|
export declare const convertPairSkewDepths: (pairSkewDepths: string[] | undefined) => {
|
|
10
14
|
[pairIndex: number]: number;
|
|
11
15
|
};
|
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertLiquidationParams = exports.convertPairName = exports.convertFeePerBlockCap = exports.convertMaxLeverages = exports.convertGlobalTradeFeeParams = exports.convertTraderFeeTiers = exports.convertFeeTiers = exports.convertCollateralConfig = exports.convertOiWindowsSettings = exports.convertOiWindows = exports.convertPairOi = exports.convertContestLeaderboardEntry = exports.generateStockPairToActiveStockSplit = exports.convertTradeInitialAccFees = exports.convertTradeInfo = exports.convertTrade = exports.convertPairFactor = exports.convertTradeContainer = exports.convertTradesAndLimitOrders = exports.convertTradingPairs = exports.convertTradingGroups = exports.convertGroupBorrowingFees = exports.convertPairBorrowingFees = exports.convertPairSkewDepths = exports.
|
|
3
|
+
exports.convertLiquidationParams = exports.convertPairName = exports.convertFeePerBlockCap = exports.convertMaxLeverages = exports.convertGlobalTradeFeeParams = exports.convertTraderFeeTiers = exports.convertFeeTiers = exports.convertCollateralConfig = exports.convertOiWindowsSettings = exports.convertOiWindows = exports.convertPairOi = exports.convertContestLeaderboardEntry = exports.generateStockPairToActiveStockSplit = exports.convertTradeInitialAccFees = exports.convertTradeInfo = exports.convertTrade = exports.convertPairFactor = exports.convertTradeContainer = exports.convertTradesAndLimitOrders = exports.convertTradingPairs = exports.convertTradingGroups = exports.convertGroupBorrowingFees = exports.convertPairBorrowingFees = exports.convertPairSkewDepths = exports.convertDepthBandsMapping = exports.convertPairDepthBands = exports.convertOpenInterests = exports.convertCollaterals = exports.convertFees = void 0;
|
|
4
4
|
const __1 = require("../../");
|
|
5
5
|
Object.defineProperty(exports, "convertLiquidationParams", { enumerable: true, get: function () { return __1.convertLiquidationParams; } });
|
|
6
6
|
const converter_1 = require("../../trade/priceImpact/skew/converter");
|
|
7
|
-
const
|
|
7
|
+
const converter_2 = require("../../trade/priceImpact/cumulVol/converter");
|
|
8
|
+
const depthBands_1 = require("../../pricing/depthBands");
|
|
9
|
+
const convertFees = (fees) => fees === null || fees === void 0 ? void 0 : fees.map(fee => convertFee(fee));
|
|
8
10
|
exports.convertFees = convertFees;
|
|
9
|
-
const convertCollateral = (collateral) =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
40
|
-
const convertCollaterals = (collaterals) => collaterals?.map(collateral => convertCollateral(collateral));
|
|
11
|
+
const convertCollateral = (collateral) => {
|
|
12
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
13
|
+
return ({
|
|
14
|
+
pairBorrowingFees: ((_a = collateral.borrowingFees) === null || _a === void 0 ? void 0 : _a.v1) !== undefined
|
|
15
|
+
? (0, exports.convertPairBorrowingFees)(collateral.borrowingFees.v1)
|
|
16
|
+
: [],
|
|
17
|
+
groupBorrowingFees: ((_b = collateral.borrowingFees) === null || _b === void 0 ? void 0 : _b.v1) !== undefined
|
|
18
|
+
? (0, exports.convertGroupBorrowingFees)(collateral.borrowingFees.v1)
|
|
19
|
+
: [],
|
|
20
|
+
collateral: collateral.collateral,
|
|
21
|
+
collateralConfig: (0, exports.convertCollateralConfig)(collateral),
|
|
22
|
+
collateralIndex: collateral.collateralIndex,
|
|
23
|
+
gToken: collateral.gToken,
|
|
24
|
+
isActive: true,
|
|
25
|
+
prices: collateral.prices,
|
|
26
|
+
symbol: collateral.symbol,
|
|
27
|
+
pairBorrowingFeesV2: {
|
|
28
|
+
params: (0, __1.convertBorrowingFeeParamsArrayV2)((_d = (_c = collateral.borrowingFees) === null || _c === void 0 ? void 0 : _c.v2) === null || _d === void 0 ? void 0 : _d.pairParams),
|
|
29
|
+
data: (0, __1.convertPairBorrowingFeeDataArrayV2)((_f = (_e = collateral.borrowingFees) === null || _e === void 0 ? void 0 : _e.v2) === null || _f === void 0 ? void 0 : _f.pairData),
|
|
30
|
+
},
|
|
31
|
+
pairFundingFees: {
|
|
32
|
+
globalParams: (0, __1.convertPairGlobalParamsArray)((_g = collateral.fundingFees) === null || _g === void 0 ? void 0 : _g.pairGlobalParams),
|
|
33
|
+
params: (0, __1.convertFundingFeeParamsArray)((_h = collateral.fundingFees) === null || _h === void 0 ? void 0 : _h.pairParams),
|
|
34
|
+
data: (0, __1.convertPairFundingFeeDataArray)((_j = collateral.fundingFees) === null || _j === void 0 ? void 0 : _j.pairData),
|
|
35
|
+
},
|
|
36
|
+
pairOis: (0, __1.convertPairOiArray)(collateral.pairOis, parseInt(collateral.collateralConfig.precision)),
|
|
37
|
+
pairSkewDepths: (0, exports.convertPairSkewDepths)(collateral.pairSkewDepths),
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
const convertCollaterals = (collaterals) => collaterals === null || collaterals === void 0 ? void 0 : collaterals.map(collateral => convertCollateral(collateral));
|
|
41
41
|
exports.convertCollaterals = convertCollaterals;
|
|
42
42
|
const convertFee = (fee) => ({
|
|
43
43
|
totalPositionSizeFeeP: parseFloat(fee.totalPositionSizeFeeP) / 1e12,
|
|
@@ -45,26 +45,31 @@ const convertFee = (fee) => ({
|
|
|
45
45
|
oraclePositionSizeFeeP: parseFloat(fee.oraclePositionSizeFeeP) / 1e12,
|
|
46
46
|
minPositionSizeUsd: parseFloat(fee.minPositionSizeUsd) / 1e3,
|
|
47
47
|
});
|
|
48
|
-
const convertOpenInterests = (interests) => interests
|
|
48
|
+
const convertOpenInterests = (interests) => interests === null || interests === void 0 ? void 0 : interests.map(interest => convertOpenInterest(interest));
|
|
49
49
|
exports.convertOpenInterests = convertOpenInterests;
|
|
50
50
|
const convertOpenInterest = (interest) => ({
|
|
51
51
|
long: parseFloat(interest.beforeV10.long) / 1e10,
|
|
52
52
|
short: parseFloat(interest.beforeV10.short) / 1e10,
|
|
53
53
|
max: parseFloat(interest.beforeV10.max) / 1e10,
|
|
54
54
|
});
|
|
55
|
-
const
|
|
56
|
-
exports.
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
const convertPairDepthBands = (pairDepthBands) => (pairDepthBands === null || pairDepthBands === void 0 ? void 0 : pairDepthBands.map(bands => (0, converter_2.convertPairDepthBandsFromSlots)(BigInt(bands.aboveSlot1), BigInt(bands.aboveSlot2), BigInt(bands.belowSlot1), BigInt(bands.belowSlot2)))) || [];
|
|
56
|
+
exports.convertPairDepthBands = convertPairDepthBands;
|
|
57
|
+
const convertDepthBandsMapping = (mapping) => {
|
|
58
|
+
// First decode the raw slots to get bands in basis points
|
|
59
|
+
const bandsBps = (0, depthBands_1.decodeDepthBandsMapping)(BigInt(mapping.slot1), BigInt(mapping.slot2));
|
|
60
|
+
// Convert from basis points to 0-1 range
|
|
61
|
+
return {
|
|
62
|
+
bands: bandsBps.map(bps => bps / 10000),
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
exports.convertDepthBandsMapping = convertDepthBandsMapping;
|
|
61
66
|
const convertPairSkewDepths = (pairSkewDepths) => {
|
|
62
67
|
if (!pairSkewDepths)
|
|
63
68
|
return {};
|
|
64
69
|
return (0, converter_1.convertPairSkewDepths)(pairSkewDepths);
|
|
65
70
|
};
|
|
66
71
|
exports.convertPairSkewDepths = convertPairSkewDepths;
|
|
67
|
-
const convertPairBorrowingFees = (pairParams) => pairParams
|
|
72
|
+
const convertPairBorrowingFees = (pairParams) => pairParams === null || pairParams === void 0 ? void 0 : pairParams.pairs.map(pairParam => convertPairBorrowingFee(pairParam));
|
|
68
73
|
exports.convertPairBorrowingFees = convertPairBorrowingFees;
|
|
69
74
|
const convertPairGroupBorrowingFee = (pairParam) => ({
|
|
70
75
|
groupIndex: parseInt(pairParam.groupIndex),
|
|
@@ -88,9 +93,9 @@ const convertPairBorrowingFee = (pairParams) => ({
|
|
|
88
93
|
short: parseFloat(pairParams.oi.beforeV10.short) / 1e10 || 0,
|
|
89
94
|
},
|
|
90
95
|
feeExponent: parseInt(pairParams.feeExponent) || 0,
|
|
91
|
-
feePerBlockCap: (0, exports.convertFeePerBlockCap)(pairParams
|
|
96
|
+
feePerBlockCap: (0, exports.convertFeePerBlockCap)(pairParams === null || pairParams === void 0 ? void 0 : pairParams.feePerBlockCap),
|
|
92
97
|
});
|
|
93
|
-
const convertGroupBorrowingFees = (pairParams) => pairParams
|
|
98
|
+
const convertGroupBorrowingFees = (pairParams) => pairParams === null || pairParams === void 0 ? void 0 : pairParams.groups.map(pairParam => convertGroupBorrowingFee(pairParam));
|
|
94
99
|
exports.convertGroupBorrowingFees = convertGroupBorrowingFees;
|
|
95
100
|
const convertGroupBorrowingFee = (pairParams) => ({
|
|
96
101
|
oi: {
|
|
@@ -104,16 +109,14 @@ const convertGroupBorrowingFee = (pairParams) => ({
|
|
|
104
109
|
accLastUpdatedBlock: parseInt(pairParams.accLastUpdatedBlock),
|
|
105
110
|
feeExponent: parseInt(pairParams.feeExponent) || 0,
|
|
106
111
|
});
|
|
107
|
-
const convertTradingGroups = (groups) => groups
|
|
112
|
+
const convertTradingGroups = (groups) => groups === null || groups === void 0 ? void 0 : groups.map(group => convertTradingGroup(group));
|
|
108
113
|
exports.convertTradingGroups = convertTradingGroups;
|
|
109
114
|
const convertTradingGroup = (group) => ({
|
|
110
115
|
maxLeverage: parseFloat(group.maxLeverage) / 1e3,
|
|
111
116
|
minLeverage: parseFloat(group.minLeverage) / 1e3,
|
|
112
117
|
name: group.name,
|
|
113
118
|
});
|
|
114
|
-
const convertTradingPairs = (pairs) => pairs
|
|
115
|
-
?.filter(pair => pair.from !== "")
|
|
116
|
-
.map((pair, index) => convertTradingPair(pair, index));
|
|
119
|
+
const convertTradingPairs = (pairs) => pairs === null || pairs === void 0 ? void 0 : pairs.filter(pair => pair.from !== "").map((pair, index) => convertTradingPair(pair, index));
|
|
117
120
|
exports.convertTradingPairs = convertTradingPairs;
|
|
118
121
|
const convertTradingPair = (pair, index) => ({
|
|
119
122
|
name: (0, exports.convertPairName)(pair),
|
|
@@ -125,7 +128,7 @@ const convertTradingPair = (pair, index) => ({
|
|
|
125
128
|
groupIndex: parseInt(pair.groupIndex),
|
|
126
129
|
spreadP: parseFloat(pair.spreadP) / 1e10,
|
|
127
130
|
});
|
|
128
|
-
const convertTradesAndLimitOrders = (allItems, collaterals) => allItems
|
|
131
|
+
const convertTradesAndLimitOrders = (allItems, collaterals) => allItems === null || allItems === void 0 ? void 0 : allItems.map(item => {
|
|
129
132
|
return (0, exports.convertTradeContainer)(item, collaterals);
|
|
130
133
|
});
|
|
131
134
|
exports.convertTradesAndLimitOrders = convertTradesAndLimitOrders;
|
|
@@ -171,10 +174,11 @@ const convertPairFactor = (pairFactor) => ({
|
|
|
171
174
|
});
|
|
172
175
|
exports.convertPairFactor = convertPairFactor;
|
|
173
176
|
const convertTrade = (trade, collaterals) => {
|
|
177
|
+
var _a;
|
|
174
178
|
const { long, user } = trade;
|
|
175
179
|
const collateralIndex = parseInt(trade.collateralIndex);
|
|
176
180
|
const collateral = collaterals[collateralIndex - 1];
|
|
177
|
-
const decimals = collateral
|
|
181
|
+
const decimals = ((_a = collateral === null || collateral === void 0 ? void 0 : collateral.collateralConfig) === null || _a === void 0 ? void 0 : _a.decimals) || 18;
|
|
178
182
|
return {
|
|
179
183
|
user,
|
|
180
184
|
index: parseInt(trade.index),
|
|
@@ -184,7 +188,7 @@ const convertTrade = (trade, collaterals) => {
|
|
|
184
188
|
isOpen: trade.isOpen,
|
|
185
189
|
collateralIndex,
|
|
186
190
|
tradeType: parseInt(trade.tradeType),
|
|
187
|
-
collateralAmount: parseFloat(trade.collateralAmount) / 10
|
|
191
|
+
collateralAmount: parseFloat(trade.collateralAmount) / Math.pow(10, decimals),
|
|
188
192
|
openPrice: parseFloat(trade.openPrice) / 1e10,
|
|
189
193
|
sl: parseFloat(trade.sl) / 1e10,
|
|
190
194
|
tp: parseFloat(trade.tp) / 1e10,
|
|
@@ -268,7 +272,7 @@ const convertPairOi = (collateral) => ({
|
|
|
268
272
|
});
|
|
269
273
|
exports.convertPairOi = convertPairOi;
|
|
270
274
|
const convertOiWindows = (oiWindows) => {
|
|
271
|
-
return oiWindows
|
|
275
|
+
return oiWindows === null || oiWindows === void 0 ? void 0 : oiWindows.map(pairWindows => {
|
|
272
276
|
const converted = {};
|
|
273
277
|
for (const [key, oiWindow] of Object.entries(pairWindows)) {
|
|
274
278
|
converted[key] = (0, exports.convertPairOi)(oiWindow);
|
|
@@ -291,14 +295,17 @@ const convertCollateralConfig = (collateral) => ({
|
|
|
291
295
|
decimals: collateral.collateralConfig.decimals,
|
|
292
296
|
});
|
|
293
297
|
exports.convertCollateralConfig = convertCollateralConfig;
|
|
294
|
-
const convertFeeTiers = (feeTiersBackend) =>
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
298
|
+
const convertFeeTiers = (feeTiersBackend) => {
|
|
299
|
+
var _a;
|
|
300
|
+
return ({
|
|
301
|
+
tiers: feeTiersBackend === null || feeTiersBackend === void 0 ? void 0 : feeTiersBackend.tiers.map(tier => ({
|
|
302
|
+
feeMultiplier: Number(tier.feeMultiplier) / 1e3,
|
|
303
|
+
pointsThreshold: parseFloat(tier.pointsThreshold),
|
|
304
|
+
})),
|
|
305
|
+
multipliers: ((_a = feeTiersBackend === null || feeTiersBackend === void 0 ? void 0 : feeTiersBackend.multipliers) === null || _a === void 0 ? void 0 : _a.map(mult => parseFloat(mult) / 1e3)) || [],
|
|
306
|
+
currentDay: (feeTiersBackend === null || feeTiersBackend === void 0 ? void 0 : feeTiersBackend.currentDay) || 0,
|
|
307
|
+
});
|
|
308
|
+
};
|
|
302
309
|
exports.convertFeeTiers = convertFeeTiers;
|
|
303
310
|
const convertTraderFeeTiers = (traderFeeTiers) => ({
|
|
304
311
|
traderEnrollment: {
|
|
@@ -323,11 +330,11 @@ const convertGlobalTradeFeeParams = (fee) => ({
|
|
|
323
330
|
gTokenFeeP: parseFloat(fee.gTokenFeeP) / 1e5,
|
|
324
331
|
});
|
|
325
332
|
exports.convertGlobalTradeFeeParams = convertGlobalTradeFeeParams;
|
|
326
|
-
const convertMaxLeverages = (maxLeverages) => maxLeverages
|
|
333
|
+
const convertMaxLeverages = (maxLeverages) => maxLeverages === null || maxLeverages === void 0 ? void 0 : maxLeverages.map(maxLeverage => parseFloat(maxLeverage) / 1e3);
|
|
327
334
|
exports.convertMaxLeverages = convertMaxLeverages;
|
|
328
335
|
const convertFeePerBlockCap = (feeCap) => ({
|
|
329
|
-
minP: feeCap
|
|
330
|
-
maxP: feeCap
|
|
336
|
+
minP: (feeCap === null || feeCap === void 0 ? void 0 : feeCap.minP) ? parseFloat(feeCap.minP.toString()) / 1e3 / 100 : 0,
|
|
337
|
+
maxP: (feeCap === null || feeCap === void 0 ? void 0 : feeCap.maxP) ? parseFloat(feeCap.maxP.toString()) / 1e3 / 100 : 1,
|
|
331
338
|
});
|
|
332
339
|
exports.convertFeePerBlockCap = convertFeePerBlockCap;
|
|
333
340
|
const convertPairName = (pair) => {
|
|
@@ -18,6 +18,7 @@ exports.transformGlobalTradingVariables = void 0;
|
|
|
18
18
|
const converter_1 = require("./converter");
|
|
19
19
|
const trade_1 = require("../../trade");
|
|
20
20
|
const transformGlobalTradingVariables = (rawData) => {
|
|
21
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
21
22
|
const globalTradingVariables = {
|
|
22
23
|
collaterals: (0, converter_1.convertCollaterals)(rawData.collaterals),
|
|
23
24
|
pairs: (0, converter_1.convertTradingPairs)(rawData.pairs),
|
|
@@ -30,10 +31,13 @@ const transformGlobalTradingVariables = (rawData) => {
|
|
|
30
31
|
stocksClosed: !rawData.isStocksOpen,
|
|
31
32
|
indicesClosed: !rawData.isIndicesOpen,
|
|
32
33
|
commoditiesClosed: !rawData.isCommoditiesOpen,
|
|
33
|
-
|
|
34
|
-
? (0, converter_1.
|
|
34
|
+
pairDepthBands: ((_a = rawData.pairInfos) === null || _a === void 0 ? void 0 : _a.pairDepthBands) !== undefined
|
|
35
|
+
? (0, converter_1.convertPairDepthBands)(rawData.pairInfos.pairDepthBands)
|
|
35
36
|
: [],
|
|
36
|
-
|
|
37
|
+
depthBandsMapping: rawData.depthBandsMapping !== undefined
|
|
38
|
+
? (0, converter_1.convertDepthBandsMapping)(rawData.depthBandsMapping)
|
|
39
|
+
: { bands: [] },
|
|
40
|
+
pairMaxLeverages: ((_b = rawData.pairInfos) === null || _b === void 0 ? void 0 : _b.maxLeverages) !== undefined
|
|
37
41
|
? (0, converter_1.convertMaxLeverages)(rawData.pairInfos.maxLeverages)
|
|
38
42
|
: [],
|
|
39
43
|
maxNegativePnlOnOpenP: (rawData.maxNegativePnlOnOpenP && rawData.maxNegativePnlOnOpenP / 1e10) ||
|
|
@@ -46,11 +50,11 @@ const transformGlobalTradingVariables = (rawData) => {
|
|
|
46
50
|
: [],
|
|
47
51
|
feeTiers: (0, converter_1.convertFeeTiers)(rawData.feeTiers),
|
|
48
52
|
liquidationParams: {
|
|
49
|
-
groups: rawData.liquidationParams
|
|
50
|
-
pairs: rawData.liquidationParams
|
|
53
|
+
groups: ((_d = (_c = rawData.liquidationParams) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.map(liqParams => (0, trade_1.convertLiquidationParams)(liqParams))) || [],
|
|
54
|
+
pairs: ((_f = (_e = rawData.liquidationParams) === null || _e === void 0 ? void 0 : _e.pairs) === null || _f === void 0 ? void 0 : _f.map(liqParams => (0, trade_1.convertLiquidationParams)(liqParams))) || [],
|
|
51
55
|
},
|
|
52
56
|
counterTradeSettings: (0, trade_1.convertCounterTradeSettingsArray)(rawData.counterTradeSettings),
|
|
53
|
-
pairFactors: rawData.pairInfos
|
|
57
|
+
pairFactors: ((_h = (_g = rawData.pairInfos) === null || _g === void 0 ? void 0 : _g.pairFactors) === null || _h === void 0 ? void 0 : _h.map(factor => (0, converter_1.convertPairFactor)(factor))) || [],
|
|
54
58
|
globalTradeFeeParams: rawData.globalTradeFeeParams
|
|
55
59
|
? (0, converter_1.convertGlobalTradeFeeParams)(rawData.globalTradeFeeParams)
|
|
56
60
|
: undefined,
|
|
@@ -59,7 +63,7 @@ const transformGlobalTradingVariables = (rawData) => {
|
|
|
59
63
|
const currentBlock = (rawData.currentBlock > -1 && rawData.currentBlock) || undefined;
|
|
60
64
|
const l1BlockNumber = (rawData.currentL1Block > -1 && rawData.currentL1Block) || undefined;
|
|
61
65
|
const pairIndexes = {};
|
|
62
|
-
for (let i = 0; i < rawData.pairs
|
|
66
|
+
for (let i = 0; i < ((_j = rawData.pairs) === null || _j === void 0 ? void 0 : _j.length); i++) {
|
|
63
67
|
pairIndexes[rawData.pairs[i].from + "/" + rawData.pairs[i].to] = i;
|
|
64
68
|
}
|
|
65
69
|
if (globalTradingVariables.collaterals !== undefined) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CollateralConfig } from "src/markets/collateral";
|
|
2
|
-
import { BorrowingFee, BorrowingFeeV2, CounterTradeSettings, Fee, FeeTiers, FundingFees, GlobalTradeFeeParams, LeaderboardTrader, LiquidationParams, OiWindows, OiWindowsSettings, Pair,
|
|
2
|
+
import { BorrowingFee, BorrowingFeeV2, CounterTradeSettings, Fee, FeeTiers, FundingFees, GlobalTradeFeeParams, LeaderboardTrader, LiquidationParams, OiWindows, OiWindowsSettings, Pair, PairFactor, PairIndexes, TradingGroup } from "../../trade";
|
|
3
|
+
import { PairDepthBands, DepthBandsMapping } from "../../trade/priceImpact/cumulVol/types";
|
|
3
4
|
import { UnifiedPairOi } from "src/markets";
|
|
4
5
|
export type TransformedGlobalTradingVariables = {
|
|
5
6
|
globalTradingVariables: GlobalTradingVariablesType;
|
|
@@ -63,7 +64,8 @@ export type GlobalTradingVariablesType = {
|
|
|
63
64
|
commodities?: string[];
|
|
64
65
|
commoditiesClosed?: boolean;
|
|
65
66
|
blockConfirmations?: number;
|
|
66
|
-
|
|
67
|
+
pairDepthBands?: PairDepthBands[];
|
|
68
|
+
depthBandsMapping?: DepthBandsMapping;
|
|
67
69
|
pairMaxLeverages?: number[];
|
|
68
70
|
maxNegativePnlOnOpenP?: number;
|
|
69
71
|
oiWindowsSettings?: OiWindowsSettings;
|
|
@@ -14,10 +14,7 @@ const getContractAddressesForChain = (chainId, collateral = types_1.CollateralTy
|
|
|
14
14
|
if (!_addresses[chainId][collateral]) {
|
|
15
15
|
throw new Error(`Unknown collateral (${collateral}) for chain id (${chainId}). No known contracts have been deployed for this collateral.`);
|
|
16
16
|
}
|
|
17
|
-
return {
|
|
18
|
-
..._addresses[chainId]["global"],
|
|
19
|
-
..._addresses[chainId][collateral],
|
|
20
|
-
};
|
|
17
|
+
return Object.assign(Object.assign({}, _addresses[chainId]["global"]), _addresses[chainId][collateral]);
|
|
21
18
|
};
|
|
22
19
|
exports.getContractAddressesForChain = getContractAddressesForChain;
|
|
23
20
|
const getCollateralByAddressForChain = (chainId, address) => {
|
package/lib/contracts/index.d.ts
CHANGED
|
@@ -11,4 +11,4 @@ export declare const COLLATERAL_TO_CHAIN_COLLATERAL_INDEX: Record<ChainId, Parti
|
|
|
11
11
|
export declare const COLLATERAL_TO_COLLATERAL_INDEX: Record<CollateralTypes, number>;
|
|
12
12
|
export * from "./utils";
|
|
13
13
|
export * from "./addresses";
|
|
14
|
-
export { CollateralTypes
|
|
14
|
+
export { CollateralTypes } from "./types";
|
package/lib/contracts/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
17
|
+
exports.CollateralTypes = exports.COLLATERAL_TO_COLLATERAL_INDEX = exports.COLLATERAL_TO_CHAIN_COLLATERAL_INDEX = exports.getCollateralIndexAndContractsForChainByRequester = exports.getContractsForChainByRequester = exports.getContractsForChain = void 0;
|
|
18
18
|
const addresses_1 = require("./addresses");
|
|
19
19
|
const factories_1 = require("./types/generated/factories");
|
|
20
20
|
const types_1 = require("./types");
|
|
@@ -34,10 +34,11 @@ const getContractsForChainByRequester = (chainId, requester, signerOrProvider) =
|
|
|
34
34
|
};
|
|
35
35
|
exports.getContractsForChainByRequester = getContractsForChainByRequester;
|
|
36
36
|
const getCollateralIndexAndContractsForChainByRequester = (chainId, requester, signerOrProvider) => {
|
|
37
|
+
var _a;
|
|
37
38
|
const collateral = (0, addresses_1.getCollateralByAddressForChain)(chainId, requester);
|
|
38
39
|
return {
|
|
39
40
|
contracts: (0, exports.getContractsForChain)(chainId, signerOrProvider, collateral),
|
|
40
|
-
collateralIndex: exports.COLLATERAL_TO_CHAIN_COLLATERAL_INDEX[chainId]
|
|
41
|
+
collateralIndex: ((_a = exports.COLLATERAL_TO_CHAIN_COLLATERAL_INDEX[chainId]) === null || _a === void 0 ? void 0 : _a[collateral]) ||
|
|
41
42
|
0,
|
|
42
43
|
};
|
|
43
44
|
};
|
|
@@ -82,4 +83,3 @@ __exportStar(require("./utils"), exports);
|
|
|
82
83
|
__exportStar(require("./addresses"), exports);
|
|
83
84
|
var types_2 = require("./types");
|
|
84
85
|
Object.defineProperty(exports, "CollateralTypes", { enumerable: true, get: function () { return types_2.CollateralTypes; } });
|
|
85
|
-
Object.defineProperty(exports, "ChainId", { enumerable: true, get: function () { return types_2.ChainId; } });
|