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