@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/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/orders.cjs +28 -7
- package/dist/orders.cjs.map +1 -1
- package/dist/orders.mjs +28 -7
- package/dist/orders.mjs.map +1 -1
- package/dist/prices.cjs +9 -1
- package/dist/prices.cjs.map +1 -1
- package/dist/prices.mjs +9 -1
- package/dist/prices.mjs.map +1 -1
- package/dist/profile.cjs +9 -1
- package/dist/profile.cjs.map +1 -1
- package/dist/profile.mjs +9 -1
- package/dist/profile.mjs.map +1 -1
- package/dist/react.cjs +65 -17
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +6 -0
- package/dist/react.d.ts +6 -0
- package/dist/react.mjs +65 -17
- package/dist/react.mjs.map +1 -1
- package/dist/stake.cjs +44 -10
- package/dist/stake.cjs.map +1 -1
- package/dist/stake.d.cts +6 -0
- package/dist/stake.d.ts +6 -0
- package/dist/stake.mjs +44 -10
- package/dist/stake.mjs.map +1 -1
- package/dist/zkkyc.cjs +7 -0
- package/dist/zkkyc.cjs.map +1 -1
- package/dist/zkkyc.mjs +7 -0
- package/dist/zkkyc.mjs.map +1 -1
- package/package.json +1 -1
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.1
|
|
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
package/dist/orders.cjs
CHANGED
|
@@ -564,6 +564,13 @@ var p2pStakeBoostFacetAbi = [
|
|
|
564
564
|
stateMutability: "nonpayable",
|
|
565
565
|
type: "function"
|
|
566
566
|
},
|
|
567
|
+
{
|
|
568
|
+
inputs: [],
|
|
569
|
+
name: "p2pBoostCancelUnstake",
|
|
570
|
+
outputs: [],
|
|
571
|
+
stateMutability: "nonpayable",
|
|
572
|
+
type: "function"
|
|
573
|
+
},
|
|
567
574
|
{
|
|
568
575
|
inputs: [{ internalType: "address", name: "user", type: "address" }],
|
|
569
576
|
name: "getUserStake",
|
|
@@ -5216,7 +5223,8 @@ var OrderRoutingError = class extends SdkError {
|
|
|
5216
5223
|
// src/orders/internal/routing/validation.ts
|
|
5217
5224
|
var import_zod5 = require("zod");
|
|
5218
5225
|
var ZodCircleScoreStateSchema = import_zod5.z.object({
|
|
5219
|
-
activeMerchantsCount: import_zod5.z.coerce.number()
|
|
5226
|
+
activeMerchantsCount: import_zod5.z.coerce.number(),
|
|
5227
|
+
availableMerchantsCount: import_zod5.z.coerce.number()
|
|
5220
5228
|
});
|
|
5221
5229
|
var ZodCircleMetricsForRoutingSchema = import_zod5.z.object({
|
|
5222
5230
|
circleScore: import_zod5.z.coerce.number(),
|
|
@@ -5432,8 +5440,9 @@ var import_neverthrow13 = require("neverthrow");
|
|
|
5432
5440
|
var EPSILON = 0.25;
|
|
5433
5441
|
var RECOVERY_SCALE = 0.3;
|
|
5434
5442
|
var BOOTSTRAP_MAX_WEIGHT = 25;
|
|
5443
|
+
var BOOTSTRAP_RESERVE = 0.1;
|
|
5435
5444
|
var MAX_VALIDATION_ATTEMPTS = 3;
|
|
5436
|
-
function
|
|
5445
|
+
function baseScore(c) {
|
|
5437
5446
|
const score = c.metrics.circleScore;
|
|
5438
5447
|
if (c.metrics.circleStatus === "paused") {
|
|
5439
5448
|
return score * RECOVERY_SCALE;
|
|
@@ -5443,8 +5452,13 @@ function circleWeight(c) {
|
|
|
5443
5452
|
}
|
|
5444
5453
|
return score;
|
|
5445
5454
|
}
|
|
5455
|
+
function circleWeight(c) {
|
|
5456
|
+
return baseScore(c) * c.metrics.scoreState.availableMerchantsCount;
|
|
5457
|
+
}
|
|
5446
5458
|
function filterEligibleCircles(circles, orderCurrency) {
|
|
5447
|
-
return circles.filter(
|
|
5459
|
+
return circles.filter(
|
|
5460
|
+
(c) => c.currency.toLowerCase() === orderCurrency.toLowerCase() && c.metrics.scoreState.availableMerchantsCount > 0
|
|
5461
|
+
);
|
|
5448
5462
|
}
|
|
5449
5463
|
function weightedRandomChoice(arr, weights) {
|
|
5450
5464
|
const totalWeight = weights.reduce((sum, w) => sum + w, 0);
|
|
@@ -5464,8 +5478,14 @@ function selectCircle(eligible) {
|
|
|
5464
5478
|
if (eligible.length === 0) {
|
|
5465
5479
|
return null;
|
|
5466
5480
|
}
|
|
5481
|
+
const bootstrapCircles = eligible.filter((c) => c.metrics.circleStatus === "bootstrap");
|
|
5467
5482
|
const activeCircles = eligible.filter((c) => c.metrics.circleStatus === "active");
|
|
5468
|
-
const
|
|
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;
|
|
5469
5489
|
if (isExplore) {
|
|
5470
5490
|
const weights2 = eligible.map(circleWeight);
|
|
5471
5491
|
return weightedRandomChoice(eligible, weights2);
|
|
@@ -5474,7 +5494,7 @@ function selectCircle(eligible) {
|
|
|
5474
5494
|
const weights2 = eligible.map(circleWeight);
|
|
5475
5495
|
return weightedRandomChoice(eligible, weights2);
|
|
5476
5496
|
}
|
|
5477
|
-
const weights = activeCircles.map(
|
|
5497
|
+
const weights = activeCircles.map(circleWeight);
|
|
5478
5498
|
return weightedRandomChoice(activeCircles, weights);
|
|
5479
5499
|
}
|
|
5480
5500
|
function selectCircleForOrderAsync(circles, orderCurrency, validateCircle, logger = noopLogger) {
|
|
@@ -5559,6 +5579,7 @@ var CIRCLES_FOR_ROUTING_QUERY = (
|
|
|
5559
5579
|
circleStatus
|
|
5560
5580
|
scoreState {
|
|
5561
5581
|
activeMerchantsCount
|
|
5582
|
+
availableMerchantsCount
|
|
5562
5583
|
}
|
|
5563
5584
|
}
|
|
5564
5585
|
}
|
|
@@ -5585,11 +5606,11 @@ function getCirclesForRouting(subgraphUrl, currency, logger = noopLogger) {
|
|
|
5585
5606
|
(message, cause, d) => new OrderRoutingError(message, { code: "VALIDATION_ERROR", cause, context: { data: d } })
|
|
5586
5607
|
).map((validated) => {
|
|
5587
5608
|
const circles = validated.circles.filter(
|
|
5588
|
-
(item) => Number(item.metrics.scoreState.
|
|
5609
|
+
(item) => Number(item.metrics.scoreState.availableMerchantsCount) > 0
|
|
5589
5610
|
);
|
|
5590
5611
|
logger.info("fetched circles from subgraph", {
|
|
5591
5612
|
total: validated.circles.length,
|
|
5592
|
-
|
|
5613
|
+
withAvailableMerchants: circles.length,
|
|
5593
5614
|
circles
|
|
5594
5615
|
});
|
|
5595
5616
|
return circles;
|