@riocrypto/common-server 1.0.2863 → 1.0.2864

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,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findUserTierForwardCurveRate = void 0;
4
+ const common_1 = require("@riocrypto/common");
4
5
  const interpolate_forward_curve_rate_1 = require("./interpolate-forward-curve-rate");
5
6
  const getRangeCurve = (range, kind) => kind === "twap"
6
7
  ? range.TWAPTwoWaySettlementDateOffsetFee
@@ -19,8 +20,12 @@ const getRangeCurve = (range, kind) => kind === "twap"
19
20
  * (`TWAPTwoWaySettlementDateOffsetFee`).
20
21
  */
21
22
  const findUserTierForwardCurveRate = ({ user, country, side, amount, day, kind = "regular", }) => {
22
- var _a, _b;
23
- const ranges = (_b = (_a = user === null || user === void 0 ? void 0 : user.platformFeeRanges) === null || _a === void 0 ? void 0 : _a[country]) === null || _b === void 0 ? void 0 : _b[side];
23
+ var _a;
24
+ const ranges = (0, common_1.getActivePlatformFeeRanges)({
25
+ platformFees: (_a = user === null || user === void 0 ? void 0 : user.platformFeeRanges) === null || _a === void 0 ? void 0 : _a[country],
26
+ country,
27
+ side,
28
+ });
24
29
  if (!ranges || ranges.length === 0)
25
30
  return undefined;
26
31
  const sorted = [...ranges].sort((a, b) => a.min - b.min);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getResolvedForwardCurveTiers = void 0;
4
+ const common_1 = require("@riocrypto/common");
4
5
  const resolve_forward_curve_rate_1 = require("./resolve-forward-curve-rate");
5
6
  /**
6
7
  * Builds per-tier resolved forward curves suitable for charting.
@@ -13,12 +14,20 @@ const resolve_forward_curve_rate_1 = require("./resolve-forward-curve-rate");
13
14
  * continuous line.
14
15
  */
15
16
  const getResolvedForwardCurveTiers = ({ user, broker, country, side, rioSettings, kind = "regular", }) => {
16
- var _a, _b, _c, _d, _e, _f, _g, _h;
17
- const userRanges = (_b = (_a = user.platformFeeRanges) === null || _a === void 0 ? void 0 : _a[country]) === null || _b === void 0 ? void 0 : _b[side];
18
- const brokerRanges = (_d = (_c = broker === null || broker === void 0 ? void 0 : broker.platformFeeRanges) === null || _c === void 0 ? void 0 : _c[country]) === null || _d === void 0 ? void 0 : _d[side];
17
+ var _a, _b, _c, _d, _e, _f;
18
+ const userRanges = (0, common_1.getActivePlatformFeeRanges)({
19
+ platformFees: (_a = user.platformFeeRanges) === null || _a === void 0 ? void 0 : _a[country],
20
+ country,
21
+ side,
22
+ });
23
+ const brokerRanges = (0, common_1.getActivePlatformFeeRanges)({
24
+ platformFees: (_b = broker === null || broker === void 0 ? void 0 : broker.platformFeeRanges) === null || _b === void 0 ? void 0 : _b[country],
25
+ country,
26
+ side,
27
+ });
19
28
  const platformCurve = kind === "twap"
20
- ? (_f = (_e = rioSettings.defaultTWAPTwoWaySettlementDateOffsetFee) === null || _e === void 0 ? void 0 : _e[country]) === null || _f === void 0 ? void 0 : _f[side]
21
- : (_h = (_g = rioSettings.defaultTwoWaySettlementDateOffsetFee) === null || _g === void 0 ? void 0 : _g[country]) === null || _h === void 0 ? void 0 : _h[side];
29
+ ? (_d = (_c = rioSettings.defaultTWAPTwoWaySettlementDateOffsetFee) === null || _c === void 0 ? void 0 : _c[country]) === null || _d === void 0 ? void 0 : _d[side]
30
+ : (_f = (_e = rioSettings.defaultTwoWaySettlementDateOffsetFee) === null || _e === void 0 ? void 0 : _e[country]) === null || _f === void 0 ? void 0 : _f[side];
22
31
  let tiers = [];
23
32
  if (userRanges && userRanges.length > 0) {
24
33
  tiers = [...userRanges]
@@ -1,4 +1,4 @@
1
- import { OnboardingStatus, PlatformFeeRange, UserAttribute, UserType, CountryOfOrigin, Country, Fiat, Side, Crypto, DeferredPaymentType, MexicoInvoicingMethod, ColombiaInvoicingMethod } from "@riocrypto/common";
1
+ import { OnboardingStatus, PlatformFeesForCountry, UserAttribute, UserType, CountryOfOrigin, Country, Fiat, Side, Crypto, MexicoInvoicingMethod, ColombiaInvoicingMethod } from "@riocrypto/common";
2
2
  import { Mongoose, Model, Document, HydratedDocument } from "mongoose";
3
3
  interface UserAttrs {
4
4
  createdAt: Date;
@@ -23,26 +23,11 @@ interface UserAttrs {
23
23
  attributes?: UserAttribute[];
24
24
  brokerId?: string;
25
25
  platformFeeRanges?: {
26
- MX?: {
27
- buy?: PlatformFeeRange[];
28
- sell?: PlatformFeeRange[];
29
- };
30
- PE?: {
31
- buy?: PlatformFeeRange[];
32
- sell?: PlatformFeeRange[];
33
- };
34
- CO?: {
35
- buy?: PlatformFeeRange[];
36
- sell?: PlatformFeeRange[];
37
- };
38
- BR?: {
39
- buy?: PlatformFeeRange[];
40
- sell?: PlatformFeeRange[];
41
- };
42
- US?: {
43
- buy?: PlatformFeeRange[];
44
- sell?: PlatformFeeRange[];
45
- };
26
+ MX?: PlatformFeesForCountry;
27
+ PE?: PlatformFeesForCountry;
28
+ CO?: PlatformFeesForCountry;
29
+ BR?: PlatformFeesForCountry;
30
+ US?: PlatformFeesForCountry;
46
31
  };
47
32
  accumulatedVolumeInUSD?: {
48
33
  MX?: {
@@ -170,56 +155,11 @@ interface UserDoc extends Document {
170
155
  attributes?: UserAttribute[];
171
156
  brokerId?: string;
172
157
  platformFeeRanges?: {
173
- MX?: {
174
- buy?: PlatformFeeRange[];
175
- sell?: PlatformFeeRange[];
176
- deferredPaymentFee?: {
177
- [deferredPaymentType in DeferredPaymentType]: number;
178
- };
179
- twoWaySettlementDateOffsetFee?: {
180
- [key: number]: number;
181
- };
182
- };
183
- PE?: {
184
- buy?: PlatformFeeRange[];
185
- sell?: PlatformFeeRange[];
186
- deferredPaymentFee?: {
187
- [deferredPaymentType in DeferredPaymentType]: number;
188
- };
189
- twoWaySettlementDateOffsetFee?: {
190
- [key: number]: number;
191
- };
192
- };
193
- CO?: {
194
- buy?: PlatformFeeRange[];
195
- sell?: PlatformFeeRange[];
196
- deferredPaymentFee?: {
197
- [deferredPaymentType in DeferredPaymentType]: number;
198
- };
199
- twoWaySettlementDateOffsetFee?: {
200
- [key: number]: number;
201
- };
202
- };
203
- BR?: {
204
- buy?: PlatformFeeRange[];
205
- sell?: PlatformFeeRange[];
206
- deferredPaymentFee?: {
207
- [deferredPaymentType in DeferredPaymentType]: number;
208
- };
209
- twoWaySettlementDateOffsetFee?: {
210
- [key: number]: number;
211
- };
212
- };
213
- US?: {
214
- buy?: PlatformFeeRange[];
215
- sell?: PlatformFeeRange[];
216
- deferredPaymentFee?: {
217
- [deferredPaymentType in DeferredPaymentType]: number;
218
- };
219
- twoWaySettlementDateOffsetFee?: {
220
- [key: number]: number;
221
- };
222
- };
158
+ MX?: PlatformFeesForCountry;
159
+ PE?: PlatformFeesForCountry;
160
+ CO?: PlatformFeesForCountry;
161
+ BR?: PlatformFeesForCountry;
162
+ US?: PlatformFeesForCountry;
223
163
  };
224
164
  accumulatedVolumeInUSD?: {
225
165
  MX?: {
@@ -1,6 +1,60 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildUser = void 0;
4
+ const common_1 = require("@riocrypto/common");
5
+ const mongoose_1 = require("mongoose");
6
+ // Defined as a sub-schema (rather than a nested plain object) so that
7
+ // ranges without a schedule keep the path undefined instead of
8
+ // materializing an empty `{ daysOfWeek: [] }` object on every range.
9
+ const platformFeeScheduleSchema = new mongoose_1.Schema({
10
+ daysOfWeek: [
11
+ {
12
+ type: String,
13
+ enum: Object.values(common_1.DayOfWeek),
14
+ },
15
+ ],
16
+ startMinute: {
17
+ type: Number,
18
+ required: true,
19
+ },
20
+ endMinute: {
21
+ type: Number,
22
+ required: true,
23
+ },
24
+ }, { _id: false });
25
+ const platformFeeRangeSchemaDefinition = {
26
+ min: {
27
+ type: Number,
28
+ required: true,
29
+ },
30
+ max: {
31
+ type: Number,
32
+ required: true,
33
+ },
34
+ fee: {
35
+ type: Number,
36
+ required: true,
37
+ },
38
+ schedule: {
39
+ type: platformFeeScheduleSchema,
40
+ },
41
+ deferredPaymentFee: {
42
+ type: Object,
43
+ },
44
+ twoWaySettlementDateOffsetFee: {
45
+ type: Object,
46
+ },
47
+ TWAPFee: {
48
+ type: Number,
49
+ },
50
+ TWAPTwoWaySettlementDateOffsetFee: {
51
+ type: Object,
52
+ },
53
+ };
54
+ const platformFeesForCountrySchemaDefinition = {
55
+ buy: [platformFeeRangeSchemaDefinition],
56
+ sell: [platformFeeRangeSchemaDefinition],
57
+ };
4
58
  const buildUser = (mongoose) => {
5
59
  // if model is already defined, return it
6
60
  if (mongoose.models.User) {
@@ -62,238 +116,11 @@ const buildUser = (mongoose) => {
62
116
  type: Number,
63
117
  },
64
118
  platformFeeRanges: {
65
- MX: {
66
- buy: [
67
- {
68
- min: {
69
- type: Number,
70
- required: true,
71
- },
72
- max: {
73
- type: Number,
74
- required: true,
75
- },
76
- fee: {
77
- type: Number,
78
- required: true,
79
- },
80
- deferredPaymentFee: {
81
- type: Object,
82
- },
83
- twoWaySettlementDateOffsetFee: {
84
- type: Object,
85
- },
86
- TWAPFee: {
87
- type: Number,
88
- },
89
- TWAPTwoWaySettlementDateOffsetFee: {
90
- type: Object,
91
- },
92
- },
93
- ],
94
- sell: [
95
- {
96
- min: {
97
- type: Number,
98
- required: true,
99
- },
100
- max: {
101
- type: Number,
102
- required: true,
103
- },
104
- fee: {
105
- type: Number,
106
- required: true,
107
- },
108
- deferredPaymentFee: {
109
- type: Object,
110
- },
111
- twoWaySettlementDateOffsetFee: {
112
- type: Object,
113
- },
114
- TWAPFee: {
115
- type: Number,
116
- },
117
- TWAPTwoWaySettlementDateOffsetFee: {
118
- type: Object,
119
- },
120
- },
121
- ],
122
- },
123
- US: {
124
- buy: [
125
- {
126
- min: {
127
- type: Number,
128
- required: true,
129
- },
130
- max: {
131
- type: Number,
132
- required: true,
133
- },
134
- fee: {
135
- type: Number,
136
- required: true,
137
- },
138
- deferredPaymentFee: {
139
- type: Object,
140
- },
141
- twoWaySettlementDateOffsetFee: {
142
- type: Object,
143
- },
144
- TWAPFee: {
145
- type: Number,
146
- },
147
- TWAPTwoWaySettlementDateOffsetFee: {
148
- type: Object,
149
- },
150
- },
151
- ],
152
- sell: [
153
- {
154
- min: {
155
- type: Number,
156
- required: true,
157
- },
158
- max: {
159
- type: Number,
160
- required: true,
161
- },
162
- fee: {
163
- type: Number,
164
- required: true,
165
- },
166
- deferredPaymentFee: {
167
- type: Object,
168
- },
169
- twoWaySettlementDateOffsetFee: {
170
- type: Object,
171
- },
172
- TWAPFee: {
173
- type: Number,
174
- },
175
- TWAPTwoWaySettlementDateOffsetFee: {
176
- type: Object,
177
- },
178
- },
179
- ],
180
- },
181
- PE: {
182
- buy: [
183
- {
184
- min: {
185
- type: Number,
186
- required: true,
187
- },
188
- max: {
189
- type: Number,
190
- required: true,
191
- },
192
- fee: {
193
- type: Number,
194
- required: true,
195
- },
196
- deferredPaymentFee: {
197
- type: Object,
198
- },
199
- twoWaySettlementDateOffsetFee: {
200
- type: Object,
201
- },
202
- TWAPFee: {
203
- type: Number,
204
- },
205
- TWAPTwoWaySettlementDateOffsetFee: {
206
- type: Object,
207
- },
208
- },
209
- ],
210
- sell: [
211
- {
212
- min: {
213
- type: Number,
214
- required: true,
215
- },
216
- max: {
217
- type: Number,
218
- required: true,
219
- },
220
- fee: {
221
- type: Number,
222
- required: true,
223
- },
224
- deferredPaymentFee: {
225
- type: Object,
226
- },
227
- twoWaySettlementDateOffsetFee: {
228
- type: Object,
229
- },
230
- TWAPFee: {
231
- type: Number,
232
- },
233
- TWAPTwoWaySettlementDateOffsetFee: {
234
- type: Object,
235
- },
236
- },
237
- ],
238
- },
239
- CO: {
240
- buy: [
241
- {
242
- min: {
243
- type: Number,
244
- required: true,
245
- },
246
- max: {
247
- type: Number,
248
- required: true,
249
- },
250
- fee: {
251
- type: Number,
252
- required: true,
253
- },
254
- deferredPaymentFee: {
255
- type: Object,
256
- },
257
- twoWaySettlementDateOffsetFee: {
258
- type: Object,
259
- },
260
- TWAPFee: {
261
- type: Number,
262
- },
263
- TWAPTwoWaySettlementDateOffsetFee: {
264
- type: Object,
265
- },
266
- },
267
- ],
268
- sell: [
269
- {
270
- min: {
271
- type: Number,
272
- required: true,
273
- },
274
- max: {
275
- type: Number,
276
- required: true,
277
- },
278
- fee: {
279
- type: Number,
280
- required: true,
281
- },
282
- deferredPaymentFee: {
283
- type: Object,
284
- },
285
- twoWaySettlementDateOffsetFee: {
286
- type: Object,
287
- },
288
- TWAPFee: {
289
- type: Number,
290
- },
291
- TWAPTwoWaySettlementDateOffsetFee: {
292
- type: Object,
293
- },
294
- },
295
- ],
296
- },
119
+ MX: platformFeesForCountrySchemaDefinition,
120
+ US: platformFeesForCountrySchemaDefinition,
121
+ PE: platformFeesForCountrySchemaDefinition,
122
+ CO: platformFeesForCountrySchemaDefinition,
123
+ BR: platformFeesForCountrySchemaDefinition,
297
124
  },
298
125
  rioBankAccount: {
299
126
  MX: Object,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2863",
3
+ "version": "1.0.2864",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "@google-cloud/secret-manager": "^5.6.0",
29
29
  "@google-cloud/storage": "^7.19.0",
30
30
  "@hyperdx/node-opentelemetry": "^0.10.3",
31
- "@riocrypto/common": "1.0.2671",
31
+ "@riocrypto/common": "1.0.2673",
32
32
  "@slack/web-api": "^7.15.0",
33
33
  "@types/express": "^4.17.25",
34
34
  "axios": "1.16.0",