@gainsnetwork/sdk 0.2.35-rc1 → 0.2.36
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 +0 -8
- package/lib/constants.js +1 -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/GNSMultiCollatDiamond.d.ts +673 -312
- 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/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/GNSTradingStorage.d.ts +1387 -0
- package/lib/contracts/types/generated/GNSTradingStorage.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/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.js +1437 -532
- 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/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/utils/pairs.js +4 -12
- package/lib/trade/fees/index.js +2 -2
- package/lib/trade/spread.d.ts +4 -5
- package/lib/trade/spread.js +32 -15
- package/lib/trade/types.d.ts +13 -11
- package/lib/trade/types.js +0 -8
- package/package.json +1 -1
|
@@ -69,10 +69,10 @@ const fetchFees = (contracts, feeIxs) => __awaiter(void 0, void 0, void 0, funct
|
|
|
69
69
|
const fees = yield Promise.all(feeIxs.map(pairIndex => multiCollatContract.fees(pairIndex)));
|
|
70
70
|
return fees.map(fee => {
|
|
71
71
|
return {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
minPositionSizeUsd: parseFloat(fee.minPositionSizeUsd.toString()) /
|
|
72
|
+
totalPositionSizeFeeP: parseFloat(fee.totalPositionSizeFeeP.toString()) / 1e12,
|
|
73
|
+
totalLiqCollateralFeeP: parseFloat(fee.totalLiqCollateralFeeP.toString()) / 1e12,
|
|
74
|
+
oraclePositionSizeFeeP: parseFloat(fee.oraclePositionSizeFeeP.toString()) / 1e12,
|
|
75
|
+
minPositionSizeUsd: parseFloat(fee.minPositionSizeUsd.toString()) / 1e3,
|
|
76
76
|
};
|
|
77
77
|
});
|
|
78
78
|
}
|
|
@@ -391,12 +391,4 @@ const PAIR_INDEX_TO_DESCRIPTION = {
|
|
|
391
391
|
[types_1.PairIndex.POLYXUSD]: "Polymesh to US Dollar",
|
|
392
392
|
[types_1.PairIndex.MOODENGUSD]: "Moo Deng to US Dollar",
|
|
393
393
|
[types_1.PairIndex.MOTHERUSD]: "Mother Iggy to US Dollar",
|
|
394
|
-
[types_1.PairIndex.AEROUSD]: "Aerodrome Finance to US Dollar",
|
|
395
|
-
[types_1.PairIndex.CVCUSD]: "Civic to US Dollar",
|
|
396
|
-
[types_1.PairIndex.NEIROCTOUSD]: "Neiro CTO to US Dollar",
|
|
397
|
-
[types_1.PairIndex.ARKUSD]: "Ark to US Dollar",
|
|
398
|
-
[types_1.PairIndex.NPCUSD]: "Non-Playable Coin to US Dollar",
|
|
399
|
-
[types_1.PairIndex.ORBSUSD]: "ORBS to US Dollar",
|
|
400
|
-
[types_1.PairIndex.APUUSD]: "Apu Apustaja to US Dollar",
|
|
401
|
-
[types_1.PairIndex.BSVUSD]: "Bitcoin SV to US Dollar",
|
|
402
394
|
};
|
package/lib/trade/fees/index.js
CHANGED
|
@@ -22,8 +22,8 @@ const getClosingFee = (posDai, leverage, pairIndex, pairFee, collateralPriceUsd
|
|
|
22
22
|
pairFee === undefined) {
|
|
23
23
|
return 0;
|
|
24
24
|
}
|
|
25
|
-
const {
|
|
26
|
-
return (
|
|
25
|
+
const { totalPositionSizeFeeP, minPositionSizeUsd } = pairFee;
|
|
26
|
+
return (totalPositionSizeFeeP *
|
|
27
27
|
feeMultiplier *
|
|
28
28
|
Math.max(collateralPriceUsd && collateralPriceUsd > 0
|
|
29
29
|
? minPositionSizeUsd / collateralPriceUsd
|
package/lib/trade/spread.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { LiquidationParams, OiWindows, OiWindowsSettings, PairDepth } from "./types";
|
|
1
|
+
import { LiquidationParams, OiWindows, OiWindowsSettings, PairDepth, PairFactor } from "./types";
|
|
2
2
|
import { ContractsVersion } from "../contracts/types";
|
|
3
3
|
export type SpreadContext = {
|
|
4
4
|
isOpen?: boolean;
|
|
5
5
|
isPnlPositive?: boolean;
|
|
6
|
-
protectionCloseFactor?: number;
|
|
7
|
-
protectionCloseFactorBlocks?: number;
|
|
8
|
-
cumulativeFactor?: number;
|
|
9
6
|
createdBlock?: number;
|
|
10
7
|
liquidationParams?: LiquidationParams | undefined;
|
|
11
8
|
currentBlock?: number | undefined;
|
|
12
9
|
contractsVersion?: ContractsVersion | undefined;
|
|
13
|
-
|
|
10
|
+
protectionCloseFactorWhitelist?: boolean;
|
|
11
|
+
} & Partial<PairFactor>;
|
|
14
12
|
export declare const getProtectionCloseFactor: (spreadCtx: SpreadContext | undefined) => number;
|
|
13
|
+
export declare const isProtectionCloseFactorActive: (spreadCtx: SpreadContext | undefined) => boolean | undefined;
|
|
15
14
|
export declare const getCumulativeFactor: (spreadCtx: SpreadContext | undefined) => number;
|
|
16
15
|
export declare const getLegacyFactor: (spreadCtx: SpreadContext | undefined) => number;
|
|
17
16
|
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;
|
package/lib/trade/spread.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSpreadP = exports.getSpreadWithPriceImpactP = exports.getLegacyFactor = exports.getCumulativeFactor = exports.getProtectionCloseFactor = void 0;
|
|
3
|
+
exports.getSpreadP = exports.getSpreadWithPriceImpactP = exports.getLegacyFactor = exports.getCumulativeFactor = exports.isProtectionCloseFactorActive = exports.getProtectionCloseFactor = void 0;
|
|
4
4
|
const oiWindows_1 = require("./oiWindows");
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
const types_1 = require("../contracts/types");
|
|
@@ -9,23 +9,32 @@ const getProtectionCloseFactor = (spreadCtx) => {
|
|
|
9
9
|
spreadCtx.contractsVersion === types_1.ContractsVersion.BEFORE_V9_2 ||
|
|
10
10
|
spreadCtx.isOpen === undefined ||
|
|
11
11
|
spreadCtx.isPnlPositive === undefined ||
|
|
12
|
-
spreadCtx
|
|
13
|
-
spreadCtx.protectionCloseFactorBlocks === undefined ||
|
|
14
|
-
spreadCtx.createdBlock === undefined ||
|
|
15
|
-
spreadCtx.currentBlock === undefined)
|
|
12
|
+
(0, exports.isProtectionCloseFactorActive)(spreadCtx) !== true)
|
|
16
13
|
return constants_1.DEFAULT_PROTECTION_CLOSE_FACTOR;
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
15
|
+
return spreadCtx.protectionCloseFactor;
|
|
16
|
+
};
|
|
17
|
+
exports.getProtectionCloseFactor = getProtectionCloseFactor;
|
|
18
|
+
const isProtectionCloseFactorActive = (spreadCtx) => {
|
|
19
|
+
if (spreadCtx === undefined ||
|
|
20
|
+
spreadCtx.currentBlock === undefined ||
|
|
21
|
+
spreadCtx.createdBlock === undefined ||
|
|
22
|
+
spreadCtx.protectionCloseFactorBlocks === undefined ||
|
|
23
|
+
spreadCtx.protectionCloseFactor === undefined) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
return (spreadCtx.isPnlPositive === true &&
|
|
27
|
+
spreadCtx.isOpen === false &&
|
|
19
28
|
spreadCtx.protectionCloseFactor > 0 &&
|
|
20
29
|
spreadCtx.currentBlock <=
|
|
21
|
-
spreadCtx.createdBlock + spreadCtx.protectionCloseFactorBlocks
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
return constants_1.DEFAULT_PROTECTION_CLOSE_FACTOR;
|
|
30
|
+
spreadCtx.createdBlock + spreadCtx.protectionCloseFactorBlocks &&
|
|
31
|
+
spreadCtx.protectionCloseFactorWhitelist !== true);
|
|
25
32
|
};
|
|
26
|
-
exports.
|
|
33
|
+
exports.isProtectionCloseFactorActive = isProtectionCloseFactorActive;
|
|
27
34
|
const getCumulativeFactor = (spreadCtx) => {
|
|
28
|
-
if (spreadCtx === undefined ||
|
|
35
|
+
if (spreadCtx === undefined ||
|
|
36
|
+
spreadCtx.cumulativeFactor === undefined ||
|
|
37
|
+
spreadCtx.cumulativeFactor === 0) {
|
|
29
38
|
return constants_1.DEFAULT_CUMULATIVE_FACTOR;
|
|
30
39
|
}
|
|
31
40
|
return spreadCtx.cumulativeFactor;
|
|
@@ -39,9 +48,17 @@ const getSpreadWithPriceImpactP = (pairSpreadP, buy, collateral, leverage, pairD
|
|
|
39
48
|
if (pairSpreadP === undefined) {
|
|
40
49
|
return 0;
|
|
41
50
|
}
|
|
51
|
+
if (
|
|
42
52
|
// No spread or price impact when closing pre-v9.2 trades
|
|
43
|
-
|
|
44
|
-
(spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.contractsVersion) === types_1.ContractsVersion.BEFORE_V9_2)
|
|
53
|
+
((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === false &&
|
|
54
|
+
(spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.contractsVersion) === types_1.ContractsVersion.BEFORE_V9_2) ||
|
|
55
|
+
// No spread or price impact for opens when `pair.exemptOnOpen` is true
|
|
56
|
+
((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === true && (spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.exemptOnOpen) === true) ||
|
|
57
|
+
// No spread or price impact for closes after `protectionCloseFactor` has expired
|
|
58
|
+
// when `pair.exemptAfterProtectionCloseFactor` is true
|
|
59
|
+
((spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.isOpen) === false &&
|
|
60
|
+
(spreadCtx === null || spreadCtx === void 0 ? void 0 : spreadCtx.exemptAfterProtectionCloseFactor) === true &&
|
|
61
|
+
(0, exports.isProtectionCloseFactorActive)(spreadCtx) !== true)) {
|
|
45
62
|
return 0;
|
|
46
63
|
}
|
|
47
64
|
const onePercentDepth = buy
|
package/lib/trade/types.d.ts
CHANGED
|
@@ -48,10 +48,17 @@ export type TradingGroup = {
|
|
|
48
48
|
name: string;
|
|
49
49
|
};
|
|
50
50
|
export type Fee = {
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
totalPositionSizeFeeP: number;
|
|
52
|
+
totalLiqCollateralFeeP: number;
|
|
53
|
+
oraclePositionSizeFeeP: number;
|
|
53
54
|
minPositionSizeUsd: number;
|
|
55
|
+
};
|
|
56
|
+
export type GlobalTradeFeeParams = {
|
|
57
|
+
referralFeeP: number;
|
|
58
|
+
govFeeP: number;
|
|
54
59
|
triggerOrderFeeP: number;
|
|
60
|
+
gnsOtcFeeP: number;
|
|
61
|
+
gTokenFeeP: number;
|
|
55
62
|
};
|
|
56
63
|
export type PairDepth = {
|
|
57
64
|
onePercentDepthAboveUsd: number;
|
|
@@ -169,11 +176,14 @@ export type TraderFeeTiers = {
|
|
|
169
176
|
outboundPoints: number;
|
|
170
177
|
lastDayUpdatedPoints: number;
|
|
171
178
|
expiredPoints: number[];
|
|
179
|
+
unclaimedPoints: number;
|
|
172
180
|
};
|
|
173
181
|
export type PairFactor = {
|
|
174
182
|
cumulativeFactor: number;
|
|
175
183
|
protectionCloseFactor: number;
|
|
176
184
|
protectionCloseFactorBlocks: number;
|
|
185
|
+
exemptOnOpen: boolean;
|
|
186
|
+
exemptAfterProtectionCloseFactor: boolean;
|
|
177
187
|
};
|
|
178
188
|
export declare enum PendingOrderType {
|
|
179
189
|
MARKET_OPEN = 0,
|
|
@@ -494,13 +504,5 @@ export declare enum PairIndex {
|
|
|
494
504
|
EIGENUSD = 282,
|
|
495
505
|
POLYXUSD = 283,
|
|
496
506
|
MOODENGUSD = 284,
|
|
497
|
-
MOTHERUSD = 285
|
|
498
|
-
AEROUSD = 286,
|
|
499
|
-
CVCUSD = 287,
|
|
500
|
-
NEIROCTOUSD = 288,
|
|
501
|
-
ARKUSD = 289,
|
|
502
|
-
NPCUSD = 290,
|
|
503
|
-
ORBSUSD = 291,
|
|
504
|
-
APUUSD = 292,
|
|
505
|
-
BSVUSD = 293
|
|
507
|
+
MOTHERUSD = 285
|
|
506
508
|
}
|
package/lib/trade/types.js
CHANGED
|
@@ -315,12 +315,4 @@ var PairIndex;
|
|
|
315
315
|
PairIndex[PairIndex["POLYXUSD"] = 283] = "POLYXUSD";
|
|
316
316
|
PairIndex[PairIndex["MOODENGUSD"] = 284] = "MOODENGUSD";
|
|
317
317
|
PairIndex[PairIndex["MOTHERUSD"] = 285] = "MOTHERUSD";
|
|
318
|
-
PairIndex[PairIndex["AEROUSD"] = 286] = "AEROUSD";
|
|
319
|
-
PairIndex[PairIndex["CVCUSD"] = 287] = "CVCUSD";
|
|
320
|
-
PairIndex[PairIndex["NEIROCTOUSD"] = 288] = "NEIROCTOUSD";
|
|
321
|
-
PairIndex[PairIndex["ARKUSD"] = 289] = "ARKUSD";
|
|
322
|
-
PairIndex[PairIndex["NPCUSD"] = 290] = "NPCUSD";
|
|
323
|
-
PairIndex[PairIndex["ORBSUSD"] = 291] = "ORBSUSD";
|
|
324
|
-
PairIndex[PairIndex["APUUSD"] = 292] = "APUUSD";
|
|
325
|
-
PairIndex[PairIndex["BSVUSD"] = 293] = "BSVUSD";
|
|
326
318
|
})(PairIndex = exports.PairIndex || (exports.PairIndex = {}));
|