@p2pdotme/sdk 1.1.9 → 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/orders.mjs CHANGED
@@ -515,6 +515,13 @@ var p2pStakeBoostFacetAbi = [
515
515
  stateMutability: "nonpayable",
516
516
  type: "function"
517
517
  },
518
+ {
519
+ inputs: [],
520
+ name: "p2pBoostCancelUnstake",
521
+ outputs: [],
522
+ stateMutability: "nonpayable",
523
+ type: "function"
524
+ },
518
525
  {
519
526
  inputs: [{ internalType: "address", name: "user", type: "address" }],
520
527
  name: "getUserStake",
@@ -5167,7 +5174,8 @@ var OrderRoutingError = class extends SdkError {
5167
5174
  // src/orders/internal/routing/validation.ts
5168
5175
  import { z as z5 } from "zod";
5169
5176
  var ZodCircleScoreStateSchema = z5.object({
5170
- activeMerchantsCount: z5.coerce.number()
5177
+ activeMerchantsCount: z5.coerce.number(),
5178
+ availableMerchantsCount: z5.coerce.number()
5171
5179
  });
5172
5180
  var ZodCircleMetricsForRoutingSchema = z5.object({
5173
5181
  circleScore: z5.coerce.number(),
@@ -5383,8 +5391,9 @@ import { errAsync as errAsync2, okAsync as okAsync3 } from "neverthrow";
5383
5391
  var EPSILON = 0.25;
5384
5392
  var RECOVERY_SCALE = 0.3;
5385
5393
  var BOOTSTRAP_MAX_WEIGHT = 25;
5394
+ var BOOTSTRAP_RESERVE = 0.1;
5386
5395
  var MAX_VALIDATION_ATTEMPTS = 3;
5387
- function circleWeight(c) {
5396
+ function baseScore(c) {
5388
5397
  const score = c.metrics.circleScore;
5389
5398
  if (c.metrics.circleStatus === "paused") {
5390
5399
  return score * RECOVERY_SCALE;
@@ -5394,8 +5403,13 @@ function circleWeight(c) {
5394
5403
  }
5395
5404
  return score;
5396
5405
  }
5406
+ function circleWeight(c) {
5407
+ return baseScore(c) * c.metrics.scoreState.availableMerchantsCount;
5408
+ }
5397
5409
  function filterEligibleCircles(circles, orderCurrency) {
5398
- return circles.filter((c) => c.currency.toLowerCase() === orderCurrency.toLowerCase());
5410
+ return circles.filter(
5411
+ (c) => c.currency.toLowerCase() === orderCurrency.toLowerCase() && c.metrics.scoreState.availableMerchantsCount > 0
5412
+ );
5399
5413
  }
5400
5414
  function weightedRandomChoice(arr, weights) {
5401
5415
  const totalWeight = weights.reduce((sum, w) => sum + w, 0);
@@ -5415,8 +5429,14 @@ function selectCircle(eligible) {
5415
5429
  if (eligible.length === 0) {
5416
5430
  return null;
5417
5431
  }
5432
+ const bootstrapCircles = eligible.filter((c) => c.metrics.circleStatus === "bootstrap");
5418
5433
  const activeCircles = eligible.filter((c) => c.metrics.circleStatus === "active");
5419
- const isExplore = Math.random() < EPSILON;
5434
+ const r = Math.random();
5435
+ if (r < BOOTSTRAP_RESERVE && bootstrapCircles.length > 0) {
5436
+ const weights2 = bootstrapCircles.map(circleWeight);
5437
+ return weightedRandomChoice(bootstrapCircles, weights2);
5438
+ }
5439
+ const isExplore = r < BOOTSTRAP_RESERVE + EPSILON;
5420
5440
  if (isExplore) {
5421
5441
  const weights2 = eligible.map(circleWeight);
5422
5442
  return weightedRandomChoice(eligible, weights2);
@@ -5425,7 +5445,7 @@ function selectCircle(eligible) {
5425
5445
  const weights2 = eligible.map(circleWeight);
5426
5446
  return weightedRandomChoice(eligible, weights2);
5427
5447
  }
5428
- const weights = activeCircles.map((c) => c.metrics.circleScore);
5448
+ const weights = activeCircles.map(circleWeight);
5429
5449
  return weightedRandomChoice(activeCircles, weights);
5430
5450
  }
5431
5451
  function selectCircleForOrderAsync(circles, orderCurrency, validateCircle, logger = noopLogger) {
@@ -5510,6 +5530,7 @@ var CIRCLES_FOR_ROUTING_QUERY = (
5510
5530
  circleStatus
5511
5531
  scoreState {
5512
5532
  activeMerchantsCount
5533
+ availableMerchantsCount
5513
5534
  }
5514
5535
  }
5515
5536
  }
@@ -5536,11 +5557,11 @@ function getCirclesForRouting(subgraphUrl, currency, logger = noopLogger) {
5536
5557
  (message, cause, d) => new OrderRoutingError(message, { code: "VALIDATION_ERROR", cause, context: { data: d } })
5537
5558
  ).map((validated) => {
5538
5559
  const circles = validated.circles.filter(
5539
- (item) => Number(item.metrics.scoreState.activeMerchantsCount) > 0
5560
+ (item) => Number(item.metrics.scoreState.availableMerchantsCount) > 0
5540
5561
  );
5541
5562
  logger.info("fetched circles from subgraph", {
5542
5563
  total: validated.circles.length,
5543
- withActiveMerchants: circles.length,
5564
+ withAvailableMerchants: circles.length,
5544
5565
  circles
5545
5566
  });
5546
5567
  return circles;