@p2pdotme/sdk 1.0.5 → 1.1.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 (64) hide show
  1. package/README.md +71 -41
  2. package/dist/country.cjs +8 -1
  3. package/dist/country.cjs.map +1 -1
  4. package/dist/country.d.cts +35 -10
  5. package/dist/country.d.ts +35 -10
  6. package/dist/country.mjs +5 -1
  7. package/dist/country.mjs.map +1 -1
  8. package/dist/fraud-engine.cjs +52 -48
  9. package/dist/fraud-engine.cjs.map +1 -1
  10. package/dist/fraud-engine.mjs +46 -42
  11. package/dist/fraud-engine.mjs.map +1 -1
  12. package/dist/index.cjs +4 -14
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +41 -36
  15. package/dist/index.d.ts +41 -36
  16. package/dist/index.mjs +4 -12
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/{payload.cjs → orders.cjs} +2357 -253
  19. package/dist/orders.cjs.map +1 -0
  20. package/dist/orders.d.cts +399 -0
  21. package/dist/orders.d.ts +399 -0
  22. package/dist/{payload.mjs → orders.mjs} +2340 -237
  23. package/dist/orders.mjs.map +1 -0
  24. package/dist/prices.cjs +1008 -0
  25. package/dist/prices.cjs.map +1 -0
  26. package/dist/prices.d.cts +109 -0
  27. package/dist/prices.d.ts +109 -0
  28. package/dist/prices.mjs +980 -0
  29. package/dist/prices.mjs.map +1 -0
  30. package/dist/profile.cjs +475 -69
  31. package/dist/profile.cjs.map +1 -1
  32. package/dist/profile.d.cts +39 -27
  33. package/dist/profile.d.ts +39 -27
  34. package/dist/profile.mjs +468 -62
  35. package/dist/profile.mjs.map +1 -1
  36. package/dist/qr-parsers.cjs +6 -6
  37. package/dist/qr-parsers.cjs.map +1 -1
  38. package/dist/qr-parsers.d.cts +38 -16
  39. package/dist/qr-parsers.d.ts +38 -16
  40. package/dist/qr-parsers.mjs +6 -6
  41. package/dist/qr-parsers.mjs.map +1 -1
  42. package/dist/react.cjs +2531 -1105
  43. package/dist/react.cjs.map +1 -1
  44. package/dist/react.d.cts +384 -104
  45. package/dist/react.d.ts +384 -104
  46. package/dist/react.mjs +2417 -992
  47. package/dist/react.mjs.map +1 -1
  48. package/dist/zkkyc.cjs +405 -24
  49. package/dist/zkkyc.cjs.map +1 -1
  50. package/dist/zkkyc.d.cts +14 -9
  51. package/dist/zkkyc.d.ts +14 -9
  52. package/dist/zkkyc.mjs +405 -24
  53. package/dist/zkkyc.mjs.map +1 -1
  54. package/package.json +12 -12
  55. package/dist/order-routing.cjs +0 -888
  56. package/dist/order-routing.cjs.map +0 -1
  57. package/dist/order-routing.d.cts +0 -68
  58. package/dist/order-routing.d.ts +0 -68
  59. package/dist/order-routing.mjs +0 -860
  60. package/dist/order-routing.mjs.map +0 -1
  61. package/dist/payload.cjs.map +0 -1
  62. package/dist/payload.d.cts +0 -147
  63. package/dist/payload.d.ts +0 -147
  64. package/dist/payload.mjs.map +0 -1
package/dist/profile.mjs CHANGED
@@ -31,6 +31,381 @@ var orderFlowFacetAbi = [
31
31
  ],
32
32
  stateMutability: "view",
33
33
  type: "function"
