@p2pdotme/sdk 1.0.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.
Files changed (50) hide show
  1. package/README.md +155 -0
  2. package/dist/fraud-engine.cjs +598 -0
  3. package/dist/fraud-engine.cjs.map +1 -0
  4. package/dist/fraud-engine.d.cts +194 -0
  5. package/dist/fraud-engine.d.ts +194 -0
  6. package/dist/fraud-engine.mjs +549 -0
  7. package/dist/fraud-engine.mjs.map +1 -0
  8. package/dist/index.cjs +75 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.cts +49 -0
  11. package/dist/index.d.ts +49 -0
  12. package/dist/index.mjs +46 -0
  13. package/dist/index.mjs.map +1 -0
  14. package/dist/order-routing.cjs +882 -0
  15. package/dist/order-routing.cjs.map +1 -0
  16. package/dist/order-routing.d.cts +68 -0
  17. package/dist/order-routing.d.ts +68 -0
  18. package/dist/order-routing.mjs +854 -0
  19. package/dist/order-routing.mjs.map +1 -0
  20. package/dist/payload.cjs +3164 -0
  21. package/dist/payload.cjs.map +1 -0
  22. package/dist/payload.d.cts +162 -0
  23. package/dist/payload.d.ts +162 -0
  24. package/dist/payload.mjs +3120 -0
  25. package/dist/payload.mjs.map +1 -0
  26. package/dist/profile.cjs +695 -0
  27. package/dist/profile.cjs.map +1 -0
  28. package/dist/profile.d.cts +133 -0
  29. package/dist/profile.d.ts +133 -0
  30. package/dist/profile.mjs +667 -0
  31. package/dist/profile.mjs.map +1 -0
  32. package/dist/qr-parsers.cjs +366 -0
  33. package/dist/qr-parsers.cjs.map +1 -0
  34. package/dist/qr-parsers.d.cts +41 -0
  35. package/dist/qr-parsers.d.ts +41 -0
  36. package/dist/qr-parsers.mjs +338 -0
  37. package/dist/qr-parsers.mjs.map +1 -0
  38. package/dist/react.cjs +4803 -0
  39. package/dist/react.cjs.map +1 -0
  40. package/dist/react.d.cts +511 -0
  41. package/dist/react.d.ts +511 -0
  42. package/dist/react.mjs +4759 -0
  43. package/dist/react.mjs.map +1 -0
  44. package/dist/zkkyc.cjs +868 -0
  45. package/dist/zkkyc.cjs.map +1 -0
  46. package/dist/zkkyc.d.cts +230 -0
  47. package/dist/zkkyc.d.ts +230 -0
  48. package/dist/zkkyc.mjs +824 -0
  49. package/dist/zkkyc.mjs.map +1 -0
  50. package/package.json +130 -0
