@p2pdotme/sdk 1.2.0 → 1.2.1

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/dist/index.cjs CHANGED
@@ -64,7 +64,7 @@ var ZodAddressSchema = import_zod.z.string().refine((s) => (0, import_viem.isAdd
64
64
  var ZodCurrencySchema = import_zod.z.enum(CURRENCY_CODES);
65
65
 
66
66
  // src/index.ts
67
- var VERSION = "1.2.0";
67
+ var VERSION = "1.2.1";
68
68
  // Annotate the CommonJS export names for ESM import in node:
69
69
  0 && (module.exports = {
70
70
  SdkError,
package/dist/index.mjs CHANGED
@@ -37,7 +37,7 @@ var ZodAddressSchema = z.string().refine((s) => isAddress(s), { message: "Invali
37
37
  var ZodCurrencySchema = z.enum(CURRENCY_CODES);
38
38
 
39
39
  // src/index.ts
40
- var VERSION = "1.2.0";
40
+ var VERSION = "1.2.1";
41
41
  export {
42
42
  SdkError,
43
43
  VERSION
package/dist/orders.cjs CHANGED
@@ -5223,7 +5223,8 @@ var OrderRoutingError = class extends SdkError {
5223
5223
  // src/orders/internal/routing/validation.ts
5224
5224
  var import_zod5 = require("zod");
5225
5225
  var ZodCircleScoreStateSchema = import_zod5.z.object({
5226
- activeMerchantsCount: import_zod5.z.coerce.number()
5226
+ activeMerchantsCount: import_zod5.z.coerce.number(),
5227
+ availableMerchantsCount: import_zod5.z.coerce.number()
5227
5228
  });
5228
5229
  var ZodCircleMetricsForRoutingSchema = import_zod5.z.object({
5229
5230
  circleScore: import_zod5.z.coerce.number(),
@@ -5439,8 +5440,9 @@ var import_neverthrow13 = require("neverthrow");
5439
5440
  var EPSILON = 0.25;
5440
5441
  var RECOVERY_SCALE = 0.3;
5441
5442
  var BOOTSTRAP_MAX_WEIGHT = 25;
5443
+ var BOOTSTRAP_RESERVE = 0.1;
5442
5444
  var MAX_VALIDATION_ATTEMPTS = 3;
5443
- function circleWeight(c) {
5445
+ function baseScore(c) {
5444
5446
  const score = c.metrics.circleScore;
5445
5447
  if (c.metrics.circleStatus === "paused") {
5446
5448
  return score * RECOVERY_SCALE;
@@ -5450,8 +5452,13 @@ function circleWeight(c) {
5450
5452
  }
5451
5453
  return score;
5452
5454
  }
5455
+ function circleWeight(c) {
5456
+ return baseScore(c) * c.metrics.scoreState.availableMerchantsCount;
5457
+ }
5453
5458
  function filterEligibleCircles(circles, orderCurrency) {
5454
- return circles.filter((c) => c.currency.toLowerCase() === orderCurrency.toLowerCase());
5459
+ return circles.filter(
5460
+ (c) => c.currency.toLowerCase() === orderCurrency.toLowerCase() && c.metrics.scoreState.availableMerchantsCount > 0
5461
+ );
5455
5462
  }
5456
5463
  function weightedRandomChoice(arr, weights) {
5457
5464
  const totalWeight = weights.reduce((sum, w) => sum + w, 0);
@@ -5471,8 +5478,14 @@ function selectCircle(eligible) {
5471
5478
  if (eligible.length === 0) {
5472
5479
  return null;
5473
5480
  }
5481
+ const bootstrapCircles = eligible.filter((c) => c.metrics.circleStatus === "bootstrap");
5474
5482
  const activeCircles = eligible.filter((c) => c.metrics.circleStatus === "active");
5475
- const isExplore = Math.random() < EPSILON;
5483
+ const r = Math.random();
5484
+ if (r < BOOTSTRAP_RESERVE && bootstrapCircles.length > 0) {
5485
+ const weights2 = bootstrapCircles.map(circleWeight);
5486
+ return weightedRandomChoice(bootstrapCircles, weights2);
5487
+ }
5488
+ const isExplore = r < BOOTSTRAP_RESERVE + EPSILON;
5476
5489
  if (isExplore) {
5477
5490
  const weights2 = eligible.map(circleWeight);
5478
5491
  return weightedRandomChoice(eligible, weights2);
@@ -5481,7 +5494,7 @@ function selectCircle(eligible) {
5481
5494
  const weights2 = eligible.map(circleWeight);
5482
5495
  return weightedRandomChoice(eligible, weights2);
5483
5496
  }
5484
- const weights = activeCircles.map((c) => c.metrics.circleScore);
5497
+ const weights = activeCircles.map(circleWeight);
5485
5498
  return weightedRandomChoice(activeCircles, weights);
5486
5499
  }
5487
5500
  function selectCircleForOrderAsync(circles, orderCurrency, validateCircle, logger = noopLogger) {
@@ -5566,6 +5579,7 @@ var CIRCLES_FOR_ROUTING_QUERY = (
5566
5579
  circleStatus
5567
5580
  scoreState {
5568
5581
  activeMerchantsCount
5582
+ availableMerchantsCount
5569
5583
  }
5570
5584
  }
5571
5585
  }
@@ -5592,11 +5606,11 @@ function getCirclesForRouting(subgraphUrl, currency, logger = noopLogger) {
5592
5606
  (message, cause, d) => new OrderRoutingError(message, { code: "VALIDATION_ERROR", cause, context: { data: d } })
5593
5607
  ).map((validated) => {
5594
5608
  const circles = validated.circles.filter(
5595
- (item) => Number(item.metrics.scoreState.activeMerchantsCount) > 0
5609
+ (item) => Number(item.metrics.scoreState.availableMerchantsCount) > 0
5596
5610
  );
5597
5611
  logger.info("fetched circles from subgraph", {
5598
5612
  total: validated.circles.length,
5599
- withActiveMerchants: circles.length,
5613
+ withAvailableMerchants: circles.length,
5600
5614
  circles
5601
5615
  });
5602
5616
  return circles;