@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/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.2";
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.2";
41
41
  export {
42
42
  SdkError,
43
43
  VERSION
package/dist/orders.cjs CHANGED
@@ -831,6 +831,32 @@ var reputationManagerAbi = [
831
831
  outputs: [],
832
832
  stateMutability: "nonpayable",
833
833
  type: "function"
834
+ },
835
+ {
836
+ inputs: [
837
+ { internalType: "bytes32", name: "nullifier", type: "bytes32" },
838
+ { internalType: "uint256", name: "limit", type: "uint256" },
839
+ { internalType: "uint256", name: "expiry", type: "uint256" },
840
+ { internalType: "bytes", name: "signature", type: "bytes" }
841
+ ],
842
+ name: "submitKycAttestation",
843
+ outputs: [],
844
+ stateMutability: "nonpayable",
845
+ type: "function"
846
+ },
847
+ {
848
+ inputs: [],
849
+ name: "kycRp",
850
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
851
+ stateMutability: "view",
852
+ type: "function"
853
+ },
854
+ {
855
+ inputs: [{ internalType: "address", name: "", type: "address" }],
856
+ name: "kycVerified",
857
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
858
+ stateMutability: "view",
859
+ type: "function"
834
860
  }
835
861
  ];
836
862
 
@@ -5223,7 +5249,8 @@ var OrderRoutingError = class extends SdkError {
5223
5249
  // src/orders/internal/routing/validation.ts
5224
5250
  var import_zod5 = require("zod");
5225
5251
  var ZodCircleScoreStateSchema = import_zod5.z.object({
5226
- activeMerchantsCount: import_zod5.z.coerce.number()
5252
+ activeMerchantsCount: import_zod5.z.coerce.number(),
5253
+ availableMerchantsCount: import_zod5.z.coerce.number()
5227
5254
  });
5228
5255
  var ZodCircleMetricsForRoutingSchema = import_zod5.z.object({
5229
5256
  circleScore: import_zod5.z.coerce.number(),
@@ -5408,6 +5435,20 @@ var ZodZkPassportRegisterParamsSchema = import_zod8.z.object({
5408
5435
  params: ZodSolidityVerifierParametersSchema,
5409
5436
  isIDCard: import_zod8.z.boolean()
5410
5437
  });
5438
+ var ZodSimpleKycSubmitParamsSchema = import_zod8.z.object({
5439
+ /** Per-(tenant, identity) Sybil nullifier (bytes32 hex). */
5440
+ nullifier: import_zod8.z.string().refine((v) => /^0x[a-fA-F0-9]{64}$/.test(v), {
5441
+ message: "nullifier must be a bytes32 hex string"
5442
+ }),
5443
+ /** Remaining limit in micro-USDC (part of the signed struct). */
5444
+ limit: import_zod8.z.bigint(),
5445
+ /** Attestation expiry (unix seconds). */
5446
+ expiry: import_zod8.z.bigint(),
5447
+ /** 65-byte secp256k1 signature (hex). */
5448
+ signature: import_zod8.z.string().refine((v) => /^0x[a-fA-F0-9]+$/.test(v), {
5449
+ message: "signature must be a hex string"
5450
+ })
5451
+ });
5411
5452
 
5412
5453
  // src/contracts/tx-limits/index.ts
5413
5454
  var import_neverthrow11 = require("neverthrow");
@@ -5439,8 +5480,9 @@ var import_neverthrow13 = require("neverthrow");
5439
5480
  var EPSILON = 0.25;
5440
5481
  var RECOVERY_SCALE = 0.3;
5441
5482
  var BOOTSTRAP_MAX_WEIGHT = 25;
5483
+ var BOOTSTRAP_RESERVE = 0.1;
5442
5484
  var MAX_VALIDATION_ATTEMPTS = 3;
5443
- function circleWeight(c) {
5485
+ function baseScore(c) {
5444
5486
  const score = c.metrics.circleScore;
5445
5487
  if (c.metrics.circleStatus === "paused") {
5446
5488
  return score * RECOVERY_SCALE;
@@ -5450,8 +5492,13 @@ function circleWeight(c) {
5450
5492
  }
5451
5493
  return score;
5452
5494
  }
5495
+ function circleWeight(c) {
5496
+ return baseScore(c) * c.metrics.scoreState.availableMerchantsCount;
5497
+ }
5453
5498
  function filterEligibleCircles(circles, orderCurrency) {
5454
- return circles.filter((c) => c.currency.toLowerCase() === orderCurrency.toLowerCase());
5499
+ return circles.filter(
5500
+ (c) => c.currency.toLowerCase() === orderCurrency.toLowerCase() && c.metrics.scoreState.availableMerchantsCount > 0
5501
+ );
5455
5502
  }
5456
5503
  function weightedRandomChoice(arr, weights) {
5457
5504
  const totalWeight = weights.reduce((sum, w) => sum + w, 0);
@@ -5471,8 +5518,14 @@ function selectCircle(eligible) {
5471
5518
  if (eligible.length === 0) {
5472
5519
  return null;
5473
5520
  }
5521
+ const bootstrapCircles = eligible.filter((c) => c.metrics.circleStatus === "bootstrap");
5474
5522
  const activeCircles = eligible.filter((c) => c.metrics.circleStatus === "active");
5475
- const isExplore = Math.random() < EPSILON;
5523
+ const r = Math.random();
5524
+ if (r < BOOTSTRAP_RESERVE && bootstrapCircles.length > 0) {
5525
+ const weights2 = bootstrapCircles.map(circleWeight);
5526
+ return weightedRandomChoice(bootstrapCircles, weights2);
5527
+ }
5528
+ const isExplore = r < BOOTSTRAP_RESERVE + EPSILON;
5476
5529
  if (isExplore) {
5477
5530
  const weights2 = eligible.map(circleWeight);
5478
5531
  return weightedRandomChoice(eligible, weights2);
@@ -5481,7 +5534,7 @@ function selectCircle(eligible) {
5481
5534
  const weights2 = eligible.map(circleWeight);
5482
5535
  return weightedRandomChoice(eligible, weights2);
5483
5536
  }
5484
- const weights = activeCircles.map((c) => c.metrics.circleScore);
5537
+ const weights = activeCircles.map(circleWeight);
5485
5538
  return weightedRandomChoice(activeCircles, weights);
5486
5539
  }
5487
5540
  function selectCircleForOrderAsync(circles, orderCurrency, validateCircle, logger = noopLogger) {
@@ -5566,6 +5619,7 @@ var CIRCLES_FOR_ROUTING_QUERY = (
5566
5619
  circleStatus
5567
5620
  scoreState {
5568
5621
  activeMerchantsCount
5622
+ availableMerchantsCount
5569
5623
  }
5570
5624
  }
5571
5625
  }
@@ -5592,11 +5646,11 @@ function getCirclesForRouting(subgraphUrl, currency, logger = noopLogger) {
5592
5646
  (message, cause, d) => new OrderRoutingError(message, { code: "VALIDATION_ERROR", cause, context: { data: d } })
5593
5647
  ).map((validated) => {
5594
5648
  const circles = validated.circles.filter(
5595
- (item) => Number(item.metrics.scoreState.activeMerchantsCount) > 0
5649
+ (item) => Number(item.metrics.scoreState.availableMerchantsCount) > 0
5596
5650
  );
5597
5651
  logger.info("fetched circles from subgraph", {
5598
5652
  total: validated.circles.length,
5599
- withActiveMerchants: circles.length,
5653
+ withAvailableMerchants: circles.length,
5600
5654
  circles
5601
5655
  });
5602
5656
  return circles;