@gainsnetwork/sdk 0.2.73-rc2 → 1.0.0-rc10
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/README.md +2 -2
- package/lib/backend/globalTrades/index.d.ts +11 -0
- package/lib/backend/globalTrades/index.js +69 -0
- package/lib/backend/index.d.ts +3 -0
- package/lib/backend/index.js +28 -0
- package/lib/backend/tradingVariables/backend.types.d.ts +318 -0
- package/lib/backend/tradingVariables/backend.types.js +2 -0
- package/lib/backend/tradingVariables/converter.d.ts +34 -0
- package/lib/backend/tradingVariables/converter.js +338 -0
- package/lib/backend/tradingVariables/index.d.ts +5 -0
- package/lib/backend/tradingVariables/index.js +96 -0
- package/lib/backend/tradingVariables/types.d.ts +113 -0
- package/lib/backend/tradingVariables/types.js +14 -0
- package/lib/constants.d.ts +0 -5
- package/lib/constants.js +0 -5
- 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 +2134 -293
- 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/GToken.d.ts +78 -107
- 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 +90 -53
- package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +4496 -430
- 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/types/generated/factories/GToken__factory.d.ts +7 -0
- package/lib/contracts/types/generated/factories/GToken__factory.js +69 -142
- package/lib/contracts/types/index.d.ts +2 -1
- package/lib/contracts/types/index.js +1 -0
- package/lib/contracts/utils/openTrades.d.ts +1 -0
- package/lib/contracts/utils/openTrades.js +94 -56
- package/lib/contracts/utils/pairs.js +0 -5
- package/lib/index.d.ts +2 -0
- package/lib/index.js +5 -0
- package/lib/markets/collateral/converter.d.ts +5 -0
- package/lib/markets/collateral/converter.js +11 -0
- package/lib/markets/collateral/index.d.ts +1 -0
- package/lib/markets/collateral/index.js +17 -0
- package/lib/markets/collateral/types.d.ts +7 -0
- package/lib/markets/collateral/types.js +2 -0
- package/lib/markets/holdingFees/index.d.ts +46 -0
- package/lib/markets/holdingFees/index.js +105 -0
- package/lib/markets/holdingFees/types.d.ts +23 -0
- package/lib/markets/holdingFees/types.js +5 -0
- package/lib/markets/index.d.ts +5 -0
- package/lib/markets/index.js +5 -0
- package/lib/markets/leverage/builder.d.ts +12 -0
- package/lib/markets/leverage/builder.js +25 -0
- package/lib/markets/leverage/getMarketLeverageRestrictions.d.ts +7 -0
- package/lib/markets/leverage/getMarketLeverageRestrictions.js +38 -0
- package/lib/markets/leverage/index.d.ts +3 -0
- package/lib/markets/leverage/index.js +19 -0
- package/lib/markets/leverage/types.d.ts +15 -0
- package/lib/markets/leverage/types.js +2 -0
- package/lib/markets/oi/converter.d.ts +62 -0
- package/lib/markets/oi/converter.js +102 -0
- package/lib/markets/oi/fetcher.d.ts +58 -0
- package/lib/markets/oi/fetcher.js +181 -0
- package/lib/markets/oi/index.d.ts +49 -0
- package/lib/markets/oi/index.js +77 -0
- package/lib/markets/oi/types.d.ts +73 -0
- package/lib/markets/oi/types.js +6 -0
- package/lib/markets/oi/validation.d.ts +80 -0
- package/lib/markets/oi/validation.js +172 -0
- package/lib/markets/price/builder.d.ts +25 -0
- package/lib/markets/price/builder.js +69 -0
- package/lib/markets/price/index.d.ts +6 -0
- package/lib/markets/price/index.js +22 -0
- package/lib/markets/price/marketPrice.d.ts +13 -0
- package/lib/markets/price/marketPrice.js +35 -0
- package/lib/markets/price/types.d.ts +23 -0
- package/lib/markets/price/types.js +5 -0
- package/lib/trade/counterTrade/index.d.ts +2 -0
- package/lib/trade/counterTrade/index.js +18 -0
- package/lib/trade/counterTrade/types.d.ts +7 -0
- package/lib/trade/counterTrade/types.js +2 -0
- package/lib/trade/counterTrade/validateCounterTrade.d.ts +10 -0
- package/lib/trade/counterTrade/validateCounterTrade.js +29 -0
- package/lib/trade/effectiveLeverage/builder.d.ts +23 -0
- package/lib/trade/effectiveLeverage/builder.js +30 -0
- package/lib/trade/effectiveLeverage/getTradeNewEffectiveLeverage.d.ts +23 -0
- package/lib/trade/effectiveLeverage/getTradeNewEffectiveLeverage.js +64 -0
- package/lib/trade/effectiveLeverage/index.d.ts +3 -0
- package/lib/trade/effectiveLeverage/index.js +22 -0
- package/lib/trade/effectiveLeverage/types.d.ts +33 -0
- package/lib/trade/effectiveLeverage/types.js +2 -0
- package/lib/trade/fees/borrowing/builder.d.ts +14 -0
- package/lib/trade/fees/borrowing/builder.js +34 -0
- package/lib/trade/fees/borrowing/index.d.ts +26 -3
- package/lib/trade/fees/borrowing/index.js +72 -22
- package/lib/trade/fees/borrowingV2/builder.d.ts +6 -0
- package/lib/trade/fees/borrowingV2/builder.js +24 -0
- package/lib/trade/fees/borrowingV2/converter.d.ts +75 -0
- package/lib/trade/fees/borrowingV2/converter.js +132 -0
- package/lib/trade/fees/borrowingV2/fetcher.d.ts +75 -0
- package/lib/trade/fees/borrowingV2/fetcher.js +185 -0
- package/lib/trade/fees/borrowingV2/index.d.ts +48 -0
- package/lib/trade/fees/borrowingV2/index.js +112 -0
- package/lib/trade/fees/borrowingV2/types.d.ts +95 -0
- package/lib/trade/fees/borrowingV2/types.js +5 -0
- package/lib/trade/fees/converter.d.ts +48 -0
- package/lib/trade/fees/converter.js +114 -0
- package/lib/trade/fees/fundingFees/builder.d.ts +9 -0
- package/lib/trade/fees/fundingFees/builder.js +35 -0
- package/lib/trade/fees/fundingFees/converter.d.ts +102 -0
- package/lib/trade/fees/fundingFees/converter.js +196 -0
- package/lib/trade/fees/fundingFees/fetcher.d.ts +66 -0
- package/lib/trade/fees/fundingFees/fetcher.js +150 -0
- package/lib/trade/fees/fundingFees/index.d.ts +124 -0
- package/lib/trade/fees/fundingFees/index.js +309 -0
- package/lib/trade/fees/fundingFees/pairContext.d.ts +33 -0
- package/lib/trade/fees/fundingFees/pairContext.js +17 -0
- package/lib/trade/fees/fundingFees/types.d.ts +77 -0
- package/lib/trade/fees/fundingFees/types.js +5 -0
- 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/index.d.ts +9 -2
- package/lib/trade/fees/index.js +69 -16
- package/lib/trade/fees/tiers/converter.d.ts +54 -0
- package/lib/trade/fees/tiers/converter.js +81 -0
- package/lib/trade/fees/tiers/index.d.ts +18 -0
- package/lib/trade/fees/tiers/index.js +45 -1
- package/lib/trade/fees/trading/builder.d.ts +18 -0
- package/lib/trade/fees/trading/builder.js +20 -0
- package/lib/trade/fees/trading/converter.d.ts +32 -0
- package/lib/trade/fees/trading/converter.js +47 -0
- 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.d.ts +62 -0
- package/lib/trade/fees/trading/index.js +155 -0
- package/lib/trade/fees/trading/types.d.ts +48 -0
- package/lib/trade/fees/trading/types.js +5 -0
- package/lib/trade/index.d.ts +5 -2
- package/lib/trade/index.js +5 -2
- package/lib/trade/liquidation/builder.d.ts +25 -0
- package/lib/trade/liquidation/builder.js +59 -0
- package/lib/trade/liquidation/converter.d.ts +23 -0
- package/lib/trade/liquidation/converter.js +46 -0
- package/lib/trade/liquidation/index.d.ts +29 -0
- package/lib/trade/liquidation/index.js +218 -0
- package/lib/trade/liquidation/types.d.ts +43 -0
- package/lib/trade/liquidation/types.js +2 -0
- package/lib/trade/pnl/builder.d.ts +16 -0
- package/lib/trade/pnl/builder.js +44 -0
- package/lib/trade/pnl/converter.d.ts +47 -0
- package/lib/trade/pnl/converter.js +72 -0
- package/lib/trade/pnl/index.d.ts +91 -0
- package/lib/trade/pnl/index.js +303 -0
- package/lib/trade/pnl/types.d.ts +79 -0
- package/lib/trade/pnl/types.js +5 -0
- package/lib/trade/priceImpact/close/builder.d.ts +23 -0
- package/lib/trade/priceImpact/close/builder.js +45 -0
- package/lib/trade/priceImpact/close/index.d.ts +22 -0
- package/lib/trade/priceImpact/close/index.js +134 -0
- package/lib/trade/priceImpact/close/types.d.ts +47 -0
- package/lib/trade/priceImpact/close/types.js +5 -0
- package/lib/trade/priceImpact/cumulVol/builder.d.ts +22 -0
- package/lib/trade/priceImpact/cumulVol/builder.js +43 -0
- package/lib/trade/priceImpact/cumulVol/converter.d.ts +31 -0
- package/lib/trade/priceImpact/cumulVol/converter.js +59 -0
- package/lib/trade/priceImpact/cumulVol/index.d.ts +108 -0
- package/lib/trade/priceImpact/cumulVol/index.js +235 -0
- package/lib/trade/priceImpact/index.d.ts +21 -0
- package/lib/trade/priceImpact/index.js +79 -0
- package/lib/trade/priceImpact/open/builder.d.ts +21 -0
- package/lib/trade/priceImpact/open/builder.js +43 -0
- package/lib/trade/priceImpact/open/index.d.ts +23 -0
- package/lib/trade/priceImpact/open/index.js +79 -0
- package/lib/trade/priceImpact/open/types.d.ts +45 -0
- package/lib/trade/priceImpact/open/types.js +5 -0
- package/lib/trade/priceImpact/skew/builder.d.ts +12 -0
- package/lib/trade/priceImpact/skew/builder.js +28 -0
- package/lib/trade/priceImpact/skew/converter.d.ts +46 -0
- package/lib/trade/priceImpact/skew/converter.js +81 -0
- package/lib/trade/priceImpact/skew/fetcher.d.ts +60 -0
- package/lib/trade/priceImpact/skew/fetcher.js +169 -0
- package/lib/trade/priceImpact/skew/index.d.ts +53 -0
- package/lib/trade/priceImpact/skew/index.js +148 -0
- package/lib/trade/priceImpact/skew/types.d.ts +44 -0
- package/lib/trade/priceImpact/skew/types.js +5 -0
- package/lib/trade/spread.d.ts +5 -18
- package/lib/trade/spread.js +17 -106
- package/lib/trade/types.d.ts +109 -14
- package/lib/trade/types.js +0 -5
- package/lib/trade/utils.d.ts +18 -0
- package/lib/trade/utils.js +30 -0
- package/lib/vault/index.d.ts +3 -1
- package/lib/vault/index.js +2 -2
- package/package.json +2 -1
- 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
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use strict";
|
|
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.convertPairDepths = exports.convertOpenInterests = exports.convertCollaterals = exports.convertFees = void 0;
|
|
4
|
+
const __1 = require("../../");
|
|
5
|
+
Object.defineProperty(exports, "convertLiquidationParams", { enumerable: true, get: function () { return __1.convertLiquidationParams; } });
|
|
6
|
+
const converter_1 = require("../../trade/priceImpact/skew/converter");
|
|
7
|
+
const convertFees = (fees) => fees === null || fees === void 0 ? void 0 : fees.map(fee => convertFee(fee));
|
|
8
|
+
exports.convertFees = convertFees;
|
|
9
|
+
const convertCollateral = (collateral) => {
|
|
10
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
11
|
+
return ({
|
|
12
|
+
pairBorrowingFees: ((_a = collateral.borrowingFees) === null || _a === void 0 ? void 0 : _a.v1) !== undefined
|
|
13
|
+
? (0, exports.convertPairBorrowingFees)(collateral.borrowingFees.v1)
|
|
14
|
+
: [],
|
|
15
|
+
groupBorrowingFees: ((_b = collateral.borrowingFees) === null || _b === void 0 ? void 0 : _b.v1) !== undefined
|
|
16
|
+
? (0, exports.convertGroupBorrowingFees)(collateral.borrowingFees.v1)
|
|
17
|
+
: [],
|
|
18
|
+
collateral: collateral.collateral,
|
|
19
|
+
collateralConfig: (0, exports.convertCollateralConfig)(collateral),
|
|
20
|
+
collateralIndex: collateral.collateralIndex,
|
|
21
|
+
gToken: collateral.gToken,
|
|
22
|
+
isActive: true,
|
|
23
|
+
prices: collateral.prices,
|
|
24
|
+
symbol: collateral.symbol,
|
|
25
|
+
pairBorrowingFeesV2: {
|
|
26
|
+
params: (0, __1.convertBorrowingFeeParamsArrayV2)((_d = (_c = collateral.borrowingFees) === null || _c === void 0 ? void 0 : _c.v2) === null || _d === void 0 ? void 0 : _d.pairParams),
|
|
27
|
+
data: (0, __1.convertPairBorrowingFeeDataArrayV2)((_f = (_e = collateral.borrowingFees) === null || _e === void 0 ? void 0 : _e.v2) === null || _f === void 0 ? void 0 : _f.pairData),
|
|
28
|
+
},
|
|
29
|
+
pairFundingFees: {
|
|
30
|
+
globalParams: (0, __1.convertPairGlobalParamsArray)((_g = collateral.fundingFees) === null || _g === void 0 ? void 0 : _g.pairGlobalParams),
|
|
31
|
+
params: (0, __1.convertFundingFeeParamsArray)((_h = collateral.fundingFees) === null || _h === void 0 ? void 0 : _h.pairParams),
|
|
32
|
+
data: (0, __1.convertPairFundingFeeDataArray)((_j = collateral.fundingFees) === null || _j === void 0 ? void 0 : _j.pairData),
|
|
33
|
+
},
|
|
34
|
+
pairOis: (0, __1.convertPairOiArray)(collateral.pairOis, parseInt(collateral.collateralConfig.precision)),
|
|
35
|
+
pairSkewDepths: (0, exports.convertPairSkewDepths)(collateral.pairSkewDepths),
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const convertCollaterals = (collaterals) => collaterals === null || collaterals === void 0 ? void 0 : collaterals.map(collateral => convertCollateral(collateral));
|
|
39
|
+
exports.convertCollaterals = convertCollaterals;
|
|
40
|
+
const convertFee = (fee) => ({
|
|
41
|
+
totalPositionSizeFeeP: parseFloat(fee.totalPositionSizeFeeP) / 1e12,
|
|
42
|
+
totalLiqCollateralFeeP: parseFloat(fee.totalLiqCollateralFeeP) / 1e12,
|
|
43
|
+
oraclePositionSizeFeeP: parseFloat(fee.oraclePositionSizeFeeP) / 1e12,
|
|
44
|
+
minPositionSizeUsd: parseFloat(fee.minPositionSizeUsd) / 1e3,
|
|
45
|
+
});
|
|
46
|
+
const convertOpenInterests = (interests) => interests === null || interests === void 0 ? void 0 : interests.map(interest => convertOpenInterest(interest));
|
|
47
|
+
exports.convertOpenInterests = convertOpenInterests;
|
|
48
|
+
const convertOpenInterest = (interest) => ({
|
|
49
|
+
long: parseFloat(interest.beforeV10.long) / 1e10,
|
|
50
|
+
short: parseFloat(interest.beforeV10.short) / 1e10,
|
|
51
|
+
max: parseFloat(interest.beforeV10.max) / 1e10,
|
|
52
|
+
});
|
|
53
|
+
const convertPairDepths = (pairDepths) => pairDepths === null || pairDepths === void 0 ? void 0 : pairDepths.map(pairDepth => convertPairDepth(pairDepth));
|
|
54
|
+
exports.convertPairDepths = convertPairDepths;
|
|
55
|
+
const convertPairDepth = (pairDepth) => ({
|
|
56
|
+
onePercentDepthAboveUsd: parseInt(pairDepth.onePercentDepthAboveUsd),
|
|
57
|
+
onePercentDepthBelowUsd: parseInt(pairDepth.onePercentDepthBelowUsd),
|
|
58
|
+
});
|
|
59
|
+
const convertPairSkewDepths = (pairSkewDepths) => {
|
|
60
|
+
if (!pairSkewDepths)
|
|
61
|
+
return {};
|
|
62
|
+
return (0, converter_1.convertPairSkewDepths)(pairSkewDepths);
|
|
63
|
+
};
|
|
64
|
+
exports.convertPairSkewDepths = convertPairSkewDepths;
|
|
65
|
+
const convertPairBorrowingFees = (pairParams) => pairParams === null || pairParams === void 0 ? void 0 : pairParams.pairs.map(pairParam => convertPairBorrowingFee(pairParam));
|
|
66
|
+
exports.convertPairBorrowingFees = convertPairBorrowingFees;
|
|
67
|
+
const convertPairGroupBorrowingFee = (pairParam) => ({
|
|
68
|
+
groupIndex: parseInt(pairParam.groupIndex),
|
|
69
|
+
initialAccFeeLong: parseFloat(pairParam.initialAccFeeLong) / 1e10,
|
|
70
|
+
initialAccFeeShort: parseFloat(pairParam.initialAccFeeShort) / 1e10,
|
|
71
|
+
pairAccFeeLong: parseFloat(pairParam.pairAccFeeLong) / 1e10,
|
|
72
|
+
pairAccFeeShort: parseFloat(pairParam.pairAccFeeShort) / 1e10,
|
|
73
|
+
prevGroupAccFeeLong: parseFloat(pairParam.prevGroupAccFeeLong) / 1e10,
|
|
74
|
+
prevGroupAccFeeShort: parseFloat(pairParam.prevGroupAccFeeShort) / 1e10,
|
|
75
|
+
block: parseInt(pairParam.block),
|
|
76
|
+
});
|
|
77
|
+
const convertPairBorrowingFee = (pairParams) => ({
|
|
78
|
+
groups: pairParams.groups.map(pairParam => convertPairGroupBorrowingFee(pairParam)),
|
|
79
|
+
feePerBlock: parseFloat(pairParams.feePerBlock) / 1e10,
|
|
80
|
+
accFeeLong: parseFloat(pairParams.accFeeLong) / 1e10,
|
|
81
|
+
accFeeShort: parseFloat(pairParams.accFeeShort) / 1e10,
|
|
82
|
+
accLastUpdatedBlock: parseInt(pairParams.accLastUpdatedBlock),
|
|
83
|
+
oi: {
|
|
84
|
+
max: parseFloat(pairParams.oi.beforeV10.max) / 1e10 || 0,
|
|
85
|
+
long: parseFloat(pairParams.oi.beforeV10.long) / 1e10 || 0,
|
|
86
|
+
short: parseFloat(pairParams.oi.beforeV10.short) / 1e10 || 0,
|
|
87
|
+
},
|
|
88
|
+
feeExponent: parseInt(pairParams.feeExponent) || 0,
|
|
89
|
+
feePerBlockCap: (0, exports.convertFeePerBlockCap)(pairParams === null || pairParams === void 0 ? void 0 : pairParams.feePerBlockCap),
|
|
90
|
+
});
|
|
91
|
+
const convertGroupBorrowingFees = (pairParams) => pairParams === null || pairParams === void 0 ? void 0 : pairParams.groups.map(pairParam => convertGroupBorrowingFee(pairParam));
|
|
92
|
+
exports.convertGroupBorrowingFees = convertGroupBorrowingFees;
|
|
93
|
+
const convertGroupBorrowingFee = (pairParams) => ({
|
|
94
|
+
oi: {
|
|
95
|
+
long: parseFloat(pairParams.oi.long) / 1e10,
|
|
96
|
+
short: parseFloat(pairParams.oi.short) / 1e10,
|
|
97
|
+
max: parseFloat(pairParams.oi.max) / 1e10 || 0,
|
|
98
|
+
},
|
|
99
|
+
feePerBlock: parseFloat(pairParams.feePerBlock) / 1e10,
|
|
100
|
+
accFeeLong: parseFloat(pairParams.accFeeLong) / 1e10,
|
|
101
|
+
accFeeShort: parseFloat(pairParams.accFeeShort) / 1e10,
|
|
102
|
+
accLastUpdatedBlock: parseInt(pairParams.accLastUpdatedBlock),
|
|
103
|
+
feeExponent: parseInt(pairParams.feeExponent) || 0,
|
|
104
|
+
});
|
|
105
|
+
const convertTradingGroups = (groups) => groups === null || groups === void 0 ? void 0 : groups.map(group => convertTradingGroup(group));
|
|
106
|
+
exports.convertTradingGroups = convertTradingGroups;
|
|
107
|
+
const convertTradingGroup = (group) => ({
|
|
108
|
+
maxLeverage: parseFloat(group.maxLeverage) / 1e3,
|
|
109
|
+
minLeverage: parseFloat(group.minLeverage) / 1e3,
|
|
110
|
+
name: group.name,
|
|
111
|
+
});
|
|
112
|
+
const convertTradingPairs = (pairs) => pairs === null || pairs === void 0 ? void 0 : pairs.filter(pair => pair.from !== "").map((pair, index) => convertTradingPair(pair, index));
|
|
113
|
+
exports.convertTradingPairs = convertTradingPairs;
|
|
114
|
+
const convertTradingPair = (pair, index) => ({
|
|
115
|
+
name: (0, exports.convertPairName)(pair),
|
|
116
|
+
description: (0, __1.getPairDescription)(index),
|
|
117
|
+
from: pair.from,
|
|
118
|
+
to: pair.to,
|
|
119
|
+
pairIndex: index,
|
|
120
|
+
feeIndex: parseInt(pair.feeIndex),
|
|
121
|
+
groupIndex: parseInt(pair.groupIndex),
|
|
122
|
+
spreadP: parseFloat(pair.spreadP) / 1e10 / 100,
|
|
123
|
+
});
|
|
124
|
+
const convertTradesAndLimitOrders = (allItems, collaterals) => allItems === null || allItems === void 0 ? void 0 : allItems.map(item => {
|
|
125
|
+
return (0, exports.convertTradeContainer)(item, collaterals);
|
|
126
|
+
});
|
|
127
|
+
exports.convertTradesAndLimitOrders = convertTradesAndLimitOrders;
|
|
128
|
+
const convertTradeContainer = (tradeContainer, collaterals) => {
|
|
129
|
+
const trade = (0, exports.convertTrade)(tradeContainer.trade, collaterals);
|
|
130
|
+
const collateralIndex = trade.collateralIndex;
|
|
131
|
+
return {
|
|
132
|
+
trade,
|
|
133
|
+
tradeInfo: (0, exports.convertTradeInfo)(tradeContainer.tradeInfo),
|
|
134
|
+
initialAccFees: tradeContainer.initialAccFees === undefined
|
|
135
|
+
? {
|
|
136
|
+
accPairFee: 0,
|
|
137
|
+
accGroupFee: 0,
|
|
138
|
+
block: 0,
|
|
139
|
+
}
|
|
140
|
+
: (0, exports.convertTradeInitialAccFees)(tradeContainer.initialAccFees),
|
|
141
|
+
liquidationParams: tradeContainer.liquidationParams === undefined
|
|
142
|
+
? {
|
|
143
|
+
maxLiqSpreadP: 0,
|
|
144
|
+
startLiqThresholdP: 0,
|
|
145
|
+
endLiqThresholdP: 0,
|
|
146
|
+
startLeverage: 0,
|
|
147
|
+
endLeverage: 0,
|
|
148
|
+
}
|
|
149
|
+
: (0, __1.convertLiquidationParams)(tradeContainer.liquidationParams),
|
|
150
|
+
tradeFeesData: tradeContainer.tradeFeesData
|
|
151
|
+
? // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
|
|
152
|
+
(0, __1.convertTradeFeesData)(tradeContainer.tradeFeesData, collaterals[collateralIndex - 1].collateralConfig)
|
|
153
|
+
: undefined,
|
|
154
|
+
uiRealizedPnlData: tradeContainer.uiRealizedPnlData
|
|
155
|
+
? // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
|
|
156
|
+
(0, __1.convertUiRealizedPnlData)(tradeContainer.uiRealizedPnlData, collaterals[collateralIndex - 1].collateralConfig)
|
|
157
|
+
: undefined,
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
exports.convertTradeContainer = convertTradeContainer;
|
|
161
|
+
const convertPairFactor = (pairFactor) => ({
|
|
162
|
+
cumulativeFactor: parseFloat(pairFactor.cumulativeFactor) / 1e10,
|
|
163
|
+
protectionCloseFactor: parseFloat(pairFactor.protectionCloseFactor) / 1e10,
|
|
164
|
+
protectionCloseFactorBlocks: parseInt(pairFactor.protectionCloseFactorBlocks),
|
|
165
|
+
exemptOnOpen: pairFactor.exemptOnOpen,
|
|
166
|
+
exemptAfterProtectionCloseFactor: pairFactor.exemptAfterProtectionCloseFactor,
|
|
167
|
+
});
|
|
168
|
+
exports.convertPairFactor = convertPairFactor;
|
|
169
|
+
const convertTrade = (trade, collaterals) => {
|
|
170
|
+
var _a;
|
|
171
|
+
const { long, user } = trade;
|
|
172
|
+
const collateralIndex = parseInt(trade.collateralIndex);
|
|
173
|
+
const collateral = collaterals[collateralIndex - 1];
|
|
174
|
+
const decimals = ((_a = collateral === null || collateral === void 0 ? void 0 : collateral.collateralConfig) === null || _a === void 0 ? void 0 : _a.decimals) || 18;
|
|
175
|
+
return {
|
|
176
|
+
user,
|
|
177
|
+
index: parseInt(trade.index),
|
|
178
|
+
pairIndex: parseInt(trade.pairIndex),
|
|
179
|
+
leverage: parseInt(trade.leverage) / 1e3,
|
|
180
|
+
long,
|
|
181
|
+
isOpen: trade.isOpen,
|
|
182
|
+
collateralIndex,
|
|
183
|
+
tradeType: parseInt(trade.tradeType),
|
|
184
|
+
collateralAmount: parseFloat(trade.collateralAmount) / Math.pow(10, decimals),
|
|
185
|
+
openPrice: parseFloat(trade.openPrice) / 1e10,
|
|
186
|
+
sl: parseFloat(trade.sl) / 1e10,
|
|
187
|
+
tp: parseFloat(trade.tp) / 1e10,
|
|
188
|
+
isCounterTrade: trade.isCounterTrade,
|
|
189
|
+
positionSizeToken: trade.positionSizeToken
|
|
190
|
+
? parseFloat(trade.positionSizeToken) / 1e18
|
|
191
|
+
: undefined,
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
exports.convertTrade = convertTrade;
|
|
195
|
+
const convertTradeInfo = (tradeInfo) => ({
|
|
196
|
+
createdBlock: parseInt(tradeInfo.createdBlock),
|
|
197
|
+
tpLastUpdatedBlock: parseInt(tradeInfo.tpLastUpdatedBlock),
|
|
198
|
+
slLastUpdatedBlock: parseInt(tradeInfo.slLastUpdatedBlock),
|
|
199
|
+
maxSlippageP: parseFloat(tradeInfo.maxSlippageP) / 1e3 || 1,
|
|
200
|
+
lastOiUpdateTs: tradeInfo.lastOiUpdateTs,
|
|
201
|
+
collateralPriceUsd: tradeInfo.collateralPriceUsd && tradeInfo.collateralPriceUsd !== "0"
|
|
202
|
+
? parseFloat(tradeInfo.collateralPriceUsd) / 1e8
|
|
203
|
+
: 1,
|
|
204
|
+
contractsVersion: parseInt(tradeInfo.contractsVersion),
|
|
205
|
+
lastPosIncreaseBlock: parseInt(tradeInfo.lastPosIncreaseBlock),
|
|
206
|
+
});
|
|
207
|
+
exports.convertTradeInfo = convertTradeInfo;
|
|
208
|
+
const convertTradeInitialAccFees = (initialAccFees) => ({
|
|
209
|
+
accPairFee: parseFloat(initialAccFees.accPairFee || "0") / 1e10,
|
|
210
|
+
accGroupFee: parseFloat(initialAccFees.accGroupFee || "0") / 1e10,
|
|
211
|
+
block: parseInt(initialAccFees.block || "0"),
|
|
212
|
+
});
|
|
213
|
+
exports.convertTradeInitialAccFees = convertTradeInitialAccFees;
|
|
214
|
+
const generateStockPairToActiveStockSplit = (pairs) => {
|
|
215
|
+
const result = new Map();
|
|
216
|
+
if (!pairs) {
|
|
217
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
218
|
+
return result;
|
|
219
|
+
}
|
|
220
|
+
const basePairFroms = new Set();
|
|
221
|
+
const splitPairFroms = new Set();
|
|
222
|
+
pairs.forEach(p => {
|
|
223
|
+
const from = p.from;
|
|
224
|
+
if (from.includes("_")) {
|
|
225
|
+
splitPairFroms.add(from);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
basePairFroms.add(from);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
splitPairFroms.forEach(splitFrom => {
|
|
232
|
+
const [potentialSplitPairFromBase, potentialSplitPairFromSplitId] = splitFrom.split("_");
|
|
233
|
+
const currentHighestSplitPairIdForBasePair = result.get(potentialSplitPairFromBase);
|
|
234
|
+
if ((currentHighestSplitPairIdForBasePair &&
|
|
235
|
+
+potentialSplitPairFromSplitId >
|
|
236
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
237
|
+
+currentHighestSplitPairIdForBasePair.split("_")[1]) ||
|
|
238
|
+
(!currentHighestSplitPairIdForBasePair &&
|
|
239
|
+
basePairFroms.has(potentialSplitPairFromBase))) {
|
|
240
|
+
result.set(potentialSplitPairFromBase, splitFrom);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
244
|
+
return result;
|
|
245
|
+
};
|
|
246
|
+
exports.generateStockPairToActiveStockSplit = generateStockPairToActiveStockSplit;
|
|
247
|
+
const convertContestLeaderboardEntry = (entry) => {
|
|
248
|
+
const [trader, numWins, numLosses, avgWin, avgLoss, daiProfit, pctProfit, daiVolume,] = entry;
|
|
249
|
+
return {
|
|
250
|
+
trader,
|
|
251
|
+
numWins,
|
|
252
|
+
numLosses,
|
|
253
|
+
avgWin,
|
|
254
|
+
avgLoss,
|
|
255
|
+
daiProfit,
|
|
256
|
+
pctProfit,
|
|
257
|
+
daiVolume,
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
exports.convertContestLeaderboardEntry = convertContestLeaderboardEntry;
|
|
261
|
+
// OiWindow values are normalized to USD 1e18
|
|
262
|
+
const convertPairOi = (collateral) => ({
|
|
263
|
+
oiLongUsd: parseFloat(collateral.oiLongUsd) / 1e18,
|
|
264
|
+
oiShortUsd: parseFloat(collateral.oiShortUsd) / 1e18,
|
|
265
|
+
});
|
|
266
|
+
exports.convertPairOi = convertPairOi;
|
|
267
|
+
const convertOiWindows = (oiWindows) => {
|
|
268
|
+
return oiWindows === null || oiWindows === void 0 ? void 0 : oiWindows.map(pairWindows => {
|
|
269
|
+
const converted = {};
|
|
270
|
+
for (const [key, oiWindow] of Object.entries(pairWindows)) {
|
|
271
|
+
converted[key] = (0, exports.convertPairOi)(oiWindow);
|
|
272
|
+
}
|
|
273
|
+
return converted;
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
exports.convertOiWindows = convertOiWindows;
|
|
277
|
+
const convertOiWindowsSettings = (oiWindowsSettings) => ({
|
|
278
|
+
startTs: oiWindowsSettings.startTs,
|
|
279
|
+
windowsDuration: oiWindowsSettings.windowsDuration,
|
|
280
|
+
windowsCount: oiWindowsSettings.windowsCount,
|
|
281
|
+
});
|
|
282
|
+
exports.convertOiWindowsSettings = convertOiWindowsSettings;
|
|
283
|
+
const convertCollateralConfig = (collateral) => ({
|
|
284
|
+
collateral: collateral.collateral,
|
|
285
|
+
isActive: collateral.isActive,
|
|
286
|
+
precision: parseInt(collateral.collateralConfig.precision),
|
|
287
|
+
precisionDelta: parseInt(collateral.collateralConfig.precisionDelta),
|
|
288
|
+
decimals: collateral.collateralConfig.decimals,
|
|
289
|
+
});
|
|
290
|
+
exports.convertCollateralConfig = convertCollateralConfig;
|
|
291
|
+
const convertFeeTiers = (feeTiersBackend) => {
|
|
292
|
+
var _a;
|
|
293
|
+
return ({
|
|
294
|
+
tiers: feeTiersBackend === null || feeTiersBackend === void 0 ? void 0 : feeTiersBackend.tiers.map(tier => ({
|
|
295
|
+
feeMultiplier: Number(tier.feeMultiplier) / 1e3,
|
|
296
|
+
pointsThreshold: parseFloat(tier.pointsThreshold),
|
|
297
|
+
})),
|
|
298
|
+
multipliers: ((_a = feeTiersBackend === null || feeTiersBackend === void 0 ? void 0 : feeTiersBackend.multipliers) === null || _a === void 0 ? void 0 : _a.map(mult => parseFloat(mult) / 1e3)) || [],
|
|
299
|
+
currentDay: (feeTiersBackend === null || feeTiersBackend === void 0 ? void 0 : feeTiersBackend.currentDay) || 0,
|
|
300
|
+
});
|
|
301
|
+
};
|
|
302
|
+
exports.convertFeeTiers = convertFeeTiers;
|
|
303
|
+
const convertTraderFeeTiers = (traderFeeTiers) => ({
|
|
304
|
+
traderEnrollment: {
|
|
305
|
+
status: traderFeeTiers.traderEnrollment.status,
|
|
306
|
+
},
|
|
307
|
+
traderInfo: {
|
|
308
|
+
lastDayUpdated: traderFeeTiers.traderInfo.lastDayUpdated,
|
|
309
|
+
trailingPoints: parseFloat(traderFeeTiers.traderInfo.trailingPoints) / 1e18,
|
|
310
|
+
},
|
|
311
|
+
inboundPoints: parseFloat(traderFeeTiers.inboundPoints) / 1e18,
|
|
312
|
+
outboundPoints: parseFloat(traderFeeTiers.outboundPoints) / 1e18,
|
|
313
|
+
lastDayUpdatedPoints: parseFloat(traderFeeTiers.lastDayUpdatedPoints) / 1e18,
|
|
314
|
+
expiredPoints: traderFeeTiers.expiredPoints.map(point => parseFloat(point) / 1e18),
|
|
315
|
+
unclaimedPoints: parseFloat(traderFeeTiers.unclaimedPoints) / 1e18,
|
|
316
|
+
});
|
|
317
|
+
exports.convertTraderFeeTiers = convertTraderFeeTiers;
|
|
318
|
+
const convertGlobalTradeFeeParams = (fee) => ({
|
|
319
|
+
referralFeeP: parseFloat(fee.referralFeeP) / 1e5,
|
|
320
|
+
govFeeP: parseFloat(fee.govFeeP) / 1e5,
|
|
321
|
+
triggerOrderFeeP: parseFloat(fee.triggerOrderFeeP) / 1e5,
|
|
322
|
+
gnsOtcFeeP: parseFloat(fee.gnsOtcFeeP) / 1e5,
|
|
323
|
+
gTokenFeeP: parseFloat(fee.gTokenFeeP) / 1e5,
|
|
324
|
+
});
|
|
325
|
+
exports.convertGlobalTradeFeeParams = convertGlobalTradeFeeParams;
|
|
326
|
+
const convertMaxLeverages = (maxLeverages) => maxLeverages === null || maxLeverages === void 0 ? void 0 : maxLeverages.map(maxLeverage => parseFloat(maxLeverage) / 1e3);
|
|
327
|
+
exports.convertMaxLeverages = convertMaxLeverages;
|
|
328
|
+
const convertFeePerBlockCap = (feeCap) => ({
|
|
329
|
+
minP: (feeCap === null || feeCap === void 0 ? void 0 : feeCap.minP) ? parseFloat(feeCap.minP.toString()) / 1e3 / 100 : 0,
|
|
330
|
+
maxP: (feeCap === null || feeCap === void 0 ? void 0 : feeCap.maxP) ? parseFloat(feeCap.maxP.toString()) / 1e3 / 100 : 1,
|
|
331
|
+
});
|
|
332
|
+
exports.convertFeePerBlockCap = convertFeePerBlockCap;
|
|
333
|
+
const convertPairName = (pair) => {
|
|
334
|
+
if (!pair)
|
|
335
|
+
return "";
|
|
336
|
+
return pair.from.split("_")[0] + "/" + pair.to;
|
|
337
|
+
};
|
|
338
|
+
exports.convertPairName = convertPairName;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TransformedGlobalTradingVariables } from "./types";
|
|
2
|
+
import { GlobalTradingVariablesBackend } from "./backend.types";
|
|
3
|
+
export declare const transformGlobalTradingVariables: (rawData: GlobalTradingVariablesBackend) => TransformedGlobalTradingVariables;
|
|
4
|
+
export * from "./backend.types";
|
|
5
|
+
export * from "./types";
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.transformGlobalTradingVariables = void 0;
|
|
18
|
+
const converter_1 = require("./converter");
|
|
19
|
+
const trade_1 = require("../../trade");
|
|
20
|
+
const transformGlobalTradingVariables = (rawData) => {
|
|
21
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
22
|
+
const globalTradingVariables = {
|
|
23
|
+
collaterals: (0, converter_1.convertCollaterals)(rawData.collaterals),
|
|
24
|
+
pairs: (0, converter_1.convertTradingPairs)(rawData.pairs),
|
|
25
|
+
stockPairToActiveStockSplit: (0, converter_1.generateStockPairToActiveStockSplit)(rawData.pairs),
|
|
26
|
+
groups: (0, converter_1.convertTradingGroups)(rawData.groups),
|
|
27
|
+
fees: (0, converter_1.convertFees)(rawData.fees),
|
|
28
|
+
orderTimeout: rawData.marketOrdersTimeoutBlocks,
|
|
29
|
+
blockConfirmations: rawData.blockConfirmations,
|
|
30
|
+
forexClosed: !rawData.isForexOpen,
|
|
31
|
+
stocksClosed: !rawData.isStocksOpen,
|
|
32
|
+
indicesClosed: !rawData.isIndicesOpen,
|
|
33
|
+
commoditiesClosed: !rawData.isCommoditiesOpen,
|
|
34
|
+
pairDepths: ((_a = rawData.pairInfos) === null || _a === void 0 ? void 0 : _a.pairDepths) !== undefined
|
|
35
|
+
? (0, converter_1.convertPairDepths)(rawData.pairInfos.pairDepths)
|
|
36
|
+
: [],
|
|
37
|
+
pairMaxLeverages: ((_b = rawData.pairInfos) === null || _b === void 0 ? void 0 : _b.maxLeverages) !== undefined
|
|
38
|
+
? (0, converter_1.convertMaxLeverages)(rawData.pairInfos.maxLeverages)
|
|
39
|
+
: [],
|
|
40
|
+
maxNegativePnlOnOpenP: (rawData.maxNegativePnlOnOpenP && rawData.maxNegativePnlOnOpenP / 1e10) ||
|
|
41
|
+
undefined,
|
|
42
|
+
oiWindowsSettings: rawData.oiWindowsSettings !== undefined
|
|
43
|
+
? (0, converter_1.convertOiWindowsSettings)(rawData.oiWindowsSettings)
|
|
44
|
+
: { startTs: 0, windowsDuration: 0, windowsCount: 0 },
|
|
45
|
+
oiWindows: rawData.oiWindows !== undefined
|
|
46
|
+
? (0, converter_1.convertOiWindows)(rawData.oiWindows)
|
|
47
|
+
: [],
|
|
48
|
+
feeTiers: (0, converter_1.convertFeeTiers)(rawData.feeTiers),
|
|
49
|
+
liquidationParams: {
|
|
50
|
+
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))) || [],
|
|
51
|
+
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))) || [],
|
|
52
|
+
},
|
|
53
|
+
counterTradeSettings: (0, trade_1.convertCounterTradeSettingsArray)(rawData.counterTradeSettings),
|
|
54
|
+
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))) || [],
|
|
55
|
+
globalTradeFeeParams: rawData.globalTradeFeeParams
|
|
56
|
+
? (0, converter_1.convertGlobalTradeFeeParams)(rawData.globalTradeFeeParams)
|
|
57
|
+
: undefined,
|
|
58
|
+
congestionLevels: rawData.congestionLevels,
|
|
59
|
+
};
|
|
60
|
+
const currentBlock = (rawData.currentBlock > -1 && rawData.currentBlock) || undefined;
|
|
61
|
+
const l1BlockNumber = (rawData.currentL1Block > -1 && rawData.currentL1Block) || undefined;
|
|
62
|
+
const pairIndexes = {};
|
|
63
|
+
for (let i = 0; i < ((_j = rawData.pairs) === null || _j === void 0 ? void 0 : _j.length); i++) {
|
|
64
|
+
pairIndexes[rawData.pairs[i].from + "/" + rawData.pairs[i].to] = i;
|
|
65
|
+
}
|
|
66
|
+
if (globalTradingVariables.collaterals !== undefined) {
|
|
67
|
+
const { collaterals } = globalTradingVariables;
|
|
68
|
+
for (let i = 0; i < collaterals.length; i++) {
|
|
69
|
+
collaterals[i].tradingPairs = getTradingPairs(globalTradingVariables.pairs, collaterals);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
globalTradingVariables,
|
|
74
|
+
pairIndexes,
|
|
75
|
+
blockNumber: currentBlock,
|
|
76
|
+
l1BlockNumber,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
exports.transformGlobalTradingVariables = transformGlobalTradingVariables;
|
|
80
|
+
// Orphaned function
|
|
81
|
+
const getTradingPairs = (pairs, collaterals) => {
|
|
82
|
+
const tradingPairs = new Map();
|
|
83
|
+
if (pairs) {
|
|
84
|
+
for (let j = 0; j < pairs.length; j++) {
|
|
85
|
+
const pair = pairs[j];
|
|
86
|
+
// pair is tradeable if any collateral is enabled (max oi > 0)
|
|
87
|
+
if (collaterals.some((collat) => collat.pairOis[j].maxCollateral > 0)) {
|
|
88
|
+
tradingPairs.set(j, pair);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return tradingPairs;
|
|
93
|
+
};
|
|
94
|
+
// Re-export everything from backend.types
|
|
95
|
+
__exportStar(require("./backend.types"), exports);
|
|
96
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { CollateralConfig } from "src/markets/collateral";
|
|
2
|
+
import { BorrowingFee, BorrowingFeeV2, CounterTradeSettings, Fee, FeeTiers, FundingFees, GlobalTradeFeeParams, LeaderboardTrader, LiquidationParams, OiWindows, OiWindowsSettings, Pair, PairDepth, PairFactor, PairIndexes, TradingGroup } from "../../trade";
|
|
3
|
+
import { UnifiedPairOi } from "src/markets";
|
|
4
|
+
export type TransformedGlobalTradingVariables = {
|
|
5
|
+
globalTradingVariables: GlobalTradingVariablesType;
|
|
6
|
+
pairIndexes: PairIndexes;
|
|
7
|
+
blockNumber: number | undefined;
|
|
8
|
+
l1BlockNumber: number | undefined;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @dev Processed collateral data from backend (wrapper of contract data)
|
|
12
|
+
*/
|
|
13
|
+
export type TradingVariablesCollateral = {
|
|
14
|
+
pairBorrowingFees: BorrowingFee.Pair[];
|
|
15
|
+
groupBorrowingFees: BorrowingFee.Group[];
|
|
16
|
+
pairBorrowingFeesV2: {
|
|
17
|
+
params: BorrowingFeeV2.BorrowingFeeParams[];
|
|
18
|
+
data: BorrowingFeeV2.PairBorrowingFeeData[];
|
|
19
|
+
};
|
|
20
|
+
pairFundingFees: {
|
|
21
|
+
globalParams: FundingFees.PairGlobalParams[];
|
|
22
|
+
params: FundingFees.FundingFeeParams[];
|
|
23
|
+
data: FundingFees.PairFundingFeeData[];
|
|
24
|
+
};
|
|
25
|
+
collateral: string;
|
|
26
|
+
collateralIndex: number;
|
|
27
|
+
collateralConfig: CollateralConfig;
|
|
28
|
+
gToken: {
|
|
29
|
+
address: string;
|
|
30
|
+
currentBalanceCollateral: string;
|
|
31
|
+
marketCap: string;
|
|
32
|
+
maxBalanceCollateral: string;
|
|
33
|
+
};
|
|
34
|
+
tradingPairs?: Map<number, Pair>;
|
|
35
|
+
isActive: boolean;
|
|
36
|
+
prices: TokenPrices;
|
|
37
|
+
symbol: string;
|
|
38
|
+
pairOis: UnifiedPairOi[];
|
|
39
|
+
pairSkewDepths: {
|
|
40
|
+
[pairIndex: number]: number;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export type TokenPrices = {
|
|
44
|
+
collateralPriceUsd: number;
|
|
45
|
+
gnsPriceCollateral: number;
|
|
46
|
+
gnsPriceUsd: number;
|
|
47
|
+
};
|
|
48
|
+
export type GlobalTradingVariablesType = {
|
|
49
|
+
collaterals: TradingVariablesCollateral[];
|
|
50
|
+
paused?: boolean;
|
|
51
|
+
pairs?: Pair[];
|
|
52
|
+
stockPairToActiveStockSplit?: Map<string, string>;
|
|
53
|
+
groups?: TradingGroup[];
|
|
54
|
+
fees?: Fee[];
|
|
55
|
+
orderTimeout?: number;
|
|
56
|
+
crypto?: string[];
|
|
57
|
+
forex?: string[];
|
|
58
|
+
forexClosed?: boolean;
|
|
59
|
+
stocks?: string[];
|
|
60
|
+
stocksClosed?: boolean;
|
|
61
|
+
indices?: string[];
|
|
62
|
+
indicesClosed?: boolean;
|
|
63
|
+
commodities?: string[];
|
|
64
|
+
commoditiesClosed?: boolean;
|
|
65
|
+
blockConfirmations?: number;
|
|
66
|
+
pairDepths?: PairDepth[];
|
|
67
|
+
pairMaxLeverages?: number[];
|
|
68
|
+
maxNegativePnlOnOpenP?: number;
|
|
69
|
+
oiWindowsSettings?: OiWindowsSettings;
|
|
70
|
+
oiWindows?: OiWindows[];
|
|
71
|
+
collateralConfig?: CollateralConfig;
|
|
72
|
+
feeTiers?: FeeTiers;
|
|
73
|
+
liquidationParams: {
|
|
74
|
+
groups: LiquidationParams[];
|
|
75
|
+
pairs: LiquidationParams[];
|
|
76
|
+
};
|
|
77
|
+
counterTradeSettings: CounterTradeSettings[];
|
|
78
|
+
pairFactors: PairFactor[];
|
|
79
|
+
globalTradeFeeParams?: GlobalTradeFeeParams;
|
|
80
|
+
congestionLevels: {
|
|
81
|
+
low: number;
|
|
82
|
+
high: number;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
export interface LeaderboardTraderWithWinsLosses extends LeaderboardTrader {
|
|
86
|
+
wins?: number;
|
|
87
|
+
losses?: number;
|
|
88
|
+
}
|
|
89
|
+
export interface ILeaderboard {
|
|
90
|
+
ready: boolean;
|
|
91
|
+
bestTraders: LeaderboardTraderWithWinsLosses[];
|
|
92
|
+
}
|
|
93
|
+
export declare enum ORDER_TYPE {
|
|
94
|
+
LIMIT = "LIMIT",
|
|
95
|
+
STOP = "STOP",
|
|
96
|
+
MARKET = "MARKET"
|
|
97
|
+
}
|
|
98
|
+
export declare enum TRADE_TYPE {
|
|
99
|
+
LONG = "LONG",
|
|
100
|
+
SHORT = "SHORT"
|
|
101
|
+
}
|
|
102
|
+
export interface ActiveNews {
|
|
103
|
+
desc: string;
|
|
104
|
+
from: number;
|
|
105
|
+
to: number;
|
|
106
|
+
}
|
|
107
|
+
export interface BorrowingFeePerBlock {
|
|
108
|
+
pairFee: number;
|
|
109
|
+
minPairFee: number;
|
|
110
|
+
groupFee: number;
|
|
111
|
+
pairLong: boolean;
|
|
112
|
+
groupLong: boolean;
|
|
113
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TRADE_TYPE = exports.ORDER_TYPE = void 0;
|
|
4
|
+
var ORDER_TYPE;
|
|
5
|
+
(function (ORDER_TYPE) {
|
|
6
|
+
ORDER_TYPE["LIMIT"] = "LIMIT";
|
|
7
|
+
ORDER_TYPE["STOP"] = "STOP";
|
|
8
|
+
ORDER_TYPE["MARKET"] = "MARKET";
|
|
9
|
+
})(ORDER_TYPE = exports.ORDER_TYPE || (exports.ORDER_TYPE = {}));
|
|
10
|
+
var TRADE_TYPE;
|
|
11
|
+
(function (TRADE_TYPE) {
|
|
12
|
+
TRADE_TYPE["LONG"] = "LONG";
|
|
13
|
+
TRADE_TYPE["SHORT"] = "SHORT";
|
|
14
|
+
})(TRADE_TYPE = exports.TRADE_TYPE || (exports.TRADE_TYPE = {}));
|
package/lib/constants.d.ts
CHANGED
|
@@ -407,11 +407,6 @@ export declare const pairs: {
|
|
|
407
407
|
"ICNT/USD": string;
|
|
408
408
|
"NEWT/USD": string;
|
|
409
409
|
"PUMP/USD": string;
|
|
410
|
-
"SAROS/USD": string;
|
|
411
|
-
"SPK/USD": string;
|
|
412
|
-
"ERA/USD": string;
|
|
413
|
-
"BGSC/USD": string;
|
|
414
|
-
"TAG/USD": string;
|
|
415
410
|
};
|
|
416
411
|
export declare const syntheticPairs: Set<string>;
|
|
417
412
|
export declare const parentToSyntheticPairMap: Map<string, string>;
|
package/lib/constants.js
CHANGED
|
@@ -415,11 +415,6 @@ exports.pairs = {
|
|
|
415
415
|
"ICNT/USD": CRYPTO,
|
|
416
416
|
"NEWT/USD": CRYPTO,
|
|
417
417
|
"PUMP/USD": CRYPTO,
|
|
418
|
-
"SAROS/USD": CRYPTO,
|
|
419
|
-
"SPK/USD": CRYPTO,
|
|
420
|
-
"ERA/USD": CRYPTO,
|
|
421
|
-
"BGSC/USD": CRYPTO,
|
|
422
|
-
"TAG/USD": CRYPTO,
|
|
423
418
|
};
|
|
424
419
|
exports.syntheticPairs = new Set([
|
|
425
420
|
"BTCDEGEN/USD",
|