@p2pdotme/sdk 1.1.8 → 1.1.9

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.cjs CHANGED
@@ -37,6 +37,7 @@ __export(react_exports, {
37
37
  usePrices: () => usePrices,
38
38
  useProfile: () => useProfile,
39
39
  useSdk: () => useSdk,
40
+ useStake: () => useStake,
40
41
  useWatchOrders: () => useWatchOrders,
41
42
  useZkkyc: () => useZkkyc
42
43
  });
@@ -685,7 +686,7 @@ function createFraudEngine(config) {
685
686
  }
686
687
 
687
688
  // src/orders/client.ts
688
- var import_neverthrow17 = require("neverthrow");
689
+ var import_neverthrow18 = require("neverthrow");
689
690
 
690
691
  // src/contracts/order-processor/index.ts
691
692
  var import_neverthrow5 = require("neverthrow");
@@ -1171,6 +1172,97 @@ var p2pConfigFacetAbi = [
1171
1172
  }
1172
1173
  ];
1173
1174
 
1175
+ // src/contracts/abis/p2p-stake-boost-facet.ts
1176
+ var p2pStakeBoostFacetAbi = [
1177
+ {
1178
+ inputs: [{ internalType: "uint256", name: "tokens", type: "uint256" }],
1179
+ name: "p2pBoostStake",
1180
+ outputs: [],
1181
+ stateMutability: "nonpayable",
1182
+ type: "function"
1183
+ },
1184
+ {
1185
+ inputs: [{ internalType: "uint256", name: "tokens", type: "uint256" }],
1186
+ name: "p2pBoostTopUp",
1187
+ outputs: [],
1188
+ stateMutability: "nonpayable",
1189
+ type: "function"
1190
+ },
1191
+ {
1192
+ inputs: [],
1193
+ name: "p2pBoostRequestUnstake",
1194
+ outputs: [],
1195
+ stateMutability: "nonpayable",
1196
+ type: "function"
1197
+ },
1198
+ {
1199
+ inputs: [],
1200
+ name: "p2pBoostClaimUnstake",
1201
+ outputs: [],
1202
+ stateMutability: "nonpayable",
1203
+ type: "function"
1204
+ },
1205
+ {
1206
+ inputs: [{ internalType: "address", name: "user", type: "address" }],
1207
+ name: "getUserStake",
1208
+ outputs: [
1209
+ {
1210
+ components: [
1211
+ { internalType: "uint128", name: "stakedAmount", type: "uint128" },
1212
+ { internalType: "uint64", name: "cooldownEnd", type: "uint64" },
1213
+ { internalType: "uint8", name: "status", type: "uint8" }
1214
+ ],
1215
+ internalType: "struct P2PStakeBoostStorage.UserStake",
1216
+ name: "",
1217
+ type: "tuple"
1218
+ }
1219
+ ],
1220
+ stateMutability: "view",
1221
+ type: "function"
1222
+ },
1223
+ {
1224
+ inputs: [{ internalType: "bytes32", name: "currency", type: "bytes32" }],
1225
+ name: "getStakeBoostConfig",
1226
+ outputs: [
1227
+ {
1228
+ components: [
1229
+ {
1230
+ internalType: "uint256",
1231
+ name: "tokensPerUsdNumerator",
1232
+ type: "uint256"
1233
+ },
1234
+ {
1235
+ internalType: "uint256",
1236
+ name: "tokensPerUsdDenominator",
1237
+ type: "uint256"
1238
+ },
1239
+ { internalType: "uint256", name: "maxBoostUsd", type: "uint256" }
1240
+ ],
1241
+ internalType: "struct P2PStakeBoostStorage.BoostConfig",
1242
+ name: "",
1243
+ type: "tuple"
1244
+ }
1245
+ ],
1246
+ stateMutability: "view",
1247
+ type: "function"
1248
+ },
1249
+ {
1250
+ inputs: [],
1251
+ name: "getStakeBoostGlobals",
1252
+ outputs: [
1253
+ { internalType: "address", name: "p2pToken", type: "address" },
1254
+ { internalType: "address", name: "fraudReserve", type: "address" },
1255
+ { internalType: "uint256", name: "maxStakeTokens", type: "uint256" },
1256
+ { internalType: "uint256", name: "normalCooldown", type: "uint256" },
1257
+ { internalType: "uint256", name: "blacklistCooldown", type: "uint256" },
1258
+ { internalType: "uint8", name: "tokenDecimals", type: "uint8" },
1259
+ { internalType: "uint256", name: "totalStaked", type: "uint256" }
1260
+ ],
1261
+ stateMutability: "view",
1262
+ type: "function"
1263
+ }
1264
+ ];
1265
+
1174
1266
  // src/contracts/abis/reputation-manager.ts
