@chainrails/vanilla 0.0.2 → 0.0.4

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.
@@ -0,0 +1,2033 @@
1
+ import './index.css';class M extends Error {
2
+ response;
3
+ request;
4
+ options;
5
+ constructor(e, s, n) {
6
+ const i = e.status || e.status === 0 ? e.status : "", a = e.statusText ?? "", r = `${i} ${a}`.trim(), c = r ? `status code ${r}` : "an unknown error";
7
+ super(`Request failed with ${c}: ${s.method} ${s.url}`), this.name = "HTTPError", this.response = e, this.request = s, this.options = n;
8
+ }
9
+ }
10
+ class ie extends Error {
11
+ name = "NonError";
12
+ value;
13
+ constructor(e) {
14
+ let s = "Non-error value was thrown";
15
+ try {
16
+ typeof e == "string" ? s = e : e && typeof e == "object" && "message" in e && typeof e.message == "string" && (s = e.message);
17
+ } catch {
18
+ }
19
+ super(s), this.value = e;
20
+ }
21
+ }
22
+ class I extends Error {
23
+ name = "ForceRetryError";
24
+ customDelay;
25
+ code;
26
+ customRequest;
27
+ constructor(e) {
28
+ const s = e?.cause ? e.cause instanceof Error ? e.cause : new ie(e.cause) : void 0;
29
+ super(e?.code ? `Forced retry: ${e.code}` : "Forced retry", s ? { cause: s } : void 0), this.customDelay = e?.delay, this.code = e?.code, this.customRequest = e?.request;
30
+ }
31
+ }
32
+ const W = (() => {
33
+ let t = !1, e = !1;
34
+ const s = typeof globalThis.ReadableStream == "function", n = typeof globalThis.Request == "function";
35
+ if (s && n)
36
+ try {
37
+ e = new globalThis.Request("https://empty.invalid", {
38
+ body: new globalThis.ReadableStream(),
39
+ method: "POST",
40
+ // @ts-expect-error - Types are outdated.
41
+ get duplex() {
42
+ return t = !0, "half";
43
+ }
44
+ }).headers.has("Content-Type");
45
+ } catch (i) {
46
+ if (i instanceof Error && i.message === "unsupported BodyInit type")
47
+ return !1;
48
+ throw i;
49
+ }
50
+ return t && !e;
51
+ })(), De = typeof globalThis.AbortController == "function", oe = typeof globalThis.AbortSignal == "function" && typeof globalThis.AbortSignal.any == "function", Re = typeof globalThis.ReadableStream == "function", Ie = typeof globalThis.FormData == "function", re = ["get", "post", "put", "patch", "head", "delete"], xe = {
52
+ json: "application/json",
53
+ text: "text/*",
54
+ formData: "multipart/form-data",
55
+ arrayBuffer: "*/*",
56
+ blob: "*/*",
57
+ // Supported in modern Fetch implementations (for example, browsers and recent Node.js/undici).
58
+ // We still feature-check at runtime before exposing the shortcut.
59
+ bytes: "*/*"
60
+ }, x = 2147483647, Ne = new TextEncoder().encode("------WebKitFormBoundaryaxpyiPgbbPti10Rw").length, ae = Symbol("stop");
61
+ class ce {
62
+ options;
63
+ constructor(e) {
64
+ this.options = e;
65
+ }
66
+ }
67
+ const Be = (t) => new ce(t), Oe = {
68
+ json: !0,
69
+ parseJson: !0,
70
+ stringifyJson: !0,
71
+ searchParams: !0,
72
+ prefixUrl: !0,
73
+ retry: !0,
74
+ timeout: !0,
75
+ hooks: !0,
76
+ throwHttpErrors: !0,
77
+ onDownloadProgress: !0,
78
+ onUploadProgress: !0,
79
+ fetch: !0,
80
+ context: !0
81
+ }, Pe = {
82
+ next: !0
83
+ // Next.js cache revalidation (revalidate, tags)
84
+ }, Me = {
85
+ method: !0,
86
+ headers: !0,
87
+ body: !0,
88
+ mode: !0,
89
+ credentials: !0,
90
+ cache: !0,
91
+ redirect: !0,
92
+ referrer: !0,
93
+ referrerPolicy: !0,
94
+ integrity: !0,
95
+ keepalive: !0,
96
+ signal: !0,
97
+ window: !0,
98
+ duplex: !0
99
+ }, _e = (t) => {
100
+ if (!t)
101
+ return 0;
102
+ if (t instanceof FormData) {
103
+ let e = 0;
104
+ for (const [s, n] of t)
105
+ e += Ne, e += new TextEncoder().encode(`Content-Disposition: form-data; name="${s}"`).length, e += typeof n == "string" ? new TextEncoder().encode(n).length : n.size;
106
+ return e;
107
+ }
108
+ if (t instanceof Blob)
109
+ return t.size;
110
+ if (t instanceof ArrayBuffer)
111
+ return t.byteLength;
112
+ if (typeof t == "string")
113
+ return new TextEncoder().encode(t).length;
114
+ if (t instanceof URLSearchParams)
115
+ return new TextEncoder().encode(t.toString()).length;
116
+ if ("byteLength" in t)
117
+ return t.byteLength;
118
+ if (typeof t == "object" && t !== null)
119
+ try {
120
+ const e = JSON.stringify(t);
121
+ return new TextEncoder().encode(e).length;
122
+ } catch {
123
+ return 0;
124
+ }
125
+ return 0;
126
+ }, le = (t, e, s) => {
127
+ let n, i = 0;
128
+ return t.pipeThrough(new TransformStream({
129
+ transform(a, r) {
130
+ if (r.enqueue(a), n) {
131
+ i += n.byteLength;
132
+ let c = e === 0 ? 0 : i / e;
133
+ c >= 1 && (c = 1 - Number.EPSILON), s?.({ percent: c, totalBytes: Math.max(e, i), transferredBytes: i }, n);
134
+ }
135
+ n = a;
136
+ },
137
+ flush() {
138
+ n && (i += n.byteLength, s?.({ percent: 1, totalBytes: Math.max(e, i), transferredBytes: i }, n));
139
+ }
140
+ }));
141
+ }, Fe = (t, e) => {
142
+ if (!t.body)
143
+ return t;
144
+ if (t.status === 204)
145
+ return new Response(null, {
146
+ status: t.status,
147
+ statusText: t.statusText,
148
+ headers: t.headers
149
+ });
150
+ const s = Math.max(0, Number(t.headers.get("content-length")) || 0);
151
+ return new Response(le(t.body, s, e), {
152
+ status: t.status,
153
+ statusText: t.statusText,
154
+ headers: t.headers
155
+ });
156
+ }, Le = (t, e, s) => {
157
+ if (!t.body)
158
+ return t;
159
+ const n = _e(s ?? t.body);
160
+ return new Request(t, {
161
+ // @ts-expect-error - Types are outdated.
162
+ duplex: "half",
163
+ body: le(t.body, n, e)
164
+ });
165
+ }, b = (t) => t !== null && typeof t == "object", A = (...t) => {
166
+ for (const e of t)
167
+ if ((!b(e) || Array.isArray(e)) && e !== void 0)
168
+ throw new TypeError("The `options` argument must be an object");
169
+ return j({}, ...t);
170
+ }, ue = (t = {}, e = {}) => {
171
+ const s = new globalThis.Headers(t), n = e instanceof globalThis.Headers, i = new globalThis.Headers(e);
172
+ for (const [a, r] of i.entries())
173
+ n && r === "undefined" || r === void 0 ? s.delete(a) : s.set(a, r);
174
+ return s;
175
+ };
176
+ function k(t, e, s) {
177
+ return Object.hasOwn(e, s) && e[s] === void 0 ? [] : j(t[s] ?? [], e[s] ?? []);
178
+ }
179
+ const he = (t = {}, e = {}) => ({
180
+ beforeRequest: k(t, e, "beforeRequest"),
181
+ beforeRetry: k(t, e, "beforeRetry"),
182
+ afterResponse: k(t, e, "afterResponse"),
183
+ beforeError: k(t, e, "beforeError")
184
+ }), je = (t, e) => {
185
+ const s = new URLSearchParams();
186
+ for (const n of [t, e])
187
+ if (n !== void 0)
188
+ if (n instanceof URLSearchParams)
189
+ for (const [i, a] of n.entries())
190
+ s.append(i, a);
191
+ else if (Array.isArray(n))
192
+ for (const i of n) {
193
+ if (!Array.isArray(i) || i.length !== 2)
194
+ throw new TypeError("Array search parameters must be provided in [[key, value], ...] format");
195
+ s.append(String(i[0]), String(i[1]));
196
+ }
197
+ else if (b(n))
198
+ for (const [i, a] of Object.entries(n))
199
+ a !== void 0 && s.append(i, String(a));
200
+ else {
201
+ const i = new URLSearchParams(n);
202
+ for (const [a, r] of i.entries())
203
+ s.append(a, r);
204
+ }
205
+ return s;
206
+ }, j = (...t) => {
207
+ let e = {}, s = {}, n = {}, i;
208
+ const a = [];
209
+ for (const r of t)
210
+ if (Array.isArray(r))
211
+ Array.isArray(e) || (e = []), e = [...e, ...r];
212
+ else if (b(r)) {
213
+ for (let [c, l] of Object.entries(r)) {
214
+ if (c === "signal" && l instanceof globalThis.AbortSignal) {
215
+ a.push(l);
216
+ continue;
217
+ }
218
+ if (c === "context") {
219
+ if (l != null && (!b(l) || Array.isArray(l)))
220
+ throw new TypeError("The `context` option must be an object");
221
+ e = {
222
+ ...e,
223
+ context: l == null ? {} : { ...e.context, ...l }
224
+ };
225
+ continue;
226
+ }
227
+ if (c === "searchParams") {
228
+ l == null ? i = void 0 : i = i === void 0 ? l : je(i, l);
229
+ continue;
230
+ }
231
+ b(l) && c in e && (l = j(e[c], l)), e = { ...e, [c]: l };
232
+ }
233
+ b(r.hooks) && (n = he(n, r.hooks), e.hooks = n), b(r.headers) && (s = ue(s, r.headers), e.headers = s);
234
+ }
235
+ return i !== void 0 && (e.searchParams = i), a.length > 0 && (a.length === 1 ? e.signal = a[0] : oe ? e.signal = AbortSignal.any(a) : e.signal = a.at(-1)), e.context === void 0 && (e.context = {}), e;
236
+ }, He = (t) => re.includes(t) ? t.toUpperCase() : t, $e = ["get", "put", "head", "delete", "options", "trace"], ze = [408, 413, 429, 500, 502, 503, 504], qe = [413, 429, 503], K = {
237
+ limit: 2,
238
+ methods: $e,
239
+ statusCodes: ze,
240
+ afterStatusCodes: qe,
241
+ maxRetryAfter: Number.POSITIVE_INFINITY,
242
+ backoffLimit: Number.POSITIVE_INFINITY,
243
+ delay: (t) => 0.3 * 2 ** (t - 1) * 1e3,
244
+ jitter: void 0,
245
+ retryOnTimeout: !1
246
+ }, We = (t = {}) => {
247
+ if (typeof t == "number")
248
+ return {
249
+ ...K,
250
+ limit: t
251
+ };
252
+ if (t.methods && !Array.isArray(t.methods))
253
+ throw new Error("retry.methods must be an array");
254
+ if (t.statusCodes && !Array.isArray(t.statusCodes))
255
+ throw new Error("retry.statusCodes must be an array");
256
+ return {
257
+ ...K,
258
+ ...t
259
+ };
260
+ };
261
+ class _ extends Error {
262
+ request;
263
+ constructor(e) {
264
+ super(`Request timed out: ${e.method} ${e.url}`), this.name = "TimeoutError", this.request = e;
265
+ }
266
+ }
267
+ async function Ke(t, e, s, n) {
268
+ return new Promise((i, a) => {
269
+ const r = setTimeout(() => {
270
+ s && s.abort(), a(new _(t));
271
+ }, n.timeout);
272
+ n.fetch(t, e).then(i).catch(a).then(() => {
273
+ clearTimeout(r);
274
+ });
275
+ });
276
+ }
277
+ async function Ve(t, { signal: e }) {
278
+ return new Promise((s, n) => {
279
+ e && (e.throwIfAborted(), e.addEventListener("abort", i, { once: !0 }));
280
+ function i() {
281
+ clearTimeout(a), n(e.reason);
282
+ }
283
+ const a = setTimeout(() => {
284
+ e?.removeEventListener("abort", i), s();
285
+ }, t);
286
+ });
287
+ }
288
+ const Ge = (t, e) => {
289
+ const s = {};
290
+ for (const n in e)
291
+ Object.hasOwn(e, n) && !(n in Me) && !(n in Oe) && (!(n in t) || n in Pe) && (s[n] = e[n]);
292
+ return s;
293
+ }, Ye = (t) => t === void 0 ? !1 : Array.isArray(t) ? t.length > 0 : t instanceof URLSearchParams ? t.size > 0 : typeof t == "object" ? Object.keys(t).length > 0 : typeof t == "string" ? t.trim().length > 0 : !!t;
294
+ function Je(t) {
295
+ return t instanceof M || t?.name === M.name;
296
+ }
297
+ function Xe(t) {
298
+ return t instanceof _ || t?.name === _.name;
299
+ }
300
+ class w {
301
+ static create(e, s) {
302
+ const n = new w(e, s), i = async () => {
303
+ if (typeof n.#e.timeout == "number" && n.#e.timeout > x)
304
+ throw new RangeError(`The \`timeout\` option cannot be greater than ${x}`);
305
+ await Promise.resolve();
306
+ let r = await n.#g();
307
+ for (const c of n.#e.hooks.afterResponse) {
308
+ const l = n.#u(r.clone()), f = await c(n.request, n.#a(), l, { retryCount: n.#s });
309
+ if (f instanceof globalThis.Response && (r = f), f instanceof ce)
310
+ throw await Promise.all([
311
+ l.body?.cancel(),
312
+ r.body?.cancel()
313
+ ]), new I(f.options);
314
+ }
315
+ if (n.#u(r), !r.ok && (typeof n.#e.throwHttpErrors == "function" ? n.#e.throwHttpErrors(r.status) : n.#e.throwHttpErrors)) {
316
+ let c = new M(r, n.request, n.#a());
317
+ for (const l of n.#e.hooks.beforeError)
318
+ c = await l(c, { retryCount: n.#s });
319
+ throw c;
320
+ }
321
+ if (n.#e.onDownloadProgress) {
322
+ if (typeof n.#e.onDownloadProgress != "function")
323
+ throw new TypeError("The `onDownloadProgress` option must be a function");
324
+ if (!Re)
325
+ throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
326
+ return Fe(r.clone(), n.#e.onDownloadProgress);
327
+ }
328
+ return r;
329
+ }, a = n.#h(i).finally(async () => {
330
+ const r = n.#o, c = [];
331
+ r && !r.bodyUsed && c.push(r.body?.cancel()), n.request.bodyUsed || c.push(n.request.body?.cancel()), await Promise.all(c);
332
+ });
333
+ for (const [r, c] of Object.entries(xe))
334
+ r === "bytes" && typeof globalThis.Response?.prototype?.bytes != "function" || (a[r] = async () => {
335
+ n.request.headers.set("accept", n.request.headers.get("accept") || c);
336
+ const l = await a;
337
+ if (r === "json") {
338
+ if (l.status === 204)
339
+ return "";
340
+ const f = await l.text();
341
+ return f === "" ? "" : s.parseJson ? s.parseJson(f) : JSON.parse(f);
342
+ }
343
+ return l[r]();
344
+ });
345
+ return a;
346
+ }
347
+ // eslint-disable-next-line unicorn/prevent-abbreviations
348
+ static #f(e) {
349
+ return e && typeof e == "object" && !Array.isArray(e) && !(e instanceof URLSearchParams) ? Object.fromEntries(Object.entries(e).filter(([, s]) => s !== void 0)) : e;
350
+ }
351
+ request;
352
+ #n;
353
+ #s = 0;
354
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly -- False positive: #input is reassigned on line 202
355
+ #t;
356
+ #e;
357
+ #o;
358
+ #i;
359
+ #r;
360
+ // eslint-disable-next-line complexity
361
+ constructor(e, s = {}) {
362
+ if (this.#t = e, this.#e = {
363
+ ...s,
364
+ headers: ue(this.#t.headers, s.headers),
365
+ hooks: he({
366
+ beforeRequest: [],
367
+ beforeRetry: [],
368
+ beforeError: [],
369
+ afterResponse: []
370
+ }, s.hooks),
371
+ method: He(s.method ?? this.#t.method ?? "GET"),
372
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
373
+ prefixUrl: String(s.prefixUrl || ""),
374
+ retry: We(s.retry),
375
+ throwHttpErrors: s.throwHttpErrors ?? !0,
376
+ timeout: s.timeout ?? 1e4,
377
+ fetch: s.fetch ?? globalThis.fetch.bind(globalThis),
378
+ context: s.context ?? {}
379
+ }, typeof this.#t != "string" && !(this.#t instanceof URL || this.#t instanceof globalThis.Request))
380
+ throw new TypeError("`input` must be a string, URL, or Request");
381
+ if (this.#e.prefixUrl && typeof this.#t == "string") {
382
+ if (this.#t.startsWith("/"))
383
+ throw new Error("`input` must not begin with a slash when using `prefixUrl`");
384
+ this.#e.prefixUrl.endsWith("/") || (this.#e.prefixUrl += "/"), this.#t = this.#e.prefixUrl + this.#t;
385
+ }
386
+ De && oe && (this.#i = this.#e.signal ?? this.#t.signal, this.#n = new globalThis.AbortController(), this.#e.signal = this.#i ? AbortSignal.any([this.#i, this.#n.signal]) : this.#n.signal), W && (this.#e.duplex = "half"), this.#e.json !== void 0 && (this.#e.body = this.#e.stringifyJson?.(this.#e.json) ?? JSON.stringify(this.#e.json), this.#e.headers.set("content-type", this.#e.headers.get("content-type") ?? "application/json"));
387
+ const n = s.headers && new globalThis.Headers(s.headers).has("content-type");
388
+ if (this.#t instanceof globalThis.Request && (Ie && this.#e.body instanceof globalThis.FormData || this.#e.body instanceof URLSearchParams) && !n && this.#e.headers.delete("content-type"), this.request = new globalThis.Request(this.#t, this.#e), Ye(this.#e.searchParams)) {
389
+ const a = "?" + (typeof this.#e.searchParams == "string" ? this.#e.searchParams.replace(/^\?/, "") : new URLSearchParams(w.#f(this.#e.searchParams)).toString()), r = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, a);
390
+ this.request = new globalThis.Request(r, this.#e);
391
+ }
392
+ if (this.#e.onUploadProgress) {
393
+ if (typeof this.#e.onUploadProgress != "function")
394
+ throw new TypeError("The `onUploadProgress` option must be a function");
395
+ if (!W)
396
+ throw new Error("Request streams are not supported in your environment. The `duplex` option for `Request` is not available.");
397
+ this.request = this.#d(this.request, this.#e.body ?? void 0);
398
+ }
399
+ }
400
+ #c() {
401
+ const e = this.#e.retry.delay(this.#s);
402
+ let s = e;
403
+ return this.#e.retry.jitter === !0 ? s = Math.random() * e : typeof this.#e.retry.jitter == "function" && (s = this.#e.retry.jitter(e), (!Number.isFinite(s) || s < 0) && (s = e)), Math.min(this.#e.retry.backoffLimit, s);
404
+ }
405
+ async #m(e) {
406
+ if (this.#s++, this.#s > this.#e.retry.limit)
407
+ throw e;
408
+ const s = e instanceof Error ? e : new ie(e);
409
+ if (s instanceof I)
410
+ return s.customDelay ?? this.#c();
411
+ if (!this.#e.retry.methods.includes(this.request.method.toLowerCase()))
412
+ throw e;
413
+ if (this.#e.retry.shouldRetry !== void 0) {
414
+ const n = await this.#e.retry.shouldRetry({ error: s, retryCount: this.#s });
415
+ if (n === !1)
416
+ throw e;
417
+ if (n === !0)
418
+ return this.#c();
419
+ }
420
+ if (Xe(e) && !this.#e.retry.retryOnTimeout)
421
+ throw e;
422
+ if (Je(e)) {
423
+ if (!this.#e.retry.statusCodes.includes(e.response.status))
424
+ throw e;
425
+ const n = e.response.headers.get("Retry-After") ?? e.response.headers.get("RateLimit-Reset") ?? e.response.headers.get("X-RateLimit-Retry-After") ?? e.response.headers.get("X-RateLimit-Reset") ?? e.response.headers.get("X-Rate-Limit-Reset");
426
+ if (n && this.#e.retry.afterStatusCodes.includes(e.response.status)) {
427
+ let i = Number(n) * 1e3;
428
+ Number.isNaN(i) ? i = Date.parse(n) - Date.now() : i >= Date.parse("2024-01-01") && (i -= Date.now());
429
+ const a = this.#e.retry.maxRetryAfter ?? i;
430
+ return i < a ? i : a;
431
+ }
432
+ if (e.response.status === 413)
433
+ throw e;
434
+ }
435
+ return this.#c();
436
+ }
437
+ #u(e) {
438
+ return this.#e.parseJson && (e.json = async () => this.#e.parseJson(await e.text())), e;
439
+ }
440
+ async #h(e) {
441
+ try {
442
+ return await e();
443
+ } catch (s) {
444
+ const n = Math.min(await this.#m(s), x);
445
+ if (this.#s < 1)
446
+ throw s;
447
+ if (await Ve(n, this.#i ? { signal: this.#i } : {}), s instanceof I && s.customRequest) {
448
+ const i = this.#e.signal ? new globalThis.Request(s.customRequest, { signal: this.#e.signal }) : new globalThis.Request(s.customRequest);
449
+ this.#l(i);
450
+ }
451
+ for (const i of this.#e.hooks.beforeRetry) {
452
+ const a = await i({
453
+ request: this.request,
454
+ options: this.#a(),
455
+ error: s,
456
+ retryCount: this.#s
457
+ });
458
+ if (a instanceof globalThis.Request) {
459
+ this.#l(a);
460
+ break;
461
+ }
462
+ if (a instanceof globalThis.Response)
463
+ return a;
464
+ if (a === ae)
465
+ return;
466
+ }
467
+ return this.#h(e);
468
+ }
469
+ }
470
+ async #g() {
471
+ this.#n?.signal.aborted && (this.#n = new globalThis.AbortController(), this.#e.signal = this.#i ? AbortSignal.any([this.#i, this.#n.signal]) : this.#n.signal, this.request = new globalThis.Request(this.request, { signal: this.#e.signal }));
472
+ for (const s of this.#e.hooks.beforeRequest) {
473
+ const n = await s(this.request, this.#a(), { retryCount: this.#s });
474
+ if (n instanceof Response)
475
+ return n;
476
+ if (n instanceof globalThis.Request) {
477
+ this.#l(n);
478
+ break;
479
+ }
480
+ }
481
+ const e = Ge(this.request, this.#e);
482
+ return this.#o = this.request, this.request = this.#o.clone(), this.#e.timeout === !1 ? this.#e.fetch(this.#o, e) : Ke(this.#o, e, this.#n, this.#e);
483
+ }
484
+ #a() {
485
+ if (!this.#r) {
486
+ const { hooks: e, ...s } = this.#e;
487
+ this.#r = Object.freeze(s);
488
+ }
489
+ return this.#r;
490
+ }
491
+ #l(e) {
492
+ this.#r = void 0, this.request = this.#d(e);
493
+ }
494
+ #d(e, s) {
495
+ return !this.#e.onUploadProgress || !e.body ? e : Le(e, this.#e.onUploadProgress, s ?? this.#e.body ?? void 0);
496
+ }
497
+ }
498
+ /*! MIT License © Sindre Sorhus */
499
+ const F = (t) => {
500
+ const e = (s, n) => w.create(s, A(t, n));
501
+ for (const s of re)
502
+ e[s] = (n, i) => w.create(n, A(t, i, { method: s }));
503
+ return e.create = (s) => F(A(s)), e.extend = (s) => (typeof s == "function" && (s = s(t ?? {})), F(A(t, s))), e.stop = ae, e.retry = Be, e;
504
+ }, Ze = F(), d = {
505
+ ARBITRUM: "ARBITRUM_MAINNET",
506
+ ARBITRUM_TESTNET: "ARBITRUM_TESTNET",
507
+ AVALANCHE: "AVALANCHE_MAINNET",
508
+ AVALANCHE_TESTNET: "AVALANCHE_TESTNET",
509
+ BASE: "BASE_MAINNET",
510
+ BASE_TESTNET: "BASE_TESTNET",
511
+ BSC: "BSC_MAINNET",
512
+ ETHEREUM: "ETHEREUM_MAINNET",
513
+ ETHEREUM_TESTNET: "ETHEREUM_TESTNET",
514
+ HYPEREVM: "HYPEREVM_MAINNET",
515
+ LISK: "LISK_MAINNET",
516
+ MONAD: "MONAD_MAINNET",
517
+ MONAD_TESTNET: "MONAD_TESTNET",
518
+ OPTIMISM: "OPTIMISM_MAINNET",
519
+ OPTIMISM_TESTNET: "OPTIMISM_TESTNET",
520
+ POLYGON: "POLYGON_MAINNET",
521
+ STARKNET: "STARKNET_MAINNET",
522
+ STARKNET_TESTNET: "STARKNET_TESTNET"
523
+ }, Xt = {
524
+ ARBITRUM: "ARBITRUM",
525
+ ARBITRUM_TESTNET: "ARBITRUM_TESTNET",
526
+ AVALANCHE: "AVALANCHE",
527
+ AVALANCHE_TESTNET: "AVALANCHE_TESTNET",
528
+ BASE: "BASE",
529
+ BASE_TESTNET: "BASE_TESTNET",
530
+ BSC: "BSC",
531
+ ETHEREUM: "ETHEREUM",
532
+ ETHEREUM_TESTNET: "ETHEREUM_TESTNET",
533
+ HYPEREVM: "HYPEREVM",
534
+ LISK: "LISK",
535
+ MONAD: "MONAD",
536
+ MONAD_TESTNET: "MONAD_TESTNET",
537
+ OPTIMISM: "OPTIMISM",
538
+ OPTIMISM_TESTNET: "OPTIMISM_TESTNET",
539
+ POLYGON: "POLYGON",
540
+ STARKNET: "STARKNET",
541
+ STARKNET_TESTNET: "STARKNET_TESTNET"
542
+ };
543
+ function H(t, { strict: e = !0 } = {}) {
544
+ return !t || typeof t != "string" ? !1 : e ? /^0x[0-9a-fA-F]*$/.test(t) : t.startsWith("0x");
545
+ }
546
+ function V(t) {
547
+ return H(t, { strict: !1 }) ? Math.ceil((t.length - 2) / 2) : t.length;
548
+ }
549
+ const de = "2.43.4";
550
+ let N = {
551
+ getDocsUrl: ({ docsBaseUrl: t, docsPath: e = "", docsSlug: s }) => e ? `${t ?? "https://viem.sh"}${e}${s ? `#${s}` : ""}` : void 0,
552
+ version: `viem@${de}`
553
+ };
554
+ class y extends Error {
555
+ constructor(e, s = {}) {
556
+ const n = s.cause instanceof y ? s.cause.details : s.cause?.message ? s.cause.message : s.details, i = s.cause instanceof y && s.cause.docsPath || s.docsPath, a = N.getDocsUrl?.({ ...s, docsPath: i }), r = [
557
+ e || "An error occurred.",
558
+ "",
559
+ ...s.metaMessages ? [...s.metaMessages, ""] : [],
560
+ ...a ? [`Docs: ${a}`] : [],
561
+ ...n ? [`Details: ${n}`] : [],
562
+ ...N.version ? [`Version: ${N.version}`] : []
563
+ ].join(`
564
+ `);
565
+ super(r, s.cause ? { cause: s.cause } : void 0), Object.defineProperty(this, "details", {
566
+ enumerable: !0,
567
+ configurable: !0,
568
+ writable: !0,
569
+ value: void 0
570
+ }), Object.defineProperty(this, "docsPath", {
571
+ enumerable: !0,
572
+ configurable: !0,
573
+ writable: !0,
574
+ value: void 0
575
+ }), Object.defineProperty(this, "metaMessages", {
576
+ enumerable: !0,
577
+ configurable: !0,
578
+ writable: !0,
579
+ value: void 0
580
+ }), Object.defineProperty(this, "shortMessage", {
581
+ enumerable: !0,
582
+ configurable: !0,
583
+ writable: !0,
584
+ value: void 0
585
+ }), Object.defineProperty(this, "version", {
586
+ enumerable: !0,
587
+ configurable: !0,
588
+ writable: !0,
589
+ value: void 0
590
+ }), Object.defineProperty(this, "name", {
591
+ enumerable: !0,
592
+ configurable: !0,
593
+ writable: !0,
594
+ value: "BaseError"
595
+ }), this.details = n, this.docsPath = i, this.metaMessages = s.metaMessages, this.name = s.name ?? this.name, this.shortMessage = e, this.version = de;
596
+ }
597
+ walk(e) {
598
+ return fe(this, e);
599
+ }
600
+ }
601
+ function fe(t, e) {
602
+ return e?.(t) ? t : t && typeof t == "object" && "cause" in t && t.cause !== void 0 ? fe(t.cause, e) : e ? null : t;
603
+ }
604
+ class me extends y {
605
+ constructor({ size: e, targetSize: s, type: n }) {
606
+ super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${e}) exceeds padding size (${s}).`, { name: "SizeExceedsPaddingSizeError" });
607
+ }
608
+ }
609
+ function R(t, { dir: e, size: s = 32 } = {}) {
610
+ return typeof t == "string" ? Qe(t, { dir: e, size: s }) : et(t, { dir: e, size: s });
611
+ }
612
+ function Qe(t, { dir: e, size: s = 32 } = {}) {
613
+ if (s === null)
614
+ return t;
615
+ const n = t.replace("0x", "");
616
+ if (n.length > s * 2)
617
+ throw new me({
618
+ size: Math.ceil(n.length / 2),
619
+ targetSize: s,
620
+ type: "hex"
621
+ });
622
+ return `0x${n[e === "right" ? "padEnd" : "padStart"](s * 2, "0")}`;
623
+ }
624
+ function et(t, { dir: e, size: s = 32 } = {}) {
625
+ if (s === null)
626
+ return t;
627
+ if (t.length > s)
628
+ throw new me({
629
+ size: t.length,
630
+ targetSize: s,
631
+ type: "bytes"
632
+ });
633
+ const n = new Uint8Array(s);
634
+ for (let i = 0; i < s; i++) {
635
+ const a = e === "right";
636
+ n[a ? i : s - i - 1] = t[a ? i : t.length - i - 1];
637
+ }
638
+ return n;
639
+ }
640
+ class tt extends y {
641
+ constructor({ max: e, min: s, signed: n, size: i, value: a }) {
642
+ super(`Number "${a}" is not in safe ${i ? `${i * 8}-bit ${n ? "signed" : "unsigned"} ` : ""}integer range ${e ? `(${s} to ${e})` : `(above ${s})`}`, { name: "IntegerOutOfRangeError" });
643
+ }
644
+ }
645
+ class st extends y {
646
+ constructor({ givenSize: e, maxSize: s }) {
647
+ super(`Size cannot exceed ${s} bytes. Given size: ${e} bytes.`, { name: "SizeOverflowError" });
648
+ }
649
+ }
650
+ function $(t, { size: e }) {
651
+ if (V(t) > e)
652
+ throw new st({
653
+ givenSize: V(t),
654
+ maxSize: e
655
+ });
656
+ }
657
+ function nt(t, e = {}) {
658
+ const { signed: s, size: n } = e, i = BigInt(t);
659
+ let a;
660
+ n ? s ? a = (1n << BigInt(n) * 8n - 1n) - 1n : a = 2n ** (BigInt(n) * 8n) - 1n : typeof t == "number" && (a = BigInt(Number.MAX_SAFE_INTEGER));
661
+ const r = typeof a == "bigint" && s ? -a - 1n : 0;
662
+ if (a && i > a || i < r) {
663
+ const l = typeof t == "bigint" ? "n" : "";
664
+ throw new tt({
665
+ max: a ? `${a}${l}` : void 0,
666
+ min: `${r}${l}`,
667
+ signed: s,
668
+ size: n,
669
+ value: `${t}${l}`
670
+ });
671
+ }
672
+ const c = `0x${(s && i < 0 ? (1n << BigInt(n * 8)) + BigInt(i) : i).toString(16)}`;
673
+ return n ? R(c, { size: n }) : c;
674
+ }
675
+ const it = /* @__PURE__ */ new TextEncoder();
676
+ function ot(t, e = {}) {
677
+ return typeof t == "number" || typeof t == "bigint" ? at(t, e) : typeof t == "boolean" ? rt(t, e) : H(t) ? ge(t, e) : pe(t, e);
678
+ }
679
+ function rt(t, e = {}) {
680
+ const s = new Uint8Array(1);
681
+ return s[0] = Number(t), typeof e.size == "number" ? ($(s, { size: e.size }), R(s, { size: e.size })) : s;
682
+ }
683
+ const p = {
684
+ zero: 48,
685
+ nine: 57,
686
+ A: 65,
687
+ F: 70,
688
+ a: 97,
689
+ f: 102
690
+ };
691
+ function G(t) {
692
+ if (t >= p.zero && t <= p.nine)
693
+ return t - p.zero;
694
+ if (t >= p.A && t <= p.F)
695
+ return t - (p.A - 10);
696
+ if (t >= p.a && t <= p.f)
697
+ return t - (p.a - 10);
698
+ }
699
+ function ge(t, e = {}) {
700
+ let s = t;
701
+ e.size && ($(s, { size: e.size }), s = R(s, { dir: "right", size: e.size }));
702
+ let n = s.slice(2);
703
+ n.length % 2 && (n = `0${n}`);
704
+ const i = n.length / 2, a = new Uint8Array(i);
705
+ for (let r = 0, c = 0; r < i; r++) {
706
+ const l = G(n.charCodeAt(c++)), f = G(n.charCodeAt(c++));
707
+ if (l === void 0 || f === void 0)
708
+ throw new y(`Invalid byte sequence ("${n[c - 2]}${n[c - 1]}" in "${n}").`);
709
+ a[r] = l * 16 + f;
710
+ }
711
+ return a;
712
+ }
713
+ function at(t, e) {
714
+ const s = nt(t, e);
715
+ return ge(s);
716
+ }
717
+ function pe(t, e = {}) {
718
+ const s = it.encode(t);
719
+ return typeof e.size == "number" ? ($(s, { size: e.size }), R(s, { dir: "right", size: e.size })) : s;
720
+ }
721
+ const v = /* @__PURE__ */ BigInt(2 ** 32 - 1), Y = /* @__PURE__ */ BigInt(32);
722
+ function ct(t, e = !1) {
723
+ return e ? { h: Number(t & v), l: Number(t >> Y & v) } : { h: Number(t >> Y & v) | 0, l: Number(t & v) | 0 };
724
+ }
725
+ function lt(t, e = !1) {
726
+ const s = t.length;
727
+ let n = new Uint32Array(s), i = new Uint32Array(s);
728
+ for (let a = 0; a < s; a++) {
729
+ const { h: r, l: c } = ct(t[a], e);
730
+ [n[a], i[a]] = [r, c];
731
+ }
732
+ return [n, i];
733
+ }
734
+ const ut = (t, e, s) => t << s | e >>> 32 - s, ht = (t, e, s) => e << s | t >>> 32 - s, dt = (t, e, s) => e << s - 32 | t >>> 64 - s, ft = (t, e, s) => t << s - 32 | e >>> 64 - s;
735
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
736
+ function mt(t) {
737
+ return t instanceof Uint8Array || ArrayBuffer.isView(t) && t.constructor.name === "Uint8Array";
738
+ }
739
+ function J(t) {
740
+ if (!Number.isSafeInteger(t) || t < 0)
741
+ throw new Error("positive integer expected, got " + t);
742
+ }
743
+ function D(t, ...e) {
744
+ if (!mt(t))
745
+ throw new Error("Uint8Array expected");
746
+ if (e.length > 0 && !e.includes(t.length))
747
+ throw new Error("Uint8Array expected of length " + e + ", got length=" + t.length);
748
+ }
749
+ function X(t, e = !0) {
750
+ if (t.destroyed)
751
+ throw new Error("Hash instance has been destroyed");
752
+ if (e && t.finished)
753
+ throw new Error("Hash#digest() has already been called");
754
+ }
755
+ function gt(t, e) {
756
+ D(t);
757
+ const s = e.outputLen;
758
+ if (t.length < s)
759
+ throw new Error("digestInto() expects output buffer of length at least " + s);
760
+ }
761
+ function pt(t) {
762
+ return new Uint32Array(t.buffer, t.byteOffset, Math.floor(t.byteLength / 4));
763
+ }
764
+ function ye(...t) {
765
+ for (let e = 0; e < t.length; e++)
766
+ t[e].fill(0);
767
+ }
768
+ const yt = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
769
+ function Tt(t) {
770
+ return t << 24 & 4278190080 | t << 8 & 16711680 | t >>> 8 & 65280 | t >>> 24 & 255;
771
+ }
772
+ function bt(t) {
773
+ for (let e = 0; e < t.length; e++)
774
+ t[e] = Tt(t[e]);
775
+ return t;
776
+ }
777
+ const Z = yt ? (t) => t : bt;
778
+ function Et(t) {
779
+ if (typeof t != "string")
780
+ throw new Error("string expected");
781
+ return new Uint8Array(new TextEncoder().encode(t));
782
+ }
783
+ function Te(t) {
784
+ return typeof t == "string" && (t = Et(t)), D(t), t;
785
+ }
786
+ class St {
787
+ }
788
+ function Ct(t) {
789
+ const e = (n) => t().update(Te(n)).digest(), s = t();
790
+ return e.outputLen = s.outputLen, e.blockLen = s.blockLen, e.create = () => t(), e;
791
+ }
792
+ const wt = BigInt(0), E = BigInt(1), Ut = BigInt(2), At = BigInt(7), kt = BigInt(256), vt = BigInt(113), be = [], Ee = [], Se = [];
793
+ for (let t = 0, e = E, s = 1, n = 0; t < 24; t++) {
794
+ [s, n] = [n, (2 * s + 3 * n) % 5], be.push(2 * (5 * n + s)), Ee.push((t + 1) * (t + 2) / 2 % 64);
795
+ let i = wt;
796
+ for (let a = 0; a < 7; a++)
797
+ e = (e << E ^ (e >> At) * vt) % kt, e & Ut && (i ^= E << (E << /* @__PURE__ */ BigInt(a)) - E);
798
+ Se.push(i);
799
+ }
800
+ const Ce = lt(Se, !0), Dt = Ce[0], Rt = Ce[1], Q = (t, e, s) => s > 32 ? dt(t, e, s) : ut(t, e, s), ee = (t, e, s) => s > 32 ? ft(t, e, s) : ht(t, e, s);
801
+ function It(t, e = 24) {
802
+ const s = new Uint32Array(10);
803
+ for (let n = 24 - e; n < 24; n++) {
804
+ for (let r = 0; r < 10; r++)
805
+ s[r] = t[r] ^ t[r + 10] ^ t[r + 20] ^ t[r + 30] ^ t[r + 40];
806
+ for (let r = 0; r < 10; r += 2) {
807
+ const c = (r + 8) % 10, l = (r + 2) % 10, f = s[l], T = s[l + 1], ke = Q(f, T, 1) ^ s[c], ve = ee(f, T, 1) ^ s[c + 1];
808
+ for (let U = 0; U < 50; U += 10)
809
+ t[r + U] ^= ke, t[r + U + 1] ^= ve;
810
+ }
811
+ let i = t[2], a = t[3];
812
+ for (let r = 0; r < 24; r++) {
813
+ const c = Ee[r], l = Q(i, a, c), f = ee(i, a, c), T = be[r];
814
+ i = t[T], a = t[T + 1], t[T] = l, t[T + 1] = f;
815
+ }
816
+ for (let r = 0; r < 50; r += 10) {
817
+ for (let c = 0; c < 10; c++)
818
+ s[c] = t[r + c];
819
+ for (let c = 0; c < 10; c++)
820
+ t[r + c] ^= ~s[(c + 2) % 10] & s[(c + 4) % 10];
821
+ }
822
+ t[0] ^= Dt[n], t[1] ^= Rt[n];
823
+ }
824
+ ye(s);
825
+ }
826
+ class z extends St {
827
+ // NOTE: we accept arguments in bytes instead of bits here.
828
+ constructor(e, s, n, i = !1, a = 24) {
829
+ if (super(), this.pos = 0, this.posOut = 0, this.finished = !1, this.destroyed = !1, this.enableXOF = !1, this.blockLen = e, this.suffix = s, this.outputLen = n, this.enableXOF = i, this.rounds = a, J(n), !(0 < e && e < 200))
830
+ throw new Error("only keccak-f1600 function is supported");
831
+ this.state = new Uint8Array(200), this.state32 = pt(this.state);
832
+ }
833
+ clone() {
834
+ return this._cloneInto();
835
+ }
836
+ keccak() {
837
+ Z(this.state32), It(this.state32, this.rounds), Z(this.state32), this.posOut = 0, this.pos = 0;
838
+ }
839
+ update(e) {
840
+ X(this), e = Te(e), D(e);
841
+ const { blockLen: s, state: n } = this, i = e.length;
842
+ for (let a = 0; a < i; ) {
843
+ const r = Math.min(s - this.pos, i - a);
844
+ for (let c = 0; c < r; c++)
845
+ n[this.pos++] ^= e[a++];
846
+ this.pos === s && this.keccak();
847
+ }
848
+ return this;
849
+ }
850
+ finish() {
851
+ if (this.finished)
852
+ return;
853
+ this.finished = !0;
854
+ const { state: e, suffix: s, pos: n, blockLen: i } = this;
855
+ e[n] ^= s, (s & 128) !== 0 && n === i - 1 && this.keccak(), e[i - 1] ^= 128, this.keccak();
856
+ }
857
+ writeInto(e) {
858
+ X(this, !1), D(e), this.finish();
859
+ const s = this.state, { blockLen: n } = this;
860
+ for (let i = 0, a = e.length; i < a; ) {
861
+ this.posOut >= n && this.keccak();
862
+ const r = Math.min(n - this.posOut, a - i);
863
+ e.set(s.subarray(this.posOut, this.posOut + r), i), this.posOut += r, i += r;
864
+ }
865
+ return e;
866
+ }
867
+ xofInto(e) {
868
+ if (!this.enableXOF)
869
+ throw new Error("XOF is not possible for this instance");
870
+ return this.writeInto(e);
871
+ }
872
+ xof(e) {
873
+ return J(e), this.xofInto(new Uint8Array(e));
874
+ }
875
+ digestInto(e) {
876
+ if (gt(e, this), this.finished)
877
+ throw new Error("digest() was already called");
878
+ return this.writeInto(e), this.destroy(), e;
879
+ }
880
+ digest() {
881
+ return this.digestInto(new Uint8Array(this.outputLen));
882
+ }
883
+ destroy() {
884
+ this.destroyed = !0, ye(this.state);
885
+ }
886
+ _cloneInto(e) {
887
+ const { blockLen: s, suffix: n, outputLen: i, rounds: a, enableXOF: r } = this;
888
+ return e || (e = new z(s, n, i, r, a)), e.state32.set(this.state32), e.pos = this.pos, e.posOut = this.posOut, e.finished = this.finished, e.rounds = a, e.suffix = n, e.outputLen = i, e.enableXOF = r, e.destroyed = this.destroyed, e;
889
+ }
890
+ }
891
+ const xt = (t, e, s) => Ct(() => new z(e, t, s)), Nt = xt(1, 136, 256 / 8);
892
+ function Bt(t, e) {
893
+ return Nt(H(t, { strict: !1 }) ? ot(t) : t);
894
+ }
895
+ class Ot extends y {
896
+ constructor({ address: e }) {
897
+ super(`Address "${e}" is invalid.`, {
898
+ metaMessages: [
899
+ "- Address must be a hex value of 20 bytes (40 hex characters).",
900
+ "- Address must match its checksum counterpart."
901
+ ],
902
+ name: "InvalidAddressError"
903
+ });
904
+ }
905
+ }
906
+ class we extends Map {
907
+ constructor(e) {
908
+ super(), Object.defineProperty(this, "maxSize", {
909
+ enumerable: !0,
910
+ configurable: !0,
911
+ writable: !0,
912
+ value: void 0
913
+ }), this.maxSize = e;
914
+ }
915
+ get(e) {
916
+ const s = super.get(e);
917
+ return super.has(e) && s !== void 0 && (this.delete(e), super.set(e, s)), s;
918
+ }
919
+ set(e, s) {
920
+ if (super.set(e, s), this.maxSize && this.size > this.maxSize) {
921
+ const n = this.keys().next().value;
922
+ n && this.delete(n);
923
+ }
924
+ return this;
925
+ }
926
+ }
927
+ const B = /* @__PURE__ */ new we(8192);
928
+ function Ue(t, e) {
929
+ if (B.has(`${t}.${e}`))
930
+ return B.get(`${t}.${e}`);
931
+ const s = t.substring(2).toLowerCase(), n = Bt(pe(s)), i = s.split("");
932
+ for (let r = 0; r < 40; r += 2)
933
+ n[r >> 1] >> 4 >= 8 && i[r] && (i[r] = i[r].toUpperCase()), (n[r >> 1] & 15) >= 8 && i[r + 1] && (i[r + 1] = i[r + 1].toUpperCase());
934
+ const a = `0x${i.join("")}`;
935
+ return B.set(`${t}.${e}`, a), a;
936
+ }
937
+ function m(t, e) {
938
+ if (!Mt(t, { strict: !1 }))
939
+ throw new Ot({ address: t });
940
+ return Ue(t, e);
941
+ }
942
+ const Pt = /^0x[a-fA-F0-9]{40}$/, O = /* @__PURE__ */ new we(8192);
943
+ function Mt(t, e) {
944
+ const { strict: s = !0 } = e ?? {}, n = `${t}.${s}`;
945
+ if (O.has(n))
946
+ return O.get(n);
947
+ const i = Pt.test(t) ? t.toLowerCase() === t ? !0 : s ? Ue(t) === t : !0 : !1;
948
+ return O.set(n, i), i;
949
+ }
950
+ const o = {
951
+ USDC: "USDC",
952
+ USDT: "USDT",
953
+ DAI: "DAI",
954
+ BUSD: "BUSD",
955
+ EURC: "EURC",
956
+ ETH: "ETH",
957
+ WETH: "WETH",
958
+ STRK: "STRK",
959
+ BNB: "BNB",
960
+ LORDS: "LORDS"
961
+ };
962
+ o.USDC;
963
+ const Ae = {
964
+ [d.ARBITRUM]: {
965
+ [o.DAI]: {
966
+ address: m("0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1"),
967
+ symbol: o.DAI,
968
+ name: "Dai Stablecoin",
969
+ decimals: 18,
970
+ logoURI: "/images/tokens/dai.png",
971
+ nativeToken: !1
972
+ },
973
+ [o.ETH]: {
974
+ address: "0x0000000000000000000000000000000000000000",
975
+ symbol: o.ETH,
976
+ name: "Ethereum",
977
+ decimals: 18,
978
+ logoURI: "/images/chains/ethereum.svg",
979
+ nativeToken: !0
980
+ },
981
+ [o.USDC]: {
982
+ address: m("0xaf88d065e77c8cC2239327C5EDb3A432268e5831"),
983
+ symbol: o.USDC,
984
+ name: "USD Coin",
985
+ decimals: 6,
986
+ logoURI: "/images/tokens/usdc.svg",
987
+ nativeToken: !1
988
+ },
989
+ [o.USDT]: {
990
+ address: m("0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9"),
991
+ symbol: o.USDT,
992
+ name: "Tether USD",
993
+ decimals: 6,
994
+ logoURI: "/images/tokens/usdt.png",
995
+ nativeToken: !1
996
+ },
997
+ [o.WETH]: {
998
+ address: m("0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"),
999
+ symbol: o.WETH,
1000
+ name: "Wrapped Ether",
1001
+ decimals: 18,
1002
+ logoURI: "/images/tokens/weth.png",
1003
+ nativeToken: !1
1004
+ }
1005
+ },
1006
+ [d.ARBITRUM_TESTNET]: {
1007
+ [o.USDC]: {
1008
+ address: m("0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d"),
1009
+ symbol: o.USDC,
1010
+ name: "USD Coin",
1011
+ fiatISO: "USD",
1012
+ decimals: 6,
1013
+ logoURI: "/images/tokens/usdc.svg",
1014
+ logoSourceURI: "https://pay.daimo.com/coin-logos/usdc.png",
1015
+ nativeToken: !1
1016
+ }
1017
+ },
1018
+ [d.AVALANCHE]: {
1019
+ [o.DAI]: {
1020
+ address: "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70",
1021
+ symbol: o.DAI,
1022
+ name: "Dai Stablecoin",
1023
+ decimals: 18,
1024
+ logoURI: "/images/tokens/dai.png",
1025
+ nativeToken: !1
1026
+ },
1027
+ [o.USDC]: {
1028
+ address: m("0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E"),
1029
+ symbol: o.USDC,
1030
+ name: "USD Coin",
1031
+ fiatISO: "USD",
1032
+ decimals: 6,
1033
+ logoURI: "/images/tokens/usdc.svg",
1034
+ logoSourceURI: "https://pay.daimo.com/coin-logos/usdc.png",
1035
+ nativeToken: !1
1036
+ },
1037
+ [o.USDT]: {
1038
+ address: "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
1039
+ symbol: o.USDT,
1040
+ name: "Tether USD",
1041
+ decimals: 6,
1042
+ logoURI: "/images/tokens/usdt.png",
1043
+ nativeToken: !1
1044
+ },
1045
+ [o.WETH]: {
1046
+ address: "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB",
1047
+ symbol: o.WETH,
1048
+ name: "Wrapped Ether",
1049
+ decimals: 18,
1050
+ logoURI: "/images/tokens/weth.png",
1051
+ nativeToken: !1
1052
+ }
1053
+ },
1054
+ [d.AVALANCHE_TESTNET]: {
1055
+ [o.USDC]: {
1056
+ address: m("0x5425890298aed601595a70AB815c96711a31Bc65"),
1057
+ symbol: o.USDC,
1058
+ name: "USD Coin",
1059
+ fiatISO: "USD",
1060
+ decimals: 6,
1061
+ logoURI: "/images/tokens/usdc.svg",
1062
+ logoSourceURI: "https://pay.daimo.com/coin-logos/usdc.png",
1063
+ nativeToken: !1
1064
+ }
1065
+ },
1066
+ [d.BASE]: {
1067
+ [o.DAI]: {
1068
+ address: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
1069
+ symbol: o.DAI,
1070
+ name: "Dai Stablecoin",
1071
+ decimals: 18,
1072
+ logoURI: "/images/tokens/dai.png",
1073
+ nativeToken: !1
1074
+ },
1075
+ [o.ETH]: {
1076
+ address: "0x0000000000000000000000000000000000000000",
1077
+ symbol: o.ETH,
1078
+ name: "Ethereum",
1079
+ decimals: 18,
1080
+ logoURI: "/images/chains/ethereum.svg",
1081
+ nativeToken: !0
1082
+ },
1083
+ [o.EURC]: {
1084
+ address: "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42",
1085
+ symbol: o.EURC,
1086
+ name: "Euro Coin",
1087
+ decimals: 6,
1088
+ logoURI: "/images/tokens/eurc.png",
1089
+ nativeToken: !1
1090
+ },
1091
+ [o.USDC]: {
1092
+ address: m("0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"),
1093
+ symbol: o.USDC,
1094
+ name: "USD Coin",
1095
+ fiatISO: "USD",
1096
+ decimals: 6,
1097
+ logoURI: "/images/tokens/usdc.svg",
1098
+ logoSourceURI: "https://pay.daimo.com/coin-logos/usdc.png",
1099
+ nativeToken: !1
1100
+ },
1101
+ [o.WETH]: {
1102
+ address: m("0x4200000000000000000000000000000000000006"),
1103
+ symbol: o.WETH,
1104
+ name: "Wrapped Ether",
1105
+ decimals: 18,
1106
+ logoURI: "/images/tokens/weth.png",
1107
+ nativeToken: !1
1108
+ }
1109
+ },
1110
+ [d.BASE_TESTNET]: {
1111
+ [o.USDC]: {
1112
+ address: m("0x036CbD53842c5426634e7929541eC2318f3dCF7e"),
1113
+ symbol: o.USDC,
1114
+ name: "USD Coin",
1115
+ fiatISO: "USD",
1116
+ decimals: 6,
1117
+ logoURI: "/images/tokens/usdc.svg",
1118
+ logoSourceURI: "https://pay.daimo.com/coin-logos/usdc.png",
1119
+ nativeToken: !1
1120
+ }
1121
+ },
1122
+ [d.BSC]: {
1123
+ [o.BNB]: {
1124
+ address: "0x0000000000000000000000000000000000000000",
1125
+ symbol: o.BNB,
1126
+ name: "BNB",
1127
+ decimals: 18,
1128
+ logoURI: "/images/chains/bsc.webp",
1129
+ nativeToken: !0
1130
+ },
1131
+ [o.BUSD]: {
1132
+ address: "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56",
1133
+ symbol: o.BUSD,
1134
+ name: "Binance USD",
1135
+ decimals: 18,
1136
+ logoURI: "/images/tokens/busd.png",
1137
+ nativeToken: !1
1138
+ },
1139
+ [o.DAI]: {
1140
+ address: "0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3",
1141
+ symbol: o.DAI,
1142
+ name: "Dai Stablecoin",
1143
+ decimals: 18,
1144
+ logoURI: "/images/tokens/dai.png",
1145
+ nativeToken: !1
1146
+ },
1147
+ [o.ETH]: {
1148
+ address: "0x2170Ed0880ac9A755fd29B2688956BD959F933F8",
1149
+ symbol: o.ETH,
1150
+ name: "Ethereum",
1151
+ decimals: 18,
1152
+ logoURI: "/images/chains/ethereum.svg",
1153
+ nativeToken: !1
1154
+ },
1155
+ [o.USDC]: {
1156
+ address: m("0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d"),
1157
+ symbol: o.USDC,
1158
+ decimals: 18,
1159
+ name: "USD Coin",
1160
+ logoURI: "/images/tokens/usdc.svg",
1161
+ logoSourceURI: "https://pay.daimo.com/coin-logos/usdc.png",
1162
+ nativeToken: !1
1163
+ },
1164
+ [o.USDT]: {
1165
+ address: "0x55d398326f99059fF775485246999027B3197955",
1166
+ symbol: o.USDT,
1167
+ name: "Tether USD",
1168
+ decimals: 18,
1169
+ logoURI: "/images/tokens/usdt.png",
1170
+ nativeToken: !1
1171
+ }
1172
+ },
1173
+ [d.ETHEREUM]: {
1174
+ [o.BUSD]: {
1175
+ address: "0x4Fabb145d64652a948d72533023f6E7A623C7C53",
1176
+ symbol: o.BUSD,
1177
+ name: "Binance USD",
1178
+ decimals: 18,
1179
+ logoURI: "/images/tokens/busd.png",
1180
+ nativeToken: !1
1181
+ },
1182
+ [o.DAI]: {
1183
+ address: m("0x6B175474E89094C44Da98b954EedeAC495271d0F"),
1184
+ symbol: o.DAI,
1185
+ name: "Dai Stablecoin",
1186
+ decimals: 18,
1187
+ logoURI: "/images/tokens/dai.png",
1188
+ nativeToken: !1
1189
+ },
1190
+ [o.ETH]: {
1191
+ address: "0x0000000000000000000000000000000000000000",
1192
+ symbol: o.ETH,
1193
+ name: "Ethereum",
1194
+ decimals: 18,
1195
+ logoURI: "/images/chains/ethereum.svg",
1196
+ nativeToken: !0
1197
+ },
1198
+ [o.EURC]: {
1199
+ address: "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
1200
+ symbol: o.EURC,
1201
+ name: "Euro Coin",
1202
+ decimals: 6,
1203
+ logoURI: "/images/tokens/eurc.png",
1204
+ nativeToken: !1
1205
+ },
1206
+ [o.STRK]: {
1207
+ address: "0xCa14007Eff0dB1f8135f4C25B34De49AB0d42766",
1208
+ symbol: o.STRK,
1209
+ name: "Starknet Token",
1210
+ decimals: 18,
1211
+ logoURI: "/images/chains/starknet.svg",
1212
+ nativeToken: !1
1213
+ },
1214
+ [o.USDC]: {
1215
+ address: m("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"),
1216
+ symbol: o.USDC,
1217
+ name: "USD Coin",
1218
+ decimals: 6,
1219
+ logoURI: "/images/tokens/usdc.svg",
1220
+ logoSourceURI: "https://pay.daimo.com/coin-logos/usdc.png",
1221
+ nativeToken: !1
1222
+ },
1223
+ [o.USDT]: {
1224
+ address: m("0xdAC17F958D2ee523a2206206994597C13D831ec7"),
1225
+ symbol: o.USDT,
1226
+ name: "Tether USD",
1227
+ decimals: 6,
1228
+ logoURI: "/images/tokens/usdt.png",
1229
+ nativeToken: !1
1230
+ },
1231
+ [o.WETH]: {
1232
+ address: m("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
1233
+ symbol: o.WETH,
1234
+ name: "Wrapped Ether",
1235
+ decimals: 18,
1236
+ logoURI: "/images/tokens/weth.png",
1237
+ nativeToken: !1
1238
+ }
1239
+ },
1240
+ [d.ETHEREUM_TESTNET]: {
1241
+ [o.USDC]: {
1242
+ address: m("0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"),
1243
+ symbol: o.USDC,
1244
+ decimals: 6,
1245
+ name: "USD Coin",
1246
+ logoURI: "/images/tokens/usdc.svg",
1247
+ logoSourceURI: "https://pay.daimo.com/coin-logos/usdc.png",
1248
+ nativeToken: !1
1249
+ }
1250
+ },
1251
+ [d.HYPEREVM]: {
1252
+ [o.USDC]: {
1253
+ address: "0xb88339CB7199b77E23DB6E890353E22632Ba630f",
1254
+ symbol: o.USDC,
1255
+ name: "USD Coin",
1256
+ decimals: 6,
1257
+ logoURI: "/images/tokens/usdc.svg",
1258
+ nativeToken: !1
1259
+ }
1260
+ },
1261
+ [d.LISK]: {
1262
+ [o.USDC]: {
1263
+ address: "0xF242275d3a6527d877f2c927a82D9b057609cc71",
1264
+ symbol: o.USDC,
1265
+ name: "USD Coin",
1266
+ decimals: 6,
1267
+ logoURI: "/images/tokens/usdc.svg",
1268
+ nativeToken: !1
1269
+ }
1270
+ },
1271
+ [d.MONAD]: {
1272
+ [o.USDC]: {
1273
+ address: "0x754704Bc059F8C67012fEd69BC8A327a5aafb603",
1274
+ symbol: o.USDC,
1275
+ name: "USD Coin",
1276
+ decimals: 6,
1277
+ logoURI: "/images/tokens/usdc.svg",
1278
+ nativeToken: !1
1279
+ }
1280
+ },
1281
+ [d.MONAD_TESTNET]: {
1282
+ [o.USDC]: {
1283
+ address: "0x534b2f3A21130d7a60830c2Df862319e593943A3",
1284
+ symbol: o.USDC,
1285
+ name: "USD Coin",
1286
+ decimals: 6,
1287
+ logoURI: "/images/tokens/usdc.svg",
1288
+ nativeToken: !1
1289
+ }
1290
+ },
1291
+ [d.OPTIMISM]: {
1292
+ [o.DAI]: {
1293
+ address: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
1294
+ symbol: o.DAI,
1295
+ name: "Dai Stablecoin",
1296
+ decimals: 18,
1297
+ logoURI: "/images/tokens/dai.png",
1298
+ nativeToken: !1
1299
+ },
1300
+ [o.ETH]: {
1301
+ address: "0x0000000000000000000000000000000000000000",
1302
+ symbol: o.ETH,
1303
+ name: "Ethereum",
1304
+ decimals: 18,
1305
+ logoURI: "/images/chains/ethereum.svg",
1306
+ nativeToken: !0
1307
+ },
1308
+ [o.USDC]: {
1309
+ address: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
1310
+ symbol: o.USDC,
1311
+ name: "USD Coin",
1312
+ decimals: 6,
1313
+ logoURI: "/images/tokens/usdc.svg",
1314
+ nativeToken: !1
1315
+ },
1316
+ [o.USDT]: {
1317
+ address: "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58",
1318
+ symbol: o.USDT,
1319
+ name: "Tether USD",
1320
+ decimals: 6,
1321
+ logoURI: "/images/tokens/usdt.png",
1322
+ nativeToken: !1
1323
+ },
1324
+ [o.WETH]: {
1325
+ address: "0x4200000000000000000000000000000000000006",
1326
+ symbol: o.WETH,
1327
+ name: "Wrapped Ether",
1328
+ decimals: 18,
1329
+ logoURI: "/images/tokens/weth.png",
1330
+ nativeToken: !1
1331
+ }
1332
+ },
1333
+ [d.OPTIMISM_TESTNET]: {
1334
+ [o.USDC]: {
1335
+ address: "0x5fd84259d66Cd46123540766Be93DFE6D43130D7",
1336
+ symbol: o.USDC,
1337
+ name: "USD Coin",
1338
+ decimals: 6,
1339
+ logoURI: "/images/tokens/usdc.svg",
1340
+ nativeToken: !1
1341
+ }
1342
+ },
1343
+ [d.POLYGON]: {
1344
+ [o.DAI]: {
1345
+ address: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
1346
+ symbol: o.DAI,
1347
+ name: "Dai Stablecoin",
1348
+ decimals: 18,
1349
+ logoURI: "/images/tokens/dai.png",
1350
+ nativeToken: !1
1351
+ },
1352
+ [o.USDC]: {
1353
+ address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
1354
+ symbol: o.USDC,
1355
+ name: "USD Coin",
1356
+ decimals: 6,
1357
+ logoURI: "/images/tokens/usdc.svg",
1358
+ nativeToken: !1
1359
+ },
1360
+ [o.USDT]: {
1361
+ address: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
1362
+ symbol: o.USDT,
1363
+ name: "Tether USD",
1364
+ decimals: 6,
1365
+ logoURI: "/images/tokens/usdt.png",
1366
+ nativeToken: !1
1367
+ },
1368
+ [o.WETH]: {
1369
+ address: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
1370
+ symbol: o.WETH,
1371
+ name: "Wrapped Ether",
1372
+ decimals: 18,
1373
+ logoURI: "/images/tokens/weth.png",
1374
+ nativeToken: !1
1375
+ }
1376
+ },
1377
+ [d.STARKNET]: {
1378
+ [o.DAI]: {
1379
+ address: "0x05574eb6b8789a91466f902c380d978e472db68170ff82a5b650b95a58ddf4ad",
1380
+ symbol: o.DAI,
1381
+ name: "Dai Stablecoin",
1382
+ decimals: 18,
1383
+ logoURI: "/images/tokens/dai.png",
1384
+ nativeToken: !1
1385
+ },
1386
+ [o.ETH]: {
1387
+ address: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
1388
+ symbol: o.ETH,
1389
+ name: "Ethereum",
1390
+ decimals: 18,
1391
+ logoURI: "/images/chains/ethereum.svg",
1392
+ nativeToken: !1
1393
+ },
1394
+ [o.LORDS]: {
1395
+ address: "0x0124aeb495b947201f5faC96fD1138E326AD86195B98df6DEc9009158A533B49",
1396
+ symbol: o.LORDS,
1397
+ name: "LORDS Token",
1398
+ decimals: 18,
1399
+ logoURI: "/images/tokens/lords.png",
1400
+ nativeToken: !1
1401
+ },
1402
+ [o.STRK]: {
1403
+ address: "0x04718f5a0Fc34cC1AF16A1cdee98fFB20C31f5cD61D6Ab07201858f4287c938D",
1404
+ symbol: o.STRK,
1405
+ name: "Starknet Token",
1406
+ decimals: 18,
1407
+ logoURI: "/images/chains/starknet.svg",
1408
+ nativeToken: !1
1409
+ },
1410
+ [o.USDC]: {
1411
+ address: "0x033068F6539f8e6e6b131e6B2B814e6c34A5224bC66947c47DaB9dFeE93b35fb",
1412
+ symbol: o.USDC,
1413
+ name: "USD Coin",
1414
+ decimals: 6,
1415
+ logoURI: "/images/tokens/usdc.svg",
1416
+ logoSourceURI: "https://pay.daimo.com/coin-logos/usdc.png",
1417
+ nativeToken: !1
1418
+ },
1419
+ [o.USDT]: {
1420
+ address: "0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8",
1421
+ symbol: o.USDT,
1422
+ name: "Tether USD",
1423
+ decimals: 6,
1424
+ logoURI: "/images/tokens/usdt.png",
1425
+ nativeToken: !1
1426
+ }
1427
+ },
1428
+ [d.STARKNET_TESTNET]: {
1429
+ [o.USDC]: {
1430
+ address: "0x0512feAc6339Ff7889822cb5aA2a86C848e9D392bB0E3E237C008674feeD8343",
1431
+ symbol: o.USDC,
1432
+ name: "USD Coin",
1433
+ decimals: 6,
1434
+ logoURI: "/images/tokens/usdc.svg",
1435
+ nativeToken: !1
1436
+ }
1437
+ }
1438
+ }, _t = new Set(Object.values(d));
1439
+ function g(t) {
1440
+ if (Ft(t))
1441
+ return t;
1442
+ const e = d[t];
1443
+ if (!e)
1444
+ throw new Error(`Invalid chain: ${t}. Chain must be a valid chain alias or internal chain value from Chains.`);
1445
+ return e;
1446
+ }
1447
+ function Ft(t) {
1448
+ return _t.has(t);
1449
+ }
1450
+ function Lt(t, e) {
1451
+ const s = e.toLowerCase().trim(), n = Ae[t];
1452
+ if (!n)
1453
+ throw new Error(
1454
+ `Chain not found: ${t}. The chain key must be a valid chain identifier.`
1455
+ );
1456
+ let i;
1457
+ for (const a in n) {
1458
+ const r = n[a];
1459
+ if (r && r.address.toLowerCase() === s.toLowerCase()) {
1460
+ i = r;
1461
+ break;
1462
+ }
1463
+ }
1464
+ if (!i)
1465
+ throw new Error(
1466
+ `Token address mismatch: address ${e} does not exist on chain ${t}. The token address must be a valid token address on the specified chain.`
1467
+ );
1468
+ return i;
1469
+ }
1470
+ function P(t, e, s) {
1471
+ const n = Lt(t, e);
1472
+ if (n.symbol !== s)
1473
+ throw new Error(
1474
+ `Token address and symbol mismatch: address ${e} on chain ${t} corresponds to token "${n.symbol}", but expected "${s}". The token address must correspond to a token with the expected symbol on the specified chain.`
1475
+ );
1476
+ return n;
1477
+ }
1478
+ function jt(t, e) {
1479
+ return Ae[t]?.[e];
1480
+ }
1481
+ function te(t, e) {
1482
+ return jt(t, e)?.address;
1483
+ }
1484
+ var q = /* @__PURE__ */ ((t) => (t.PRODUCTION = "production", t.STAGING = "staging", t))(q || {});
1485
+ class u {
1486
+ constructor({ api_key: e, env: s, seesion_token: n, props: i }) {
1487
+ this.api_key = e || "", this.sessionToken = n || "", this.env = s ?? q.PRODUCTION, this.props = i;
1488
+ }
1489
+ static async config(e) {
1490
+ if (!u.app) {
1491
+ if (!e)
1492
+ throw new Error("Please provide an api_key");
1493
+ u.app = new u(e);
1494
+ }
1495
+ return e && (e.api_key !== void 0 && (u.app.api_key = e.api_key), e.seesion_token !== void 0 && (u.app.sessionToken = e.seesion_token), e.env !== void 0 && (u.app.env = e.env), e.props !== void 0 && (u.app.props = e.props)), u.app;
1496
+ }
1497
+ static getApiKey() {
1498
+ if (!u.app)
1499
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
1500
+ return u.app.api_key;
1501
+ }
1502
+ static getSessionToken() {
1503
+ if (!u.app)
1504
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
1505
+ return u.app.sessionToken;
1506
+ }
1507
+ static getProps() {
1508
+ if (!u.app)
1509
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
1510
+ return u.app.props;
1511
+ }
1512
+ static getEnv() {
1513
+ if (!u.app)
1514
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
1515
+ return u.app.env === "internal" ? "staging" : u.app.env;
1516
+ }
1517
+ static getBaseUrl() {
1518
+ if (!u.app)
1519
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
1520
+ switch (u.app.env) {
1521
+ case "production":
1522
+ return "https://api.chainrails.io/api/v1";
1523
+ case "staging":
1524
+ return "https://dev.chainrails.io/api/v1";
1525
+ case "internal":
1526
+ return "https://dev.chainrails.io/api/v1";
1527
+ default:
1528
+ return "https://api.chainrails.io/api/v1";
1529
+ }
1530
+ }
1531
+ static getPayModalUrl(e) {
1532
+ if (!u.app)
1533
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
1534
+ const s = u.app.env === "internal" ? "https://chainrails-frontend-git-staging-horus-labs.vercel.app" : "https://app.chainrails.io", n = Number(e), i = e && !isNaN(Number(e)) && n > 0 ? "/pay/" : "/deposit/", a = `${e && !isNaN(Number(e)) && n > 0 ? n * 100 : ""}`;
1535
+ return s + i + a;
1536
+ }
1537
+ }
1538
+ let L = null;
1539
+ function Ht() {
1540
+ L = Ze.create({
1541
+ prefixUrl: u.getBaseUrl(),
1542
+ headers: {
1543
+ "Content-Type": "application/json"
1544
+ },
1545
+ hooks: {
1546
+ beforeRequest: [
1547
+ (t) => {
1548
+ const e = u.getSessionToken() || u.getApiKey();
1549
+ t.headers.set("Authorization", `Bearer ${e}`);
1550
+ }
1551
+ ],
1552
+ afterResponse: [(t, e, s) => s]
1553
+ },
1554
+ retry: {
1555
+ limit: 2
1556
+ }
1557
+ });
1558
+ }
1559
+ function h() {
1560
+ return L || Ht(), L;
1561
+ }
1562
+ class $t {
1563
+ async getById(e) {
1564
+ return await h().get("intents/" + e).json();
1565
+ }
1566
+ async getForSender(e) {
1567
+ return await h().get("intents/user/" + e).json();
1568
+ }
1569
+ async getForAddress(e) {
1570
+ return await h().get("intents/address/" + e).json();
1571
+ }
1572
+ async getForSession(e) {
1573
+ return await h().get("modal/sessions/intents/" + e).json();
1574
+ }
1575
+ async getAll(e) {
1576
+ return await h().get("intents", { searchParams: e }).json();
1577
+ }
1578
+ async create(e) {
1579
+ const s = g(e.source_chain), n = g(e.destination_chain);
1580
+ return await h().post("intents", {
1581
+ json: {
1582
+ ...e,
1583
+ source_chain: s,
1584
+ destination_chain: n
1585
+ }
1586
+ }).json();
1587
+ }
1588
+ async createForSession(e) {
1589
+ const s = g(e.sourceChain);
1590
+ return await h().post("modal/sessions/intents", {
1591
+ json: { ...e, sourceChain: s }
1592
+ }).json();
1593
+ }
1594
+ async update(e, s) {
1595
+ return await h().post("intents", { json: s }).json();
1596
+ }
1597
+ async triggerProcessing(e) {
1598
+ return await h().post(`intents/${e}/trigger-processing`).json();
1599
+ }
1600
+ async triggerProcessingForSession(e) {
1601
+ return await h().post(`modal/sessions/intents/${e}/process`).json();
1602
+ }
1603
+ }
1604
+ class zt {
1605
+ async getFromSpecificBridge(e) {
1606
+ const s = g(e.sourceChain);
1607
+ P(s, e.tokenIn, e.amountSymbol);
1608
+ const n = g(e.destinationChain);
1609
+ return await h().get("quotes/single", {
1610
+ searchParams: {
1611
+ ...e,
1612
+ sourceChain: s,
1613
+ destinationChain: n
1614
+ }
1615
+ }).json();
1616
+ }
1617
+ async getFromAllBridges(e) {
1618
+ const s = g(e.sourceChain);
1619
+ P(s, e.tokenIn, e.amountSymbol);
1620
+ const n = g(e.destinationChain);
1621
+ return await h().get("quotes/multiple", {
1622
+ searchParams: {
1623
+ ...e,
1624
+ sourceChain: s,
1625
+ destinationChain: n
1626
+ }
1627
+ }).json();
1628
+ }
1629
+ async getBestAcrossBridges(e) {
1630
+ const s = g(e.sourceChain);
1631
+ P(s, e.tokenIn, e.amountSymbol);
1632
+ const n = g(e.destinationChain);
1633
+ return await h().get("quotes/best", { searchParams: {
1634
+ ...e,
1635
+ sourceChain: s,
1636
+ destinationChain: n
1637
+ } }).json();
1638
+ }
1639
+ async getAll(e) {
1640
+ const s = g(e.destinationChain);
1641
+ return await h().get("quotes/multi-source", { searchParams: {
1642
+ ...e,
1643
+ destinationChain: s
1644
+ } }).json();
1645
+ }
1646
+ async getAllForSession(e) {
1647
+ return await h().get("modal/sessions/quotes", { searchParams: e }).json();
1648
+ }
1649
+ }
1650
+ class qt {
1651
+ async getOptimalRoutes(e) {
1652
+ const s = g(e.sourceChain), n = g(e.destinationChain);
1653
+ return await h().get("router/optimal-route", {
1654
+ searchParams: {
1655
+ ...e,
1656
+ sourceChain: s,
1657
+ destinationChain: n
1658
+ }
1659
+ }).json();
1660
+ }
1661
+ async getAllSupportedBridges() {
1662
+ return await h().get("router/supported-bridges/all").json();
1663
+ }
1664
+ async getSupportedBridges(e) {
1665
+ const s = g(e.sourceChain), n = g(e.destinationChain);
1666
+ return await h().get("router/supported-bridges/route", { searchParams: {
1667
+ ...e,
1668
+ sourceChain: s,
1669
+ destinationChain: n
1670
+ } }).json();
1671
+ }
1672
+ async getSupportedRoutes(e) {
1673
+ return await h().get("router/supported-routes/bridge/" + e).json();
1674
+ }
1675
+ }
1676
+ class Wt {
1677
+ async getSupported(e) {
1678
+ return await h().get("chains", { searchParams: e }).json();
1679
+ }
1680
+ async getBalance(e) {
1681
+ return await h().get(`chains/balances/${e.address}`, { searchParams: e }).json();
1682
+ }
1683
+ }
1684
+ class Kt {
1685
+ async getClientInfo() {
1686
+ return await h().get("client/auth/client-info").json();
1687
+ }
1688
+ async getClientInfoForSession() {
1689
+ return await h().get("modal/sessions/client").json();
1690
+ }
1691
+ }
1692
+ class Vt {
1693
+ async getSessionToken(e) {
1694
+ const s = g(e.destinationChain);
1695
+ let n = te(s, e.token);
1696
+ n || (console.error(`${e.token} on ${e.destinationChain} is currently unsupported, defaulting to usdc`), n = te(s, "USDC"));
1697
+ const i = {
1698
+ recipient: e.recipient,
1699
+ tokenOut: n,
1700
+ destinationChain: s,
1701
+ amount: e.amount
1702
+ };
1703
+ return h().post("modal/sessions", { json: i }).json().then((a) => ({ ...a, amount: i.amount }));
1704
+ }
1705
+ }
1706
+ const Zt = {
1707
+ router: new qt(),
1708
+ quotes: new zt(),
1709
+ intents: new $t(),
1710
+ chains: new Wt(),
1711
+ client: new Kt(),
1712
+ auth: new Vt()
1713
+ }, Gt = ["light", "dark", "system"], se = "https://app.chainrails.io", ne = "https://chainrails-frontend-git-staging-horus-labs.vercel.app", C = class C extends HTMLElement {
1714
+ constructor() {
1715
+ super(...arguments), this.key = 0, this.initialized = !1, this.iframe = null, this.loader = null, this.themeCss = null, this.previousBodyOverflow = "", this._sessionToken = null, this._env = "production", this._isOpen = !1, this._isPending = !1, this.handleMessage = (e) => {
1716
+ e.data === "closed" && (this.close(), this._onCancel?.(), this.dispatchEvent(new CustomEvent("cancelled"))), e.data === "completed" && (window.setTimeout(() => this.close(), 2e3), this._onSuccess?.(), this.dispatchEvent(new CustomEvent("completed")));
1717
+ };
1718
+ }
1719
+ static get observedAttributes() {
1720
+ return C.observed;
1721
+ }
1722
+ connectedCallback() {
1723
+ this.setup(), this.syncFromAttributes(), this.refreshUi(), window.addEventListener("message", this.handleMessage);
1724
+ }
1725
+ disconnectedCallback() {
1726
+ window.removeEventListener("message", this.handleMessage), this._isOpen && (document.body.style.overflow = this.previousBodyOverflow || "");
1727
+ }
1728
+ attributeChangedCallback(e, s, n) {
1729
+ if (this.initialized) {
1730
+ if (e === "session-token") {
1731
+ this.sessionToken = n;
1732
+ return;
1733
+ }
1734
+ if (e === "amount") {
1735
+ this.amount = n ?? void 0;
1736
+ return;
1737
+ }
1738
+ if (e === "session-url") {
1739
+ this.sessionUrl = n ?? void 0;
1740
+ return;
1741
+ }
1742
+ if (e === "is-open") {
1743
+ this.isOpen = n !== null && n !== "false";
1744
+ return;
1745
+ }
1746
+ if (e === "is-pending") {
1747
+ this.isPending = n !== null && n !== "false";
1748
+ return;
1749
+ }
1750
+ if (e === "env") {
1751
+ this.env = n === "internal" ? "internal" : "production";
1752
+ return;
1753
+ }
1754
+ if (e === "exclude-chains") {
1755
+ this.excludeChains = n ? n.split(",").map((i) => i.trim()).filter(Boolean) : void 0;
1756
+ return;
1757
+ }
1758
+ if (e === "theme" || e === "accent-color") {
1759
+ const i = this.styles || {};
1760
+ this.styles = {
1761
+ ...i,
1762
+ theme: this.getAttribute("theme") ?? i.theme,
1763
+ accentColor: this.getAttribute("accent-color") ?? i.accentColor
1764
+ };
1765
+ }
1766
+ }
1767
+ }
1768
+ get sessionToken() {
1769
+ return this._sessionToken;
1770
+ }
1771
+ set sessionToken(e) {
1772
+ this._sessionToken = e ?? null, this.postAuth();
1773
+ }
1774
+ get amount() {
1775
+ return this._amount;
1776
+ }
1777
+ set amount(e) {
1778
+ this._amount = e, this.key = 0, this.setIframeSrc(), this.refreshUi();
1779
+ }
1780
+ get sessionUrl() {
1781
+ return this._sessionUrl;
1782
+ }
1783
+ set sessionUrl(e) {
1784
+ this._sessionUrl = e;
1785
+ }
1786
+ get styles() {
1787
+ return this._styles;
1788
+ }
1789
+ set styles(e) {
1790
+ this._styles = e, this.resolveThemeCss().finally(() => this.postAuth());
1791
+ }
1792
+ get excludeChains() {
1793
+ return this._excludeChains;
1794
+ }
1795
+ set excludeChains(e) {
1796
+ this._excludeChains = e, this.postAuth();
1797
+ }
1798
+ get env() {
1799
+ return this._env;
1800
+ }
1801
+ set env(e) {
1802
+ this._env = e, this.configureSdk(), this.setIframeSrc(), this.postAuth();
1803
+ }
1804
+ get isOpen() {
1805
+ return this._isOpen;
1806
+ }
1807
+ set isOpen(e) {
1808
+ this._isOpen = !!e, this.refreshUi();
1809
+ }
1810
+ get isPending() {
1811
+ return this._isPending;
1812
+ }
1813
+ set isPending(e) {
1814
+ this._isPending = !!e, this.refreshUi();
1815
+ }
1816
+ get onCancel() {
1817
+ return this._onCancel;
1818
+ }
1819
+ set onCancel(e) {
1820
+ this._onCancel = e;
1821
+ }
1822
+ get onSuccess() {
1823
+ return this._onSuccess;
1824
+ }
1825
+ set onSuccess(e) {
1826
+ this._onSuccess = e;
1827
+ }
1828
+ open() {
1829
+ this.sessionToken || window.setTimeout(() => {
1830
+ this.sessionToken && (this.isOpen = !0);
1831
+ }, 200), this.isOpen = !0;
1832
+ }
1833
+ close() {
1834
+ this.isOpen = !1;
1835
+ }
1836
+ setProps(e) {
1837
+ typeof e.sessionToken < "u" && (this.sessionToken = e.sessionToken), typeof e.amount < "u" && (this.amount = e.amount), typeof e.sessionUrl < "u" && (this.sessionUrl = e.sessionUrl), typeof e.styles < "u" && (this.styles = e.styles), typeof e.excludeChains < "u" && (this.excludeChains = e.excludeChains), typeof e.env < "u" && (this.env = e.env), typeof e.isPending < "u" && (this.isPending = e.isPending), typeof e.isOpen < "u" && (this.isOpen = e.isOpen), typeof e.onCancel < "u" && (this.onCancel = e.onCancel), typeof e.onSuccess < "u" && (this.onSuccess = e.onSuccess);
1838
+ }
1839
+ setup() {
1840
+ this.initialized || (this.classList.add("payment-modal-wrapper"), this.loader = document.createElement("div"), this.loader.className = "payment-modal-loader", this.loader.setAttribute("role", "status"), this.loader.innerHTML = `<svg aria-hidden="true" class="icon" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
1841
+ <path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor" />
1842
+ <path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill" />
1843
+ </svg>`, this.iframe = document.createElement("iframe"), this.iframe.className = "payment-modal invisible", this.iframe.setAttribute("allow", "clipboard-read *; clipboard-write *"), this.iframe.addEventListener("load", () => {
1844
+ this.key = Math.random(), this.refreshUi(), this.postAuth();
1845
+ }), this.appendChild(this.loader), this.appendChild(this.iframe), this.configureSdk(), this.setIframeSrc(), this.initialized = !0);
1846
+ }
1847
+ syncFromAttributes() {
1848
+ this.sessionToken = this.getAttribute("session-token");
1849
+ const e = this.getAttribute("amount");
1850
+ e && (this.amount = e);
1851
+ const s = this.getAttribute("session-url");
1852
+ s && (this.sessionUrl = s), this.isOpen = this.hasAttribute("is-open"), this.isPending = this.hasAttribute("is-pending");
1853
+ const n = this.getAttribute("env");
1854
+ this.env = n === "internal" ? "internal" : "production";
1855
+ const i = this.getAttribute("theme") ?? void 0, a = this.getAttribute("accent-color") ?? void 0;
1856
+ (i || a) && (this.styles = { theme: i, accentColor: a });
1857
+ const r = this.getAttribute("exclude-chains");
1858
+ r && (this.excludeChains = r.split(",").map((c) => c.trim()).filter(Boolean));
1859
+ }
1860
+ configureSdk() {
1861
+ u.config({
1862
+ api_key: "",
1863
+ env: this._env
1864
+ });
1865
+ }
1866
+ setIframeSrc() {
1867
+ this.iframe && (this.iframe.src = u.getPayModalUrl(this._amount));
1868
+ }
1869
+ refreshUi() {
1870
+ const e = this.key === 0 || this._isPending;
1871
+ this.classList.toggle("loading", e), this.classList.toggle("not-loading", !e), this.classList.toggle("open", this._isOpen), this.classList.toggle("closed", !this._isOpen), this.iframe && (this.iframe.classList.toggle("invisible", e), this.iframe.classList.toggle("visible", !e), this.iframe.dataset.id = this._amount ?? ""), this._isOpen ? (this.previousBodyOverflow = document.body.style.overflow, document.body.style.overflow = "hidden") : document.body.style.overflow = this.previousBodyOverflow || "";
1872
+ }
1873
+ async resolveThemeCss() {
1874
+ const e = this._styles?.theme;
1875
+ if (!e || Gt.includes(e)) {
1876
+ this.themeCss = null;
1877
+ return;
1878
+ }
1879
+ try {
1880
+ const s = u.getBaseUrl(), n = await fetch(`${s}/themes/${e}`);
1881
+ if (!n.ok) return;
1882
+ const i = await n.json();
1883
+ i.status === "approved" && i.cssContent && (this.themeCss = i.cssContent);
1884
+ } catch (s) {
1885
+ console.error("Failed to fetch theme:", s);
1886
+ }
1887
+ }
1888
+ postAuth() {
1889
+ if (!this._sessionToken || !this.iframe?.contentWindow) return;
1890
+ const e = {
1891
+ type: "session",
1892
+ session_token: this._sessionToken,
1893
+ environment: u.getEnv() || q.PRODUCTION,
1894
+ styles: this._styles,
1895
+ props: { excludeChains: this._excludeChains?.join(",") },
1896
+ ...this.themeCss ? { css: this.themeCss } : {}
1897
+ };
1898
+ this.iframe.contentWindow.postMessage(e, se), this.iframe.contentWindow.postMessage(e, ne), window.setTimeout(() => {
1899
+ this.iframe?.contentWindow && (this.iframe.contentWindow.postMessage(e, se), this.iframe.contentWindow.postMessage(e, ne));
1900
+ }, 1e3);
1901
+ }
1902
+ };
1903
+ C.tagName = "chainrails-payment-modal", C.observed = [
1904
+ "session-token",
1905
+ "amount",
1906
+ "session-url",
1907
+ "is-open",
1908
+ "is-pending",
1909
+ "theme",
1910
+ "accent-color",
1911
+ "exclude-chains",
1912
+ "env"
1913
+ ];
1914
+ let S = C;
1915
+ function Yt() {
1916
+ customElements.get(S.tagName) || customElements.define(S.tagName, S);
1917
+ }
1918
+ class Jt extends EventTarget {
1919
+ constructor({ session_url: e, onCancel: s, onSuccess: n }) {
1920
+ super(), this.data = null, this.error = null, this.isPending = !1, this.isOpen = !1, this.current = Date.now(), this.retryIntervalId = null, this.sessionUrl = e, this.onCancel = s, this.onSuccess = n;
1921
+ }
1922
+ get sessionToken() {
1923
+ return this.data?.sessionToken ?? null;
1924
+ }
1925
+ get amount() {
1926
+ return this.data?.amount;
1927
+ }
1928
+ get session_url() {
1929
+ return this.sessionUrl;
1930
+ }
1931
+ snapshot() {
1932
+ return {
1933
+ data: this.data,
1934
+ error: this.error,
1935
+ isPending: this.isPending,
1936
+ isOpen: this.isOpen,
1937
+ sessionToken: this.sessionToken,
1938
+ amount: this.amount,
1939
+ session_url: this.sessionUrl
1940
+ };
1941
+ }
1942
+ subscribe(e) {
1943
+ const s = () => e(this.snapshot());
1944
+ return this.addEventListener("change", s), e(this.snapshot()), () => this.removeEventListener("change", s);
1945
+ }
1946
+ open() {
1947
+ this.sessionToken || window.setTimeout(() => {
1948
+ this.sessionToken && this.setOpen(!0);
1949
+ }, 200), this.setOpen(!0);
1950
+ }
1951
+ close() {
1952
+ this.setOpen(!1);
1953
+ }
1954
+ async refetch() {
1955
+ const e = Date.now();
1956
+ this.isPending = !0, this.error = null, this.data = null, this.dispatchChange();
1957
+ try {
1958
+ const n = await (await fetch(this.sessionUrl, {
1959
+ headers: {
1960
+ "Content-Type": "application/json"
1961
+ }
1962
+ })).json();
1963
+ if (e < this.current) return;
1964
+ this.data = n, this.isPending = !1, this.current = e, this.clearRetry(), this.dispatchChange();
1965
+ } catch (s) {
1966
+ if (e < this.current) return;
1967
+ this.error = s?.toString() ?? "Unknown error", this.isPending = !1, this.current = e, this.dispatchChange(), this.retryIntervalId === null && (this.retryIntervalId = window.setInterval(() => {
1968
+ this.refetch();
1969
+ }, 5e3));
1970
+ }
1971
+ }
1972
+ bind(e) {
1973
+ e.setProps({
1974
+ sessionToken: this.sessionToken,
1975
+ amount: this.amount,
1976
+ sessionUrl: this.sessionUrl,
1977
+ isOpen: this.isOpen,
1978
+ isPending: this.isPending,
1979
+ onCancel: () => {
1980
+ this.close(), this.onCancel?.();
1981
+ },
1982
+ onSuccess: () => {
1983
+ this.onSuccess?.();
1984
+ }
1985
+ });
1986
+ const s = this.subscribe((n) => {
1987
+ e.setProps({
1988
+ sessionToken: n.sessionToken,
1989
+ amount: n.amount,
1990
+ isOpen: n.isOpen,
1991
+ isPending: n.isPending
1992
+ });
1993
+ });
1994
+ return () => {
1995
+ s();
1996
+ };
1997
+ }
1998
+ destroy() {
1999
+ this.clearRetry();
2000
+ }
2001
+ setOpen(e) {
2002
+ this.isOpen = e, this.dispatchChange();
2003
+ }
2004
+ dispatchChange() {
2005
+ this.dispatchEvent(new Event("change"));
2006
+ }
2007
+ clearRetry() {
2008
+ this.retryIntervalId !== null && (window.clearInterval(this.retryIntervalId), this.retryIntervalId = null);
2009
+ }
2010
+ }
2011
+ function Qt(t) {
2012
+ const e = new Jt(t);
2013
+ return e.refetch(), e;
2014
+ }
2015
+ function es(t) {
2016
+ return typeof t == "number" && Number.isInteger(t) ? BigInt(t).toString() : String(t);
2017
+ }
2018
+ function ts(t, e) {
2019
+ return Number(t) * Math.pow(10, e);
2020
+ }
2021
+ Yt();
2022
+ export {
2023
+ o as AmountSymbols,
2024
+ u as Chainrails,
2025
+ S as ChainrailsPaymentModalElement,
2026
+ Xt as Chains,
2027
+ Jt as PaymentSessionController,
2028
+ ts as convertToBaseUnits,
2029
+ es as convertToNormalNumber,
2030
+ Zt as crapi,
2031
+ Qt as createPaymentSession,
2032
+ Yt as definePaymentModalElement
2033
+ };