@gainsnetwork/sdk 0.2.9-rc1 → 0.2.10-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/constants.d.ts +4 -1
- package/lib/constants.js +6 -3
- package/lib/contracts/types/generated/GNSMultiCollatDiamond.d.ts +412 -892
- package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.d.ts +94 -0
- package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +852 -2130
- package/lib/contracts/utils/openTrades.js +2 -11
- package/lib/contracts/utils/pairs.d.ts +0 -1
- package/lib/contracts/utils/pairs.js +5 -18
- package/lib/trade/spread.d.ts +1 -8
- package/lib/trade/spread.js +6 -23
- package/lib/trade/types.d.ts +6 -11
- package/lib/trade/types.js +4 -0
- package/package.json +1 -1
- 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/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/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/GNSTradingStorage.d.ts +0 -1387
- package/lib/contracts/types/generated/GNSTradingStorage.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/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/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
|
@@ -14,7 +14,7 @@ const ethcall_1 = require("ethcall");
|
|
|
14
14
|
const fetchOpenPairTrades = (contracts, overrides = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
15
|
const rawTrades = yield (0, exports.fetchOpenPairTradesRaw)(contracts, overrides);
|
|
16
16
|
const collateralPrecisions = (yield contracts.gnsMultiCollatDiamond.getCollaterals()).map(({ precision }) => precision);
|
|
17
|
-
return rawTrades.map(rawTrade => _prepareTradeContainer(rawTrade.trade, rawTrade.tradeInfo, rawTrade.
|
|
17
|
+
return rawTrades.map(rawTrade => _prepareTradeContainer(rawTrade.trade, rawTrade.tradeInfo, rawTrade.initialAccFees, collateralPrecisions[parseInt(rawTrade.trade.collateralIndex.toString()) - 1]));
|
|
18
18
|
});
|
|
19
19
|
exports.fetchOpenPairTrades = fetchOpenPairTrades;
|
|
20
20
|
// @todo rename
|
|
@@ -40,7 +40,6 @@ const fetchOpenPairTradesRaw = (contracts, overrides = {}) => __awaiter(void 0,
|
|
|
40
40
|
while (running) {
|
|
41
41
|
const trades = yield multiCollatDiamondContract.getAllTrades(offset, offset + batchSize);
|
|
42
42
|
const tradeInfos = yield multiCollatDiamondContract.getAllTradeInfos(offset, offset + batchSize);
|
|
43
|
-
const tradeLiquidationParams = yield multiCollatDiamondContract.getAllTradesLiquidationParams(offset, offset + batchSize);
|
|
44
43
|
// Array is always of length `batchSize`
|
|
45
44
|
// so we need to filter out the empty trades, indexes are reliable
|
|
46
45
|
const openTrades = trades
|
|
@@ -49,7 +48,6 @@ const fetchOpenPairTradesRaw = (contracts, overrides = {}) => __awaiter(void 0,
|
|
|
49
48
|
.map((trade, ix) => ({
|
|
50
49
|
trade,
|
|
51
50
|
tradeInfo: tradeInfos[ix],
|
|
52
|
-
liquidationParams: tradeLiquidationParams[ix],
|
|
53
51
|
initialAccFees: {
|
|
54
52
|
accPairFee: 0,
|
|
55
53
|
accGroupFee: 0,
|
|
@@ -85,7 +83,7 @@ const fetchOpenPairTradesRaw = (contracts, overrides = {}) => __awaiter(void 0,
|
|
|
85
83
|
}
|
|
86
84
|
});
|
|
87
85
|
exports.fetchOpenPairTradesRaw = fetchOpenPairTradesRaw;
|
|
88
|
-
const _prepareTradeContainer = (trade, tradeInfo,
|
|
86
|
+
const _prepareTradeContainer = (trade, tradeInfo, tradeInitialAccFees, collateralPrecision) => ({
|
|
89
87
|
trade: {
|
|
90
88
|
user: trade.user,
|
|
91
89
|
index: parseInt(trade.index.toString()),
|
|
@@ -109,13 +107,6 @@ const _prepareTradeContainer = (trade, tradeInfo, tradeLiquidationParams, tradeI
|
|
|
109
107
|
lastOiUpdateTs: parseFloat(tradeInfo.lastOiUpdateTs),
|
|
110
108
|
collateralPriceUsd: parseFloat(tradeInfo.collateralPriceUsd.toString()) / 1e8,
|
|
111
109
|
},
|
|
112
|
-
liquidationParams: {
|
|
113
|
-
maxLiqSpreadP: parseFloat(tradeLiquidationParams.maxLiqSpreadP.toString()) / 1e10,
|
|
114
|
-
startLiqThresholdP: parseFloat(tradeLiquidationParams.startLiqThresholdP.toString()) / 1e10,
|
|
115
|
-
endLiqThresholdP: parseFloat(tradeLiquidationParams.endLiqThresholdP.toString()) / 1e10,
|
|
116
|
-
startLeverage: parseFloat(tradeLiquidationParams.startLeverage.toString()) / 1e3,
|
|
117
|
-
endLeverage: parseFloat(tradeLiquidationParams.endLeverage.toString()) / 1e3,
|
|
118
|
-
},
|
|
119
110
|
initialAccFees: {
|
|
120
111
|
accPairFee: parseFloat(tradeInitialAccFees.accPairFee.toString()) / 1e10,
|
|
121
112
|
accGroupFee: parseFloat(tradeInitialAccFees.accGroupFee.toString()) / 1e10,
|
|
@@ -2,7 +2,6 @@ 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
4
|
export declare const fetchPairDepths: (contracts: Contracts, pairIxs: number[]) => Promise<PairDepth[]>;
|
|
5
|
-
export declare const fetchProtectionCloseFactors: (contracts: Contracts, pairIxs: number[]) => Promise<number[]>;
|
|
6
5
|
export declare const fetchFees: (contracts: Contracts, feeIxs: PairIndex[]) => Promise<Fee[]>;
|
|
7
6
|
export declare const fetchOpenInterest: (contracts: Contracts, collateralIndex: number, pairIxs: number[]) => Promise<OpenInterest[]>;
|
|
8
7
|
export declare const getPairDescription: (pairIndex: PairIndex) => string;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getPairDescription = exports.fetchOpenInterest = exports.fetchFees = exports.
|
|
12
|
+
exports.getPairDescription = exports.fetchOpenInterest = exports.fetchFees = exports.fetchPairDepths = exports.fetchPairs = void 0;
|
|
13
13
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
14
14
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
15
15
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
@@ -60,23 +60,6 @@ const fetchPairDepths = (contracts, pairIxs) => __awaiter(void 0, void 0, void 0
|
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
62
|
exports.fetchPairDepths = fetchPairDepths;
|
|
63
|
-
const fetchProtectionCloseFactors = (contracts, pairIxs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
-
if (!contracts) {
|
|
65
|
-
return [];
|
|
66
|
-
}
|
|
67
|
-
const { gnsMultiCollatDiamond: multiCollatContract } = contracts;
|
|
68
|
-
try {
|
|
69
|
-
const protectionCloseFactors = yield multiCollatContract.getProtectionCloseFactors(pairIxs);
|
|
70
|
-
return protectionCloseFactors.map(protectionCloseFactor => {
|
|
71
|
-
return protectionCloseFactor.toNumber();
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
console.error(`Unexpected error while fetching pairs!`);
|
|
76
|
-
throw error;
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
exports.fetchProtectionCloseFactors = fetchProtectionCloseFactors;
|
|
80
63
|
const fetchFees = (contracts, feeIxs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
64
|
if (!contracts) {
|
|
82
65
|
return [];
|
|
@@ -373,4 +356,8 @@ const PAIR_INDEX_TO_DESCRIPTION = {
|
|
|
373
356
|
[types_1.PairIndex.COREUSD]: "Core to US Dollar",
|
|
374
357
|
[types_1.PairIndex.JASMYUSD]: "Jasmy Coin to US Dollar",
|
|
375
358
|
[types_1.PairIndex.DARUSD]: "Mines of Dalarnia to US Dollar",
|
|
359
|
+
[types_1.PairIndex.MEWUSD]: "Cats in a dog world to US Dollar",
|
|
360
|
+
[types_1.PairIndex.DEGENUSD]: "Degen Base to US Dollar",
|
|
361
|
+
[types_1.PairIndex.SLERFUSD]: "Slerf to US Dollar",
|
|
362
|
+
[types_1.PairIndex.UXLINKUSD]: "UXLink to US Dollar",
|
|
376
363
|
};
|
package/lib/trade/spread.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
1
|
import { OiWindows, OiWindowsSettings, PairDepth } from "./types";
|
|
2
|
-
export
|
|
3
|
-
isOpen: boolean | undefined;
|
|
4
|
-
protectionCloseFactor: number | undefined;
|
|
5
|
-
createdBlock: number | undefined;
|
|
6
|
-
currentBlock: number | undefined;
|
|
7
|
-
};
|
|
8
|
-
export declare const getProtectionCloseFactor: (spreadCtx: SpreadContext | undefined) => number;
|
|
9
|
-
export declare const getSpreadWithPriceImpactP: (pairSpreadP: number, buy: boolean, collateral: number, leverage: number, pairDepth: PairDepth | undefined, oiWindowsSettings?: OiWindowsSettings | undefined, oiWindows?: OiWindows | undefined, spreadCtx?: SpreadContext | undefined) => number;
|
|
2
|
+
export declare const getSpreadWithPriceImpactP: (pairSpreadP: number, buy: boolean, collateral: number, leverage: number, pairDepth: PairDepth | undefined, oiWindowsSettings?: OiWindowsSettings | undefined, oiWindows?: OiWindows | undefined) => number;
|
package/lib/trade/spread.js
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSpreadWithPriceImpactP =
|
|
3
|
+
exports.getSpreadWithPriceImpactP = void 0;
|
|
4
4
|
const oiWindows_1 = require("./oiWindows");
|
|
5
|
-
const
|
|
6
|
-
const getProtectionCloseFactor = (spreadCtx) => {
|
|
7
|
-
return spreadCtx === undefined ||
|
|
8
|
-
spreadCtx.protectionCloseFactor === undefined ||
|
|
9
|
-
spreadCtx.createdBlock === undefined ||
|
|
10
|
-
spreadCtx.currentBlock === undefined ||
|
|
11
|
-
spreadCtx.createdBlock + constants_1.PROTECTION_CLOSE_FACTOR_BLOCKS <
|
|
12
|
-
spreadCtx.currentBlock
|
|
13
|
-
? 1
|
|
14
|
-
: spreadCtx.protectionCloseFactor;
|
|
15
|
-
};
|
|
16
|
-
exports.getProtectionCloseFactor = getProtectionCloseFactor;
|
|
17
|
-
const getSpreadWithPriceImpactP = (pairSpreadP, buy, collateral, leverage, pairDepth, oiWindowsSettings, oiWindows, spreadCtx) => {
|
|
5
|
+
const getSpreadWithPriceImpactP = (pairSpreadP, buy, collateral, leverage, pairDepth, oiWindowsSettings, oiWindows) => {
|
|
18
6
|
if (pairSpreadP === undefined) {
|
|
19
7
|
return 0;
|
|
20
8
|
}
|
|
@@ -23,17 +11,12 @@ const getSpreadWithPriceImpactP = (pairSpreadP, buy, collateral, leverage, pairD
|
|
|
23
11
|
: pairDepth === null || pairDepth === void 0 ? void 0 : pairDepth.onePercentDepthBelowUsd;
|
|
24
12
|
let activeOi = undefined;
|
|
25
13
|
if (oiWindowsSettings !== undefined && (oiWindowsSettings === null || oiWindowsSettings === void 0 ? void 0 : oiWindowsSettings.windowsCount) > 0) {
|
|
26
|
-
activeOi = (0, oiWindows_1.getActiveOi)((0, oiWindows_1.getCurrentOiWindowId)(oiWindowsSettings), oiWindowsSettings.windowsCount, oiWindows,
|
|
27
|
-
spreadCtx.isOpen === undefined ||
|
|
28
|
-
spreadCtx.isOpen
|
|
29
|
-
? buy
|
|
30
|
-
: !buy);
|
|
14
|
+
activeOi = (0, oiWindows_1.getActiveOi)((0, oiWindows_1.getCurrentOiWindowId)(oiWindowsSettings), oiWindowsSettings.windowsCount, oiWindows, buy);
|
|
31
15
|
}
|
|
32
16
|
if (!onePercentDepth || activeOi === undefined || collateral === undefined) {
|
|
33
|
-
return pairSpreadP
|
|
17
|
+
return pairSpreadP;
|
|
34
18
|
}
|
|
35
|
-
return (pairSpreadP
|
|
36
|
-
(
|
|
37
|
-
(0, exports.getProtectionCloseFactor)(spreadCtx));
|
|
19
|
+
return (pairSpreadP +
|
|
20
|
+
(activeOi + (collateral * leverage) / 2) / onePercentDepth / 100);
|
|
38
21
|
};
|
|
39
22
|
exports.getSpreadWithPriceImpactP = getSpreadWithPriceImpactP;
|
package/lib/trade/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ITradingStorage, IBorrowingFees
|
|
1
|
+
import { ITradingStorage, IBorrowingFees } from "../contracts/types/generated/GNSMultiCollatDiamond";
|
|
2
2
|
import { BorrowingFee } from "./fees/borrowing";
|
|
3
3
|
import { FeeTier, TraderInfo } from "./fees/tiers/types";
|
|
4
4
|
export type PairIndexes = {
|
|
@@ -7,7 +7,6 @@ export type PairIndexes = {
|
|
|
7
7
|
export type TradeContainer = {
|
|
8
8
|
trade: Trade;
|
|
9
9
|
tradeInfo: TradeInfo;
|
|
10
|
-
liquidationParams: LiquidationParams;
|
|
11
10
|
initialAccFees: TradeInitialAccFees;
|
|
12
11
|
receivedAt?: number;
|
|
13
12
|
};
|
|
@@ -33,13 +32,6 @@ export type TradeInfo = {
|
|
|
33
32
|
lastOiUpdateTs: number;
|
|
34
33
|
collateralPriceUsd: number;
|
|
35
34
|
};
|
|
36
|
-
export type LiquidationParams = {
|
|
37
|
-
maxLiqSpreadP: number;
|
|
38
|
-
startLiqThresholdP: number;
|
|
39
|
-
endLiqThresholdP: number;
|
|
40
|
-
startLeverage: number;
|
|
41
|
-
endLeverage: number;
|
|
42
|
-
};
|
|
43
35
|
export type TradingGroup = {
|
|
44
36
|
maxLeverage: number;
|
|
45
37
|
minLeverage: number;
|
|
@@ -130,7 +122,6 @@ export declare enum PositionType {
|
|
|
130
122
|
export type TradeContainerRaw = {
|
|
131
123
|
trade: ITradingStorage.TradeStruct;
|
|
132
124
|
tradeInfo: ITradingStorage.TradeInfoStruct;
|
|
133
|
-
liquidationParams: IPairsStorage.GroupLiquidationParamsStruct;
|
|
134
125
|
initialAccFees: IBorrowingFees.BorrowingInitialAccFeesStruct;
|
|
135
126
|
};
|
|
136
127
|
export type OiWindowsSettings = {
|
|
@@ -449,5 +440,9 @@ export declare enum PairIndex {
|
|
|
449
440
|
OMUSD = 247,
|
|
450
441
|
COREUSD = 248,
|
|
451
442
|
JASMYUSD = 249,
|
|
452
|
-
DARUSD = 250
|
|
443
|
+
DARUSD = 250,
|
|
444
|
+
MEWUSD = 251,
|
|
445
|
+
DEGENUSD = 252,
|
|
446
|
+
SLERFUSD = 253,
|
|
447
|
+
UXLINKUSD = 254
|
|
453
448
|
}
|
package/lib/trade/types.js
CHANGED
|
@@ -280,4 +280,8 @@ var PairIndex;
|
|
|
280
280
|
PairIndex[PairIndex["COREUSD"] = 248] = "COREUSD";
|
|
281
281
|
PairIndex[PairIndex["JASMYUSD"] = 249] = "JASMYUSD";
|
|
282
282
|
PairIndex[PairIndex["DARUSD"] = 250] = "DARUSD";
|
|
283
|
+
PairIndex[PairIndex["MEWUSD"] = 251] = "MEWUSD";
|
|
284
|
+
PairIndex[PairIndex["DEGENUSD"] = 252] = "DEGENUSD";
|
|
285
|
+
PairIndex[PairIndex["SLERFUSD"] = 253] = "SLERFUSD";
|
|
286
|
+
PairIndex[PairIndex["UXLINKUSD"] = 254] = "UXLINKUSD";
|
|
283
287
|
})(PairIndex = exports.PairIndex || (exports.PairIndex = {}));
|