@p2pdotme/sdk 1.0.5 → 1.1.1
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 +103 -41
- package/dist/country.cjs +9 -2
- package/dist/country.cjs.map +1 -1
- package/dist/country.d.cts +35 -10
- package/dist/country.d.ts +35 -10
- package/dist/country.mjs +6 -2
- package/dist/country.mjs.map +1 -1
- package/dist/fraud-engine.cjs +52 -48
- package/dist/fraud-engine.cjs.map +1 -1
- package/dist/fraud-engine.mjs +46 -42
- package/dist/fraud-engine.mjs.map +1 -1
- package/dist/index.cjs +4 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -36
- package/dist/index.d.ts +41 -36
- package/dist/index.mjs +4 -12
- package/dist/index.mjs.map +1 -1
- package/dist/orders.cjs +5961 -0
- package/dist/orders.cjs.map +1 -0
- package/dist/orders.d.cts +620 -0
- package/dist/orders.d.ts +620 -0
- package/dist/orders.mjs +5911 -0
- package/dist/orders.mjs.map +1 -0
- package/dist/prices.cjs +1432 -0
- package/dist/prices.cjs.map +1 -0
- package/dist/prices.d.cts +109 -0
- package/dist/prices.d.ts +109 -0
- package/dist/prices.mjs +1404 -0
- package/dist/prices.mjs.map +1 -0
- package/dist/profile.cjs +899 -69
- package/dist/profile.cjs.map +1 -1
- package/dist/profile.d.cts +39 -27
- package/dist/profile.d.ts +39 -27
- package/dist/profile.mjs +892 -62
- package/dist/profile.mjs.map +1 -1
- package/dist/qr-parsers.cjs +88 -7
- package/dist/qr-parsers.cjs.map +1 -1
- package/dist/qr-parsers.d.cts +38 -16
- package/dist/qr-parsers.d.ts +38 -16
- package/dist/qr-parsers.mjs +88 -7
- package/dist/qr-parsers.mjs.map +1 -1
- package/dist/react.cjs +2955 -1105
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +384 -104
- package/dist/react.d.ts +384 -104
- package/dist/react.mjs +2841 -992
- package/dist/react.mjs.map +1 -1
- package/dist/zkkyc.cjs +405 -24
- package/dist/zkkyc.cjs.map +1 -1
- package/dist/zkkyc.d.cts +14 -9
- package/dist/zkkyc.d.ts +14 -9
- package/dist/zkkyc.mjs +405 -24
- package/dist/zkkyc.mjs.map +1 -1
- package/package.json +12 -12
- package/dist/order-routing.cjs +0 -888
- package/dist/order-routing.cjs.map +0 -1
- package/dist/order-routing.d.cts +0 -68
- package/dist/order-routing.d.ts +0 -68
- package/dist/order-routing.mjs +0 -860
- package/dist/order-routing.mjs.map +0 -1
- package/dist/payload.cjs +0 -3168
- package/dist/payload.cjs.map +0 -1
- package/dist/payload.d.cts +0 -147
- package/dist/payload.d.ts +0 -147
- package/dist/payload.mjs +0 -3124
- package/dist/payload.mjs.map +0 -1
package/dist/react.cjs
CHANGED
|
@@ -33,10 +33,11 @@ __export(react_exports, {
|
|
|
33
33
|
SdkProvider: () => SdkProvider,
|
|
34
34
|
useFingerprint: () => useFingerprint,
|
|
35
35
|
useFraudEngine: () => useFraudEngine,
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
useOrders: () => useOrders,
|
|
37
|
+
usePrices: () => usePrices,
|
|
38
38
|
useProfile: () => useProfile,
|
|
39
39
|
useSdk: () => useSdk,
|
|
40
|
+
useWatchOrders: () => useWatchOrders,
|
|
40
41
|
useZkkyc: () => useZkkyc
|
|
41
42
|
});
|
|
42
43
|
module.exports = __toCommonJS(react_exports);
|
|
@@ -45,7 +46,7 @@ module.exports = __toCommonJS(react_exports);
|
|
|
45
46
|
var import_react = require("react");
|
|
46
47
|
|
|
47
48
|
// src/fraud-engine/client.ts
|
|
48
|
-
var
|
|
49
|
+
var import_neverthrow4 = require("neverthrow");
|
|
49
50
|
|
|
50
51
|
// src/lib/encoding.ts
|
|
51
52
|
function hexToBytes(hex) {
|
|
@@ -78,48 +79,8 @@ function sleep(ms) {
|
|
|
78
79
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
// src/
|
|
82
|
-
|
|
83
|
-
const nav = typeof navigator !== "undefined" ? navigator : void 0;
|
|
84
|
-
const win = typeof window !== "undefined" ? window : void 0;
|
|
85
|
-
return {
|
|
86
|
-
userAgent: nav?.userAgent ?? "",
|
|
87
|
-
platform: nav?.platform ?? "",
|
|
88
|
-
language: nav?.language ?? "",
|
|
89
|
-
languages: nav ? Array.from(nav.languages) : [],
|
|
90
|
-
screenWidth: win?.screen?.width ?? 0,
|
|
91
|
-
screenHeight: win?.screen?.height ?? 0,
|
|
92
|
-
devicePixelRatio: win?.devicePixelRatio ?? 1,
|
|
93
|
-
timezone: Intl?.DateTimeFormat?.()?.resolvedOptions?.()?.timeZone ?? "",
|
|
94
|
-
timezoneOffset: (/* @__PURE__ */ new Date()).getTimezoneOffset(),
|
|
95
|
-
cookiesEnabled: nav?.cookieEnabled ?? false,
|
|
96
|
-
doNotTrack: nav?.doNotTrack ?? null,
|
|
97
|
-
online: nav?.onLine ?? true,
|
|
98
|
-
connectionType: nav?.connection?.effectiveType,
|
|
99
|
-
deviceMemory: nav?.deviceMemory,
|
|
100
|
-
hardwareConcurrency: nav?.hardwareConcurrency,
|
|
101
|
-
touchSupport: nav ? "ontouchstart" in window : false,
|
|
102
|
-
maxTouchPoints: nav?.maxTouchPoints ?? 0,
|
|
103
|
-
vendor: nav?.vendor ?? "",
|
|
104
|
-
appVersion: nav?.appVersion ?? "",
|
|
105
|
-
colorDepth: win?.screen?.colorDepth ?? 0,
|
|
106
|
-
pixelDepth: win?.screen?.pixelDepth ?? 0
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
async function fetchIpAddress() {
|
|
110
|
-
try {
|
|
111
|
-
const response = await fetch("https://api.ipify.org?format=json");
|
|
112
|
-
const data = await response.json();
|
|
113
|
-
return data.ip;
|
|
114
|
-
} catch {
|
|
115
|
-
return void 0;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
async function getDeviceDetails(seonSession) {
|
|
119
|
-
const basic = getBasicDeviceDetails();
|
|
120
|
-
const ip = await fetchIpAddress();
|
|
121
|
-
return { ...basic, ip, seonSession };
|
|
122
|
-
}
|
|
82
|
+
// src/lib/subgraph.ts
|
|
83
|
+
var import_neverthrow2 = require("neverthrow");
|
|
123
84
|
|
|
124
85
|
// src/validation/errors.validation.ts
|
|
125
86
|
var SdkError = class extends Error {
|
|
@@ -140,7 +101,7 @@ var import_neverthrow = require("neverthrow");
|
|
|
140
101
|
var import_viem = require("viem");
|
|
141
102
|
var import_zod = require("zod");
|
|
142
103
|
|
|
143
|
-
// src/
|
|
104
|
+
// src/country/currency.ts
|
|
144
105
|
var CURRENCY = {
|
|
145
106
|
IDR: "IDR",
|
|
146
107
|
INR: "INR",
|
|
@@ -153,17 +114,11 @@ var CURRENCY = {
|
|
|
153
114
|
USD: "USD",
|
|
154
115
|
COP: "COP"
|
|
155
116
|
};
|
|
156
|
-
|
|
157
|
-
// src/constants/orders.constant.ts
|
|
158
|
-
var ORDER_TYPE = {
|
|
159
|
-
BUY: 0,
|
|
160
|
-
SELL: 1,
|
|
161
|
-
PAY: 2
|
|
162
|
-
};
|
|
117
|
+
var CURRENCY_CODES = Object.values(CURRENCY);
|
|
163
118
|
|
|
164
119
|
// src/validation/schemas.validation.ts
|
|
165
120
|
var ZodAddressSchema = import_zod.z.string().refine((s) => (0, import_viem.isAddress)(s), { message: "Invalid Ethereum address" });
|
|
166
|
-
var ZodCurrencySchema = import_zod.z.enum(
|
|
121
|
+
var ZodCurrencySchema = import_zod.z.enum(CURRENCY_CODES);
|
|
167
122
|
function validate(schema, data, toError) {
|
|
168
123
|
const result = schema.safeParse(data);
|
|
169
124
|
if (result.success) {
|
|
@@ -172,6 +127,132 @@ function validate(schema, data, toError) {
|
|
|
172
127
|
return (0, import_neverthrow.err)(toError(import_zod.z.prettifyError(result.error), result.error, data));
|
|
173
128
|
}
|
|
174
129
|
|
|
130
|
+
// src/lib/subgraph.ts
|
|
131
|
+
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
132
|
+
var MAX_RETRIES = 3;
|
|
133
|
+
var BACKOFF_MS = 500;
|
|
134
|
+
var SubgraphError = class extends SdkError {
|
|
135
|
+
constructor(message, options) {
|
|
136
|
+
super(message, options);
|
|
137
|
+
this.name = "SubgraphError";
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
function isTransient(error) {
|
|
141
|
+
if (error instanceof SubgraphError) {
|
|
142
|
+
if (error.code !== "HTTP_ERROR") return false;
|
|
143
|
+
const status = error.context?.status;
|
|
144
|
+
return typeof status === "number" && status >= 500;
|
|
145
|
+
}
|
|
146
|
+
if (error instanceof DOMException && error.name === "AbortError") return true;
|
|
147
|
+
if (error instanceof TypeError) return true;
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
function querySubgraph(url, params) {
|
|
151
|
+
const timeoutMs = params.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
152
|
+
const fetchOnce = async () => {
|
|
153
|
+
const controller = new AbortController();
|
|
154
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
155
|
+
try {
|
|
156
|
+
const response = await fetch(url, {
|
|
157
|
+
method: "POST",
|
|
158
|
+
headers: { "Content-Type": "application/json" },
|
|
159
|
+
body: JSON.stringify({
|
|
160
|
+
query: params.query,
|
|
161
|
+
variables: params.variables
|
|
162
|
+
}),
|
|
163
|
+
signal: controller.signal
|
|
164
|
+
});
|
|
165
|
+
if (!response.ok) {
|
|
166
|
+
throw new SubgraphError(`Subgraph request failed (status: ${response.status})`, {
|
|
167
|
+
code: "HTTP_ERROR",
|
|
168
|
+
cause: response,
|
|
169
|
+
context: { status: response.status }
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
const json = await response.json();
|
|
173
|
+
if (json.errors?.length > 0) {
|
|
174
|
+
throw new SubgraphError("Subgraph returned GraphQL errors", {
|
|
175
|
+
code: "GRAPHQL_ERROR",
|
|
176
|
+
cause: json.errors,
|
|
177
|
+
context: { errors: json.errors }
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (!json.data) {
|
|
181
|
+
throw new SubgraphError("Subgraph returned no data", {
|
|
182
|
+
code: "NO_DATA",
|
|
183
|
+
cause: "Missing data field in GraphQL response",
|
|
184
|
+
context: { response: json }
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return json.data;
|
|
188
|
+
} finally {
|
|
189
|
+
clearTimeout(timer);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
const fetchWithRetry = async () => {
|
|
193
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
194
|
+
try {
|
|
195
|
+
return await fetchOnce();
|
|
196
|
+
} catch (error) {
|
|
197
|
+
const lastAttempt = attempt === MAX_RETRIES;
|
|
198
|
+
if (lastAttempt || !isTransient(error)) throw error;
|
|
199
|
+
await sleep(BACKOFF_MS * (attempt + 1));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
throw new SubgraphError("Subgraph query exhausted retries", { code: "TRANSPORT_ERROR" });
|
|
203
|
+
};
|
|
204
|
+
return import_neverthrow2.ResultAsync.fromPromise(
|
|
205
|
+
fetchWithRetry(),
|
|
206
|
+
(error) => error instanceof SubgraphError ? error : new SubgraphError("Subgraph query failed", {
|
|
207
|
+
code: "TRANSPORT_ERROR",
|
|
208
|
+
cause: error
|
|
209
|
+
})
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/fraud-engine/device.ts
|
|
214
|
+
function getBasicDeviceDetails() {
|
|
215
|
+
const nav = typeof navigator !== "undefined" ? navigator : void 0;
|
|
216
|
+
const win = typeof window !== "undefined" ? window : void 0;
|
|
217
|
+
return {
|
|
218
|
+
userAgent: nav?.userAgent ?? "",
|
|
219
|
+
platform: nav?.platform ?? "",
|
|
220
|
+
language: nav?.language ?? "",
|
|
221
|
+
languages: nav ? Array.from(nav.languages) : [],
|
|
222
|
+
screenWidth: win?.screen?.width ?? 0,
|
|
223
|
+
screenHeight: win?.screen?.height ?? 0,
|
|
224
|
+
devicePixelRatio: win?.devicePixelRatio ?? 1,
|
|
225
|
+
timezone: Intl?.DateTimeFormat?.()?.resolvedOptions?.()?.timeZone ?? "",
|
|
226
|
+
timezoneOffset: (/* @__PURE__ */ new Date()).getTimezoneOffset(),
|
|
227
|
+
cookiesEnabled: nav?.cookieEnabled ?? false,
|
|
228
|
+
doNotTrack: nav?.doNotTrack ?? null,
|
|
229
|
+
online: nav?.onLine ?? true,
|
|
230
|
+
connectionType: nav?.connection?.effectiveType,
|
|
231
|
+
deviceMemory: nav?.deviceMemory,
|
|
232
|
+
hardwareConcurrency: nav?.hardwareConcurrency,
|
|
233
|
+
touchSupport: nav ? "ontouchstart" in window : false,
|
|
234
|
+
maxTouchPoints: nav?.maxTouchPoints ?? 0,
|
|
235
|
+
vendor: nav?.vendor ?? "",
|
|
236
|
+
appVersion: nav?.appVersion ?? "",
|
|
237
|
+
colorDepth: win?.screen?.colorDepth ?? 0,
|
|
238
|
+
pixelDepth: win?.screen?.pixelDepth ?? 0
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
async function fetchIpAddress() {
|
|
242
|
+
try {
|
|
243
|
+
const response = await fetch("https://api.ipify.org?format=json");
|
|
244
|
+
const data = await response.json();
|
|
245
|
+
return data.ip;
|
|
246
|
+
} catch {
|
|
247
|
+
return void 0;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
async function getDeviceDetails(seonSession) {
|
|
251
|
+
const basic = getBasicDeviceDetails();
|
|
252
|
+
const ip = await fetchIpAddress();
|
|
253
|
+
return { ...basic, ip, seonSession };
|
|
254
|
+
}
|
|
255
|
+
|
|
175
256
|
// src/fraud-engine/errors.ts
|
|
176
257
|
var FraudEngineError = class extends SdkError {
|
|
177
258
|
constructor(message, options) {
|
|
@@ -302,7 +383,7 @@ async function getSignedHeaders(signer, action) {
|
|
|
302
383
|
}
|
|
303
384
|
|
|
304
385
|
// src/fraud-engine/validation.ts
|
|
305
|
-
var
|
|
386
|
+
var import_neverthrow3 = require("neverthrow");
|
|
306
387
|
var import_zod2 = require("zod");
|
|
307
388
|
var ZodFraudEngineConfigSchema = import_zod2.z.object({
|
|
308
389
|
apiUrl: import_zod2.z.url(),
|
|
@@ -334,9 +415,9 @@ var ZodLinkOrderParamsSchema = import_zod2.z.object({
|
|
|
334
415
|
function validate2(schema, data) {
|
|
335
416
|
const result = schema.safeParse(data);
|
|
336
417
|
if (result.success) {
|
|
337
|
-
return (0,
|
|
418
|
+
return (0, import_neverthrow3.ok)(result.data);
|
|
338
419
|
}
|
|
339
|
-
return (0,
|
|
420
|
+
return (0, import_neverthrow3.err)(
|
|
340
421
|
new FraudEngineError(import_zod2.z.prettifyError(result.error), {
|
|
341
422
|
code: "VALIDATION_ERROR",
|
|
342
423
|
cause: result.error,
|
|
@@ -363,7 +444,7 @@ function createFraudEngine(config) {
|
|
|
363
444
|
);
|
|
364
445
|
}
|
|
365
446
|
function linkOrderInternal(signer, activityLogId, orderId) {
|
|
366
|
-
return
|
|
447
|
+
return import_neverthrow4.ResultAsync.fromPromise(
|
|
367
448
|
(async () => {
|
|
368
449
|
logger.info("Linking order to activity log", { activityLogId, orderId });
|
|
369
450
|
const signedHeaders = await getSignedHeaders(signer, "link-order");
|
|
@@ -480,8 +561,8 @@ function createFraudEngine(config) {
|
|
|
480
561
|
logger.info("Fraud engine initialized");
|
|
481
562
|
},
|
|
482
563
|
checkBuyOrder(params) {
|
|
483
|
-
if (configError) return (0,
|
|
484
|
-
return
|
|
564
|
+
if (configError) return (0, import_neverthrow4.errAsync)(configError);
|
|
565
|
+
return import_neverthrow4.ResultAsync.fromPromise(
|
|
485
566
|
checkBuyOrderInternal(params).then((data) => ({
|
|
486
567
|
approved: data.approved,
|
|
487
568
|
activityLogId: data.activity_log_id,
|
|
@@ -498,8 +579,8 @@ function createFraudEngine(config) {
|
|
|
498
579
|
);
|
|
499
580
|
},
|
|
500
581
|
processBuyOrder(params) {
|
|
501
|
-
if (configError) return (0,
|
|
502
|
-
return
|
|
582
|
+
if (configError) return (0, import_neverthrow4.errAsync)(configError);
|
|
583
|
+
return import_neverthrow4.ResultAsync.fromPromise(
|
|
503
584
|
(async () => {
|
|
504
585
|
let activityLogId = null;
|
|
505
586
|
try {
|
|
@@ -543,8 +624,8 @@ function createFraudEngine(config) {
|
|
|
543
624
|
);
|
|
544
625
|
},
|
|
545
626
|
logFingerprint(params) {
|
|
546
|
-
if (configError) return (0,
|
|
547
|
-
return
|
|
627
|
+
if (configError) return (0, import_neverthrow4.errAsync)(configError);
|
|
628
|
+
return import_neverthrow4.ResultAsync.fromPromise(
|
|
548
629
|
(async () => {
|
|
549
630
|
logger.info("Logging fingerprint");
|
|
550
631
|
const fingerprintResult = await getFingerprint(5e3);
|
|
@@ -603,8 +684,12 @@ function createFraudEngine(config) {
|
|
|
603
684
|
};
|
|
604
685
|
}
|
|
605
686
|
|
|
606
|
-
// src/
|
|
607
|
-
var
|
|
687
|
+
// src/orders/client.ts
|
|
688
|
+
var import_neverthrow17 = require("neverthrow");
|
|
689
|
+
|
|
690
|
+
// src/contracts/order-processor/index.ts
|
|
691
|
+
var import_neverthrow5 = require("neverthrow");
|
|
692
|
+
var import_viem3 = require("viem");
|
|
608
693
|
|
|
609
694
|
// src/contracts/abis/index.ts
|
|
610
695
|
var import_viem2 = require("viem");
|
|
@@ -639,67 +724,442 @@ var orderFlowFacetAbi = [
|
|
|
639
724
|
],
|
|
640
725
|
stateMutability: "view",
|
|
641
726
|
type: "function"
|
|
642
|
-
}
|
|
643
|
-
];
|
|
644
|
-
|
|
645
|
-
// src/contracts/abis/p2p-config-facet.ts
|
|
646
|
-
var p2pConfigFacetAbi = [
|
|
727
|
+
},
|
|
647
728
|
{
|
|
648
729
|
inputs: [
|
|
649
|
-
{
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
}
|
|
730
|
+
{ internalType: "string", name: "_pubKey", type: "string" },
|
|
731
|
+
{ internalType: "uint256", name: "_amount", type: "uint256" },
|
|
732
|
+
{ internalType: "address", name: "_recipientAddr", type: "address" },
|
|
733
|
+
{ internalType: "uint8", name: "_orderType", type: "uint8" },
|
|
734
|
+
{ internalType: "string", name: "_userUpi", type: "string" },
|
|
735
|
+
{ internalType: "string", name: "_userPubKey", type: "string" },
|
|
736
|
+
{ internalType: "bytes32", name: "_currency", type: "bytes32" },
|
|
737
|
+
{ internalType: "uint256", name: "preferredPaymentChannelConfigId", type: "uint256" },
|
|
738
|
+
{ internalType: "uint256", name: "_circleId", type: "uint256" },
|
|
739
|
+
{ internalType: "uint256", name: "_fiatAmountLimit", type: "uint256" }
|
|
654
740
|
],
|
|
655
|
-
name: "
|
|
656
|
-
outputs: [
|
|
741
|
+
name: "placeOrder",
|
|
742
|
+
outputs: [],
|
|
743
|
+
stateMutability: "nonpayable",
|
|
744
|
+
type: "function"
|
|
745
|
+
},
|
|
746
|
+
{
|
|
747
|
+
inputs: [{ internalType: "uint256", name: "_orderId", type: "uint256" }],
|
|
748
|
+
name: "cancelOrder",
|
|
749
|
+
outputs: [],
|
|
750
|
+
stateMutability: "nonpayable",
|
|
751
|
+
type: "function"
|
|
752
|
+
},
|
|
753
|
+
{
|
|
754
|
+
inputs: [
|
|
755
|
+
{ internalType: "uint256", name: "_orderId", type: "uint256" },
|
|
756
|
+
{ internalType: "string", name: "_userEncUpi", type: "string" },
|
|
757
|
+
{ internalType: "uint256", name: "_updatedAmount", type: "uint256" }
|
|
758
|
+
],
|
|
759
|
+
name: "setSellOrderUpi",
|
|
760
|
+
outputs: [],
|
|
761
|
+
stateMutability: "nonpayable",
|
|
762
|
+
type: "function"
|
|
763
|
+
},
|
|
764
|
+
{
|
|
765
|
+
type: "event",
|
|
766
|
+
name: "OrderPlaced",
|
|
767
|
+
anonymous: false,
|
|
768
|
+
inputs: [
|
|
769
|
+
{ indexed: true, name: "orderId", type: "uint256" },
|
|
770
|
+
{ indexed: true, name: "user", type: "address" },
|
|
771
|
+
{ indexed: true, name: "merchant", type: "address" },
|
|
772
|
+
{ indexed: false, name: "amount", type: "uint256" },
|
|
773
|
+
{ indexed: false, name: "orderType", type: "uint8" },
|
|
774
|
+
{ indexed: false, name: "placedTimestamp", type: "uint256" },
|
|
657
775
|
{
|
|
776
|
+
indexed: false,
|
|
777
|
+
name: "_order",
|
|
778
|
+
type: "tuple",
|
|
658
779
|
components: [
|
|
780
|
+
{ name: "amount", type: "uint256" },
|
|
781
|
+
{ name: "fiatAmount", type: "uint256" },
|
|
782
|
+
{ name: "placedTimestamp", type: "uint256" },
|
|
783
|
+
{ name: "completedTimestamp", type: "uint256" },
|
|
784
|
+
{ name: "userCompletedTimestamp", type: "uint256" },
|
|
785
|
+
{ name: "acceptedMerchant", type: "address" },
|
|
786
|
+
{ name: "user", type: "address" },
|
|
787
|
+
{ name: "recipientAddr", type: "address" },
|
|
788
|
+
{ name: "pubkey", type: "string" },
|
|
789
|
+
{ name: "encUpi", type: "string" },
|
|
790
|
+
{ name: "userCompleted", type: "bool" },
|
|
791
|
+
{ name: "status", type: "uint8" },
|
|
792
|
+
{ name: "orderType", type: "uint8" },
|
|
659
793
|
{
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
794
|
+
name: "disputeInfo",
|
|
795
|
+
type: "tuple",
|
|
796
|
+
components: [
|
|
797
|
+
{ name: "raisedBy", type: "uint8" },
|
|
798
|
+
{ name: "status", type: "uint8" },
|
|
799
|
+
{ name: "redactTransId", type: "uint256" },
|
|
800
|
+
{ name: "accountNumber", type: "uint256" }
|
|
801
|
+
]
|
|
663
802
|
},
|
|
803
|
+
{ name: "id", type: "uint256" },
|
|
804
|
+
{ name: "userPubKey", type: "string" },
|
|
805
|
+
{ name: "encMerchantUpi", type: "string" },
|
|
806
|
+
{ name: "acceptedAccountNo", type: "uint256" },
|
|
807
|
+
{ name: "assignedAccountNos", type: "uint256[]" },
|
|
808
|
+
{ name: "currency", type: "bytes32" },
|
|
809
|
+
{ name: "preferredPaymentChannelConfigId", type: "uint256" },
|
|
810
|
+
{ name: "circleId", type: "uint256" }
|
|
811
|
+
]
|
|
812
|
+
}
|
|
813
|
+
]
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
type: "event",
|
|
817
|
+
name: "OrderAccepted",
|
|
818
|
+
anonymous: false,
|
|
819
|
+
inputs: [
|
|
820
|
+
{ indexed: true, name: "orderId", type: "uint256" },
|
|
821
|
+
{ indexed: true, name: "merchant", type: "address" },
|
|
822
|
+
{ indexed: false, name: "pubKey", type: "string" },
|
|
823
|
+
{
|
|
824
|
+
indexed: false,
|
|
825
|
+
name: "_order",
|
|
826
|
+
type: "tuple",
|
|
827
|
+
components: [
|
|
828
|
+
{ name: "amount", type: "uint256" },
|
|
829
|
+
{ name: "fiatAmount", type: "uint256" },
|
|
830
|
+
{ name: "placedTimestamp", type: "uint256" },
|
|
831
|
+
{ name: "completedTimestamp", type: "uint256" },
|
|
832
|
+
{ name: "userCompletedTimestamp", type: "uint256" },
|
|
833
|
+
{ name: "acceptedMerchant", type: "address" },
|
|
834
|
+
{ name: "user", type: "address" },
|
|
835
|
+
{ name: "recipientAddr", type: "address" },
|
|
836
|
+
{ name: "pubkey", type: "string" },
|
|
837
|
+
{ name: "encUpi", type: "string" },
|
|
838
|
+
{ name: "userCompleted", type: "bool" },
|
|
839
|
+
{ name: "status", type: "uint8" },
|
|
840
|
+
{ name: "orderType", type: "uint8" },
|
|
664
841
|
{
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
842
|
+
name: "disputeInfo",
|
|
843
|
+
type: "tuple",
|
|
844
|
+
components: [
|
|
845
|
+
{ name: "raisedBy", type: "uint8" },
|
|
846
|
+
{ name: "status", type: "uint8" },
|
|
847
|
+
{ name: "redactTransId", type: "uint256" },
|
|
848
|
+
{ name: "accountNumber", type: "uint256" }
|
|
849
|
+
]
|
|
668
850
|
},
|
|
851
|
+
{ name: "id", type: "uint256" },
|
|
852
|
+
{ name: "userPubKey", type: "string" },
|
|
853
|
+
{ name: "encMerchantUpi", type: "string" },
|
|
854
|
+
{ name: "acceptedAccountNo", type: "uint256" },
|
|
855
|
+
{ name: "assignedAccountNos", type: "uint256[]" },
|
|
856
|
+
{ name: "currency", type: "bytes32" },
|
|
857
|
+
{ name: "preferredPaymentChannelConfigId", type: "uint256" },
|
|
858
|
+
{ name: "circleId", type: "uint256" }
|
|
859
|
+
]
|
|
860
|
+
}
|
|
861
|
+
]
|
|
862
|
+
},
|
|
863
|
+
{
|
|
864
|
+
type: "event",
|
|
865
|
+
name: "BuyOrderPaid",
|
|
866
|
+
anonymous: false,
|
|
867
|
+
inputs: [
|
|
868
|
+
{ indexed: true, name: "orderId", type: "uint256" },
|
|
869
|
+
{ indexed: true, name: "user", type: "address" },
|
|
870
|
+
{
|
|
871
|
+
indexed: false,
|
|
872
|
+
name: "_order",
|
|
873
|
+
type: "tuple",
|
|
874
|
+
components: [
|
|
875
|
+
{ name: "amount", type: "uint256" },
|
|
876
|
+
{ name: "fiatAmount", type: "uint256" },
|
|
877
|
+
{ name: "placedTimestamp", type: "uint256" },
|
|
878
|
+
{ name: "completedTimestamp", type: "uint256" },
|
|
879
|
+
{ name: "userCompletedTimestamp", type: "uint256" },
|
|
880
|
+
{ name: "acceptedMerchant", type: "address" },
|
|
881
|
+
{ name: "user", type: "address" },
|
|
882
|
+
{ name: "recipientAddr", type: "address" },
|
|
883
|
+
{ name: "pubkey", type: "string" },
|
|
884
|
+
{ name: "encUpi", type: "string" },
|
|
885
|
+
{ name: "userCompleted", type: "bool" },
|
|
886
|
+
{ name: "status", type: "uint8" },
|
|
887
|
+
{ name: "orderType", type: "uint8" },
|
|
669
888
|
{
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
889
|
+
name: "disputeInfo",
|
|
890
|
+
type: "tuple",
|
|
891
|
+
components: [
|
|
892
|
+
{ name: "raisedBy", type: "uint8" },
|
|
893
|
+
{ name: "status", type: "uint8" },
|
|
894
|
+
{ name: "redactTransId", type: "uint256" },
|
|
895
|
+
{ name: "accountNumber", type: "uint256" }
|
|
896
|
+
]
|
|
673
897
|
},
|
|
674
|
-
{
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
898
|
+
{ name: "id", type: "uint256" },
|
|
899
|
+
{ name: "userPubKey", type: "string" },
|
|
900
|
+
{ name: "encMerchantUpi", type: "string" },
|
|
901
|
+
{ name: "acceptedAccountNo", type: "uint256" },
|
|
902
|
+
{ name: "assignedAccountNos", type: "uint256[]" },
|
|
903
|
+
{ name: "currency", type: "bytes32" },
|
|
904
|
+
{ name: "preferredPaymentChannelConfigId", type: "uint256" },
|
|
905
|
+
{ name: "circleId", type: "uint256" }
|
|
906
|
+
]
|
|
683
907
|
}
|
|
684
|
-
]
|
|
685
|
-
stateMutability: "view",
|
|
686
|
-
type: "function"
|
|
908
|
+
]
|
|
687
909
|
},
|
|
688
910
|
{
|
|
911
|
+
type: "event",
|
|
912
|
+
name: "OrderCompleted",
|
|
913
|
+
anonymous: false,
|
|
689
914
|
inputs: [
|
|
915
|
+
{ indexed: true, name: "orderId", type: "uint256" },
|
|
916
|
+
{ indexed: true, name: "user", type: "address" },
|
|
917
|
+
{ indexed: false, name: "completedTimestamp", type: "uint256" },
|
|
690
918
|
{
|
|
691
|
-
|
|
692
|
-
name: "
|
|
693
|
-
type: "
|
|
919
|
+
indexed: false,
|
|
920
|
+
name: "_order",
|
|
921
|
+
type: "tuple",
|
|
922
|
+
components: [
|
|
923
|
+
{ name: "amount", type: "uint256" },
|
|
924
|
+
{ name: "fiatAmount", type: "uint256" },
|
|
925
|
+
{ name: "placedTimestamp", type: "uint256" },
|
|
926
|
+
{ name: "completedTimestamp", type: "uint256" },
|
|
927
|
+
{ name: "userCompletedTimestamp", type: "uint256" },
|
|
928
|
+
{ name: "acceptedMerchant", type: "address" },
|
|
929
|
+
{ name: "user", type: "address" },
|
|
930
|
+
{ name: "recipientAddr", type: "address" },
|
|
931
|
+
{ name: "pubkey", type: "string" },
|
|
932
|
+
{ name: "encUpi", type: "string" },
|
|
933
|
+
{ name: "userCompleted", type: "bool" },
|
|
934
|
+
{ name: "status", type: "uint8" },
|
|
935
|
+
{ name: "orderType", type: "uint8" },
|
|
936
|
+
{
|
|
937
|
+
name: "disputeInfo",
|
|
938
|
+
type: "tuple",
|
|
939
|
+
components: [
|
|
940
|
+
{ name: "raisedBy", type: "uint8" },
|
|
941
|
+
{ name: "status", type: "uint8" },
|
|
942
|
+
{ name: "redactTransId", type: "uint256" },
|
|
943
|
+
{ name: "accountNumber", type: "uint256" }
|
|
944
|
+
]
|
|
945
|
+
},
|
|
946
|
+
{ name: "id", type: "uint256" },
|
|
947
|
+
{ name: "userPubKey", type: "string" },
|
|
948
|
+
{ name: "encMerchantUpi", type: "string" },
|
|
949
|
+
{ name: "acceptedAccountNo", type: "uint256" },
|
|
950
|
+
{ name: "assignedAccountNos", type: "uint256[]" },
|
|
951
|
+
{ name: "currency", type: "bytes32" },
|
|
952
|
+
{ name: "preferredPaymentChannelConfigId", type: "uint256" },
|
|
953
|
+
{ name: "circleId", type: "uint256" }
|
|
954
|
+
]
|
|
694
955
|
}
|
|
695
|
-
]
|
|
696
|
-
|
|
697
|
-
|
|
956
|
+
]
|
|
957
|
+
},
|
|
958
|
+
{
|
|
959
|
+
type: "event",
|
|
960
|
+
name: "CancelledOrders",
|
|
961
|
+
anonymous: false,
|
|
962
|
+
inputs: [
|
|
963
|
+
{ indexed: true, name: "orderId", type: "uint256" },
|
|
698
964
|
{
|
|
699
|
-
|
|
700
|
-
name: "
|
|
701
|
-
type: "
|
|
702
|
-
|
|
965
|
+
indexed: false,
|
|
966
|
+
name: "_order",
|
|
967
|
+
type: "tuple",
|
|
968
|
+
components: [
|
|
969
|
+
{ name: "amount", type: "uint256" },
|
|
970
|
+
{ name: "fiatAmount", type: "uint256" },
|
|
971
|
+
{ name: "placedTimestamp", type: "uint256" },
|
|
972
|
+
{ name: "completedTimestamp", type: "uint256" },
|
|
973
|
+
{ name: "userCompletedTimestamp", type: "uint256" },
|
|
974
|
+
{ name: "acceptedMerchant", type: "address" },
|
|
975
|
+
{ name: "user", type: "address" },
|
|
976
|
+
{ name: "recipientAddr", type: "address" },
|
|
977
|
+
{ name: "pubkey", type: "string" },
|
|
978
|
+
{ name: "encUpi", type: "string" },
|
|
979
|
+
{ name: "userCompleted", type: "bool" },
|
|
980
|
+
{ name: "status", type: "uint8" },
|
|
981
|
+
{ name: "orderType", type: "uint8" },
|
|
982
|
+
{
|
|
983
|
+
name: "disputeInfo",
|
|
984
|
+
type: "tuple",
|
|
985
|
+
components: [
|
|
986
|
+
{ name: "raisedBy", type: "uint8" },
|
|
987
|
+
{ name: "status", type: "uint8" },
|
|
988
|
+
{ name: "redactTransId", type: "uint256" },
|
|
989
|
+
{ name: "accountNumber", type: "uint256" }
|
|
990
|
+
]
|
|
991
|
+
},
|
|
992
|
+
{ name: "id", type: "uint256" },
|
|
993
|
+
{ name: "userPubKey", type: "string" },
|
|
994
|
+
{ name: "encMerchantUpi", type: "string" },
|
|
995
|
+
{ name: "acceptedAccountNo", type: "uint256" },
|
|
996
|
+
{ name: "assignedAccountNos", type: "uint256[]" },
|
|
997
|
+
{ name: "currency", type: "bytes32" },
|
|
998
|
+
{ name: "preferredPaymentChannelConfigId", type: "uint256" },
|
|
999
|
+
{ name: "circleId", type: "uint256" }
|
|
1000
|
+
]
|
|
1001
|
+
}
|
|
1002
|
+
]
|
|
1003
|
+
}
|
|
1004
|
+
];
|
|
1005
|
+
|
|
1006
|
+
// src/contracts/abis/order-processor-facet.ts
|
|
1007
|
+
var orderProcessorFacetAbi = [
|
|
1008
|
+
{
|
|
1009
|
+
type: "function",
|
|
1010
|
+
name: "getOrdersById",
|
|
1011
|
+
stateMutability: "view",
|
|
1012
|
+
inputs: [{ name: "orderId", type: "uint256" }],
|
|
1013
|
+
outputs: [
|
|
1014
|
+
{
|
|
1015
|
+
type: "tuple",
|
|
1016
|
+
components: [
|
|
1017
|
+
{ name: "amount", type: "uint256" },
|
|
1018
|
+
{ name: "fiatAmount", type: "uint256" },
|
|
1019
|
+
{ name: "placedTimestamp", type: "uint256" },
|
|
1020
|
+
{ name: "completedTimestamp", type: "uint256" },
|
|
1021
|
+
{ name: "userCompletedTimestamp", type: "uint256" },
|
|
1022
|
+
{ name: "acceptedMerchant", type: "address" },
|
|
1023
|
+
{ name: "user", type: "address" },
|
|
1024
|
+
{ name: "recipientAddr", type: "address" },
|
|
1025
|
+
{ name: "pubkey", type: "string" },
|
|
1026
|
+
{ name: "encUpi", type: "string" },
|
|
1027
|
+
{ name: "userCompleted", type: "bool" },
|
|
1028
|
+
{ name: "status", type: "uint8" },
|
|
1029
|
+
{ name: "orderType", type: "uint8" },
|
|
1030
|
+
{
|
|
1031
|
+
name: "disputeInfo",
|
|
1032
|
+
type: "tuple",
|
|
1033
|
+
components: [
|
|
1034
|
+
{ name: "raisedBy", type: "uint8" },
|
|
1035
|
+
{ name: "status", type: "uint8" },
|
|
1036
|
+
{ name: "redactTransId", type: "uint256" },
|
|
1037
|
+
{ name: "accountNumber", type: "uint256" }
|
|
1038
|
+
]
|
|
1039
|
+
},
|
|
1040
|
+
{ name: "id", type: "uint256" },
|
|
1041
|
+
{ name: "userPubKey", type: "string" },
|
|
1042
|
+
{ name: "encMerchantUpi", type: "string" },
|
|
1043
|
+
{ name: "acceptedAccountNo", type: "uint256" },
|
|
1044
|
+
{ name: "assignedAccountNos", type: "uint256[]" },
|
|
1045
|
+
{ name: "currency", type: "bytes32" },
|
|
1046
|
+
{ name: "preferredPaymentChannelConfigId", type: "uint256" },
|
|
1047
|
+
{ name: "circleId", type: "uint256" }
|
|
1048
|
+
]
|
|
1049
|
+
}
|
|
1050
|
+
]
|
|
1051
|
+
},
|
|
1052
|
+
{
|
|
1053
|
+
type: "function",
|
|
1054
|
+
name: "getAdditionalOrderDetails",
|
|
1055
|
+
stateMutability: "view",
|
|
1056
|
+
inputs: [{ name: "orderId", type: "uint256" }],
|
|
1057
|
+
outputs: [
|
|
1058
|
+
{
|
|
1059
|
+
type: "tuple",
|
|
1060
|
+
components: [
|
|
1061
|
+
{ name: "fixedFeePaid", type: "uint64" },
|
|
1062
|
+
{ name: "tipsPaid", type: "uint64" },
|
|
1063
|
+
{ name: "acceptedTimestamp", type: "uint128" },
|
|
1064
|
+
{ name: "paidTimestamp", type: "uint128" },
|
|
1065
|
+
{ name: "reserved2", type: "uint128" },
|
|
1066
|
+
{ name: "actualUsdtAmount", type: "uint256" },
|
|
1067
|
+
{ name: "actualFiatAmount", type: "uint256" }
|
|
1068
|
+
]
|
|
1069
|
+
}
|
|
1070
|
+
]
|
|
1071
|
+
},
|
|
1072
|
+
{
|
|
1073
|
+
type: "function",
|
|
1074
|
+
name: "getSmallOrderThreshold",
|
|
1075
|
+
stateMutability: "view",
|
|
1076
|
+
inputs: [{ name: "currency", type: "bytes32" }],
|
|
1077
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
1078
|
+
},
|
|
1079
|
+
{
|
|
1080
|
+
type: "function",
|
|
1081
|
+
name: "getSmallOrderFixedFee",
|
|
1082
|
+
stateMutability: "view",
|
|
1083
|
+
inputs: [{ name: "currency", type: "bytes32" }],
|
|
1084
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
1085
|
+
},
|
|
1086
|
+
{
|
|
1087
|
+
type: "function",
|
|
1088
|
+
name: "raiseDispute",
|
|
1089
|
+
stateMutability: "nonpayable",
|
|
1090
|
+
inputs: [
|
|
1091
|
+
{ name: "_orderId", type: "uint256" },
|
|
1092
|
+
{ name: "redactTransId", type: "uint256" }
|
|
1093
|
+
],
|
|
1094
|
+
outputs: []
|
|
1095
|
+
},
|
|
1096
|
+
{
|
|
1097
|
+
type: "function",
|
|
1098
|
+
name: "paidBuyOrder",
|
|
1099
|
+
stateMutability: "nonpayable",
|
|
1100
|
+
inputs: [{ name: "_orderId", type: "uint256" }],
|
|
1101
|
+
outputs: []
|
|
1102
|
+
}
|
|
1103
|
+
];
|
|
1104
|
+
|
|
1105
|
+
// src/contracts/abis/p2p-config-facet.ts
|
|
1106
|
+
var p2pConfigFacetAbi = [
|
|
1107
|
+
{
|
|
1108
|
+
inputs: [
|
|
1109
|
+
{
|
|
1110
|
+
internalType: "bytes32",
|
|
1111
|
+
name: "_currency",
|
|
1112
|
+
type: "bytes32"
|
|
1113
|
+
}
|
|
1114
|
+
],
|
|
1115
|
+
name: "getPriceConfig",
|
|
1116
|
+
outputs: [
|
|
1117
|
+
{
|
|
1118
|
+
components: [
|
|
1119
|
+
{
|
|
1120
|
+
internalType: "uint256",
|
|
1121
|
+
name: "buyPrice",
|
|
1122
|
+
type: "uint256"
|
|
1123
|
+
},
|
|
1124
|
+
{
|
|
1125
|
+
internalType: "uint256",
|
|
1126
|
+
name: "sellPrice",
|
|
1127
|
+
type: "uint256"
|
|
1128
|
+
},
|
|
1129
|
+
{
|
|
1130
|
+
internalType: "int256",
|
|
1131
|
+
name: "buyPriceOffset",
|
|
1132
|
+
type: "int256"
|
|
1133
|
+
},
|
|
1134
|
+
{
|
|
1135
|
+
internalType: "uint256",
|
|
1136
|
+
name: "baseSpread",
|
|
1137
|
+
type: "uint256"
|
|
1138
|
+
}
|
|
1139
|
+
],
|
|
1140
|
+
internalType: "struct P2pConfigStorage.PriceConfig",
|
|
1141
|
+
name: "",
|
|
1142
|
+
type: "tuple"
|
|
1143
|
+
}
|
|
1144
|
+
],
|
|
1145
|
+
stateMutability: "view",
|
|
1146
|
+
type: "function"
|
|
1147
|
+
},
|
|
1148
|
+
{
|
|
1149
|
+
inputs: [
|
|
1150
|
+
{
|
|
1151
|
+
internalType: "bytes32",
|
|
1152
|
+
name: "_nativeCurrency",
|
|
1153
|
+
type: "bytes32"
|
|
1154
|
+
}
|
|
1155
|
+
],
|
|
1156
|
+
name: "getRpPerUsdtLimitRational",
|
|
1157
|
+
outputs: [
|
|
1158
|
+
{
|
|
1159
|
+
internalType: "uint256",
|
|
1160
|
+
name: "numerator",
|
|
1161
|
+
type: "uint256"
|
|
1162
|
+
},
|
|
703
1163
|
{
|
|
704
1164
|
internalType: "uint256",
|
|
705
1165
|
name: "denominator",
|
|
@@ -914,11 +1374,16 @@ var reputationManagerAbi = [
|
|
|
914
1374
|
];
|
|
915
1375
|
|
|
916
1376
|
// src/contracts/abis/index.ts
|
|
917
|
-
var DIAMOND_ABI = [
|
|
1377
|
+
var DIAMOND_ABI = [
|
|
1378
|
+
...orderFlowFacetAbi,
|
|
1379
|
+
...orderProcessorFacetAbi,
|
|
1380
|
+
...p2pConfigFacetAbi
|
|
1381
|
+
];
|
|
918
1382
|
var ABIS = {
|
|
919
1383
|
DIAMOND: DIAMOND_ABI,
|
|
920
1384
|
FACETS: {
|
|
921
1385
|
ORDER_FLOW: orderFlowFacetAbi,
|
|
1386
|
+
ORDER_PROCESSOR: orderProcessorFacetAbi,
|
|
922
1387
|
CONFIG: p2pConfigFacetAbi
|
|
923
1388
|
},
|
|
924
1389
|
EXTERNAL: {
|
|
@@ -927,817 +1392,663 @@ var ABIS = {
|
|
|
927
1392
|
}
|
|
928
1393
|
};
|
|
929
1394
|
|
|
930
|
-
// src/contracts/order-
|
|
931
|
-
|
|
1395
|
+
// src/contracts/order-processor/index.ts
|
|
1396
|
+
function readOrderMulticall(publicClient, diamondAddress, orderId) {
|
|
1397
|
+
const calls = [
|
|
1398
|
+
{
|
|
1399
|
+
address: diamondAddress,
|
|
1400
|
+
abi: ABIS.FACETS.ORDER_PROCESSOR,
|
|
1401
|
+
functionName: "getOrdersById",
|
|
1402
|
+
args: [orderId]
|
|
1403
|
+
},
|
|
1404
|
+
{
|
|
1405
|
+
address: diamondAddress,
|
|
1406
|
+
abi: ABIS.FACETS.ORDER_PROCESSOR,
|
|
1407
|
+
functionName: "getAdditionalOrderDetails",
|
|
1408
|
+
args: [orderId]
|
|
1409
|
+
}
|
|
1410
|
+
];
|
|
1411
|
+
const toError = (error) => new Error("Order contract read failed", { cause: error });
|
|
1412
|
+
const exec = async () => {
|
|
1413
|
+
if (publicClient.multicall) {
|
|
1414
|
+
const [order2, details2] = await publicClient.multicall({
|
|
1415
|
+
contracts: calls,
|
|
1416
|
+
allowFailure: false
|
|
1417
|
+
});
|
|
1418
|
+
return { order: order2, details: details2 };
|
|
1419
|
+
}
|
|
1420
|
+
const [order, details] = await Promise.all(
|
|
1421
|
+
calls.map((c) => publicClient.readContract(c))
|
|
1422
|
+
);
|
|
1423
|
+
return { order, details };
|
|
1424
|
+
};
|
|
1425
|
+
return import_neverthrow5.ResultAsync.fromPromise(exec(), toError);
|
|
1426
|
+
}
|
|
1427
|
+
function readFeeConfigMulticall(publicClient, diamondAddress, currency) {
|
|
1428
|
+
const currencyHex = (0, import_viem3.stringToHex)(currency, { size: 32 });
|
|
1429
|
+
const calls = [
|
|
1430
|
+
{
|
|
1431
|
+
address: diamondAddress,
|
|
1432
|
+
abi: ABIS.FACETS.ORDER_PROCESSOR,
|
|
1433
|
+
functionName: "getSmallOrderThreshold",
|
|
1434
|
+
args: [currencyHex]
|
|
1435
|
+
},
|
|
1436
|
+
{
|
|
1437
|
+
address: diamondAddress,
|
|
1438
|
+
abi: ABIS.FACETS.ORDER_PROCESSOR,
|
|
1439
|
+
functionName: "getSmallOrderFixedFee",
|
|
1440
|
+
args: [currencyHex]
|
|
1441
|
+
}
|
|
1442
|
+
];
|
|
1443
|
+
const toError = (error) => new Error("Fee config contract read failed", { cause: error });
|
|
1444
|
+
const exec = async () => {
|
|
1445
|
+
if (publicClient.multicall) {
|
|
1446
|
+
const [smallOrderThreshold2, smallOrderFixedFee2] = await publicClient.multicall({
|
|
1447
|
+
contracts: calls,
|
|
1448
|
+
allowFailure: false
|
|
1449
|
+
});
|
|
1450
|
+
return { smallOrderThreshold: smallOrderThreshold2, smallOrderFixedFee: smallOrderFixedFee2 };
|
|
1451
|
+
}
|
|
1452
|
+
const [smallOrderThreshold, smallOrderFixedFee] = await Promise.all(
|
|
1453
|
+
calls.map((c) => publicClient.readContract(c))
|
|
1454
|
+
);
|
|
1455
|
+
return { smallOrderThreshold, smallOrderFixedFee };
|
|
1456
|
+
};
|
|
1457
|
+
return import_neverthrow5.ResultAsync.fromPromise(exec(), toError);
|
|
1458
|
+
}
|
|
932
1459
|
|
|
933
|
-
// src/
|
|
934
|
-
var
|
|
1460
|
+
// src/orders/actions/approve-usdc.ts
|
|
1461
|
+
var import_viem4 = require("viem");
|
|
1462
|
+
|
|
1463
|
+
// src/orders/errors.ts
|
|
1464
|
+
var OrdersError = class extends SdkError {
|
|
935
1465
|
constructor(message, options) {
|
|
936
1466
|
super(message, options);
|
|
937
|
-
this.name = "
|
|
1467
|
+
this.name = "OrdersError";
|
|
938
1468
|
}
|
|
939
1469
|
};
|
|
940
1470
|
|
|
941
|
-
// src/
|
|
1471
|
+
// src/orders/tx.ts
|
|
1472
|
+
var import_neverthrow6 = require("neverthrow");
|
|
1473
|
+
function submitPreparedTx(input) {
|
|
1474
|
+
const { prepared, walletClient, publicClient, waitForReceipt, extraMeta } = input;
|
|
1475
|
+
const account = walletClient.account;
|
|
1476
|
+
if (!account) {
|
|
1477
|
+
return (0, import_neverthrow6.errAsync)(
|
|
1478
|
+
new OrdersError("WalletClient is missing an account", {
|
|
1479
|
+
code: "TX_SUBMISSION_FAILED"
|
|
1480
|
+
})
|
|
1481
|
+
);
|
|
1482
|
+
}
|
|
1483
|
+
const chain = walletClient.chain;
|
|
1484
|
+
return import_neverthrow6.ResultAsync.fromPromise(
|
|
1485
|
+
walletClient.sendTransaction({
|
|
1486
|
+
account,
|
|
1487
|
+
chain,
|
|
1488
|
+
to: prepared.to,
|
|
1489
|
+
data: prepared.data,
|
|
1490
|
+
value: prepared.value
|
|
1491
|
+
}),
|
|
1492
|
+
(cause) => new OrdersError("walletClient.sendTransaction rejected", {
|
|
1493
|
+
code: "TX_SUBMISSION_FAILED",
|
|
1494
|
+
cause
|
|
1495
|
+
})
|
|
1496
|
+
).andThen((hash) => {
|
|
1497
|
+
const combinedMeta = prepared.meta || extraMeta ? { ...prepared.meta, ...extraMeta } : void 0;
|
|
1498
|
+
if (!waitForReceipt) {
|
|
1499
|
+
return (0, import_neverthrow6.okAsync)({ hash, meta: combinedMeta });
|
|
1500
|
+
}
|
|
1501
|
+
return import_neverthrow6.ResultAsync.fromPromise(
|
|
1502
|
+
publicClient.waitForTransactionReceipt({ hash }),
|
|
1503
|
+
(cause) => new OrdersError("waitForTransactionReceipt failed", {
|
|
1504
|
+
code: "RECEIPT_TIMEOUT",
|
|
1505
|
+
cause
|
|
1506
|
+
})
|
|
1507
|
+
).andThen((receipt) => {
|
|
1508
|
+
if (receipt.status !== "success") {
|
|
1509
|
+
return (0, import_neverthrow6.errAsync)(
|
|
1510
|
+
new OrdersError("Transaction reverted", {
|
|
1511
|
+
code: "TX_REVERTED",
|
|
1512
|
+
context: { hash, blockNumber: receipt.blockNumber.toString() }
|
|
1513
|
+
})
|
|
1514
|
+
);
|
|
1515
|
+
}
|
|
1516
|
+
return (0, import_neverthrow6.okAsync)({ hash, receipt, meta: combinedMeta });
|
|
1517
|
+
});
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
// src/orders/validation.ts
|
|
942
1522
|
var import_zod3 = require("zod");
|
|
943
|
-
var
|
|
944
|
-
|
|
945
|
-
});
|
|
946
|
-
var ZodCircleMetricsForRoutingSchema = import_zod3.z.object({
|
|
947
|
-
circleScore: import_zod3.z.coerce.number(),
|
|
948
|
-
circleStatus: import_zod3.z.string(),
|
|
949
|
-
scoreState: ZodCircleScoreStateSchema
|
|
1523
|
+
var ZodGetOrderParamsSchema = import_zod3.z.object({
|
|
1524
|
+
orderId: import_zod3.z.bigint().positive()
|
|
950
1525
|
});
|
|
951
|
-
var
|
|
952
|
-
|
|
953
|
-
currency: import_zod3.z.string(),
|
|
954
|
-
metrics: ZodCircleMetricsForRoutingSchema
|
|
1526
|
+
var ZodGetFeeConfigParamsSchema = import_zod3.z.object({
|
|
1527
|
+
currency: ZodCurrencySchema
|
|
955
1528
|
});
|
|
956
|
-
var
|
|
957
|
-
|
|
1529
|
+
var ZodGetOrdersParamsSchema = import_zod3.z.object({
|
|
1530
|
+
userAddress: ZodAddressSchema,
|
|
1531
|
+
skip: import_zod3.z.number().int().min(0).default(0),
|
|
1532
|
+
limit: import_zod3.z.number().int().min(1).max(100).default(20)
|
|
958
1533
|
});
|
|
959
|
-
var
|
|
960
|
-
|
|
961
|
-
currency:
|
|
1534
|
+
var ZodPlaceOrderParamsSchema = import_zod3.z.object({
|
|
1535
|
+
orderType: import_zod3.z.number().int().min(0).max(2),
|
|
1536
|
+
currency: ZodCurrencySchema,
|
|
962
1537
|
user: ZodAddressSchema,
|
|
963
|
-
|
|
1538
|
+
amount: import_zod3.z.bigint(),
|
|
964
1539
|
fiatAmount: import_zod3.z.bigint(),
|
|
965
|
-
|
|
966
|
-
|
|
1540
|
+
fiatAmountLimit: import_zod3.z.bigint().optional().default(0n),
|
|
1541
|
+
recipientAddr: ZodAddressSchema,
|
|
1542
|
+
preferredPaymentChannelConfigId: import_zod3.z.bigint().optional(),
|
|
1543
|
+
pubKey: import_zod3.z.string().optional()
|
|
967
1544
|
});
|
|
968
|
-
var
|
|
969
|
-
|
|
970
|
-
user: ZodAddressSchema,
|
|
971
|
-
usdtAmount: import_zod3.z.bigint(),
|
|
972
|
-
fiatAmount: import_zod3.z.bigint(),
|
|
973
|
-
orderType: import_zod3.z.bigint(),
|
|
974
|
-
preferredPCConfigId: import_zod3.z.bigint()
|
|
1545
|
+
var ZodCancelOrderParamsSchema = import_zod3.z.object({
|
|
1546
|
+
orderId: import_zod3.z.bigint().nonnegative()
|
|
975
1547
|
});
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
params,
|
|
982
|
-
(message, cause, d) => new OrderRoutingError(message, { code: "VALIDATION_ERROR", cause, context: { data: d } })
|
|
983
|
-
).asyncAndThen((validated) => {
|
|
984
|
-
logger.debug("checking on-chain eligibility", {
|
|
985
|
-
circleId: String(validated.circleId),
|
|
986
|
-
contractAddress
|
|
987
|
-
});
|
|
988
|
-
return import_neverthrow4.ResultAsync.fromPromise(
|
|
989
|
-
publicClient.readContract({
|
|
990
|
-
address: contractAddress,
|
|
991
|
-
abi: ABIS.FACETS.ORDER_FLOW,
|
|
992
|
-
functionName: "getAssignableMerchantsFromCircle",
|
|
993
|
-
args: [
|
|
994
|
-
validated.circleId,
|
|
995
|
-
1n,
|
|
996
|
-
validated.currency,
|
|
997
|
-
validated.user,
|
|
998
|
-
validated.usdtAmount,
|
|
999
|
-
validated.fiatAmount,
|
|
1000
|
-
validated.orderType,
|
|
1001
|
-
validated.preferredPCConfigId
|
|
1002
|
-
]
|
|
1003
|
-
}),
|
|
1004
|
-
(error) => new OrderRoutingError("Eligibility check failed", {
|
|
1005
|
-
code: "CONTRACT_READ_ERROR",
|
|
1006
|
-
cause: error,
|
|
1007
|
-
context: { circleId: String(params.circleId) }
|
|
1008
|
-
})
|
|
1009
|
-
);
|
|
1010
|
-
}).map((merchants) => {
|
|
1011
|
-
const arr = merchants;
|
|
1012
|
-
const eligible = arr.length >= 1;
|
|
1013
|
-
logger.debug("eligibility check result", {
|
|
1014
|
-
circleId: String(params.circleId),
|
|
1015
|
-
assignableMerchants: arr.length,
|
|
1016
|
-
eligible
|
|
1017
|
-
});
|
|
1018
|
-
return eligible;
|
|
1019
|
-
});
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
// src/contracts/p2p-config/index.ts
|
|
1023
|
-
var import_neverthrow5 = require("neverthrow");
|
|
1024
|
-
var import_viem3 = require("viem");
|
|
1025
|
-
|
|
1026
|
-
// src/profile/errors.ts
|
|
1027
|
-
var ProfileError = class extends SdkError {
|
|
1028
|
-
constructor(message, options) {
|
|
1029
|
-
super(message, options);
|
|
1030
|
-
this.name = "ProfileError";
|
|
1031
|
-
}
|
|
1032
|
-
};
|
|
1033
|
-
|
|
1034
|
-
// src/profile/validation.ts
|
|
1035
|
-
var import_zod4 = require("zod");
|
|
1036
|
-
var ZodUsdcBalanceParamsSchema = import_zod4.z.object({
|
|
1037
|
-
address: ZodAddressSchema
|
|
1548
|
+
var ZodSetSellOrderUpiParamsSchema = import_zod3.z.object({
|
|
1549
|
+
orderId: import_zod3.z.bigint().nonnegative(),
|
|
1550
|
+
paymentAddress: import_zod3.z.string().min(1),
|
|
1551
|
+
merchantPublicKey: import_zod3.z.string().min(1),
|
|
1552
|
+
updatedAmount: import_zod3.z.bigint()
|
|
1038
1553
|
});
|
|
1039
|
-
var
|
|
1040
|
-
|
|
1041
|
-
|
|
1554
|
+
var ZodRaiseDisputeParamsSchema = import_zod3.z.object({
|
|
1555
|
+
orderId: import_zod3.z.bigint().nonnegative(),
|
|
1556
|
+
redactTransId: import_zod3.z.bigint().nonnegative()
|
|
1042
1557
|
});
|
|
1043
|
-
var
|
|
1044
|
-
|
|
1045
|
-
currency: ZodCurrencySchema
|
|
1558
|
+
var ZodApproveUsdcParamsSchema = import_zod3.z.object({
|
|
1559
|
+
amount: import_zod3.z.bigint().nonnegative()
|
|
1046
1560
|
});
|
|
1047
|
-
var
|
|
1048
|
-
|
|
1561
|
+
var ZodPaidBuyOrderParamsSchema = import_zod3.z.object({
|
|
1562
|
+
orderId: import_zod3.z.bigint().nonnegative()
|
|
1563
|
+
});
|
|
1564
|
+
var HexString = import_zod3.z.string().regex(/^0x[0-9a-fA-F]*$/, "Expected 0x-prefixed hex");
|
|
1565
|
+
var ZodSubgraphOrderSchema = import_zod3.z.object({
|
|
1566
|
+
orderId: import_zod3.z.string(),
|
|
1567
|
+
type: import_zod3.z.number().int().min(0),
|
|
1568
|
+
status: import_zod3.z.number().int().min(0),
|
|
1569
|
+
circleId: import_zod3.z.string(),
|
|
1570
|
+
userAddress: HexString,
|
|
1571
|
+
usdcRecipientAddress: HexString,
|
|
1572
|
+
acceptedMerchantAddress: HexString,
|
|
1573
|
+
usdcAmount: import_zod3.z.string(),
|
|
1574
|
+
fiatAmount: import_zod3.z.string(),
|
|
1575
|
+
actualUsdcAmount: import_zod3.z.string(),
|
|
1576
|
+
actualFiatAmount: import_zod3.z.string(),
|
|
1577
|
+
currency: HexString,
|
|
1578
|
+
placedAt: import_zod3.z.string(),
|
|
1579
|
+
acceptedAt: import_zod3.z.string(),
|
|
1580
|
+
paidAt: import_zod3.z.string(),
|
|
1581
|
+
completedAt: import_zod3.z.string(),
|
|
1582
|
+
fixedFeePaid: import_zod3.z.string(),
|
|
1583
|
+
tipsPaid: import_zod3.z.string(),
|
|
1584
|
+
disputeStatus: import_zod3.z.number().int().min(0)
|
|
1585
|
+
});
|
|
1586
|
+
var ZodSubgraphOrdersResponseSchema = import_zod3.z.object({
|
|
1587
|
+
orders_collection: import_zod3.z.array(ZodSubgraphOrderSchema)
|
|
1049
1588
|
});
|
|
1050
1589
|
|
|
1051
|
-
// src/
|
|
1052
|
-
function
|
|
1053
|
-
|
|
1054
|
-
|
|
1590
|
+
// src/orders/actions/approve-usdc.ts
|
|
1591
|
+
function createApproveUsdcAction(input) {
|
|
1592
|
+
const { publicClient, diamondAddress, usdcAddress } = input;
|
|
1593
|
+
const prepareFn = (params) => validate(
|
|
1594
|
+
ZodApproveUsdcParamsSchema,
|
|
1055
1595
|
params,
|
|
1056
|
-
(message, cause, data) => new
|
|
1596
|
+
(message, cause, data) => new OrdersError(message, {
|
|
1057
1597
|
code: "VALIDATION_ERROR",
|
|
1058
1598
|
cause,
|
|
1059
|
-
context: {
|
|
1599
|
+
context: { data }
|
|
1060
1600
|
})
|
|
1061
|
-
).
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
)
|
|
1075
|
-
|
|
1601
|
+
).map(({ amount }) => ({
|
|
1602
|
+
to: usdcAddress,
|
|
1603
|
+
data: (0, import_viem4.encodeFunctionData)({
|
|
1604
|
+
abi: import_viem4.erc20Abi,
|
|
1605
|
+
functionName: "approve",
|
|
1606
|
+
args: [diamondAddress, amount]
|
|
1607
|
+
}),
|
|
1608
|
+
value: 0n
|
|
1609
|
+
}));
|
|
1610
|
+
return {
|
|
1611
|
+
prepare(params) {
|
|
1612
|
+
return prepareFn(params).asyncMap(async (tx) => tx);
|
|
1613
|
+
},
|
|
1614
|
+
execute({ walletClient, waitForReceipt, ...params }) {
|
|
1615
|
+
return prepareFn(params).asyncAndThen(
|
|
1616
|
+
(prepared) => submitPreparedTx({ prepared, walletClient, publicClient, waitForReceipt })
|
|
1617
|
+
);
|
|
1618
|
+
}
|
|
1619
|
+
};
|
|
1076
1620
|
}
|
|
1077
1621
|
|
|
1078
|
-
// src/
|
|
1079
|
-
var
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
// src/zkkyc/validation.ts
|
|
1091
|
-
var import_zod5 = require("zod");
|
|
1092
|
-
var ZodAnonAadharProofParamsSchema = import_zod5.z.object({
|
|
1093
|
-
nullifierSeed: import_zod5.z.bigint(),
|
|
1094
|
-
nullifier: import_zod5.z.bigint(),
|
|
1095
|
-
timestamp: import_zod5.z.bigint(),
|
|
1096
|
-
signal: import_zod5.z.bigint(),
|
|
1097
|
-
revealArray: import_zod5.z.tuple([import_zod5.z.bigint(), import_zod5.z.bigint(), import_zod5.z.bigint(), import_zod5.z.bigint()]),
|
|
1098
|
-
packedGroth16Proof: import_zod5.z.tuple([
|
|
1099
|
-
import_zod5.z.bigint(),
|
|
1100
|
-
import_zod5.z.bigint(),
|
|
1101
|
-
import_zod5.z.bigint(),
|
|
1102
|
-
import_zod5.z.bigint(),
|
|
1103
|
-
import_zod5.z.bigint(),
|
|
1104
|
-
import_zod5.z.bigint(),
|
|
1105
|
-
import_zod5.z.bigint(),
|
|
1106
|
-
import_zod5.z.bigint()
|
|
1107
|
-
])
|
|
1108
|
-
});
|
|
1109
|
-
var ZodSocialVerifyParamsSchema = import_zod5.z.object({
|
|
1110
|
-
_socialName: import_zod5.z.string(),
|
|
1111
|
-
proofs: import_zod5.z.array(
|
|
1112
|
-
import_zod5.z.object({
|
|
1113
|
-
claimInfo: import_zod5.z.object({
|
|
1114
|
-
provider: import_zod5.z.string(),
|
|
1115
|
-
parameters: import_zod5.z.string(),
|
|
1116
|
-
context: import_zod5.z.string()
|
|
1117
|
-
}),
|
|
1118
|
-
signedClaim: import_zod5.z.object({
|
|
1119
|
-
claim: import_zod5.z.object({
|
|
1120
|
-
identifier: import_zod5.z.string(),
|
|
1121
|
-
owner: ZodAddressSchema,
|
|
1122
|
-
timestampS: import_zod5.z.number(),
|
|
1123
|
-
epoch: import_zod5.z.number()
|
|
1124
|
-
}),
|
|
1125
|
-
signatures: import_zod5.z.array(import_zod5.z.string())
|
|
1126
|
-
})
|
|
1622
|
+
// src/orders/actions/cancel-order.ts
|
|
1623
|
+
var import_viem5 = require("viem");
|
|
1624
|
+
function createCancelOrderAction(input) {
|
|
1625
|
+
const { publicClient, diamondAddress } = input;
|
|
1626
|
+
const prepareFn = (params) => validate(
|
|
1627
|
+
ZodCancelOrderParamsSchema,
|
|
1628
|
+
params,
|
|
1629
|
+
(message, cause, data) => new OrdersError(message, {
|
|
1630
|
+
code: "VALIDATION_ERROR",
|
|
1631
|
+
cause,
|
|
1632
|
+
context: { data }
|
|
1127
1633
|
})
|
|
1128
|
-
)
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
proofVerificationData: import_zod5.z.object({
|
|
1135
|
-
vkeyHash: import_zod5.z.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
|
|
1136
|
-
message: "Invalid bytes32 hex string"
|
|
1634
|
+
).map(({ orderId }) => ({
|
|
1635
|
+
to: diamondAddress,
|
|
1636
|
+
data: (0, import_viem5.encodeFunctionData)({
|
|
1637
|
+
abi: ABIS.FACETS.ORDER_FLOW,
|
|
1638
|
+
functionName: "cancelOrder",
|
|
1639
|
+
args: [orderId]
|
|
1137
1640
|
}),
|
|
1138
|
-
|
|
1139
|
-
|
|
1641
|
+
value: 0n
|
|
1642
|
+
}));
|
|
1643
|
+
return {
|
|
1644
|
+
prepare(params) {
|
|
1645
|
+
return prepareFn(params).asyncMap(async (tx) => tx);
|
|
1646
|
+
},
|
|
1647
|
+
execute({ walletClient, waitForReceipt, ...params }) {
|
|
1648
|
+
return prepareFn(params).asyncAndThen(
|
|
1649
|
+
(prepared) => submitPreparedTx({ prepared, walletClient, publicClient, waitForReceipt })
|
|
1650
|
+
);
|
|
1651
|
+
}
|
|
1652
|
+
};
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
// src/orders/actions/paid-buy-order.ts
|
|
1656
|
+
var import_viem6 = require("viem");
|
|
1657
|
+
function createPaidBuyOrderAction(input) {
|
|
1658
|
+
const { publicClient, diamondAddress } = input;
|
|
1659
|
+
const prepareFn = (params) => validate(
|
|
1660
|
+
ZodPaidBuyOrderParamsSchema,
|
|
1661
|
+
params,
|
|
1662
|
+
(message, cause, data) => new OrdersError(message, {
|
|
1663
|
+
code: "VALIDATION_ERROR",
|
|
1664
|
+
cause,
|
|
1665
|
+
context: { data }
|
|
1666
|
+
})
|
|
1667
|
+
).map(({ orderId }) => ({
|
|
1668
|
+
to: diamondAddress,
|
|
1669
|
+
data: (0, import_viem6.encodeFunctionData)({
|
|
1670
|
+
abi: ABIS.FACETS.ORDER_PROCESSOR,
|
|
1671
|
+
functionName: "paidBuyOrder",
|
|
1672
|
+
args: [orderId]
|
|
1140
1673
|
}),
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1674
|
+
value: 0n
|
|
1675
|
+
}));
|
|
1676
|
+
return {
|
|
1677
|
+
prepare(params) {
|
|
1678
|
+
return prepareFn(params).asyncMap(async (tx) => tx);
|
|
1679
|
+
},
|
|
1680
|
+
execute({ walletClient, waitForReceipt, ...params }) {
|
|
1681
|
+
return prepareFn(params).asyncAndThen(
|
|
1682
|
+
(prepared) => submitPreparedTx({ prepared, walletClient, publicClient, waitForReceipt })
|
|
1683
|
+
);
|
|
1684
|
+
}
|
|
1685
|
+
};
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
// src/orders/actions/place-order.ts
|
|
1689
|
+
var import_viem8 = require("viem");
|
|
1690
|
+
|
|
1691
|
+
// src/constants/orders.constant.ts
|
|
1692
|
+
var ORDER_TYPE = {
|
|
1693
|
+
BUY: 0,
|
|
1694
|
+
SELL: 1,
|
|
1695
|
+
PAY: 2
|
|
1696
|
+
};
|
|
1697
|
+
var ORDER_STATUS = {
|
|
1698
|
+
PLACED: 0,
|
|
1699
|
+
ACCEPTED: 1,
|
|
1700
|
+
PAID: 2,
|
|
1701
|
+
COMPLETED: 3,
|
|
1702
|
+
CANCELLED: 4
|
|
1703
|
+
};
|
|
1704
|
+
var DISPUTE_STATUS = {
|
|
1705
|
+
NONE: 0,
|
|
1706
|
+
OPEN: 1,
|
|
1707
|
+
RESOLVED: 2
|
|
1708
|
+
};
|
|
1709
|
+
|
|
1710
|
+
// src/orders/relay-identity/identity.ts
|
|
1711
|
+
var import_viem7 = require("viem");
|
|
1712
|
+
var import_accounts = require("viem/accounts");
|
|
1713
|
+
var import_zod4 = require("zod");
|
|
1714
|
+
var ZodRelayIdentitySchema = import_zod4.z.object({
|
|
1715
|
+
address: import_zod4.z.string().refine(import_viem7.isAddress, { message: "Invalid relay identity address" }),
|
|
1716
|
+
publicKey: import_zod4.z.string().refine((v) => (0, import_viem7.isHex)(`0x${v}`), {
|
|
1717
|
+
message: "Invalid relay identity public key"
|
|
1149
1718
|
}),
|
|
1150
|
-
|
|
1151
|
-
validityPeriodInSeconds: import_zod5.z.number().int().nonnegative(),
|
|
1152
|
-
domain: import_zod5.z.string(),
|
|
1153
|
-
scope: import_zod5.z.string(),
|
|
1154
|
-
devMode: import_zod5.z.boolean()
|
|
1155
|
-
})
|
|
1156
|
-
});
|
|
1157
|
-
var ZodZkPassportRegisterParamsSchema = import_zod5.z.object({
|
|
1158
|
-
params: ZodSolidityVerifierParametersSchema,
|
|
1159
|
-
isIDCard: import_zod5.z.boolean()
|
|
1719
|
+
privateKey: import_zod4.z.string().refine(import_viem7.isHex, { message: "Invalid relay identity private key" })
|
|
1160
1720
|
});
|
|
1721
|
+
function createRelayIdentity() {
|
|
1722
|
+
const privateKey = (0, import_accounts.generatePrivateKey)();
|
|
1723
|
+
const account = (0, import_accounts.privateKeyToAccount)(privateKey);
|
|
1724
|
+
const publicKey = account.publicKey.slice(4);
|
|
1725
|
+
return {
|
|
1726
|
+
address: account.address,
|
|
1727
|
+
publicKey,
|
|
1728
|
+
privateKey
|
|
1729
|
+
};
|
|
1730
|
+
}
|
|
1161
1731
|
|
|
1162
|
-
// src/
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1732
|
+
// src/orders/relay-identity/resolve.ts
|
|
1733
|
+
var import_neverthrow7 = require("neverthrow");
|
|
1734
|
+
|
|
1735
|
+
// src/orders/relay-identity/stores.ts
|
|
1736
|
+
var RelayIdentityCorruptError = class extends Error {
|
|
1737
|
+
constructor(cause) {
|
|
1738
|
+
super("Stored relay identity is corrupt", { cause });
|
|
1739
|
+
this.name = "RelayIdentityCorruptError";
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
function createInMemoryRelayStore() {
|
|
1743
|
+
let value = null;
|
|
1744
|
+
return {
|
|
1745
|
+
async get() {
|
|
1746
|
+
return value;
|
|
1747
|
+
},
|
|
1748
|
+
async set(identity) {
|
|
1749
|
+
value = identity;
|
|
1750
|
+
}
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
// src/orders/relay-identity/resolve.ts
|
|
1755
|
+
var pending = /* @__PURE__ */ new WeakMap();
|
|
1756
|
+
async function resolveFromStore(store) {
|
|
1757
|
+
let stored;
|
|
1758
|
+
try {
|
|
1759
|
+
stored = await store.get();
|
|
1760
|
+
} catch (cause) {
|
|
1761
|
+
if (cause instanceof RelayIdentityCorruptError) {
|
|
1762
|
+
return (0, import_neverthrow7.err)(
|
|
1763
|
+
new OrdersError("Stored relay identity is corrupt", {
|
|
1764
|
+
code: "RELAY_IDENTITY_CORRUPT",
|
|
1765
|
+
cause: cause.cause
|
|
1189
1766
|
})
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1767
|
+
);
|
|
1768
|
+
}
|
|
1769
|
+
return (0, import_neverthrow7.err)(
|
|
1770
|
+
new OrdersError("Relay identity store.get failed", {
|
|
1771
|
+
code: "RELAY_IDENTITY_STORE_FAILED",
|
|
1772
|
+
cause
|
|
1194
1773
|
})
|
|
1195
|
-
)
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
(validated) => import_neverthrow6.Result.fromThrowable(
|
|
1205
|
-
() => ({
|
|
1206
|
-
to: reputationManagerAddress,
|
|
1207
|
-
data: (0, import_viem4.encodeFunctionData)({
|
|
1208
|
-
abi: ABIS.EXTERNAL.REPUTATION_MANAGER,
|
|
1209
|
-
functionName: "submitAnonAadharProof",
|
|
1210
|
-
args: [
|
|
1211
|
-
validated.nullifierSeed,
|
|
1212
|
-
validated.nullifier,
|
|
1213
|
-
validated.timestamp,
|
|
1214
|
-
validated.signal,
|
|
1215
|
-
validated.revealArray,
|
|
1216
|
-
validated.packedGroth16Proof
|
|
1217
|
-
]
|
|
1774
|
+
);
|
|
1775
|
+
}
|
|
1776
|
+
if (stored !== null) {
|
|
1777
|
+
const parsed = ZodRelayIdentitySchema.safeParse(stored);
|
|
1778
|
+
if (!parsed.success) {
|
|
1779
|
+
return (0, import_neverthrow7.err)(
|
|
1780
|
+
new OrdersError("Stored relay identity failed validation", {
|
|
1781
|
+
code: "RELAY_IDENTITY_CORRUPT",
|
|
1782
|
+
cause: parsed.error
|
|
1218
1783
|
})
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1784
|
+
);
|
|
1785
|
+
}
|
|
1786
|
+
return (0, import_neverthrow7.ok)(stored);
|
|
1787
|
+
}
|
|
1788
|
+
const fresh = createRelayIdentity();
|
|
1789
|
+
try {
|
|
1790
|
+
await store.set(fresh);
|
|
1791
|
+
} catch (cause) {
|
|
1792
|
+
return (0, import_neverthrow7.err)(
|
|
1793
|
+
new OrdersError("Relay identity store.set failed", {
|
|
1794
|
+
code: "RELAY_IDENTITY_STORE_FAILED",
|
|
1795
|
+
cause
|
|
1223
1796
|
})
|
|
1224
|
-
)
|
|
1225
|
-
|
|
1797
|
+
);
|
|
1798
|
+
}
|
|
1799
|
+
return (0, import_neverthrow7.ok)(fresh);
|
|
1226
1800
|
}
|
|
1227
|
-
function
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
)
|
|
1233
|
-
(
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
proof: proofVerificationData.proof,
|
|
1241
|
-
publicInputs: proofVerificationData.publicInputs
|
|
1242
|
-
},
|
|
1243
|
-
committedInputs,
|
|
1244
|
-
serviceConfig: {
|
|
1245
|
-
validityPeriodInSeconds: BigInt(serviceConfig.validityPeriodInSeconds),
|
|
1246
|
-
domain: serviceConfig.domain,
|
|
1247
|
-
scope: serviceConfig.scope,
|
|
1248
|
-
devMode: serviceConfig.devMode
|
|
1249
|
-
}
|
|
1250
|
-
};
|
|
1251
|
-
return {
|
|
1252
|
-
to: reputationManagerAddress,
|
|
1253
|
-
data: (0, import_viem4.encodeFunctionData)({
|
|
1254
|
-
abi: ABIS.EXTERNAL.REPUTATION_MANAGER,
|
|
1255
|
-
functionName: "zkPassportRegister",
|
|
1256
|
-
args: [proofVerificationParams, validated.isIDCard]
|
|
1257
|
-
})
|
|
1258
|
-
};
|
|
1259
|
-
},
|
|
1260
|
-
(error) => new ZkkycError("Failed to encode zkPassportRegister", {
|
|
1261
|
-
code: "ENCODE_ERROR",
|
|
1262
|
-
cause: error
|
|
1263
|
-
})
|
|
1264
|
-
)()
|
|
1265
|
-
);
|
|
1801
|
+
function resolveRelayIdentity(input) {
|
|
1802
|
+
if (input.relayIdentity) {
|
|
1803
|
+
return (0, import_neverthrow7.okAsync)(input.relayIdentity);
|
|
1804
|
+
}
|
|
1805
|
+
const existing = pending.get(input.store);
|
|
1806
|
+
if (existing) {
|
|
1807
|
+
return import_neverthrow7.ResultAsync.fromSafePromise(existing).andThen((r) => r);
|
|
1808
|
+
}
|
|
1809
|
+
const promise = resolveFromStore(input.store).finally(() => {
|
|
1810
|
+
pending.delete(input.store);
|
|
1811
|
+
});
|
|
1812
|
+
pending.set(input.store, promise);
|
|
1813
|
+
return import_neverthrow7.ResultAsync.fromSafePromise(promise).andThen((r) => r);
|
|
1266
1814
|
}
|
|
1267
1815
|
|
|
1268
|
-
// src/
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1816
|
+
// src/orders/actions/place-order.ts
|
|
1817
|
+
function enrichWithOrderId(result, userAddress) {
|
|
1818
|
+
if (!result.receipt) return result;
|
|
1819
|
+
try {
|
|
1820
|
+
const events = (0, import_viem8.parseEventLogs)({
|
|
1821
|
+
abi: ABIS.FACETS.ORDER_FLOW,
|
|
1822
|
+
eventName: "OrderPlaced",
|
|
1823
|
+
logs: result.receipt.logs
|
|
1824
|
+
});
|
|
1825
|
+
const lowered = userAddress.toLowerCase();
|
|
1826
|
+
const mine = events.find((e) => e.args.user?.toLowerCase() === lowered);
|
|
1827
|
+
const chosen = mine ?? events[0];
|
|
1828
|
+
if (!chosen) return result;
|
|
1829
|
+
const orderId = chosen.args.orderId;
|
|
1830
|
+
if (orderId === void 0) return result;
|
|
1831
|
+
return { ...result, meta: { ...result.meta, orderId } };
|
|
1832
|
+
} catch {
|
|
1833
|
+
return result;
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
function createPlaceOrderAction(input) {
|
|
1837
|
+
const { publicClient, diamondAddress, orderRouter, relayIdentityStore, relayIdentity } = input;
|
|
1838
|
+
const prepareFn = (params) => validate(
|
|
1839
|
+
ZodPlaceOrderParamsSchema,
|
|
1274
1840
|
params,
|
|
1275
|
-
(message, cause, data) => new
|
|
1841
|
+
(message, cause, data) => new OrdersError(message, {
|
|
1276
1842
|
code: "VALIDATION_ERROR",
|
|
1277
1843
|
cause,
|
|
1278
|
-
context: {
|
|
1844
|
+
context: { data }
|
|
1279
1845
|
})
|
|
1280
|
-
).asyncAndThen(
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1846
|
+
).asyncAndThen((v) => {
|
|
1847
|
+
const pcConfigId = v.preferredPaymentChannelConfigId ?? 0n;
|
|
1848
|
+
const circleResult = orderRouter.selectCircle({
|
|
1849
|
+
currency: v.currency,
|
|
1850
|
+
user: v.user,
|
|
1851
|
+
usdtAmount: v.amount,
|
|
1852
|
+
fiatAmount: v.fiatAmount,
|
|
1853
|
+
orderType: BigInt(v.orderType),
|
|
1854
|
+
preferredPCConfigId: pcConfigId
|
|
1855
|
+
}).mapErr(
|
|
1856
|
+
(cause) => new OrdersError(`Circle selection failed: ${cause.message}`, {
|
|
1857
|
+
code: "CIRCLE_SELECTION_FAILED",
|
|
1858
|
+
cause
|
|
1292
1859
|
})
|
|
1293
|
-
)
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1860
|
+
);
|
|
1861
|
+
const identityResult = resolveRelayIdentity({
|
|
1862
|
+
relayIdentity,
|
|
1863
|
+
store: relayIdentityStore
|
|
1864
|
+
});
|
|
1865
|
+
return identityResult.andThen(
|
|
1866
|
+
(senderIdentity) => circleResult.map((circleId) => {
|
|
1867
|
+
const isBuy = v.orderType === ORDER_TYPE.BUY;
|
|
1868
|
+
const keyFromCaller = v.pubKey ?? senderIdentity.publicKey;
|
|
1869
|
+
const pubKey = isBuy ? keyFromCaller : "";
|
|
1870
|
+
const userPubKey = isBuy ? "" : keyFromCaller;
|
|
1871
|
+
const currencyBytes32 = (0, import_viem8.stringToHex)(v.currency, { size: 32 });
|
|
1872
|
+
const data = (0, import_viem8.encodeFunctionData)({
|
|
1873
|
+
abi: ABIS.FACETS.ORDER_FLOW,
|
|
1874
|
+
functionName: "placeOrder",
|
|
1875
|
+
args: [
|
|
1876
|
+
pubKey,
|
|
1877
|
+
v.amount,
|
|
1878
|
+
v.recipientAddr,
|
|
1879
|
+
v.orderType,
|
|
1880
|
+
"",
|
|
1881
|
+
// _userUpi — set later via setSellOrderUpi if applicable
|
|
1882
|
+
userPubKey,
|
|
1883
|
+
currencyBytes32,
|
|
1884
|
+
pcConfigId,
|
|
1885
|
+
circleId,
|
|
1886
|
+
v.fiatAmountLimit ?? 0n
|
|
1887
|
+
]
|
|
1888
|
+
});
|
|
1889
|
+
return {
|
|
1890
|
+
to: diamondAddress,
|
|
1891
|
+
data,
|
|
1892
|
+
value: 0n,
|
|
1893
|
+
meta: { circleId, relayIdentity: senderIdentity }
|
|
1894
|
+
};
|
|
1895
|
+
})
|
|
1896
|
+
);
|
|
1897
|
+
});
|
|
1898
|
+
return {
|
|
1899
|
+
prepare(params) {
|
|
1900
|
+
return prepareFn(params);
|
|
1901
|
+
},
|
|
1902
|
+
execute({ walletClient, waitForReceipt, ...params }) {
|
|
1903
|
+
const owner = walletClient.account?.address;
|
|
1904
|
+
const enrich = (r) => owner ? enrichWithOrderId(r, owner) : r;
|
|
1905
|
+
return prepareFn(params).andThen(
|
|
1906
|
+
(prepared) => submitPreparedTx({ prepared, walletClient, publicClient, waitForReceipt }).map(enrich)
|
|
1907
|
+
);
|
|
1908
|
+
}
|
|
1909
|
+
};
|
|
1298
1910
|
}
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1911
|
+
|
|
1912
|
+
// src/orders/actions/raise-dispute.ts
|
|
1913
|
+
var import_viem9 = require("viem");
|
|
1914
|
+
function createRaiseDisputeAction(input) {
|
|
1915
|
+
const { publicClient, diamondAddress } = input;
|
|
1916
|
+
const prepareFn = (params) => validate(
|
|
1917
|
+
ZodRaiseDisputeParamsSchema,
|
|
1302
1918
|
params,
|
|
1303
|
-
(message, cause, data) => new
|
|
1919
|
+
(message, cause, data) => new OrdersError(message, {
|
|
1304
1920
|
code: "VALIDATION_ERROR",
|
|
1305
1921
|
cause,
|
|
1306
|
-
context: {
|
|
1922
|
+
context: { data }
|
|
1307
1923
|
})
|
|
1308
|
-
).
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
|
-
// src/contracts/usdc/index.ts
|
|
1330
|
-
var import_neverthrow8 = require("neverthrow");
|
|
1331
|
-
function getUsdcBalance(publicClient, usdcAddress, params) {
|
|
1332
|
-
return validate(
|
|
1333
|
-
ZodUsdcBalanceParamsSchema,
|
|
1334
|
-
params,
|
|
1335
|
-
(message, cause, data) => new ProfileError(message, {
|
|
1336
|
-
code: "VALIDATION_ERROR",
|
|
1337
|
-
cause,
|
|
1338
|
-
context: { params: data }
|
|
1339
|
-
})
|
|
1340
|
-
).asyncAndThen(
|
|
1341
|
-
(validated) => import_neverthrow8.ResultAsync.fromPromise(
|
|
1342
|
-
publicClient.readContract({
|
|
1343
|
-
address: usdcAddress,
|
|
1344
|
-
abi: ABIS.EXTERNAL.USDC,
|
|
1345
|
-
functionName: "balanceOf",
|
|
1346
|
-
args: [validated.address]
|
|
1347
|
-
}),
|
|
1348
|
-
(error) => new ProfileError("Failed to read USDC balance", {
|
|
1349
|
-
code: "CONTRACT_READ_ERROR",
|
|
1350
|
-
cause: error,
|
|
1351
|
-
context: { address: validated.address, usdcAddress }
|
|
1352
|
-
})
|
|
1353
|
-
)
|
|
1354
|
-
);
|
|
1924
|
+
).map(({ orderId, redactTransId }) => ({
|
|
1925
|
+
to: diamondAddress,
|
|
1926
|
+
data: (0, import_viem9.encodeFunctionData)({
|
|
1927
|
+
abi: ABIS.FACETS.ORDER_PROCESSOR,
|
|
1928
|
+
functionName: "raiseDispute",
|
|
1929
|
+
args: [orderId, redactTransId]
|
|
1930
|
+
}),
|
|
1931
|
+
value: 0n
|
|
1932
|
+
}));
|
|
1933
|
+
return {
|
|
1934
|
+
prepare(params) {
|
|
1935
|
+
return prepareFn(params).asyncMap(async (tx) => tx);
|
|
1936
|
+
},
|
|
1937
|
+
execute({ walletClient, waitForReceipt, ...params }) {
|
|
1938
|
+
return prepareFn(params).asyncAndThen(
|
|
1939
|
+
(prepared) => submitPreparedTx({ prepared, walletClient, publicClient, waitForReceipt })
|
|
1940
|
+
);
|
|
1941
|
+
}
|
|
1942
|
+
};
|
|
1355
1943
|
}
|
|
1356
1944
|
|
|
1357
|
-
// src/order-
|
|
1358
|
-
var
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
var
|
|
1362
|
-
var
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
return Math.min(score, BOOTSTRAP_MAX_WEIGHT);
|
|
1370
|
-
}
|
|
1371
|
-
return score;
|
|
1945
|
+
// src/orders/actions/set-sell-order-upi.ts
|
|
1946
|
+
var import_viem11 = require("viem");
|
|
1947
|
+
|
|
1948
|
+
// src/orders/crypto/encryption.ts
|
|
1949
|
+
var import_neverthrow8 = require("neverthrow");
|
|
1950
|
+
var import_viem10 = require("viem");
|
|
1951
|
+
var import_accounts2 = require("viem/accounts");
|
|
1952
|
+
var import_zod5 = require("zod");
|
|
1953
|
+
|
|
1954
|
+
// node_modules/@noble/ciphers/esm/utils.js
|
|
1955
|
+
function isBytes(a) {
|
|
1956
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
1372
1957
|
}
|
|
1373
|
-
function
|
|
1374
|
-
|
|
1958
|
+
function abytes(b, ...lengths) {
|
|
1959
|
+
if (!isBytes(b))
|
|
1960
|
+
throw new Error("Uint8Array expected");
|
|
1961
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
1962
|
+
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
1375
1963
|
}
|
|
1376
|
-
function
|
|
1377
|
-
|
|
1378
|
-
if (totalWeight === 0) {
|
|
1379
|
-
return arr[Math.floor(Math.random() * arr.length)];
|
|
1380
|
-
}
|
|
1381
|
-
let rand = Math.random() * totalWeight;
|
|
1382
|
-
for (let i = 0; i < arr.length; i++) {
|
|
1383
|
-
rand -= weights[i];
|
|
1384
|
-
if (rand <= 0) {
|
|
1385
|
-
return arr[i];
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
return arr[arr.length - 1];
|
|
1964
|
+
function u32(arr) {
|
|
1965
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
1389
1966
|
}
|
|
1390
|
-
function
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
}
|
|
1394
|
-
const activeCircles = eligible.filter((c) => c.metrics.circleStatus === "active");
|
|
1395
|
-
const isExplore = Math.random() < EPSILON;
|
|
1396
|
-
if (isExplore) {
|
|
1397
|
-
const weights2 = eligible.map(circleWeight);
|
|
1398
|
-
return weightedRandomChoice(eligible, weights2);
|
|
1399
|
-
}
|
|
1400
|
-
if (activeCircles.length === 0) {
|
|
1401
|
-
const weights2 = eligible.map(circleWeight);
|
|
1402
|
-
return weightedRandomChoice(eligible, weights2);
|
|
1967
|
+
function clean(...arrays) {
|
|
1968
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
1969
|
+
arrays[i].fill(0);
|
|
1403
1970
|
}
|
|
1404
|
-
const weights = activeCircles.map((c) => c.metrics.circleScore);
|
|
1405
|
-
return weightedRandomChoice(activeCircles, weights);
|
|
1406
1971
|
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
if (
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1972
|
+
var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
1973
|
+
function overlapBytes(a, b) {
|
|
1974
|
+
return a.buffer === b.buffer && // best we can do, may fail with an obscure Proxy
|
|
1975
|
+
a.byteOffset < b.byteOffset + b.byteLength && // a starts before b end
|
|
1976
|
+
b.byteOffset < a.byteOffset + a.byteLength;
|
|
1977
|
+
}
|
|
1978
|
+
function complexOverlapBytes(input, output) {
|
|
1979
|
+
if (overlapBytes(input, output) && input.byteOffset < output.byteOffset)
|
|
1980
|
+
throw new Error("complex overlap of input and output is not supported");
|
|
1981
|
+
}
|
|
1982
|
+
var wrapCipher = /* @__NO_SIDE_EFFECTS__ */ (params, constructor) => {
|
|
1983
|
+
function wrappedCipher(key, ...args) {
|
|
1984
|
+
abytes(key);
|
|
1985
|
+
if (!isLE)
|
|
1986
|
+
throw new Error("Non little-endian hardware is not yet supported");
|
|
1987
|
+
if (params.nonceLength !== void 0) {
|
|
1988
|
+
const nonce = args[0];
|
|
1989
|
+
if (!nonce)
|
|
1990
|
+
throw new Error("nonce / iv required");
|
|
1991
|
+
if (params.varSizeNonce)
|
|
1992
|
+
abytes(nonce);
|
|
1993
|
+
else
|
|
1994
|
+
abytes(nonce, params.nonceLength);
|
|
1430
1995
|
}
|
|
1431
|
-
const
|
|
1432
|
-
if (
|
|
1433
|
-
|
|
1434
|
-
new OrderRoutingError("No eligible circles found", {
|
|
1435
|
-
code: "NO_ELIGIBLE_CIRCLES"
|
|
1436
|
-
})
|
|
1437
|
-
);
|
|
1996
|
+
const tagl = params.tagLength;
|
|
1997
|
+
if (tagl && args[1] !== void 0) {
|
|
1998
|
+
abytes(args[1]);
|
|
1438
1999
|
}
|
|
1439
|
-
const
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
});
|
|
1446
|
-
return validateCircle(circleId).orElse((error) => {
|
|
1447
|
-
logger.warn("validation errored, treating as ineligible", {
|
|
1448
|
-
circleId: String(circleId),
|
|
1449
|
-
error: String(error)
|
|
1450
|
-
});
|
|
1451
|
-
return (0, import_neverthrow9.okAsync)(false);
|
|
1452
|
-
}).andThen((isValid) => {
|
|
1453
|
-
if (isValid) {
|
|
1454
|
-
logger.info("circle validated successfully", { circleId: String(circleId) });
|
|
1455
|
-
return (0, import_neverthrow9.okAsync)(circleId);
|
|
2000
|
+
const cipher = constructor(key, ...args);
|
|
2001
|
+
const checkOutput = (fnLength, output) => {
|
|
2002
|
+
if (output !== void 0) {
|
|
2003
|
+
if (fnLength !== 2)
|
|
2004
|
+
throw new Error("cipher output not supported");
|
|
2005
|
+
abytes(output);
|
|
1456
2006
|
}
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
2007
|
+
};
|
|
2008
|
+
let called = false;
|
|
2009
|
+
const wrCipher = {
|
|
2010
|
+
encrypt(data, output) {
|
|
2011
|
+
if (called)
|
|
2012
|
+
throw new Error("cannot encrypt() twice with same key + nonce");
|
|
2013
|
+
called = true;
|
|
2014
|
+
abytes(data);
|
|
2015
|
+
checkOutput(cipher.encrypt.length, output);
|
|
2016
|
+
return cipher.encrypt(data, output);
|
|
2017
|
+
},
|
|
2018
|
+
decrypt(data, output) {
|
|
2019
|
+
abytes(data);
|
|
2020
|
+
if (tagl && data.length < tagl)
|
|
2021
|
+
throw new Error("invalid ciphertext length: smaller than tagLength=" + tagl);
|
|
2022
|
+
checkOutput(cipher.decrypt.length, output);
|
|
2023
|
+
return cipher.decrypt(data, output);
|
|
2024
|
+
}
|
|
2025
|
+
};
|
|
2026
|
+
return wrCipher;
|
|
1464
2027
|
}
|
|
1465
|
-
|
|
2028
|
+
Object.assign(wrappedCipher, params);
|
|
2029
|
+
return wrappedCipher;
|
|
2030
|
+
};
|
|
2031
|
+
function getOutput(expectedLength, out, onlyAligned = true) {
|
|
2032
|
+
if (out === void 0)
|
|
2033
|
+
return new Uint8Array(expectedLength);
|
|
2034
|
+
if (out.length !== expectedLength)
|
|
2035
|
+
throw new Error("invalid output length, expected " + expectedLength + ", got: " + out.length);
|
|
2036
|
+
if (onlyAligned && !isAligned32(out))
|
|
2037
|
+
throw new Error("invalid output, must be aligned");
|
|
2038
|
+
return out;
|
|
2039
|
+
}
|
|
2040
|
+
function isAligned32(bytes) {
|
|
2041
|
+
return bytes.byteOffset % 4 === 0;
|
|
2042
|
+
}
|
|
2043
|
+
function copyBytes(bytes) {
|
|
2044
|
+
return Uint8Array.from(bytes);
|
|
1466
2045
|
}
|
|
1467
2046
|
|
|
1468
|
-
//
|
|
1469
|
-
var
|
|
1470
|
-
var
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
function isTransient(error) {
|
|
1474
|
-
if (error instanceof OrderRoutingError) return false;
|
|
1475
|
-
if (error instanceof DOMException && error.name === "AbortError") return true;
|
|
1476
|
-
if (error instanceof TypeError) return true;
|
|
1477
|
-
return false;
|
|
1478
|
-
}
|
|
1479
|
-
function querySubgraph(url, params) {
|
|
1480
|
-
const timeoutMs = params.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
1481
|
-
const fetchOnce = async () => {
|
|
1482
|
-
const controller = new AbortController();
|
|
1483
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
1484
|
-
try {
|
|
1485
|
-
const response = await fetch(url, {
|
|
1486
|
-
method: "POST",
|
|
1487
|
-
headers: { "Content-Type": "application/json" },
|
|
1488
|
-
body: JSON.stringify({
|
|
1489
|
-
query: params.query,
|
|
1490
|
-
variables: params.variables
|
|
1491
|
-
}),
|
|
1492
|
-
signal: controller.signal
|
|
1493
|
-
});
|
|
1494
|
-
if (!response.ok) {
|
|
1495
|
-
throw new OrderRoutingError(`Subgraph request failed (status: ${response.status})`, {
|
|
1496
|
-
code: "SUBGRAPH_ERROR",
|
|
1497
|
-
cause: response,
|
|
1498
|
-
context: { status: response.status }
|
|
1499
|
-
});
|
|
1500
|
-
}
|
|
1501
|
-
const json = await response.json();
|
|
1502
|
-
if (json.errors?.length > 0) {
|
|
1503
|
-
throw new OrderRoutingError("Subgraph returned GraphQL errors", {
|
|
1504
|
-
code: "SUBGRAPH_ERROR",
|
|
1505
|
-
cause: json.errors,
|
|
1506
|
-
context: { errors: json.errors }
|
|
1507
|
-
});
|
|
1508
|
-
}
|
|
1509
|
-
if (!json.data) {
|
|
1510
|
-
throw new OrderRoutingError("Subgraph returned no data", {
|
|
1511
|
-
code: "SUBGRAPH_ERROR",
|
|
1512
|
-
cause: "Missing data field in GraphQL response",
|
|
1513
|
-
context: { response: json }
|
|
1514
|
-
});
|
|
1515
|
-
}
|
|
1516
|
-
return json.data;
|
|
1517
|
-
} finally {
|
|
1518
|
-
clearTimeout(timer);
|
|
1519
|
-
}
|
|
1520
|
-
};
|
|
1521
|
-
const fetchWithRetry = async () => {
|
|
1522
|
-
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
1523
|
-
try {
|
|
1524
|
-
return await fetchOnce();
|
|
1525
|
-
} catch (error) {
|
|
1526
|
-
const lastAttempt = attempt === MAX_RETRIES;
|
|
1527
|
-
if (lastAttempt || !isTransient(error)) throw error;
|
|
1528
|
-
await sleep(BACKOFF_MS * (attempt + 1));
|
|
1529
|
-
}
|
|
1530
|
-
}
|
|
1531
|
-
throw new OrderRoutingError("Subgraph query exhausted retries", {
|
|
1532
|
-
code: "SUBGRAPH_ERROR"
|
|
1533
|
-
});
|
|
1534
|
-
};
|
|
1535
|
-
return import_neverthrow10.ResultAsync.fromPromise(
|
|
1536
|
-
fetchWithRetry(),
|
|
1537
|
-
(error) => error instanceof OrderRoutingError ? error : new OrderRoutingError("Subgraph query failed", {
|
|
1538
|
-
code: "SUBGRAPH_ERROR",
|
|
1539
|
-
cause: error
|
|
1540
|
-
})
|
|
1541
|
-
);
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
// src/order-routing/subgraph/queries.ts
|
|
1545
|
-
var CIRCLES_FOR_ROUTING_QUERY = (
|
|
1546
|
-
/* GraphQL */
|
|
1547
|
-
`
|
|
1548
|
-
query CirclesForRouting($currency: Bytes!) {
|
|
1549
|
-
circles(
|
|
1550
|
-
first: 1000
|
|
1551
|
-
where: {
|
|
1552
|
-
currency: $currency
|
|
1553
|
-
metrics_: {
|
|
1554
|
-
circleStatus_in: ["active", "bootstrap", "paused"]
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
) {
|
|
1558
|
-
circleId
|
|
1559
|
-
currency
|
|
1560
|
-
metrics {
|
|
1561
|
-
circleScore
|
|
1562
|
-
circleStatus
|
|
1563
|
-
scoreState {
|
|
1564
|
-
activeMerchantsCount
|
|
1565
|
-
}
|
|
1566
|
-
}
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
`
|
|
1570
|
-
);
|
|
1571
|
-
|
|
1572
|
-
// src/order-routing/subgraph/index.ts
|
|
1573
|
-
function getCirclesForRouting(subgraphUrl, currency, logger = noopLogger) {
|
|
1574
|
-
logger.debug("fetching circles from subgraph", { subgraphUrl, currency });
|
|
1575
|
-
return querySubgraph(subgraphUrl, {
|
|
1576
|
-
query: CIRCLES_FOR_ROUTING_QUERY,
|
|
1577
|
-
variables: { currency }
|
|
1578
|
-
}).andThen(
|
|
1579
|
-
(data) => validate(
|
|
1580
|
-
ZodCirclesForRoutingResponseSchema,
|
|
1581
|
-
data,
|
|
1582
|
-
(message, cause, d) => new OrderRoutingError(message, { code: "VALIDATION_ERROR", cause, context: { data: d } })
|
|
1583
|
-
).map((validated) => {
|
|
1584
|
-
const circles = validated.circles.filter(
|
|
1585
|
-
(item) => Number(item.metrics.scoreState.activeMerchantsCount) > 0
|
|
1586
|
-
);
|
|
1587
|
-
logger.info("fetched circles from subgraph", {
|
|
1588
|
-
total: validated.circles.length,
|
|
1589
|
-
withActiveMerchants: circles.length,
|
|
1590
|
-
circles
|
|
1591
|
-
});
|
|
1592
|
-
return circles;
|
|
1593
|
-
})
|
|
1594
|
-
);
|
|
1595
|
-
}
|
|
1596
|
-
|
|
1597
|
-
// src/order-routing/client.ts
|
|
1598
|
-
function createOrderRouter(config) {
|
|
1599
|
-
const { subgraphUrl, publicClient, contractAddress } = config;
|
|
1600
|
-
const logger = config.logger ?? noopLogger;
|
|
1601
|
-
return {
|
|
1602
|
-
selectCircle(params) {
|
|
1603
|
-
const currencyHex = (0, import_viem6.stringToHex)(params.currency, { size: 32 });
|
|
1604
|
-
logger.info("selectCircle started", {
|
|
1605
|
-
currency: params.currency,
|
|
1606
|
-
user: params.user,
|
|
1607
|
-
orderType: String(params.orderType)
|
|
1608
|
-
});
|
|
1609
|
-
return getCirclesForRouting(subgraphUrl, currencyHex, logger).andThen(
|
|
1610
|
-
(circles) => selectCircleForOrderAsync(
|
|
1611
|
-
circles,
|
|
1612
|
-
currencyHex,
|
|
1613
|
-
(circleId) => checkCircleEligibility(
|
|
1614
|
-
publicClient,
|
|
1615
|
-
contractAddress,
|
|
1616
|
-
{
|
|
1617
|
-
circleId,
|
|
1618
|
-
currency: currencyHex,
|
|
1619
|
-
user: params.user,
|
|
1620
|
-
usdtAmount: params.usdtAmount,
|
|
1621
|
-
fiatAmount: params.fiatAmount,
|
|
1622
|
-
orderType: params.orderType,
|
|
1623
|
-
preferredPCConfigId: params.preferredPCConfigId
|
|
1624
|
-
},
|
|
1625
|
-
logger
|
|
1626
|
-
),
|
|
1627
|
-
logger
|
|
1628
|
-
)
|
|
1629
|
-
);
|
|
1630
|
-
}
|
|
1631
|
-
};
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1634
|
-
// src/payload/actions.ts
|
|
1635
|
-
var import_neverthrow13 = require("neverthrow");
|
|
1636
|
-
|
|
1637
|
-
// src/payload/crypto.ts
|
|
1638
|
-
var import_neverthrow12 = require("neverthrow");
|
|
1639
|
-
var import_viem8 = require("viem");
|
|
1640
|
-
var import_accounts2 = require("viem/accounts");
|
|
1641
|
-
var import_zod7 = require("zod");
|
|
1642
|
-
|
|
1643
|
-
// node_modules/@noble/ciphers/esm/utils.js
|
|
1644
|
-
function isBytes(a) {
|
|
1645
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
1646
|
-
}
|
|
1647
|
-
function abytes(b, ...lengths) {
|
|
1648
|
-
if (!isBytes(b))
|
|
1649
|
-
throw new Error("Uint8Array expected");
|
|
1650
|
-
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
1651
|
-
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
1652
|
-
}
|
|
1653
|
-
function u32(arr) {
|
|
1654
|
-
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
1655
|
-
}
|
|
1656
|
-
function clean(...arrays) {
|
|
1657
|
-
for (let i = 0; i < arrays.length; i++) {
|
|
1658
|
-
arrays[i].fill(0);
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
1662
|
-
function overlapBytes(a, b) {
|
|
1663
|
-
return a.buffer === b.buffer && // best we can do, may fail with an obscure Proxy
|
|
1664
|
-
a.byteOffset < b.byteOffset + b.byteLength && // a starts before b end
|
|
1665
|
-
b.byteOffset < a.byteOffset + a.byteLength;
|
|
1666
|
-
}
|
|
1667
|
-
function complexOverlapBytes(input, output) {
|
|
1668
|
-
if (overlapBytes(input, output) && input.byteOffset < output.byteOffset)
|
|
1669
|
-
throw new Error("complex overlap of input and output is not supported");
|
|
1670
|
-
}
|
|
1671
|
-
var wrapCipher = /* @__NO_SIDE_EFFECTS__ */ (params, constructor) => {
|
|
1672
|
-
function wrappedCipher(key, ...args) {
|
|
1673
|
-
abytes(key);
|
|
1674
|
-
if (!isLE)
|
|
1675
|
-
throw new Error("Non little-endian hardware is not yet supported");
|
|
1676
|
-
if (params.nonceLength !== void 0) {
|
|
1677
|
-
const nonce = args[0];
|
|
1678
|
-
if (!nonce)
|
|
1679
|
-
throw new Error("nonce / iv required");
|
|
1680
|
-
if (params.varSizeNonce)
|
|
1681
|
-
abytes(nonce);
|
|
1682
|
-
else
|
|
1683
|
-
abytes(nonce, params.nonceLength);
|
|
1684
|
-
}
|
|
1685
|
-
const tagl = params.tagLength;
|
|
1686
|
-
if (tagl && args[1] !== void 0) {
|
|
1687
|
-
abytes(args[1]);
|
|
1688
|
-
}
|
|
1689
|
-
const cipher = constructor(key, ...args);
|
|
1690
|
-
const checkOutput = (fnLength, output) => {
|
|
1691
|
-
if (output !== void 0) {
|
|
1692
|
-
if (fnLength !== 2)
|
|
1693
|
-
throw new Error("cipher output not supported");
|
|
1694
|
-
abytes(output);
|
|
1695
|
-
}
|
|
1696
|
-
};
|
|
1697
|
-
let called = false;
|
|
1698
|
-
const wrCipher = {
|
|
1699
|
-
encrypt(data, output) {
|
|
1700
|
-
if (called)
|
|
1701
|
-
throw new Error("cannot encrypt() twice with same key + nonce");
|
|
1702
|
-
called = true;
|
|
1703
|
-
abytes(data);
|
|
1704
|
-
checkOutput(cipher.encrypt.length, output);
|
|
1705
|
-
return cipher.encrypt(data, output);
|
|
1706
|
-
},
|
|
1707
|
-
decrypt(data, output) {
|
|
1708
|
-
abytes(data);
|
|
1709
|
-
if (tagl && data.length < tagl)
|
|
1710
|
-
throw new Error("invalid ciphertext length: smaller than tagLength=" + tagl);
|
|
1711
|
-
checkOutput(cipher.decrypt.length, output);
|
|
1712
|
-
return cipher.decrypt(data, output);
|
|
1713
|
-
}
|
|
1714
|
-
};
|
|
1715
|
-
return wrCipher;
|
|
1716
|
-
}
|
|
1717
|
-
Object.assign(wrappedCipher, params);
|
|
1718
|
-
return wrappedCipher;
|
|
1719
|
-
};
|
|
1720
|
-
function getOutput(expectedLength, out, onlyAligned = true) {
|
|
1721
|
-
if (out === void 0)
|
|
1722
|
-
return new Uint8Array(expectedLength);
|
|
1723
|
-
if (out.length !== expectedLength)
|
|
1724
|
-
throw new Error("invalid output length, expected " + expectedLength + ", got: " + out.length);
|
|
1725
|
-
if (onlyAligned && !isAligned32(out))
|
|
1726
|
-
throw new Error("invalid output, must be aligned");
|
|
1727
|
-
return out;
|
|
1728
|
-
}
|
|
1729
|
-
function isAligned32(bytes) {
|
|
1730
|
-
return bytes.byteOffset % 4 === 0;
|
|
1731
|
-
}
|
|
1732
|
-
function copyBytes(bytes) {
|
|
1733
|
-
return Uint8Array.from(bytes);
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1736
|
-
// node_modules/@noble/ciphers/esm/aes.js
|
|
1737
|
-
var BLOCK_SIZE = 16;
|
|
1738
|
-
var POLY = 283;
|
|
1739
|
-
function mul2(n) {
|
|
1740
|
-
return n << 1 ^ POLY & -(n >> 7);
|
|
2047
|
+
// node_modules/@noble/ciphers/esm/aes.js
|
|
2048
|
+
var BLOCK_SIZE = 16;
|
|
2049
|
+
var POLY = 283;
|
|
2050
|
+
function mul2(n) {
|
|
2051
|
+
return n << 1 ^ POLY & -(n >> 7);
|
|
1741
2052
|
}
|
|
1742
2053
|
function mul(a, b) {
|
|
1743
2054
|
let res = 0;
|
|
@@ -3587,15 +3898,15 @@ function weierstrassPoints(opts) {
|
|
|
3587
3898
|
throw new Error("ProjectivePoint expected");
|
|
3588
3899
|
}
|
|
3589
3900
|
const toAffineMemo = memoized((p, iz) => {
|
|
3590
|
-
const { px: x, py: y, pz:
|
|
3591
|
-
if (Fp.eql(
|
|
3901
|
+
const { px: x, py: y, pz: z10 } = p;
|
|
3902
|
+
if (Fp.eql(z10, Fp.ONE))
|
|
3592
3903
|
return { x, y };
|
|
3593
3904
|
const is0 = p.is0();
|
|
3594
3905
|
if (iz == null)
|
|
3595
|
-
iz = is0 ? Fp.ONE : Fp.inv(
|
|
3906
|
+
iz = is0 ? Fp.ONE : Fp.inv(z10);
|
|
3596
3907
|
const ax = Fp.mul(x, iz);
|
|
3597
3908
|
const ay = Fp.mul(y, iz);
|
|
3598
|
-
const zz = Fp.mul(
|
|
3909
|
+
const zz = Fp.mul(z10, iz);
|
|
3599
3910
|
if (is0)
|
|
3600
3911
|
return { x: Fp.ZERO, y: Fp.ZERO };
|
|
3601
3912
|
if (!Fp.eql(zz, Fp.ONE))
|
|
@@ -4356,7 +4667,8 @@ var sha2562 = sha256;
|
|
|
4356
4667
|
// node_modules/@noble/hashes/esm/sha512.js
|
|
4357
4668
|
var sha5122 = sha512;
|
|
4358
4669
|
|
|
4359
|
-
// src/
|
|
4670
|
+
// src/orders/crypto/ecies.ts
|
|
4671
|
+
var MIN_CIPHER_BYTES = 82;
|
|
4360
4672
|
function hexToBytes3(hex) {
|
|
4361
4673
|
const bytes = new Uint8Array(hex.length / 2);
|
|
4362
4674
|
for (let i = 0; i < bytes.length; i++) {
|
|
@@ -4369,243 +4681,1747 @@ function bytesToHex2(bytes) {
|
|
|
4369
4681
|
for (const b of bytes) {
|
|
4370
4682
|
hex += b.toString(16).padStart(2, "0");
|
|
4371
4683
|
}
|
|
4372
|
-
return hex;
|
|
4373
|
-
}
|
|
4374
|
-
function
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
}
|
|
4684
|
+
return hex;
|
|
4685
|
+
}
|
|
4686
|
+
function timingSafeEqual(a, b) {
|
|
4687
|
+
if (a.length !== b.length) return false;
|
|
4688
|
+
let diff = 0;
|
|
4689
|
+
for (let i = 0; i < a.length; i++) {
|
|
4690
|
+
diff |= a[i] ^ b[i];
|
|
4691
|
+
}
|
|
4692
|
+
return diff === 0;
|
|
4693
|
+
}
|
|
4694
|
+
function deriveKeys(sharedSecret) {
|
|
4695
|
+
const hash = sha5122(sharedSecret);
|
|
4696
|
+
return {
|
|
4697
|
+
encKey: hash.slice(0, 32),
|
|
4698
|
+
macKey: hash.slice(32)
|
|
4699
|
+
};
|
|
4700
|
+
}
|
|
4701
|
+
async function encryptWithPublicKey(publicKey, message) {
|
|
4702
|
+
const pubKeyBytes = hexToBytes3(`04${publicKey}`);
|
|
4703
|
+
const ephemPrivKey = randomBytes(32);
|
|
4704
|
+
const ephemPubKey = secp256k1.getPublicKey(ephemPrivKey, false);
|
|
4705
|
+
const sharedPoint = secp256k1.getSharedSecret(ephemPrivKey, pubKeyBytes, true);
|
|
4706
|
+
const sharedSecret = sharedPoint.slice(1);
|
|
4707
|
+
const { encKey, macKey } = deriveKeys(sharedSecret);
|
|
4708
|
+
const iv = randomBytes(16);
|
|
4709
|
+
const plaintext = new TextEncoder().encode(message);
|
|
4710
|
+
const cipher = cbc(encKey, iv);
|
|
4711
|
+
const ciphertext = cipher.encrypt(plaintext);
|
|
4712
|
+
const macData = concatBytes2(iv, ephemPubKey, ciphertext);
|
|
4713
|
+
const mac = hmac(sha2562, macKey, macData);
|
|
4714
|
+
return {
|
|
4715
|
+
iv: bytesToHex2(iv),
|
|
4716
|
+
ephemPublicKey: bytesToHex2(ephemPubKey),
|
|
4717
|
+
ciphertext: bytesToHex2(ciphertext),
|
|
4718
|
+
mac: bytesToHex2(mac)
|
|
4719
|
+
};
|
|
4720
|
+
}
|
|
4721
|
+
async function decryptWithPrivateKey(privateKey, encrypted) {
|
|
4722
|
+
const privKeyBytes = hexToBytes3(privateKey.replace(/^0x/, ""));
|
|
4723
|
+
const ephemPubKeyBytes = hexToBytes3(encrypted.ephemPublicKey);
|
|
4724
|
+
const ivBytes = hexToBytes3(encrypted.iv);
|
|
4725
|
+
const ciphertextBytes = hexToBytes3(encrypted.ciphertext);
|
|
4726
|
+
const macBytes = hexToBytes3(encrypted.mac);
|
|
4727
|
+
const sharedPoint = secp256k1.getSharedSecret(privKeyBytes, ephemPubKeyBytes, true);
|
|
4728
|
+
const sharedSecret = sharedPoint.slice(1);
|
|
4729
|
+
const { encKey, macKey } = deriveKeys(sharedSecret);
|
|
4730
|
+
const macData = concatBytes2(ivBytes, ephemPubKeyBytes, ciphertextBytes);
|
|
4731
|
+
const computedMac = hmac(sha2562, macKey, macData);
|
|
4732
|
+
if (!timingSafeEqual(computedMac, macBytes)) {
|
|
4733
|
+
throw new Error("MAC mismatch \u2014 ciphertext may be corrupted or tampered with");
|
|
4734
|
+
}
|
|
4735
|
+
const cipher = cbc(encKey, ivBytes);
|
|
4736
|
+
const plaintext = cipher.decrypt(ciphertextBytes);
|
|
4737
|
+
return new TextDecoder().decode(plaintext);
|
|
4738
|
+
}
|
|
4739
|
+
function cipherStringify(encrypted) {
|
|
4740
|
+
const ephemPubKeyBytes = hexToBytes3(encrypted.ephemPublicKey);
|
|
4741
|
+
const compressed = secp256k1.ProjectivePoint.fromHex(ephemPubKeyBytes).toRawBytes(true);
|
|
4742
|
+
const iv = hexToBytes3(encrypted.iv);
|
|
4743
|
+
const mac = hexToBytes3(encrypted.mac);
|
|
4744
|
+
const ciphertext = hexToBytes3(encrypted.ciphertext);
|
|
4745
|
+
return bytesToHex2(concatBytes2(iv, compressed, mac, ciphertext));
|
|
4746
|
+
}
|
|
4747
|
+
function cipherParse(str) {
|
|
4748
|
+
const buf = hexToBytes3(str);
|
|
4749
|
+
if (buf.length < MIN_CIPHER_BYTES) {
|
|
4750
|
+
throw new Error(
|
|
4751
|
+
`cipherParse: input too short (${buf.length} bytes, need at least ${MIN_CIPHER_BYTES})`
|
|
4752
|
+
);
|
|
4753
|
+
}
|
|
4754
|
+
const iv = buf.slice(0, 16);
|
|
4755
|
+
const compressed = buf.slice(16, 49);
|
|
4756
|
+
const mac = buf.slice(49, 81);
|
|
4757
|
+
const ciphertext = buf.slice(81);
|
|
4758
|
+
const ephemPubKey = secp256k1.ProjectivePoint.fromHex(compressed).toRawBytes(false);
|
|
4759
|
+
return {
|
|
4760
|
+
iv: bytesToHex2(iv),
|
|
4761
|
+
ephemPublicKey: bytesToHex2(ephemPubKey),
|
|
4762
|
+
ciphertext: bytesToHex2(ciphertext),
|
|
4763
|
+
mac: bytesToHex2(mac)
|
|
4764
|
+
};
|
|
4765
|
+
}
|
|
4766
|
+
|
|
4767
|
+
// src/orders/crypto/encryption.ts
|
|
4768
|
+
function tryParseLegacyEthCryptoEnvelope(input) {
|
|
4769
|
+
if (input.charCodeAt(0) !== 123) return void 0;
|
|
4770
|
+
let parsed;
|
|
4771
|
+
try {
|
|
4772
|
+
parsed = JSON.parse(input);
|
|
4773
|
+
} catch {
|
|
4774
|
+
return void 0;
|
|
4775
|
+
}
|
|
4776
|
+
if (!parsed || typeof parsed !== "object") return void 0;
|
|
4777
|
+
const o = parsed;
|
|
4778
|
+
if (typeof o.iv !== "string" || typeof o.ephemPublicKey !== "string" || typeof o.ciphertext !== "string" || typeof o.mac !== "string") {
|
|
4779
|
+
return void 0;
|
|
4780
|
+
}
|
|
4781
|
+
return {
|
|
4782
|
+
iv: o.iv,
|
|
4783
|
+
ephemPublicKey: o.ephemPublicKey,
|
|
4784
|
+
ciphertext: o.ciphertext,
|
|
4785
|
+
mac: o.mac
|
|
4786
|
+
};
|
|
4787
|
+
}
|
|
4788
|
+
function encryptPaymentAddress(input) {
|
|
4789
|
+
return (0, import_neverthrow8.safeTry)(async function* () {
|
|
4790
|
+
const messageHash = (0, import_viem10.keccak256)((0, import_viem10.stringToHex)(input.paymentAddress));
|
|
4791
|
+
const signature = yield* import_neverthrow8.ResultAsync.fromPromise(
|
|
4792
|
+
(0, import_accounts2.sign)({ hash: messageHash, privateKey: input.senderIdentity.privateKey }),
|
|
4793
|
+
(cause) => new OrdersError("Failed to sign payment address", {
|
|
4794
|
+
code: "ENCRYPTION_FAILED",
|
|
4795
|
+
cause
|
|
4796
|
+
})
|
|
4797
|
+
).map(import_viem10.serializeSignature);
|
|
4798
|
+
const payload = JSON.stringify({ message: input.paymentAddress, signature });
|
|
4799
|
+
const encrypted = yield* import_neverthrow8.ResultAsync.fromPromise(
|
|
4800
|
+
encryptWithPublicKey(input.recipientPublicKey, payload),
|
|
4801
|
+
(cause) => new OrdersError("ECIES encryption failed", {
|
|
4802
|
+
code: "ENCRYPTION_FAILED",
|
|
4803
|
+
cause
|
|
4804
|
+
})
|
|
4805
|
+
);
|
|
4806
|
+
const safeStringify = import_neverthrow8.Result.fromThrowable(
|
|
4807
|
+
(e) => cipherStringify(e),
|
|
4808
|
+
(cause) => new OrdersError("Ciphertext stringify failed", {
|
|
4809
|
+
code: "ENCRYPTION_FAILED",
|
|
4810
|
+
cause
|
|
4811
|
+
})
|
|
4812
|
+
);
|
|
4813
|
+
return (0, import_neverthrow8.ok)(yield* safeStringify(encrypted));
|
|
4814
|
+
});
|
|
4815
|
+
}
|
|
4816
|
+
var ZodDecryptedPayloadSchema = import_zod5.z.object({
|
|
4817
|
+
message: import_zod5.z.string(),
|
|
4818
|
+
signature: import_zod5.z.string()
|
|
4819
|
+
});
|
|
4820
|
+
function decryptPaymentAddress(input) {
|
|
4821
|
+
return (0, import_neverthrow8.safeTry)(async function* () {
|
|
4822
|
+
const legacyEnvelope = tryParseLegacyEthCryptoEnvelope(input.encrypted);
|
|
4823
|
+
const safeCipherParse = import_neverthrow8.Result.fromThrowable(
|
|
4824
|
+
(s) => cipherParse(s),
|
|
4825
|
+
(cause) => new OrdersError("Failed to parse ciphertext", {
|
|
4826
|
+
code: "ENCRYPTION_FAILED",
|
|
4827
|
+
cause
|
|
4828
|
+
})
|
|
4829
|
+
);
|
|
4830
|
+
const encryptedData = legacyEnvelope ?? (yield* safeCipherParse(input.encrypted));
|
|
4831
|
+
const plaintext = yield* import_neverthrow8.ResultAsync.fromPromise(
|
|
4832
|
+
decryptWithPrivateKey(input.recipientIdentity.privateKey, encryptedData),
|
|
4833
|
+
(cause) => new OrdersError("ECIES decryption failed", {
|
|
4834
|
+
code: "ENCRYPTION_FAILED",
|
|
4835
|
+
cause
|
|
4836
|
+
})
|
|
4837
|
+
);
|
|
4838
|
+
if (legacyEnvelope) {
|
|
4839
|
+
return (0, import_neverthrow8.ok)(plaintext);
|
|
4840
|
+
}
|
|
4841
|
+
const safeJsonParse = import_neverthrow8.Result.fromThrowable(
|
|
4842
|
+
(s) => JSON.parse(s),
|
|
4843
|
+
(cause) => new OrdersError("Failed to parse decrypted payload JSON", {
|
|
4844
|
+
code: "ENCRYPTION_FAILED",
|
|
4845
|
+
cause
|
|
4846
|
+
})
|
|
4847
|
+
);
|
|
4848
|
+
const parsed = yield* safeJsonParse(plaintext);
|
|
4849
|
+
const payload = yield* validate(
|
|
4850
|
+
ZodDecryptedPayloadSchema,
|
|
4851
|
+
parsed,
|
|
4852
|
+
(message, cause, data) => new OrdersError(message, {
|
|
4853
|
+
code: "ENCRYPTION_FAILED",
|
|
4854
|
+
cause,
|
|
4855
|
+
context: { data }
|
|
4856
|
+
})
|
|
4857
|
+
);
|
|
4858
|
+
return (0, import_neverthrow8.ok)(payload.message);
|
|
4859
|
+
});
|
|
4860
|
+
}
|
|
4861
|
+
|
|
4862
|
+
// src/orders/actions/set-sell-order-upi.ts
|
|
4863
|
+
function createSetSellOrderUpiAction(input) {
|
|
4864
|
+
const { publicClient, diamondAddress, relayIdentityStore, relayIdentity } = input;
|
|
4865
|
+
const prepareFn = (params) => validate(
|
|
4866
|
+
ZodSetSellOrderUpiParamsSchema,
|
|
4867
|
+
params,
|
|
4868
|
+
(message, cause, data) => new OrdersError(message, {
|
|
4869
|
+
code: "VALIDATION_ERROR",
|
|
4870
|
+
cause,
|
|
4871
|
+
context: { data }
|
|
4872
|
+
})
|
|
4873
|
+
).asyncAndThen(
|
|
4874
|
+
(v) => resolveRelayIdentity({ relayIdentity, store: relayIdentityStore }).andThen(
|
|
4875
|
+
(senderIdentity) => encryptPaymentAddress({
|
|
4876
|
+
paymentAddress: v.paymentAddress,
|
|
4877
|
+
recipientPublicKey: v.merchantPublicKey,
|
|
4878
|
+
senderIdentity
|
|
4879
|
+
}).map((userEncUpi) => ({ v, userEncUpi, senderIdentity }))
|
|
4880
|
+
)
|
|
4881
|
+
).map(({ v, userEncUpi, senderIdentity }) => ({
|
|
4882
|
+
to: diamondAddress,
|
|
4883
|
+
data: (0, import_viem11.encodeFunctionData)({
|
|
4884
|
+
abi: ABIS.FACETS.ORDER_FLOW,
|
|
4885
|
+
functionName: "setSellOrderUpi",
|
|
4886
|
+
args: [v.orderId, userEncUpi, v.updatedAmount]
|
|
4887
|
+
}),
|
|
4888
|
+
value: 0n,
|
|
4889
|
+
meta: { relayIdentity: senderIdentity }
|
|
4890
|
+
}));
|
|
4891
|
+
return {
|
|
4892
|
+
prepare(params) {
|
|
4893
|
+
return prepareFn(params);
|
|
4894
|
+
},
|
|
4895
|
+
execute({ walletClient, waitForReceipt, ...params }) {
|
|
4896
|
+
return prepareFn(params).andThen(
|
|
4897
|
+
(prepared) => submitPreparedTx({ prepared, walletClient, publicClient, waitForReceipt })
|
|
4898
|
+
);
|
|
4899
|
+
}
|
|
4900
|
+
};
|
|
4901
|
+
}
|
|
4902
|
+
|
|
4903
|
+
// src/orders/internal/routing/client.ts
|
|
4904
|
+
var import_viem16 = require("viem");
|
|
4905
|
+
|
|
4906
|
+
// src/contracts/errors.ts
|
|
4907
|
+
var contractErrors = {
|
|
4908
|
+
// Access control
|
|
4909
|
+
NotAdmin: "NOT_ADMIN",
|
|
4910
|
+
NotSuperAdmin: "NOT_SUPER_ADMIN",
|
|
4911
|
+
NotAuthorized: "NOT_AUTHORIZED",
|
|
4912
|
+
NotSelf: "NOT_SELF",
|
|
4913
|
+
NotWhitelisted: "NOT_WHITELISTED",
|
|
4914
|
+
NotCircleAdmin: "NOT_CIRCLE_ADMIN",
|
|
4915
|
+
// Circle / community management
|
|
4916
|
+
InvalidName: "INVALID_NAME",
|
|
4917
|
+
InvalidCommunityUrl: "INVALID_COMMUNITY_URL",
|
|
4918
|
+
InvalidAdminCommunityUrl: "INVALID_ADMIN_COMMUNITY_URL",
|
|
4919
|
+
AdminAlreadyHasCircle: "ADMIN_ALREADY_HAS_CIRCLE",
|
|
4920
|
+
CircleNameAlreadyTaken: "CIRCLE_NAME_ALREADY_TAKEN",
|
|
4921
|
+
P2PStakeConfigNotSet: "P2P_STAKE_CONFIG_NOT_SET",
|
|
4922
|
+
InsufficientP2PStake: "INSUFFICIENT_P2P_STAKE",
|
|
4923
|
+
P2PTokenNotSet: "P2P_TOKEN_NOT_SET",
|
|
4924
|
+
P2PUnstakeRequestPending: "P2P_UNSTAKE_REQUEST_PENDING",
|
|
4925
|
+
NoP2PUnstakeRequest: "NO_P2P_UNSTAKE_REQUEST",
|
|
4926
|
+
P2PUnstakeCooldownNotPassed: "P2P_UNSTAKE_COOLDOWN_NOT_PASSED",
|
|
4927
|
+
SlashAmountExceedsStake: "SLASH_AMOUNT_EXCEEDS_STAKE",
|
|
4928
|
+
CircleNotActive: "CIRCLE_NOT_ACTIVE",
|
|
4929
|
+
InvalidCircleId: "INVALID_CIRCLE_ID",
|
|
4930
|
+
CurrencyMismatch: "CURRENCY_MISMATCH",
|
|
4931
|
+
CircleFull: "CIRCLE_FULL",
|
|
4932
|
+
CircleIdMismatch: "CIRCLE_ID_MISMATCH",
|
|
4933
|
+
DuplicateAccountName: "DUPLICATE_ACCOUNT_NAME",
|
|
4934
|
+
EmptyName: "EMPTY_NAME",
|
|
4935
|
+
AccountBoundToAnotherCircle: "ACCOUNT_BOUND_TO_ANOTHER_CIRCLE",
|
|
4936
|
+
ExitAmountExceededCircleBalance: "EXIT_AMOUNT_EXCEEDED_CIRCLE_BALANCE",
|
|
4937
|
+
UndelegationAmountTooHigh: "UNDELEGATION_AMOUNT_TOO_HIGH",
|
|
4938
|
+
// Exchange / order lifecycle
|
|
4939
|
+
ExchangeNotOperational: "EXCHANGE_NOT_OPERATIONAL",
|
|
4940
|
+
OrderNotPlaced: "ORDER_NOT_PLACED",
|
|
4941
|
+
OrderNotPaid: "ORDER_NOT_PAID",
|
|
4942
|
+
OrderStatusInvalid: "ORDER_STATUS_INVALID",
|
|
4943
|
+
OrderExpired: "ORDER_EXPIRED",
|
|
4944
|
+
OrderAlreadyPaid: "ORDER_ALREADY_PAID",
|
|
4945
|
+
OrderAlreadyCompleted: "ORDER_ALREADY_COMPLETED",
|
|
4946
|
+
InvalidOrderType: "INVALID_ORDER_TYPE",
|
|
4947
|
+
OrderTypeIncorrect: "ORDER_TYPE_INCORRECT",
|
|
4948
|
+
OrderNotAccepted: "ORDER_NOT_ACCEPTED",
|
|
4949
|
+
OrderNotAssigned: "ORDER_NOT_ASSIGNED",
|
|
4950
|
+
OrderAmountExceedsLimit: "ORDER_AMOUNT_EXCEEDS_LIMIT",
|
|
4951
|
+
InvalidOrderAmount: "INVALID_ORDER_AMOUNT",
|
|
4952
|
+
InvalidOrderAmountToCoverFee: "INVALID_ORDER_AMOUNT_TO_COVER_FEE",
|
|
4953
|
+
InvalidOrderId: "INVALID_ORDER_ID",
|
|
4954
|
+
OrderTooEarlyForReassignment: "ORDER_TOO_EARLY_FOR_REASSIGNMENT",
|
|
4955
|
+
OrderTooLateForReassignment: "ORDER_TOO_LATE_FOR_REASSIGNMENT",
|
|
4956
|
+
ReAssignmentNotRequired: "REASSIGNMENT_NOT_REQUIRED",
|
|
4957
|
+
TipAlreadyGiven: "TIP_ALREADY_GIVEN",
|
|
4958
|
+
CashbackTransferFailed: "CASHBACK_TRANSFER_FAILED",
|
|
4959
|
+
// Order limits
|
|
4960
|
+
DailyBuyOrderLimitExceeded: "DAILY_BUY_ORDER_LIMIT_EXCEEDED",
|
|
4961
|
+
MonthlyBuyOrderLimitExceeded: "MONTHLY_BUY_ORDER_LIMIT_EXCEEDED",
|
|
4962
|
+
SellOrderAmountLimitExceeded: "SELL_ORDER_AMOUNT_LIMIT_EXCEEDED",
|
|
4963
|
+
BuyOrderAmountExceedsLimit: "BUY_ORDER_AMOUNT_EXCEEDS_LIMIT",
|
|
4964
|
+
SellOrderAmountExceedsLimit: "SELL_ORDER_AMOUNT_EXCEEDS_LIMIT",
|
|
4965
|
+
BuyAmountExceedsUsdcLimit: "BUY_AMOUNT_EXCEEDS_USDC_LIMIT",
|
|
4966
|
+
SellAmountExceedsFiatLimit: "SELL_AMOUNT_EXCEEDS_FIAT_LIMIT",
|
|
4967
|
+
DailyVolumeLimitExceeded: "DAILY_VOLUME_LIMIT_EXCEEDED",
|
|
4968
|
+
MonthlyVolumeLimitExceeded: "MONTHLY_VOLUME_LIMIT_EXCEEDED",
|
|
4969
|
+
UserYearlyVolumeLimitExceeded: "USER_YEARLY_VOLUME_LIMIT_EXCEEDED",
|
|
4970
|
+
// Dispute
|
|
4971
|
+
DisputeTimeNotReached: "DISPUTE_TIME_NOT_REACHED",
|
|
4972
|
+
DisputeTimeExpired: "DISPUTE_TIME_EXPIRED",
|
|
4973
|
+
InvalidOrderStatusToRaiseDispute: "INVALID_ORDER_STATUS_TO_RAISE_DISPUTE",
|
|
4974
|
+
DisputeNotRaised: "DISPUTE_NOT_RAISED",
|
|
4975
|
+
CannotRaiseDisputeTwice: "CANNOT_RAISE_DISPUTE_TWICE",
|
|
4976
|
+
DisputeAlreadySettled: "DISPUTE_ALREADY_SETTLED",
|
|
4977
|
+
TransactionIdMismatch: "TRANSACTION_ID_MISMATCH",
|
|
4978
|
+
AccountNumberMismatch: "ACCOUNT_NUMBER_MISMATCH",
|
|
4979
|
+
NotPaidBuyOrder: "NOT_PAID_BUY_ORDER",
|
|
4980
|
+
// Payment channels
|
|
4981
|
+
PaymentChannelNotFound: "PAYMENT_CHANNEL_NOT_FOUND",
|
|
4982
|
+
PaymentChannelNotActive: "PAYMENT_CHANNEL_NOT_ACTIVE",
|
|
4983
|
+
PaymentChannelNotApproved: "PAYMENT_CHANNEL_NOT_APPROVED",
|
|
4984
|
+
PaymentChannelNotRejected: "PAYMENT_CHANNEL_NOT_REJECTED",
|
|
4985
|
+
InvalidPaymentChannelId: "INVALID_PAYMENT_CHANNEL_ID",
|
|
4986
|
+
DuplicatePaymentChannel: "DUPLICATE_PAYMENT_CHANNEL",
|
|
4987
|
+
OldPaymentChannelNotFound: "OLD_PAYMENT_CHANNEL_NOT_FOUND",
|
|
4988
|
+
NewPaymentChannelNotFound: "NEW_PAYMENT_CHANNEL_NOT_FOUND",
|
|
4989
|
+
SamePaymentChannel: "SAME_PAYMENT_CHANNEL",
|
|
4990
|
+
OldPaymentChannelShouldBeInactive: "OLD_PAYMENT_CHANNEL_SHOULD_BE_INACTIVE",
|
|
4991
|
+
NewPaymentChannelShouldBeActive: "NEW_PAYMENT_CHANNEL_SHOULD_BE_ACTIVE",
|
|
4992
|
+
OngoingOrderOnPaymentChannel: "ONGOING_ORDER_ON_PAYMENT_CHANNEL",
|
|
4993
|
+
UpiAlreadySent: "UPI_ALREADY_SENT",
|
|
4994
|
+
InvalidOrderUpi: "INVALID_ORDER_UPI",
|
|
4995
|
+
NoFiatLiquidity: "NO_FIAT_LIQUIDITY",
|
|
4996
|
+
// Merchant
|
|
4997
|
+
NotEnoughEligibleMerchants: "NOT_ENOUGH_ELIGIBLE_MERCHANTS",
|
|
4998
|
+
MerchantNotRegistered: "MERCHANT_NOT_REGISTERED",
|
|
4999
|
+
MerchantNotApproved: "MERCHANT_NOT_APPROVED",
|
|
5000
|
+
MerchantAlreadyRegistered: "MERCHANT_ALREADY_REGISTERED",
|
|
5001
|
+
MerchantAlreadyRejected: "MERCHANT_ALREADY_REJECTED",
|
|
5002
|
+
MerchantBlacklisted: "MERCHANT_BLACKLISTED",
|
|
5003
|
+
MerchantNotBlacklisted: "MERCHANT_NOT_BLACKLISTED",
|
|
5004
|
+
MerchantAlreadyBlacklisted: "MERCHANT_ALREADY_BLACKLISTED",
|
|
5005
|
+
MerchantHasOngoingOrders: "MERCHANT_HAS_ONGOING_ORDERS",
|
|
5006
|
+
MerchantNotFullfilledEligibilityThreshold: "MERCHANT_NOT_FULLFILLED_ELIGIBILITY_THRESHOLD",
|
|
5007
|
+
InvalidMerchant: "INVALID_MERCHANT",
|
|
5008
|
+
// Staking / unstaking
|
|
5009
|
+
StakeAmountTooLow: "STAKE_AMOUNT_TOO_LOW",
|
|
5010
|
+
AdditionalStakeNotAllowed: "ADDITIONAL_STAKE_NOT_ALLOWED",
|
|
5011
|
+
UnstakeRequestPending: "UNSTAKE_REQUEST_PENDING",
|
|
5012
|
+
UnstakeRequestNotPending: "UNSTAKE_REQUEST_NOT_PENDING",
|
|
5013
|
+
UnstakeAmountExceeded: "UNSTAKE_AMOUNT_EXCEEDED",
|
|
5014
|
+
ZeroUnstakeAmount: "ZERO_UNSTAKE_AMOUNT",
|
|
5015
|
+
NoWithdrawableAmount: "NO_WITHDRAWABLE_AMOUNT",
|
|
5016
|
+
NoStake: "NO_STAKE",
|
|
5017
|
+
NoStakers: "NO_STAKERS",
|
|
5018
|
+
InsufficientStakedAmount: "INSUFFICIENT_STAKED_AMOUNT",
|
|
5019
|
+
CooldownNotPassed: "COOLDOWN_NOT_PASSED",
|
|
5020
|
+
ClaimableRewardsNotAvailable: "CLAIMABLE_REWARDS_NOT_AVAILABLE",
|
|
5021
|
+
// Delegation
|
|
5022
|
+
ExitWouldBreachDelegationInvariant: "EXIT_WOULD_BREACH_DELEGATION_INVARIANT",
|
|
5023
|
+
AggregateDelegationExceedsTotalStaked: "AGGREGATE_DELEGATION_EXCEEDS_TOTAL_STAKED",
|
|
5024
|
+
InsufficientMerchantRewards: "INSUFFICIENT_MERCHANT_REWARDS",
|
|
5025
|
+
// Migration
|
|
5026
|
+
InvalidMigrationStatus: "INVALID_MIGRATION_STATUS",
|
|
5027
|
+
MigrationRequestNotPending: "MIGRATION_REQUEST_NOT_PENDING",
|
|
5028
|
+
MigrationAlreadyRequested: "MIGRATION_ALREADY_REQUESTED",
|
|
5029
|
+
// Token / currency
|
|
5030
|
+
TokenAlreadyExists: "TOKEN_ALREADY_EXISTS",
|
|
5031
|
+
TokenNotFound: "TOKEN_NOT_FOUND",
|
|
5032
|
+
TokenEmpty: "TOKEN_EMPTY",
|
|
5033
|
+
CurrencyNotSupported: "CURRENCY_NOT_SUPPORTED",
|
|
5034
|
+
InvalidCurrency: "INVALID_CURRENCY",
|
|
5035
|
+
// USDC / transfer
|
|
5036
|
+
UsdtTransferFailed: "USDC_TRANSFER_FAILED",
|
|
5037
|
+
UsdtTransferFailedWithErrorMessage: "USDC_TRANSFER_FAILED_WITH_ERROR_MESSAGE",
|
|
5038
|
+
UsdtTransferFailedWithPanic: "USDC_TRANSFER_FAILED_WITH_PANIC",
|
|
5039
|
+
InsufficientAllowance: "INSUFFICIENT_ALLOWANCE",
|
|
5040
|
+
// ZK Passport
|
|
5041
|
+
ZKPassportVerifierNotSet: "ZK_PASSPORT_VERIFIER_NOT_SET",
|
|
5042
|
+
ZKPassportDomainEmpty: "ZK_PASSPORT_DOMAIN_EMPTY",
|
|
5043
|
+
ZKPassportScopeEmpty: "ZK_PASSPORT_SCOPE_EMPTY",
|
|
5044
|
+
PassportAlreadyVerified: "PASSPORT_ALREADY_VERIFIED",
|
|
5045
|
+
ZKPassportProofInvalid: "ZK_PASSPORT_PROOF_INVALID",
|
|
5046
|
+
ZKPassportIdentifierAlreadyVerified: "ZK_PASSPORT_IDENTIFIER_ALREADY_VERIFIED",
|
|
5047
|
+
ZKPassportInvalidScope: "ZK_PASSPORT_INVALID_SCOPE",
|
|
5048
|
+
ZKPassportUnexpectedSender: "ZK_PASSPORT_UNEXPECTED_SENDER",
|
|
5049
|
+
ZKPassportAgeBelowMinimum: "ZK_PASSPORT_AGE_BELOW_MINIMUM",
|
|
5050
|
+
ZKPassportMinAgeTooHigh: "ZK_PASSPORT_MIN_AGE_TOO_HIGH",
|
|
5051
|
+
// Chainlink / oracle
|
|
5052
|
+
UnexpectedRequestId: "UNEXPECTED_REQUEST_ID",
|
|
5053
|
+
OnlyRouterCanFulfill: "ONLY_ROUTER_CAN_FULFILL",
|
|
5054
|
+
RequestFailed: "REQUEST_FAILED",
|
|
5055
|
+
SourceCodeMismatch: "SOURCE_CODE_MISMATCH",
|
|
5056
|
+
ZeroMarketPrice: "ZERO_MARKET_PRICE",
|
|
5057
|
+
InvalidComputedPrices: "INVALID_COMPUTED_PRICES",
|
|
5058
|
+
NotPriceUpdaterForCurrency: "NOT_PRICE_UPDATER_FOR_CURRENCY",
|
|
5059
|
+
ThresholdNotConfigured: "THRESHOLD_NOT_CONFIGURED",
|
|
5060
|
+
SlippageExceeded: "SLIPPAGE_EXCEEDED",
|
|
5061
|
+
// Reputation / verification
|
|
5062
|
+
UserHasNoReputation: "USER_HAS_NO_REPUTATION",
|
|
5063
|
+
ZeroReputationPoints: "ZERO_REPUTATION_POINTS",
|
|
5064
|
+
NoReputation: "NO_REPUTATION",
|
|
5065
|
+
InsufficientRP: "INSUFFICIENT_RP",
|
|
5066
|
+
NullifierAlreadyVerified: "NULLIFIER_ALREADY_VERIFIED",
|
|
5067
|
+
VerificationFailed: "VERIFICATION_FAILED",
|
|
5068
|
+
InvalidSocialPlatform: "INVALID_SOCIAL_PLATFORM",
|
|
5069
|
+
SocialAlreadyVerified: "SOCIAL_ALREADY_VERIFIED",
|
|
5070
|
+
YearFieldNotInProof: "YEAR_FIELD_NOT_IN_PROOF",
|
|
5071
|
+
UserIdFieldNotInProof: "USER_ID_FIELD_NOT_IN_PROOF",
|
|
5072
|
+
UserIdAlreadyVerified: "USER_ID_ALREADY_VERIFIED",
|
|
5073
|
+
UsernameAlreadyVerified: "USERNAME_ALREADY_VERIFIED",
|
|
5074
|
+
UsernameNotInProof: "USERNAME_NOT_IN_PROOF",
|
|
5075
|
+
LinkedInOnlyRpUpdates: "LINKEDIN_ONLY_RP_UPDATES",
|
|
5076
|
+
FacebookOnlyRpUpdates: "FACEBOOK_ONLY_RP_UPDATES",
|
|
5077
|
+
// Voting / referral
|
|
5078
|
+
AlreadyReferred: "ALREADY_REFERRED",
|
|
5079
|
+
SelfReferralNotAllowed: "SELF_REFERRAL_NOT_ALLOWED",
|
|
5080
|
+
NotEligibleToRefer: "NOT_ELIGIBLE_TO_REFER",
|
|
5081
|
+
MerchantMonthlyReferralLimitReached: "MERCHANT_MONTHLY_REFERRAL_LIMIT_REACHED",
|
|
5082
|
+
NoRecommender: "NO_RECOMMENDER",
|
|
5083
|
+
RecommendationAlreadyClaimed: "RECOMMENDATION_ALREADY_CLAIMED",
|
|
5084
|
+
CannotVoteYourself: "CANNOT_VOTE_YOURSELF",
|
|
5085
|
+
VotesPerEpochExceeded: "VOTES_PER_EPOCH_EXCEEDED",
|
|
5086
|
+
AlreadyVoted: "ALREADY_VOTED",
|
|
5087
|
+
FunctionNotFound: "FUNCTION_NOT_FOUND",
|
|
5088
|
+
// Campaign
|
|
5089
|
+
CampaignNotActive: "CAMPAIGN_NOT_ACTIVE",
|
|
5090
|
+
InvalidManagerDetails: "INVALID_MANAGER_DETAILS",
|
|
5091
|
+
UnclaimedRewardsExist: "UNCLAIMED_REWARDS_EXIST",
|
|
5092
|
+
RewardAlreadyClaimed: "REWARD_ALREADY_CLAIMED",
|
|
5093
|
+
OnlyNewUsersAllowed: "ONLY_NEW_USERS_ALLOWED",
|
|
5094
|
+
ManagerNotFound: "MANAGER_NOT_FOUND",
|
|
5095
|
+
ManagerInactive: "MANAGER_INACTIVE",
|
|
5096
|
+
NoRewards: "NO_REWARDS",
|
|
5097
|
+
InvalidCampaignId: "INVALID_CAMPAIGN_ID",
|
|
5098
|
+
CannotClaimRevenueForCurrentMonth: "CANNOT_CLAIM_REVENUE_FOR_CURRENT_MONTH",
|
|
5099
|
+
// Referral reward config
|
|
5100
|
+
RewardPercentageTooHigh: "REWARD_PERCENTAGE_TOO_HIGH",
|
|
5101
|
+
// Signature / nonce
|
|
5102
|
+
NonceAlreadyUsed: "NONCE_ALREADY_USED",
|
|
5103
|
+
SignatureValidationFailed: "SIGNATURE_VALIDATION_FAILED",
|
|
5104
|
+
// Misc
|
|
5105
|
+
InvalidAddress: "INVALID_ADDRESS",
|
|
5106
|
+
InvalidBlockAmount: "INVALID_BLOCK_AMOUNT",
|
|
5107
|
+
InvalidAmount: "INVALID_AMOUNT",
|
|
5108
|
+
InvalidInput: "INVALID_INPUT",
|
|
5109
|
+
InvalidStatusTransition: "INVALID_STATUS_TRANSITION",
|
|
5110
|
+
ArrayLengthMismatch: "ARRAY_LENGTH_MISMATCH",
|
|
5111
|
+
UserIsBlacklisted: "USER_IS_BLACKLISTED",
|
|
5112
|
+
ZeroAddress: "ZERO_ADDRESS",
|
|
5113
|
+
ReentrancyGuard: "REENTRANCY_GUARD",
|
|
5114
|
+
BatchTooLarge: "BATCH_TOO_LARGE",
|
|
5115
|
+
UnderflowSubtraction: "UNDERFLOW_SUBTRACTION",
|
|
5116
|
+
TargetLongerThanData: "TARGET_LONGER_THAN_DATA"
|
|
5117
|
+
};
|
|
5118
|
+
var hexContractErrors = {
|
|
5119
|
+
// Access control
|
|
5120
|
+
"0x7bfa4b9f": contractErrors.NotAdmin,
|
|
5121
|
+
"0x16c726b1": contractErrors.NotSuperAdmin,
|
|
5122
|
+
"0xea8e4eb5": contractErrors.NotAuthorized,
|
|
5123
|
+
"0x29c3b7ee": contractErrors.NotSelf,
|
|
5124
|
+
"0x584a7938": contractErrors.NotWhitelisted,
|
|
5125
|
+
"0xa8143fbc": contractErrors.NotCircleAdmin,
|
|
5126
|
+
// Circle / community management
|
|
5127
|
+
"0x430f13b3": contractErrors.InvalidName,
|
|
5128
|
+
"0xe7cbf75a": contractErrors.InvalidCommunityUrl,
|
|
5129
|
+
"0x3762bfee": contractErrors.InvalidAdminCommunityUrl,
|
|
5130
|
+
"0x201c1ffc": contractErrors.AdminAlreadyHasCircle,
|
|
5131
|
+
"0x6540a51d": contractErrors.CircleNameAlreadyTaken,
|
|
5132
|
+
"0xcadc6786": contractErrors.P2PStakeConfigNotSet,
|
|
5133
|
+
"0x78317f44": contractErrors.InsufficientP2PStake,
|
|
5134
|
+
"0x18eda032": contractErrors.P2PTokenNotSet,
|
|
5135
|
+
"0xdab11ea6": contractErrors.P2PUnstakeRequestPending,
|
|
5136
|
+
"0xeb1ce40b": contractErrors.NoP2PUnstakeRequest,
|
|
5137
|
+
"0xbf2d0ba1": contractErrors.P2PUnstakeCooldownNotPassed,
|
|
5138
|
+
"0x06b663af": contractErrors.SlashAmountExceedsStake,
|
|
5139
|
+
"0xff9b022c": contractErrors.CircleNotActive,
|
|
5140
|
+
"0x3d90c0a6": contractErrors.InvalidCircleId,
|
|
5141
|
+
"0xfb42a67d": contractErrors.CurrencyMismatch,
|
|
5142
|
+
"0xf2775265": contractErrors.CircleFull,
|
|
5143
|
+
"0x784b6c3c": contractErrors.CircleIdMismatch,
|
|
5144
|
+
"0xee240e49": contractErrors.DuplicateAccountName,
|
|
5145
|
+
"0x2ef13105": contractErrors.EmptyName,
|
|
5146
|
+
"0x1b5433c8": contractErrors.AccountBoundToAnotherCircle,
|
|
5147
|
+
"0x549e2555": contractErrors.ExitAmountExceededCircleBalance,
|
|
5148
|
+
"0x865b21e1": contractErrors.UndelegationAmountTooHigh,
|
|
5149
|
+
// Exchange / order lifecycle
|
|
5150
|
+
"0x4bbac5de": contractErrors.ExchangeNotOperational,
|
|
5151
|
+
"0x58db8ed6": contractErrors.OrderNotPlaced,
|
|
5152
|
+
"0x1e3b9629": contractErrors.OrderNotPaid,
|
|
5153
|
+
"0x181b1b2e": contractErrors.OrderStatusInvalid,
|
|
5154
|
+
"0xc56873ba": contractErrors.OrderExpired,
|
|
5155
|
+
"0x7f61b868": contractErrors.OrderAlreadyPaid,
|
|
5156
|
+
"0x03683687": contractErrors.OrderAlreadyCompleted,
|
|
5157
|
+
"0x688c176f": contractErrors.InvalidOrderType,
|
|
5158
|
+
"0x2e757a60": contractErrors.OrderTypeIncorrect,
|
|
5159
|
+
"0x6b1b90b4": contractErrors.OrderNotAccepted,
|
|
5160
|
+
"0x1775c43e": contractErrors.OrderNotAssigned,
|
|
5161
|
+
"0xf42e41a1": contractErrors.OrderAmountExceedsLimit,
|
|
5162
|
+
"0x93845d68": contractErrors.InvalidOrderAmount,
|
|
5163
|
+
"0x138b9d5a": contractErrors.InvalidOrderAmountToCoverFee,
|
|
5164
|
+
"0x5d706033": contractErrors.InvalidOrderId,
|
|
5165
|
+
"0xbb776720": contractErrors.OrderTooEarlyForReassignment,
|
|
5166
|
+
"0x20d5910f": contractErrors.OrderTooLateForReassignment,
|
|
5167
|
+
"0xccd87bf0": contractErrors.ReAssignmentNotRequired,
|
|
5168
|
+
"0xb20277f8": contractErrors.TipAlreadyGiven,
|
|
5169
|
+
"0xdf9f707c": contractErrors.CashbackTransferFailed,
|
|
5170
|
+
// Order limits
|
|
5171
|
+
"0xe595a7bf": contractErrors.DailyBuyOrderLimitExceeded,
|
|
5172
|
+
"0x675dbc86": contractErrors.MonthlyBuyOrderLimitExceeded,
|
|
5173
|
+
"0x64301cb8": contractErrors.SellOrderAmountLimitExceeded,
|
|
5174
|
+
"0x91da284f": contractErrors.BuyOrderAmountExceedsLimit,
|
|
5175
|
+
"0xb407b9ec": contractErrors.SellOrderAmountExceedsLimit,
|
|
5176
|
+
"0x4b29cf0a": contractErrors.BuyAmountExceedsUsdcLimit,
|
|
5177
|
+
"0xbba2edf9": contractErrors.SellAmountExceedsFiatLimit,
|
|
5178
|
+
"0x7e2ee654": contractErrors.DailyVolumeLimitExceeded,
|
|
5179
|
+
"0x49de1789": contractErrors.MonthlyVolumeLimitExceeded,
|
|
5180
|
+
"0xb14a1ff3": contractErrors.UserYearlyVolumeLimitExceeded,
|
|
5181
|
+
// Dispute
|
|
5182
|
+
"0x07a2454f": contractErrors.DisputeTimeNotReached,
|
|
5183
|
+
"0xb28c3e29": contractErrors.DisputeTimeExpired,
|
|
5184
|
+
"0x2a829f07": contractErrors.InvalidOrderStatusToRaiseDispute,
|
|
5185
|
+
"0x88d039ce": contractErrors.DisputeNotRaised,
|
|
5186
|
+
"0x3764a75c": contractErrors.CannotRaiseDisputeTwice,
|
|
5187
|
+
"0x866e9f89": contractErrors.DisputeAlreadySettled,
|
|
5188
|
+
"0x6131d13d": contractErrors.TransactionIdMismatch,
|
|
5189
|
+
"0x8ec051b8": contractErrors.AccountNumberMismatch,
|
|
5190
|
+
"0xf8bfad32": contractErrors.NotPaidBuyOrder,
|
|
5191
|
+
// Payment channels
|
|
5192
|
+
"0x552ff5ec": contractErrors.PaymentChannelNotFound,
|
|
5193
|
+
"0xfccd93cf": contractErrors.PaymentChannelNotActive,
|
|
5194
|
+
"0x6764f4d6": contractErrors.PaymentChannelNotApproved,
|
|
5195
|
+
"0xab284291": contractErrors.PaymentChannelNotRejected,
|
|
5196
|
+
"0x99c8ef4d": contractErrors.InvalidPaymentChannelId,
|
|
5197
|
+
"0x0569ab3e": contractErrors.DuplicatePaymentChannel,
|
|
5198
|
+
"0xff4f83ca": contractErrors.OldPaymentChannelNotFound,
|
|
5199
|
+
"0xb1198199": contractErrors.NewPaymentChannelNotFound,
|
|
5200
|
+
"0xc905b99a": contractErrors.SamePaymentChannel,
|
|
5201
|
+
"0xcedb41f1": contractErrors.OldPaymentChannelShouldBeInactive,
|
|
5202
|
+
"0x487add97": contractErrors.NewPaymentChannelShouldBeActive,
|
|
5203
|
+
"0x6d4c3f9e": contractErrors.OngoingOrderOnPaymentChannel,
|
|
5204
|
+
"0xc1654697": contractErrors.UpiAlreadySent,
|
|
5205
|
+
"0xaa60ec26": contractErrors.InvalidOrderUpi,
|
|
5206
|
+
"0x81c2b982": contractErrors.NoFiatLiquidity,
|
|
5207
|
+
// Merchant
|
|
5208
|
+
"0x5d04ff4c": contractErrors.NotEnoughEligibleMerchants,
|
|
5209
|
+
"0xa6af7ebe": contractErrors.MerchantNotRegistered,
|
|
5210
|
+
"0x7290a612": contractErrors.MerchantNotApproved,
|
|
5211
|
+
"0xf4a1e014": contractErrors.MerchantAlreadyRegistered,
|
|
5212
|
+
"0x8713aaba": contractErrors.MerchantAlreadyRejected,
|
|
5213
|
+
"0x9ae55bc7": contractErrors.MerchantBlacklisted,
|
|
5214
|
+
"0x0ee0b659": contractErrors.MerchantNotBlacklisted,
|
|
5215
|
+
"0x5f765689": contractErrors.MerchantAlreadyBlacklisted,
|
|
5216
|
+
"0x9c54e5a8": contractErrors.MerchantHasOngoingOrders,
|
|
5217
|
+
"0x70d753bd": contractErrors.MerchantNotFullfilledEligibilityThreshold,
|
|
5218
|
+
"0xc0b6c919": contractErrors.InvalidMerchant,
|
|
5219
|
+
// Staking / unstaking
|
|
5220
|
+
"0x3fd2347e": contractErrors.StakeAmountTooLow,
|
|
5221
|
+
"0x703cde0a": contractErrors.AdditionalStakeNotAllowed,
|
|
5222
|
+
"0xa9de99ae": contractErrors.UnstakeRequestPending,
|
|
5223
|
+
"0x0b7c70f3": contractErrors.UnstakeRequestNotPending,
|
|
5224
|
+
"0xe665491f": contractErrors.UnstakeAmountExceeded,
|
|
5225
|
+
"0x2d3087f9": contractErrors.ZeroUnstakeAmount,
|
|
5226
|
+
"0x1b1d7861": contractErrors.NoWithdrawableAmount,
|
|
5227
|
+
"0xcacf989a": contractErrors.NoStake,
|
|
5228
|
+
"0x21311aa3": contractErrors.NoStakers,
|
|
5229
|
+
"0xd06ff88e": contractErrors.InsufficientStakedAmount,
|
|
5230
|
+
"0x9ab7872d": contractErrors.CooldownNotPassed,
|
|
5231
|
+
"0x73380d99": contractErrors.ClaimableRewardsNotAvailable,
|
|
5232
|
+
// Delegation
|
|
5233
|
+
"0xec4b3ce6": contractErrors.ExitWouldBreachDelegationInvariant,
|
|
5234
|
+
"0x8f90a426": contractErrors.AggregateDelegationExceedsTotalStaked,
|
|
5235
|
+
"0x2cc11576": contractErrors.InsufficientMerchantRewards,
|
|
5236
|
+
// Migration
|
|
5237
|
+
"0x92aa7d0f": contractErrors.InvalidMigrationStatus,
|
|
5238
|
+
"0x7ff47425": contractErrors.MigrationRequestNotPending,
|
|
5239
|
+
"0x88ddec46": contractErrors.MigrationAlreadyRequested,
|
|
5240
|
+
// Token / currency
|
|
5241
|
+
"0xc991cbb1": contractErrors.TokenAlreadyExists,
|
|
5242
|
+
"0xcbdb7b30": contractErrors.TokenNotFound,
|
|
5243
|
+
"0x9f11a53f": contractErrors.TokenEmpty,
|
|
5244
|
+
"0x02a6fdd2": contractErrors.CurrencyNotSupported,
|
|
5245
|
+
"0xf5993428": contractErrors.InvalidCurrency,
|
|
5246
|
+
// USDC / transfer
|
|
5247
|
+
"0x149f9fca": contractErrors.UsdtTransferFailed,
|
|
5248
|
+
"0x47bfece5": contractErrors.UsdtTransferFailedWithErrorMessage,
|
|
5249
|
+
"0x279bbc0c": contractErrors.UsdtTransferFailedWithPanic,
|
|
5250
|
+
"0xfb8f41b2": contractErrors.InsufficientAllowance,
|
|
5251
|
+
// ZK Passport
|
|
5252
|
+
"0xfd8d4a6d": contractErrors.ZKPassportVerifierNotSet,
|
|
5253
|
+
"0xb87078f9": contractErrors.ZKPassportDomainEmpty,
|
|
5254
|
+
"0x5eadc4c2": contractErrors.ZKPassportScopeEmpty,
|
|
5255
|
+
"0x7642fe15": contractErrors.PassportAlreadyVerified,
|
|
5256
|
+
"0x1fa24b35": contractErrors.ZKPassportProofInvalid,
|
|
5257
|
+
"0x36bdb7b6": contractErrors.ZKPassportIdentifierAlreadyVerified,
|
|
5258
|
+
"0xd13a7934": contractErrors.ZKPassportInvalidScope,
|
|
5259
|
+
"0x69f5bfe7": contractErrors.ZKPassportUnexpectedSender,
|
|
5260
|
+
"0x0464115c": contractErrors.ZKPassportAgeBelowMinimum,
|
|
5261
|
+
"0x48183836": contractErrors.ZKPassportMinAgeTooHigh,
|
|
5262
|
+
// Chainlink / oracle
|
|
5263
|
+
"0x7f73f237": contractErrors.UnexpectedRequestId,
|
|
5264
|
+
"0xab948796": contractErrors.OnlyRouterCanFulfill,
|
|
5265
|
+
"0x61982c98": contractErrors.RequestFailed,
|
|
5266
|
+
"0xab66be18": contractErrors.SourceCodeMismatch,
|
|
5267
|
+
"0xff2826ef": contractErrors.ZeroMarketPrice,
|
|
5268
|
+
"0xbb6c216c": contractErrors.InvalidComputedPrices,
|
|
5269
|
+
"0x3a8fbef4": contractErrors.NotPriceUpdaterForCurrency,
|
|
5270
|
+
"0x3e2c36f2": contractErrors.ThresholdNotConfigured,
|
|
5271
|
+
"0x71c4efed": contractErrors.SlippageExceeded,
|
|
5272
|
+
// Reputation / verification
|
|
5273
|
+
"0x071ea33c": contractErrors.UserHasNoReputation,
|
|
5274
|
+
"0xd2e1e6e0": contractErrors.ZeroReputationPoints,
|
|
5275
|
+
"0x3c0ca622": contractErrors.NoReputation,
|
|
5276
|
+
"0x412dd2b1": contractErrors.InsufficientRP,
|
|
5277
|
+
"0x0f165e7b": contractErrors.NullifierAlreadyVerified,
|
|
5278
|
+
"0x439cc0cd": contractErrors.VerificationFailed,
|
|
5279
|
+
"0x2366073b": contractErrors.InvalidSocialPlatform,
|
|
5280
|
+
"0x2f850b6b": contractErrors.SocialAlreadyVerified,
|
|
5281
|
+
"0x466f52a8": contractErrors.YearFieldNotInProof,
|
|
5282
|
+
"0x4d460588": contractErrors.UserIdFieldNotInProof,
|
|
5283
|
+
"0xa18ea4e8": contractErrors.UserIdAlreadyVerified,
|
|
5284
|
+
"0x69470b13": contractErrors.UsernameAlreadyVerified,
|
|
5285
|
+
"0x8390b2dd": contractErrors.UsernameNotInProof,
|
|
5286
|
+
"0xef053cf4": contractErrors.LinkedInOnlyRpUpdates,
|
|
5287
|
+
"0x355b0709": contractErrors.FacebookOnlyRpUpdates,
|
|
5288
|
+
// Voting / referral
|
|
5289
|
+
"0x7aabdfe3": contractErrors.AlreadyReferred,
|
|
5290
|
+
"0x83463f4a": contractErrors.SelfReferralNotAllowed,
|
|
5291
|
+
"0x69f6994a": contractErrors.NotEligibleToRefer,
|
|
5292
|
+
"0x1b19ad97": contractErrors.MerchantMonthlyReferralLimitReached,
|
|
5293
|
+
"0x944a2241": contractErrors.NoRecommender,
|
|
5294
|
+
"0x0ece93a6": contractErrors.RecommendationAlreadyClaimed,
|
|
5295
|
+
"0x74785d0f": contractErrors.CannotVoteYourself,
|
|
5296
|
+
"0xc26d5f75": contractErrors.VotesPerEpochExceeded,
|
|
5297
|
+
"0x7c9a1cf9": contractErrors.AlreadyVoted,
|
|
5298
|
+
"0x403e7fa6": contractErrors.FunctionNotFound,
|
|
5299
|
+
// Campaign
|
|
5300
|
+
"0x7a551e38": contractErrors.CampaignNotActive,
|
|
5301
|
+
"0x668ca75d": contractErrors.InvalidManagerDetails,
|
|
5302
|
+
"0x2f950361": contractErrors.UnclaimedRewardsExist,
|
|
5303
|
+
"0x626b7c00": contractErrors.RewardAlreadyClaimed,
|
|
5304
|
+
"0x902ade67": contractErrors.OnlyNewUsersAllowed,
|
|
5305
|
+
"0x22a5e34b": contractErrors.ManagerNotFound,
|
|
5306
|
+
"0xa1610e37": contractErrors.ManagerInactive,
|
|
5307
|
+
"0x3fb087f4": contractErrors.NoRewards,
|
|
5308
|
+
"0x3eedee0f": contractErrors.InvalidCampaignId,
|
|
5309
|
+
"0x302c5138": contractErrors.CannotClaimRevenueForCurrentMonth,
|
|
5310
|
+
// Referral reward config
|
|
5311
|
+
"0x074a6991": contractErrors.RewardPercentageTooHigh,
|
|
5312
|
+
// Signature / nonce
|
|
5313
|
+
"0x1fb09b80": contractErrors.NonceAlreadyUsed,
|
|
5314
|
+
"0x2fdec18b": contractErrors.SignatureValidationFailed,
|
|
5315
|
+
// Misc
|
|
5316
|
+
"0xe6c4247b": contractErrors.InvalidAddress,
|
|
5317
|
+
"0x3eb17c88": contractErrors.InvalidBlockAmount,
|
|
5318
|
+
"0x2c5211c6": contractErrors.InvalidAmount,
|
|
5319
|
+
"0xb4fa3fb3": contractErrors.InvalidInput,
|
|
5320
|
+
"0x1117a646": contractErrors.InvalidStatusTransition,
|
|
5321
|
+
"0xa24a13a6": contractErrors.ArrayLengthMismatch,
|
|
5322
|
+
"0xebb6f34b": contractErrors.UserIsBlacklisted,
|
|
5323
|
+
"0xd92e233d": contractErrors.ZeroAddress,
|
|
5324
|
+
"0x8beb9d16": contractErrors.ReentrancyGuard,
|
|
5325
|
+
"0xbb1cb70b": contractErrors.BatchTooLarge,
|
|
5326
|
+
"0xd97cf1ba": contractErrors.UnderflowSubtraction,
|
|
5327
|
+
"0xc9b16952": contractErrors.TargetLongerThanData
|
|
5328
|
+
};
|
|
5329
|
+
|
|
5330
|
+
// src/contracts/order-flow/index.ts
|
|
5331
|
+
var import_neverthrow9 = require("neverthrow");
|
|
5332
|
+
|
|
5333
|
+
// src/orders/internal/routing/errors.ts
|
|
5334
|
+
var OrderRoutingError = class extends SdkError {
|
|
5335
|
+
constructor(message, options) {
|
|
5336
|
+
super(message, options);
|
|
5337
|
+
this.name = "OrderRoutingError";
|
|
5338
|
+
}
|
|
5339
|
+
};
|
|
5340
|
+
|
|
5341
|
+
// src/orders/internal/routing/validation.ts
|
|
5342
|
+
var import_zod6 = require("zod");
|
|
5343
|
+
var ZodCircleScoreStateSchema = import_zod6.z.object({
|
|
5344
|
+
activeMerchantsCount: import_zod6.z.coerce.number()
|
|
5345
|
+
});
|
|
5346
|
+
var ZodCircleMetricsForRoutingSchema = import_zod6.z.object({
|
|
5347
|
+
circleScore: import_zod6.z.coerce.number(),
|
|
5348
|
+
circleStatus: import_zod6.z.string(),
|
|
5349
|
+
scoreState: ZodCircleScoreStateSchema
|
|
5350
|
+
});
|
|
5351
|
+
var ZodCircleForRoutingSchema = import_zod6.z.object({
|
|
5352
|
+
circleId: import_zod6.z.string(),
|
|
5353
|
+
currency: import_zod6.z.string(),
|
|
5354
|
+
metrics: ZodCircleMetricsForRoutingSchema
|
|
5355
|
+
});
|
|
5356
|
+
var ZodCirclesForRoutingResponseSchema = import_zod6.z.object({
|
|
5357
|
+
circles: import_zod6.z.array(ZodCircleForRoutingSchema)
|
|
5358
|
+
});
|
|
5359
|
+
var ZodCheckCircleEligibilityParamsSchema = import_zod6.z.object({
|
|
5360
|
+
circleId: import_zod6.z.bigint(),
|
|
5361
|
+
currency: import_zod6.z.string(),
|
|
5362
|
+
user: ZodAddressSchema,
|
|
5363
|
+
usdtAmount: import_zod6.z.bigint(),
|
|
5364
|
+
fiatAmount: import_zod6.z.bigint(),
|
|
5365
|
+
orderType: import_zod6.z.bigint(),
|
|
5366
|
+
preferredPCConfigId: import_zod6.z.bigint()
|
|
5367
|
+
});
|
|
5368
|
+
var ZodSelectCircleParamsSchema = import_zod6.z.object({
|
|
5369
|
+
currency: import_zod6.z.string().min(1),
|
|
5370
|
+
user: ZodAddressSchema,
|
|
5371
|
+
usdtAmount: import_zod6.z.bigint(),
|
|
5372
|
+
fiatAmount: import_zod6.z.bigint(),
|
|
5373
|
+
orderType: import_zod6.z.bigint(),
|
|
5374
|
+
preferredPCConfigId: import_zod6.z.bigint()
|
|
5375
|
+
});
|
|
5376
|
+
|
|
5377
|
+
// src/contracts/order-flow/index.ts
|
|
5378
|
+
function checkCircleEligibility(publicClient, contractAddress, params, logger = noopLogger) {
|
|
5379
|
+
return validate(
|
|
5380
|
+
ZodCheckCircleEligibilityParamsSchema,
|
|
5381
|
+
params,
|
|
5382
|
+
(message, cause, d) => new OrderRoutingError(message, { code: "VALIDATION_ERROR", cause, context: { data: d } })
|
|
5383
|
+
).asyncAndThen((validated) => {
|
|
5384
|
+
logger.debug("checking on-chain eligibility", {
|
|
5385
|
+
circleId: String(validated.circleId),
|
|
5386
|
+
contractAddress
|
|
5387
|
+
});
|
|
5388
|
+
return import_neverthrow9.ResultAsync.fromPromise(
|
|
5389
|
+
publicClient.readContract({
|
|
5390
|
+
address: contractAddress,
|
|
5391
|
+
abi: ABIS.FACETS.ORDER_FLOW,
|
|
5392
|
+
functionName: "getAssignableMerchantsFromCircle",
|
|
5393
|
+
args: [
|
|
5394
|
+
validated.circleId,
|
|
5395
|
+
1n,
|
|
5396
|
+
validated.currency,
|
|
5397
|
+
validated.user,
|
|
5398
|
+
validated.usdtAmount,
|
|
5399
|
+
validated.fiatAmount,
|
|
5400
|
+
validated.orderType,
|
|
5401
|
+
validated.preferredPCConfigId
|
|
5402
|
+
]
|
|
5403
|
+
}),
|
|
5404
|
+
(error) => new OrderRoutingError("Eligibility check failed", {
|
|
5405
|
+
code: "CONTRACT_READ_ERROR",
|
|
5406
|
+
cause: error,
|
|
5407
|
+
context: { circleId: String(params.circleId) }
|
|
5408
|
+
})
|
|
5409
|
+
);
|
|
5410
|
+
}).map((merchants) => {
|
|
5411
|
+
const arr = merchants;
|
|
5412
|
+
const eligible = arr.length >= 1;
|
|
5413
|
+
logger.debug("eligibility check result", {
|
|
5414
|
+
circleId: String(params.circleId),
|
|
5415
|
+
assignableMerchants: arr.length,
|
|
5416
|
+
eligible
|
|
5417
|
+
});
|
|
5418
|
+
return eligible;
|
|
5419
|
+
});
|
|
5420
|
+
}
|
|
5421
|
+
|
|
5422
|
+
// src/contracts/p2p-config/index.ts
|
|
5423
|
+
var import_neverthrow10 = require("neverthrow");
|
|
5424
|
+
var import_viem12 = require("viem");
|
|
5425
|
+
|
|
5426
|
+
// src/prices/errors.ts
|
|
5427
|
+
var PricesError = class extends SdkError {
|
|
5428
|
+
constructor(message, options) {
|
|
5429
|
+
super(message, options);
|
|
5430
|
+
this.name = "PricesError";
|
|
5431
|
+
}
|
|
5432
|
+
};
|
|
5433
|
+
|
|
5434
|
+
// src/prices/validation.ts
|
|
5435
|
+
var import_zod7 = require("zod");
|
|
5436
|
+
var ZodCurrencyScopedParamsSchema = import_zod7.z.object({
|
|
5437
|
+
currency: ZodCurrencySchema
|
|
5438
|
+
});
|
|
5439
|
+
|
|
5440
|
+
// src/contracts/p2p-config/index.ts
|
|
5441
|
+
function getPriceConfig(publicClient, diamondAddress, params) {
|
|
5442
|
+
return validate(
|
|
5443
|
+
ZodCurrencyScopedParamsSchema,
|
|
5444
|
+
params,
|
|
5445
|
+
(message, cause, data) => new PricesError(message, {
|
|
5446
|
+
code: "VALIDATION_ERROR",
|
|
5447
|
+
cause,
|
|
5448
|
+
context: { params: data }
|
|
5449
|
+
})
|
|
5450
|
+
).asyncAndThen(
|
|
5451
|
+
(validated) => import_neverthrow10.ResultAsync.fromPromise(
|
|
5452
|
+
publicClient.readContract({
|
|
5453
|
+
address: diamondAddress,
|
|
5454
|
+
abi: ABIS.FACETS.CONFIG,
|
|
5455
|
+
functionName: "getPriceConfig",
|
|
5456
|
+
args: [(0, import_viem12.stringToHex)(validated.currency, { size: 32 })]
|
|
5457
|
+
}),
|
|
5458
|
+
(error) => new PricesError("Failed to read price config", {
|
|
5459
|
+
code: "CONTRACT_READ_ERROR",
|
|
5460
|
+
cause: error,
|
|
5461
|
+
context: { currency: validated.currency, diamondAddress }
|
|
5462
|
+
})
|
|
5463
|
+
)
|
|
5464
|
+
);
|
|
5465
|
+
}
|
|
5466
|
+
function getReputationPerUsdcLimit(publicClient, diamondAddress, params) {
|
|
5467
|
+
return validate(
|
|
5468
|
+
ZodCurrencyScopedParamsSchema,
|
|
5469
|
+
params,
|
|
5470
|
+
(message, cause, data) => new PricesError(message, {
|
|
5471
|
+
code: "VALIDATION_ERROR",
|
|
5472
|
+
cause,
|
|
5473
|
+
context: { params: data }
|
|
5474
|
+
})
|
|
5475
|
+
).asyncAndThen(
|
|
5476
|
+
(validated) => import_neverthrow10.ResultAsync.fromPromise(
|
|
5477
|
+
publicClient.readContract({
|
|
5478
|
+
address: diamondAddress,
|
|
5479
|
+
abi: ABIS.DIAMOND,
|
|
5480
|
+
functionName: "getRpPerUsdtLimitRational",
|
|
5481
|
+
args: [(0, import_viem12.stringToHex)(validated.currency, { size: 32 })]
|
|
5482
|
+
}),
|
|
5483
|
+
(error) => new PricesError("Failed to read reputation-per-USDC limit", {
|
|
5484
|
+
code: "CONTRACT_READ_ERROR",
|
|
5485
|
+
cause: error,
|
|
5486
|
+
context: { currency: validated.currency, diamondAddress }
|
|
5487
|
+
})
|
|
5488
|
+
).map(([numerator, denominator]) => ({
|
|
5489
|
+
numerator,
|
|
5490
|
+
denominator,
|
|
5491
|
+
multiplier: numerator > 0n ? Number(denominator) / Number(numerator) : 0
|
|
5492
|
+
}))
|
|
5493
|
+
);
|
|
5494
|
+
}
|
|
5495
|
+
|
|
5496
|
+
// src/contracts/reputation-manager/writes.ts
|
|
5497
|
+
var import_neverthrow11 = require("neverthrow");
|
|
5498
|
+
var import_viem13 = require("viem");
|
|
5499
|
+
|
|
5500
|
+
// src/zkkyc/errors.ts
|
|
5501
|
+
var ZkkycError = class extends SdkError {
|
|
5502
|
+
constructor(message, options) {
|
|
5503
|
+
super(message, options);
|
|
5504
|
+
this.name = "ZkkycError";
|
|
5505
|
+
}
|
|
5506
|
+
};
|
|
5507
|
+
|
|
5508
|
+
// src/zkkyc/validation.ts
|
|
5509
|
+
var import_zod8 = require("zod");
|
|
5510
|
+
var ZodAnonAadharProofParamsSchema = import_zod8.z.object({
|
|
5511
|
+
nullifierSeed: import_zod8.z.bigint(),
|
|
5512
|
+
nullifier: import_zod8.z.bigint(),
|
|
5513
|
+
timestamp: import_zod8.z.bigint(),
|
|
5514
|
+
signal: import_zod8.z.bigint(),
|
|
5515
|
+
revealArray: import_zod8.z.tuple([import_zod8.z.bigint(), import_zod8.z.bigint(), import_zod8.z.bigint(), import_zod8.z.bigint()]),
|
|
5516
|
+
packedGroth16Proof: import_zod8.z.tuple([
|
|
5517
|
+
import_zod8.z.bigint(),
|
|
5518
|
+
import_zod8.z.bigint(),
|
|
5519
|
+
import_zod8.z.bigint(),
|
|
5520
|
+
import_zod8.z.bigint(),
|
|
5521
|
+
import_zod8.z.bigint(),
|
|
5522
|
+
import_zod8.z.bigint(),
|
|
5523
|
+
import_zod8.z.bigint(),
|
|
5524
|
+
import_zod8.z.bigint()
|
|
5525
|
+
])
|
|
5526
|
+
});
|
|
5527
|
+
var ZodSocialVerifyParamsSchema = import_zod8.z.object({
|
|
5528
|
+
_socialName: import_zod8.z.string(),
|
|
5529
|
+
proofs: import_zod8.z.array(
|
|
5530
|
+
import_zod8.z.object({
|
|
5531
|
+
claimInfo: import_zod8.z.object({
|
|
5532
|
+
provider: import_zod8.z.string(),
|
|
5533
|
+
parameters: import_zod8.z.string(),
|
|
5534
|
+
context: import_zod8.z.string()
|
|
5535
|
+
}),
|
|
5536
|
+
signedClaim: import_zod8.z.object({
|
|
5537
|
+
claim: import_zod8.z.object({
|
|
5538
|
+
identifier: import_zod8.z.string(),
|
|
5539
|
+
owner: ZodAddressSchema,
|
|
5540
|
+
timestampS: import_zod8.z.number(),
|
|
5541
|
+
epoch: import_zod8.z.number()
|
|
5542
|
+
}),
|
|
5543
|
+
signatures: import_zod8.z.array(import_zod8.z.string())
|
|
5544
|
+
})
|
|
5545
|
+
})
|
|
5546
|
+
)
|
|
5547
|
+
});
|
|
5548
|
+
var ZodSolidityVerifierParametersSchema = import_zod8.z.object({
|
|
5549
|
+
version: import_zod8.z.string().refine((val) => val.startsWith("0x"), {
|
|
5550
|
+
message: "Version must be a hex string"
|
|
5551
|
+
}),
|
|
5552
|
+
proofVerificationData: import_zod8.z.object({
|
|
5553
|
+
vkeyHash: import_zod8.z.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
|
|
5554
|
+
message: "Invalid bytes32 hex string"
|
|
5555
|
+
}),
|
|
5556
|
+
proof: import_zod8.z.string().refine((val) => val.startsWith("0x"), {
|
|
5557
|
+
message: "Proof must be a hex string"
|
|
5558
|
+
}),
|
|
5559
|
+
publicInputs: import_zod8.z.array(
|
|
5560
|
+
import_zod8.z.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
|
|
5561
|
+
message: "Each public input must be a valid bytes32 hex string"
|
|
5562
|
+
})
|
|
5563
|
+
)
|
|
5564
|
+
}),
|
|
5565
|
+
committedInputs: import_zod8.z.string().refine((val) => val.startsWith("0x"), {
|
|
5566
|
+
message: "Committed inputs must be a hex string"
|
|
5567
|
+
}),
|
|
5568
|
+
serviceConfig: import_zod8.z.object({
|
|
5569
|
+
validityPeriodInSeconds: import_zod8.z.number().int().nonnegative(),
|
|
5570
|
+
domain: import_zod8.z.string(),
|
|
5571
|
+
scope: import_zod8.z.string(),
|
|
5572
|
+
devMode: import_zod8.z.boolean()
|
|
5573
|
+
})
|
|
5574
|
+
});
|
|
5575
|
+
var ZodZkPassportRegisterParamsSchema = import_zod8.z.object({
|
|
5576
|
+
params: ZodSolidityVerifierParametersSchema,
|
|
5577
|
+
isIDCard: import_zod8.z.boolean()
|
|
5578
|
+
});
|
|
5579
|
+
|
|
5580
|
+
// src/contracts/reputation-manager/writes.ts
|
|
5581
|
+
function prepareSocialVerify(reputationManagerAddress, params) {
|
|
5582
|
+
return validate(
|
|
5583
|
+
ZodSocialVerifyParamsSchema,
|
|
5584
|
+
params,
|
|
5585
|
+
(message, cause, data) => new ZkkycError(message, { code: "VALIDATION_ERROR", cause, context: { params: data } })
|
|
5586
|
+
).andThen(
|
|
5587
|
+
(validated) => import_neverthrow11.Result.fromThrowable(
|
|
5588
|
+
() => ({
|
|
5589
|
+
to: reputationManagerAddress,
|
|
5590
|
+
data: (0, import_viem13.encodeFunctionData)({
|
|
5591
|
+
abi: ABIS.EXTERNAL.REPUTATION_MANAGER,
|
|
5592
|
+
functionName: "socialVerify",
|
|
5593
|
+
args: [
|
|
5594
|
+
validated._socialName,
|
|
5595
|
+
validated.proofs.map((proof) => ({
|
|
5596
|
+
...proof,
|
|
5597
|
+
signedClaim: {
|
|
5598
|
+
...proof.signedClaim,
|
|
5599
|
+
claim: {
|
|
5600
|
+
...proof.signedClaim.claim,
|
|
5601
|
+
identifier: proof.signedClaim.claim.identifier
|
|
5602
|
+
},
|
|
5603
|
+
signatures: proof.signedClaim.signatures
|
|
5604
|
+
}
|
|
5605
|
+
}))
|
|
5606
|
+
]
|
|
5607
|
+
})
|
|
5608
|
+
}),
|
|
5609
|
+
(error) => new ZkkycError("Failed to encode socialVerify", {
|
|
5610
|
+
code: "ENCODE_ERROR",
|
|
5611
|
+
cause: error
|
|
5612
|
+
})
|
|
5613
|
+
)()
|
|
5614
|
+
);
|
|
5615
|
+
}
|
|
5616
|
+
function prepareSubmitAnonAadharProof(reputationManagerAddress, params) {
|
|
5617
|
+
return validate(
|
|
5618
|
+
ZodAnonAadharProofParamsSchema,
|
|
5619
|
+
params,
|
|
5620
|
+
(message, cause, data) => new ZkkycError(message, { code: "VALIDATION_ERROR", cause, context: { params: data } })
|
|
5621
|
+
).andThen(
|
|
5622
|
+
(validated) => import_neverthrow11.Result.fromThrowable(
|
|
5623
|
+
() => ({
|
|
5624
|
+
to: reputationManagerAddress,
|
|
5625
|
+
data: (0, import_viem13.encodeFunctionData)({
|
|
5626
|
+
abi: ABIS.EXTERNAL.REPUTATION_MANAGER,
|
|
5627
|
+
functionName: "submitAnonAadharProof",
|
|
5628
|
+
args: [
|
|
5629
|
+
validated.nullifierSeed,
|
|
5630
|
+
validated.nullifier,
|
|
5631
|
+
validated.timestamp,
|
|
5632
|
+
validated.signal,
|
|
5633
|
+
validated.revealArray,
|
|
5634
|
+
validated.packedGroth16Proof
|
|
5635
|
+
]
|
|
5636
|
+
})
|
|
5637
|
+
}),
|
|
5638
|
+
(error) => new ZkkycError("Failed to encode submitAnonAadharProof", {
|
|
5639
|
+
code: "ENCODE_ERROR",
|
|
5640
|
+
cause: error
|
|
5641
|
+
})
|
|
5642
|
+
)()
|
|
5643
|
+
);
|
|
5644
|
+
}
|
|
5645
|
+
function prepareZkPassportRegister(reputationManagerAddress, params) {
|
|
5646
|
+
return validate(
|
|
5647
|
+
ZodZkPassportRegisterParamsSchema,
|
|
5648
|
+
params,
|
|
5649
|
+
(message, cause, data) => new ZkkycError(message, { code: "VALIDATION_ERROR", cause, context: { params: data } })
|
|
5650
|
+
).andThen(
|
|
5651
|
+
(validated) => import_neverthrow11.Result.fromThrowable(
|
|
5652
|
+
() => {
|
|
5653
|
+
const { proofVerificationData, serviceConfig, committedInputs, version } = validated.params;
|
|
5654
|
+
const proofVerificationParams = {
|
|
5655
|
+
version,
|
|
5656
|
+
proofVerificationData: {
|
|
5657
|
+
vkeyHash: proofVerificationData.vkeyHash,
|
|
5658
|
+
proof: proofVerificationData.proof,
|
|
5659
|
+
publicInputs: proofVerificationData.publicInputs
|
|
5660
|
+
},
|
|
5661
|
+
committedInputs,
|
|
5662
|
+
serviceConfig: {
|
|
5663
|
+
validityPeriodInSeconds: BigInt(serviceConfig.validityPeriodInSeconds),
|
|
5664
|
+
domain: serviceConfig.domain,
|
|
5665
|
+
scope: serviceConfig.scope,
|
|
5666
|
+
devMode: serviceConfig.devMode
|
|
5667
|
+
}
|
|
5668
|
+
};
|
|
5669
|
+
return {
|
|
5670
|
+
to: reputationManagerAddress,
|
|
5671
|
+
data: (0, import_viem13.encodeFunctionData)({
|
|
5672
|
+
abi: ABIS.EXTERNAL.REPUTATION_MANAGER,
|
|
5673
|
+
functionName: "zkPassportRegister",
|
|
5674
|
+
args: [proofVerificationParams, validated.isIDCard]
|
|
5675
|
+
})
|
|
5676
|
+
};
|
|
5677
|
+
},
|
|
5678
|
+
(error) => new ZkkycError("Failed to encode zkPassportRegister", {
|
|
5679
|
+
code: "ENCODE_ERROR",
|
|
5680
|
+
cause: error
|
|
5681
|
+
})
|
|
5682
|
+
)()
|
|
5683
|
+
);
|
|
5684
|
+
}
|
|
5685
|
+
|
|
5686
|
+
// src/contracts/tx-limits/index.ts
|
|
5687
|
+
var import_neverthrow12 = require("neverthrow");
|
|
5688
|
+
var import_viem14 = require("viem");
|
|
5689
|
+
|
|
5690
|
+
// src/profile/errors.ts
|
|
5691
|
+
var ProfileError = class extends SdkError {
|
|
5692
|
+
constructor(message, options) {
|
|
5693
|
+
super(message, options);
|
|
5694
|
+
this.name = "ProfileError";
|
|
5695
|
+
}
|
|
5696
|
+
};
|
|
5697
|
+
|
|
5698
|
+
// src/profile/validation.ts
|
|
5699
|
+
var import_zod9 = require("zod");
|
|
5700
|
+
var ZodUsdcBalanceParamsSchema = import_zod9.z.object({
|
|
5701
|
+
address: ZodAddressSchema
|
|
5702
|
+
});
|
|
5703
|
+
var ZodUsdcAllowanceParamsSchema = import_zod9.z.object({
|
|
5704
|
+
owner: ZodAddressSchema
|
|
5705
|
+
});
|
|
5706
|
+
var ZodGetBalancesParamsSchema = import_zod9.z.object({
|
|
5707
|
+
address: ZodAddressSchema,
|
|
5708
|
+
currency: ZodCurrencySchema
|
|
5709
|
+
});
|
|
5710
|
+
var ZodTxLimitsParamsSchema = import_zod9.z.object({
|
|
5711
|
+
address: ZodAddressSchema,
|
|
5712
|
+
currency: ZodCurrencySchema
|
|
5713
|
+
});
|
|
5714
|
+
|
|
5715
|
+
// src/contracts/tx-limits/index.ts
|
|
5716
|
+
function getTxLimits(publicClient, diamondAddress, params) {
|
|
5717
|
+
return validate(
|
|
5718
|
+
ZodTxLimitsParamsSchema,
|
|
5719
|
+
params,
|
|
5720
|
+
(message, cause, data) => new ProfileError(message, {
|
|
5721
|
+
code: "VALIDATION_ERROR",
|
|
5722
|
+
cause,
|
|
5723
|
+
context: { params: data }
|
|
5724
|
+
})
|
|
5725
|
+
).asyncAndThen(
|
|
5726
|
+
(validated) => import_neverthrow12.ResultAsync.fromPromise(
|
|
5727
|
+
publicClient.readContract({
|
|
5728
|
+
address: diamondAddress,
|
|
5729
|
+
abi: ABIS.FACETS.ORDER_FLOW,
|
|
5730
|
+
functionName: "userTxLimit",
|
|
5731
|
+
args: [validated.address, (0, import_viem14.stringToHex)(validated.currency, { size: 32 })]
|
|
5732
|
+
}),
|
|
5733
|
+
(error) => new ProfileError("Failed to read tx limits", {
|
|
5734
|
+
code: "CONTRACT_READ_ERROR",
|
|
5735
|
+
cause: error,
|
|
5736
|
+
context: { address: validated.address, currency: validated.currency, diamondAddress }
|
|
5737
|
+
})
|
|
5738
|
+
).map(([buyLimit, sellLimit]) => ({
|
|
5739
|
+
buyLimit: Number((0, import_viem14.formatUnits)(buyLimit, 6)),
|
|
5740
|
+
sellLimit: Number((0, import_viem14.formatUnits)(sellLimit, 6))
|
|
5741
|
+
}))
|
|
5742
|
+
);
|
|
5743
|
+
}
|
|
5744
|
+
|
|
5745
|
+
// src/contracts/usdc/index.ts
|
|
5746
|
+
var import_neverthrow13 = require("neverthrow");
|
|
5747
|
+
var import_viem15 = require("viem");
|
|
5748
|
+
function getUsdcBalance(publicClient, usdcAddress, params) {
|
|
5749
|
+
return validate(
|
|
5750
|
+
ZodUsdcBalanceParamsSchema,
|
|
5751
|
+
params,
|
|
5752
|
+
(message, cause, data) => new ProfileError(message, {
|
|
5753
|
+
code: "VALIDATION_ERROR",
|
|
5754
|
+
cause,
|
|
5755
|
+
context: { params: data }
|
|
5756
|
+
})
|
|
5757
|
+
).asyncAndThen(
|
|
5758
|
+
(validated) => import_neverthrow13.ResultAsync.fromPromise(
|
|
5759
|
+
publicClient.readContract({
|
|
5760
|
+
address: usdcAddress,
|
|
5761
|
+
abi: ABIS.EXTERNAL.USDC,
|
|
5762
|
+
functionName: "balanceOf",
|
|
5763
|
+
args: [validated.address]
|
|
5764
|
+
}),
|
|
5765
|
+
(error) => new ProfileError("Failed to read USDC balance", {
|
|
5766
|
+
code: "CONTRACT_READ_ERROR",
|
|
5767
|
+
cause: error,
|
|
5768
|
+
context: { address: validated.address, usdcAddress }
|
|
5769
|
+
})
|
|
5770
|
+
)
|
|
5771
|
+
);
|
|
5772
|
+
}
|
|
5773
|
+
function getUsdcAllowance(publicClient, usdcAddress, diamondAddress, params) {
|
|
5774
|
+
return validate(
|
|
5775
|
+
ZodUsdcAllowanceParamsSchema,
|
|
5776
|
+
params,
|
|
5777
|
+
(message, cause, data) => new ProfileError(message, {
|
|
5778
|
+
code: "VALIDATION_ERROR",
|
|
5779
|
+
cause,
|
|
5780
|
+
context: { params: data }
|
|
5781
|
+
})
|
|
5782
|
+
).asyncAndThen(
|
|
5783
|
+
(validated) => import_neverthrow13.ResultAsync.fromPromise(
|
|
5784
|
+
publicClient.readContract({
|
|
5785
|
+
address: usdcAddress,
|
|
5786
|
+
abi: import_viem15.erc20Abi,
|
|
5787
|
+
functionName: "allowance",
|
|
5788
|
+
args: [validated.owner, diamondAddress]
|
|
5789
|
+
}),
|
|
5790
|
+
(error) => new ProfileError("Failed to read USDC allowance", {
|
|
5791
|
+
code: "CONTRACT_READ_ERROR",
|
|
5792
|
+
cause: error,
|
|
5793
|
+
context: { owner: validated.owner, usdcAddress, diamondAddress }
|
|
5794
|
+
})
|
|
5795
|
+
)
|
|
5796
|
+
);
|
|
5797
|
+
}
|
|
5798
|
+
|
|
5799
|
+
// src/orders/internal/routing/routing.ts
|
|
5800
|
+
var import_neverthrow14 = require("neverthrow");
|
|
5801
|
+
var EPSILON = 0.25;
|
|
5802
|
+
var RECOVERY_SCALE = 0.3;
|
|
5803
|
+
var BOOTSTRAP_MAX_WEIGHT = 25;
|
|
5804
|
+
var MAX_VALIDATION_ATTEMPTS = 3;
|
|
5805
|
+
function circleWeight(c) {
|
|
5806
|
+
const score = c.metrics.circleScore;
|
|
5807
|
+
if (c.metrics.circleStatus === "paused") {
|
|
5808
|
+
return score * RECOVERY_SCALE;
|
|
5809
|
+
}
|
|
5810
|
+
if (c.metrics.circleStatus === "bootstrap") {
|
|
5811
|
+
return Math.min(score, BOOTSTRAP_MAX_WEIGHT);
|
|
5812
|
+
}
|
|
5813
|
+
return score;
|
|
5814
|
+
}
|
|
5815
|
+
function filterEligibleCircles(circles, orderCurrency) {
|
|
5816
|
+
return circles.filter((c) => c.currency.toLowerCase() === orderCurrency.toLowerCase());
|
|
5817
|
+
}
|
|
5818
|
+
function weightedRandomChoice(arr, weights) {
|
|
5819
|
+
const totalWeight = weights.reduce((sum, w) => sum + w, 0);
|
|
5820
|
+
if (totalWeight === 0) {
|
|
5821
|
+
return arr[Math.floor(Math.random() * arr.length)];
|
|
5822
|
+
}
|
|
5823
|
+
let rand = Math.random() * totalWeight;
|
|
5824
|
+
for (let i = 0; i < arr.length; i++) {
|
|
5825
|
+
rand -= weights[i];
|
|
5826
|
+
if (rand <= 0) {
|
|
5827
|
+
return arr[i];
|
|
5828
|
+
}
|
|
5829
|
+
}
|
|
5830
|
+
return arr[arr.length - 1];
|
|
5831
|
+
}
|
|
5832
|
+
function selectCircle(eligible) {
|
|
5833
|
+
if (eligible.length === 0) {
|
|
5834
|
+
return null;
|
|
5835
|
+
}
|
|
5836
|
+
const activeCircles = eligible.filter((c) => c.metrics.circleStatus === "active");
|
|
5837
|
+
const isExplore = Math.random() < EPSILON;
|
|
5838
|
+
if (isExplore) {
|
|
5839
|
+
const weights2 = eligible.map(circleWeight);
|
|
5840
|
+
return weightedRandomChoice(eligible, weights2);
|
|
5841
|
+
}
|
|
5842
|
+
if (activeCircles.length === 0) {
|
|
5843
|
+
const weights2 = eligible.map(circleWeight);
|
|
5844
|
+
return weightedRandomChoice(eligible, weights2);
|
|
5845
|
+
}
|
|
5846
|
+
const weights = activeCircles.map((c) => c.metrics.circleScore);
|
|
5847
|
+
return weightedRandomChoice(activeCircles, weights);
|
|
5848
|
+
}
|
|
5849
|
+
function selectCircleForOrderAsync(circles, orderCurrency, validateCircle, logger = noopLogger) {
|
|
5850
|
+
const eligible = filterEligibleCircles(circles, orderCurrency);
|
|
5851
|
+
let remaining = [...eligible];
|
|
5852
|
+
logger.debug("filtering eligible circles", {
|
|
5853
|
+
total: circles.length,
|
|
5854
|
+
eligible: eligible.length,
|
|
5855
|
+
currency: orderCurrency,
|
|
5856
|
+
circles: eligible
|
|
5857
|
+
});
|
|
5858
|
+
if (eligible.length === 0) {
|
|
5859
|
+
logger.warn("no eligible circles found for currency", { currency: orderCurrency });
|
|
5860
|
+
}
|
|
5861
|
+
function attempt(attemptsLeft) {
|
|
5862
|
+
if (attemptsLeft <= 0 || remaining.length === 0) {
|
|
5863
|
+
logger.warn("exhausted all attempts or circles", {
|
|
5864
|
+
attemptsLeft,
|
|
5865
|
+
remainingCircles: remaining.length
|
|
5866
|
+
});
|
|
5867
|
+
return (0, import_neverthrow14.errAsync)(
|
|
5868
|
+
new OrderRoutingError("No eligible circles found", {
|
|
5869
|
+
code: "NO_ELIGIBLE_CIRCLES"
|
|
5870
|
+
})
|
|
5871
|
+
);
|
|
5872
|
+
}
|
|
5873
|
+
const selected = selectCircle(remaining);
|
|
5874
|
+
if (!selected) {
|
|
5875
|
+
return (0, import_neverthrow14.errAsync)(
|
|
5876
|
+
new OrderRoutingError("No eligible circles found", {
|
|
5877
|
+
code: "NO_ELIGIBLE_CIRCLES"
|
|
5878
|
+
})
|
|
5879
|
+
);
|
|
5880
|
+
}
|
|
5881
|
+
const circleId = BigInt(selected.circleId);
|
|
5882
|
+
logger.debug("selected circle, validating on-chain", {
|
|
5883
|
+
circleId: String(circleId),
|
|
5884
|
+
status: selected.metrics.circleStatus,
|
|
5885
|
+
score: selected.metrics.circleScore,
|
|
5886
|
+
attemptsLeft
|
|
5887
|
+
});
|
|
5888
|
+
return validateCircle(circleId).orElse((error) => {
|
|
5889
|
+
logger.warn("validation errored, treating as ineligible", {
|
|
5890
|
+
circleId: String(circleId),
|
|
5891
|
+
error: String(error)
|
|
5892
|
+
});
|
|
5893
|
+
return (0, import_neverthrow14.okAsync)(false);
|
|
5894
|
+
}).andThen((isValid) => {
|
|
5895
|
+
if (isValid) {
|
|
5896
|
+
logger.info("circle validated successfully", { circleId: String(circleId) });
|
|
5897
|
+
return (0, import_neverthrow14.okAsync)(circleId);
|
|
5898
|
+
}
|
|
5899
|
+
logger.debug("circle failed validation, retrying", {
|
|
5900
|
+
circleId: String(circleId),
|
|
5901
|
+
remainingCircles: remaining.length - 1
|
|
5902
|
+
});
|
|
5903
|
+
remaining = remaining.filter((c) => c.circleId !== selected.circleId);
|
|
5904
|
+
return attempt(attemptsLeft - 1);
|
|
5905
|
+
});
|
|
5906
|
+
}
|
|
5907
|
+
return attempt(MAX_VALIDATION_ATTEMPTS);
|
|
5908
|
+
}
|
|
5909
|
+
|
|
5910
|
+
// src/orders/internal/routing/subgraph/queries.ts
|
|
5911
|
+
var CIRCLES_FOR_ROUTING_QUERY = (
|
|
5912
|
+
/* GraphQL */
|
|
5913
|
+
`
|
|
5914
|
+
query CirclesForRouting($currency: Bytes!) {
|
|
5915
|
+
circles(
|
|
5916
|
+
first: 1000
|
|
5917
|
+
where: {
|
|
5918
|
+
currency: $currency
|
|
5919
|
+
metrics_: {
|
|
5920
|
+
circleStatus_in: ["active", "bootstrap", "paused"]
|
|
5921
|
+
}
|
|
5922
|
+
}
|
|
5923
|
+
) {
|
|
5924
|
+
circleId
|
|
5925
|
+
currency
|
|
5926
|
+
metrics {
|
|
5927
|
+
circleScore
|
|
5928
|
+
circleStatus
|
|
5929
|
+
scoreState {
|
|
5930
|
+
activeMerchantsCount
|
|
5931
|
+
}
|
|
5932
|
+
}
|
|
5933
|
+
}
|
|
5934
|
+
}
|
|
5935
|
+
`
|
|
5936
|
+
);
|
|
5937
|
+
|
|
5938
|
+
// src/orders/internal/routing/subgraph/index.ts
|
|
5939
|
+
function getCirclesForRouting(subgraphUrl, currency, logger = noopLogger) {
|
|
5940
|
+
logger.debug("fetching circles from subgraph", { subgraphUrl, currency });
|
|
5941
|
+
return querySubgraph(subgraphUrl, {
|
|
5942
|
+
query: CIRCLES_FOR_ROUTING_QUERY,
|
|
5943
|
+
variables: { currency }
|
|
5944
|
+
}).mapErr(
|
|
5945
|
+
(e) => new OrderRoutingError(e.message, {
|
|
5946
|
+
code: "SUBGRAPH_ERROR",
|
|
5947
|
+
cause: e.cause ?? e,
|
|
5948
|
+
context: e.context
|
|
5949
|
+
})
|
|
5950
|
+
).andThen(
|
|
5951
|
+
(data) => validate(
|
|
5952
|
+
ZodCirclesForRoutingResponseSchema,
|
|
5953
|
+
data,
|
|
5954
|
+
(message, cause, d) => new OrderRoutingError(message, { code: "VALIDATION_ERROR", cause, context: { data: d } })
|
|
5955
|
+
).map((validated) => {
|
|
5956
|
+
const circles = validated.circles.filter(
|
|
5957
|
+
(item) => Number(item.metrics.scoreState.activeMerchantsCount) > 0
|
|
5958
|
+
);
|
|
5959
|
+
logger.info("fetched circles from subgraph", {
|
|
5960
|
+
total: validated.circles.length,
|
|
5961
|
+
withActiveMerchants: circles.length,
|
|
5962
|
+
circles
|
|
5963
|
+
});
|
|
5964
|
+
return circles;
|
|
5965
|
+
})
|
|
5966
|
+
);
|
|
4380
5967
|
}
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
const
|
|
4385
|
-
const
|
|
4386
|
-
const sharedSecret = sharedPoint.slice(1);
|
|
4387
|
-
const { encKey, macKey } = deriveKeys(sharedSecret);
|
|
4388
|
-
const iv = randomBytes(16);
|
|
4389
|
-
const plaintext = new TextEncoder().encode(message);
|
|
4390
|
-
const cipher = cbc(encKey, iv);
|
|
4391
|
-
const ciphertext = cipher.encrypt(plaintext);
|
|
4392
|
-
const macData = concatBytes2(iv, ephemPubKey, ciphertext);
|
|
4393
|
-
const mac = hmac(sha2562, macKey, macData);
|
|
5968
|
+
|
|
5969
|
+
// src/orders/internal/routing/client.ts
|
|
5970
|
+
function createOrderRouter(config) {
|
|
5971
|
+
const { subgraphUrl, publicClient, contractAddress } = config;
|
|
5972
|
+
const logger = config.logger ?? noopLogger;
|
|
4394
5973
|
return {
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
5974
|
+
selectCircle(params) {
|
|
5975
|
+
const currencyHex = (0, import_viem16.stringToHex)(params.currency, { size: 32 });
|
|
5976
|
+
logger.info("selectCircle started", {
|
|
5977
|
+
currency: params.currency,
|
|
5978
|
+
user: params.user,
|
|
5979
|
+
orderType: String(params.orderType)
|
|
5980
|
+
});
|
|
5981
|
+
return getCirclesForRouting(subgraphUrl, currencyHex, logger).andThen(
|
|
5982
|
+
(circles) => selectCircleForOrderAsync(
|
|
5983
|
+
circles,
|
|
5984
|
+
currencyHex,
|
|
5985
|
+
(circleId) => checkCircleEligibility(
|
|
5986
|
+
publicClient,
|
|
5987
|
+
contractAddress,
|
|
5988
|
+
{
|
|
5989
|
+
circleId,
|
|
5990
|
+
currency: currencyHex,
|
|
5991
|
+
user: params.user,
|
|
5992
|
+
usdtAmount: params.usdtAmount,
|
|
5993
|
+
fiatAmount: params.fiatAmount,
|
|
5994
|
+
orderType: params.orderType,
|
|
5995
|
+
preferredPCConfigId: params.preferredPCConfigId
|
|
5996
|
+
},
|
|
5997
|
+
logger
|
|
5998
|
+
),
|
|
5999
|
+
logger
|
|
6000
|
+
)
|
|
6001
|
+
);
|
|
6002
|
+
}
|
|
4399
6003
|
};
|
|
4400
6004
|
}
|
|
4401
|
-
function cipherStringify(encrypted) {
|
|
4402
|
-
const ephemPubKeyBytes = hexToBytes3(encrypted.ephemPublicKey);
|
|
4403
|
-
const compressed = secp256k1.ProjectivePoint.fromHex(ephemPubKeyBytes).toRawBytes(true);
|
|
4404
|
-
const iv = hexToBytes3(encrypted.iv);
|
|
4405
|
-
const mac = hexToBytes3(encrypted.mac);
|
|
4406
|
-
const ciphertext = hexToBytes3(encrypted.ciphertext);
|
|
4407
|
-
return bytesToHex2(concatBytes2(iv, compressed, mac, ciphertext));
|
|
4408
|
-
}
|
|
4409
6005
|
|
|
4410
|
-
// src/
|
|
4411
|
-
var
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
6006
|
+
// src/orders/normalize.ts
|
|
6007
|
+
var import_neverthrow15 = require("neverthrow");
|
|
6008
|
+
var import_viem17 = require("viem");
|
|
6009
|
+
var ORDER_TYPE_MAP = {
|
|
6010
|
+
[ORDER_TYPE.BUY]: "buy",
|
|
6011
|
+
[ORDER_TYPE.SELL]: "sell",
|
|
6012
|
+
[ORDER_TYPE.PAY]: "pay"
|
|
4416
6013
|
};
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
const rawPubKey = account.publicKey;
|
|
4435
|
-
const publicKey = rawPubKey.slice(4);
|
|
4436
|
-
const identity = {
|
|
4437
|
-
address: account.address,
|
|
4438
|
-
publicKey,
|
|
4439
|
-
privateKey
|
|
4440
|
-
};
|
|
4441
|
-
localStorage.setItem(STORAGE_KEY, JSON.stringify(identity));
|
|
4442
|
-
return identity;
|
|
6014
|
+
var ORDER_STATUS_MAP = {
|
|
6015
|
+
[ORDER_STATUS.PLACED]: "placed",
|
|
6016
|
+
[ORDER_STATUS.ACCEPTED]: "accepted",
|
|
6017
|
+
[ORDER_STATUS.PAID]: "paid",
|
|
6018
|
+
[ORDER_STATUS.COMPLETED]: "completed",
|
|
6019
|
+
[ORDER_STATUS.CANCELLED]: "cancelled"
|
|
6020
|
+
};
|
|
6021
|
+
var DISPUTE_STATUS_MAP = {
|
|
6022
|
+
[DISPUTE_STATUS.NONE]: "none",
|
|
6023
|
+
[DISPUTE_STATUS.OPEN]: "open",
|
|
6024
|
+
[DISPUTE_STATUS.RESOLVED]: "resolved"
|
|
6025
|
+
};
|
|
6026
|
+
function malformed(field, value, context) {
|
|
6027
|
+
return new OrdersError(`Unknown ${field}: ${String(value)}`, {
|
|
6028
|
+
code: "MALFORMED_ORDER",
|
|
6029
|
+
context: { field, value, ...context }
|
|
6030
|
+
});
|
|
4443
6031
|
}
|
|
4444
|
-
function
|
|
4445
|
-
const
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
if (
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
6032
|
+
function mapOrderType(v, ctx) {
|
|
6033
|
+
const t = ORDER_TYPE_MAP[v];
|
|
6034
|
+
return t ? (0, import_neverthrow15.ok)(t) : (0, import_neverthrow15.err)(malformed("orderType", v, ctx));
|
|
6035
|
+
}
|
|
6036
|
+
function mapOrderStatus(v, ctx) {
|
|
6037
|
+
const s = ORDER_STATUS_MAP[v];
|
|
6038
|
+
return s ? (0, import_neverthrow15.ok)(s) : (0, import_neverthrow15.err)(malformed("status", v, ctx));
|
|
6039
|
+
}
|
|
6040
|
+
function mapDisputeStatus(v, ctx) {
|
|
6041
|
+
const s = DISPUTE_STATUS_MAP[v];
|
|
6042
|
+
return s ? (0, import_neverthrow15.ok)(s) : (0, import_neverthrow15.err)(malformed("disputeStatus", v, ctx));
|
|
6043
|
+
}
|
|
6044
|
+
function decodeCurrency(hex) {
|
|
6045
|
+
return (0, import_viem17.hexToString)(hex, { size: 32 }).replaceAll("\0", "");
|
|
6046
|
+
}
|
|
6047
|
+
function normalizeContractOrder(raw, details) {
|
|
6048
|
+
if (raw.id === 0n && (0, import_viem17.isAddressEqual)(raw.user, import_viem17.zeroAddress)) return (0, import_neverthrow15.ok)(null);
|
|
6049
|
+
const ctx = { orderId: raw.id.toString() };
|
|
6050
|
+
return import_neverthrow15.Result.combine([
|
|
6051
|
+
mapOrderType(raw.orderType, ctx),
|
|
6052
|
+
mapOrderStatus(raw.status, ctx),
|
|
6053
|
+
mapDisputeStatus(raw.disputeInfo.status, ctx)
|
|
6054
|
+
]).map(([type, status, disputeStatus]) => ({
|
|
6055
|
+
orderId: raw.id,
|
|
6056
|
+
type,
|
|
6057
|
+
status,
|
|
6058
|
+
usdcAmount: raw.amount,
|
|
6059
|
+
fiatAmount: raw.fiatAmount,
|
|
6060
|
+
actualUsdcAmount: details.actualUsdtAmount,
|
|
6061
|
+
actualFiatAmount: details.actualFiatAmount,
|
|
6062
|
+
currency: decodeCurrency(raw.currency),
|
|
6063
|
+
user: raw.user,
|
|
6064
|
+
recipient: raw.recipientAddr,
|
|
6065
|
+
acceptedMerchant: raw.acceptedMerchant,
|
|
6066
|
+
placedAt: raw.placedTimestamp,
|
|
6067
|
+
acceptedAt: details.acceptedTimestamp,
|
|
6068
|
+
paidAt: details.paidTimestamp,
|
|
6069
|
+
completedAt: raw.completedTimestamp,
|
|
6070
|
+
circleId: raw.circleId,
|
|
6071
|
+
fixedFeePaid: details.fixedFeePaid,
|
|
6072
|
+
tipsPaid: details.tipsPaid,
|
|
6073
|
+
disputeStatus,
|
|
6074
|
+
encUpi: raw.encUpi,
|
|
6075
|
+
encMerchantUpi: raw.encMerchantUpi,
|
|
6076
|
+
pubkey: raw.pubkey
|
|
6077
|
+
}));
|
|
4464
6078
|
}
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
)
|
|
4498
|
-
);
|
|
4499
|
-
const stringified = yield* safeCipherStringify(encrypted);
|
|
4500
|
-
return (0, import_neverthrow12.ok)(stringified);
|
|
4501
|
-
});
|
|
6079
|
+
function normalizeSubgraphOrder(raw) {
|
|
6080
|
+
const ctx = { orderId: raw.orderId };
|
|
6081
|
+
return import_neverthrow15.Result.combine([
|
|
6082
|
+
mapOrderType(raw.type, ctx),
|
|
6083
|
+
mapOrderStatus(raw.status, ctx),
|
|
6084
|
+
mapDisputeStatus(raw.disputeStatus, ctx)
|
|
6085
|
+
]).map(([type, status, disputeStatus]) => ({
|
|
6086
|
+
orderId: BigInt(raw.orderId),
|
|
6087
|
+
type,
|
|
6088
|
+
status,
|
|
6089
|
+
usdcAmount: BigInt(raw.usdcAmount),
|
|
6090
|
+
fiatAmount: BigInt(raw.fiatAmount),
|
|
6091
|
+
actualUsdcAmount: BigInt(raw.actualUsdcAmount),
|
|
6092
|
+
actualFiatAmount: BigInt(raw.actualFiatAmount),
|
|
6093
|
+
currency: decodeCurrency(raw.currency),
|
|
6094
|
+
user: raw.userAddress,
|
|
6095
|
+
recipient: raw.usdcRecipientAddress,
|
|
6096
|
+
acceptedMerchant: raw.acceptedMerchantAddress,
|
|
6097
|
+
placedAt: BigInt(raw.placedAt),
|
|
6098
|
+
acceptedAt: BigInt(raw.acceptedAt),
|
|
6099
|
+
paidAt: BigInt(raw.paidAt),
|
|
6100
|
+
completedAt: BigInt(raw.completedAt),
|
|
6101
|
+
circleId: BigInt(raw.circleId),
|
|
6102
|
+
fixedFeePaid: BigInt(raw.fixedFeePaid),
|
|
6103
|
+
tipsPaid: BigInt(raw.tipsPaid),
|
|
6104
|
+
disputeStatus,
|
|
6105
|
+
// Subgraph entity does not currently expose these encryption fields;
|
|
6106
|
+
// consumers needing them should fall back to the contract via getOrder.
|
|
6107
|
+
encUpi: "",
|
|
6108
|
+
encMerchantUpi: "",
|
|
6109
|
+
pubkey: ""
|
|
6110
|
+
}));
|
|
4502
6111
|
}
|
|
4503
|
-
var ZodEncryptedDataSchema = import_zod7.z.object({
|
|
4504
|
-
ciphertext: import_zod7.z.string(),
|
|
4505
|
-
iv: import_zod7.z.string(),
|
|
4506
|
-
mac: import_zod7.z.string(),
|
|
4507
|
-
ephemPublicKey: import_zod7.z.string()
|
|
4508
|
-
});
|
|
4509
6112
|
|
|
4510
|
-
// src/
|
|
4511
|
-
var
|
|
4512
|
-
var ZodPlaceOrderParamsSchema = import_zod8.z.object({
|
|
4513
|
-
amount: import_zod8.z.bigint(),
|
|
4514
|
-
recipientAddr: ZodAddressSchema,
|
|
4515
|
-
orderType: import_zod8.z.number().int().min(0).max(2),
|
|
4516
|
-
currency: ZodCurrencySchema,
|
|
4517
|
-
fiatAmount: import_zod8.z.bigint(),
|
|
4518
|
-
user: ZodAddressSchema,
|
|
4519
|
-
pubKey: import_zod8.z.string().optional(),
|
|
4520
|
-
preferredPaymentChannelConfigId: import_zod8.z.bigint().optional(),
|
|
4521
|
-
fiatAmountLimit: import_zod8.z.bigint().optional().default(0n)
|
|
4522
|
-
});
|
|
4523
|
-
var ZodSetSellOrderUpiParamsSchema = import_zod8.z.object({
|
|
4524
|
-
orderId: import_zod8.z.number().int().nonnegative(),
|
|
4525
|
-
paymentAddress: import_zod8.z.string().min(1),
|
|
4526
|
-
merchantPublicKey: import_zod8.z.string().min(1),
|
|
4527
|
-
updatedAmount: import_zod8.z.bigint()
|
|
4528
|
-
});
|
|
6113
|
+
// src/orders/subgraph/index.ts
|
|
6114
|
+
var import_neverthrow16 = require("neverthrow");
|
|
4529
6115
|
|
|
4530
|
-
// src/
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
(
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
6116
|
+
// src/orders/subgraph/queries.ts
|
|
6117
|
+
var ORDERS_BY_USER_QUERY = (
|
|
6118
|
+
/* GraphQL */
|
|
6119
|
+
`
|
|
6120
|
+
query OrdersByUser($user: Bytes!, $skip: Int!, $first: Int!) {
|
|
6121
|
+
orders_collection(
|
|
6122
|
+
where: { userAddress: $user }
|
|
6123
|
+
orderBy: placedAt
|
|
6124
|
+
orderDirection: desc
|
|
6125
|
+
skip: $skip
|
|
6126
|
+
first: $first
|
|
6127
|
+
) {
|
|
6128
|
+
orderId
|
|
6129
|
+
type
|
|
6130
|
+
status
|
|
6131
|
+
circleId
|
|
6132
|
+
userAddress
|
|
6133
|
+
usdcRecipientAddress
|
|
6134
|
+
acceptedMerchantAddress
|
|
6135
|
+
usdcAmount
|
|
6136
|
+
fiatAmount
|
|
6137
|
+
actualUsdcAmount
|
|
6138
|
+
actualFiatAmount
|
|
6139
|
+
currency
|
|
6140
|
+
placedAt
|
|
6141
|
+
acceptedAt
|
|
6142
|
+
paidAt
|
|
6143
|
+
completedAt
|
|
6144
|
+
fixedFeePaid
|
|
6145
|
+
tipsPaid
|
|
6146
|
+
disputeStatus
|
|
6147
|
+
}
|
|
6148
|
+
}
|
|
6149
|
+
`
|
|
6150
|
+
);
|
|
6151
|
+
|
|
6152
|
+
// src/orders/subgraph/index.ts
|
|
6153
|
+
function getOrdersForUser(subgraphUrl, userAddress, skip, limit, logger = noopLogger) {
|
|
6154
|
+
const user = userAddress.toLowerCase();
|
|
6155
|
+
logger.debug("fetching orders from subgraph", { subgraphUrl, user, skip, limit });
|
|
6156
|
+
return querySubgraph(subgraphUrl, {
|
|
6157
|
+
query: ORDERS_BY_USER_QUERY,
|
|
6158
|
+
variables: { user, skip, first: limit }
|
|
6159
|
+
}).mapErr(
|
|
6160
|
+
(e) => new OrdersError(e.message, {
|
|
6161
|
+
code: "SUBGRAPH_REQUEST_FAILED",
|
|
6162
|
+
cause: e.cause ?? e,
|
|
6163
|
+
context: { user, skip, limit, ...e.context ?? {} }
|
|
4574
6164
|
})
|
|
6165
|
+
).andThen(
|
|
6166
|
+
(data) => validate(
|
|
6167
|
+
ZodSubgraphOrdersResponseSchema,
|
|
6168
|
+
data,
|
|
6169
|
+
(message, cause, d) => new OrdersError(message, {
|
|
6170
|
+
code: "SUBGRAPH_VALIDATION_FAILED",
|
|
6171
|
+
cause,
|
|
6172
|
+
context: { data: d }
|
|
6173
|
+
})
|
|
6174
|
+
).andThen(
|
|
6175
|
+
(validated) => import_neverthrow16.Result.combine(validated.orders_collection.map(normalizeSubgraphOrder))
|
|
6176
|
+
)
|
|
4575
6177
|
);
|
|
4576
6178
|
}
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
6179
|
+
|
|
6180
|
+
// src/orders/watch-events.ts
|
|
6181
|
+
var PLACED_CONFIG = {
|
|
6182
|
+
eventName: "OrderPlaced",
|
|
6183
|
+
toEvent: (log) => ({
|
|
6184
|
+
type: "placed",
|
|
6185
|
+
orderId: log.args.orderId,
|
|
6186
|
+
user: log.args.user,
|
|
6187
|
+
orderType: log.args.orderType,
|
|
6188
|
+
blockNumber: log.blockNumber,
|
|
6189
|
+
txHash: log.transactionHash
|
|
6190
|
+
}),
|
|
6191
|
+
userFromLog: (log) => log.args.user
|
|
6192
|
+
};
|
|
6193
|
+
var ACCEPTED_CONFIG = {
|
|
6194
|
+
eventName: "OrderAccepted",
|
|
6195
|
+
toEvent: (log) => ({
|
|
6196
|
+
type: "accepted",
|
|
6197
|
+
orderId: log.args.orderId,
|
|
6198
|
+
merchant: log.args.merchant,
|
|
6199
|
+
blockNumber: log.blockNumber,
|
|
6200
|
+
txHash: log.transactionHash
|
|
6201
|
+
}),
|
|
6202
|
+
// OrderAccepted's top-level args are (orderId, merchant, pubKey, _order).
|
|
6203
|
+
// The buyer's address lives inside the _order tuple as _order.user.
|
|
6204
|
+
userFromLog: (log) => log.args._order?.user
|
|
6205
|
+
};
|
|
6206
|
+
var PAID_CONFIG = {
|
|
6207
|
+
eventName: "BuyOrderPaid",
|
|
6208
|
+
toEvent: (log) => ({
|
|
6209
|
+
type: "paid",
|
|
6210
|
+
orderId: log.args.orderId,
|
|
6211
|
+
blockNumber: log.blockNumber,
|
|
6212
|
+
txHash: log.transactionHash
|
|
6213
|
+
}),
|
|
6214
|
+
userFromLog: (log) => log.args.user
|
|
6215
|
+
};
|
|
6216
|
+
var COMPLETED_CONFIG = {
|
|
6217
|
+
eventName: "OrderCompleted",
|
|
6218
|
+
toEvent: (log) => ({
|
|
6219
|
+
type: "completed",
|
|
6220
|
+
orderId: log.args.orderId,
|
|
6221
|
+
blockNumber: log.blockNumber,
|
|
6222
|
+
txHash: log.transactionHash
|
|
6223
|
+
}),
|
|
6224
|
+
userFromLog: (log) => log.args.user
|
|
6225
|
+
};
|
|
6226
|
+
var CANCELLED_CONFIG = {
|
|
6227
|
+
eventName: "CancelledOrders",
|
|
6228
|
+
toEvent: (log) => ({
|
|
6229
|
+
type: "cancelled",
|
|
6230
|
+
orderId: log.args.orderId,
|
|
6231
|
+
blockNumber: log.blockNumber,
|
|
6232
|
+
txHash: log.transactionHash
|
|
6233
|
+
}),
|
|
6234
|
+
// CancelledOrders's top-level args are (orderId, _order). The buyer's
|
|
6235
|
+
// address lives inside the _order tuple as _order.user.
|
|
6236
|
+
userFromLog: (log) => log.args._order?.user
|
|
6237
|
+
};
|
|
6238
|
+
var ALL_CONFIGS = [
|
|
6239
|
+
PLACED_CONFIG,
|
|
6240
|
+
ACCEPTED_CONFIG,
|
|
6241
|
+
PAID_CONFIG,
|
|
6242
|
+
COMPLETED_CONFIG,
|
|
6243
|
+
CANCELLED_CONFIG
|
|
6244
|
+
];
|
|
6245
|
+
function createWatchEvents(input) {
|
|
6246
|
+
const { publicClient, diamondAddress } = input;
|
|
6247
|
+
return ({ user, onEvent, onError }) => {
|
|
6248
|
+
const unwatchers = [];
|
|
6249
|
+
for (const config of ALL_CONFIGS) {
|
|
6250
|
+
try {
|
|
6251
|
+
const unwatch = publicClient.watchContractEvent({
|
|
6252
|
+
address: diamondAddress,
|
|
6253
|
+
abi: ABIS.DIAMOND,
|
|
6254
|
+
eventName: config.eventName,
|
|
6255
|
+
onLogs: (logs) => {
|
|
6256
|
+
for (const log of logs) {
|
|
6257
|
+
if (user && config.userFromLog) {
|
|
6258
|
+
const logUser = config.userFromLog(log);
|
|
6259
|
+
if (!logUser || logUser.toLowerCase() !== user.toLowerCase()) continue;
|
|
6260
|
+
}
|
|
6261
|
+
onEvent(config.toEvent(log));
|
|
6262
|
+
}
|
|
6263
|
+
},
|
|
6264
|
+
onError: (err5) => {
|
|
6265
|
+
onError?.(
|
|
6266
|
+
new OrdersError(`watchContractEvent failed for ${config.eventName}`, {
|
|
6267
|
+
code: "EVENT_WATCH_FAILED",
|
|
6268
|
+
cause: err5,
|
|
6269
|
+
context: { eventName: config.eventName }
|
|
6270
|
+
})
|
|
6271
|
+
);
|
|
6272
|
+
}
|
|
6273
|
+
});
|
|
6274
|
+
unwatchers.push(unwatch);
|
|
6275
|
+
} catch (err5) {
|
|
6276
|
+
onError?.(
|
|
6277
|
+
new OrdersError(`failed to subscribe to ${config.eventName}`, {
|
|
6278
|
+
code: "EVENT_WATCH_FAILED",
|
|
6279
|
+
cause: err5,
|
|
6280
|
+
context: { eventName: config.eventName }
|
|
6281
|
+
})
|
|
6282
|
+
);
|
|
6283
|
+
}
|
|
6284
|
+
}
|
|
6285
|
+
return () => {
|
|
6286
|
+
for (const u of unwatchers) {
|
|
6287
|
+
try {
|
|
6288
|
+
u();
|
|
6289
|
+
} catch {
|
|
6290
|
+
}
|
|
6291
|
+
}
|
|
6292
|
+
};
|
|
6293
|
+
};
|
|
4592
6294
|
}
|
|
4593
6295
|
|
|
4594
|
-
// src/
|
|
4595
|
-
function
|
|
6296
|
+
// src/orders/client.ts
|
|
6297
|
+
function createOrders(config) {
|
|
6298
|
+
const { publicClient, diamondAddress, usdcAddress, subgraphUrl, relayIdentity } = config;
|
|
6299
|
+
const logger = config.logger ?? noopLogger;
|
|
6300
|
+
const relayIdentityStore = config.relayIdentityStore ?? createInMemoryRelayStore();
|
|
6301
|
+
const orderRouter = createOrderRouter({
|
|
6302
|
+
publicClient,
|
|
6303
|
+
subgraphUrl,
|
|
6304
|
+
contractAddress: diamondAddress,
|
|
6305
|
+
logger
|
|
6306
|
+
});
|
|
4596
6307
|
return {
|
|
4597
|
-
|
|
4598
|
-
|
|
6308
|
+
// ── Reads ─────────────────────────────────────────────────────────
|
|
6309
|
+
getOrder(params) {
|
|
6310
|
+
return validate(
|
|
6311
|
+
ZodGetOrderParamsSchema,
|
|
6312
|
+
params,
|
|
6313
|
+
(message, cause, d) => new OrdersError(message, {
|
|
6314
|
+
code: "INVALID_ORDER_ID",
|
|
6315
|
+
cause,
|
|
6316
|
+
context: { params: d }
|
|
6317
|
+
})
|
|
6318
|
+
).asyncAndThen(
|
|
6319
|
+
({ orderId }) => readOrderMulticall(publicClient, diamondAddress, orderId).mapErr(
|
|
6320
|
+
(cause) => new OrdersError("Order contract read failed", {
|
|
6321
|
+
code: "CONTRACT_READ_FAILED",
|
|
6322
|
+
cause,
|
|
6323
|
+
context: { orderId: orderId.toString() }
|
|
6324
|
+
})
|
|
6325
|
+
)
|
|
6326
|
+
).andThen(
|
|
6327
|
+
({ order, details }) => normalizeContractOrder(order, details).asyncAndThen((normalized) => {
|
|
6328
|
+
if (!normalized) {
|
|
6329
|
+
return (0, import_neverthrow17.errAsync)(
|
|
6330
|
+
new OrdersError("Order not found", {
|
|
6331
|
+
code: "ORDER_NOT_FOUND",
|
|
6332
|
+
context: { orderId: params.orderId.toString() }
|
|
6333
|
+
})
|
|
6334
|
+
);
|
|
6335
|
+
}
|
|
6336
|
+
logger.debug("getOrder resolved", { orderId: params.orderId.toString() });
|
|
6337
|
+
return (0, import_neverthrow17.okAsync)(normalized);
|
|
6338
|
+
})
|
|
6339
|
+
);
|
|
6340
|
+
},
|
|
6341
|
+
getOrders(params) {
|
|
6342
|
+
return validate(
|
|
6343
|
+
ZodGetOrdersParamsSchema,
|
|
6344
|
+
params,
|
|
6345
|
+
(message, cause, d) => new OrdersError(message, {
|
|
6346
|
+
code: "INVALID_GET_ORDERS_PARAMS",
|
|
6347
|
+
cause,
|
|
6348
|
+
context: { params: d }
|
|
6349
|
+
})
|
|
6350
|
+
).asyncAndThen(
|
|
6351
|
+
({ userAddress, skip, limit }) => getOrdersForUser(subgraphUrl, userAddress, skip, limit, logger)
|
|
6352
|
+
);
|
|
6353
|
+
},
|
|
6354
|
+
getFeeConfig(params) {
|
|
6355
|
+
return validate(
|
|
6356
|
+
ZodGetFeeConfigParamsSchema,
|
|
6357
|
+
params,
|
|
6358
|
+
(message, cause, d) => new OrdersError(message, {
|
|
6359
|
+
code: "INVALID_FEE_CONFIG_PARAMS",
|
|
6360
|
+
cause,
|
|
6361
|
+
context: { params: d }
|
|
6362
|
+
})
|
|
6363
|
+
).asyncAndThen(
|
|
6364
|
+
({ currency }) => readFeeConfigMulticall(publicClient, diamondAddress, currency).mapErr(
|
|
6365
|
+
(cause) => new OrdersError("Fee config contract read failed", {
|
|
6366
|
+
code: "CONTRACT_READ_FAILED",
|
|
6367
|
+
cause,
|
|
6368
|
+
context: { currency }
|
|
6369
|
+
})
|
|
6370
|
+
)
|
|
6371
|
+
).map((config2) => {
|
|
6372
|
+
logger.debug("getFeeConfig resolved", { currency: params.currency });
|
|
6373
|
+
return config2;
|
|
6374
|
+
});
|
|
6375
|
+
},
|
|
6376
|
+
// ── Writes ────────────────────────────────────────────────────────
|
|
6377
|
+
placeOrder: createPlaceOrderAction({
|
|
6378
|
+
publicClient,
|
|
6379
|
+
diamondAddress,
|
|
6380
|
+
orderRouter,
|
|
6381
|
+
relayIdentityStore,
|
|
6382
|
+
relayIdentity
|
|
6383
|
+
}),
|
|
6384
|
+
cancelOrder: createCancelOrderAction({ publicClient, diamondAddress }),
|
|
6385
|
+
setSellOrderUpi: createSetSellOrderUpiAction({
|
|
6386
|
+
publicClient,
|
|
6387
|
+
diamondAddress,
|
|
6388
|
+
relayIdentityStore,
|
|
6389
|
+
relayIdentity
|
|
6390
|
+
}),
|
|
6391
|
+
raiseDispute: createRaiseDisputeAction({ publicClient, diamondAddress }),
|
|
6392
|
+
approveUsdc: createApproveUsdcAction({ publicClient, diamondAddress, usdcAddress }),
|
|
6393
|
+
paidBuyOrder: createPaidBuyOrderAction({ publicClient, diamondAddress }),
|
|
6394
|
+
watchEvents: createWatchEvents({ publicClient, diamondAddress }),
|
|
6395
|
+
// ── Crypto helpers ───────────────────────────────────────────────
|
|
6396
|
+
decryptPaymentAddress({ encrypted }) {
|
|
6397
|
+
return resolveRelayIdentity({ relayIdentity, store: relayIdentityStore }).andThen(
|
|
6398
|
+
(recipientIdentity) => decryptPaymentAddress({ encrypted, recipientIdentity })
|
|
6399
|
+
);
|
|
4599
6400
|
},
|
|
4600
|
-
|
|
4601
|
-
return
|
|
6401
|
+
encryptPaymentAddress({ paymentAddress, recipientPublicKey }) {
|
|
6402
|
+
return resolveRelayIdentity({ relayIdentity, store: relayIdentityStore }).andThen(
|
|
6403
|
+
(senderIdentity) => encryptPaymentAddress({
|
|
6404
|
+
paymentAddress,
|
|
6405
|
+
recipientPublicKey,
|
|
6406
|
+
senderIdentity
|
|
6407
|
+
})
|
|
6408
|
+
);
|
|
4602
6409
|
}
|
|
4603
6410
|
};
|
|
4604
6411
|
}
|
|
4605
6412
|
|
|
6413
|
+
// src/prices/client.ts
|
|
6414
|
+
function createPrices(config) {
|
|
6415
|
+
const { publicClient, diamondAddress } = config;
|
|
6416
|
+
return {
|
|
6417
|
+
getPriceConfig: (params) => getPriceConfig(publicClient, diamondAddress, params),
|
|
6418
|
+
getReputationPerUsdcLimit: (params) => getReputationPerUsdcLimit(publicClient, diamondAddress, params)
|
|
6419
|
+
};
|
|
6420
|
+
}
|
|
6421
|
+
|
|
4606
6422
|
// src/profile/contracts/actions.ts
|
|
4607
|
-
var
|
|
4608
|
-
var
|
|
6423
|
+
var import_neverthrow18 = require("neverthrow");
|
|
6424
|
+
var import_viem18 = require("viem");
|
|
4609
6425
|
function getBalances(publicClient, usdcAddress, diamondAddress, params) {
|
|
4610
6426
|
return validate(
|
|
4611
6427
|
ZodGetBalancesParamsSchema,
|
|
@@ -4616,16 +6432,22 @@ function getBalances(publicClient, usdcAddress, diamondAddress, params) {
|
|
|
4616
6432
|
context: { params: data }
|
|
4617
6433
|
})
|
|
4618
6434
|
).asyncAndThen(
|
|
4619
|
-
(validated) =>
|
|
6435
|
+
(validated) => import_neverthrow18.ResultAsync.combine([
|
|
4620
6436
|
getUsdcBalance(publicClient, usdcAddress, {
|
|
4621
6437
|
address: validated.address
|
|
4622
6438
|
}),
|
|
4623
6439
|
getPriceConfig(publicClient, diamondAddress, {
|
|
4624
6440
|
currency: validated.currency
|
|
4625
|
-
})
|
|
6441
|
+
}).mapErr(
|
|
6442
|
+
(cause) => new ProfileError("Failed to read price config for balance conversion", {
|
|
6443
|
+
code: "CONTRACT_READ_ERROR",
|
|
6444
|
+
cause,
|
|
6445
|
+
context: { currency: validated.currency }
|
|
6446
|
+
})
|
|
6447
|
+
)
|
|
4626
6448
|
]).map(([usdc, priceConfig]) => {
|
|
4627
|
-
const usdcFormatted = Number((0,
|
|
4628
|
-
const sellPriceFormatted = Number((0,
|
|
6449
|
+
const usdcFormatted = Number((0, import_viem18.formatUnits)(usdc, 6));
|
|
6450
|
+
const sellPriceFormatted = Number((0, import_viem18.formatUnits)(priceConfig.sellPrice, 6));
|
|
4629
6451
|
return {
|
|
4630
6452
|
usdc: usdcFormatted,
|
|
4631
6453
|
fiat: usdcFormatted * sellPriceFormatted,
|
|
@@ -4640,10 +6462,9 @@ function createProfile(config) {
|
|
|
4640
6462
|
const { publicClient, diamondAddress, usdcAddress } = config;
|
|
4641
6463
|
return {
|
|
4642
6464
|
getUsdcBalance: (params) => getUsdcBalance(publicClient, usdcAddress, params),
|
|
4643
|
-
|
|
6465
|
+
getUsdcAllowance: (params) => getUsdcAllowance(publicClient, usdcAddress, diamondAddress, params),
|
|
4644
6466
|
getBalances: (params) => getBalances(publicClient, usdcAddress, diamondAddress, params),
|
|
4645
|
-
getTxLimits: (params) => getTxLimits(publicClient, diamondAddress, params)
|
|
4646
|
-
getRpPerUsdtLimitRational: (params) => getRpPerUsdtLimitRational(publicClient, diamondAddress, params)
|
|
6467
|
+
getTxLimits: (params) => getTxLimits(publicClient, diamondAddress, params)
|
|
4647
6468
|
};
|
|
4648
6469
|
}
|
|
4649
6470
|
|
|
@@ -4684,21 +6505,28 @@ function SdkProvider({ children, ...config }) {
|
|
|
4684
6505
|
initedRef.current = fraudEngine;
|
|
4685
6506
|
fraudEngine.init();
|
|
4686
6507
|
}, [fraudEngine]);
|
|
6508
|
+
const relayIdentityStore = config.orders?.relayIdentityStore;
|
|
6509
|
+
const relayIdentity = config.orders?.relayIdentity;
|
|
4687
6510
|
const sdk = (0, import_react.useMemo)(() => {
|
|
4688
|
-
const orderRouter = createOrderRouter({
|
|
4689
|
-
publicClient,
|
|
4690
|
-
subgraphUrl: config.subgraphUrl,
|
|
4691
|
-
contractAddress: config.diamondAddress,
|
|
4692
|
-
logger
|
|
4693
|
-
});
|
|
4694
6511
|
return {
|
|
4695
6512
|
profile: createProfile({
|
|
4696
6513
|
publicClient,
|
|
4697
6514
|
diamondAddress: config.diamondAddress,
|
|
4698
6515
|
usdcAddress: config.usdcAddress
|
|
4699
6516
|
}),
|
|
4700
|
-
|
|
4701
|
-
|
|
6517
|
+
prices: createPrices({
|
|
6518
|
+
publicClient,
|
|
6519
|
+
diamondAddress: config.diamondAddress
|
|
6520
|
+
}),
|
|
6521
|
+
orders: createOrders({
|
|
6522
|
+
publicClient,
|
|
6523
|
+
diamondAddress: config.diamondAddress,
|
|
6524
|
+
usdcAddress: config.usdcAddress,
|
|
6525
|
+
subgraphUrl: config.subgraphUrl,
|
|
6526
|
+
relayIdentityStore,
|
|
6527
|
+
relayIdentity,
|
|
6528
|
+
logger
|
|
6529
|
+
}),
|
|
4702
6530
|
zkkyc: config.reputationManagerAddress ? createZkkyc({
|
|
4703
6531
|
reputationManagerAddress: config.reputationManagerAddress
|
|
4704
6532
|
}) : void 0,
|
|
@@ -4710,6 +6538,8 @@ function SdkProvider({ children, ...config }) {
|
|
|
4710
6538
|
config.diamondAddress,
|
|
4711
6539
|
config.usdcAddress,
|
|
4712
6540
|
config.reputationManagerAddress,
|
|
6541
|
+
relayIdentityStore,
|
|
6542
|
+
relayIdentity,
|
|
4713
6543
|
logger,
|
|
4714
6544
|
fraudEngine
|
|
4715
6545
|
]);
|
|
@@ -4725,11 +6555,11 @@ function useSdk() {
|
|
|
4725
6555
|
function useProfile() {
|
|
4726
6556
|
return useSdk().profile;
|
|
4727
6557
|
}
|
|
4728
|
-
function
|
|
4729
|
-
return useSdk().
|
|
6558
|
+
function usePrices() {
|
|
6559
|
+
return useSdk().prices;
|
|
4730
6560
|
}
|
|
4731
|
-
function
|
|
4732
|
-
return useSdk().
|
|
6561
|
+
function useOrders() {
|
|
6562
|
+
return useSdk().orders;
|
|
4733
6563
|
}
|
|
4734
6564
|
function useZkkyc() {
|
|
4735
6565
|
const zkkyc = useSdk().zkkyc;
|
|
@@ -4746,13 +6576,32 @@ function useFraudEngine() {
|
|
|
4746
6576
|
return fraudEngine;
|
|
4747
6577
|
}
|
|
4748
6578
|
|
|
4749
|
-
// src/
|
|
6579
|
+
// src/react/use-watch-orders.ts
|
|
4750
6580
|
var import_react2 = require("react");
|
|
4751
|
-
function
|
|
4752
|
-
const
|
|
4753
|
-
const
|
|
4754
|
-
const
|
|
6581
|
+
function useWatchOrders(params) {
|
|
6582
|
+
const orders = useOrders();
|
|
6583
|
+
const { user, onEvent, onError } = params;
|
|
6584
|
+
const onEventRef = (0, import_react2.useRef)(onEvent);
|
|
6585
|
+
const onErrorRef = (0, import_react2.useRef)(onError);
|
|
6586
|
+
onEventRef.current = onEvent;
|
|
6587
|
+
onErrorRef.current = onError;
|
|
4755
6588
|
(0, import_react2.useEffect)(() => {
|
|
6589
|
+
const unsubscribe = orders.watchEvents({
|
|
6590
|
+
user,
|
|
6591
|
+
onEvent: (event) => onEventRef.current(event),
|
|
6592
|
+
onError: (error) => onErrorRef.current?.(error)
|
|
6593
|
+
});
|
|
6594
|
+
return unsubscribe;
|
|
6595
|
+
}, [orders, user]);
|
|
6596
|
+
}
|
|
6597
|
+
|
|
6598
|
+
// src/fraud-engine/react/use-fingerprint.ts
|
|
6599
|
+
var import_react3 = require("react");
|
|
6600
|
+
function useFingerprint(enabled) {
|
|
6601
|
+
const [data, setData] = (0, import_react3.useState)(null);
|
|
6602
|
+
const [error, setError] = (0, import_react3.useState)(null);
|
|
6603
|
+
const [isLoading, setIsLoading] = (0, import_react3.useState)(false);
|
|
6604
|
+
(0, import_react3.useEffect)(() => {
|
|
4756
6605
|
if (!enabled) return;
|
|
4757
6606
|
let cancelled = false;
|
|
4758
6607
|
setIsLoading(true);
|
|
@@ -4784,10 +6633,11 @@ function useFingerprint(enabled) {
|
|
|
4784
6633
|
SdkProvider,
|
|
4785
6634
|
useFingerprint,
|
|
4786
6635
|
useFraudEngine,
|
|
4787
|
-
|
|
4788
|
-
|
|
6636
|
+
useOrders,
|
|
6637
|
+
usePrices,
|
|
4789
6638
|
useProfile,
|
|
4790
6639
|
useSdk,
|
|
6640
|
+
useWatchOrders,
|
|
4791
6641
|
useZkkyc
|
|
4792
6642
|
});
|
|
4793
6643
|
/*! Bundled license information:
|