@riocrypto/common-server 1.0.723 → 1.0.725
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,3 +1,6 @@
|
|
|
1
1
|
import { User } from "@riocrypto/common";
|
|
2
2
|
import { Mongoose } from "mongoose";
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const calculateAggregateVolumeAndRevenue: (mongoose: Mongoose, days: number, user?: User) => Promise<{
|
|
4
|
+
volume: number;
|
|
5
|
+
revenue: number;
|
|
6
|
+
}>;
|
|
@@ -9,10 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.calculateAggregateVolumeAndRevenue = void 0;
|
|
13
13
|
const common_1 = require("@riocrypto/common");
|
|
14
14
|
const order_1 = require("../models/order");
|
|
15
|
-
const
|
|
15
|
+
const calculateAggregateVolumeAndRevenue = (mongoose, days, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
16
|
const startDate = new Date();
|
|
17
17
|
startDate.setDate(startDate.getDate() - days); // Subtract 14 days from current date
|
|
18
18
|
const Order = (0, order_1.buildOrder)(mongoose);
|
|
@@ -30,7 +30,9 @@ const calculateAggregateVolume = (mongoose, days, user) => __awaiter(void 0, voi
|
|
|
30
30
|
createdAt: { $gte: startDate },
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
let volume = 0;
|
|
34
|
+
let revenue = 0;
|
|
35
|
+
orders.forEach((order) => {
|
|
34
36
|
var _a, _b, _c, _d, _e;
|
|
35
37
|
const fiatAmount = order.amountFiat || 0;
|
|
36
38
|
const conversionRate = order.conversionRateToUSD || 0;
|
|
@@ -39,6 +41,8 @@ const calculateAggregateVolume = (mongoose, days, user) => __awaiter(void 0, voi
|
|
|
39
41
|
const platformTax = ((_c = order.fees) === null || _c === void 0 ? void 0 : _c.platformFeeFiatTax) || 0;
|
|
40
42
|
const processingFee = ((_d = order.fees) === null || _d === void 0 ? void 0 : _d.processingFeeFiat) || 0;
|
|
41
43
|
const transferFee = ((_e = order.fees) === null || _e === void 0 ? void 0 : _e.transferFeeFiat) || 0;
|
|
44
|
+
const price = order.price || 0;
|
|
45
|
+
const amountCrypto = order.amountCrypto || 0;
|
|
42
46
|
const sellVolume = (fiatAmount +
|
|
43
47
|
partnerFee +
|
|
44
48
|
platformFee +
|
|
@@ -47,9 +51,13 @@ const calculateAggregateVolume = (mongoose, days, user) => __awaiter(void 0, voi
|
|
|
47
51
|
transferFee) *
|
|
48
52
|
conversionRate;
|
|
49
53
|
const buyVolume = fiatAmount * conversionRate;
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
volume += sellVolume + buyVolume;
|
|
55
|
+
const sellRevenue = amountCrypto * price * platformFee * conversionRate;
|
|
56
|
+
const buyRevenue = fiatAmount * platformFee * conversionRate;
|
|
57
|
+
revenue += sellRevenue + buyRevenue;
|
|
58
|
+
});
|
|
52
59
|
const volumeResult = volume || 0;
|
|
53
|
-
|
|
60
|
+
const revenueResult = revenue || 0;
|
|
61
|
+
return { volume: volumeResult, revenue: revenueResult };
|
|
54
62
|
});
|
|
55
|
-
exports.
|
|
63
|
+
exports.calculateAggregateVolumeAndRevenue = calculateAggregateVolumeAndRevenue;
|
|
@@ -60,7 +60,8 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
|
|
|
60
60
|
else if (user === null || user === void 0 ? void 0 : user.platformFeeRanges) {
|
|
61
61
|
let volume;
|
|
62
62
|
if ((_a = user === null || user === void 0 ? void 0 : user.attributes) === null || _a === void 0 ? void 0 : _a.includes(common_1.UserAttribute.summedVolumeFees)) {
|
|
63
|
-
|
|
63
|
+
const volumeAndRevenue = yield (0, calculate_aggregate_volume_1.calculateAggregateVolumeAndRevenue)(mongoose, 14, user);
|
|
64
|
+
volume = volumeAndRevenue.volume;
|
|
64
65
|
}
|
|
65
66
|
else {
|
|
66
67
|
volume = Number(amountUSD);
|
package/build/models/user.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ interface UserAttrs {
|
|
|
26
26
|
COIFile?: string;
|
|
27
27
|
KYCReportFile?: string;
|
|
28
28
|
authorizedPhoneNumbers?: string[];
|
|
29
|
+
notificationUrl?: string;
|
|
29
30
|
}
|
|
30
31
|
interface UserModel extends Model<UserDoc> {
|
|
31
32
|
build(attrs: UserAttrs): UserDoc;
|
|
@@ -57,6 +58,7 @@ interface UserDoc extends Document {
|
|
|
57
58
|
COIFile?: string;
|
|
58
59
|
KYCReportFile?: string;
|
|
59
60
|
authorizedPhoneNumbers?: string[];
|
|
61
|
+
notificationUrl?: string;
|
|
60
62
|
}
|
|
61
63
|
declare const buildUser: (mongoose: Mongoose) => UserModel;
|
|
62
64
|
export { buildUser, UserDoc };
|
package/build/models/user.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.725",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@aws-sdk/client-s3": "^3.297.0",
|
|
25
25
|
"@everapi/currencyapi-js": "^1.0.6",
|
|
26
26
|
"@google-cloud/storage": "^6.9.5",
|
|
27
|
-
"@riocrypto/common": "^1.0.
|
|
27
|
+
"@riocrypto/common": "^1.0.644",
|
|
28
28
|
"@types/express": "^4.17.13",
|
|
29
29
|
"axios": "^0.27.2",
|
|
30
30
|
"ccxt": "^3.0.30",
|