@riocrypto/common-server 1.0.1260 → 1.0.1262
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/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/build/models/circle-address-book-recipient.d.ts +23 -0
- package/build/models/circle-address-book-recipient.js +49 -0
- package/package.json +2 -2
- package/build/helpers/get-platform-fees.d.ts +0 -7
- package/build/helpers/get-platform-fees.js +0 -168
package/build/index.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export * from "./models/bitso-receiving-account";
|
|
|
37
37
|
export * from "./models/bitso-fx-order";
|
|
38
38
|
export * from "./models/internal-swap";
|
|
39
39
|
export * from "./models/bitso-mxn-withdrawal";
|
|
40
|
+
export * from "./models/circle-address-book-recipient";
|
|
40
41
|
export * from "./clients/bitstamp-client";
|
|
41
42
|
export * from "./clients/ccxt-client";
|
|
42
43
|
export * from "./clients/kushki-client";
|
|
@@ -57,7 +58,6 @@ export * from "./clients/cluster-client";
|
|
|
57
58
|
export * from "./clients/cosigner-client";
|
|
58
59
|
export * from "./clients/bitso-client";
|
|
59
60
|
export * from "./helpers/get-user-helper";
|
|
60
|
-
export * from "./helpers/get-platform-fees";
|
|
61
61
|
export * from "./helpers/get-processor-fees";
|
|
62
62
|
export * from "./helpers/get-network-fees";
|
|
63
63
|
export * from "./helpers/calculate-aggregate-volume-and-revenue";
|
package/build/index.js
CHANGED
|
@@ -53,6 +53,7 @@ __exportStar(require("./models/bitso-receiving-account"), exports);
|
|
|
53
53
|
__exportStar(require("./models/bitso-fx-order"), exports);
|
|
54
54
|
__exportStar(require("./models/internal-swap"), exports);
|
|
55
55
|
__exportStar(require("./models/bitso-mxn-withdrawal"), exports);
|
|
56
|
+
__exportStar(require("./models/circle-address-book-recipient"), exports);
|
|
56
57
|
__exportStar(require("./clients/bitstamp-client"), exports);
|
|
57
58
|
__exportStar(require("./clients/ccxt-client"), exports);
|
|
58
59
|
__exportStar(require("./clients/kushki-client"), exports);
|
|
@@ -73,7 +74,6 @@ __exportStar(require("./clients/cluster-client"), exports);
|
|
|
73
74
|
__exportStar(require("./clients/cosigner-client"), exports);
|
|
74
75
|
__exportStar(require("./clients/bitso-client"), exports);
|
|
75
76
|
__exportStar(require("./helpers/get-user-helper"), exports);
|
|
76
|
-
__exportStar(require("./helpers/get-platform-fees"), exports);
|
|
77
77
|
__exportStar(require("./helpers/get-processor-fees"), exports);
|
|
78
78
|
__exportStar(require("./helpers/get-network-fees"), exports);
|
|
79
79
|
__exportStar(require("./helpers/calculate-aggregate-volume-and-revenue"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CircleChain } from "@riocrypto/common";
|
|
2
|
+
import { Mongoose, Model, Document } from "mongoose";
|
|
3
|
+
interface CircleAddressBookRecipientAttrs {
|
|
4
|
+
createdAt: Date;
|
|
5
|
+
userId: string;
|
|
6
|
+
circleRecipientId: string;
|
|
7
|
+
address: string;
|
|
8
|
+
chain: CircleChain;
|
|
9
|
+
status: "pending" | "inactive" | "active" | "denied";
|
|
10
|
+
}
|
|
11
|
+
interface CircleAddressBookRecipientDoc extends Document {
|
|
12
|
+
createdAt: Date;
|
|
13
|
+
userId: string;
|
|
14
|
+
circleRecipientId: string;
|
|
15
|
+
address: string;
|
|
16
|
+
chain: CircleChain;
|
|
17
|
+
status: "pending" | "inactive" | "active" | "denied";
|
|
18
|
+
}
|
|
19
|
+
interface CircleAddressBookRecipientModel extends Model<CircleAddressBookRecipientDoc> {
|
|
20
|
+
build(attrs: CircleAddressBookRecipientAttrs): CircleAddressBookRecipientDoc;
|
|
21
|
+
}
|
|
22
|
+
declare const buildCircleAddressBookRecipient: (mongoose: Mongoose) => CircleAddressBookRecipientModel;
|
|
23
|
+
export { buildCircleAddressBookRecipient, CircleAddressBookRecipientDoc };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildCircleAddressBookRecipient = void 0;
|
|
4
|
+
const buildCircleAddressBookRecipient = (mongoose) => {
|
|
5
|
+
// if model is already defined, return it
|
|
6
|
+
if (mongoose.models.CircleAddressBookRecipient) {
|
|
7
|
+
return mongoose.model("CircleAddressBookRecipient");
|
|
8
|
+
}
|
|
9
|
+
const CircleAddressBookRecipientSchema = new mongoose.Schema({
|
|
10
|
+
userId: {
|
|
11
|
+
type: String,
|
|
12
|
+
required: true,
|
|
13
|
+
},
|
|
14
|
+
circleRecipientId: {
|
|
15
|
+
type: String,
|
|
16
|
+
required: true,
|
|
17
|
+
},
|
|
18
|
+
address: {
|
|
19
|
+
type: String,
|
|
20
|
+
required: true,
|
|
21
|
+
},
|
|
22
|
+
chain: {
|
|
23
|
+
type: String,
|
|
24
|
+
required: true,
|
|
25
|
+
},
|
|
26
|
+
status: {
|
|
27
|
+
type: String,
|
|
28
|
+
required: true,
|
|
29
|
+
},
|
|
30
|
+
createdAt: {
|
|
31
|
+
type: mongoose.Schema.Types.Date,
|
|
32
|
+
required: true,
|
|
33
|
+
},
|
|
34
|
+
}, {
|
|
35
|
+
toJSON: {
|
|
36
|
+
transform(doc, ret) {
|
|
37
|
+
ret.id = ret._id.valueOf();
|
|
38
|
+
delete ret._id;
|
|
39
|
+
delete ret.__v;
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
CircleAddressBookRecipientSchema.statics.build = (attrs) => {
|
|
44
|
+
return new CircleAddressBookRecipient(attrs);
|
|
45
|
+
};
|
|
46
|
+
const CircleAddressBookRecipient = mongoose.model("CircleAddressBookRecipient", CircleAddressBookRecipientSchema);
|
|
47
|
+
return CircleAddressBookRecipient;
|
|
48
|
+
};
|
|
49
|
+
exports.buildCircleAddressBookRecipient = buildCircleAddressBookRecipient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1262",
|
|
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.1143",
|
|
31
31
|
"@types/express": "^4.17.13",
|
|
32
32
|
"axios": "^0.27.2",
|
|
33
33
|
"ccxt": "^3.0.30",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Country, Fiat, Processor, Side, User } from "@riocrypto/common";
|
|
2
|
-
import { Mongoose } from "mongoose";
|
|
3
|
-
export declare const getPlatformFees: (mongoose: Mongoose, conversionRateToUSD: number, amountFiat: number, fiat: Fiat, processor: Processor, side: Side, country: Country, brokerId?: string, user?: User, markup?: number, discount?: number) => Promise<{
|
|
4
|
-
platformFeeFiat: number;
|
|
5
|
-
platformFeeFiatTax: number;
|
|
6
|
-
feesComped: boolean;
|
|
7
|
-
}>;
|
|
@@ -1,168 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getPlatformFees = void 0;
|
|
13
|
-
const rio_settings_1 = require("../models/rio-settings");
|
|
14
|
-
const common_1 = require("@riocrypto/common");
|
|
15
|
-
const user_1 = require("../models/user");
|
|
16
|
-
const calculate_aggregate_volume_and_revenue_1 = require("./calculate-aggregate-volume-and-revenue");
|
|
17
|
-
const getPlatformFees = (mongoose, conversionRateToUSD, amountFiat, fiat, processor, side, country, brokerId, user, markup, discount) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
var _a, _b;
|
|
19
|
-
let platformFeeFiat;
|
|
20
|
-
let platformFeeFiatTax = 0;
|
|
21
|
-
let feesComped = false;
|
|
22
|
-
let amountUSD;
|
|
23
|
-
const RioSettings = (0, rio_settings_1.buildRioSettings)(mongoose);
|
|
24
|
-
const rioSettings = yield RioSettings.findOne();
|
|
25
|
-
if (!rioSettings) {
|
|
26
|
-
throw new common_1.RioSettingsNotFoundError();
|
|
27
|
-
}
|
|
28
|
-
if (discount && markup) {
|
|
29
|
-
throw new common_1.GenericInputError("Cannot specify markup and discount");
|
|
30
|
-
}
|
|
31
|
-
amountUSD = amountFiat * conversionRateToUSD;
|
|
32
|
-
if (!amountUSD) {
|
|
33
|
-
throw new common_1.GenericInternalError("Could not convert amount to USD");
|
|
34
|
-
}
|
|
35
|
-
if (brokerId) {
|
|
36
|
-
const User = (0, user_1.buildUser)(mongoose);
|
|
37
|
-
const broker = yield User.findById(brokerId);
|
|
38
|
-
if (!broker) {
|
|
39
|
-
throw new common_1.NotFoundError("Broker customer");
|
|
40
|
-
}
|
|
41
|
-
let volume;
|
|
42
|
-
if ((_a = broker.attributes) === null || _a === void 0 ? void 0 : _a.includes(common_1.UserAttribute.summedVolumeFees)) {
|
|
43
|
-
const volumeAndRevenue = yield (0, calculate_aggregate_volume_and_revenue_1.calculateAggregateVolumeAndRevenue)(mongoose, 14, user);
|
|
44
|
-
volume = volumeAndRevenue.volume;
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
volume = Number(amountUSD);
|
|
48
|
-
}
|
|
49
|
-
if (broker.platformFeeRanges &&
|
|
50
|
-
broker.platformFeeRanges[country] &&
|
|
51
|
-
broker.platformFeeRanges[country][side]) {
|
|
52
|
-
for (const range of broker.platformFeeRanges[country][side]) {
|
|
53
|
-
if (range.min <= Number(volume) && range.max >= Number(volume)) {
|
|
54
|
-
if (discount) {
|
|
55
|
-
if (discount > range.fee) {
|
|
56
|
-
throw new common_1.GenericInputError("Discount cannot be greater than platform fee");
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
const netFee = range.fee - discount;
|
|
60
|
-
platformFeeFiat = amountFiat * netFee;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else if (markup) {
|
|
64
|
-
const netFee = range.fee + markup;
|
|
65
|
-
platformFeeFiat = amountFiat * netFee;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
platformFeeFiat = amountFiat * range.fee;
|
|
69
|
-
}
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// @ts-ignore
|
|
75
|
-
if (platformFeeFiat === undefined) {
|
|
76
|
-
let netPlatformFee = rioSettings.platformFee;
|
|
77
|
-
if (discount) {
|
|
78
|
-
netPlatformFee -= discount;
|
|
79
|
-
}
|
|
80
|
-
if (markup) {
|
|
81
|
-
netPlatformFee += markup;
|
|
82
|
-
}
|
|
83
|
-
if (netPlatformFee < 0) {
|
|
84
|
-
throw new common_1.GenericInputError("Discount cannot be greater than platform fee");
|
|
85
|
-
}
|
|
86
|
-
platformFeeFiat = amountFiat * netPlatformFee;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else if ((user === null || user === void 0 ? void 0 : user.platformFeeRanges) &&
|
|
90
|
-
user.platformFeeRanges[country] &&
|
|
91
|
-
user.platformFeeRanges[country][side]) {
|
|
92
|
-
let volume;
|
|
93
|
-
if ((_b = user === null || user === void 0 ? void 0 : user.attributes) === null || _b === void 0 ? void 0 : _b.includes(common_1.UserAttribute.summedVolumeFees)) {
|
|
94
|
-
const volumeAndRevenue = yield (0, calculate_aggregate_volume_and_revenue_1.calculateAggregateVolumeAndRevenue)(mongoose, 14, user);
|
|
95
|
-
volume = volumeAndRevenue.volume;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
volume = Number(amountUSD);
|
|
99
|
-
}
|
|
100
|
-
for (const range of user.platformFeeRanges[country][side]) {
|
|
101
|
-
if (range.min <= Number(volume) && range.max >= Number(volume)) {
|
|
102
|
-
if (discount) {
|
|
103
|
-
if (discount > range.fee) {
|
|
104
|
-
throw new common_1.GenericInputError("Discount cannot be greater than platform fee");
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
const netFee = range.fee - discount;
|
|
108
|
-
platformFeeFiat = amountFiat * netFee;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
else if (markup) {
|
|
112
|
-
const netFee = range.fee + markup;
|
|
113
|
-
platformFeeFiat = amountFiat * netFee;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
platformFeeFiat = amountFiat * range.fee;
|
|
117
|
-
}
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
// @ts-ignore
|
|
122
|
-
if (platformFeeFiat === undefined) {
|
|
123
|
-
let netPlatformFee = rioSettings.platformFee;
|
|
124
|
-
if (discount) {
|
|
125
|
-
netPlatformFee -= discount;
|
|
126
|
-
}
|
|
127
|
-
if (markup) {
|
|
128
|
-
netPlatformFee += markup;
|
|
129
|
-
}
|
|
130
|
-
if (netPlatformFee < 0) {
|
|
131
|
-
throw new common_1.GenericInputError("Discount cannot be greater than platform fee");
|
|
132
|
-
}
|
|
133
|
-
platformFeeFiat = amountFiat * netPlatformFee;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
let netPlatformFee = rioSettings.platformFee;
|
|
138
|
-
if (discount) {
|
|
139
|
-
netPlatformFee -= discount;
|
|
140
|
-
}
|
|
141
|
-
if (markup) {
|
|
142
|
-
netPlatformFee += markup;
|
|
143
|
-
}
|
|
144
|
-
if (netPlatformFee < 0) {
|
|
145
|
-
throw new common_1.GenericInputError("Discount cannot be greater than platform fee");
|
|
146
|
-
}
|
|
147
|
-
platformFeeFiat = amountFiat * netPlatformFee;
|
|
148
|
-
}
|
|
149
|
-
if ((fiat === common_1.Fiat.MXN && processor === common_1.Processor.SPEI) ||
|
|
150
|
-
(fiat === common_1.Fiat.MXN && processor === common_1.Processor.Bitso) ||
|
|
151
|
-
(fiat === common_1.Fiat.USD && processor === common_1.Processor.SPID)) {
|
|
152
|
-
if (country === common_1.Country.Mexico &&
|
|
153
|
-
(user === null || user === void 0 ? void 0 : user.country) === common_1.CountryOfOrigin.Mexico) {
|
|
154
|
-
platformFeeFiatTax = platformFeeFiat * 0.16;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if (fiat === common_1.Fiat.PEN && processor === common_1.Processor.Interbank) {
|
|
158
|
-
if (country === common_1.Country.Peru) {
|
|
159
|
-
platformFeeFiatTax = platformFeeFiat * 0.18;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return {
|
|
163
|
-
platformFeeFiat: platformFeeFiat,
|
|
164
|
-
platformFeeFiatTax,
|
|
165
|
-
feesComped,
|
|
166
|
-
};
|
|
167
|
-
});
|
|
168
|
-
exports.getPlatformFees = getPlatformFees;
|