34
+ },
35
+ {
36
+ inputs: [
37
+ { internalType: "string", name: "_pubKey", type: "string" },
38
+ { internalType: "uint256", name: "_amount", type: "uint256" },
39
+ { internalType: "address", name: "_recipientAddr", type: "address" },
40
+ { internalType: "uint8", name: "_orderType", type: "uint8" },
41
+ { internalType: "string", name: "_userUpi", type: "string" },
42
+ { internalType: "string", name: "_userPubKey", type: "string" },
43
+ { internalType: "bytes32", name: "_currency", type: "bytes32" },
44
+ { internalType: "uint256", name: "preferredPaymentChannelConfigId", type: "uint256" },
45
+ { internalType: "uint256", name: "_circleId", type: "uint256" },
46
+ { internalType: "uint256", name: "_fiatAmountLimit", type: "uint256" }
47
+ ],
48
+ name: "placeOrder",
49
+ outputs: [],
50
+ stateMutability: "nonpayable",
51
+ type: "function"
52
+ },
53
+ {
54
+ inputs: [{ internalType: "uint256", name: "_orderId", type: "uint256" }],
55
+ name: "cancelOrder",
56
+ outputs: [],
57
+ stateMutability: "nonpayable",
58
+ type: "function"
59
+ },
60
+ {
61
+ inputs: [
62
+ { internalType: "uint256", name: "_orderId", type: "uint256" },
63
+ { internalType: "string", name: "_userEncUpi", type: "string" },
64
+ { internalType: "uint256", name: "_updatedAmount", type: "uint256" }
65
+ ],
66
+ name: "setSellOrderUpi",
67
+ outputs: [],
68
+ stateMutability: "nonpayable",
69
+ type: "function"
70
+ },
71
+ {
72
+ type: "event",
73
+ name: "OrderPlaced",
74
+ anonymous: false,
75
+ inputs: [
76
+ { indexed: true, name: "orderId", type: "uint256" },
77
+ { indexed: true, name: "user", type: "address" },
78
+ { indexed: true, name: "merchant", type: "address" },
79
+ { indexed: false, name: "amount", type: "uint256" },
80
+ { indexed: false, name: "orderType", type: "uint8" },
81
+ { indexed: false, name: "placedTimestamp", type: "uint256" },
82
+ {
83
+ indexed: false,
84
+ name: "_order",
85
+ type: "tuple",
86
+ components: [
87
+ { name: "amount", type: "uint256" },
88
+ { name: "fiatAmount", type: "uint256" },
89
+ { name: "placedTimestamp", type: "uint256" },
90
+ { name: "completedTimestamp", type: "uint256" },
91
+ { name: "userCompletedTimestamp", type: "uint256" },
92
+ { name: "acceptedMerchant", type: "address" },
93
+ { name: "user", type: "address" },
94
+ { name: "recipientAddr", type: "address" },
95
+ { name: "pubkey", type: "string" },
96
+ { name: "encUpi", type: "string" },
97
+ { name: "userCompleted", type: "bool" },
98
+ { name: "status", type: "uint8" },
99
+ { name: "orderType", type: "uint8" },
100
+ {
101
+ name: "disputeInfo",
102
+ type: "tuple",
103
+ components: [
104
+ { name: "raisedBy", type: "uint8" },
105
+ { name: "status", type: "uint8" },
106
+ { name: "redactTransId", type: "uint256" },
107
+ { name: "accountNumber", type: "uint256" }
108
+ ]
109
+ },
110
+ { name: "id", type: "uint256" },
111
+ { name: "userPubKey", type: "string" },
112
+ { name: "encMerchantUpi", type: "string" },
113
+ { name: "acceptedAccountNo", type: "uint256" },
114
+ { name: "assignedAccountNos", type: "uint256[]" },
115
+ { name: "currency", type: "bytes32" },
116
+ { name: "preferredPaymentChannelConfigId", type: "uint256" },
117
+ { name: "circleId", type: "uint256" }
118
+ ]
119
+ }
120
+ ]
121
+ },
122
+ {
123
+ type: "event",
124
+ name: "OrderAccepted",
125
+ anonymous: false,
126
+ inputs: [
127
+ { indexed: true, name: "orderId", type: "uint256" },
128
+ { indexed: true, name: "merchant", type: "address" },
129
+ { indexed: false, name: "pubKey", type: "string" },
130
+ {
131
+ indexed: false,
132
+ name: "_order",
133
+ type: "tuple",
134
+ components: [
135
+ { name: "amount", type: "uint256" },
136
+ { name: "fiatAmount", type: "uint256" },
137
+ { name: "placedTimestamp", type: "uint256" },
138
+ { name: "completedTimestamp", type: "uint256" },
139
+ { name: "userCompletedTimestamp", type: "uint256" },
140
+ { name: "acceptedMerchant", type: "address" },
141
+ { name: "user", type: "address" },
142
+ { name: "recipientAddr", type: "address" },
143
+ { name: "pubkey", type: "string" },
144
+ { name: "encUpi", type: "string" },
145
+ { name: "userCompleted", type: "bool" },
146
+ { name: "status", type: "uint8" },
147
+ { name: "orderType", type: "uint8" },
148
+ {
149
+ name: "disputeInfo",
150
+ type: "tuple",
151
+ components: [
152
+ { name: "raisedBy", type: "uint8" },
153
+ { name: "status", type: "uint8" },
154
+ { name: "redactTransId", type: "uint256" },
155
+ { name: "accountNumber", type: "uint256" }
156
+ ]
157
+ },
158
+ { name: "id", type: "uint256" },
159
+ { name: "userPubKey", type: "string" },
160
+ { name: "encMerchantUpi", type: "string" },
161
+ { name: "acceptedAccountNo", type: "uint256" },
162
+ { name: "assignedAccountNos", type: "uint256[]" },
163
+ { name: "currency", type: "bytes32" },
164
+ { name: "preferredPaymentChannelConfigId", type: "uint256" },
165
+ { name: "circleId", type: "uint256" }
166
+ ]
167
+ }
168
+ ]
169
+ },
170
+ {
171
+ type: "event",
172
+ name: "BuyOrderPaid",
173
+ anonymous: false,
174
+ inputs: [
175
+ { indexed: true, name: "orderId", type: "uint256" },
176
+ { indexed: true, name: "user", type: "address" },
177
+ {
178
+ indexed: false,
179
+ name: "_order",
180
+ type: "tuple",
181
+ components: [
182
+ { name: "amount", type: "uint256" },
183
+ { name: "fiatAmount", type: "uint256" },
184
+ { name: "placedTimestamp", type: "uint256" },
185
+ { name: "completedTimestamp", type: "uint256" },
186
+ { name: "userCompletedTimestamp", type: "uint256" },
187
+ { name: "acceptedMerchant", type: "address" },
188
+ { name: "user", type: "address" },
189
+ { name: "recipientAddr", type: "address" },
190
+ { name: "pubkey", type: "string" },
191
+ { name: "encUpi", type: "string" },
192
+ { name: "userCompleted", type: "bool" },
193
+ { name: "status", type: "uint8" },
194
+ { name: "orderType", type: "uint8" },
195
+ {
196
+ name: "disputeInfo",
197
+ type: "tuple",
198
+ components: [
199
+ { name: "raisedBy", type: "uint8" },
200
+ { name: "status", type: "uint8" },
201
+ { name: "redactTransId", type: "uint256" },
202
+ { name: "accountNumber", type: "uint256" }
203
+ ]
204
+ },
205
+ { name: "id", type: "uint256" },
206
+ { name: "userPubKey", type: "string" },
207
+ { name: "encMerchantUpi", type: "string" },
208
+ { name: "acceptedAccountNo", type: "uint256" },
209
+ { name: "assignedAccountNos", type: "uint256[]" },
210
+ { name: "currency", type: "bytes32" },
211
+ { name: "preferredPaymentChannelConfigId", type: "uint256" },
212
+ { name: "circleId", type: "uint256" }
213
+ ]
214
+ }
215
+ ]
216
+ },
217
+ {
218
+ type: "event",
219
+ name: "OrderCompleted",
220
+ anonymous: false,
221
+ inputs: [
222
+ { indexed: true, name: "orderId", type: "uint256" },
223
+ { indexed: true, name: "user", type: "address" },
224
+ { indexed: false, name: "completedTimestamp", type: "uint256" },
225
+ {
226
+ indexed: false,
227
+ name: "_order",
228
+ type: "tuple",
229
+ components: [
230
+ { name: "amount", type: "uint256" },
231
+ { name: "fiatAmount", type: "uint256" },
232
+ { name: "placedTimestamp", type: "uint256" },
233
+ { name: "completedTimestamp", type: "uint256" },
234
+ { name: "userCompletedTimestamp", type: "uint256" },
235
+ { name: "acceptedMerchant", type: "address" },
236
+ { name: "user", type: "address" },
237
+ { name: "recipientAddr", type: "address" },
238
+ { name: "pubkey", type: "string" },
239
+ { name: "encUpi", type: "string" },
240
+ { name: "userCompleted", type: "bool" },
241
+ { name: "status", type: "uint8" },
242
+ { name: "orderType", type: "uint8" },
243
+ {
244
+ name: "disputeInfo",
245
+ type: "tuple",
246
+ components: [
247
+ { name: "raisedBy", type: "uint8" },
248
+ { name: "status", type: "uint8" },
249
+ { name: "redactTransId", type: "uint256" },
250
+ { name: "accountNumber", type: "uint256" }
251
+ ]
252
+ },
253
+ { name: "id", type: "uint256" },
254
+ { name: "userPubKey", type: "string" },
255
+ { name: "encMerchantUpi", type: "string" },
256
+ { name: "acceptedAccountNo", type: "uint256" },
257
+ { name: "assignedAccountNos", type: "uint256[]" },
258
+ { name: "currency", type: "bytes32" },
259
+ { name: "preferredPaymentChannelConfigId", type: "uint256" },
260
+ { name: "circleId", type: "uint256" }
261
+ ]
262
+ }
263
+ ]
264
+ },
265
+ {
266
+ type: "event",
267
+ name: "CancelledOrders",
268
+ anonymous: false,
269
+ inputs: [
270
+ { indexed: true, name: "orderId", type: "uint256" },
271
+ {
272
+ indexed: false,
273
+ name: "_order",
274
+ type: "tuple",
275
+ components: [
276
+ { name: "amount", type: "uint256" },
277
+ { name: "fiatAmount", type: "uint256" },
278
+ { name: "placedTimestamp", type: "uint256" },
279
+ { name: "completedTimestamp", type: "uint256" },
280
+ { name: "userCompletedTimestamp", type: "uint256" },
281
+ { name: "acceptedMerchant", type: "address" },
282
+ { name: "user", type: "address" },
283
+ { name: "recipientAddr", type: "address" },
284
+ { name: "pubkey", type: "string" },
285
+ { name: "encUpi", type: "string" },
286
+ { name: "userCompleted", type: "bool" },
287
+ { name: "status", type: "uint8" },
288
+ { name: "orderType", type: "uint8" },
289
+ {
290
+ name: "disputeInfo",
291
+ type: "tuple",
292
+ components: [
293
+ { name: "raisedBy", type: "uint8" },
294
+ { name: "status", type: "uint8" },
295
+ { name: "redactTransId", type: "uint256" },
296
+ { name: "accountNumber", type: "uint256" }
297
+ ]
298
+ },
299
+ { name: "id", type: "uint256" },
300
+ { name: "userPubKey", type: "string" },
301
+ { name: "encMerchantUpi", type: "string" },
302
+ { name: "acceptedAccountNo", type: "uint256" },
303
+ { name: "assignedAccountNos", type: "uint256[]" },
304
+ { name: "currency", type: "bytes32" },
305
+ { name: "preferredPaymentChannelConfigId", type: "uint256" },
306
+ { name: "circleId", type: "uint256" }
307
+ ]
308
+ }
309
+ ]
310
+ }
311
+ ];
312
+
313
+ // src/contracts/abis/order-processor-facet.ts
314
+ var orderProcessorFacetAbi = [
315
+ {
316
+ type: "function",
317
+ name: "getOrdersById",
318
+ stateMutability: "view",
319
+ inputs: [{ name: "orderId", type: "uint256" }],
320
+ outputs: [
321
+ {
322
+ type: "tuple",
323
+ components: [
324
+ { name: "amount", type: "uint256" },
325
+ { name: "fiatAmount", type: "uint256" },
326
+ { name: "placedTimestamp", type: "uint256" },
327
+ { name: "completedTimestamp", type: "uint256" },
328
+ { name: "userCompletedTimestamp", type: "uint256" },
329
+ { name: "acceptedMerchant", type: "address" },
330
+ { name: "user", type: "address" },
331
+ { name: "recipientAddr", type: "address" },
332
+ { name: "pubkey", type: "string" },
333
+ { name: "encUpi", type: "string" },
334
+ { name: "userCompleted", type: "bool" },
335
+ { name: "status", type: "uint8" },
336
+ { name: "orderType", type: "uint8" },
337
+ {
338
+ name: "disputeInfo",
339
+ type: "tuple",
340
+ components: [
341
+ { name: "raisedBy", type: "uint8" },
342
+ { name: "status", type: "uint8" },
343
+ { name: "redactTransId", type: "uint256" },
344
+ { name: "accountNumber", type: "uint256" }
345
+ ]
346
+ },
347
+ { name: "id", type: "uint256" },
348
+ { name: "userPubKey", type: "string" },
349
+ { name: "encMerchantUpi", type: "string" },
350
+ { name: "acceptedAccountNo", type: "uint256" },
351
+ { name: "assignedAccountNos", type: "uint256[]" },
352
+ { name: "currency", type: "bytes32" },
353
+ { name: "preferredPaymentChannelConfigId", type: "uint256" },
354
+ { name: "circleId", type: "uint256" }
355
+ ]
356
+ }
357
+ ]
358
+ },
359
+ {
360
+ type: "function",
361
+ name: "getAdditionalOrderDetails",
362
+ stateMutability: "view",
363
+ inputs: [{ name: "orderId", type: "uint256" }],
364
+ outputs: [
365
+ {
366
+ type: "tuple",
367
+ components: [
368
+ { name: "fixedFeePaid", type: "uint64" },
369
+ { name: "tipsPaid", type: "uint64" },
370
+ { name: "acceptedTimestamp", type: "uint128" },
371
+ { name: "paidTimestamp", type: "uint128" },
372
+ { name: "reserved2", type: "uint128" },
373
+ { name: "actualUsdtAmount", type: "uint256" },
374
+ { name: "actualFiatAmount", type: "uint256" }
375
+ ]
376
+ }
377
+ ]
378
+ },
379
+ {
380
+ type: "function",
381
+ name: "getSmallOrderThreshold",
382
+ stateMutability: "view",
383
+ inputs: [{ name: "currency", type: "bytes32" }],
384
+ outputs: [{ name: "", type: "uint256" }]
385
+ },
386
+ {
387
+ type: "function",
388
+ name: "getSmallOrderFixedFee",
389
+ stateMutability: "view",
390
+ inputs: [{ name: "currency", type: "bytes32" }],
391
+ outputs: [{ name: "", type: "uint256" }]
392
+ },
393
+ {
394
+ type: "function",
395
+ name: "raiseDispute",
396
+ stateMutability: "nonpayable",
397
+ inputs: [
398
+ { name: "_orderId", type: "uint256" },
399
+ { name: "redactTransId", type: "uint256" }
400
+ ],
401
+ outputs: []
402
+ },
403
+ {
404
+ type: "function",
405
+ name: "paidBuyOrder",
406
+ stateMutability: "nonpayable",
407
+ inputs: [{ name: "_orderId", type: "uint256" }],
408
+ outputs: []
34
409
  }
35
410
  ];
