@riocrypto/common-server 1.0.2667 → 1.0.2669

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.
@@ -10,9 +10,11 @@ const generateReference = (order) => {
10
10
  // Using last 6 chars alone caused collisions (~50/month) because the counter
11
11
  // portion can overlap across different MongoDB instances/pods.
12
12
  //
13
- // Solution: Use 7 consecutive chars from the random portion (8-14).
14
- // This gives 16^7 = 268 million combinations vs 16^6 = 16.7 million (16x better).
15
- // Using consecutive chars from the ID keeps it simple and traceable.
16
- return order.id.slice(8, 15).toUpperCase();
13
+ // Solution: 2 chars from random portion (8-9) + last 6 chars of order ID.
14
+ // Last 6 chars are kept for easy traceability by finance team.
15
+ // This gives 16^8 = 4.3 billion combinations vs 16^6 = 16.7 million (256x better).
16
+ const randomPrefix = order.id.slice(8, 10);
17
+ const last6 = order.id.slice(-6);
18
+ return (randomPrefix + last6).toUpperCase();
17
19
  };
18
20
  exports.generateReference = generateReference;
@@ -28,11 +28,13 @@ const getBulkPaymentFromReference = (reference, mongoose) => __awaiter(void 0, v
28
28
  ],
29
29
  },
30
30
  });
31
- // Reference format uses 7 consecutive chars from the random portion (8-14)
31
+ // Reference format: 2 chars from random portion (8-9) + last 6 chars of ID
32
32
  const bulkPayment = bulkPayments.find((bulkPayment) => {
33
33
  const bulkPaymentId = bulkPayment.id.toString().toLowerCase();
34
- const reference7Chars = bulkPaymentId.slice(8, 15);
35
- return referenceText.includes(reference7Chars);
34
+ const randomPrefix = bulkPaymentId.slice(8, 10);
35
+ const last6 = bulkPaymentId.slice(-6);
36
+ const reference8Chars = randomPrefix + last6;
37
+ return referenceText.includes(reference8Chars);
36
38
  });
