@manifoldxyz/dropkit 0.3.0 → 0.4.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/dist/index.cjs CHANGED
@@ -27,7 +27,8 @@
27
27
 
28
28
 
29
29
 
30
- var _chunkOO6QQT3Mcjs = require('./chunk-OO6QQT3M.cjs');
30
+
31
+ var _chunkX4P6BUV4cjs = require('./chunk-X4P6BUV4.cjs');
31
32
 
32
33
  // src/react/useMint.ts
33
34
  var _react = require('react');
@@ -70,7 +71,7 @@ function revertReason(errorData) {
70
71
  function parseQuote(body, originChainId) {
71
72
  const b = obj(body);
72
73
  const steps = Array.isArray(b.steps) ? b.steps.map(obj) : [];
73
- const unknownStep = () => new (0, _chunkOO6QQT3Mcjs.MintError)("BRIDGE_UNAVAILABLE", "Relay returned a route this button cannot execute.");
74
+ const unknownStep = () => new (0, _chunkX4P6BUV4cjs.MintError)("BRIDGE_UNAVAILABLE", "Relay returned a route this button cannot execute.");
74
75
  if (steps.length !== 1 || steps[0].kind !== "transaction") throw unknownStep();
75
76
  const step = steps[0];
76
77
  const rawItems = Array.isArray(step.items) ? step.items.map(obj) : [];
@@ -83,8 +84,8 @@ function parseQuote(body, originChainId) {
83
84
  });
84
85
  const requestId = _viem.isHex.call(void 0, step.requestId) ? step.requestId : _viem.isHex.call(void 0, b.requestId) ? b.requestId : null;
85
86
  if (!requestId) throw unknownStep();
86
- const details = obj(b.details);
87
- const currencyIn = obj(details.currencyIn);
87
+ const details2 = obj(b.details);
88
+ const currencyIn = obj(details2.currencyIn);
88
89
  const fees = obj(b.fees);
89
90
  const amountIn = moneyOf(currencyIn.amount, currencyIn.currency);
90
91
  if (obj(currencyIn.currency).address !== void 0 && obj(currencyIn.currency).address !== _viem.zeroAddress) throw unknownStep();
@@ -163,21 +164,21 @@ async function requestQuote(a) {
163
164
  body: JSON.stringify(body)
164
165
  }, RELAY_TIMEOUTS.quoteMs);
165
166
  } catch (e) {
166
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("BRIDGE_UNAVAILABLE", "Could not reach Relay for a cross-chain quote.", { cause: e });
167
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("BRIDGE_UNAVAILABLE", "Could not reach Relay for a cross-chain quote.", { cause: e });
167
168
  }
168
169
  const json = res.json;
169
170
  if (res.ok) return parseQuote(json, a.originChainId);
170
171
  const j = obj(json);
171
172
  if (j.errorCode === "DESTINATION_TX_FAILED") {
172
173
  const reason = revertReason(j.errorData);
173
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("SIMULATION_REVERTED", reason || "The mint would fail on the drop network.", { cause: json, domain: "relay" });
174
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("SIMULATION_REVERTED", reason || "The mint would fail on the drop network.", { cause: json, domain: "relay" });
174
175
  }
175
176
  if (res.status === 401 || j.errorCode === "UNAUTHORIZED_QUOTE") {
176
177
  console.warn("dropkit: Relay rejected the quote (401 UNAUTHORIZED_QUOTE). Relay gates quotes that carry a referrer or need an API key.");
177
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("BRIDGE_UNAVAILABLE", "Relay refused the cross-chain quote.", { cause: json });
178
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("BRIDGE_UNAVAILABLE", "Relay refused the cross-chain quote.", { cause: json });
178
179
  }
179
- if (res.status === 429) throw new (0, _chunkOO6QQT3Mcjs.MintError)("RATE_LIMITED", "Relay is rate limiting quotes. Try again in a moment.", { cause: json });
180
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("BRIDGE_UNAVAILABLE", `Relay could not quote this mint (${String(res.status)}).`, { cause: json });
180
+ if (res.status === 429) throw new (0, _chunkX4P6BUV4cjs.MintError)("RATE_LIMITED", "Relay is rate limiting quotes. Try again in a moment.", { cause: json });
181
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("BRIDGE_UNAVAILABLE", `Relay could not quote this mint (${String(res.status)}).`, { cause: json });
181
182
  }
182
183
  function getQuote(a) {
183
184
  const k = cacheKey(a);
@@ -243,12 +244,621 @@ async function pollUntilTerminal(a) {
243
244
  }
244
245
  }
245
246
 