1175
1267
  var reputationManagerAbi = [
1176
1268
  {
@@ -1377,14 +1469,16 @@ var reputationManagerAbi = [
1377
1469
  var DIAMOND_ABI = [
1378
1470
  ...orderFlowFacetAbi,
1379
1471
  ...orderProcessorFacetAbi,
1380
- ...p2pConfigFacetAbi
1472
+ ...p2pConfigFacetAbi,
1473
+ ...p2pStakeBoostFacetAbi
1381
1474
  ];
1382
1475
  var ABIS = {
1383
1476
  DIAMOND: DIAMOND_ABI,
1384
1477
  FACETS: {
1385
1478
  ORDER_FLOW: orderFlowFacetAbi,
1386
1479
  ORDER_PROCESSOR: orderProcessorFacetAbi,
1387
- CONFIG: p2pConfigFacetAbi
1480
+ CONFIG: p2pConfigFacetAbi,
1481
+ STAKE: p2pStakeBoostFacetAbi
1388
1482
  },
1389
1483
  EXTERNAL: {
1390
1484
  USDC: import_viem2.erc20Abi,
@@ -3898,15 +3992,15 @@ function weierstrassPoints(opts) {
3898
3992
  throw new Error("ProjectivePoint expected");
3899
3993
  }
3900
3994
  const toAffineMemo = memoized((p, iz) => {
3901
- const { px: x, py: y, pz: z10 } = p;
3902
- if (Fp.eql(z10, Fp.ONE))
3995
+ const { px: x, py: y, pz: z11 } = p;
3996
+ if (Fp.eql(z11, Fp.ONE))
3903
3997
  return { x, y };
3904
3998
  const is0 = p.is0();
3905
3999
  if (iz == null)
3906
- iz = is0 ? Fp.ONE : Fp.inv(z10);
4000
+ iz = is0 ? Fp.ONE : Fp.inv(z11);
3907
4001
  const ax = Fp.mul(x, iz);
3908
4002
  const ay = Fp.mul(y, iz);
3909
- const zz = Fp.mul(z10, iz);
4003
+ const zz = Fp.mul(z11, iz);
3910
4004
  if (is0)
3911
4005
  return { x: Fp.ZERO, y: Fp.ZERO };
3912
4006
  if (!Fp.eql(zz, Fp.ONE))
@@ -4901,7 +4995,7 @@ function createSetSellOrderUpiAction(input) {
4901
4995
  }
4902
4996
 
4903
4997
  // src/orders/internal/routing/client.ts
4904
- var import_viem16 = require("viem");
4998
+ var import_viem17 = require("viem");
4905
4999
 
4906
5000
  // src/contracts/errors.ts
4907
5001
  var contractErrors = {
@@ -5493,10 +5587,132 @@ function getReputationPerUsdcLimit(publicClient, diamondAddress, params) {
5493
5587
  );
5494
5588
  }
5495
5589
 
5496
- // src/contracts/reputation-manager/writes.ts
5590
+ // src/contracts/p2p-stake/index.ts
5497
5591
  var import_neverthrow11 = require("neverthrow");
5498
5592
  var import_viem13 = require("viem");
5499
5593
 
5594
+ // src/stake/errors.ts
5595
+ var StakeError = class extends SdkError {
5596
+ constructor(message, options) {
5597
+ super(message, options);
5598
+ this.name = "StakeError";
5599
+ }
5600
+ };
5601
+
5602
+ // src/stake/validation.ts
5603
+ var import_zod8 = require("zod");
5604
+ var ZodGetUserStakeParamsSchema = import_zod8.z.object({
5605
+ user: ZodAddressSchema
5606
+ });
5607
+ var ZodGetStakeBoostConfigParamsSchema = import_zod8.z.object({
5608
+ currency: ZodCurrencySchema
5609
+ });
5610
+ var ZodGetP2pTokenBalanceParamsSchema = import_zod8.z.object({
5611
+ address: ZodAddressSchema
5612
+ });
5613
+ var ZodStakeParamsSchema = import_zod8.z.object({
5614
+ tokens: import_zod8.z.bigint().positive()
5615
+ });
5616
+ var ZodTopUpParamsSchema = import_zod8.z.object({
5617
+ tokens: import_zod8.z.bigint().positive()
5618
+ });
5619
+
5620
+ // src/contracts/p2p-stake/index.ts
5621
+ function getUserStake(publicClient, diamondAddress, params) {
5622
+ return validate(
5623
+ ZodGetUserStakeParamsSchema,
5624
+ params,
5625
+ (message, cause, data) => new StakeError(message, {
5626
+ code: "VALIDATION_ERROR",
5627
+ cause,
5628
+ context: { params: data }
5629
+ })
5630
+ ).asyncAndThen(
5631
+ (validated) => import_neverthrow11.ResultAsync.fromPromise(
5632
+ publicClient.readContract({
5633
+ address: diamondAddress,
5634
+ abi: ABIS.FACETS.STAKE,
5635
+ functionName: "getUserStake",
5636
+ args: [validated.user]
5637
+ }),
5638
+ (error) => new StakeError("Failed to read user stake", {
5639
+ code: "CONTRACT_READ_ERROR",
5640
+ cause: error,
5641
+ context: { user: validated.user, diamondAddress }
5642
+ })
5643
+ )
5644
+ );
5645
+ }
5646
+ function getStakeBoostConfig(publicClient, diamondAddress, params) {
5647
+ return validate(
5648
+ ZodGetStakeBoostConfigParamsSchema,
5649
+ params,
5650
+ (message, cause, data) => new StakeError(message, {
5651
+ code: "VALIDATION_ERROR",
5652
+ cause,
5653
+ context: { params: data }
5654
+ })
5655
+ ).asyncAndThen(
5656
+ (validated) => import_neverthrow11.ResultAsync.fromPromise(
5657
+ publicClient.readContract({
5658
+ address: diamondAddress,
5659
+ abi: ABIS.FACETS.STAKE,
5660
+ functionName: "getStakeBoostConfig",
5661
+ args: [(0, import_viem13.stringToHex)(validated.currency, { size: 32 })]
5662
+ }),
5663
+ (error) => new StakeError("Failed to read stake boost config", {
5664
+ code: "CONTRACT_READ_ERROR",
5665
+ cause: error,
5666
+ context: { currency: validated.currency, diamondAddress }
5667
+ })
5668
+ )
5669
+ );
5670
+ }
5671
+ function getStakeBoostGlobals(publicClient, diamondAddress) {
5672
+ return import_neverthrow11.ResultAsync.fromPromise(
5673
+ publicClient.readContract({
5674
+ address: diamondAddress,
5675
+ abi: ABIS.FACETS.STAKE,
5676
+ functionName: "getStakeBoostGlobals",
5677
+ args: []
5678
+ }),
5679
+ (error) => new StakeError("Failed to read stake boost globals", {
5680
+ code: "CONTRACT_READ_ERROR",
5681
+ cause: error,
5682
+ context: { diamondAddress }
5683
+ })
5684
+ );
5685
+ }
5686
+ function getP2pTokenBalance(publicClient, p2pTokenAddress, params) {
5687
+ return validate(
5688
+ ZodGetP2pTokenBalanceParamsSchema,
5689
+ params,
5690
+ (message, cause, data) => new StakeError(message, {
5691
+ code: "VALIDATION_ERROR",
5692
+ cause,
5693
+ context: { params: data }
5694
+ })
5695
+ ).asyncAndThen(
5696
+ (validated) => import_neverthrow11.ResultAsync.fromPromise(
5697
+ publicClient.readContract({
5698
+ address: p2pTokenAddress,
5699
+ abi: ABIS.EXTERNAL.USDC,
5700
+ functionName: "balanceOf",
5701
+ args: [validated.address]
5702
+ }),
5703
+ (error) => new StakeError("Failed to read P2P token balance", {
5704
+ code: "CONTRACT_READ_ERROR",
5705
+ cause: error,
5706
+ context: { address: validated.address, p2pTokenAddress }
5707
+ })
5708
+ )
5709
+ );
5710
+ }
5711
+
5712
+ // src/contracts/reputation-manager/writes.ts
5713
+ var import_neverthrow12 = require("neverthrow");
5714
+ var import_viem14 = require("viem");
5715
+
5500
5716
  // src/zkkyc/errors.ts
5501
5717
  var ZkkycError = class extends SdkError {
5502
5718
  constructor(message, options) {
@@ -5506,75 +5722,75 @@ var ZkkycError = class extends SdkError {
5506
5722
  };
5507
5723
 
5508
5724
  // src/zkkyc/validation.ts
5509
- var import_zod8 = require("zod");
5510
- var ZodAnonAadharProofParamsSchema = import_zod8.z.object({
5511
- nullifierSeed: import_zod8.z.bigint(),
5512
- nullifier: import_zod8.z.bigint(),
5513
- timestamp: import_zod8.z.bigint(),
5514
- signal: import_zod8.z.bigint(),
5515
- revealArray: import_zod8.z.tuple([import_zod8.z.bigint(), import_zod8.z.bigint(), import_zod8.z.bigint(), import_zod8.z.bigint()]),
5516
- packedGroth16Proof: import_zod8.z.tuple([
5517
- import_zod8.z.bigint(),
5518
- import_zod8.z.bigint(),
5519
- import_zod8.z.bigint(),
5520
- import_zod8.z.bigint(),
5521
- import_zod8.z.bigint(),
5522
- import_zod8.z.bigint(),
5523
- import_zod8.z.bigint(),
5524
- import_zod8.z.bigint()
5725
+ var import_zod9 = require("zod");
5726
+ var ZodAnonAadharProofParamsSchema = import_zod9.z.object({
5727
+ nullifierSeed: import_zod9.z.bigint(),
5728
+ nullifier: import_zod9.z.bigint(),
5729
+ timestamp: import_zod9.z.bigint(),
5730
+ signal: import_zod9.z.bigint(),
5731
+ revealArray: import_zod9.z.tuple([import_zod9.z.bigint(), import_zod9.z.bigint(), import_zod9.z.bigint(), import_zod9.z.bigint()]),
5732
+ packedGroth16Proof: import_zod9.z.tuple([
5733
+ import_zod9.z.bigint(),
5734
+ import_zod9.z.bigint(),
5735
+ import_zod9.z.bigint(),
5736
+ import_zod9.z.bigint(),
5737
+ import_zod9.z.bigint(),
5738
+ import_zod9.z.bigint(),
5739
+ import_zod9.z.bigint(),
5740
+ import_zod9.z.bigint()
5525
5741
  ])
5526
5742
  });
5527
- var ZodSocialVerifyParamsSchema = import_zod8.z.object({
5528
- _socialName: import_zod8.z.string(),
5529
- proofs: import_zod8.z.array(
5530
- import_zod8.z.object({
5531
- claimInfo: import_zod8.z.object({
5532
- provider: import_zod8.z.string(),
5533
- parameters: import_zod8.z.string(),
5534
- context: import_zod8.z.string()
5743
+ var ZodSocialVerifyParamsSchema = import_zod9.z.object({
5744
+ _socialName: import_zod9.z.string(),
5745
+ proofs: import_zod9.z.array(
5746
+ import_zod9.z.object({
5747
+ claimInfo: import_zod9.z.object({
5748
+ provider: import_zod9.z.string(),
5749
+ parameters: import_zod9.z.string(),
5750
+ context: import_zod9.z.string()
5535
5751
  }),
5536
- signedClaim: import_zod8.z.object({
5537
- claim: import_zod8.z.object({
5538
- identifier: import_zod8.z.string(),
5752
+ signedClaim: import_zod9.z.object({
5753
+ claim: import_zod9.z.object({
5754
+ identifier: import_zod9.z.string(),
5539
5755
  owner: ZodAddressSchema,
5540
- timestampS: import_zod8.z.number(),
5541
- epoch: import_zod8.z.number()
5756
+ timestampS: import_zod9.z.number(),
5757
+ epoch: import_zod9.z.number()
5542
5758
  }),
5543
- signatures: import_zod8.z.array(import_zod8.z.string())
5759
+ signatures: import_zod9.z.array(import_zod9.z.string())
5544
5760
  })
5545
5761
  })
5546
5762
  )
5547
5763
  });
5548
- var ZodSolidityVerifierParametersSchema = import_zod8.z.object({
5549
- version: import_zod8.z.string().refine((val) => val.startsWith("0x"), {
5764
+ var ZodSolidityVerifierParametersSchema = import_zod9.z.object({
5765
+ version: import_zod9.z.string().refine((val) => val.startsWith("0x"), {
5550
5766
  message: "Version must be a hex string"
5551
5767
  }),
5552
- proofVerificationData: import_zod8.z.object({
5553
- vkeyHash: import_zod8.z.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
5768
+ proofVerificationData: import_zod9.z.object({
5769
+ vkeyHash: import_zod9.z.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
5554
5770
  message: "Invalid bytes32 hex string"
5555
5771
  }),
5556
- proof: import_zod8.z.string().refine((val) => val.startsWith("0x"), {
5772
+ proof: import_zod9.z.string().refine((val) => val.startsWith("0x"), {
5557
5773
  message: "Proof must be a hex string"
5558
5774
  }),
5559
- publicInputs: import_zod8.z.array(
5560
- import_zod8.z.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
5775
+ publicInputs: import_zod9.z.array(
5776
+ import_zod9.z.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
5561
5777
  message: "Each public input must be a valid bytes32 hex string"
5562
5778
  })
5563
5779
  )
5564
5780
  }),
5565
- committedInputs: import_zod8.z.string().refine((val) => val.startsWith("0x"), {
5781
+ committedInputs: import_zod9.z.string().refine((val) => val.startsWith("0x"), {
5566
5782
  message: "Committed inputs must be a hex string"
5567
5783
  }),
5568
- serviceConfig: import_zod8.z.object({
5569
- validityPeriodInSeconds: import_zod8.z.number().int().nonnegative(),
5570
- domain: import_zod8.z.string(),
5571
- scope: import_zod8.z.string(),
5572
- devMode: import_zod8.z.boolean()
5784
+ serviceConfig: import_zod9.z.object({
5785
+ validityPeriodInSeconds: import_zod9.z.number().int().nonnegative(),
5786
+ domain: import_zod9.z.string(),
5787
+ scope: import_zod9.z.string(),
5788
+ devMode: import_zod9.z.boolean()
5573
5789
  })
5574
5790
  });
5575
- var ZodZkPassportRegisterParamsSchema = import_zod8.z.object({
5791
+ var ZodZkPassportRegisterParamsSchema = import_zod9.z.object({
5576
5792
  params: ZodSolidityVerifierParametersSchema,
5577
- isIDCard: import_zod8.z.boolean()
5793
+ isIDCard: import_zod9.z.boolean()
5578
5794
  });
5579
5795
 
5580
5796
  // src/contracts/reputation-manager/writes.ts
@@ -5584,10 +5800,10 @@ function prepareSocialVerify(reputationManagerAddress, params) {
5584
5800
  params,
5585
5801
  (message, cause, data) => new ZkkycError(message, { code: "VALIDATION_ERROR", cause, context: { params: data } })
5586
5802
  ).andThen(
5587
- (validated) => import_neverthrow11.Result.fromThrowable(
5803
+ (validated) => import_neverthrow12.Result.fromThrowable(
5588
5804
  () => ({
5589
5805
  to: reputationManagerAddress,
5590
- data: (0, import_viem13.encodeFunctionData)({
5806
+ data: (0, import_viem14.encodeFunctionData)({
5591
5807
  abi: ABIS.EXTERNAL.REPUTATION_MANAGER,
5592
5808
  functionName: "socialVerify",
5593
5809
  args: [
@@ -5619,10 +5835,10 @@ function prepareSubmitAnonAadharProof(reputationManagerAddress, params) {
5619
5835
  params,
5620
5836
  (message, cause, data) => new ZkkycError(message, { code: "VALIDATION_ERROR", cause, context: { params: data } })
5621
5837
  ).andThen(
5622
- (validated) => import_neverthrow11.Result.fromThrowable(
5838
+ (validated) => import_neverthrow12.Result.fromThrowable(
5623
5839
  () => ({
5624
5840
  to: reputationManagerAddress,
5625
- data: (0, import_viem13.encodeFunctionData)({
5841
+ data: (0, import_viem14.encodeFunctionData)({
5626
5842
  abi: ABIS.EXTERNAL.REPUTATION_MANAGER,
5627
5843
  functionName: "submitAnonAadharProof",
5628
5844
  args: [
@@ -5648,7 +5864,7 @@ function prepareZkPassportRegister(reputationManagerAddress, params) {
5648
5864
  params,
5649
5865
  (message, cause, data) => new ZkkycError(message, { code: "VALIDATION_ERROR", cause, context: { params: data } })
5650
5866
  ).andThen(
5651
- (validated) => import_neverthrow11.Result.fromThrowable(
5867
+ (validated) => import_neverthrow12.Result.fromThrowable(
5652
5868
  () => {
5653
5869
  const { proofVerificationData, serviceConfig, committedInputs, version } = validated.params;
5654
5870
  const proofVerificationParams = {
@@ -5668,7 +5884,7 @@ function prepareZkPassportRegister(reputationManagerAddress, params) {
5668
5884
  };
5669
5885
  return {
5670
5886
  to: reputationManagerAddress,
5671
- data: (0, import_viem13.encodeFunctionData)({
5887
+ data: (0, import_viem14.encodeFunctionData)({
5672
5888
  abi: ABIS.EXTERNAL.REPUTATION_MANAGER,
5673
5889
  functionName: "zkPassportRegister",
5674
5890
  args: [proofVerificationParams, validated.isIDCard]
@@ -5684,8 +5900,8 @@ function prepareZkPassportRegister(reputationManagerAddress, params) {
5684
5900
  }
5685
5901
 
5686
5902
  // src/contracts/tx-limits/index.ts
5687
- var import_neverthrow12 = require("neverthrow");
5688
- var import_viem14 = require("viem");
5903
+ var import_neverthrow13 = require("neverthrow");
5904
+ var import_viem15 = require("viem");
5689
5905
 
5690
5906
  // src/profile/errors.ts
5691
5907
  var ProfileError = class extends SdkError {
@@ -5696,18 +5912,18 @@ var ProfileError = class extends SdkError {
5696
5912
  };
5697
5913
 
5698
5914
  // src/profile/validation.ts
5699
- var import_zod9 = require("zod");
5700
- var ZodUsdcBalanceParamsSchema = import_zod9.z.object({
5915
+ var import_zod10 = require("zod");
5916
+ var ZodUsdcBalanceParamsSchema = import_zod10.z.object({
5701
5917
  address: ZodAddressSchema
5702
5918
  });
5703
- var ZodUsdcAllowanceParamsSchema = import_zod9.z.object({
5919
+ var ZodUsdcAllowanceParamsSchema = import_zod10.z.object({
5704
5920
  owner: ZodAddressSchema
5705
5921
  });
5706
- var ZodGetBalancesParamsSchema = import_zod9.z.object({
5922
+ var ZodGetBalancesParamsSchema = import_zod10.z.object({
5707
5923
  address: ZodAddressSchema,
5708
5924
  currency: ZodCurrencySchema
5709
5925
  });
5710
- var ZodTxLimitsParamsSchema = import_zod9.z.object({
5926
+ var ZodTxLimitsParamsSchema = import_zod10.z.object({
5711
5927
  address: ZodAddressSchema,
5712
5928
  currency: ZodCurrencySchema
5713
5929
  });
@@ -5723,12 +5939,12 @@ function getTxLimits(publicClient, diamondAddress, params) {
5723
5939
  context: { params: data }
5724
5940
  })
5725
5941
  ).asyncAndThen(
5726
- (validated) => import_neverthrow12.ResultAsync.fromPromise(
5942
+ (validated) => import_neverthrow13.ResultAsync.fromPromise(
5727
5943
  publicClient.readContract({
5728
5944
  address: diamondAddress,
5729
5945
  abi: ABIS.FACETS.ORDER_FLOW,
5730
5946
  functionName: "userTxLimit",
5731
- args: [validated.address, (0, import_viem14.stringToHex)(validated.currency, { size: 32 })]
5947
+ args: [validated.address, (0, import_viem15.stringToHex)(validated.currency, { size: 32 })]
5732
5948
  }),
5733
5949
  (error) => new ProfileError("Failed to read tx limits", {
5734
5950
  code: "CONTRACT_READ_ERROR",
@@ -5736,15 +5952,15 @@ function getTxLimits(publicClient, diamondAddress, params) {
5736
5952
  context: { address: validated.address, currency: validated.currency, diamondAddress }
5737
5953
  })
5738
5954
  ).map(([buyLimit, sellLimit]) => ({
5739
- buyLimit: Number((0, import_viem14.formatUnits)(buyLimit, 6)),
5740
- sellLimit: Number((0, import_viem14.formatUnits)(sellLimit, 6))
5955
+ buyLimit: Number((0, import_viem15.formatUnits)(buyLimit, 6)),
5956
+ sellLimit: Number((0, import_viem15.formatUnits)(sellLimit, 6))
5741
5957
  }))
5742
5958
  );
5743
5959
  }
5744
5960
 
5745
5961
  // src/contracts/usdc/index.ts
5746
- var import_neverthrow13 = require("neverthrow");
5747
- var import_viem15 = require("viem");
5962
+ var import_neverthrow14 = require("neverthrow");
5963
+ var import_viem16 = require("viem");
5748
5964
  function getUsdcBalance(publicClient, usdcAddress, params) {
5749
5965
  return validate(
5750
5966
  ZodUsdcBalanceParamsSchema,
@@ -5755,7 +5971,7 @@ function getUsdcBalance(publicClient, usdcAddress, params) {
5755
5971
  context: { params: data }
5756
5972
  })
5757
5973
  ).asyncAndThen(
5758
- (validated) => import_neverthrow13.ResultAsync.fromPromise(
5974
+ (validated) => import_neverthrow14.ResultAsync.fromPromise(
5759
5975
  publicClient.readContract({
5760
5976
  address: usdcAddress,
5761
5977
  abi: ABIS.EXTERNAL.USDC,
@@ -5780,10 +5996,10 @@ function getUsdcAllowance(publicClient, usdcAddress, diamondAddress, params) {
5780
5996
  context: { params: data }
5781
5997
  })
5782
5998
  ).asyncAndThen(
5783
- (validated) => import_neverthrow13.ResultAsync.fromPromise(
5999
+ (validated) => import_neverthrow14.ResultAsync.fromPromise(
5784
6000
  publicClient.readContract({
5785
6001
  address: usdcAddress,
5786
- abi: import_viem15.erc20Abi,
6002
+ abi: import_viem16.erc20Abi,
5787
6003
  functionName: "allowance",
5788
6004
  args: [validated.owner, diamondAddress]
5789
6005
  }),
@@ -5797,7 +6013,7 @@ function getUsdcAllowance(publicClient, usdcAddress, diamondAddress, params) {
5797
6013
  }
5798
6014
 
5799
6015
  // src/orders/internal/routing/routing.ts
5800
- var import_neverthrow14 = require("neverthrow");
6016
+ var import_neverthrow15 = require("neverthrow");
5801
6017
  var EPSILON = 0.25;
5802
6018
  var RECOVERY_SCALE = 0.3;
5803
6019
  var BOOTSTRAP_MAX_WEIGHT = 25;
@@ -5864,7 +6080,7 @@ function selectCircleForOrderAsync(circles, orderCurrency, validateCircle, logge
5864
6080
  attemptsLeft,
5865
6081
  remainingCircles: remaining.length
5866
6082
  });
5867
- return (0, import_neverthrow14.errAsync)(
6083
+ return (0, import_neverthrow15.errAsync)(
5868
6084
  new OrderRoutingError("No eligible circles found", {
5869
6085
  code: "NO_ELIGIBLE_CIRCLES"
5870
6086
  })
@@ -5872,7 +6088,7 @@ function selectCircleForOrderAsync(circles, orderCurrency, validateCircle, logge
5872
6088
  }
5873
6089
  const selected = selectCircle(remaining);
5874
6090
  if (!selected) {
5875
- return (0, import_neverthrow14.errAsync)(
6091
+ return (0, import_neverthrow15.errAsync)(
5876
6092
  new OrderRoutingError("No eligible circles found", {
5877
6093
  code: "NO_ELIGIBLE_CIRCLES"
5878
6094
  })
@@ -5890,11 +6106,11 @@ function selectCircleForOrderAsync(circles, orderCurrency, validateCircle, logge
5890
6106
  circleId: String(circleId),
5891
6107
  error: String(error)
5892
6108
  });
5893
- return (0, import_neverthrow14.okAsync)(false);
6109
+ return (0, import_neverthrow15.okAsync)(false);
5894
6110
  }).andThen((isValid) => {
5895
6111
  if (isValid) {
5896
6112
  logger.info("circle validated successfully", { circleId: String(circleId) });
5897
- return (0, import_neverthrow14.okAsync)(circleId);
6113
+ return (0, import_neverthrow15.okAsync)(circleId);
5898
6114
  }
5899
6115
  logger.debug("circle failed validation, retrying", {
5900
6116
  circleId: String(circleId),
@@ -5972,7 +6188,7 @@ function createOrderRouter(config) {
5972
6188
  const logger = config.logger ?? noopLogger;
5973
6189
  return {
5974
6190
  selectCircle(params) {
5975
- const currencyHex = (0, import_viem16.stringToHex)(params.currency, { size: 32 });
6191
+ const currencyHex = (0, import_viem17.stringToHex)(params.currency, { size: 32 });
5976
6192
  logger.info("selectCircle started", {
5977
6193
  currency: params.currency,
5978
6194
  user: params.user,
@@ -6004,8 +6220,8 @@ function createOrderRouter(config) {
6004
6220
  }
6005
6221
 
6006
6222
  // src/orders/normalize.ts
6007
- var import_neverthrow15 = require("neverthrow");
6008
- var import_viem17 = require("viem");
6223
+ var import_neverthrow16 = require("neverthrow");
6224
+ var import_viem18 = require("viem");
6009
6225
  var ORDER_TYPE_MAP = {
6010
6226
  [ORDER_TYPE.BUY]: "buy",
6011
6227
  [ORDER_TYPE.SELL]: "sell",
@@ -6031,23 +6247,23 @@ function malformed(field, value, context) {
6031
6247
  }
6032
6248
  function mapOrderType(v, ctx) {
6033
6249
  const t = ORDER_TYPE_MAP[v];
6034
- return t ? (0, import_neverthrow15.ok)(t) : (0, import_neverthrow15.err)(malformed("orderType", v, ctx));
6250
+ return t ? (0, import_neverthrow16.ok)(t) : (0, import_neverthrow16.err)(malformed("orderType", v, ctx));
6035
6251
  }
6036
6252
  function mapOrderStatus(v, ctx) {
6037
6253
  const s = ORDER_STATUS_MAP[v];
6038
- return s ? (0, import_neverthrow15.ok)(s) : (0, import_neverthrow15.err)(malformed("status", v, ctx));
6254
+ return s ? (0, import_neverthrow16.ok)(s) : (0, import_neverthrow16.err)(malformed("status", v, ctx));
6039
6255
  }
6040
6256
  function mapDisputeStatus(v, ctx) {
6041
6257
  const s = DISPUTE_STATUS_MAP[v];
6042
- return s ? (0, import_neverthrow15.ok)(s) : (0, import_neverthrow15.err)(malformed("disputeStatus", v, ctx));
6258
+ return s ? (0, import_neverthrow16.ok)(s) : (0, import_neverthrow16.err)(malformed("disputeStatus", v, ctx));
6043
6259
  }
6044
6260
  function decodeCurrency(hex) {
6045
- return (0, import_viem17.hexToString)(hex, { size: 32 }).replaceAll("\0", "");
6261
+ return (0, import_viem18.hexToString)(hex, { size: 32 }).replaceAll("\0", "");
6046
6262
  }
6047
6263
  function normalizeContractOrder(raw, details) {
6048
- if (raw.id === 0n && (0, import_viem17.isAddressEqual)(raw.user, import_viem17.zeroAddress)) return (0, import_neverthrow15.ok)(null);
6264
+ if (raw.id === 0n && (0, import_viem18.isAddressEqual)(raw.user, import_viem18.zeroAddress)) return (0, import_neverthrow16.ok)(null);
6049
6265
  const ctx = { orderId: raw.id.toString() };
6050
- return import_neverthrow15.Result.combine([
6266
+ return import_neverthrow16.Result.combine([
6051
6267
  mapOrderType(raw.orderType, ctx),
6052
6268
  mapOrderStatus(raw.status, ctx),
6053
6269
  mapDisputeStatus(raw.disputeInfo.status, ctx)
@@ -6078,7 +6294,7 @@ function normalizeContractOrder(raw, details) {
6078
6294
  }
6079
6295
  function normalizeSubgraphOrder(raw) {
6080
6296
  const ctx = { orderId: raw.orderId };
6081
- return import_neverthrow15.Result.combine([
6297
+ return import_neverthrow16.Result.combine([
6082
6298
  mapOrderType(raw.type, ctx),
6083
6299
  mapOrderStatus(raw.status, ctx),
6084
6300
  mapDisputeStatus(raw.disputeStatus, ctx)
@@ -6111,7 +6327,7 @@ function normalizeSubgraphOrder(raw) {
6111
6327
  }
6112
6328
 
6113
6329
  // src/orders/subgraph/index.ts
6114
- var import_neverthrow16 = require("neverthrow");
6330
+ var import_neverthrow17 = require("neverthrow");
6115
6331
 
6116
6332
  // src/orders/subgraph/queries.ts
6117
6333
  var ORDERS_BY_USER_QUERY = (
@@ -6172,7 +6388,7 @@ function getOrdersForUser(subgraphUrl, userAddress, skip, limit, logger = noopLo
6172
6388
  context: { data: d }
6173
6389
  })
6174
6390
  ).andThen(
6175
- (validated) => import_neverthrow16.Result.combine(validated.orders_collection.map(normalizeSubgraphOrder))
6391
+ (validated) => import_neverthrow17.Result.combine(validated.orders_collection.map(normalizeSubgraphOrder))
6176
6392
  )
6177
6393
  );
6178
6394
  }
@@ -6326,7 +6542,7 @@ function createOrders(config) {
6326
6542
  ).andThen(
6327
6543
  ({ order, details }) => normalizeContractOrder(order, details).asyncAndThen((normalized) => {
6328
6544
  if (!normalized) {
6329
- return (0, import_neverthrow17.errAsync)(
6545
+ return (0, import_neverthrow18.errAsync)(
6330
6546
  new OrdersError("Order not found", {
6331
6547
  code: "ORDER_NOT_FOUND",
6332
6548
  context: { orderId: params.orderId.toString() }
@@ -6334,7 +6550,7 @@ function createOrders(config) {
6334
6550
  );
6335
6551
  }
6336
6552
  logger.debug("getOrder resolved", { orderId: params.orderId.toString() });
6337
- return (0, import_neverthrow17.okAsync)(normalized);
6553
+ return (0, import_neverthrow18.okAsync)(normalized);
6338
6554
  })
6339
6555
  );
6340
6556
  },
@@ -6420,8 +6636,8 @@ function createPrices(config) {
6420
6636
  }
6421
6637
 
6422
6638
  // src/profile/contracts/actions.ts
6423
- var import_neverthrow18 = require("neverthrow");
6424
- var import_viem18 = require("viem");
6639
+ var import_neverthrow19 = require("neverthrow");
6640
+ var import_viem19 = require("viem");
6425
6641
  function getBalances(publicClient, usdcAddress, diamondAddress, params) {
6426
6642
  return validate(
6427
6643
  ZodGetBalancesParamsSchema,
@@ -6432,7 +6648,7 @@ function getBalances(publicClient, usdcAddress, diamondAddress, params) {
6432
6648
  context: { params: data }
6433
6649
  })
6434
6650
  ).asyncAndThen(
6435
- (validated) => import_neverthrow18.ResultAsync.combine([
6651
+ (validated) => import_neverthrow19.ResultAsync.combine([
6436
6652
  getUsdcBalance(publicClient, usdcAddress, {
6437
6653
  address: validated.address
6438
6654
  }),
@@ -6446,8 +6662,8 @@ function getBalances(publicClient, usdcAddress, diamondAddress, params) {
6446
6662
  })
6447
6663
  )
6448
6664
  ]).map(([usdc, priceConfig]) => {
6449
- const usdcFormatted = Number((0, import_viem18.formatUnits)(usdc, 6));
6450
- const sellPriceFormatted = Number((0, import_viem18.formatUnits)(priceConfig.sellPrice, 6));
6665
+ const usdcFormatted = Number((0, import_viem19.formatUnits)(usdc, 6));
6666
+ const sellPriceFormatted = Number((0, import_viem19.formatUnits)(priceConfig.sellPrice, 6));
6451
6667
  return {
6452
6668
  usdc: usdcFormatted,
6453
6669
  fiat: usdcFormatted * sellPriceFormatted,
@@ -6468,6 +6684,225 @@ function createProfile(config) {
6468
6684
  };
6469
6685
  }
6470
6686
 
6687
+ // src/stake/actions/claim-unstake.ts
6688
+ var import_neverthrow21 = require("neverthrow");
6689
+ var import_viem20 = require("viem");
6690
+
6691
+ // src/stake/tx.ts
6692
+ var import_neverthrow20 = require("neverthrow");
6693
+ function submitPreparedTx2(input) {
6694
+ const { prepared, walletClient, publicClient, waitForReceipt } = input;
6695
+ const account = walletClient.account;
6696
+ if (!account) {
6697
+ return (0, import_neverthrow20.errAsync)(
6698
+ new StakeError("WalletClient is missing an account", {
6699
+ code: "TX_SUBMISSION_FAILED"
6700
+ })
6701
+ );
6702
+ }
6703
+ const chain = walletClient.chain;
6704
+ return import_neverthrow20.ResultAsync.fromPromise(
6705
+ walletClient.sendTransaction({
6706
+ account,
6707
+ chain,
6708
+ to: prepared.to,
6709
+ data: prepared.data,
6710
+ value: prepared.value
6711
+ }),
6712
+ (cause) => new StakeError("walletClient.sendTransaction rejected", {
6713
+ code: "TX_SUBMISSION_FAILED",
6714
+ cause
6715
+ })
6716
+ ).andThen((hash) => {
6717
+ if (!waitForReceipt) {
6718
+ return (0, import_neverthrow20.okAsync)({ hash });
6719
+ }
6720
+ return import_neverthrow20.ResultAsync.fromPromise(
6721
+ publicClient.waitForTransactionReceipt({ hash }),
6722
+ (cause) => new StakeError("waitForTransactionReceipt failed", {
6723
+ code: "RECEIPT_TIMEOUT",
6724
+ cause
6725
+ })
6726
+ ).andThen((receipt) => {
6727
+ if (receipt.status !== "success") {
6728
+ return (0, import_neverthrow20.errAsync)(
6729
+ new StakeError("Transaction reverted", {
6730
+ code: "TX_REVERTED",
6731
+ context: { hash, blockNumber: receipt.blockNumber.toString() }
6732
+ })
6733
+ );
6734
+ }
6735
+ return (0, import_neverthrow20.okAsync)({ hash, receipt });
6736
+ });
6737
+ });
6738
+ }
6739
+
6740
+ // src/stake/actions/claim-unstake.ts
6741
+ function createClaimUnstakeAction(input) {
6742
+ const { publicClient, diamondAddress } = input;
6743
+ const prepareFn = () => (0, import_neverthrow21.okAsync)({
6744
+ to: diamondAddress,
6745
+ data: (0, import_viem20.encodeFunctionData)({
6746
+ abi: ABIS.FACETS.STAKE,
6747
+ functionName: "p2pBoostClaimUnstake",
6748
+ args: []
6749
+ }),
6750
+ value: 0n
6751
+ });
6752
+ return {
6753
+ prepare() {
6754
+ return prepareFn();
6755
+ },
6756
+ execute({ walletClient, waitForReceipt }) {
6757
+ return prepareFn().andThen(
6758
+ (prepared) => submitPreparedTx2({ prepared, walletClient, publicClient, waitForReceipt })
6759
+ );
6760
+ }
6761
+ };
6762
+ }
6763
+
6764
+ // src/stake/actions/request-unstake.ts
6765
+ var import_neverthrow22 = require("neverthrow");
6766
+ var import_viem21 = require("viem");
6767
+ function createRequestUnstakeAction(input) {
6768
+ const { publicClient, diamondAddress } = input;
6769
+ const prepareFn = () => (0, import_neverthrow22.okAsync)({
6770
+ to: diamondAddress,
6771
+ data: (0, import_viem21.encodeFunctionData)({
6772
+ abi: ABIS.FACETS.STAKE,
6773
+ functionName: "p2pBoostRequestUnstake",
6774
+ args: []
6775
+ }),
6776
+ value: 0n
6777
+ });
6778
+ return {
6779
+ prepare() {
6780
+ return prepareFn();
6781
+ },
6782
+ execute({ walletClient, waitForReceipt }) {
6783
+ return prepareFn().andThen(
6784
+ (prepared) => submitPreparedTx2({ prepared, walletClient, publicClient, waitForReceipt })
6785
+ );
6786
+ }
6787
+ };
6788
+ }
6789
+
6790
+ // src/stake/actions/stake.ts
6791
+ var import_viem22 = require("viem");
6792
+ function createStakeAction(input) {
6793
+ const { publicClient, diamondAddress } = input;
6794
+ const prepareFn = (params) => validate(
6795
+ ZodStakeParamsSchema,
6796
+ params,
6797
+ (message, cause, data) => new StakeError(message, {
6798
+ code: "VALIDATION_ERROR",
6799
+ cause,
6800
+ context: { data }
6801
+ })
6802
+ ).map(({ tokens }) => ({
6803
+ to: diamondAddress,
6804
+ data: (0, import_viem22.encodeFunctionData)({
6805
+ abi: ABIS.FACETS.STAKE,
6806
+ functionName: "p2pBoostStake",
6807
+ args: [tokens]
6808
+ }),
6809
+ value: 0n
6810
+ }));
6811
+ return {
6812
+ prepare(params) {
6813
+ return prepareFn(params).asyncMap(async (tx) => tx);
6814
+ },
6815
+ execute({ walletClient, waitForReceipt, ...params }) {
6816
+ return prepareFn(params).asyncAndThen(
6817
+ (prepared) => submitPreparedTx2({ prepared, walletClient, publicClient, waitForReceipt })
6818
+ );
6819
+ }
6820
+ };
6821
+ }
6822
+
6823
+ // src/stake/actions/top-up.ts
6824
+ var import_viem23 = require("viem");
6825
+ function createTopUpAction(input) {
6826
+ const { publicClient, diamondAddress } = input;
6827
+ const prepareFn = (params) => validate(
6828
+ ZodTopUpParamsSchema,
6829
+ params,
6830
+ (message, cause, data) => new StakeError(message, {
6831
+ code: "VALIDATION_ERROR",
6832
+ cause,
6833
+ context: { data }
6834
+ })
6835
+ ).map(({ tokens }) => ({
6836
+ to: diamondAddress,
6837
+ data: (0, import_viem23.encodeFunctionData)({
6838
+ abi: ABIS.FACETS.STAKE,
6839
+ functionName: "p2pBoostTopUp",
6840
+ args: [tokens]
6841
+ }),
6842
+ value: 0n
6843
+ }));
6844
+ return {
6845
+ prepare(params) {
6846
+ return prepareFn(params).asyncMap(async (tx) => tx);
6847
+ },
6848
+ execute({ walletClient, waitForReceipt, ...params }) {
6849
+ return prepareFn(params).asyncAndThen(
6850
+ (prepared) => submitPreparedTx2({ prepared, walletClient, publicClient, waitForReceipt })
6851
+ );
6852
+ }
6853
+ };
6854
+ }
6855
+
6856
+ // src/stake/normalize.ts
6857
+ var STATUS_MAP = {
6858
+ 0: "none",
6859
+ 1: "active",
6860
+ 2: "cooldown",
6861
+ 3: "seized"
6862
+ };
6863
+ function normalizeUserStake(raw) {
6864
+ return {
6865
+ stakedAmount: raw.stakedAmount,
6866
+ cooldownEnd: raw.cooldownEnd,
6867
+ status: STATUS_MAP[raw.status] ?? "none"
6868
+ };
6869
+ }
6870
+ function normalizeStakeBoostGlobals(raw) {
6871
+ const [
6872
+ p2pToken,
6873
+ fraudReserve,
6874
+ maxStakeTokens,
6875
+ normalCooldown,
6876
+ blacklistCooldown,
6877
+ tokenDecimals,
6878
+ totalStaked
6879
+ ] = raw;
6880
+ return {
6881
+ p2pToken,
6882
+ fraudReserve,
6883
+ maxStakeTokens,
6884
+ normalCooldown,
6885
+ blacklistCooldown,
6886
+ tokenDecimals,
6887
+ totalStaked
6888
+ };
6889
+ }
6890
+
6891
+ // src/stake/client.ts
6892
+ function createStake(config) {
6893
+ const { publicClient, diamondAddress, p2pTokenAddress } = config;
6894
+ return {
6895
+ getUserStake: (params) => getUserStake(publicClient, diamondAddress, params).map(normalizeUserStake),
6896
+ getStakeBoostConfig: (params) => getStakeBoostConfig(publicClient, diamondAddress, params),
6897
+ getStakeBoostGlobals: () => getStakeBoostGlobals(publicClient, diamondAddress).map(normalizeStakeBoostGlobals),
6898
+ getP2pTokenBalance: (params) => getP2pTokenBalance(publicClient, p2pTokenAddress, params),
6899
+ stake: createStakeAction({ publicClient, diamondAddress }),
6900
+ topUp: createTopUpAction({ publicClient, diamondAddress }),
6901
+ requestUnstake: createRequestUnstakeAction({ publicClient, diamondAddress }),
6902
+ claimUnstake: createClaimUnstakeAction({ publicClient, diamondAddress })
6903
+ };
6904
+ }
6905
+
6471
6906
  // src/zkkyc/client.ts
6472
6907
  function createZkkyc(config) {
6473
6908
  const { reputationManagerAddress } = config;
@@ -6527,6 +6962,11 @@ function SdkProvider({ children, ...config }) {
6527
6962
  relayIdentity,
6528
6963
  logger
6529
6964
  }),
6965
+ stake: createStake({
6966
+ publicClient,
6967
+ diamondAddress: config.diamondAddress,
6968
+ p2pTokenAddress: config.p2pTokenAddress
6969
+ }),
6530
6970
  zkkyc: config.reputationManagerAddress ? createZkkyc({
6531
6971
  reputationManagerAddress: config.reputationManagerAddress
6532
6972
  }) : void 0,
@@ -6537,6 +6977,7 @@ function SdkProvider({ children, ...config }) {
6537
6977
  config.subgraphUrl,
6538
6978
  config.diamondAddress,
6539
6979
  config.usdcAddress,
6980
+ config.p2pTokenAddress,
6540
6981
  config.reputationManagerAddress,
6541
6982
  relayIdentityStore,
6542
6983
  relayIdentity,
@@ -6561,6 +7002,9 @@ function usePrices() {
6561
7002
  function useOrders() {
6562
7003
  return useSdk().orders;
6563
7004
  }
7005
+ function useStake() {
7006
+ return useSdk().stake;
7007
+ }
6564
7008
  function useZkkyc() {
6565
7009
  const zkkyc = useSdk().zkkyc;
6566
7010
  if (!zkkyc) {
@@ -6637,6 +7081,7 @@ function useFingerprint(enabled) {
6637
7081
  usePrices,
6638
7082
  useProfile,
6639
7083
  useSdk,
7084
+ useStake,
6640
7085
  useWatchOrders,
6641
7086
  useZkkyc
6642
7087
  });