37
39
  if (!bulkPayment) {
38
40
  throw new Error("Bulk payment not found");
@@ -47,11 +47,13 @@ const getOrderFromReference = (reference, mongoose) => __awaiter(void 0, void 0,
47
47
  break;
48
48
  }
49
49
  // Check each order ID against the reference
50
- // Reference format uses 7 consecutive chars from the random portion (8-14)
50
+ // Reference format: 2 chars from random portion (8-9) + last 6 chars of order ID
51
51
  for (const order of orders) {
52
52
  const orderId = order._id.toString().toLowerCase();
53
- const reference7Chars = orderId.slice(8, 15);
54
- if (referenceText.includes(reference7Chars)) {
53
+ const randomPrefix = orderId.slice(8, 10);
54
+ const last6 = orderId.slice(-6);
55
+ const reference8Chars = randomPrefix + last6;
56
+ if (referenceText.includes(reference8Chars)) {
55
57
  // Found a match, now fetch the full order document
56
58
  foundOrder = yield Order.findById(order._id);
57
59
  break;
package/build/index.d.ts CHANGED
@@ -105,6 +105,8 @@ export * from "./models/inbound-bank-deposit";
105
105
  export * from "./models/inbound-crypto-deposit";
106
106
  export * from "./models/order-log";
107
107
  export * from "./models/approved-alternative-bank-account-holder-name";
108
+ export * from "./models/liquidity-sourcing-plan";
109
+ export * from "./models/liquidity-sourcing-exclusion";
108
110
  export * from "./clients/axios-with-logging";
109
111
  export * from "./clients/slack-client";
110
112
  export * from "./clients/fireblocks-client";
package/build/index.js CHANGED
@@ -121,6 +121,8 @@ __exportStar(require("./models/inbound-bank-deposit"), exports);
121
121
  __exportStar(require("./models/inbound-crypto-deposit"), exports);
122
122
  __exportStar(require("./models/order-log"), exports);
123
123
  __exportStar(require("./models/approved-alternative-bank-account-holder-name"), exports);
124
+ __exportStar(require("./models/liquidity-sourcing-plan"), exports);
125
+ __exportStar(require("./models/liquidity-sourcing-exclusion"), exports);
124
126
  __exportStar(require("./clients/axios-with-logging"), exports);
125
127
  __exportStar(require("./clients/slack-client"), exports);
126
128
  __exportStar(require("./clients/fireblocks-client"), exports);
@@ -1,7 +1,8 @@
1
1
  import mongoose from "mongoose";
2
2
  import { TreasuryProvider, Fiat, Crypto, InternalTradeStatus, InternalTradeType, InternalTradeStrategy } from "@riocrypto/common";
3
3
  interface InternalTradeAttrs {
4
- adminId: string;
4
+ adminId?: string;
5
+ liquiditySourcingPlanId?: string;
5
6
  createdAt: Date;
6
7
  provider: TreasuryProvider;
7
8
  originAmount: number;
@@ -21,7 +22,8 @@ interface InternalTradeAttrs {
21
22
  }
22
23
  interface InternalTradeDoc extends mongoose.Document {
23
24
  id: string;
24
- adminId: string;
25
+ adminId?: string;
26
+ liquiditySourcingPlanId?: string;
25
27
  createdAt: Date;
26
28
  provider: TreasuryProvider;
27
29
  originAmount: number;
@@ -9,7 +9,9 @@ const buildInternalTrade = (mongoose) => {
9
9
  const InternalTradeSchema = new mongoose.Schema({
10
10
  adminId: {
11
11
  type: String,
12
- required: true,
12
+ },
13
+ liquiditySourcingPlanId: {
14
+ type: String,
13
15
  },
14
16
  createdAt: {
15
17
  type: Date,
@@ -2,8 +2,9 @@ import mongoose from "mongoose";
2
2
  import { InternalTransferType, TreasuryProvider, Fiat, Crypto, InternalTransferOriginStatus, InternalTransferDestinationStatus } from "@riocrypto/common";
3
3
  interface InternalTransferAttrs {
4
4
  createdAt: Date;
5
- adminId: string;
5
+ adminId?: string;
6
6
  liquidityAutomationId?: string;
7
+ liquiditySourcingPlanId?: string;
7
8
  transferType: InternalTransferType;
8
9
  amount: number;
9
10
  currency: Fiat | Crypto;
@@ -28,8 +29,9 @@ interface InternalTransferAttrs {
28
29
  }
29
30
  interface InternalTransferDoc extends mongoose.Document {
30
31
  id: string;
31
- adminId: string;
32
+ adminId?: string;
32
33
  liquidityAutomationId?: string;
34
+ liquiditySourcingPlanId?: string;
33
35
  createdAt: Date;
34
36
  transferType: InternalTransferType;
35
37
  blockchainTxId?: string;
@@ -10,11 +10,13 @@ const buildInternalTransfer = (mongoose) => {
10
10
  const InternalTransferSchema = new mongoose.Schema({
11
11
  adminId: {
12
12
  type: String,
13
- required: true,
14
13
  },
15
14
  liquidityAutomationId: {
16
15
  type: String,
17
16
  },
17
+ liquiditySourcingPlanId: {
18
+ type: String,
19
+ },
18
20
  createdAt: {
19
21
  type: Date,
20
22
  required: true,
@@ -0,0 +1,19 @@
1
+ import mongoose from "mongoose";
2
+ import { Crypto, Fiat, LiquiditySourcingExclusion, LiquiditySourcingExclusionType, TreasuryProvider } from "@riocrypto/common";
3
+ interface LiquiditySourcingExclusionAttrs {
4
+ createdAt: Date;
5
+ type: LiquiditySourcingExclusionType;
6
+ provider: TreasuryProvider;
7
+ currencies?: (Crypto | Fiat)[];
8
+ originCurrencies?: Crypto[];
9
+ destinationCurrencies?: Crypto[];
10
+ reason?: string;
11
+ }
12
+ interface LiquiditySourcingExclusionDoc extends mongoose.Document, Omit<LiquiditySourcingExclusion, "id"> {
13
+ id: string;
14
+ }
15
+ interface LiquiditySourcingExclusionModel extends mongoose.Model<LiquiditySourcingExclusionDoc> {
16
+ build(attrs: LiquiditySourcingExclusionAttrs): LiquiditySourcingExclusionDoc;
17
+ }
18
+ declare const buildLiquiditySourcingExclusion: (mongooseInstance: mongoose.Mongoose) => LiquiditySourcingExclusionModel;
19
+ export { LiquiditySourcingExclusionAttrs, LiquiditySourcingExclusionDoc, LiquiditySourcingExclusionModel, buildLiquiditySourcingExclusion, };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.buildLiquiditySourcingExclusion = void 0;
7
+ const mongoose_1 = __importDefault(require("mongoose"));
8
+ const common_1 = require("@riocrypto/common");
9
+ const LiquiditySourcingExclusionSchema = new mongoose_1.default.Schema({
10
+ createdAt: { type: Date, required: true },
11
+ type: {
12
+ type: String,
13
+ enum: Object.values(common_1.LiquiditySourcingExclusionType),
14
+ required: true,
15
+ },
16
+ provider: {
17
+ type: String,
18
+ enum: Object.values(common_1.TreasuryProvider),
19
+ required: true,
20
+ },
21
+ currencies: { type: [String], default: [] },
22
+ originCurrencies: { type: [String], default: [] },
23
+ destinationCurrencies: { type: [String], default: [] },
24
+ reason: { type: String },
25
+ }, {
26
+ toJSON: {
27
+ transform(doc, ret) {
28
+ ret.id = ret._id;
29
+ delete ret._id;
30
+ delete ret.__v;
31
+ },
32
+ },
33
+ });
34
+ const buildLiquiditySourcingExclusion = (mongooseInstance) => {
35
+ if (mongooseInstance.models.LiquiditySourcingExclusion) {
36
+ return mongooseInstance.model("LiquiditySourcingExclusion");
37
+ }
38
+ LiquiditySourcingExclusionSchema.statics.build = (attrs) => {
39
+ return new LiquiditySourcingExclusionModelInstance(attrs);
40
+ };
41
+ const LiquiditySourcingExclusionModelInstance = mongooseInstance.model("LiquiditySourcingExclusion", LiquiditySourcingExclusionSchema);
42
+ return LiquiditySourcingExclusionModelInstance;
43
+ };
44
+ exports.buildLiquiditySourcingExclusion = buildLiquiditySourcingExclusion;
@@ -0,0 +1,24 @@
1
+ import mongoose from "mongoose";
2
+ import { Crypto, Fiat, LiquiditySourcingPlan, LiquiditySourcingPlanStatus, LiquiditySourcingStep, TreasuryProvider } from "@riocrypto/common";
3
+ interface LiquiditySourcingPlanAttrs {
4
+ createdAt: Date;
5
+ orderIds?: string[];
6
+ bulkBankPayoutId?: string;
7
+ bulkCryptoPayoutId?: string;
8
+ targetCurrency: Fiat | Crypto;
9
+ targetProvider: TreasuryProvider;
10
+ amountNeeded: number;
11
+ amountToSource: number;
12
+ status: LiquiditySourcingPlanStatus;
13
+ currentStepIndex: number;
14
+ steps: LiquiditySourcingStep[];
15
+ amountSourced?: number;
16
+ }
17
+ interface LiquiditySourcingPlanDoc extends mongoose.Document, Omit<LiquiditySourcingPlan, "id"> {
18
+ id: string;
19
+ }
20
+ interface LiquiditySourcingPlanModel extends mongoose.Model<LiquiditySourcingPlanDoc> {
21
+ build(attrs: LiquiditySourcingPlanAttrs): LiquiditySourcingPlanDoc;
22
+ }
23
+ declare const buildLiquiditySourcingPlan: (mongooseInstance: mongoose.Mongoose) => LiquiditySourcingPlanModel;
24
+ export { LiquiditySourcingPlanAttrs, LiquiditySourcingPlanDoc, LiquiditySourcingPlanModel, buildLiquiditySourcingPlan, };
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.buildLiquiditySourcingPlan = void 0;
7
+ const mongoose_1 = __importDefault(require("mongoose"));
8
+ const common_1 = require("@riocrypto/common");
9
+ const StepSchema = new mongoose_1.default.Schema({
10
+ type: {
11
+ type: String,
12
+ enum: Object.values(common_1.LiquiditySourcingStepType),
13
+ required: true,
14
+ },
15
+ status: {
16
+ type: String,
17
+ enum: Object.values(common_1.LiquiditySourcingStepStatus),
18
+ required: true,
19
+ },
20
+ startedAt: { type: Date },
21
+ origin: { type: String, enum: Object.values(common_1.TreasuryProvider) },
22
+ destination: { type: String, enum: Object.values(common_1.TreasuryProvider) },
23
+ currency: { type: String },
24
+ amount: { type: Number },
25
+ internalTransferId: { type: String },
26
+ provider: { type: String },
27
+ originCurrency: { type: String },
28
+ originAmount: { type: Number },
29
+ destinationCurrency: { type: String },
30
+ internalTradeId: { type: String },
31
+ externalTradeId: { type: String },
32
+ side: { type: String, enum: Object.values(common_1.Side) },
33
+ }, { _id: false });
34
+ const LiquiditySourcingPlanSchema = new mongoose_1.default.Schema({
35
+ createdAt: { type: Date, required: true },
36
+ orderIds: { type: [String], default: [] },
37
+ bulkBankPayoutId: { type: String },
38
+ bulkCryptoPayoutId: { type: String },
39
+ targetCurrency: { type: String, required: true },
40
+ targetProvider: {
41
+ type: String,
42
+ enum: Object.values(common_1.TreasuryProvider),
43
+ required: true,
44
+ },
45
+ amountNeeded: { type: Number, required: true },
46
+ amountToSource: { type: Number, required: true },
47
+ status: {
48
+ type: String,
49
+ enum: Object.values(common_1.LiquiditySourcingPlanStatus),
50
+ required: true,
51
+ },
52
+ currentStepIndex: { type: Number, required: true },
53
+ steps: { type: [StepSchema], required: true },
54
+ amountSourced: { type: Number },
55
+ }, {
56
+ toJSON: {
57
+ transform(doc, ret) {
58
+ ret.id = ret._id;
59
+ delete ret._id;
60
+ delete ret.__v;
61
+ },
62
+ },
63
+ });
64
+ const buildLiquiditySourcingPlan = (mongooseInstance) => {
65
+ if (mongooseInstance.models.LiquiditySourcingPlan) {
66
+ return mongooseInstance.model("LiquiditySourcingPlan");
67
+ }
68
+ LiquiditySourcingPlanSchema.statics.build = (attrs) => {
69
+ return new LiquiditySourcingPlanModelInstance(attrs);
70
+ };
71
+ const LiquiditySourcingPlanModelInstance = mongooseInstance.model("LiquiditySourcingPlan", LiquiditySourcingPlanSchema);
72
+ return LiquiditySourcingPlanModelInstance;
73
+ };
74
+ exports.buildLiquiditySourcingPlan = buildLiquiditySourcingPlan;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2667",
3
+ "version": "1.0.2669",
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.3.0",
29
29
  "@google-cloud/storage": "^6.9.5",
30
30
  "@hyperdx/node-opentelemetry": "^0.7.0",
31
- "@riocrypto/common": "^1.0.2466",
31
+ "@riocrypto/common": "^1.0.2468",
32
32
  "@types/express": "^4.17.13",
33
33
  "axios": "^1.7.4",
34
34
  "crypto-js": "^4.2.0",