@usdctofiat/offramp 1.0.1 → 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 +38 -10
- package/dist/{chunk-2UENKRGX.js → chunk-2XJXFOPJ.js} +784 -125
- package/dist/chunk-2XJXFOPJ.js.map +1 -0
- package/dist/{errors-A8NBr_Iw.d.cts → errors-Dtzrl98J.d.cts} +5 -1
- package/dist/{errors-A8NBr_Iw.d.ts → errors-Dtzrl98J.d.ts} +5 -1
- package/dist/index.cjs +714 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -3
- package/dist/index.d.ts +36 -3
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +688 -46
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +5 -2
- package/dist/react.js.map +1 -1
- package/package.json +30 -13
- package/dist/chunk-2UENKRGX.js.map +0 -1
package/dist/react.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/react.ts
|
|
@@ -28,7 +38,7 @@ module.exports = __toCommonJS(react_exports);
|
|
|
28
38
|
var import_react = require("react");
|
|
29
39
|
|
|
30
40
|
// src/deposit.ts
|
|
31
|
-
var
|
|
41
|
+
var import_viem3 = require("viem");
|
|
32
42
|
var import_chains = require("viem/chains");
|
|
33
43
|
var import_sdk4 = require("@zkp2p/sdk");
|
|
34
44
|
|
|
@@ -43,7 +53,10 @@ var addresses = contracts.addresses;
|
|
|
43
53
|
var addrs = addresses;
|
|
44
54
|
var USDC_ADDRESS = addrs.token || "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913";
|
|
45
55
|
var ESCROW_ADDRESS = addrs.escrowV2 || addrs.escrow || "";
|
|
46
|
-
var GATING_SERVICE_ADDRESS = (0, import_sdk.getGatingServiceAddress)(
|
|
56
|
+
var GATING_SERVICE_ADDRESS = (0, import_sdk.getGatingServiceAddress)(
|
|
57
|
+
BASE_CHAIN_ID,
|
|
58
|
+
RUNTIME_ENV
|
|
59
|
+
);
|
|
47
60
|
var DELEGATE_RATE_MANAGER_ID = "0x8666d6fb0f6797c56e95339fd7ca82fdd348b9db200e10a4c4aa0a0b879fc41c";
|
|
48
61
|
var RATE_MANAGER_REGISTRY_ADDRESS = "0xeed7db23e724ac4590d6db6f78fda6db203535f3";
|
|
49
62
|
var REFERRER = "galleonlabs";
|
|
@@ -63,8 +76,64 @@ var FALLBACK_CURRENCIES = {
|
|
|
63
76
|
venmo: ["USD"],
|
|
64
77
|
cashapp: ["USD"],
|
|
65
78
|
chime: ["USD"],
|
|
66
|
-
revolut: [
|
|
67
|
-
|
|
79
|
+
revolut: [
|
|
80
|
+
"USD",
|
|
81
|
+
"EUR",
|
|
82
|
+
"GBP",
|
|
83
|
+
"SGD",
|
|
84
|
+
"NZD",
|
|
85
|
+
"AUD",
|
|
86
|
+
"CAD",
|
|
87
|
+
"HKD",
|
|
88
|
+
"MXN",
|
|
89
|
+
"SAR",
|
|
90
|
+
"AED",
|
|
91
|
+
"THB",
|
|
92
|
+
"TRY",
|
|
93
|
+
"PLN",
|
|
94
|
+
"CHF",
|
|
95
|
+
"ZAR",
|
|
96
|
+
"CZK",
|
|
97
|
+
"CNY",
|
|
98
|
+
"DKK",
|
|
99
|
+
"HUF",
|
|
100
|
+
"NOK",
|
|
101
|
+
"RON",
|
|
102
|
+
"SEK"
|
|
103
|
+
],
|
|
104
|
+
wise: [
|
|
105
|
+
"USD",
|
|
106
|
+
"CNY",
|
|
107
|
+
"EUR",
|
|
108
|
+
"GBP",
|
|
109
|
+
"AUD",
|
|
110
|
+
"NZD",
|
|
111
|
+
"CAD",
|
|
112
|
+
"AED",
|
|
113
|
+
"CHF",
|
|
114
|
+
"ZAR",
|
|
115
|
+
"SGD",
|
|
116
|
+
"ILS",
|
|
117
|
+
"HKD",
|
|
118
|
+
"JPY",
|
|
119
|
+
"PLN",
|
|
120
|
+
"TRY",
|
|
121
|
+
"IDR",
|
|
122
|
+
"KES",
|
|
123
|
+
"MYR",
|
|
124
|
+
"MXN",
|
|
125
|
+
"THB",
|
|
126
|
+
"VND",
|
|
127
|
+
"UGX",
|
|
128
|
+
"CZK",
|
|
129
|
+
"DKK",
|
|
130
|
+
"HUF",
|
|
131
|
+
"INR",
|
|
132
|
+
"NOK",
|
|
133
|
+
"PHP",
|
|
134
|
+
"RON",
|
|
135
|
+
"SEK"
|
|
136
|
+
],
|
|
68
137
|
mercadopago: ["ARS"],
|
|
69
138
|
zelle: ["USD"],
|
|
70
139
|
paypal: ["USD", "EUR", "GBP", "SGD", "NZD", "AUD", "CAD"],
|
|
@@ -91,19 +160,95 @@ function resolveSupportedCurrencies(platform) {
|
|
|
91
160
|
return Array.from(codes).sort();
|
|
92
161
|
}
|
|
93
162
|
var BLUEPRINTS = {
|
|
94
|
-
venmo: {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
163
|
+
venmo: {
|
|
164
|
+
id: "venmo",
|
|
165
|
+
name: "Venmo",
|
|
166
|
+
identifierLabel: "Username",
|
|
167
|
+
placeholder: "venmo username (no @)",
|
|
168
|
+
helperText: "Username without @ (publicly discoverable)",
|
|
169
|
+
validation: import_zod.z.string().min(1).regex(/^[a-zA-Z0-9_-]+$/),
|
|
170
|
+
transform: (v) => v.replace(/^@+/, "")
|
|
171
|
+
},
|
|
172
|
+
cashapp: {
|
|
173
|
+
id: "cashapp",
|
|
174
|
+
name: "Cash App",
|
|
175
|
+
identifierLabel: "Cashtag",
|
|
176
|
+
placeholder: "cashtag (no $)",
|
|
177
|
+
helperText: "Cashtag without $ (publicly discoverable)",
|
|
178
|
+
validation: import_zod.z.string().min(1).regex(/^[a-zA-Z0-9]+$/),
|
|
179
|
+
transform: (v) => v.replace(/^\$+/, "")
|
|
180
|
+
},
|
|
181
|
+
chime: {
|
|
182
|
+
id: "chime",
|
|
183
|
+
name: "Chime",
|
|
184
|
+
identifierLabel: "ChimeSign",
|
|
185
|
+
placeholder: "$chimesign",
|
|
186
|
+
helperText: "ChimeSign with $ (must be discoverable)",
|
|
187
|
+
validation: import_zod.z.string().min(2).regex(/^\$[a-zA-Z0-9]+$/),
|
|
188
|
+
transform: (v) => {
|
|
189
|
+
const t = v.trim().toLowerCase();
|
|
190
|
+
return t.startsWith("$") ? t : `$${t}`;
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
revolut: {
|
|
194
|
+
id: "revolut",
|
|
195
|
+
name: "Revolut",
|
|
196
|
+
identifierLabel: "Revtag",
|
|
197
|
+
placeholder: "revtag (no @)",
|
|
198
|
+
helperText: "Revtag without @ (must be public)",
|
|
199
|
+
validation: import_zod.z.string().min(1).regex(/^[a-zA-Z0-9]+$/),
|
|
200
|
+
transform: (v) => v.replace(/^@+/, "").trim()
|
|
201
|
+
},
|
|
202
|
+
wise: {
|
|
203
|
+
id: "wise",
|
|
204
|
+
name: "Wise",
|
|
205
|
+
identifierLabel: "Wisetag",
|
|
206
|
+
placeholder: "wisetag (no @)",
|
|
207
|
+
helperText: "Your Wise @wisetag (no @)",
|
|
208
|
+
validation: import_zod.z.string().min(1).regex(/^[a-zA-Z0-9_-]+$/),
|
|
209
|
+
transform: (v) => v.replace(/^@+/, "").trim()
|
|
210
|
+
},
|
|
211
|
+
mercadopago: {
|
|
212
|
+
id: "mercadopago",
|
|
213
|
+
name: "Mercado Pago",
|
|
214
|
+
identifierLabel: "CVU",
|
|
215
|
+
placeholder: "22-digit CVU",
|
|
216
|
+
helperText: "CVU must be exactly 22 digits",
|
|
217
|
+
validation: import_zod.z.string().length(22).regex(/^\d{22}$/)
|
|
218
|
+
},
|
|
219
|
+
zelle: {
|
|
220
|
+
id: "zelle",
|
|
221
|
+
name: "Zelle",
|
|
222
|
+
identifierLabel: "Email",
|
|
223
|
+
placeholder: "email",
|
|
224
|
+
helperText: "Registered Zelle email",
|
|
225
|
+
validation: import_zod.z.string().email()
|
|
226
|
+
},
|
|
227
|
+
paypal: {
|
|
228
|
+
id: "paypal",
|
|
229
|
+
name: "PayPal",
|
|
230
|
+
identifierLabel: "Email",
|
|
231
|
+
placeholder: "email",
|
|
232
|
+
helperText: "Email linked to PayPal account",
|
|
233
|
+
validation: import_zod.z.string().email()
|
|
234
|
+
},
|
|
235
|
+
monzo: {
|
|
236
|
+
id: "monzo",
|
|
237
|
+
name: "Monzo",
|
|
238
|
+
identifierLabel: "Username",
|
|
239
|
+
placeholder: "monzo.me username",
|
|
240
|
+
helperText: "Your Monzo.me username",
|
|
241
|
+
validation: import_zod.z.string().min(1).regex(/^[a-zA-Z0-9_-]+$/)
|
|
242
|
+
},
|
|
243
|
+
n26: {
|
|
244
|
+
id: "n26",
|
|
245
|
+
name: "N26",
|
|
246
|
+
identifierLabel: "IBAN",
|
|
247
|
+
placeholder: "IBAN (e.g. DE89...)",
|
|
248
|
+
helperText: "Your IBAN (spaces will be removed)",
|
|
249
|
+
validation: import_zod.z.string().min(15).max(34).regex(/^[A-Z]{2}[0-9]{2}[A-Z0-9]+$/i),
|
|
250
|
+
transform: (v) => v.replace(/\s/g, "").toUpperCase()
|
|
251
|
+
}
|
|
107
252
|
};
|
|
108
253
|
function buildPlatformEntry(bp) {
|
|
109
254
|
const currencies = resolveSupportedCurrencies(bp.id);
|
|
@@ -120,7 +265,11 @@ function buildPlatformEntry(bp) {
|
|
|
120
265
|
const transformed = bp.transform ? bp.transform(input) : input;
|
|
121
266
|
const result = bp.validation.safeParse(transformed);
|
|
122
267
|
if (!result.success) {
|
|
123
|
-
return {
|
|
268
|
+
return {
|
|
269
|
+
valid: false,
|
|
270
|
+
normalized: transformed,
|
|
271
|
+
error: result.error.issues[0]?.message || "Invalid input"
|
|
272
|
+
};
|
|
124
273
|
}
|
|
125
274
|
return { valid: true, normalized: transformed };
|
|
126
275
|
}
|
|
@@ -231,8 +380,434 @@ function isUserCancellation(error) {
|
|
|
231
380
|
return msg.includes("user rejected") || msg.includes("user denied") || msg.includes("user cancelled") || msg.includes("rejected the request") || msg.includes("action_rejected");
|
|
232
381
|
}
|
|
233
382
|
|
|
234
|
-
// src/
|
|
383
|
+
// src/otc.ts
|
|
235
384
|
var import_viem = require("viem");
|
|
385
|
+
|
|
386
|
+
// ../../node_modules/@zkp2p/contracts-v2/abis/base/WhitelistPreIntentHook.json
|
|
387
|
+
var WhitelistPreIntentHook_default = [
|
|
388
|
+
{
|
|
389
|
+
inputs: [
|
|
390
|
+
{
|
|
391
|
+
internalType: "address",
|
|
392
|
+
name: "_orchestratorRegistry",
|
|
393
|
+
type: "address"
|
|
394
|
+
}
|
|
395
|
+
],
|
|
396
|
+
stateMutability: "nonpayable",
|
|
397
|
+
type: "constructor"
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
inputs: [],
|
|
401
|
+
name: "EmptyArray",
|
|
402
|
+
type: "error"
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
inputs: [
|
|
406
|
+
{
|
|
407
|
+
internalType: "address",
|
|
408
|
+
name: "taker",
|
|
409
|
+
type: "address"
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
internalType: "address",
|
|
413
|
+
name: "escrow",
|
|
414
|
+
type: "address"
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
internalType: "uint256",
|
|
418
|
+
name: "depositId",
|
|
419
|
+
type: "uint256"
|
|
420
|
+
}
|
|
421
|
+
],
|
|
422
|
+
name: "TakerNotInWhitelist",
|
|
423
|
+
type: "error"
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
inputs: [
|
|
427
|
+
{
|
|
428
|
+
internalType: "address",
|
|
429
|
+
name: "taker",
|
|
430
|
+
type: "address"
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
internalType: "address",
|
|
434
|
+
name: "escrow",
|
|
435
|
+
type: "address"
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
internalType: "uint256",
|
|
439
|
+
name: "depositId",
|
|
440
|
+
type: "uint256"
|
|
441
|
+
}
|
|
442
|
+
],
|
|
443
|
+
name: "TakerNotWhitelisted",
|
|
444
|
+
type: "error"
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
inputs: [
|
|
448
|
+
{
|
|
449
|
+
internalType: "address",
|
|
450
|
+
name: "caller",
|
|
451
|
+
type: "address"
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
internalType: "address",
|
|
455
|
+
name: "owner",
|
|
456
|
+
type: "address"
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
internalType: "address",
|
|
460
|
+
name: "delegate",
|
|
461
|
+
type: "address"
|
|
462
|
+
}
|
|
463
|
+
],
|
|
464
|
+
name: "UnauthorizedCallerOrDelegate",
|
|
465
|
+
type: "error"
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
inputs: [
|
|
469
|
+
{
|
|
470
|
+
internalType: "address",
|
|
471
|
+
name: "caller",
|
|
472
|
+
type: "address"
|
|
473
|
+
}
|
|
474
|
+
],
|
|
475
|
+
name: "UnauthorizedOrchestratorCaller",
|
|
476
|
+
type: "error"
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
inputs: [],
|
|
480
|
+
name: "ZeroAddress",
|
|
481
|
+
type: "error"
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
anonymous: false,
|
|
485
|
+
inputs: [
|
|
486
|
+
{
|
|
487
|
+
indexed: true,
|
|
488
|
+
internalType: "address",
|
|
489
|
+
name: "escrow",
|
|
490
|
+
type: "address"
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
indexed: true,
|
|
494
|
+
internalType: "uint256",
|
|
495
|
+
name: "depositId",
|
|
496
|
+
type: "uint256"
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
indexed: true,
|
|
500
|
+
internalType: "address",
|
|
501
|
+
name: "taker",
|
|
502
|
+
type: "address"
|
|
503
|
+
}
|
|
504
|
+
],
|
|
505
|
+
name: "TakerRemovedFromWhitelist",
|
|
506
|
+
type: "event"
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
anonymous: false,
|
|
510
|
+
inputs: [
|
|
511
|
+
{
|
|
512
|
+
indexed: true,
|
|
513
|
+
internalType: "address",
|
|
514
|
+
name: "escrow",
|
|
515
|
+
type: "address"
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
indexed: true,
|
|
519
|
+
internalType: "uint256",
|
|
520
|
+
name: "depositId",
|
|
521
|
+
type: "uint256"
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
indexed: true,
|
|
525
|
+
internalType: "address",
|
|
526
|
+
name: "taker",
|
|
527
|
+
type: "address"
|
|
528
|
+
}
|
|
529
|
+
],
|
|
530
|
+
name: "TakerWhitelisted",
|
|
531
|
+
type: "event"
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
inputs: [
|
|
535
|
+
{
|
|
536
|
+
internalType: "address",
|
|
537
|
+
name: "_escrow",
|
|
538
|
+
type: "address"
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
internalType: "uint256",
|
|
542
|
+
name: "_depositId",
|
|
543
|
+
type: "uint256"
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
internalType: "address[]",
|
|
547
|
+
name: "_takers",
|
|
548
|
+
type: "address[]"
|
|
549
|
+
}
|
|
550
|
+
],
|
|
551
|
+
name: "addToWhitelist",
|
|
552
|
+
outputs: [],
|
|
553
|
+
stateMutability: "nonpayable",
|
|
554
|
+
type: "function"
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
inputs: [
|
|
558
|
+
{
|
|
559
|
+
internalType: "address",
|
|
560
|
+
name: "_escrow",
|
|
561
|
+
type: "address"
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
internalType: "uint256",
|
|
565
|
+
name: "_depositId",
|
|
566
|
+
type: "uint256"
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
internalType: "address",
|
|
570
|
+
name: "_taker",
|
|
571
|
+
type: "address"
|
|
572
|
+
}
|
|
573
|
+
],
|
|
574
|
+
name: "isWhitelisted",
|
|
575
|
+
outputs: [
|
|
576
|
+
{
|
|
577
|
+
internalType: "bool",
|
|
578
|
+
name: "",
|
|
579
|
+
type: "bool"
|
|
580
|
+
}
|
|
581
|
+
],
|
|
582
|
+
stateMutability: "view",
|
|
583
|
+
type: "function"
|
|
584
|
+
},
|
|
585
|
+
{
|
|
586
|
+
inputs: [],
|
|
587
|
+
name: "orchestratorRegistry",
|
|
588
|
+
outputs: [
|
|
589
|
+
{
|
|
590
|
+
internalType: "contract IOrchestratorRegistry",
|
|
591
|
+
name: "",
|
|
592
|
+
type: "address"
|
|
593
|
+
}
|
|
594
|
+
],
|
|
595
|
+
stateMutability: "view",
|
|
596
|
+
type: "function"
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
inputs: [
|
|
600
|
+
{
|
|
601
|
+
internalType: "address",
|
|
602
|
+
name: "_escrow",
|
|
603
|
+
type: "address"
|
|
604
|
+
},
|
|
605
|
+
{
|
|
606
|
+
internalType: "uint256",
|
|
607
|
+
name: "_depositId",
|
|
608
|
+
type: "uint256"
|
|
609
|
+
},
|
|
610
|
+
{
|
|
611
|
+
internalType: "address[]",
|
|
612
|
+
name: "_takers",
|
|
613
|
+
type: "address[]"
|
|
614
|
+
}
|
|
615
|
+
],
|
|
616
|
+
name: "removeFromWhitelist",
|
|
617
|
+
outputs: [],
|
|
618
|
+
stateMutability: "nonpayable",
|
|
619
|
+
type: "function"
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
inputs: [
|
|
623
|
+
{
|
|
624
|
+
components: [
|
|
625
|
+
{
|
|
626
|
+
internalType: "address",
|
|
627
|
+
name: "taker",
|
|
628
|
+
type: "address"
|
|
629
|
+
},
|
|
630
|
+
{
|
|
631
|
+
internalType: "address",
|
|
632
|
+
name: "escrow",
|
|
633
|
+
type: "address"
|
|
634
|
+
},
|
|
635
|
+
{
|
|
636
|
+
internalType: "uint256",
|
|
637
|
+
name: "depositId",
|
|
638
|
+
type: "uint256"
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
internalType: "uint256",
|
|
642
|
+
name: "amount",
|
|
643
|
+
type: "uint256"
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
internalType: "address",
|
|
647
|
+
name: "to",
|
|
648
|
+
type: "address"
|
|
649
|
+
},
|
|
650
|
+
{
|
|
651
|
+
internalType: "bytes32",
|
|
652
|
+
name: "paymentMethod",
|
|
653
|
+
type: "bytes32"
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
internalType: "bytes32",
|
|
657
|
+
name: "fiatCurrency",
|
|
658
|
+
type: "bytes32"
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
internalType: "uint256",
|
|
662
|
+
name: "conversionRate",
|
|
663
|
+
type: "uint256"
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
internalType: "address",
|
|
667
|
+
name: "referrer",
|
|
668
|
+
type: "address"
|
|
669
|
+
},
|
|
670
|
+
{
|
|
671
|
+
internalType: "uint256",
|
|
672
|
+
name: "referrerFee",
|
|
673
|
+
type: "uint256"
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
internalType: "bytes",
|
|
677
|
+
name: "preIntentHookData",
|
|
678
|
+
type: "bytes"
|
|
679
|
+
}
|
|
680
|
+
],
|
|
681
|
+
internalType: "struct IPreIntentHook.PreIntentContext",
|
|
682
|
+
name: "_ctx",
|
|
683
|
+
type: "tuple"
|
|
684
|
+
}
|
|
685
|
+
],
|
|
686
|
+
name: "validateSignalIntent",
|
|
687
|
+
outputs: [],
|
|
688
|
+
stateMutability: "view",
|
|
689
|
+
type: "function"
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
inputs: [
|
|
693
|
+
{
|
|
694
|
+
internalType: "address",
|
|
695
|
+
name: "",
|
|
696
|
+
type: "address"
|
|
697
|
+
},
|
|
698
|
+
{
|
|
699
|
+
internalType: "uint256",
|
|
700
|
+
name: "",
|
|
701
|
+
type: "uint256"
|
|
702
|
+
},
|
|
703
|
+
{
|
|
704
|
+
internalType: "address",
|
|
705
|
+
name: "",
|
|
706
|
+
type: "address"
|
|
707
|
+
}
|
|
708
|
+
],
|
|
709
|
+
name: "whitelist",
|
|
710
|
+
outputs: [
|
|
711
|
+
{
|
|
712
|
+
internalType: "bool",
|
|
713
|
+
name: "",
|
|
714
|
+
type: "bool"
|
|
715
|
+
}
|
|
716
|
+
],
|
|
717
|
+
stateMutability: "view",
|
|
718
|
+
type: "function"
|
|
719
|
+
}
|
|
720
|
+
];
|
|
721
|
+
|
|
722
|
+
// src/otc.ts
|
|
723
|
+
var WHITELIST_HOOK_ADDRESS = "0xda023Ea0d789A41BcF5866F7B6BBd2CaDF9b79B8";
|
|
724
|
+
var OTC_BASE_URL = "https://usdctofiat.xyz";
|
|
725
|
+
async function enableOtc(walletClient, depositId, takerAddress, escrowAddress) {
|
|
726
|
+
if (!(0, import_viem.isAddress)(takerAddress)) {
|
|
727
|
+
throw new OfframpError("Invalid taker address", "VALIDATION");
|
|
728
|
+
}
|
|
729
|
+
const escrow = escrowAddress || ESCROW_ADDRESS;
|
|
730
|
+
const taker = takerAddress;
|
|
731
|
+
const depositIdBig = BigInt(depositId);
|
|
732
|
+
const client = createSdkClient(walletClient);
|
|
733
|
+
const txOverrides = { referrer: [REFERRER] };
|
|
734
|
+
try {
|
|
735
|
+
const currentHook = await client.getDepositWhitelistHook(depositIdBig, {
|
|
736
|
+
escrowAddress: escrow
|
|
737
|
+
});
|
|
738
|
+
if (currentHook !== import_viem.zeroAddress) {
|
|
739
|
+
const isAlready = await readIsWhitelisted(
|
|
740
|
+
walletClient,
|
|
741
|
+
escrow,
|
|
742
|
+
depositIdBig,
|
|
743
|
+
taker
|
|
744
|
+
);
|
|
745
|
+
if (isAlready) {
|
|
746
|
+
return {
|
|
747
|
+
depositId,
|
|
748
|
+
takerAddress: taker,
|
|
749
|
+
otcLink: getOtcLink(depositId, escrow)
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
await writeContract(walletClient, "addToWhitelist", [escrow, depositIdBig, [taker]]);
|
|
754
|
+
if (currentHook === import_viem.zeroAddress) {
|
|
755
|
+
await client.setDepositWhitelistHook({
|
|
756
|
+
depositId: depositIdBig,
|
|
757
|
+
whitelistHook: WHITELIST_HOOK_ADDRESS,
|
|
758
|
+
escrowAddress: escrow,
|
|
759
|
+
txOverrides
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
return {
|
|
763
|
+
depositId,
|
|
764
|
+
takerAddress: taker,
|
|
765
|
+
otcLink: getOtcLink(depositId, escrow)
|
|
766
|
+
};
|
|
767
|
+
} catch (err) {
|
|
768
|
+
if (err instanceof OfframpError) throw err;
|
|
769
|
+
if (isUserCancellation(err)) {
|
|
770
|
+
throw new OfframpError("User cancelled", "USER_CANCELLED", void 0, err, { depositId });
|
|
771
|
+
}
|
|
772
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
773
|
+
throw new OfframpError(`Failed to enable OTC: ${detail}`, "DEPOSIT_FAILED", void 0, err, {
|
|
774
|
+
depositId
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
function getOtcLink(depositId, escrowAddress) {
|
|
779
|
+
const escrow = escrowAddress || ESCROW_ADDRESS;
|
|
780
|
+
return `${OTC_BASE_URL}/deposit/${escrow}/${depositId}`;
|
|
781
|
+
}
|
|
782
|
+
async function writeContract(walletClient, functionName, args) {
|
|
783
|
+
const wc = walletClient;
|
|
784
|
+
if (typeof wc.writeContract !== "function") {
|
|
785
|
+
throw new OfframpError("Wallet client does not support writeContract", "VALIDATION");
|
|
786
|
+
}
|
|
787
|
+
await wc.writeContract({
|
|
788
|
+
address: WHITELIST_HOOK_ADDRESS,
|
|
789
|
+
abi: WhitelistPreIntentHook_default,
|
|
790
|
+
functionName,
|
|
791
|
+
args
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
async function readIsWhitelisted(walletClient, escrow, depositId, taker) {
|
|
795
|
+
const { createPublicClient: createPublicClient2, http: http2 } = await import("viem");
|
|
796
|
+
const { base: base2 } = await import("viem/chains");
|
|
797
|
+
const publicClient = createPublicClient2({
|
|
798
|
+
chain: base2,
|
|
799
|
+
transport: http2("https://mainnet.base.org")
|
|
800
|
+
});
|
|
801
|
+
return publicClient.readContract({
|
|
802
|
+
address: WHITELIST_HOOK_ADDRESS,
|
|
803
|
+
abi: WhitelistPreIntentHook_default,
|
|
804
|
+
functionName: "isWhitelisted",
|
|
805
|
+
args: [escrow, depositId, taker]
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// src/queries.ts
|
|
810
|
+
var import_viem2 = require("viem");
|
|
236
811
|
var import_sdk3 = require("@zkp2p/sdk");
|
|
237
812
|
var indexerService = null;
|
|
238
813
|
function getIndexerService() {
|
|
@@ -251,7 +826,7 @@ function toBigInt(value) {
|
|
|
251
826
|
}
|
|
252
827
|
}
|
|
253
828
|
function toUsdc(value) {
|
|
254
|
-
return Number((0,
|
|
829
|
+
return Number((0, import_viem2.formatUnits)(toBigInt(value), 6));
|
|
255
830
|
}
|
|
256
831
|
function resolveStatus(deposit) {
|
|
257
832
|
if (deposit.status === "CLOSED") return "closed";
|
|
@@ -300,8 +875,10 @@ function mapDeposit(d) {
|
|
|
300
875
|
}
|
|
301
876
|
function extractTxHash(result) {
|
|
302
877
|
if (typeof result === "string") return result;
|
|
303
|
-
if (result && typeof result === "object" && "hash" in result)
|
|
304
|
-
|
|
878
|
+
if (result && typeof result === "object" && "hash" in result)
|
|
879
|
+
return result.hash;
|
|
880
|
+
if (result && typeof result === "object" && "transactionHash" in result)
|
|
881
|
+
return result.transactionHash;
|
|
305
882
|
throw new Error("Unexpected transaction result format");
|
|
306
883
|
}
|
|
307
884
|
async function deposits(walletAddress) {
|
|
@@ -329,7 +906,7 @@ async function close(walletClient, depositId, escrowAddress) {
|
|
|
329
906
|
|
|
330
907
|
// src/deposit.ts
|
|
331
908
|
function usdcToUnits(amount) {
|
|
332
|
-
return (0,
|
|
909
|
+
return (0, import_viem3.parseUnits)(amount, 6);
|
|
333
910
|
}
|
|
334
911
|
var DEPOSIT_RECEIVED_ABI = [
|
|
335
912
|
{
|
|
@@ -340,10 +917,15 @@ var DEPOSIT_RECEIVED_ABI = [
|
|
|
340
917
|
{ indexed: true, name: "depositor", type: "address" },
|
|
341
918
|
{ indexed: true, name: "token", type: "address" },
|
|
342
919
|
{ indexed: false, name: "amount", type: "uint256" },
|
|
343
|
-
{
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
920
|
+
{
|
|
921
|
+
indexed: false,
|
|
922
|
+
name: "intentAmountRange",
|
|
923
|
+
type: "tuple",
|
|
924
|
+
components: [
|
|
925
|
+
{ name: "min", type: "uint256" },
|
|
926
|
+
{ name: "max", type: "uint256" }
|
|
927
|
+
]
|
|
928
|
+
},
|
|
347
929
|
{ indexed: false, name: "delegate", type: "address" },
|
|
348
930
|
{ indexed: false, name: "intentGuardian", type: "address" }
|
|
349
931
|
]
|
|
@@ -353,7 +935,7 @@ function extractDepositIdFromLogs(logs) {
|
|
|
353
935
|
for (const log of logs) {
|
|
354
936
|
if (!log?.topics?.length || !log.data) continue;
|
|
355
937
|
try {
|
|
356
|
-
const decoded = (0,
|
|
938
|
+
const decoded = (0, import_viem3.decodeEventLog)({
|
|
357
939
|
abi: DEPOSIT_RECEIVED_ABI,
|
|
358
940
|
data: log.data,
|
|
359
941
|
topics: log.topics
|
|
@@ -411,8 +993,10 @@ function attachOracleConfig(entries, conversionRates) {
|
|
|
411
993
|
}
|
|
412
994
|
function extractTxHash2(result) {
|
|
413
995
|
if (typeof result === "string") return result;
|
|
414
|
-
if (result && typeof result === "object" && "hash" in result)
|
|
415
|
-
|
|
996
|
+
if (result && typeof result === "object" && "hash" in result)
|
|
997
|
+
return result.hash;
|
|
998
|
+
if (result && typeof result === "object" && "transactionHash" in result)
|
|
999
|
+
return result.transactionHash;
|
|
416
1000
|
throw new Error("Unexpected transaction result format");
|
|
417
1001
|
}
|
|
418
1002
|
function createSdkClient(walletClient) {
|
|
@@ -492,7 +1076,8 @@ async function offramp(walletClient, params, onProgress) {
|
|
|
492
1076
|
onProgress?.({ step: "done", txHash, depositId: existing.depositId });
|
|
493
1077
|
return { depositId: existing.depositId, txHash, resumed: true };
|
|
494
1078
|
} catch (err) {
|
|
495
|
-
if (isUserCancellation(err))
|
|
1079
|
+
if (isUserCancellation(err))
|
|
1080
|
+
throw new OfframpError("User cancelled", "USER_CANCELLED", "resuming", err);
|
|
496
1081
|
throw new OfframpError(
|
|
497
1082
|
"Found undelegated deposit but delegation failed. Try again.",
|
|
498
1083
|
"DELEGATION_FAILED",
|
|
@@ -507,16 +1092,27 @@ async function offramp(walletClient, params, onProgress) {
|
|
|
507
1092
|
const minUnits = usdcToUnits(String(MIN_ORDER_USDC));
|
|
508
1093
|
const maxUnits = usdcToUnits(String(Math.min(amt, 2500)));
|
|
509
1094
|
try {
|
|
510
|
-
const publicClient = (0,
|
|
1095
|
+
const publicClient = (0, import_viem3.createPublicClient)({ chain: import_chains.base, transport: (0, import_viem3.http)(BASE_RPC_URL) });
|
|
511
1096
|
const balance = await publicClient.readContract({
|
|
512
1097
|
address: USDC_ADDRESS,
|
|
513
|
-
abi: [
|
|
1098
|
+
abi: [
|
|
1099
|
+
{
|
|
1100
|
+
name: "balanceOf",
|
|
1101
|
+
type: "function",
|
|
1102
|
+
stateMutability: "view",
|
|
1103
|
+
inputs: [{ name: "account", type: "address" }],
|
|
1104
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
1105
|
+
}
|
|
1106
|
+
],
|
|
514
1107
|
functionName: "balanceOf",
|
|
515
1108
|
args: [walletAddress]
|
|
516
1109
|
});
|
|
517
1110
|
if (balance < amountUnits) {
|
|
518
|
-
const available = Number((0,
|
|
519
|
-
throw new OfframpError(
|
|
1111
|
+
const available = Number((0, import_viem3.formatUnits)(balance, 6));
|
|
1112
|
+
throw new OfframpError(
|
|
1113
|
+
`Insufficient USDC balance. Have ${available.toFixed(2)}, need ${truncatedAmount}.`,
|
|
1114
|
+
"VALIDATION"
|
|
1115
|
+
);
|
|
520
1116
|
}
|
|
521
1117
|
} catch (err) {
|
|
522
1118
|
if (err instanceof OfframpError) throw err;
|
|
@@ -533,7 +1129,8 @@ async function offramp(walletClient, params, onProgress) {
|
|
|
533
1129
|
txOverrides
|
|
534
1130
|
});
|
|
535
1131
|
} catch (err) {
|
|
536
|
-
if (isUserCancellation(err))
|
|
1132
|
+
if (isUserCancellation(err))
|
|
1133
|
+
throw new OfframpError("User cancelled", "USER_CANCELLED", "approving", err);
|
|
537
1134
|
const detail = err instanceof Error ? err.message : String(err);
|
|
538
1135
|
throw new OfframpError(`USDC approval failed: ${detail}`, "APPROVAL_FAILED", "approving", err);
|
|
539
1136
|
}
|
|
@@ -563,11 +1160,13 @@ async function offramp(walletClient, params, onProgress) {
|
|
|
563
1160
|
depositData: [buildDepositData(platformId, normalizedIdentifier)],
|
|
564
1161
|
conversionRates,
|
|
565
1162
|
paymentMethodsOverride: [methodHash],
|
|
566
|
-
paymentMethodDataOverride: [
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
1163
|
+
paymentMethodDataOverride: [
|
|
1164
|
+
{
|
|
1165
|
+
intentGatingService: GATING_SERVICE_ADDRESS,
|
|
1166
|
+
payeeDetails: hashedOnchainId,
|
|
1167
|
+
data: "0x"
|
|
1168
|
+
}
|
|
1169
|
+
],
|
|
571
1170
|
currenciesOverride,
|
|
572
1171
|
escrowAddress: ESCROW_ADDRESS,
|
|
573
1172
|
txOverrides
|
|
@@ -575,9 +1174,15 @@ async function offramp(walletClient, params, onProgress) {
|
|
|
575
1174
|
if (!result?.hash) throw new Error("No transaction hash returned");
|
|
576
1175
|
hash = result.hash;
|
|
577
1176
|
} catch (err) {
|
|
578
|
-
if (isUserCancellation(err))
|
|
1177
|
+
if (isUserCancellation(err))
|
|
1178
|
+
throw new OfframpError("User cancelled", "USER_CANCELLED", "depositing", err);
|
|
579
1179
|
const detail = err instanceof Error ? err.message : String(err);
|
|
580
|
-
throw new OfframpError(
|
|
1180
|
+
throw new OfframpError(
|
|
1181
|
+
`Deposit transaction failed: ${detail}`,
|
|
1182
|
+
"DEPOSIT_FAILED",
|
|
1183
|
+
"depositing",
|
|
1184
|
+
err
|
|
1185
|
+
);
|
|
581
1186
|
}
|
|
582
1187
|
onProgress?.({ step: "confirming", txHash: hash });
|
|
583
1188
|
let depositId = "";
|
|
@@ -628,7 +1233,13 @@ async function offramp(walletClient, params, onProgress) {
|
|
|
628
1233
|
});
|
|
629
1234
|
} catch (delegationError) {
|
|
630
1235
|
if (isUserCancellation(delegationError)) {
|
|
631
|
-
throw new OfframpError(
|
|
1236
|
+
throw new OfframpError(
|
|
1237
|
+
"User cancelled delegation",
|
|
1238
|
+
"USER_CANCELLED",
|
|
1239
|
+
"delegating",
|
|
1240
|
+
delegationError,
|
|
1241
|
+
{ txHash: hash, depositId }
|
|
1242
|
+
);
|
|
632
1243
|
}
|
|
633
1244
|
throw new OfframpError(
|
|
634
1245
|
"Deposit created but delegation failed. Call offramp() again to resume delegation.",
|
|
@@ -638,8 +1249,36 @@ async function offramp(walletClient, params, onProgress) {
|
|
|
638
1249
|
{ txHash: hash, depositId }
|
|
639
1250
|
);
|
|
640
1251
|
}
|
|
1252
|
+
let otcLink;
|
|
1253
|
+
if (params.otcTaker) {
|
|
1254
|
+
onProgress?.({ step: "restricting", txHash: hash, depositId });
|
|
1255
|
+
try {
|
|
1256
|
+
const otcResult = await enableOtc(walletClient, depositId, params.otcTaker);
|
|
1257
|
+
otcLink = otcResult.otcLink;
|
|
1258
|
+
} catch (otcError) {
|
|
1259
|
+
if (isUserCancellation(otcError)) {
|
|
1260
|
+
throw new OfframpError(
|
|
1261
|
+
"User cancelled OTC restriction",
|
|
1262
|
+
"USER_CANCELLED",
|
|
1263
|
+
"restricting",
|
|
1264
|
+
otcError,
|
|
1265
|
+
{
|
|
1266
|
+
txHash: hash,
|
|
1267
|
+
depositId
|
|
1268
|
+
}
|
|
1269
|
+
);
|
|
1270
|
+
}
|
|
1271
|
+
throw new OfframpError(
|
|
1272
|
+
"Deposit created and delegated but OTC restriction failed. Use enableOtc() to retry.",
|
|
1273
|
+
"DEPOSIT_FAILED",
|
|
1274
|
+
"restricting",
|
|
1275
|
+
otcError,
|
|
1276
|
+
{ txHash: hash, depositId }
|
|
1277
|
+
);
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
641
1280
|
onProgress?.({ step: "done", txHash: hash, depositId });
|
|
642
|
-
return { depositId, txHash: hash, resumed: false };
|
|
1281
|
+
return { depositId, txHash: hash, resumed: false, otcLink };
|
|
643
1282
|
}
|
|
644
1283
|
|
|
645
1284
|
// src/hooks/useOfframp.ts
|
|
@@ -677,7 +1316,10 @@ function useOfframp() {
|
|
|
677
1316
|
setTxHash(result.txHash);
|
|
678
1317
|
return result;
|
|
679
1318
|
} catch (err) {
|
|
680
|
-
const offrampError = err instanceof OfframpError ? err : new OfframpError(
|
|
1319
|
+
const offrampError = err instanceof OfframpError ? err : new OfframpError(
|
|
1320
|
+
err instanceof Error ? err.message : "Offramp failed",
|
|
1321
|
+
"DEPOSIT_FAILED"
|
|
1322
|
+
);
|
|
681
1323
|
setError(offrampError);
|
|
682
1324
|
throw err;
|
|
683
1325
|
} finally {
|