@riocrypto/common-server 1.0.2812 → 1.0.2816

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.
@@ -0,0 +1,3 @@
1
+ import { Mongoose } from "mongoose";
2
+ import { BulkBankPaymentDoc } from "../models/bulk-bank-payment";
3
+ export declare const getBulkBankPaymentFromStaticReference: (reference: string, amount: number, mongoose: Mongoose) => Promise<BulkBankPaymentDoc | null>;
@@ -0,0 +1,57 @@
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.getBulkBankPaymentFromStaticReference = void 0;
13
+ const common_1 = require("@riocrypto/common");
14
+ const bulk_bank_payment_1 = require("../models/bulk-bank-payment");
15
+ const static_bank_payment_reference_1 = require("../models/static-bank-payment-reference");
16
+ const user_1 = require("../models/user");
17
+ const getBulkBankPaymentFromStaticReference = (reference, amount, mongoose) => __awaiter(void 0, void 0, void 0, function* () {
18
+ // Ensure reference is defined
19
+ if (!reference) {
20
+ throw new Error("Invalid reference. Reference cannot be empty.");
21
+ }
22
+ // Check if first 3 characters are SPR
23
+ if (!reference.startsWith("SPR")) {
24
+ throw new Error("Invalid reference. Reference must start with SPR.");
25
+ }
26
+ const StaticBankPaymentReference = (0, static_bank_payment_reference_1.buildStaticBankPaymentReference)(mongoose);
27
+ const staticBankPaymentReference = yield StaticBankPaymentReference.findOne({
28
+ reference: reference,
29
+ });
30
+ if (!staticBankPaymentReference) {
31
+ throw new Error("Static bank payment reference not found");
32
+ }
33
+ const User = (0, user_1.buildUser)(mongoose);
34
+ const user = yield User.findById(staticBankPaymentReference.userId);
35
+ if (!user) {
36
+ throw new Error("User not found");
37
+ }
38
+ const BulkBankPayment = (0, bulk_bank_payment_1.buildBulkBankPayment)(mongoose);
39
+ // Find the oldest bulk bank payment that is awaiting payment and has the
40
+ // same amount and fiat as the static bank payment reference
41
+ const bulkBankPayment = yield BulkBankPayment.findOne({
42
+ userId: user.id,
43
+ fiat: staticBankPaymentReference.fiat,
44
+ status: {
45
+ $in: [
46
+ common_1.BulkBankPaymentStatus.AwaitingPayment,
47
+ common_1.BulkBankPaymentStatus.AwaitingAsyncPayment,
48
+ ],
49
+ },
50
+ amount: amount,
51
+ }).sort({ createdAt: 1 });
52
+ if (!bulkBankPayment) {
53
+ throw new Error("Bulk bank payment not found");
54
+ }
55
+ return bulkBankPayment;
56
+ });
57
+ exports.getBulkBankPaymentFromStaticReference = getBulkBankPaymentFromStaticReference;
package/build/index.d.ts CHANGED
@@ -169,6 +169,7 @@ export * from "./helpers/get-bulk-payment-from-reference";
169
169
  export * from "./helpers/extract-error-message";
170
170
  export * from "./helpers/get-exchange-rates-with-markups";
171
171
  export * from "./helpers/get-order-from-static-reference";
172
+ export * from "./helpers/get-bulk-bank-payment-from-static-reference";
172
173
  export * from "./helpers/is-after-hours";
173
174
  export * from "./helpers/interpolate-forward-curve-rate";
174
175
  export * from "./helpers/find-user-tier-forward-curve-rate";
package/build/index.js CHANGED
@@ -185,6 +185,7 @@ __exportStar(require("./helpers/get-bulk-payment-from-reference"), exports);
185
185
  __exportStar(require("./helpers/extract-error-message"), exports);
186
186
  __exportStar(require("./helpers/get-exchange-rates-with-markups"), exports);
187
187
  __exportStar(require("./helpers/get-order-from-static-reference"), exports);
188
+ __exportStar(require("./helpers/get-bulk-bank-payment-from-static-reference"), exports);
188
189
  __exportStar(require("./helpers/is-after-hours"), exports);
189
190
  __exportStar(require("./helpers/interpolate-forward-curve-rate"), exports);
190
191
  __exportStar(require("./helpers/find-user-tier-forward-curve-rate"), exports);
@@ -91,6 +91,14 @@ const buildFireblocksTransfer = (mongoose) => {
91
91
  },
92
92
  },
93
93
  });
94
+ // Backs the dispatch worker poll ({ type, "fireblocksTransfers.status": queued })
95
+ // and the reconciliation sweeper ($elemMatch on status). Without it, both run as
96
+ // full collection scans on every tick.
97
+ FireblocksTransferSchema.index({ type: 1, "fireblocksTransfers.status": 1 });
98
+ // Back the Fireblocks webhook correlation ($or on rioId / fireblocksTransferId)
99
+ // and the reconciliation lookups by rioId.
100
+ FireblocksTransferSchema.index({ "fireblocksTransfers.rioId": 1 });
101
+ FireblocksTransferSchema.index({ "fireblocksTransfers.fireblocksTransferId": 1 });
94
102
  FireblocksTransferSchema.statics.build = (attrs) => {
95
103
  return new FireblocksTransfer(attrs);
96
104
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2812",
3
+ "version": "1.0.2816",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",