@riocrypto/common-server 1.0.778 → 1.0.780
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.
|
@@ -13,16 +13,26 @@ exports.calculateAggregateVolumeAndRevenue = void 0;
|
|
|
13
13
|
const common_1 = require("@riocrypto/common");
|
|
14
14
|
const order_1 = require("../models/order");
|
|
15
15
|
const calculateAggregateVolumeAndRevenue = (mongoose, days, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
var _a;
|
|
16
17
|
const startDate = new Date();
|
|
17
18
|
startDate.setDate(startDate.getDate() - days); // Subtract 14 days from current date
|
|
18
19
|
const Order = (0, order_1.buildOrder)(mongoose);
|
|
19
20
|
let orders;
|
|
20
21
|
if (user) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
if ((_a = user.attributes) === null || _a === void 0 ? void 0 : _a.includes(common_1.UserAttribute.broker)) {
|
|
23
|
+
orders = yield Order.find({
|
|
24
|
+
$or: [{ userId: user.id }, { brokerId: user.id }],
|
|
25
|
+
status: common_1.OrderStatus.Complete,
|
|
26
|
+
createdAt: { $gte: startDate },
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
orders = yield Order.find({
|
|
31
|
+
userId: user.id,
|
|
32
|
+
status: common_1.OrderStatus.Complete,
|
|
33
|
+
createdAt: { $gte: startDate },
|
|
34
|
+
});
|
|
35
|
+
}
|
|
26
36
|
}
|
|
27
37
|
else {
|
|
28
38
|
orders = yield Order.find({
|
|
@@ -16,10 +16,16 @@ const ccxt_client_1 = require("../clients/ccxt-client");
|
|
|
16
16
|
const getNetworkFees = (crypto, cryptoPrice, conversionRateToUSD) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
17
|
let withdrawFee;
|
|
18
18
|
const fireblocksClient = yield (0, fireblocks_client_1.buildFireblocksClient)();
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
if ([
|
|
20
|
+
common_1.Crypto.USDTEthereum,
|
|
21
|
+
common_1.Crypto.USDCPolygon,
|
|
22
|
+
common_1.Crypto.USDTPolygon,
|
|
23
|
+
common_1.Crypto.USDTEthereum,
|
|
24
|
+
common_1.Crypto.USDTEthereum,
|
|
25
|
+
].includes(crypto)) {
|
|
26
|
+
const address = crypto === common_1.Crypto.USDCSolana
|
|
27
|
+
? "HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH"
|
|
28
|
+
: "0x66ECBd38905CC32249ddd6f4f0B4A3DdDDCbd608";
|
|
23
29
|
withdrawFee = yield fireblocksClient.estimateWithdrawFee(crypto, address, 100);
|
|
24
30
|
if (!withdrawFee) {
|
|
25
31
|
throw new Error("Withdraw fee not set");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Country, Fiat, Processor, User } from "@riocrypto/common";
|
|
2
2
|
import { Mongoose } from "mongoose";
|
|
3
3
|
export declare const getPlatformAndPartnerFees: (mongoose: Mongoose, amountFiat: number, fiat: Fiat, processor: Processor, country: Country, discount: number, partnerId?: string, brokerId?: string, user?: User) => Promise<{
|
|
4
|
-
platformFeeFiat: number
|
|
4
|
+
platformFeeFiat: number;
|
|
5
5
|
platformFeeFiatTax: number;
|
|
6
6
|
partnerFeeFiat: number;
|
|
7
7
|
feesComped: boolean;
|
|
@@ -18,7 +18,7 @@ const partner_1 = require("../models/partner");
|
|
|
18
18
|
const user_1 = require("../models/user");
|
|
19
19
|
const calculate_aggregate_volume_1 = require("./calculate-aggregate-volume");
|
|
20
20
|
const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, country, discount, partnerId, brokerId, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
var _a;
|
|
21
|
+
var _a, _b;
|
|
22
22
|
let platformFeeFiat;
|
|
23
23
|
let platformFeeFiatTax = 0;
|
|
24
24
|
let partnerFeeFiat = 0;
|
|
@@ -63,13 +63,21 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
|
|
|
63
63
|
}
|
|
64
64
|
else if (brokerId) {
|
|
65
65
|
const User = (0, user_1.buildUser)(mongoose);
|
|
66
|
-
const
|
|
67
|
-
if (!
|
|
66
|
+
const broker = yield User.findById(brokerId);
|
|
67
|
+
if (!broker) {
|
|
68
68
|
throw new Error("Broker customer not found");
|
|
69
69
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
let volume;
|
|
71
|
+
if ((_a = broker.attributes) === null || _a === void 0 ? void 0 : _a.includes(common_1.UserAttribute.summedVolumeFees)) {
|
|
72
|
+
const volumeAndRevenue = yield (0, calculate_aggregate_volume_1.calculateAggregateVolumeAndRevenue)(mongoose, 14, user);
|
|
73
|
+
volume = volumeAndRevenue.volume;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
volume = Number(amountUSD);
|
|
77
|
+
}
|
|
78
|
+
if (broker.platformFeeRanges) {
|
|
79
|
+
for (const range of broker.platformFeeRanges) {
|
|
80
|
+
if (range.min <= Number(volume) && range.max >= Number(volume)) {
|
|
73
81
|
if (discount) {
|
|
74
82
|
if (discount > range.fee) {
|
|
75
83
|
throw new Error("Discount cannot be greater than platform fee");
|
|
@@ -89,7 +97,7 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
|
|
|
89
97
|
}
|
|
90
98
|
else if (user === null || user === void 0 ? void 0 : user.platformFeeRanges) {
|
|
91
99
|
let volume;
|
|
92
|
-
if ((
|
|
100
|
+
if ((_b = user === null || user === void 0 ? void 0 : user.attributes) === null || _b === void 0 ? void 0 : _b.includes(common_1.UserAttribute.summedVolumeFees)) {
|
|
93
101
|
const volumeAndRevenue = yield (0, calculate_aggregate_volume_1.calculateAggregateVolumeAndRevenue)(mongoose, 14, user);
|
|
94
102
|
volume = volumeAndRevenue.volume;
|
|
95
103
|
}
|
|
@@ -143,7 +151,7 @@ const getPlatformAndPartnerFees = (mongoose, amountFiat, fiat, processor, countr
|
|
|
143
151
|
}
|
|
144
152
|
}
|
|
145
153
|
return {
|
|
146
|
-
platformFeeFiat,
|
|
154
|
+
platformFeeFiat: platformFeeFiat,
|
|
147
155
|
platformFeeFiatTax,
|
|
148
156
|
partnerFeeFiat,
|
|
149
157
|
feesComped,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.780",
|
|
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.687",
|
|
28
28
|
"@types/express": "^4.17.13",
|
|
29
29
|
"axios": "^0.27.2",
|
|
30
30
|
"ccxt": "^3.0.30",
|