@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.mjs CHANGED
@@ -1127,6 +1127,97 @@ var p2pConfigFacetAbi = [
1127
1127
  }
1128
1128
  ];
1129
1129
 
1130
+ // src/contracts/abis/p2p-stake-boost-facet.ts
1131
+ var p2pStakeBoostFacetAbi = [
1132
+ {
1133
+ inputs: [{ internalType: "uint256", name: "tokens", type: "uint256" }],
1134
+ name: "p2pBoostStake",
1135
+ outputs: [],
1136
+ stateMutability: "nonpayable",
1137
+ type: "function"
1138
+ },
1139
+ {
1140
+ inputs: [{ internalType: "uint256", name: "tokens", type: "uint256" }],
1141
+ name: "p2pBoostTopUp",
1142
+ outputs: [],
1143
+ stateMutability: "nonpayable",
1144
+ type: "function"
1145
+ },
1146
+ {
1147
+ inputs: [],
1148
+ name: "p2pBoostRequestUnstake",
1149
+ outputs: [],
1150
+ stateMutability: "nonpayable",
1151
+ type: "function"
1152
+ },
1153
+ {
1154
+ inputs: [],
1155
+ name: "p2pBoostClaimUnstake",
1156
+ outputs: [],
1157
+ stateMutability: "nonpayable",
1158
+ type: "function"
1159
+ },
1160
+ {
1161
+ inputs: [{ internalType: "address", name: "user", type: "address" }],
1162
+ name: "getUserStake",
1163
+ outputs: [
1164
+ {
1165
+ components: [
1166
+ { internalType: "uint128", name: "stakedAmount", type: "uint128" },
1167
+ { internalType: "uint64", name: "cooldownEnd", type: "uint64" },
1168
+ { internalType: "uint8", name: "status", type: "uint8" }
1169
+ ],
1170
+ internalType: "struct P2PStakeBoostStorage.UserStake",
1171
+ name: "",
1172
+ type: "tuple"
1173
+ }
1174
+ ],
1175
+ stateMutability: "view",
1176
+ type: "function"
1177
+ },
1178
+ {
1179
+ inputs: [{ internalType: "bytes32", name: "currency", type: "bytes32" }],
1180
+ name: "getStakeBoostConfig",
1181
+ outputs: [
1182
+ {
1183
+ components: [
1184
+ {
1185
+ internalType: "uint256",
1186
+ name: "tokensPerUsdNumerator",
1187
+ type: "uint256"
1188
+ },
1189
+ {
1190
+ internalType: "uint256",
1191
+ name: "tokensPerUsdDenominator",
1192
+ type: "uint256"
1193
+ },
1194
+ { internalType: "uint256", name: "maxBoostUsd", type: "uint256" }
1195
+ ],
1196
+ internalType: "struct P2PStakeBoostStorage.BoostConfig",
1197
+ name: "",
1198
+ type: "tuple"
1199
+ }
1200
+ ],
1201
+ stateMutability: "view",
1202
+ type: "function"
1203
+ },
1204
+ {
1205
+ inputs: [],
1206
+ name: "getStakeBoostGlobals",
1207
+ outputs: [
1208
+ { internalType: "address", name: "p2pToken", type: "address" },
1209
+ { internalType: "address", name: "fraudReserve", type: "address" },
1210
+ { internalType: "uint256", name: "maxStakeTokens", type: "uint256" },
1211
+ { internalType: "uint256", name: "normalCooldown", type: "uint256" },
1212
+ { internalType: "uint256", name: "blacklistCooldown", type: "uint256" },
1213
+ { internalType: "uint8", name: "tokenDecimals", type: "uint8" },
1214
+ { internalType: "uint256", name: "totalStaked", type: "uint256" }
1215
+ ],
1216
+ stateMutability: "view",
1217
+ type: "function"
1218
+ }
1219
+ ];
1220
+
1130
1221
  // src/contracts/abis/reputation-manager.ts