247
+ // src/core/adapters/tl-stacks/index.ts
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+
261
+ // src/core/adapters/tl-stacks/abis.ts
262
+ var DROP_PHASE = { NOT_CONFIGURED: 0, NOT_STARTED: 1, PRESALE: 2, PUBLIC_SALE: 3, ENDED: 4 };
263
+ var SUPPORTED_VERSIONS = ["2.3.0", "2.3.1"];
264
+ var stacksAbi = [
265
+ { type: "function", name: "VERSION", stateMutability: "view", inputs: [], outputs: [{ name: "", type: "string" }] },
266
+ { type: "function", name: "protocolFee", stateMutability: "view", inputs: [], outputs: [{ name: "", type: "uint256" }] },
267
+ {
268
+ type: "function",
269
+ name: "getDrop",
270
+ stateMutability: "view",
271
+ inputs: [{ name: "nftAddress", type: "address" }],
272
+ outputs: [
273
+ {
274
+ name: "",
275
+ type: "tuple",
276
+ components: [
277
+ { name: "dropType", type: "uint8" },
278
+ { name: "payoutReceiver", type: "address" },
279
+ { name: "initialSupply", type: "uint256" },
280
+ { name: "supply", type: "uint256" },
281
+ { name: "allowance", type: "uint256" },
282
+ { name: "currencyAddress", type: "address" },
283
+ { name: "startTime", type: "uint256" },
284
+ { name: "presaleDuration", type: "uint256" },
285
+ { name: "presaleCost", type: "uint256" },
286
+ { name: "presaleMerkleRoot", type: "bytes32" },
287
+ { name: "publicDuration", type: "uint256" },
288
+ { name: "publicCost", type: "uint256" },
289
+ { name: "decayRate", type: "int256" },
290
+ { name: "baseUri", type: "string" }
291
+ ]
292
+ }
293
+ ]
294
+ },
295
+ {
296
+ type: "function",
297
+ name: "getDropPhase",
298
+ stateMutability: "view",
299
+ inputs: [{ name: "nftAddress", type: "address" }],
300
+ outputs: [{ name: "", type: "uint8" }]
301
+ },
302
+ {
303
+ type: "function",
304
+ name: "getNumberMinted",
305
+ stateMutability: "view",
306
+ inputs: [
307
+ { name: "nftAddress", type: "address" },
308
+ { name: "recipient", type: "address" }
309
+ ],
310
+ outputs: [{ name: "", type: "uint256" }]
311
+ },
312
+ {
313
+ type: "function",
314
+ name: "purchase",
315
+ stateMutability: "payable",
316
+ inputs: [
317
+ { name: "nftAddress", type: "address" },
318
+ { name: "recipient", type: "address" },
319
+ { name: "numberToMint", type: "uint256" },
320
+ { name: "presaleNumberCanMint", type: "uint256" },
321
+ { name: "proof", type: "bytes32[]" }
322
+ ],
323
+ outputs: [{ name: "refundAmount", type: "uint256" }]
324
+ },
325
+ { type: "error", name: "MintZeroTokens", inputs: [] },
326
+ { type: "error", name: "NotOnAllowlist", inputs: [] },
327
+ { type: "error", name: "YouShallNotMint", inputs: [] },
328
+ { type: "error", name: "AlreadyReachedMintAllowance", inputs: [] },
329
+ { type: "error", name: "InsufficientFunds", inputs: [] },
330
+ { type: "error", name: "SanctionedAddress", inputs: [] },
331
+ // OpenZeppelin v5 Pausable: purchase is whenNotPaused.
332
+ { type: "error", name: "EnforcedPause", inputs: [] }
333
+ ];
334
+
335
+ // src/core/adapters/tl-stacks/allowlist.ts
336
+
337
+ var HASH = /^0x[0-9a-fA-F]{64}$/;
338
+ var UINT = /^\d+$/;
339
+ var MAX_UINT256 = 2n ** 256n - 1n;
340
+ var unavailable = (message, cause) => new (0, _chunkX4P6BUV4cjs.MintError)("ALLOWLIST_UNAVAILABLE", message, cause === void 0 ? void 0 : { cause });
341
+ var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
342
+ var hashWallet = (wallet) => _viem.keccak256.call(void 0, _viem.encodeAbiParameters.call(void 0, [{ type: "address" }], [_viem.getAddress.call(void 0, wallet)]));
343
+ var leafOf = (hashedWallet, allowance) => _viem.keccak256.call(void 0, _viem.concatHex.call(void 0, [_viem.keccak256.call(void 0, _viem.encodeAbiParameters.call(void 0, [{ type: "bytes32" }, { type: "uint256" }], [hashedWallet, allowance]))]));
344
+ var hashPair = (a, b) => BigInt(a) < BigInt(b) ? _viem.keccak256.call(void 0, _viem.concatHex.call(void 0, [a, b])) : _viem.keccak256.call(void 0, _viem.concatHex.call(void 0, [b, a]));
345
+ var processProof = (leaf, proof) => proof.reduce((node, sibling) => hashPair(node, sibling), leaf);
346
+ function parseAllowlist(body) {
347
+ if (!isRecord(body)) throw unavailable("The allowlist file is not a merkle tree dump.");
348
+ if (body.format !== "standard-v1") throw unavailable("The allowlist file is in an unsupported format.");
349
+ const enc = body.leafEncoding;
350
+ if (!Array.isArray(enc) || enc.length !== 2 || enc[0] !== "bytes32" || enc[1] !== "uint256") {
351
+ throw unavailable("The allowlist file uses an unsupported leaf encoding.");
352
+ }
353
+ const { tree, values } = body;
354
+ if (!Array.isArray(tree) || tree.length === 0 || !tree.every((n) => typeof n === "string" && HASH.test(n))) {
355
+ throw unavailable("The allowlist file has no readable merkle tree.");
356
+ }
357
+ if (!Array.isArray(values)) throw unavailable("The allowlist file has no wallet values.");
358
+ const entries = /* @__PURE__ */ new Map();
359
+ for (const row of values) {
360
+ const value = isRecord(row) ? row.value : void 0;
361
+ const treeIndex = isRecord(row) ? row.treeIndex : void 0;
362
+ if (!Array.isArray(value) || value.length !== 2 || typeof value[0] !== "string" || !HASH.test(value[0])) {
363
+ throw unavailable("The allowlist file has an unreadable wallet entry.");
364
+ }
365
+ const raw = value[1];
366
+ const allowanceText = typeof raw === "string" ? raw : typeof raw === "number" && Number.isSafeInteger(raw) ? String(raw) : "";
367
+ if (!UINT.test(allowanceText) || BigInt(allowanceText) > MAX_UINT256) throw unavailable("The allowlist file has an unreadable allowance.");
368
+ if (typeof treeIndex !== "number") throw unavailable("The allowlist file has an unreadable tree index.");
369
+ const key = value[0].toLowerCase();
370
+ const allowance = BigInt(allowanceText);
371
+ const prev = entries.get(key);
372
+ if (!prev || allowance > prev.allowance) entries.set(key, { allowance, treeIndex });
373
+ }
374
+ return { root: tree[0].toLowerCase(), tree, entries };
375
+ }
376
+ var findEntry = (list, recipient) => _nullishCoalesce(list.entries.get(hashWallet(recipient).toLowerCase()), () => ( null));
377
+ function assertRoot(list, presaleMerkleRoot) {
378
+ if (list.root !== presaleMerkleRoot.toLowerCase()) {
379
+ throw unavailable("The allowlist file does not match this drop. The creator may have updated the allowlist; reload the page.");
380
+ }
381
+ }
382
+ var buildProof = (list, recipient, entry) => buildProofForHash(list, hashWallet(recipient), entry);
383
+ function buildProofForHash(list, hashedWallet, entry) {
384
+ const { tree } = list;
385
+ const { treeIndex } = entry;
386
+ if (!Number.isInteger(treeIndex) || treeIndex < 1 || treeIndex >= tree.length) {
387
+ throw unavailable("The allowlist file has a tree index outside the tree.");
388
+ }
389
+ const leaf = leafOf(hashedWallet, entry.allowance);
390
+ if (tree[treeIndex].toLowerCase() !== leaf.toLowerCase()) throw unavailable("The allowlist file entry does not match its merkle leaf.");
391
+ const proof = [];
392
+ let i = treeIndex;
393
+ while (i > 0) {
394
+ const sibling = i % 2 === 0 ? i - 1 : i + 1;
395
+ const node = tree[sibling];
396
+ if (node === void 0) throw unavailable("The allowlist file has a broken merkle tree.");
397
+ proof.push(node);
398
+ i = Math.floor((i - 1) / 2);
399
+ }
400
+ if (processProof(leaf, proof).toLowerCase() !== list.root) throw unavailable("The allowlist file does not produce a valid proof for this wallet.");
401
+ return proof;
402
+ }
403
+ var scopeCaches = /* @__PURE__ */ new WeakMap();
404
+ function withSignal(p, signal) {
405
+ if (!signal) return p;
406
+ return new Promise((resolve, reject) => {
407
+ const onAbort = () => reject(unavailable("The allowlist request was cancelled.", signal.reason));
408
+ p.then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
409
+ if (signal.aborted) return onAbort();
410
+ signal.addEventListener("abort", onAbort, { once: true });
411
+ });
412
+ }
413
+ var ALLOWLIST_TIMEOUT_MS = 3e4;
414
+ var ALLOWLIST_MAX_BYTES = 10 * 1024 * 1024;
415
+ var tooLarge = () => unavailable(`The allowlist file is larger than ${ALLOWLIST_MAX_BYTES / (1024 * 1024)} MB.`);
416
+ async function readCapped(res) {
417
+ const declared = Number(res.headers.get("content-length"));
418
+ if (Number.isFinite(declared) && declared > ALLOWLIST_MAX_BYTES) throw tooLarge();
419
+ if (!res.body) return "";
420
+ const reader = res.body.getReader();
421
+ const chunks = [];
422
+ let total = 0;
423
+ for (; ; ) {
424
+ const { done, value } = await reader.read();
425
+ if (done) break;
426
+ total += value.byteLength;
427
+ if (total > ALLOWLIST_MAX_BYTES) {
428
+ void reader.cancel().catch(() => void 0);
429
+ throw tooLarge();
430
+ }
431
+ chunks.push(value);
432
+ }
433
+ const bytes = new Uint8Array(total);
434
+ let offset = 0;
435
+ for (const c of chunks) {
436
+ bytes.set(c, offset);
437
+ offset += c.byteLength;
438
+ }
439
+ return new TextDecoder().decode(bytes);
440
+ }
441
+ async function fetchAndParse(fetchFn, url, signal) {
442
+ let res;
443
+ try {
444
+ signal.throwIfAborted();
445
+ res = await fetchFn(url, { signal });
446
+ } catch (cause) {
447
+ throw unavailable("Could not reach the allowlist file.", cause);
448
+ }
449
+ if (res.status === 429) throw new (0, _chunkX4P6BUV4cjs.MintError)("RATE_LIMITED", "The allowlist host is rate limiting requests. Try again shortly.");
450
+ if (!res.ok) throw unavailable(`The allowlist file is not available (HTTP ${res.status}).`);
451
+ let body;
452
+ try {
453
+ const text = await readCapped(res);
454
+ body = JSON.parse(text);
455
+ } catch (cause) {
456
+ if (cause instanceof _chunkX4P6BUV4cjs.MintError) throw cause;
457
+ throw unavailable("The allowlist file could not be read.", cause);
458
+ }
459
+ return parseAllowlist(body);
460
+ }
461
+ async function download(fetchFn, url, signal) {
462
+ const controller = new AbortController();
463
+ let onAbort;
464
+ const stopped = new Promise((_, reject) => {
465
+ onAbort = () => {
466
+ const reason = controller.signal.reason;
467
+ reject(reason instanceof _chunkX4P6BUV4cjs.MintError ? reason : unavailable("The allowlist request was cancelled.", reason));
468
+ };
469
+ controller.signal.addEventListener("abort", onAbort, { once: true });
470
+ });
471
+ const onLifetimeAbort = () => controller.abort(_optionalChain([signal, 'optionalAccess', _12 => _12.reason]));
472
+ if (_optionalChain([signal, 'optionalAccess', _13 => _13.aborted])) onLifetimeAbort();
473
+ else _optionalChain([signal, 'optionalAccess', _14 => _14.addEventListener, 'call', _15 => _15("abort", onLifetimeAbort, { once: true })]);
474
+ const timer = setTimeout(
475
+ () => controller.abort(unavailable(`The allowlist file did not load within ${ALLOWLIST_TIMEOUT_MS / 1e3} seconds. Try again.`)),
476
+ ALLOWLIST_TIMEOUT_MS
477
+ );
478
+ try {
479
+ return await Promise.race([fetchAndParse(fetchFn, url, controller.signal), stopped]);
480
+ } finally {
481
+ clearTimeout(timer);
482
+ if (onAbort) controller.signal.removeEventListener("abort", onAbort);
483
+ _optionalChain([signal, 'optionalAccess', _16 => _16.removeEventListener, 'call', _17 => _17("abort", onLifetimeAbort)]);
484
+ }
485
+ }
486
+ function loadAllowlist(args) {
487
+ if (!args.url) {
488
+ return Promise.reject(unavailable("This presale has no allowlist file configured (allowlistUrl). Ask the creator to add it."));
489
+ }
490
+ if (_optionalChain([args, 'access', _18 => _18.signal, 'optionalAccess', _19 => _19.aborted])) return Promise.reject(unavailable("The allowlist request was cancelled.", args.signal.reason));
491
+ const fetchFn = _nullishCoalesce(args.fetch, () => ( ((input, init) => globalThis.fetch(input, init))));
492
+ let scoped = scopeCaches.get(args.scope);
493
+ if (!scoped || _optionalChain([scoped, 'access', _20 => _20.signal, 'optionalAccess', _21 => _21.aborted])) {
494
+ scoped = { signal: args.signal, loads: /* @__PURE__ */ new Map() };
495
+ scopeCaches.set(args.scope, scoped);
496
+ }
497
+ const cache2 = scoped;
498
+ const hit = cache2.loads.get(args.url);
499
+ if (hit) return hit;
500
+ const url = args.url;
501
+ const p = withSignal(download(fetchFn, url, cache2.signal), cache2.signal);
502
+ cache2.loads.set(url, p);
503
+ p.catch(() => {
504
+ if (cache2.loads.get(url) === p) cache2.loads.delete(url);
505
+ });
506
+ return p;
507
+ }
508
+
509
+ // src/core/adapters/tl-stacks/index.ts
510
+ var FALLBACK_GAS_BASE = 150000n;
511
+ var FALLBACK_GAS_PER_TOKEN = 150000n;
512
+ var details = /* @__PURE__ */ new WeakMap();
513
+ function bad(field, message) {
514
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("INVALID_CONFIG", `${field} ${message}`, { field });
515
+ }
516
+ function validateTlStacksConfig(config) {
517
+ if (!Number.isInteger(config.chainId) || config.chainId <= 0) bad("chainId", "must be a positive integer");
518
+ if (typeof config.stacks !== "string" || !_viem.isAddress.call(void 0, config.stacks, { strict: false })) bad("stacks", "is not a valid address");
519
+ if (typeof config.nftContract !== "string" || !_viem.isAddress.call(void 0, config.nftContract, { strict: false })) bad("nftContract", "is not a valid address");
520
+ if (config.allowlistUrl !== void 0) {
521
+ const https = (() => {
522
+ try {
523
+ return typeof config.allowlistUrl === "string" && new URL(config.allowlistUrl).protocol === "https:";
524
+ } catch (e2) {
525
+ return false;
526
+ }
527
+ })();
528
+ if (!https) bad("allowlistUrl", "must be an https: URL");
529
+ }
530
+ }
531
+ var abortError = () => new DOMException("The operation was aborted", "AbortError");
532
+ var isAbortError = (e) => _optionalChain([e, 'optionalAccess', _22 => _22.name]) === "AbortError";
533
+ function throwIfAborted(ctx) {
534
+ if (_optionalChain([ctx, 'access', _23 => _23.signal, 'optionalAccess', _24 => _24.aborted])) throw abortError();
535
+ }
536
+ function io(ctx, start) {
537
+ const signal = ctx.signal;
538
+ if (!signal) return start();
539
+ if (signal.aborted) return Promise.reject(abortError());
540
+ return new Promise((resolve, reject) => {
541
+ const onAbort = () => reject(abortError());
542
+ signal.addEventListener("abort", onAbort, { once: true });
543
+ start().then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
544
+ });
545
+ }
546
+ var shortMessage = (e) => e instanceof _viem.BaseError ? e.shortMessage : e instanceof Error ? e.message : String(e);
547
+ function rpcError(e) {
548
+ if (_chunkX4P6BUV4cjs.isMintError.call(void 0, e) || isAbortError(e)) throw e;
549
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("RPC_ERROR", `RPC request failed: ${shortMessage(e)}`, { cause: e });
550
+ }
551
+ async function readStacks(ctx, config, functionName, args = []) {
552
+ try {
553
+ return await io(
554
+ ctx,
555
+ () => ctx.client.readContract({ address: _viem.getAddress.call(void 0, config.stacks), abi: stacksAbi, functionName, args })
556
+ );
557
+ } catch (e) {
558
+ if (_chunkX4P6BUV4cjs.isMintError.call(void 0, e) || isAbortError(e)) throw e;
559
+ if (e instanceof _viem.BaseError && e.walk((x) => x instanceof _viem.ContractFunctionRevertedError || x instanceof _viem.ContractFunctionZeroDataError)) {
560
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("INVALID_CONFIG", `stacks ${functionName}() reverted or returned no data. Is ${config.stacks} a TL Stacks 721 contract on chain ${config.chainId}?`, {
561
+ field: "stacks",
562
+ cause: e
563
+ });
564
+ }
565
+ return rpcError(e);
566
+ }
567
+ }
568
+ var versions = /* @__PURE__ */ new WeakMap();
569
+ async function checkVersion(ctx, config) {
570
+ const load = () => readStacks(ctx, config, "VERSION");
571
+ let version;
572
+ if (ctx.cacheScope) {
573
+ let byStacks = versions.get(ctx.cacheScope);
574
+ if (!byStacks) versions.set(ctx.cacheScope, byStacks = /* @__PURE__ */ new Map());
575
+ const key = `${config.chainId}:${config.stacks.toLowerCase()}`;
576
+ const cache2 = byStacks;
577
+ let hit = cache2.get(key);
578
+ if (!hit) {
579
+ const p = load();
580
+ cache2.set(key, hit = p);
581
+ p.catch(() => {
582
+ if (cache2.get(key) === p) cache2.delete(key);
583
+ });
584
+ }
585
+ version = hit;
586
+ } else {
587
+ version = load();
588
+ }
589
+ const v = await version;
590
+ if (!SUPPORTED_VERSIONS.includes(v)) {
591
+ bad("stacks", `is TL Stacks ${v}. Dropkit supports ${SUPPORTED_VERSIONS.join(" and ")} only.`);
592
+ }
593
+ }
594
+ var money = (value, decimals, symbol) => ({ value, decimals, symbol, formatted: _viem.formatUnits.call(void 0, value, decimals) });
595
+ function nativeMeta(ctx) {
596
+ const n = _optionalChain([ctx, 'access', _25 => _25.client, 'access', _26 => _26.chain, 'optionalAccess', _27 => _27.nativeCurrency]);
597
+ return { decimals: _nullishCoalesce(_optionalChain([n, 'optionalAccess', _28 => _28.decimals]), () => ( 18)), symbol: _nullishCoalesce(_optionalChain([n, 'optionalAccess', _29 => _29.symbol]), () => ( "ETH")) };
598
+ }
599
+ function seconds(v, field) {
600
+ if (v > BigInt(Number.MAX_SAFE_INTEGER)) throw new (0, _chunkX4P6BUV4cjs.MintError)("INVALID_CONFIG", `${field} is too large for a unix timestamp`, { field });
601
+ return Number(v);
602
+ }
603
+ function priceFor(drop, phase) {
604
+ const presalePrice = phase === DROP_PHASE.PRESALE || phase === DROP_PHASE.NOT_STARTED && drop.presaleDuration > 0n;
605
+ return { presalePrice, unitPrice: presalePrice ? drop.presaleCost : drop.publicCost };
606
+ }
607
+ async function readDrop(ctx, config) {
608
+ validateTlStacksConfig(config);
609
+ throwIfAborted(ctx);
610
+ await checkVersion(ctx, config);
611
+ const nft = _viem.getAddress.call(void 0, config.nftContract);
612
+ const [drop, phaseRaw, fee] = await Promise.all([
613
+ readStacks(ctx, config, "getDrop", [nft]),
614
+ readStacks(ctx, config, "getDropPhase", [nft]),
615
+ readStacks(ctx, config, "protocolFee")
616
+ ]);
617
+ const phase = Number(phaseRaw);
618
+ if (phase === DROP_PHASE.NOT_CONFIGURED) {
619
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("DROP_NOT_FOUND", "No Transient Labs drop is configured for this NFT contract on this chain.");
620
+ }
621
+ if (drop.currencyAddress !== _viem.zeroAddress) {
622
+ bad("nftContract", `is sold for an ERC-20 (${drop.currencyAddress}). Dropkit supports drops priced in the native token only.`);
623
+ }
624
+ const { presalePrice, unitPrice } = priceFor(drop, phase);
625
+ const startTime = seconds(drop.startTime, "startTime");
626
+ const presaleEnd = seconds(drop.startTime + drop.presaleDuration, "presaleDuration");
627
+ const soldOut = drop.supply === 0n;
628
+ const neverMintable = drop.initialSupply === 0n;
629
+ const native = nativeMeta(ctx);
630
+ const info = {
631
+ chainId: config.chainId,
632
+ unitPrice: money(unitPrice, native.decimals, native.symbol),
633
+ unitFee: money(fee, native.decimals, native.symbol),
634
+ totalMinted: drop.initialSupply - drop.supply,
635
+ maxSupply: drop.initialSupply,
636
+ // A never-mintable drop has no start either, so the hook clock has no boundary ahead to tick towards (review F13).
637
+ startTime: neverMintable || startTime === 0 ? null : startTime,
638
+ // At supply 0 the drop is sold out for good: no end time, so it never turns into `ended` (D14).
639
+ endTime: neverMintable ? 0 : soldOut ? null : seconds(drop.startTime + drop.presaleDuration + drop.publicDuration, "publicDuration"),
640
+ isAllowlist: phase === DROP_PHASE.PRESALE,
641
+ paymentToken: null,
642
+ pricePer: "unit",
643
+ phaseEndsAt: presalePrice ? presaleEnd : null,
644
+ walletKey: `${phase}:${drop.presaleMerkleRoot}:${unitPrice}:${fee}`
645
+ };
646
+ details.set(info, {
647
+ phase,
648
+ presaleMerkleRoot: drop.presaleMerkleRoot,
649
+ allowance: drop.allowance,
650
+ presaleDuration: drop.presaleDuration,
651
+ publicDuration: drop.publicDuration,
652
+ startTime: drop.startTime
653
+ });
654
+ return info;
655
+ }
656
+ async function detailOf(ctx, config, drop) {
657
+ const hit = details.get(drop);
658
+ if (hit) return hit;
659
+ const nft = _viem.getAddress.call(void 0, config.nftContract);
660
+ const [raw, phase] = await Promise.all([
661
+ readStacks(ctx, config, "getDrop", [nft]),
662
+ readStacks(ctx, config, "getDropPhase", [nft])
663
+ ]);
664
+ return {
665
+ phase: Number(phase),
666
+ presaleMerkleRoot: raw.presaleMerkleRoot,
667
+ allowance: raw.allowance,
668
+ presaleDuration: raw.presaleDuration,
669
+ publicDuration: raw.publicDuration,
670
+ startTime: raw.startTime
671
+ };
672
+ }
673
+ var dayTime = (unix) => new Date(unix * 1e3).toLocaleString(void 0, { dateStyle: "medium", timeStyle: "short" });
674
+ function notOnAllowlist(d) {
675
+ const opens = Number(d.startTime + d.presaleDuration);
676
+ const message = d.publicDuration > 0n ? `This wallet is not on the allowlist. The public sale opens ${dayTime(opens)}.` : "This wallet is not on the allowlist. This drop is allowlist only.";
677
+ return { reason: "NOT_ON_ALLOWLIST", message };
678
+ }
679
+ async function readWallet(ctx, config, { payer, recipient, quantity, drop }) {
680
+ validateTlStacksConfig(config);
681
+ throwIfAborted(ctx);
682
+ const detail = await detailOf(ctx, config, drop);
683
+ const nft = _viem.getAddress.call(void 0, config.nftContract);
684
+ const presale = detail.phase === DROP_PHASE.PRESALE;
685
+ const [minted, native, gasPrice, list] = await Promise.all([
686
+ readStacks(ctx, config, "getNumberMinted", [nft, _viem.getAddress.call(void 0, recipient)]),
687
+ io(ctx, () => ctx.client.getBalance({ address: payer })).catch(rpcError),
688
+ io(ctx, () => ctx.client.getGasPrice()).catch(rpcError),
689
+ presale ? loadAllowlist({ scope: _nullishCoalesce(ctx.cacheScope, () => ( drop)), url: config.allowlistUrl, fetch: ctx.fetch, signal: ctx.signal }) : Promise.resolve(null)
690
+ ]);
691
+ let walletMax = detail.allowance;
692
+ let proof = [];
693
+ let presaleNumberCanMint = 0n;
694
+ let ineligible = null;
695
+ let allowlistRemaining = null;
696
+ if (presale && list) {
697
+ assertRoot(list, detail.presaleMerkleRoot);
698
+ const entry = findEntry(list, recipient);
699
+ if (!entry) {
700
+ walletMax = 0n;
701
+ ineligible = notOnAllowlist(detail);
702
+ } else {
703
+ walletMax = entry.allowance;
704
+ presaleNumberCanMint = entry.allowance;
705
+ proof = buildProof(list, recipient, entry);
706
+ }
707
+ }
708
+ const remaining = walletMax > minted ? walletMax - minted : 0n;
709
+ if (presale && ineligible === null) {
710
+ allowlistRemaining = Number(remaining < BigInt(_chunkX4P6BUV4cjs.MAX_QUANTITY) ? remaining : BigInt(_chunkX4P6BUV4cjs.MAX_QUANTITY));
711
+ if (remaining === 0n) ineligible = { reason: "ALLOWLIST_USED", message: `This wallet has already minted its allowlist allocation of ${walletMax}.` };
712
+ } else if (!presale && remaining === 0n) {
713
+ ineligible = { reason: "WALLET_LIMIT", message: `This wallet has already minted its limit of ${walletMax}.` };
714
+ }
715
+ const maxQuantity = Number(remaining < BigInt(_chunkX4P6BUV4cjs.MAX_QUANTITY) ? remaining : BigInt(_chunkX4P6BUV4cjs.MAX_QUANTITY));
716
+ const data = { presaleNumberCanMint, proof, unitPrice: drop.unitPrice.value, unitFee: drop.unitFee.value };
717
+ const qty = BigInt(quantity);
718
+ const value = qty * (data.unitPrice + data.unitFee);
719
+ let gas = FALLBACK_GAS_BASE + FALLBACK_GAS_PER_TOKEN * qty;
720
+ const open = detail.phase === DROP_PHASE.PRESALE || detail.phase === DROP_PHASE.PUBLIC_SALE;
721
+ if (open && ineligible === null && native >= value) {
722
+ try {
723
+ const estimated = await io(
724
+ ctx,
725
+ () => ctx.client.estimateGas({ account: payer, to: _viem.getAddress.call(void 0, config.stacks), data: encodePurchase(config, recipient, qty, data), value })
726
+ );
727
+ gas = estimated;
728
+ } catch (e) {
729
+ if (isAbortError(e)) throw e;
730
+ }
731
+ }
732
+ return {
733
+ walletMinted: minted,
734
+ walletMax,
735
+ allowlistRemaining,
736
+ maxQuantity,
737
+ ineligible,
738
+ balances: { native, erc20: null },
739
+ gasReserve: gas * gasPrice,
740
+ data
741
+ };
742
+ }
743
+ function encodePurchase(config, recipient, quantity, data) {
744
+ return _viem.encodeFunctionData.call(void 0, {
745
+ abi: stacksAbi,
746
+ functionName: "purchase",
747
+ args: [_viem.getAddress.call(void 0, config.nftContract), _viem.getAddress.call(void 0, recipient), quantity, data.presaleNumberCanMint, [...data.proof]]
748
+ });
749
+ }
750
+ function walletData(wallet) {
751
+ const d = wallet.data;
752
+ if (!d || typeof d.presaleNumberCanMint !== "bigint" || typeof d.unitPrice !== "bigint" || typeof d.unitFee !== "bigint" || !Array.isArray(d.proof)) {
753
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("RPC_ERROR", "The wallet read is missing the data this mint needs. Reload and try again.");
754
+ }
755
+ return d;
756
+ }
757
+ async function buildPlan(ctx, attempt, wallet) {
758
+ const { config, recipient } = attempt;
759
+ validateTlStacksConfig(config);
760
+ throwIfAborted(ctx);
761
+ if (!Number.isInteger(attempt.quantity) || attempt.quantity < 1) {
762
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("SIMULATION_REVERTED", "Choose at least one token to mint.");
763
+ }
764
+ const data = walletData(wallet);
765
+ const qty = BigInt(attempt.quantity);
766
+ return {
767
+ approve: null,
768
+ mint: {
769
+ to: _viem.getAddress.call(void 0, config.stacks),
770
+ data: encodePurchase(config, recipient, qty, data),
771
+ value: qty * (data.unitPrice + data.unitFee)
772
+ },
773
+ tokenContract: _viem.getAddress.call(void 0, config.nftContract)
774
+ };
775
+ }
776
+ var TL_MESSAGES = {
777
+ NotOnAllowlist: "This wallet is not on the allowlist for the current sale.",
778
+ YouShallNotMint: "This drop is not open for minting right now.",
779
+ AlreadyReachedMintAllowance: "This wallet has already minted its limit.",
780
+ InsufficientFunds: "The price or fee changed since the page loaded, so the payment is too low. Reload the page and try again.",
781
+ MintZeroTokens: "Choose at least one token to mint.",
782
+ SanctionedAddress: "This wallet or the recipient is blocked by a sanctions check, so it cannot mint.",
783
+ EnforcedPause: "Minting is paused by Transient Labs right now. Try again later."
784
+ };
785
+ function revertData(e) {
786
+ for (let cur = e, depth = 0; cur && depth < 12; depth++) {
787
+ const d = cur.data;
788
+ if (typeof d === "string" && d.startsWith("0x") && d.length >= 10) return d;
789
+ if (d && typeof d === "object" && typeof d.data === "string") {
790
+ const inner = d.data;
791
+ if (inner.startsWith("0x") && inner.length >= 10) return inner;
792
+ }
793
+ cur = cur.cause;
794
+ }
795
+ return null;
796
+ }
797
+ function decodeTlRevert(e) {
798
+ if (_chunkX4P6BUV4cjs.isMintError.call(void 0, e)) return e;
799
+ if (isAbortError(e)) throw e;
800
+ if (e instanceof _viem.BaseError && e.walk((x) => x instanceof _viem.InsufficientFundsError)) {
801
+ return new (0, _chunkX4P6BUV4cjs.MintError)("INSUFFICIENT_FUNDS", `The wallet cannot cover the mint: ${e.shortMessage}`, { cause: e });
802
+ }
803
+ const data = revertData(e);
804
+ if (data) {
805
+ try {
806
+ const { errorName, args } = _viem.decodeErrorResult.call(void 0, { abi: stacksAbi, data });
807
+ const known = TL_MESSAGES[errorName];
808
+ if (known) return new (0, _chunkX4P6BUV4cjs.MintError)("SIMULATION_REVERTED", known, { cause: e, domain: "tl-stacks" });
809
+ const shown = (_nullishCoalesce(args, () => ( []))).map(String).join(", ");
810
+ return new (0, _chunkX4P6BUV4cjs.MintError)("SIMULATION_REVERTED", `Transient Labs rejected the mint (${errorName}(${shown})).`, { cause: e, domain: "tl-stacks" });
811
+ } catch (e3) {
812
+ return new (0, _chunkX4P6BUV4cjs.MintError)("SIMULATION_REVERTED", `Transient Labs rejected the mint (unrecognized error ${data.slice(0, 10)}).`, { cause: e, domain: "tl-stacks" });
813
+ }
814
+ }
815
+ const reverted = e instanceof _viem.BaseError && e.walk((x) => x.code === 3 || /execution reverted/i.test(x.message));
816
+ if (reverted) return new (0, _chunkX4P6BUV4cjs.MintError)("SIMULATION_REVERTED", shortMessage(e), { cause: e });
817
+ return new (0, _chunkX4P6BUV4cjs.MintError)("RPC_ERROR", `RPC request failed: ${shortMessage(e)}`, { cause: e });
818
+ }
819
+ async function simulate(ctx, attempt, plan) {
820
+ throwIfAborted(ctx);
821
+ const { config } = attempt;
822
+ const nft = _viem.getAddress.call(void 0, config.nftContract);
823
+ const [drop, phaseRaw, fee] = await Promise.all([
824
+ readStacks(ctx, config, "getDrop", [nft]),
825
+ readStacks(ctx, config, "getDropPhase", [nft]),
826
+ readStacks(ctx, config, "protocolFee")
827
+ ]);
828
+ if (drop.currencyAddress !== _viem.zeroAddress) {
829
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("SIMULATION_REVERTED", "This drop is now sold for a token instead of the native currency, so it cannot be minted here. Reload the page.", { domain: "tl-stacks" });
830
+ }
831
+ const current = BigInt(attempt.quantity) * (priceFor(drop, Number(phaseRaw)).unitPrice + fee);
832
+ if (current !== plan.mint.value) {
833
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("SIMULATION_REVERTED", TL_MESSAGES.InsufficientFunds, { domain: "tl-stacks" });
834
+ }
835
+ try {
836
+ await io(ctx, () => ctx.client.call({ account: attempt.payer, to: plan.mint.to, data: plan.mint.data, value: plan.mint.value }));
837
+ } catch (e) {
838
+ throw decodeTlRevert(e);
839
+ }
840
+ }
841
+ var tlStacksAdapter = { readDrop, readWallet, buildPlan, simulate };
842
+
246
843
  // src/core/relay/outstanding.ts
