@gainsnetwork/sdk 0.0.0-v10.rc1 → 0.0.0-v10.rc3
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.d.ts +11 -0
- package/lib/backend/globalTrades/index.js +69 -0
- package/lib/backend/index.d.ts +2 -0
- package/lib/backend/index.js +18 -0
- package/lib/backend/tradingVariables/backend.types.d.ts +312 -0
- package/lib/backend/tradingVariables/backend.types.js +2 -0
- package/lib/backend/tradingVariables/converter.d.ts +30 -0
- package/lib/backend/tradingVariables/converter.js +329 -0
- package/lib/backend/tradingVariables/index.d.ts +3 -0
- package/lib/backend/tradingVariables/index.js +78 -0
- package/lib/backend/tradingVariables/types.d.ts +109 -0
- package/lib/backend/tradingVariables/types.js +14 -0
- package/lib/constants.d.ts +8 -1
- package/lib/constants.js +8 -1
- package/lib/contracts/fetch/fees/borrowingFeesV2.d.ts +75 -0
- package/lib/contracts/fetch/fees/borrowingFeesV2.js +193 -0
- package/lib/contracts/fetch/fees/fundingFees.d.ts +66 -0
- package/lib/contracts/fetch/fees/fundingFees.js +150 -0
- package/lib/contracts/fetch/priceImpact/skew.d.ts +63 -0
- package/lib/contracts/fetch/priceImpact/skew.js +168 -0
- 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/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/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/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 +7 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -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/index.d.ts +2 -0
- package/lib/markets/index.js +2 -0
- package/lib/markets/oi/converter.d.ts +63 -0
- package/lib/markets/oi/converter.js +103 -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 +10 -0
- package/lib/markets/oi/index.js +37 -0
- package/lib/markets/oi/types.d.ts +82 -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/trade/fees/borrowing/index.d.ts +22 -1
- package/lib/trade/fees/borrowing/index.js +39 -13
- package/lib/trade/fees/borrowingV2/converter.d.ts +66 -0
- package/lib/trade/fees/borrowingV2/converter.js +121 -0
- package/lib/trade/fees/borrowingV2/fetcher.d.ts +75 -0
- package/lib/trade/fees/borrowingV2/fetcher.js +193 -0
- package/lib/trade/fees/borrowingV2/index.d.ts +60 -0
- package/lib/trade/fees/borrowingV2/index.js +140 -0
- package/lib/trade/fees/borrowingV2/types.d.ts +79 -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 +110 -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 +136 -0
- package/lib/trade/fees/fundingFees/index.js +326 -0
- package/lib/trade/fees/fundingFees/types.d.ts +77 -0
- package/lib/trade/fees/fundingFees/types.js +5 -0
- package/lib/trade/fees/index.d.ts +7 -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/converter.d.ts +30 -0
- package/lib/trade/fees/trading/converter.js +43 -0
- package/lib/trade/fees/trading/index.d.ts +54 -0
- package/lib/trade/fees/trading/index.js +147 -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 +3 -2
- package/lib/trade/index.js +3 -2
- package/lib/trade/liquidation/converter.d.ts +23 -0
- package/lib/trade/liquidation/converter.js +46 -0
- package/lib/trade/liquidation/index.d.ts +31 -0
- package/lib/trade/liquidation/index.js +187 -0
- package/lib/trade/liquidation/types.d.ts +44 -0
- package/lib/trade/liquidation/types.js +2 -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 +86 -0
- package/lib/trade/pnl/index.js +201 -0
- package/lib/trade/pnl/types.d.ts +86 -0
- package/lib/trade/pnl/types.js +5 -0
- package/lib/trade/priceImpact/close/index.d.ts +21 -0
- package/lib/trade/priceImpact/close/index.js +131 -0
- package/lib/trade/priceImpact/close/types.d.ts +43 -0
- package/lib/trade/priceImpact/close/types.js +5 -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 +107 -0
- package/lib/trade/priceImpact/cumulVol/index.js +228 -0
- package/lib/trade/priceImpact/index.d.ts +12 -0
- package/lib/trade/priceImpact/index.js +59 -0
- package/lib/trade/priceImpact/open/index.d.ts +22 -0
- package/lib/trade/priceImpact/open/index.js +76 -0
- package/lib/trade/priceImpact/open/types.d.ts +41 -0
- package/lib/trade/priceImpact/open/types.js +5 -0
- package/lib/trade/priceImpact/skew/converter.d.ts +77 -0
- package/lib/trade/priceImpact/skew/converter.js +171 -0
- package/lib/trade/priceImpact/skew/fetcher.d.ts +63 -0
- package/lib/trade/priceImpact/skew/fetcher.js +168 -0
- package/lib/trade/priceImpact/skew/index.d.ts +58 -0
- package/lib/trade/priceImpact/skew/index.js +179 -0
- package/lib/trade/priceImpact/skew/types.d.ts +55 -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 +34 -9
- package/lib/trade/types.js +7 -0
- package/lib/trade/utils.d.ts +18 -0
- package/lib/trade/utils.js +30 -0
- package/package.json +2 -1
|
@@ -20,7 +20,8 @@ export declare enum CollateralTypes {
|
|
|
20
20
|
}
|
|
21
21
|
export declare enum ContractsVersion {
|
|
22
22
|
BEFORE_V9_2 = 0,
|
|
23
|
-
V9_2 = 1
|
|
23
|
+
V9_2 = 1,
|
|
24
|
+
V10 = 2
|
|
24
25
|
}
|
|
25
26
|
export type ContractAddressList = Record<string, Partial<Record<CollateralTypes | "global", Partial<ContractAddresses>>>>;
|
|
26
27
|
export declare enum ChainId {
|
|
@@ -14,6 +14,7 @@ var ContractsVersion;
|
|
|
14
14
|
(function (ContractsVersion) {
|
|
15
15
|
ContractsVersion[ContractsVersion["BEFORE_V9_2"] = 0] = "BEFORE_V9_2";
|
|
16
16
|
ContractsVersion[ContractsVersion["V9_2"] = 1] = "V9_2";
|
|
17
|
+
ContractsVersion[ContractsVersion["V10"] = 2] = "V10";
|
|
17
18
|
})(ContractsVersion = exports.ContractsVersion || (exports.ContractsVersion = {}));
|
|
18
19
|
var ChainId;
|
|
19
20
|
(function (ChainId) {
|
|
@@ -5,6 +5,7 @@ export type FetchOpenPairTradesOverrides = {
|
|
|
5
5
|
useMulticall?: boolean;
|
|
6
6
|
includeLimits?: boolean;
|
|
7
7
|
blockTag?: BlockTag;
|
|
8
|
+
includeUIRealizedPnlData?: boolean;
|
|
8
9
|
};
|
|
9
10
|
export declare const fetchOpenPairTrades: (contracts: Contracts, overrides?: FetchOpenPairTradesOverrides) => Promise<TradeContainer[]>;
|
|
10
11
|
export declare const fetchOpenPairTradesRaw: (contracts: Contracts, overrides?: FetchOpenPairTradesOverrides) => Promise<TradeContainerRaw[]>;
|
|
@@ -11,10 +11,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.fetchOpenPairTradesRaw = exports.fetchOpenPairTrades = void 0;
|
|
13
13
|
const ethcall_1 = require("ethcall");
|
|
14
|
+
const trade_1 = require("../../trade");
|
|
14
15
|
const fetchOpenPairTrades = (contracts, overrides = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
16
|
const rawTrades = yield (0, exports.fetchOpenPairTradesRaw)(contracts, overrides);
|
|
16
|
-
const
|
|
17
|
-
|
|
17
|
+
const collaterals = yield contracts.gnsMultiCollatDiamond.getCollaterals();
|
|
18
|
+
const collateralConfigs = collaterals.map(c => ({
|
|
19
|
+
collateral: c.collateral,
|
|
20
|
+
isActive: c.isActive,
|
|
21
|
+
precision: parseFloat(c.precision.toString()),
|
|
22
|
+
precisionDelta: parseFloat(c.precisionDelta.toString()),
|
|
23
|
+
}));
|
|
24
|
+
return rawTrades.map(rawTrade => _prepareTradeContainer(rawTrade.trade, rawTrade.tradeInfo, rawTrade.liquidationParams, rawTrade.initialAccFees, rawTrade.tradeFeesData, rawTrade.uiRealizedPnlData, collateralConfigs[parseInt(rawTrade.trade.collateralIndex.toString()) - 1]));
|
|
18
25
|
});
|
|
19
26
|
exports.fetchOpenPairTrades = fetchOpenPairTrades;
|
|
20
27
|
// @todo rename
|
|
@@ -22,7 +29,7 @@ const fetchOpenPairTradesRaw = (contracts, overrides = {}) => __awaiter(void 0,
|
|
|
22
29
|
if (!contracts) {
|
|
23
30
|
return [];
|
|
24
31
|
}
|
|
25
|
-
const { batchSize = 50, includeLimits = true, useMulticall = false, } = overrides;
|
|
32
|
+
const { batchSize = 50, includeLimits = true, useMulticall = false, includeUIRealizedPnlData = true, } = overrides;
|
|
26
33
|
const { gnsMultiCollatDiamond: multiCollatDiamondContract } = contracts;
|
|
27
34
|
try {
|
|
28
35
|
const multicallCtx = {
|
|
@@ -38,25 +45,52 @@ const fetchOpenPairTradesRaw = (contracts, overrides = {}) => __awaiter(void 0,
|
|
|
38
45
|
let running = true;
|
|
39
46
|
let offset = 0;
|
|
40
47
|
while (running) {
|
|
41
|
-
const trades = yield
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
const [trades, tradeInfos, tradeLiquidationParams] = yield Promise.all([
|
|
49
|
+
multiCollatDiamondContract.getAllTrades(offset, offset + batchSize),
|
|
50
|
+
multiCollatDiamondContract.getAllTradeInfos(offset, offset + batchSize),
|
|
51
|
+
multiCollatDiamondContract.getAllTradesLiquidationParams(offset, offset + batchSize),
|
|
52
|
+
]);
|
|
53
|
+
const fundingFeesCallParams = [
|
|
54
|
+
[],
|
|
55
|
+
[], // indices
|
|
56
|
+
];
|
|
44
57
|
// Array is always of length `batchSize`
|
|
45
58
|
// so we need to filter out the empty trades, indexes are reliable
|
|
46
59
|
const openTrades = trades
|
|
47
60
|
.filter(t => t.collateralIndex > 0 &&
|
|
48
61
|
(includeLimits || (!includeLimits && t.tradeType === 0)))
|
|
49
|
-
.map((trade, ix) =>
|
|
50
|
-
trade
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
.map((trade, ix) => {
|
|
63
|
+
fundingFeesCallParams[0].push(trade.user);
|
|
64
|
+
fundingFeesCallParams[1].push(trade.index);
|
|
65
|
+
return {
|
|
66
|
+
trade,
|
|
67
|
+
tradeInfo: tradeInfos[ix],
|
|
68
|
+
liquidationParams: tradeLiquidationParams[ix],
|
|
69
|
+
initialAccFees: {
|
|
70
|
+
accPairFee: 0,
|
|
71
|
+
accGroupFee: 0,
|
|
72
|
+
block: 0,
|
|
73
|
+
__placeholder: 0,
|
|
74
|
+
},
|
|
75
|
+
tradeFeesData: {
|
|
76
|
+
realizedTradingFeesCollateral: 0,
|
|
77
|
+
realizedPnlCollateral: 0,
|
|
78
|
+
manuallyRealizedNegativePnlCollateral: 0,
|
|
79
|
+
alreadyTransferredNegativePnlCollateral: 0,
|
|
80
|
+
virtualAvailableCollateralInDiamond: 0,
|
|
81
|
+
initialAccFundingFeeP: 0,
|
|
82
|
+
initialAccBorrowingFeeP: 0,
|
|
83
|
+
__placeholder: 0,
|
|
84
|
+
},
|
|
85
|
+
uiRealizedPnlData: undefined,
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
const [tradeFeesData, uiRealizedPnlData] = yield Promise.all([
|
|
89
|
+
multiCollatDiamondContract.getTradeFeesDataArray(...fundingFeesCallParams),
|
|
90
|
+
includeUIRealizedPnlData
|
|
91
|
+
? multiCollatDiamondContract.getTradeUiRealizedPnlDataArray(...fundingFeesCallParams)
|
|
92
|
+
: [],
|
|
93
|
+
]);
|
|
60
94
|
const initialAccFeesPromises = openTrades
|
|
61
95
|
.map(({ trade }) => ({
|
|
62
96
|
collateralIndex: trade.collateralIndex,
|
|
@@ -71,6 +105,8 @@ const fetchOpenPairTradesRaw = (contracts, overrides = {}) => __awaiter(void 0,
|
|
|
71
105
|
: Promise.all(initialAccFeesPromises));
|
|
72
106
|
initialAccFees.forEach((accFees, ix) => {
|
|
73
107
|
openTrades[ix].initialAccFees = accFees;
|
|
108
|
+
openTrades[ix].tradeFeesData = tradeFeesData[ix];
|
|
109
|
+
openTrades[ix].uiRealizedPnlData = uiRealizedPnlData === null || uiRealizedPnlData === void 0 ? void 0 : uiRealizedPnlData[ix];
|
|
74
110
|
});
|
|
75
111
|
allOpenPairTrades = allOpenPairTrades.concat(openTrades);
|
|
76
112
|
offset += batchSize + 1;
|
|
@@ -85,42 +121,44 @@ const fetchOpenPairTradesRaw = (contracts, overrides = {}) => __awaiter(void 0,
|
|
|
85
121
|
}
|
|
86
122
|
});
|
|
87
123
|
exports.fetchOpenPairTradesRaw = fetchOpenPairTradesRaw;
|
|
88
|
-
const _prepareTradeContainer = (trade, tradeInfo, tradeLiquidationParams, tradeInitialAccFees,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
const _prepareTradeContainer = (trade, tradeInfo, tradeLiquidationParams, tradeInitialAccFees, tradeFeesData, uiRealizedPnlData, collateralConfig) => {
|
|
125
|
+
const precision = collateralConfig.precision;
|
|
126
|
+
return {
|
|
127
|
+
trade: {
|
|
128
|
+
user: trade.user,
|
|
129
|
+
index: parseInt(trade.index.toString()),
|
|
130
|
+
pairIndex: parseInt(trade.pairIndex.toString()),
|
|
131
|
+
leverage: parseFloat(trade.leverage.toString()) / 1e3,
|
|
132
|
+
long: trade.long.toString() === "true",
|
|
133
|
+
isOpen: trade.isOpen.toString() === "true",
|
|
134
|
+
collateralIndex: parseInt(trade.collateralIndex.toString()),
|
|
135
|
+
tradeType: trade.tradeType,
|
|
136
|
+
collateralAmount: parseFloat(trade.collateralAmount.toString()) / precision,
|
|
137
|
+
openPrice: parseFloat(trade.openPrice.toString()) / 1e10,
|
|
138
|
+
tp: parseFloat(trade.tp.toString()) / 1e10,
|
|
139
|
+
sl: parseFloat(trade.sl.toString()) / 1e10,
|
|
140
|
+
isCounterTrade: trade.isCounterTrade,
|
|
141
|
+
positionSizeToken: parseFloat(trade.positionSizeToken.toString()) / 1e18,
|
|
142
|
+
},
|
|
143
|
+
tradeInfo: {
|
|
144
|
+
createdBlock: parseInt(tradeInfo.createdBlock.toString()),
|
|
145
|
+
tpLastUpdatedBlock: parseInt(tradeInfo.tpLastUpdatedBlock.toString()),
|
|
146
|
+
slLastUpdatedBlock: parseInt(tradeInfo.slLastUpdatedBlock.toString()),
|
|
147
|
+
maxSlippageP: parseFloat(tradeInfo.maxSlippageP.toString()) / 1e3,
|
|
148
|
+
lastOiUpdateTs: parseFloat(tradeInfo.lastOiUpdateTs),
|
|
149
|
+
collateralPriceUsd: parseFloat(tradeInfo.collateralPriceUsd.toString()) / 1e8,
|
|
150
|
+
contractsVersion: parseInt(tradeInfo.contractsVersion.toString()),
|
|
151
|
+
lastPosIncreaseBlock: parseInt(tradeInfo.lastPosIncreaseBlock.toString()),
|
|
152
|
+
},
|
|
153
|
+
liquidationParams: (0, trade_1.convertLiquidationParams)(tradeLiquidationParams),
|
|
154
|
+
initialAccFees: {
|
|
155
|
+
accPairFee: parseFloat(tradeInitialAccFees.accPairFee.toString()) / 1e10,
|
|
156
|
+
accGroupFee: parseFloat(tradeInitialAccFees.accGroupFee.toString()) / 1e10,
|
|
157
|
+
block: parseFloat(tradeInitialAccFees.block.toString()),
|
|
158
|
+
},
|
|
159
|
+
tradeFeesData: (0, trade_1.convertTradeFeesData)(tradeFeesData, collateralConfig),
|
|
160
|
+
uiRealizedPnlData: uiRealizedPnlData
|
|
161
|
+
? (0, trade_1.convertUiRealizedPnlData)(uiRealizedPnlData, collateralConfig)
|
|
162
|
+
: undefined,
|
|
163
|
+
};
|
|
164
|
+
};
|
|
@@ -475,4 +475,11 @@ const PAIR_INDEX_TO_DESCRIPTION = {
|
|
|
475
475
|
[types_1.PairIndex.WCTUSD]: "WalletConnect Token to US Dollar",
|
|
476
476
|
[types_1.PairIndex.BIGTIMEUSD]: "Big Time to US Dollar",
|
|
477
477
|
[types_1.PairIndex.BABYUSD]: "Babylon to US Dollar",
|
|
478
|
+
[types_1.PairIndex.COOKIEUSD]: "Cookie DAO to US Dollar",
|
|
479
|
+
[types_1.PairIndex.KMNOUSD]: "Kamino to US Dollar",
|
|
480
|
+
[types_1.PairIndex.INITUSD]: "Initia to US Dollar",
|
|
481
|
+
[types_1.PairIndex.SYRUPUSD]: "Maple Finance to US Dollar",
|
|
482
|
+
[types_1.PairIndex.SIGNUSD]: "Sign to US Dollar",
|
|
483
|
+
[types_1.PairIndex.ZORAUSD]: "ZORA to US Dollar",
|
|
484
|
+
[types_1.PairIndex.COINUSD]: "Coinbase to US Dollar",
|
|
478
485
|
};
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -20,5 +20,6 @@ __exportStar(require("./markets"), exports);
|
|
|
20
20
|
__exportStar(require("./constants"), exports);
|
|
21
21
|
__exportStar(require("./utils"), exports);
|
|
22
22
|
__exportStar(require("./vault"), exports);
|
|
23
|
+
__exportStar(require("./backend"), exports);
|
|
23
24
|
// Not sure why this is needed, but it is. Barrel imports are not working.
|
|
24
25
|
__exportStar(require("./trade/fees/borrowing/index"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ITradingStorage } from "src/contracts/types/generated/GNSMultiCollatDiamond";
|
|
2
|
+
import { CollateralConfig } from "./types";
|
|
3
|
+
export declare const convertCollateralConfig: (collateral: ITradingStorage.CollateralStructOutput & {
|
|
4
|
+
decimals: number;
|
|
5
|
+
}) => CollateralConfig;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertCollateralConfig = void 0;
|
|
4
|
+
const convertCollateralConfig = (collateral) => ({
|
|
5
|
+
collateral: collateral.collateral,
|
|
6
|
+
isActive: collateral.isActive,
|
|
7
|
+
precision: Number(collateral.precision),
|
|
8
|
+
precisionDelta: Number(collateral.precisionDelta),
|
|
9
|
+
decimals: collateral.decimals,
|
|
10
|
+
});
|
|
11
|
+
exports.convertCollateralConfig = convertCollateralConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./types";
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
__exportStar(require("./types"), exports);
|
package/lib/markets/index.d.ts
CHANGED
package/lib/markets/index.js
CHANGED
|
@@ -19,3 +19,5 @@ __exportStar(require("./forex"), exports);
|
|
|
19
19
|
__exportStar(require("./stocks"), exports);
|
|
20
20
|
__exportStar(require("./indices"), exports);
|
|
21
21
|
__exportStar(require("./commodities"), exports);
|
|
22
|
+
__exportStar(require("./oi"), exports);
|
|
23
|
+
__exportStar(require("./collateral"), exports);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dev Converters for OI data between contract and SDK formats
|
|
3
|
+
* @dev Handles the three OI storage systems and precision conversions
|
|
4
|
+
*/
|
|
5
|
+
import { IBorrowingFees, IPriceImpact } from "../../contracts/types/generated/GNSMultiCollatDiamond";
|
|
6
|
+
import { UnifiedPairOi, ComputedOi } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* @dev Converts pre-v10 OI from contract format
|
|
9
|
+
* @param contractOi Contract OpenInterest struct from BorrowingFeesStorage
|
|
10
|
+
* @param precision Collateral precision for conversion
|
|
11
|
+
* @returns Normalized OI with long/short values
|
|
12
|
+
*/
|
|
13
|
+
export declare const convertBeforeV10Collateral: (contractOi: IBorrowingFees.OpenInterestStructOutput, precision: number) => {
|
|
14
|
+
long: number;
|
|
15
|
+
short: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @dev Converts post-v10 collateral OI from contract format
|
|
19
|
+
* @param contractOi Contract PairOiCollateral struct
|
|
20
|
+
* @param precision Collateral precision for conversion
|
|
21
|
+
* @returns Normalized OI with long/short values
|
|
22
|
+
*/
|
|
23
|
+
export declare const convertCollateralOi: (contractOi: IPriceImpact.PairOiCollateralStructOutput, precision: number) => {
|
|
24
|
+
long: number;
|
|
25
|
+
short: number;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* @dev Converts post-v10 token OI from contract format
|
|
29
|
+
* @param contractOi Contract PairOiToken struct
|
|
30
|
+
* @returns Normalized OI with long/short values (1e18 precision)
|
|
31
|
+
*/
|
|
32
|
+
export declare const convertTokenOi: (contractOi: IPriceImpact.PairOiTokenStructOutput) => {
|
|
33
|
+
long: number;
|
|
34
|
+
short: number;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* @dev Converts all OI data for a pair into unified structure
|
|
38
|
+
* @param beforeV10 Pre-v10 OI from BorrowingFeesStorage
|
|
39
|
+
* @param afterV10Collateral Post-v10 collateral OI from PriceImpactStorage
|
|
40
|
+
* @param afterV10Token Post-v10 token OI from PriceImpactStorage
|
|
41
|
+
* @param maxOi Maximum OI allowed (from BorrowingFeesStorage)
|
|
42
|
+
* @param collateralPrecision Precision for collateral conversions
|
|
43
|
+
* @returns Unified PairOi structure
|
|
44
|
+
*/
|
|
45
|
+
export declare const convertPairOi: (beforeV10: IBorrowingFees.OpenInterestStructOutput, afterV10Collateral: IPriceImpact.PairOiCollateralStructOutput, afterV10Token: IPriceImpact.PairOiTokenStructOutput, collateralPrecision: number) => UnifiedPairOi;
|
|
46
|
+
/**
|
|
47
|
+
* @dev Batch converter for multiple pairs
|
|
48
|
+
* @param pairs Array of OI data for multiple pairs
|
|
49
|
+
* @param collateralPrecision Precision for collateral conversions
|
|
50
|
+
* @returns Array of unified PairOi structures
|
|
51
|
+
*/
|
|
52
|
+
export declare const convertPairOiArray: (pairs: Array<{
|
|
53
|
+
beforeV10: IBorrowingFees.OpenInterestStructOutput;
|
|
54
|
+
collateral: IPriceImpact.PairOiCollateralStructOutput;
|
|
55
|
+
token: IPriceImpact.PairOiTokenStructOutput;
|
|
56
|
+
}>, collateralPrecision: number) => UnifiedPairOi[];
|
|
57
|
+
/**
|
|
58
|
+
* @dev Computes derived OI values from unified structure
|
|
59
|
+
* @param pairOi Unified pair OI data
|
|
60
|
+
* @param tokenPriceCollateral Current token price in collateral units
|
|
61
|
+
* @returns Computed values including total OI and skew
|
|
62
|
+
*/
|
|
63
|
+
export declare const computeOiValues: (pairOi: UnifiedPairOi, tokenPriceCollateral: number) => ComputedOi;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @dev Converters for OI data between contract and SDK formats
|
|
4
|
+
* @dev Handles the three OI storage systems and precision conversions
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.computeOiValues = exports.convertPairOiArray = exports.convertPairOi = exports.convertTokenOi = exports.convertCollateralOi = exports.convertBeforeV10Collateral = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* @dev Converts pre-v10 OI from contract format
|
|
10
|
+
* @param contractOi Contract OpenInterest struct from BorrowingFeesStorage
|
|
11
|
+
* @param precision Collateral precision for conversion
|
|
12
|
+
* @returns Normalized OI with long/short values
|
|
13
|
+
*/
|
|
14
|
+
const convertBeforeV10Collateral = (contractOi, precision) => {
|
|
15
|
+
return {
|
|
16
|
+
long: Number(contractOi.long) / precision,
|
|
17
|
+
short: Number(contractOi.short) / precision,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
exports.convertBeforeV10Collateral = convertBeforeV10Collateral;
|
|
21
|
+
/**
|
|
22
|
+
* @dev Converts post-v10 collateral OI from contract format
|
|
23
|
+
* @param contractOi Contract PairOiCollateral struct
|
|
24
|
+
* @param precision Collateral precision for conversion
|
|
25
|
+
* @returns Normalized OI with long/short values
|
|
26
|
+
*/
|
|
27
|
+
const convertCollateralOi = (contractOi, precision) => {
|
|
28
|
+
return {
|
|
29
|
+
long: Number(contractOi.oiLongCollateral) / precision,
|
|
30
|
+
short: Number(contractOi.oiShortCollateral) / precision,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
exports.convertCollateralOi = convertCollateralOi;
|
|
34
|
+
/**
|
|
35
|
+
* @dev Converts post-v10 token OI from contract format
|
|
36
|
+
* @param contractOi Contract PairOiToken struct
|
|
37
|
+
* @returns Normalized OI with long/short values (1e18 precision)
|
|
38
|
+
*/
|
|
39
|
+
const convertTokenOi = (contractOi) => {
|
|
40
|
+
return {
|
|
41
|
+
long: Number(contractOi.oiLongToken) / 1e18,
|
|
42
|
+
short: Number(contractOi.oiShortToken) / 1e18,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
exports.convertTokenOi = convertTokenOi;
|
|
46
|
+
/**
|
|
47
|
+
* @dev Converts all OI data for a pair into unified structure
|
|
48
|
+
* @param beforeV10 Pre-v10 OI from BorrowingFeesStorage
|
|
49
|
+
* @param afterV10Collateral Post-v10 collateral OI from PriceImpactStorage
|
|
50
|
+
* @param afterV10Token Post-v10 token OI from PriceImpactStorage
|
|
51
|
+
* @param maxOi Maximum OI allowed (from BorrowingFeesStorage)
|
|
52
|
+
* @param collateralPrecision Precision for collateral conversions
|
|
53
|
+
* @returns Unified PairOi structure
|
|
54
|
+
*/
|
|
55
|
+
const convertPairOi = (beforeV10, afterV10Collateral, afterV10Token, collateralPrecision) => {
|
|
56
|
+
return {
|
|
57
|
+
maxCollateral: Number(beforeV10.max) / collateralPrecision,
|
|
58
|
+
beforeV10Collateral: (0, exports.convertBeforeV10Collateral)(beforeV10, collateralPrecision),
|
|
59
|
+
collateral: (0, exports.convertCollateralOi)(afterV10Collateral, collateralPrecision),
|
|
60
|
+
token: (0, exports.convertTokenOi)(afterV10Token),
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
exports.convertPairOi = convertPairOi;
|
|
64
|
+
/**
|
|
65
|
+
* @dev Batch converter for multiple pairs
|
|
66
|
+
* @param pairs Array of OI data for multiple pairs
|
|
67
|
+
* @param collateralPrecision Precision for collateral conversions
|
|
68
|
+
* @returns Array of unified PairOi structures
|
|
69
|
+
*/
|
|
70
|
+
const convertPairOiArray = (pairs, collateralPrecision) => {
|
|
71
|
+
return pairs.map(p => (0, exports.convertPairOi)(p.beforeV10, p.collateral, p.token, collateralPrecision));
|
|
72
|
+
};
|
|
73
|
+
exports.convertPairOiArray = convertPairOiArray;
|
|
74
|
+
/**
|
|
75
|
+
* @dev Computes derived OI values from unified structure
|
|
76
|
+
* @param pairOi Unified pair OI data
|
|
77
|
+
* @param tokenPriceCollateral Current token price in collateral units
|
|
78
|
+
* @returns Computed values including total OI and skew
|
|
79
|
+
*/
|
|
80
|
+
const computeOiValues = (pairOi, tokenPriceCollateral) => {
|
|
81
|
+
// Static total (used for admin operations)
|
|
82
|
+
const totalStaticLong = pairOi.beforeV10Collateral.long + pairOi.collateral.long;
|
|
83
|
+
const totalStaticShort = pairOi.beforeV10Collateral.short + pairOi.collateral.short;
|
|
84
|
+
// Dynamic total (used for real-time calculations)
|
|
85
|
+
const tokenLongCollateral = pairOi.token.long * tokenPriceCollateral;
|
|
86
|
+
const tokenShortCollateral = pairOi.token.short * tokenPriceCollateral;
|
|
87
|
+
const totalDynamicLong = pairOi.beforeV10Collateral.long + tokenLongCollateral;
|
|
88
|
+
const totalDynamicShort = pairOi.beforeV10Collateral.short + tokenShortCollateral;
|
|
89
|
+
// Skew (v10+ only, in tokens)
|
|
90
|
+
const skewToken = pairOi.token.long - pairOi.token.short;
|
|
91
|
+
return {
|
|
92
|
+
totalStaticCollateral: {
|
|
93
|
+
long: totalStaticLong,
|
|
94
|
+
short: totalStaticShort,
|
|
95
|
+
},
|
|
96
|
+
totalDynamicCollateral: {
|
|
97
|
+
long: totalDynamicLong,
|
|
98
|
+
short: totalDynamicShort,
|
|
99
|
+
},
|
|
100
|
+
skewToken,
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
exports.computeOiValues = computeOiValues;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dev Fetchers for retrieving OI data from contracts
|
|
3
|
+
* @dev Consolidates the three OI storage systems into unified format
|
|
4
|
+
*/
|
|
5
|
+
import { ethers } from "ethers";
|
|
6
|
+
import { ChainId } from "../../contracts/types";
|
|
7
|
+
import { UnifiedPairOi } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* @dev Fetches all OI data for a single pair
|
|
10
|
+
* @param chainId Target chain
|
|
11
|
+
* @param collateralIndex Collateral type
|
|
12
|
+
* @param pairIndex Trading pair
|
|
13
|
+
* @param signer Ethers signer
|
|
14
|
+
* @returns Unified PairOi structure with all OI data
|
|
15
|
+
*/
|
|
16
|
+
export declare function fetchPairOi(chainId: ChainId, collateralIndex: number, pairIndex: number, signer: ethers.Signer): Promise<UnifiedPairOi>;
|
|
17
|
+
/**
|
|
18
|
+
* @dev Fetches OI data for multiple pairs efficiently
|
|
19
|
+
* @param chainId Target chain
|
|
20
|
+
* @param collateralIndex Collateral type
|
|
21
|
+
* @param pairIndices Array of trading pairs
|
|
22
|
+
* @param signer Ethers signer
|
|
23
|
+
* @returns Array of unified PairOi structures
|
|
24
|
+
*/
|
|
25
|
+
export declare function fetchMultiplePairOi(chainId: ChainId, collateralIndex: number, pairIndices: number[], signer: ethers.Signer): Promise<UnifiedPairOi[]>;
|
|
26
|
+
/**
|
|
27
|
+
* @dev Creates OI context for fee calculations
|
|
28
|
+
* @param chainId Target chain
|
|
29
|
+
* @param collateralIndex Collateral type
|
|
30
|
+
* @param pairIndex Trading pair
|
|
31
|
+
* @param signer Ethers signer
|
|
32
|
+
* @returns OI data formatted for SDK calculations
|
|
33
|
+
*/
|
|
34
|
+
export declare function createOiContext(chainId: ChainId, collateralIndex: number, pairIndex: number, signer: ethers.Signer): Promise<{
|
|
35
|
+
pairOi: UnifiedPairOi;
|
|
36
|
+
currentPrice: number;
|
|
37
|
+
computed: {
|
|
38
|
+
totalDynamicOi: {
|
|
39
|
+
long: number;
|
|
40
|
+
short: number;
|
|
41
|
+
};
|
|
42
|
+
totalStaticOi: {
|
|
43
|
+
long: number;
|
|
44
|
+
short: number;
|
|
45
|
+
};
|
|
46
|
+
skew: number;
|
|
47
|
+
};
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* @dev Fetches only the OI data needed for specific use cases
|
|
51
|
+
* @param chainId Target chain
|
|
52
|
+
* @param collateralIndex Collateral type
|
|
53
|
+
* @param pairIndex Trading pair
|
|
54
|
+
* @param useCase Which OI systems to fetch
|
|
55
|
+
* @param signer Ethers signer
|
|
56
|
+
* @returns Partial OI data based on use case
|
|
57
|
+
*/
|
|
58
|
+
export declare function fetchOiForUseCase(chainId: ChainId, collateralIndex: number, pairIndex: number, useCase: "skew" | "funding" | "borrowingV1" | "limits", signer: ethers.Signer): Promise<Partial<UnifiedPairOi>>;
|