@riocrypto/common-server 1.0.1308 → 1.0.1311
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/build/helpers/get-exchange-rates.d.ts +1 -2
- package/build/helpers/get-exchange-rates.js +1 -7
- package/build/helpers/get-user-transaction-limits.d.ts +4 -0
- package/build/helpers/get-user-transaction-limits.js +45 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/models/market-data.d.ts +10 -3
- package/package.json +2 -2
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Fiat } from "@riocrypto/common";
|
|
2
|
-
export declare const getExchangeRates: (from: Fiat, to: Fiat
|
|
2
|
+
export declare const getExchangeRates: (from: Fiat, to: Fiat) => Promise<{
|
|
3
3
|
conversionRate: number;
|
|
4
4
|
conversionRateWithMarkups?: number | undefined;
|
|
5
|
-
safestPrice?: number | undefined;
|
|
6
5
|
}>;
|
|
@@ -13,18 +13,12 @@ exports.getExchangeRates = void 0;
|
|
|
13
13
|
const common_1 = require("@riocrypto/common");
|
|
14
14
|
const currency_api_client_1 = require("../clients/currency-api-client");
|
|
15
15
|
const kapstar_client_1 = require("../clients/kapstar-client");
|
|
16
|
-
const
|
|
17
|
-
const getExchangeRates = (from, to, noMarkups) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const getExchangeRates = (from, to) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
17
|
const currencyAPIClient = yield (0, currency_api_client_1.buildCurrencyAPIClient)();
|
|
19
18
|
const kapstarClient = yield (0, kapstar_client_1.buildKapstarClient)();
|
|
20
19
|
const conversionRate = to === common_1.Fiat.BRL
|
|
21
20
|
? yield kapstarClient.getBRLExchangeRateUSD()
|
|
22
21
|
: yield currencyAPIClient.convert(from, to);
|
|
23
|
-
if (noMarkups) {
|
|
24
|
-
return {
|
|
25
|
-
conversionRate,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
22
|
let conversionRateWithMarkups = conversionRate;
|
|
29
23
|
// Time based markups
|
|
30
24
|
if (from === common_1.Fiat.PEN || to === common_1.Fiat.PEN) {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getUserTransactionLimits = void 0;
|
|
16
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
17
|
+
const user_1 = require("../models/user");
|
|
18
|
+
const common_1 = require("@riocrypto/common");
|
|
19
|
+
const calculate_aggregate_volume_and_revenue_1 = require("./calculate-aggregate-volume-and-revenue");
|
|
20
|
+
const getUserTransactionLimits = (id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const User = (0, user_1.buildUser)(mongoose_1.default);
|
|
22
|
+
const user = yield User.findById(id);
|
|
23
|
+
if (!user) {
|
|
24
|
+
throw new common_1.NotFoundError("User");
|
|
25
|
+
}
|
|
26
|
+
const { volume } = yield (0, calculate_aggregate_volume_and_revenue_1.calculateAggregateVolumeAndRevenue)(mongoose_1.default, 30, user, true);
|
|
27
|
+
const { riskTier } = user;
|
|
28
|
+
let limit = 0;
|
|
29
|
+
if (riskTier === common_1.RiskTier.High) {
|
|
30
|
+
limit = 3000;
|
|
31
|
+
}
|
|
32
|
+
else if (riskTier === common_1.RiskTier.Medium) {
|
|
33
|
+
limit = 75000;
|
|
34
|
+
}
|
|
35
|
+
else if (riskTier === common_1.RiskTier.Low) {
|
|
36
|
+
if (user.hasPassedEDD) {
|
|
37
|
+
limit = 100000000;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
limit = 100000;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return { limit, used: volume };
|
|
44
|
+
});
|
|
45
|
+
exports.getUserTransactionLimits = getUserTransactionLimits;
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -84,3 +84,4 @@ __exportStar(require("./helpers/calculate-weekly-volume-and-revenue"), exports);
|
|
|
84
84
|
__exportStar(require("./helpers/get-exchange-rates"), exports);
|
|
85
85
|
__exportStar(require("./helpers/get-user"), exports);
|
|
86
86
|
__exportStar(require("./helpers/unescape"), exports);
|
|
87
|
+
__exportStar(require("./helpers/get-user-transaction-limits"), exports);
|
|
@@ -3,6 +3,7 @@ interface MarketDataAttrs {
|
|
|
3
3
|
conversionRatesToUSD: {
|
|
4
4
|
[key: string]: {
|
|
5
5
|
value: number;
|
|
6
|
+
valueWithMarkups: number;
|
|
6
7
|
lastUpdated: Date;
|
|
7
8
|
};
|
|
8
9
|
};
|
|
@@ -16,11 +17,17 @@ interface MarketDataModel extends Model<MarketDataDoc> {
|
|
|
16
17
|
}
|
|
17
18
|
interface MarketDataDoc extends Document {
|
|
18
19
|
_id: string;
|
|
19
|
-
lastUpdated: Date;
|
|
20
20
|
conversionRatesToUSD: {
|
|
21
|
-
[key: string]:
|
|
21
|
+
[key: string]: {
|
|
22
|
+
value: number;
|
|
23
|
+
valueWithMarkups: number;
|
|
24
|
+
lastUpdated: Date;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
totalFireblocksLiquidityUSD: {
|
|
28
|
+
value: number;
|
|
29
|
+
lastUpdated: Date;
|
|
22
30
|
};
|
|
23
|
-
totalFireblocksLiquidityUSD: number;
|
|
24
31
|
}
|
|
25
32
|
declare const buildMarketData: (mongoose: Mongoose) => MarketDataModel;
|
|
26
33
|
export { buildMarketData, MarketDataDoc };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1311",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@everapi/currencyapi-js": "^1.0.6",
|
|
28
28
|
"@google-cloud/storage": "^6.9.5",
|
|
29
29
|
"@google-cloud/vision": "^4.0.2",
|
|
30
|
-
"@riocrypto/common": "^1.0.
|
|
30
|
+
"@riocrypto/common": "^1.0.1178",
|
|
31
31
|
"@types/express": "^4.17.13",
|
|
32
32
|
"axios": "^0.27.2",
|
|
33
33
|
"ccxt": "^3.0.30",
|