36
411
 
@@ -306,11 +681,16 @@ var reputationManagerAbi = [
306
681
  ];
307
682
 
308
683
  // src/contracts/abis/index.ts
309
- var DIAMOND_ABI = [...orderFlowFacetAbi, ...p2pConfigFacetAbi];
684
+ var DIAMOND_ABI = [
685
+ ...orderFlowFacetAbi,
686
+ ...orderProcessorFacetAbi,
687
+ ...p2pConfigFacetAbi
688
+ ];
310
689
  var ABIS = {
311
690
  DIAMOND: DIAMOND_ABI,
312
691
  FACETS: {
313
692
  ORDER_FLOW: orderFlowFacetAbi,
693
+ ORDER_PROCESSOR: orderProcessorFacetAbi,
314
694
  CONFIG: p2pConfigFacetAbi
315
695
  },
316
696
  EXTERNAL: {
@@ -320,6 +700,9 @@ var ABIS = {
320
700
  };
321
701
 
322
702
  // src/contracts/order-flow/index.ts
703
+ import { ResultAsync as ResultAsync2 } from "neverthrow";
704
+
705
+ // src/lib/subgraph.ts
323
706
  import { ResultAsync } from "neverthrow";
324
707
 
325
708
  // src/validation/errors.validation.ts
@@ -341,7 +724,7 @@ import { err, ok } from "neverthrow";
341
724
  import { isAddress } from "viem";
342
725
  import { z } from "zod";
343
726
 
344
- // src/constants/currencies.constant.ts
727
+ // src/country/currency.ts
345
728
  var CURRENCY = {
346
729
  IDR: "IDR",
347
730
  INR: "INR",
@@ -354,10 +737,11 @@ var CURRENCY = {
354
737
  USD: "USD",
355
738
  COP: "COP"
356
739
  };
740
+ var CURRENCY_CODES = Object.values(CURRENCY);
357
741
 
358
742
  // src/validation/schemas.validation.ts
359
743
  var ZodAddressSchema = z.string().refine((s) => isAddress(s), { message: "Invalid Ethereum address" });
360
- var ZodCurrencySchema = z.enum(Object.values(CURRENCY));
744
+ var ZodCurrencySchema = z.enum(CURRENCY_CODES);
361
745
  function validate(schema, data, toError) {
362
746
  const result = schema.safeParse(data);
363
747
  if (result.success) {
@@ -366,7 +750,7 @@ function validate(schema, data, toError) {
366
750
  return err(toError(z.prettifyError(result.error), result.error, data));
367
751
  }
368
752
 
369
- // src/order-routing/validation.ts
753
+ // src/orders/internal/routing/validation.ts
370
754
  import { z as z2 } from "zod";
371
755
  var ZodCircleScoreStateSchema = z2.object({
372
756
  activeMerchantsCount: z2.coerce.number()
@@ -402,54 +786,47 @@ var ZodSelectCircleParamsSchema = z2.object({
402
786
  preferredPCConfigId: z2.bigint()
403
787
  });
404
788
 
405
- // src/contracts/p2p-config/index.ts
406
- import { ResultAsync as ResultAsync2 } from "neverthrow";
789
+ // src/contracts/order-processor/index.ts
790
+ import { ResultAsync as ResultAsync3 } from "neverthrow";
407
791
  import { stringToHex } from "viem";
408
792
 
409
- // src/profile/errors.ts
410
- var ProfileError = class extends SdkError {
793
+ // src/contracts/p2p-config/index.ts
794
+ import { ResultAsync as ResultAsync4 } from "neverthrow";
795
+ import { stringToHex as stringToHex2 } from "viem";
796
+
797
+ // src/prices/errors.ts
798
+ var PricesError = class extends SdkError {
411
799
  constructor(message, options) {
412
800
  super(message, options);
413
- this.name = "ProfileError";
801
+ this.name = "PricesError";
414
802
  }
415
803
  };
416
804
 
417
- // src/profile/validation.ts
805
+ // src/prices/validation.ts
418
806
  import { z as z3 } from "zod";
419
- var ZodUsdcBalanceParamsSchema = z3.object({
420
- address: ZodAddressSchema
421
- });
422
- var ZodGetBalancesParamsSchema = z3.object({
423
- address: ZodAddressSchema,
424
- currency: ZodCurrencySchema
425
- });
426
- var ZodTxLimitsParamsSchema = z3.object({
427
- address: ZodAddressSchema,
428
- currency: ZodCurrencySchema
429
- });
430
- var ZodPriceConfigParamsSchema = z3.object({
807
+ var ZodCurrencyScopedParamsSchema = z3.object({
431
808
  currency: ZodCurrencySchema
432
809
  });
433
810
 
434
811
  // src/contracts/p2p-config/index.ts
435
812
  function getPriceConfig(publicClient, diamondAddress, params) {
436
813
  return validate(
437
- ZodPriceConfigParamsSchema,
814
+ ZodCurrencyScopedParamsSchema,
438
815
  params,
439
- (message, cause, data) => new ProfileError(message, {
816
+ (message, cause, data) => new PricesError(message, {
440
817
  code: "VALIDATION_ERROR",
441
818
  cause,
442
819
  context: { params: data }
443
820
  })
444
821
  ).asyncAndThen(
445
- (validated) => ResultAsync2.fromPromise(
822
+ (validated) => ResultAsync4.fromPromise(
446
823
  publicClient.readContract({
447
824
  address: diamondAddress,
448
825
  abi: ABIS.FACETS.CONFIG,
449
826
  functionName: "getPriceConfig",
450
- args: [stringToHex(validated.currency, { size: 32 })]
827
+ args: [stringToHex2(validated.currency, { size: 32 })]
451
828
  }),
452
- (error) => new ProfileError("Failed to read price config", {
829
+ (error) => new PricesError("Failed to read price config", {
453
830
  code: "CONTRACT_READ_ERROR",
454
831
  cause: error,
455
832
  context: { currency: validated.currency, diamondAddress }
@@ -535,8 +912,35 @@ var ZodZkPassportRegisterParamsSchema = z4.object({
535
912
  });
536
913
 
537
914
  // src/contracts/tx-limits/index.ts
538
- import { ResultAsync as ResultAsync3 } from "neverthrow";
539
- import { formatUnits, stringToHex as stringToHex2 } from "viem";
915
+ import { ResultAsync as ResultAsync5 } from "neverthrow";
916
+ import { formatUnits, stringToHex as stringToHex3 } from "viem";
917
+
918
+ // src/profile/errors.ts
919
+ var ProfileError = class extends SdkError {
920
+ constructor(message, options) {
921
+ super(message, options);
922
+ this.name = "ProfileError";
923
+ }
924
+ };
925
+
926
+ // src/profile/validation.ts
927
+ import { z as z5 } from "zod";
928
+ var ZodUsdcBalanceParamsSchema = z5.object({
929
+ address: ZodAddressSchema
930
+ });
931
+ var ZodUsdcAllowanceParamsSchema = z5.object({
932
+ owner: ZodAddressSchema
933
+ });
934
+ var ZodGetBalancesParamsSchema = z5.object({
935
+ address: ZodAddressSchema,
936
+ currency: ZodCurrencySchema
937
+ });
938
+ var ZodTxLimitsParamsSchema = z5.object({
939
+ address: ZodAddressSchema,
940
+ currency: ZodCurrencySchema
941
+ });
942
+
943
+ // src/contracts/tx-limits/index.ts
540
944
  function getTxLimits(publicClient, diamondAddress, params) {
541
945
  return validate(
542
946
  ZodTxLimitsParamsSchema,
@@ -547,12 +951,12 @@ function getTxLimits(publicClient, diamondAddress, params) {
547
951
  context: { params: data }
548
952
  })
549
953
  ).asyncAndThen(
550
- (validated) => ResultAsync3.fromPromise(
954
+ (validated) => ResultAsync5.fromPromise(
551
955
  publicClient.readContract({
552
956
  address: diamondAddress,
553
957
  abi: ABIS.FACETS.ORDER_FLOW,
554
958
  functionName: "userTxLimit",
555
- args: [validated.address, stringToHex2(validated.currency, { size: 32 })]
959
+ args: [validated.address, stringToHex3(validated.currency, { size: 32 })]
556
960
  }),
557
961
  (error) => new ProfileError("Failed to read tx limits", {
558
962
  code: "CONTRACT_READ_ERROR",
@@ -565,9 +969,13 @@ function getTxLimits(publicClient, diamondAddress, params) {
565
969
  }))
566
970
  );
567
971
  }
568
- function getRpPerUsdtLimitRational(publicClient, diamondAddress, params) {
972
+
973
+ // src/contracts/usdc/index.ts
974
+ import { ResultAsync as ResultAsync6 } from "neverthrow";
975
+ import { erc20Abi as erc20Abi2 } from "viem";
976
+ function getUsdcBalance(publicClient, usdcAddress, params) {
569
977
  return validate(
570
- ZodPriceConfigParamsSchema,
978
+ ZodUsdcBalanceParamsSchema,
571
979
  params,
572
980
  (message, cause, data) => new ProfileError(message, {
573
981
  code: "VALIDATION_ERROR",
@@ -575,31 +983,24 @@ function getRpPerUsdtLimitRational(publicClient, diamondAddress, params) {
575
983
  context: { params: data }
576
984
  })
577
985
  ).asyncAndThen(
578
- (validated) => ResultAsync3.fromPromise(
986
+ (validated) => ResultAsync6.fromPromise(
579
987
  publicClient.readContract({
580
- address: diamondAddress,
581
- abi: ABIS.DIAMOND,
582
- functionName: "getRpPerUsdtLimitRational",
583
- args: [stringToHex2(validated.currency, { size: 32 })]
988
+ address: usdcAddress,
989
+ abi: ABIS.EXTERNAL.USDC,
990
+ functionName: "balanceOf",
991
+ args: [validated.address]
584
992
  }),
585
- (error) => new ProfileError("Failed to read RP per USDT limit rational", {
993
+ (error) => new ProfileError("Failed to read USDC balance", {
586
994
  code: "CONTRACT_READ_ERROR",
587
995
  cause: error,
588
- context: { currency: validated.currency, diamondAddress }
996
+ context: { address: validated.address, usdcAddress }
589
997
  })
590
- ).map(([numerator, denominator]) => ({
591
- numerator,
592
- denominator,
593
- multiplier: numerator > 0n ? Number(denominator) / Number(numerator) : 0
594
- }))
998
+ )
595
999
  );
596
1000
  }
597
-
598
- // src/contracts/usdc/index.ts
599
- import { ResultAsync as ResultAsync4 } from "neverthrow";
600
- function getUsdcBalance(publicClient, usdcAddress, params) {
1001
+ function getUsdcAllowance(publicClient, usdcAddress, diamondAddress, params) {
601
1002
  return validate(
602
- ZodUsdcBalanceParamsSchema,
1003
+ ZodUsdcAllowanceParamsSchema,
603
1004
  params,
604
1005
  (message, cause, data) => new ProfileError(message, {
605
1006
  code: "VALIDATION_ERROR",
@@ -607,24 +1008,24 @@ function getUsdcBalance(publicClient, usdcAddress, params) {
607
1008
  context: { params: data }
608
1009
  })
609
1010
  ).asyncAndThen(
610
- (validated) => ResultAsync4.fromPromise(
1011
+ (validated) => ResultAsync6.fromPromise(
611
1012
  publicClient.readContract({
612
1013
  address: usdcAddress,
613
- abi: ABIS.EXTERNAL.USDC,
614
- functionName: "balanceOf",
615
- args: [validated.address]
1014
+ abi: erc20Abi2,
1015
+ functionName: "allowance",
1016
+ args: [validated.owner, diamondAddress]
616
1017
  }),
617
- (error) => new ProfileError("Failed to read USDC balance", {
1018
+ (error) => new ProfileError("Failed to read USDC allowance", {
618
1019
  code: "CONTRACT_READ_ERROR",
619
1020
  cause: error,
620
- context: { address: validated.address, usdcAddress }
1021
+ context: { owner: validated.owner, usdcAddress, diamondAddress }
621
1022
  })
622
1023
  )
623
1024
  );
624
1025
  }
625
1026
 
626
1027
  // src/profile/contracts/actions.ts
627
- import { ResultAsync as ResultAsync5 } from "neverthrow";
1028
+ import { ResultAsync as ResultAsync7 } from "neverthrow";
628
1029
  import { formatUnits as formatUnits2 } from "viem";
629
1030
  function getBalances(publicClient, usdcAddress, diamondAddress, params) {
630
1031
  return validate(
@@ -636,13 +1037,19 @@ function getBalances(publicClient, usdcAddress, diamondAddress, params) {
636
1037
  context: { params: data }
637
1038
  })
638
1039
  ).asyncAndThen(
639
- (validated) => ResultAsync5.combine([
1040
+ (validated) => ResultAsync7.combine([
640
1041
  getUsdcBalance(publicClient, usdcAddress, {
641
1042
  address: validated.address
642
1043
  }),
643
1044
  getPriceConfig(publicClient, diamondAddress, {
644
1045
  currency: validated.currency
645
- })
1046
+ }).mapErr(
1047
+ (cause) => new ProfileError("Failed to read price config for balance conversion", {
1048
+ code: "CONTRACT_READ_ERROR",
1049
+ cause,
1050
+ context: { currency: validated.currency }
1051
+ })
1052
+ )
646
1053
  ]).map(([usdc, priceConfig]) => {
647
1054
  const usdcFormatted = Number(formatUnits2(usdc, 6));
648
1055
  const sellPriceFormatted = Number(formatUnits2(priceConfig.sellPrice, 6));
@@ -660,10 +1067,9 @@ function createProfile(config) {
660
1067
  const { publicClient, diamondAddress, usdcAddress } = config;
661
1068
  return {
662
1069
  getUsdcBalance: (params) => getUsdcBalance(publicClient, usdcAddress, params),
663
- getPriceConfig: (params) => getPriceConfig(publicClient, diamondAddress, params),
1070
+ getUsdcAllowance: (params) => getUsdcAllowance(publicClient, usdcAddress, diamondAddress, params),
664
1071
  getBalances: (params) => getBalances(publicClient, usdcAddress, diamondAddress, params),
665
- getTxLimits: (params) => getTxLimits(publicClient, diamondAddress, params),
666
- getRpPerUsdtLimitRational: (params) => getRpPerUsdtLimitRational(publicClient, diamondAddress, params)
1072
+ getTxLimits: (params) => getTxLimits(publicClient, diamondAddress, params)
667
1073
  };
668
1074
  }
669
1075
  export {