@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/react.cjs
CHANGED
|
@@ -1202,6 +1202,13 @@ var p2pStakeBoostFacetAbi = [
|
|
|
1202
1202
|
stateMutability: "nonpayable",
|
|
1203
1203
|
type: "function"
|
|
1204
1204
|
},
|
|
1205
|
+
{
|
|
1206
|
+
inputs: [],
|
|
1207
|
+
name: "p2pBoostCancelUnstake",
|
|
1208
|
+
outputs: [],
|
|
1209
|
+
stateMutability: "nonpayable",
|
|
1210
|
+
type: "function"
|
|
1211
|
+
},
|
|
1205
1212
|
{
|
|
1206
1213
|
inputs: [{ internalType: "address", name: "user", type: "address" }],
|
|
1207
1214
|
name: "getUserStake",
|
|
@@ -5435,7 +5442,8 @@ var OrderRoutingError = class extends SdkError {
|
|
|
5435
5442
|
// src/orders/internal/routing/validation.ts
|
|
5436
5443
|
var import_zod6 = require("zod");
|
|
5437
5444
|
var ZodCircleScoreStateSchema = import_zod6.z.object({
|
|
5438
|
-
activeMerchantsCount: import_zod6.z.coerce.number()
|
|
5445
|
+
activeMerchantsCount: import_zod6.z.coerce.number(),
|
|
5446
|
+
availableMerchantsCount: import_zod6.z.coerce.number()
|
|
5439
5447
|
});
|
|
5440
5448
|
var ZodCircleMetricsForRoutingSchema = import_zod6.z.object({
|
|
5441
5449
|
circleScore: import_zod6.z.coerce.number(),
|
|
@@ -6017,8 +6025,9 @@ var import_neverthrow15 = require("neverthrow");
|
|
|
6017
6025
|
var EPSILON = 0.25;
|
|
6018
6026
|
var RECOVERY_SCALE = 0.3;
|
|
6019
6027
|
var BOOTSTRAP_MAX_WEIGHT = 25;
|
|
6028
|
+
var BOOTSTRAP_RESERVE = 0.1;
|
|
6020
6029
|
var MAX_VALIDATION_ATTEMPTS = 3;
|
|
6021
|
-
function
|
|
6030
|
+
function baseScore(c) {
|
|
6022
6031
|
const score = c.metrics.circleScore;
|
|
6023
6032
|
if (c.metrics.circleStatus === "paused") {
|
|
6024
6033
|
return score * RECOVERY_SCALE;
|
|
@@ -6028,8 +6037,13 @@ function circleWeight(c) {
|
|
|
6028
6037
|
}
|
|
6029
6038
|
return score;
|
|
6030
6039
|
}
|
|
6040
|
+
function circleWeight(c) {
|
|
6041
|
+
return baseScore(c) * c.metrics.scoreState.availableMerchantsCount;
|
|
6042
|
+
}
|
|
6031
6043
|
function filterEligibleCircles(circles, orderCurrency) {
|
|
6032
|
-
return circles.filter(
|
|
6044
|
+
return circles.filter(
|
|
6045
|
+
(c) => c.currency.toLowerCase() === orderCurrency.toLowerCase() && c.metrics.scoreState.availableMerchantsCount > 0
|
|
6046
|
+
);
|
|
6033
6047
|
}
|
|
6034
6048
|
function weightedRandomChoice(arr, weights) {
|
|
6035
6049
|
const totalWeight = weights.reduce((sum, w) => sum + w, 0);
|
|
@@ -6049,8 +6063,14 @@ function selectCircle(eligible) {
|
|
|
6049
6063
|
if (eligible.length === 0) {
|
|
6050
6064
|
return null;
|
|
6051
6065
|
}
|
|
6066
|
+
const bootstrapCircles = eligible.filter((c) => c.metrics.circleStatus === "bootstrap");
|
|
6052
6067
|
const activeCircles = eligible.filter((c) => c.metrics.circleStatus === "active");
|
|
6053
|
-
const
|
|
6068
|
+
const r = Math.random();
|
|
6069
|
+
if (r < BOOTSTRAP_RESERVE && bootstrapCircles.length > 0) {
|
|
6070
|
+
const weights2 = bootstrapCircles.map(circleWeight);
|
|
6071
|
+
return weightedRandomChoice(bootstrapCircles, weights2);
|
|
6072
|
+
}
|
|
6073
|
+
const isExplore = r < BOOTSTRAP_RESERVE + EPSILON;
|
|
6054
6074
|
if (isExplore) {
|
|
6055
6075
|
const weights2 = eligible.map(circleWeight);
|
|
6056
6076
|
return weightedRandomChoice(eligible, weights2);
|
|
@@ -6059,7 +6079,7 @@ function selectCircle(eligible) {
|
|
|
6059
6079
|
const weights2 = eligible.map(circleWeight);
|
|
6060
6080
|
return weightedRandomChoice(eligible, weights2);
|
|
6061
6081
|
}
|
|
6062
|
-
const weights = activeCircles.map(
|
|
6082
|
+
const weights = activeCircles.map(circleWeight);
|
|
6063
6083
|
return weightedRandomChoice(activeCircles, weights);
|
|
6064
6084
|
}
|
|
6065
6085
|
function selectCircleForOrderAsync(circles, orderCurrency, validateCircle, logger = noopLogger) {
|
|
@@ -6144,6 +6164,7 @@ var CIRCLES_FOR_ROUTING_QUERY = (
|
|
|
6144
6164
|
circleStatus
|
|
6145
6165
|
scoreState {
|
|
6146
6166
|
activeMerchantsCount
|
|
6167
|
+
availableMerchantsCount
|
|
6147
6168
|
}
|
|
6148
6169
|
}
|
|
6149
6170
|
}
|
|
@@ -6170,11 +6191,11 @@ function getCirclesForRouting(subgraphUrl, currency, logger = noopLogger) {
|
|
|
6170
6191
|
(message, cause, d) => new OrderRoutingError(message, { code: "VALIDATION_ERROR", cause, context: { data: d } })
|
|
6171
6192
|
).map((validated) => {
|
|
6172
6193
|
const circles = validated.circles.filter(
|
|
6173
|
-
(item) => Number(item.metrics.scoreState.
|
|
6194
|
+
(item) => Number(item.metrics.scoreState.availableMerchantsCount) > 0
|
|
6174
6195
|
);
|
|
6175
6196
|
logger.info("fetched circles from subgraph", {
|
|
6176
6197
|
total: validated.circles.length,
|
|
6177
|
-
|
|
6198
|
+
withAvailableMerchants: circles.length,
|
|
6178
6199
|
circles
|
|
6179
6200
|
});
|
|
6180
6201
|
return circles;
|
|
@@ -6684,7 +6705,7 @@ function createProfile(config) {
|
|
|
6684
6705
|
};
|
|
6685
6706
|
}
|
|
6686
6707
|
|
|
6687
|
-
// src/stake/actions/
|
|
6708
|
+
// src/stake/actions/cancel-unstake.ts
|
|
6688
6709
|
var import_neverthrow21 = require("neverthrow");
|
|
6689
6710
|
var import_viem20 = require("viem");
|
|
6690
6711
|
|
|
@@ -6737,14 +6758,14 @@ function submitPreparedTx2(input) {
|
|
|
6737
6758
|
});
|
|
6738
6759
|
}
|
|
6739
6760
|
|
|
6740
|
-
// src/stake/actions/
|
|
6741
|
-
function
|
|
6761
|
+
// src/stake/actions/cancel-unstake.ts
|
|
6762
|
+
function createCancelUnstakeAction(input) {
|
|
6742
6763
|
const { publicClient, diamondAddress } = input;
|
|
6743
6764
|
const prepareFn = () => (0, import_neverthrow21.okAsync)({
|
|
6744
6765
|
to: diamondAddress,
|
|
6745
6766
|
data: (0, import_viem20.encodeFunctionData)({
|
|
6746
6767
|
abi: ABIS.FACETS.STAKE,
|
|
6747
|
-
functionName: "
|
|
6768
|
+
functionName: "p2pBoostCancelUnstake",
|
|
6748
6769
|
args: []
|
|
6749
6770
|
}),
|
|
6750
6771
|
value: 0n
|
|
@@ -6761,14 +6782,40 @@ function createClaimUnstakeAction(input) {
|
|
|
6761
6782
|
};
|
|
6762
6783
|
}
|
|
6763
6784
|
|
|
6764
|
-
// src/stake/actions/
|
|
6785
|
+
// src/stake/actions/claim-unstake.ts
|
|
6765
6786
|
var import_neverthrow22 = require("neverthrow");
|
|
6766
6787
|
var import_viem21 = require("viem");
|
|
6767
|
-
function
|
|
6788
|
+
function createClaimUnstakeAction(input) {
|
|
6768
6789
|
const { publicClient, diamondAddress } = input;
|
|
6769
6790
|
const prepareFn = () => (0, import_neverthrow22.okAsync)({
|
|
6770
6791
|
to: diamondAddress,
|
|
6771
6792
|
data: (0, import_viem21.encodeFunctionData)({
|
|
6793
|
+
abi: ABIS.FACETS.STAKE,
|
|
6794
|
+
functionName: "p2pBoostClaimUnstake",
|
|
6795
|
+
args: []
|
|
6796
|
+
}),
|
|
6797
|
+
value: 0n
|
|
6798
|
+
});
|
|
6799
|
+
return {
|
|
6800
|
+
prepare() {
|
|
6801
|
+
return prepareFn();
|
|
6802
|
+
},
|
|
6803
|
+
execute({ walletClient, waitForReceipt }) {
|
|
6804
|
+
return prepareFn().andThen(
|
|
6805
|
+
(prepared) => submitPreparedTx2({ prepared, walletClient, publicClient, waitForReceipt })
|
|
6806
|
+
);
|
|
6807
|
+
}
|
|
6808
|
+
};
|
|
6809
|
+
}
|
|
6810
|
+
|
|
6811
|
+
// src/stake/actions/request-unstake.ts
|
|
6812
|
+
var import_neverthrow23 = require("neverthrow");
|
|
6813
|
+
var import_viem22 = require("viem");
|
|
6814
|
+
function createRequestUnstakeAction(input) {
|
|
6815
|
+
const { publicClient, diamondAddress } = input;
|
|
6816
|
+
const prepareFn = () => (0, import_neverthrow23.okAsync)({
|
|
6817
|
+
to: diamondAddress,
|
|
6818
|
+
data: (0, import_viem22.encodeFunctionData)({
|
|
6772
6819
|
abi: ABIS.FACETS.STAKE,
|
|
6773
6820
|
functionName: "p2pBoostRequestUnstake",
|
|
6774
6821
|
args: []
|
|
@@ -6788,7 +6835,7 @@ function createRequestUnstakeAction(input) {
|
|
|
6788
6835
|
}
|
|
6789
6836
|
|
|
6790
6837
|
// src/stake/actions/stake.ts
|
|
6791
|
-
var
|
|
6838
|
+
var import_viem23 = require("viem");
|
|
6792
6839
|
function createStakeAction(input) {
|
|
6793
6840
|
const { publicClient, diamondAddress } = input;
|
|
6794
6841
|
const prepareFn = (params) => validate(
|
|
@@ -6801,7 +6848,7 @@ function createStakeAction(input) {
|
|
|
6801
6848
|
})
|
|
6802
6849
|
).map(({ tokens }) => ({
|
|
6803
6850
|
to: diamondAddress,
|
|
6804
|
-
data: (0,
|
|
6851
|
+
data: (0, import_viem23.encodeFunctionData)({
|
|
6805
6852
|
abi: ABIS.FACETS.STAKE,
|
|
6806
6853
|
functionName: "p2pBoostStake",
|
|
6807
6854
|
args: [tokens]
|
|
@@ -6821,7 +6868,7 @@ function createStakeAction(input) {
|
|
|
6821
6868
|
}
|
|
6822
6869
|
|
|
6823
6870
|
// src/stake/actions/top-up.ts
|
|
6824
|
-
var
|
|
6871
|
+
var import_viem24 = require("viem");
|
|
6825
6872
|
function createTopUpAction(input) {
|
|
6826
6873
|
const { publicClient, diamondAddress } = input;
|
|
6827
6874
|
const prepareFn = (params) => validate(
|
|
@@ -6834,7 +6881,7 @@ function createTopUpAction(input) {
|
|
|
6834
6881
|
})
|
|
6835
6882
|
).map(({ tokens }) => ({
|
|
6836
6883
|
to: diamondAddress,
|
|
6837
|
-
data: (0,
|
|
6884
|
+
data: (0, import_viem24.encodeFunctionData)({
|
|
6838
6885
|
abi: ABIS.FACETS.STAKE,
|
|
6839
6886
|
functionName: "p2pBoostTopUp",
|
|
6840
6887
|
args: [tokens]
|
|
@@ -6899,6 +6946,7 @@ function createStake(config) {
|
|
|
6899
6946
|
stake: createStakeAction({ publicClient, diamondAddress }),
|
|
6900
6947
|
topUp: createTopUpAction({ publicClient, diamondAddress }),
|
|
6901
6948
|
requestUnstake: createRequestUnstakeAction({ publicClient, diamondAddress }),
|
|
6949
|
+
cancelUnstake: createCancelUnstakeAction({ publicClient, diamondAddress }),
|
|
6902
6950
|
claimUnstake: createClaimUnstakeAction({ publicClient, diamondAddress })
|
|
6903
6951
|
};
|
|
6904
6952
|
}
|