@gainsnetwork/sdk 0.1.19-rc2 → 0.1.19-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.
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FeeTiers, TraderFeeTiers } from "../../types";
|
|
2
|
+
import { FeeTier } from "./types";
|
|
2
3
|
export declare const TRAILING_PERIOD_DAYS = 30;
|
|
3
4
|
export declare const FEE_MULTIPLIER_SCALE = 1;
|
|
4
5
|
export declare const MAX_FEE_TIERS = 8;
|
|
5
6
|
export declare const getCurrentDay: () => number;
|
|
6
7
|
export declare const getFeeTiersCount: (feeTiers: FeeTier[]) => number;
|
|
7
|
-
export declare const computeFeeMulitplier: (
|
|
8
|
+
export declare const computeFeeMulitplier: (feeTiers: FeeTiers, traderFeeTiers: TraderFeeTiers) => {
|
|
9
|
+
feeMultiplier: number;
|
|
10
|
+
trailingPoints: number;
|
|
11
|
+
};
|
|
@@ -15,33 +15,34 @@ const getFeeTiersCount = (feeTiers) => {
|
|
|
15
15
|
return 0;
|
|
16
16
|
};
|
|
17
17
|
exports.getFeeTiersCount = getFeeTiersCount;
|
|
18
|
-
const computeFeeMulitplier = (
|
|
19
|
-
const currentDay =
|
|
20
|
-
|
|
18
|
+
const computeFeeMulitplier = (feeTiers, traderFeeTiers) => {
|
|
19
|
+
const { currentDay, tiers } = feeTiers;
|
|
20
|
+
const { traderInfo, expiredPoints, lastDayUpdatedPoints } = traderFeeTiers;
|
|
21
|
+
const { lastDayUpdated, trailingPoints } = traderInfo;
|
|
22
|
+
if (currentDay > lastDayUpdated) {
|
|
21
23
|
let curTrailingPoints = 0;
|
|
22
24
|
const earliestActiveDay = currentDay - exports.TRAILING_PERIOD_DAYS;
|
|
23
|
-
if (
|
|
24
|
-
curTrailingPoints =
|
|
25
|
-
|
|
26
|
-
traderDailyInfo[traderInfo.lastDayUpdated].points;
|
|
27
|
-
const earliestOutdatedDay = traderInfo.lastDayUpdated - exports.TRAILING_PERIOD_DAYS;
|
|
28
|
-
const lastOutdatedDay = earliestActiveDay - 1;
|
|
29
|
-
let expiredTrailingPoints = 0;
|
|
30
|
-
for (let i = earliestOutdatedDay; i <= lastOutdatedDay; ++i) {
|
|
31
|
-
expiredTrailingPoints += traderDailyInfo[i].points;
|
|
32
|
-
}
|
|
25
|
+
if (lastDayUpdated >= earliestActiveDay) {
|
|
26
|
+
curTrailingPoints = trailingPoints + lastDayUpdatedPoints;
|
|
27
|
+
const expiredTrailingPoints = expiredPoints.reduce((acc, points) => acc + points, 0);
|
|
33
28
|
curTrailingPoints -= expiredTrailingPoints;
|
|
34
29
|
}
|
|
35
30
|
let newFeeMultiplier = exports.FEE_MULTIPLIER_SCALE;
|
|
36
|
-
for (let i = (0, exports.getFeeTiersCount)(
|
|
37
|
-
const feeTier =
|
|
31
|
+
for (let i = (0, exports.getFeeTiersCount)(tiers); i > 0; --i) {
|
|
32
|
+
const feeTier = tiers[i - 1];
|
|
38
33
|
if (curTrailingPoints >= feeTier.pointsThreshold) {
|
|
39
34
|
newFeeMultiplier = feeTier.feeMultiplier;
|
|
40
35
|
break;
|
|
41
36
|
}
|
|
42
37
|
}
|
|
43
|
-
return
|
|
38
|
+
return {
|
|
39
|
+
feeMultiplier: newFeeMultiplier,
|
|
40
|
+
trailingPoints: curTrailingPoints,
|
|
41
|
+
};
|
|
44
42
|
}
|
|
45
|
-
return
|
|
43
|
+
return {
|
|
44
|
+
feeMultiplier: exports.FEE_MULTIPLIER_SCALE,
|
|
45
|
+
trailingPoints,
|
|
46
|
+
};
|
|
46
47
|
};
|
|
47
48
|
exports.computeFeeMulitplier = computeFeeMulitplier;
|