@gainsnetwork/sdk 0.2.71-rc4 → 1.0.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/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 -3
- package/lib/constants.js +7 -9
- 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 -3
- 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 +33 -0
- package/lib/trade/fees/borrowing/index.d.ts +23 -2
- package/lib/trade/fees/borrowing/index.js +50 -16
- 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 +8 -2
- package/lib/trade/fees/index.js +67 -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 +89 -0
- package/lib/trade/pnl/index.js +302 -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 +78 -0
- package/lib/trade/priceImpact/open/types.d.ts +44 -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 -12
- package/lib/trade/types.js +0 -3
- 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
package/README.md
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Pair, TradeContainer } from "../../trade";
|
|
2
|
+
import { TradeContainerBackend } from "./../tradingVariables/backend.types";
|
|
3
|
+
import { TradingVariablesCollateral } from "./../tradingVariables/types";
|
|
4
|
+
export type TransformedGlobalTrades = {
|
|
5
|
+
allTrades: Map<string, NestedTrade>;
|
|
6
|
+
allLimitOrders: Map<string, NestedTrade>;
|
|
7
|
+
trades: NestedTrade;
|
|
8
|
+
limitOrders: NestedTrade;
|
|
9
|
+
};
|
|
10
|
+
export type NestedTrade = Map<number, Map<number, TradeContainer>>;
|
|
11
|
+
export declare const transformGlobalTrades: (rawTrades: TradeContainerBackend[], pairs: Pair[], currentAddress: string | undefined, collaterals: TradingVariablesCollateral[]) => TransformedGlobalTrades | undefined;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformGlobalTrades = void 0;
|
|
4
|
+
const trade_1 = require("../../trade");
|
|
5
|
+
const converter_1 = require("./../tradingVariables/converter");
|
|
6
|
+
const transformGlobalTrades = (rawTrades, pairs, currentAddress, collaterals) => {
|
|
7
|
+
if (rawTrades === undefined)
|
|
8
|
+
return;
|
|
9
|
+
const r = (0, converter_1.convertTradesAndLimitOrders)(rawTrades, collaterals);
|
|
10
|
+
const returnObject = {
|
|
11
|
+
allTrades: new Map(),
|
|
12
|
+
allLimitOrders: new Map(),
|
|
13
|
+
trades: new Map(),
|
|
14
|
+
limitOrders: new Map(),
|
|
15
|
+
};
|
|
16
|
+
currentAddress = currentAddress === undefined ? "" : currentAddress;
|
|
17
|
+
const _trades = new Map();
|
|
18
|
+
const _limitOrders = new Map();
|
|
19
|
+
const _allTrades = new Map();
|
|
20
|
+
const _allLimitOrders = new Map();
|
|
21
|
+
for (let s = 0; s < r.length; s++) {
|
|
22
|
+
if (r[s].trade.tradeType !== trade_1.TradeType.TRADE) {
|
|
23
|
+
const t = r[s];
|
|
24
|
+
if (_allLimitOrders.get(t.trade.user) === undefined) {
|
|
25
|
+
_allLimitOrders.set(t.trade.user, new Map());
|
|
26
|
+
}
|
|
27
|
+
const traderMap_all = _allLimitOrders.get(t.trade.user);
|
|
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
|
+
}
|
|
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
|
+
if (t.trade.user.toUpperCase() !== currentAddress.toUpperCase()) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (_limitOrders.get(t.trade.pairIndex) === undefined) {
|
|
37
|
+
_limitOrders.set(t.trade.pairIndex, new Map());
|
|
38
|
+
}
|
|
39
|
+
const traderPairMap = _limitOrders.get(t.trade.pairIndex);
|
|
40
|
+
traderPairMap === null || traderPairMap === void 0 ? void 0 : traderPairMap.set(t.trade.index, t);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const t = r[s];
|
|
44
|
+
if (_allTrades.get(t.trade.user) === undefined) {
|
|
45
|
+
_allTrades.set(t.trade.user, new Map());
|
|
46
|
+
}
|
|
47
|
+
const traderMap_all = _allTrades.get(t.trade.user);
|
|
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
|
+
}
|
|
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
|
+
if (t.trade.user.toUpperCase() !== currentAddress.toUpperCase()) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (_trades.get(t.trade.pairIndex) === undefined) {
|
|
57
|
+
_trades.set(t.trade.pairIndex, new Map());
|
|
58
|
+
}
|
|
59
|
+
const traderPairMap = _trades.get(t.trade.pairIndex);
|
|
60
|
+
traderPairMap === null || traderPairMap === void 0 ? void 0 : traderPairMap.set(t.trade.index, t);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
returnObject.trades = _trades;
|
|
64
|
+
returnObject.limitOrders = _limitOrders;
|
|
65
|
+
returnObject.allTrades = _allTrades;
|
|
66
|
+
returnObject.allLimitOrders = _allLimitOrders;
|
|
67
|
+
return returnObject;
|
|
68
|
+
};
|
|
69
|
+
exports.transformGlobalTrades = transformGlobalTrades;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export * from "./tradingVariables";
|
|
2
|
+
export * from "./globalTrades";
|
|
3
|
+
export { convertTradeContainer as convertTradeContainerBackend, convertPairOi as convertPairOiBackend, convertOiWindows as convertOiWindowsBackend, convertOiWindowsSettings as convertOiWindowsSettingsBackend, convertTraderFeeTiers as convertTraderFeeTiersBackend, convertTradingPairs as convertTradingPairsBackend, convertCollaterals as convertCollateralsBackend, } from "./tradingVariables/converter";
|
|
@@ -0,0 +1,28 @@
|
|
|
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.convertCollateralsBackend = exports.convertTradingPairsBackend = exports.convertTraderFeeTiersBackend = exports.convertOiWindowsSettingsBackend = exports.convertOiWindowsBackend = exports.convertPairOiBackend = exports.convertTradeContainerBackend = void 0;
|
|
18
|
+
__exportStar(require("./tradingVariables"), exports);
|
|
19
|
+
__exportStar(require("./globalTrades"), exports);
|
|
20
|
+
// Re-export backend-specific converters with "Backend" suffix to avoid conflicts
|
|
21
|
+
var converter_1 = require("./tradingVariables/converter");
|
|
22
|
+
Object.defineProperty(exports, "convertTradeContainerBackend", { enumerable: true, get: function () { return converter_1.convertTradeContainer; } });
|
|
23
|
+
Object.defineProperty(exports, "convertPairOiBackend", { enumerable: true, get: function () { return converter_1.convertPairOi; } });
|
|
24
|
+
Object.defineProperty(exports, "convertOiWindowsBackend", { enumerable: true, get: function () { return converter_1.convertOiWindows; } });
|
|
25
|
+
Object.defineProperty(exports, "convertOiWindowsSettingsBackend", { enumerable: true, get: function () { return converter_1.convertOiWindowsSettings; } });
|
|
26
|
+
Object.defineProperty(exports, "convertTraderFeeTiersBackend", { enumerable: true, get: function () { return converter_1.convertTraderFeeTiers; } });
|
|
27
|
+
Object.defineProperty(exports, "convertTradingPairsBackend", { enumerable: true, get: function () { return converter_1.convertTradingPairs; } });
|
|
28
|
+
Object.defineProperty(exports, "convertCollateralsBackend", { enumerable: true, get: function () { return converter_1.convertCollaterals; } });
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { TokenPrices } from "./types";
|
|
2
|
+
export interface TradeContainerBackend {
|
|
3
|
+
trade: TradeBackend;
|
|
4
|
+
tradeInfo: TradeInfoBackend;
|
|
5
|
+
initialAccFees: TradeInitialAccFeesBackend;
|
|
6
|
+
liquidationParams: LiquidationParamsBackend;
|
|
7
|
+
tradeFeesData?: TradeFeesDataBackend;
|
|
8
|
+
uiRealizedPnlData?: UiRealizedPnlDataBackend;
|
|
9
|
+
}
|
|
10
|
+
export interface TradeBackend {
|
|
11
|
+
user: string;
|
|
12
|
+
index: string;
|
|
13
|
+
pairIndex: string;
|
|
14
|
+
leverage: string;
|
|
15
|
+
long: boolean;
|
|
16
|
+
isOpen: boolean;
|
|
17
|
+
collateralIndex: string;
|
|
18
|
+
tradeType: string;
|
|
19
|
+
collateralAmount: string;
|
|
20
|
+
openPrice: string;
|
|
21
|
+
tp: string;
|
|
22
|
+
sl: string;
|
|
23
|
+
isCounterTrade?: boolean;
|
|
24
|
+
positionSizeToken?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface TradeInfoBackend {
|
|
27
|
+
createdBlock: string;
|
|
28
|
+
tpLastUpdatedBlock: string;
|
|
29
|
+
slLastUpdatedBlock: string;
|
|
30
|
+
maxSlippageP: string;
|
|
31
|
+
lastOiUpdateTs: number;
|
|
32
|
+
collateralPriceUsd: string;
|
|
33
|
+
contractsVersion: string;
|
|
34
|
+
lastPosIncreaseBlock: string;
|
|
35
|
+
}
|
|
36
|
+
export interface TradeInitialAccFeesBackend {
|
|
37
|
+
accPairFee: string;
|
|
38
|
+
accGroupFee: string;
|
|
39
|
+
block: string;
|
|
40
|
+
}
|
|
41
|
+
export interface TradeFeesDataBackend {
|
|
42
|
+
realizedTradingFeesCollateral: string;
|
|
43
|
+
realizedPnlCollateral: string;
|
|
44
|
+
manuallyRealizedNegativePnlCollateral: string;
|
|
45
|
+
alreadyTransferredNegativePnlCollateral: string;
|
|
46
|
+
virtualAvailableCollateralInDiamond: string;
|
|
47
|
+
initialAccFundingFeeP: string;
|
|
48
|
+
initialAccBorrowingFeeP: string;
|
|
49
|
+
}
|
|
50
|
+
export interface UiRealizedPnlDataBackend {
|
|
51
|
+
realizedTradingFeesCollateral: string;
|
|
52
|
+
realizedOldBorrowingFeesCollateral: string;
|
|
53
|
+
realizedNewBorrowingFeesCollateral: string;
|
|
54
|
+
realizedFundingFeesCollateral: string;
|
|
55
|
+
realizedPnlPartialCloseCollateral: string;
|
|
56
|
+
pnlWithdrawnCollateral: string;
|
|
57
|
+
}
|
|
58
|
+
export interface LiquidationParamsBackend {
|
|
59
|
+
maxLiqSpreadP: string;
|
|
60
|
+
startLiqThresholdP: string;
|
|
61
|
+
endLiqThresholdP: string;
|
|
62
|
+
startLeverage: string;
|
|
63
|
+
endLeverage: string;
|
|
64
|
+
}
|
|
65
|
+
export interface TradingGroupBackend {
|
|
66
|
+
name: string;
|
|
67
|
+
minLeverage: string;
|
|
68
|
+
maxLeverage: string;
|
|
69
|
+
}
|
|
70
|
+
export interface FeeBackend {
|
|
71
|
+
totalPositionSizeFeeP: string;
|
|
72
|
+
totalLiqCollateralFeeP: string;
|
|
73
|
+
oraclePositionSizeFeeP: string;
|
|
74
|
+
minPositionSizeUsd: string;
|
|
75
|
+
}
|
|
76
|
+
export interface OpenInterestBeforeV10Backend {
|
|
77
|
+
long: string;
|
|
78
|
+
short: string;
|
|
79
|
+
max: string;
|
|
80
|
+
}
|
|
81
|
+
export interface OpenInterestCollateralBackend {
|
|
82
|
+
oiLongCollateral: string;
|
|
83
|
+
oiShortCollateral: string;
|
|
84
|
+
}
|
|
85
|
+
export interface OpenInterestTokenBackend {
|
|
86
|
+
oiLongToken: string;
|
|
87
|
+
oiShortToken: string;
|
|
88
|
+
}
|
|
89
|
+
export interface OpenInterestBackend {
|
|
90
|
+
beforeV10: OpenInterestBeforeV10Backend;
|
|
91
|
+
collateral: OpenInterestCollateralBackend;
|
|
92
|
+
token: OpenInterestTokenBackend;
|
|
93
|
+
}
|
|
94
|
+
export interface GroupOpenInterestBackend {
|
|
95
|
+
long: string;
|
|
96
|
+
short: string;
|
|
97
|
+
max: string;
|
|
98
|
+
}
|
|
99
|
+
export interface PairDepthBackend {
|
|
100
|
+
onePercentDepthAboveUsd: string;
|
|
101
|
+
onePercentDepthBelowUsd: string;
|
|
102
|
+
}
|
|
103
|
+
export interface PairBorrowingFeesBackendPairGroup {
|
|
104
|
+
groupIndex: string;
|
|
105
|
+
block: string;
|
|
106
|
+
initialAccFeeLong: string;
|
|
107
|
+
initialAccFeeShort: string;
|
|
108
|
+
prevGroupAccFeeLong: string;
|
|
109
|
+
prevGroupAccFeeShort: string;
|
|
110
|
+
pairAccFeeLong: string;
|
|
111
|
+
pairAccFeeShort: string;
|
|
112
|
+
}
|
|
113
|
+
export interface PairBorrowingFeesBackendPair {
|
|
114
|
+
oi: OpenInterestBackend;
|
|
115
|
+
feePerBlock: string;
|
|
116
|
+
accFeeLong: string;
|
|
117
|
+
accFeeShort: string;
|
|
118
|
+
accLastUpdatedBlock: string;
|
|
119
|
+
feeExponent: string;
|
|
120
|
+
groups: PairBorrowingFeesBackendPairGroup[];
|
|
121
|
+
feePerBlockCap?: BorrowingFeePerBlockCapBackend;
|
|
122
|
+
}
|
|
123
|
+
export interface PairBorrowingFeesBackendGroup {
|
|
124
|
+
oi: GroupOpenInterestBackend;
|
|
125
|
+
feePerBlock: string;
|
|
126
|
+
accFeeLong: string;
|
|
127
|
+
accFeeShort: string;
|
|
128
|
+
accLastUpdatedBlock: string;
|
|
129
|
+
feeExponent: string;
|
|
130
|
+
}
|
|
131
|
+
export interface BorrowingFeePerBlockCapBackend {
|
|
132
|
+
minP: string;
|
|
133
|
+
maxP: string;
|
|
134
|
+
}
|
|
135
|
+
export interface PairParamsBorrowingFeesBackend {
|
|
136
|
+
pairs: PairBorrowingFeesBackendPair[];
|
|
137
|
+
groups: PairBorrowingFeesBackendGroup[];
|
|
138
|
+
}
|
|
139
|
+
export interface PairBackend {
|
|
140
|
+
from: string;
|
|
141
|
+
to: string;
|
|
142
|
+
spreadP: string;
|
|
143
|
+
groupIndex: string;
|
|
144
|
+
feeIndex: string;
|
|
145
|
+
}
|
|
146
|
+
export type PairFactorBackend = {
|
|
147
|
+
cumulativeFactor: string;
|
|
148
|
+
protectionCloseFactor: string;
|
|
149
|
+
protectionCloseFactorBlocks: string;
|
|
150
|
+
exemptOnOpen: boolean;
|
|
151
|
+
exemptAfterProtectionCloseFactor: boolean;
|
|
152
|
+
};
|
|
153
|
+
export interface GlobalTradingVariablesBackend {
|
|
154
|
+
lastRefreshed: string;
|
|
155
|
+
refreshId: number;
|
|
156
|
+
tradingState: number;
|
|
157
|
+
marketOrdersTimeoutBlocks: number;
|
|
158
|
+
pairs: PairBackend[];
|
|
159
|
+
groups: TradingGroupBackend[];
|
|
160
|
+
fees: FeeBackend[];
|
|
161
|
+
pairInfos: PairInfosBackend;
|
|
162
|
+
collaterals: CollateralBackend[];
|
|
163
|
+
sssTokenBalance: string;
|
|
164
|
+
sssLegacyTokenBalance: string;
|
|
165
|
+
sssRewardTokens: string[];
|
|
166
|
+
vaultClosingFeeP: string;
|
|
167
|
+
maxNegativePnlOnOpenP: number;
|
|
168
|
+
blockConfirmations: number;
|
|
169
|
+
oiWindowsSettings: OiWindowsSettingsBackend;
|
|
170
|
+
oiWindows: OiWindowsBackend[];
|
|
171
|
+
feeTiers: FeeTiersBackend;
|
|
172
|
+
allTrades: TradeContainerBackend[];
|
|
173
|
+
currentBlock: number;
|
|
174
|
+
currentL1Block: number;
|
|
175
|
+
isForexOpen: boolean;
|
|
176
|
+
isStocksOpen: boolean;
|
|
177
|
+
isIndicesOpen: boolean;
|
|
178
|
+
isCommoditiesOpen: boolean;
|
|
179
|
+
liquidationParams: {
|
|
180
|
+
groups: LiquidationParamsBackend[];
|
|
181
|
+
pairs: LiquidationParamsBackend[];
|
|
182
|
+
};
|
|
183
|
+
counterTradeSettings: CounterTradeSettingsBackend[];
|
|
184
|
+
globalTradeFeeParams: GlobalTradeFeeParamsBackend;
|
|
185
|
+
negPnlCumulVolMultiplier: string;
|
|
186
|
+
congestionLevels: {
|
|
187
|
+
low: number;
|
|
188
|
+
high: number;
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
export interface FundingFeesBackend {
|
|
192
|
+
pairGlobalParams: {
|
|
193
|
+
maxSkewCollateral: string;
|
|
194
|
+
}[];
|
|
195
|
+
pairParams: {
|
|
196
|
+
skewCoefficientPerYear: string;
|
|
197
|
+
absoluteVelocityPerYearCap: string;
|
|
198
|
+
absoluteRatePerSecondCap: string;
|
|
199
|
+
thetaThresholdUsd: string;
|
|
200
|
+
fundingFeesEnabled: boolean;
|
|
201
|
+
aprMultiplierEnabled: boolean;
|
|
202
|
+
}[];
|
|
203
|
+
pairData: {
|
|
204
|
+
accFundingFeeLongP: string;
|
|
205
|
+
accFundingFeeShortP: string;
|
|
206
|
+
lastFundingRatePerSecondP: string;
|
|
207
|
+
lastFundingUpdateTs: string;
|
|
208
|
+
}[];
|
|
209
|
+
}
|
|
210
|
+
export interface BorrowingFeesV2Backend {
|
|
211
|
+
pairParams: {
|
|
212
|
+
borrowingRatePerSecondP: string;
|
|
213
|
+
}[];
|
|
214
|
+
pairData: {
|
|
215
|
+
accBorrowingFeeP: string;
|
|
216
|
+
lastBorrowingUpdateTs: string;
|
|
217
|
+
}[];
|
|
218
|
+
}
|
|
219
|
+
export interface CollateralBackend {
|
|
220
|
+
collateralIndex: number;
|
|
221
|
+
collateral: string;
|
|
222
|
+
symbol: string;
|
|
223
|
+
isActive: boolean;
|
|
224
|
+
prices: TokenPrices;
|
|
225
|
+
collateralConfig: CollateralConfigBackend;
|
|
226
|
+
gToken: {
|
|
227
|
+
address: string;
|
|
228
|
+
currentBalanceCollateral: string;
|
|
229
|
+
maxBalanceCollateral: string;
|
|
230
|
+
marketCap: string;
|
|
231
|
+
};
|
|
232
|
+
borrowingFees: {
|
|
233
|
+
v1: PairParamsBorrowingFeesBackend;
|
|
234
|
+
v2: BorrowingFeesV2Backend;
|
|
235
|
+
};
|
|
236
|
+
fundingFees: FundingFeesBackend;
|
|
237
|
+
pairOis: OpenInterestBackend[];
|
|
238
|
+
pairSkewDepths?: string[];
|
|
239
|
+
}
|
|
240
|
+
export interface PairInfosBackend {
|
|
241
|
+
maxLeverages: string[];
|
|
242
|
+
pairDepths: PairDepthBackend[];
|
|
243
|
+
pairFactors: PairFactorBackend[];
|
|
244
|
+
}
|
|
245
|
+
export type TraderInfoBackend = {
|
|
246
|
+
lastDayUpdated: number;
|
|
247
|
+
trailingPoints: string;
|
|
248
|
+
};
|
|
249
|
+
export type TraderEnrollmentBackend = {
|
|
250
|
+
status: number;
|
|
251
|
+
};
|
|
252
|
+
export type TraderFeeTiersBackend = {
|
|
253
|
+
traderEnrollment: TraderEnrollmentBackend;
|
|
254
|
+
traderInfo: TraderInfoBackend;
|
|
255
|
+
lastDayUpdatedPoints: string;
|
|
256
|
+
inboundPoints: string;
|
|
257
|
+
outboundPoints: string;
|
|
258
|
+
expiredPoints: string[];
|
|
259
|
+
unclaimedPoints: string;
|
|
260
|
+
};
|
|
261
|
+
export interface UserTradingVariablesBackend {
|
|
262
|
+
pendingMarketOrdersIds: any[];
|
|
263
|
+
pendingMarketOrders: any[];
|
|
264
|
+
feeTiers: TraderFeeTiersBackend;
|
|
265
|
+
collaterals: Array<{
|
|
266
|
+
balance: string;
|
|
267
|
+
allowance: string;
|
|
268
|
+
decimals: number;
|
|
269
|
+
}>;
|
|
270
|
+
protectionCloseFactorWhitelist: boolean;
|
|
271
|
+
userPriceImpact: Array<{
|
|
272
|
+
cumulVolPriceImpactMultiplier: string;
|
|
273
|
+
fixedSpreadP: string;
|
|
274
|
+
}>;
|
|
275
|
+
}
|
|
276
|
+
export type OpenTradeInfo = {
|
|
277
|
+
tradeId: string;
|
|
278
|
+
timestamp: number;
|
|
279
|
+
};
|
|
280
|
+
export type OpenTradeInfoMap = {
|
|
281
|
+
[key: string]: OpenTradeInfo;
|
|
282
|
+
};
|
|
283
|
+
export type PairOiBackend = {
|
|
284
|
+
oiLongUsd: string;
|
|
285
|
+
oiShortUsd: string;
|
|
286
|
+
};
|
|
287
|
+
export type OiWindowsBackend = {
|
|
288
|
+
[key: string]: PairOiBackend;
|
|
289
|
+
};
|
|
290
|
+
export type OiWindowsSettingsBackend = {
|
|
291
|
+
startTs: number;
|
|
292
|
+
windowsDuration: number;
|
|
293
|
+
windowsCount: number;
|
|
294
|
+
};
|
|
295
|
+
export type CollateralConfigBackend = {
|
|
296
|
+
precision: string;
|
|
297
|
+
precisionDelta: string;
|
|
298
|
+
decimals: number;
|
|
299
|
+
};
|
|
300
|
+
export type FeeTiersBackend = {
|
|
301
|
+
tiers: Array<{
|
|
302
|
+
feeMultiplier: string;
|
|
303
|
+
pointsThreshold: string;
|
|
304
|
+
}>;
|
|
305
|
+
multipliers: string[];
|
|
306
|
+
currentDay: number;
|
|
307
|
+
};
|
|
308
|
+
export type GlobalTradeFeeParamsBackend = {
|
|
309
|
+
referralFeeP: string;
|
|
310
|
+
govFeeP: string;
|
|
311
|
+
triggerOrderFeeP: string;
|
|
312
|
+
gnsOtcFeeP: string;
|
|
313
|
+
gTokenFeeP: string;
|
|
314
|
+
};
|
|
315
|
+
export type CounterTradeSettingsBackend = {
|
|
316
|
+
maxLeverage: string;
|
|
317
|
+
feeRateMultiplier: string;
|
|
318
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ContestLeaderboardBackendEntry, ContestLeaderboardEntry } from "@gainsnetwork/contests";
|
|
2
|
+
import { BorrowingFee, CollateralConfig, Fee, FeeTiers, GlobalTradeFeeParams, OiWindows, OiWindowsSettings, OpenInterest, Pair, PairDepth, PairOi, Trade, TradeContainer, TradeInfo, TradeInitialAccFees, TraderFeeTiers, TradingGroup, PairFactor, convertLiquidationParams } from "../../";
|
|
3
|
+
import { BorrowingFeePerBlockCapBackend, CollateralBackend, FeeBackend, FeeTiersBackend, GlobalTradeFeeParamsBackend, OiWindowsBackend, OiWindowsSettingsBackend, OpenInterestBackend, PairBackend, PairDepthBackend, PairFactorBackend, PairOiBackend, PairParamsBorrowingFeesBackend, TradeBackend, TradeContainerBackend, TradeInfoBackend, TradeInitialAccFeesBackend, TraderFeeTiersBackend, TradingGroupBackend } from "./backend.types";
|
|
4
|
+
import { TradingVariablesCollateral } from "./types";
|
|
5
|
+
export declare const convertFees: (fees: FeeBackend[]) => Fee[];
|
|
6
|
+
export declare const convertCollaterals: (collaterals: CollateralBackend[]) => TradingVariablesCollateral[];
|
|
7
|
+
export declare const convertOpenInterests: (interests: OpenInterestBackend[]) => OpenInterest[];
|
|
8
|
+
export declare const convertPairDepths: (pairDepths: PairDepthBackend[]) => PairDepth[];
|
|
9
|
+
export declare const convertPairSkewDepths: (pairSkewDepths: string[] | undefined) => {
|
|
10
|
+
[pairIndex: number]: number;
|
|
11
|
+
};
|
|
12
|
+
export declare const convertPairBorrowingFees: (pairParams: PairParamsBorrowingFeesBackend) => BorrowingFee.Pair[];
|
|
13
|
+
export declare const convertGroupBorrowingFees: (pairParams: PairParamsBorrowingFeesBackend) => BorrowingFee.Group[];
|
|
14
|
+
export declare const convertTradingGroups: (groups: TradingGroupBackend[]) => TradingGroup[];
|
|
15
|
+
export declare const convertTradingPairs: (pairs: PairBackend[]) => Pair[];
|
|
16
|
+
export declare const convertTradesAndLimitOrders: (allItems: TradeContainerBackend[], collaterals: TradingVariablesCollateral[]) => TradeContainer[];
|
|
17
|
+
export declare const convertTradeContainer: (tradeContainer: TradeContainerBackend, collaterals: TradingVariablesCollateral[]) => TradeContainer;
|
|
18
|
+
export declare const convertPairFactor: (pairFactor: PairFactorBackend) => PairFactor;
|
|
19
|
+
export declare const convertTrade: (trade: TradeBackend, collaterals: TradingVariablesCollateral[]) => Trade;
|
|
20
|
+
export declare const convertTradeInfo: (tradeInfo: TradeInfoBackend) => TradeInfo;
|
|
21
|
+
export declare const convertTradeInitialAccFees: (initialAccFees: TradeInitialAccFeesBackend) => TradeInitialAccFees;
|
|
22
|
+
export declare const generateStockPairToActiveStockSplit: (pairs?: PairBackend[]) => Map<string, string>;
|
|
23
|
+
export declare const convertContestLeaderboardEntry: (entry: ContestLeaderboardBackendEntry) => ContestLeaderboardEntry;
|
|
24
|
+
export declare const convertPairOi: (collateral: PairOiBackend) => PairOi;
|
|
25
|
+
export declare const convertOiWindows: (oiWindows: OiWindowsBackend[]) => OiWindows[];
|
|
26
|
+
export declare const convertOiWindowsSettings: (oiWindowsSettings: OiWindowsSettingsBackend) => OiWindowsSettings;
|
|
27
|
+
export declare const convertCollateralConfig: (collateral: CollateralBackend) => CollateralConfig;
|
|
28
|
+
export declare const convertFeeTiers: (feeTiersBackend: FeeTiersBackend) => FeeTiers;
|
|
29
|
+
export declare const convertTraderFeeTiers: (traderFeeTiers: TraderFeeTiersBackend) => TraderFeeTiers;
|
|
30
|
+
export declare const convertGlobalTradeFeeParams: (fee: GlobalTradeFeeParamsBackend) => GlobalTradeFeeParams;
|
|
31
|
+
export declare const convertMaxLeverages: (maxLeverages: string[]) => number[];
|
|
32
|
+
export declare const convertFeePerBlockCap: (feeCap: BorrowingFeePerBlockCapBackend | undefined) => BorrowingFee.BorrowingFeePerBlockCap;
|
|
33
|
+
export declare const convertPairName: (pair?: PairBackend) => string;
|
|
34
|
+
export { convertLiquidationParams };
|