@@ -0,0 +1,695 @@
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/profile/index.ts
21
+ var profile_exports = {};
22
+ __export(profile_exports, {
23
+ ProfileError: () => ProfileError,
24
+ createProfile: () => createProfile
25
+ });
26
+ module.exports = __toCommonJS(profile_exports);
27
+
28
+ // src/contracts/abis/index.ts
29
+ var import_viem = require("viem");
30
+
31
+ // src/contracts/abis/order-flow-facet.ts
32
+ var orderFlowFacetAbi = [
33
+ {
34
+ inputs: [
35
+ { internalType: "uint256", name: "circleId", type: "uint256" },
36
+ { internalType: "uint256", name: "assignUpto", type: "uint256" },
37
+ { internalType: "bytes32", name: "currency", type: "bytes32" },
38
+ { internalType: "address", name: "user", type: "address" },
39
+ { internalType: "uint256", name: "usdtAmount", type: "uint256" },
40
+ { internalType: "uint256", name: "fiatAmount", type: "uint256" },
41
+ { internalType: "int256", name: "orderType", type: "int256" },
42
+ { internalType: "uint256", name: "preferredPCConfigId", type: "uint256" }
43
+ ],
44
+ name: "getAssignableMerchantsFromCircle",
45
+ outputs: [{ internalType: "address[]", name: "", type: "address[]" }],
46
+ stateMutability: "view",
47
+ type: "function"
48
+ },
49
+ {
50
+ inputs: [
51
+ { internalType: "address", name: "_user", type: "address" },
52
+ { internalType: "bytes32", name: "_nativeCurrency", type: "bytes32" }
53
+ ],
54
+ name: "userTxLimit",
55
+ outputs: [
56
+ { internalType: "uint256", name: "", type: "uint256" },
57
+ { internalType: "uint256", name: "", type: "uint256" }
58
+ ],
59
+ stateMutability: "view",
60
+ type: "function"
61
+ }
62
+ ];
63
+
64
+ // src/contracts/abis/p2p-config-facet.ts
65
+ var p2pConfigFacetAbi = [
66
+ {
67
+ inputs: [
68
+ {
69
+ internalType: "bytes32",
70
+ name: "_currency",
71
+ type: "bytes32"
72
+ }
73
+ ],
74
+ name: "getPriceConfig",
75
+ outputs: [
76
+ {
77
+ components: [
78
+ {
79
+ internalType: "uint256",
80
+ name: "buyPrice",
81
+ type: "uint256"
82
+ },
83
+ {
84
+ internalType: "uint256",
85
+ name: "sellPrice",
86
+ type: "uint256"
87
+ },
88
+ {
89
+ internalType: "int256",
90
+ name: "buyPriceOffset",
91
+ type: "int256"
92
+ },
93
+ {
94
+ internalType: "uint256",
95
+ name: "baseSpread",
96
+ type: "uint256"
97
+ }
98
+ ],
99
+ internalType: "struct P2pConfigStorage.PriceConfig",
100
+ name: "",
101
+ type: "tuple"
102
+ }
103
+ ],
104
+ stateMutability: "view",
105
+ type: "function"
106
+ },
107
+ {
108
+ inputs: [
109
+ {
110
+ internalType: "bytes32",
111
+ name: "_nativeCurrency",
112
+ type: "bytes32"
113
+ }
114
+ ],
115
+ name: "getRpPerUsdtLimitRational",
116
+ outputs: [
117
+ {
118
+ internalType: "uint256",
119
+ name: "numerator",
120
+ type: "uint256"
121
+ },
122
+ {
123
+ internalType: "uint256",
124
+ name: "denominator",
125
+ type: "uint256"
126
+ }
127
+ ],
128
+ stateMutability: "view",
129
+ type: "function"
130
+ }
131
+ ];
132
+
133
+ // src/contracts/abis/reputation-manager.ts
134
+ var reputationManagerAbi = [
135
+ {
136
+ inputs: [
137
+ {
138
+ internalType: "string",
139
+ name: "_socialName",
140
+ type: "string"
141
+ },
142
+ {
143
+ components: [
144
+ {
145
+ components: [
146
+ {
147
+ internalType: "string",
148
+ name: "provider",
149
+ type: "string"
150
+ },
151
+ {
152
+ internalType: "string",
153
+ name: "parameters",
154
+ type: "string"
155
+ },
156
+ {
157
+ internalType: "string",
158
+ name: "context",
159
+ type: "string"
160
+ }
161
+ ],
162
+ internalType: "struct IReclaimSDK.ClaimInfo",
163
+ name: "claimInfo",
164
+ type: "tuple"
165
+ },
166
+ {
167
+ components: [
168
+ {
169
+ components: [
170
+ {
171
+ internalType: "bytes32",
172
+ name: "identifier",
173
+ type: "bytes32"
174
+ },
175
+ {
176
+ internalType: "address",
177
+ name: "owner",
178
+ type: "address"
179
+ },
180
+ {
181
+ internalType: "uint32",
182
+ name: "timestampS",
183
+ type: "uint32"
184
+ },
185
+ {
186
+ internalType: "uint32",
187
+ name: "epoch",
188
+ type: "uint32"
189
+ }
190
+ ],
191
+ internalType: "struct IReclaimSDK.CompleteClaimData",
192
+ name: "claim",
193
+ type: "tuple"
194
+ },
195
+ {
196
+ internalType: "bytes[]",
197
+ name: "signatures",
198
+ type: "bytes[]"
199
+ }
200
+ ],
201
+ internalType: "struct IReclaimSDK.SignedClaim",
202
+ name: "signedClaim",
203
+ type: "tuple"
204
+ }
205
+ ],
206
+ internalType: "struct IReclaimSDK.Proof[]",
207
+ name: "proofs",
208
+ type: "tuple[]"
209
+ }
210
+ ],
211
+ name: "socialVerify",
212
+ outputs: [],
213
+ stateMutability: "nonpayable",
214
+ type: "function"
215
+ },
216
+ {
217
+ inputs: [
218
+ {
219
+ internalType: "uint256",
220
+ name: "nullifierSeed",
221
+ type: "uint256"
222
+ },
223
+ {
224
+ internalType: "uint256",
225
+ name: "nullifier",
226
+ type: "uint256"
227
+ },
228
+ {
229
+ internalType: "uint256",
230
+ name: "timestamp",
231
+ type: "uint256"
232
+ },
233
+ {
234
+ internalType: "uint256",
235
+ name: "signal",
236
+ type: "uint256"
237
+ },
238
+ {
239
+ internalType: "uint256[4]",
240
+ name: "revealArray",
241
+ type: "uint256[4]"
242
+ },
243
+ {
244
+ internalType: "uint256[8]",
245
+ name: "groth16Proof",
246
+ type: "uint256[8]"
247
+ }
248
+ ],
249
+ name: "submitAnonAadharProof",
250
+ outputs: [],
251
+ stateMutability: "nonpayable",
252
+ type: "function"
253
+ },
254
+ {
255
+ inputs: [
256
+ {
257
+ components: [
258
+ {
259
+ internalType: "bytes32",
260
+ name: "version",
261
+ type: "bytes32"
262
+ },
263
+ {
264
+ components: [
265
+ {
266
+ internalType: "bytes32",
267
+ name: "vkeyHash",
268
+ type: "bytes32"
269
+ },
270
+ {
271
+ internalType: "bytes",
272
+ name: "proof",
273
+ type: "bytes"
274
+ },
275
+ {
276
+ internalType: "bytes32[]",
277
+ name: "publicInputs",
278
+ type: "bytes32[]"
279
+ }
280
+ ],
281
+ internalType: "struct ProofVerificationData",
282
+ name: "proofVerificationData",
283
+ type: "tuple"
284
+ },
285
+ {
286
+ internalType: "bytes",
287
+ name: "committedInputs",
288
+ type: "bytes"
289
+ },
290
+ {
291
+ components: [
292
+ {
293
+ internalType: "uint256",
294
+ name: "validityPeriodInSeconds",
295
+ type: "uint256"
296
+ },
297
+ {
298
+ internalType: "string",
299
+ name: "domain",
300
+ type: "string"
301
+ },
302
+ {
303
+ internalType: "string",
304
+ name: "scope",
305
+ type: "string"
306
+ },
307
+ {
308
+ internalType: "bool",
309
+ name: "devMode",
310
+ type: "bool"
311
+ }
312
+ ],
313
+ internalType: "struct ServiceConfig",
314
+ name: "serviceConfig",
315
+ type: "tuple"
316
+ }
317
+ ],
318
+ internalType: "struct ProofVerificationParams",
319
+ name: "params",
320
+ type: "tuple"
321
+ },
322
+ {
323
+ internalType: "bool",
324
+ name: "isIDCard",
325
+ type: "bool"
326
+ }
327
+ ],
328
+ name: "zkPassportRegister",
329
+ outputs: [],
330
+ stateMutability: "nonpayable",
331
+ type: "function"
332
+ }
333
+ ];
334
+
335
+ // src/contracts/abis/index.ts
336
+ var DIAMOND_ABI = [...orderFlowFacetAbi, ...p2pConfigFacetAbi];
337
+ var ABIS = {
338
+ DIAMOND: DIAMOND_ABI,
339
+ FACETS: {
340
+ ORDER_FLOW: orderFlowFacetAbi,
341
+ CONFIG: p2pConfigFacetAbi
342
+ },
343
+ EXTERNAL: {
344
+ USDC: import_viem.erc20Abi,
345
+ REPUTATION_MANAGER: reputationManagerAbi
346
+ }
347
+ };
348
+
349
+ // src/contracts/order-flow/index.ts
350
+ var import_neverthrow2 = require("neverthrow");
351
+
352
+ // src/validation/errors.ts
353
+ var SdkError = class extends Error {
354
+ code;
355
+ cause;
356
+ context;
357
+ constructor(message, options) {
358
+ super(message);
359
+ this.name = "SdkError";
360
+ this.code = options.code;
361
+ this.cause = options.cause;
362
+ this.context = options.context;
363
+ }
364
+ };
365
+
366
+ // src/validation/schemas.ts
367
+ var import_neverthrow = require("neverthrow");
368
+ var import_viem2 = require("viem");
369
+ var import_zod = require("zod");
370
+ var ZodAddressSchema = import_zod.z.string().refine((s) => (0, import_viem2.isAddress)(s), { message: "Invalid Ethereum address" });
371
+ var ZodCurrencySchema = import_zod.z.enum([
372
+ "IDR",
373
+ "INR",
374
+ "BRL",
375
+ "ARS",
376
+ "MEX",
377
+ "VEN",
378
+ "EUR",
379
+ "NGN",
380
+ "USD"
381
+ ]);
382
+ function validate(schema, data, toError) {
383
+ const result = schema.safeParse(data);
384
+ if (result.success) {
385
+ return (0, import_neverthrow.ok)(result.data);
386
+ }
387
+ return (0, import_neverthrow.err)(toError(import_zod.z.prettifyError(result.error), result.error, data));
388
+ }
389
+
390
+ // src/order-routing/validation.ts
391
+ var import_zod2 = require("zod");
392
+ var ZodCircleScoreStateSchema = import_zod2.z.object({
393
+ activeMerchantsCount: import_zod2.z.coerce.number()
394
+ });
395
+ var ZodCircleMetricsForRoutingSchema = import_zod2.z.object({
396
+ circleScore: import_zod2.z.coerce.number(),
397
+ circleStatus: import_zod2.z.string(),
398
+ scoreState: ZodCircleScoreStateSchema
399
+ });
400
+ var ZodCircleForRoutingSchema = import_zod2.z.object({
401
+ circleId: import_zod2.z.string(),
402
+ currency: import_zod2.z.string(),
403
+ metrics: ZodCircleMetricsForRoutingSchema
404
+ });
405
+ var ZodCirclesForRoutingResponseSchema = import_zod2.z.object({
406
+ circles: import_zod2.z.array(ZodCircleForRoutingSchema)
407
+ });
408
+ var ZodCheckCircleEligibilityParamsSchema = import_zod2.z.object({
409
+ circleId: import_zod2.z.bigint(),
410
+ currency: import_zod2.z.string(),
411
+ user: ZodAddressSchema,
412
+ usdtAmount: import_zod2.z.bigint(),
413
+ fiatAmount: import_zod2.z.bigint(),
414
+ orderType: import_zod2.z.bigint(),
415
+ preferredPCConfigId: import_zod2.z.bigint()
416
+ });
417
+ var ZodSelectCircleParamsSchema = import_zod2.z.object({
418
+ currency: import_zod2.z.string().min(1),
419
+ user: ZodAddressSchema,
420
+ usdtAmount: import_zod2.z.bigint(),
421
+ fiatAmount: import_zod2.z.bigint(),
422
+ orderType: import_zod2.z.bigint(),
423
+ preferredPCConfigId: import_zod2.z.bigint()
424
+ });
425
+
426
+ // src/contracts/p2p-config/index.ts
427
+ var import_neverthrow3 = require("neverthrow");
428
+ var import_viem3 = require("viem");
429
+
430
+ // src/profile/errors.ts
431
+ var ProfileError = class extends SdkError {
432
+ constructor(message, options) {
433
+ super(message, options);
434
+ this.name = "ProfileError";
435
+ }
436
+ };
437
+
438
+ // src/profile/validation.ts
439
+ var import_zod3 = require("zod");
440
+ var ZodUsdcBalanceParamsSchema = import_zod3.z.object({
441
+ address: ZodAddressSchema
442
+ });
443
+ var ZodGetBalancesParamsSchema = import_zod3.z.object({
444
+ address: ZodAddressSchema,
445
+ currency: ZodCurrencySchema
446
+ });
447
+ var ZodTxLimitsParamsSchema = import_zod3.z.object({
448
+ address: ZodAddressSchema,
449
+ currency: ZodCurrencySchema
450
+ });
451
+ var ZodPriceConfigParamsSchema = import_zod3.z.object({
452
+ currency: ZodCurrencySchema
453
+ });
454
+
455
+ // src/contracts/p2p-config/index.ts
456
+ function getPriceConfig(publicClient, diamondAddress, params) {
457
+ return validate(
458
+ ZodPriceConfigParamsSchema,
459
+ params,
460
+ (message, cause, data) => new ProfileError(message, {
461
+ code: "VALIDATION_ERROR",
462
+ cause,
463
+ context: { params: data }
464
+ })
465
+ ).asyncAndThen(
466
+ (validated) => import_neverthrow3.ResultAsync.fromPromise(
467
+ publicClient.readContract({
468
+ address: diamondAddress,
469
+ abi: ABIS.FACETS.CONFIG,
470
+ functionName: "getPriceConfig",
471
+ args: [(0, import_viem3.stringToHex)(validated.currency, { size: 32 })]
472
+ }),
473
+ (error) => new ProfileError("Failed to read price config", {
474
+ code: "CONTRACT_READ_ERROR",
475
+ cause: error,
476
+ context: { currency: validated.currency, diamondAddress }
477
+ })
478
+ )
479
+ );
480
+ }
481
+
482
+ // src/contracts/reputation-manager/writes.ts
483
+ var import_neverthrow4 = require("neverthrow");
484
+ var import_viem4 = require("viem");
485
+
486
+ // src/zkkyc/validation.ts
487
+ var import_zod4 = require("zod");
488
+ var ZodAnonAadharProofParamsSchema = import_zod4.z.object({
489
+ nullifierSeed: import_zod4.z.bigint(),
490
+ nullifier: import_zod4.z.bigint(),
491
+ timestamp: import_zod4.z.bigint(),
492
+ signal: import_zod4.z.bigint(),
493
+ revealArray: import_zod4.z.tuple([import_zod4.z.bigint(), import_zod4.z.bigint(), import_zod4.z.bigint(), import_zod4.z.bigint()]),
494
+ packedGroth16Proof: import_zod4.z.tuple([
495
+ import_zod4.z.bigint(),
496
+ import_zod4.z.bigint(),
497
+ import_zod4.z.bigint(),
498
+ import_zod4.z.bigint(),
499
+ import_zod4.z.bigint(),
500
+ import_zod4.z.bigint(),
501
+ import_zod4.z.bigint(),
502
+ import_zod4.z.bigint()
503
+ ])
504
+ });
505
+ var ZodSocialVerifyParamsSchema = import_zod4.z.object({
506
+ _socialName: import_zod4.z.string(),
507
+ proofs: import_zod4.z.array(
508
+ import_zod4.z.object({
509
+ claimInfo: import_zod4.z.object({
510
+ provider: import_zod4.z.string(),
511
+ parameters: import_zod4.z.string(),
512
+ context: import_zod4.z.string()
513
+ }),
514
+ signedClaim: import_zod4.z.object({
515
+ claim: import_zod4.z.object({
516
+ identifier: import_zod4.z.string(),
517
+ owner: ZodAddressSchema,
518
+ timestampS: import_zod4.z.number(),
519
+ epoch: import_zod4.z.number()
520
+ }),
521
+ signatures: import_zod4.z.array(import_zod4.z.string())
522
+ })
523
+ })
524
+ )
525
+ });
526
+ var ZodSolidityVerifierParametersSchema = import_zod4.z.object({
527
+ version: import_zod4.z.string().refine((val) => val.startsWith("0x"), {
528
+ message: "Version must be a hex string"
529
+ }),
530
+ proofVerificationData: import_zod4.z.object({
531
+ vkeyHash: import_zod4.z.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
532
+ message: "Invalid bytes32 hex string"
533
+ }),
534
+ proof: import_zod4.z.string().refine((val) => val.startsWith("0x"), {
535
+ message: "Proof must be a hex string"
536
+ }),
537
+ publicInputs: import_zod4.z.array(
538
+ import_zod4.z.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
539
+ message: "Each public input must be a valid bytes32 hex string"
540
+ })
541
+ )
542
+ }),
543
+ committedInputs: import_zod4.z.string().refine((val) => val.startsWith("0x"), {
544
+ message: "Committed inputs must be a hex string"
545
+ }),
546
+ serviceConfig: import_zod4.z.object({
547
+ validityPeriodInSeconds: import_zod4.z.number().int().nonnegative(),
548
+ domain: import_zod4.z.string(),
549
+ scope: import_zod4.z.string(),
550
+ devMode: import_zod4.z.boolean()
551
+ })
552
+ });
553
+ var ZodZkPassportRegisterParamsSchema = import_zod4.z.object({
554
+ params: ZodSolidityVerifierParametersSchema,
555
+ isIDCard: import_zod4.z.boolean()
556
+ });
557
+
558
+ // src/contracts/tx-limits/index.ts
559
+ var import_neverthrow5 = require("neverthrow");
560
+ var import_viem5 = require("viem");
561
+ function getTxLimits(publicClient, diamondAddress, params) {
562
+ return validate(
563
+ ZodTxLimitsParamsSchema,
564
+ params,
565
+ (message, cause, data) => new ProfileError(message, {
566
+ code: "VALIDATION_ERROR",
567
+ cause,
568
+ context: { params: data }
569
+ })
570
+ ).asyncAndThen(
571
+ (validated) => import_neverthrow5.ResultAsync.fromPromise(
572
+ publicClient.readContract({
573
+ address: diamondAddress,
574
+ abi: ABIS.FACETS.ORDER_FLOW,
575
+ functionName: "userTxLimit",
576
+ args: [validated.address, (0, import_viem5.stringToHex)(validated.currency, { size: 32 })]
577
+ }),
578
+ (error) => new ProfileError("Failed to read tx limits", {
579
+ code: "CONTRACT_READ_ERROR",
580
+ cause: error,
581
+ context: { address: validated.address, currency: validated.currency, diamondAddress }
582
+ })
583
+ ).map(([buyLimit, sellLimit]) => ({
584
+ buyLimit: Number((0, import_viem5.formatUnits)(buyLimit, 6)),
585
+ sellLimit: Number((0, import_viem5.formatUnits)(sellLimit, 6))
586
+ }))
587
+ );
588
+ }
589
+ function getRpPerUsdtLimitRational(publicClient, diamondAddress, params) {
590
+ return validate(
591
+ ZodPriceConfigParamsSchema,
592
+ params,
593
+ (message, cause, data) => new ProfileError(message, {
594
+ code: "VALIDATION_ERROR",
595
+ cause,
596
+ context: { params: data }
597
+ })
598
+ ).asyncAndThen(
599
+ (validated) => import_neverthrow5.ResultAsync.fromPromise(
600
+ publicClient.readContract({
601
+ address: diamondAddress,
602
+ abi: ABIS.DIAMOND,
603
+ functionName: "getRpPerUsdtLimitRational",
604
+ args: [(0, import_viem5.stringToHex)(validated.currency, { size: 32 })]
605
+ }),
606
+ (error) => new ProfileError("Failed to read RP per USDT limit rational", {
607
+ code: "CONTRACT_READ_ERROR",
608
+ cause: error,
609
+ context: { currency: validated.currency, diamondAddress }
610
+ })
611
+ ).map(([numerator, denominator]) => ({
612
+ numerator,
613
+ denominator,
614
+ multiplier: numerator > 0n ? Number(denominator) / Number(numerator) : 0
615
+ }))
616
+ );
617
+ }
618
+
619
+ // src/contracts/usdc/index.ts
620
+ var import_neverthrow6 = require("neverthrow");
621
+ function getUsdcBalance(publicClient, usdcAddress, params) {
622
+ return validate(
623
+ ZodUsdcBalanceParamsSchema,
624
+ params,
625
+ (message, cause, data) => new ProfileError(message, {
626
+ code: "VALIDATION_ERROR",
627
+ cause,
628
+ context: { params: data }
629
+ })
630
+ ).asyncAndThen(
631
+ (validated) => import_neverthrow6.ResultAsync.fromPromise(
632
+ publicClient.readContract({
633
+ address: usdcAddress,
634
+ abi: ABIS.EXTERNAL.USDC,
635
+ functionName: "balanceOf",
636
+ args: [validated.address]
637
+ }),
638
+ (error) => new ProfileError("Failed to read USDC balance", {
639
+ code: "CONTRACT_READ_ERROR",
640
+ cause: error,
641
+ context: { address: validated.address, usdcAddress }
642
+ })
643
+ )
644
+ );
645
+ }
646
+
647
+ // src/profile/contracts/actions.ts
648
+ var import_neverthrow7 = require("neverthrow");
649
+ var import_viem6 = require("viem");
650
+ function getBalances(publicClient, usdcAddress, diamondAddress, params) {
651
+ return validate(
652
+ ZodGetBalancesParamsSchema,
653
+ params,
654
+ (message, cause, data) => new ProfileError(message, {
655
+ code: "VALIDATION_ERROR",
656
+ cause,
657
+ context: { params: data }
658
+ })
659
+ ).asyncAndThen(
660
+ (validated) => import_neverthrow7.ResultAsync.combine([
661
+ getUsdcBalance(publicClient, usdcAddress, {
662
+ address: validated.address
663
+ }),
664
+ getPriceConfig(publicClient, diamondAddress, {
665
+ currency: validated.currency
666
+ })
667
+ ]).map(([usdc, priceConfig]) => {
668
+ const usdcFormatted = Number((0, import_viem6.formatUnits)(usdc, 6));
669
+ const sellPriceFormatted = Number((0, import_viem6.formatUnits)(priceConfig.sellPrice, 6));
670
+ return {
671
+ usdc: usdcFormatted,
672
+ fiat: usdcFormatted * sellPriceFormatted,
673
+ sellPrice: sellPriceFormatted
674
+ };
675
+ })
676
+ );
677
+ }
678
+
679
+ // src/profile/client.ts
680
+ function createProfile(config) {
681
+ const { publicClient, diamondAddress, usdcAddress } = config;
682
+ return {
683
+ getUsdcBalance: (params) => getUsdcBalance(publicClient, usdcAddress, params),
684
+ getPriceConfig: (params) => getPriceConfig(publicClient, diamondAddress, params),
685
+ getBalances: (params) => getBalances(publicClient, usdcAddress, diamondAddress, params),
686
+ getTxLimits: (params) => getTxLimits(publicClient, diamondAddress, params),
687
+ getRpPerUsdtLimitRational: (params) => getRpPerUsdtLimitRational(publicClient, diamondAddress, params)
688
+ };
689
+ }
690
+ // Annotate the CommonJS export names for ESM import in node:
691
+ 0 && (module.exports = {
692
+ ProfileError,
693
+ createProfile
694
+ });
695
+ //# sourceMappingURL=profile.cjs.map