@riocrypto/common 1.0.2150 → 1.0.2152
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/events/payout-advance-transaction-created-event.d.ts +1 -1
- package/build/helpers/get-country-timezone.d.ts +2 -0
- package/build/helpers/get-country-timezone.js +17 -0
- package/build/helpers/get-days-between-agreed-two-way-settlement-date-and-payment-date.d.ts +10 -0
- package/build/helpers/get-days-between-agreed-two-way-settlement-date-and-payment-date.js +37 -0
- package/build/helpers/get-days-until-two-way-settlement-date.d.ts +10 -0
- package/build/helpers/get-days-until-two-way-settlement-date.js +60 -0
- package/build/helpers/get-two-way-settlement-date.d.ts +5 -0
- package/build/helpers/get-two-way-settlement-date.js +15 -0
- package/build/helpers/should-add-one-day-to-settlement-date.js +5 -0
- package/build/index.d.ts +5 -1
- package/build/index.js +5 -1
- package/build/types/payout-advance-transaction-type.d.ts +4 -0
- package/build/types/payout-advance-transaction-type.js +8 -0
- package/build/types/payout-advance-transaction.d.ts +20 -3
- package/build/types/payout-advance-transaction.js +0 -6
- package/package.json +1 -1
- package/build/types/pre-settlement-transaction.d.ts +0 -21
- package/build/types/pre-settlement-transaction.js +0 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PayoutAdvanceTransactionType } from "../types/payout-advance-transaction";
|
|
1
|
+
import { PayoutAdvanceTransactionType } from "../types/payout-advance-transaction-type";
|
|
2
2
|
import { Subjects } from "./subjects";
|
|
3
3
|
import { Fiat } from "../types/fiat";
|
|
4
4
|
import { Crypto } from "../types/crypto";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCountryTimezone = void 0;
|
|
4
|
+
const country_1 = require("../types/country");
|
|
5
|
+
const getCountryTimezone = (country) => {
|
|
6
|
+
switch (country) {
|
|
7
|
+
case country_1.Country.Mexico:
|
|
8
|
+
return "America/Mexico_City";
|
|
9
|
+
case country_1.Country.Peru:
|
|
10
|
+
return "America/Lima";
|
|
11
|
+
case country_1.Country.UnitedStates:
|
|
12
|
+
return "America/New_York";
|
|
13
|
+
default:
|
|
14
|
+
throw new Error(`Unsupported country: ${country}`);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.getCountryTimezone = getCountryTimezone;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Country } from "../types/country";
|
|
2
|
+
import { DeferredPaymentType } from "../types/deferred-payment-type";
|
|
3
|
+
export declare const getDaysBetweenAgreedTwoWaySettlementDateAndPaymentDate: ({ country, holidays, twoWaySettlementDate, deferredPaymentType, }: {
|
|
4
|
+
country: Country;
|
|
5
|
+
holidays: {
|
|
6
|
+
dates: string[];
|
|
7
|
+
};
|
|
8
|
+
twoWaySettlementDate: Date;
|
|
9
|
+
deferredPaymentType: DeferredPaymentType;
|
|
10
|
+
}) => number;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDaysBetweenAgreedTwoWaySettlementDateAndPaymentDate = void 0;
|
|
4
|
+
const deferred_payment_type_1 = require("../types/deferred-payment-type");
|
|
5
|
+
const get_country_timezone_1 = require("./get-country-timezone");
|
|
6
|
+
const formatDateInTimezone = (date, timezone) => {
|
|
7
|
+
// Format the date in the specified timezone as YYYY-MM-DD
|
|
8
|
+
const dateInTimezone = new Date(date.toLocaleString("en-US", { timeZone: timezone }));
|
|
9
|
+
const year = dateInTimezone.getFullYear();
|
|
10
|
+
const month = String(dateInTimezone.getMonth() + 1).padStart(2, "0");
|
|
11
|
+
const day = String(dateInTimezone.getDate()).padStart(2, "0");
|
|
12
|
+
return `${year}-${month}-${day}`;
|
|
13
|
+
};
|
|
14
|
+
const getDaysBetweenAgreedTwoWaySettlementDateAndPaymentDate = ({ country, holidays, twoWaySettlementDate, deferredPaymentType, }) => {
|
|
15
|
+
if (deferredPaymentType !== deferred_payment_type_1.DeferredPaymentType.OneDayAfter) {
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
const timezone = (0, get_country_timezone_1.getCountryTimezone)(country);
|
|
19
|
+
// Convert the two way settlement date to the country's timezone
|
|
20
|
+
const settlementDateInCountryTZ = new Date(twoWaySettlementDate.toLocaleString("en-US", { timeZone: timezone }));
|
|
21
|
+
// Find the next business day after the settlement date
|
|
22
|
+
const nextBusinessDay = new Date(settlementDateInCountryTZ);
|
|
23
|
+
nextBusinessDay.setDate(settlementDateInCountryTZ.getDate() + 1);
|
|
24
|
+
while (true) {
|
|
25
|
+
const isWeekend = nextBusinessDay.getDay() === 0 || nextBusinessDay.getDay() === 6;
|
|
26
|
+
const isHoliday = holidays.dates.includes(formatDateInTimezone(nextBusinessDay, timezone));
|
|
27
|
+
if (!isWeekend && !isHoliday) {
|
|
28
|
+
break; // Found the next business day
|
|
29
|
+
}
|
|
30
|
+
nextBusinessDay.setDate(nextBusinessDay.getDate() + 1);
|
|
31
|
+
}
|
|
32
|
+
// Calculate the calendar days difference between settlement date and next business day
|
|
33
|
+
const timeDifference = nextBusinessDay.getTime() - settlementDateInCountryTZ.getTime();
|
|
34
|
+
const daysDifference = Math.ceil(timeDifference / (1000 * 3600 * 24));
|
|
35
|
+
return daysDifference;
|
|
36
|
+
};
|
|
37
|
+
exports.getDaysBetweenAgreedTwoWaySettlementDateAndPaymentDate = getDaysBetweenAgreedTwoWaySettlementDateAndPaymentDate;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Country } from "../types/country";
|
|
2
|
+
import { TwoWaySettlementType } from "../types/two-way-settlement-type";
|
|
3
|
+
export declare const getDaysUntilTwoWaySettlementDate: ({ country, holidays, twoWaySettlementType, twoWaySettlementDateOffset, }: {
|
|
4
|
+
country: Country;
|
|
5
|
+
holidays: {
|
|
6
|
+
dates: string[];
|
|
7
|
+
};
|
|
8
|
+
twoWaySettlementDateOffset: number;
|
|
9
|
+
twoWaySettlementType: TwoWaySettlementType;
|
|
10
|
+
}) => number;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDaysUntilTwoWaySettlementDate = void 0;
|
|
4
|
+
const two_way_settlement_type_1 = require("../types/two-way-settlement-type");
|
|
5
|
+
const get_country_timezone_1 = require("./get-country-timezone");
|
|
6
|
+
const should_add_one_day_to_settlement_date_1 = require("./should-add-one-day-to-settlement-date");
|
|
7
|
+
const formatDateInTimezone = (date, timezone) => {
|
|
8
|
+
// Format the date in the specified timezone as YYYY-MM-DD
|
|
9
|
+
const dateInTimezone = new Date(date.toLocaleString("en-US", { timeZone: timezone }));
|
|
10
|
+
const year = dateInTimezone.getFullYear();
|
|
11
|
+
const month = String(dateInTimezone.getMonth() + 1).padStart(2, "0");
|
|
12
|
+
const day = String(dateInTimezone.getDate()).padStart(2, "0");
|
|
13
|
+
return `${year}-${month}-${day}`;
|
|
14
|
+
};
|
|
15
|
+
const getDaysUntilTwoWaySettlementDate = ({ country, holidays, twoWaySettlementType, twoWaySettlementDateOffset, }) => {
|
|
16
|
+
if (twoWaySettlementType === two_way_settlement_type_1.TwoWaySettlementType.Default) {
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
19
|
+
let businessDaysToAdd = twoWaySettlementDateOffset;
|
|
20
|
+
// If in Asia time, add 1 day to the offset
|
|
21
|
+
const isAsiaTime = (0, should_add_one_day_to_settlement_date_1.shouldAddOneDayToSettlementDate)();
|
|
22
|
+
if (isAsiaTime) {
|
|
23
|
+
businessDaysToAdd += 1;
|
|
24
|
+
}
|
|
25
|
+
const timezone = (0, get_country_timezone_1.getCountryTimezone)(country);
|
|
26
|
+
// Get today's date in the country's timezone
|
|
27
|
+
const today = new Date();
|
|
28
|
+
const todayInCountryTZ = new Date(today.toLocaleString("en-US", { timeZone: timezone }));
|
|
29
|
+
// Calculate settlement date from today in country's timezone
|
|
30
|
+
const settlementDate = new Date(todayInCountryTZ);
|
|
31
|
+
if (businessDaysToAdd === 0) {
|
|
32
|
+
// Find today if it's a business day, otherwise the next business day
|
|
33
|
+
while (true) {
|
|
34
|
+
const isWeekend = settlementDate.getDay() === 0 || settlementDate.getDay() === 6;
|
|
35
|
+
const isHoliday = holidays.dates.includes(formatDateInTimezone(settlementDate, timezone));
|
|
36
|
+
if (!isWeekend && !isHoliday) {
|
|
37
|
+
break; // Found the business day
|
|
38
|
+
}
|
|
39
|
+
settlementDate.setDate(settlementDate.getDate() + 1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// Add the specified number of business days from today
|
|
44
|
+
let businessDaysAdded = 0;
|
|
45
|
+
while (businessDaysAdded < businessDaysToAdd) {
|
|
46
|
+
settlementDate.setDate(settlementDate.getDate() + 1);
|
|
47
|
+
const isWeekend = settlementDate.getDay() === 0 || settlementDate.getDay() === 6;
|
|
48
|
+
const isHoliday = holidays.dates.includes(formatDateInTimezone(settlementDate, timezone));
|
|
49
|
+
if (!isWeekend && !isHoliday) {
|
|
50
|
+
businessDaysAdded++;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Calculate the calendar days difference between today and settlement date
|
|
55
|
+
// Both dates are in the country's timezone
|
|
56
|
+
const timeDifference = settlementDate.getTime() - todayInCountryTZ.getTime();
|
|
57
|
+
const daysDifference = Math.ceil(timeDifference / (1000 * 3600 * 24));
|
|
58
|
+
return daysDifference;
|
|
59
|
+
};
|
|
60
|
+
exports.getDaysUntilTwoWaySettlementDate = getDaysUntilTwoWaySettlementDate;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTwoWaySettlementDate = void 0;
|
|
4
|
+
const get_country_timezone_1 = require("./get-country-timezone");
|
|
5
|
+
const getTwoWaySettlementDate = ({ country, daysUntilSettlementDate, }) => {
|
|
6
|
+
const timezone = (0, get_country_timezone_1.getCountryTimezone)(country);
|
|
7
|
+
// Get today's date in the country's timezone
|
|
8
|
+
const today = new Date();
|
|
9
|
+
const todayInCountryTZ = new Date(today.toLocaleString("en-US", { timeZone: timezone }));
|
|
10
|
+
// Add the specified number of days
|
|
11
|
+
const settlementDate = new Date(todayInCountryTZ);
|
|
12
|
+
settlementDate.setDate(todayInCountryTZ.getDate() + daysUntilSettlementDate);
|
|
13
|
+
return settlementDate;
|
|
14
|
+
};
|
|
15
|
+
exports.getTwoWaySettlementDate = getTwoWaySettlementDate;
|
|
@@ -7,6 +7,11 @@ const shouldAddOneDayToSettlementDate = () => {
|
|
|
7
7
|
timeZone: "America/Mexico_City",
|
|
8
8
|
});
|
|
9
9
|
const now = new Date(mexicoCityTime);
|
|
10
|
+
// Return false if it's Saturday or Sunday
|
|
11
|
+
const dayOfWeek = now.getDay(); // 0 = Sunday, 1 = Monday, ..., 6 = Saturday
|
|
12
|
+
if (dayOfWeek === 0 || dayOfWeek === 6) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
10
15
|
const currentHour = now.getHours();
|
|
11
16
|
const currentMinute = now.getMinutes();
|
|
12
17
|
// Check if between 2:55PM (14:55) and 12:00AM (00:00)
|
package/build/index.d.ts
CHANGED
|
@@ -334,8 +334,8 @@ export * from "./types/arbitrage-provider-status";
|
|
|
334
334
|
export * from "./types/arbitrage-trade";
|
|
335
335
|
export * from "./types/arbitrage-trade-status";
|
|
336
336
|
export * from "./types/arbitrage-trade-type";
|
|
337
|
-
export * from "./types/pre-settlement-transaction";
|
|
338
337
|
export * from "./types/payout-advance-transaction";
|
|
338
|
+
export * from "./types/payout-advance-transaction-type";
|
|
339
339
|
export * from "./types/currency-with-country";
|
|
340
340
|
export * from "./types/CEP";
|
|
341
341
|
export * from "./types/CEP-status";
|
|
@@ -399,5 +399,9 @@ export * from "./helpers/is-bitso-bank-account";
|
|
|
399
399
|
export * from "./helpers/is-overnight-or-weekend-mexico-city";
|
|
400
400
|
export * from "./helpers/get-user-payout-vault-id";
|
|
401
401
|
export * from "./helpers/should-add-one-day-to-settlement-date";
|
|
402
|
+
export * from "./helpers/get-country-timezone";
|
|
403
|
+
export * from "./helpers/get-days-between-agreed-two-way-settlement-date-and-payment-date";
|
|
404
|
+
export * from "./helpers/get-days-until-two-way-settlement-date";
|
|
405
|
+
export * from "./helpers/get-two-way-settlement-date";
|
|
402
406
|
export * from "./constants/mexico-fiscal-regimens";
|
|
403
407
|
export * from "./constants/mexican-banks";
|
package/build/index.js
CHANGED
|
@@ -350,8 +350,8 @@ __exportStar(require("./types/arbitrage-provider-status"), exports);
|
|
|
350
350
|
__exportStar(require("./types/arbitrage-trade"), exports);
|
|
351
351
|
__exportStar(require("./types/arbitrage-trade-status"), exports);
|
|
352
352
|
__exportStar(require("./types/arbitrage-trade-type"), exports);
|
|
353
|
-
__exportStar(require("./types/pre-settlement-transaction"), exports);
|
|
354
353
|
__exportStar(require("./types/payout-advance-transaction"), exports);
|
|
354
|
+
__exportStar(require("./types/payout-advance-transaction-type"), exports);
|
|
355
355
|
__exportStar(require("./types/currency-with-country"), exports);
|
|
356
356
|
__exportStar(require("./types/CEP"), exports);
|
|
357
357
|
__exportStar(require("./types/CEP-status"), exports);
|
|
@@ -415,5 +415,9 @@ __exportStar(require("./helpers/is-bitso-bank-account"), exports);
|
|
|
415
415
|
__exportStar(require("./helpers/is-overnight-or-weekend-mexico-city"), exports);
|
|
416
416
|
__exportStar(require("./helpers/get-user-payout-vault-id"), exports);
|
|
417
417
|
__exportStar(require("./helpers/should-add-one-day-to-settlement-date"), exports);
|
|
418
|
+
__exportStar(require("./helpers/get-country-timezone"), exports);
|
|
419
|
+
__exportStar(require("./helpers/get-days-between-agreed-two-way-settlement-date-and-payment-date"), exports);
|
|
420
|
+
__exportStar(require("./helpers/get-days-until-two-way-settlement-date"), exports);
|
|
421
|
+
__exportStar(require("./helpers/get-two-way-settlement-date"), exports);
|
|
418
422
|
__exportStar(require("./constants/mexico-fiscal-regimens"), exports);
|
|
419
423
|
__exportStar(require("./constants/mexican-banks"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PayoutAdvanceTransactionType = void 0;
|
|
4
|
+
var PayoutAdvanceTransactionType;
|
|
5
|
+
(function (PayoutAdvanceTransactionType) {
|
|
6
|
+
PayoutAdvanceTransactionType["Credit"] = "credit";
|
|
7
|
+
PayoutAdvanceTransactionType["Debit"] = "debit";
|
|
8
|
+
})(PayoutAdvanceTransactionType = exports.PayoutAdvanceTransactionType || (exports.PayoutAdvanceTransactionType = {}));
|
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { PayoutAdvanceTransactionType } from "./payout-advance-transaction-type";
|
|
2
|
+
import { Fiat } from "./fiat";
|
|
3
|
+
import { Crypto } from "./crypto";
|
|
4
|
+
export interface PayoutAdvanceTransaction {
|
|
5
|
+
id: string;
|
|
6
|
+
createdAt: Date;
|
|
7
|
+
userId: string;
|
|
8
|
+
bankAccountId?: string;
|
|
9
|
+
cryptoAddressId?: string;
|
|
10
|
+
type: PayoutAdvanceTransactionType;
|
|
11
|
+
amount: number;
|
|
12
|
+
currency: Fiat | Crypto;
|
|
13
|
+
orderId?: string;
|
|
14
|
+
SPEITrackingNumber?: string;
|
|
15
|
+
SPIDTrackingNumber?: string;
|
|
16
|
+
blockchainTxId?: string;
|
|
17
|
+
oppositeTransactionAmount?: number;
|
|
18
|
+
oppositeTransactions?: string[];
|
|
19
|
+
reference?: string;
|
|
20
|
+
CEPLink?: string;
|
|
4
21
|
}
|
|
@@ -1,8 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PayoutAdvanceTransactionType = void 0;
|
|
4
|
-
var PayoutAdvanceTransactionType;
|
|
5
|
-
(function (PayoutAdvanceTransactionType) {
|
|
6
|
-
PayoutAdvanceTransactionType["Credit"] = "credit";
|
|
7
|
-
PayoutAdvanceTransactionType["Debit"] = "debit";
|
|
8
|
-
})(PayoutAdvanceTransactionType = exports.PayoutAdvanceTransactionType || (exports.PayoutAdvanceTransactionType = {}));
|
package/package.json
CHANGED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { PayoutAdvanceTransactionType } from "./payout-advance-transaction";
|
|
2
|
-
import { Fiat } from "./fiat";
|
|
3
|
-
import { Crypto } from "./crypto";
|
|
4
|
-
export interface PayoutAdvanceTransaction {
|
|
5
|
-
id: string;
|
|
6
|
-
createdAt: Date;
|
|
7
|
-
userId: string;
|
|
8
|
-
bankAccountId?: string;
|
|
9
|
-
cryptoAddressId?: string;
|
|
10
|
-
type: PayoutAdvanceTransactionType;
|
|
11
|
-
amount: number;
|
|
12
|
-
currency: Fiat | Crypto;
|
|
13
|
-
orderId?: string;
|
|
14
|
-
SPEITrackingNumber?: string;
|
|
15
|
-
SPIDTrackingNumber?: string;
|
|
16
|
-
blockchainTxId?: string;
|
|
17
|
-
oppositeTransactionAmount?: number;
|
|
18
|
-
oppositeTransactions?: string[];
|
|
19
|
-
reference?: string;
|
|
20
|
-
CEPLink?: string;
|
|
21
|
-
}
|