@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/stake.mjs ADDED
@@ -0,0 +1,1218 @@
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: [],
588
+ name: "p2pBoostCancelUnstake",
589
+ outputs: [],
590
+ stateMutability: "nonpayable",
591
+ type: "function"
592
+ },
593
+ {
594
+ inputs: [{ internalType: "address", name: "user", type: "address" }],
595
+ name: "getUserStake",
596
+ outputs: [
597
+ {
598
+ components: [
599
+ { internalType: "uint128", name: "stakedAmount", type: "uint128" },
600
+ { internalType: "uint64", name: "cooldownEnd", type: "uint64" },
601
+ { internalType: "uint8", name: "status", type: "uint8" }
602
+ ],
603
+ internalType: "struct P2PStakeBoostStorage.UserStake",
604
+ name: "",
605
+ type: "tuple"
606
+ }
607
+ ],
608
+ stateMutability: "view",
609
+ type: "function"
610
+ },
611
+ {
612
+ inputs: [{ internalType: "bytes32", name: "currency", type: "bytes32" }],
613
+ name: "getStakeBoostConfig",
614
+ outputs: [
615
+ {
616
+ components: [
617
+ {
618
+ internalType: "uint256",
619
+ name: "tokensPerUsdNumerator",
620
+ type: "uint256"
621
+ },
622
+ {
623
+ internalType: "uint256",
624
+ name: "tokensPerUsdDenominator",
625
+ type: "uint256"
626
+ },
627
+ { internalType: "uint256", name: "maxBoostUsd", type: "uint256" }
628
+ ],
629
+ internalType: "struct P2PStakeBoostStorage.BoostConfig",
630
+ name: "",
631
+ type: "tuple"
632
+ }
633
+ ],
634
+ stateMutability: "view",
635
+ type: "function"
636
+ },
637
+ {
638
+ inputs: [],
639
+ name: "getStakeBoostGlobals",
640
+ outputs: [
641
+ { internalType: "address", name: "p2pToken", type: "address" },
642
+ { internalType: "address", name: "fraudReserve", type: "address" },
643
+ { internalType: "uint256", name: "maxStakeTokens", type: "uint256" },
644
+ { internalType: "uint256", name: "normalCooldown", type: "uint256" },
645
+ { internalType: "uint256", name: "blacklistCooldown", type: "uint256" },
646
+ { internalType: "uint8", name: "tokenDecimals", type: "uint8" },
647
+ { internalType: "uint256", name: "totalStaked", type: "uint256" }
648
+ ],
649
+ stateMutability: "view",
650
+ type: "function"
651
+ }
652
+ ];
653
+
654
+ // src/contracts/abis/reputation-manager.ts
655
+ var reputationManagerAbi = [
656
+ {
657
+ inputs: [
658
+ {
659
+ internalType: "string",
660
+ name: "_socialName",
661
+ type: "string"
662
+ },
663
+ {
664
+ components: [
665
+ {
666
+ components: [
667
+ {
668
+ internalType: "string",
669
+ name: "provider",
670
+ type: "string"
671
+ },
672
+ {
673
+ internalType: "string",
674
+ name: "parameters",
675
+ type: "string"
676
+ },
677
+ {
678
+ internalType: "string",
679
+ name: "context",
680
+ type: "string"
681
+ }
682
+ ],
683
+ internalType: "struct IReclaimSDK.ClaimInfo",
684
+ name: "claimInfo",
685
+ type: "tuple"
686
+ },
687
+ {
688
+ components: [
689
+ {
690
+ components: [
691
+ {
692
+ internalType: "bytes32",
693
+ name: "identifier",
694
+ type: "bytes32"
695
+ },
696
+ {
697
+ internalType: "address",
698
+ name: "owner",
699
+ type: "address"
700
+ },
701
+ {
702
+ internalType: "uint32",
703
+ name: "timestampS",
704
+ type: "uint32"
705
+ },
706
+ {
707
+ internalType: "uint32",
708
+ name: "epoch",
709
+ type: "uint32"
710
+ }
711
+ ],
712
+ internalType: "struct IReclaimSDK.CompleteClaimData",
713
+ name: "claim",
714
+ type: "tuple"
715
+ },
716
+ {
717
+ internalType: "bytes[]",
718
+ name: "signatures",
719
+ type: "bytes[]"
720
+ }
721
+ ],
722
+ internalType: "struct IReclaimSDK.SignedClaim",
723
+ name: "signedClaim",
724
+ type: "tuple"
725
+ }
726
+ ],
727
+ internalType: "struct IReclaimSDK.Proof[]",
728
+ name: "proofs",
729
+ type: "tuple[]"
730
+ }
731
+ ],
732
+ name: "socialVerify",
733
+ outputs: [],
734
+ stateMutability: "nonpayable",
735
+ type: "function"
736
+ },
737
+ {
738
+ inputs: [
739
+ {
740
+ internalType: "uint256",
741
+ name: "nullifierSeed",
742
+ type: "uint256"
743
+ },
744
+ {
745
+ internalType: "uint256",
746
+ name: "nullifier",
747
+ type: "uint256"
748
+ },
749
+ {
750
+ internalType: "uint256",
751
+ name: "timestamp",
752
+ type: "uint256"
753
+ },
754
+ {
755
+ internalType: "uint256",
756
+ name: "signal",
757
+ type: "uint256"
758
+ },
759
+ {
760
+ internalType: "uint256[4]",
761
+ name: "revealArray",
762
+ type: "uint256[4]"
763
+ },
764
+ {
765
+ internalType: "uint256[8]",
766
+ name: "groth16Proof",
767
+ type: "uint256[8]"
768
+ }
769
+ ],
770
+ name: "submitAnonAadharProof",
771
+ outputs: [],
772
+ stateMutability: "nonpayable",
773
+ type: "function"
774
+ },
775
+ {
776
+ inputs: [
777
+ {
778
+ components: [
779
+ {
780
+ internalType: "bytes32",
781
+ name: "version",
782
+ type: "bytes32"
783
+ },
784
+ {
785
+ components: [
786
+ {
787
+ internalType: "bytes32",
788
+ name: "vkeyHash",
789
+ type: "bytes32"
790
+ },
791
+ {
792
+ internalType: "bytes",
793
+ name: "proof",
794
+ type: "bytes"
795
+ },
796
+ {
797
+ internalType: "bytes32[]",
798
+ name: "publicInputs",
799
+ type: "bytes32[]"
800
+ }
801
+ ],
802
+ internalType: "struct ProofVerificationData",
803
+ name: "proofVerificationData",
804
+ type: "tuple"
805
+ },
806
+ {
807
+ internalType: "bytes",
808
+ name: "committedInputs",
809
+ type: "bytes"
810
+ },
811
+ {
812
+ components: [
813
+ {
814
+ internalType: "uint256",
815
+ name: "validityPeriodInSeconds",
816
+ type: "uint256"
817
+ },
818
+ {
819
+ internalType: "string",
820
+ name: "domain",
821
+ type: "string"
822
+ },
823
+ {
824
+ internalType: "string",
825
+ name: "scope",
826
+ type: "string"
827
+ },
828
+ {
829
+ internalType: "bool",
830
+ name: "devMode",
831
+ type: "bool"
832
+ }
833
+ ],
834
+ internalType: "struct ServiceConfig",
835
+ name: "serviceConfig",
836
+ type: "tuple"
837
+ }
838
+ ],
839
+ internalType: "struct ProofVerificationParams",
840
+ name: "params",
841
+ type: "tuple"
842
+ },
843
+ {
844
+ internalType: "bool",
845
+ name: "isIDCard",
846
+ type: "bool"
847
+ }
848
+ ],
849
+ name: "zkPassportRegister",
850
+ outputs: [],
851
+ stateMutability: "nonpayable",
852
+ type: "function"
853
+ }
854
+ ];
855
+
856
+ // src/contracts/abis/index.ts
857
+ var DIAMOND_ABI = [
858
+ ...orderFlowFacetAbi,
859
+ ...orderProcessorFacetAbi,
860
+ ...p2pConfigFacetAbi,
861
+ ...p2pStakeBoostFacetAbi
862
+ ];
863
+ var ABIS = {
864
+ DIAMOND: DIAMOND_ABI,
865
+ FACETS: {
866
+ ORDER_FLOW: orderFlowFacetAbi,
867
+ ORDER_PROCESSOR: orderProcessorFacetAbi,
868
+ CONFIG: p2pConfigFacetAbi,
869
+ STAKE: p2pStakeBoostFacetAbi
870
+ },
871
+ EXTERNAL: {
872
+ USDC: erc20Abi,
873
+ REPUTATION_MANAGER: reputationManagerAbi
874
+ }
875
+ };
876
+
877
+ // src/contracts/p2p-stake/index.ts
878
+ function getUserStake(publicClient, diamondAddress, params) {
879
+ return validate(
880
+ ZodGetUserStakeParamsSchema,
881
+ params,
882
+ (message, cause, data) => new StakeError(message, {
883
+ code: "VALIDATION_ERROR",
884
+ cause,
885
+ context: { params: data }
886
+ })
887
+ ).asyncAndThen(
888
+ (validated) => ResultAsync.fromPromise(
889
+ publicClient.readContract({
890
+ address: diamondAddress,
891
+ abi: ABIS.FACETS.STAKE,
892
+ functionName: "getUserStake",
893
+ args: [validated.user]
894
+ }),
895
+ (error) => new StakeError("Failed to read user stake", {
896
+ code: "CONTRACT_READ_ERROR",
897
+ cause: error,
898
+ context: { user: validated.user, diamondAddress }
899
+ })
900
+ )
901
+ );
902
+ }
903
+ function getStakeBoostConfig(publicClient, diamondAddress, params) {
904
+ return validate(
905
+ ZodGetStakeBoostConfigParamsSchema,
906
+ params,
907
+ (message, cause, data) => new StakeError(message, {
908
+ code: "VALIDATION_ERROR",
909
+ cause,
910
+ context: { params: data }
911
+ })
912
+ ).asyncAndThen(
913
+ (validated) => ResultAsync.fromPromise(
914
+ publicClient.readContract({
915
+ address: diamondAddress,
916
+ abi: ABIS.FACETS.STAKE,
917
+ functionName: "getStakeBoostConfig",
918
+ args: [stringToHex(validated.currency, { size: 32 })]
919
+ }),
920
+ (error) => new StakeError("Failed to read stake boost config", {
921
+ code: "CONTRACT_READ_ERROR",
922
+ cause: error,
923
+ context: { currency: validated.currency, diamondAddress }
924
+ })
925
+ )
926
+ );
927
+ }
928
+ function getStakeBoostGlobals(publicClient, diamondAddress) {
929
+ return ResultAsync.fromPromise(
930
+ publicClient.readContract({
931
+ address: diamondAddress,
932
+ abi: ABIS.FACETS.STAKE,
933
+ functionName: "getStakeBoostGlobals",
934
+ args: []
935
+ }),
936
+ (error) => new StakeError("Failed to read stake boost globals", {
937
+ code: "CONTRACT_READ_ERROR",
938
+ cause: error,
939
+ context: { diamondAddress }
940
+ })
941
+ );
942
+ }
943
+ function getP2pTokenBalance(publicClient, p2pTokenAddress, params) {
944
+ return validate(
945
+ ZodGetP2pTokenBalanceParamsSchema,
946
+ params,
947
+ (message, cause, data) => new StakeError(message, {
948
+ code: "VALIDATION_ERROR",
949
+ cause,
950
+ context: { params: data }
951
+ })
952
+ ).asyncAndThen(
953
+ (validated) => ResultAsync.fromPromise(
954
+ publicClient.readContract({
955
+ address: p2pTokenAddress,
956
+ abi: ABIS.EXTERNAL.USDC,
957
+ functionName: "balanceOf",
958
+ args: [validated.address]
959
+ }),
960
+ (error) => new StakeError("Failed to read P2P token balance", {
961
+ code: "CONTRACT_READ_ERROR",
962
+ cause: error,
963
+ context: { address: validated.address, p2pTokenAddress }
964
+ })
965
+ )
966
+ );
967
+ }
968
+
969
+ // src/stake/actions/cancel-unstake.ts
970
+ import { okAsync as okAsync2 } from "neverthrow";
971
+ import { encodeFunctionData } from "viem";
972
+
973
+ // src/stake/tx.ts
974
+ import { errAsync, okAsync, ResultAsync as ResultAsync2 } from "neverthrow";
975
+ function submitPreparedTx(input) {
976
+ const { prepared, walletClient, publicClient, waitForReceipt } = input;
977
+ const account = walletClient.account;
978
+ if (!account) {
979
+ return errAsync(
980
+ new StakeError("WalletClient is missing an account", {
981
+ code: "TX_SUBMISSION_FAILED"
982
+ })
983
+ );
984
+ }
985
+ const chain = walletClient.chain;
986
+ return ResultAsync2.fromPromise(
987
+ walletClient.sendTransaction({
988
+ account,
989
+ chain,
990
+ to: prepared.to,
991
+ data: prepared.data,
992
+ value: prepared.value
993
+ }),
994
+ (cause) => new StakeError("walletClient.sendTransaction rejected", {
995
+ code: "TX_SUBMISSION_FAILED",
996
+ cause
997
+ })
998
+ ).andThen((hash) => {
999
+ if (!waitForReceipt) {
1000
+ return okAsync({ hash });
1001
+ }
1002
+ return ResultAsync2.fromPromise(
1003
+ publicClient.waitForTransactionReceipt({ hash }),
1004
+ (cause) => new StakeError("waitForTransactionReceipt failed", {
1005
+ code: "RECEIPT_TIMEOUT",
1006
+ cause
1007
+ })
1008
+ ).andThen((receipt) => {
1009
+ if (receipt.status !== "success") {
1010
+ return errAsync(
1011
+ new StakeError("Transaction reverted", {
1012
+ code: "TX_REVERTED",
1013
+ context: { hash, blockNumber: receipt.blockNumber.toString() }
1014
+ })
1015
+ );
1016
+ }
1017
+ return okAsync({ hash, receipt });
1018
+ });
1019
+ });
1020
+ }
1021
+
1022
+ // src/stake/actions/cancel-unstake.ts
1023
+ function createCancelUnstakeAction(input) {
1024
+ const { publicClient, diamondAddress } = input;
1025
+ const prepareFn = () => okAsync2({
1026
+ to: diamondAddress,
1027
+ data: encodeFunctionData({
1028
+ abi: ABIS.FACETS.STAKE,
1029
+ functionName: "p2pBoostCancelUnstake",
1030
+ args: []
1031
+ }),
1032
+ value: 0n
1033
+ });
1034
+ return {
1035
+ prepare() {
1036
+ return prepareFn();
1037
+ },
1038
+ execute({ walletClient, waitForReceipt }) {
1039
+ return prepareFn().andThen(
1040
+ (prepared) => submitPreparedTx({ prepared, walletClient, publicClient, waitForReceipt })
1041
+ );
1042
+ }
1043
+ };
1044
+ }
1045
+
1046
+ // src/stake/actions/claim-unstake.ts
1047
+ import { okAsync as okAsync3 } from "neverthrow";
1048
+ import { encodeFunctionData as encodeFunctionData2 } from "viem";
1049
+ function createClaimUnstakeAction(input) {
1050
+ const { publicClient, diamondAddress } = input;
1051
+ const prepareFn = () => okAsync3({
1052
+ to: diamondAddress,
1053
+ data: encodeFunctionData2({
1054
+ abi: ABIS.FACETS.STAKE,
1055
+ functionName: "p2pBoostClaimUnstake",
1056
+ args: []
1057
+ }),
1058
+ value: 0n
1059
+ });
1060
+ return {
1061
+ prepare() {
1062
+ return prepareFn();
1063
+ },
1064
+ execute({ walletClient, waitForReceipt }) {
1065
+ return prepareFn().andThen(
1066
+ (prepared) => submitPreparedTx({ prepared, walletClient, publicClient, waitForReceipt })
1067
+ );
1068
+ }
1069
+ };
1070
+ }
1071
+
1072
+ // src/stake/actions/request-unstake.ts
1073
+ import { okAsync as okAsync4 } from "neverthrow";
1074
+ import { encodeFunctionData as encodeFunctionData3 } from "viem";
1075
+ function createRequestUnstakeAction(input) {
1076
+ const { publicClient, diamondAddress } = input;
1077
+ const prepareFn = () => okAsync4({
1078
+ to: diamondAddress,
1079
+ data: encodeFunctionData3({
1080
+ abi: ABIS.FACETS.STAKE,
1081
+ functionName: "p2pBoostRequestUnstake",
1082
+ args: []
1083
+ }),
1084
+ value: 0n
1085
+ });
1086
+ return {
1087
+ prepare() {
1088
+ return prepareFn();
1089
+ },
1090
+ execute({ walletClient, waitForReceipt }) {
1091
+ return prepareFn().andThen(
1092
+ (prepared) => submitPreparedTx({ prepared, walletClient, publicClient, waitForReceipt })
1093
+ );
1094
+ }
1095
+ };
1096
+ }
1097
+
1098
+ // src/stake/actions/stake.ts
1099
+ import { encodeFunctionData as encodeFunctionData4 } from "viem";
1100
+ function createStakeAction(input) {
1101
+ const { publicClient, diamondAddress } = input;
1102
+ const prepareFn = (params) => validate(
1103
+ ZodStakeParamsSchema,
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: "p2pBoostStake",
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/actions/top-up.ts
1132
+ import { encodeFunctionData as encodeFunctionData5 } from "viem";
1133
+ function createTopUpAction(input) {
1134
+ const { publicClient, diamondAddress } = input;
1135
+ const prepareFn = (params) => validate(
1136
+ ZodTopUpParamsSchema,
1137
+ params,
1138
+ (message, cause, data) => new StakeError(message, {
1139
+ code: "VALIDATION_ERROR",
1140
+ cause,
1141
+ context: { data }
1142
+ })
1143
+ ).map(({ tokens }) => ({
1144
+ to: diamondAddress,
1145
+ data: encodeFunctionData5({
1146
+ abi: ABIS.FACETS.STAKE,
1147
+ functionName: "p2pBoostTopUp",
1148
+ args: [tokens]
1149
+ }),
1150
+ value: 0n
1151
+ }));
1152
+ return {
1153
+ prepare(params) {
1154
+ return prepareFn(params).asyncMap(async (tx) => tx);
1155
+ },
1156
+ execute({ walletClient, waitForReceipt, ...params }) {
1157
+ return prepareFn(params).asyncAndThen(
1158
+ (prepared) => submitPreparedTx({ prepared, walletClient, publicClient, waitForReceipt })
1159
+ );
1160
+ }
1161
+ };
1162
+ }
1163
+
1164
+ // src/stake/normalize.ts
1165
+ var STATUS_MAP = {
1166
+ 0: "none",
1167
+ 1: "active",
1168
+ 2: "cooldown",
1169
+ 3: "seized"
1170
+ };
1171
+ function normalizeUserStake(raw) {
1172
+ return {
1173
+ stakedAmount: raw.stakedAmount,
1174
+ cooldownEnd: raw.cooldownEnd,
1175
+ status: STATUS_MAP[raw.status] ?? "none"
1176
+ };
1177
+ }
1178
+ function normalizeStakeBoostGlobals(raw) {
1179
+ const [
1180
+ p2pToken,
1181
+ fraudReserve,
1182
+ maxStakeTokens,
1183
+ normalCooldown,
1184
+ blacklistCooldown,
1185
+ tokenDecimals,
1186
+ totalStaked
1187
+ ] = raw;
1188
+ return {
1189
+ p2pToken,
1190
+ fraudReserve,
1191
+ maxStakeTokens,
1192
+ normalCooldown,
1193
+ blacklistCooldown,
1194
+ tokenDecimals,
1195
+ totalStaked
1196
+ };
1197
+ }
1198
+
1199
+ // src/stake/client.ts
1200
+ function createStake(config) {
1201
+ const { publicClient, diamondAddress, p2pTokenAddress } = config;
1202
+ return {
1203
+ getUserStake: (params) => getUserStake(publicClient, diamondAddress, params).map(normalizeUserStake),
1204
+ getStakeBoostConfig: (params) => getStakeBoostConfig(publicClient, diamondAddress, params),
1205
+ getStakeBoostGlobals: () => getStakeBoostGlobals(publicClient, diamondAddress).map(normalizeStakeBoostGlobals),
1206
+ getP2pTokenBalance: (params) => getP2pTokenBalance(publicClient, p2pTokenAddress, params),
1207
+ stake: createStakeAction({ publicClient, diamondAddress }),
1208
+ topUp: createTopUpAction({ publicClient, diamondAddress }),
1209
+ requestUnstake: createRequestUnstakeAction({ publicClient, diamondAddress }),
1210
+ cancelUnstake: createCancelUnstakeAction({ publicClient, diamondAddress }),
1211
+ claimUnstake: createClaimUnstakeAction({ publicClient, diamondAddress })
1212
+ };
1213
+ }
1214
+ export {
1215
+ StakeError,
1216
+ createStake
1217
+ };
1218
+ //# sourceMappingURL=stake.mjs.map