@p2pdotme/sdk 1.1.7 → 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/stake.mjs ADDED
@@ -0,0 +1,1184 @@
1
+ // src/contracts/p2p-stake/index.ts
2
+ import { ResultAsync } from "neverthrow";
3
+ import { stringToHex } from "viem";
4
+
5
+ // src/validation/errors.validation.ts
6
+ var SdkError = class extends Error {
7
+ code;
8
+ cause;
9
+ context;
10
+ constructor(message, options) {
11
+ super(message);
12
+ this.name = "SdkError";
13
+ this.code = options.code;
14
+ this.cause = options.cause;
15
+ this.context = options.context;
16
+ }
17
+ };
18
+
19
+ // src/validation/schemas.validation.ts
20
+ import { err, ok } from "neverthrow";
21
+ import { isAddress } from "viem";
22
+ import { z } from "zod";
23
+
24
+ // src/country/currency.ts
25
+ var CURRENCY = {
26
+ IDR: "IDR",
27
+ INR: "INR",
28
+ BRL: "BRL",
29
+ ARS: "ARS",
30
+ MEX: "MEX",
31
+ VEN: "VEN",
32
+ EUR: "EUR",
33
+ NGN: "NGN",
34
+ USD: "USD",
35
+ COP: "COP"
36
+ };
37
+ var CURRENCY_CODES = Object.values(CURRENCY);
38
+
39
+ // src/validation/schemas.validation.ts
40
+ var ZodAddressSchema = z.string().refine((s) => isAddress(s), { message: "Invalid Ethereum address" });
41
+ var ZodCurrencySchema = z.enum(CURRENCY_CODES);
42
+ function validate(schema, data, toError) {
43
+ const result = schema.safeParse(data);
44
+ if (result.success) {
45
+ return ok(result.data);
46
+ }
47
+ return err(toError(z.prettifyError(result.error), result.error, data));
48
+ }
49
+
50
+ // src/stake/errors.ts
51
+ var StakeError = class extends SdkError {
52
+ constructor(message, options) {
53
+ super(message, options);
54
+ this.name = "StakeError";
55
+ }
56
+ };
57
+
58
+ // src/stake/validation.ts
59
+ import { z as z2 } from "zod";
60
+ var ZodGetUserStakeParamsSchema = z2.object({
61
+ user: ZodAddressSchema
62
+ });
63
+ var ZodGetStakeBoostConfigParamsSchema = z2.object({
64
+ currency: ZodCurrencySchema
65
+ });
66
+ var ZodGetP2pTokenBalanceParamsSchema = z2.object({
67
+ address: ZodAddressSchema
68
+ });
69
+ var ZodStakeParamsSchema = z2.object({
70
+ tokens: z2.bigint().positive()
71
+ });
72
+ var ZodTopUpParamsSchema = z2.object({
73
+ tokens: z2.bigint().positive()
74
+ });
75
+
76
+ // src/contracts/abis/index.ts
77
+ import { erc20Abi } from "viem";
78
+
79
+ // src/contracts/abis/order-flow-facet.ts
80
+ var orderFlowFacetAbi = [
81
+ {
82
+ inputs: [
83
+ { internalType: "uint256", name: "circleId", type: "uint256" },
84
+ { internalType: "uint256", name: "assignUpto", type: "uint256" },
85
+ { internalType: "bytes32", name: "currency", type: "bytes32" },
86
+ { internalType: "address", name: "user", type: "address" },
87
+ { internalType: "uint256", name: "usdtAmount", type: "uint256" },
88
+ { internalType: "uint256", name: "fiatAmount", type: "uint256" },
89
+ { internalType: "int256", name: "orderType", type: "int256" },
90
+ { internalType: "uint256", name: "preferredPCConfigId", type: "uint256" }
91
+ ],
92
+ name: "getAssignableMerchantsFromCircle",
93
+ outputs: [{ internalType: "address[]", name: "", type: "address[]" }],
94
+ stateMutability: "view",
95
+ type: "function"
96
+ },
97
+ {
98
+ inputs: [
99
+ { internalType: "address", name: "_user", type: "address" },
100
+ { internalType: "bytes32", name: "_nativeCurrency", type: "bytes32" }
101
+ ],
102
+ name: "userTxLimit",
103
+ outputs: [
104
+ { internalType: "uint256", name: "", type: "uint256" },
105
+ { internalType: "uint256", name: "", type: "uint256" }
106
+ ],
107
+ stateMutability: "view",
108
+ type: "function"
109
+ },
110
+ {
111
+ inputs: [
112
+ { internalType: "string", name: "_pubKey", type: "string" },
113
+ { internalType: "uint256", name: "_amount", type: "uint256" },
114
+ { internalType: "address", name: "_recipientAddr", type: "address" },
115
+ { internalType: "uint8", name: "_orderType", type: "uint8" },
116
+ { internalType: "string", name: "_userUpi", type: "string" },
117
+ { internalType: "string", name: "_userPubKey", type: "string" },
118
+ { internalType: "bytes32", name: "_currency", type: "bytes32" },
119
+ { internalType: "uint256", name: "preferredPaymentChannelConfigId", type: "uint256" },
120
+ { internalType: "uint256", name: "_circleId", type: "uint256" },
121
+ { internalType: "uint256", name: "_fiatAmountLimit", type: "uint256" }
122
+ ],
123
+ name: "placeOrder",
124
+ outputs: [],
125
+ stateMutability: "nonpayable",
126
+ type: "function"
127
+ },
128
+ {
129
+ inputs: [{ internalType: "uint256", name: "_orderId", type: "uint256" }],
130
+ name: "cancelOrder",
131
+ outputs: [],
132
+ stateMutability: "nonpayable",
133
+ type: "function"
134
+ },
135
+ {
136
+ inputs: [
137
+ { internalType: "uint256", name: "_orderId", type: "uint256" },
138
+ { internalType: "string", name: "_userEncUpi", type: "string" },
139
+ { internalType: "uint256", name: "_updatedAmount", type: "uint256" }
140
+ ],
141
+ name: "setSellOrderUpi",
142
+ outputs: [],
143
+ stateMutability: "nonpayable",
144
+ type: "function"
145
+ },
146
+ {
147
+ type: "event",
148
+ name: "OrderPlaced",
149
+ anonymous: false,
150
+ inputs: [
151
+ { indexed: true, name: "orderId", type: "uint256" },
152
+ { indexed: true, name: "user", type: "address" },
153
+ { indexed: true, name: "merchant", type: "address" },
154
+ { indexed: false, name: "amount", type: "uint256" },
155
+ { indexed: false, name: "orderType", type: "uint8" },
156
+ { indexed: false, name: "placedTimestamp", type: "uint256" },
157
+ {
158
+ indexed: false,
159
+ name: "_order",
160
+ type: "tuple",
161
+ components: [
162
+ { name: "amount", type: "uint256" },
163
+ { name: "fiatAmount", type: "uint256" },
164
+ { name: "placedTimestamp", type: "uint256" },
165
+ { name: "completedTimestamp", type: "uint256" },
166
+ { name: "userCompletedTimestamp", type: "uint256" },
167
+ { name: "acceptedMerchant", type: "address" },
168
+ { name: "user", type: "address" },
169
+ { name: "recipientAddr", type: "address" },
170
+ { name: "pubkey", type: "string" },
171
+ { name: "encUpi", type: "string" },
172
+ { name: "userCompleted", type: "bool" },
173
+ { name: "status", type: "uint8" },
174
+ { name: "orderType", type: "uint8" },
175
+ {
176
+ name: "disputeInfo",
177
+ type: "tuple",
178
+ components: [
179
+ { name: "raisedBy", type: "uint8" },
180
+ { name: "status", type: "uint8" },
181
+ { name: "redactTransId", type: "uint256" },
182
+ { name: "accountNumber", type: "uint256" }
183
+ ]
184
+ },
185
+ { name: "id", type: "uint256" },
186
+ { name: "userPubKey", type: "string" },
187
+ { name: "encMerchantUpi", type: "string" },
188
+ { name: "acceptedAccountNo", type: "uint256" },
189
+ { name: "assignedAccountNos", type: "uint256[]" },
190
+ { name: "currency", type: "bytes32" },
191
+ { name: "preferredPaymentChannelConfigId", type: "uint256" },
192
+ { name: "circleId", type: "uint256" }
193
+ ]
194
+ }
195
+ ]
196
+ },
197
+ {
198
+ type: "event",
199
+ name: "OrderAccepted",
200
+ anonymous: false,
201
+ inputs: [
202
+ { indexed: true, name: "orderId", type: "uint256" },
203
+ { indexed: true, name: "merchant", type: "address" },
204
+ { indexed: false, name: "pubKey", type: "string" },
205
+ {
206
+ indexed: false,
207
+ name: "_order",
208
+ type: "tuple",
209
+ components: [
210
+ { name: "amount", type: "uint256" },
211
+ { name: "fiatAmount", type: "uint256" },
212
+ { name: "placedTimestamp", type: "uint256" },
213
+ { name: "completedTimestamp", type: "uint256" },
214
+ { name: "userCompletedTimestamp", type: "uint256" },
215
+ { name: "acceptedMerchant", type: "address" },
216
+ { name: "user", type: "address" },
217
+ { name: "recipientAddr", type: "address" },
218
+ { name: "pubkey", type: "string" },
219
+ { name: "encUpi", type: "string" },
220
+ { name: "userCompleted", type: "bool" },
221
+ { name: "status", type: "uint8" },
222
+ { name: "orderType", type: "uint8" },
223
+ {
224
+ name: "disputeInfo",
225
+ type: "tuple",
226
+ components: [
227
+ { name: "raisedBy", type: "uint8" },
228
+ { name: "status", type: "uint8" },
229
+ { name: "redactTransId", type: "uint256" },
230
+ { name: "accountNumber", type: "uint256" }
231
+ ]
232
+ },
233
+ { name: "id", type: "uint256" },
234
+ { name: "userPubKey", type: "string" },
235
+ { name: "encMerchantUpi", type: "string" },
236
+ { name: "acceptedAccountNo", type: "uint256" },
237
+ { name: "assignedAccountNos", type: "uint256[]" },
238
+ { name: "currency", type: "bytes32" },
239
+ { name: "preferredPaymentChannelConfigId", type: "uint256" },
240
+ { name: "circleId", type: "uint256" }
241
+ ]
242
+ }
243
+ ]
244
+ },
245
+ {
246
+ type: "event",
247
+ name: "BuyOrderPaid",
248
+ anonymous: false,
249
+ inputs: [
250
+ { indexed: true, name: "orderId", type: "uint256" },
251
+ { indexed: true, name: "user", type: "address" },
252
+ {
253
+ indexed: false,
254
+ name: "_order",
255
+ type: "tuple",
256
+ components: [
257
+ { name: "amount", type: "uint256" },
258
+ { name: "fiatAmount", type: "uint256" },
259
+ { name: "placedTimestamp", type: "uint256" },
260
+ { name: "completedTimestamp", type: "uint256" },
261
+ { name: "userCompletedTimestamp", type: "uint256" },
262
+ { name: "acceptedMerchant", type: "address" },
263
+ { name: "user", type: "address" },
264
+ { name: "recipientAddr", type: "address" },
265
+ { name: "pubkey", type: "string" },
266
+ { name: "encUpi", type: "string" },
267
+ { name: "userCompleted", type: "bool" },
268
+ { name: "status", type: "uint8" },
269
+ { name: "orderType", type: "uint8" },
270
+ {
271
+ name: "disputeInfo",
272
+ type: "tuple",
273
+ components: [
274
+ { name: "raisedBy", type: "uint8" },
275
+ { name: "status", type: "uint8" },
276
+ { name: "redactTransId", type: "uint256" },
277
+ { name: "accountNumber", type: "uint256" }
278
+ ]
279
+ },
280
+ { name: "id", type: "uint256" },
281
+ { name: "userPubKey", type: "string" },
282
+ { name: "encMerchantUpi", type: "string" },
283
+ { name: "acceptedAccountNo", type: "uint256" },
284
+ { name: "assignedAccountNos", type: "uint256[]" },
285
+ { name: "currency", type: "bytes32" },
286
+ { name: "preferredPaymentChannelConfigId", type: "uint256" },
287
+ { name: "circleId", type: "uint256" }
288
+ ]
289
+ }
290
+ ]
291
+ },
292
+ {
293
+ type: "event",
294
+ name: "OrderCompleted",
295
+ anonymous: false,
296
+ inputs: [
297
+ { indexed: true, name: "orderId", type: "uint256" },
298
+ { indexed: true, name: "user", type: "address" },
299
+ { indexed: false, name: "completedTimestamp", type: "uint256" },
300
+ {
301
+ indexed: false,
302
+ name: "_order",
303
+ type: "tuple",
304
+ components: [
305
+ { name: "amount", type: "uint256" },
306
+ { name: "fiatAmount", type: "uint256" },
307
+ { name: "placedTimestamp", type: "uint256" },
308
+ { name: "completedTimestamp", type: "uint256" },
309
+ { name: "userCompletedTimestamp", type: "uint256" },
310
+ { name: "acceptedMerchant", type: "address" },
311
+ { name: "user", type: "address" },
312
+ { name: "recipientAddr", type: "address" },
313
+ { name: "pubkey", type: "string" },
314
+ { name: "encUpi", type: "string" },
315
+ { name: "userCompleted", type: "bool" },
316
+ { name: "status", type: "uint8" },
317
+ { name: "orderType", type: "uint8" },
318
+ {
319
+ name: "disputeInfo",
320
+ type: "tuple",
321
+ components: [
322
+ { name: "raisedBy", type: "uint8" },
323
+ { name: "status", type: "uint8" },
324
+ { name: "redactTransId", type: "uint256" },
325
+ { name: "accountNumber", type: "uint256" }
326
+ ]
327
+ },
328
+ { name: "id", type: "uint256" },
329
+ { name: "userPubKey", type: "string" },
330
+ { name: "encMerchantUpi", type: "string" },
331
+ { name: "acceptedAccountNo", type: "uint256" },
332
+ { name: "assignedAccountNos", type: "uint256[]" },
333
+ { name: "currency", type: "bytes32" },
334
+ { name: "preferredPaymentChannelConfigId", type: "uint256" },
335
+ { name: "circleId", type: "uint256" }
336
+ ]
337
+ }
338
+ ]
339
+ },
340
+ {
341
+ type: "event",
342
+ name: "CancelledOrders",
343
+ anonymous: false,
344
+ inputs: [
345
+ { indexed: true, name: "orderId", type: "uint256" },
346
+ {
347
+ indexed: false,
348
+ name: "_order",
349
+ type: "tuple",
350
+ components: [
351
+ { name: "amount", type: "uint256" },
352
+ { name: "fiatAmount", type: "uint256" },
353
+ { name: "placedTimestamp", type: "uint256" },
354
+ { name: "completedTimestamp", type: "uint256" },
355
+ { name: "userCompletedTimestamp", type: "uint256" },
356
+ { name: "acceptedMerchant", type: "address" },
357
+ { name: "user", type: "address" },
358
+ { name: "recipientAddr", type: "address" },
359
+ { name: "pubkey", type: "string" },
360
+ { name: "encUpi", type: "string" },
361
+ { name: "userCompleted", type: "bool" },
362
+ { name: "status", type: "uint8" },
363
+ { name: "orderType", type: "uint8" },
364
+ {
365
+ name: "disputeInfo",
366
+ type: "tuple",
367
+ components: [
368
+ { name: "raisedBy", type: "uint8" },
369
+ { name: "status", type: "uint8" },
370
+ { name: "redactTransId", type: "uint256" },
371
+ { name: "accountNumber", type: "uint256" }
372
+ ]
373
+ },
374
+ { name: "id", type: "uint256" },
375
+ { name: "userPubKey", type: "string" },
376
+ { name: "encMerchantUpi", type: "string" },
377
+ { name: "acceptedAccountNo", type: "uint256" },
378
+ { name: "assignedAccountNos", type: "uint256[]" },
379
+ { name: "currency", type: "bytes32" },
380
+ { name: "preferredPaymentChannelConfigId", type: "uint256" },
381
+ { name: "circleId", type: "uint256" }
382
+ ]
383
+ }
384
+ ]
385
+ }
386
+ ];
387
+
388
+ // src/contracts/abis/order-processor-facet.ts
389
+ var orderProcessorFacetAbi = [
390
+ {
391
+ type: "function",
392
+ name: "getOrdersById",
393
+ stateMutability: "view",
394
+ inputs: [{ name: "orderId", type: "uint256" }],
395
+ outputs: [
396
+ {
397
+ type: "tuple",
398
+ components: [
399
+ { name: "amount", type: "uint256" },
400
+ { name: "fiatAmount", type: "uint256" },
401
+ { name: "placedTimestamp", type: "uint256" },
402
+ { name: "completedTimestamp", type: "uint256" },
403
+ { name: "userCompletedTimestamp", type: "uint256" },
404
+ { name: "acceptedMerchant", type: "address" },
405
+ { name: "user", type: "address" },
406
+ { name: "recipientAddr", type: "address" },
407
+ { name: "pubkey", type: "string" },
408
+ { name: "encUpi", type: "string" },
409
+ { name: "userCompleted", type: "bool" },
410
+ { name: "status", type: "uint8" },
411
+ { name: "orderType", type: "uint8" },
412
+ {
413
+ name: "disputeInfo",
414
+ type: "tuple",
415
+ components: [
416
+ { name: "raisedBy", type: "uint8" },
417
+ { name: "status", type: "uint8" },
418
+ { name: "redactTransId", type: "uint256" },
419
+ { name: "accountNumber", type: "uint256" }
420
+ ]
421
+ },
422
+ { name: "id", type: "uint256" },
423
+ { name: "userPubKey", type: "string" },
424
+ { name: "encMerchantUpi", type: "string" },
425
+ { name: "acceptedAccountNo", type: "uint256" },
426
+ { name: "assignedAccountNos", type: "uint256[]" },
427
+ { name: "currency", type: "bytes32" },
428
+ { name: "preferredPaymentChannelConfigId", type: "uint256" },
429
+ { name: "circleId", type: "uint256" }
430
+ ]
431
+ }
432
+ ]
433
+ },
434
+ {
435
+ type: "function",
436
+ name: "getAdditionalOrderDetails",
437
+ stateMutability: "view",
438
+ inputs: [{ name: "orderId", type: "uint256" }],
439
+ outputs: [
440
+ {
441
+ type: "tuple",
442
+ components: [
443
+ { name: "fixedFeePaid", type: "uint64" },
444
+ { name: "tipsPaid", type: "uint64" },
445
+ { name: "acceptedTimestamp", type: "uint128" },
446
+ { name: "paidTimestamp", type: "uint128" },
447
+ { name: "reserved2", type: "uint128" },
448
+ { name: "actualUsdtAmount", type: "uint256" },
449
+ { name: "actualFiatAmount", type: "uint256" }
450
+ ]
451
+ }
452
+ ]
453
+ },
454
+ {
455
+ type: "function",
456
+ name: "getSmallOrderThreshold",
457
+ stateMutability: "view",
458
+ inputs: [{ name: "currency", type: "bytes32" }],
459
+ outputs: [{ name: "", type: "uint256" }]
460
+ },
461
+ {
462
+ type: "function",
463
+ name: "getSmallOrderFixedFee",
464
+ stateMutability: "view",
465
+ inputs: [{ name: "currency", type: "bytes32" }],
466
+ outputs: [{ name: "", type: "uint256" }]
467
+ },
468
+ {
469
+ type: "function",
470
+ name: "raiseDispute",
471
+ stateMutability: "nonpayable",
472
+ inputs: [
473
+ { name: "_orderId", type: "uint256" },
474
+ { name: "redactTransId", type: "uint256" }
475
+ ],
476
+ outputs: []
477
+ },
478
+ {
479
+ type: "function",
480
+ name: "paidBuyOrder",
481
+ stateMutability: "nonpayable",
482
+ inputs: [{ name: "_orderId", type: "uint256" }],
483
+ outputs: []
484
+ }
485
+ ];
486
+
487
+ // src/contracts/abis/p2p-config-facet.ts
488
+ var p2pConfigFacetAbi = [
489
+ {
490
+ inputs: [
491
+ {
492
+ internalType: "bytes32",
493
+ name: "_currency",
494
+ type: "bytes32"
495
+ }
496
+ ],
497
+ name: "getPriceConfig",
498
+ outputs: [
499
+ {
500
+ components: [
501
+ {
502
+ internalType: "uint256",
503
+ name: "buyPrice",
504
+ type: "uint256"
505
+ },
506
+ {
507
+ internalType: "uint256",
508
+ name: "sellPrice",
509
+ type: "uint256"
510
+ },
511
+ {
512
+ internalType: "int256",
513
+ name: "buyPriceOffset",
514
+ type: "int256"
515
+ },
516
+ {
517
+ internalType: "uint256",
518
+ name: "baseSpread",
519
+ type: "uint256"
520
+ }
521
+ ],
522
+ internalType: "struct P2pConfigStorage.PriceConfig",
523
+ name: "",
524
+ type: "tuple"
525
+ }
526
+ ],
527
+ stateMutability: "view",
528
+ type: "function"
529
+ },
530
+ {
531
+ inputs: [
532
+ {
533
+ internalType: "bytes32",
534
+ name: "_nativeCurrency",
535
+ type: "bytes32"
536
+ }
537
+ ],
538
+ name: "getRpPerUsdtLimitRational",
539
+ outputs: [
540
+ {
541
+ internalType: "uint256",
542
+ name: "numerator",
543
+ type: "uint256"
544
+ },
545
+ {
546
+ internalType: "uint256",
547
+ name: "denominator",
548
+ type: "uint256"
549
+ }
550
+ ],
551
+ stateMutability: "view",
552
+ type: "function"
553
+ }
554
+ ];
555
+
556
+ // src/contracts/abis/p2p-stake-boost-facet.ts
557
+ var p2pStakeBoostFacetAbi = [
558
+ {
559
+ inputs: [{ internalType: "uint256", name: "tokens", type: "uint256" }],
560
+ name: "p2pBoostStake",
561
+ outputs: [],
562
+ stateMutability: "nonpayable",
563
+ type: "function"
564
+ },
565
+ {
566
+ inputs: [{ internalType: "uint256", name: "tokens", type: "uint256" }],
567
+ name: "p2pBoostTopUp",
568
+ outputs: [],
569
+ stateMutability: "nonpayable",
570
+ type: "function"
571
+ },
572
+ {
573
+ inputs: [],
574
+ name: "p2pBoostRequestUnstake",
575
+ outputs: [],
576
+ stateMutability: "nonpayable",
577
+ type: "function"
578
+ },
579
+ {
580
+ inputs: [],
581
+ name: "p2pBoostClaimUnstake",
582
+ outputs: [],
583
+ stateMutability: "nonpayable",
584
+ type: "function"
585
+ },
586
+ {
587
+ inputs: [{ internalType: "address", name: "user", type: "address" }],
588
+ name: "getUserStake",
589
+ outputs: [
590
+ {
591
+ components: [
592
+ { internalType: "uint128", name: "stakedAmount", type: "uint128" },
593
+ { internalType: "uint64", name: "cooldownEnd", type: "uint64" },
594
+ { internalType: "uint8", name: "status", type: "uint8" }
595
+ ],
596
+ internalType: "struct P2PStakeBoostStorage.UserStake",
597
+ name: "",
598
+ type: "tuple"
599
+ }
600
+ ],
601
+ stateMutability: "view",
602
+ type: "function"
603
+ },
604
+ {
605
+ inputs: [{ internalType: "bytes32", name: "currency", type: "bytes32" }],
606
+ name: "getStakeBoostConfig",
607
+ outputs: [
608
+ {
609
+ components: [
610
+ {
611
+ internalType: "uint256",
612
+ name: "tokensPerUsdNumerator",
613
+ type: "uint256"
614
+ },
615
+ {
616
+ internalType: "uint256",
617
+ name: "tokensPerUsdDenominator",
618
+ type: "uint256"
619
+ },
620
+ { internalType: "uint256", name: "maxBoostUsd", type: "uint256" }
621
+ ],
622
+ internalType: "struct P2PStakeBoostStorage.BoostConfig",
623
+ name: "",
624
+ type: "tuple"
625
+ }
626
+ ],
627
+ stateMutability: "view",
628
+ type: "function"
629
+ },
630
+ {
631
+ inputs: [],
632
+ name: "getStakeBoostGlobals",
633
+ outputs: [
634
+ { internalType: "address", name: "p2pToken", type: "address" },
635
+ { internalType: "address", name: "fraudReserve", type: "address" },
636
+ { internalType: "uint256", name: "maxStakeTokens", type: "uint256" },
637
+ { internalType: "uint256", name: "normalCooldown", type: "uint256" },
638
+ { internalType: "uint256", name: "blacklistCooldown", type: "uint256" },
639
+ { internalType: "uint8", name: "tokenDecimals", type: "uint8" },
640
+ { internalType: "uint256", name: "totalStaked", type: "uint256" }
641
+ ],
642
+ stateMutability: "view",
643
+ type: "function"
644
+ }
645
+ ];
646
+
647
+ // src/contracts/abis/reputation-manager.ts
648
+ var reputationManagerAbi = [
649
+ {
650
+ inputs: [
651
+ {
652
+ internalType: "string",
653
+ name: "_socialName",
654
+ type: "string"
655
+ },
656
+ {
657
+ components: [
658
+ {
659
+ components: [
660
+ {
661
+ internalType: "string",
662
+ name: "provider",
663
+ type: "string"
664
+ },
665
+ {
666
+ internalType: "string",
667
+ name: "parameters",
668
+ type: "string"
669
+ },
670
+ {
671
+ internalType: "string",
672
+ name: "context",
673
+ type: "string"
674
+ }
675
+ ],
676
+ internalType: "struct IReclaimSDK.ClaimInfo",
677
+ name: "claimInfo",
678
+ type: "tuple"
679
+ },
680
+ {
681
+ components: [
682
+ {
683
+ components: [
684
+ {
685
+ internalType: "bytes32",
686
+ name: "identifier",
687
+ type: "bytes32"
688
+ },
689
+ {
690
+ internalType: "address",
691
+ name: "owner",
692
+ type: "address"
693
+ },
694
+ {
695
+ internalType: "uint32",
696
+ name: "timestampS",
697
+ type: "uint32"
698
+ },
699
+ {
700
+ internalType: "uint32",
701
+ name: "epoch",
702
+ type: "uint32"
703
+ }
704
+ ],
705
+ internalType: "struct IReclaimSDK.CompleteClaimData",
706
+ name: "claim",
707
+ type: "tuple"
708
+ },
709
+ {
710
+ internalType: "bytes[]",
711
+ name: "signatures",
712
+ type: "bytes[]"
713
+ }
714
+ ],
715
+ internalType: "struct IReclaimSDK.SignedClaim",
716
+ name: "signedClaim",
717
+ type: "tuple"
718
+ }
719
+ ],
720
+ internalType: "struct IReclaimSDK.Proof[]",
721
+ name: "proofs",
722
+ type: "tuple[]"
723
+ }
724
+ ],
725
+ name: "socialVerify",
726
+ outputs: [],
727
+ stateMutability: "nonpayable",
728
+ type: "function"
729
+ },
730
+ {
731
+ inputs: [
732
+ {
733
+ internalType: "uint256",
734
+ name: "nullifierSeed",
735
+ type: "uint256"
736
+ },
737
+ {
738
+ internalType: "uint256",
739
+ name: "nullifier",
740
+ type: "uint256"
741
+ },
742
+ {
743
+ internalType: "uint256",
744
+ name: "timestamp",
745
+ type: "uint256"
746
+ },
747
+ {
748
+ internalType: "uint256",
749
+ name: "signal",
750
+ type: "uint256"
751
+ },
752
+ {
753
+ internalType: "uint256[4]",
754
+ name: "revealArray",
755
+ type: "uint256[4]"
756
+ },
757
+ {
758
+ internalType: "uint256[8]",
759
+ name: "groth16Proof",
760
+ type: "uint256[8]"
761
+ }
762
+ ],
763
+ name: "submitAnonAadharProof",
764
+ outputs: [],
765
+ stateMutability: "nonpayable",
766
+ type: "function"
767
+ },
768
+ {
769
+ inputs: [
770
+ {
771
+ components: [
772
+ {
773
+ internalType: "bytes32",
774
+ name: "version",
775
+ type: "bytes32"
776
+ },
777
+ {
778
+ components: [
779
+ {
780
+ internalType: "bytes32",
781
+ name: "vkeyHash",
782
+ type: "bytes32"
783
+ },
784
+ {
785
+ internalType: "bytes",
786
+ name: "proof",
787
+ type: "bytes"
788
+ },
789
+ {
790
+ internalType: "bytes32[]",
791
+ name: "publicInputs",
792
+ type: "bytes32[]"
793
+ }
794
+ ],
795
+ internalType: "struct ProofVerificationData",
796
+ name: "proofVerificationData",
797
+ type: "tuple"
798
+ },
799
+ {
800
+ internalType: "bytes",
801
+ name: "committedInputs",
802
+ type: "bytes"
803
+ },
804
+ {
805
+ components: [
806
+ {
807
+ internalType: "uint256",
808
+ name: "validityPeriodInSeconds",
809
+ type: "uint256"
810
+ },
811
+ {
812
+ internalType: "string",
813
+ name: "domain",
814
+ type: "string"
815
+ },
816
+ {
817
+ internalType: "string",
818
+ name: "scope",
819
+ type: "string"
820
+ },
821
+ {
822
+ internalType: "bool",
823
+ name: "devMode",
824
+ type: "bool"
825
+ }
826
+ ],
827
+ internalType: "struct ServiceConfig",
828
+ name: "serviceConfig",
829
+ type: "tuple"
830
+ }
831
+ ],
832
+ internalType: "struct ProofVerificationParams",
833
+ name: "params",
834
+ type: "tuple"
835
+ },
836
+ {
837
+ internalType: "bool",
838
+ name: "isIDCard",
839
+ type: "bool"
840
+ }
841
+ ],
842
+ name: "zkPassportRegister",
843
+ outputs: [],
844
+ stateMutability: "nonpayable",
845
+ type: "function"
846
+ }
847
+ ];
848
+
849
+ // src/contracts/abis/index.ts
850
+ var DIAMOND_ABI = [
851
+ ...orderFlowFacetAbi,
852
+ ...orderProcessorFacetAbi,
853
+ ...p2pConfigFacetAbi,
854
+ ...p2pStakeBoostFacetAbi
855
+ ];
856
+ var ABIS = {
857
+ DIAMOND: DIAMOND_ABI,
858
+ FACETS: {
859
+ ORDER_FLOW: orderFlowFacetAbi,
860
+ ORDER_PROCESSOR: orderProcessorFacetAbi,
861
+ CONFIG: p2pConfigFacetAbi,
862
+ STAKE: p2pStakeBoostFacetAbi
863
+ },
864
+ EXTERNAL: {
865
+ USDC: erc20Abi,
866
+ REPUTATION_MANAGER: reputationManagerAbi
867
+ }
868
+ };
869
+
870
+ // src/contracts/p2p-stake/index.ts
871
+ function getUserStake(publicClient, diamondAddress, params) {
872
+ return validate(
873
+ ZodGetUserStakeParamsSchema,
874
+ params,
875
+ (message, cause, data) => new StakeError(message, {
876
+ code: "VALIDATION_ERROR",
877
+ cause,
878
+ context: { params: data }
879
+ })
880
+ ).asyncAndThen(
881
+ (validated) => ResultAsync.fromPromise(
882
+ publicClient.readContract({
883
+ address: diamondAddress,
884
+ abi: ABIS.FACETS.STAKE,
885
+ functionName: "getUserStake",
886
+ args: [validated.user]
887
+ }),
888
+ (error) => new StakeError("Failed to read user stake", {
889
+ code: "CONTRACT_READ_ERROR",
890
+ cause: error,
891
+ context: { user: validated.user, diamondAddress }
892
+ })
893
+ )
894
+ );
895
+ }
896
+ function getStakeBoostConfig(publicClient, diamondAddress, params) {
897
+ return validate(
898
+ ZodGetStakeBoostConfigParamsSchema,
899
+ params,
900
+ (message, cause, data) => new StakeError(message, {
901
+ code: "VALIDATION_ERROR",
902
+ cause,
903
+ context: { params: data }
904
+ })
905
+ ).asyncAndThen(
906
+ (validated) => ResultAsync.fromPromise(
907
+ publicClient.readContract({
908
+ address: diamondAddress,
909
+ abi: ABIS.FACETS.STAKE,
910
+ functionName: "getStakeBoostConfig",
911
+ args: [stringToHex(validated.currency, { size: 32 })]
912
+ }),
913
+ (error) => new StakeError("Failed to read stake boost config", {
914
+ code: "CONTRACT_READ_ERROR",
915
+ cause: error,
916
+ context: { currency: validated.currency, diamondAddress }
917
+ })
918
+ )
919
+ );
920
+ }
921
+ function getStakeBoostGlobals(publicClient, diamondAddress) {
922
+ return ResultAsync.fromPromise(
923
+ publicClient.readContract({
924
+ address: diamondAddress,
925
+ abi: ABIS.FACETS.STAKE,
926
+ functionName: "getStakeBoostGlobals",
927
+ args: []
928
+ }),
929
+ (error) => new StakeError("Failed to read stake boost globals", {
930
+ code: "CONTRACT_READ_ERROR",
931
+ cause: error,
932
+ context: { diamondAddress }
933
+ })
934
+ );
935
+ }
936
+ function getP2pTokenBalance(publicClient, p2pTokenAddress, params) {
937
+ return validate(
938
+ ZodGetP2pTokenBalanceParamsSchema,
939
+ params,
940
+ (message, cause, data) => new StakeError(message, {
941
+ code: "VALIDATION_ERROR",
942
+ cause,
943
+ context: { params: data }
944
+ })
945
+ ).asyncAndThen(
946
+ (validated) => ResultAsync.fromPromise(
947
+ publicClient.readContract({
948
+ address: p2pTokenAddress,
949
+ abi: ABIS.EXTERNAL.USDC,
950
+ functionName: "balanceOf",
951
+ args: [validated.address]
952
+ }),
953
+ (error) => new StakeError("Failed to read P2P token balance", {
954
+ code: "CONTRACT_READ_ERROR",
955
+ cause: error,
956
+ context: { address: validated.address, p2pTokenAddress }
957
+ })
958
+ )
959
+ );
960
+ }
961
+
962
+ // src/stake/actions/claim-unstake.ts
963
+ import { okAsync as okAsync2 } from "neverthrow";
964
+ import { encodeFunctionData } from "viem";
965
+
966
+ // src/stake/tx.ts
967
+ import { errAsync, okAsync, ResultAsync as ResultAsync2 } from "neverthrow";
968
+ function submitPreparedTx(input) {
969
+ const { prepared, walletClient, publicClient, waitForReceipt } = input;
970
+ const account = walletClient.account;
971
+ if (!account) {
972
+ return errAsync(
973
+ new StakeError("WalletClient is missing an account", {
974
+ code: "TX_SUBMISSION_FAILED"
975
+ })
976
+ );
977
+ }
978
+ const chain = walletClient.chain;
979
+ return ResultAsync2.fromPromise(
980
+ walletClient.sendTransaction({
981
+ account,
982
+ chain,
983
+ to: prepared.to,
984
+ data: prepared.data,
985
+ value: prepared.value
986
+ }),
987
+ (cause) => new StakeError("walletClient.sendTransaction rejected", {
988
+ code: "TX_SUBMISSION_FAILED",
989
+ cause
990
+ })
991
+ ).andThen((hash) => {
992
+ if (!waitForReceipt) {
993
+ return okAsync({ hash });
994
+ }
995
+ return ResultAsync2.fromPromise(
996
+ publicClient.waitForTransactionReceipt({ hash }),
997
+ (cause) => new StakeError("waitForTransactionReceipt failed", {
998
+ code: "RECEIPT_TIMEOUT",
999
+ cause
1000
+ })
1001
+ ).andThen((receipt) => {
1002
+ if (receipt.status !== "success") {
1003
+ return errAsync(
1004
+ new StakeError("Transaction reverted", {
1005
+ code: "TX_REVERTED",
1006
+ context: { hash, blockNumber: receipt.blockNumber.toString() }
1007
+ })
1008
+ );
1009
+ }
1010
+ return okAsync({ hash, receipt });
1011
+ });
1012
+ });
1013
+ }
1014
+
1015
+ // src/stake/actions/claim-unstake.ts
1016
+ function createClaimUnstakeAction(input) {
1017
+ const { publicClient, diamondAddress } = input;
1018
+ const prepareFn = () => okAsync2({
1019
+ to: diamondAddress,
1020
+ data: encodeFunctionData({
1021
+ abi: ABIS.FACETS.STAKE,
1022
+ functionName: "p2pBoostClaimUnstake",
1023
+ args: []
1024
+ }),
1025
+ value: 0n
1026
+ });
1027
+ return {
1028
+ prepare() {
1029
+ return prepareFn();
1030
+ },
1031
+ execute({ walletClient, waitForReceipt }) {
1032
+ return prepareFn().andThen(
1033
+ (prepared) => submitPreparedTx({ prepared, walletClient, publicClient, waitForReceipt })
1034
+ );
1035
+ }
1036
+ };
1037
+ }
1038
+
1039
+ // src/stake/actions/request-unstake.ts
1040
+ import { okAsync as okAsync3 } from "neverthrow";
1041
+ import { encodeFunctionData as encodeFunctionData2 } from "viem";
1042
+ function createRequestUnstakeAction(input) {
1043
+ const { publicClient, diamondAddress } = input;
1044
+ const prepareFn = () => okAsync3({
1045
+ to: diamondAddress,
1046
+ data: encodeFunctionData2({
1047
+ abi: ABIS.FACETS.STAKE,
1048
+ functionName: "p2pBoostRequestUnstake",
1049
+ args: []
1050
+ }),
1051
+ value: 0n
1052
+ });
1053
+ return {
1054
+ prepare() {
1055
+ return prepareFn();
1056
+ },
1057
+ execute({ walletClient, waitForReceipt }) {
1058
+ return prepareFn().andThen(
1059
+ (prepared) => submitPreparedTx({ prepared, walletClient, publicClient, waitForReceipt })
1060
+ );
1061
+ }
1062
+ };
1063
+ }
1064
+
1065
+ // src/stake/actions/stake.ts
1066
+ import { encodeFunctionData as encodeFunctionData3 } from "viem";
1067
+ function createStakeAction(input) {
1068
+ const { publicClient, diamondAddress } = input;
1069
+ const prepareFn = (params) => validate(
1070
+ ZodStakeParamsSchema,
1071
+ params,
1072
+ (message, cause, data) => new StakeError(message, {
1073
+ code: "VALIDATION_ERROR",
1074
+ cause,
1075
+ context: { data }
1076
+ })
1077
+ ).map(({ tokens }) => ({
1078
+ to: diamondAddress,
1079
+ data: encodeFunctionData3({
1080
+ abi: ABIS.FACETS.STAKE,
1081
+ functionName: "p2pBoostStake",
1082
+ args: [tokens]
1083
+ }),
1084
+ value: 0n
1085
+ }));
1086
+ return {
1087
+ prepare(params) {
1088
+ return prepareFn(params).asyncMap(async (tx) => tx);
1089
+ },
1090
+ execute({ walletClient, waitForReceipt, ...params }) {
1091
+ return prepareFn(params).asyncAndThen(
1092
+ (prepared) => submitPreparedTx({ prepared, walletClient, publicClient, waitForReceipt })
1093
+ );
1094
+ }
1095
+ };
1096
+ }
1097
+
1098
+ // src/stake/actions/top-up.ts
1099
+ import { encodeFunctionData as encodeFunctionData4 } from "viem";
1100
+ function createTopUpAction(input) {
1101
+ const { publicClient, diamondAddress } = input;
1102
+ const prepareFn = (params) => validate(
1103
+ ZodTopUpParamsSchema,
1104
+ params,
1105
+ (message, cause, data) => new StakeError(message, {
1106
+ code: "VALIDATION_ERROR",
1107
+ cause,
1108
+ context: { data }
1109
+ })
1110
+ ).map(({ tokens }) => ({
1111
+ to: diamondAddress,
1112
+ data: encodeFunctionData4({
1113
+ abi: ABIS.FACETS.STAKE,
1114
+ functionName: "p2pBoostTopUp",
1115
+ args: [tokens]
1116
+ }),
1117
+ value: 0n
1118
+ }));
1119
+ return {
1120
+ prepare(params) {
1121
+ return prepareFn(params).asyncMap(async (tx) => tx);
1122
+ },
1123
+ execute({ walletClient, waitForReceipt, ...params }) {
1124
+ return prepareFn(params).asyncAndThen(
1125
+ (prepared) => submitPreparedTx({ prepared, walletClient, publicClient, waitForReceipt })
1126
+ );
1127
+ }
1128
+ };
1129
+ }
1130
+
1131
+ // src/stake/normalize.ts
1132
+ var STATUS_MAP = {
1133
+ 0: "none",
1134
+ 1: "active",
1135
+ 2: "cooldown",
1136
+ 3: "seized"
1137
+ };
1138
+ function normalizeUserStake(raw) {
1139
+ return {
1140
+ stakedAmount: raw.stakedAmount,
1141
+ cooldownEnd: raw.cooldownEnd,
1142
+ status: STATUS_MAP[raw.status] ?? "none"
1143
+ };
1144
+ }
1145
+ function normalizeStakeBoostGlobals(raw) {
1146
+ const [
1147
+ p2pToken,
1148
+ fraudReserve,
1149
+ maxStakeTokens,
1150
+ normalCooldown,
1151
+ blacklistCooldown,
1152
+ tokenDecimals,
1153
+ totalStaked
1154
+ ] = raw;
1155
+ return {
1156
+ p2pToken,
1157
+ fraudReserve,
1158
+ maxStakeTokens,
1159
+ normalCooldown,
1160
+ blacklistCooldown,
1161
+ tokenDecimals,
1162
+ totalStaked
1163
+ };
1164
+ }
1165
+
1166
+ // src/stake/client.ts
1167
+ function createStake(config) {
1168
+ const { publicClient, diamondAddress, p2pTokenAddress } = config;
1169
+ return {
1170
+ getUserStake: (params) => getUserStake(publicClient, diamondAddress, params).map(normalizeUserStake),
1171
+ getStakeBoostConfig: (params) => getStakeBoostConfig(publicClient, diamondAddress, params),
1172
+ getStakeBoostGlobals: () => getStakeBoostGlobals(publicClient, diamondAddress).map(normalizeStakeBoostGlobals),
1173
+ getP2pTokenBalance: (params) => getP2pTokenBalance(publicClient, p2pTokenAddress, params),
1174
+ stake: createStakeAction({ publicClient, diamondAddress }),
1175
+ topUp: createTopUpAction({ publicClient, diamondAddress }),
1176
+ requestUnstake: createRequestUnstakeAction({ publicClient, diamondAddress }),
1177
+ claimUnstake: createClaimUnstakeAction({ publicClient, diamondAddress })
1178
+ };
1179
+ }
1180
+ export {
1181
+ StakeError,
1182
+ createStake
1183
+ };
1184
+ //# sourceMappingURL=stake.mjs.map