@p2pdotme/sdk 1.2.0 → 1.2.2

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
@@ -782,6 +782,32 @@ var reputationManagerAbi = [
782
782
  outputs: [],
783
783
  stateMutability: "nonpayable",
784
784
  type: "function"
785
+ },
786
+ {
787
+ inputs: [
788
+ { internalType: "bytes32", name: "nullifier", type: "bytes32" },
789
+ { internalType: "uint256", name: "limit", type: "uint256" },
790
+ { internalType: "uint256", name: "expiry", type: "uint256" },
791
+ { internalType: "bytes", name: "signature", type: "bytes" }
792
+ ],
793
+ name: "submitKycAttestation",
794
+ outputs: [],
795
+ stateMutability: "nonpayable",
796
+ type: "function"
797
+ },
798
+ {
799
+ inputs: [],
800
+ name: "kycRp",
801
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
802
+ stateMutability: "view",
803
+ type: "function"
804
+ },
805
+ {
806
+ inputs: [{ internalType: "address", name: "", type: "address" }],
807
+ name: "kycVerified",
808
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
809
+ stateMutability: "view",
810
+ type: "function"
785
811
  }
786
812
  ];
787
813
 
@@ -5174,7 +5200,8 @@ var OrderRoutingError = class extends SdkError {
5174
5200
  // src/orders/internal/routing/validation.ts
5175
5201
  import { z as z5 } from "zod";
5176
5202
  var ZodCircleScoreStateSchema = z5.object({
5177
- activeMerchantsCount: z5.coerce.number()
5203
+ activeMerchantsCount: z5.coerce.number(),
5204
+ availableMerchantsCount: z5.coerce.number()
5178
5205
  });
5179
5206
  var ZodCircleMetricsForRoutingSchema = z5.object({
5180
5207
  circleScore: z5.coerce.number(),
@@ -5359,6 +5386,20 @@ var ZodZkPassportRegisterParamsSchema = z8.object({
5359
5386
  params: ZodSolidityVerifierParametersSchema,
5360
5387
  isIDCard: z8.boolean()
5361
5388
  });
5389
+ var ZodSimpleKycSubmitParamsSchema = z8.object({
5390
+ /** Per-(tenant, identity) Sybil nullifier (bytes32 hex). */
5391
+ nullifier: z8.string().refine((v) => /^0x[a-fA-F0-9]{64}$/.test(v), {
5392
+ message: "nullifier must be a bytes32 hex string"
5393
+ }),
5394
+ /** Remaining limit in micro-USDC (part of the signed struct). */
5395
+ limit: z8.bigint(),
5396
+ /** Attestation expiry (unix seconds). */
5397
+ expiry: z8.bigint(),
5398
+ /** 65-byte secp256k1 signature (hex). */
5399
+ signature: z8.string().refine((v) => /^0x[a-fA-F0-9]+$/.test(v), {
5400
+ message: "signature must be a hex string"
5401
+ })
5402
+ });
5362
5403
 
5363
5404
  // src/contracts/tx-limits/index.ts
5364
5405
  import { ResultAsync as ResultAsync9 } from "neverthrow";
@@ -5390,8 +5431,9 @@ import { errAsync as errAsync2, okAsync as okAsync3 } from "neverthrow";
5390
5431
  var EPSILON = 0.25;
5391
5432
  var RECOVERY_SCALE = 0.3;
5392
5433
  var BOOTSTRAP_MAX_WEIGHT = 25;
5434
+ var BOOTSTRAP_RESERVE = 0.1;
5393
5435
  var MAX_VALIDATION_ATTEMPTS = 3;
5394
- function circleWeight(c) {
5436
+ function baseScore(c) {
5395
5437
  const score = c.metrics.circleScore;
5396
5438
  if (c.metrics.circleStatus === "paused") {
5397
5439
  return score * RECOVERY_SCALE;
@@ -5401,8 +5443,13 @@ function circleWeight(c) {
5401
5443
  }
5402
5444
  return score;
5403
5445
  }
5446
+ function circleWeight(c) {
5447
+ return baseScore(c) * c.metrics.scoreState.availableMerchantsCount;
5448
+ }
5404
5449
  function filterEligibleCircles(circles, orderCurrency) {
5405
- return circles.filter((c) => c.currency.toLowerCase() === orderCurrency.toLowerCase());
5450
+ return circles.filter(
5451
+ (c) => c.currency.toLowerCase() === orderCurrency.toLowerCase() && c.metrics.scoreState.availableMerchantsCount > 0
5452
+ );
5406
5453
  }
5407
5454
  function weightedRandomChoice(arr, weights) {
5408
5455
  const totalWeight = weights.reduce((sum, w) => sum + w, 0);
@@ -5422,8 +5469,14 @@ function selectCircle(eligible) {
5422
5469
  if (eligible.length === 0) {
5423
5470
  return null;
5424
5471
  }
5472
+ const bootstrapCircles = eligible.filter((c) => c.metrics.circleStatus === "bootstrap");
5425
5473
  const activeCircles = eligible.filter((c) => c.metrics.circleStatus === "active");
5426
- const isExplore = Math.random() < EPSILON;
5474
+ const r = Math.random();
5475
+ if (r < BOOTSTRAP_RESERVE && bootstrapCircles.length > 0) {
5476
+ const weights2 = bootstrapCircles.map(circleWeight);
5477
+ return weightedRandomChoice(bootstrapCircles, weights2);
5478
+ }
5479
+ const isExplore = r < BOOTSTRAP_RESERVE + EPSILON;
5427
5480
  if (isExplore) {
5428
5481
  const weights2 = eligible.map(circleWeight);
5429
5482
  return weightedRandomChoice(eligible, weights2);
@@ -5432,7 +5485,7 @@ function selectCircle(eligible) {
5432
5485
  const weights2 = eligible.map(circleWeight);
5433
5486
  return weightedRandomChoice(eligible, weights2);
5434
5487
  }
5435
- const weights = activeCircles.map((c) => c.metrics.circleScore);
5488
+ const weights = activeCircles.map(circleWeight);
5436
5489
  return weightedRandomChoice(activeCircles, weights);
5437
5490
  }
5438
5491
  function selectCircleForOrderAsync(circles, orderCurrency, validateCircle, logger = noopLogger) {
@@ -5517,6 +5570,7 @@ var CIRCLES_FOR_ROUTING_QUERY = (
5517
5570
  circleStatus
5518
5571
  scoreState {
5519
5572
  activeMerchantsCount
5573
+ availableMerchantsCount
5520
5574
  }
5521
5575
  }
5522
5576
  }
@@ -5543,11 +5597,11 @@ function getCirclesForRouting(subgraphUrl, currency, logger = noopLogger) {
5543
5597
  (message, cause, d) => new OrderRoutingError(message, { code: "VALIDATION_ERROR", cause, context: { data: d } })
5544
5598
  ).map((validated) => {
5545
5599
  const circles = validated.circles.filter(
5546
- (item) => Number(item.metrics.scoreState.activeMerchantsCount) > 0
5600
+ (item) => Number(item.metrics.scoreState.availableMerchantsCount) > 0
5547
5601
  );
5548
5602
  logger.info("fetched circles from subgraph", {
5549
5603
  total: validated.circles.length,
5550
- withActiveMerchants: circles.length,
5604
+ withAvailableMerchants: circles.length,
5551
5605
  circles
5552
5606
  });
5553
5607
  return circles;