@p2pdotme/sdk 1.1.8 → 1.1.9

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