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