@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/react.d.cts CHANGED
@@ -203,6 +203,11 @@ interface ExecuteBase$1 {
203
203
  readonly waitForReceipt?: boolean;
204
204
  }
205
205
 
206
+ interface CancelUnstakeAction {
207
+ prepare(): ResultAsync<PreparedTx$1, StakeError>;
208
+ execute(params: ExecuteBase$1): ResultAsync<TxResult$1, StakeError>;
209
+ }
210
+
206
211
  interface ClaimUnstakeAction {
207
212
  prepare(): ResultAsync<PreparedTx$1, StakeError>;
208
213
  execute(params: ExecuteBase$1): ResultAsync<TxResult$1, StakeError>;
@@ -235,6 +240,7 @@ interface StakeClient {
235
240
  readonly stake: StakeAction;
236
241
  readonly topUp: TopUpAction;
237
242
  readonly requestUnstake: RequestUnstakeAction;
243
+ readonly cancelUnstake: CancelUnstakeAction;
238
244
  readonly claimUnstake: ClaimUnstakeAction;
239
245
  }
240
246
 
package/dist/react.d.ts CHANGED
@@ -203,6 +203,11 @@ interface ExecuteBase$1 {
203
203
  readonly waitForReceipt?: boolean;
204
204
  }
205
205
 
206
+ interface CancelUnstakeAction {
207
+ prepare(): ResultAsync<PreparedTx$1, StakeError>;
208
+ execute(params: ExecuteBase$1): ResultAsync<TxResult$1, StakeError>;
209
+ }
210
+
206
211
  interface ClaimUnstakeAction {
207
212
  prepare(): ResultAsync<PreparedTx$1, StakeError>;
208
213
  execute(params: ExecuteBase$1): ResultAsync<TxResult$1, StakeError>;
@@ -235,6 +240,7 @@ interface StakeClient {
235
240
  readonly stake: StakeAction;
236
241
  readonly topUp: TopUpAction;
237
242
  readonly requestUnstake: RequestUnstakeAction;
243
+ readonly cancelUnstake: CancelUnstakeAction;
238
244
  readonly claimUnstake: ClaimUnstakeAction;
239
245
  }
240
246
 
package/dist/react.mjs CHANGED
@@ -1157,6 +1157,13 @@ var p2pStakeBoostFacetAbi = [
1157
1157
  stateMutability: "nonpayable",
1158
1158
  type: "function"
1159
1159
  },
1160
+ {
1161
+ inputs: [],
1162
+ name: "p2pBoostCancelUnstake",
1163
+ outputs: [],
1164
+ stateMutability: "nonpayable",
1165
+ type: "function"
1166
+ },
1160
1167
  {
1161
1168
  inputs: [{ internalType: "address", name: "user", type: "address" }],
1162
1169
  name: "getUserStake",
@@ -5390,7 +5397,8 @@ var OrderRoutingError = class extends SdkError {
5390
5397
  // src/orders/internal/routing/validation.ts
5391
5398
  import { z as z6 } from "zod";
5392
5399
  var ZodCircleScoreStateSchema = z6.object({
5393
- activeMerchantsCount: z6.coerce.number()
5400
+ activeMerchantsCount: z6.coerce.number(),
5401
+ availableMerchantsCount: z6.coerce.number()
5394
5402
  });
5395
5403
  var ZodCircleMetricsForRoutingSchema = z6.object({
5396
5404
  circleScore: z6.coerce.number(),
@@ -5972,8 +5980,9 @@ import { errAsync as errAsync3, okAsync as okAsync3 } from "neverthrow";
5972
5980
  var EPSILON = 0.25;
5973
5981
  var RECOVERY_SCALE = 0.3;
5974
5982
  var BOOTSTRAP_MAX_WEIGHT = 25;
5983
+ var BOOTSTRAP_RESERVE = 0.1;
5975
5984
  var MAX_VALIDATION_ATTEMPTS = 3;
5976
- function circleWeight(c) {
5985
+ function baseScore(c) {
5977
5986
  const score = c.metrics.circleScore;
5978
5987
  if (c.metrics.circleStatus === "paused") {
5979
5988
  return score * RECOVERY_SCALE;
@@ -5983,8 +5992,13 @@ function circleWeight(c) {
5983
5992
  }
5984
5993
  return score;
5985
5994
  }
5995
+ function circleWeight(c) {
5996
+ return baseScore(c) * c.metrics.scoreState.availableMerchantsCount;
5997
+ }
5986
5998
  function filterEligibleCircles(circles, orderCurrency) {
5987
- return circles.filter((c) => c.currency.toLowerCase() === orderCurrency.toLowerCase());
5999
+ return circles.filter(
6000
+ (c) => c.currency.toLowerCase() === orderCurrency.toLowerCase() && c.metrics.scoreState.availableMerchantsCount > 0
6001
+ );
5988
6002
  }
5989
6003
  function weightedRandomChoice(arr, weights) {
5990
6004
  const totalWeight = weights.reduce((sum, w) => sum + w, 0);
@@ -6004,8 +6018,14 @@ function selectCircle(eligible) {
6004
6018
  if (eligible.length === 0) {
6005
6019
  return null;
6006
6020
  }
6021
+ const bootstrapCircles = eligible.filter((c) => c.metrics.circleStatus === "bootstrap");
6007
6022
  const activeCircles = eligible.filter((c) => c.metrics.circleStatus === "active");
6008
- const isExplore = Math.random() < EPSILON;
6023
+ const r = Math.random();
6024
+ if (r < BOOTSTRAP_RESERVE && bootstrapCircles.length > 0) {
6025
+ const weights2 = bootstrapCircles.map(circleWeight);
6026
+ return weightedRandomChoice(bootstrapCircles, weights2);
6027
+ }
6028
+ const isExplore = r < BOOTSTRAP_RESERVE + EPSILON;
6009
6029
  if (isExplore) {
6010
6030
  const weights2 = eligible.map(circleWeight);
6011
6031
  return weightedRandomChoice(eligible, weights2);
@@ -6014,7 +6034,7 @@ function selectCircle(eligible) {
6014
6034
  const weights2 = eligible.map(circleWeight);
6015
6035
  return weightedRandomChoice(eligible, weights2);
6016
6036
  }
6017
- const weights = activeCircles.map((c) => c.metrics.circleScore);
6037
+ const weights = activeCircles.map(circleWeight);
6018
6038
  return weightedRandomChoice(activeCircles, weights);
6019
6039
  }
6020
6040
  function selectCircleForOrderAsync(circles, orderCurrency, validateCircle, logger = noopLogger) {
@@ -6099,6 +6119,7 @@ var CIRCLES_FOR_ROUTING_QUERY = (
6099
6119
  circleStatus
6100
6120
  scoreState {
6101
6121
  activeMerchantsCount
6122
+ availableMerchantsCount
6102
6123
  }
6103
6124
  }
6104
6125
  }
@@ -6125,11 +6146,11 @@ function getCirclesForRouting(subgraphUrl, currency, logger = noopLogger) {
6125
6146
  (message, cause, d) => new OrderRoutingError(message, { code: "VALIDATION_ERROR", cause, context: { data: d } })
6126
6147
  ).map((validated) => {
6127
6148
  const circles = validated.circles.filter(
6128
- (item) => Number(item.metrics.scoreState.activeMerchantsCount) > 0
6149
+ (item) => Number(item.metrics.scoreState.availableMerchantsCount) > 0
6129
6150
  );
6130
6151
  logger.info("fetched circles from subgraph", {
6131
6152
  total: validated.circles.length,
6132
- withActiveMerchants: circles.length,
6153
+ withAvailableMerchants: circles.length,
6133
6154
  circles
6134
6155
  });
6135
6156
  return circles;
@@ -6639,7 +6660,7 @@ function createProfile(config) {
6639
6660
  };
6640
6661
  }
6641
6662
 
6642
- // src/stake/actions/claim-unstake.ts
6663
+ // src/stake/actions/cancel-unstake.ts
6643
6664
  import { okAsync as okAsync6 } from "neverthrow";
6644
6665
  import { encodeFunctionData as encodeFunctionData8 } from "viem";
6645
6666
 
@@ -6692,14 +6713,14 @@ function submitPreparedTx2(input) {
6692
6713
  });
6693
6714
  }
6694
6715
 
6695
- // src/stake/actions/claim-unstake.ts
6696
- function createClaimUnstakeAction(input) {
6716
+ // src/stake/actions/cancel-unstake.ts
6717
+ function createCancelUnstakeAction(input) {
6697
6718
  const { publicClient, diamondAddress } = input;
6698
6719
  const prepareFn = () => okAsync6({
6699
6720
  to: diamondAddress,
6700
6721
  data: encodeFunctionData8({
6701
6722
  abi: ABIS.FACETS.STAKE,
6702
- functionName: "p2pBoostClaimUnstake",
6723
+ functionName: "p2pBoostCancelUnstake",
6703
6724
  args: []
6704
6725
  }),
6705
6726
  value: 0n
@@ -6716,14 +6737,40 @@ function createClaimUnstakeAction(input) {
6716
6737
  };
6717
6738
  }
6718
6739
 
6719
- // src/stake/actions/request-unstake.ts
6740
+ // src/stake/actions/claim-unstake.ts
6720
6741
  import { okAsync as okAsync7 } from "neverthrow";
6721
6742
  import { encodeFunctionData as encodeFunctionData9 } from "viem";
6722
- function createRequestUnstakeAction(input) {
6743
+ function createClaimUnstakeAction(input) {
6723
6744
  const { publicClient, diamondAddress } = input;
6724
6745
  const prepareFn = () => okAsync7({
6725
6746
  to: diamondAddress,
6726
6747
  data: encodeFunctionData9({
6748
+ abi: ABIS.FACETS.STAKE,
6749
+ functionName: "p2pBoostClaimUnstake",
6750
+ args: []
6751
+ }),
6752
+ value: 0n
6753
+ });
6754
+ return {
6755
+ prepare() {
6756
+ return prepareFn();
6757
+ },
6758
+ execute({ walletClient, waitForReceipt }) {
6759
+ return prepareFn().andThen(
6760
+ (prepared) => submitPreparedTx2({ prepared, walletClient, publicClient, waitForReceipt })
6761
+ );
6762
+ }
6763
+ };
6764
+ }
6765
+
6766
+ // src/stake/actions/request-unstake.ts
6767
+ import { okAsync as okAsync8 } from "neverthrow";
6768
+ import { encodeFunctionData as encodeFunctionData10 } from "viem";
6769
+ function createRequestUnstakeAction(input) {
6770
+ const { publicClient, diamondAddress } = input;
6771
+ const prepareFn = () => okAsync8({
6772
+ to: diamondAddress,
6773
+ data: encodeFunctionData10({
6727
6774
  abi: ABIS.FACETS.STAKE,
6728
6775
  functionName: "p2pBoostRequestUnstake",
6729
6776
  args: []
@@ -6743,7 +6790,7 @@ function createRequestUnstakeAction(input) {
6743
6790
  }
6744
6791
 
6745
6792
  // src/stake/actions/stake.ts
6746
- import { encodeFunctionData as encodeFunctionData10 } from "viem";
6793
+ import { encodeFunctionData as encodeFunctionData11 } from "viem";
6747
6794
  function createStakeAction(input) {
6748
6795
  const { publicClient, diamondAddress } = input;
6749
6796
  const prepareFn = (params) => validate(
@@ -6756,7 +6803,7 @@ function createStakeAction(input) {
6756
6803
  })
6757
6804
  ).map(({ tokens }) => ({
6758
6805
  to: diamondAddress,
6759
- data: encodeFunctionData10({
6806
+ data: encodeFunctionData11({
6760
6807
  abi: ABIS.FACETS.STAKE,
6761
6808
  functionName: "p2pBoostStake",
6762
6809
  args: [tokens]
@@ -6776,7 +6823,7 @@ function createStakeAction(input) {
6776
6823
  }
6777
6824
 
6778
6825
  // src/stake/actions/top-up.ts
6779
- import { encodeFunctionData as encodeFunctionData11 } from "viem";
6826
+ import { encodeFunctionData as encodeFunctionData12 } from "viem";
6780
6827
  function createTopUpAction(input) {
6781
6828
  const { publicClient, diamondAddress } = input;
6782
6829
  const prepareFn = (params) => validate(
@@ -6789,7 +6836,7 @@ function createTopUpAction(input) {
6789
6836
  })
6790
6837
  ).map(({ tokens }) => ({
6791
6838
  to: diamondAddress,
6792
- data: encodeFunctionData11({
6839
+ data: encodeFunctionData12({
6793
6840
  abi: ABIS.FACETS.STAKE,
6794
6841
  functionName: "p2pBoostTopUp",
6795
6842
  args: [tokens]
@@ -6854,6 +6901,7 @@ function createStake(config) {
6854
6901
  stake: createStakeAction({ publicClient, diamondAddress }),
6855
6902
  topUp: createTopUpAction({ publicClient, diamondAddress }),
6856
6903
  requestUnstake: createRequestUnstakeAction({ publicClient, diamondAddress }),
6904
+ cancelUnstake: createCancelUnstakeAction({ publicClient, diamondAddress }),
6857
6905
  claimUnstake: createClaimUnstakeAction({ publicClient, diamondAddress })
6858
6906
  };
6859
6907
  }