@riocrypto/common-server 1.0.2815 → 1.0.2818

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.
@@ -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
  };
@@ -35,6 +35,7 @@ interface OrderAttrs {
35
35
  withdrawalTxId?: string;
36
36
  withdrawalTxIds?: string[];
37
37
  brokerId?: string;
38
+ rootUserId?: string;
38
39
  limitNetPrice?: number;
39
40
  timeInForceStartsAt?: Date;
40
41
  timeInForceEndsAt?: Date;
@@ -181,6 +182,7 @@ interface OrderDoc extends Document {
181
182
  withdrawalTxId?: string;
182
183
  withdrawalTxIds?: string[];
183
184
  brokerId?: string;
185
+ rootUserId?: string;
184
186
  conversionRateUSD: number;
185
187
  conversionRateUSDWithMarkups: number;
186
188
  actualConversionRateUSD?: number;
@@ -186,6 +186,9 @@ const buildOrder = (mongoose) => {
186
186
  brokerId: {
187
187
  type: String,
188
188
  },
189
+ rootUserId: {
190
+ type: String,
191
+ },
189
192
  conversionRateUSD: {
190
193
  type: Number,
191
194
  required: true,
@@ -383,6 +386,16 @@ const buildOrder = (mongoose) => {
383
386
  orderSchema.index({ brokerId: 1, "TWAP.sessionId": 1, createdAt: 1 });
384
387
  orderSchema.index({ clientReferenceId: 1 }, { sparse: true });
385
388
  orderSchema.index({ "paymentsReceived.blockchainTxId": 1 }, { sparse: true });
389
+ // At most one order per real quoteId. Imported orders use quoteId "" and are
390
+ // excluded by the partial filter (which also serves the createOrder lookup).
391
+ orderSchema.index({ quoteId: 1 }, { unique: true, partialFilterExpression: { quoteId: { $gt: "" } } });
392
+ // At most one order per (broker family, clientReferenceId). rootUserId is
393
+ // brokerId || userId; orders without a clientReferenceId are excluded.
394
+ orderSchema.index({ rootUserId: 1, clientReferenceId: 1 }, { unique: true, partialFilterExpression: { clientReferenceId: { $type: "string" } } });
395
+ orderSchema.pre("validate", function (next) {
396
+ this.rootUserId = this.brokerId || this.userId;
397
+ next();
398
+ });
386
399
  orderSchema.statics.build = (attrs) => {
387
400
  return new Order(attrs);
388
401
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2815",
3
+ "version": "1.0.2818",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",