247
844
  var memory = /* @__PURE__ */ new Map();
248
845
  var claimed = /* @__PURE__ */ new Set();
846
+ function targetOf(config) {
847
+ switch (config.type) {
848
+ case "manifold-claim":
849
+ return `${config.creatorContract.toLowerCase()}:${config.instanceId}`;
850
+ case "contract":
851
+ return config.address.toLowerCase();
852
+ case "tl-stacks":
853
+ return `stacks:${config.nftContract.toLowerCase()}`;
854
+ default: {
855
+ const unreachable = config;
856
+ return unreachable;
857
+ }
858
+ }
859
+ }
249
860
  function outstandingKey(config, payer) {
250
- const target = config.type === "manifold-claim" ? `${config.creatorContract.toLowerCase()}:${config.instanceId}` : config.address.toLowerCase();
251
- return `${String(config.chainId)}:${target}:${payer.toLowerCase()}`;
861
+ return `${String(config.chainId)}:${targetOf(config)}:${payer.toLowerCase()}`;
252
862
  }
253
863
  var getOutstanding = (key) => _nullishCoalesce(memory.get(key), () => ( null));
254
864
  var setOutstanding = (key, out) => void memory.set(key, out);
@@ -287,8 +897,8 @@ var APPROVE_GAS = 65000n;
287
897
  var PLACEHOLDER_TOKEN = /\{[A-Za-z_]\w*\}/g;
288
898
  var DISPLAY_AMOUNT = /^\d+(\.\d+)?$/;
289
899
  var NUMERIC_TYPE = /^u?int\d*$/;
