@manifoldxyz/dropkit 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,7 +43,7 @@ function friendlyErrorMessage(error) {
43
43
  const errors = collect(error);
44
44
  const hasText = (phrase) => errors.some((e) => e.message.includes(phrase));
45
45
  const hasName = (name) => errors.some((e) => e.name === name);
46
- const hasCode2 = (code2) => errors.some((e) => e.code === code2);
46
+ const hasCode2 = (code) => errors.some((e) => e.code === code);
47
47
  if (hasName("UserRejectedRequestError") || hasCode2("ACTION_REJECTED") || hasCode2(4001) || hasText("user denied transaction signature") || hasText("userrefusedondevice") || hasText("rejected transaction") || hasText("user rejected") || errors.some((e) => e.message.includes("cancelled") && !e.cancelled)) {
48
48
  return "Transaction Rejected";
49
49
  }
@@ -149,264 +149,6 @@ function toReason(e) {
149
149
  return { reason: "RPC_ERROR", message: friendlyErrorMessage(e) };
150
150
  }
151
151
 
152
- // src/core/machine.ts
153
- import { formatUnits } from "viem";
154
- var MINT_STATES = [
155
- "loading",
156
- "unsupported",
157
- "upcoming",
158
- "ended",
159
- "sold-out",
160
- "disconnected",
161
- "connecting",
162
- "live",
163
- "ineligible",
164
- "insufficient-funds",
165
- "switching-chain",
166
- "approving",
167
- "minting",
168
- "confirming",
169
- "success",
170
- "error"
171
- ];
172
- var CLICKABLE_STATES = ["disconnected", "live", "success", "error"];
173
- var IN_FLIGHT_STATES = ["switching-chain", "approving", "minting", "confirming"];
174
- var MAX_QUANTITY = 65535;
175
- function initialState(opts) {
176
- return {
177
- name: "loading",
178
- reason: null,
179
- message: null,
180
- readGen: 0,
181
- walletGen: 0,
182
- drop: null,
183
- account: null,
184
- walletRead: null,
185
- blocked: null,
186
- quantity: toQuantity(opts?.quantity ?? 1, MAX_QUANTITY),
187
- attempt: null,
188
- result: null,
189
- pendingRefresh: false,
190
- now: 0,
191
- crossChain: false,
192
- routePending: false,
193
- route: null,
194
- short: null
195
- };
196
- }
197
- var NO_ROUTE = { crossChain: false, routePending: false, route: null, short: null };
198
- var PICK_ANOTHER = "Pick another network to pay from.";
199
- function toQuantity(q, max) {
200
- if (Number.isNaN(q)) return 1;
201
- return Math.max(1, Math.min(Math.floor(q), max));
202
- }
203
- function isInFlight(s) {
204
- return s.attempt !== null || IN_FLIGHT_STATES.includes(s.name);
205
- }
206
- function isIdle(s) {
207
- return !isInFlight(s) && s.name !== "connecting" && s.name !== "success" && s.name !== "error";
208
- }
209
- function derive(s, unsupported) {
210
- const named = (name) => ({ name, reason: null, message: null });
211
- const { drop, walletRead } = s;
212
- if (unsupported) return { name: "unsupported", reason: s.reason, message: s.message };
213
- if (drop === null) return named("loading");
214
- if (drop.endTime !== null && drop.endTime <= s.now) return named("ended");
215
- if (drop.maxSupply !== null && drop.maxSupply > 0n && drop.totalMinted >= drop.maxSupply) return named("sold-out");
216
- if (drop.startTime !== null && drop.startTime > s.now) return named("upcoming");
217
- if (s.account === null) return named("disconnected");
218
- if (walletRead === null) return named("loading");
219
- if (s.blocked !== null) return s.blocked;
220
- if (walletRead.ineligible !== null) {
221
- return { name: "ineligible", reason: walletRead.ineligible.reason, message: walletRead.ineligible.message };
222
- }
223
- if (s.routePending) return named("loading");
224
- if (s.route?.kind === "relay") return named("live");
225
- if (s.short !== null) {
226
- return { name: "insufficient-funds", reason: "INSUFFICIENT_FUNDS", message: `Not enough ${s.short.symbol} on ${s.short.name}. ${PICK_ANOTHER}` };
227
- }
228
- const total = selectTotal(s);
229
- if (total !== null) {
230
- const { native, erc20 } = total;
231
- if (native.value + walletRead.gasReserve > walletRead.balances.native) {
232
- const more = s.crossChain ? ` ${PICK_ANOTHER}` : "";
233
- return { name: "insufficient-funds", reason: "INSUFFICIENT_FUNDS", message: `Not enough ${native.symbol} to cover the mint.${more}` };
234
- }
235
- if (erc20 !== null && walletRead.balances.erc20 !== null && erc20.value > walletRead.balances.erc20) {
236
- return { name: "insufficient-funds", reason: "INSUFFICIENT_FUNDS", message: `Not enough ${erc20.symbol} to cover the mint.` };
237
- }
238
- }
239
- return named("live");
240
- }
241
- function settle(s, unsupported = s.name === "unsupported") {
242
- if (!isIdle(s)) return s;
243
- return { ...s, ...derive(s, unsupported) };
244
- }
245
- function clampQuantity(s) {
246
- const quantity = toQuantity(s.quantity, selectMaxQuantity(s) ?? MAX_QUANTITY);
247
- return quantity === s.quantity ? s : { ...s, quantity };
248
- }
249
- function reducer(state, event) {
250
- const inFlight = isInFlight(state);
251
- const failed = (reason, message) => {
252
- if (inFlight) return { ...state, pendingRefresh: true };
253
- if (state.name === "success" || state.name === "error") return state;
254
- return { ...state, name: "error", reason, message };
255
- };
256
- switch (event.type) {
257
- case "LOAD": {
258
- if (event.kind === "refresh") {
259
- const next2 = { ...state, readGen: event.gen };
260
- return inFlight ? { ...next2, pendingRefresh: true } : settle(next2);
261
- }
262
- const next = { ...state, ...NO_ROUTE, readGen: event.gen, drop: null, walletRead: null, blocked: null, walletGen: state.walletGen + 1 };
263
- return inFlight ? { ...next, pendingRefresh: true } : settle(next, false);
264
- }
265
- case "DROP_LOADED": {
266
- if (event.gen !== state.readGen) return state;
267
- let next = { ...state, drop: event.drop, now: Math.max(state.now, event.now) };
268
- const oldKey = state.drop?.walletKey;
269
- const newKey = event.drop.walletKey;
270
- if (oldKey !== void 0 && newKey !== void 0 && oldKey !== newKey) {
271
- next = { ...next, walletRead: null, walletGen: state.walletGen + 1 };
272
- }
273
- if (inFlight) return { ...next, pendingRefresh: true };
274
- return isIdle(next) ? settle(clampQuantity(next), false) : clampQuantity(next);
275
- }
276
- case "DROP_UNSUPPORTED": {
277
- if (event.gen !== state.readGen) return state;
278
- if (inFlight) return { ...state, pendingRefresh: true };
279
- if (state.name === "success" || state.name === "error") return state;
280
- return { ...state, name: "unsupported", reason: event.reason, message: event.message };
281
- }
282
- case "READ_FAILED":
283
- return event.gen !== state.readGen ? state : failed(event.reason, event.message);
284
- case "ACCOUNT_CHANGED": {
285
- const next = { ...state, ...NO_ROUTE, account: event.account, walletRead: null, blocked: null, walletGen: state.walletGen + 1 };
286
- if (inFlight) return { ...next, pendingRefresh: true };
287
- if (state.name === "connecting") return event.account === null ? next : settle({ ...next, name: "loading" }, false);
288
- return settle(next);
289
- }
290
- case "WALLET_LOADED": {
291
- if (event.gen !== state.walletGen) return state;
292
- const route = event.routePending ? { routePending: state.route === null && state.short === null, route: state.route, short: state.short } : { routePending: false, route: null, short: null };
293
- const next = { ...state, ...route, crossChain: event.crossChain ?? false, walletRead: event.read, blocked: null };
294
- return inFlight ? { ...next, pendingRefresh: true } : settle(clampQuantity(next));
295
- }
296
- case "ROUTE_LOADED": {
297
- if (event.gen !== state.walletGen) return state;
298
- const next = { ...state, routePending: false, route: event.route, short: event.short };
299
- return inFlight ? { ...next, pendingRefresh: true } : settle(next);
300
- }
301
- case "WALLET_FAILED":
302
- return event.gen !== state.walletGen ? state : failed(event.reason, event.message);
303
- case "CONNECT_STARTED":
304
- return state.name === "disconnected" && state.attempt === null ? { ...state, name: "connecting", reason: null, message: null } : state;
305
- case "CONNECT_DISMISSED":
306
- return state.name === "connecting" ? settle({ ...state, name: "disconnected" }, false) : state;
307
- case "TICK":
308
- return settle({ ...state, now: Math.max(state.now, event.now) });
309
- case "SET_QUANTITY": {
310
- const next = { ...state, quantity: toQuantity(event.quantity, selectMaxQuantity(state) ?? MAX_QUANTITY) };
311
- return inFlight ? { ...next, pendingRefresh: true } : settle(next);
312
- }
313
- case "ATTEMPT_STARTED":
314
- if (state.attempt !== null) return state;
315
- if (event.resume === true) return IN_FLIGHT_STATES.includes(state.name) ? state : { ...state, attempt: event.attempt };
316
- return state.name === "live" ? { ...state, attempt: event.attempt } : state;
317
- case "SWITCHING_CHAIN":
318
- return step(state, event.attemptId, "switching-chain");
319
- case "APPROVING":
320
- return step(state, event.attemptId, "approving");
321
- case "MINT_PROMPTED":
322
- return step(state, event.attemptId, "minting");
323
- case "TX_SUBMITTED":
324
- return step(state, event.attemptId, "confirming");
325
- case "ATTEMPT_SUCCEEDED":
326
- return state.attempt?.attemptId === event.attemptId ? {
327
- ...state,
328
- name: "success",
329
- reason: null,
330
- message: null,
331
- attempt: null,
332
- result: event.result,
333
- drop: null,
334
- readGen: state.readGen + 1
335
- } : state;
336
- case "ATTEMPT_FAILED": {
337
- if (state.attempt?.attemptId !== event.attemptId) return state;
338
- const { reason, message } = event;
339
- const done = { ...state, reason, message, attempt: null, result: null };
340
- if (INELIGIBLE_REASONS.includes(reason)) {
341
- return { ...done, name: "ineligible", blocked: { name: "ineligible", reason, message } };
342
- }
343
- if (reason === "INSUFFICIENT_FUNDS") {
344
- return { ...done, name: "insufficient-funds", blocked: { name: "insufficient-funds", reason, message } };
345
- }
346
- return {
347
- ...done,
348
- name: "error",
349
- drop: state.name === "confirming" ? null : state.drop,
350
- readGen: state.name === "confirming" ? state.readGen + 1 : state.readGen
351
- };
352
- }
353
- case "RESET": {
354
- if (state.name !== "success" && state.name !== "error") return state;
355
- const next = {
356
- ...state,
357
- readGen: event.gen,
358
- ...NO_ROUTE,
359
- walletRead: null,
360
- blocked: null,
361
- walletGen: state.walletGen + 1,
362
- result: null,
363
- pendingRefresh: false
364
- };
365
- return settle(clampQuantity({ ...next, name: "loading" }), false);
366
- }
367
- }
368
- }
369
- var STEP_ORDER = ["switching-chain", "approving", "minting", "confirming"];
370
- function step(state, attemptId, name) {
371
- if (state.attempt?.attemptId !== attemptId) return state;
372
- if (STEP_ORDER.indexOf(name) <= STEP_ORDER.indexOf(state.name)) return state;
373
- return { ...state, name, reason: null, message: null };
374
- }
375
- function selectMaxQuantity(state) {
376
- const { drop, walletRead } = state;
377
- if (drop === null) return null;
378
- let max = MAX_QUANTITY;
379
- if (drop.maxSupply !== null && drop.maxSupply > 0n) {
380
- const remaining = drop.maxSupply - drop.totalMinted;
381
- if (remaining < BigInt(max)) max = remaining > 0n ? Number(remaining) : 0;
382
- }
383
- if (walletRead !== null && walletRead.maxQuantity !== null) {
384
- max = Math.min(max, Math.max(0, Math.floor(walletRead.maxQuantity)));
385
- }
386
- return max;
387
- }
388
- function selectTotal(state) {
389
- const { drop } = state;
390
- if (drop === null) return null;
391
- const q = BigInt(state.quantity);
392
- const price = drop.unitPrice;
393
- const fee = drop.unitFee;
394
- const priceTotal = drop.pricePer === "total" ? price.value : price.value * q;
395
- if (drop.paymentToken !== null) {
396
- return {
397
- native: money(fee.value * q, fee),
398
- erc20: money(priceTotal, price)
399
- };
400
- }
401
- return { native: money(priceTotal + fee.value * q, price), erc20: null };
402
- }
403
- function money(value, like) {
404
- return { value, decimals: like.decimals, symbol: like.symbol, formatted: formatUnits(value, like.decimals) };
405
- }
406
- function canAct(state) {
407
- return state.attempt === null && CLICKABLE_STATES.includes(state.name);
408
- }
409
-
410
152
  // src/core/rpc/index.ts
411
153
  import { createPublicClient, http } from "viem";
412
154
  import { apeChain, base, baseSepolia, mainnet, optimism, sepolia, shape } from "viem/chains";
@@ -509,277 +251,14 @@ function createReadClient(opts) {
509
251
  return createPublicClient({ chain, transport });
510
252
  }
511
253
 
512
- // src/core/wallet/index.ts
513
- import { createWalletClient, custom, getAddress, publicActions } from "viem";
514
- var CONNECT_WIDGET_VERSION = "6.5.0";
515
- var CONNECT_BASE_URL = `https://connect.manifoldxyz.dev/${CONNECT_WIDGET_VERSION}`;
516
- var CONNECT_ID = "mint-button";
517
- var ADDRESS_CHANGED = "ethereum-address-changed";
518
- var CHAIN_CHANGED = "frontend-provider-chain-changed";
519
- var LOADER_KEY = "__manifoldMintConnectLoader";
520
- var DEFAULT_WALLETCONNECT_PROJECT_ID = "a03ac1695f309dc8d756e7b4006e5e7d";
521
- var STATE_KEY = "__manifoldMintConnectStateV1";
522
- var win = () => window;
523
- var pageState = () => win()[STATE_KEY] ??= {};
524
- var TOO_OLD = "A Manifold connect widget older than 6.4.0 is already on this page; update it or remove it so dropkit can load " + CONNECT_WIDGET_VERSION + ".";
525
- var MANIFOLD_HOST = /(^|\.)(manifoldxyz\.dev|manifold\.xyz)$/;
526
- function isManifoldConnectScript(src) {
527
- try {
528
- const url = new URL(src, document.baseURI);
529
- return url.hostname === "connect.manifoldxyz.dev" || MANIFOLD_HOST.test(url.hostname) && /\/connect\.umd[^/]*\.js$/.test(url.pathname);
530
- } catch {
531
- return false;
532
- }
533
- }
534
- function applyState(state) {
535
- if (!state.div) return;
536
- const network = state.networks.join(",");
537
- if (state.div.dataset.network !== network) state.div.dataset.network = network;
538
- const projectId = state.projectId ?? state.div.dataset.walletConnectProjectId ?? DEFAULT_WALLETCONNECT_PROJECT_ID;
539
- if (state.div.dataset.walletConnectProjectId !== projectId) state.div.dataset.walletConnectProjectId = projectId;
540
- }
541
- function register(state, opts) {
542
- for (const id2 of opts.chainIds) if (!state.networks.includes(id2)) state.networks.push(id2);
543
- const id = opts.walletConnectProjectId;
544
- if (id) {
545
- if (!state.projectId) state.projectId = id;
546
- else if (state.projectId !== id) {
547
- console.warn(`dropkit: walletConnectProjectId "${id}" ignored; this page already uses "${state.projectId}" for the shared connect widget.`);
548
- }
549
- }
550
- applyState(state);
551
- }
552
- function startLoad(state) {
553
- const connect = win().ManifoldConnect;
554
- if (connect?.capabilities?.includes("open")) return Promise.resolve(connect.ready).then(() => void 0);
555
- const hasScript = Array.from(document.querySelectorAll("script[src]")).some((s) => isManifoldConnectScript(s.src));
556
- if (hasScript || document.querySelector('[data-widget="m-connect"]')) {
557
- return Promise.reject(new MintError("CONNECT_WIDGET_TOO_OLD", TOO_OLD));
558
- }
559
- return new Promise((resolve, reject) => {
560
- const css = document.createElement("link");
561
- css.rel = "stylesheet";
562
- css.href = `${CONNECT_BASE_URL}/connect.css`;
563
- document.head.appendChild(css);
564
- state.nodes.push(css);
565
- const div = document.createElement("div");
566
- div.hidden = true;
567
- div.style.display = "none";
568
- div.dataset.widget = "m-connect";
569
- div.dataset.connectId = CONNECT_ID;
570
- div.dataset.autoReconnect = "true";
571
- div.dataset.enableNetworkSwitching = "true";
572
- state.div = div;
573
- applyState(state);
574
- document.body.appendChild(div);
575
- state.nodes.push(div);
576
- const script = document.createElement("script");
577
- script.src = `${CONNECT_BASE_URL}/connect.umd.min.js`;
578
- script.async = true;
579
- script.addEventListener("load", () => {
580
- const ready = win().ManifoldConnect?.ready;
581
- if (!ready) return reject(new MintError("CONNECT_WIDGET_TOO_OLD", TOO_OLD));
582
- Promise.resolve(ready).then(() => resolve(), reject);
583
- });
584
- script.addEventListener("error", () => reject(new MintError("RPC_ERROR", `Could not load the Manifold connect widget from ${CONNECT_BASE_URL}`)));
585
- document.head.appendChild(script);
586
- state.nodes.push(script);
587
- });
588
- }
589
- function loadConnectWidget(opts) {
590
- const w = win();
591
- const page = pageState();
592
- const existing = w[LOADER_KEY];
593
- if (existing) {
594
- if (page.load?.promise !== existing) {
595
- const div = document.querySelector(`[data-widget="m-connect"][data-connect-id="${CONNECT_ID}"]`) ?? void 0;
596
- page.load = {
597
- promise: existing,
598
- networks: div?.dataset.network?.split(",").filter(Boolean).map(Number) ?? [],
599
- // The default id is a placeholder, not a choice: a caller's real id may still replace it.
600
- projectId: div?.dataset.walletConnectProjectId === DEFAULT_WALLETCONNECT_PROJECT_ID ? void 0 : div?.dataset.walletConnectProjectId,
601
- div,
602
- nodes: []
603
- };
604
- }
605
- register(page.load, opts);
606
- return existing;
607
- }
608
- let resolve;
609
- let reject;
610
- const p = new Promise((res, rej) => {
611
- resolve = res;
612
- reject = rej;
613
- });
614
- const state = { promise: p, networks: [], nodes: [] };
615
- page.load = state;
616
- w[LOADER_KEY] = p;
617
- p.catch(() => {
618
- if (w[LOADER_KEY] === p) delete w[LOADER_KEY];
619
- if (page.load === state) page.load = void 0;
620
- for (const node of state.nodes) node.parentNode?.removeChild(node);
621
- state.nodes.length = 0;
622
- state.div = void 0;
623
- });
624
- register(state, opts);
625
- try {
626
- startLoad(state).then(resolve, reject);
627
- } catch (error) {
628
- reject(error);
629
- }
630
- return p;
631
- }
632
- function openConnectModal() {
633
- const page = pageState();
634
- if (page.pendingModal) return page.pendingModal;
635
- const p = new Promise((resolve) => {
636
- const onClosed = (e) => {
637
- const detail = e.detail ?? {};
638
- if (detail.connectId !== void 0 && detail.connectId !== CONNECT_ID) return;
639
- window.removeEventListener("m-connect:closed", onClosed);
640
- page.pendingModal = void 0;
641
- resolve(detail.reason === "connected" ? "connected" : "dismissed");
642
- };
643
- window.addEventListener("m-connect:closed", onClosed);
644
- });
645
- page.pendingModal = p;
646
- window.dispatchEvent(new CustomEvent("m-connect:open", { detail: { connectId: CONNECT_ID } }));
647
- return p;
648
- }
649
- function getAccount() {
650
- const p = win().ManifoldEthereumProvider;
651
- const address = p?.selectedAddress?.();
652
- let chainId = p?.chainId?.();
653
- if (chainId === void 0 || chainId === null) {
654
- try {
655
- chainId = p?.browserChainId?.();
656
- } catch {
657
- chainId = void 0;
658
- }
659
- }
660
- if (!address || chainId === void 0 || chainId === null) return null;
661
- return { address: getAddress(address), chainId: Number(chainId) };
662
- }
663
- function subscribeAccount(cb) {
664
- const handler = () => cb(getAccount());
665
- window.addEventListener(ADDRESS_CHANGED, handler);
666
- window.addEventListener(CHAIN_CHANGED, handler);
667
- return () => {
668
- window.removeEventListener(ADDRESS_CHANGED, handler);
669
- window.removeEventListener(CHAIN_CHANGED, handler);
670
- };
671
- }
672
- function eip1193() {
673
- const p = win().ManifoldEthereumProvider;
674
- const provider = (p?.provider?.(true) ?? p?.browserProvider?.())?.provider;
675
- if (!provider) throw new MintError("CHAIN_SWITCH_FAILED", "No wallet is connected.");
676
- return provider;
677
- }
678
- function getWalletClient(chainId) {
679
- const provider = eip1193();
680
- const request = ((args) => provider.request(args));
681
- return createWalletClient({ chain: getChain(chainId), transport: custom({ request }) });
682
- }
683
- async function waitForDeposit(chainId, hash, timeoutMs = 12e4) {
684
- try {
685
- const receipt = await getWalletClient(chainId).extend(publicActions).waitForTransactionReceipt({ hash, confirmations: 1, timeout: timeoutMs });
686
- return receipt.status === "reverted" ? "reverted" : "mined";
687
- } catch {
688
- return "unknown";
689
- }
690
- }
691
- var WALLET_READ_TIMEOUT = { ms: 1e4 };
692
- async function getConnectedBalance(address, chainId) {
693
- const provider = eip1193();
694
- let timer;
695
- const timeout = new Promise((_, reject) => {
696
- timer = setTimeout(() => reject(new MintError("RPC_ERROR", "The wallet did not report a balance in time.")), WALLET_READ_TIMEOUT.ms);
697
- });
698
- try {
699
- return await Promise.race([
700
- (async () => {
701
- const current = Number(await provider.request({ method: "eth_chainId" }));
702
- if (current !== chainId) {
703
- throw new MintError("CHAIN_SWITCH_FAILED", `The wallet is on chain ${String(current)}, not ${String(chainId)}.`);
704
- }
705
- const hex = await provider.request({ method: "eth_getBalance", params: [address, "latest"] });
706
- return BigInt(hex);
707
- })(),
708
- timeout
709
- ]);
710
- } finally {
711
- clearTimeout(timer);
712
- }
713
- }
714
- var code = (e) => e?.code;
715
- var hexChainId = (chainId) => `0x${chainId.toString(16)}`;
716
- var sendSwitchRequest = (provider, chainId) => provider.request({ method: "wallet_switchEthereumChain", params: [{ chainId: hexChainId(chainId) }] });
717
- var sendAddRequest = (provider, chainId) => {
718
- const chain = getChain(chainId);
719
- return provider.request({
720
- method: "wallet_addEthereumChain",
721
- params: [
722
- {
723
- chainId: hexChainId(chainId),
724
- chainName: chain.name,
725
- nativeCurrency: chain.nativeCurrency,
726
- rpcUrls: [...chain.rpcUrls.default.http],
727
- ...chain.blockExplorers ? { blockExplorerUrls: [chain.blockExplorers.default.url] } : {}
728
- }
729
- ]
730
- });
731
- };
732
- function chainRequestError(e, chainId) {
733
- if (code(e) === 4001) return new MintError("USER_REJECTED", "You rejected the network switch.", { cause: e });
734
- return new MintError("CHAIN_SWITCH_FAILED", `Could not switch the wallet to chain ${String(chainId)}.`, { cause: e });
735
- }
736
- async function switchToChain(chainId) {
737
- getChain(chainId);
738
- const provider = eip1193();
739
- try {
740
- try {
741
- await sendSwitchRequest(provider, chainId);
742
- } catch (e) {
743
- if (code(e) !== 4902) throw e;
744
- await sendAddRequest(provider, chainId);
745
- await sendSwitchRequest(provider, chainId);
746
- }
747
- } catch (e) {
748
- throw chainRequestError(e, chainId);
749
- }
750
- }
751
- async function requestSwitch(chainId) {
752
- getChain(chainId);
753
- const provider = eip1193();
754
- try {
755
- await sendSwitchRequest(provider, chainId);
756
- return { needsAdd: false };
757
- } catch (e) {
758
- if (code(e) === 4902) return { needsAdd: true };
759
- throw chainRequestError(e, chainId);
760
- }
761
- }
762
- async function requestAddChain(chainId) {
763
- getChain(chainId);
764
- const provider = eip1193();
765
- try {
766
- await sendAddRequest(provider, chainId);
767
- } catch (e) {
768
- throw chainRequestError(e, chainId);
769
- }
770
- }
771
- function getWalletProvider() {
772
- return eip1193();
773
- }
774
-
775
254
  // src/core/adapters/manifold-claim/index.ts
776
255
  import {
777
256
  BaseError,
778
257
  ContractFunctionRevertedError,
779
258
  decodeErrorResult,
780
259
  encodeFunctionData,
781
- formatUnits as formatUnits2,
782
- getAddress as getAddress2,
260
+ formatUnits,
261
+ getAddress,
783
262
  isAddress,
784
263
  isHex,
785
264
  zeroAddress,
@@ -1000,7 +479,7 @@ function decodeRevert(e) {
1000
479
  const named = e.walk((x) => ["ExecutionRevertedError", "InsufficientFundsError"].includes(x.name));
1001
480
  return named instanceof BaseError ? named.shortMessage : null;
1002
481
  }
1003
- var money2 = (value, decimals, symbol) => ({ value, decimals, symbol, formatted: formatUnits2(value, decimals) });
482
+ var money = (value, decimals, symbol) => ({ value, decimals, symbol, formatted: formatUnits(value, decimals) });
1004
483
  function timestamp(v, field) {
1005
484
  if (v === 0n) return null;
1006
485
  if (v > BigInt(Number.MAX_SAFE_INTEGER)) throw new MintError("RPC_ERROR", `Claim ${field} does not fit a safe integer`);
@@ -1017,14 +496,14 @@ function parseConfig(config) {
1017
496
  throw new MintError("INVALID_CONFIG", "instanceId must be a non-negative integer string.", { field: "instanceId" });
1018
497
  }
1019
498
  return {
1020
- creator: getAddress2(config.creatorContract),
499
+ creator: getAddress(config.creatorContract),
1021
500
  instanceId: BigInt(config.instanceId),
1022
- extension: config.extension === void 0 ? void 0 : getAddress2(config.extension)
501
+ extension: config.extension === void 0 ? void 0 : getAddress(config.extension)
1023
502
  };
1024
503
  }
1025
504
  var notFound = (config) => new MintError("CLAIM_NOT_FOUND", `No Manifold claim ${config.instanceId} found on ${config.creatorContract}.`);
1026
505
  async function readClaim(client, entry, creator, instanceId, config) {
1027
- const address = getAddress2(entry.address);
506
+ const address = getAddress(entry.address);
1028
507
  const args = [creator, instanceId];
1029
508
  try {
1030
509
  switch (entry.abi) {
@@ -1050,6 +529,30 @@ async function readClaim(client, entry, creator, instanceId, config) {
1050
529
  throw toRpcError(e);
1051
530
  }
1052
531
  }
532
+ var CLAIM_ABIS = {
533
+ Claim721V5Optimization: CLAIM_721_V5_ABI,
534
+ Claim1155V5Optimization: CLAIM_1155_V5_ABI,
535
+ Claim721V7: CLAIM_721_V7_ABI,
536
+ Claim1155V7: CLAIM_1155_V7_ABI
537
+ };
538
+ function decodeClaim(abi, raw) {
539
+ switch (abi) {
540
+ case "Claim721V5Optimization":
541
+ return { ...base2(raw), signingAddress: null, tokenId: null };
542
+ case "Claim1155V5Optimization": {
543
+ const c = raw;
544
+ return { ...base2(c), signingAddress: null, tokenId: c.tokenId };
545
+ }
546
+ case "Claim721V7": {
547
+ const c = raw;
548
+ return { ...base2(c), signingAddress: c.signingAddress, tokenId: null };
549
+ }
550
+ case "Claim1155V7": {
551
+ const c = raw;
552
+ return { ...base2(c), signingAddress: c.signingAddress, tokenId: c.tokenId };
553
+ }
554
+ }
555
+ }
1053
556
  function base2(c) {
1054
557
  return {
1055
558
  total: BigInt(c.total),
@@ -1063,8 +566,8 @@ function base2(c) {
1063
566
  };
1064
567
  }
1065
568
  async function hasCode(client, address) {
1066
- const code2 = await rpc(() => client.getCode({ address: getAddress2(address) }));
1067
- return code2 !== void 0 && code2 !== "0x";
569
+ const code = await rpc(() => client.getCode({ address: getAddress(address) }));
570
+ return code !== void 0 && code !== "0x";
1068
571
  }
1069
572
  var unknownExtension = (address, why) => new MintError("UNKNOWN_EXTENSION", `Extension ${address} ${why}.`);
1070
573
  async function resolveExtension(ctx, config) {
@@ -1111,7 +614,7 @@ async function loadDrop(ctx, config) {
1111
614
  throw new MintError("SIGNATURE_CLAIM", "This claim mints with a signature (redemption code), which this button does not support.");
1112
615
  }
1113
616
  const { client } = ctx;
1114
- const extension = getAddress2(entry.address);
617
+ const extension = getAddress(entry.address);
1115
618
  const fee = await rpc(
1116
619
  () => client.readContract({ address: extension, abi: EXTENSION_COMMON_ABI, functionName: isAllowlist(claim) ? "MINT_FEE_MERKLE" : "MINT_FEE" })
1117
620
  );
@@ -1119,9 +622,9 @@ async function loadDrop(ctx, config) {
1119
622
  let unitPrice;
1120
623
  let paymentToken = null;
1121
624
  if (claim.erc20 === zeroAddress) {
1122
- unitPrice = money2(claim.cost, native.decimals, native.symbol);
625
+ unitPrice = money(claim.cost, native.decimals, native.symbol);
1123
626
  } else {
1124
- paymentToken = getAddress2(claim.erc20);
627
+ paymentToken = getAddress(claim.erc20);
1125
628
  const token = paymentToken;
1126
629
  const [symbol, decimals] = await rpc(
1127
630
  () => Promise.all([
@@ -1129,12 +632,12 @@ async function loadDrop(ctx, config) {
1129
632
  client.readContract({ address: token, abi: ERC20_ABI, functionName: "decimals" })
1130
633
  ])
1131
634
  );
1132
- unitPrice = money2(claim.cost, decimals, symbol);
635
+ unitPrice = money(claim.cost, decimals, symbol);
1133
636
  }
1134
637
  const drop = {
1135
638
  chainId: config.chainId,
1136
639
  unitPrice,
1137
- unitFee: money2(fee, native.decimals, native.symbol),
640
+ unitFee: money(fee, native.decimals, native.symbol),
1138
641
  totalMinted: claim.total,
1139
642
  maxSupply: claim.totalMax === 0n ? null : claim.totalMax,
1140
643
  startTime: timestamp(claim.startDate, "startDate"),
@@ -1153,9 +656,9 @@ async function loadWallet(ctx, config, args) {
1153
656
  const { client } = ctx;
1154
657
  const resolved = dropResolved.get(args.drop) ?? (await loadDrop(ctx, config)).resolved;
1155
658
  const { entry, claim } = resolved;
1156
- const extension = getAddress2(entry.address);
1157
- const payer = getAddress2(args.payer);
1158
- const recipient = getAddress2(args.recipient);
659
+ const extension = getAddress(entry.address);
660
+ const payer = getAddress(args.payer);
661
+ const recipient = getAddress(args.recipient);
1159
662
  let walletMinted = null;
1160
663
  let walletMax = null;
1161
664
  let allowlistRemaining = null;
@@ -1191,7 +694,7 @@ async function loadWallet(ctx, config, args) {
1191
694
  maxQuantity = Number(left);
1192
695
  if (left === 0n) ineligible = { reason: "WALLET_LIMIT", message: `This wallet has already minted its limit of ${walletMax}.` };
1193
696
  }
1194
- const token = claim.erc20 === zeroAddress ? null : getAddress2(claim.erc20);
697
+ const token = claim.erc20 === zeroAddress ? null : getAddress(claim.erc20);
1195
698
  const [native, erc20, gasPrice] = await rpc(
1196
699
  () => Promise.all([
1197
700
  client.getBalance({ address: payer }),
@@ -1219,8 +722,8 @@ async function buildPlan(ctx, attempt, wallet) {
1219
722
  throw new MintError("INVALID_CONFIG", `quantity must be an integer from 1 to ${MAX_MINT_COUNT}.`, { field: "quantity" });
1220
723
  }
1221
724
  const { creator, instanceId } = parseConfig(config);
1222
- const recipient = getAddress2(attempt.recipient);
1223
- const payer = getAddress2(attempt.payer);
725
+ const recipient = getAddress(attempt.recipient);
726
+ const payer = getAddress(attempt.payer);
1224
727
  let data = wallet.data;
1225
728
  if (!isWalletData(data) || !sameClaim(data.config, config) || data.recipient !== recipient) {
1226
729
  const drop = (await loadDrop(ctx, config)).drop;
@@ -1228,7 +731,7 @@ async function buildPlan(ctx, attempt, wallet) {
1228
731
  }
1229
732
  if (!isWalletData(data)) throw new MintError("RPC_ERROR", "Wallet read produced no plan data.");
1230
733
  const { entry, claim, fee } = data.resolved;
1231
- const extension = getAddress2(entry.address);
734
+ const extension = getAddress(entry.address);
1232
735
  let mintIndices = [];
1233
736
  let merkleProofs = [];
1234
737
  if (isAllowlist(claim)) {
@@ -1240,7 +743,7 @@ async function buildPlan(ctx, attempt, wallet) {
1240
743
  merkleProofs = picked.map((p) => p.proof);
1241
744
  }
1242
745
  const qty = BigInt(quantity);
1243
- const erc20 = claim.erc20 === zeroAddress ? null : getAddress2(claim.erc20);
746
+ const erc20 = claim.erc20 === zeroAddress ? null : getAddress(claim.erc20);
1244
747
  const cost = claim.cost * qty;
1245
748
  const value = fee * qty + (erc20 ? 0n : cost);
1246
749
  let approve = null;
@@ -1280,12 +783,12 @@ function holdingsQueryFor(drop, purpose = "settle") {
1280
783
  return { kind: "balance-1155", creatorContract: creator, tokenId: claim.tokenId.toString() };
1281
784
  }
1282
785
  if (!isAllowlist(claim) && claim.walletMax > 0n) {
1283
- return { kind: "total-mints", extension: getAddress2(entry.address), creatorContract: creator, instanceId: instanceId.toString() };
786
+ return { kind: "total-mints", extension: getAddress(entry.address), creatorContract: creator, instanceId: instanceId.toString() };
1284
787
  }
1285
788
  return { kind: "balance-721", creatorContract: creator };
1286
789
  }
1287
790
  if (!isAllowlist(claim) && claim.walletMax > 0n) {
1288
- return { kind: "total-mints", extension: getAddress2(entry.address), creatorContract: creator, instanceId: instanceId.toString() };
791
+ return { kind: "total-mints", extension: getAddress(entry.address), creatorContract: creator, instanceId: instanceId.toString() };
1289
792
  }
1290
793
  if (entry.spec === "1155") {
1291
794
  if (claim.tokenId === null) return null;
@@ -1295,25 +798,25 @@ function holdingsQueryFor(drop, purpose = "settle") {
1295
798
  }
1296
799
  async function readHoldings(ctx, query, recipient) {
1297
800
  const { client } = ctx;
1298
- const owner = getAddress2(recipient);
801
+ const owner = getAddress(recipient);
1299
802
  switch (query.kind) {
1300
803
  case "total-mints":
1301
804
  return BigInt(
1302
805
  await rpc(
1303
806
  () => client.readContract({
1304
- address: getAddress2(query.extension),
807
+ address: getAddress(query.extension),
1305
808
  abi: EXTENSION_COMMON_ABI,
1306
809
  functionName: "getTotalMints",
1307
- args: [owner, getAddress2(query.creatorContract), BigInt(query.instanceId)]
810
+ args: [owner, getAddress(query.creatorContract), BigInt(query.instanceId)]
1308
811
  })
1309
812
  )
1310
813
  );
1311
814
  case "balance-1155":
1312
815
  return rpc(
1313
- () => client.readContract({ address: getAddress2(query.creatorContract), abi: ERC1155_BALANCE_ABI, functionName: "balanceOf", args: [owner, BigInt(query.tokenId)] })
816
+ () => client.readContract({ address: getAddress(query.creatorContract), abi: ERC1155_BALANCE_ABI, functionName: "balanceOf", args: [owner, BigInt(query.tokenId)] })
1314
817
  );
1315
818
  case "balance-721":
1316
- return rpc(() => client.readContract({ address: getAddress2(query.creatorContract), abi: ERC721_BALANCE_ABI, functionName: "balanceOf", args: [owner] }));
819
+ return rpc(() => client.readContract({ address: getAddress(query.creatorContract), abi: ERC721_BALANCE_ABI, functionName: "balanceOf", args: [owner] }));
1317
820
  }
1318
821
  }
1319
822
  var manifoldClaimAdapter = {
@@ -1328,7 +831,7 @@ var manifoldClaimAdapter = {
1328
831
  buildPlan,
1329
832
  simulate: async (ctx, attempt, plan) => {
1330
833
  try {
1331
- await ctx.client.call({ account: getAddress2(attempt.payer), to: plan.mint.to, data: plan.mint.data, value: plan.mint.value });
834
+ await ctx.client.call({ account: getAddress(attempt.payer), to: plan.mint.to, data: plan.mint.data, value: plan.mint.value });
1332
835
  } catch (e) {
1333
836
  const text2 = decodeRevert(e);
1334
837
  if (text2 === null) throw toRpcError(e);
@@ -1337,40 +840,10 @@ var manifoldClaimAdapter = {
1337
840
  }
1338
841
  };
1339
842
 
1340
- // src/core/adapters/receipt.ts
1341
- import { decodeAbiParameters, getAddress as getAddress3, zeroAddress as zeroAddress2 } from "viem";
1342
- var TRANSFER_TOPIC = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
1343
- var TRANSFER_SINGLE_TOPIC = "0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62";
1344
- var TRANSFER_BATCH_TOPIC = "0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb";
1345
- var topicAddress = (t) => t && t.length === 66 ? getAddress3(`0x${t.slice(26)}`) : null;
1346
- function parseMintReceipt(logs, { tokenContract, recipient }) {
1347
- const contract = getAddress3(tokenContract);
1348
- const to = getAddress3(recipient);
1349
- const out = /* @__PURE__ */ new Map();
1350
- const add = (id, amount) => out.set(id, (out.get(id) ?? 0n) + amount);
1351
- for (const log of logs) {
1352
- if (getAddress3(log.address) !== contract) continue;
1353
- const [t0, t1, t2, t3] = log.topics;
1354
- if (t0 === TRANSFER_TOPIC && log.topics.length === 4) {
1355
- if (topicAddress(t1) !== zeroAddress2 || topicAddress(t2) !== to || !t3) continue;
1356
- add(BigInt(t3), 1n);
1357
- } else if (t0 === TRANSFER_SINGLE_TOPIC && log.topics.length === 4) {
1358
- if (topicAddress(t2) !== zeroAddress2 || topicAddress(t3) !== to) continue;
1359
- const [id, value] = decodeAbiParameters([{ type: "uint256" }, { type: "uint256" }], log.data);
1360
- add(id, value);
1361
- } else if (t0 === TRANSFER_BATCH_TOPIC && log.topics.length === 4) {
1362
- if (topicAddress(t2) !== zeroAddress2 || topicAddress(t3) !== to) continue;
1363
- const [ids, values] = decodeAbiParameters([{ type: "uint256[]" }, { type: "uint256[]" }], log.data);
1364
- if (ids.length !== values.length) continue;
1365
- ids.forEach((id, i) => add(id, values[i]));
1366
- }
1367
- }
1368
- return [...out].map(([tokenId, amount]) => ({ contract, tokenId, amount }));
1369
- }
1370
-
1371
843
  export {
1372
844
  friendlyErrorMessage,
1373
845
  UNSUPPORTED_REASONS,
846
+ INELIGIBLE_REASONS,
1374
847
  REASON_CODES,
1375
848
  MintError,
1376
849
  isMintError,
@@ -1379,28 +852,10 @@ export {
1379
852
  chainName,
1380
853
  getChain,
1381
854
  createReadClient,
1382
- loadConnectWidget,
1383
- openConnectModal,
1384
- getAccount,
1385
- subscribeAccount,
1386
- getWalletClient,
1387
- waitForDeposit,
1388
- getConnectedBalance,
1389
- switchToChain,
1390
- requestSwitch,
1391
- requestAddChain,
1392
- getWalletProvider,
1393
- MINT_STATES,
1394
- CLICKABLE_STATES,
1395
- IN_FLIGHT_STATES,
1396
- MAX_QUANTITY,
1397
- initialState,
1398
- reducer,
1399
- selectMaxQuantity,
1400
- selectTotal,
1401
- canAct,
855
+ EXTENSIONS,
1402
856
  findExtension,
1403
- manifoldClaimAdapter,
1404
- parseMintReceipt
857
+ CLAIM_ABIS,
858
+ decodeClaim,
859
+ manifoldClaimAdapter
1405
860
  };
1406
- //# sourceMappingURL=chunk-SUJQB3SL.js.map
861
+ //# sourceMappingURL=chunk-VHAAGH7Z.js.map