@gainsnetwork/sdk 1.5.0-rc6 → 1.6.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/tradingVariables/backend.types.d.ts +16 -4
- package/lib/backend/tradingVariables/converter.js +14 -0
- package/lib/contracts/types/generated/GNSMultiCollatDiamond.d.ts +298 -1
- package/lib/contracts/types/generated/factories/GNSMultiCollatDiamond__factory.js +565 -0
- package/lib/trade/fees/tiers/converter.d.ts +16 -6
- package/lib/trade/fees/tiers/converter.js +26 -7
- package/lib/trade/fees/tiers/index.d.ts +8 -1
- package/lib/trade/fees/tiers/index.js +22 -5
- package/lib/trade/fees/tiers/types.d.ts +7 -0
- package/lib/trade/types.d.ts +5 -1
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @dev All BigNumber values are normalized to floats with appropriate precision
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.convertTraderFeeTiersData = exports.convertFeeTiersConfig = exports.convertTraderEnrollment = exports.convertTraderInfo = exports.convertFeeTierArray = exports.convertFeeTier = void 0;
|
|
7
|
+
exports.convertTraderFeeTiersData = exports.convertFeeTiersConfig = exports.convertStakingInfo = exports.convertTraderEnrollment = exports.convertTraderInfo = exports.convertFeeTierArray = exports.convertFeeTier = void 0;
|
|
8
8
|
/**
|
|
9
9
|
* @dev Converts contract fee tier data to SDK format
|
|
10
10
|
* @param contractData Contract FeeTier struct
|
|
@@ -13,7 +13,7 @@ exports.convertTraderFeeTiersData = exports.convertFeeTiersConfig = exports.conv
|
|
|
13
13
|
const convertFeeTier = (contractData) => {
|
|
14
14
|
return {
|
|
15
15
|
feeMultiplier: Number(contractData.feeMultiplier) / 1e3,
|
|
16
|
-
pointsThreshold: Number(contractData.pointsThreshold)
|
|
16
|
+
pointsThreshold: Number(contractData.pointsThreshold), // 0 precision
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
exports.convertFeeTier = convertFeeTier;
|
|
@@ -49,33 +49,52 @@ const convertTraderEnrollment = (contractData) => {
|
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
51
|
exports.convertTraderEnrollment = convertTraderEnrollment;
|
|
52
|
+
/**
|
|
53
|
+
* @dev Converts contract gns staking info to SDK format
|
|
54
|
+
* @param contractData Contract GnsStakingInfo struct
|
|
55
|
+
* @returns Normalized gns staking info
|
|
56
|
+
*/
|
|
57
|
+
const convertStakingInfo = (contractData) => {
|
|
58
|
+
return {
|
|
59
|
+
stakedGns: Number(contractData.stakedGns) / 1e18,
|
|
60
|
+
stakedVaultGns: Number(contractData.stakedVaultGns) / 1e18,
|
|
61
|
+
bonusAmount: Number(contractData.bonusAmount),
|
|
62
|
+
stakeTimestamp: Number(contractData.stakeTimestamp),
|
|
63
|
+
feeMultiplierCache: Number(contractData.feeMultiplierCache) / 1e3,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
exports.convertStakingInfo = convertStakingInfo;
|
|
52
67
|
/**
|
|
53
68
|
* @dev Converts the complete fee tiers configuration from contract format
|
|
54
|
-
* @param tiers Array of fee tiers from contract
|
|
69
|
+
* @param tiers Array of volume fee tiers from contract
|
|
55
70
|
* @param groupVolumeMultipliers Array of group volume multipliers
|
|
56
71
|
* @param currentDay Current day from contract
|
|
72
|
+
* @param stakingTiers Array of staking fee tiers from contract
|
|
57
73
|
* @returns Complete fee tiers configuration
|
|
58
74
|
*/
|
|
59
|
-
const convertFeeTiersConfig = (tiers, groupVolumeMultipliers, currentDay) => {
|
|
75
|
+
const convertFeeTiersConfig = (tiers, groupVolumeMultipliers, currentDay, stakingTiers) => {
|
|
60
76
|
return {
|
|
61
77
|
tiers: (0, exports.convertFeeTierArray)(tiers),
|
|
62
78
|
groupVolumeMultipliers: groupVolumeMultipliers.map(m => Number(m) / 1e3),
|
|
63
79
|
currentDay: Number(currentDay),
|
|
80
|
+
stakingTiers: (0, exports.convertFeeTierArray)(stakingTiers),
|
|
64
81
|
};
|
|
65
82
|
};
|
|
66
83
|
exports.convertFeeTiersConfig = convertFeeTiersConfig;
|
|
67
84
|
/**
|
|
68
|
-
* @dev Converts trader's fee tier data from contract format
|
|
85
|
+
* @dev Converts trader's volume and staking fee tier data from contract format
|
|
69
86
|
* @param traderInfo Trader info from contract
|
|
70
87
|
* @param traderDailyInfo Array of daily points info
|
|
71
88
|
* @param traderEnrollment Enrollment status from contract
|
|
72
|
-
* @
|
|
89
|
+
* @param stakingInfo Staking info from contract
|
|
90
|
+
* @returns Complete trader volume and staking fee tier data
|
|
73
91
|
*/
|
|
74
|
-
const convertTraderFeeTiersData = (traderInfo, traderDailyInfo, traderEnrollment) => {
|
|
92
|
+
const convertTraderFeeTiersData = (traderInfo, traderDailyInfo, traderEnrollment, stakingInfo) => {
|
|
75
93
|
return {
|
|
76
94
|
traderInfo: (0, exports.convertTraderInfo)(traderInfo),
|
|
77
95
|
dailyPoints: traderDailyInfo.map(points => Number(points) / 1e18),
|
|
78
96
|
traderEnrollment: (0, exports.convertTraderEnrollment)(traderEnrollment),
|
|
97
|
+
stakingInfo: (0, exports.convertStakingInfo)(stakingInfo),
|
|
79
98
|
};
|
|
80
99
|
};
|
|
81
100
|
exports.convertTraderFeeTiersData = convertTraderFeeTiersData;
|
|
@@ -5,12 +5,15 @@ export * from "./converter";
|
|
|
5
5
|
export declare const TRAILING_PERIOD_DAYS = 30;
|
|
6
6
|
export declare const FEE_MULTIPLIER_SCALE = 1;
|
|
7
7
|
export declare const MAX_FEE_TIERS = 8;
|
|
8
|
+
export declare const GNS_STAKING_COOLDOWN_SECONDS = 86400;
|
|
8
9
|
export declare const getCurrentDay: () => number;
|
|
9
10
|
export declare const getFeeTiersCount: (feeTiers: FeeTier[]) => number;
|
|
10
11
|
export declare const getFeeMultiplier: (trailingPoints: number, tiers: FeeTier[]) => number;
|
|
11
12
|
export declare const computeFeeMultiplier: (feeTiers: FeeTiers, traderFeeTiers: TraderFeeTiers) => {
|
|
12
13
|
feeMultiplier: number;
|
|
14
|
+
volumeFeeMultiplier: number;
|
|
13
15
|
trailingPoints: number;
|
|
16
|
+
stakingFeeMultiplier: number;
|
|
14
17
|
};
|
|
15
18
|
/**
|
|
16
19
|
* @dev Calculates the final fee amount after applying the trader's fee tier discount
|
|
@@ -22,9 +25,13 @@ export declare const computeFeeMultiplier: (feeTiers: FeeTiers, traderFeeTiers:
|
|
|
22
25
|
*/
|
|
23
26
|
export declare const calculateFeeAmount: (trader: string, normalFeeAmountCollateral: number, feeMultiplier?: number) => number;
|
|
24
27
|
/**
|
|
25
|
-
* @dev Helper function to get trader's fee multiplier from fee tiers data
|
|
28
|
+
* @dev Helper function to get trader's fee multiplier from volume and staking fee tiers data
|
|
26
29
|
* @param feeTiers System fee tiers configuration
|
|
27
30
|
* @param traderFeeTiers Trader's fee tier data
|
|
28
31
|
* @returns Fee multiplier (1e3 precision)
|
|
29
32
|
*/
|
|
30
33
|
export declare const getTraderFeeMultiplier: (feeTiers: FeeTiers, traderFeeTiers: TraderFeeTiers) => number;
|
|
34
|
+
export declare const isGnsStakingCooldownActive: (traderFeeTiers: TraderFeeTiers) => {
|
|
35
|
+
isActive: boolean;
|
|
36
|
+
expiryTs: number;
|
|
37
|
+
};
|
|
@@ -14,13 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getTraderFeeMultiplier = exports.calculateFeeAmount = exports.computeFeeMultiplier = exports.getFeeMultiplier = exports.getFeeTiersCount = exports.getCurrentDay = exports.MAX_FEE_TIERS = exports.FEE_MULTIPLIER_SCALE = exports.TRAILING_PERIOD_DAYS = void 0;
|
|
17
|
+
exports.isGnsStakingCooldownActive = exports.getTraderFeeMultiplier = exports.calculateFeeAmount = exports.computeFeeMultiplier = exports.getFeeMultiplier = exports.getFeeTiersCount = exports.getCurrentDay = exports.GNS_STAKING_COOLDOWN_SECONDS = exports.MAX_FEE_TIERS = exports.FEE_MULTIPLIER_SCALE = exports.TRAILING_PERIOD_DAYS = void 0;
|
|
18
18
|
const types_1 = require("./types");
|
|
19
19
|
__exportStar(require("./types"), exports);
|
|
20
20
|
__exportStar(require("./converter"), exports);
|
|
21
21
|
exports.TRAILING_PERIOD_DAYS = 30;
|
|
22
22
|
exports.FEE_MULTIPLIER_SCALE = 1;
|
|
23
23
|
exports.MAX_FEE_TIERS = 8;
|
|
24
|
+
exports.GNS_STAKING_COOLDOWN_SECONDS = 86400; // 1 day in seconds
|
|
24
25
|
const getCurrentDay = () => Math.floor(Date.now() / 1000 / 60 / 60 / 24);
|
|
25
26
|
exports.getCurrentDay = getCurrentDay;
|
|
26
27
|
const getFeeTiersCount = (feeTiers) => {
|
|
@@ -46,7 +47,7 @@ const getFeeMultiplier = (trailingPoints, tiers) => {
|
|
|
46
47
|
exports.getFeeMultiplier = getFeeMultiplier;
|
|
47
48
|
const computeFeeMultiplier = (feeTiers, traderFeeTiers) => {
|
|
48
49
|
const { currentDay, tiers } = feeTiers;
|
|
49
|
-
const { traderInfo, expiredPoints, lastDayUpdatedPoints, traderEnrollment } = traderFeeTiers;
|
|
50
|
+
const { traderInfo, expiredPoints, lastDayUpdatedPoints, traderEnrollment, stakingInfo, } = traderFeeTiers;
|
|
50
51
|
const { lastDayUpdated, trailingPoints } = traderInfo;
|
|
51
52
|
let curTrailingPoints = trailingPoints;
|
|
52
53
|
if (currentDay > lastDayUpdated) {
|
|
@@ -58,12 +59,22 @@ const computeFeeMultiplier = (feeTiers, traderFeeTiers) => {
|
|
|
58
59
|
curTrailingPoints -= expiredTrailingPoints;
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
|
-
const
|
|
62
|
+
const isTraderExcluded = traderEnrollment.status === types_1.TraderEnrollmentStatus.EXCLUDED;
|
|
63
|
+
// Fee multiplier from volume tiers
|
|
64
|
+
const volumeFeeMultiplier = isTraderExcluded
|
|
62
65
|
? exports.FEE_MULTIPLIER_SCALE
|
|
63
66
|
: (0, exports.getFeeMultiplier)(curTrailingPoints, tiers);
|
|
67
|
+
// Fee multiplier from staking tiers
|
|
68
|
+
const stakingFeeMultiplier = isTraderExcluded || stakingInfo.feeMultiplierCache === 0
|
|
69
|
+
? exports.FEE_MULTIPLIER_SCALE
|
|
70
|
+
: stakingInfo.feeMultiplierCache;
|
|
71
|
+
// Total fee multiplier is the product of both multipliers
|
|
72
|
+
const totalFeeMultiplier = volumeFeeMultiplier * stakingFeeMultiplier;
|
|
64
73
|
return {
|
|
65
|
-
feeMultiplier,
|
|
74
|
+
feeMultiplier: totalFeeMultiplier,
|
|
75
|
+
volumeFeeMultiplier: volumeFeeMultiplier,
|
|
66
76
|
trailingPoints: curTrailingPoints,
|
|
77
|
+
stakingFeeMultiplier: stakingFeeMultiplier,
|
|
67
78
|
};
|
|
68
79
|
};
|
|
69
80
|
exports.computeFeeMultiplier = computeFeeMultiplier;
|
|
@@ -85,7 +96,7 @@ const calculateFeeAmount = (trader, normalFeeAmountCollateral, feeMultiplier) =>
|
|
|
85
96
|
};
|
|
86
97
|
exports.calculateFeeAmount = calculateFeeAmount;
|
|
87
98
|
/**
|
|
88
|
-
* @dev Helper function to get trader's fee multiplier from fee tiers data
|
|
99
|
+
* @dev Helper function to get trader's fee multiplier from volume and staking fee tiers data
|
|
89
100
|
* @param feeTiers System fee tiers configuration
|
|
90
101
|
* @param traderFeeTiers Trader's fee tier data
|
|
91
102
|
* @returns Fee multiplier (1e3 precision)
|
|
@@ -95,3 +106,9 @@ const getTraderFeeMultiplier = (feeTiers, traderFeeTiers) => {
|
|
|
95
106
|
return feeMultiplier;
|
|
96
107
|
};
|
|
97
108
|
exports.getTraderFeeMultiplier = getTraderFeeMultiplier;
|
|
109
|
+
const isGnsStakingCooldownActive = (traderFeeTiers) => {
|
|
110
|
+
const now = Math.floor(Date.now() / 1000);
|
|
111
|
+
const expiryTs = traderFeeTiers.stakingInfo.stakeTimestamp + exports.GNS_STAKING_COOLDOWN_SECONDS;
|
|
112
|
+
return { isActive: now < expiryTs, expiryTs };
|
|
113
|
+
};
|
|
114
|
+
exports.isGnsStakingCooldownActive = isGnsStakingCooldownActive;
|
|
@@ -13,3 +13,10 @@ export declare enum TraderEnrollmentStatus {
|
|
|
13
13
|
export type TraderEnrollment = {
|
|
14
14
|
status: TraderEnrollmentStatus;
|
|
15
15
|
};
|
|
16
|
+
export type StakingInfo = {
|
|
17
|
+
stakedGns: number;
|
|
18
|
+
stakedVaultGns: number;
|
|
19
|
+
bonusAmount: number;
|
|
20
|
+
stakeTimestamp: number;
|
|
21
|
+
feeMultiplierCache: number;
|
|
22
|
+
};
|
package/lib/trade/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ITradingStorage, IBorrowingFees, IPairsStorage, IFundingFees } from "../contracts/types/generated/GNSMultiCollatDiamond";
|
|
2
2
|
import { BorrowingFee } from "./fees/borrowing";
|
|
3
|
-
import { FeeTier, TraderEnrollment, TraderInfo } from "./fees/tiers/types";
|
|
3
|
+
import { FeeTier, TraderEnrollment, TraderInfo, StakingInfo } from "./fees/tiers/types";
|
|
4
4
|
export type PairIndexes = {
|
|
5
5
|
[key: string]: PairIndex;
|
|
6
6
|
};
|
|
@@ -269,10 +269,14 @@ export type FeeTiers = {
|
|
|
269
269
|
tiers: FeeTier[];
|
|
270
270
|
multipliers: number[];
|
|
271
271
|
currentDay: number;
|
|
272
|
+
stakingTiers: FeeTier[];
|
|
273
|
+
gnsVaultAddress?: string;
|
|
274
|
+
useGnsVaultBalance?: boolean;
|
|
272
275
|
};
|
|
273
276
|
export type TraderFeeTiers = {
|
|
274
277
|
traderEnrollment: TraderEnrollment;
|
|
275
278
|
traderInfo: TraderInfo;
|
|
279
|
+
stakingInfo: StakingInfo;
|
|
276
280
|
inboundPoints: number;
|
|
277
281
|
outboundPoints: number;
|
|
278
282
|
lastDayUpdatedPoints: number;
|