290
- function bad(field, message) {
291
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("INVALID_CONFIG", `${field} ${message}`, { field });
900
+ function bad2(field, message) {
901
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("INVALID_CONFIG", `${field} ${message}`, { field });
292
902
  }
293
903
  var isHexAddress = (a) => typeof a === "string" && _viem.isAddress.call(void 0, a, { strict: false });
294
904
  function functionsNamed(abi, name) {
@@ -297,15 +907,15 @@ function functionsNamed(abi, name) {
297
907
  function validateTemplate(t, path, allowed) {
298
908
  if (typeof t === "string") {
299
909
  for (const token of _nullishCoalesce(t.match(PLACEHOLDER_TOKEN), () => ( []))) {
300
- if (!PLACEHOLDERS.includes(token)) bad(path, `"${t}" is not a known placeholder (${token})`);
301
- if (!allowed.includes(token)) bad(path, `"${t}" uses ${token}, which is not available in this field`);
910
+ if (!PLACEHOLDERS.includes(token)) bad2(path, `"${t}" is not a known placeholder (${token})`);
911
+ if (!allowed.includes(token)) bad2(path, `"${t}" uses ${token}, which is not available in this field`);
302
912
  }
303
913
  } else if (Array.isArray(t)) {
304
914
  t.forEach((x, i) => validateTemplate(x, `${path}[${i}]`, allowed));
305
915
  } else if (typeof t === "number") {
306
- if (!Number.isSafeInteger(t)) bad(path, `${t} is not a safe integer; pass larger or fractional values as a bigint or decimal string`);
916
+ if (!Number.isSafeInteger(t)) bad2(path, `${t} is not a safe integer; pass larger or fractional values as a bigint or decimal string`);
307
917
  } else if (typeof t !== "bigint" && typeof t !== "boolean") {
308
- bad(path, "must be a string, number, bigint, boolean or array");
918
+ bad2(path, "must be a string, number, bigint, boolean or array");
309
919
  }
310
920
  }
311
921
  var ARRAY_TYPE = /^(.*)\[(\d*)\]$/;
@@ -373,15 +983,15 @@ var NO_PLACEHOLDERS = [];
373
983
  function validateCall(abi, call, prefix, kind, allowed) {
374
984
  const c = _nullishCoalesce(call, () => ( {}));
375
985
  const named = typeof c.functionName === "string" ? functionsNamed(abi, c.functionName) : [];
376
- if (named.length === 0) bad(`${prefix}.functionName`, `"${String(c.functionName)}" is not a function in the abi`);
377
- if (c.args !== void 0 && !Array.isArray(c.args)) bad(`${prefix}.args`, "must be an array");
378
- if (kind === "mint" && c.args === void 0) bad(`${prefix}.args`, "is required");
986
+ if (named.length === 0) bad2(`${prefix}.functionName`, `"${String(c.functionName)}" is not a function in the abi`);
987
+ if (c.args !== void 0 && !Array.isArray(c.args)) bad2(`${prefix}.args`, "must be an array");
988
+ if (kind === "mint" && c.args === void 0) bad2(`${prefix}.args`, "is required");
379
989
  const args = _nullishCoalesce(c.args, () => ( []));
380
990
  args.forEach((a, i) => validateTemplate(a, `${prefix}.args[${i}]`, allowed));
381
991
  const sameArity = named.filter((f) => f.inputs.length === args.length);
382
992
  if (sameArity.length === 0) {
383
993
  const want = [...new Set(named.map((f) => f.inputs.length))].join(" or ");
384
- bad(`${prefix}.args`, `has ${args.length} argument(s) but "${String(c.functionName)}" takes ${want}`);
994
+ bad2(`${prefix}.args`, `has ${args.length} argument(s) but "${String(c.functionName)}" takes ${want}`);
385
995
  }
386
996
  const checked = sameArity.map((f) => {
387
997
  let issue = null;
@@ -391,75 +1001,75 @@ function validateCall(abi, call, prefix, kind, allowed) {
391
1001
  const fits = checked.filter((x) => !x.issue);
392
1002
  if (fits.length === 0) {
393
1003
  const first = checked[0].issue;
394
- if (sameArity.length === 1) bad(first.path, first.message);
395
- bad(`${prefix}.args`, `fit none of the overloads ${sameArity.map(signature).join(", ")}: ${first.path} ${first.message}`);
1004
+ if (sameArity.length === 1) bad2(first.path, first.message);
1005
+ bad2(`${prefix}.args`, `fit none of the overloads ${sameArity.map(signature).join(", ")}: ${first.path} ${first.message}`);
396
1006
  }
397
1007
  const roleFits = fits.filter(
398
1008
  ({ f }) => kind === "read" ? f.stateMutability === "view" || f.stateMutability === "pure" : f.stateMutability === "payable" || f.stateMutability === "nonpayable"
399
1009
  );
400
1010
  if (roleFits.length === 0) {
401
1011
  const name = fits[0].f.name;
402
- if (kind === "read") bad(`${prefix}.functionName`, `"${name}" is not a view or pure function`);
1012
+ if (kind === "read") bad2(`${prefix}.functionName`, `"${name}" is not a view or pure function`);
403
1013
  if (fits.some(({ f }) => f.stateMutability !== "view" && f.stateMutability !== "pure")) {
404
- bad(`${prefix}.functionName`, `"${name}" has missing or invalid stateMutability; mint requires payable or nonpayable`);
1014
+ bad2(`${prefix}.functionName`, `"${name}" has missing or invalid stateMutability; mint requires payable or nonpayable`);
405
1015
  }
406
- bad(`${prefix}.functionName`, `"${name}" is a view or pure function and cannot mint`);
1016
+ bad2(`${prefix}.functionName`, `"${name}" is a view or pure function and cannot mint`);
407
1017
  }
408
1018
  if (roleFits.length > 1) {
409
- bad(`${prefix}.functionName`, `"${String(c.functionName)}" is ambiguous: ${roleFits.map((x) => signature(x.f)).join(" and ")} both accept these arguments`);
1019
+ bad2(`${prefix}.functionName`, `"${String(c.functionName)}" is ambiguous: ${roleFits.map((x) => signature(x.f)).join(" and ")} both accept these arguments`);
410
1020
  }
411
1021
  return roleFits[0].f;
412
1022
  }
413
1023
  function resolveOutput(fn, output, path) {
414
1024
  const outs = fn.outputs;
415
- if (outs.length === 0) bad(`${path}.functionName`, `"${fn.name}" returns nothing`);
1025
+ if (outs.length === 0) bad2(`${path}.functionName`, `"${fn.name}" returns nothing`);
416
1026
  const first = outs[0];
417
1027
  const tuple = outs.length === 1 && first.type === "tuple";
418
1028
  const members = tuple ? _nullishCoalesce(first.components, () => ( [])) : outs;
419
1029
  const memberNames = members.map((m, i) => m.name || String(i)).join(", ");
420
1030
  let index;
421
1031
  if (output === void 0) {
422
- if (members.length !== 1) bad(`${path}.output`, `is required: "${fn.name}" returns several values (${memberNames})`);
1032
+ if (members.length !== 1) bad2(`${path}.output`, `is required: "${fn.name}" returns several values (${memberNames})`);
423
1033
  index = 0;
424
1034
  } else if (typeof output === "number") {
425
1035
  if (!Number.isInteger(output) || output < 0 || output >= members.length) {
426
- bad(`${path}.output`, `${output} is not in the abi outputs of "${fn.name}" (${memberNames})`);
1036
+ bad2(`${path}.output`, `${output} is not in the abi outputs of "${fn.name}" (${memberNames})`);
427
1037
  }
428
1038
  index = output;
429
1039
  } else if (typeof output === "string") {
430
1040
  index = members.findIndex((m) => m.name === output);
431
- if (index < 0) bad(`${path}.output`, `"${output}" is not in the abi outputs of "${fn.name}" (${memberNames})`);
1041
+ if (index < 0) bad2(`${path}.output`, `"${output}" is not in the abi outputs of "${fn.name}" (${memberNames})`);
432
1042
  } else {
433
- return bad(`${path}.output`, "must be an index or a name");
1043
+ return bad2(`${path}.output`, "must be an index or a name");
434
1044
  }
435
1045
  const type = members[index].type;
436
1046
  if (!NUMERIC_TYPE.test(type)) {
437
1047
  const reason = `returns ${type}, not a number`;
438
- if (output === void 0) bad(`${path}.functionName`, `"${fn.name}" ${reason}`);
439
- bad(`${path}.output`, `selects a value that is ${type}, not a number`);
1048
+ if (output === void 0) bad2(`${path}.functionName`, `"${fn.name}" ${reason}`);
1049
+ bad2(`${path}.output`, `selects a value that is ${type}, not a number`);
440
1050
  }
441
1051
  return { tuple, index, type };
442
1052
  }
443
1053
  function validateField(abi, name, src, allowed, isPrice) {
444
- if (typeof src !== "object" || src === null) bad(name, "is required and must be { value } or { read }");
1054
+ if (typeof src !== "object" || src === null) bad2(name, "is required and must be { value } or { read }");
445
1055
  const s = src;
446
1056
  const hasRead = Object.hasOwn(s, "read");
447
1057
  const hasValue = Object.hasOwn(s, "value");
448
- if (hasRead && hasValue) bad(name, "must be exactly one of { value } or { read }, not both");
1058
+ if (hasRead && hasValue) bad2(name, "must be exactly one of { value } or { read }, not both");
449
1059
  if (hasRead) {
450
- if (typeof s.read !== "object" || s.read === null) bad(`${name}.read`, "must be { functionName, args?, output? }");
451
- if (s.unit !== void 0) bad(name, "unit is only valid with a string value");
1060
+ if (typeof s.read !== "object" || s.read === null) bad2(`${name}.read`, "must be { functionName, args?, output? }");
1061
+ if (s.unit !== void 0) bad2(name, "unit is only valid with a string value");
452
1062
  const fn = validateCall(abi, s.read, `${name}.read`, "read", allowed);
453
1063
  resolveOutput(fn, s.read.output, `${name}.read`);
454
1064
  } else if (typeof s.value === "bigint") {
455
- if (s.unit !== void 0) bad(name, "unit is only valid with a string value");
456
- if (s.value < 0n) bad(`${name}.value`, "must not be negative");
1065
+ if (s.unit !== void 0) bad2(name, "unit is only valid with a string value");
1066
+ if (s.value < 0n) bad2(`${name}.value`, "must not be negative");
457
1067
  } else if (typeof s.value === "string") {
458
- if (s.unit !== "display") bad(name, 'string values need unit: "display"');
459
- if (!isPrice) bad(name, "display units are only valid for price; use a bigint in base units");
460
- if (!DISPLAY_AMOUNT.test(s.value)) bad(`${name}.value`, `"${s.value}" is not a decimal number like "0.01"`);
1068
+ if (s.unit !== "display") bad2(name, 'string values need unit: "display"');
1069
+ if (!isPrice) bad2(name, "display units are only valid for price; use a bigint in base units");
1070
+ if (!DISPLAY_AMOUNT.test(s.value)) bad2(`${name}.value`, `"${s.value}" is not a decimal number like "0.01"`);
461
1071
  } else {
462
- bad(name, 'must be { value: bigint }, { value: string, unit: "display" } (price only) or { read: {...} }');
1072
+ bad2(name, 'must be { value: bigint }, { value: string, unit: "display" } (price only) or { read: {...} }');
463
1073
  }
464
1074
  }
465
1075
  function hasNonzeroStaticPrice(price) {
@@ -469,27 +1079,27 @@ function hasNonzeroStaticPrice(price) {
469
1079
  }
470
1080
  function validateContractConfig(config) {
471
1081
  const c = config;
472
- if (!c || typeof c !== "object") bad("config", "must be an object");
473
- if (c.type !== "contract") bad("type", 'must be "contract"');
474
- if (!Number.isSafeInteger(c.chainId) || c.chainId <= 0) bad("chainId", "must be a positive safe integer");
475
- if (!isHexAddress(c.address)) bad("address", `"${String(c.address)}" is not a valid address`);
1082
+ if (!c || typeof c !== "object") bad2("config", "must be an object");
1083
+ if (c.type !== "contract") bad2("type", 'must be "contract"');
1084
+ if (!Number.isSafeInteger(c.chainId) || c.chainId <= 0) bad2("chainId", "must be a positive safe integer");
1085
+ if (!isHexAddress(c.address)) bad2("address", `"${String(c.address)}" is not a valid address`);
476
1086
  if (c.tokenContract !== void 0 && !isHexAddress(c.tokenContract)) {
477
- bad("tokenContract", `"${String(c.tokenContract)}" is not a valid address`);
1087
+ bad2("tokenContract", `"${String(c.tokenContract)}" is not a valid address`);
478
1088
  }
479
- if (!Array.isArray(c.abi)) bad("abi", "must be an abi array");
1089
+ if (!Array.isArray(c.abi)) bad2("abi", "must be an abi array");
480
1090
  const abi = c.abi;
481
1091
  const mintFn = validateCall(abi, c.mint, "mint", "mint", PLACEHOLDERS);
482
- if (c.price === void 0 || c.price === null) bad("price", "is required");
1092
+ if (c.price === void 0 || c.price === null) bad2("price", "is required");
483
1093
  validateField(abi, "price", c.price, NO_PLACEHOLDERS, true);
484
1094
  const cur = c.price.currency;
485
1095
  if (cur !== "native" && !(typeof cur === "object" && cur !== null && isHexAddress(cur.address))) {
486
- bad("price.currency", 'must be "native" or { address } with a valid ERC20 address');
1096
+ bad2("price.currency", 'must be "native" or { address } with a valid ERC20 address');
487
1097
  }
488
1098
  if (cur === "native" && mintFn.stateMutability === "nonpayable" && hasNonzeroStaticPrice(c.price)) {
489
- bad("price", `is a native price, but "${mintFn.name}" is nonpayable and cannot take value`);
1099
+ bad2("price", `is a native price, but "${mintFn.name}" is nonpayable and cannot take value`);
490
1100
  }
491
1101
  const per = c.price.per;
492
- if (per !== void 0 && per !== "unit" && per !== "total") bad("price.per", 'must be "unit" or "total"');
1102
+ if (per !== void 0 && per !== "unit" && per !== "total") bad2("price.per", 'must be "unit" or "total"');
493
1103
  validateOptional(abi, "totalMinted", c.totalMinted, NO_PLACEHOLDERS);
494
1104
  validateOptional(abi, "maxSupply", c.maxSupply, NO_PLACEHOLDERS);
495
1105
  validateOptional(abi, "startTime", c.startTime, NO_PLACEHOLDERS);
@@ -503,7 +1113,7 @@ function validateOptional(abi, name, src, allowed) {
503
1113
  function varFor(token, vars) {
504
1114
  const key = token.slice(1, -1);
505
1115
  const v = vars[key];
506
- if (v === void 0) throw new (0, _chunkOO6QQT3Mcjs.MintError)("INVALID_CONFIG", `placeholder ${token} has no value here`);
1116
+ if (v === void 0) throw new (0, _chunkX4P6BUV4cjs.MintError)("INVALID_CONFIG", `placeholder ${token} has no value here`);
507
1117
  return typeof v === "string" ? _viem.getAddress.call(void 0, v) : v;
508
1118
  }
509
1119
  function fill(t, p, vars) {
@@ -519,46 +1129,46 @@ function fill(t, p, vars) {
519
1129
  }
520
1130
  var fillArgs = (args, inputs, vars) => (_nullishCoalesce(args, () => ( []))).map((a, i) => fill(a, inputs[i], vars));
521
1131
  var totalFor = (per, price, quantity) => per === "total" ? price : price * quantity;
522
- function shortMessage(e) {
1132
+ function shortMessage2(e) {
523
1133
  return e instanceof _viem.BaseError ? e.shortMessage : e instanceof Error ? e.message : String(e);
524
1134
  }
525
- var abortError = () => new DOMException("The operation was aborted", "AbortError");
526
- var isAbortError = (e) => _optionalChain([e, 'optionalAccess', _12 => _12.name]) === "AbortError";
527
- function throwIfAborted(ctx) {
528
- if (_optionalChain([ctx, 'access', _13 => _13.signal, 'optionalAccess', _14 => _14.aborted])) throw abortError();
1135
+ var abortError2 = () => new DOMException("The operation was aborted", "AbortError");
1136
+ var isAbortError2 = (e) => _optionalChain([e, 'optionalAccess', _30 => _30.name]) === "AbortError";
1137
+ function throwIfAborted2(ctx) {
1138
+ if (_optionalChain([ctx, 'access', _31 => _31.signal, 'optionalAccess', _32 => _32.aborted])) throw abortError2();
529
1139
  }
530
- function io(ctx, start) {
1140
+ function io2(ctx, start) {
531
1141
  const signal = ctx.signal;
532
1142
  if (!signal) return start();
533
- if (signal.aborted) return Promise.reject(abortError());
1143
+ if (signal.aborted) return Promise.reject(abortError2());
534
1144
  return new Promise((resolve, reject) => {
535
- const onAbort = () => reject(abortError());
1145
+ const onAbort = () => reject(abortError2());
536
1146
  signal.addEventListener("abort", onAbort, { once: true });
537
1147
  start().then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
538
1148
  });
539
1149
  }
540
- function rpcError(e) {
541
- if (_chunkOO6QQT3Mcjs.isMintError.call(void 0, e) || isAbortError(e)) throw e;
542
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("RPC_ERROR", `RPC request failed: ${shortMessage(e)}`, { cause: e });
1150
+ function rpcError2(e) {
1151
+ if (_chunkX4P6BUV4cjs.isMintError.call(void 0, e) || isAbortError2(e)) throw e;
1152
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("RPC_ERROR", `RPC request failed: ${shortMessage2(e)}`, { cause: e });
543
1153
  }
544
1154
  function classifyReadError(e, field) {
545
- if (_chunkOO6QQT3Mcjs.isMintError.call(void 0, e) || isAbortError(e)) throw e;
1155
+ if (_chunkX4P6BUV4cjs.isMintError.call(void 0, e) || isAbortError2(e)) throw e;
546
1156
  if (e instanceof _viem.BaseError && e.walk((x) => x instanceof _viem.ContractFunctionRevertedError || x instanceof _viem.ContractFunctionZeroDataError)) {
547
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("INVALID_CONFIG", `${field} read reverted or returned no data: ${e.shortMessage}`, { field, cause: e });
1157
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("INVALID_CONFIG", `${field} read reverted or returned no data: ${e.shortMessage}`, { field, cause: e });
548
1158
  }
549
- return rpcError(e);
1159
+ return rpcError2(e);
550
1160
  }
551
1161
  async function readCall(ctx, params, field) {
552
1162
  try {
553
- return await io(ctx, () => ctx.client.readContract(params));
1163
+ return await io2(ctx, () => ctx.client.readContract(params));
554
1164
  } catch (e) {
555
1165
  return classifyReadError(e, field);
556
1166
  }
557
1167
  }
558
1168
  function toBigInt(v, field) {
559
1169
  const n = typeof v === "number" ? BigInt(v) : v;
560
- if (typeof n !== "bigint") throw new (0, _chunkOO6QQT3Mcjs.MintError)("INVALID_CONFIG", `${field} did not return a number`, { field });
561
- if (n < 0n) throw new (0, _chunkOO6QQT3Mcjs.MintError)("INVALID_CONFIG", `${field} returned a negative number`, { field });
1170
+ if (typeof n !== "bigint") throw new (0, _chunkX4P6BUV4cjs.MintError)("INVALID_CONFIG", `${field} did not return a number`, { field });
1171
+ if (n < 0n) throw new (0, _chunkX4P6BUV4cjs.MintError)("INVALID_CONFIG", `${field} returned a negative number`, { field });
562
1172
  return n;
563
1173
  }
564
1174
  async function readField(ctx, config, name, src, vars) {
@@ -574,43 +1184,43 @@ async function readField(ctx, config, name, src, vars) {
574
1184
  }
575
1185
  const value = src.value;
576
1186
  if (typeof value === "bigint") return value;
577
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("INVALID_CONFIG", `${name} display units are only valid for price`, { field: name });
1187
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("INVALID_CONFIG", `${name} display units are only valid for price`, { field: name });
578
1188
  }
579
1189
  function tupleMembers(res, fn, index) {
580
1190
  if (Array.isArray(res)) return res;
581
1191
  const comps = _nullishCoalesce(fn.outputs[0].components, () => ( []));
582
1192
  const out = [];
583
- out[index] = res[_nullishCoalesce(_optionalChain([comps, 'access', _15 => _15[index], 'optionalAccess', _16 => _16.name]), () => ( ""))];
1193
+ out[index] = res[_nullishCoalesce(_optionalChain([comps, 'access', _33 => _33[index], 'optionalAccess', _34 => _34.name]), () => ( ""))];
584
1194
  return out;
585
1195
  }
586
1196
  var optField = (ctx, config, name, src, vars) => src ? readField(ctx, config, name, src, vars) : Promise.resolve(null);
587
1197
  function toSeconds(v, field) {
588
1198
  if (v === null || v === 0n) return null;
589
- if (v > BigInt(Number.MAX_SAFE_INTEGER)) throw new (0, _chunkOO6QQT3Mcjs.MintError)("INVALID_CONFIG", `${field} is too large for a unix timestamp`, { field });
1199
+ if (v > BigInt(Number.MAX_SAFE_INTEGER)) throw new (0, _chunkX4P6BUV4cjs.MintError)("INVALID_CONFIG", `${field} is too large for a unix timestamp`, { field });
590
1200
  return Number(v);
591
1201
  }
592
- function nativeMeta(ctx) {
593
- const n = _optionalChain([ctx, 'access', _17 => _17.client, 'access', _18 => _18.chain, 'optionalAccess', _19 => _19.nativeCurrency]);
594
- return { decimals: _nullishCoalesce(_optionalChain([n, 'optionalAccess', _20 => _20.decimals]), () => ( 18)), symbol: _nullishCoalesce(_optionalChain([n, 'optionalAccess', _21 => _21.symbol]), () => ( "ETH")) };
1202
+ function nativeMeta2(ctx) {
1203
+ const n = _optionalChain([ctx, 'access', _35 => _35.client, 'access', _36 => _36.chain, 'optionalAccess', _37 => _37.nativeCurrency]);
1204
+ return { decimals: _nullishCoalesce(_optionalChain([n, 'optionalAccess', _38 => _38.decimals]), () => ( 18)), symbol: _nullishCoalesce(_optionalChain([n, 'optionalAccess', _39 => _39.symbol]), () => ( "ETH")) };
595
1205
  }
596
1206
  var erc20Of = (config) => config.price.currency === "native" ? null : _viem.getAddress.call(void 0, config.price.currency.address);
597
1207
  async function currencyMeta(ctx, config) {
598
1208
  const token = erc20Of(config);
599
- if (!token) return { token, ...nativeMeta(ctx) };
1209
+ if (!token) return { token, ...nativeMeta2(ctx) };
600
1210
  const field = "price.currency.address";
601
1211
  const [symbol, decimals] = await Promise.all([
602
1212
  readCall(ctx, { address: token, abi: ERC20_ABI, functionName: "symbol" }, field),
603
1213
  readCall(ctx, { address: token, abi: ERC20_ABI, functionName: "decimals" }, field)
604
1214
  ]);
605
1215
  if (typeof symbol !== "string" || typeof decimals !== "number") {
606
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("INVALID_CONFIG", `${field} ${token} is not an ERC20 (symbol/decimals unreadable)`, { field });
1216
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("INVALID_CONFIG", `${field} ${token} is not an ERC20 (symbol/decimals unreadable)`, { field });
607
1217
  }
608
1218
  return { token, decimals, symbol };
609
1219
  }
610
1220
  function parseDisplay(value, decimals) {
611
1221
  const frac = _nullishCoalesce(value.split(".")[1], () => ( ""));
612
1222
  if (frac.length > decimals) {
613
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("INVALID_CONFIG", `price.value "${value}" has more than ${decimals} decimal places`, { field: "price.value" });
1223
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("INVALID_CONFIG", `price.value "${value}" has more than ${decimals} decimal places`, { field: "price.value" });
614
1224
  }
615
1225
  return _viem.parseUnits.call(void 0, value, decimals);
616
1226
  }
@@ -621,13 +1231,13 @@ async function resolvePrice(ctx, config, meta) {
621
1231
  if (typeof value === "bigint") return value;
622
1232
  return parseDisplay(value, (await _asyncNullishCoalesce(meta, async () => ( await currencyMeta(ctx, config)))).decimals);
623
1233
  }
624
- var money = (value, decimals, symbol) => ({
1234
+ var money2 = (value, decimals, symbol) => ({
625
1235
  value,
626
1236
  decimals,
627
1237
  symbol,
628
1238
  formatted: _viem.formatUnits.call(void 0, value, decimals)
629
1239
  });
630
- function revertData(e) {
1240
+ function revertData2(e) {
631
1241
  for (let cur = e, depth = 0; cur && depth < 12; depth++) {
632
1242
  const d = cur.data;
633
1243
  if (typeof d === "string" && d.startsWith("0x") && d.length >= 10) return d;
@@ -644,28 +1254,28 @@ function describeRevert(abi, data) {
644
1254
  const d = _viem.decodeErrorResult.call(void 0, { abi, data });
645
1255
  const args = _nullishCoalesce(d.args, () => ( []));
646
1256
  if (d.errorName === "Error") return String(_nullishCoalesce(args[0], () => ( "execution reverted")));
647
- const inputs = _nullishCoalesce(_optionalChain([d, 'access', _22 => _22.abiItem, 'optionalAccess', _23 => _23.inputs]), () => ( []));
648
- const shown = args.map((a, i) => _optionalChain([inputs, 'access', _24 => _24[i], 'optionalAccess', _25 => _25.name]) ? `${inputs[i].name}: ${String(a)}` : String(a));
1257
+ const inputs = _nullishCoalesce(_optionalChain([d, 'access', _40 => _40.abiItem, 'optionalAccess', _41 => _41.inputs]), () => ( []));
1258
+ const shown = args.map((a, i) => _optionalChain([inputs, 'access', _42 => _42[i], 'optionalAccess', _43 => _43.name]) ? `${inputs[i].name}: ${String(a)}` : String(a));
649
1259
  return `${d.errorName}(${shown.join(", ")})`;
650
- } catch (e2) {
1260
+ } catch (e4) {
651
1261
  return `reverted with unrecognized error ${data.slice(0, 10)}`;
652
1262
  }
653
1263
  }
654
1264
  function toSimulationError(e, abi) {
655
- if (_chunkOO6QQT3Mcjs.isMintError.call(void 0, e)) return e;
656
- if (isAbortError(e)) throw e;
1265
+ if (_chunkX4P6BUV4cjs.isMintError.call(void 0, e)) return e;
1266
+ if (isAbortError2(e)) throw e;
657
1267
  if (e instanceof _viem.BaseError && e.walk((x) => x instanceof _viem.InsufficientFundsError)) {
658
- return new (0, _chunkOO6QQT3Mcjs.MintError)("INSUFFICIENT_FUNDS", `Payer cannot cover the mint: ${e.shortMessage}`, { cause: e });
1268
+ return new (0, _chunkX4P6BUV4cjs.MintError)("INSUFFICIENT_FUNDS", `Payer cannot cover the mint: ${e.shortMessage}`, { cause: e });
659
1269
  }
660
- const data = revertData(e);
661
- if (data) return new (0, _chunkOO6QQT3Mcjs.MintError)("SIMULATION_REVERTED", describeRevert(abi, data), { cause: e });
1270
+ const data = revertData2(e);
1271
+ if (data) return new (0, _chunkX4P6BUV4cjs.MintError)("SIMULATION_REVERTED", describeRevert(abi, data), { cause: e });
662
1272
  const isRevert = e instanceof _viem.BaseError && e.walk((x) => x.code === 3 || /execution reverted/i.test(x.message));
663
- if (isRevert) return new (0, _chunkOO6QQT3Mcjs.MintError)("SIMULATION_REVERTED", shortMessage(e), { cause: e });
664
- return new (0, _chunkOO6QQT3Mcjs.MintError)("RPC_ERROR", `RPC request failed: ${shortMessage(e)}`, { cause: e });
1273
+ if (isRevert) return new (0, _chunkX4P6BUV4cjs.MintError)("SIMULATION_REVERTED", shortMessage2(e), { cause: e });
1274
+ return new (0, _chunkX4P6BUV4cjs.MintError)("RPC_ERROR", `RPC request failed: ${shortMessage2(e)}`, { cause: e });
665
1275
  }
666
1276
  async function simulateMint(ctx, config, call) {
667
1277
  try {
668
- await io(ctx, () => ctx.client.call({ account: call.payer, to: call.to, data: call.data, value: call.value }));
1278
+ await io2(ctx, () => ctx.client.call({ account: call.payer, to: call.to, data: call.data, value: call.value }));
669
1279
  } catch (e) {
670
1280
  throw toSimulationError(e, config.abi);
671
1281
  }
@@ -675,22 +1285,22 @@ function encodeMint(config, vars) {
675
1285
  try {
676
1286
  return _viem.encodeFunctionData.call(void 0, { abi: [fn], functionName: fn.name, args: fillArgs(config.mint.args, fn.inputs, vars) });
677
1287
  } catch (e) {
678
- if (_chunkOO6QQT3Mcjs.isMintError.call(void 0, e)) throw e;
679
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("INVALID_CONFIG", `mint.args cannot be encoded for ${signature(fn)}: ${shortMessage(e)}`, { field: "mint.args", cause: e });
1288
+ if (_chunkX4P6BUV4cjs.isMintError.call(void 0, e)) throw e;
1289
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("INVALID_CONFIG", `mint.args cannot be encoded for ${signature(fn)}: ${shortMessage2(e)}`, { field: "mint.args", cause: e });
680
1290
  }
681
1291
  }
682
1292
  function mintValue(config, token, totalPrice) {
683
1293
  if (token) return 0n;
684
1294
  const fn = validateCall(config.abi, config.mint, "mint", "mint", PLACEHOLDERS);
685
1295
  if (fn.stateMutability === "nonpayable") {
686
- if (totalPrice > 0n) bad("price", `is ${totalPrice} wei in native currency, but "${fn.name}" is nonpayable and cannot take value`);
1296
+ if (totalPrice > 0n) bad2("price", `is ${totalPrice} wei in native currency, but "${fn.name}" is nonpayable and cannot take value`);
687
1297
  return 0n;
688
1298
  }
689
1299
  return totalPrice;
690
1300
  }
691
- async function readDrop(ctx, config) {
1301
+ async function readDrop2(ctx, config) {
692
1302
  validateContractConfig(config);
693
- throwIfAborted(ctx);
1303
+ throwIfAborted2(ctx);
694
1304
  const meta = await currencyMeta(ctx, config);
695
1305
  const none = {};
696
1306
  const [price, totalMinted, maxSupply, start, end] = await Promise.all([
@@ -701,11 +1311,11 @@ async function readDrop(ctx, config) {
701
1311
  optField(ctx, config, "endTime", config.endTime, none)
702
1312
  ]);
703
1313
  mintValue(config, meta.token, price);
704
- const native = nativeMeta(ctx);
1314
+ const native = nativeMeta2(ctx);
705
1315
  return {
706
1316
  chainId: config.chainId,
707
- unitPrice: money(price, meta.decimals, meta.symbol),
708
- unitFee: money(0n, native.decimals, native.symbol),
1317
+ unitPrice: money2(price, meta.decimals, meta.symbol),
1318
+ unitFee: money2(0n, native.decimals, native.symbol),
709
1319
  totalMinted: _nullishCoalesce(totalMinted, () => ( 0n)),
710
1320
  maxSupply: maxSupply === null || maxSupply === 0n ? null : maxSupply,
711
1321
  startTime: toSeconds(start, "startTime"),
@@ -715,9 +1325,9 @@ async function readDrop(ctx, config) {
715
1325
  pricePer: _nullishCoalesce(config.price.per, () => ( "unit"))
716
1326
  };
717
1327
  }
718
- async function readWallet(ctx, config, { payer, recipient, quantity, drop }) {
1328
+ async function readWallet2(ctx, config, { payer, recipient, quantity, drop }) {
719
1329
  validateContractConfig(config);
720
- throwIfAborted(ctx);
1330
+ throwIfAborted2(ctx);
721
1331
  const qty = BigInt(quantity);
722
1332
  const unitPrice = drop.unitPrice.value;
723
1333
  const totalPrice = totalFor(drop.pricePer, unitPrice, qty);
@@ -725,14 +1335,14 @@ async function readWallet(ctx, config, { payer, recipient, quantity, drop }) {
725
1335
  const [walletMinted, rawMax, native, erc20] = await Promise.all([
726
1336
  optField(ctx, config, "walletMinted", config.walletMinted, vars),
727
1337
  optField(ctx, config, "walletMax", config.walletMax, vars),
728
- io(ctx, () => ctx.client.getBalance({ address: payer })).catch(rpcError),
1338
+ io2(ctx, () => ctx.client.getBalance({ address: payer })).catch(rpcError2),
729
1339
  drop.paymentToken ? readCall(ctx, { address: drop.paymentToken, abi: ERC20_ABI, functionName: "balanceOf", args: [payer] }, "price.currency.address").then(
730
1340
  (v) => toBigInt(v, "price.currency.address")
731
1341
  ) : Promise.resolve(null)
732
1342
  ]);
733
1343
  const walletMax = rawMax === null || rawMax === 0n ? null : rawMax;
734
1344
  const remaining = walletMax === null ? null : walletMax > (_nullishCoalesce(walletMinted, () => ( 0n))) ? walletMax - (_nullishCoalesce(walletMinted, () => ( 0n))) : 0n;
735
- const maxQuantity = remaining === null ? null : Number(remaining < BigInt(_chunkOO6QQT3Mcjs.MAX_QUANTITY) ? remaining : BigInt(_chunkOO6QQT3Mcjs.MAX_QUANTITY));
1345
+ const maxQuantity = remaining === null ? null : Number(remaining < BigInt(_chunkX4P6BUV4cjs.MAX_QUANTITY) ? remaining : BigInt(_chunkX4P6BUV4cjs.MAX_QUANTITY));
736
1346
  let ineligible = null;
737
1347
  let gas = FALLBACK_MINT_GAS;
738
1348
  if (remaining === 0n) {
@@ -741,16 +1351,16 @@ async function readWallet(ctx, config, { payer, recipient, quantity, drop }) {
741
1351
  const call = { payer, to: _viem.getAddress.call(void 0, config.address), data: encodeMint(config, vars), value: mintValue(config, null, totalPrice) };
742
1352
  try {
743
1353
  await simulateMint(ctx, config, call);
744
- gas = await io(ctx, () => ctx.client.estimateGas({ account: payer, to: call.to, data: call.data, value: call.value })).catch((e) => {
1354
+ gas = await io2(ctx, () => ctx.client.estimateGas({ account: payer, to: call.to, data: call.data, value: call.value })).catch((e) => {
745
1355
  throw toSimulationError(e, config.abi);
746
1356
  });
747
1357
  } catch (e) {
748
- if (!_chunkOO6QQT3Mcjs.isMintError.call(void 0, e) || e.reason !== "SIMULATION_REVERTED") throw e;
1358
+ if (!_chunkX4P6BUV4cjs.isMintError.call(void 0, e) || e.reason !== "SIMULATION_REVERTED") throw e;
749
1359
  ineligible = { reason: "SIMULATION_REVERTED", message: e.message };
750
1360
  }
751
1361
  }
752
1362
  if (drop.paymentToken) gas += APPROVE_GAS;
753
- const gasPrice = await io(ctx, () => ctx.client.getGasPrice()).catch(rpcError);
1363
+ const gasPrice = await io2(ctx, () => ctx.client.getGasPrice()).catch(rpcError2);
754
1364
  return {
755
1365
  walletMinted,
756
1366
  walletMax,
@@ -761,11 +1371,11 @@ async function readWallet(ctx, config, { payer, recipient, quantity, drop }) {
761
1371
  gasReserve: gas * gasPrice
762
1372
  };
763
1373
  }
764
- async function buildPlan(ctx, attempt, wallet) {
1374
+ async function buildPlan2(ctx, attempt, wallet) {
765
1375
  void wallet;
766
1376
  const { config, payer, recipient } = attempt;
767
1377
  validateContractConfig(config);
768
- throwIfAborted(ctx);
1378
+ throwIfAborted2(ctx);
769
1379
  const qty = BigInt(attempt.quantity);
770
1380
  const unitPrice = await resolvePrice(ctx, config);
771
1381
  const totalPrice = totalFor(_nullishCoalesce(config.price.per, () => ( "unit")), unitPrice, qty);
@@ -793,15 +1403,17 @@ async function buildPlan(ctx, attempt, wallet) {
793
1403
  }
794
1404
  return { approve, mint, tokenContract: _viem.getAddress.call(void 0, attempt.tokenContract) };
795
1405
  }
796
- async function simulate(ctx, attempt, plan) {
797
- throwIfAborted(ctx);
1406
+ async function simulate2(ctx, attempt, plan) {
1407
+ throwIfAborted2(ctx);
798
1408
  await simulateMint(ctx, attempt.config, { payer: attempt.payer, to: plan.mint.to, data: plan.mint.data, value: plan.mint.value });
799
1409
  }
800
- var contractAdapter = { readDrop, readWallet, buildPlan, simulate };
1410
+ var contractAdapter = { readDrop: readDrop2, readWallet: readWallet2, buildPlan: buildPlan2, simulate: simulate2 };
801
1411
 
802
1412
  // src/react/useMint.ts
803
1413
  var REFRESH_MS = 3e4;
804
1414
  var TICK_MS = 1e3;
1415
+ var BOUNDARY_RETRY_MS = 3e3;
1416
+ var BOUNDARY_RETRY_MAX = 10;
805
1417
  var ASYNC_STATES = ["loading", "connecting", "switching-chain", "approving", "minting", "confirming"];
806
1418
  function isAsyncState(name) {
807
1419
  return ASYNC_STATES.includes(name);
@@ -811,7 +1423,18 @@ function configKeyOf(config) {
811
1423
  return JSON.stringify(config, (_k, v) => typeof v === "bigint" ? { __dropkitBigInt: v.toString() } : v);
812
1424
  }
813
1425
  function adapterFor(config) {
814
- return config.type === "manifold-claim" ? _chunkOO6QQT3Mcjs.manifoldClaimAdapter : contractAdapter;
1426
+ switch (config.type) {
1427
+ case "manifold-claim":
1428
+ return _chunkX4P6BUV4cjs.manifoldClaimAdapter;
1429
+ case "contract":
1430
+ return contractAdapter;
1431
+ case "tl-stacks":
1432
+ return tlStacksAdapter;
1433
+ default: {
1434
+ const unreachable = config;
1435
+ return unreachable;
1436
+ }
1437
+ }
815
1438
  }
816
1439
  var bridgeEnabled = (config) => config.type === "manifold-claim";
817
1440
  function payChainsOf(config, option) {
@@ -827,36 +1450,58 @@ function routeChainOf(payChains, accountChainId, payChainId) {
827
1450
  var ROUTE_DEBOUNCE_MS = 500;
828
1451
  var symbolOf = (chainId) => {
829
1452
  try {
830
- return _chunkOO6QQT3Mcjs.getChain.call(void 0, chainId).nativeCurrency.symbol;
831
- } catch (e3) {
1453
+ return _chunkX4P6BUV4cjs.getChain.call(void 0, chainId).nativeCurrency.symbol;
1454
+ } catch (e5) {
832
1455
  return "ETH";
833
1456
  }
834
1457
  };
835
- var shortOf = (chainId) => ({ chainId, symbol: symbolOf(chainId), name: _chunkOO6QQT3Mcjs.chainName.call(void 0, chainId) });
1458
+ var shortOf = (chainId) => ({ chainId, symbol: symbolOf(chainId), name: _chunkX4P6BUV4cjs.chainName.call(void 0, chainId) });
836
1459
  function tokenContractOf(config) {
837
- return config.type === "manifold-claim" ? config.creatorContract : _nullishCoalesce(config.tokenContract, () => ( config.address));
1460
+ switch (config.type) {
1461
+ case "manifold-claim":
1462
+ return config.creatorContract;
1463
+ case "contract":
1464
+ return _nullishCoalesce(config.tokenContract, () => ( config.address));
1465
+ case "tl-stacks":
1466
+ return config.nftContract;
1467
+ default: {
1468
+ const unreachable = config;
1469
+ return unreachable;
1470
+ }
1471
+ }
838
1472
  }
839
1473
  function eventAddressOf(config) {
840
- return config.type === "manifold-claim" ? config.creatorContract : config.address;
1474
+ switch (config.type) {
1475
+ case "manifold-claim":
1476
+ return config.creatorContract;
1477
+ case "contract":
1478
+ return config.address;
1479
+ case "tl-stacks":
1480
+ return config.nftContract;
1481
+ default: {
1482
+ const unreachable = config;
1483
+ return unreachable;
1484
+ }
1485
+ }
841
1486
  }
842
- var isUnsupported = (reason) => _chunkOO6QQT3Mcjs.UNSUPPORTED_REASONS.includes(reason);
1487
+ var isUnsupported = (reason) => _chunkX4P6BUV4cjs.UNSUPPORTED_REASONS.includes(reason);
843
1488
  function errorReasonOf(e) {
844
- const { reason, message } = _chunkOO6QQT3Mcjs.toReason.call(void 0, e);
1489
+ const { reason, message } = _chunkX4P6BUV4cjs.toReason.call(void 0, e);
845
1490
  const ok = ["USER_REJECTED", "TX_REVERTED", "RATE_LIMITED", "RPC_ERROR", "CHAIN_SWITCH_FAILED", "ALLOWLIST_UNAVAILABLE"];
846
1491
  return { reason: ok.includes(reason) ? reason : "RPC_ERROR", message };
847
1492
  }
848
1493
  function explorerUrlFor(chainId, hash) {
849
1494
  try {
850
- const url = _optionalChain([_chunkOO6QQT3Mcjs.getChain.call(void 0, chainId), 'access', _26 => _26.blockExplorers, 'optionalAccess', _27 => _27.default, 'access', _28 => _28.url]);
1495
+ const url = _optionalChain([_chunkX4P6BUV4cjs.getChain.call(void 0, chainId), 'access', _44 => _44.blockExplorers, 'optionalAccess', _45 => _45.default, 'access', _46 => _46.url]);
851
1496
  return url ? `${url.replace(/\/$/, "")}/tx/${hash}` : null;
852
- } catch (e4) {
1497
+ } catch (e6) {
853
1498
  return null;
854
1499
  }
855
1500
  }
856
1501
  var receiptOk = (status) => status === "success" || status === 1 || status === 1n || status === "0x1";
857
1502
  function useMint(options) {
858
1503
  const { config, recipient, quantity: quantityProp, connect } = options;
859
- const [machine, rawDispatch] = _react.useReducer.call(void 0, _chunkOO6QQT3Mcjs.reducer, void 0, () => _chunkOO6QQT3Mcjs.initialState.call(void 0, { quantity: quantityProp }));
1504
+ const [machine, rawDispatch] = _react.useReducer.call(void 0, _chunkX4P6BUV4cjs.reducer, void 0, () => _chunkX4P6BUV4cjs.initialState.call(void 0, { quantity: quantityProp }));
860
1505
  const [widgetFail, setWidgetFail] = _react.useState.call(void 0, null);
861
1506
  const [widgetRetry, setWidgetRetry] = _react.useState.call(void 0, 0);
862
1507
  const configKey = configKeyOf(config);
@@ -870,6 +1515,7 @@ function useMint(options) {
870
1515
  const accountKeyRef = _react.useRef.call(void 0, null);
871
1516
  const connectingRef = _react.useRef.call(void 0, false);
872
1517
  const pendingRefreshRef = _react.useRef.call(void 0, false);
1518
+ const boundaryRetryRef = _react.useRef.call(void 0, null);
873
1519
  const pendingQuantityRef = _react.useRef.call(void 0, null);
874
1520
  const widgetFailRef = _react.useRef.call(void 0, null);
875
1521
  const widgetLoadRef = _react.useRef.call(void 0, null);
@@ -883,15 +1529,15 @@ function useMint(options) {
883
1529
  });
884
1530
  const dispatch = _react.useCallback.call(void 0, (event) => {
885
1531
  if (!mounted.current) return;
886
- stateRef.current = _chunkOO6QQT3Mcjs.reducer.call(void 0, stateRef.current, event);
1532
+ stateRef.current = _chunkX4P6BUV4cjs.reducer.call(void 0, stateRef.current, event);
887
1533
  rawDispatch(event);
888
1534
  }, []);
889
1535
  const emit = _react.useCallback.call(void 0, (type, over = {}) => {
890
1536
  const handler = propsRef.current.onEvent;
891
1537
  if (!handler || !mounted.current) return;
892
- const cfg = _nullishCoalesce(_optionalChain([attemptRef, 'access', _29 => _29.current, 'optionalAccess', _30 => _30.config]), () => ( propsRef.current.config));
1538
+ const cfg = _nullishCoalesce(_optionalChain([attemptRef, 'access', _47 => _47.current, 'optionalAccess', _48 => _48.config]), () => ( propsRef.current.config));
893
1539
  const s = stateRef.current;
894
- const originChainId = _nullishCoalesce(_optionalChain([attemptRef, 'access', _31 => _31.current, 'optionalAccess', _32 => _32.originChainId]), () => ( (_optionalChain([s, 'access', _33 => _33.route, 'optionalAccess', _34 => _34.kind]) === "relay" ? s.route.originChainId : _nullishCoalesce(_optionalChain([s, 'access', _35 => _35.short, 'optionalAccess', _36 => _36.chainId]), () => ( cfg.chainId)))));
1540
+ const originChainId = _nullishCoalesce(_optionalChain([attemptRef, 'access', _49 => _49.current, 'optionalAccess', _50 => _50.originChainId]), () => ( (_optionalChain([s, 'access', _51 => _51.route, 'optionalAccess', _52 => _52.kind]) === "relay" ? s.route.originChainId : _nullishCoalesce(_optionalChain([s, 'access', _53 => _53.short, 'optionalAccess', _54 => _54.chainId]), () => ( cfg.chainId)))));
895
1541
  const payload = {
896
1542
  type,
897
1543
  state: s.name,
@@ -905,14 +1551,14 @@ function useMint(options) {
905
1551
  };
906
1552
  try {
907
1553
  handler(payload);
908
- } catch (e5) {
1554
+ } catch (e7) {
909
1555
  }
910
1556
  }, []);
911
1557
  const clientFor = _react.useCallback.call(void 0, (life, cfg) => {
912
- const rpcUrl = _optionalChain([propsRef, 'access', _37 => _37.current, 'access', _38 => _38.rpcUrls, 'optionalAccess', _39 => _39[cfg.chainId]]);
1558
+ const rpcUrl = _optionalChain([propsRef, 'access', _55 => _55.current, 'access', _56 => _56.rpcUrls, 'optionalAccess', _57 => _57[cfg.chainId]]);
913
1559
  if (!life.client || life.rpcUrl !== rpcUrl) {
914
1560
  life.rpcUrl = rpcUrl;
915
- life.client = _chunkOO6QQT3Mcjs.createReadClient.call(void 0, { chainId: cfg.chainId, rpcUrls: propsRef.current.rpcUrls, useBridge: bridgeEnabled(cfg) });
1561
+ life.client = _chunkX4P6BUV4cjs.createReadClient.call(void 0, { chainId: cfg.chainId, rpcUrls: propsRef.current.rpcUrls, useBridge: bridgeEnabled(cfg) });
916
1562
  }
917
1563
  return life.client;
918
1564
  }, []);
@@ -925,7 +1571,7 @@ function useMint(options) {
925
1571
  }),
926
1572
  [clientFor]
927
1573
  );
928
- const readDrop2 = _react.useCallback.call(void 0,
1574
+ const readDrop3 = _react.useCallback.call(void 0,
929
1575
  async (life, gen, cfg) => {
930
1576
  const adapter = adapterFor(cfg);
931
1577
  try {
@@ -934,7 +1580,7 @@ function useMint(options) {
934
1580
  dispatch({ type: "DROP_LOADED", gen, drop, now: Math.max(stateRef.current.now, nowSec()) });
935
1581
  } catch (e) {
936
1582
  if (life.controller.signal.aborted || life.gen !== gen || lifeRef.current !== life) return;
937
- const { reason, message } = _chunkOO6QQT3Mcjs.toReason.call(void 0, e);
1583
+ const { reason, message } = _chunkX4P6BUV4cjs.toReason.call(void 0, e);
938
1584
  if (isUnsupported(reason)) dispatch({ type: "DROP_UNSUPPORTED", gen, reason, message });
939
1585
  else dispatch({ type: "READ_FAILED", gen, ...errorReasonOf(e) });
940
1586
  }
@@ -945,14 +1591,14 @@ function useMint(options) {
945
1591
  (key, cfg) => {
946
1592
  const prev = lifeRef.current;
947
1593
  lifeRef.current = null;
948
- _optionalChain([prev, 'optionalAccess', _40 => _40.controller, 'access', _41 => _41.abort, 'call', _42 => _42()]);
1594
+ _optionalChain([prev, 'optionalAccess', _58 => _58.controller, 'access', _59 => _59.abort, 'call', _60 => _60()]);
949
1595
  const gen = ++genRef.current;
950
1596
  const life = { key, controller: new AbortController(), cacheScope: {}, gen };
951
1597
  lifeRef.current = life;
952
1598
  dispatch({ type: "LOAD", gen, kind: "config" });
953
- void readDrop2(life, gen, cfg);
1599
+ void readDrop3(life, gen, cfg);
954
1600
  },
955
- [dispatch, readDrop2]
1601
+ [dispatch, readDrop3]
956
1602
  );
957
1603
  const refreshNow = _react.useCallback.call(void 0,
958
1604
  async (kind = "refresh") => {
@@ -965,13 +1611,13 @@ function useMint(options) {
965
1611
  const gen = ++genRef.current;
966
1612
  life.gen = gen;
967
1613
  dispatch({ type: "LOAD", gen, kind });
968
- await readDrop2(life, gen, propsRef.current.config);
1614
+ await readDrop3(life, gen, propsRef.current.config);
969
1615
  },
970
- [dispatch, readDrop2]
1616
+ [dispatch, readDrop3]
971
1617
  );
972
1618
  const refresh = _react.useCallback.call(void 0, () => refreshNow("refresh"), [refreshNow]);
973
1619
  const isBusy = _react.useCallback.call(void 0,
974
- () => connectingRef.current || attemptRef.current !== null || stateRef.current.attempt !== null || _chunkOO6QQT3Mcjs.IN_FLIGHT_STATES.includes(stateRef.current.name),
1620
+ () => connectingRef.current || attemptRef.current !== null || stateRef.current.attempt !== null || _chunkX4P6BUV4cjs.IN_FLIGHT_STATES.includes(stateRef.current.name),
975
1621
  []
976
1622
  );
977
1623
  const executeAttempt = _react.useCallback.call(void 0,
@@ -987,20 +1633,20 @@ function useMint(options) {
987
1633
  };
988
1634
  const assertPayer = () => {
989
1635
  assertActive();
990
- const live = _chunkOO6QQT3Mcjs.getAccount.call(void 0, );
1636
+ const live = _chunkX4P6BUV4cjs.getAccount.call(void 0, );
991
1637
  if (!live || live.address.toLowerCase() !== attempt.payer.toLowerCase()) {
992
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("USER_REJECTED", "The connected wallet changed before the transaction was sent.");
1638
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("USER_REJECTED", "The connected wallet changed before the transaction was sent.");
993
1639
  }
994
1640
  };
995
1641
  let wallet2 = null;
996
1642
  const walletFor = () => {
997
- if (!wallet2) wallet2 = _chunkOO6QQT3Mcjs.getWalletClient.call(void 0, attempt.chainId);
1643
+ if (!wallet2) wallet2 = _chunkX4P6BUV4cjs.getWalletClient.call(void 0, attempt.chainId);
998
1644
  return wallet2;
999
1645
  };
1000
1646
  const submit = async (tx) => {
1001
1647
  assertPayer();
1002
1648
  const w = walletFor();
1003
- return w.sendTransaction({ account: attempt.payer, to: tx.to, data: tx.data, value: tx.value, chain: _chunkOO6QQT3Mcjs.getChain.call(void 0, attempt.chainId) });
1649
+ return w.sendTransaction({ account: attempt.payer, to: tx.to, data: tx.data, value: tx.value, chain: _chunkX4P6BUV4cjs.getChain.call(void 0, attempt.chainId) });
1004
1650
  };
1005
1651
  const waitReceipt = async (hash2) => {
1006
1652
  let cancelled = false;
@@ -1017,19 +1663,19 @@ function useMint(options) {
1017
1663
  receipt2 = await client.waitForTransactionReceipt(params);
1018
1664
  } catch (e) {
1019
1665
  assertActive();
1020
- if (cancelled) throw new (0, _chunkOO6QQT3Mcjs.MintError)("USER_REJECTED", "The transaction was cancelled or replaced with a different transaction.");
1666
+ if (cancelled) throw new (0, _chunkX4P6BUV4cjs.MintError)("USER_REJECTED", "The transaction was cancelled or replaced with a different transaction.");
1021
1667
  if (await walletFor().getChainId() !== attempt.chainId) throw e;
1022
1668
  assertActive();
1023
1669
  receipt2 = await walletFor().extend(_viem.publicActions).waitForTransactionReceipt(params);
1024
1670
  }
1025
1671
  assertActive();
1026
- if (cancelled) throw new (0, _chunkOO6QQT3Mcjs.MintError)("USER_REJECTED", "The transaction was cancelled or replaced with a different transaction.");
1672
+ if (cancelled) throw new (0, _chunkX4P6BUV4cjs.MintError)("USER_REJECTED", "The transaction was cancelled or replaced with a different transaction.");
1027
1673
  return receipt2;
1028
1674
  };
1029
1675
  assertPayer();
1030
1676
  if (account2.chainId !== attempt.chainId) {
1031
1677
  dispatch({ type: "SWITCHING_CHAIN", attemptId: attempt.attemptId });
1032
- await _chunkOO6QQT3Mcjs.switchToChain.call(void 0, attempt.chainId);
1678
+ await _chunkX4P6BUV4cjs.switchToChain.call(void 0, attempt.chainId);
1033
1679
  }
1034
1680
  assertPayer();
1035
1681
  let plan = await adapter.buildPlan(ctx, attempt, walletRead);
@@ -1039,13 +1685,13 @@ function useMint(options) {
1039
1685
  try {
1040
1686
  const simulated = await client.call({ account: attempt.payer, to: a.tx.to, data: a.tx.data, value: a.tx.value });
1041
1687
  if (simulated.data && simulated.data !== "0x" && BigInt(simulated.data) === 0n) {
1042
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("SIMULATION_REVERTED", "The token refused the approval.");
1688
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("SIMULATION_REVERTED", "The token refused the approval.");
1043
1689
  }
1044
1690
  } catch (e) {
1045
- if (_chunkOO6QQT3Mcjs.isMintError.call(void 0, e)) throw e;
1691
+ if (_chunkX4P6BUV4cjs.isMintError.call(void 0, e)) throw e;
1046
1692
  const reverted = e instanceof _viem.BaseError ? e.walk((cause) => cause instanceof _viem.ExecutionRevertedError) : null;
1047
1693
  if (reverted instanceof _viem.ExecutionRevertedError) {
1048
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("SIMULATION_REVERTED", reverted.shortMessage);
1694
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("SIMULATION_REVERTED", reverted.shortMessage);
1049
1695
  }
1050
1696
  throw e;
1051
1697
  }
@@ -1057,7 +1703,7 @@ function useMint(options) {
1057
1703
  const approveReceipt = await waitReceipt(approveHash);
1058
1704
  assertActive();
1059
1705
  if (!receiptOk(approveReceipt.status)) {
1060
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("TX_REVERTED", `The approval transaction reverted (${approveHash}).`);
1706
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("TX_REVERTED", `The approval transaction reverted (${approveHash}).`);
1061
1707
  }
1062
1708
  const freshDrop = await adapter.readDrop(ctx, cfg);
1063
1709
  assertActive();
@@ -1068,11 +1714,11 @@ function useMint(options) {
1068
1714
  drop: freshDrop
1069
1715
  });
1070
1716
  assertPayer();
1071
- let checked = _chunkOO6QQT3Mcjs.reducer.call(void 0, _chunkOO6QQT3Mcjs.initialState.call(void 0, { quantity: attempt.quantity }), { type: "ACCOUNT_CHANGED", account: account2 });
1072
- checked = _chunkOO6QQT3Mcjs.reducer.call(void 0, checked, { type: "DROP_LOADED", gen: checked.readGen, drop: freshDrop, now: nowSec() });
1073
- checked = _chunkOO6QQT3Mcjs.reducer.call(void 0, checked, { type: "WALLET_LOADED", gen: checked.walletGen, read: freshWallet });
1074
- if (checked.name !== "live" || (_nullishCoalesce(_chunkOO6QQT3Mcjs.selectMaxQuantity.call(void 0, checked), () => ( 0))) < attempt.quantity) {
1075
- throw new (0, _chunkOO6QQT3Mcjs.MintError)(_nullishCoalesce(checked.reason, () => ( "SIMULATION_REVERTED")), _nullishCoalesce(checked.message, () => ( "The drop is no longer available for this quantity.")));
1717
+ let checked = _chunkX4P6BUV4cjs.reducer.call(void 0, _chunkX4P6BUV4cjs.initialState.call(void 0, { quantity: attempt.quantity }), { type: "ACCOUNT_CHANGED", account: account2 });
1718
+ checked = _chunkX4P6BUV4cjs.reducer.call(void 0, checked, { type: "DROP_LOADED", gen: checked.readGen, drop: freshDrop, now: nowSec() });
1719
+ checked = _chunkX4P6BUV4cjs.reducer.call(void 0, checked, { type: "WALLET_LOADED", gen: checked.walletGen, read: freshWallet });
1720
+ if (checked.name !== "live" || (_nullishCoalesce(_chunkX4P6BUV4cjs.selectMaxQuantity.call(void 0, checked), () => ( 0))) < attempt.quantity) {
1721
+ throw new (0, _chunkX4P6BUV4cjs.MintError)(_nullishCoalesce(checked.reason, () => ( "SIMULATION_REVERTED")), _nullishCoalesce(checked.message, () => ( "The drop is no longer available for this quantity.")));
1076
1722
  }
1077
1723
  plan = await adapter.buildPlan(ctx, attempt, freshWallet);
1078
1724
  assertPayer();
@@ -1081,6 +1727,7 @@ function useMint(options) {
1081
1727
  assertPayer();
1082
1728
  dispatch({ type: "MINT_PROMPTED", attemptId: attempt.attemptId });
1083
1729
  const hash = await submit(plan.mint);
1730
+ if (cfg.type === "manifold-claim") void _chunkX4P6BUV4cjs.recordClaimMint.call(void 0, { instanceId: cfg.instanceId, hash });
1084
1731
  assertActive();
1085
1732
  dispatch({ type: "TX_SUBMITTED", attemptId: attempt.attemptId });
1086
1733
  emit("tx-submitted", { state: "confirming", reason: null, txHash: hash, quantity: attempt.quantity, chainId: attempt.chainId });
@@ -1088,13 +1735,13 @@ function useMint(options) {
1088
1735
  assertActive();
1089
1736
  const confirmedHash = _nullishCoalesce(receipt.transactionHash, () => ( hash));
1090
1737
  if (!receiptOk(receipt.status)) {
1091
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("TX_REVERTED", `The mint transaction reverted (${confirmedHash}).`);
1738
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("TX_REVERTED", `The mint transaction reverted (${confirmedHash}).`);
1092
1739
  }
1093
- const tokens = _chunkOO6QQT3Mcjs.parseMintReceipt.call(void 0, _nullishCoalesce(receipt.logs, () => ( [])), {
1740
+ const tokens = _chunkX4P6BUV4cjs.parseMintReceipt.call(void 0, _nullishCoalesce(receipt.logs, () => ( [])), {
1094
1741
  tokenContract: _nullishCoalesce(plan.tokenContract, () => ( attempt.tokenContract)),
1095
1742
  recipient: attempt.recipient
1096
1743
  });
1097
- const result = { txHash: confirmedHash, explorerUrl: explorerUrlFor(attempt.chainId, confirmedHash), tokens };
1744
+ const result = { txHash: confirmedHash, explorerUrl: explorerUrlFor(attempt.chainId, confirmedHash), tokens, requested: attempt.quantity };
1098
1745
  dispatch({ type: "ATTEMPT_SUCCEEDED", attemptId: attempt.attemptId, result });
1099
1746
  emit("success", { state: "success", reason: null, txHash: confirmedHash, quantity: attempt.quantity, chainId: attempt.chainId });
1100
1747
  },
@@ -1111,30 +1758,31 @@ function useMint(options) {
1111
1758
  };
1112
1759
  const outcome = await pollUntilTerminal({ testnet: out.testnet, requestId: out.requestId, signal: life.controller.signal, assertActive });
1113
1760
  assertActive();
1114
- const where = _chunkOO6QQT3Mcjs.chainName.call(void 0, out.originChainId);
1761
+ const where = _chunkX4P6BUV4cjs.chainName.call(void 0, out.originChainId);
1115
1762
  if (outcome.kind === "timeout") {
1116
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("BRIDGE_TIMEOUT", "The bridge is still processing. Your mint may still complete.");
1763
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("BRIDGE_TIMEOUT", "The bridge is still processing. Your mint may still complete.");
1117
1764
  }
1118
1765
  const key = outstandingKey(attempt.config, attempt.payer);
1119
1766
  const { status } = outcome;
1120
1767
  if (status.status !== "success") clearOutstanding(key);
1121
1768
  if (status.status === "refund") {
1122
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("BRIDGE_REFUNDED", `Relay could not complete the mint and is refunding your payment. Relay request ${out.requestId}.`);
1769
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("BRIDGE_REFUNDED", `Relay could not complete the mint and is refunding your payment. Relay request ${out.requestId}.`);
1123
1770
  }
1124
1771
  if (status.status === "failure") {
1125
1772
  const why = status.failReason ? ` (${status.failReason})` : "";
1126
1773
  const noRefund = status.refundFailReason ? ` No automatic refund was sent. Contact support with Relay request ${out.requestId}.` : "";
1127
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("BRIDGE_FAILED", `Relay could not complete the mint paid on ${where}${why}.${noRefund}`);
1774
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("BRIDGE_FAILED", `Relay could not complete the mint paid on ${where}${why}.${noRefund}`);
1128
1775
  }
1129
1776
  const fillHash = _nullishCoalesce(status.txHashes[0], () => ( null));
1777
+ if (fillHash && cfg.type === "manifold-claim") void _chunkX4P6BUV4cjs.recordClaimMint.call(void 0, { instanceId: cfg.instanceId, hash: fillHash });
1130
1778
  let tokens = [];
1131
1779
  if (fillHash) {
1132
1780
  try {
1133
1781
  const receipt = await client.waitForTransactionReceipt({ hash: fillHash, confirmations: 1, timeout: 6e4 });
1134
1782
  if (receiptOk(receipt.status)) {
1135
- tokens = _chunkOO6QQT3Mcjs.parseMintReceipt.call(void 0, _nullishCoalesce(receipt.logs, () => ( [])), { tokenContract: attempt.tokenContract, recipient: attempt.recipient });
1783
+ tokens = _chunkX4P6BUV4cjs.parseMintReceipt.call(void 0, _nullishCoalesce(receipt.logs, () => ( [])), { tokenContract: attempt.tokenContract, recipient: attempt.recipient });
1136
1784
  }
1137
- } catch (e6) {
1785
+ } catch (e8) {
1138
1786
  }
1139
1787
  assertActive();
1140
1788
  }
@@ -1143,6 +1791,7 @@ function useMint(options) {
1143
1791
  txHash,
1144
1792
  explorerUrl: explorerUrlFor(fillHash ? cfg.chainId : out.originChainId, txHash),
1145
1793
  tokens,
1794
+ requested: attempt.quantity,
1146
1795
  relay: { requestId: out.requestId, originTxHash: out.originTxHash, originChainId: out.originChainId }
1147
1796
  };
1148
1797
  clearOutstanding(key);
@@ -1162,19 +1811,19 @@ function useMint(options) {
1162
1811
  if (!mounted.current || life.controller.signal.aborted || lifeRef.current !== life || attemptRef.current !== attempt) {
1163
1812
  throw new DOMException("Mint attempt cancelled", "AbortError");
1164
1813
  }
1165
- const live = _chunkOO6QQT3Mcjs.getAccount.call(void 0, );
1814
+ const live = _chunkX4P6BUV4cjs.getAccount.call(void 0, );
1166
1815
  if (!live || live.address.toLowerCase() !== attempt.payer.toLowerCase()) {
1167
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("USER_REJECTED", "The connected wallet changed before the transaction was sent.");
1816
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("USER_REJECTED", "The connected wallet changed before the transaction was sent.");
1168
1817
  }
1169
1818
  };
1170
1819
  assertPayer();
1171
1820
  if (account2.chainId !== origin) {
1172
1821
  dispatch({ type: "SWITCHING_CHAIN", attemptId: attempt.attemptId });
1173
- await _chunkOO6QQT3Mcjs.switchToChain.call(void 0, origin);
1822
+ await _chunkX4P6BUV4cjs.switchToChain.call(void 0, origin);
1174
1823
  }
1175
1824
  assertPayer();
1176
1825
  const plan = await adapter.buildPlan(ctx, attempt, walletRead);
1177
- if (plan.approve) throw new (0, _chunkOO6QQT3Mcjs.MintError)("BRIDGE_UNAVAILABLE", "Cross-chain mint supports native-priced drops only.");
1826
+ if (plan.approve) throw new (0, _chunkX4P6BUV4cjs.MintError)("BRIDGE_UNAVAILABLE", "Cross-chain mint supports native-priced drops only.");
1178
1827
  assertPayer();
1179
1828
  const quote = await getQuote({
1180
1829
  testnet,
@@ -1187,18 +1836,18 @@ function useMint(options) {
1187
1836
  signal: life.controller.signal
1188
1837
  });
1189
1838
  assertPayer();
1190
- const balance = await _chunkOO6QQT3Mcjs.getConnectedBalance.call(void 0, attempt.payer, origin);
1839
+ const balance = await _chunkX4P6BUV4cjs.getConnectedBalance.call(void 0, attempt.payer, origin);
1191
1840
  if (balance < quote.amountIn.value + quote.originGas.value) {
1192
1841
  const s = shortOf(origin);
1193
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("INSUFFICIENT_FUNDS", `Not enough ${s.symbol} on ${s.name}. Pick another network to pay from.`);
1842
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("INSUFFICIENT_FUNDS", `Not enough ${s.symbol} on ${s.name}. Pick another network to pay from.`);
1194
1843
  }
1195
1844
  assertPayer();
1196
1845
  const item = quote.items[0];
1197
1846
  const key = outstandingKey(cfg, attempt.payer);
1198
- const wallet2 = _chunkOO6QQT3Mcjs.getWalletClient.call(void 0, origin);
1847
+ const wallet2 = _chunkX4P6BUV4cjs.getWalletClient.call(void 0, origin);
1199
1848
  assertPayer();
1200
1849
  if (!claimDeposit(key)) {
1201
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("BRIDGE_UNAVAILABLE", "A cross-chain payment for this drop is already in progress. Try again once it finishes.");
1850
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("BRIDGE_UNAVAILABLE", "A cross-chain payment for this drop is already in progress. Try again once it finishes.");
1202
1851
  }
1203
1852
  let out;
1204
1853
  try {
@@ -1210,7 +1859,7 @@ function useMint(options) {
1210
1859
  data: item.data,
1211
1860
  value: item.value,
1212
1861
  ...item.gas !== null && item.gas > 0n ? { gas: item.gas } : {},
1213
- chain: _chunkOO6QQT3Mcjs.getChain.call(void 0, origin)
1862
+ chain: _chunkX4P6BUV4cjs.getChain.call(void 0, origin)
1214
1863
  });
1215
1864
  out = { requestId: quote.requestId, testnet, originChainId: origin, originTxHash: originTxHash2, attempt };
1216
1865
  setOutstanding(key, out);
@@ -1221,10 +1870,10 @@ function useMint(options) {
1221
1870
  autoResumedRef.current.add(key);
1222
1871
  dispatch({ type: "TX_SUBMITTED", attemptId: attempt.attemptId });
1223
1872
  emit("tx-submitted", { state: "confirming", reason: null, txHash: originTxHash, quantity: attempt.quantity, chainId: cfg.chainId });
1224
- const deposit = await _chunkOO6QQT3Mcjs.waitForDeposit.call(void 0, origin, originTxHash);
1873
+ const deposit = await _chunkX4P6BUV4cjs.waitForDeposit.call(void 0, origin, originTxHash);
1225
1874
  if (deposit === "reverted") {
1226
1875
  clearOutstanding(key);
1227
- throw new (0, _chunkOO6QQT3Mcjs.MintError)("TX_REVERTED", `The payment transaction reverted (${originTxHash}).`);
1876
+ throw new (0, _chunkX4P6BUV4cjs.MintError)("TX_REVERTED", `The payment transaction reverted (${originTxHash}).`);
1228
1877
  }
1229
1878
  await finishRelay(attempt, out, life);
1230
1879
  },
@@ -1241,7 +1890,7 @@ function useMint(options) {
1241
1890
  await finishRelay(attempt, out, life);
1242
1891
  } catch (e) {
1243
1892
  if (!mounted.current || life.controller.signal.aborted || lifeRef.current !== life) return;
1244
- const { reason, message } = _chunkOO6QQT3Mcjs.toReason.call(void 0, e);
1893
+ const { reason, message } = _chunkX4P6BUV4cjs.toReason.call(void 0, e);
1245
1894
  dispatch({ type: "ATTEMPT_FAILED", attemptId: attempt.attemptId, reason, message });
1246
1895
  emit("error", { quantity: attempt.quantity, chainId: attempt.chainId });
1247
1896
  } finally {
@@ -1262,31 +1911,31 @@ function useMint(options) {
1262
1911
  return;
1263
1912
  }
1264
1913
  const s = stateRef.current;
1265
- if (!_chunkOO6QQT3Mcjs.canAct.call(void 0, s) || s.attempt !== null) return;
1914
+ if (!_chunkX4P6BUV4cjs.canAct.call(void 0, s) || s.attempt !== null) return;
1266
1915
  if (s.name === "disconnected") {
1267
1916
  if (connectingRef.current) return;
1268
1917
  connectingRef.current = true;
1269
1918
  dispatch({ type: "CONNECT_STARTED" });
1270
1919
  const connectLife = lifeRef.current;
1271
- const active = () => mounted.current && lifeRef.current === connectLife && !_optionalChain([connectLife, 'optionalAccess', _43 => _43.controller, 'access', _44 => _44.signal, 'access', _45 => _45.aborted]);
1920
+ const active = () => mounted.current && lifeRef.current === connectLife && !_optionalChain([connectLife, 'optionalAccess', _61 => _61.controller, 'access', _62 => _62.signal, 'access', _63 => _63.aborted]);
1272
1921
  try {
1273
1922
  await widgetLoadRef.current;
1274
1923
  if (!active()) return;
1275
- const outcome = await _chunkOO6QQT3Mcjs.openConnectModal.call(void 0, );
1924
+ const outcome = await _chunkX4P6BUV4cjs.openConnectModal.call(void 0, );
1276
1925
  if (!active()) return;
1277
1926
  connectingRef.current = false;
1278
1927
  if (outcome === "connected") {
1279
1928
  accountKeyRef.current = null;
1280
- _optionalChain([pushAccountRef, 'access', _46 => _46.current, 'optionalCall', _47 => _47(_chunkOO6QQT3Mcjs.getAccount.call(void 0, ))]);
1929
+ _optionalChain([pushAccountRef, 'access', _64 => _64.current, 'optionalCall', _65 => _65(_chunkX4P6BUV4cjs.getAccount.call(void 0, ))]);
1281
1930
  } else dispatch({ type: "CONNECT_DISMISSED" });
1282
- } catch (e7) {
1931
+ } catch (e9) {
1283
1932
  if (active()) dispatch({ type: "CONNECT_DISMISSED" });
1284
1933
  } finally {
1285
1934
  connectingRef.current = false;
1286
1935
  }
1287
1936
  return;
1288
1937
  }
1289
- const payer = _optionalChain([s, 'access', _48 => _48.account, 'optionalAccess', _49 => _49.address]);
1938
+ const payer = _optionalChain([s, 'access', _66 => _66.account, 'optionalAccess', _67 => _67.address]);
1290
1939
  const out = payer ? getOutstanding(outstandingKey(propsRef.current.config, payer)) : null;
1291
1940
  if (out && lifeRef.current) {
1292
1941
  await resumeOutstanding(out, lifeRef.current);
@@ -1298,7 +1947,7 @@ function useMint(options) {
1298
1947
  if (life2) life2.gen = gen;
1299
1948
  dispatch({ type: "RESET", gen });
1300
1949
  dispatch({ type: "LOAD", gen, kind: "config" });
1301
- if (life2) void readDrop2(life2, gen, propsRef.current.config);
1950
+ if (life2) void readDrop3(life2, gen, propsRef.current.config);
1302
1951
  return;
1303
1952
  }
1304
1953
  if (s.name !== "live") return;
@@ -1307,7 +1956,7 @@ function useMint(options) {
1307
1956
  const life = lifeRef.current;
1308
1957
  if (!account2 || !walletRead || !life) return;
1309
1958
  const cfg = propsRef.current.config;
1310
- const relayRoute = _optionalChain([s, 'access', _50 => _50.route, 'optionalAccess', _51 => _51.kind]) === "relay" ? s.route : null;
1959
+ const relayRoute = _optionalChain([s, 'access', _68 => _68.route, 'optionalAccess', _69 => _69.kind]) === "relay" ? s.route : null;
1311
1960
  const attempt = Object.freeze({
1312
1961
  attemptId: ++attemptIdRef.current,
1313
1962
  config: structuredClone(cfg),
@@ -1326,13 +1975,13 @@ function useMint(options) {
1326
1975
  else await executeAttempt(attempt, walletRead, life, account2);
1327
1976
  } catch (e) {
1328
1977
  if (!mounted.current || life.controller.signal.aborted || lifeRef.current !== life) return;
1329
- const { reason, message } = _chunkOO6QQT3Mcjs.toReason.call(void 0, e);
1978
+ const { reason, message } = _chunkX4P6BUV4cjs.toReason.call(void 0, e);
1330
1979
  dispatch({ type: "ATTEMPT_FAILED", attemptId: attempt.attemptId, reason, message });
1331
1980
  emit("error", { quantity: attempt.quantity, chainId: attempt.chainId });
1332
1981
  } finally {
1333
1982
  attemptRef.current = null;
1334
1983
  }
1335
- }, [dispatch, emit, readDrop2, executeAttempt, executeRelayAttempt, resumeOutstanding, refreshNow]);
1984
+ }, [dispatch, emit, readDrop3, executeAttempt, executeRelayAttempt, resumeOutstanding, refreshNow]);
1336
1985
  const mint = _react.useCallback.call(void 0, () => {
1337
1986
  void runMint();
1338
1987
  }, [runMint]);
@@ -1340,7 +1989,9 @@ function useMint(options) {
1340
1989
  mounted.current = true;
1341
1990
  return () => {
1342
1991
  mounted.current = false;
1343
- _optionalChain([lifeRef, 'access', _52 => _52.current, 'optionalAccess', _53 => _53.controller, 'access', _54 => _54.abort, 'call', _55 => _55()]);
1992
+ if (boundaryRetryRef.current) clearTimeout(boundaryRetryRef.current);
1993
+ boundaryRetryRef.current = null;
1994
+ _optionalChain([lifeRef, 'access', _70 => _70.current, 'optionalAccess', _71 => _71.controller, 'access', _72 => _72.abort, 'call', _73 => _73()]);
1344
1995
  lifeRef.current = null;
1345
1996
  };
1346
1997
  }, []);
@@ -1353,8 +2004,8 @@ function useMint(options) {
1353
2004
  dispatch({ type: "ACCOUNT_CHANGED", account: a });
1354
2005
  };
1355
2006
  pushAccountRef.current = push;
1356
- push(_chunkOO6QQT3Mcjs.getAccount.call(void 0, ));
1357
- const unsubscribe = _chunkOO6QQT3Mcjs.subscribeAccount.call(void 0, push);
2007
+ push(_chunkX4P6BUV4cjs.getAccount.call(void 0, ));
2008
+ const unsubscribe = _chunkX4P6BUV4cjs.subscribeAccount.call(void 0, push);
1358
2009
  return () => {
1359
2010
  unsubscribe();
1360
2011
  };
@@ -1364,13 +2015,13 @@ function useMint(options) {
1364
2015
  if (isBusy() || recipientRef.current === recipient) return;
1365
2016
  recipientRef.current = recipient;
1366
2017
  accountKeyRef.current = null;
1367
- _optionalChain([pushAccountRef, 'access', _56 => _56.current, 'optionalCall', _57 => _57(_chunkOO6QQT3Mcjs.getAccount.call(void 0, ))]);
2018
+ _optionalChain([pushAccountRef, 'access', _74 => _74.current, 'optionalCall', _75 => _75(_chunkX4P6BUV4cjs.getAccount.call(void 0, ))]);
1368
2019
  }, [recipient, machine.attempt, isBusy]);
1369
- const projectId = _optionalChain([connect, 'optionalAccess', _58 => _58.walletConnectProjectId]);
2020
+ const projectId = _optionalChain([connect, 'optionalAccess', _76 => _76.walletConnectProjectId]);
1370
2021
  const widgetChains = [config.chainId, ...payChainsOf(config, options.crossChain).filter((id) => id !== config.chainId)].join(",");
1371
2022
  _react.useEffect.call(void 0, () => {
1372
2023
  let alive = true;
1373
- const loading = _chunkOO6QQT3Mcjs.loadConnectWidget.call(void 0, { chainIds: widgetChains.split(",").map(Number), ...projectId ? { walletConnectProjectId: projectId } : {} });
2024
+ const loading = _chunkX4P6BUV4cjs.loadConnectWidget.call(void 0, { chainIds: widgetChains.split(",").map(Number), ...projectId ? { walletConnectProjectId: projectId } : {} });
1374
2025
  widgetLoadRef.current = loading;
1375
2026
  loading.then(
1376
2027
  () => {
@@ -1378,7 +2029,7 @@ function useMint(options) {
1378
2029
  },
1379
2030
  (e) => {
1380
2031
  if (!alive) return;
1381
- const { reason, message } = _chunkOO6QQT3Mcjs.toReason.call(void 0, e);
2032
+ const { reason, message } = _chunkX4P6BUV4cjs.toReason.call(void 0, e);
1382
2033
  setWidgetFail({ reason, message });
1383
2034
  }
1384
2035
  );
@@ -1394,10 +2045,10 @@ function useMint(options) {
1394
2045
  pendingQuantityRef.current = null;
1395
2046
  dispatch({ type: "SET_QUANTITY", quantity });
1396
2047
  }
1397
- if (_optionalChain([lifeRef, 'access', _59 => _59.current, 'optionalAccess', _60 => _60.key]) !== configKey) {
2048
+ if (_optionalChain([lifeRef, 'access', _77 => _77.current, 'optionalAccess', _78 => _78.key]) !== configKey) {
1398
2049
  pendingRefreshRef.current = false;
1399
2050
  startLifetime(configKey, config);
1400
- } else if (pendingRefreshRef.current || lifeRef.current.rpcUrl !== _optionalChain([options, 'access', _61 => _61.rpcUrls, 'optionalAccess', _62 => _62[config.chainId]])) {
2051
+ } else if (pendingRefreshRef.current || lifeRef.current.rpcUrl !== _optionalChain([options, 'access', _79 => _79.rpcUrls, 'optionalAccess', _80 => _80[config.chainId]])) {
1401
2052
  pendingRefreshRef.current = false;
1402
2053
  void refreshNow();
1403
2054
  }
@@ -1431,7 +2082,7 @@ function useMint(options) {
1431
2082
  _react.useEffect.call(void 0, () => {
1432
2083
  if (!account || !loadedDrop || isBusy()) return;
1433
2084
  const previous = lastWalletRead.current;
1434
- if (stateRef.current.blocked && _optionalChain([previous, 'optionalAccess', _63 => _63.drop]) === loadedDrop && previous.gen === walletGen && previous.quantity === machine.quantity) return;
2085
+ if (stateRef.current.blocked && _optionalChain([previous, 'optionalAccess', _81 => _81.drop]) === loadedDrop && previous.gen === walletGen && previous.quantity === machine.quantity) return;
1435
2086
  lastWalletRead.current = { drop: loadedDrop, gen: walletGen, quantity: machine.quantity };
1436
2087
  const life = lifeRef.current;
1437
2088
  const drop = stateRef.current.drop;
@@ -1449,10 +2100,10 @@ function useMint(options) {
1449
2100
  drop
1450
2101
  });
1451
2102
  if (!alive || life.controller.signal.aborted || lifeRef.current !== life || life.gen !== readGen) return;
1452
- const ineligible = _optionalChain([read, 'access', _64 => _64.ineligible, 'optionalAccess', _65 => _65.reason]) === "SIMULATION_REVERTED" ? { ...read.ineligible, message: _chunkOO6QQT3Mcjs.friendlyErrorMessage.call(void 0, new (0, _chunkOO6QQT3Mcjs.MintError)("SIMULATION_REVERTED", read.ineligible.message)) } : read.ineligible;
2103
+ const ineligible = _optionalChain([read, 'access', _82 => _82.ineligible, 'optionalAccess', _83 => _83.reason]) === "SIMULATION_REVERTED" ? { ...read.ineligible, message: _chunkX4P6BUV4cjs.friendlyErrorMessage.call(void 0, new (0, _chunkX4P6BUV4cjs.MintError)("SIMULATION_REVERTED", read.ineligible.message)) } : read.ineligible;
1453
2104
  const fullRead = { ...read, ineligible };
1454
2105
  const payChains = payChainsOf(cfg, propsRef.current.crossChain);
1455
- const crossChain = payChains.length > 0 && ineligible === null && (_nullishCoalesce(_optionalChain([adapter, 'access', _66 => _66.supportsRelay, 'optionalCall', _67 => _67(drop)]), () => ( false)));
2106
+ const crossChain = payChains.length > 0 && ineligible === null && (_nullishCoalesce(_optionalChain([adapter, 'access', _84 => _84.supportsRelay, 'optionalCall', _85 => _85(drop)]), () => ( false)));
1456
2107
  const routeChain = routeChainOf(payChains, account.chainId, propsRef.current.payChainId);
1457
2108
  const routePending = crossChain && routeChain !== cfg.chainId && payChains.includes(routeChain);
1458
2109
  dispatch({ type: "WALLET_LOADED", gen: walletGen, read: fullRead, crossChain, routePending });
@@ -1475,7 +2126,7 @@ function useMint(options) {
1475
2126
  let tx;
1476
2127
  try {
1477
2128
  tx = (await adapter.buildPlan(ctxFor(life, cfg), draft, fullRead)).mint;
1478
- } catch (e8) {
2129
+ } catch (e10) {
1479
2130
  if (!alive) return;
1480
2131
  setCrossChainInfo(null);
1481
2132
  if (routePending) dispatch({ type: "ROUTE_LOADED", gen: walletGen, route: { kind: "direct", chainId: cfg.chainId }, short: null });
@@ -1497,11 +2148,11 @@ function useMint(options) {
1497
2148
  if (routeChain !== account.chainId) {
1498
2149
  route = relay;
1499
2150
  } else {
1500
- const balance = await _chunkOO6QQT3Mcjs.getConnectedBalance.call(void 0, account.address, routeChain);
2151
+ const balance = await _chunkX4P6BUV4cjs.getConnectedBalance.call(void 0, account.address, routeChain);
1501
2152
  if (balance >= quote.amountIn.value + quote.originGas.value) route = relay;
1502
2153
  else short = shortOf(routeChain);
1503
2154
  }
1504
- } catch (e9) {
2155
+ } catch (e11) {
1505
2156
  }
1506
2157
  if (!alive || life.controller.signal.aborted || lifeRef.current !== life) return;
1507
2158
  dispatch({ type: "ROUTE_LOADED", gen: walletGen, route: short ? null : route, short });
@@ -1523,9 +2174,9 @@ function useMint(options) {
1523
2174
  const state = stateRef.current;
1524
2175
  if (!propChanged && state.account && !state.walletRead) return;
1525
2176
  const event = { type: "SET_QUANTITY", quantity: quantityProp };
1526
- const clamped = _chunkOO6QQT3Mcjs.reducer.call(void 0, state, event).quantity;
2177
+ const clamped = _chunkX4P6BUV4cjs.reducer.call(void 0, state, event).quantity;
1527
2178
  if (clamped !== state.quantity) dispatch(event);
1528
- if (clamped !== quantityProp) _optionalChain([propsRef, 'access', _68 => _68.current, 'access', _69 => _69.onQuantityChange, 'optionalCall', _70 => _70(clamped)]);
2179
+ if (clamped !== quantityProp) _optionalChain([propsRef, 'access', _86 => _86.current, 'access', _87 => _87.onQuantityChange, 'optionalCall', _88 => _88(clamped)]);
1529
2180
  }, [quantityProp, machine.quantity, machine.drop, machine.walletRead, machine.attempt, dispatch, isBusy]);
1530
2181
  _react.useEffect.call(void 0, () => {
1531
2182
  const timer = setInterval(() => {
@@ -1541,29 +2192,48 @@ function useMint(options) {
1541
2192
  document.removeEventListener("visibilitychange", onVisible);
1542
2193
  };
1543
2194
  }, [refreshNow]);
1544
- const boundary = machine.drop ? [machine.drop.startTime, machine.drop.endTime].some((t) => t !== null && t > machine.now) : false;
2195
+ const retryWhileStale = _react.useCallback.call(void 0,
2196
+ (staleKey, life) => {
2197
+ if (staleKey === void 0) return;
2198
+ const step = (tries) => {
2199
+ if (tries >= BOUNDARY_RETRY_MAX || !mounted.current || lifeRef.current !== life || _optionalChain([stateRef, 'access', _89 => _89.current, 'access', _90 => _90.drop, 'optionalAccess', _91 => _91.walletKey]) !== staleKey) return;
2200
+ if (boundaryRetryRef.current) clearTimeout(boundaryRetryRef.current);
2201
+ boundaryRetryRef.current = setTimeout(() => {
2202
+ boundaryRetryRef.current = null;
2203
+ if (!mounted.current || lifeRef.current !== life) return;
2204
+ void refreshNow().then(() => step(tries + 1));
2205
+ }, BOUNDARY_RETRY_MS);
2206
+ };
2207
+ step(0);
2208
+ },
2209
+ [refreshNow]
2210
+ );
2211
+ const boundary = machine.drop ? [machine.drop.startTime, machine.drop.endTime, _nullishCoalesce(machine.drop.phaseEndsAt, () => ( null))].some((t) => t !== null && t > machine.now) : false;
1545
2212
  _react.useEffect.call(void 0, () => {
1546
2213
  if (!boundary) return;
1547
2214
  const timer = setInterval(() => {
1548
2215
  const s = stateRef.current;
1549
2216
  const now = nowSec();
1550
- const crossed = s.drop && [s.drop.startTime, s.drop.endTime].some((t) => t !== null && t > s.now && t <= now);
2217
+ const crossed = s.drop && [s.drop.startTime, s.drop.endTime, _nullishCoalesce(s.drop.phaseEndsAt, () => ( null))].some((t) => t !== null && t > s.now && t <= now);
1551
2218
  dispatch({ type: "TICK", now });
1552
- if (crossed) void refreshNow();
2219
+ if (crossed) {
2220
+ const life = lifeRef.current;
2221
+ void refreshNow().then(() => life && retryWhileStale(_optionalChain([s, 'access', _92 => _92.drop, 'optionalAccess', _93 => _93.walletKey]), life));
2222
+ }
1553
2223
  }, TICK_MS);
1554
2224
  return () => clearInterval(timer);
1555
- }, [boundary, dispatch, refreshNow]);
2225
+ }, [boundary, dispatch, refreshNow, retryWhileStale]);
1556
2226
  const prevName = _react.useRef.call(void 0, null);
1557
2227
  _react.useEffect.call(void 0, () => {
1558
2228
  const name = widgetFail ? isUnsupported(widgetFail.reason) ? "unsupported" : "error" : machine.name;
1559
2229
  if (prevName.current === name) return;
1560
2230
  prevName.current = name;
1561
- emit("state", { state: name, reason: _nullishCoalesce(_optionalChain([widgetFail, 'optionalAccess', _71 => _71.reason]), () => ( machine.reason)) });
2231
+ emit("state", { state: name, reason: _nullishCoalesce(_optionalChain([widgetFail, 'optionalAccess', _94 => _94.reason]), () => ( machine.reason)) });
1562
2232
  }, [machine.name, machine.reason, widgetFail, emit]);
1563
2233
  const setQuantity = _react.useCallback.call(void 0,
1564
2234
  (next) => {
1565
2235
  const s = stateRef.current;
1566
- const max = _nullishCoalesce(_chunkOO6QQT3Mcjs.selectMaxQuantity.call(void 0, s), () => ( 65535));
2236
+ const max = _nullishCoalesce(_chunkX4P6BUV4cjs.selectMaxQuantity.call(void 0, s), () => ( 65535));
1567
2237
  const clamped = Math.max(1, Math.min(Math.floor(Number.isNaN(next) ? 1 : next), max));
1568
2238
  const handler = propsRef.current.onQuantityChange;
1569
2239
  if (handler) {
@@ -1598,16 +2268,16 @@ function useMint(options) {
1598
2268
  wallet,
1599
2269
  quantity: machine.quantity,
1600
2270
  setQuantity,
1601
- maxQuantity: _chunkOO6QQT3Mcjs.selectMaxQuantity.call(void 0, machine),
1602
- total: _chunkOO6QQT3Mcjs.selectTotal.call(void 0, machine),
2271
+ maxQuantity: _chunkX4P6BUV4cjs.selectMaxQuantity.call(void 0, machine),
2272
+ total: _chunkX4P6BUV4cjs.selectTotal.call(void 0, machine),
1603
2273
  mint,
1604
2274
  result: machine.result,
1605
2275
  refresh,
1606
2276
  // An attempt claimed by a click is not clickable, even while the reducer still reads 'live'.
1607
- canAct: _chunkOO6QQT3Mcjs.canAct.call(void 0, { ...machine, name: effective.name }) && machine.attempt === null,
2277
+ canAct: _chunkX4P6BUV4cjs.canAct.call(void 0, { ...machine, name: effective.name }) && machine.attempt === null,
1608
2278
  // Short on the wallet chain is neither route: nothing can be paid until the collector picks another chain.
1609
2279
  route: _nullishCoalesce(machine.route, () => ( (machine.walletRead && machine.drop && !machine.routePending && machine.short === null ? { kind: "direct", chainId: machine.drop.chainId } : null))),
1610
- crossChain: machine.crossChain && machine.account && _optionalChain([crossChainInfo, 'optionalAccess', _72 => _72.gen]) === machine.walletGen ? crossChainInfo.info : null
2280
+ crossChain: machine.crossChain && machine.account && _optionalChain([crossChainInfo, 'optionalAccess', _95 => _95.gen]) === machine.walletGen ? crossChainInfo.info : null
1611
2281
  };
1612
2282
  }
1613
2283
 
@@ -1617,13 +2287,13 @@ function useMint(options) {
1617
2287
  var PICKER_REFRESH_MS = 2e4;
1618
2288
  var PICKER_DEBOUNCE_MS = 500;
1619
2289
  var RELAY_REASONS = /* @__PURE__ */ new Set(["BRIDGE_UNAVAILABLE", "BRIDGE_TIMEOUT", "BRIDGE_REFUNDED", "BRIDGE_FAILED"]);
1620
- var money2 = (value, chainId) => {
1621
- const c = _chunkOO6QQT3Mcjs.getChain.call(void 0, chainId).nativeCurrency;
2290
+ var money3 = (value, chainId) => {
2291
+ const c = _chunkX4P6BUV4cjs.getChain.call(void 0, chainId).nativeCurrency;
1622
2292
  return { value, decimals: c.decimals, symbol: c.symbol, formatted: _viem.formatUnits.call(void 0, value, c.decimals) };
1623
2293
  };
1624
2294
  function usePayOptions(mint, onSelect) {
1625
2295
  const info = mint.crossChain;
1626
- const current = _nullishCoalesce(_optionalChain([mint, 'access', _73 => _73.wallet, 'optionalAccess', _74 => _74.chainId]), () => ( null));
2296
+ const current = _nullishCoalesce(_optionalChain([mint, 'access', _96 => _96.wallet, 'optionalAccess', _97 => _97.chainId]), () => ( null));
1627
2297
  const [quotes, setQuotes] = _react.useState.call(void 0, {});
1628
2298
  const [balance, setBalance] = _react.useState.call(void 0, null);
1629
2299
  const [tick, setTick] = _react.useState.call(void 0, 0);
@@ -1648,7 +2318,7 @@ function usePayOptions(mint, onSelect) {
1648
2318
  if (!controller.signal.aborted) setQuotes((prev) => ({ ...prev, [chainId]: { relayFee: q.relayFee, amountIn: q.amountIn } }));
1649
2319
  },
1650
2320
  (e) => {
1651
- if (controller.signal.aborted || _optionalChain([e, 'optionalAccess', _75 => _75.reason]) === "RATE_LIMITED") return;
2321
+ if (controller.signal.aborted || _optionalChain([e, 'optionalAccess', _98 => _98.reason]) === "RATE_LIMITED") return;
1652
2322
  setQuotes((prev) => ({ ...prev, [chainId]: "failed" }));
1653
2323
  }
1654
2324
  );
@@ -1662,7 +2332,7 @@ function usePayOptions(mint, onSelect) {
1662
2332
  _react.useEffect.call(void 0, () => {
1663
2333
  if (!info || current === null || !mint.wallet) return;
1664
2334
  let alive = true;
1665
- _chunkOO6QQT3Mcjs.getConnectedBalance.call(void 0, mint.wallet.address, current).then(
2335
+ _chunkX4P6BUV4cjs.getConnectedBalance.call(void 0, mint.wallet.address, current).then(
1666
2336
  (value) => {
1667
2337
  if (alive) setBalance({ chainId: current, value });
1668
2338
  },
@@ -1673,12 +2343,12 @@ function usePayOptions(mint, onSelect) {
1673
2343
  return () => {
1674
2344
  alive = false;
1675
2345
  };
1676
- }, [current, _optionalChain([mint, 'access', _76 => _76.wallet, 'optionalAccess', _77 => _77.address]), key, tick]);
2346
+ }, [current, _optionalChain([mint, 'access', _99 => _99.wallet, 'optionalAccess', _100 => _100.address]), key, tick]);
1677
2347
  const select = _react.useCallback.call(void 0,
1678
2348
  (chainId) => {
1679
- _chunkOO6QQT3Mcjs.switchToChain.call(void 0, chainId).then(
1680
- () => _optionalChain([onSelect, 'optionalCall', _78 => _78(chainId, null)]),
1681
- (e) => _optionalChain([onSelect, 'optionalCall', _79 => _79(chainId, e)])
2349
+ _chunkX4P6BUV4cjs.switchToChain.call(void 0, chainId).then(
2350
+ () => _optionalChain([onSelect, 'optionalCall', _101 => _101(chainId, null)]),
2351
+ (e) => _optionalChain([onSelect, 'optionalCall', _102 => _102(chainId, e)])
1682
2352
  );
1683
2353
  },
1684
2354
  [onSelect]
@@ -1690,12 +2360,12 @@ function usePayOptions(mint, onSelect) {
1690
2360
  const quoted = q && q !== "failed" ? q : null;
1691
2361
  return {
1692
2362
  chainId,
1693
- name: _chunkOO6QQT3Mcjs.chainName.call(void 0, chainId),
2363
+ name: _chunkX4P6BUV4cjs.chainName.call(void 0, chainId),
1694
2364
  selected: chainId === current,
1695
2365
  isDropChain,
1696
- relayFee: isDropChain ? null : _nullishCoalesce(_optionalChain([quoted, 'optionalAccess', _80 => _80.relayFee]), () => ( null)),
1697
- amountIn: isDropChain ? null : _nullishCoalesce(_optionalChain([quoted, 'optionalAccess', _81 => _81.amountIn]), () => ( null)),
1698
- balance: balance && balance.chainId === chainId && chainId === current ? money2(balance.value, chainId) : null,
2366
+ relayFee: isDropChain ? null : _nullishCoalesce(_optionalChain([quoted, 'optionalAccess', _103 => _103.relayFee]), () => ( null)),
2367
+ amountIn: isDropChain ? null : _nullishCoalesce(_optionalChain([quoted, 'optionalAccess', _104 => _104.amountIn]), () => ( null)),
2368
+ balance: balance && balance.chainId === chainId && chainId === current ? money3(balance.value, chainId) : null,
1699
2369
  loading: !isDropChain && q === void 0,
1700
2370
  select: () => select(chainId)
1701
2371
  };
@@ -1736,14 +2406,14 @@ function PayWithPicker(props) {
1736
2406
  // src/react/MintButton.ts
1737
2407
 
1738
2408
  function defaultLabel(m) {
1739
- const symbol = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([m, 'access', _82 => _82.total, 'optionalAccess', _83 => _83.erc20, 'optionalAccess', _84 => _84.symbol]), () => ( _optionalChain([m, 'access', _85 => _85.total, 'optionalAccess', _86 => _86.native, 'access', _87 => _87.symbol]))), () => ( _optionalChain([m, 'access', _88 => _88.drop, 'optionalAccess', _89 => _89.unitPrice, 'access', _90 => _90.symbol]))), () => ( ""));
2409
+ const symbol = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([m, 'access', _105 => _105.total, 'optionalAccess', _106 => _106.erc20, 'optionalAccess', _107 => _107.symbol]), () => ( _optionalChain([m, 'access', _108 => _108.total, 'optionalAccess', _109 => _109.native, 'access', _110 => _110.symbol]))), () => ( _optionalChain([m, 'access', _111 => _111.drop, 'optionalAccess', _112 => _112.unitPrice, 'access', _113 => _113.symbol]))), () => ( ""));
1740
2410
  switch (m.state) {
1741
2411
  case "loading":
1742
2412
  return "Loading\u2026";
1743
2413
  case "unsupported":
1744
2414
  return "Unavailable";
1745
2415
  case "upcoming": {
1746
- const t = _optionalChain([m, 'access', _91 => _91.drop, 'optionalAccess', _92 => _92.startTime]);
2416
+ const t = _optionalChain([m, 'access', _114 => _114.drop, 'optionalAccess', _115 => _115.startTime]);
1747
2417
  return `Starts ${t ? new Date(t * 1e3).toLocaleString() : "soon"}`;
1748
2418
  }
1749
2419
  case "ended":
@@ -1756,8 +2426,8 @@ function defaultLabel(m) {
1756
2426
  return "Connecting\u2026";
1757
2427
  case "live": {
1758
2428
  const route = m.route;
1759
- if (_optionalChain([route, 'optionalAccess', _93 => _93.kind]) === "relay") {
1760
- return `Mint \xB7 ${route.amountIn.formatted} ${route.amountIn.symbol} on ${_chunkOO6QQT3Mcjs.chainName.call(void 0, route.originChainId)}`;
2429
+ if (_optionalChain([route, 'optionalAccess', _116 => _116.kind]) === "relay") {
2430
+ return `Mint \xB7 ${route.amountIn.formatted} ${route.amountIn.symbol} on ${_chunkX4P6BUV4cjs.chainName.call(void 0, route.originChainId)}`;
1761
2431
  }
1762
2432
  const total = m.total;
1763
2433
  if (!total) return "Mint";
@@ -1767,8 +2437,8 @@ function defaultLabel(m) {
1767
2437
  case "ineligible":
1768
2438
  return "Not eligible";
1769
2439
  case "insufficient-funds": {
1770
- const erc20 = _optionalChain([m, 'access', _94 => _94.total, 'optionalAccess', _95 => _95.erc20]);
1771
- const shortage = erc20 && m.message === `Not enough ${erc20.symbol} to cover the mint.` ? erc20.symbol : _nullishCoalesce(_optionalChain([m, 'access', _96 => _96.total, 'optionalAccess', _97 => _97.native, 'access', _98 => _98.symbol]), () => ( symbol));
2440
+ const erc20 = _optionalChain([m, 'access', _117 => _117.total, 'optionalAccess', _118 => _118.erc20]);
2441
+ const shortage = erc20 && m.message === `Not enough ${erc20.symbol} to cover the mint.` ? erc20.symbol : _nullishCoalesce(_optionalChain([m, 'access', _119 => _119.total, 'optionalAccess', _120 => _120.native, 'access', _121 => _121.symbol]), () => ( symbol));
1772
2442
  return `Insufficient ${shortage}`.trimEnd();
1773
2443
  }
1774
2444
  case "switching-chain":
@@ -1789,7 +2459,7 @@ function MintButton(props) {
1789
2459
  const { className, labels, children, ...options } = props;
1790
2460
  const m = useMint(options);
1791
2461
  if (typeof children === "function") return children(m);
1792
- const label = _nullishCoalesce(_optionalChain([labels, 'optionalAccess', _99 => _99[m.state]]), () => ( defaultLabel(m)));
2462
+ const label = _nullishCoalesce(_optionalChain([labels, 'optionalAccess', _122 => _122[m.state]]), () => ( defaultLabel(m)));
1793
2463
  return _react.createElement.call(void 0,
1794
2464
  "button",
1795
2465
  {
@@ -1806,7 +2476,7 @@ function MintButton(props) {
1806
2476
  }
1807
2477
 
1808
2478
  // src/index.ts
1809
- var VERSION = "0.3.0";
2479
+ var VERSION = "0.4.1";
1810
2480
 
1811
2481
 
1812
2482
 
@@ -1819,5 +2489,5 @@ var VERSION = "0.3.0";
1819
2489
 
1820
2490
 
1821
2491
 
1822
- exports.CLICKABLE_STATES = _chunkOO6QQT3Mcjs.CLICKABLE_STATES; exports.MAX_QUANTITY = _chunkOO6QQT3Mcjs.MAX_QUANTITY; exports.MINT_STATES = _chunkOO6QQT3Mcjs.MINT_STATES; exports.MintButton = MintButton; exports.MintError = _chunkOO6QQT3Mcjs.MintError; exports.PayWithPicker = PayWithPicker; exports.REASON_CODES = _chunkOO6QQT3Mcjs.REASON_CODES; exports.VERSION = VERSION; exports.isMintError = _chunkOO6QQT3Mcjs.isMintError; exports.useMint = useMint; exports.usePayOptions = usePayOptions;
2492
+ exports.CLICKABLE_STATES = _chunkX4P6BUV4cjs.CLICKABLE_STATES; exports.MAX_QUANTITY = _chunkX4P6BUV4cjs.MAX_QUANTITY; exports.MINT_STATES = _chunkX4P6BUV4cjs.MINT_STATES; exports.MintButton = MintButton; exports.MintError = _chunkX4P6BUV4cjs.MintError; exports.PayWithPicker = PayWithPicker; exports.REASON_CODES = _chunkX4P6BUV4cjs.REASON_CODES; exports.VERSION = VERSION; exports.isMintError = _chunkX4P6BUV4cjs.isMintError; exports.useMint = useMint; exports.usePayOptions = usePayOptions;
1823
2493
  //# sourceMappingURL=index.cjs.map