@gainsnetwork/sdk 0.1.19-rc1 → 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 { FeeTier, TraderDailyInfo, TraderInfo } from "./types";
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: (traderInfo: TraderInfo, traderDailyInfo: Record<number, TraderDailyInfo>, feeTiers: FeeTier[]) => number;
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 = (traderInfo, traderDailyInfo, feeTiers) => {
19
- const currentDay = (0, exports.getCurrentDay)();
20
- if (currentDay > traderInfo.lastDayUpdated) {
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 (traderInfo.lastDayUpdated >= earliestActiveDay) {
24
- curTrailingPoints =
25
- traderInfo.trailingPoints +
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)(feeTiers); i > 0; --i) {
37
- const feeTier = feeTiers[i - 1];
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 newFeeMultiplier;
38
+ return {
39
+ feeMultiplier: newFeeMultiplier,
40
+ trailingPoints: curTrailingPoints,
41
+ };
44
42
  }
45
- return exports.FEE_MULTIPLIER_SCALE;
43
+ return {
44
+ feeMultiplier: exports.FEE_MULTIPLIER_SCALE,
45
+ trailingPoints,
46
+ };
46
47
  };
47
48
  exports.computeFeeMulitplier = computeFeeMulitplier;
@@ -6,7 +6,3 @@ export type TraderInfo = {
6
6
  lastDayUpdated: number;
7
7
  trailingPoints: number;
8
8
  };
9
- export type TraderDailyInfo = {
10
- feeMultiplierCache: number;
11
- points: number;
12
- };
@@ -190,6 +190,7 @@ export type TraderFeeTiers = {
190
190
  traderInfo: TraderInfo;
191
191
  inboundPoints: number;
192
192
  outboundPoints: number;
193
+ lastDayUpdatedPoints: number;
193
194
  expiredPoints: number[];
194
195
  };
195
196
  export declare enum PairIndex {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gainsnetwork/sdk",
3
- "version": "0.1.19-rc1",
3
+ "version": "0.1.19-rc3",
4
4
  "description": "Gains Network SDK",
5
5
  "main": "./lib/index.js",
6
6
  "files": [