@p2pdotme/sdk 1.1.8 → 1.2.0
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 +204 -82
- package/dist/orders.cjs.map +1 -1
- package/dist/orders.mjs +183 -61
- package/dist/orders.mjs.map +1 -1
- package/dist/prices.cjs +179 -57
- package/dist/prices.cjs.map +1 -1
- package/dist/prices.mjs +177 -55
- package/dist/prices.mjs.map +1 -1
- package/dist/profile.cjs +191 -69
- package/dist/profile.cjs.map +1 -1
- package/dist/profile.mjs +183 -61
- package/dist/profile.mjs.map +1 -1
- package/dist/react.cjs +579 -100
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +137 -1
- package/dist/react.d.ts +137 -1
- package/dist/react.mjs +545 -67
- package/dist/react.mjs.map +1 -1
- package/dist/stake.cjs +1246 -0
- package/dist/stake.cjs.map +1 -0
- package/dist/stake.d.cts +197 -0
- package/dist/stake.d.ts +197 -0
- package/dist/stake.mjs +1218 -0
- package/dist/stake.mjs.map +1 -0
- package/dist/zkkyc.cjs +102 -2
- package/dist/zkkyc.cjs.map +1 -1
- package/dist/zkkyc.mjs +102 -2
- package/dist/zkkyc.mjs.map +1 -1
- package/package.json +7 -1
package/dist/react.mjs
CHANGED
|
@@ -1127,6 +1127,104 @@ 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: [],
|
|
1162
|
+
name: "p2pBoostCancelUnstake",
|
|
1163
|
+
outputs: [],
|
|
1164
|
+
stateMutability: "nonpayable",
|
|
1165
|
+
type: "function"
|
|
1166
|
+
},
|
|
1167
|
+
{
|
|
1168
|
+
inputs: [{ internalType: "address", name: "user", type: "address" }],
|
|
1169
|
+
name: "getUserStake",
|
|
1170
|
+
outputs: [
|
|
1171
|
+
{
|
|
1172
|
+
components: [
|
|
1173
|
+
{ internalType: "uint128", name: "stakedAmount", type: "uint128" },
|
|
1174
|
+
{ internalType: "uint64", name: "cooldownEnd", type: "uint64" },
|
|
1175
|
+
{ internalType: "uint8", name: "status", type: "uint8" }
|
|
1176
|
+
],
|
|
1177
|
+
internalType: "struct P2PStakeBoostStorage.UserStake",
|
|
1178
|
+
name: "",
|
|
1179
|
+
type: "tuple"
|
|
1180
|
+
}
|
|
1181
|
+
],
|
|
1182
|
+
stateMutability: "view",
|
|
1183
|
+
type: "function"
|
|
1184
|
+
},
|
|
1185
|
+
{
|
|
1186
|
+
inputs: [{ internalType: "bytes32", name: "currency", type: "bytes32" }],
|
|
1187
|
+
name: "getStakeBoostConfig",
|
|
1188
|
+
outputs: [
|
|
1189
|
+
{
|
|
1190
|
+
components: [
|
|
1191
|
+
{
|
|
1192
|
+
internalType: "uint256",
|
|
1193
|
+
name: "tokensPerUsdNumerator",
|
|
1194
|
+
type: "uint256"
|
|
1195
|
+
},
|
|
1196
|
+
{
|
|
1197
|
+
internalType: "uint256",
|
|
1198
|
+
name: "tokensPerUsdDenominator",
|
|
1199
|
+
type: "uint256"
|
|
1200
|
+
},
|
|
1201
|
+
{ internalType: "uint256", name: "maxBoostUsd", type: "uint256" }
|
|
1202
|
+
],
|
|
1203
|
+
internalType: "struct P2PStakeBoostStorage.BoostConfig",
|
|
1204
|
+
name: "",
|
|
1205
|
+
type: "tuple"
|
|
1206
|
+
}
|
|
1207
|
+
],
|
|
1208
|
+
stateMutability: "view",
|
|
1209
|
+
type: "function"
|
|
1210
|
+
},
|
|
1211
|
+
{
|
|
1212
|
+
inputs: [],
|
|
1213
|
+
name: "getStakeBoostGlobals",
|
|
1214
|
+
outputs: [
|
|
1215
|
+
{ internalType: "address", name: "p2pToken", type: "address" },
|
|
1216
|
+
{ internalType: "address", name: "fraudReserve", type: "address" },
|
|
1217
|
+
{ internalType: "uint256", name: "maxStakeTokens", type: "uint256" },
|
|
1218
|
+
{ internalType: "uint256", name: "normalCooldown", type: "uint256" },
|
|
1219
|
+
{ internalType: "uint256", name: "blacklistCooldown", type: "uint256" },
|
|
1220
|
+
{ internalType: "uint8", name: "tokenDecimals", type: "uint8" },
|
|
1221
|
+
{ internalType: "uint256", name: "totalStaked", type: "uint256" }
|
|
1222
|
+
],
|
|
1223
|
+
stateMutability: "view",
|
|
1224
|
+
type: "function"
|
|
1225
|
+
}
|
|
1226
|
+
];
|
|
1227
|
+
|
|
1130
1228
|
// src/contracts/abis/reputation-manager.ts
|
|
1131
1229
|
var reputationManagerAbi = [
|
|
1132
1230
|
{
|
|
@@ -1333,14 +1431,16 @@ var reputationManagerAbi = [
|
|
|
1333
1431
|
var DIAMOND_ABI = [
|
|
1334
1432
|
...orderFlowFacetAbi,
|
|
1335
1433
|
...orderProcessorFacetAbi,
|
|
1336
|
-
...p2pConfigFacetAbi
|
|
1434
|
+
...p2pConfigFacetAbi,
|
|
1435
|
+
...p2pStakeBoostFacetAbi
|
|
1337
1436
|
];
|
|
1338
1437
|
var ABIS = {
|
|
1339
1438
|
DIAMOND: DIAMOND_ABI,
|
|
1340
1439
|
FACETS: {
|
|
1341
1440
|
ORDER_FLOW: orderFlowFacetAbi,
|
|
1342
1441
|
ORDER_PROCESSOR: orderProcessorFacetAbi,
|
|
1343
|
-
CONFIG: p2pConfigFacetAbi
|
|
1442
|
+
CONFIG: p2pConfigFacetAbi,
|
|
1443
|
+
STAKE: p2pStakeBoostFacetAbi
|
|
1344
1444
|
},
|
|
1345
1445
|
EXTERNAL: {
|
|
1346
1446
|
USDC: erc20Abi,
|
|
@@ -3854,15 +3954,15 @@ function weierstrassPoints(opts) {
|
|
|
3854
3954
|
throw new Error("ProjectivePoint expected");
|
|
3855
3955
|
}
|
|
3856
3956
|
const toAffineMemo = memoized((p, iz) => {
|
|
3857
|
-
const { px: x, py: y, pz:
|
|
3858
|
-
if (Fp.eql(
|
|
3957
|
+
const { px: x, py: y, pz: z11 } = p;
|
|
3958
|
+
if (Fp.eql(z11, Fp.ONE))
|
|
3859
3959
|
return { x, y };
|
|
3860
3960
|
const is0 = p.is0();
|
|
3861
3961
|
if (iz == null)
|
|
3862
|
-
iz = is0 ? Fp.ONE : Fp.inv(
|
|
3962
|
+
iz = is0 ? Fp.ONE : Fp.inv(z11);
|
|
3863
3963
|
const ax = Fp.mul(x, iz);
|
|
3864
3964
|
const ay = Fp.mul(y, iz);
|
|
3865
|
-
const zz = Fp.mul(
|
|
3965
|
+
const zz = Fp.mul(z11, iz);
|
|
3866
3966
|
if (is0)
|
|
3867
3967
|
return { x: Fp.ZERO, y: Fp.ZERO };
|
|
3868
3968
|
if (!Fp.eql(zz, Fp.ONE))
|
|
@@ -4857,7 +4957,7 @@ function createSetSellOrderUpiAction(input) {
|
|
|
4857
4957
|
}
|
|
4858
4958
|
|
|
4859
4959
|
// src/orders/internal/routing/client.ts
|
|
4860
|
-
import { stringToHex as
|
|
4960
|
+
import { stringToHex as stringToHex7 } from "viem";
|
|
4861
4961
|
|
|
4862
4962
|
// src/contracts/errors.ts
|
|
4863
4963
|
var contractErrors = {
|
|
@@ -5449,6 +5549,128 @@ function getReputationPerUsdcLimit(publicClient, diamondAddress, params) {
|
|
|
5449
5549
|
);
|
|
5450
5550
|
}
|
|
5451
5551
|
|
|
5552
|
+
// src/contracts/p2p-stake/index.ts
|
|
5553
|
+
import { ResultAsync as ResultAsync9 } from "neverthrow";
|
|
5554
|
+
import { stringToHex as stringToHex5 } from "viem";
|
|
5555
|
+
|
|
5556
|
+
// src/stake/errors.ts
|
|
5557
|
+
var StakeError = class extends SdkError {
|
|
5558
|
+
constructor(message, options) {
|
|
5559
|
+
super(message, options);
|
|
5560
|
+
this.name = "StakeError";
|
|
5561
|
+
}
|
|
5562
|
+
};
|
|
5563
|
+
|
|
5564
|
+
// src/stake/validation.ts
|
|
5565
|
+
import { z as z8 } from "zod";
|
|
5566
|
+
var ZodGetUserStakeParamsSchema = z8.object({
|
|
5567
|
+
user: ZodAddressSchema
|
|
5568
|
+
});
|
|
5569
|
+
var ZodGetStakeBoostConfigParamsSchema = z8.object({
|
|
5570
|
+
currency: ZodCurrencySchema
|
|
5571
|
+
});
|
|
5572
|
+
var ZodGetP2pTokenBalanceParamsSchema = z8.object({
|
|
5573
|
+
address: ZodAddressSchema
|
|
5574
|
+
});
|
|
5575
|
+
var ZodStakeParamsSchema = z8.object({
|
|
5576
|
+
tokens: z8.bigint().positive()
|
|
5577
|
+
});
|
|
5578
|
+
var ZodTopUpParamsSchema = z8.object({
|
|
5579
|
+
tokens: z8.bigint().positive()
|
|
5580
|
+
});
|
|
5581
|
+
|
|
5582
|
+
// src/contracts/p2p-stake/index.ts
|
|
5583
|
+
function getUserStake(publicClient, diamondAddress, params) {
|
|
5584
|
+
return validate(
|
|
5585
|
+
ZodGetUserStakeParamsSchema,
|
|
5586
|
+
params,
|
|
5587
|
+
(message, cause, data) => new StakeError(message, {
|
|
5588
|
+
code: "VALIDATION_ERROR",
|
|
5589
|
+
cause,
|
|
5590
|
+
context: { params: data }
|
|
5591
|
+
})
|
|
5592
|
+
).asyncAndThen(
|
|
5593
|
+
(validated) => ResultAsync9.fromPromise(
|
|
5594
|
+
publicClient.readContract({
|
|
5595
|
+
address: diamondAddress,
|
|
5596
|
+
abi: ABIS.FACETS.STAKE,
|
|
5597
|
+
functionName: "getUserStake",
|
|
5598
|
+
args: [validated.user]
|
|
5599
|
+
}),
|
|
5600
|
+
(error) => new StakeError("Failed to read user stake", {
|
|
5601
|
+
code: "CONTRACT_READ_ERROR",
|
|
5602
|
+
cause: error,
|
|
5603
|
+
context: { user: validated.user, diamondAddress }
|
|
5604
|
+
})
|
|
5605
|
+
)
|
|
5606
|
+
);
|
|
5607
|
+
}
|
|
5608
|
+
function getStakeBoostConfig(publicClient, diamondAddress, params) {
|
|
5609
|
+
return validate(
|
|
5610
|
+
ZodGetStakeBoostConfigParamsSchema,
|
|
5611
|
+
params,
|
|
5612
|
+
(message, cause, data) => new StakeError(message, {
|
|
5613
|
+
code: "VALIDATION_ERROR",
|
|
5614
|
+
cause,
|
|
5615
|
+
context: { params: data }
|
|
5616
|
+
})
|
|
5617
|
+
).asyncAndThen(
|
|
5618
|
+
(validated) => ResultAsync9.fromPromise(
|
|
5619
|
+
publicClient.readContract({
|
|
5620
|
+
address: diamondAddress,
|
|
5621
|
+
abi: ABIS.FACETS.STAKE,
|
|
5622
|
+
functionName: "getStakeBoostConfig",
|
|
5623
|
+
args: [stringToHex5(validated.currency, { size: 32 })]
|
|
5624
|
+
}),
|
|
5625
|
+
(error) => new StakeError("Failed to read stake boost config", {
|
|
5626
|
+
code: "CONTRACT_READ_ERROR",
|
|
5627
|
+
cause: error,
|
|
5628
|
+
context: { currency: validated.currency, diamondAddress }
|
|
5629
|
+
})
|
|
5630
|
+
)
|
|
5631
|
+
);
|
|
5632
|
+
}
|
|
5633
|
+
function getStakeBoostGlobals(publicClient, diamondAddress) {
|
|
5634
|
+
return ResultAsync9.fromPromise(
|
|
5635
|
+
publicClient.readContract({
|
|
5636
|
+
address: diamondAddress,
|
|
5637
|
+
abi: ABIS.FACETS.STAKE,
|
|
5638
|
+
functionName: "getStakeBoostGlobals",
|
|
5639
|
+
args: []
|
|
5640
|
+
}),
|
|
5641
|
+
(error) => new StakeError("Failed to read stake boost globals", {
|
|
5642
|
+
code: "CONTRACT_READ_ERROR",
|
|
5643
|
+
cause: error,
|
|
5644
|
+
context: { diamondAddress }
|
|
5645
|
+
})
|
|
5646
|
+
);
|
|
5647
|
+
}
|
|
5648
|
+
function getP2pTokenBalance(publicClient, p2pTokenAddress, params) {
|
|
5649
|
+
return validate(
|
|
5650
|
+
ZodGetP2pTokenBalanceParamsSchema,
|
|
5651
|
+
params,
|
|
5652
|
+
(message, cause, data) => new StakeError(message, {
|
|
5653
|
+
code: "VALIDATION_ERROR",
|
|
5654
|
+
cause,
|
|
5655
|
+
context: { params: data }
|
|
5656
|
+
})
|
|
5657
|
+
).asyncAndThen(
|
|
5658
|
+
(validated) => ResultAsync9.fromPromise(
|
|
5659
|
+
publicClient.readContract({
|
|
5660
|
+
address: p2pTokenAddress,
|
|
5661
|
+
abi: ABIS.EXTERNAL.USDC,
|
|
5662
|
+
functionName: "balanceOf",
|
|
5663
|
+
args: [validated.address]
|
|
5664
|
+
}),
|
|
5665
|
+
(error) => new StakeError("Failed to read P2P token balance", {
|
|
5666
|
+
code: "CONTRACT_READ_ERROR",
|
|
5667
|
+
cause: error,
|
|
5668
|
+
context: { address: validated.address, p2pTokenAddress }
|
|
5669
|
+
})
|
|
5670
|
+
)
|
|
5671
|
+
);
|
|
5672
|
+
}
|
|
5673
|
+
|
|
5452
5674
|
// src/contracts/reputation-manager/writes.ts
|
|
5453
5675
|
import { Result as Result2 } from "neverthrow";
|
|
5454
5676
|
import { encodeFunctionData as encodeFunctionData7 } from "viem";
|
|
@@ -5462,75 +5684,75 @@ var ZkkycError = class extends SdkError {
|
|
|
5462
5684
|
};
|
|
5463
5685
|
|
|
5464
5686
|
// src/zkkyc/validation.ts
|
|
5465
|
-
import { z as
|
|
5466
|
-
var ZodAnonAadharProofParamsSchema =
|
|
5467
|
-
nullifierSeed:
|
|
5468
|
-
nullifier:
|
|
5469
|
-
timestamp:
|
|
5470
|
-
signal:
|
|
5471
|
-
revealArray:
|
|
5472
|
-
packedGroth16Proof:
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5687
|
+
import { z as z9 } from "zod";
|
|
5688
|
+
var ZodAnonAadharProofParamsSchema = z9.object({
|
|
5689
|
+
nullifierSeed: z9.bigint(),
|
|
5690
|
+
nullifier: z9.bigint(),
|
|
5691
|
+
timestamp: z9.bigint(),
|
|
5692
|
+
signal: z9.bigint(),
|
|
5693
|
+
revealArray: z9.tuple([z9.bigint(), z9.bigint(), z9.bigint(), z9.bigint()]),
|
|
5694
|
+
packedGroth16Proof: z9.tuple([
|
|
5695
|
+
z9.bigint(),
|
|
5696
|
+
z9.bigint(),
|
|
5697
|
+
z9.bigint(),
|
|
5698
|
+
z9.bigint(),
|
|
5699
|
+
z9.bigint(),
|
|
5700
|
+
z9.bigint(),
|
|
5701
|
+
z9.bigint(),
|
|
5702
|
+
z9.bigint()
|
|
5481
5703
|
])
|
|
5482
5704
|
});
|
|
5483
|
-
var ZodSocialVerifyParamsSchema =
|
|
5484
|
-
_socialName:
|
|
5485
|
-
proofs:
|
|
5486
|
-
|
|
5487
|
-
claimInfo:
|
|
5488
|
-
provider:
|
|
5489
|
-
parameters:
|
|
5490
|
-
context:
|
|
5705
|
+
var ZodSocialVerifyParamsSchema = z9.object({
|
|
5706
|
+
_socialName: z9.string(),
|
|
5707
|
+
proofs: z9.array(
|
|
5708
|
+
z9.object({
|
|
5709
|
+
claimInfo: z9.object({
|
|
5710
|
+
provider: z9.string(),
|
|
5711
|
+
parameters: z9.string(),
|
|
5712
|
+
context: z9.string()
|
|
5491
5713
|
}),
|
|
5492
|
-
signedClaim:
|
|
5493
|
-
claim:
|
|
5494
|
-
identifier:
|
|
5714
|
+
signedClaim: z9.object({
|
|
5715
|
+
claim: z9.object({
|
|
5716
|
+
identifier: z9.string(),
|
|
5495
5717
|
owner: ZodAddressSchema,
|
|
5496
|
-
timestampS:
|
|
5497
|
-
epoch:
|
|
5718
|
+
timestampS: z9.number(),
|
|
5719
|
+
epoch: z9.number()
|
|
5498
5720
|
}),
|
|
5499
|
-
signatures:
|
|
5721
|
+
signatures: z9.array(z9.string())
|
|
5500
5722
|
})
|
|
5501
5723
|
})
|
|
5502
5724
|
)
|
|
5503
5725
|
});
|
|
5504
|
-
var ZodSolidityVerifierParametersSchema =
|
|
5505
|
-
version:
|
|
5726
|
+
var ZodSolidityVerifierParametersSchema = z9.object({
|
|
5727
|
+
version: z9.string().refine((val) => val.startsWith("0x"), {
|
|
5506
5728
|
message: "Version must be a hex string"
|
|
5507
5729
|
}),
|
|
5508
|
-
proofVerificationData:
|
|
5509
|
-
vkeyHash:
|
|
5730
|
+
proofVerificationData: z9.object({
|
|
5731
|
+
vkeyHash: z9.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
|
|
5510
5732
|
message: "Invalid bytes32 hex string"
|
|
5511
5733
|
}),
|
|
5512
|
-
proof:
|
|
5734
|
+
proof: z9.string().refine((val) => val.startsWith("0x"), {
|
|
5513
5735
|
message: "Proof must be a hex string"
|
|
5514
5736
|
}),
|
|
5515
|
-
publicInputs:
|
|
5516
|
-
|
|
5737
|
+
publicInputs: z9.array(
|
|
5738
|
+
z9.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
|
|
5517
5739
|
message: "Each public input must be a valid bytes32 hex string"
|
|
5518
5740
|
})
|
|
5519
5741
|
)
|
|
5520
5742
|
}),
|
|
5521
|
-
committedInputs:
|
|
5743
|
+
committedInputs: z9.string().refine((val) => val.startsWith("0x"), {
|
|
5522
5744
|
message: "Committed inputs must be a hex string"
|
|
5523
5745
|
}),
|
|
5524
|
-
serviceConfig:
|
|
5525
|
-
validityPeriodInSeconds:
|
|
5526
|
-
domain:
|
|
5527
|
-
scope:
|
|
5528
|
-
devMode:
|
|
5746
|
+
serviceConfig: z9.object({
|
|
5747
|
+
validityPeriodInSeconds: z9.number().int().nonnegative(),
|
|
5748
|
+
domain: z9.string(),
|
|
5749
|
+
scope: z9.string(),
|
|
5750
|
+
devMode: z9.boolean()
|
|
5529
5751
|
})
|
|
5530
5752
|
});
|
|
5531
|
-
var ZodZkPassportRegisterParamsSchema =
|
|
5753
|
+
var ZodZkPassportRegisterParamsSchema = z9.object({
|
|
5532
5754
|
params: ZodSolidityVerifierParametersSchema,
|
|
5533
|
-
isIDCard:
|
|
5755
|
+
isIDCard: z9.boolean()
|
|
5534
5756
|
});
|
|
5535
5757
|
|
|
5536
5758
|
// src/contracts/reputation-manager/writes.ts
|
|
@@ -5640,8 +5862,8 @@ function prepareZkPassportRegister(reputationManagerAddress, params) {
|
|
|
5640
5862
|
}
|
|
5641
5863
|
|
|
5642
5864
|
// src/contracts/tx-limits/index.ts
|
|
5643
|
-
import { ResultAsync as
|
|
5644
|
-
import { formatUnits, stringToHex as
|
|
5865
|
+
import { ResultAsync as ResultAsync10 } from "neverthrow";
|
|
5866
|
+
import { formatUnits, stringToHex as stringToHex6 } from "viem";
|
|
5645
5867
|
|
|
5646
5868
|
// src/profile/errors.ts
|
|
5647
5869
|
var ProfileError = class extends SdkError {
|
|
@@ -5652,18 +5874,18 @@ var ProfileError = class extends SdkError {
|
|
|
5652
5874
|
};
|
|
5653
5875
|
|
|
5654
5876
|
// src/profile/validation.ts
|
|
5655
|
-
import { z as
|
|
5656
|
-
var ZodUsdcBalanceParamsSchema =
|
|
5877
|
+
import { z as z10 } from "zod";
|
|
5878
|
+
var ZodUsdcBalanceParamsSchema = z10.object({
|
|
5657
5879
|
address: ZodAddressSchema
|
|
5658
5880
|
});
|
|
5659
|
-
var ZodUsdcAllowanceParamsSchema =
|
|
5881
|
+
var ZodUsdcAllowanceParamsSchema = z10.object({
|
|
5660
5882
|
owner: ZodAddressSchema
|
|
5661
5883
|
});
|
|
5662
|
-
var ZodGetBalancesParamsSchema =
|
|
5884
|
+
var ZodGetBalancesParamsSchema = z10.object({
|
|
5663
5885
|
address: ZodAddressSchema,
|
|
5664
5886
|
currency: ZodCurrencySchema
|
|
5665
5887
|
});
|
|
5666
|
-
var ZodTxLimitsParamsSchema =
|
|
5888
|
+
var ZodTxLimitsParamsSchema = z10.object({
|
|
5667
5889
|
address: ZodAddressSchema,
|
|
5668
5890
|
currency: ZodCurrencySchema
|
|
5669
5891
|
});
|
|
@@ -5679,12 +5901,12 @@ function getTxLimits(publicClient, diamondAddress, params) {
|
|
|
5679
5901
|
context: { params: data }
|
|
5680
5902
|
})
|
|
5681
5903
|
).asyncAndThen(
|
|
5682
|
-
(validated) =>
|
|
5904
|
+
(validated) => ResultAsync10.fromPromise(
|
|
5683
5905
|
publicClient.readContract({
|
|
5684
5906
|
address: diamondAddress,
|
|
5685
5907
|
abi: ABIS.FACETS.ORDER_FLOW,
|
|
5686
5908
|
functionName: "userTxLimit",
|
|
5687
|
-
args: [validated.address,
|
|
5909
|
+
args: [validated.address, stringToHex6(validated.currency, { size: 32 })]
|
|
5688
5910
|
}),
|
|
5689
5911
|
(error) => new ProfileError("Failed to read tx limits", {
|
|
5690
5912
|
code: "CONTRACT_READ_ERROR",
|
|
@@ -5699,7 +5921,7 @@ function getTxLimits(publicClient, diamondAddress, params) {
|
|
|
5699
5921
|
}
|
|
5700
5922
|
|
|
5701
5923
|
// src/contracts/usdc/index.ts
|
|
5702
|
-
import { ResultAsync as
|
|
5924
|
+
import { ResultAsync as ResultAsync11 } from "neverthrow";
|
|
5703
5925
|
import { erc20Abi as erc20Abi3 } from "viem";
|
|
5704
5926
|
function getUsdcBalance(publicClient, usdcAddress, params) {
|
|
5705
5927
|
return validate(
|
|
@@ -5711,7 +5933,7 @@ function getUsdcBalance(publicClient, usdcAddress, params) {
|
|
|
5711
5933
|
context: { params: data }
|
|
5712
5934
|
})
|
|
5713
5935
|
).asyncAndThen(
|
|
5714
|
-
(validated) =>
|
|
5936
|
+
(validated) => ResultAsync11.fromPromise(
|
|
5715
5937
|
publicClient.readContract({
|
|
5716
5938
|
address: usdcAddress,
|
|
5717
5939
|
abi: ABIS.EXTERNAL.USDC,
|
|
@@ -5736,7 +5958,7 @@ function getUsdcAllowance(publicClient, usdcAddress, diamondAddress, params) {
|
|
|
5736
5958
|
context: { params: data }
|
|
5737
5959
|
})
|
|
5738
5960
|
).asyncAndThen(
|
|
5739
|
-
(validated) =>
|
|
5961
|
+
(validated) => ResultAsync11.fromPromise(
|
|
5740
5962
|
publicClient.readContract({
|
|
5741
5963
|
address: usdcAddress,
|
|
5742
5964
|
abi: erc20Abi3,
|
|
@@ -5928,7 +6150,7 @@ function createOrderRouter(config) {
|
|
|
5928
6150
|
const logger = config.logger ?? noopLogger;
|
|
5929
6151
|
return {
|
|
5930
6152
|
selectCircle(params) {
|
|
5931
|
-
const currencyHex =
|
|
6153
|
+
const currencyHex = stringToHex7(params.currency, { size: 32 });
|
|
5932
6154
|
logger.info("selectCircle started", {
|
|
5933
6155
|
currency: params.currency,
|
|
5934
6156
|
user: params.user,
|
|
@@ -6376,7 +6598,7 @@ function createPrices(config) {
|
|
|
6376
6598
|
}
|
|
6377
6599
|
|
|
6378
6600
|
// src/profile/contracts/actions.ts
|
|
6379
|
-
import { ResultAsync as
|
|
6601
|
+
import { ResultAsync as ResultAsync12 } from "neverthrow";
|
|
6380
6602
|
import { formatUnits as formatUnits2 } from "viem";
|
|
6381
6603
|
function getBalances(publicClient, usdcAddress, diamondAddress, params) {
|
|
6382
6604
|
return validate(
|
|
@@ -6388,7 +6610,7 @@ function getBalances(publicClient, usdcAddress, diamondAddress, params) {
|
|
|
6388
6610
|
context: { params: data }
|
|
6389
6611
|
})
|
|
6390
6612
|
).asyncAndThen(
|
|
6391
|
-
(validated) =>
|
|
6613
|
+
(validated) => ResultAsync12.combine([
|
|
6392
6614
|
getUsdcBalance(publicClient, usdcAddress, {
|
|
6393
6615
|
address: validated.address
|
|
6394
6616
|
}),
|
|
@@ -6424,6 +6646,252 @@ function createProfile(config) {
|
|
|
6424
6646
|
};
|
|
6425
6647
|
}
|
|
6426
6648
|
|
|
6649
|
+
// src/stake/actions/cancel-unstake.ts
|
|
6650
|
+
import { okAsync as okAsync6 } from "neverthrow";
|
|
6651
|
+
import { encodeFunctionData as encodeFunctionData8 } from "viem";
|
|
6652
|
+
|
|
6653
|
+
// src/stake/tx.ts
|
|
6654
|
+
import { errAsync as errAsync5, okAsync as okAsync5, ResultAsync as ResultAsync13 } from "neverthrow";
|
|
6655
|
+
function submitPreparedTx2(input) {
|
|
6656
|
+
const { prepared, walletClient, publicClient, waitForReceipt } = input;
|
|
6657
|
+
const account = walletClient.account;
|
|
6658
|
+
if (!account) {
|
|
6659
|
+
return errAsync5(
|
|
6660
|
+
new StakeError("WalletClient is missing an account", {
|
|
6661
|
+
code: "TX_SUBMISSION_FAILED"
|
|
6662
|
+
})
|
|
6663
|
+
);
|
|
6664
|
+
}
|
|
6665
|
+
const chain = walletClient.chain;
|
|
6666
|
+
return ResultAsync13.fromPromise(
|
|
6667
|
+
walletClient.sendTransaction({
|
|
6668
|
+
account,
|
|
6669
|
+
chain,
|
|
6670
|
+
to: prepared.to,
|
|
6671
|
+
data: prepared.data,
|
|
6672
|
+
value: prepared.value
|
|
6673
|
+
}),
|
|
6674
|
+
(cause) => new StakeError("walletClient.sendTransaction rejected", {
|
|
6675
|
+
code: "TX_SUBMISSION_FAILED",
|
|
6676
|
+
cause
|
|
6677
|
+
})
|
|
6678
|
+
).andThen((hash) => {
|
|
6679
|
+
if (!waitForReceipt) {
|
|
6680
|
+
return okAsync5({ hash });
|
|
6681
|
+
}
|
|
6682
|
+
return ResultAsync13.fromPromise(
|
|
6683
|
+
publicClient.waitForTransactionReceipt({ hash }),
|
|
6684
|
+
(cause) => new StakeError("waitForTransactionReceipt failed", {
|
|
6685
|
+
code: "RECEIPT_TIMEOUT",
|
|
6686
|
+
cause
|
|
6687
|
+
})
|
|
6688
|
+
).andThen((receipt) => {
|
|
6689
|
+
if (receipt.status !== "success") {
|
|
6690
|
+
return errAsync5(
|
|
6691
|
+
new StakeError("Transaction reverted", {
|
|
6692
|
+
code: "TX_REVERTED",
|
|
6693
|
+
context: { hash, blockNumber: receipt.blockNumber.toString() }
|
|
6694
|
+
})
|
|
6695
|
+
);
|
|
6696
|
+
}
|
|
6697
|
+
return okAsync5({ hash, receipt });
|
|
6698
|
+
});
|
|
6699
|
+
});
|
|
6700
|
+
}
|
|
6701
|
+
|
|
6702
|
+
// src/stake/actions/cancel-unstake.ts
|
|
6703
|
+
function createCancelUnstakeAction(input) {
|
|
6704
|
+
const { publicClient, diamondAddress } = input;
|
|
6705
|
+
const prepareFn = () => okAsync6({
|
|
6706
|
+
to: diamondAddress,
|
|
6707
|
+
data: encodeFunctionData8({
|
|
6708
|
+
abi: ABIS.FACETS.STAKE,
|
|
6709
|
+
functionName: "p2pBoostCancelUnstake",
|
|
6710
|
+
args: []
|
|
6711
|
+
}),
|
|
6712
|
+
value: 0n
|
|
6713
|
+
});
|
|
6714
|
+
return {
|
|
6715
|
+
prepare() {
|
|
6716
|
+
return prepareFn();
|
|
6717
|
+
},
|
|
6718
|
+
execute({ walletClient, waitForReceipt }) {
|
|
6719
|
+
return prepareFn().andThen(
|
|
6720
|
+
(prepared) => submitPreparedTx2({ prepared, walletClient, publicClient, waitForReceipt })
|
|
6721
|
+
);
|
|
6722
|
+
}
|
|
6723
|
+
};
|
|
6724
|
+
}
|
|
6725
|
+
|
|
6726
|
+
// src/stake/actions/claim-unstake.ts
|
|
6727
|
+
import { okAsync as okAsync7 } from "neverthrow";
|
|
6728
|
+
import { encodeFunctionData as encodeFunctionData9 } from "viem";
|
|
6729
|
+
function createClaimUnstakeAction(input) {
|
|
6730
|
+
const { publicClient, diamondAddress } = input;
|
|
6731
|
+
const prepareFn = () => okAsync7({
|
|
6732
|
+
to: diamondAddress,
|
|
6733
|
+
data: encodeFunctionData9({
|
|
6734
|
+
abi: ABIS.FACETS.STAKE,
|
|
6735
|
+
functionName: "p2pBoostClaimUnstake",
|
|
6736
|
+
args: []
|
|
6737
|
+
}),
|
|
6738
|
+
value: 0n
|
|
6739
|
+
});
|
|
6740
|
+
return {
|
|
6741
|
+
prepare() {
|
|
6742
|
+
return prepareFn();
|
|
6743
|
+
},
|
|
6744
|
+
execute({ walletClient, waitForReceipt }) {
|
|
6745
|
+
return prepareFn().andThen(
|
|
6746
|
+
(prepared) => submitPreparedTx2({ prepared, walletClient, publicClient, waitForReceipt })
|
|
6747
|
+
);
|
|
6748
|
+
}
|
|
6749
|
+
};
|
|
6750
|
+
}
|
|
6751
|
+
|
|
6752
|
+
// src/stake/actions/request-unstake.ts
|
|
6753
|
+
import { okAsync as okAsync8 } from "neverthrow";
|
|
6754
|
+
import { encodeFunctionData as encodeFunctionData10 } from "viem";
|
|
6755
|
+
function createRequestUnstakeAction(input) {
|
|
6756
|
+
const { publicClient, diamondAddress } = input;
|
|
6757
|
+
const prepareFn = () => okAsync8({
|
|
6758
|
+
to: diamondAddress,
|
|
6759
|
+
data: encodeFunctionData10({
|
|
6760
|
+
abi: ABIS.FACETS.STAKE,
|
|
6761
|
+
functionName: "p2pBoostRequestUnstake",
|
|
6762
|
+
args: []
|
|
6763
|
+
}),
|
|
6764
|
+
value: 0n
|
|
6765
|
+
});
|
|
6766
|
+
return {
|
|
6767
|
+
prepare() {
|
|
6768
|
+
return prepareFn();
|
|
6769
|
+
},
|
|
6770
|
+
execute({ walletClient, waitForReceipt }) {
|
|
6771
|
+
return prepareFn().andThen(
|
|
6772
|
+
(prepared) => submitPreparedTx2({ prepared, walletClient, publicClient, waitForReceipt })
|
|
6773
|
+
);
|
|
6774
|
+
}
|
|
6775
|
+
};
|
|
6776
|
+
}
|
|
6777
|
+
|
|
6778
|
+
// src/stake/actions/stake.ts
|
|
6779
|
+
import { encodeFunctionData as encodeFunctionData11 } from "viem";
|
|
6780
|
+
function createStakeAction(input) {
|
|
6781
|
+
const { publicClient, diamondAddress } = input;
|
|
6782
|
+
const prepareFn = (params) => validate(
|
|
6783
|
+
ZodStakeParamsSchema,
|
|
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: "p2pBoostStake",
|
|
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/actions/top-up.ts
|
|
6812
|
+
import { encodeFunctionData as encodeFunctionData12 } from "viem";
|
|
6813
|
+
function createTopUpAction(input) {
|
|
6814
|
+
const { publicClient, diamondAddress } = input;
|
|
6815
|
+
const prepareFn = (params) => validate(
|
|
6816
|
+
ZodTopUpParamsSchema,
|
|
6817
|
+
params,
|
|
6818
|
+
(message, cause, data) => new StakeError(message, {
|
|
6819
|
+
code: "VALIDATION_ERROR",
|
|
6820
|
+
cause,
|
|
6821
|
+
context: { data }
|
|
6822
|
+
})
|
|
6823
|
+
).map(({ tokens }) => ({
|
|
6824
|
+
to: diamondAddress,
|
|
6825
|
+
data: encodeFunctionData12({
|
|
6826
|
+
abi: ABIS.FACETS.STAKE,
|
|
6827
|
+
functionName: "p2pBoostTopUp",
|
|
6828
|
+
args: [tokens]
|
|
6829
|
+
}),
|
|
6830
|
+
value: 0n
|
|
6831
|
+
}));
|
|
6832
|
+
return {
|
|
6833
|
+
prepare(params) {
|
|
6834
|
+
return prepareFn(params).asyncMap(async (tx) => tx);
|
|
6835
|
+
},
|
|
6836
|
+
execute({ walletClient, waitForReceipt, ...params }) {
|
|
6837
|
+
return prepareFn(params).asyncAndThen(
|
|
6838
|
+
(prepared) => submitPreparedTx2({ prepared, walletClient, publicClient, waitForReceipt })
|
|
6839
|
+
);
|
|
6840
|
+
}
|
|
6841
|
+
};
|
|
6842
|
+
}
|
|
6843
|
+
|
|
6844
|
+
// src/stake/normalize.ts
|
|
6845
|
+
var STATUS_MAP = {
|
|
6846
|
+
0: "none",
|
|
6847
|
+
1: "active",
|
|
6848
|
+
2: "cooldown",
|
|
6849
|
+
3: "seized"
|
|
6850
|
+
};
|
|
6851
|
+
function normalizeUserStake(raw) {
|
|
6852
|
+
return {
|
|
6853
|
+
stakedAmount: raw.stakedAmount,
|
|
6854
|
+
cooldownEnd: raw.cooldownEnd,
|
|
6855
|
+
status: STATUS_MAP[raw.status] ?? "none"
|
|
6856
|
+
};
|
|
6857
|
+
}
|
|
6858
|
+
function normalizeStakeBoostGlobals(raw) {
|
|
6859
|
+
const [
|
|
6860
|
+
p2pToken,
|
|
6861
|
+
fraudReserve,
|
|
6862
|
+
maxStakeTokens,
|
|
6863
|
+
normalCooldown,
|
|
6864
|
+
blacklistCooldown,
|
|
6865
|
+
tokenDecimals,
|
|
6866
|
+
totalStaked
|
|
6867
|
+
] = raw;
|
|
6868
|
+
return {
|
|
6869
|
+
p2pToken,
|
|
6870
|
+
fraudReserve,
|
|
6871
|
+
maxStakeTokens,
|
|
6872
|
+
normalCooldown,
|
|
6873
|
+
blacklistCooldown,
|
|
6874
|
+
tokenDecimals,
|
|
6875
|
+
totalStaked
|
|
6876
|
+
};
|
|
6877
|
+
}
|
|
6878
|
+
|
|
6879
|
+
// src/stake/client.ts
|
|
6880
|
+
function createStake(config) {
|
|
6881
|
+
const { publicClient, diamondAddress, p2pTokenAddress } = config;
|
|
6882
|
+
return {
|
|
6883
|
+
getUserStake: (params) => getUserStake(publicClient, diamondAddress, params).map(normalizeUserStake),
|
|
6884
|
+
getStakeBoostConfig: (params) => getStakeBoostConfig(publicClient, diamondAddress, params),
|
|
6885
|
+
getStakeBoostGlobals: () => getStakeBoostGlobals(publicClient, diamondAddress).map(normalizeStakeBoostGlobals),
|
|
6886
|
+
getP2pTokenBalance: (params) => getP2pTokenBalance(publicClient, p2pTokenAddress, params),
|
|
6887
|
+
stake: createStakeAction({ publicClient, diamondAddress }),
|
|
6888
|
+
topUp: createTopUpAction({ publicClient, diamondAddress }),
|
|
6889
|
+
requestUnstake: createRequestUnstakeAction({ publicClient, diamondAddress }),
|
|
6890
|
+
cancelUnstake: createCancelUnstakeAction({ publicClient, diamondAddress }),
|
|
6891
|
+
claimUnstake: createClaimUnstakeAction({ publicClient, diamondAddress })
|
|
6892
|
+
};
|
|
6893
|
+
}
|
|
6894
|
+
|
|
6427
6895
|
// src/zkkyc/client.ts
|
|
6428
6896
|
function createZkkyc(config) {
|
|
6429
6897
|
const { reputationManagerAddress } = config;
|
|
@@ -6483,6 +6951,11 @@ function SdkProvider({ children, ...config }) {
|
|
|
6483
6951
|
relayIdentity,
|
|
6484
6952
|
logger
|
|
6485
6953
|
}),
|
|
6954
|
+
stake: createStake({
|
|
6955
|
+
publicClient,
|
|
6956
|
+
diamondAddress: config.diamondAddress,
|
|
6957
|
+
p2pTokenAddress: config.p2pTokenAddress
|
|
6958
|
+
}),
|
|
6486
6959
|
zkkyc: config.reputationManagerAddress ? createZkkyc({
|
|
6487
6960
|
reputationManagerAddress: config.reputationManagerAddress
|
|
6488
6961
|
}) : void 0,
|
|
@@ -6493,6 +6966,7 @@ function SdkProvider({ children, ...config }) {
|
|
|
6493
6966
|
config.subgraphUrl,
|
|
6494
6967
|
config.diamondAddress,
|
|
6495
6968
|
config.usdcAddress,
|
|
6969
|
+
config.p2pTokenAddress,
|
|
6496
6970
|
config.reputationManagerAddress,
|
|
6497
6971
|
relayIdentityStore,
|
|
6498
6972
|
relayIdentity,
|
|
@@ -6517,6 +6991,9 @@ function usePrices() {
|
|
|
6517
6991
|
function useOrders() {
|
|
6518
6992
|
return useSdk().orders;
|
|
6519
6993
|
}
|
|
6994
|
+
function useStake() {
|
|
6995
|
+
return useSdk().stake;
|
|
6996
|
+
}
|
|
6520
6997
|
function useZkkyc() {
|
|
6521
6998
|
const zkkyc = useSdk().zkkyc;
|
|
6522
6999
|
if (!zkkyc) {
|
|
@@ -6592,6 +7069,7 @@ export {
|
|
|
6592
7069
|
usePrices,
|
|
6593
7070
|
useProfile,
|
|
6594
7071
|
useSdk,
|
|
7072
|
+
useStake,
|
|
6595
7073
|
useWatchOrders,
|
|
6596
7074
|
useZkkyc
|
|
6597
7075
|
};
|