@gainsnetwork/sdk 1.3.0-rc7 → 1.4.0-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/backend/globalTrades/index.js +10 -10
- package/lib/backend/tradingVariables/backend.types.d.ts +4 -11
- package/lib/backend/tradingVariables/converter.d.ts +3 -7
- package/lib/backend/tradingVariables/converter.js +63 -71
- package/lib/backend/tradingVariables/index.js +8 -10
- package/lib/backend/tradingVariables/types.d.ts +2 -4
- package/lib/constants.js +1 -1
- package/lib/contracts/addresses.d.ts +1 -1
- package/lib/contracts/addresses.js +4 -8
- package/lib/contracts/addresses.json +0 -29
- package/lib/contracts/index.d.ts +1 -1
- package/lib/contracts/index.js +3 -3
- package/lib/contracts/types/generated/GNSMultiCollatDiamond.d.ts +299 -608
- package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.d.ts +10 -2
- package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +317 -1995
- package/lib/contracts/utils/borrowingFees.js +20 -9
- package/lib/contracts/utils/openTrades.js +20 -11
- package/lib/contracts/utils/pairs.d.ts +2 -13
- package/lib/contracts/utils/pairs.js +30 -80
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/markets/forex.js +1 -1
- package/lib/markets/leverage/builder.js +2 -2
- package/lib/markets/price/index.d.ts +0 -1
- package/lib/markets/price/index.js +0 -1
- package/lib/markets/price/types.d.ts +0 -27
- package/lib/trade/fees/borrowing/builder.js +3 -2
- package/lib/trade/fees/borrowing/converter.js +1 -5
- package/lib/trade/fees/borrowing/index.js +5 -5
- package/lib/trade/fees/borrowingV2/builder.js +4 -3
- package/lib/trade/fees/borrowingV2/converter.js +1 -1
- package/lib/trade/fees/borrowingV2/fetcher.js +32 -26
- package/lib/trade/fees/borrowingV2/index.js +3 -3
- package/lib/trade/fees/converter.js +22 -22
- package/lib/trade/fees/fundingFees/builder.js +7 -6
- package/lib/trade/fees/fundingFees/converter.js +1 -1
- package/lib/trade/fees/fundingFees/fetcher.js +25 -16
- package/lib/trade/fees/fundingFees/index.js +3 -2
- package/lib/trade/fees/tiers/index.js +2 -1
- package/lib/trade/fees/trading/index.js +3 -5
- package/lib/trade/liquidation/builder.js +2 -1
- package/lib/trade/liquidation/index.js +6 -4
- package/lib/trade/liquidation.d.ts +12 -0
- package/lib/trade/liquidation.js +55 -0
- package/lib/trade/oiWindows.js +2 -1
- package/lib/trade/pnl/builder.js +2 -1
- package/lib/trade/pnl/converter.js +1 -1
- package/lib/trade/pnl/index.js +7 -4
- package/lib/trade/pnl.d.ts +10 -0
- package/lib/trade/pnl.js +33 -0
- package/lib/trade/priceImpact/close/builder.js +2 -1
- package/lib/trade/priceImpact/close/index.js +1 -4
- package/lib/trade/priceImpact/cumulVol/builder.js +11 -21
- package/lib/trade/priceImpact/cumulVol/converter.d.ts +0 -63
- package/lib/trade/priceImpact/cumulVol/converter.js +1 -97
- package/lib/trade/priceImpact/cumulVol/index.d.ts +6 -7
- package/lib/trade/priceImpact/cumulVol/index.js +41 -149
- package/lib/trade/priceImpact/open/builder.js +2 -1
- package/lib/trade/priceImpact/open/index.js +1 -7
- package/lib/trade/priceImpact/skew/builder.js +3 -2
- package/lib/trade/priceImpact/skew/converter.js +1 -1
- package/lib/trade/priceImpact/skew/fetcher.js +33 -24
- package/package.json +2 -2
- package/lib/contracts/types/generated/GFarmTradingStorageV5.d.ts +0 -1911
- package/lib/contracts/types/generated/GFarmTradingStorageV5.js +0 -2
- package/lib/contracts/types/generated/GNSBorrowingFees.d.ts +0 -1067
- package/lib/contracts/types/generated/GNSBorrowingFees.js +0 -2
- package/lib/contracts/types/generated/GNSBorrowingFeesV6_3_2.d.ts +0 -979
- package/lib/contracts/types/generated/GNSBorrowingFeesV6_3_2.js +0 -2
- package/lib/contracts/types/generated/GNSBorrowingFeesV6_4.d.ts +0 -1058
- package/lib/contracts/types/generated/GNSBorrowingFeesV6_4.js +0 -2
- package/lib/contracts/types/generated/GNSNftRewardsV6.d.ts +0 -533
- package/lib/contracts/types/generated/GNSNftRewardsV6.js +0 -2
- package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.d.ts +0 -613
- package/lib/contracts/types/generated/GNSNftRewardsV6_3_1.js +0 -2
- package/lib/contracts/types/generated/GNSPairInfosV6_1.d.ts +0 -911
- package/lib/contracts/types/generated/GNSPairInfosV6_1.js +0 -2
- package/lib/contracts/types/generated/GNSPairsStorageV6.d.ts +0 -660
- package/lib/contracts/types/generated/GNSPairsStorageV6.js +0 -2
- package/lib/contracts/types/generated/GNSTrading.d.ts +0 -758
- package/lib/contracts/types/generated/GNSTrading.js +0 -2
- package/lib/contracts/types/generated/GNSTradingCallbacks.d.ts +0 -875
- package/lib/contracts/types/generated/GNSTradingCallbacks.js +0 -2
- package/lib/contracts/types/generated/GNSTradingCallbacksV6_3_2.d.ts +0 -806
- package/lib/contracts/types/generated/GNSTradingCallbacksV6_3_2.js +0 -2
- package/lib/contracts/types/generated/GNSTradingCallbacksV6_4.d.ts +0 -821
- package/lib/contracts/types/generated/GNSTradingCallbacksV6_4.js +0 -2
- package/lib/contracts/types/generated/GNSTradingStorage.d.ts +0 -1387
- package/lib/contracts/types/generated/GNSTradingStorage.js +0 -2
- package/lib/contracts/types/generated/GTokenV6_3_2.d.ts +0 -1838
- package/lib/contracts/types/generated/GTokenV6_3_2.js +0 -2
- package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.d.ts +0 -83
- package/lib/contracts/types/generated/factories/GFarmTradingStorageV5__factory.js +0 -2691
- package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_3_2__factory.d.ts +0 -88
- package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_3_2__factory.js +0 -1654
- package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_4__factory.d.ts +0 -113
- package/lib/contracts/types/generated/factories/GNSBorrowingFeesV6_4__factory.js +0 -1742
- package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.d.ts +0 -124
- package/lib/contracts/types/generated/factories/GNSBorrowingFees__factory.js +0 -1784
- package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.d.ts +0 -100
- package/lib/contracts/types/generated/factories/GNSNftRewardsV6_3_1__factory.js +0 -1116
- package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.d.ts +0 -100
- package/lib/contracts/types/generated/factories/GNSNftRewardsV6__factory.js +0 -1003
- package/lib/contracts/types/generated/factories/GNSPairInfosV6_1__factory.d.ts +0 -98
- package/lib/contracts/types/generated/factories/GNSPairInfosV6_1__factory.js +0 -1485
- package/lib/contracts/types/generated/factories/GNSPairsStorageV6__factory.d.ts +0 -117
- package/lib/contracts/types/generated/factories/GNSPairsStorageV6__factory.js +0 -1265
- package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_3_2__factory.d.ts +0 -82
- package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_3_2__factory.js +0 -1273
- package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_4__factory.d.ts +0 -82
- package/lib/contracts/types/generated/factories/GNSTradingCallbacksV6_4__factory.js +0 -1326
- package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.d.ts +0 -113
- package/lib/contracts/types/generated/factories/GNSTradingCallbacks__factory.js +0 -1428
- package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.d.ts +0 -96
- package/lib/contracts/types/generated/factories/GNSTradingStorage__factory.js +0 -2241
- package/lib/contracts/types/generated/factories/GNSTrading__factory.d.ts +0 -95
- package/lib/contracts/types/generated/factories/GNSTrading__factory.js +0 -1071
- package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.d.ts +0 -110
- package/lib/contracts/types/generated/factories/GTokenV6_3_2__factory.js +0 -2682
- package/lib/markets/oi/fetcher.d.ts +0 -58
- package/lib/markets/oi/fetcher.js +0 -181
- package/lib/markets/oi/validation.d.ts +0 -80
- package/lib/markets/oi/validation.js +0 -172
- package/lib/markets/price/signedPrices.d.ts +0 -36
- package/lib/markets/price/signedPrices.js +0 -181
- package/lib/pricing/depthBands/converter.d.ts +0 -65
- package/lib/pricing/depthBands/converter.js +0 -155
- package/lib/pricing/depthBands/decoder.d.ts +0 -32
- package/lib/pricing/depthBands/decoder.js +0 -109
- package/lib/pricing/depthBands/encoder.d.ts +0 -19
- package/lib/pricing/depthBands/encoder.js +0 -105
- package/lib/pricing/depthBands/index.d.ts +0 -8
- package/lib/pricing/depthBands/index.js +0 -26
- package/lib/pricing/depthBands/types.d.ts +0 -49
- package/lib/pricing/depthBands/types.js +0 -10
- package/lib/pricing/depthBands/validator.d.ts +0 -22
- package/lib/pricing/depthBands/validator.js +0 -113
- package/lib/pricing/depthBands.d.ts +0 -39
- package/lib/pricing/depthBands.js +0 -94
- package/lib/pricing/index.d.ts +0 -4
- package/lib/pricing/index.js +0 -20
- package/lib/trade/effectiveLeverage/builder.d.ts +0 -23
- package/lib/trade/effectiveLeverage/builder.js +0 -30
- package/lib/trade/fees/holdingFees/index.d.ts +0 -46
- package/lib/trade/fees/holdingFees/index.js +0 -105
- package/lib/trade/fees/holdingFees/types.d.ts +0 -23
- package/lib/trade/fees/holdingFees/types.js +0 -5
- package/lib/trade/fees/trading/holdingFees.d.ts +0 -28
- package/lib/trade/fees/trading/holdingFees.js +0 -66
- package/lib/trade/fees/trading/holdingFeesStructured.d.ts +0 -28
- package/lib/trade/fees/trading/holdingFeesStructured.js +0 -66
- package/lib/trade/priceImpact/cumulVol/types.d.ts +0 -11
- package/lib/trade/priceImpact/cumulVol/types.js +0 -2
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.fetchAllPairAndGroupBorrowingFees = exports.fetchGroupBorrowingFees = exports.fetchAllPairBorrowingFees = exports.getBorrowingGroupName = void 0;
|
|
4
13
|
const trade_1 = require("../../trade");
|
|
@@ -22,22 +31,24 @@ const getBorrowingGroupName = (groupIndex) => {
|
|
|
22
31
|
return groupNamesByIndex[groupIndex - 1] || "Unknown";
|
|
23
32
|
};
|
|
24
33
|
exports.getBorrowingGroupName = getBorrowingGroupName;
|
|
25
|
-
const fetchAllPairBorrowingFees =
|
|
26
|
-
const [pairs, pairOi, pairGroups] =
|
|
27
|
-
const feeCaps =
|
|
34
|
+
const fetchAllPairBorrowingFees = (contract, collateralIndex) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
const [pairs, pairOi, pairGroups] = yield contract.getAllBorrowingPairs(collateralIndex);
|
|
36
|
+
const feeCaps = yield contract.getBorrowingPairFeePerBlockCaps(collateralIndex, [...Array(pairs.length).keys()]);
|
|
28
37
|
return (0, trade_1.convertPairBorrowingFees)([pairs, pairOi, pairGroups, feeCaps]);
|
|
29
|
-
};
|
|
38
|
+
});
|
|
30
39
|
exports.fetchAllPairBorrowingFees = fetchAllPairBorrowingFees;
|
|
31
|
-
const fetchGroupBorrowingFees =
|
|
40
|
+
const fetchGroupBorrowingFees = (contract, collateralIndex, groupIxs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
return (0, trade_1.convertGroupBorrowingFees)(yield contract.getBorrowingGroups(collateralIndex, groupIxs));
|
|
42
|
+
});
|
|
32
43
|
exports.fetchGroupBorrowingFees = fetchGroupBorrowingFees;
|
|
33
|
-
const fetchAllPairAndGroupBorrowingFees =
|
|
34
|
-
const pairs =
|
|
44
|
+
const fetchAllPairAndGroupBorrowingFees = (contract, collateralIndex) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
const pairs = yield (0, exports.fetchAllPairBorrowingFees)(contract, collateralIndex);
|
|
35
46
|
const groupIxs = [
|
|
36
47
|
...new Set(pairs
|
|
37
48
|
.map(value => value.groups.map(value => value.groupIndex))
|
|
38
49
|
.reduce((acc, value) => acc.concat(value), [])),
|
|
39
50
|
].sort((a, b) => a - b);
|
|
40
|
-
const groups =
|
|
51
|
+
const groups = yield (0, exports.fetchGroupBorrowingFees)(contract, collateralIndex, groupIxs);
|
|
41
52
|
return { pairs, groups };
|
|
42
|
-
};
|
|
53
|
+
});
|
|
43
54
|
exports.fetchAllPairAndGroupBorrowingFees = fetchAllPairAndGroupBorrowingFees;
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.fetchOpenPairTradesRaw = exports.fetchOpenPairTrades = void 0;
|
|
4
13
|
const ethcall_1 = require("ethcall");
|
|
5
14
|
const trade_1 = require("../../trade");
|
|
6
|
-
const fetchOpenPairTrades =
|
|
7
|
-
const rawTrades =
|
|
8
|
-
const collaterals =
|
|
15
|
+
const fetchOpenPairTrades = (contracts, overrides = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const rawTrades = yield (0, exports.fetchOpenPairTradesRaw)(contracts, overrides);
|
|
17
|
+
const collaterals = yield contracts.gnsMultiCollatDiamond.getCollaterals();
|
|
9
18
|
const collateralConfigs = collaterals.map(c => ({
|
|
10
19
|
collateral: c.collateral,
|
|
11
20
|
isActive: c.isActive,
|
|
@@ -13,10 +22,10 @@ const fetchOpenPairTrades = async (contracts, overrides = {}) => {
|
|
|
13
22
|
precisionDelta: parseFloat(c.precisionDelta.toString()),
|
|
14
23
|
}));
|
|
15
24
|
return rawTrades.map(rawTrade => _prepareTradeContainer(rawTrade.trade, rawTrade.tradeInfo, rawTrade.liquidationParams, rawTrade.initialAccFees, rawTrade.tradeFeesData, rawTrade.uiRealizedPnlData, collateralConfigs[parseInt(rawTrade.trade.collateralIndex.toString()) - 1]));
|
|
16
|
-
};
|
|
25
|
+
});
|
|
17
26
|
exports.fetchOpenPairTrades = fetchOpenPairTrades;
|
|
18
27
|
// @todo rename
|
|
19
|
-
const fetchOpenPairTradesRaw =
|
|
28
|
+
const fetchOpenPairTradesRaw = (contracts, overrides = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
29
|
if (!contracts) {
|
|
21
30
|
return [];
|
|
22
31
|
}
|
|
@@ -30,13 +39,13 @@ const fetchOpenPairTradesRaw = async (contracts, overrides = {}) => {
|
|
|
30
39
|
]),
|
|
31
40
|
};
|
|
32
41
|
if (useMulticall) {
|
|
33
|
-
|
|
42
|
+
yield multicallCtx.provider.init(multiCollatDiamondContract.provider);
|
|
34
43
|
}
|
|
35
44
|
let allOpenPairTrades = [];
|
|
36
45
|
let running = true;
|
|
37
46
|
let offset = 0;
|
|
38
47
|
while (running) {
|
|
39
|
-
const [trades, tradeInfos, tradeLiquidationParams] =
|
|
48
|
+
const [trades, tradeInfos, tradeLiquidationParams] = yield Promise.all([
|
|
40
49
|
multiCollatDiamondContract.getAllTrades(offset, offset + batchSize),
|
|
41
50
|
multiCollatDiamondContract.getAllTradeInfos(offset, offset + batchSize),
|
|
42
51
|
multiCollatDiamondContract.getAllTradesLiquidationParams(offset, offset + batchSize),
|
|
@@ -76,7 +85,7 @@ const fetchOpenPairTradesRaw = async (contracts, overrides = {}) => {
|
|
|
76
85
|
uiRealizedPnlData: undefined,
|
|
77
86
|
};
|
|
78
87
|
});
|
|
79
|
-
const [tradeFeesData, uiRealizedPnlData] =
|
|
88
|
+
const [tradeFeesData, uiRealizedPnlData] = yield Promise.all([
|
|
80
89
|
multiCollatDiamondContract.getTradeFeesDataArray(...fundingFeesCallParams),
|
|
81
90
|
includeUIRealizedPnlData
|
|
82
91
|
? multiCollatDiamondContract.getTradeUiRealizedPnlDataArray(...fundingFeesCallParams)
|
|
@@ -91,13 +100,13 @@ const fetchOpenPairTradesRaw = async (contracts, overrides = {}) => {
|
|
|
91
100
|
.map(({ collateralIndex, user, index }) => (useMulticall
|
|
92
101
|
? multicallCtx.diamond
|
|
93
102
|
: multiCollatDiamondContract).getBorrowingInitialAccFees(collateralIndex, user, index));
|
|
94
|
-
const initialAccFees =
|
|
103
|
+
const initialAccFees = yield (useMulticall
|
|
95
104
|
? multicallCtx.provider.all(initialAccFeesPromises)
|
|
96
105
|
: Promise.all(initialAccFeesPromises));
|
|
97
106
|
initialAccFees.forEach((accFees, ix) => {
|
|
98
107
|
openTrades[ix].initialAccFees = accFees;
|
|
99
108
|
openTrades[ix].tradeFeesData = tradeFeesData[ix];
|
|
100
|
-
openTrades[ix].uiRealizedPnlData = uiRealizedPnlData
|
|
109
|
+
openTrades[ix].uiRealizedPnlData = uiRealizedPnlData === null || uiRealizedPnlData === void 0 ? void 0 : uiRealizedPnlData[ix];
|
|
101
110
|
});
|
|
102
111
|
allOpenPairTrades = allOpenPairTrades.concat(openTrades);
|
|
103
112
|
offset += batchSize + 1;
|
|
@@ -110,7 +119,7 @@ const fetchOpenPairTradesRaw = async (contracts, overrides = {}) => {
|
|
|
110
119
|
console.error(`Unexpected error while fetching open pair trades!`);
|
|
111
120
|
throw error;
|
|
112
121
|
}
|
|
113
|
-
};
|
|
122
|
+
});
|
|
114
123
|
exports.fetchOpenPairTradesRaw = fetchOpenPairTradesRaw;
|
|
115
124
|
const _prepareTradeContainer = (trade, tradeInfo, tradeLiquidationParams, tradeInitialAccFees, tradeFeesData, uiRealizedPnlData, collateralConfig) => {
|
|
116
125
|
const precision = collateralConfig.precision;
|
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
import { Pair, Fee, OpenInterest, PairIndex } from "../../trade/types";
|
|
1
|
+
import { Pair, Fee, OpenInterest, PairDepth, PairIndex } from "../../trade/types";
|
|
2
2
|
import { Contracts } from "../../contracts/types";
|
|
3
3
|
export declare const fetchPairs: (contracts: Contracts, pairIxs: PairIndex[]) => Promise<Pair[]>;
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const fetchPairDepthBandsDecoded: (contracts: Contracts, pairIxs: number[]) => Promise<{
|
|
6
|
-
totalDepthAboveUsd: number[];
|
|
7
|
-
totalDepthBelowUsd: number[];
|
|
8
|
-
bandsAbove: number[][];
|
|
9
|
-
bandsBelow: number[][];
|
|
10
|
-
}>;
|
|
11
|
-
export declare const fetchDepthBandsMapping: (contracts: Contracts) => Promise<{
|
|
12
|
-
slot1: string;
|
|
13
|
-
slot2: string;
|
|
14
|
-
}>;
|
|
15
|
-
export declare const fetchDepthBandsMappingDecoded: (contracts: Contracts) => Promise<number[]>;
|
|
4
|
+
export declare const fetchPairDepths: (contracts: Contracts, pairIxs: number[]) => Promise<PairDepth[]>;
|
|
16
5
|
export declare const fetchFees: (contracts: Contracts, feeIxs: PairIndex[]) => Promise<Fee[]>;
|
|
17
6
|
export declare const fetchOpenInterest: (contracts: Contracts, collateralIndex: number, pairIxs: number[]) => Promise<OpenInterest[]>;
|
|
18
7
|
export declare const getPairDescription: (pairIndex: PairIndex) => string;
|
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPairDescription = exports.fetchOpenInterest = exports.fetchFees = exports.
|
|
12
|
+
exports.getPairDescription = exports.fetchOpenInterest = exports.fetchFees = exports.fetchPairDepths = exports.fetchPairs = void 0;
|
|
4
13
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
5
14
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
6
15
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
7
16
|
const types_1 = require("../../trade/types");
|
|
8
|
-
const fetchPairs =
|
|
17
|
+
const fetchPairs = (contracts, pairIxs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
9
18
|
if (!contracts) {
|
|
10
19
|
return [];
|
|
11
20
|
}
|
|
12
21
|
const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
|
|
13
22
|
try {
|
|
14
|
-
const pairs =
|
|
23
|
+
const pairs = yield Promise.all(pairIxs.map(pairIndex => multiCollatContract.pairs(pairIndex)));
|
|
15
24
|
return pairs.map((pair, index) => {
|
|
16
25
|
return {
|
|
17
26
|
name: pair.from + "/" + pair.to,
|
|
@@ -29,94 +38,35 @@ const fetchPairs = async (contracts, pairIxs) => {
|
|
|
29
38
|
console.error(`Unexpected error while fetching pairs!`);
|
|
30
39
|
throw error;
|
|
31
40
|
}
|
|
32
|
-
};
|
|
41
|
+
});
|
|
33
42
|
exports.fetchPairs = fetchPairs;
|
|
34
|
-
const
|
|
35
|
-
if (!contracts || pairIxs.length === 0) {
|
|
36
|
-
return [];
|
|
37
|
-
}
|
|
38
|
-
const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
|
|
39
|
-
try {
|
|
40
|
-
// Returns array of PairDepthBands structs (encoded slots)
|
|
41
|
-
// Using quoted signature for overloaded function
|
|
42
|
-
const depthBands = await multiCollatContract["getPairDepthBands(uint256[])"](pairIxs);
|
|
43
|
-
return depthBands;
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
console.error(`Unexpected error while fetching pair depth bands!`);
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
exports.fetchPairDepthBands = fetchPairDepthBands;
|
|
51
|
-
const fetchPairDepthBandsDecoded = async (contracts, pairIxs) => {
|
|
52
|
-
if (!contracts || pairIxs.length === 0) {
|
|
53
|
-
return {
|
|
54
|
-
totalDepthAboveUsd: [],
|
|
55
|
-
totalDepthBelowUsd: [],
|
|
56
|
-
bandsAbove: [],
|
|
57
|
-
bandsBelow: [],
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
|
|
61
|
-
try {
|
|
62
|
-
// Returns decoded values
|
|
63
|
-
// Using quoted signature for overloaded function
|
|
64
|
-
const [totalDepthAboveUsd, totalDepthBelowUsd, bandsAbove, bandsBelow] = await multiCollatContract["getPairDepthBandsDecoded(uint256[])"](pairIxs);
|
|
65
|
-
return {
|
|
66
|
-
totalDepthAboveUsd: totalDepthAboveUsd.map((v) => parseFloat(v.toString())),
|
|
67
|
-
totalDepthBelowUsd: totalDepthBelowUsd.map((v) => parseFloat(v.toString())),
|
|
68
|
-
bandsAbove: bandsAbove.map((bands) => bands.map((b) => parseInt(b.toString()))),
|
|
69
|
-
bandsBelow: bandsBelow.map((bands) => bands.map((b) => parseInt(b.toString()))),
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
console.error(`Unexpected error while fetching decoded pair depth bands!`);
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
exports.fetchPairDepthBandsDecoded = fetchPairDepthBandsDecoded;
|
|
78
|
-
const fetchDepthBandsMapping = async (contracts) => {
|
|
79
|
-
if (!contracts) {
|
|
80
|
-
return { slot1: "0", slot2: "0" };
|
|
81
|
-
}
|
|
82
|
-
const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
|
|
83
|
-
try {
|
|
84
|
-
// Returns two uint256 slots
|
|
85
|
-
const [slot1, slot2] = await multiCollatContract.getDepthBandsMapping();
|
|
86
|
-
return {
|
|
87
|
-
slot1: slot1.toString(),
|
|
88
|
-
slot2: slot2.toString(),
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
console.error(`Unexpected error while fetching depth bands mapping!`);
|
|
93
|
-
throw error;
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
exports.fetchDepthBandsMapping = fetchDepthBandsMapping;
|
|
97
|
-
const fetchDepthBandsMappingDecoded = async (contracts) => {
|
|
43
|
+
const fetchPairDepths = (contracts, pairIxs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
44
|
if (!contracts) {
|
|
99
45
|
return [];
|
|
100
46
|
}
|
|
101
47
|
const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
|
|
102
48
|
try {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
49
|
+
const pairParams = yield multiCollatContract.getPairDepths(pairIxs);
|
|
50
|
+
return pairParams.map(pair => {
|
|
51
|
+
return {
|
|
52
|
+
onePercentDepthAboveUsd: parseFloat(pair.onePercentDepthAboveUsd.toString()),
|
|
53
|
+
onePercentDepthBelowUsd: parseFloat(pair.onePercentDepthBelowUsd.toString()),
|
|
54
|
+
};
|
|
55
|
+
});
|
|
106
56
|
}
|
|
107
57
|
catch (error) {
|
|
108
|
-
console.error(`Unexpected error while fetching
|
|
58
|
+
console.error(`Unexpected error while fetching pairs!`);
|
|
109
59
|
throw error;
|
|
110
60
|
}
|
|
111
|
-
};
|
|
112
|
-
exports.
|
|
113
|
-
const fetchFees =
|
|
61
|
+
});
|
|
62
|
+
exports.fetchPairDepths = fetchPairDepths;
|
|
63
|
+
const fetchFees = (contracts, feeIxs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
64
|
if (!contracts) {
|
|
115
65
|
return [];
|
|
116
66
|
}
|
|
117
67
|
const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
|
|
118
68
|
try {
|
|
119
|
-
const fees =
|
|
69
|
+
const fees = yield Promise.all(feeIxs.map(pairIndex => multiCollatContract.fees(pairIndex)));
|
|
120
70
|
return fees.map(fee => {
|
|
121
71
|
return {
|
|
122
72
|
totalPositionSizeFeeP: parseFloat(fee.totalPositionSizeFeeP.toString()) / 1e12,
|
|
@@ -130,13 +80,13 @@ const fetchFees = async (contracts, feeIxs) => {
|
|
|
130
80
|
console.error(`Unexpected error while fetching pairs!`);
|
|
131
81
|
throw error;
|
|
132
82
|
}
|
|
133
|
-
};
|
|
83
|
+
});
|
|
134
84
|
exports.fetchFees = fetchFees;
|
|
135
|
-
const fetchOpenInterest =
|
|
85
|
+
const fetchOpenInterest = (contracts, collateralIndex, pairIxs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
136
86
|
if (pairIxs.length === 0) {
|
|
137
87
|
return [];
|
|
138
88
|
}
|
|
139
|
-
const openInterests = (
|
|
89
|
+
const openInterests = (yield contracts.gnsMultiCollatDiamond.getAllBorrowingPairs(collateralIndex))[1];
|
|
140
90
|
return pairIxs.map(pairIndex => {
|
|
141
91
|
const openInterest = openInterests[pairIndex];
|
|
142
92
|
if (!openInterest) {
|
|
@@ -148,7 +98,7 @@ const fetchOpenInterest = async (contracts, collateralIndex, pairIxs) => {
|
|
|
148
98
|
max: parseFloat(openInterest[2].toString()) / 1e10,
|
|
149
99
|
};
|
|
150
100
|
});
|
|
151
|
-
};
|
|
101
|
+
});
|
|
152
102
|
exports.fetchOpenInterest = fetchOpenInterest;
|
|
153
103
|
const getPairDescription = (pairIndex) => {
|
|
154
104
|
return PAIR_INDEX_TO_DESCRIPTION[pairIndex] || "";
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -22,7 +22,6 @@ __exportStar(require("./constants"), exports);
|
|
|
22
22
|
__exportStar(require("./utils"), exports);
|
|
23
23
|
__exportStar(require("./vault"), exports);
|
|
24
24
|
__exportStar(require("./backend"), exports);
|
|
25
|
-
__exportStar(require("./pricing"), exports);
|
|
26
25
|
// Not sure why this is needed, but it is. Barrel imports are not working.
|
|
27
26
|
__exportStar(require("./trade/fees/borrowing/index"), exports);
|
|
28
27
|
// Export ContractsVersion for frontend usage
|
package/lib/markets/forex.js
CHANGED
|
@@ -33,7 +33,7 @@ const isForexLowLiquidity = (timestampToCheck, pair) => {
|
|
|
33
33
|
const hour = now.hour;
|
|
34
34
|
const minute = now.minute;
|
|
35
35
|
const isInDST = now.isInDST;
|
|
36
|
-
const groupIndex = pair
|
|
36
|
+
const groupIndex = pair === null || pair === void 0 ? void 0 : pair.groupIndex;
|
|
37
37
|
if (groupIndex && extendedLowLiqGroupIds.includes(+groupIndex)) {
|
|
38
38
|
return ((isInDST &&
|
|
39
39
|
((hour == 14 && minute >= 45) || (hour >= 15 && hour < 21))) ||
|
|
@@ -18,8 +18,8 @@ const buildMarketLeverageRestrictionsContext = (globalTradingVariables, pairInde
|
|
|
18
18
|
return {
|
|
19
19
|
groupMinLeverage: group.minLeverage,
|
|
20
20
|
groupMaxLeverage: group.maxLeverage,
|
|
21
|
-
pairMaxLeverage: pairMaxLeverages
|
|
22
|
-
counterTradeSettings: counterTradeSettings
|
|
21
|
+
pairMaxLeverage: pairMaxLeverages === null || pairMaxLeverages === void 0 ? void 0 : pairMaxLeverages[pairIndex],
|
|
22
|
+
counterTradeSettings: counterTradeSettings === null || counterTradeSettings === void 0 ? void 0 : counterTradeSettings[pairIndex],
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
exports.buildMarketLeverageRestrictionsContext = buildMarketLeverageRestrictionsContext;
|
|
@@ -21,30 +21,3 @@ export type MarketPriceContext = {
|
|
|
21
21
|
oiShortToken: number;
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
|
-
/**
|
|
25
|
-
* @dev Types for signed prices data structure
|
|
26
|
-
*/
|
|
27
|
-
export type SignedPricesResponse = {
|
|
28
|
-
signedData: SignedPrices;
|
|
29
|
-
missingPrices: number[];
|
|
30
|
-
};
|
|
31
|
-
export type SignedPrices = {
|
|
32
|
-
signerId: number;
|
|
33
|
-
expiryTs: number;
|
|
34
|
-
fromBlock: number;
|
|
35
|
-
isLookback: boolean;
|
|
36
|
-
pairIndices: number[];
|
|
37
|
-
prices: Price[];
|
|
38
|
-
signature: string;
|
|
39
|
-
};
|
|
40
|
-
export type Price = {
|
|
41
|
-
open: string;
|
|
42
|
-
high: string;
|
|
43
|
-
low: string;
|
|
44
|
-
current: string;
|
|
45
|
-
ts: number;
|
|
46
|
-
};
|
|
47
|
-
export type Oracle = {
|
|
48
|
-
url: string;
|
|
49
|
-
key?: string;
|
|
50
|
-
};
|
|
@@ -13,8 +13,9 @@ exports.buildBorrowingV1Context = void 0;
|
|
|
13
13
|
* @returns Full borrowing context with all pairs and groups or undefined if data not available
|
|
14
14
|
*/
|
|
15
15
|
const buildBorrowingV1Context = (globalTradingVariables, collateralIndex, currentBlock) => {
|
|
16
|
+
var _a;
|
|
16
17
|
const collateral = globalTradingVariables.collaterals[collateralIndex - 1];
|
|
17
|
-
if (!collateral
|
|
18
|
+
if (!(collateral === null || collateral === void 0 ? void 0 : collateral.pairBorrowingFees) || !(collateral === null || collateral === void 0 ? void 0 : collateral.groupBorrowingFees)) {
|
|
18
19
|
return undefined;
|
|
19
20
|
}
|
|
20
21
|
const pairs = collateral.pairBorrowingFees;
|
|
@@ -26,7 +27,7 @@ const buildBorrowingV1Context = (globalTradingVariables, collateralIndex, curren
|
|
|
26
27
|
currentBlock,
|
|
27
28
|
pairs,
|
|
28
29
|
groups,
|
|
29
|
-
collateralPriceUsd: collateral.prices
|
|
30
|
+
collateralPriceUsd: ((_a = collateral.prices) === null || _a === void 0 ? void 0 : _a.collateralPriceUsd) || 1,
|
|
30
31
|
pairOis: collateral.pairOis,
|
|
31
32
|
};
|
|
32
33
|
};
|
|
@@ -14,11 +14,7 @@ const convertPairGroupBorrowingFee = (pairGroup) => ({
|
|
|
14
14
|
block: pairGroup.block,
|
|
15
15
|
});
|
|
16
16
|
exports.convertPairGroupBorrowingFee = convertPairGroupBorrowingFee;
|
|
17
|
-
const convertPairBorrowingFee = (pair, pairOi, pairGroup, feeCap) => ({
|
|
18
|
-
...(0, exports.convertGroupBorrowingData)(pair, pairOi),
|
|
19
|
-
groups: pairGroup.map(value => (0, exports.convertPairGroupBorrowingFee)(value)),
|
|
20
|
-
feePerBlockCap: (0, exports.convertFeePerBlockCap)(feeCap),
|
|
21
|
-
});
|
|
17
|
+
const convertPairBorrowingFee = (pair, pairOi, pairGroup, feeCap) => (Object.assign(Object.assign({}, (0, exports.convertGroupBorrowingData)(pair, pairOi)), { groups: pairGroup.map(value => (0, exports.convertPairGroupBorrowingFee)(value)), feePerBlockCap: (0, exports.convertFeePerBlockCap)(feeCap) }));
|
|
22
18
|
exports.convertPairBorrowingFee = convertPairBorrowingFee;
|
|
23
19
|
const convertPairBorrowingFees = ([pairs, pairOi, pairGroups, feeCaps]) => pairs.map((value, ix) => (0, exports.convertPairBorrowingFee)(value, pairOi[ix], pairGroups[ix], feeCaps[ix]));
|
|
24
20
|
exports.convertPairBorrowingFees = convertPairBorrowingFees;
|
|
@@ -48,7 +48,7 @@ const getBorrowingFee = (posDai, pairIndex, long, initialAccFees, currentPairPri
|
|
|
48
48
|
return 0;
|
|
49
49
|
}
|
|
50
50
|
const pairGroups = pairs[pairIndex].groups;
|
|
51
|
-
const firstPairGroup = pairGroups
|
|
51
|
+
const firstPairGroup = (pairGroups === null || pairGroups === void 0 ? void 0 : pairGroups.length) > 0 ? pairGroups[0] : undefined;
|
|
52
52
|
let fee = 0;
|
|
53
53
|
if (!firstPairGroup || firstPairGroup.block > initialAccFees.block) {
|
|
54
54
|
const openInterest = (0, __1.getPairTotalOisDynamicCollateral)(pairIndex, {
|
|
@@ -215,13 +215,13 @@ collateralPriceUsd) => {
|
|
|
215
215
|
};
|
|
216
216
|
const getPendingAccFeesDelta = (blockDistance, feePerBlock, netOi, maxOi, feeExponent) => {
|
|
217
217
|
return maxOi > 0 && feeExponent > 0
|
|
218
|
-
? feePerBlock * blockDistance * (netOi / maxOi)
|
|
218
|
+
? feePerBlock * blockDistance * Math.pow((netOi / maxOi), feeExponent)
|
|
219
219
|
: 0;
|
|
220
220
|
};
|
|
221
221
|
const getFeePerBlockCaps = (cap) => {
|
|
222
222
|
return {
|
|
223
|
-
minP: cap
|
|
224
|
-
maxP: cap
|
|
223
|
+
minP: (cap === null || cap === void 0 ? void 0 : cap.minP) || 0,
|
|
224
|
+
maxP: (cap === null || cap === void 0 ? void 0 : cap.maxP) && cap.maxP > 0 ? cap.maxP : 1,
|
|
225
225
|
};
|
|
226
226
|
};
|
|
227
227
|
const getBorrowingDataActiveFeePerBlock = (val) => {
|
|
@@ -231,7 +231,7 @@ const getBorrowingDataActiveFeePerBlock = (val) => {
|
|
|
231
231
|
// If minP > 0 then netOi has to be at least minP * maxOi
|
|
232
232
|
// If maxP > 0 then netOi cannot be more than maxP * maxOi
|
|
233
233
|
const effectiveOi = Math.min(Math.max(Math.abs(long - short), max * minP), max * maxP);
|
|
234
|
-
return val.feePerBlock * (effectiveOi / max)
|
|
234
|
+
return val.feePerBlock * Math.pow((effectiveOi / max), val.feeExponent);
|
|
235
235
|
};
|
|
236
236
|
const getActiveFeePerBlock = (pair, group) => {
|
|
237
237
|
const pairFeePerBlock = getBorrowingDataActiveFeePerBlock(pair);
|
|
@@ -5,12 +5,13 @@ exports.buildBorrowingV2Context = void 0;
|
|
|
5
5
|
* @dev Builds borrowing v2 sub-context for a specific pair
|
|
6
6
|
*/
|
|
7
7
|
const buildBorrowingV2Context = (globalTradingVariables, collateralIndex, pairIndex, currentTimestamp) => {
|
|
8
|
+
var _a, _b;
|
|
8
9
|
const collateral = globalTradingVariables.collaterals[collateralIndex - 1];
|
|
9
|
-
if (!collateral
|
|
10
|
+
if (!(collateral === null || collateral === void 0 ? void 0 : collateral.pairBorrowingFeesV2)) {
|
|
10
11
|
return undefined;
|
|
11
12
|
}
|
|
12
|
-
const params = collateral.pairBorrowingFeesV2.params
|
|
13
|
-
const data = collateral.pairBorrowingFeesV2.data
|
|
13
|
+
const params = (_a = collateral.pairBorrowingFeesV2.params) === null || _a === void 0 ? void 0 : _a[pairIndex];
|
|
14
|
+
const data = (_b = collateral.pairBorrowingFeesV2.data) === null || _b === void 0 ? void 0 : _b[pairIndex];
|
|
14
15
|
if (!params || !data) {
|
|
15
16
|
return undefined;
|
|
16
17
|
}
|
|
@@ -116,7 +116,7 @@ exports.aprToBorrowingRate = aprToBorrowingRate;
|
|
|
116
116
|
*/
|
|
117
117
|
const createCollateralScopedBorrowingContext = (collateralBorrowingData, currentTimestamp) => {
|
|
118
118
|
const context = {
|
|
119
|
-
currentTimestamp: currentTimestamp
|
|
119
|
+
currentTimestamp: currentTimestamp !== null && currentTimestamp !== void 0 ? currentTimestamp : Math.floor(Date.now() / 1000),
|
|
120
120
|
borrowingParams: {},
|
|
121
121
|
borrowingData: {},
|
|
122
122
|
};
|