1131
1222
  var reputationManagerAbi = [
1132
1223
  {
@@ -1333,14 +1424,16 @@ var reputationManagerAbi = [
1333
1424
  var DIAMOND_ABI = [
1334
1425
  ...orderFlowFacetAbi,
1335
1426
  ...orderProcessorFacetAbi,
1336
- ...p2pConfigFacetAbi
1427
+ ...p2pConfigFacetAbi,
1428
+ ...p2pStakeBoostFacetAbi
1337
1429
  ];
1338
1430
  var ABIS = {
1339
1431
  DIAMOND: DIAMOND_ABI,
1340
1432
  FACETS: {
1341
1433
  ORDER_FLOW: orderFlowFacetAbi,
1342
1434
  ORDER_PROCESSOR: orderProcessorFacetAbi,
1343
- CONFIG: p2pConfigFacetAbi
1435
+ CONFIG: p2pConfigFacetAbi,
1436
+ STAKE: p2pStakeBoostFacetAbi
1344
1437
  },
1345
1438
  EXTERNAL: {
1346
1439
  USDC: erc20Abi,
@@ -3854,15 +3947,15 @@ function weierstrassPoints(opts) {
3854
3947
  throw new Error("ProjectivePoint expected");
3855
3948
  }
3856
3949
  const toAffineMemo = memoized((p, iz) => {
3857
- const { px: x, py: y, pz: z10 } = p;
3858
- if (Fp.eql(z10, Fp.ONE))
3950
+ const { px: x, py: y, pz: z11 } = p;
3951
+ if (Fp.eql(z11, Fp.ONE))
3859
3952
  return { x, y };
3860
3953
  const is0 = p.is0();
3861
3954
  if (iz == null)
3862
- iz = is0 ? Fp.ONE : Fp.inv(z10);
3955
+ iz = is0 ? Fp.ONE : Fp.inv(z11);
3863
3956
  const ax = Fp.mul(x, iz);
3864
3957
  const ay = Fp.mul(y, iz);
3865
- const zz = Fp.mul(z10, iz);
3958
+ const zz = Fp.mul(z11, iz);
3866
3959
  if (is0)
3867
3960
  return { x: Fp.ZERO, y: Fp.ZERO };
3868
3961
  if (!Fp.eql(zz, Fp.ONE))
@@ -4857,7 +4950,7 @@ function createSetSellOrderUpiAction(input) {
4857
4950
  }
4858
4951
 
4859
4952
  // src/orders/internal/routing/client.ts
4860
- import { stringToHex as stringToHex6 } from "viem";
4953
+ import { stringToHex as stringToHex7 } from "viem";
4861
4954
 
4862
4955
  // src/contracts/errors.ts
4863
4956
  var contractErrors = {
@@ -5449,6 +5542,128 @@ function getReputationPerUsdcLimit(publicClient, diamondAddress, params) {
5449
5542
  );
5450
5543
  }
5451
5544
 
5545
+ // src/contracts/p2p-stake/index.ts
5546
+ import { ResultAsync as ResultAsync9 } from "neverthrow";
5547
+ import { stringToHex as stringToHex5 } from "viem";
5548
+
5549
+ // src/stake/errors.ts
5550
+ var StakeError = class extends SdkError {
5551
+ constructor(message, options) {
5552
+ super(message, options);
5553
+ this.name = "StakeError";
5554
+ }
5555
+ };
5556
+
5557
+ // src/stake/validation.ts
5558
+ import { z as z8 } from "zod";
5559
+ var ZodGetUserStakeParamsSchema = z8.object({
5560
+ user: ZodAddressSchema
5561
+ });
5562
+ var ZodGetStakeBoostConfigParamsSchema = z8.object({
5563
+ currency: ZodCurrencySchema
5564
+ });
5565
+ var ZodGetP2pTokenBalanceParamsSchema = z8.object({
5566
+ address: ZodAddressSchema
5567
+ });
5568
+ var ZodStakeParamsSchema = z8.object({
5569
+ tokens: z8.bigint().positive()
5570
+ });
5571
+ var ZodTopUpParamsSchema = z8.object({
5572
+ tokens: z8.bigint().positive()
5573
+ });
5574
+
5575
+ // src/contracts/p2p-stake/index.ts
5576
+ function getUserStake(publicClient, diamondAddress, params) {
5577
+ return validate(
5578
+ ZodGetUserStakeParamsSchema,
5579
+ params,
5580
+ (message, cause, data) => new StakeError(message, {
5581
+ code: "VALIDATION_ERROR",
5582
+ cause,
5583
+ context: { params: data }
5584
+ })
5585
+ ).asyncAndThen(
5586
+ (validated) => ResultAsync9.fromPromise(
5587
+ publicClient.readContract({
5588
+ address: diamondAddress,
5589
+ abi: ABIS.FACETS.STAKE,
5590
+ functionName: "getUserStake",
5591
+ args: [validated.user]
5592
+ }),
5593
+ (error) => new StakeError("Failed to read user stake", {
5594
+ code: "CONTRACT_READ_ERROR",
5595
+ cause: error,
5596
+ context: { user: validated.user, diamondAddress }
5597
+ })
5598
+ )
5599
+ );
5600
+ }
5601
+ function getStakeBoostConfig(publicClient, diamondAddress, params) {
5602
+ return validate(
5603
+ ZodGetStakeBoostConfigParamsSchema,
5604
+ params,
5605
+ (message, cause, data) => new StakeError(message, {
5606
+ code: "VALIDATION_ERROR",
5607
+ cause,
5608
+ context: { params: data }
5609
+ })
5610
+ ).asyncAndThen(
5611
+ (validated) => ResultAsync9.fromPromise(
5612
+ publicClient.readContract({
5613
+ address: diamondAddress,
5614
+ abi: ABIS.FACETS.STAKE,
5615
+ functionName: "getStakeBoostConfig",
5616
+ args: [stringToHex5(validated.currency, { size: 32 })]
5617
+ }),
5618
+ (error) => new StakeError("Failed to read stake boost config", {
5619
+ code: "CONTRACT_READ_ERROR",
5620
+ cause: error,
5621
+ context: { currency: validated.currency, diamondAddress }
5622
+ })
5623
+ )
5624
+ );
5625
+ }
5626
+ function getStakeBoostGlobals(publicClient, diamondAddress) {
5627
+ return ResultAsync9.fromPromise(
5628
+ publicClient.readContract({
5629
+ address: diamondAddress,
5630
+ abi: ABIS.FACETS.STAKE,
5631
+ functionName: "getStakeBoostGlobals",
5632
+ args: []
5633
+ }),
5634
+ (error) => new StakeError("Failed to read stake boost globals", {
5635
+ code: "CONTRACT_READ_ERROR",
5636
+ cause: error,
5637
+ context: { diamondAddress }
5638
+ })
5639
+ );
5640
+ }
5641
+ function getP2pTokenBalance(publicClient, p2pTokenAddress, params) {
5642
+ return validate(
5643
+ ZodGetP2pTokenBalanceParamsSchema,
5644
+ params,
5645
+ (message, cause, data) => new StakeError(message, {
5646
+ code: "VALIDATION_ERROR",
5647
+ cause,
5648
+ context: { params: data }
5649
+ })
5650
+ ).asyncAndThen(
5651
+ (validated) => ResultAsync9.fromPromise(
5652
+ publicClient.readContract({
5653
+ address: p2pTokenAddress,
5654
+ abi: ABIS.EXTERNAL.USDC,
5655
+ functionName: "balanceOf",
5656
+ args: [validated.address]
5657
+ }),
5658
+ (error) => new StakeError("Failed to read P2P token balance", {
5659
+ code: "CONTRACT_READ_ERROR",
5660
+ cause: error,
5661
+ context: { address: validated.address, p2pTokenAddress }
5662
+ })
5663
+ )
5664
+ );
5665
+ }
5666
+
5452
5667
  // src/contracts/reputation-manager/writes.ts
5453
5668
  import { Result as Result2 } from "neverthrow";
5454
5669
  import { encodeFunctionData as encodeFunctionData7 } from "viem";
@@ -5462,75 +5677,75 @@ var ZkkycError = class extends SdkError {
5462
5677
  };
5463
5678
 
5464
5679
  // src/zkkyc/validation.ts
5465
- import { z as z8 } from "zod";
5466
- var ZodAnonAadharProofParamsSchema = z8.object({
5467
- nullifierSeed: z8.bigint(),
5468
- nullifier: z8.bigint(),
5469
- timestamp: z8.bigint(),
5470
- signal: z8.bigint(),
5471
- revealArray: z8.tuple([z8.bigint(), z8.bigint(), z8.bigint(), z8.bigint()]),
5472
- packedGroth16Proof: z8.tuple([
5473
- z8.bigint(),
5474
- z8.bigint(),
5475
- z8.bigint(),
5476
- z8.bigint(),
5477
- z8.bigint(),
5478
- z8.bigint(),
5479
- z8.bigint(),
5480
- z8.bigint()
5680
+ import { z as z9 } from "zod";
5681
+ var ZodAnonAadharProofParamsSchema = z9.object({
5682
+ nullifierSeed: z9.bigint(),
5683
+ nullifier: z9.bigint(),
5684
+ timestamp: z9.bigint(),
5685
+ signal: z9.bigint(),
5686
+ revealArray: z9.tuple([z9.bigint(), z9.bigint(), z9.bigint(), z9.bigint()]),
5687
+ packedGroth16Proof: z9.tuple([
5688
+ z9.bigint(),
5689
+ z9.bigint(),
5690
+ z9.bigint(),
5691
+ z9.bigint(),
5692
+ z9.bigint(),
5693
+ z9.bigint(),
5694
+ z9.bigint(),
5695
+ z9.bigint()
5481
5696
  ])
5482
5697
  });
5483
- var ZodSocialVerifyParamsSchema = z8.object({
5484
- _socialName: z8.string(),
5485
- proofs: z8.array(
5486
- z8.object({
5487
- claimInfo: z8.object({
5488
- provider: z8.string(),
5489
- parameters: z8.string(),
5490
- context: z8.string()
5698
+ var ZodSocialVerifyParamsSchema = z9.object({
5699
+ _socialName: z9.string(),
5700
+ proofs: z9.array(
5701
+ z9.object({
5702
+ claimInfo: z9.object({
5703
+ provider: z9.string(),
5704
+ parameters: z9.string(),
5705
+ context: z9.string()
5491
5706
  }),
5492
- signedClaim: z8.object({
5493
- claim: z8.object({
5494
- identifier: z8.string(),
5707
+ signedClaim: z9.object({
5708
+ claim: z9.object({
5709
+ identifier: z9.string(),
5495
5710
  owner: ZodAddressSchema,
5496
- timestampS: z8.number(),
5497
- epoch: z8.number()
5711
+ timestampS: z9.number(),
5712
+ epoch: z9.number()
5498
5713
  }),
5499
- signatures: z8.array(z8.string())
5714
+ signatures: z9.array(z9.string())
5500
5715
  })
5501
5716
  })
5502
5717
  )
5503
5718
  });
5504
- var ZodSolidityVerifierParametersSchema = z8.object({
5505
- version: z8.string().refine((val) => val.startsWith("0x"), {
5719
+ var ZodSolidityVerifierParametersSchema = z9.object({
5720
+ version: z9.string().refine((val) => val.startsWith("0x"), {
5506
5721
  message: "Version must be a hex string"
5507
5722
  }),
5508
- proofVerificationData: z8.object({
5509
- vkeyHash: z8.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
5723
+ proofVerificationData: z9.object({
5724
+ vkeyHash: z9.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
5510
5725
  message: "Invalid bytes32 hex string"
5511
5726
  }),
5512
- proof: z8.string().refine((val) => val.startsWith("0x"), {
5727
+ proof: z9.string().refine((val) => val.startsWith("0x"), {
5513
5728
  message: "Proof must be a hex string"
5514
5729
  }),
5515
- publicInputs: z8.array(
5516
- z8.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
5730
+ publicInputs: z9.array(
5731
+ z9.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
5517
5732
  message: "Each public input must be a valid bytes32 hex string"
5518
5733
  })
5519
5734
  )
5520
5735
  }),
5521
- committedInputs: z8.string().refine((val) => val.startsWith("0x"), {
5736
+ committedInputs: z9.string().refine((val) => val.startsWith("0x"), {
5522
5737
  message: "Committed inputs must be a hex string"
5523
5738
  }),
5524
- serviceConfig: z8.object({
5525
- validityPeriodInSeconds: z8.number().int().nonnegative(),
5526
- domain: z8.string(),
5527
- scope: z8.string(),
5528
- devMode: z8.boolean()
5739
+ serviceConfig: z9.object({
5740
+ validityPeriodInSeconds: z9.number().int().nonnegative(),
5741
+ domain: z9.string(),
5742
+ scope: z9.string(),
5743
+ devMode: z9.boolean()
5529
5744
  })
5530
5745
  });
5531
- var ZodZkPassportRegisterParamsSchema = z8.object({
5746
+ var ZodZkPassportRegisterParamsSchema = z9.object({
5532
5747
  params: ZodSolidityVerifierParametersSchema,
5533
- isIDCard: z8.boolean()
5748
+ isIDCard: z9.boolean()
5534
5749
  });
5535
5750
 
5536
5751
  // src/contracts/reputation-manager/writes.ts
@@ -5640,8 +5855,8 @@ function prepareZkPassportRegister(reputationManagerAddress, params) {
5640
5855
  }
5641
5856
 
5642
5857
  // src/contracts/tx-limits/index.ts
5643
- import { ResultAsync as ResultAsync9 } from "neverthrow";
5644
- import { formatUnits, stringToHex as stringToHex5 } from "viem";
5858
+ import { ResultAsync as ResultAsync10 } from "neverthrow";
5859
+ import { formatUnits, stringToHex as stringToHex6 } from "viem";
5645
5860
 
5646
5861
  // src/profile/errors.ts
5647
5862
  var ProfileError = class extends SdkError {
@@ -5652,18 +5867,18 @@ var ProfileError = class extends SdkError {
5652
5867
  };
5653
5868
 
5654
5869
  // src/profile/validation.ts
5655
- import { z as z9 } from "zod";
5656
- var ZodUsdcBalanceParamsSchema = z9.object({
5870
+ import { z as z10 } from "zod";
5871
+ var ZodUsdcBalanceParamsSchema = z10.object({
5657
5872
  address: ZodAddressSchema
5658
5873
  });
5659
- var ZodUsdcAllowanceParamsSchema = z9.object({
5874
+ var ZodUsdcAllowanceParamsSchema = z10.object({
5660
5875
  owner: ZodAddressSchema
5661
5876
  });
5662
- var ZodGetBalancesParamsSchema = z9.object({
5877
+ var ZodGetBalancesParamsSchema = z10.object({
5663
5878
  address: ZodAddressSchema,
5664
5879
  currency: ZodCurrencySchema
5665
5880
  });
5666
- var ZodTxLimitsParamsSchema = z9.object({
5881
+ var ZodTxLimitsParamsSchema = z10.object({
5667
5882
  address: ZodAddressSchema,
5668
5883
  currency: ZodCurrencySchema
5669
5884
  });
@@ -5679,12 +5894,12 @@ function getTxLimits(publicClient, diamondAddress, params) {
5679
5894
  context: { params: data }
5680
5895
  })
5681
5896
  ).asyncAndThen(
5682
- (validated) => ResultAsync9.fromPromise(
5897
+ (validated) => ResultAsync10.fromPromise(
5683
5898
  publicClient.readContract({
5684
5899
  address: diamondAddress,
5685
5900
  abi: ABIS.FACETS.ORDER_FLOW,
5686
5901
  functionName: "userTxLimit",
5687
- args: [validated.address, stringToHex5(validated.currency, { size: 32 })]
5902
+ args: [validated.address, stringToHex6(validated.currency, { size: 32 })]
5688
5903
  }),
5689
5904
  (error) => new ProfileError("Failed to read tx limits", {
5690
5905
  code: "CONTRACT_READ_ERROR",
@@ -5699,7 +5914,7 @@ function getTxLimits(publicClient, diamondAddress, params) {
5699
5914
  }
5700
5915
 
5701
5916
  // src/contracts/usdc/index.ts
5702
- import { ResultAsync as ResultAsync10 } from "neverthrow";
5917
+ import { ResultAsync as ResultAsync11 } from "neverthrow";
5703
5918
  import { erc20Abi as erc20Abi3 } from "viem";
5704
5919
  function getUsdcBalance(publicClient, usdcAddress, params) {
5705
5920
  return validate(
@@ -5711,7 +5926,7 @@ function getUsdcBalance(publicClient, usdcAddress, params) {
5711
5926
  context: { params: data }
5712
5927
  })
5713
5928
  ).asyncAndThen(
5714
- (validated) => ResultAsync10.fromPromise(
5929
+ (validated) => ResultAsync11.fromPromise(
5715
5930
  publicClient.readContract({
5716
5931
  address: usdcAddress,
5717
5932
  abi: ABIS.EXTERNAL.USDC,
@@ -5736,7 +5951,7 @@ function getUsdcAllowance(publicClient, usdcAddress, diamondAddress, params) {
5736
5951
  context: { params: data }
5737
5952
  })
5738
5953
  ).asyncAndThen(
5739
- (validated) => ResultAsync10.fromPromise(
5954
+ (validated) => ResultAsync11.fromPromise(
5740
5955
  publicClient.readContract({
5741
5956
  address: usdcAddress,
5742
5957
  abi: erc20Abi3,
@@ -5928,7 +6143,7 @@ function createOrderRouter(config) {
5928
6143
  const logger = config.logger ?? noopLogger;
5929
6144
  return {
5930
6145
  selectCircle(params) {
5931
- const currencyHex = stringToHex6(params.currency, { size: 32 });
6146
+ const currencyHex = stringToHex7(params.currency, { size: 32 });
5932
6147
  logger.info("selectCircle started", {
5933
6148
  currency: params.currency,
5934
6149
  user: params.user,
@@ -6376,7 +6591,7 @@ function createPrices(config) {
6376
6591
  }
6377
6592
 
6378
6593
  // src/profile/contracts/actions.ts
6379
- import { ResultAsync as ResultAsync11 } from "neverthrow";
6594
+ import { ResultAsync as ResultAsync12 } from "neverthrow";
6380
6595
  import { formatUnits as formatUnits2 } from "viem";
6381
6596
  function getBalances(publicClient, usdcAddress, diamondAddress, params) {
6382
6597
  return validate(
@@ -6388,7 +6603,7 @@ function getBalances(publicClient, usdcAddress, diamondAddress, params) {
6388
6603
  context: { params: data }
6389
6604
  })
6390
6605
  ).asyncAndThen(
6391
- (validated) => ResultAsync11.combine([
6606
+ (validated) => ResultAsync12.combine([
6392
6607
  getUsdcBalance(publicClient, usdcAddress, {
6393
6608
  address: validated.address
6394
6609
  }),
@@ -6424,6 +6639,225 @@ function createProfile(config) {
6424
6639
  };
6425
6640
  }
6426
6641
 
6642
+ // src/stake/actions/claim-unstake.ts
6643
+ import { okAsync as okAsync6 } from "neverthrow";
6644
+ import { encodeFunctionData as encodeFunctionData8 } from "viem";
6645
+
6646
+ // src/stake/tx.ts
6647
+ import { errAsync as errAsync5, okAsync as okAsync5, ResultAsync as ResultAsync13 } from "neverthrow";
6648
+ function submitPreparedTx2(input) {
6649
+ const { prepared, walletClient, publicClient, waitForReceipt } = input;
6650
+ const account = walletClient.account;
6651
+ if (!account) {
6652
+ return errAsync5(
6653
+ new StakeError("WalletClient is missing an account", {
6654
+ code: "TX_SUBMISSION_FAILED"
6655
+ })
6656
+ );
6657
+ }
6658
+ const chain = walletClient.chain;
6659
+ return ResultAsync13.fromPromise(
6660
+ walletClient.sendTransaction({
6661
+ account,
6662
+ chain,
6663
+ to: prepared.to,
6664
+ data: prepared.data,
6665
+ value: prepared.value
6666
+ }),
6667
+ (cause) => new StakeError("walletClient.sendTransaction rejected", {
6668
+ code: "TX_SUBMISSION_FAILED",
6669
+ cause
6670
+ })
6671
+ ).andThen((hash) => {
6672
+ if (!waitForReceipt) {
6673
+ return okAsync5({ hash });
6674
+ }
6675
+ return ResultAsync13.fromPromise(
6676
+ publicClient.waitForTransactionReceipt({ hash }),
6677
+ (cause) => new StakeError("waitForTransactionReceipt failed", {
6678
+ code: "RECEIPT_TIMEOUT",
6679
+ cause
6680
+ })
6681
+ ).andThen((receipt) => {
6682
+ if (receipt.status !== "success") {
6683
+ return errAsync5(
6684
+ new StakeError("Transaction reverted", {
6685
+ code: "TX_REVERTED",
6686
+ context: { hash, blockNumber: receipt.blockNumber.toString() }
6687
+ })
6688
+ );
6689
+ }
6690
+ return okAsync5({ hash, receipt });
6691
+ });
6692
+ });
6693
+ }
6694
+
6695
+ // src/stake/actions/claim-unstake.ts
6696
+ function createClaimUnstakeAction(input) {
6697
+ const { publicClient, diamondAddress } = input;
6698
+ const prepareFn = () => okAsync6({
6699
+ to: diamondAddress,
6700
+ data: encodeFunctionData8({
6701
+ abi: ABIS.FACETS.STAKE,
6702
+ functionName: "p2pBoostClaimUnstake",
6703
+ args: []
6704
+ }),
6705
+ value: 0n
6706
+ });
6707
+ return {
6708
+ prepare() {
6709
+ return prepareFn();
6710
+ },
6711
+ execute({ walletClient, waitForReceipt }) {
6712
+ return prepareFn().andThen(
6713
+ (prepared) => submitPreparedTx2({ prepared, walletClient, publicClient, waitForReceipt })
6714
+ );
6715
+ }
6716
+ };
6717
+ }
6718
+
6719
+ // src/stake/actions/request-unstake.ts
6720
+ import { okAsync as okAsync7 } from "neverthrow";
6721
+ import { encodeFunctionData as encodeFunctionData9 } from "viem";
6722
+ function createRequestUnstakeAction(input) {
6723
+ const { publicClient, diamondAddress } = input;
6724
+ const prepareFn = () => okAsync7({
6725
+ to: diamondAddress,
6726
+ data: encodeFunctionData9({
6727
+ abi: ABIS.FACETS.STAKE,
6728
+ functionName: "p2pBoostRequestUnstake",
6729
+ args: []
6730
+ }),
6731
+ value: 0n
6732
+ });
6733
+ return {
6734
+ prepare() {
6735
+ return prepareFn();
6736
+ },
6737
+ execute({ walletClient, waitForReceipt }) {
6738
+ return prepareFn().andThen(
6739
+ (prepared) => submitPreparedTx2({ prepared, walletClient, publicClient, waitForReceipt })
6740
+ );
6741
+ }
6742
+ };
6743
+ }
6744
+
6745
+ // src/stake/actions/stake.ts
6746
+ import { encodeFunctionData as encodeFunctionData10 } from "viem";
6747
+ function createStakeAction(input) {
6748
+ const { publicClient, diamondAddress } = input;
6749
+ const prepareFn = (params) => validate(
6750
+ ZodStakeParamsSchema,
6751
+ params,
6752
+ (message, cause, data) => new StakeError(message, {
6753
+ code: "VALIDATION_ERROR",
6754
+ cause,
6755
+ context: { data }
6756
+ })
6757
+ ).map(({ tokens }) => ({
6758
+ to: diamondAddress,
6759
+ data: encodeFunctionData10({
6760
+ abi: ABIS.FACETS.STAKE,
6761
+ functionName: "p2pBoostStake",
6762
+ args: [tokens]
6763
+ }),
6764
+ value: 0n
6765
+ }));
6766
+ return {
6767
+ prepare(params) {
6768
+ return prepareFn(params).asyncMap(async (tx) => tx);
6769
+ },
6770
+ execute({ walletClient, waitForReceipt, ...params }) {
6771
+ return prepareFn(params).asyncAndThen(
6772
+ (prepared) => submitPreparedTx2({ prepared, walletClient, publicClient, waitForReceipt })
6773
+ );
6774
+ }
6775
+ };
6776
+ }
6777
+
6778
+ // src/stake/actions/top-up.ts
6779
+ import { encodeFunctionData as encodeFunctionData11 } from "viem";
6780
+ function createTopUpAction(input) {
6781
+ const { publicClient, diamondAddress } = input;
6782
+ const prepareFn = (params) => validate(
6783
+ ZodTopUpParamsSchema,
6784
+ params,
6785
+ (message, cause, data) => new StakeError(message, {
6786
+ code: "VALIDATION_ERROR",
6787
+ cause,
6788
+ context: { data }
6789
+ })
6790
+ ).map(({ tokens }) => ({
6791
+ to: diamondAddress,
6792
+ data: encodeFunctionData11({
6793
+ abi: ABIS.FACETS.STAKE,
6794
+ functionName: "p2pBoostTopUp",
6795
+ args: [tokens]
6796
+ }),
6797
+ value: 0n
6798
+ }));
6799
+ return {
6800
+ prepare(params) {
6801
+ return prepareFn(params).asyncMap(async (tx) => tx);
6802
+ },
6803
+ execute({ walletClient, waitForReceipt, ...params }) {
6804
+ return prepareFn(params).asyncAndThen(
6805
+ (prepared) => submitPreparedTx2({ prepared, walletClient, publicClient, waitForReceipt })
6806
+ );
6807
+ }
6808
+ };
6809
+ }
6810
+
6811
+ // src/stake/normalize.ts
6812
+ var STATUS_MAP = {
6813
+ 0: "none",
6814
+ 1: "active",
6815
+ 2: "cooldown",
6816
+ 3: "seized"
6817
+ };
6818
+ function normalizeUserStake(raw) {
6819
+ return {
6820
+ stakedAmount: raw.stakedAmount,
6821
+ cooldownEnd: raw.cooldownEnd,
6822
+ status: STATUS_MAP[raw.status] ?? "none"
6823
+ };
6824
+ }
6825
+ function normalizeStakeBoostGlobals(raw) {
6826
+ const [
6827
+ p2pToken,
6828
+ fraudReserve,
6829
+ maxStakeTokens,
6830
+ normalCooldown,
6831
+ blacklistCooldown,
6832
+ tokenDecimals,
6833
+ totalStaked
6834
+ ] = raw;
6835
+ return {
6836
+ p2pToken,
6837
+ fraudReserve,
6838
+ maxStakeTokens,
6839
+ normalCooldown,
6840
+ blacklistCooldown,
6841
+ tokenDecimals,
6842
+ totalStaked
6843
+ };
6844
+ }
6845
+
6846
+ // src/stake/client.ts
6847
+ function createStake(config) {
6848
+ const { publicClient, diamondAddress, p2pTokenAddress } = config;
6849
+ return {
6850
+ getUserStake: (params) => getUserStake(publicClient, diamondAddress, params).map(normalizeUserStake),
6851
+ getStakeBoostConfig: (params) => getStakeBoostConfig(publicClient, diamondAddress, params),
6852
+ getStakeBoostGlobals: () => getStakeBoostGlobals(publicClient, diamondAddress).map(normalizeStakeBoostGlobals),
6853
+ getP2pTokenBalance: (params) => getP2pTokenBalance(publicClient, p2pTokenAddress, params),
6854
+ stake: createStakeAction({ publicClient, diamondAddress }),
6855
+ topUp: createTopUpAction({ publicClient, diamondAddress }),
6856
+ requestUnstake: createRequestUnstakeAction({ publicClient, diamondAddress }),
6857
+ claimUnstake: createClaimUnstakeAction({ publicClient, diamondAddress })
6858
+ };
6859
+ }
6860
+
6427
6861
  // src/zkkyc/client.ts
6428
6862
  function createZkkyc(config) {
6429
6863
  const { reputationManagerAddress } = config;
@@ -6483,6 +6917,11 @@ function SdkProvider({ children, ...config }) {
6483
6917
  relayIdentity,
6484
6918
  logger
6485
6919
  }),
6920
+ stake: createStake({
6921
+ publicClient,
6922
+ diamondAddress: config.diamondAddress,
6923
+ p2pTokenAddress: config.p2pTokenAddress
6924
+ }),
6486
6925
  zkkyc: config.reputationManagerAddress ? createZkkyc({
6487
6926
  reputationManagerAddress: config.reputationManagerAddress
6488
6927
  }) : void 0,
@@ -6493,6 +6932,7 @@ function SdkProvider({ children, ...config }) {
6493
6932
  config.subgraphUrl,
6494
6933
  config.diamondAddress,
6495
6934
  config.usdcAddress,
6935
+ config.p2pTokenAddress,
6496
6936
  config.reputationManagerAddress,
6497
6937
  relayIdentityStore,
6498
6938
  relayIdentity,
@@ -6517,6 +6957,9 @@ function usePrices() {
6517
6957
  function useOrders() {
6518
6958
  return useSdk().orders;
6519
6959
  }
6960
+ function useStake() {
6961
+ return useSdk().stake;
6962
+ }
6520
6963
  function useZkkyc() {
6521
6964
  const zkkyc = useSdk().zkkyc;
6522
6965
  if (!zkkyc) {
@@ -6592,6 +7035,7 @@ export {
6592
7035
  usePrices,
6593
7036
  useProfile,
6594
7037
  useSdk,
7038
+ useStake,
6595
7039
  useWatchOrders,
6596
7040
  useZkkyc
6597
7041
  };