@manifoldxyz/dropkit 0.2.1 → 0.4.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.
- package/README.md +98 -3
- package/dist/cart.cjs +1832 -0
- package/dist/cart.cjs.map +1 -0
- package/dist/cart.d.cts +216 -0
- package/dist/cart.d.ts +216 -0
- package/dist/cart.js +1832 -0
- package/dist/cart.js.map +1 -0
- package/dist/chunk-GO4TR3HB.cjs +1406 -0
- package/dist/chunk-GO4TR3HB.cjs.map +1 -0
- package/dist/chunk-SUJQB3SL.js +1406 -0
- package/dist/chunk-SUJQB3SL.js.map +1 -0
- package/dist/index.cjs +1004 -1647
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -194
- package/dist/index.d.ts +5 -194
- package/dist/index.js +724 -1353
- package/dist/index.js.map +1 -1
- package/dist/types-BjKGb6c7.d.cts +210 -0
- package/dist/types-BjKGb6c7.d.ts +210 -0
- package/package.json +11 -1
package/dist/index.cjs
CHANGED
|
@@ -1,430 +1,40 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
19
24
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
MintButton: () => MintButton,
|
|
27
|
-
MintError: () => MintError,
|
|
28
|
-
PayWithPicker: () => PayWithPicker,
|
|
29
|
-
REASON_CODES: () => REASON_CODES,
|
|
30
|
-
VERSION: () => VERSION,
|
|
31
|
-
isMintError: () => isMintError,
|
|
32
|
-
useMint: () => useMint,
|
|
33
|
-
usePayOptions: () => usePayOptions
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(index_exports);
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
var _chunkGO4TR3HBcjs = require('./chunk-GO4TR3HB.cjs');
|
|
36
31
|
|
|
37
32
|
// src/react/useMint.ts
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
// src/core/rpc/index.ts
|
|
42
|
-
var import_viem = require("viem");
|
|
43
|
-
var import_chains = require("viem/chains");
|
|
44
|
-
|
|
45
|
-
// src/core/errors.ts
|
|
46
|
-
var UNSUPPORTED_REASONS = [
|
|
47
|
-
"UNKNOWN_EXTENSION",
|
|
48
|
-
"AMBIGUOUS_EXTENSION",
|
|
49
|
-
"CLAIM_NOT_FOUND",
|
|
50
|
-
"SIGNATURE_CLAIM",
|
|
51
|
-
"INVALID_CONFIG",
|
|
52
|
-
"CONNECT_WIDGET_TOO_OLD"
|
|
53
|
-
];
|
|
54
|
-
var INELIGIBLE_REASONS = ["NOT_ON_ALLOWLIST", "ALLOWLIST_USED", "WALLET_LIMIT", "SIMULATION_REVERTED"];
|
|
55
|
-
var ERROR_REASONS = [
|
|
56
|
-
"USER_REJECTED",
|
|
57
|
-
"TX_REVERTED",
|
|
58
|
-
"RATE_LIMITED",
|
|
59
|
-
"RPC_ERROR",
|
|
60
|
-
"CHAIN_SWITCH_FAILED",
|
|
61
|
-
"ALLOWLIST_UNAVAILABLE",
|
|
62
|
-
// Relay cross-chain mint (spec relay-cross-chain-mint #execute-click).
|
|
63
|
-
"BRIDGE_UNAVAILABLE",
|
|
64
|
-
"BRIDGE_REFUNDED",
|
|
65
|
-
"BRIDGE_FAILED",
|
|
66
|
-
"BRIDGE_TIMEOUT"
|
|
67
|
-
];
|
|
68
|
-
var FUNDS_REASONS = ["INSUFFICIENT_FUNDS"];
|
|
69
|
-
var REASON_CODES = [
|
|
70
|
-
...UNSUPPORTED_REASONS,
|
|
71
|
-
...INELIGIBLE_REASONS,
|
|
72
|
-
...ERROR_REASONS,
|
|
73
|
-
...FUNDS_REASONS
|
|
74
|
-
];
|
|
75
|
-
var MintError = class extends Error {
|
|
76
|
-
reason;
|
|
77
|
-
/** INVALID_CONFIG only: dotted path of the bad field, e.g. "mint.args[1]" or "price". */
|
|
78
|
-
field;
|
|
79
|
-
/** 'relay': the message is Relay's decoded destination revert, shown as-is. */
|
|
80
|
-
domain;
|
|
81
|
-
constructor(reason, message, opts) {
|
|
82
|
-
super(message, opts?.cause === void 0 ? void 0 : { cause: opts.cause });
|
|
83
|
-
this.name = "MintError";
|
|
84
|
-
this.reason = reason;
|
|
85
|
-
if (opts?.field !== void 0) this.field = opts.field;
|
|
86
|
-
if (opts?.domain !== void 0) this.domain = opts.domain;
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
function isMintError(e) {
|
|
90
|
-
return e instanceof MintError;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// src/core/rpc/index.ts
|
|
94
|
-
var BRIDGE_URLS = {
|
|
95
|
-
1: "https://bridge.manifoldxyz.dev/rpc",
|
|
96
|
-
11155111: "https://sepolia.bridge.manifoldxyz.dev/rpc",
|
|
97
|
-
8453: "https://base.bridge.manifoldxyz.dev/rpc",
|
|
98
|
-
10: "https://optimism.bridge.manifoldxyz.dev/rpc",
|
|
99
|
-
360: "https://shape.bridge.manifoldxyz.dev/rpc",
|
|
100
|
-
33139: "https://apechain.bridge.manifoldxyz.dev/rpc"
|
|
101
|
-
};
|
|
102
|
-
var CHAINS = {
|
|
103
|
-
[import_chains.mainnet.id]: import_chains.mainnet,
|
|
104
|
-
[import_chains.sepolia.id]: import_chains.sepolia,
|
|
105
|
-
[import_chains.base.id]: import_chains.base,
|
|
106
|
-
[import_chains.optimism.id]: import_chains.optimism,
|
|
107
|
-
[import_chains.shape.id]: import_chains.shape,
|
|
108
|
-
[import_chains.apeChain.id]: import_chains.apeChain,
|
|
109
|
-
// Relay pay chain for Sepolia drops only: never a drop chain, no Manifold bridge.
|
|
110
|
-
[import_chains.baseSepolia.id]: import_chains.baseSepolia
|
|
111
|
-
};
|
|
112
|
-
var CHAIN_NAMES = {
|
|
113
|
-
1: "Ethereum",
|
|
114
|
-
8453: "Base",
|
|
115
|
-
10: "Optimism",
|
|
116
|
-
360: "Shape",
|
|
117
|
-
33139: "ApeChain",
|
|
118
|
-
11155111: "Sepolia",
|
|
119
|
-
84532: "Base Sepolia"
|
|
120
|
-
};
|
|
121
|
-
function chainName(chainId) {
|
|
122
|
-
return CHAIN_NAMES[chainId] ?? CHAINS[chainId]?.name ?? `chain ${String(chainId)}`;
|
|
123
|
-
}
|
|
124
|
-
var TRANSPORT_TIMEOUT_MS = 8e3;
|
|
125
|
-
function getChain(chainId) {
|
|
126
|
-
const chain = CHAINS[chainId];
|
|
127
|
-
if (!chain) {
|
|
128
|
-
throw new MintError("INVALID_CONFIG", `chainId ${String(chainId)} is not supported`, { field: "chainId" });
|
|
129
|
-
}
|
|
130
|
-
return chain;
|
|
131
|
-
}
|
|
132
|
-
var TERMINAL_CODES = /* @__PURE__ */ new Set([3, -32602, -32003, 4001, 4100, 4200, 4900, 4901, 4902]);
|
|
133
|
-
var FALLBACK_CODES = /* @__PURE__ */ new Set([-32700, -32600, -32601, -32001, -32002, -32004, -32005, 429]);
|
|
134
|
-
var EXECUTION_WORDING = /execution reverted|execution error|\breverted?\b|out of gas|invalid opcode|insufficient funds|nonce too low|gas required exceeds/i;
|
|
135
|
-
var UPSTREAM_WORDING = /\btimeout\b|\btimed out\b|\btoo many requests\b|\brate limit\b|\brequest limit reached\b|\b(?:exceeded.*capacity|capacity.*exceeded)\b|\bheader not found\b|\binternal (?:json-rpc )?(?:server )?error\b|\bnon-200 status code:\s*['"]?503\b/i;
|
|
136
|
-
var TRANSPORT_ERROR_NAMES = /* @__PURE__ */ new Set(["HttpRequestError", "TimeoutError", "SocketClosedError", "WebSocketRequestError"]);
|
|
137
|
-
function carriesExecutionEvidence(value, seen = /* @__PURE__ */ new Set()) {
|
|
138
|
-
if (typeof value === "string") return /^(?:Reverted\s+)?0x(?:[a-f\d]{2})*$/i.test(value) || EXECUTION_WORDING.test(value);
|
|
139
|
-
if (!value || typeof value !== "object" || seen.has(value)) return false;
|
|
140
|
-
seen.add(value);
|
|
141
|
-
const e = value;
|
|
142
|
-
if (typeof e.code === "number" && TERMINAL_CODES.has(e.code)) return true;
|
|
143
|
-
if (typeof e.message === "string" && EXECUTION_WORDING.test(e.message)) return true;
|
|
144
|
-
return ["data", "error", "originalError", "cause", "result"].some((key) => carriesExecutionEvidence(e[key], seen));
|
|
145
|
-
}
|
|
146
|
-
function shouldFallback(err) {
|
|
147
|
-
let retry = false;
|
|
148
|
-
const seen = /* @__PURE__ */ new Set();
|
|
149
|
-
for (let e = err; e && typeof e === "object" && !seen.has(e); ) {
|
|
150
|
-
seen.add(e);
|
|
151
|
-
const error = e;
|
|
152
|
-
const message = typeof error.details === "string" ? error.details : typeof error.shortMessage !== "string" ? error.message : "";
|
|
153
|
-
if (typeof message === "string" && EXECUTION_WORDING.test(message)) return false;
|
|
154
|
-
if (carriesExecutionEvidence(error.data)) return false;
|
|
155
|
-
if (typeof error.code === "number" && TERMINAL_CODES.has(error.code)) return false;
|
|
156
|
-
if (error.name === "ContractFunctionRevertedError" || error.name === "ExecutionRevertedError") return false;
|
|
157
|
-
if (typeof error.name === "string" && TRANSPORT_ERROR_NAMES.has(error.name)) retry = true;
|
|
158
|
-
if (typeof error.code === "number" && FALLBACK_CODES.has(error.code)) retry = true;
|
|
159
|
-
if (typeof message === "string" && UPSTREAM_WORDING.test(message)) retry = true;
|
|
160
|
-
e = error.cause;
|
|
161
|
-
}
|
|
162
|
-
return retry;
|
|
163
|
-
}
|
|
164
|
-
function createReadClient(opts) {
|
|
165
|
-
const chain = getChain(opts.chainId);
|
|
166
|
-
const urls = [opts.rpcUrls?.[opts.chainId], opts.useBridge ? BRIDGE_URLS[opts.chainId] : void 0, chain.rpcUrls.default.http[0]].filter(
|
|
167
|
-
(u, i, all) => !!u && all.indexOf(u) === i
|
|
168
|
-
);
|
|
169
|
-
const transport = ({ chain: c, pollingInterval }) => {
|
|
170
|
-
const transports = urls.map((url) => (0, import_viem.http)(url, { timeout: TRANSPORT_TIMEOUT_MS, retryCount: 0 })({ chain: c, pollingInterval, retryCount: 0, timeout: TRANSPORT_TIMEOUT_MS }));
|
|
171
|
-
const request = (async (args) => {
|
|
172
|
-
let last;
|
|
173
|
-
for (const t of transports) {
|
|
174
|
-
try {
|
|
175
|
-
return await t.request(args);
|
|
176
|
-
} catch (err) {
|
|
177
|
-
if (!shouldFallback(err)) throw err;
|
|
178
|
-
last = err;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
console.warn(`dropkit: all RPC endpoints failed for chain ${String(opts.chainId)}; pass rpcUrls={{ ${String(opts.chainId)}: '<your RPC url>' }} to <MintButton>.`);
|
|
182
|
-
throw new MintError("RPC_ERROR", `All RPC endpoints failed for chain ${String(opts.chainId)}`, { cause: last });
|
|
183
|
-
});
|
|
184
|
-
return {
|
|
185
|
-
config: { key: "dropkit-fallback", name: "Dropkit fallback", request, retryCount: 0, retryDelay: 0, timeout: TRANSPORT_TIMEOUT_MS, type: "fallback" },
|
|
186
|
-
request,
|
|
187
|
-
value: {}
|
|
188
|
-
};
|
|
189
|
-
};
|
|
190
|
-
return (0, import_viem.createPublicClient)({ chain, transport });
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// src/core/wallet/index.ts
|
|
194
|
-
var import_viem2 = require("viem");
|
|
195
|
-
var CONNECT_WIDGET_VERSION = "6.5.0";
|
|
196
|
-
var CONNECT_BASE_URL = `https://connect.manifoldxyz.dev/${CONNECT_WIDGET_VERSION}`;
|
|
197
|
-
var CONNECT_ID = "mint-button";
|
|
198
|
-
var ADDRESS_CHANGED = "ethereum-address-changed";
|
|
199
|
-
var CHAIN_CHANGED = "frontend-provider-chain-changed";
|
|
200
|
-
var LOADER_KEY = "__manifoldMintConnectLoader";
|
|
201
|
-
var DEFAULT_WALLETCONNECT_PROJECT_ID = "a03ac1695f309dc8d756e7b4006e5e7d";
|
|
202
|
-
var STATE_KEY = "__manifoldMintConnectStateV1";
|
|
203
|
-
var win = () => window;
|
|
204
|
-
var pageState = () => win()[STATE_KEY] ??= {};
|
|
205
|
-
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 + ".";
|
|
206
|
-
var MANIFOLD_HOST = /(^|\.)(manifoldxyz\.dev|manifold\.xyz)$/;
|
|
207
|
-
function isManifoldConnectScript(src) {
|
|
208
|
-
try {
|
|
209
|
-
const url = new URL(src, document.baseURI);
|
|
210
|
-
return url.hostname === "connect.manifoldxyz.dev" || MANIFOLD_HOST.test(url.hostname) && /\/connect\.umd[^/]*\.js$/.test(url.pathname);
|
|
211
|
-
} catch {
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
function applyState(state) {
|
|
216
|
-
if (!state.div) return;
|
|
217
|
-
const network = state.networks.join(",");
|
|
218
|
-
if (state.div.dataset.network !== network) state.div.dataset.network = network;
|
|
219
|
-
const projectId = state.projectId ?? state.div.dataset.walletConnectProjectId ?? DEFAULT_WALLETCONNECT_PROJECT_ID;
|
|
220
|
-
if (state.div.dataset.walletConnectProjectId !== projectId) state.div.dataset.walletConnectProjectId = projectId;
|
|
221
|
-
}
|
|
222
|
-
function register(state, opts) {
|
|
223
|
-
for (const id2 of opts.chainIds) if (!state.networks.includes(id2)) state.networks.push(id2);
|
|
224
|
-
const id = opts.walletConnectProjectId;
|
|
225
|
-
if (id) {
|
|
226
|
-
if (!state.projectId) state.projectId = id;
|
|
227
|
-
else if (state.projectId !== id) {
|
|
228
|
-
console.warn(`dropkit: walletConnectProjectId "${id}" ignored; this page already uses "${state.projectId}" for the shared connect widget.`);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
applyState(state);
|
|
232
|
-
}
|
|
233
|
-
function startLoad(state) {
|
|
234
|
-
const connect = win().ManifoldConnect;
|
|
235
|
-
if (connect?.capabilities?.includes("open")) return Promise.resolve(connect.ready).then(() => void 0);
|
|
236
|
-
const hasScript = Array.from(document.querySelectorAll("script[src]")).some((s) => isManifoldConnectScript(s.src));
|
|
237
|
-
if (hasScript || document.querySelector('[data-widget="m-connect"]')) {
|
|
238
|
-
return Promise.reject(new MintError("CONNECT_WIDGET_TOO_OLD", TOO_OLD));
|
|
239
|
-
}
|
|
240
|
-
return new Promise((resolve, reject) => {
|
|
241
|
-
const css = document.createElement("link");
|
|
242
|
-
css.rel = "stylesheet";
|
|
243
|
-
css.href = `${CONNECT_BASE_URL}/connect.css`;
|
|
244
|
-
document.head.appendChild(css);
|
|
245
|
-
state.nodes.push(css);
|
|
246
|
-
const div = document.createElement("div");
|
|
247
|
-
div.hidden = true;
|
|
248
|
-
div.style.display = "none";
|
|
249
|
-
div.dataset.widget = "m-connect";
|
|
250
|
-
div.dataset.connectId = CONNECT_ID;
|
|
251
|
-
div.dataset.autoReconnect = "true";
|
|
252
|
-
div.dataset.enableNetworkSwitching = "true";
|
|
253
|
-
state.div = div;
|
|
254
|
-
applyState(state);
|
|
255
|
-
document.body.appendChild(div);
|
|
256
|
-
state.nodes.push(div);
|
|
257
|
-
const script = document.createElement("script");
|
|
258
|
-
script.src = `${CONNECT_BASE_URL}/connect.umd.min.js`;
|
|
259
|
-
script.async = true;
|
|
260
|
-
script.addEventListener("load", () => {
|
|
261
|
-
const ready = win().ManifoldConnect?.ready;
|
|
262
|
-
if (!ready) return reject(new MintError("CONNECT_WIDGET_TOO_OLD", TOO_OLD));
|
|
263
|
-
Promise.resolve(ready).then(() => resolve(), reject);
|
|
264
|
-
});
|
|
265
|
-
script.addEventListener("error", () => reject(new MintError("RPC_ERROR", `Could not load the Manifold connect widget from ${CONNECT_BASE_URL}`)));
|
|
266
|
-
document.head.appendChild(script);
|
|
267
|
-
state.nodes.push(script);
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
function loadConnectWidget(opts) {
|
|
271
|
-
const w = win();
|
|
272
|
-
const page = pageState();
|
|
273
|
-
const existing = w[LOADER_KEY];
|
|
274
|
-
if (existing) {
|
|
275
|
-
if (page.load?.promise !== existing) {
|
|
276
|
-
const div = document.querySelector(`[data-widget="m-connect"][data-connect-id="${CONNECT_ID}"]`) ?? void 0;
|
|
277
|
-
page.load = {
|
|
278
|
-
promise: existing,
|
|
279
|
-
networks: div?.dataset.network?.split(",").filter(Boolean).map(Number) ?? [],
|
|
280
|
-
// The default id is a placeholder, not a choice: a caller's real id may still replace it.
|
|
281
|
-
projectId: div?.dataset.walletConnectProjectId === DEFAULT_WALLETCONNECT_PROJECT_ID ? void 0 : div?.dataset.walletConnectProjectId,
|
|
282
|
-
div,
|
|
283
|
-
nodes: []
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
register(page.load, opts);
|
|
287
|
-
return existing;
|
|
288
|
-
}
|
|
289
|
-
let resolve;
|
|
290
|
-
let reject;
|
|
291
|
-
const p = new Promise((res, rej) => {
|
|
292
|
-
resolve = res;
|
|
293
|
-
reject = rej;
|
|
294
|
-
});
|
|
295
|
-
const state = { promise: p, networks: [], nodes: [] };
|
|
296
|
-
page.load = state;
|
|
297
|
-
w[LOADER_KEY] = p;
|
|
298
|
-
p.catch(() => {
|
|
299
|
-
if (w[LOADER_KEY] === p) delete w[LOADER_KEY];
|
|
300
|
-
if (page.load === state) page.load = void 0;
|
|
301
|
-
for (const node of state.nodes) node.parentNode?.removeChild(node);
|
|
302
|
-
state.nodes.length = 0;
|
|
303
|
-
state.div = void 0;
|
|
304
|
-
});
|
|
305
|
-
register(state, opts);
|
|
306
|
-
try {
|
|
307
|
-
startLoad(state).then(resolve, reject);
|
|
308
|
-
} catch (error) {
|
|
309
|
-
reject(error);
|
|
310
|
-
}
|
|
311
|
-
return p;
|
|
312
|
-
}
|
|
313
|
-
function openConnectModal() {
|
|
314
|
-
const page = pageState();
|
|
315
|
-
if (page.pendingModal) return page.pendingModal;
|
|
316
|
-
const p = new Promise((resolve) => {
|
|
317
|
-
const onClosed = (e) => {
|
|
318
|
-
const detail = e.detail ?? {};
|
|
319
|
-
if (detail.connectId !== void 0 && detail.connectId !== CONNECT_ID) return;
|
|
320
|
-
window.removeEventListener("m-connect:closed", onClosed);
|
|
321
|
-
page.pendingModal = void 0;
|
|
322
|
-
resolve(detail.reason === "connected" ? "connected" : "dismissed");
|
|
323
|
-
};
|
|
324
|
-
window.addEventListener("m-connect:closed", onClosed);
|
|
325
|
-
});
|
|
326
|
-
page.pendingModal = p;
|
|
327
|
-
window.dispatchEvent(new CustomEvent("m-connect:open", { detail: { connectId: CONNECT_ID } }));
|
|
328
|
-
return p;
|
|
329
|
-
}
|
|
330
|
-
function getAccount() {
|
|
331
|
-
const p = win().ManifoldEthereumProvider;
|
|
332
|
-
const address = p?.selectedAddress?.();
|
|
333
|
-
let chainId = p?.chainId?.();
|
|
334
|
-
if (chainId === void 0 || chainId === null) {
|
|
335
|
-
try {
|
|
336
|
-
chainId = p?.browserChainId?.();
|
|
337
|
-
} catch {
|
|
338
|
-
chainId = void 0;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
if (!address || chainId === void 0 || chainId === null) return null;
|
|
342
|
-
return { address: (0, import_viem2.getAddress)(address), chainId: Number(chainId) };
|
|
343
|
-
}
|
|
344
|
-
function subscribeAccount(cb) {
|
|
345
|
-
const handler = () => cb(getAccount());
|
|
346
|
-
window.addEventListener(ADDRESS_CHANGED, handler);
|
|
347
|
-
window.addEventListener(CHAIN_CHANGED, handler);
|
|
348
|
-
return () => {
|
|
349
|
-
window.removeEventListener(ADDRESS_CHANGED, handler);
|
|
350
|
-
window.removeEventListener(CHAIN_CHANGED, handler);
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
function eip1193() {
|
|
354
|
-
const p = win().ManifoldEthereumProvider;
|
|
355
|
-
const provider = (p?.provider?.(true) ?? p?.browserProvider?.())?.provider;
|
|
356
|
-
if (!provider) throw new MintError("CHAIN_SWITCH_FAILED", "No wallet is connected.");
|
|
357
|
-
return provider;
|
|
358
|
-
}
|
|
359
|
-
function getWalletClient(chainId) {
|
|
360
|
-
const provider = eip1193();
|
|
361
|
-
const request = ((args) => provider.request(args));
|
|
362
|
-
return (0, import_viem2.createWalletClient)({ chain: getChain(chainId), transport: (0, import_viem2.custom)({ request }) });
|
|
363
|
-
}
|
|
364
|
-
async function waitForDeposit(chainId, hash, timeoutMs = 12e4) {
|
|
365
|
-
try {
|
|
366
|
-
const receipt = await getWalletClient(chainId).extend(import_viem2.publicActions).waitForTransactionReceipt({ hash, confirmations: 1, timeout: timeoutMs });
|
|
367
|
-
return receipt.status === "reverted" ? "reverted" : "mined";
|
|
368
|
-
} catch {
|
|
369
|
-
return "unknown";
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
var WALLET_READ_TIMEOUT = { ms: 1e4 };
|
|
373
|
-
async function getConnectedBalance(address, chainId) {
|
|
374
|
-
const provider = eip1193();
|
|
375
|
-
let timer;
|
|
376
|
-
const timeout = new Promise((_, reject) => {
|
|
377
|
-
timer = setTimeout(() => reject(new MintError("RPC_ERROR", "The wallet did not report a balance in time.")), WALLET_READ_TIMEOUT.ms);
|
|
378
|
-
});
|
|
379
|
-
try {
|
|
380
|
-
return await Promise.race([
|
|
381
|
-
(async () => {
|
|
382
|
-
const current = Number(await provider.request({ method: "eth_chainId" }));
|
|
383
|
-
if (current !== chainId) {
|
|
384
|
-
throw new MintError("CHAIN_SWITCH_FAILED", `The wallet is on chain ${String(current)}, not ${String(chainId)}.`);
|
|
385
|
-
}
|
|
386
|
-
const hex = await provider.request({ method: "eth_getBalance", params: [address, "latest"] });
|
|
387
|
-
return BigInt(hex);
|
|
388
|
-
})(),
|
|
389
|
-
timeout
|
|
390
|
-
]);
|
|
391
|
-
} finally {
|
|
392
|
-
clearTimeout(timer);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
var code = (e) => e?.code;
|
|
396
|
-
async function switchToChain(chainId) {
|
|
397
|
-
const chain = getChain(chainId);
|
|
398
|
-
const provider = eip1193();
|
|
399
|
-
const hexId = `0x${chainId.toString(16)}`;
|
|
400
|
-
const switchChain = () => provider.request({ method: "wallet_switchEthereumChain", params: [{ chainId: hexId }] });
|
|
401
|
-
try {
|
|
402
|
-
try {
|
|
403
|
-
await switchChain();
|
|
404
|
-
} catch (e) {
|
|
405
|
-
if (code(e) !== 4902) throw e;
|
|
406
|
-
await provider.request({
|
|
407
|
-
method: "wallet_addEthereumChain",
|
|
408
|
-
params: [
|
|
409
|
-
{
|
|
410
|
-
chainId: hexId,
|
|
411
|
-
chainName: chain.name,
|
|
412
|
-
nativeCurrency: chain.nativeCurrency,
|
|
413
|
-
rpcUrls: [...chain.rpcUrls.default.http],
|
|
414
|
-
...chain.blockExplorers ? { blockExplorerUrls: [chain.blockExplorers.default.url] } : {}
|
|
415
|
-
}
|
|
416
|
-
]
|
|
417
|
-
});
|
|
418
|
-
await switchChain();
|
|
419
|
-
}
|
|
420
|
-
} catch (e) {
|
|
421
|
-
if (code(e) === 4001) throw new MintError("USER_REJECTED", "You rejected the network switch.", { cause: e });
|
|
422
|
-
throw new MintError("CHAIN_SWITCH_FAILED", `Could not switch the wallet to chain ${String(chainId)}.`, { cause: e });
|
|
423
|
-
}
|
|
424
|
-
}
|
|
33
|
+
var _react = require('react');
|
|
34
|
+
var _viem = require('viem');
|
|
425
35
|
|
|
426
36
|
// src/core/relay/client.ts
|
|
427
|
-
|
|
37
|
+
|
|
428
38
|
var RELAY_API = { mainnet: "https://api.relay.link", testnet: "https://api.testnets.relay.link" };
|
|
429
39
|
var MAINNET_PAY_CHAINS = [1, 8453, 10, 360, 33139];
|
|
430
40
|
var MAINNET_DROP_CHAINS = [1, 8453, 10, 360];
|
|
@@ -438,7 +48,7 @@ function payChainsFor(dropChainId) {
|
|
|
438
48
|
}
|
|
439
49
|
var CACHE_MS = 3e4;
|
|
440
50
|
var cache = /* @__PURE__ */ new Map();
|
|
441
|
-
var cacheKey = (a) => [a.testnet, a.originChainId, a.destinationChainId, a.tx.to.toLowerCase(), a.tx.value, (0,
|
|
51
|
+
var cacheKey = (a) => [a.testnet, a.originChainId, a.destinationChainId, a.tx.to.toLowerCase(), a.tx.value, _viem.keccak256.call(void 0, a.tx.data), a.payer.toLowerCase(), a.recipient.toLowerCase()].join(":");
|
|
442
52
|
var big = (v) => {
|
|
443
53
|
if (typeof v === "string" && /^\d+$/.test(v)) return BigInt(v);
|
|
444
54
|
if (typeof v === "number" && Number.isSafeInteger(v) && v >= 0) return BigInt(v);
|
|
@@ -450,42 +60,42 @@ function moneyOf(amount, currency) {
|
|
|
450
60
|
const decimals = typeof c.decimals === "number" ? c.decimals : 18;
|
|
451
61
|
const symbol = typeof c.symbol === "string" ? c.symbol : "ETH";
|
|
452
62
|
const value = big(amount);
|
|
453
|
-
return { value, decimals, symbol, formatted: (0,
|
|
63
|
+
return { value, decimals, symbol, formatted: _viem.formatUnits.call(void 0, value, decimals) };
|
|
454
64
|
}
|
|
455
65
|
function revertReason(errorData) {
|
|
456
66
|
if (typeof errorData !== "string") return "";
|
|
457
|
-
const
|
|
458
|
-
return
|
|
67
|
+
const text = errorData.replace(/^execution reverted:?\s*/i, "").trim();
|
|
68
|
+
return text === "execution reverted" ? "" : text;
|
|
459
69
|
}
|
|
460
70
|
function parseQuote(body, originChainId) {
|
|
461
71
|
const b = obj(body);
|
|
462
72
|
const steps = Array.isArray(b.steps) ? b.steps.map(obj) : [];
|
|
463
|
-
const unknownStep = () => new MintError("BRIDGE_UNAVAILABLE", "Relay returned a route this button cannot execute.");
|
|
73
|
+
const unknownStep = () => new (0, _chunkGO4TR3HBcjs.MintError)("BRIDGE_UNAVAILABLE", "Relay returned a route this button cannot execute.");
|
|
464
74
|
if (steps.length !== 1 || steps[0].kind !== "transaction") throw unknownStep();
|
|
465
|
-
const
|
|
466
|
-
const rawItems = Array.isArray(
|
|
75
|
+
const step = steps[0];
|
|
76
|
+
const rawItems = Array.isArray(step.items) ? step.items.map(obj) : [];
|
|
467
77
|
if (rawItems.length !== 1) throw unknownStep();
|
|
468
78
|
const items = rawItems.map((item) => {
|
|
469
79
|
const d = obj(item.data);
|
|
470
80
|
const chainId = Number(d.chainId);
|
|
471
|
-
if (chainId !== originChainId || typeof d.to !== "string" || !(0,
|
|
472
|
-
return { chainId, to: (0,
|
|
81
|
+
if (chainId !== originChainId || typeof d.to !== "string" || !_viem.isHex.call(void 0, d.data)) throw unknownStep();
|
|
82
|
+
return { chainId, to: _viem.getAddress.call(void 0, d.to), data: d.data, value: big(d.value), gas: d.gas === void 0 ? null : big(d.gas) };
|
|
473
83
|
});
|
|
474
|
-
const requestId = (0,
|
|
84
|
+
const requestId = _viem.isHex.call(void 0, step.requestId) ? step.requestId : _viem.isHex.call(void 0, b.requestId) ? b.requestId : null;
|
|
475
85
|
if (!requestId) throw unknownStep();
|
|
476
|
-
const
|
|
477
|
-
const currencyIn = obj(
|
|
86
|
+
const details2 = obj(b.details);
|
|
87
|
+
const currencyIn = obj(details2.currencyIn);
|
|
478
88
|
const fees = obj(b.fees);
|
|
479
89
|
const amountIn = moneyOf(currencyIn.amount, currencyIn.currency);
|
|
480
|
-
if (obj(currencyIn.currency).address !== void 0 && obj(currencyIn.currency).address !==
|
|
90
|
+
if (obj(currencyIn.currency).address !== void 0 && obj(currencyIn.currency).address !== _viem.zeroAddress) throw unknownStep();
|
|
481
91
|
if (items[0].value !== amountIn.value) throw unknownStep();
|
|
482
92
|
return {
|
|
483
93
|
requestId,
|
|
484
94
|
originChainId,
|
|
485
95
|
items,
|
|
486
96
|
amountIn,
|
|
487
|
-
relayFee: moneyOf(obj(fees.relayer).amount, obj(fees.relayer).currency
|
|
488
|
-
originGas: moneyOf(obj(fees.gas).amount, obj(fees.gas).currency
|
|
97
|
+
relayFee: moneyOf(obj(fees.relayer).amount, _nullishCoalesce(obj(fees.relayer).currency, () => ( currencyIn.currency))),
|
|
98
|
+
originGas: moneyOf(obj(fees.gas).amount, _nullishCoalesce(obj(fees.gas).currency, () => ( currencyIn.currency))),
|
|
489
99
|
quotedAt: Math.floor(Date.now() / 1e3)
|
|
490
100
|
};
|
|
491
101
|
}
|
|
@@ -531,7 +141,7 @@ async function timedFetch(f, url, init, ms) {
|
|
|
531
141
|
}
|
|
532
142
|
}
|
|
533
143
|
async function requestQuote(a) {
|
|
534
|
-
const f = a.fetch
|
|
144
|
+
const f = _nullishCoalesce(a.fetch, () => ( globalThis.fetch));
|
|
535
145
|
const body = {
|
|
536
146
|
user: a.payer,
|
|
537
147
|
recipient: a.recipient,
|
|
@@ -539,8 +149,8 @@ async function requestQuote(a) {
|
|
|
539
149
|
// R11: without refundTo, Relay disables automatic refunds.
|
|
540
150
|
originChainId: a.originChainId,
|
|
541
151
|
destinationChainId: a.destinationChainId,
|
|
542
|
-
originCurrency:
|
|
543
|
-
destinationCurrency:
|
|
152
|
+
originCurrency: _viem.zeroAddress,
|
|
153
|
+
destinationCurrency: _viem.zeroAddress,
|
|
544
154
|
tradeType: "EXACT_OUTPUT",
|
|
545
155
|
amount: a.tx.value.toString(),
|
|
546
156
|
txs: [{ to: a.tx.to, value: a.tx.value.toString(), data: a.tx.data }]
|
|
@@ -553,21 +163,21 @@ async function requestQuote(a) {
|
|
|
553
163
|
body: JSON.stringify(body)
|
|
554
164
|
}, RELAY_TIMEOUTS.quoteMs);
|
|
555
165
|
} catch (e) {
|
|
556
|
-
throw new MintError("BRIDGE_UNAVAILABLE", "Could not reach Relay for a cross-chain quote.", { cause: e });
|
|
166
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("BRIDGE_UNAVAILABLE", "Could not reach Relay for a cross-chain quote.", { cause: e });
|
|
557
167
|
}
|
|
558
168
|
const json = res.json;
|
|
559
169
|
if (res.ok) return parseQuote(json, a.originChainId);
|
|
560
170
|
const j = obj(json);
|
|
561
171
|
if (j.errorCode === "DESTINATION_TX_FAILED") {
|
|
562
172
|
const reason = revertReason(j.errorData);
|
|
563
|
-
throw new MintError("SIMULATION_REVERTED", reason || "The mint would fail on the drop network.", { cause: json, domain: "relay" });
|
|
173
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("SIMULATION_REVERTED", reason || "The mint would fail on the drop network.", { cause: json, domain: "relay" });
|
|
564
174
|
}
|
|
565
175
|
if (res.status === 401 || j.errorCode === "UNAUTHORIZED_QUOTE") {
|
|
566
176
|
console.warn("dropkit: Relay rejected the quote (401 UNAUTHORIZED_QUOTE). Relay gates quotes that carry a referrer or need an API key.");
|
|
567
|
-
throw new MintError("BRIDGE_UNAVAILABLE", "Relay refused the cross-chain quote.", { cause: json });
|
|
177
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("BRIDGE_UNAVAILABLE", "Relay refused the cross-chain quote.", { cause: json });
|
|
568
178
|
}
|
|
569
|
-
if (res.status === 429) throw new MintError("RATE_LIMITED", "Relay is rate limiting quotes. Try again in a moment.", { cause: json });
|
|
570
|
-
throw new MintError("BRIDGE_UNAVAILABLE", `Relay could not quote this mint (${String(res.status)}).`, { cause: json });
|
|
179
|
+
if (res.status === 429) throw new (0, _chunkGO4TR3HBcjs.MintError)("RATE_LIMITED", "Relay is rate limiting quotes. Try again in a moment.", { cause: json });
|
|
180
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("BRIDGE_UNAVAILABLE", `Relay could not quote this mint (${String(res.status)}).`, { cause: json });
|
|
571
181
|
}
|
|
572
182
|
function getQuote(a) {
|
|
573
183
|
const k = cacheKey(a);
|
|
@@ -577,19 +187,19 @@ function getQuote(a) {
|
|
|
577
187
|
const quote = requestQuote(a);
|
|
578
188
|
cache.set(k, { at: now, quote });
|
|
579
189
|
quote.catch(() => {
|
|
580
|
-
if (cache.get(k)
|
|
190
|
+
if (_optionalChain([cache, 'access', _2 => _2.get, 'call', _3 => _3(k), 'optionalAccess', _4 => _4.quote]) === quote) cache.delete(k);
|
|
581
191
|
});
|
|
582
192
|
return raceSignal(quote, a.signal);
|
|
583
193
|
}
|
|
584
194
|
var realReason = (v) => typeof v === "string" && v !== "" && v !== "N/A" ? v : null;
|
|
585
195
|
async function getStatus(a) {
|
|
586
|
-
const f = a.fetch
|
|
196
|
+
const f = _nullishCoalesce(a.fetch, () => ( globalThis.fetch));
|
|
587
197
|
const res = await raceSignal(timedFetch(f, `${a.testnet ? RELAY_API.testnet : RELAY_API.mainnet}/intents/status/v3?requestId=${a.requestId}`, {}, RELAY_TIMEOUTS.statusMs), a.signal);
|
|
588
198
|
if (!res.ok) throw new Error(`Relay status ${String(res.status)}`);
|
|
589
199
|
const j = obj(res.json);
|
|
590
200
|
return {
|
|
591
201
|
status: typeof j.status === "string" ? j.status : "unknown",
|
|
592
|
-
txHashes: Array.isArray(j.txHashes) ? j.txHashes.filter((h) => (0,
|
|
202
|
+
txHashes: Array.isArray(j.txHashes) ? j.txHashes.filter((h) => _viem.isHex.call(void 0, h)) : [],
|
|
593
203
|
failReason: realReason(j.failReason),
|
|
594
204
|
refundFailReason: realReason(j.refundFailReason)
|
|
595
205
|
};
|
|
@@ -604,18 +214,18 @@ var POLL_FAST_FOR_MS = 6e4;
|
|
|
604
214
|
var POLL_CAP_MS = 10 * 6e4;
|
|
605
215
|
var defaultSleep = (ms, signal) => new Promise((resolve, reject) => {
|
|
606
216
|
const t = setTimeout(resolve, ms);
|
|
607
|
-
signal
|
|
217
|
+
_optionalChain([signal, 'optionalAccess', _5 => _5.addEventListener, 'call', _6 => _6("abort", () => {
|
|
608
218
|
clearTimeout(t);
|
|
609
219
|
reject(new DOMException("Relay polling cancelled", "AbortError"));
|
|
610
|
-
}, { once: true });
|
|
220
|
+
}, { once: true })]);
|
|
611
221
|
});
|
|
612
222
|
async function pollUntilTerminal(a) {
|
|
613
|
-
const sleep = a.sleep
|
|
614
|
-
const now = a.now
|
|
223
|
+
const sleep = _nullishCoalesce(a.sleep, () => ( defaultSleep));
|
|
224
|
+
const now = _nullishCoalesce(a.now, () => ( Date.now));
|
|
615
225
|
const start = now();
|
|
616
226
|
let warned = false;
|
|
617
227
|
for (; ; ) {
|
|
618
|
-
a.assertActive
|
|
228
|
+
_optionalChain([a, 'access', _7 => _7.assertActive, 'optionalCall', _8 => _8()]);
|
|
619
229
|
try {
|
|
620
230
|
const status = await getStatus({ testnet: a.testnet, requestId: a.requestId, ...a.signal ? { signal: a.signal } : {}, ...a.fetch ? { fetch: a.fetch } : {} });
|
|
621
231
|
if (TERMINAL.includes(status.status)) return { kind: "terminal", status };
|
|
@@ -624,794 +234,641 @@ async function pollUntilTerminal(a) {
|
|
|
624
234
|
console.warn(`dropkit: Relay status "${status.status}" for ${a.requestId}; still waiting.`);
|
|
625
235
|
}
|
|
626
236
|
} catch (e) {
|
|
627
|
-
if (e
|
|
237
|
+
if (_optionalChain([e, 'optionalAccess', _9 => _9.name]) === "AbortError") throw e;
|
|
628
238
|
}
|
|
629
|
-
a.assertActive
|
|
239
|
+
_optionalChain([a, 'access', _10 => _10.assertActive, 'optionalCall', _11 => _11()]);
|
|
630
240
|
const elapsed = now() - start;
|
|
631
241
|
if (elapsed >= POLL_CAP_MS) return { kind: "timeout" };
|
|
632
242
|
await sleep(elapsed < POLL_FAST_FOR_MS ? POLL_FAST_MS : POLL_SLOW_MS, a.signal);
|
|
633
243
|
}
|
|
634
244
|
}
|
|
635
245
|
|
|
636
|
-
// src/core/
|
|
637
|
-
var memory = /* @__PURE__ */ new Map();
|
|
638
|
-
var claimed = /* @__PURE__ */ new Set();
|
|
639
|
-
function outstandingKey(config, payer) {
|
|
640
|
-
const target = config.type === "manifold-claim" ? `${config.creatorContract.toLowerCase()}:${config.instanceId}` : config.address.toLowerCase();
|
|
641
|
-
return `${String(config.chainId)}:${target}:${payer.toLowerCase()}`;
|
|
642
|
-
}
|
|
643
|
-
var getOutstanding = (key) => memory.get(key) ?? null;
|
|
644
|
-
var setOutstanding = (key, out) => void memory.set(key, out);
|
|
645
|
-
var clearOutstanding = (key) => void memory.delete(key);
|
|
646
|
-
function claimDeposit(key) {
|
|
647
|
-
if (claimed.has(key) || memory.has(key)) return false;
|
|
648
|
-
claimed.add(key);
|
|
649
|
-
return true;
|
|
650
|
-
}
|
|
651
|
-
var releaseDeposit = (key) => void claimed.delete(key);
|
|
246
|
+
// src/core/adapters/tl-stacks/index.ts
|
|
652
247
|
|
|
653
|
-
// src/core/adapters/manifold-claim/index.ts
|
|
654
|
-
var import_viem5 = require("viem");
|
|
655
248
|
|
|
656
|
-
// src/core/adapters/manifold-claim/abis.ts
|
|
657
|
-
var import_viem4 = require("viem");
|
|
658
|
-
var CLAIM_721_V5_ABI = (0, import_viem4.parseAbi)([
|
|
659
|
-
"function getClaim(address creatorContractAddress, uint256 instanceId) view returns ((uint32 total, uint32 totalMax, uint32 walletMax, uint48 startDate, uint48 endDate, uint8 storageProtocol, uint8 contractVersion, bool identical, bytes32 merkleRoot, string location, uint256 cost, address paymentReceiver, address erc20) claim)"
|
|
660
|
-
]);
|
|
661
|
-
var CLAIM_1155_V5_ABI = (0, import_viem4.parseAbi)([
|
|
662
|
-
"function getClaim(address creatorContractAddress, uint256 instanceId) view returns ((uint32 total, uint32 totalMax, uint32 walletMax, uint48 startDate, uint48 endDate, uint8 storageProtocol, bytes32 merkleRoot, string location, uint256 tokenId, uint256 cost, address paymentReceiver, address erc20) claim)"
|
|
663
|
-
]);
|
|
664
|
-
var CLAIM_721_V7_ABI = (0, import_viem4.parseAbi)([
|
|
665
|
-
"function getClaim(address creatorContractAddress, uint256 instanceId) view returns ((uint32 total, uint32 totalMax, uint32 walletMax, uint48 startDate, uint48 endDate, uint8 storageProtocol, uint8 contractVersion, bool identical, bytes32 merkleRoot, string location, uint256 cost, address paymentReceiver, address erc20, address signingAddress) claim)"
|
|
666
|
-
]);
|
|
667
|
-
var CLAIM_1155_V7_ABI = (0, import_viem4.parseAbi)([
|
|
668
|
-
"function getClaim(address creatorContractAddress, uint256 instanceId) view returns ((uint32 total, uint32 totalMax, uint32 walletMax, uint48 startDate, uint48 endDate, uint8 storageProtocol, bytes32 merkleRoot, string location, uint256 tokenId, uint256 cost, address paymentReceiver, address erc20, address signingAddress) claim)"
|
|
669
|
-
]);
|
|
670
|
-
var EXTENSION_COMMON_ABI = (0, import_viem4.parseAbi)([
|
|
671
|
-
"function MINT_FEE() view returns (uint256)",
|
|
672
|
-
"function MINT_FEE_MERKLE() view returns (uint256)",
|
|
673
|
-
"function getTotalMints(address minter, address creatorContractAddress, uint256 instanceId) view returns (uint32)",
|
|
674
|
-
"function checkMintIndices(address creatorContractAddress, uint256 instanceId, uint32[] mintIndices) view returns (bool[] minted)",
|
|
675
|
-
"function mintProxy(address creatorContractAddress, uint256 instanceId, uint16 mintCount, uint32[] mintIndices, bytes32[][] merkleProofs, address mintFor) payable"
|
|
676
|
-
]);
|
|
677
|
-
var EXTENSION_ERRORS_ABI = (0, import_viem4.parseAbi)([
|
|
678
|
-
"error Error(string message)",
|
|
679
|
-
"error Panic(uint256 code)",
|
|
680
|
-
"error ClaimInactive()",
|
|
681
|
-
"error ClaimNotInitialized()",
|
|
682
|
-
"error ExpiredSignature()",
|
|
683
|
-
"error FailedToTransfer()",
|
|
684
|
-
"error InvalidAirdrop()",
|
|
685
|
-
"error InvalidInput()",
|
|
686
|
-
"error InvalidInstance()",
|
|
687
|
-
"error InvalidSignature()",
|
|
688
|
-
"error InvalidStartDate()",
|
|
689
|
-
"error InvalidStorageProtocol()",
|
|
690
|
-
"error MustUseSignatureMinting()",
|
|
691
|
-
"error TokenDNE()",
|
|
692
|
-
"error TooManyRequested()"
|
|
693
|
-
]);
|
|
694
|
-
var CREATOR_ABI = (0, import_viem4.parseAbi)(["function getExtensions() view returns (address[])"]);
|
|
695
|
-
var ERC20_ABI = (0, import_viem4.parseAbi)([
|
|
696
|
-
"function symbol() view returns (string)",
|
|
697
|
-
"function decimals() view returns (uint8)",
|
|
698
|
-
"function balanceOf(address owner) view returns (uint256)",
|
|
699
|
-
"function allowance(address owner, address spender) view returns (uint256)",
|
|
700
|
-
"function approve(address spender, uint256 amount) returns (bool)"
|
|
701
|
-
]);
|
|
702
249
|
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
// src/core/adapters/tl-stacks/abis.ts
|
|
261
|
+
var DROP_PHASE = { NOT_CONFIGURED: 0, NOT_STARTED: 1, PRESALE: 2, PUBLIC_SALE: 3, ENDED: 4 };
|
|
262
|
+
var SUPPORTED_VERSIONS = ["2.3.0", "2.3.1"];
|
|
263
|
+
var stacksAbi = [
|
|
264
|
+
{ type: "function", name: "VERSION", stateMutability: "view", inputs: [], outputs: [{ name: "", type: "string" }] },
|
|
265
|
+
{ type: "function", name: "protocolFee", stateMutability: "view", inputs: [], outputs: [{ name: "", type: "uint256" }] },
|
|
266
|
+
{
|
|
267
|
+
type: "function",
|
|
268
|
+
name: "getDrop",
|
|
269
|
+
stateMutability: "view",
|
|
270
|
+
inputs: [{ name: "nftAddress", type: "address" }],
|
|
271
|
+
outputs: [
|
|
272
|
+
{
|
|
273
|
+
name: "",
|
|
274
|
+
type: "tuple",
|
|
275
|
+
components: [
|
|
276
|
+
{ name: "dropType", type: "uint8" },
|
|
277
|
+
{ name: "payoutReceiver", type: "address" },
|
|
278
|
+
{ name: "initialSupply", type: "uint256" },
|
|
279
|
+
{ name: "supply", type: "uint256" },
|
|
280
|
+
{ name: "allowance", type: "uint256" },
|
|
281
|
+
{ name: "currencyAddress", type: "address" },
|
|
282
|
+
{ name: "startTime", type: "uint256" },
|
|
283
|
+
{ name: "presaleDuration", type: "uint256" },
|
|
284
|
+
{ name: "presaleCost", type: "uint256" },
|
|
285
|
+
{ name: "presaleMerkleRoot", type: "bytes32" },
|
|
286
|
+
{ name: "publicDuration", type: "uint256" },
|
|
287
|
+
{ name: "publicCost", type: "uint256" },
|
|
288
|
+
{ name: "decayRate", type: "int256" },
|
|
289
|
+
{ name: "baseUri", type: "string" }
|
|
290
|
+
]
|
|
291
|
+
}
|
|
292
|
+
]
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
type: "function",
|
|
296
|
+
name: "getDropPhase",
|
|
297
|
+
stateMutability: "view",
|
|
298
|
+
inputs: [{ name: "nftAddress", type: "address" }],
|
|
299
|
+
outputs: [{ name: "", type: "uint8" }]
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
type: "function",
|
|
303
|
+
name: "getNumberMinted",
|
|
304
|
+
stateMutability: "view",
|
|
305
|
+
inputs: [
|
|
306
|
+
{ name: "nftAddress", type: "address" },
|
|
307
|
+
{ name: "recipient", type: "address" }
|
|
308
|
+
],
|
|
309
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
type: "function",
|
|
313
|
+
name: "purchase",
|
|
314
|
+
stateMutability: "payable",
|
|
315
|
+
inputs: [
|
|
316
|
+
{ name: "nftAddress", type: "address" },
|
|
317
|
+
{ name: "recipient", type: "address" },
|
|
318
|
+
{ name: "numberToMint", type: "uint256" },
|
|
319
|
+
{ name: "presaleNumberCanMint", type: "uint256" },
|
|
320
|
+
{ name: "proof", type: "bytes32[]" }
|
|
321
|
+
],
|
|
322
|
+
outputs: [{ name: "refundAmount", type: "uint256" }]
|
|
323
|
+
},
|
|
324
|
+
{ type: "error", name: "MintZeroTokens", inputs: [] },
|
|
325
|
+
{ type: "error", name: "NotOnAllowlist", inputs: [] },
|
|
326
|
+
{ type: "error", name: "YouShallNotMint", inputs: [] },
|
|
327
|
+
{ type: "error", name: "AlreadyReachedMintAllowance", inputs: [] },
|
|
328
|
+
{ type: "error", name: "InsufficientFunds", inputs: [] },
|
|
329
|
+
{ type: "error", name: "SanctionedAddress", inputs: [] },
|
|
330
|
+
// OpenZeppelin v5 Pausable: purchase is whenNotPaused.
|
|
331
|
+
{ type: "error", name: "EnforcedPause", inputs: [] }
|
|
332
|
+
];
|
|
333
|
+
|
|
334
|
+
// src/core/adapters/tl-stacks/allowlist.ts
|
|
335
|
+
|
|
336
|
+
var HASH = /^0x[0-9a-fA-F]{64}$/;
|
|
337
|
+
var UINT = /^\d+$/;
|
|
338
|
+
var MAX_UINT256 = 2n ** 256n - 1n;
|
|
339
|
+
var unavailable = (message, cause) => new (0, _chunkGO4TR3HBcjs.MintError)("ALLOWLIST_UNAVAILABLE", message, cause === void 0 ? void 0 : { cause });
|
|
340
|
+
var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
341
|
+
var hashWallet = (wallet) => _viem.keccak256.call(void 0, _viem.encodeAbiParameters.call(void 0, [{ type: "address" }], [_viem.getAddress.call(void 0, wallet)]));
|
|
342
|
+
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]))]));
|
|
343
|
+
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]));
|
|
344
|
+
var processProof = (leaf, proof) => proof.reduce((node, sibling) => hashPair(node, sibling), leaf);
|
|
345
|
+
function parseAllowlist(body) {
|
|
346
|
+
if (!isRecord(body)) throw unavailable("The allowlist file is not a merkle tree dump.");
|
|
347
|
+
if (body.format !== "standard-v1") throw unavailable("The allowlist file is in an unsupported format.");
|
|
348
|
+
const enc = body.leafEncoding;
|
|
349
|
+
if (!Array.isArray(enc) || enc.length !== 2 || enc[0] !== "bytes32" || enc[1] !== "uint256") {
|
|
350
|
+
throw unavailable("The allowlist file uses an unsupported leaf encoding.");
|
|
351
|
+
}
|
|
352
|
+
const { tree, values } = body;
|
|
353
|
+
if (!Array.isArray(tree) || tree.length === 0 || !tree.every((n) => typeof n === "string" && HASH.test(n))) {
|
|
354
|
+
throw unavailable("The allowlist file has no readable merkle tree.");
|
|
355
|
+
}
|
|
356
|
+
if (!Array.isArray(values)) throw unavailable("The allowlist file has no wallet values.");
|
|
357
|
+
const entries = /* @__PURE__ */ new Map();
|
|
358
|
+
for (const row of values) {
|
|
359
|
+
const value = isRecord(row) ? row.value : void 0;
|
|
360
|
+
const treeIndex = isRecord(row) ? row.treeIndex : void 0;
|
|
361
|
+
if (!Array.isArray(value) || value.length !== 2 || typeof value[0] !== "string" || !HASH.test(value[0])) {
|
|
362
|
+
throw unavailable("The allowlist file has an unreadable wallet entry.");
|
|
363
|
+
}
|
|
364
|
+
const raw = value[1];
|
|
365
|
+
const allowanceText = typeof raw === "string" ? raw : typeof raw === "number" && Number.isSafeInteger(raw) ? String(raw) : "";
|
|
366
|
+
if (!UINT.test(allowanceText) || BigInt(allowanceText) > MAX_UINT256) throw unavailable("The allowlist file has an unreadable allowance.");
|
|
367
|
+
if (typeof treeIndex !== "number") throw unavailable("The allowlist file has an unreadable tree index.");
|
|
368
|
+
const key = value[0].toLowerCase();
|
|
369
|
+
const allowance = BigInt(allowanceText);
|
|
370
|
+
const prev = entries.get(key);
|
|
371
|
+
if (!prev || allowance > prev.allowance) entries.set(key, { allowance, treeIndex });
|
|
372
|
+
}
|
|
373
|
+
return { root: tree[0].toLowerCase(), tree, entries };
|
|
374
|
+
}
|
|
375
|
+
var findEntry = (list, recipient) => _nullishCoalesce(list.entries.get(hashWallet(recipient).toLowerCase()), () => ( null));
|
|
376
|
+
function assertRoot(list, presaleMerkleRoot) {
|
|
377
|
+
if (list.root !== presaleMerkleRoot.toLowerCase()) {
|
|
378
|
+
throw unavailable("The allowlist file does not match this drop. The creator may have updated the allowlist; reload the page.");
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
var buildProof = (list, recipient, entry) => buildProofForHash(list, hashWallet(recipient), entry);
|
|
382
|
+
function buildProofForHash(list, hashedWallet, entry) {
|
|
383
|
+
const { tree } = list;
|
|
384
|
+
const { treeIndex } = entry;
|
|
385
|
+
if (!Number.isInteger(treeIndex) || treeIndex < 1 || treeIndex >= tree.length) {
|
|
386
|
+
throw unavailable("The allowlist file has a tree index outside the tree.");
|
|
387
|
+
}
|
|
388
|
+
const leaf = leafOf(hashedWallet, entry.allowance);
|
|
389
|
+
if (tree[treeIndex].toLowerCase() !== leaf.toLowerCase()) throw unavailable("The allowlist file entry does not match its merkle leaf.");
|
|
390
|
+
const proof = [];
|
|
391
|
+
let i = treeIndex;
|
|
392
|
+
while (i > 0) {
|
|
393
|
+
const sibling = i % 2 === 0 ? i - 1 : i + 1;
|
|
394
|
+
const node = tree[sibling];
|
|
395
|
+
if (node === void 0) throw unavailable("The allowlist file has a broken merkle tree.");
|
|
396
|
+
proof.push(node);
|
|
397
|
+
i = Math.floor((i - 1) / 2);
|
|
398
|
+
}
|
|
399
|
+
if (processProof(leaf, proof).toLowerCase() !== list.root) throw unavailable("The allowlist file does not produce a valid proof for this wallet.");
|
|
400
|
+
return proof;
|
|
720
401
|
}
|
|
721
|
-
var isRecord = (v) => typeof v === "object" && v !== null;
|
|
722
402
|
var scopeCaches = /* @__PURE__ */ new WeakMap();
|
|
723
|
-
function memo(cache2, key, signal, load) {
|
|
724
|
-
const hit = cache2.get(key);
|
|
725
|
-
if (hit) return hit;
|
|
726
|
-
const p = withSignal(load(), signal);
|
|
727
|
-
cache2.set(key, p);
|
|
728
|
-
p.catch(() => {
|
|
729
|
-
if (cache2.get(key) === p) cache2.delete(key);
|
|
730
|
-
});
|
|
731
|
-
return p;
|
|
732
|
-
}
|
|
733
403
|
function withSignal(p, signal) {
|
|
734
404
|
if (!signal) return p;
|
|
735
405
|
return new Promise((resolve, reject) => {
|
|
736
|
-
const onAbort = () => reject(
|
|
406
|
+
const onAbort = () => reject(unavailable("The allowlist request was cancelled.", signal.reason));
|
|
737
407
|
p.then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
738
408
|
if (signal.aborted) return onAbort();
|
|
739
409
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
740
410
|
});
|
|
741
411
|
}
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
const
|
|
747
|
-
|
|
748
|
-
if (
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
return body.map((row) => {
|
|
760
|
-
const proof = isRecord(row) ? row.merkleProof : void 0;
|
|
761
|
-
const value = isRecord(row) ? row.value : void 0;
|
|
762
|
-
if (!Array.isArray(proof) || !proof.every((p) => typeof p === "string" && /^0x[0-9a-fA-F]{64}$/.test(p)) || typeof value !== "number" || !Number.isInteger(value) || value < 0 || value > UINT32_MAX) {
|
|
763
|
-
throw new MintError("ALLOWLIST_UNAVAILABLE", "The allowlist service returned an unexpected response.");
|
|
412
|
+
var ALLOWLIST_TIMEOUT_MS = 3e4;
|
|
413
|
+
var ALLOWLIST_MAX_BYTES = 10 * 1024 * 1024;
|
|
414
|
+
var tooLarge = () => unavailable(`The allowlist file is larger than ${ALLOWLIST_MAX_BYTES / (1024 * 1024)} MB.`);
|
|
415
|
+
async function readCapped(res) {
|
|
416
|
+
const declared = Number(res.headers.get("content-length"));
|
|
417
|
+
if (Number.isFinite(declared) && declared > ALLOWLIST_MAX_BYTES) throw tooLarge();
|
|
418
|
+
if (!res.body) return "";
|
|
419
|
+
const reader = res.body.getReader();
|
|
420
|
+
const chunks = [];
|
|
421
|
+
let total = 0;
|
|
422
|
+
for (; ; ) {
|
|
423
|
+
const { done, value } = await reader.read();
|
|
424
|
+
if (done) break;
|
|
425
|
+
total += value.byteLength;
|
|
426
|
+
if (total > ALLOWLIST_MAX_BYTES) {
|
|
427
|
+
void reader.cancel().catch(() => void 0);
|
|
428
|
+
throw tooLarge();
|
|
764
429
|
}
|
|
765
|
-
|
|
766
|
-
});
|
|
767
|
-
}
|
|
768
|
-
async function fetchMerkleEntries(args) {
|
|
769
|
-
if (args.signal?.aborted) {
|
|
770
|
-
throw new MintError("ALLOWLIST_UNAVAILABLE", "The allowlist request was cancelled.", { cause: args.signal.reason });
|
|
430
|
+
chunks.push(value);
|
|
771
431
|
}
|
|
772
|
-
const
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
scopeCaches.set(args.scope, scoped);
|
|
432
|
+
const bytes = new Uint8Array(total);
|
|
433
|
+
let offset = 0;
|
|
434
|
+
for (const c of chunks) {
|
|
435
|
+
bytes.set(c, offset);
|
|
436
|
+
offset += c.byteLength;
|
|
778
437
|
}
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
// src/core/adapters/manifold-claim/index.ts
|
|
785
|
-
var V6_721 = "0x1eb73fee2090fb1c20105d5ba887e3c3ba14a17e";
|
|
786
|
-
var V6_1155 = "0x04ba6cf3c5aa6d4946f5b7f7adf111012a9fac65";
|
|
787
|
-
var V7_721 = "0x23aa05a271debffaa3d75739af5581f744b326e4";
|
|
788
|
-
var V7_1155 = "0x26bbea7803dcac346d5f5f135b57cf2c752a02be";
|
|
789
|
-
var V8_721 = "0x5889e848b2423344f7969bc158100c07595c0137";
|
|
790
|
-
var V8_1155 = "0x88438f4d4b8516e758a319ad16924da60e1e56cc";
|
|
791
|
-
var v6 = (chainId) => [
|
|
792
|
-
{ chainId, address: V6_721, generation: "V6", spec: "721", abi: "Claim721V5Optimization" },
|
|
793
|
-
{ chainId, address: V6_1155, generation: "V6", spec: "1155", abi: "Claim1155V5Optimization" }
|
|
794
|
-
];
|
|
795
|
-
var v7 = (chainId) => [
|
|
796
|
-
{ chainId, address: V7_721, generation: "V7", spec: "721", abi: "Claim721V7" },
|
|
797
|
-
{ chainId, address: V7_1155, generation: "V7", spec: "1155", abi: "Claim1155V7" }
|
|
798
|
-
];
|
|
799
|
-
var EXTENSIONS = [
|
|
800
|
-
...v6(1),
|
|
801
|
-
...v7(1),
|
|
802
|
-
...v6(8453),
|
|
803
|
-
...v7(8453),
|
|
804
|
-
...v6(10),
|
|
805
|
-
...v7(10),
|
|
806
|
-
...v7(360),
|
|
807
|
-
{ chainId: 360, address: V8_1155, generation: "V8", spec: "1155", abi: "Claim1155V7" },
|
|
808
|
-
...v6(11155111),
|
|
809
|
-
...v7(11155111),
|
|
810
|
-
{ chainId: 11155111, address: V8_721, generation: "V8", spec: "721", abi: "Claim721V7" },
|
|
811
|
-
{ chainId: 11155111, address: V8_1155, generation: "V8", spec: "1155", abi: "Claim1155V7" }
|
|
812
|
-
];
|
|
813
|
-
function findExtension(chainId, address) {
|
|
814
|
-
const a = address.toLowerCase();
|
|
815
|
-
return EXTENSIONS.find((e) => e.chainId === chainId && e.address === a);
|
|
816
|
-
}
|
|
817
|
-
var MERKLE_API = "https://apps.api.manifoldxyz.dev";
|
|
818
|
-
var MAX_MINT_COUNT = 65535;
|
|
819
|
-
var GAS_UNITS_BASE = 100000n;
|
|
820
|
-
var GAS_UNITS_PER_TOKEN = 150000n;
|
|
821
|
-
var GAS_UNITS_APPROVE = 60000n;
|
|
822
|
-
var dropResolved = /* @__PURE__ */ new WeakMap();
|
|
823
|
-
var WALLET_DATA_BRAND = /* @__PURE__ */ Symbol("manifold-claim-wallet-data");
|
|
824
|
-
var isWalletData = (d) => typeof d === "object" && d !== null && d.brand === WALLET_DATA_BRAND;
|
|
825
|
-
var isAllowlist = (claim) => claim.merkleRoot !== import_viem5.zeroHash;
|
|
826
|
-
function isContractFailure(e) {
|
|
827
|
-
if (!(e instanceof import_viem5.BaseError)) return false;
|
|
828
|
-
return e.walk((x) => x instanceof import_viem5.ContractFunctionRevertedError || x.name === "ContractFunctionZeroDataError") !== null;
|
|
829
|
-
}
|
|
830
|
-
function toRpcError(e) {
|
|
831
|
-
if (e instanceof MintError) return e;
|
|
832
|
-
const msg = e instanceof import_viem5.BaseError ? e.shortMessage : e instanceof Error ? e.message : String(e);
|
|
833
|
-
return new MintError("RPC_ERROR", `RPC request failed: ${msg}`, { cause: e });
|
|
834
|
-
}
|
|
835
|
-
async function rpc(fn) {
|
|
438
|
+
return new TextDecoder().decode(bytes);
|
|
439
|
+
}
|
|
440
|
+
async function fetchAndParse(fetchFn, url, signal) {
|
|
441
|
+
let res;
|
|
836
442
|
try {
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
443
|
+
signal.throwIfAborted();
|
|
444
|
+
res = await fetchFn(url, { signal });
|
|
445
|
+
} catch (cause) {
|
|
446
|
+
throw unavailable("Could not reach the allowlist file.", cause);
|
|
447
|
+
}
|
|
448
|
+
if (res.status === 429) throw new (0, _chunkGO4TR3HBcjs.MintError)("RATE_LIMITED", "The allowlist host is rate limiting requests. Try again shortly.");
|
|
449
|
+
if (!res.ok) throw unavailable(`The allowlist file is not available (HTTP ${res.status}).`);
|
|
450
|
+
let body;
|
|
451
|
+
try {
|
|
452
|
+
const text = await readCapped(res);
|
|
453
|
+
body = JSON.parse(text);
|
|
454
|
+
} catch (cause) {
|
|
455
|
+
if (cause instanceof _chunkGO4TR3HBcjs.MintError) throw cause;
|
|
456
|
+
throw unavailable("The allowlist file could not be read.", cause);
|
|
840
457
|
}
|
|
458
|
+
return parseAllowlist(body);
|
|
841
459
|
}
|
|
842
|
-
function
|
|
843
|
-
const
|
|
844
|
-
|
|
845
|
-
|
|
460
|
+
async function download(fetchFn, url, signal) {
|
|
461
|
+
const controller = new AbortController();
|
|
462
|
+
let onAbort;
|
|
463
|
+
const stopped = new Promise((_, reject) => {
|
|
464
|
+
onAbort = () => {
|
|
465
|
+
const reason = controller.signal.reason;
|
|
466
|
+
reject(reason instanceof _chunkGO4TR3HBcjs.MintError ? reason : unavailable("The allowlist request was cancelled.", reason));
|
|
467
|
+
};
|
|
468
|
+
controller.signal.addEventListener("abort", onAbort, { once: true });
|
|
846
469
|
});
|
|
847
|
-
const
|
|
848
|
-
if ((
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
return d.errorName;
|
|
861
|
-
} catch {
|
|
862
|
-
return `reverted with unknown error ${data.slice(0, 10)}`;
|
|
863
|
-
}
|
|
470
|
+
const onLifetimeAbort = () => controller.abort(_optionalChain([signal, 'optionalAccess', _12 => _12.reason]));
|
|
471
|
+
if (_optionalChain([signal, 'optionalAccess', _13 => _13.aborted])) onLifetimeAbort();
|
|
472
|
+
else _optionalChain([signal, 'optionalAccess', _14 => _14.addEventListener, 'call', _15 => _15("abort", onLifetimeAbort, { once: true })]);
|
|
473
|
+
const timer = setTimeout(
|
|
474
|
+
() => controller.abort(unavailable(`The allowlist file did not load within ${ALLOWLIST_TIMEOUT_MS / 1e3} seconds. Try again.`)),
|
|
475
|
+
ALLOWLIST_TIMEOUT_MS
|
|
476
|
+
);
|
|
477
|
+
try {
|
|
478
|
+
return await Promise.race([fetchAndParse(fetchFn, url, controller.signal), stopped]);
|
|
479
|
+
} finally {
|
|
480
|
+
clearTimeout(timer);
|
|
481
|
+
if (onAbort) controller.signal.removeEventListener("abort", onAbort);
|
|
482
|
+
_optionalChain([signal, 'optionalAccess', _16 => _16.removeEventListener, 'call', _17 => _17("abort", onLifetimeAbort)]);
|
|
864
483
|
}
|
|
865
|
-
const named = e.walk((x) => ["ExecutionRevertedError", "InsufficientFundsError"].includes(x.name));
|
|
866
|
-
return named instanceof import_viem5.BaseError ? named.shortMessage : null;
|
|
867
484
|
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
if (v > BigInt(Number.MAX_SAFE_INTEGER)) throw new MintError("RPC_ERROR", `Claim ${field} does not fit a safe integer`);
|
|
872
|
-
return Number(v);
|
|
873
|
-
}
|
|
874
|
-
function parseConfig(config) {
|
|
875
|
-
if (!(0, import_viem5.isAddress)(config.creatorContract, { strict: false })) {
|
|
876
|
-
throw new MintError("INVALID_CONFIG", "creatorContract is not a valid address.", { field: "creatorContract" });
|
|
877
|
-
}
|
|
878
|
-
if (config.extension !== void 0 && !(0, import_viem5.isAddress)(config.extension, { strict: false })) {
|
|
879
|
-
throw new MintError("INVALID_CONFIG", "extension is not a valid address.", { field: "extension" });
|
|
485
|
+
function loadAllowlist(args) {
|
|
486
|
+
if (!args.url) {
|
|
487
|
+
return Promise.reject(unavailable("This presale has no allowlist file configured (allowlistUrl). Ask the creator to add it."));
|
|
880
488
|
}
|
|
881
|
-
if (
|
|
882
|
-
|
|
489
|
+
if (_optionalChain([args, 'access', _18 => _18.signal, 'optionalAccess', _19 => _19.aborted])) return Promise.reject(unavailable("The allowlist request was cancelled.", args.signal.reason));
|
|
490
|
+
const fetchFn = _nullishCoalesce(args.fetch, () => ( ((input, init) => globalThis.fetch(input, init))));
|
|
491
|
+
let scoped = scopeCaches.get(args.scope);
|
|
492
|
+
if (!scoped || _optionalChain([scoped, 'access', _20 => _20.signal, 'optionalAccess', _21 => _21.aborted])) {
|
|
493
|
+
scoped = { signal: args.signal, loads: /* @__PURE__ */ new Map() };
|
|
494
|
+
scopeCaches.set(args.scope, scoped);
|
|
883
495
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
496
|
+
const cache2 = scoped;
|
|
497
|
+
const hit = cache2.loads.get(args.url);
|
|
498
|
+
if (hit) return hit;
|
|
499
|
+
const url = args.url;
|
|
500
|
+
const p = withSignal(download(fetchFn, url, cache2.signal), cache2.signal);
|
|
501
|
+
cache2.loads.set(url, p);
|
|
502
|
+
p.catch(() => {
|
|
503
|
+
if (cache2.loads.get(url) === p) cache2.loads.delete(url);
|
|
504
|
+
});
|
|
505
|
+
return p;
|
|
889
506
|
}
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
case "Claim1155V7": {
|
|
909
|
-
const c = await client.readContract({ address, abi: CLAIM_1155_V7_ABI, functionName: "getClaim", args });
|
|
910
|
-
return { ...base2(c), signingAddress: c.signingAddress };
|
|
507
|
+
|
|
508
|
+
// src/core/adapters/tl-stacks/index.ts
|
|
509
|
+
var FALLBACK_GAS_BASE = 150000n;
|
|
510
|
+
var FALLBACK_GAS_PER_TOKEN = 150000n;
|
|
511
|
+
var details = /* @__PURE__ */ new WeakMap();
|
|
512
|
+
function bad(field, message) {
|
|
513
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("INVALID_CONFIG", `${field} ${message}`, { field });
|
|
514
|
+
}
|
|
515
|
+
function validateTlStacksConfig(config) {
|
|
516
|
+
if (!Number.isInteger(config.chainId) || config.chainId <= 0) bad("chainId", "must be a positive integer");
|
|
517
|
+
if (typeof config.stacks !== "string" || !_viem.isAddress.call(void 0, config.stacks, { strict: false })) bad("stacks", "is not a valid address");
|
|
518
|
+
if (typeof config.nftContract !== "string" || !_viem.isAddress.call(void 0, config.nftContract, { strict: false })) bad("nftContract", "is not a valid address");
|
|
519
|
+
if (config.allowlistUrl !== void 0) {
|
|
520
|
+
const https = (() => {
|
|
521
|
+
try {
|
|
522
|
+
return typeof config.allowlistUrl === "string" && new URL(config.allowlistUrl).protocol === "https:";
|
|
523
|
+
} catch (e2) {
|
|
524
|
+
return false;
|
|
911
525
|
}
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
if (isContractFailure(e)) throw notFound(config);
|
|
915
|
-
throw toRpcError(e);
|
|
526
|
+
})();
|
|
527
|
+
if (!https) bad("allowlistUrl", "must be an https: URL");
|
|
916
528
|
}
|
|
917
529
|
}
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
530
|
+
var abortError = () => new DOMException("The operation was aborted", "AbortError");
|
|
531
|
+
var isAbortError = (e) => _optionalChain([e, 'optionalAccess', _22 => _22.name]) === "AbortError";
|
|
532
|
+
function throwIfAborted(ctx) {
|
|
533
|
+
if (_optionalChain([ctx, 'access', _23 => _23.signal, 'optionalAccess', _24 => _24.aborted])) throw abortError();
|
|
534
|
+
}
|
|
535
|
+
function io(ctx, start) {
|
|
536
|
+
const signal = ctx.signal;
|
|
537
|
+
if (!signal) return start();
|
|
538
|
+
if (signal.aborted) return Promise.reject(abortError());
|
|
539
|
+
return new Promise((resolve, reject) => {
|
|
540
|
+
const onAbort = () => reject(abortError());
|
|
541
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
542
|
+
start().then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
543
|
+
});
|
|
929
544
|
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
async function
|
|
936
|
-
const { creator, instanceId, extension } = parseConfig(config);
|
|
937
|
-
const { client } = ctx;
|
|
938
|
-
if (extension) {
|
|
939
|
-
const entry = findExtension(config.chainId, extension);
|
|
940
|
-
if (!entry) throw unknownExtension(extension, `is not a supported Manifold claim extension on chain ${config.chainId}`);
|
|
941
|
-
if (!await hasCode(client, extension)) throw unknownExtension(extension, "has no contract code on this chain");
|
|
942
|
-
return { entry, claim: await readClaim(client, entry, creator, instanceId, config) };
|
|
943
|
-
}
|
|
944
|
-
let registered;
|
|
545
|
+
var shortMessage = (e) => e instanceof _viem.BaseError ? e.shortMessage : e instanceof Error ? e.message : String(e);
|
|
546
|
+
function rpcError(e) {
|
|
547
|
+
if (_chunkGO4TR3HBcjs.isMintError.call(void 0, e) || isAbortError(e)) throw e;
|
|
548
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("RPC_ERROR", `RPC request failed: ${shortMessage(e)}`, { cause: e });
|
|
549
|
+
}
|
|
550
|
+
async function readStacks(ctx, config, functionName, args = []) {
|
|
945
551
|
try {
|
|
946
|
-
|
|
552
|
+
return await io(
|
|
553
|
+
ctx,
|
|
554
|
+
() => ctx.client.readContract({ address: _viem.getAddress.call(void 0, config.stacks), abi: stacksAbi, functionName, args })
|
|
555
|
+
);
|
|
947
556
|
} catch (e) {
|
|
948
|
-
if (
|
|
949
|
-
|
|
557
|
+
if (_chunkGO4TR3HBcjs.isMintError.call(void 0, e) || isAbortError(e)) throw e;
|
|
558
|
+
if (e instanceof _viem.BaseError && e.walk((x) => x instanceof _viem.ContractFunctionRevertedError || x instanceof _viem.ContractFunctionZeroDataError)) {
|
|
559
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("INVALID_CONFIG", `stacks ${functionName}() reverted or returned no data. Is ${config.stacks} a TL Stacks 721 contract on chain ${config.chainId}?`, {
|
|
560
|
+
field: "stacks",
|
|
561
|
+
cause: e
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
return rpcError(e);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
var versions = /* @__PURE__ */ new WeakMap();
|
|
568
|
+
async function checkVersion(ctx, config) {
|
|
569
|
+
const load = () => readStacks(ctx, config, "VERSION");
|
|
570
|
+
let version;
|
|
571
|
+
if (ctx.cacheScope) {
|
|
572
|
+
let byStacks = versions.get(ctx.cacheScope);
|
|
573
|
+
if (!byStacks) versions.set(ctx.cacheScope, byStacks = /* @__PURE__ */ new Map());
|
|
574
|
+
const key = `${config.chainId}:${config.stacks.toLowerCase()}`;
|
|
575
|
+
const cache2 = byStacks;
|
|
576
|
+
let hit = cache2.get(key);
|
|
577
|
+
if (!hit) {
|
|
578
|
+
const p = load();
|
|
579
|
+
cache2.set(key, hit = p);
|
|
580
|
+
p.catch(() => {
|
|
581
|
+
if (cache2.get(key) === p) cache2.delete(key);
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
version = hit;
|
|
585
|
+
} else {
|
|
586
|
+
version = load();
|
|
950
587
|
}
|
|
951
|
-
const
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
if (!await hasCode(client, entry.address)) return null;
|
|
955
|
-
try {
|
|
956
|
-
return { entry, claim: await readClaim(client, entry, creator, instanceId, config) };
|
|
957
|
-
} catch (e) {
|
|
958
|
-
if (e instanceof MintError && e.reason === "CLAIM_NOT_FOUND") return null;
|
|
959
|
-
throw e;
|
|
960
|
-
}
|
|
961
|
-
})
|
|
962
|
-
);
|
|
963
|
-
const hits = found.filter((f) => f !== null);
|
|
964
|
-
if (hits.length === 0) throw notFound(config);
|
|
965
|
-
if (hits.length > 1) {
|
|
966
|
-
throw new MintError(
|
|
967
|
-
"AMBIGUOUS_EXTENSION",
|
|
968
|
-
`Claim ${config.instanceId} exists on ${hits.length} extensions (${hits.map((h) => h.entry.address).join(", ")}). Set config.extension.`
|
|
969
|
-
);
|
|
588
|
+
const v = await version;
|
|
589
|
+
if (!SUPPORTED_VERSIONS.includes(v)) {
|
|
590
|
+
bad("stacks", `is TL Stacks ${v}. Dropkit supports ${SUPPORTED_VERSIONS.join(" and ")} only.`);
|
|
970
591
|
}
|
|
971
|
-
return hits[0];
|
|
972
592
|
}
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
}
|
|
999
|
-
const
|
|
593
|
+
var money = (value, decimals, symbol) => ({ value, decimals, symbol, formatted: _viem.formatUnits.call(void 0, value, decimals) });
|
|
594
|
+
function nativeMeta(ctx) {
|
|
595
|
+
const n = _optionalChain([ctx, 'access', _25 => _25.client, 'access', _26 => _26.chain, 'optionalAccess', _27 => _27.nativeCurrency]);
|
|
596
|
+
return { decimals: _nullishCoalesce(_optionalChain([n, 'optionalAccess', _28 => _28.decimals]), () => ( 18)), symbol: _nullishCoalesce(_optionalChain([n, 'optionalAccess', _29 => _29.symbol]), () => ( "ETH")) };
|
|
597
|
+
}
|
|
598
|
+
function seconds(v, field) {
|
|
599
|
+
if (v > BigInt(Number.MAX_SAFE_INTEGER)) throw new (0, _chunkGO4TR3HBcjs.MintError)("INVALID_CONFIG", `${field} is too large for a unix timestamp`, { field });
|
|
600
|
+
return Number(v);
|
|
601
|
+
}
|
|
602
|
+
async function readDrop(ctx, config) {
|
|
603
|
+
validateTlStacksConfig(config);
|
|
604
|
+
throwIfAborted(ctx);
|
|
605
|
+
await checkVersion(ctx, config);
|
|
606
|
+
const nft = _viem.getAddress.call(void 0, config.nftContract);
|
|
607
|
+
const [drop, phaseRaw, fee] = await Promise.all([
|
|
608
|
+
readStacks(ctx, config, "getDrop", [nft]),
|
|
609
|
+
readStacks(ctx, config, "getDropPhase", [nft]),
|
|
610
|
+
readStacks(ctx, config, "protocolFee")
|
|
611
|
+
]);
|
|
612
|
+
const phase = Number(phaseRaw);
|
|
613
|
+
if (phase === DROP_PHASE.NOT_CONFIGURED) {
|
|
614
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("DROP_NOT_FOUND", "No Transient Labs drop is configured for this NFT contract on this chain.");
|
|
615
|
+
}
|
|
616
|
+
if (drop.currencyAddress !== _viem.zeroAddress) {
|
|
617
|
+
bad("nftContract", `is sold for an ERC-20 (${drop.currencyAddress}). Dropkit supports drops priced in the native token only.`);
|
|
618
|
+
}
|
|
619
|
+
const hasPresale = drop.presaleDuration > 0n;
|
|
620
|
+
const presalePrice = phase === DROP_PHASE.PRESALE || phase === DROP_PHASE.NOT_STARTED && hasPresale;
|
|
621
|
+
const unitPrice = presalePrice ? drop.presaleCost : drop.publicCost;
|
|
622
|
+
const startTime = seconds(drop.startTime, "startTime");
|
|
623
|
+
const presaleEnd = seconds(drop.startTime + drop.presaleDuration, "presaleDuration");
|
|
624
|
+
const soldOut = drop.supply === 0n;
|
|
625
|
+
const neverMintable = drop.initialSupply === 0n;
|
|
626
|
+
const native = nativeMeta(ctx);
|
|
627
|
+
const info = {
|
|
1000
628
|
chainId: config.chainId,
|
|
1001
|
-
unitPrice,
|
|
629
|
+
unitPrice: money(unitPrice, native.decimals, native.symbol),
|
|
1002
630
|
unitFee: money(fee, native.decimals, native.symbol),
|
|
1003
|
-
totalMinted:
|
|
1004
|
-
maxSupply:
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
631
|
+
totalMinted: drop.initialSupply - drop.supply,
|
|
632
|
+
maxSupply: drop.initialSupply,
|
|
633
|
+
// A never-mintable drop has no start either, so the hook clock has no boundary ahead to tick towards (review F13).
|
|
634
|
+
startTime: neverMintable || startTime === 0 ? null : startTime,
|
|
635
|
+
// At supply 0 the drop is sold out for good: no end time, so it never turns into `ended` (D14).
|
|
636
|
+
endTime: neverMintable ? 0 : soldOut ? null : seconds(drop.startTime + drop.presaleDuration + drop.publicDuration, "publicDuration"),
|
|
637
|
+
isAllowlist: phase === DROP_PHASE.PRESALE,
|
|
638
|
+
paymentToken: null,
|
|
639
|
+
pricePer: "unit",
|
|
640
|
+
phaseEndsAt: presalePrice ? presaleEnd : null,
|
|
641
|
+
walletKey: `${phase}:${drop.presaleMerkleRoot}:${unitPrice}:${fee}`
|
|
1010
642
|
};
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
const
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
643
|
+
details.set(info, {
|
|
644
|
+
phase,
|
|
645
|
+
presaleMerkleRoot: drop.presaleMerkleRoot,
|
|
646
|
+
allowance: drop.allowance,
|
|
647
|
+
presaleDuration: drop.presaleDuration,
|
|
648
|
+
publicDuration: drop.publicDuration,
|
|
649
|
+
startTime: drop.startTime
|
|
650
|
+
});
|
|
651
|
+
return info;
|
|
652
|
+
}
|
|
653
|
+
async function detailOf(ctx, config, drop) {
|
|
654
|
+
const hit = details.get(drop);
|
|
655
|
+
if (hit) return hit;
|
|
656
|
+
const nft = _viem.getAddress.call(void 0, config.nftContract);
|
|
657
|
+
const [raw, phase] = await Promise.all([
|
|
658
|
+
readStacks(ctx, config, "getDrop", [nft]),
|
|
659
|
+
readStacks(ctx, config, "getDropPhase", [nft])
|
|
660
|
+
]);
|
|
661
|
+
return {
|
|
662
|
+
phase: Number(phase),
|
|
663
|
+
presaleMerkleRoot: raw.presaleMerkleRoot,
|
|
664
|
+
allowance: raw.allowance,
|
|
665
|
+
presaleDuration: raw.presaleDuration,
|
|
666
|
+
publicDuration: raw.publicDuration,
|
|
667
|
+
startTime: raw.startTime
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
var dayTime = (unix) => new Date(unix * 1e3).toLocaleString(void 0, { dateStyle: "medium", timeStyle: "short" });
|
|
671
|
+
function notOnAllowlist(d) {
|
|
672
|
+
const opens = Number(d.startTime + d.presaleDuration);
|
|
673
|
+
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.";
|
|
674
|
+
return { reason: "NOT_ON_ALLOWLIST", message };
|
|
675
|
+
}
|
|
676
|
+
async function readWallet(ctx, config, { payer, recipient, quantity, drop }) {
|
|
677
|
+
validateTlStacksConfig(config);
|
|
678
|
+
throwIfAborted(ctx);
|
|
679
|
+
const detail = await detailOf(ctx, config, drop);
|
|
680
|
+
const nft = _viem.getAddress.call(void 0, config.nftContract);
|
|
681
|
+
const presale = detail.phase === DROP_PHASE.PRESALE;
|
|
682
|
+
const [minted, native, gasPrice, list] = await Promise.all([
|
|
683
|
+
readStacks(ctx, config, "getNumberMinted", [nft, _viem.getAddress.call(void 0, recipient)]),
|
|
684
|
+
io(ctx, () => ctx.client.getBalance({ address: payer })).catch(rpcError),
|
|
685
|
+
io(ctx, () => ctx.client.getGasPrice()).catch(rpcError),
|
|
686
|
+
presale ? loadAllowlist({ scope: _nullishCoalesce(ctx.cacheScope, () => ( drop)), url: config.allowlistUrl, fetch: ctx.fetch, signal: ctx.signal }) : Promise.resolve(null)
|
|
687
|
+
]);
|
|
688
|
+
let walletMax = detail.allowance;
|
|
689
|
+
let proof = [];
|
|
690
|
+
let presaleNumberCanMint = 0n;
|
|
1027
691
|
let ineligible = null;
|
|
1028
|
-
let
|
|
1029
|
-
if (
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
);
|
|
1040
|
-
unused = entries.filter((_, i) => minted[i] === false);
|
|
692
|
+
let allowlistRemaining = null;
|
|
693
|
+
if (presale && list) {
|
|
694
|
+
assertRoot(list, detail.presaleMerkleRoot);
|
|
695
|
+
const entry = findEntry(list, recipient);
|
|
696
|
+
if (!entry) {
|
|
697
|
+
walletMax = 0n;
|
|
698
|
+
ineligible = notOnAllowlist(detail);
|
|
699
|
+
} else {
|
|
700
|
+
walletMax = entry.allowance;
|
|
701
|
+
presaleNumberCanMint = entry.allowance;
|
|
702
|
+
proof = buildProof(list, recipient, entry);
|
|
1041
703
|
}
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
704
|
+
}
|
|
705
|
+
const remaining = walletMax > minted ? walletMax - minted : 0n;
|
|
706
|
+
if (presale && ineligible === null) {
|
|
707
|
+
allowlistRemaining = Number(remaining < BigInt(_chunkGO4TR3HBcjs.MAX_QUANTITY) ? remaining : BigInt(_chunkGO4TR3HBcjs.MAX_QUANTITY));
|
|
708
|
+
if (remaining === 0n) ineligible = { reason: "ALLOWLIST_USED", message: `This wallet has already minted its allowlist allocation of ${walletMax}.` };
|
|
709
|
+
} else if (!presale && remaining === 0n) {
|
|
710
|
+
ineligible = { reason: "WALLET_LIMIT", message: `This wallet has already minted its limit of ${walletMax}.` };
|
|
711
|
+
}
|
|
712
|
+
const maxQuantity = Number(remaining < BigInt(_chunkGO4TR3HBcjs.MAX_QUANTITY) ? remaining : BigInt(_chunkGO4TR3HBcjs.MAX_QUANTITY));
|
|
713
|
+
const data = { presaleNumberCanMint, proof, unitPrice: drop.unitPrice.value, unitFee: drop.unitFee.value };
|
|
714
|
+
const qty = BigInt(quantity);
|
|
715
|
+
const value = qty * (data.unitPrice + data.unitFee);
|
|
716
|
+
let gas = FALLBACK_GAS_BASE + FALLBACK_GAS_PER_TOKEN * qty;
|
|
717
|
+
const open = detail.phase === DROP_PHASE.PRESALE || detail.phase === DROP_PHASE.PUBLIC_SALE;
|
|
718
|
+
if (open && ineligible === null && native >= value) {
|
|
719
|
+
try {
|
|
720
|
+
const estimated = await io(
|
|
721
|
+
ctx,
|
|
722
|
+
() => ctx.client.estimateGas({ account: payer, to: _viem.getAddress.call(void 0, config.stacks), data: encodePurchase(config, recipient, qty, data), value })
|
|
723
|
+
);
|
|
724
|
+
gas = estimated;
|
|
725
|
+
} catch (e) {
|
|
726
|
+
if (isAbortError(e)) throw e;
|
|
1048
727
|
}
|
|
1049
|
-
}
|
|
1050
|
-
walletMax = claim.walletMax;
|
|
1051
|
-
walletMinted = BigInt(
|
|
1052
|
-
await rpc(() => client.readContract({ address: extension, abi: EXTENSION_COMMON_ABI, functionName: "getTotalMints", args: [recipient, creator, instanceId] }))
|
|
1053
|
-
);
|
|
1054
|
-
const left = walletMax > walletMinted ? walletMax - walletMinted : 0n;
|
|
1055
|
-
maxQuantity = Number(left);
|
|
1056
|
-
if (left === 0n) ineligible = { reason: "WALLET_LIMIT", message: `This wallet has already minted its limit of ${walletMax}.` };
|
|
1057
|
-
}
|
|
1058
|
-
const token = claim.erc20 === import_viem5.zeroAddress ? null : (0, import_viem5.getAddress)(claim.erc20);
|
|
1059
|
-
const [native, erc20, gasPrice] = await rpc(
|
|
1060
|
-
() => Promise.all([
|
|
1061
|
-
client.getBalance({ address: payer }),
|
|
1062
|
-
token ? client.readContract({ address: token, abi: ERC20_ABI, functionName: "balanceOf", args: [payer] }) : Promise.resolve(null),
|
|
1063
|
-
client.getGasPrice()
|
|
1064
|
-
])
|
|
1065
|
-
);
|
|
1066
|
-
const gasUnits = GAS_UNITS_BASE + GAS_UNITS_PER_TOKEN * BigInt(Math.max(1, args.quantity)) + (token ? GAS_UNITS_APPROVE : 0n);
|
|
1067
|
-
const data = { brand: WALLET_DATA_BRAND, resolved, config, recipient, unused };
|
|
728
|
+
}
|
|
1068
729
|
return {
|
|
1069
|
-
walletMinted,
|
|
730
|
+
walletMinted: minted,
|
|
1070
731
|
walletMax,
|
|
1071
732
|
allowlistRemaining,
|
|
1072
733
|
maxQuantity,
|
|
1073
734
|
ineligible,
|
|
1074
|
-
balances: { native, erc20 },
|
|
1075
|
-
gasReserve:
|
|
735
|
+
balances: { native, erc20: null },
|
|
736
|
+
gasReserve: gas * gasPrice,
|
|
1076
737
|
data
|
|
1077
738
|
};
|
|
1078
739
|
}
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
const
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
const drop = (await loadDrop(ctx, config)).drop;
|
|
1091
|
-
data = (await loadWallet(ctx, config, { payer, recipient, quantity, drop })).data;
|
|
1092
|
-
}
|
|
1093
|
-
if (!isWalletData(data)) throw new MintError("RPC_ERROR", "Wallet read produced no plan data.");
|
|
1094
|
-
const { entry, claim, fee } = data.resolved;
|
|
1095
|
-
const extension = (0, import_viem5.getAddress)(entry.address);
|
|
1096
|
-
let mintIndices = [];
|
|
1097
|
-
let merkleProofs = [];
|
|
1098
|
-
if (isAllowlist(claim)) {
|
|
1099
|
-
if (quantity > data.unused.length) {
|
|
1100
|
-
throw new MintError("WALLET_LIMIT", `Only ${data.unused.length} allowlist spot(s) left for this wallet.`);
|
|
1101
|
-
}
|
|
1102
|
-
const picked = data.unused.slice(0, quantity);
|
|
1103
|
-
mintIndices = picked.map((p) => p.mintIndex);
|
|
1104
|
-
merkleProofs = picked.map((p) => p.proof);
|
|
740
|
+
function encodePurchase(config, recipient, quantity, data) {
|
|
741
|
+
return _viem.encodeFunctionData.call(void 0, {
|
|
742
|
+
abi: stacksAbi,
|
|
743
|
+
functionName: "purchase",
|
|
744
|
+
args: [_viem.getAddress.call(void 0, config.nftContract), _viem.getAddress.call(void 0, recipient), quantity, data.presaleNumberCanMint, [...data.proof]]
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
function walletData(wallet) {
|
|
748
|
+
const d = wallet.data;
|
|
749
|
+
if (!d || typeof d.presaleNumberCanMint !== "bigint" || typeof d.unitPrice !== "bigint" || typeof d.unitFee !== "bigint" || !Array.isArray(d.proof)) {
|
|
750
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("RPC_ERROR", "The wallet read is missing the data this mint needs. Reload and try again.");
|
|
1105
751
|
}
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
const
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
approve = {
|
|
1115
|
-
token: erc20,
|
|
1116
|
-
spender: extension,
|
|
1117
|
-
amount: cost,
|
|
1118
|
-
tx: { to: erc20, data: (0, import_viem5.encodeFunctionData)({ abi: ERC20_ABI, functionName: "approve", args: [extension, cost] }), value: 0n }
|
|
1119
|
-
};
|
|
1120
|
-
}
|
|
752
|
+
return d;
|
|
753
|
+
}
|
|
754
|
+
async function buildPlan(ctx, attempt, wallet) {
|
|
755
|
+
const { config, recipient } = attempt;
|
|
756
|
+
validateTlStacksConfig(config);
|
|
757
|
+
throwIfAborted(ctx);
|
|
758
|
+
if (!Number.isInteger(attempt.quantity) || attempt.quantity < 1) {
|
|
759
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("SIMULATION_REVERTED", "Choose at least one token to mint.");
|
|
1121
760
|
}
|
|
761
|
+
const data = walletData(wallet);
|
|
762
|
+
const qty = BigInt(attempt.quantity);
|
|
1122
763
|
return {
|
|
1123
|
-
approve,
|
|
764
|
+
approve: null,
|
|
1124
765
|
mint: {
|
|
1125
|
-
to:
|
|
1126
|
-
data: (
|
|
1127
|
-
|
|
1128
|
-
functionName: "mintProxy",
|
|
1129
|
-
args: [creator, instanceId, quantity, mintIndices, merkleProofs.map((p) => [...p]), recipient]
|
|
1130
|
-
}),
|
|
1131
|
-
value
|
|
766
|
+
to: _viem.getAddress.call(void 0, config.stacks),
|
|
767
|
+
data: encodePurchase(config, recipient, qty, data),
|
|
768
|
+
value: qty * (data.unitPrice + data.unitFee)
|
|
1132
769
|
},
|
|
1133
|
-
tokenContract:
|
|
770
|
+
tokenContract: _viem.getAddress.call(void 0, config.nftContract)
|
|
1134
771
|
};
|
|
1135
772
|
}
|
|
1136
|
-
var
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
773
|
+
var TL_MESSAGES = {
|
|
774
|
+
NotOnAllowlist: "This wallet is not on the allowlist for the current sale.",
|
|
775
|
+
YouShallNotMint: "This drop is not open for minting right now.",
|
|
776
|
+
AlreadyReachedMintAllowance: "This wallet has already minted its limit.",
|
|
777
|
+
InsufficientFunds: "The price or fee changed since the page loaded, so the payment is too low. Reload the page and try again.",
|
|
778
|
+
MintZeroTokens: "Choose at least one token to mint.",
|
|
779
|
+
SanctionedAddress: "This wallet or the recipient is blocked by a sanctions check, so it cannot mint.",
|
|
780
|
+
EnforcedPause: "Minting is paused by Transient Labs right now. Try again later."
|
|
781
|
+
};
|
|
782
|
+
function revertData(e) {
|
|
783
|
+
for (let cur = e, depth = 0; cur && depth < 12; depth++) {
|
|
784
|
+
const d = cur.data;
|
|
785
|
+
if (typeof d === "string" && d.startsWith("0x") && d.length >= 10) return d;
|
|
786
|
+
if (d && typeof d === "object" && typeof d.data === "string") {
|
|
787
|
+
const inner = d.data;
|
|
788
|
+
if (inner.startsWith("0x") && inner.length >= 10) return inner;
|
|
1152
789
|
}
|
|
790
|
+
cur = cur.cause;
|
|
1153
791
|
}
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
// src/core/adapters/contract/index.ts
|
|
1157
|
-
var import_viem7 = require("viem");
|
|
1158
|
-
|
|
1159
|
-
// src/core/machine.ts
|
|
1160
|
-
var import_viem6 = require("viem");
|
|
1161
|
-
var MINT_STATES = [
|
|
1162
|
-
"loading",
|
|
1163
|
-
"unsupported",
|
|
1164
|
-
"upcoming",
|
|
1165
|
-
"ended",
|
|
1166
|
-
"sold-out",
|
|
1167
|
-
"disconnected",
|
|
1168
|
-
"connecting",
|
|
1169
|
-
"live",
|
|
1170
|
-
"ineligible",
|
|
1171
|
-
"insufficient-funds",
|
|
1172
|
-
"switching-chain",
|
|
1173
|
-
"approving",
|
|
1174
|
-
"minting",
|
|
1175
|
-
"confirming",
|
|
1176
|
-
"success",
|
|
1177
|
-
"error"
|
|
1178
|
-
];
|
|
1179
|
-
var CLICKABLE_STATES = ["disconnected", "live", "success", "error"];
|
|
1180
|
-
var IN_FLIGHT_STATES = ["switching-chain", "approving", "minting", "confirming"];
|
|
1181
|
-
var MAX_QUANTITY = 65535;
|
|
1182
|
-
function initialState(opts) {
|
|
1183
|
-
return {
|
|
1184
|
-
name: "loading",
|
|
1185
|
-
reason: null,
|
|
1186
|
-
message: null,
|
|
1187
|
-
readGen: 0,
|
|
1188
|
-
walletGen: 0,
|
|
1189
|
-
drop: null,
|
|
1190
|
-
account: null,
|
|
1191
|
-
walletRead: null,
|
|
1192
|
-
blocked: null,
|
|
1193
|
-
quantity: toQuantity(opts?.quantity ?? 1, MAX_QUANTITY),
|
|
1194
|
-
attempt: null,
|
|
1195
|
-
result: null,
|
|
1196
|
-
pendingRefresh: false,
|
|
1197
|
-
now: 0,
|
|
1198
|
-
crossChain: false,
|
|
1199
|
-
routePending: false,
|
|
1200
|
-
route: null,
|
|
1201
|
-
short: null
|
|
1202
|
-
};
|
|
792
|
+
return null;
|
|
1203
793
|
}
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
if (
|
|
1208
|
-
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
if (drop === null) return named("loading");
|
|
1221
|
-
if (drop.endTime !== null && drop.endTime <= s.now) return named("ended");
|
|
1222
|
-
if (drop.maxSupply !== null && drop.maxSupply > 0n && drop.totalMinted >= drop.maxSupply) return named("sold-out");
|
|
1223
|
-
if (drop.startTime !== null && drop.startTime > s.now) return named("upcoming");
|
|
1224
|
-
if (s.account === null) return named("disconnected");
|
|
1225
|
-
if (walletRead === null) return named("loading");
|
|
1226
|
-
if (s.blocked !== null) return s.blocked;
|
|
1227
|
-
if (walletRead.ineligible !== null) {
|
|
1228
|
-
return { name: "ineligible", reason: walletRead.ineligible.reason, message: walletRead.ineligible.message };
|
|
1229
|
-
}
|
|
1230
|
-
if (s.routePending) return named("loading");
|
|
1231
|
-
if (s.route?.kind === "relay") return named("live");
|
|
1232
|
-
if (s.short !== null) {
|
|
1233
|
-
return { name: "insufficient-funds", reason: "INSUFFICIENT_FUNDS", message: `Not enough ${s.short.symbol} on ${s.short.name}. ${PICK_ANOTHER}` };
|
|
1234
|
-
}
|
|
1235
|
-
const total = selectTotal(s);
|
|
1236
|
-
if (total !== null) {
|
|
1237
|
-
const { native, erc20 } = total;
|
|
1238
|
-
if (native.value + walletRead.gasReserve > walletRead.balances.native) {
|
|
1239
|
-
const more = s.crossChain ? ` ${PICK_ANOTHER}` : "";
|
|
1240
|
-
return { name: "insufficient-funds", reason: "INSUFFICIENT_FUNDS", message: `Not enough ${native.symbol} to cover the mint.${more}` };
|
|
1241
|
-
}
|
|
1242
|
-
if (erc20 !== null && walletRead.balances.erc20 !== null && erc20.value > walletRead.balances.erc20) {
|
|
1243
|
-
return { name: "insufficient-funds", reason: "INSUFFICIENT_FUNDS", message: `Not enough ${erc20.symbol} to cover the mint.` };
|
|
794
|
+
function decodeTlRevert(e) {
|
|
795
|
+
if (_chunkGO4TR3HBcjs.isMintError.call(void 0, e)) return e;
|
|
796
|
+
if (isAbortError(e)) throw e;
|
|
797
|
+
if (e instanceof _viem.BaseError && e.walk((x) => x instanceof _viem.InsufficientFundsError)) {
|
|
798
|
+
return new (0, _chunkGO4TR3HBcjs.MintError)("INSUFFICIENT_FUNDS", `The wallet cannot cover the mint: ${e.shortMessage}`, { cause: e });
|
|
799
|
+
}
|
|
800
|
+
const data = revertData(e);
|
|
801
|
+
if (data) {
|
|
802
|
+
try {
|
|
803
|
+
const { errorName, args } = _viem.decodeErrorResult.call(void 0, { abi: stacksAbi, data });
|
|
804
|
+
const known = TL_MESSAGES[errorName];
|
|
805
|
+
if (known) return new (0, _chunkGO4TR3HBcjs.MintError)("SIMULATION_REVERTED", known, { cause: e, domain: "tl-stacks" });
|
|
806
|
+
const shown = (_nullishCoalesce(args, () => ( []))).map(String).join(", ");
|
|
807
|
+
return new (0, _chunkGO4TR3HBcjs.MintError)("SIMULATION_REVERTED", `Transient Labs rejected the mint (${errorName}(${shown})).`, { cause: e, domain: "tl-stacks" });
|
|
808
|
+
} catch (e3) {
|
|
809
|
+
return new (0, _chunkGO4TR3HBcjs.MintError)("SIMULATION_REVERTED", `Transient Labs rejected the mint (unrecognized error ${data.slice(0, 10)}).`, { cause: e, domain: "tl-stacks" });
|
|
1244
810
|
}
|
|
1245
811
|
}
|
|
1246
|
-
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
if (!isIdle(s)) return s;
|
|
1250
|
-
return { ...s, ...derive(s, unsupported) };
|
|
812
|
+
const reverted = e instanceof _viem.BaseError && e.walk((x) => x.code === 3 || /execution reverted/i.test(x.message));
|
|
813
|
+
if (reverted) return new (0, _chunkGO4TR3HBcjs.MintError)("SIMULATION_REVERTED", shortMessage(e), { cause: e });
|
|
814
|
+
return new (0, _chunkGO4TR3HBcjs.MintError)("RPC_ERROR", `RPC request failed: ${shortMessage(e)}`, { cause: e });
|
|
1251
815
|
}
|
|
1252
|
-
function
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
const failed = (reason, message) => {
|
|
1259
|
-
if (inFlight) return { ...state, pendingRefresh: true };
|
|
1260
|
-
if (state.name === "success" || state.name === "error") return state;
|
|
1261
|
-
return { ...state, name: "error", reason, message };
|
|
1262
|
-
};
|
|
1263
|
-
switch (event.type) {
|
|
1264
|
-
case "LOAD": {
|
|
1265
|
-
if (event.kind === "refresh") {
|
|
1266
|
-
const next2 = { ...state, readGen: event.gen };
|
|
1267
|
-
return inFlight ? { ...next2, pendingRefresh: true } : settle(next2);
|
|
1268
|
-
}
|
|
1269
|
-
const next = { ...state, ...NO_ROUTE, readGen: event.gen, drop: null, walletRead: null, blocked: null, walletGen: state.walletGen + 1 };
|
|
1270
|
-
return inFlight ? { ...next, pendingRefresh: true } : settle(next, false);
|
|
1271
|
-
}
|
|
1272
|
-
case "DROP_LOADED": {
|
|
1273
|
-
if (event.gen !== state.readGen) return state;
|
|
1274
|
-
const next = { ...state, drop: event.drop, now: Math.max(state.now, event.now) };
|
|
1275
|
-
if (inFlight) return { ...next, pendingRefresh: true };
|
|
1276
|
-
return isIdle(next) ? settle(clampQuantity(next), false) : clampQuantity(next);
|
|
1277
|
-
}
|
|
1278
|
-
case "DROP_UNSUPPORTED": {
|
|
1279
|
-
if (event.gen !== state.readGen) return state;
|
|
1280
|
-
if (inFlight) return { ...state, pendingRefresh: true };
|
|
1281
|
-
if (state.name === "success" || state.name === "error") return state;
|
|
1282
|
-
return { ...state, name: "unsupported", reason: event.reason, message: event.message };
|
|
1283
|
-
}
|
|
1284
|
-
case "READ_FAILED":
|
|
1285
|
-
return event.gen !== state.readGen ? state : failed(event.reason, event.message);
|
|
1286
|
-
case "ACCOUNT_CHANGED": {
|
|
1287
|
-
const next = { ...state, ...NO_ROUTE, account: event.account, walletRead: null, blocked: null, walletGen: state.walletGen + 1 };
|
|
1288
|
-
if (inFlight) return { ...next, pendingRefresh: true };
|
|
1289
|
-
if (state.name === "connecting") return event.account === null ? next : settle({ ...next, name: "loading" }, false);
|
|
1290
|
-
return settle(next);
|
|
1291
|
-
}
|
|
1292
|
-
case "WALLET_LOADED": {
|
|
1293
|
-
if (event.gen !== state.walletGen) return state;
|
|
1294
|
-
const route = event.routePending ? { routePending: state.route === null && state.short === null, route: state.route, short: state.short } : { routePending: false, route: null, short: null };
|
|
1295
|
-
const next = { ...state, ...route, crossChain: event.crossChain ?? false, walletRead: event.read, blocked: null };
|
|
1296
|
-
return inFlight ? { ...next, pendingRefresh: true } : settle(clampQuantity(next));
|
|
1297
|
-
}
|
|
1298
|
-
case "ROUTE_LOADED": {
|
|
1299
|
-
if (event.gen !== state.walletGen) return state;
|
|
1300
|
-
const next = { ...state, routePending: false, route: event.route, short: event.short };
|
|
1301
|
-
return inFlight ? { ...next, pendingRefresh: true } : settle(next);
|
|
1302
|
-
}
|
|
1303
|
-
case "WALLET_FAILED":
|
|
1304
|
-
return event.gen !== state.walletGen ? state : failed(event.reason, event.message);
|
|
1305
|
-
case "CONNECT_STARTED":
|
|
1306
|
-
return state.name === "disconnected" && state.attempt === null ? { ...state, name: "connecting", reason: null, message: null } : state;
|
|
1307
|
-
case "CONNECT_DISMISSED":
|
|
1308
|
-
return state.name === "connecting" ? settle({ ...state, name: "disconnected" }, false) : state;
|
|
1309
|
-
case "TICK":
|
|
1310
|
-
return settle({ ...state, now: Math.max(state.now, event.now) });
|
|
1311
|
-
case "SET_QUANTITY": {
|
|
1312
|
-
const next = { ...state, quantity: toQuantity(event.quantity, selectMaxQuantity(state) ?? MAX_QUANTITY) };
|
|
1313
|
-
return inFlight ? { ...next, pendingRefresh: true } : settle(next);
|
|
1314
|
-
}
|
|
1315
|
-
case "ATTEMPT_STARTED":
|
|
1316
|
-
if (state.attempt !== null) return state;
|
|
1317
|
-
if (event.resume === true) return IN_FLIGHT_STATES.includes(state.name) ? state : { ...state, attempt: event.attempt };
|
|
1318
|
-
return state.name === "live" ? { ...state, attempt: event.attempt } : state;
|
|
1319
|
-
case "SWITCHING_CHAIN":
|
|
1320
|
-
return step(state, event.attemptId, "switching-chain");
|
|
1321
|
-
case "APPROVING":
|
|
1322
|
-
return step(state, event.attemptId, "approving");
|
|
1323
|
-
case "MINT_PROMPTED":
|
|
1324
|
-
return step(state, event.attemptId, "minting");
|
|
1325
|
-
case "TX_SUBMITTED":
|
|
1326
|
-
return step(state, event.attemptId, "confirming");
|
|
1327
|
-
case "ATTEMPT_SUCCEEDED":
|
|
1328
|
-
return state.attempt?.attemptId === event.attemptId ? {
|
|
1329
|
-
...state,
|
|
1330
|
-
name: "success",
|
|
1331
|
-
reason: null,
|
|
1332
|
-
message: null,
|
|
1333
|
-
attempt: null,
|
|
1334
|
-
result: event.result,
|
|
1335
|
-
drop: null,
|
|
1336
|
-
readGen: state.readGen + 1
|
|
1337
|
-
} : state;
|
|
1338
|
-
case "ATTEMPT_FAILED": {
|
|
1339
|
-
if (state.attempt?.attemptId !== event.attemptId) return state;
|
|
1340
|
-
const { reason, message } = event;
|
|
1341
|
-
const done = { ...state, reason, message, attempt: null, result: null };
|
|
1342
|
-
if (INELIGIBLE_REASONS.includes(reason)) {
|
|
1343
|
-
return { ...done, name: "ineligible", blocked: { name: "ineligible", reason, message } };
|
|
1344
|
-
}
|
|
1345
|
-
if (reason === "INSUFFICIENT_FUNDS") {
|
|
1346
|
-
return { ...done, name: "insufficient-funds", blocked: { name: "insufficient-funds", reason, message } };
|
|
1347
|
-
}
|
|
1348
|
-
return {
|
|
1349
|
-
...done,
|
|
1350
|
-
name: "error",
|
|
1351
|
-
drop: state.name === "confirming" ? null : state.drop,
|
|
1352
|
-
readGen: state.name === "confirming" ? state.readGen + 1 : state.readGen
|
|
1353
|
-
};
|
|
1354
|
-
}
|
|
1355
|
-
case "RESET": {
|
|
1356
|
-
if (state.name !== "success" && state.name !== "error") return state;
|
|
1357
|
-
const next = {
|
|
1358
|
-
...state,
|
|
1359
|
-
readGen: event.gen,
|
|
1360
|
-
...NO_ROUTE,
|
|
1361
|
-
walletRead: null,
|
|
1362
|
-
blocked: null,
|
|
1363
|
-
walletGen: state.walletGen + 1,
|
|
1364
|
-
result: null,
|
|
1365
|
-
pendingRefresh: false
|
|
1366
|
-
};
|
|
1367
|
-
return settle(clampQuantity({ ...next, name: "loading" }), false);
|
|
1368
|
-
}
|
|
816
|
+
async function simulate(ctx, attempt, plan) {
|
|
817
|
+
throwIfAborted(ctx);
|
|
818
|
+
try {
|
|
819
|
+
await io(ctx, () => ctx.client.call({ account: attempt.payer, to: plan.mint.to, data: plan.mint.data, value: plan.mint.value }));
|
|
820
|
+
} catch (e) {
|
|
821
|
+
throw decodeTlRevert(e);
|
|
1369
822
|
}
|
|
1370
823
|
}
|
|
1371
|
-
var
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
return max;
|
|
1389
|
-
}
|
|
1390
|
-
function selectTotal(state) {
|
|
1391
|
-
const { drop } = state;
|
|
1392
|
-
if (drop === null) return null;
|
|
1393
|
-
const q = BigInt(state.quantity);
|
|
1394
|
-
const price = drop.unitPrice;
|
|
1395
|
-
const fee = drop.unitFee;
|
|
1396
|
-
const priceTotal = drop.pricePer === "total" ? price.value : price.value * q;
|
|
1397
|
-
if (drop.paymentToken !== null) {
|
|
1398
|
-
return {
|
|
1399
|
-
native: money2(fee.value * q, fee),
|
|
1400
|
-
erc20: money2(priceTotal, price)
|
|
1401
|
-
};
|
|
824
|
+
var tlStacksAdapter = { readDrop, readWallet, buildPlan, simulate };
|
|
825
|
+
|
|
826
|
+
// src/core/relay/outstanding.ts
|
|
827
|
+
var memory = /* @__PURE__ */ new Map();
|
|
828
|
+
var claimed = /* @__PURE__ */ new Set();
|
|
829
|
+
function targetOf(config) {
|
|
830
|
+
switch (config.type) {
|
|
831
|
+
case "manifold-claim":
|
|
832
|
+
return `${config.creatorContract.toLowerCase()}:${config.instanceId}`;
|
|
833
|
+
case "contract":
|
|
834
|
+
return config.address.toLowerCase();
|
|
835
|
+
case "tl-stacks":
|
|
836
|
+
return `stacks:${config.nftContract.toLowerCase()}`;
|
|
837
|
+
default: {
|
|
838
|
+
const unreachable = config;
|
|
839
|
+
return unreachable;
|
|
840
|
+
}
|
|
1402
841
|
}
|
|
1403
|
-
return { native: money2(priceTotal + fee.value * q, price), erc20: null };
|
|
1404
842
|
}
|
|
1405
|
-
function
|
|
1406
|
-
return {
|
|
843
|
+
function outstandingKey(config, payer) {
|
|
844
|
+
return `${String(config.chainId)}:${targetOf(config)}:${payer.toLowerCase()}`;
|
|
1407
845
|
}
|
|
1408
|
-
|
|
1409
|
-
|
|
846
|
+
var getOutstanding = (key) => _nullishCoalesce(memory.get(key), () => ( null));
|
|
847
|
+
var setOutstanding = (key, out) => void memory.set(key, out);
|
|
848
|
+
var clearOutstanding = (key) => void memory.delete(key);
|
|
849
|
+
function claimDeposit(key) {
|
|
850
|
+
if (claimed.has(key) || memory.has(key)) return false;
|
|
851
|
+
claimed.add(key);
|
|
852
|
+
return true;
|
|
1410
853
|
}
|
|
854
|
+
var releaseDeposit = (key) => void claimed.delete(key);
|
|
1411
855
|
|
|
1412
856
|
// src/core/adapters/contract/index.ts
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
|
|
1413
870
|
var PLACEHOLDERS = ["{recipient}", "{payer}", "{quantity}", "{unitPrice}", "{totalPrice}"];
|
|
1414
|
-
var
|
|
871
|
+
var ERC20_ABI = _viem.parseAbi.call(void 0, [
|
|
1415
872
|
"function symbol() view returns (string)",
|
|
1416
873
|
"function decimals() view returns (uint8)",
|
|
1417
874
|
"function balanceOf(address) view returns (uint256)",
|
|
@@ -1423,32 +880,32 @@ var APPROVE_GAS = 65000n;
|
|
|
1423
880
|
var PLACEHOLDER_TOKEN = /\{[A-Za-z_]\w*\}/g;
|
|
1424
881
|
var DISPLAY_AMOUNT = /^\d+(\.\d+)?$/;
|
|
1425
882
|
var NUMERIC_TYPE = /^u?int\d*$/;
|
|
1426
|
-
function
|
|
1427
|
-
throw new MintError("INVALID_CONFIG", `${field} ${message}`, { field });
|
|
883
|
+
function bad2(field, message) {
|
|
884
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("INVALID_CONFIG", `${field} ${message}`, { field });
|
|
1428
885
|
}
|
|
1429
|
-
var isHexAddress = (a) => typeof a === "string" && (0,
|
|
886
|
+
var isHexAddress = (a) => typeof a === "string" && _viem.isAddress.call(void 0, a, { strict: false });
|
|
1430
887
|
function functionsNamed(abi, name) {
|
|
1431
888
|
return abi.filter((i) => i.type === "function" && i.name === name);
|
|
1432
889
|
}
|
|
1433
890
|
function validateTemplate(t, path, allowed) {
|
|
1434
891
|
if (typeof t === "string") {
|
|
1435
|
-
for (const token of t.match(PLACEHOLDER_TOKEN)
|
|
1436
|
-
if (!PLACEHOLDERS.includes(token))
|
|
1437
|
-
if (!allowed.includes(token))
|
|
892
|
+
for (const token of _nullishCoalesce(t.match(PLACEHOLDER_TOKEN), () => ( []))) {
|
|
893
|
+
if (!PLACEHOLDERS.includes(token)) bad2(path, `"${t}" is not a known placeholder (${token})`);
|
|
894
|
+
if (!allowed.includes(token)) bad2(path, `"${t}" uses ${token}, which is not available in this field`);
|
|
1438
895
|
}
|
|
1439
896
|
} else if (Array.isArray(t)) {
|
|
1440
897
|
t.forEach((x, i) => validateTemplate(x, `${path}[${i}]`, allowed));
|
|
1441
898
|
} else if (typeof t === "number") {
|
|
1442
|
-
if (!Number.isSafeInteger(t))
|
|
899
|
+
if (!Number.isSafeInteger(t)) bad2(path, `${t} is not a safe integer; pass larger or fractional values as a bigint or decimal string`);
|
|
1443
900
|
} else if (typeof t !== "bigint" && typeof t !== "boolean") {
|
|
1444
|
-
|
|
901
|
+
bad2(path, "must be a string, number, bigint, boolean or array");
|
|
1445
902
|
}
|
|
1446
903
|
}
|
|
1447
904
|
var ARRAY_TYPE = /^(.*)\[(\d*)\]$/;
|
|
1448
905
|
var BYTES_TYPE = /^bytes(\d*)$/;
|
|
1449
906
|
var INT_TYPE = /^(u?)int(\d*)$/;
|
|
1450
907
|
var isExactPlaceholder = (t) => typeof t === "string" && PLACEHOLDERS.includes(t);
|
|
1451
|
-
var hasPlaceholder = (t) => typeof t === "string" && (t.match(PLACEHOLDER_TOKEN)
|
|
908
|
+
var hasPlaceholder = (t) => typeof t === "string" && (_nullishCoalesce(t.match(PLACEHOLDER_TOKEN), () => ( []))).length > 0;
|
|
1452
909
|
function intBounds(type) {
|
|
1453
910
|
const m = INT_TYPE.exec(type);
|
|
1454
911
|
if (!m) return null;
|
|
@@ -1456,7 +913,7 @@ function intBounds(type) {
|
|
|
1456
913
|
return m[1] ? { min: 0n, max: 2n ** bits - 1n } : { min: -(2n ** (bits - 1n)), max: 2n ** (bits - 1n) - 1n };
|
|
1457
914
|
}
|
|
1458
915
|
var elementParam = (p, type) => ({ ...p, type });
|
|
1459
|
-
var componentsOf = (p) => p.components
|
|
916
|
+
var componentsOf = (p) => _nullishCoalesce(p.components, () => ( []));
|
|
1460
917
|
function typeIssue(t, p, path) {
|
|
1461
918
|
const no = (message) => ({ path, message });
|
|
1462
919
|
const arr = ARRAY_TYPE.exec(p.type);
|
|
@@ -1483,7 +940,7 @@ function typeIssue(t, p, path) {
|
|
|
1483
940
|
if (Array.isArray(t)) return no(`must not be an array for ${p.type}`);
|
|
1484
941
|
if (p.type === "address") {
|
|
1485
942
|
if (isExactPlaceholder(t)) return t === "{recipient}" || t === "{payer}" ? null : no(`${t} is a number, but the abi input is an address`);
|
|
1486
|
-
return typeof t === "string" && !hasPlaceholder(t) && (0,
|
|
943
|
+
return typeof t === "string" && !hasPlaceholder(t) && _viem.isAddress.call(void 0, t) ? null : no(`${JSON.stringify(String(t))} is not an address`);
|
|
1487
944
|
}
|
|
1488
945
|
if (p.type === "bool") return typeof t === "boolean" ? null : no(`${JSON.stringify(String(t))} is not a boolean`);
|
|
1489
946
|
if (p.type === "string") return typeof t === "string" ? null : no(`${JSON.stringify(String(t))} is not a string`);
|
|
@@ -1507,17 +964,17 @@ function typeIssue(t, p, path) {
|
|
|
1507
964
|
var signature = (f) => `${f.name}(${f.inputs.map((i) => i.type).join(",")})`;
|
|
1508
965
|
var NO_PLACEHOLDERS = [];
|
|
1509
966
|
function validateCall(abi, call, prefix, kind, allowed) {
|
|
1510
|
-
const c = call
|
|
967
|
+
const c = _nullishCoalesce(call, () => ( {}));
|
|
1511
968
|
const named = typeof c.functionName === "string" ? functionsNamed(abi, c.functionName) : [];
|
|
1512
|
-
if (named.length === 0)
|
|
1513
|
-
if (c.args !== void 0 && !Array.isArray(c.args))
|
|
1514
|
-
if (kind === "mint" && c.args === void 0)
|
|
1515
|
-
const args = c.args
|
|
969
|
+
if (named.length === 0) bad2(`${prefix}.functionName`, `"${String(c.functionName)}" is not a function in the abi`);
|
|
970
|
+
if (c.args !== void 0 && !Array.isArray(c.args)) bad2(`${prefix}.args`, "must be an array");
|
|
971
|
+
if (kind === "mint" && c.args === void 0) bad2(`${prefix}.args`, "is required");
|
|
972
|
+
const args = _nullishCoalesce(c.args, () => ( []));
|
|
1516
973
|
args.forEach((a, i) => validateTemplate(a, `${prefix}.args[${i}]`, allowed));
|
|
1517
974
|
const sameArity = named.filter((f) => f.inputs.length === args.length);
|
|
1518
975
|
if (sameArity.length === 0) {
|
|
1519
976
|
const want = [...new Set(named.map((f) => f.inputs.length))].join(" or ");
|
|
1520
|
-
|
|
977
|
+
bad2(`${prefix}.args`, `has ${args.length} argument(s) but "${String(c.functionName)}" takes ${want}`);
|
|
1521
978
|
}
|
|
1522
979
|
const checked = sameArity.map((f) => {
|
|
1523
980
|
let issue = null;
|
|
@@ -1527,75 +984,75 @@ function validateCall(abi, call, prefix, kind, allowed) {
|
|
|
1527
984
|
const fits = checked.filter((x) => !x.issue);
|
|
1528
985
|
if (fits.length === 0) {
|
|
1529
986
|
const first = checked[0].issue;
|
|
1530
|
-
if (sameArity.length === 1)
|
|
1531
|
-
|
|
987
|
+
if (sameArity.length === 1) bad2(first.path, first.message);
|
|
988
|
+
bad2(`${prefix}.args`, `fit none of the overloads ${sameArity.map(signature).join(", ")}: ${first.path} ${first.message}`);
|
|
1532
989
|
}
|
|
1533
990
|
const roleFits = fits.filter(
|
|
1534
991
|
({ f }) => kind === "read" ? f.stateMutability === "view" || f.stateMutability === "pure" : f.stateMutability === "payable" || f.stateMutability === "nonpayable"
|
|
1535
992
|
);
|
|
1536
993
|
if (roleFits.length === 0) {
|
|
1537
994
|
const name = fits[0].f.name;
|
|
1538
|
-
if (kind === "read")
|
|
995
|
+
if (kind === "read") bad2(`${prefix}.functionName`, `"${name}" is not a view or pure function`);
|
|
1539
996
|
if (fits.some(({ f }) => f.stateMutability !== "view" && f.stateMutability !== "pure")) {
|
|
1540
|
-
|
|
997
|
+
bad2(`${prefix}.functionName`, `"${name}" has missing or invalid stateMutability; mint requires payable or nonpayable`);
|
|
1541
998
|
}
|
|
1542
|
-
|
|
999
|
+
bad2(`${prefix}.functionName`, `"${name}" is a view or pure function and cannot mint`);
|
|
1543
1000
|
}
|
|
1544
1001
|
if (roleFits.length > 1) {
|
|
1545
|
-
|
|
1002
|
+
bad2(`${prefix}.functionName`, `"${String(c.functionName)}" is ambiguous: ${roleFits.map((x) => signature(x.f)).join(" and ")} both accept these arguments`);
|
|
1546
1003
|
}
|
|
1547
1004
|
return roleFits[0].f;
|
|
1548
1005
|
}
|
|
1549
1006
|
function resolveOutput(fn, output, path) {
|
|
1550
1007
|
const outs = fn.outputs;
|
|
1551
|
-
if (outs.length === 0)
|
|
1008
|
+
if (outs.length === 0) bad2(`${path}.functionName`, `"${fn.name}" returns nothing`);
|
|
1552
1009
|
const first = outs[0];
|
|
1553
1010
|
const tuple = outs.length === 1 && first.type === "tuple";
|
|
1554
|
-
const members = tuple ? first.components
|
|
1011
|
+
const members = tuple ? _nullishCoalesce(first.components, () => ( [])) : outs;
|
|
1555
1012
|
const memberNames = members.map((m, i) => m.name || String(i)).join(", ");
|
|
1556
1013
|
let index;
|
|
1557
1014
|
if (output === void 0) {
|
|
1558
|
-
if (members.length !== 1)
|
|
1015
|
+
if (members.length !== 1) bad2(`${path}.output`, `is required: "${fn.name}" returns several values (${memberNames})`);
|
|
1559
1016
|
index = 0;
|
|
1560
1017
|
} else if (typeof output === "number") {
|
|
1561
1018
|
if (!Number.isInteger(output) || output < 0 || output >= members.length) {
|
|
1562
|
-
|
|
1019
|
+
bad2(`${path}.output`, `${output} is not in the abi outputs of "${fn.name}" (${memberNames})`);
|
|
1563
1020
|
}
|
|
1564
1021
|
index = output;
|
|
1565
1022
|
} else if (typeof output === "string") {
|
|
1566
1023
|
index = members.findIndex((m) => m.name === output);
|
|
1567
|
-
if (index < 0)
|
|
1024
|
+
if (index < 0) bad2(`${path}.output`, `"${output}" is not in the abi outputs of "${fn.name}" (${memberNames})`);
|
|
1568
1025
|
} else {
|
|
1569
|
-
return
|
|
1026
|
+
return bad2(`${path}.output`, "must be an index or a name");
|
|
1570
1027
|
}
|
|
1571
1028
|
const type = members[index].type;
|
|
1572
1029
|
if (!NUMERIC_TYPE.test(type)) {
|
|
1573
1030
|
const reason = `returns ${type}, not a number`;
|
|
1574
|
-
if (output === void 0)
|
|
1575
|
-
|
|
1031
|
+
if (output === void 0) bad2(`${path}.functionName`, `"${fn.name}" ${reason}`);
|
|
1032
|
+
bad2(`${path}.output`, `selects a value that is ${type}, not a number`);
|
|
1576
1033
|
}
|
|
1577
1034
|
return { tuple, index, type };
|
|
1578
1035
|
}
|
|
1579
1036
|
function validateField(abi, name, src, allowed, isPrice) {
|
|
1580
|
-
if (typeof src !== "object" || src === null)
|
|
1037
|
+
if (typeof src !== "object" || src === null) bad2(name, "is required and must be { value } or { read }");
|
|
1581
1038
|
const s = src;
|
|
1582
1039
|
const hasRead = Object.hasOwn(s, "read");
|
|
1583
1040
|
const hasValue = Object.hasOwn(s, "value");
|
|
1584
|
-
if (hasRead && hasValue)
|
|
1041
|
+
if (hasRead && hasValue) bad2(name, "must be exactly one of { value } or { read }, not both");
|
|
1585
1042
|
if (hasRead) {
|
|
1586
|
-
if (typeof s.read !== "object" || s.read === null)
|
|
1587
|
-
if (s.unit !== void 0)
|
|
1043
|
+
if (typeof s.read !== "object" || s.read === null) bad2(`${name}.read`, "must be { functionName, args?, output? }");
|
|
1044
|
+
if (s.unit !== void 0) bad2(name, "unit is only valid with a string value");
|
|
1588
1045
|
const fn = validateCall(abi, s.read, `${name}.read`, "read", allowed);
|
|
1589
1046
|
resolveOutput(fn, s.read.output, `${name}.read`);
|
|
1590
1047
|
} else if (typeof s.value === "bigint") {
|
|
1591
|
-
if (s.unit !== void 0)
|
|
1592
|
-
if (s.value < 0n)
|
|
1048
|
+
if (s.unit !== void 0) bad2(name, "unit is only valid with a string value");
|
|
1049
|
+
if (s.value < 0n) bad2(`${name}.value`, "must not be negative");
|
|
1593
1050
|
} else if (typeof s.value === "string") {
|
|
1594
|
-
if (s.unit !== "display")
|
|
1595
|
-
if (!isPrice)
|
|
1596
|
-
if (!DISPLAY_AMOUNT.test(s.value))
|
|
1051
|
+
if (s.unit !== "display") bad2(name, 'string values need unit: "display"');
|
|
1052
|
+
if (!isPrice) bad2(name, "display units are only valid for price; use a bigint in base units");
|
|
1053
|
+
if (!DISPLAY_AMOUNT.test(s.value)) bad2(`${name}.value`, `"${s.value}" is not a decimal number like "0.01"`);
|
|
1597
1054
|
} else {
|
|
1598
|
-
|
|
1055
|
+
bad2(name, 'must be { value: bigint }, { value: string, unit: "display" } (price only) or { read: {...} }');
|
|
1599
1056
|
}
|
|
1600
1057
|
}
|
|
1601
1058
|
function hasNonzeroStaticPrice(price) {
|
|
@@ -1605,27 +1062,27 @@ function hasNonzeroStaticPrice(price) {
|
|
|
1605
1062
|
}
|
|
1606
1063
|
function validateContractConfig(config) {
|
|
1607
1064
|
const c = config;
|
|
1608
|
-
if (!c || typeof c !== "object")
|
|
1609
|
-
if (c.type !== "contract")
|
|
1610
|
-
if (!Number.isSafeInteger(c.chainId) || c.chainId <= 0)
|
|
1611
|
-
if (!isHexAddress(c.address))
|
|
1065
|
+
if (!c || typeof c !== "object") bad2("config", "must be an object");
|
|
1066
|
+
if (c.type !== "contract") bad2("type", 'must be "contract"');
|
|
1067
|
+
if (!Number.isSafeInteger(c.chainId) || c.chainId <= 0) bad2("chainId", "must be a positive safe integer");
|
|
1068
|
+
if (!isHexAddress(c.address)) bad2("address", `"${String(c.address)}" is not a valid address`);
|
|
1612
1069
|
if (c.tokenContract !== void 0 && !isHexAddress(c.tokenContract)) {
|
|
1613
|
-
|
|
1070
|
+
bad2("tokenContract", `"${String(c.tokenContract)}" is not a valid address`);
|
|
1614
1071
|
}
|
|
1615
|
-
if (!Array.isArray(c.abi))
|
|
1072
|
+
if (!Array.isArray(c.abi)) bad2("abi", "must be an abi array");
|
|
1616
1073
|
const abi = c.abi;
|
|
1617
1074
|
const mintFn = validateCall(abi, c.mint, "mint", "mint", PLACEHOLDERS);
|
|
1618
|
-
if (c.price === void 0 || c.price === null)
|
|
1075
|
+
if (c.price === void 0 || c.price === null) bad2("price", "is required");
|
|
1619
1076
|
validateField(abi, "price", c.price, NO_PLACEHOLDERS, true);
|
|
1620
1077
|
const cur = c.price.currency;
|
|
1621
1078
|
if (cur !== "native" && !(typeof cur === "object" && cur !== null && isHexAddress(cur.address))) {
|
|
1622
|
-
|
|
1079
|
+
bad2("price.currency", 'must be "native" or { address } with a valid ERC20 address');
|
|
1623
1080
|
}
|
|
1624
1081
|
if (cur === "native" && mintFn.stateMutability === "nonpayable" && hasNonzeroStaticPrice(c.price)) {
|
|
1625
|
-
|
|
1082
|
+
bad2("price", `is a native price, but "${mintFn.name}" is nonpayable and cannot take value`);
|
|
1626
1083
|
}
|
|
1627
1084
|
const per = c.price.per;
|
|
1628
|
-
if (per !== void 0 && per !== "unit" && per !== "total")
|
|
1085
|
+
if (per !== void 0 && per !== "unit" && per !== "total") bad2("price.per", 'must be "unit" or "total"');
|
|
1629
1086
|
validateOptional(abi, "totalMinted", c.totalMinted, NO_PLACEHOLDERS);
|
|
1630
1087
|
validateOptional(abi, "maxSupply", c.maxSupply, NO_PLACEHOLDERS);
|
|
1631
1088
|
validateOptional(abi, "startTime", c.startTime, NO_PLACEHOLDERS);
|
|
@@ -1639,8 +1096,8 @@ function validateOptional(abi, name, src, allowed) {
|
|
|
1639
1096
|
function varFor(token, vars) {
|
|
1640
1097
|
const key = token.slice(1, -1);
|
|
1641
1098
|
const v = vars[key];
|
|
1642
|
-
if (v === void 0) throw new MintError("INVALID_CONFIG", `placeholder ${token} has no value here`);
|
|
1643
|
-
return typeof v === "string" ? (0,
|
|
1099
|
+
if (v === void 0) throw new (0, _chunkGO4TR3HBcjs.MintError)("INVALID_CONFIG", `placeholder ${token} has no value here`);
|
|
1100
|
+
return typeof v === "string" ? _viem.getAddress.call(void 0, v) : v;
|
|
1644
1101
|
}
|
|
1645
1102
|
function fill(t, p, vars) {
|
|
1646
1103
|
const arr = ARRAY_TYPE.exec(p.type);
|
|
@@ -1653,48 +1110,48 @@ function fill(t, p, vars) {
|
|
|
1653
1110
|
if (intBounds(p.type)) return BigInt(t);
|
|
1654
1111
|
return t;
|
|
1655
1112
|
}
|
|
1656
|
-
var fillArgs = (args, inputs, vars) => (args
|
|
1113
|
+
var fillArgs = (args, inputs, vars) => (_nullishCoalesce(args, () => ( []))).map((a, i) => fill(a, inputs[i], vars));
|
|
1657
1114
|
var totalFor = (per, price, quantity) => per === "total" ? price : price * quantity;
|
|
1658
|
-
function
|
|
1659
|
-
return e instanceof
|
|
1115
|
+
function shortMessage2(e) {
|
|
1116
|
+
return e instanceof _viem.BaseError ? e.shortMessage : e instanceof Error ? e.message : String(e);
|
|
1660
1117
|
}
|
|
1661
|
-
var
|
|
1662
|
-
var
|
|
1663
|
-
function
|
|
1664
|
-
if (ctx.signal
|
|
1118
|
+
var abortError2 = () => new DOMException("The operation was aborted", "AbortError");
|
|
1119
|
+
var isAbortError2 = (e) => _optionalChain([e, 'optionalAccess', _30 => _30.name]) === "AbortError";
|
|
1120
|
+
function throwIfAborted2(ctx) {
|
|
1121
|
+
if (_optionalChain([ctx, 'access', _31 => _31.signal, 'optionalAccess', _32 => _32.aborted])) throw abortError2();
|
|
1665
1122
|
}
|
|
1666
|
-
function
|
|
1123
|
+
function io2(ctx, start) {
|
|
1667
1124
|
const signal = ctx.signal;
|
|
1668
1125
|
if (!signal) return start();
|
|
1669
|
-
if (signal.aborted) return Promise.reject(
|
|
1126
|
+
if (signal.aborted) return Promise.reject(abortError2());
|
|
1670
1127
|
return new Promise((resolve, reject) => {
|
|
1671
|
-
const onAbort = () => reject(
|
|
1128
|
+
const onAbort = () => reject(abortError2());
|
|
1672
1129
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
1673
1130
|
start().then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
1674
1131
|
});
|
|
1675
1132
|
}
|
|
1676
|
-
function
|
|
1677
|
-
if (isMintError(e) ||
|
|
1678
|
-
throw new MintError("RPC_ERROR", `RPC request failed: ${
|
|
1133
|
+
function rpcError2(e) {
|
|
1134
|
+
if (_chunkGO4TR3HBcjs.isMintError.call(void 0, e) || isAbortError2(e)) throw e;
|
|
1135
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("RPC_ERROR", `RPC request failed: ${shortMessage2(e)}`, { cause: e });
|
|
1679
1136
|
}
|
|
1680
1137
|
function classifyReadError(e, field) {
|
|
1681
|
-
if (isMintError(e) ||
|
|
1682
|
-
if (e instanceof
|
|
1683
|
-
throw new MintError("INVALID_CONFIG", `${field} read reverted or returned no data: ${e.shortMessage}`, { field, cause: e });
|
|
1138
|
+
if (_chunkGO4TR3HBcjs.isMintError.call(void 0, e) || isAbortError2(e)) throw e;
|
|
1139
|
+
if (e instanceof _viem.BaseError && e.walk((x) => x instanceof _viem.ContractFunctionRevertedError || x instanceof _viem.ContractFunctionZeroDataError)) {
|
|
1140
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("INVALID_CONFIG", `${field} read reverted or returned no data: ${e.shortMessage}`, { field, cause: e });
|
|
1684
1141
|
}
|
|
1685
|
-
return
|
|
1142
|
+
return rpcError2(e);
|
|
1686
1143
|
}
|
|
1687
1144
|
async function readCall(ctx, params, field) {
|
|
1688
1145
|
try {
|
|
1689
|
-
return await
|
|
1146
|
+
return await io2(ctx, () => ctx.client.readContract(params));
|
|
1690
1147
|
} catch (e) {
|
|
1691
1148
|
return classifyReadError(e, field);
|
|
1692
1149
|
}
|
|
1693
1150
|
}
|
|
1694
1151
|
function toBigInt(v, field) {
|
|
1695
1152
|
const n = typeof v === "number" ? BigInt(v) : v;
|
|
1696
|
-
if (typeof n !== "bigint") throw new MintError("INVALID_CONFIG", `${field} did not return a number`, { field });
|
|
1697
|
-
if (n < 0n) throw new MintError("INVALID_CONFIG", `${field} returned a negative number`, { field });
|
|
1153
|
+
if (typeof n !== "bigint") throw new (0, _chunkGO4TR3HBcjs.MintError)("INVALID_CONFIG", `${field} did not return a number`, { field });
|
|
1154
|
+
if (n < 0n) throw new (0, _chunkGO4TR3HBcjs.MintError)("INVALID_CONFIG", `${field} returned a negative number`, { field });
|
|
1698
1155
|
return n;
|
|
1699
1156
|
}
|
|
1700
1157
|
async function readField(ctx, config, name, src, vars) {
|
|
@@ -1710,58 +1167,58 @@ async function readField(ctx, config, name, src, vars) {
|
|
|
1710
1167
|
}
|
|
1711
1168
|
const value = src.value;
|
|
1712
1169
|
if (typeof value === "bigint") return value;
|
|
1713
|
-
throw new MintError("INVALID_CONFIG", `${name} display units are only valid for price`, { field: name });
|
|
1170
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("INVALID_CONFIG", `${name} display units are only valid for price`, { field: name });
|
|
1714
1171
|
}
|
|
1715
1172
|
function tupleMembers(res, fn, index) {
|
|
1716
1173
|
if (Array.isArray(res)) return res;
|
|
1717
|
-
const comps = fn.outputs[0].components
|
|
1174
|
+
const comps = _nullishCoalesce(fn.outputs[0].components, () => ( []));
|
|
1718
1175
|
const out = [];
|
|
1719
|
-
out[index] = res[comps[index]
|
|
1176
|
+
out[index] = res[_nullishCoalesce(_optionalChain([comps, 'access', _33 => _33[index], 'optionalAccess', _34 => _34.name]), () => ( ""))];
|
|
1720
1177
|
return out;
|
|
1721
1178
|
}
|
|
1722
1179
|
var optField = (ctx, config, name, src, vars) => src ? readField(ctx, config, name, src, vars) : Promise.resolve(null);
|
|
1723
1180
|
function toSeconds(v, field) {
|
|
1724
1181
|
if (v === null || v === 0n) return null;
|
|
1725
|
-
if (v > BigInt(Number.MAX_SAFE_INTEGER)) throw new MintError("INVALID_CONFIG", `${field} is too large for a unix timestamp`, { field });
|
|
1182
|
+
if (v > BigInt(Number.MAX_SAFE_INTEGER)) throw new (0, _chunkGO4TR3HBcjs.MintError)("INVALID_CONFIG", `${field} is too large for a unix timestamp`, { field });
|
|
1726
1183
|
return Number(v);
|
|
1727
1184
|
}
|
|
1728
|
-
function
|
|
1729
|
-
const n = ctx.client.chain
|
|
1730
|
-
return { decimals: n
|
|
1185
|
+
function nativeMeta2(ctx) {
|
|
1186
|
+
const n = _optionalChain([ctx, 'access', _35 => _35.client, 'access', _36 => _36.chain, 'optionalAccess', _37 => _37.nativeCurrency]);
|
|
1187
|
+
return { decimals: _nullishCoalesce(_optionalChain([n, 'optionalAccess', _38 => _38.decimals]), () => ( 18)), symbol: _nullishCoalesce(_optionalChain([n, 'optionalAccess', _39 => _39.symbol]), () => ( "ETH")) };
|
|
1731
1188
|
}
|
|
1732
|
-
var erc20Of = (config) => config.price.currency === "native" ? null : (0,
|
|
1189
|
+
var erc20Of = (config) => config.price.currency === "native" ? null : _viem.getAddress.call(void 0, config.price.currency.address);
|
|
1733
1190
|
async function currencyMeta(ctx, config) {
|
|
1734
1191
|
const token = erc20Of(config);
|
|
1735
|
-
if (!token) return { token, ...
|
|
1192
|
+
if (!token) return { token, ...nativeMeta2(ctx) };
|
|
1736
1193
|
const field = "price.currency.address";
|
|
1737
1194
|
const [symbol, decimals] = await Promise.all([
|
|
1738
|
-
readCall(ctx, { address: token, abi:
|
|
1739
|
-
readCall(ctx, { address: token, abi:
|
|
1195
|
+
readCall(ctx, { address: token, abi: ERC20_ABI, functionName: "symbol" }, field),
|
|
1196
|
+
readCall(ctx, { address: token, abi: ERC20_ABI, functionName: "decimals" }, field)
|
|
1740
1197
|
]);
|
|
1741
1198
|
if (typeof symbol !== "string" || typeof decimals !== "number") {
|
|
1742
|
-
throw new MintError("INVALID_CONFIG", `${field} ${token} is not an ERC20 (symbol/decimals unreadable)`, { field });
|
|
1199
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("INVALID_CONFIG", `${field} ${token} is not an ERC20 (symbol/decimals unreadable)`, { field });
|
|
1743
1200
|
}
|
|
1744
1201
|
return { token, decimals, symbol };
|
|
1745
1202
|
}
|
|
1746
1203
|
function parseDisplay(value, decimals) {
|
|
1747
|
-
const frac = value.split(".")[1]
|
|
1204
|
+
const frac = _nullishCoalesce(value.split(".")[1], () => ( ""));
|
|
1748
1205
|
if (frac.length > decimals) {
|
|
1749
|
-
throw new MintError("INVALID_CONFIG", `price.value "${value}" has more than ${decimals} decimal places`, { field: "price.value" });
|
|
1206
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("INVALID_CONFIG", `price.value "${value}" has more than ${decimals} decimal places`, { field: "price.value" });
|
|
1750
1207
|
}
|
|
1751
|
-
return (0,
|
|
1208
|
+
return _viem.parseUnits.call(void 0, value, decimals);
|
|
1752
1209
|
}
|
|
1753
1210
|
async function resolvePrice(ctx, config, meta) {
|
|
1754
1211
|
const price = config.price;
|
|
1755
1212
|
if (Object.hasOwn(price, "read")) return readField(ctx, config, "price", price, {});
|
|
1756
1213
|
const value = price.value;
|
|
1757
1214
|
if (typeof value === "bigint") return value;
|
|
1758
|
-
return parseDisplay(value, (meta
|
|
1215
|
+
return parseDisplay(value, (await _asyncNullishCoalesce(meta, async () => ( await currencyMeta(ctx, config)))).decimals);
|
|
1759
1216
|
}
|
|
1760
|
-
var
|
|
1217
|
+
var money2 = (value, decimals, symbol) => ({
|
|
1761
1218
|
value,
|
|
1762
1219
|
decimals,
|
|
1763
1220
|
symbol,
|
|
1764
|
-
formatted: (0,
|
|
1221
|
+
formatted: _viem.formatUnits.call(void 0, value, decimals)
|
|
1765
1222
|
});
|
|
1766
1223
|
function revertData2(e) {
|
|
1767
1224
|
for (let cur = e, depth = 0; cur && depth < 12; depth++) {
|
|
@@ -1777,31 +1234,31 @@ function revertData2(e) {
|
|
|
1777
1234
|
}
|
|
1778
1235
|
function describeRevert(abi, data) {
|
|
1779
1236
|
try {
|
|
1780
|
-
const d = (0,
|
|
1781
|
-
const args = d.args
|
|
1782
|
-
if (d.errorName === "Error") return String(args[0]
|
|
1783
|
-
const inputs = d.abiItem
|
|
1784
|
-
const shown = args.map((a, i) => inputs[i]
|
|
1237
|
+
const d = _viem.decodeErrorResult.call(void 0, { abi, data });
|
|
1238
|
+
const args = _nullishCoalesce(d.args, () => ( []));
|
|
1239
|
+
if (d.errorName === "Error") return String(_nullishCoalesce(args[0], () => ( "execution reverted")));
|
|
1240
|
+
const inputs = _nullishCoalesce(_optionalChain([d, 'access', _40 => _40.abiItem, 'optionalAccess', _41 => _41.inputs]), () => ( []));
|
|
1241
|
+
const shown = args.map((a, i) => _optionalChain([inputs, 'access', _42 => _42[i], 'optionalAccess', _43 => _43.name]) ? `${inputs[i].name}: ${String(a)}` : String(a));
|
|
1785
1242
|
return `${d.errorName}(${shown.join(", ")})`;
|
|
1786
|
-
} catch {
|
|
1243
|
+
} catch (e4) {
|
|
1787
1244
|
return `reverted with unrecognized error ${data.slice(0, 10)}`;
|
|
1788
1245
|
}
|
|
1789
1246
|
}
|
|
1790
1247
|
function toSimulationError(e, abi) {
|
|
1791
|
-
if (isMintError(e)) return e;
|
|
1792
|
-
if (
|
|
1793
|
-
if (e instanceof
|
|
1794
|
-
return new MintError("INSUFFICIENT_FUNDS", `Payer cannot cover the mint: ${e.shortMessage}`, { cause: e });
|
|
1248
|
+
if (_chunkGO4TR3HBcjs.isMintError.call(void 0, e)) return e;
|
|
1249
|
+
if (isAbortError2(e)) throw e;
|
|
1250
|
+
if (e instanceof _viem.BaseError && e.walk((x) => x instanceof _viem.InsufficientFundsError)) {
|
|
1251
|
+
return new (0, _chunkGO4TR3HBcjs.MintError)("INSUFFICIENT_FUNDS", `Payer cannot cover the mint: ${e.shortMessage}`, { cause: e });
|
|
1795
1252
|
}
|
|
1796
1253
|
const data = revertData2(e);
|
|
1797
|
-
if (data) return new MintError("SIMULATION_REVERTED", describeRevert(abi, data), { cause: e });
|
|
1798
|
-
const isRevert = e instanceof
|
|
1799
|
-
if (isRevert) return new MintError("SIMULATION_REVERTED",
|
|
1800
|
-
return new MintError("RPC_ERROR", `RPC request failed: ${
|
|
1254
|
+
if (data) return new (0, _chunkGO4TR3HBcjs.MintError)("SIMULATION_REVERTED", describeRevert(abi, data), { cause: e });
|
|
1255
|
+
const isRevert = e instanceof _viem.BaseError && e.walk((x) => x.code === 3 || /execution reverted/i.test(x.message));
|
|
1256
|
+
if (isRevert) return new (0, _chunkGO4TR3HBcjs.MintError)("SIMULATION_REVERTED", shortMessage2(e), { cause: e });
|
|
1257
|
+
return new (0, _chunkGO4TR3HBcjs.MintError)("RPC_ERROR", `RPC request failed: ${shortMessage2(e)}`, { cause: e });
|
|
1801
1258
|
}
|
|
1802
1259
|
async function simulateMint(ctx, config, call) {
|
|
1803
1260
|
try {
|
|
1804
|
-
await
|
|
1261
|
+
await io2(ctx, () => ctx.client.call({ account: call.payer, to: call.to, data: call.data, value: call.value }));
|
|
1805
1262
|
} catch (e) {
|
|
1806
1263
|
throw toSimulationError(e, config.abi);
|
|
1807
1264
|
}
|
|
@@ -1809,24 +1266,24 @@ async function simulateMint(ctx, config, call) {
|
|
|
1809
1266
|
function encodeMint(config, vars) {
|
|
1810
1267
|
const fn = validateCall(config.abi, config.mint, "mint", "mint", PLACEHOLDERS);
|
|
1811
1268
|
try {
|
|
1812
|
-
return (0,
|
|
1269
|
+
return _viem.encodeFunctionData.call(void 0, { abi: [fn], functionName: fn.name, args: fillArgs(config.mint.args, fn.inputs, vars) });
|
|
1813
1270
|
} catch (e) {
|
|
1814
|
-
if (isMintError(e)) throw e;
|
|
1815
|
-
throw new MintError("INVALID_CONFIG", `mint.args cannot be encoded for ${signature(fn)}: ${
|
|
1271
|
+
if (_chunkGO4TR3HBcjs.isMintError.call(void 0, e)) throw e;
|
|
1272
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("INVALID_CONFIG", `mint.args cannot be encoded for ${signature(fn)}: ${shortMessage2(e)}`, { field: "mint.args", cause: e });
|
|
1816
1273
|
}
|
|
1817
1274
|
}
|
|
1818
1275
|
function mintValue(config, token, totalPrice) {
|
|
1819
1276
|
if (token) return 0n;
|
|
1820
1277
|
const fn = validateCall(config.abi, config.mint, "mint", "mint", PLACEHOLDERS);
|
|
1821
1278
|
if (fn.stateMutability === "nonpayable") {
|
|
1822
|
-
if (totalPrice > 0n)
|
|
1279
|
+
if (totalPrice > 0n) bad2("price", `is ${totalPrice} wei in native currency, but "${fn.name}" is nonpayable and cannot take value`);
|
|
1823
1280
|
return 0n;
|
|
1824
1281
|
}
|
|
1825
1282
|
return totalPrice;
|
|
1826
1283
|
}
|
|
1827
|
-
async function
|
|
1284
|
+
async function readDrop2(ctx, config) {
|
|
1828
1285
|
validateContractConfig(config);
|
|
1829
|
-
|
|
1286
|
+
throwIfAborted2(ctx);
|
|
1830
1287
|
const meta = await currencyMeta(ctx, config);
|
|
1831
1288
|
const none = {};
|
|
1832
1289
|
const [price, totalMinted, maxSupply, start, end] = await Promise.all([
|
|
@@ -1837,23 +1294,23 @@ async function readDrop(ctx, config) {
|
|
|
1837
1294
|
optField(ctx, config, "endTime", config.endTime, none)
|
|
1838
1295
|
]);
|
|
1839
1296
|
mintValue(config, meta.token, price);
|
|
1840
|
-
const native =
|
|
1297
|
+
const native = nativeMeta2(ctx);
|
|
1841
1298
|
return {
|
|
1842
1299
|
chainId: config.chainId,
|
|
1843
|
-
unitPrice:
|
|
1844
|
-
unitFee:
|
|
1845
|
-
totalMinted: totalMinted
|
|
1300
|
+
unitPrice: money2(price, meta.decimals, meta.symbol),
|
|
1301
|
+
unitFee: money2(0n, native.decimals, native.symbol),
|
|
1302
|
+
totalMinted: _nullishCoalesce(totalMinted, () => ( 0n)),
|
|
1846
1303
|
maxSupply: maxSupply === null || maxSupply === 0n ? null : maxSupply,
|
|
1847
1304
|
startTime: toSeconds(start, "startTime"),
|
|
1848
1305
|
endTime: toSeconds(end, "endTime"),
|
|
1849
1306
|
isAllowlist: false,
|
|
1850
1307
|
paymentToken: meta.token,
|
|
1851
|
-
pricePer: config.price.per
|
|
1308
|
+
pricePer: _nullishCoalesce(config.price.per, () => ( "unit"))
|
|
1852
1309
|
};
|
|
1853
1310
|
}
|
|
1854
|
-
async function
|
|
1311
|
+
async function readWallet2(ctx, config, { payer, recipient, quantity, drop }) {
|
|
1855
1312
|
validateContractConfig(config);
|
|
1856
|
-
|
|
1313
|
+
throwIfAborted2(ctx);
|
|
1857
1314
|
const qty = BigInt(quantity);
|
|
1858
1315
|
const unitPrice = drop.unitPrice.value;
|
|
1859
1316
|
const totalPrice = totalFor(drop.pricePer, unitPrice, qty);
|
|
@@ -1861,32 +1318,32 @@ async function readWallet(ctx, config, { payer, recipient, quantity, drop }) {
|
|
|
1861
1318
|
const [walletMinted, rawMax, native, erc20] = await Promise.all([
|
|
1862
1319
|
optField(ctx, config, "walletMinted", config.walletMinted, vars),
|
|
1863
1320
|
optField(ctx, config, "walletMax", config.walletMax, vars),
|
|
1864
|
-
|
|
1865
|
-
drop.paymentToken ? readCall(ctx, { address: drop.paymentToken, abi:
|
|
1321
|
+
io2(ctx, () => ctx.client.getBalance({ address: payer })).catch(rpcError2),
|
|
1322
|
+
drop.paymentToken ? readCall(ctx, { address: drop.paymentToken, abi: ERC20_ABI, functionName: "balanceOf", args: [payer] }, "price.currency.address").then(
|
|
1866
1323
|
(v) => toBigInt(v, "price.currency.address")
|
|
1867
1324
|
) : Promise.resolve(null)
|
|
1868
1325
|
]);
|
|
1869
1326
|
const walletMax = rawMax === null || rawMax === 0n ? null : rawMax;
|
|
1870
|
-
const remaining = walletMax === null ? null : walletMax > (walletMinted
|
|
1871
|
-
const maxQuantity = remaining === null ? null : Number(remaining < BigInt(MAX_QUANTITY) ? remaining : BigInt(MAX_QUANTITY));
|
|
1327
|
+
const remaining = walletMax === null ? null : walletMax > (_nullishCoalesce(walletMinted, () => ( 0n))) ? walletMax - (_nullishCoalesce(walletMinted, () => ( 0n))) : 0n;
|
|
1328
|
+
const maxQuantity = remaining === null ? null : Number(remaining < BigInt(_chunkGO4TR3HBcjs.MAX_QUANTITY) ? remaining : BigInt(_chunkGO4TR3HBcjs.MAX_QUANTITY));
|
|
1872
1329
|
let ineligible = null;
|
|
1873
1330
|
let gas = FALLBACK_MINT_GAS;
|
|
1874
1331
|
if (remaining === 0n) {
|
|
1875
1332
|
ineligible = { reason: "WALLET_LIMIT", message: `This wallet has already minted its limit of ${walletMax}.` };
|
|
1876
1333
|
} else if (drop.paymentToken === null && native >= totalPrice) {
|
|
1877
|
-
const call = { payer, to: (0,
|
|
1334
|
+
const call = { payer, to: _viem.getAddress.call(void 0, config.address), data: encodeMint(config, vars), value: mintValue(config, null, totalPrice) };
|
|
1878
1335
|
try {
|
|
1879
1336
|
await simulateMint(ctx, config, call);
|
|
1880
|
-
gas = await
|
|
1337
|
+
gas = await io2(ctx, () => ctx.client.estimateGas({ account: payer, to: call.to, data: call.data, value: call.value })).catch((e) => {
|
|
1881
1338
|
throw toSimulationError(e, config.abi);
|
|
1882
1339
|
});
|
|
1883
1340
|
} catch (e) {
|
|
1884
|
-
if (!isMintError(e) || e.reason !== "SIMULATION_REVERTED") throw e;
|
|
1341
|
+
if (!_chunkGO4TR3HBcjs.isMintError.call(void 0, e) || e.reason !== "SIMULATION_REVERTED") throw e;
|
|
1885
1342
|
ineligible = { reason: "SIMULATION_REVERTED", message: e.message };
|
|
1886
1343
|
}
|
|
1887
1344
|
}
|
|
1888
1345
|
if (drop.paymentToken) gas += APPROVE_GAS;
|
|
1889
|
-
const gasPrice = await
|
|
1346
|
+
const gasPrice = await io2(ctx, () => ctx.client.getGasPrice()).catch(rpcError2);
|
|
1890
1347
|
return {
|
|
1891
1348
|
walletMinted,
|
|
1892
1349
|
walletMax,
|
|
@@ -1901,11 +1358,11 @@ async function buildPlan2(ctx, attempt, wallet) {
|
|
|
1901
1358
|
void wallet;
|
|
1902
1359
|
const { config, payer, recipient } = attempt;
|
|
1903
1360
|
validateContractConfig(config);
|
|
1904
|
-
|
|
1361
|
+
throwIfAborted2(ctx);
|
|
1905
1362
|
const qty = BigInt(attempt.quantity);
|
|
1906
1363
|
const unitPrice = await resolvePrice(ctx, config);
|
|
1907
|
-
const totalPrice = totalFor(config.price.per
|
|
1908
|
-
const to = (0,
|
|
1364
|
+
const totalPrice = totalFor(_nullishCoalesce(config.price.per, () => ( "unit")), unitPrice, qty);
|
|
1365
|
+
const to = _viem.getAddress.call(void 0, config.address);
|
|
1909
1366
|
const token = erc20Of(config);
|
|
1910
1367
|
const mint = {
|
|
1911
1368
|
to,
|
|
@@ -1915,7 +1372,7 @@ async function buildPlan2(ctx, attempt, wallet) {
|
|
|
1915
1372
|
let approve = null;
|
|
1916
1373
|
if (token) {
|
|
1917
1374
|
const allowance = toBigInt(
|
|
1918
|
-
await readCall(ctx, { address: token, abi:
|
|
1375
|
+
await readCall(ctx, { address: token, abi: ERC20_ABI, functionName: "allowance", args: [payer, to] }, "price.currency.address"),
|
|
1919
1376
|
"price.currency.address"
|
|
1920
1377
|
);
|
|
1921
1378
|
if (allowance < totalPrice) {
|
|
@@ -1923,134 +1380,17 @@ async function buildPlan2(ctx, attempt, wallet) {
|
|
|
1923
1380
|
token,
|
|
1924
1381
|
spender: to,
|
|
1925
1382
|
amount: totalPrice,
|
|
1926
|
-
tx: { to: token, data: (0,
|
|
1383
|
+
tx: { to: token, data: _viem.encodeFunctionData.call(void 0, { abi: ERC20_ABI, functionName: "approve", args: [to, totalPrice] }), value: 0n }
|
|
1927
1384
|
};
|
|
1928
1385
|
}
|
|
1929
1386
|
}
|
|
1930
|
-
return { approve, mint, tokenContract: (0,
|
|
1387
|
+
return { approve, mint, tokenContract: _viem.getAddress.call(void 0, attempt.tokenContract) };
|
|
1931
1388
|
}
|
|
1932
|
-
async function
|
|
1933
|
-
|
|
1389
|
+
async function simulate2(ctx, attempt, plan) {
|
|
1390
|
+
throwIfAborted2(ctx);
|
|
1934
1391
|
await simulateMint(ctx, attempt.config, { payer: attempt.payer, to: plan.mint.to, data: plan.mint.data, value: plan.mint.value });
|
|
1935
1392
|
}
|
|
1936
|
-
var contractAdapter = { readDrop, readWallet, buildPlan: buildPlan2, simulate };
|
|
1937
|
-
|
|
1938
|
-
// src/core/adapters/receipt.ts
|
|
1939
|
-
var import_viem8 = require("viem");
|
|
1940
|
-
var TRANSFER_TOPIC = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
|
|
1941
|
-
var TRANSFER_SINGLE_TOPIC = "0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62";
|
|
1942
|
-
var TRANSFER_BATCH_TOPIC = "0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb";
|
|
1943
|
-
var topicAddress = (t) => t && t.length === 66 ? (0, import_viem8.getAddress)(`0x${t.slice(26)}`) : null;
|
|
1944
|
-
function parseMintReceipt(logs, { tokenContract, recipient }) {
|
|
1945
|
-
const contract = (0, import_viem8.getAddress)(tokenContract);
|
|
1946
|
-
const to = (0, import_viem8.getAddress)(recipient);
|
|
1947
|
-
const out = /* @__PURE__ */ new Map();
|
|
1948
|
-
const add = (id, amount) => out.set(id, (out.get(id) ?? 0n) + amount);
|
|
1949
|
-
for (const log of logs) {
|
|
1950
|
-
if ((0, import_viem8.getAddress)(log.address) !== contract) continue;
|
|
1951
|
-
const [t0, t1, t2, t3] = log.topics;
|
|
1952
|
-
if (t0 === TRANSFER_TOPIC && log.topics.length === 4) {
|
|
1953
|
-
if (topicAddress(t1) !== import_viem8.zeroAddress || topicAddress(t2) !== to || !t3) continue;
|
|
1954
|
-
add(BigInt(t3), 1n);
|
|
1955
|
-
} else if (t0 === TRANSFER_SINGLE_TOPIC && log.topics.length === 4) {
|
|
1956
|
-
if (topicAddress(t2) !== import_viem8.zeroAddress || topicAddress(t3) !== to) continue;
|
|
1957
|
-
const [id, value] = (0, import_viem8.decodeAbiParameters)([{ type: "uint256" }, { type: "uint256" }], log.data);
|
|
1958
|
-
add(id, value);
|
|
1959
|
-
} else if (t0 === TRANSFER_BATCH_TOPIC && log.topics.length === 4) {
|
|
1960
|
-
if (topicAddress(t2) !== import_viem8.zeroAddress || topicAddress(t3) !== to) continue;
|
|
1961
|
-
const [ids, values] = (0, import_viem8.decodeAbiParameters)([{ type: "uint256[]" }, { type: "uint256[]" }], log.data);
|
|
1962
|
-
if (ids.length !== values.length) continue;
|
|
1963
|
-
ids.forEach((id, i) => add(id, values[i]));
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
return [...out].map(([tokenId, amount]) => ({ contract, tokenId, amount }));
|
|
1967
|
-
}
|
|
1968
|
-
|
|
1969
|
-
// src/core/friendly-errors.ts
|
|
1970
|
-
var GENERIC = "Transaction failed. Please try again. If it fails again, please contact support.";
|
|
1971
|
-
var REVERTED = "Transaction reverted";
|
|
1972
|
-
var record = (value) => value !== null && typeof value === "object" ? value : void 0;
|
|
1973
|
-
var text = (value) => typeof value === "string" ? value.toLowerCase() : "";
|
|
1974
|
-
function collect(error) {
|
|
1975
|
-
const pending = [error];
|
|
1976
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1977
|
-
const errors = [];
|
|
1978
|
-
while (pending.length) {
|
|
1979
|
-
const e = record(pending.pop());
|
|
1980
|
-
if (!e || seen.has(e)) continue;
|
|
1981
|
-
seen.add(e);
|
|
1982
|
-
const data = record(e.data);
|
|
1983
|
-
errors.push({
|
|
1984
|
-
name: e.name,
|
|
1985
|
-
code: e.code,
|
|
1986
|
-
cancelled: e.cancelled,
|
|
1987
|
-
replacement: e.replacement,
|
|
1988
|
-
message: [e.message, e.shortMessage, isMintError(e) ? void 0 : e.reason, data?.message].map(text).join("\n")
|
|
1989
|
-
});
|
|
1990
|
-
pending.push(e.cause, data?.originalError);
|
|
1991
|
-
}
|
|
1992
|
-
return errors;
|
|
1993
|
-
}
|
|
1994
|
-
function fundsMessage(errors) {
|
|
1995
|
-
const hasText = (phrase) => errors.some((e) => e.message.includes(phrase));
|
|
1996
|
-
if (hasText("insufficient funds for gas")) {
|
|
1997
|
-
return "Your wallet does not have enough funds to pay for gas fees. Please try again with a different wallet or add more funds to your wallet.";
|
|
1998
|
-
}
|
|
1999
|
-
if (errors.some((e) => e.name === "InsufficientFundsError" || e.code === "INSUFFICIENT_FUNDS") || hasText("insufficient funds") || hasText("balance too low to proceed")) {
|
|
2000
|
-
return "Your wallet does not have enough funds to complete this transaction. Please try again with a different wallet or add more funds to your wallet.";
|
|
2001
|
-
}
|
|
2002
|
-
return null;
|
|
2003
|
-
}
|
|
2004
|
-
function friendlyErrorMessage(error) {
|
|
2005
|
-
if (isMintError(error)) {
|
|
2006
|
-
if (error.reason === "INSUFFICIENT_FUNDS") return fundsMessage(collect(error.cause)) ?? error.message;
|
|
2007
|
-
if (error.reason !== "RPC_ERROR" && error.reason !== "SIMULATION_REVERTED") return error.message;
|
|
2008
|
-
if (error.reason === "SIMULATION_REVERTED" && error.domain === "relay") return error.message;
|
|
2009
|
-
if (error.reason === "SIMULATION_REVERTED" && (error.message === "The token refused the approval." || error.message === "The drop is no longer available for this quantity.")) return error.message;
|
|
2010
|
-
}
|
|
2011
|
-
const errors = collect(error);
|
|
2012
|
-
const hasText = (phrase) => errors.some((e) => e.message.includes(phrase));
|
|
2013
|
-
const hasName = (name) => errors.some((e) => e.name === name);
|
|
2014
|
-
const hasCode2 = (code2) => errors.some((e) => e.code === code2);
|
|
2015
|
-
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)) {
|
|
2016
|
-
return "Transaction Rejected";
|
|
2017
|
-
}
|
|
2018
|
-
if (hasCode2(4902)) return "Network not available in wallet";
|
|
2019
|
-
const replaced = errors.find((e) => e.name === "TransactionReplacedError" || e.code === "TRANSACTION_REPLACED");
|
|
2020
|
-
if (replaced?.cancelled) return "Transaction was cancelled";
|
|
2021
|
-
if (replaced?.replacement) return "Transaction was replaced with a new transaction (usually due to speed up)";
|
|
2022
|
-
if (hasText("ledger")) return "Error with Ledger device. Please ensure device is connected and unlocked";
|
|
2023
|
-
if (errors.some((e) => e.code === -32002 && e.message.includes("pending"))) {
|
|
2024
|
-
return "Transaction already pending in wallet. Please check your wallet";
|
|
2025
|
-
}
|
|
2026
|
-
if (hasText("invalid amount")) return "Price calculation is incorrect, contact support!";
|
|
2027
|
-
const funds = fundsMessage(errors);
|
|
2028
|
-
if (funds) return funds;
|
|
2029
|
-
if (hasName("NonceTooLowError") || hasName("NonceExhaustedError") || hasText("nonce too low")) {
|
|
2030
|
-
return "Transaction nonce is too low. Please try again";
|
|
2031
|
-
}
|
|
2032
|
-
if (hasName("FeeCapTooLowError") || hasText("max fee per gas less than block base fee")) {
|
|
2033
|
-
return "Gas price too low for current network conditions. Please try again";
|
|
2034
|
-
}
|
|
2035
|
-
if (hasName("TimeoutError") || hasCode2("TIMEOUT") || hasText("timeout")) {
|
|
2036
|
-
return "Transaction timed out. Your wallet connection is having issues. Disconnect and reconnect your wallet, then please try again";
|
|
2037
|
-
}
|
|
2038
|
-
if (hasText("network disconnected")) return "Network connection lost. Please check your internet connection and try again";
|
|
2039
|
-
if (hasName("ChainMismatchError") || hasText("wrong network")) return "Wrong network selected. Please switch to the correct network";
|
|
2040
|
-
if (hasText("erc20: transfer amount exceeds balance")) {
|
|
2041
|
-
return "You do not have the required amount of ERC20 tokens to complete this transaction.";
|
|
2042
|
-
}
|
|
2043
|
-
if (hasName("EstimateGasExecutionError") || hasCode2("UNPREDICTABLE_GAS_LIMIT") || hasText("cannot estimate gas")) {
|
|
2044
|
-
return "Unable to estimate gas for transaction. The transaction may fail. Please try again.";
|
|
2045
|
-
}
|
|
2046
|
-
if (hasName("ContractFunctionExecutionError") || hasCode2("CALL_EXCEPTION")) {
|
|
2047
|
-
return "Transaction failed due to contract execution error";
|
|
2048
|
-
}
|
|
2049
|
-
if (hasName("ContractFunctionRevertedError") || hasName("ExecutionRevertedError") || hasText("revert")) return REVERTED;
|
|
2050
|
-
if (hasName("TransactionExecutionError")) return "Transaction execution failed";
|
|
2051
|
-
if (hasCode2("NETWORK_ERROR") || hasName("HttpRequestError") || hasText("network")) return "Network error occurred";
|
|
2052
|
-
return isMintError(error) && error.reason === "SIMULATION_REVERTED" ? REVERTED : GENERIC;
|
|
2053
|
-
}
|
|
1393
|
+
var contractAdapter = { readDrop: readDrop2, readWallet: readWallet2, buildPlan: buildPlan2, simulate: simulate2 };
|
|
2054
1394
|
|
|
2055
1395
|
// src/react/useMint.ts
|
|
2056
1396
|
var REFRESH_MS = 3e4;
|
|
@@ -2064,7 +1404,18 @@ function configKeyOf(config) {
|
|
|
2064
1404
|
return JSON.stringify(config, (_k, v) => typeof v === "bigint" ? { __dropkitBigInt: v.toString() } : v);
|
|
2065
1405
|
}
|
|
2066
1406
|
function adapterFor(config) {
|
|
2067
|
-
|
|
1407
|
+
switch (config.type) {
|
|
1408
|
+
case "manifold-claim":
|
|
1409
|
+
return _chunkGO4TR3HBcjs.manifoldClaimAdapter;
|
|
1410
|
+
case "contract":
|
|
1411
|
+
return contractAdapter;
|
|
1412
|
+
case "tl-stacks":
|
|
1413
|
+
return tlStacksAdapter;
|
|
1414
|
+
default: {
|
|
1415
|
+
const unreachable = config;
|
|
1416
|
+
return unreachable;
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
2068
1419
|
}
|
|
2069
1420
|
var bridgeEnabled = (config) => config.type === "manifold-claim";
|
|
2070
1421
|
function payChainsOf(config, option) {
|
|
@@ -2080,87 +1431,93 @@ function routeChainOf(payChains, accountChainId, payChainId) {
|
|
|
2080
1431
|
var ROUTE_DEBOUNCE_MS = 500;
|
|
2081
1432
|
var symbolOf = (chainId) => {
|
|
2082
1433
|
try {
|
|
2083
|
-
return getChain(chainId).nativeCurrency.symbol;
|
|
2084
|
-
} catch {
|
|
1434
|
+
return _chunkGO4TR3HBcjs.getChain.call(void 0, chainId).nativeCurrency.symbol;
|
|
1435
|
+
} catch (e5) {
|
|
2085
1436
|
return "ETH";
|
|
2086
1437
|
}
|
|
2087
1438
|
};
|
|
2088
|
-
var shortOf = (chainId) => ({ chainId, symbol: symbolOf(chainId), name: chainName(chainId) });
|
|
1439
|
+
var shortOf = (chainId) => ({ chainId, symbol: symbolOf(chainId), name: _chunkGO4TR3HBcjs.chainName.call(void 0, chainId) });
|
|
2089
1440
|
function tokenContractOf(config) {
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
1441
|
+
switch (config.type) {
|
|
1442
|
+
case "manifold-claim":
|
|
1443
|
+
return config.creatorContract;
|
|
1444
|
+
case "contract":
|
|
1445
|
+
return _nullishCoalesce(config.tokenContract, () => ( config.address));
|
|
1446
|
+
case "tl-stacks":
|
|
1447
|
+
return config.nftContract;
|
|
1448
|
+
default: {
|
|
1449
|
+
const unreachable = config;
|
|
1450
|
+
return unreachable;
|
|
1451
|
+
}
|
|
2100
1452
|
}
|
|
2101
|
-
return false;
|
|
2102
1453
|
}
|
|
2103
|
-
function
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
1454
|
+
function eventAddressOf(config) {
|
|
1455
|
+
switch (config.type) {
|
|
1456
|
+
case "manifold-claim":
|
|
1457
|
+
return config.creatorContract;
|
|
1458
|
+
case "contract":
|
|
1459
|
+
return config.address;
|
|
1460
|
+
case "tl-stacks":
|
|
1461
|
+
return config.nftContract;
|
|
1462
|
+
default: {
|
|
1463
|
+
const unreachable = config;
|
|
1464
|
+
return unreachable;
|
|
1465
|
+
}
|
|
2109
1466
|
}
|
|
2110
|
-
return { reason: "RPC_ERROR", message: friendlyErrorMessage(e) };
|
|
2111
1467
|
}
|
|
1468
|
+
var isUnsupported = (reason) => _chunkGO4TR3HBcjs.UNSUPPORTED_REASONS.includes(reason);
|
|
2112
1469
|
function errorReasonOf(e) {
|
|
2113
|
-
const { reason, message } = toReason(e);
|
|
1470
|
+
const { reason, message } = _chunkGO4TR3HBcjs.toReason.call(void 0, e);
|
|
2114
1471
|
const ok = ["USER_REJECTED", "TX_REVERTED", "RATE_LIMITED", "RPC_ERROR", "CHAIN_SWITCH_FAILED", "ALLOWLIST_UNAVAILABLE"];
|
|
2115
1472
|
return { reason: ok.includes(reason) ? reason : "RPC_ERROR", message };
|
|
2116
1473
|
}
|
|
2117
1474
|
function explorerUrlFor(chainId, hash) {
|
|
2118
1475
|
try {
|
|
2119
|
-
const url = getChain(chainId).blockExplorers
|
|
1476
|
+
const url = _optionalChain([_chunkGO4TR3HBcjs.getChain.call(void 0, chainId), 'access', _44 => _44.blockExplorers, 'optionalAccess', _45 => _45.default, 'access', _46 => _46.url]);
|
|
2120
1477
|
return url ? `${url.replace(/\/$/, "")}/tx/${hash}` : null;
|
|
2121
|
-
} catch {
|
|
1478
|
+
} catch (e6) {
|
|
2122
1479
|
return null;
|
|
2123
1480
|
}
|
|
2124
1481
|
}
|
|
2125
1482
|
var receiptOk = (status) => status === "success" || status === 1 || status === 1n || status === "0x1";
|
|
2126
1483
|
function useMint(options) {
|
|
2127
1484
|
const { config, recipient, quantity: quantityProp, connect } = options;
|
|
2128
|
-
const [machine, rawDispatch] = (0,
|
|
2129
|
-
const [widgetFail, setWidgetFail] = (0,
|
|
2130
|
-
const [widgetRetry, setWidgetRetry] = (0,
|
|
1485
|
+
const [machine, rawDispatch] = _react.useReducer.call(void 0, _chunkGO4TR3HBcjs.reducer, void 0, () => _chunkGO4TR3HBcjs.initialState.call(void 0, { quantity: quantityProp }));
|
|
1486
|
+
const [widgetFail, setWidgetFail] = _react.useState.call(void 0, null);
|
|
1487
|
+
const [widgetRetry, setWidgetRetry] = _react.useState.call(void 0, 0);
|
|
2131
1488
|
const configKey = configKeyOf(config);
|
|
2132
|
-
const mounted = (0,
|
|
2133
|
-
const stateRef = (0,
|
|
2134
|
-
const propsRef = (0,
|
|
2135
|
-
const lifeRef = (0,
|
|
2136
|
-
const genRef = (0,
|
|
2137
|
-
const attemptRef = (0,
|
|
2138
|
-
const attemptIdRef = (0,
|
|
2139
|
-
const accountKeyRef = (0,
|
|
2140
|
-
const connectingRef = (0,
|
|
2141
|
-
const pendingRefreshRef = (0,
|
|
2142
|
-
const pendingQuantityRef = (0,
|
|
2143
|
-
const widgetFailRef = (0,
|
|
2144
|
-
const widgetLoadRef = (0,
|
|
2145
|
-
const pushAccountRef = (0,
|
|
2146
|
-
const autoResumedRef = (0,
|
|
2147
|
-
const [crossChainInfo, setCrossChainInfo] = (0,
|
|
2148
|
-
(0,
|
|
1489
|
+
const mounted = _react.useRef.call(void 0, false);
|
|
1490
|
+
const stateRef = _react.useRef.call(void 0, machine);
|
|
1491
|
+
const propsRef = _react.useRef.call(void 0, options);
|
|
1492
|
+
const lifeRef = _react.useRef.call(void 0, null);
|
|
1493
|
+
const genRef = _react.useRef.call(void 0, 0);
|
|
1494
|
+
const attemptRef = _react.useRef.call(void 0, null);
|
|
1495
|
+
const attemptIdRef = _react.useRef.call(void 0, 0);
|
|
1496
|
+
const accountKeyRef = _react.useRef.call(void 0, null);
|
|
1497
|
+
const connectingRef = _react.useRef.call(void 0, false);
|
|
1498
|
+
const pendingRefreshRef = _react.useRef.call(void 0, false);
|
|
1499
|
+
const pendingQuantityRef = _react.useRef.call(void 0, null);
|
|
1500
|
+
const widgetFailRef = _react.useRef.call(void 0, null);
|
|
1501
|
+
const widgetLoadRef = _react.useRef.call(void 0, null);
|
|
1502
|
+
const pushAccountRef = _react.useRef.call(void 0, null);
|
|
1503
|
+
const autoResumedRef = _react.useRef.call(void 0, /* @__PURE__ */ new Set());
|
|
1504
|
+
const [crossChainInfo, setCrossChainInfo] = _react.useState.call(void 0, null);
|
|
1505
|
+
_react.useEffect.call(void 0, () => {
|
|
2149
1506
|
stateRef.current = machine;
|
|
2150
1507
|
propsRef.current = options;
|
|
2151
1508
|
widgetFailRef.current = widgetFail;
|
|
2152
1509
|
});
|
|
2153
|
-
const dispatch = (0,
|
|
1510
|
+
const dispatch = _react.useCallback.call(void 0, (event) => {
|
|
2154
1511
|
if (!mounted.current) return;
|
|
2155
|
-
stateRef.current = reducer(stateRef.current, event);
|
|
1512
|
+
stateRef.current = _chunkGO4TR3HBcjs.reducer.call(void 0, stateRef.current, event);
|
|
2156
1513
|
rawDispatch(event);
|
|
2157
1514
|
}, []);
|
|
2158
|
-
const emit = (0,
|
|
1515
|
+
const emit = _react.useCallback.call(void 0, (type, over = {}) => {
|
|
2159
1516
|
const handler = propsRef.current.onEvent;
|
|
2160
1517
|
if (!handler || !mounted.current) return;
|
|
2161
|
-
const cfg = attemptRef.current
|
|
1518
|
+
const cfg = _nullishCoalesce(_optionalChain([attemptRef, 'access', _47 => _47.current, 'optionalAccess', _48 => _48.config]), () => ( propsRef.current.config));
|
|
2162
1519
|
const s = stateRef.current;
|
|
2163
|
-
const originChainId = attemptRef.current
|
|
1520
|
+
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)))));
|
|
2164
1521
|
const payload = {
|
|
2165
1522
|
type,
|
|
2166
1523
|
state: s.name,
|
|
@@ -2174,18 +1531,18 @@ function useMint(options) {
|
|
|
2174
1531
|
};
|
|
2175
1532
|
try {
|
|
2176
1533
|
handler(payload);
|
|
2177
|
-
} catch {
|
|
1534
|
+
} catch (e7) {
|
|
2178
1535
|
}
|
|
2179
1536
|
}, []);
|
|
2180
|
-
const clientFor = (0,
|
|
2181
|
-
const rpcUrl = propsRef.current.rpcUrls
|
|
1537
|
+
const clientFor = _react.useCallback.call(void 0, (life, cfg) => {
|
|
1538
|
+
const rpcUrl = _optionalChain([propsRef, 'access', _55 => _55.current, 'access', _56 => _56.rpcUrls, 'optionalAccess', _57 => _57[cfg.chainId]]);
|
|
2182
1539
|
if (!life.client || life.rpcUrl !== rpcUrl) {
|
|
2183
1540
|
life.rpcUrl = rpcUrl;
|
|
2184
|
-
life.client = createReadClient({ chainId: cfg.chainId, rpcUrls: propsRef.current.rpcUrls, useBridge: bridgeEnabled(cfg) });
|
|
1541
|
+
life.client = _chunkGO4TR3HBcjs.createReadClient.call(void 0, { chainId: cfg.chainId, rpcUrls: propsRef.current.rpcUrls, useBridge: bridgeEnabled(cfg) });
|
|
2185
1542
|
}
|
|
2186
1543
|
return life.client;
|
|
2187
1544
|
}, []);
|
|
2188
|
-
const ctxFor = (0,
|
|
1545
|
+
const ctxFor = _react.useCallback.call(void 0,
|
|
2189
1546
|
(life, cfg) => ({
|
|
2190
1547
|
client: clientFor(life, cfg),
|
|
2191
1548
|
cacheScope: life.cacheScope,
|
|
@@ -2194,7 +1551,7 @@ function useMint(options) {
|
|
|
2194
1551
|
}),
|
|
2195
1552
|
[clientFor]
|
|
2196
1553
|
);
|
|
2197
|
-
const
|
|
1554
|
+
const readDrop3 = _react.useCallback.call(void 0,
|
|
2198
1555
|
async (life, gen, cfg) => {
|
|
2199
1556
|
const adapter = adapterFor(cfg);
|
|
2200
1557
|
try {
|
|
@@ -2203,27 +1560,27 @@ function useMint(options) {
|
|
|
2203
1560
|
dispatch({ type: "DROP_LOADED", gen, drop, now: Math.max(stateRef.current.now, nowSec()) });
|
|
2204
1561
|
} catch (e) {
|
|
2205
1562
|
if (life.controller.signal.aborted || life.gen !== gen || lifeRef.current !== life) return;
|
|
2206
|
-
const { reason, message } = toReason(e);
|
|
1563
|
+
const { reason, message } = _chunkGO4TR3HBcjs.toReason.call(void 0, e);
|
|
2207
1564
|
if (isUnsupported(reason)) dispatch({ type: "DROP_UNSUPPORTED", gen, reason, message });
|
|
2208
1565
|
else dispatch({ type: "READ_FAILED", gen, ...errorReasonOf(e) });
|
|
2209
1566
|
}
|
|
2210
1567
|
},
|
|
2211
1568
|
[ctxFor, dispatch]
|
|
2212
1569
|
);
|
|
2213
|
-
const startLifetime = (0,
|
|
1570
|
+
const startLifetime = _react.useCallback.call(void 0,
|
|
2214
1571
|
(key, cfg) => {
|
|
2215
1572
|
const prev = lifeRef.current;
|
|
2216
1573
|
lifeRef.current = null;
|
|
2217
|
-
prev
|
|
1574
|
+
_optionalChain([prev, 'optionalAccess', _58 => _58.controller, 'access', _59 => _59.abort, 'call', _60 => _60()]);
|
|
2218
1575
|
const gen = ++genRef.current;
|
|
2219
1576
|
const life = { key, controller: new AbortController(), cacheScope: {}, gen };
|
|
2220
1577
|
lifeRef.current = life;
|
|
2221
1578
|
dispatch({ type: "LOAD", gen, kind: "config" });
|
|
2222
|
-
void
|
|
1579
|
+
void readDrop3(life, gen, cfg);
|
|
2223
1580
|
},
|
|
2224
|
-
[dispatch,
|
|
1581
|
+
[dispatch, readDrop3]
|
|
2225
1582
|
);
|
|
2226
|
-
const refreshNow = (0,
|
|
1583
|
+
const refreshNow = _react.useCallback.call(void 0,
|
|
2227
1584
|
async (kind = "refresh") => {
|
|
2228
1585
|
const life = lifeRef.current;
|
|
2229
1586
|
if (!life || !mounted.current) return;
|
|
@@ -2234,16 +1591,16 @@ function useMint(options) {
|
|
|
2234
1591
|
const gen = ++genRef.current;
|
|
2235
1592
|
life.gen = gen;
|
|
2236
1593
|
dispatch({ type: "LOAD", gen, kind });
|
|
2237
|
-
await
|
|
1594
|
+
await readDrop3(life, gen, propsRef.current.config);
|
|
2238
1595
|
},
|
|
2239
|
-
[dispatch,
|
|
1596
|
+
[dispatch, readDrop3]
|
|
2240
1597
|
);
|
|
2241
|
-
const refresh = (0,
|
|
2242
|
-
const isBusy = (0,
|
|
2243
|
-
() => connectingRef.current || attemptRef.current !== null || stateRef.current.attempt !== null || IN_FLIGHT_STATES.includes(stateRef.current.name),
|
|
1598
|
+
const refresh = _react.useCallback.call(void 0, () => refreshNow("refresh"), [refreshNow]);
|
|
1599
|
+
const isBusy = _react.useCallback.call(void 0,
|
|
1600
|
+
() => connectingRef.current || attemptRef.current !== null || stateRef.current.attempt !== null || _chunkGO4TR3HBcjs.IN_FLIGHT_STATES.includes(stateRef.current.name),
|
|
2244
1601
|
[]
|
|
2245
1602
|
);
|
|
2246
|
-
const executeAttempt = (0,
|
|
1603
|
+
const executeAttempt = _react.useCallback.call(void 0,
|
|
2247
1604
|
async (attempt, walletRead, life, account2) => {
|
|
2248
1605
|
const cfg = attempt.config;
|
|
2249
1606
|
const adapter = adapterFor(cfg);
|
|
@@ -2256,20 +1613,20 @@ function useMint(options) {
|
|
|
2256
1613
|
};
|
|
2257
1614
|
const assertPayer = () => {
|
|
2258
1615
|
assertActive();
|
|
2259
|
-
const live = getAccount();
|
|
1616
|
+
const live = _chunkGO4TR3HBcjs.getAccount.call(void 0, );
|
|
2260
1617
|
if (!live || live.address.toLowerCase() !== attempt.payer.toLowerCase()) {
|
|
2261
|
-
throw new MintError("USER_REJECTED", "The connected wallet changed before the transaction was sent.");
|
|
1618
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("USER_REJECTED", "The connected wallet changed before the transaction was sent.");
|
|
2262
1619
|
}
|
|
2263
1620
|
};
|
|
2264
1621
|
let wallet2 = null;
|
|
2265
1622
|
const walletFor = () => {
|
|
2266
|
-
if (!wallet2) wallet2 = getWalletClient(attempt.chainId);
|
|
1623
|
+
if (!wallet2) wallet2 = _chunkGO4TR3HBcjs.getWalletClient.call(void 0, attempt.chainId);
|
|
2267
1624
|
return wallet2;
|
|
2268
1625
|
};
|
|
2269
1626
|
const submit = async (tx) => {
|
|
2270
1627
|
assertPayer();
|
|
2271
1628
|
const w = walletFor();
|
|
2272
|
-
return w.sendTransaction({ account: attempt.payer, to: tx.to, data: tx.data, value: tx.value, chain: getChain(attempt.chainId) });
|
|
1629
|
+
return w.sendTransaction({ account: attempt.payer, to: tx.to, data: tx.data, value: tx.value, chain: _chunkGO4TR3HBcjs.getChain.call(void 0, attempt.chainId) });
|
|
2273
1630
|
};
|
|
2274
1631
|
const waitReceipt = async (hash2) => {
|
|
2275
1632
|
let cancelled = false;
|
|
@@ -2286,19 +1643,19 @@ function useMint(options) {
|
|
|
2286
1643
|
receipt2 = await client.waitForTransactionReceipt(params);
|
|
2287
1644
|
} catch (e) {
|
|
2288
1645
|
assertActive();
|
|
2289
|
-
if (cancelled) throw new MintError("USER_REJECTED", "The transaction was cancelled or replaced with a different transaction.");
|
|
1646
|
+
if (cancelled) throw new (0, _chunkGO4TR3HBcjs.MintError)("USER_REJECTED", "The transaction was cancelled or replaced with a different transaction.");
|
|
2290
1647
|
if (await walletFor().getChainId() !== attempt.chainId) throw e;
|
|
2291
1648
|
assertActive();
|
|
2292
|
-
receipt2 = await walletFor().extend(
|
|
1649
|
+
receipt2 = await walletFor().extend(_viem.publicActions).waitForTransactionReceipt(params);
|
|
2293
1650
|
}
|
|
2294
1651
|
assertActive();
|
|
2295
|
-
if (cancelled) throw new MintError("USER_REJECTED", "The transaction was cancelled or replaced with a different transaction.");
|
|
1652
|
+
if (cancelled) throw new (0, _chunkGO4TR3HBcjs.MintError)("USER_REJECTED", "The transaction was cancelled or replaced with a different transaction.");
|
|
2296
1653
|
return receipt2;
|
|
2297
1654
|
};
|
|
2298
1655
|
assertPayer();
|
|
2299
1656
|
if (account2.chainId !== attempt.chainId) {
|
|
2300
1657
|
dispatch({ type: "SWITCHING_CHAIN", attemptId: attempt.attemptId });
|
|
2301
|
-
await switchToChain(attempt.chainId);
|
|
1658
|
+
await _chunkGO4TR3HBcjs.switchToChain.call(void 0, attempt.chainId);
|
|
2302
1659
|
}
|
|
2303
1660
|
assertPayer();
|
|
2304
1661
|
let plan = await adapter.buildPlan(ctx, attempt, walletRead);
|
|
@@ -2308,13 +1665,13 @@ function useMint(options) {
|
|
|
2308
1665
|
try {
|
|
2309
1666
|
const simulated = await client.call({ account: attempt.payer, to: a.tx.to, data: a.tx.data, value: a.tx.value });
|
|
2310
1667
|
if (simulated.data && simulated.data !== "0x" && BigInt(simulated.data) === 0n) {
|
|
2311
|
-
throw new MintError("SIMULATION_REVERTED", "The token refused the approval.");
|
|
1668
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("SIMULATION_REVERTED", "The token refused the approval.");
|
|
2312
1669
|
}
|
|
2313
1670
|
} catch (e) {
|
|
2314
|
-
if (isMintError(e)) throw e;
|
|
2315
|
-
const reverted = e instanceof
|
|
2316
|
-
if (reverted instanceof
|
|
2317
|
-
throw new MintError("SIMULATION_REVERTED", reverted.shortMessage);
|
|
1671
|
+
if (_chunkGO4TR3HBcjs.isMintError.call(void 0, e)) throw e;
|
|
1672
|
+
const reverted = e instanceof _viem.BaseError ? e.walk((cause) => cause instanceof _viem.ExecutionRevertedError) : null;
|
|
1673
|
+
if (reverted instanceof _viem.ExecutionRevertedError) {
|
|
1674
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("SIMULATION_REVERTED", reverted.shortMessage);
|
|
2318
1675
|
}
|
|
2319
1676
|
throw e;
|
|
2320
1677
|
}
|
|
@@ -2326,7 +1683,7 @@ function useMint(options) {
|
|
|
2326
1683
|
const approveReceipt = await waitReceipt(approveHash);
|
|
2327
1684
|
assertActive();
|
|
2328
1685
|
if (!receiptOk(approveReceipt.status)) {
|
|
2329
|
-
throw new MintError("TX_REVERTED", `The approval transaction reverted (${approveHash}).`);
|
|
1686
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("TX_REVERTED", `The approval transaction reverted (${approveHash}).`);
|
|
2330
1687
|
}
|
|
2331
1688
|
const freshDrop = await adapter.readDrop(ctx, cfg);
|
|
2332
1689
|
assertActive();
|
|
@@ -2337,11 +1694,11 @@ function useMint(options) {
|
|
|
2337
1694
|
drop: freshDrop
|
|
2338
1695
|
});
|
|
2339
1696
|
assertPayer();
|
|
2340
|
-
let checked = reducer(initialState({ quantity: attempt.quantity }), { type: "ACCOUNT_CHANGED", account: account2 });
|
|
2341
|
-
checked = reducer(checked, { type: "DROP_LOADED", gen: checked.readGen, drop: freshDrop, now: nowSec() });
|
|
2342
|
-
checked = reducer(checked, { type: "WALLET_LOADED", gen: checked.walletGen, read: freshWallet });
|
|
2343
|
-
if (checked.name !== "live" || (selectMaxQuantity(checked)
|
|
2344
|
-
throw new MintError(checked.reason
|
|
1697
|
+
let checked = _chunkGO4TR3HBcjs.reducer.call(void 0, _chunkGO4TR3HBcjs.initialState.call(void 0, { quantity: attempt.quantity }), { type: "ACCOUNT_CHANGED", account: account2 });
|
|
1698
|
+
checked = _chunkGO4TR3HBcjs.reducer.call(void 0, checked, { type: "DROP_LOADED", gen: checked.readGen, drop: freshDrop, now: nowSec() });
|
|
1699
|
+
checked = _chunkGO4TR3HBcjs.reducer.call(void 0, checked, { type: "WALLET_LOADED", gen: checked.walletGen, read: freshWallet });
|
|
1700
|
+
if (checked.name !== "live" || (_nullishCoalesce(_chunkGO4TR3HBcjs.selectMaxQuantity.call(void 0, checked), () => ( 0))) < attempt.quantity) {
|
|
1701
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)(_nullishCoalesce(checked.reason, () => ( "SIMULATION_REVERTED")), _nullishCoalesce(checked.message, () => ( "The drop is no longer available for this quantity.")));
|
|
2345
1702
|
}
|
|
2346
1703
|
plan = await adapter.buildPlan(ctx, attempt, freshWallet);
|
|
2347
1704
|
assertPayer();
|
|
@@ -2355,21 +1712,21 @@ function useMint(options) {
|
|
|
2355
1712
|
emit("tx-submitted", { state: "confirming", reason: null, txHash: hash, quantity: attempt.quantity, chainId: attempt.chainId });
|
|
2356
1713
|
const receipt = await waitReceipt(hash);
|
|
2357
1714
|
assertActive();
|
|
2358
|
-
const confirmedHash = receipt.transactionHash
|
|
1715
|
+
const confirmedHash = _nullishCoalesce(receipt.transactionHash, () => ( hash));
|
|
2359
1716
|
if (!receiptOk(receipt.status)) {
|
|
2360
|
-
throw new MintError("TX_REVERTED", `The mint transaction reverted (${confirmedHash}).`);
|
|
1717
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("TX_REVERTED", `The mint transaction reverted (${confirmedHash}).`);
|
|
2361
1718
|
}
|
|
2362
|
-
const tokens = parseMintReceipt(receipt.logs
|
|
2363
|
-
tokenContract: plan.tokenContract
|
|
1719
|
+
const tokens = _chunkGO4TR3HBcjs.parseMintReceipt.call(void 0, _nullishCoalesce(receipt.logs, () => ( [])), {
|
|
1720
|
+
tokenContract: _nullishCoalesce(plan.tokenContract, () => ( attempt.tokenContract)),
|
|
2364
1721
|
recipient: attempt.recipient
|
|
2365
1722
|
});
|
|
2366
|
-
const result = { txHash: confirmedHash, explorerUrl: explorerUrlFor(attempt.chainId, confirmedHash), tokens };
|
|
1723
|
+
const result = { txHash: confirmedHash, explorerUrl: explorerUrlFor(attempt.chainId, confirmedHash), tokens, requested: attempt.quantity };
|
|
2367
1724
|
dispatch({ type: "ATTEMPT_SUCCEEDED", attemptId: attempt.attemptId, result });
|
|
2368
1725
|
emit("success", { state: "success", reason: null, txHash: confirmedHash, quantity: attempt.quantity, chainId: attempt.chainId });
|
|
2369
1726
|
},
|
|
2370
1727
|
[clientFor, ctxFor, dispatch, emit]
|
|
2371
1728
|
);
|
|
2372
|
-
const finishRelay = (0,
|
|
1729
|
+
const finishRelay = _react.useCallback.call(void 0,
|
|
2373
1730
|
async (attempt, out, life) => {
|
|
2374
1731
|
const cfg = attempt.config;
|
|
2375
1732
|
const client = clientFor(life, cfg);
|
|
@@ -2380,38 +1737,39 @@ function useMint(options) {
|
|
|
2380
1737
|
};
|
|
2381
1738
|
const outcome = await pollUntilTerminal({ testnet: out.testnet, requestId: out.requestId, signal: life.controller.signal, assertActive });
|
|
2382
1739
|
assertActive();
|
|
2383
|
-
const where = chainName(out.originChainId);
|
|
1740
|
+
const where = _chunkGO4TR3HBcjs.chainName.call(void 0, out.originChainId);
|
|
2384
1741
|
if (outcome.kind === "timeout") {
|
|
2385
|
-
throw new MintError("BRIDGE_TIMEOUT", "The bridge is still processing. Your mint may still complete.");
|
|
1742
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("BRIDGE_TIMEOUT", "The bridge is still processing. Your mint may still complete.");
|
|
2386
1743
|
}
|
|
2387
1744
|
const key = outstandingKey(attempt.config, attempt.payer);
|
|
2388
1745
|
const { status } = outcome;
|
|
2389
1746
|
if (status.status !== "success") clearOutstanding(key);
|
|
2390
1747
|
if (status.status === "refund") {
|
|
2391
|
-
throw new MintError("BRIDGE_REFUNDED", `Relay could not complete the mint and is refunding your payment. Relay request ${out.requestId}.`);
|
|
1748
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("BRIDGE_REFUNDED", `Relay could not complete the mint and is refunding your payment. Relay request ${out.requestId}.`);
|
|
2392
1749
|
}
|
|
2393
1750
|
if (status.status === "failure") {
|
|
2394
1751
|
const why = status.failReason ? ` (${status.failReason})` : "";
|
|
2395
1752
|
const noRefund = status.refundFailReason ? ` No automatic refund was sent. Contact support with Relay request ${out.requestId}.` : "";
|
|
2396
|
-
throw new MintError("BRIDGE_FAILED", `Relay could not complete the mint paid on ${where}${why}.${noRefund}`);
|
|
1753
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("BRIDGE_FAILED", `Relay could not complete the mint paid on ${where}${why}.${noRefund}`);
|
|
2397
1754
|
}
|
|
2398
|
-
const fillHash = status.txHashes[0]
|
|
1755
|
+
const fillHash = _nullishCoalesce(status.txHashes[0], () => ( null));
|
|
2399
1756
|
let tokens = [];
|
|
2400
1757
|
if (fillHash) {
|
|
2401
1758
|
try {
|
|
2402
1759
|
const receipt = await client.waitForTransactionReceipt({ hash: fillHash, confirmations: 1, timeout: 6e4 });
|
|
2403
1760
|
if (receiptOk(receipt.status)) {
|
|
2404
|
-
tokens = parseMintReceipt(receipt.logs
|
|
1761
|
+
tokens = _chunkGO4TR3HBcjs.parseMintReceipt.call(void 0, _nullishCoalesce(receipt.logs, () => ( [])), { tokenContract: attempt.tokenContract, recipient: attempt.recipient });
|
|
2405
1762
|
}
|
|
2406
|
-
} catch {
|
|
1763
|
+
} catch (e8) {
|
|
2407
1764
|
}
|
|
2408
1765
|
assertActive();
|
|
2409
1766
|
}
|
|
2410
|
-
const txHash = fillHash
|
|
1767
|
+
const txHash = _nullishCoalesce(fillHash, () => ( out.originTxHash));
|
|
2411
1768
|
const result = {
|
|
2412
1769
|
txHash,
|
|
2413
1770
|
explorerUrl: explorerUrlFor(fillHash ? cfg.chainId : out.originChainId, txHash),
|
|
2414
1771
|
tokens,
|
|
1772
|
+
requested: attempt.quantity,
|
|
2415
1773
|
relay: { requestId: out.requestId, originTxHash: out.originTxHash, originChainId: out.originChainId }
|
|
2416
1774
|
};
|
|
2417
1775
|
clearOutstanding(key);
|
|
@@ -2420,7 +1778,7 @@ function useMint(options) {
|
|
|
2420
1778
|
},
|
|
2421
1779
|
[clientFor, dispatch, emit]
|
|
2422
1780
|
);
|
|
2423
|
-
const executeRelayAttempt = (0,
|
|
1781
|
+
const executeRelayAttempt = _react.useCallback.call(void 0,
|
|
2424
1782
|
async (attempt, walletRead, life, account2) => {
|
|
2425
1783
|
const cfg = attempt.config;
|
|
2426
1784
|
const adapter = adapterFor(cfg);
|
|
@@ -2431,19 +1789,19 @@ function useMint(options) {
|
|
|
2431
1789
|
if (!mounted.current || life.controller.signal.aborted || lifeRef.current !== life || attemptRef.current !== attempt) {
|
|
2432
1790
|
throw new DOMException("Mint attempt cancelled", "AbortError");
|
|
2433
1791
|
}
|
|
2434
|
-
const live = getAccount();
|
|
1792
|
+
const live = _chunkGO4TR3HBcjs.getAccount.call(void 0, );
|
|
2435
1793
|
if (!live || live.address.toLowerCase() !== attempt.payer.toLowerCase()) {
|
|
2436
|
-
throw new MintError("USER_REJECTED", "The connected wallet changed before the transaction was sent.");
|
|
1794
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("USER_REJECTED", "The connected wallet changed before the transaction was sent.");
|
|
2437
1795
|
}
|
|
2438
1796
|
};
|
|
2439
1797
|
assertPayer();
|
|
2440
1798
|
if (account2.chainId !== origin) {
|
|
2441
1799
|
dispatch({ type: "SWITCHING_CHAIN", attemptId: attempt.attemptId });
|
|
2442
|
-
await switchToChain(origin);
|
|
1800
|
+
await _chunkGO4TR3HBcjs.switchToChain.call(void 0, origin);
|
|
2443
1801
|
}
|
|
2444
1802
|
assertPayer();
|
|
2445
1803
|
const plan = await adapter.buildPlan(ctx, attempt, walletRead);
|
|
2446
|
-
if (plan.approve) throw new MintError("BRIDGE_UNAVAILABLE", "Cross-chain mint supports native-priced drops only.");
|
|
1804
|
+
if (plan.approve) throw new (0, _chunkGO4TR3HBcjs.MintError)("BRIDGE_UNAVAILABLE", "Cross-chain mint supports native-priced drops only.");
|
|
2447
1805
|
assertPayer();
|
|
2448
1806
|
const quote = await getQuote({
|
|
2449
1807
|
testnet,
|
|
@@ -2456,18 +1814,18 @@ function useMint(options) {
|
|
|
2456
1814
|
signal: life.controller.signal
|
|
2457
1815
|
});
|
|
2458
1816
|
assertPayer();
|
|
2459
|
-
const balance = await getConnectedBalance(attempt.payer, origin);
|
|
1817
|
+
const balance = await _chunkGO4TR3HBcjs.getConnectedBalance.call(void 0, attempt.payer, origin);
|
|
2460
1818
|
if (balance < quote.amountIn.value + quote.originGas.value) {
|
|
2461
1819
|
const s = shortOf(origin);
|
|
2462
|
-
throw new MintError("INSUFFICIENT_FUNDS", `Not enough ${s.symbol} on ${s.name}. Pick another network to pay from.`);
|
|
1820
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("INSUFFICIENT_FUNDS", `Not enough ${s.symbol} on ${s.name}. Pick another network to pay from.`);
|
|
2463
1821
|
}
|
|
2464
1822
|
assertPayer();
|
|
2465
1823
|
const item = quote.items[0];
|
|
2466
1824
|
const key = outstandingKey(cfg, attempt.payer);
|
|
2467
|
-
const wallet2 = getWalletClient(origin);
|
|
1825
|
+
const wallet2 = _chunkGO4TR3HBcjs.getWalletClient.call(void 0, origin);
|
|
2468
1826
|
assertPayer();
|
|
2469
1827
|
if (!claimDeposit(key)) {
|
|
2470
|
-
throw new MintError("BRIDGE_UNAVAILABLE", "A cross-chain payment for this drop is already in progress. Try again once it finishes.");
|
|
1828
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("BRIDGE_UNAVAILABLE", "A cross-chain payment for this drop is already in progress. Try again once it finishes.");
|
|
2471
1829
|
}
|
|
2472
1830
|
let out;
|
|
2473
1831
|
try {
|
|
@@ -2479,7 +1837,7 @@ function useMint(options) {
|
|
|
2479
1837
|
data: item.data,
|
|
2480
1838
|
value: item.value,
|
|
2481
1839
|
...item.gas !== null && item.gas > 0n ? { gas: item.gas } : {},
|
|
2482
|
-
chain: getChain(origin)
|
|
1840
|
+
chain: _chunkGO4TR3HBcjs.getChain.call(void 0, origin)
|
|
2483
1841
|
});
|
|
2484
1842
|
out = { requestId: quote.requestId, testnet, originChainId: origin, originTxHash: originTxHash2, attempt };
|
|
2485
1843
|
setOutstanding(key, out);
|
|
@@ -2490,16 +1848,16 @@ function useMint(options) {
|
|
|
2490
1848
|
autoResumedRef.current.add(key);
|
|
2491
1849
|
dispatch({ type: "TX_SUBMITTED", attemptId: attempt.attemptId });
|
|
2492
1850
|
emit("tx-submitted", { state: "confirming", reason: null, txHash: originTxHash, quantity: attempt.quantity, chainId: cfg.chainId });
|
|
2493
|
-
const deposit = await waitForDeposit(origin, originTxHash);
|
|
1851
|
+
const deposit = await _chunkGO4TR3HBcjs.waitForDeposit.call(void 0, origin, originTxHash);
|
|
2494
1852
|
if (deposit === "reverted") {
|
|
2495
1853
|
clearOutstanding(key);
|
|
2496
|
-
throw new MintError("TX_REVERTED", `The payment transaction reverted (${originTxHash}).`);
|
|
1854
|
+
throw new (0, _chunkGO4TR3HBcjs.MintError)("TX_REVERTED", `The payment transaction reverted (${originTxHash}).`);
|
|
2497
1855
|
}
|
|
2498
1856
|
await finishRelay(attempt, out, life);
|
|
2499
1857
|
},
|
|
2500
1858
|
[ctxFor, dispatch, emit, finishRelay]
|
|
2501
1859
|
);
|
|
2502
|
-
const resumeOutstanding = (0,
|
|
1860
|
+
const resumeOutstanding = _react.useCallback.call(void 0,
|
|
2503
1861
|
async (out, life) => {
|
|
2504
1862
|
const attempt = Object.freeze({ ...out.attempt, attemptId: ++attemptIdRef.current });
|
|
2505
1863
|
attemptRef.current = attempt;
|
|
@@ -2510,7 +1868,7 @@ function useMint(options) {
|
|
|
2510
1868
|
await finishRelay(attempt, out, life);
|
|
2511
1869
|
} catch (e) {
|
|
2512
1870
|
if (!mounted.current || life.controller.signal.aborted || lifeRef.current !== life) return;
|
|
2513
|
-
const { reason, message } = toReason(e);
|
|
1871
|
+
const { reason, message } = _chunkGO4TR3HBcjs.toReason.call(void 0, e);
|
|
2514
1872
|
dispatch({ type: "ATTEMPT_FAILED", attemptId: attempt.attemptId, reason, message });
|
|
2515
1873
|
emit("error", { quantity: attempt.quantity, chainId: attempt.chainId });
|
|
2516
1874
|
} finally {
|
|
@@ -2519,7 +1877,7 @@ function useMint(options) {
|
|
|
2519
1877
|
},
|
|
2520
1878
|
[dispatch, emit, finishRelay]
|
|
2521
1879
|
);
|
|
2522
|
-
const runMint = (0,
|
|
1880
|
+
const runMint = _react.useCallback.call(void 0, async () => {
|
|
2523
1881
|
if (!mounted.current) return;
|
|
2524
1882
|
if (attemptRef.current !== null) return;
|
|
2525
1883
|
if (widgetFailRef.current) {
|
|
@@ -2531,31 +1889,31 @@ function useMint(options) {
|
|
|
2531
1889
|
return;
|
|
2532
1890
|
}
|
|
2533
1891
|
const s = stateRef.current;
|
|
2534
|
-
if (!canAct(s) || s.attempt !== null) return;
|
|
1892
|
+
if (!_chunkGO4TR3HBcjs.canAct.call(void 0, s) || s.attempt !== null) return;
|
|
2535
1893
|
if (s.name === "disconnected") {
|
|
2536
1894
|
if (connectingRef.current) return;
|
|
2537
1895
|
connectingRef.current = true;
|
|
2538
1896
|
dispatch({ type: "CONNECT_STARTED" });
|
|
2539
1897
|
const connectLife = lifeRef.current;
|
|
2540
|
-
const active = () => mounted.current && lifeRef.current === connectLife && !connectLife
|
|
1898
|
+
const active = () => mounted.current && lifeRef.current === connectLife && !_optionalChain([connectLife, 'optionalAccess', _61 => _61.controller, 'access', _62 => _62.signal, 'access', _63 => _63.aborted]);
|
|
2541
1899
|
try {
|
|
2542
1900
|
await widgetLoadRef.current;
|
|
2543
1901
|
if (!active()) return;
|
|
2544
|
-
const outcome = await openConnectModal();
|
|
1902
|
+
const outcome = await _chunkGO4TR3HBcjs.openConnectModal.call(void 0, );
|
|
2545
1903
|
if (!active()) return;
|
|
2546
1904
|
connectingRef.current = false;
|
|
2547
1905
|
if (outcome === "connected") {
|
|
2548
1906
|
accountKeyRef.current = null;
|
|
2549
|
-
pushAccountRef.current
|
|
1907
|
+
_optionalChain([pushAccountRef, 'access', _64 => _64.current, 'optionalCall', _65 => _65(_chunkGO4TR3HBcjs.getAccount.call(void 0, ))]);
|
|
2550
1908
|
} else dispatch({ type: "CONNECT_DISMISSED" });
|
|
2551
|
-
} catch {
|
|
1909
|
+
} catch (e9) {
|
|
2552
1910
|
if (active()) dispatch({ type: "CONNECT_DISMISSED" });
|
|
2553
1911
|
} finally {
|
|
2554
1912
|
connectingRef.current = false;
|
|
2555
1913
|
}
|
|
2556
1914
|
return;
|
|
2557
1915
|
}
|
|
2558
|
-
const payer = s.account
|
|
1916
|
+
const payer = _optionalChain([s, 'access', _66 => _66.account, 'optionalAccess', _67 => _67.address]);
|
|
2559
1917
|
const out = payer ? getOutstanding(outstandingKey(propsRef.current.config, payer)) : null;
|
|
2560
1918
|
if (out && lifeRef.current) {
|
|
2561
1919
|
await resumeOutstanding(out, lifeRef.current);
|
|
@@ -2567,7 +1925,7 @@ function useMint(options) {
|
|
|
2567
1925
|
if (life2) life2.gen = gen;
|
|
2568
1926
|
dispatch({ type: "RESET", gen });
|
|
2569
1927
|
dispatch({ type: "LOAD", gen, kind: "config" });
|
|
2570
|
-
if (life2) void
|
|
1928
|
+
if (life2) void readDrop3(life2, gen, propsRef.current.config);
|
|
2571
1929
|
return;
|
|
2572
1930
|
}
|
|
2573
1931
|
if (s.name !== "live") return;
|
|
@@ -2576,12 +1934,12 @@ function useMint(options) {
|
|
|
2576
1934
|
const life = lifeRef.current;
|
|
2577
1935
|
if (!account2 || !walletRead || !life) return;
|
|
2578
1936
|
const cfg = propsRef.current.config;
|
|
2579
|
-
const relayRoute = s.route
|
|
1937
|
+
const relayRoute = _optionalChain([s, 'access', _68 => _68.route, 'optionalAccess', _69 => _69.kind]) === "relay" ? s.route : null;
|
|
2580
1938
|
const attempt = Object.freeze({
|
|
2581
1939
|
attemptId: ++attemptIdRef.current,
|
|
2582
1940
|
config: structuredClone(cfg),
|
|
2583
1941
|
payer: account2.address,
|
|
2584
|
-
recipient: propsRef.current.recipient
|
|
1942
|
+
recipient: _nullishCoalesce(propsRef.current.recipient, () => ( account2.address)),
|
|
2585
1943
|
quantity: s.quantity,
|
|
2586
1944
|
chainId: cfg.chainId,
|
|
2587
1945
|
tokenContract: tokenContractOf(cfg),
|
|
@@ -2595,51 +1953,51 @@ function useMint(options) {
|
|
|
2595
1953
|
else await executeAttempt(attempt, walletRead, life, account2);
|
|
2596
1954
|
} catch (e) {
|
|
2597
1955
|
if (!mounted.current || life.controller.signal.aborted || lifeRef.current !== life) return;
|
|
2598
|
-
const { reason, message } = toReason(e);
|
|
1956
|
+
const { reason, message } = _chunkGO4TR3HBcjs.toReason.call(void 0, e);
|
|
2599
1957
|
dispatch({ type: "ATTEMPT_FAILED", attemptId: attempt.attemptId, reason, message });
|
|
2600
1958
|
emit("error", { quantity: attempt.quantity, chainId: attempt.chainId });
|
|
2601
1959
|
} finally {
|
|
2602
1960
|
attemptRef.current = null;
|
|
2603
1961
|
}
|
|
2604
|
-
}, [dispatch, emit,
|
|
2605
|
-
const mint = (0,
|
|
1962
|
+
}, [dispatch, emit, readDrop3, executeAttempt, executeRelayAttempt, resumeOutstanding, refreshNow]);
|
|
1963
|
+
const mint = _react.useCallback.call(void 0, () => {
|
|
2606
1964
|
void runMint();
|
|
2607
1965
|
}, [runMint]);
|
|
2608
|
-
(0,
|
|
1966
|
+
_react.useEffect.call(void 0, () => {
|
|
2609
1967
|
mounted.current = true;
|
|
2610
1968
|
return () => {
|
|
2611
1969
|
mounted.current = false;
|
|
2612
|
-
lifeRef.current
|
|
1970
|
+
_optionalChain([lifeRef, 'access', _70 => _70.current, 'optionalAccess', _71 => _71.controller, 'access', _72 => _72.abort, 'call', _73 => _73()]);
|
|
2613
1971
|
lifeRef.current = null;
|
|
2614
1972
|
};
|
|
2615
1973
|
}, []);
|
|
2616
|
-
(0,
|
|
1974
|
+
_react.useEffect.call(void 0, () => {
|
|
2617
1975
|
const push = (a) => {
|
|
2618
|
-
const key = a ? `${a.address.toLowerCase()}:${a.chainId}:${(propsRef.current.recipient
|
|
1976
|
+
const key = a ? `${a.address.toLowerCase()}:${a.chainId}:${(_nullishCoalesce(propsRef.current.recipient, () => ( ""))).toLowerCase()}` : "null";
|
|
2619
1977
|
if (key === accountKeyRef.current) return;
|
|
2620
1978
|
accountKeyRef.current = key;
|
|
2621
1979
|
if (attemptRef.current || stateRef.current.attempt) pendingRefreshRef.current = true;
|
|
2622
1980
|
dispatch({ type: "ACCOUNT_CHANGED", account: a });
|
|
2623
1981
|
};
|
|
2624
1982
|
pushAccountRef.current = push;
|
|
2625
|
-
push(getAccount());
|
|
2626
|
-
const unsubscribe = subscribeAccount(push);
|
|
1983
|
+
push(_chunkGO4TR3HBcjs.getAccount.call(void 0, ));
|
|
1984
|
+
const unsubscribe = _chunkGO4TR3HBcjs.subscribeAccount.call(void 0, push);
|
|
2627
1985
|
return () => {
|
|
2628
1986
|
unsubscribe();
|
|
2629
1987
|
};
|
|
2630
1988
|
}, [dispatch]);
|
|
2631
|
-
const recipientRef = (0,
|
|
2632
|
-
(0,
|
|
1989
|
+
const recipientRef = _react.useRef.call(void 0, recipient);
|
|
1990
|
+
_react.useEffect.call(void 0, () => {
|
|
2633
1991
|
if (isBusy() || recipientRef.current === recipient) return;
|
|
2634
1992
|
recipientRef.current = recipient;
|
|
2635
1993
|
accountKeyRef.current = null;
|
|
2636
|
-
pushAccountRef.current
|
|
1994
|
+
_optionalChain([pushAccountRef, 'access', _74 => _74.current, 'optionalCall', _75 => _75(_chunkGO4TR3HBcjs.getAccount.call(void 0, ))]);
|
|
2637
1995
|
}, [recipient, machine.attempt, isBusy]);
|
|
2638
|
-
const projectId = connect
|
|
1996
|
+
const projectId = _optionalChain([connect, 'optionalAccess', _76 => _76.walletConnectProjectId]);
|
|
2639
1997
|
const widgetChains = [config.chainId, ...payChainsOf(config, options.crossChain).filter((id) => id !== config.chainId)].join(",");
|
|
2640
|
-
(0,
|
|
1998
|
+
_react.useEffect.call(void 0, () => {
|
|
2641
1999
|
let alive = true;
|
|
2642
|
-
const loading = loadConnectWidget({ chainIds: widgetChains.split(",").map(Number), ...projectId ? { walletConnectProjectId: projectId } : {} });
|
|
2000
|
+
const loading = _chunkGO4TR3HBcjs.loadConnectWidget.call(void 0, { chainIds: widgetChains.split(",").map(Number), ...projectId ? { walletConnectProjectId: projectId } : {} });
|
|
2643
2001
|
widgetLoadRef.current = loading;
|
|
2644
2002
|
loading.then(
|
|
2645
2003
|
() => {
|
|
@@ -2647,7 +2005,7 @@ function useMint(options) {
|
|
|
2647
2005
|
},
|
|
2648
2006
|
(e) => {
|
|
2649
2007
|
if (!alive) return;
|
|
2650
|
-
const { reason, message } = toReason(e);
|
|
2008
|
+
const { reason, message } = _chunkGO4TR3HBcjs.toReason.call(void 0, e);
|
|
2651
2009
|
setWidgetFail({ reason, message });
|
|
2652
2010
|
}
|
|
2653
2011
|
);
|
|
@@ -2655,7 +2013,7 @@ function useMint(options) {
|
|
|
2655
2013
|
alive = false;
|
|
2656
2014
|
};
|
|
2657
2015
|
}, [widgetChains, projectId, widgetRetry]);
|
|
2658
|
-
(0,
|
|
2016
|
+
_react.useEffect.call(void 0, () => {
|
|
2659
2017
|
if (!mounted.current) return;
|
|
2660
2018
|
if (isBusy()) return;
|
|
2661
2019
|
if (pendingQuantityRef.current !== null) {
|
|
@@ -2663,16 +2021,16 @@ function useMint(options) {
|
|
|
2663
2021
|
pendingQuantityRef.current = null;
|
|
2664
2022
|
dispatch({ type: "SET_QUANTITY", quantity });
|
|
2665
2023
|
}
|
|
2666
|
-
if (lifeRef.current
|
|
2024
|
+
if (_optionalChain([lifeRef, 'access', _77 => _77.current, 'optionalAccess', _78 => _78.key]) !== configKey) {
|
|
2667
2025
|
pendingRefreshRef.current = false;
|
|
2668
2026
|
startLifetime(configKey, config);
|
|
2669
|
-
} else if (pendingRefreshRef.current || lifeRef.current.rpcUrl !== options.rpcUrls
|
|
2027
|
+
} else if (pendingRefreshRef.current || lifeRef.current.rpcUrl !== _optionalChain([options, 'access', _79 => _79.rpcUrls, 'optionalAccess', _80 => _80[config.chainId]])) {
|
|
2670
2028
|
pendingRefreshRef.current = false;
|
|
2671
2029
|
void refreshNow();
|
|
2672
2030
|
}
|
|
2673
2031
|
});
|
|
2674
2032
|
const resumeKey = machine.account ? outstandingKey(config, machine.account.address) : null;
|
|
2675
|
-
(0,
|
|
2033
|
+
_react.useEffect.call(void 0, () => {
|
|
2676
2034
|
if (!resumeKey || autoResumedRef.current.has(resumeKey) || attemptRef.current !== null || isBusy()) return;
|
|
2677
2035
|
const out = getOutstanding(resumeKey);
|
|
2678
2036
|
const life = lifeRef.current;
|
|
@@ -2680,15 +2038,15 @@ function useMint(options) {
|
|
|
2680
2038
|
autoResumedRef.current.add(resumeKey);
|
|
2681
2039
|
void resumeOutstanding(out, life);
|
|
2682
2040
|
}, [resumeKey, machine.attempt, isBusy, resumeOutstanding]);
|
|
2683
|
-
const routeOptionsKey = `${String(options.payChainId
|
|
2684
|
-
const previousRouteOptions = (0,
|
|
2685
|
-
(0,
|
|
2041
|
+
const routeOptionsKey = `${String(_nullishCoalesce(options.payChainId, () => ( "")))}|${JSON.stringify(_nullishCoalesce(options.crossChain, () => ( null)))}`;
|
|
2042
|
+
const previousRouteOptions = _react.useRef.call(void 0, routeOptionsKey);
|
|
2043
|
+
_react.useEffect.call(void 0, () => {
|
|
2686
2044
|
if (previousRouteOptions.current === routeOptionsKey || isBusy()) return;
|
|
2687
2045
|
previousRouteOptions.current = routeOptionsKey;
|
|
2688
2046
|
if (stateRef.current.account) dispatch({ type: "ACCOUNT_CHANGED", account: stateRef.current.account });
|
|
2689
2047
|
}, [routeOptionsKey, machine.attempt, dispatch, isBusy]);
|
|
2690
|
-
const previousQuantity = (0,
|
|
2691
|
-
(0,
|
|
2048
|
+
const previousQuantity = _react.useRef.call(void 0, machine.quantity);
|
|
2049
|
+
_react.useEffect.call(void 0, () => {
|
|
2692
2050
|
if (previousQuantity.current === machine.quantity || isBusy()) return;
|
|
2693
2051
|
previousQuantity.current = machine.quantity;
|
|
2694
2052
|
if (stateRef.current.walletRead) dispatch({ type: "ACCOUNT_CHANGED", account: stateRef.current.account });
|
|
@@ -2696,11 +2054,11 @@ function useMint(options) {
|
|
|
2696
2054
|
const loadedDrop = machine.drop;
|
|
2697
2055
|
const walletGen = machine.walletGen;
|
|
2698
2056
|
const account = machine.account;
|
|
2699
|
-
const lastWalletRead = (0,
|
|
2700
|
-
(0,
|
|
2057
|
+
const lastWalletRead = _react.useRef.call(void 0, null);
|
|
2058
|
+
_react.useEffect.call(void 0, () => {
|
|
2701
2059
|
if (!account || !loadedDrop || isBusy()) return;
|
|
2702
2060
|
const previous = lastWalletRead.current;
|
|
2703
|
-
if (stateRef.current.blocked && previous
|
|
2061
|
+
if (stateRef.current.blocked && _optionalChain([previous, 'optionalAccess', _81 => _81.drop]) === loadedDrop && previous.gen === walletGen && previous.quantity === machine.quantity) return;
|
|
2704
2062
|
lastWalletRead.current = { drop: loadedDrop, gen: walletGen, quantity: machine.quantity };
|
|
2705
2063
|
const life = lifeRef.current;
|
|
2706
2064
|
const drop = stateRef.current.drop;
|
|
@@ -2713,15 +2071,15 @@ function useMint(options) {
|
|
|
2713
2071
|
try {
|
|
2714
2072
|
const read = await adapter.readWallet(ctxFor(life, cfg), cfg, {
|
|
2715
2073
|
payer: account.address,
|
|
2716
|
-
recipient: propsRef.current.recipient
|
|
2074
|
+
recipient: _nullishCoalesce(propsRef.current.recipient, () => ( account.address)),
|
|
2717
2075
|
quantity: stateRef.current.quantity,
|
|
2718
2076
|
drop
|
|
2719
2077
|
});
|
|
2720
2078
|
if (!alive || life.controller.signal.aborted || lifeRef.current !== life || life.gen !== readGen) return;
|
|
2721
|
-
const ineligible = read.ineligible
|
|
2079
|
+
const ineligible = _optionalChain([read, 'access', _82 => _82.ineligible, 'optionalAccess', _83 => _83.reason]) === "SIMULATION_REVERTED" ? { ...read.ineligible, message: _chunkGO4TR3HBcjs.friendlyErrorMessage.call(void 0, new (0, _chunkGO4TR3HBcjs.MintError)("SIMULATION_REVERTED", read.ineligible.message)) } : read.ineligible;
|
|
2722
2080
|
const fullRead = { ...read, ineligible };
|
|
2723
2081
|
const payChains = payChainsOf(cfg, propsRef.current.crossChain);
|
|
2724
|
-
const crossChain = payChains.length > 0 && ineligible === null && (adapter.supportsRelay
|
|
2082
|
+
const crossChain = payChains.length > 0 && ineligible === null && (_nullishCoalesce(_optionalChain([adapter, 'access', _84 => _84.supportsRelay, 'optionalCall', _85 => _85(drop)]), () => ( false)));
|
|
2725
2083
|
const routeChain = routeChainOf(payChains, account.chainId, propsRef.current.payChainId);
|
|
2726
2084
|
const routePending = crossChain && routeChain !== cfg.chainId && payChains.includes(routeChain);
|
|
2727
2085
|
dispatch({ type: "WALLET_LOADED", gen: walletGen, read: fullRead, crossChain, routePending });
|
|
@@ -2729,7 +2087,7 @@ function useMint(options) {
|
|
|
2729
2087
|
setCrossChainInfo(null);
|
|
2730
2088
|
return;
|
|
2731
2089
|
}
|
|
2732
|
-
const recipientAddr = propsRef.current.recipient
|
|
2090
|
+
const recipientAddr = _nullishCoalesce(propsRef.current.recipient, () => ( account.address));
|
|
2733
2091
|
const draft = {
|
|
2734
2092
|
attemptId: 0,
|
|
2735
2093
|
config: cfg,
|
|
@@ -2744,7 +2102,7 @@ function useMint(options) {
|
|
|
2744
2102
|
let tx;
|
|
2745
2103
|
try {
|
|
2746
2104
|
tx = (await adapter.buildPlan(ctxFor(life, cfg), draft, fullRead)).mint;
|
|
2747
|
-
} catch {
|
|
2105
|
+
} catch (e10) {
|
|
2748
2106
|
if (!alive) return;
|
|
2749
2107
|
setCrossChainInfo(null);
|
|
2750
2108
|
if (routePending) dispatch({ type: "ROUTE_LOADED", gen: walletGen, route: { kind: "direct", chainId: cfg.chainId }, short: null });
|
|
@@ -2766,11 +2124,11 @@ function useMint(options) {
|
|
|
2766
2124
|
if (routeChain !== account.chainId) {
|
|
2767
2125
|
route = relay;
|
|
2768
2126
|
} else {
|
|
2769
|
-
const balance = await getConnectedBalance(account.address, routeChain);
|
|
2127
|
+
const balance = await _chunkGO4TR3HBcjs.getConnectedBalance.call(void 0, account.address, routeChain);
|
|
2770
2128
|
if (balance >= quote.amountIn.value + quote.originGas.value) route = relay;
|
|
2771
2129
|
else short = shortOf(routeChain);
|
|
2772
2130
|
}
|
|
2773
|
-
} catch {
|
|
2131
|
+
} catch (e11) {
|
|
2774
2132
|
}
|
|
2775
2133
|
if (!alive || life.controller.signal.aborted || lifeRef.current !== life) return;
|
|
2776
2134
|
dispatch({ type: "ROUTE_LOADED", gen: walletGen, route: short ? null : route, short });
|
|
@@ -2783,8 +2141,8 @@ function useMint(options) {
|
|
|
2783
2141
|
alive = false;
|
|
2784
2142
|
};
|
|
2785
2143
|
}, [account, loadedDrop, walletGen, machine.quantity, machine.attempt, ctxFor, dispatch, isBusy]);
|
|
2786
|
-
const prevQuantityProp = (0,
|
|
2787
|
-
(0,
|
|
2144
|
+
const prevQuantityProp = _react.useRef.call(void 0, quantityProp);
|
|
2145
|
+
_react.useEffect.call(void 0, () => {
|
|
2788
2146
|
if (isBusy()) return;
|
|
2789
2147
|
const propChanged = prevQuantityProp.current !== quantityProp;
|
|
2790
2148
|
prevQuantityProp.current = quantityProp;
|
|
@@ -2792,11 +2150,11 @@ function useMint(options) {
|
|
|
2792
2150
|
const state = stateRef.current;
|
|
2793
2151
|
if (!propChanged && state.account && !state.walletRead) return;
|
|
2794
2152
|
const event = { type: "SET_QUANTITY", quantity: quantityProp };
|
|
2795
|
-
const clamped = reducer(state, event).quantity;
|
|
2153
|
+
const clamped = _chunkGO4TR3HBcjs.reducer.call(void 0, state, event).quantity;
|
|
2796
2154
|
if (clamped !== state.quantity) dispatch(event);
|
|
2797
|
-
if (clamped !== quantityProp) propsRef.current.onQuantityChange
|
|
2155
|
+
if (clamped !== quantityProp) _optionalChain([propsRef, 'access', _86 => _86.current, 'access', _87 => _87.onQuantityChange, 'optionalCall', _88 => _88(clamped)]);
|
|
2798
2156
|
}, [quantityProp, machine.quantity, machine.drop, machine.walletRead, machine.attempt, dispatch, isBusy]);
|
|
2799
|
-
(0,
|
|
2157
|
+
_react.useEffect.call(void 0, () => {
|
|
2800
2158
|
const timer = setInterval(() => {
|
|
2801
2159
|
if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
|
|
2802
2160
|
void refreshNow("refresh");
|
|
@@ -2810,29 +2168,29 @@ function useMint(options) {
|
|
|
2810
2168
|
document.removeEventListener("visibilitychange", onVisible);
|
|
2811
2169
|
};
|
|
2812
2170
|
}, [refreshNow]);
|
|
2813
|
-
const boundary = machine.drop ? [machine.drop.startTime, machine.drop.endTime].some((t) => t !== null && t > machine.now) : false;
|
|
2814
|
-
(0,
|
|
2171
|
+
const boundary = machine.drop ? [machine.drop.startTime, machine.drop.endTime, _nullishCoalesce(machine.drop.phaseEndsAt, () => ( null))].some((t) => t !== null && t > machine.now) : false;
|
|
2172
|
+
_react.useEffect.call(void 0, () => {
|
|
2815
2173
|
if (!boundary) return;
|
|
2816
2174
|
const timer = setInterval(() => {
|
|
2817
2175
|
const s = stateRef.current;
|
|
2818
2176
|
const now = nowSec();
|
|
2819
|
-
const crossed = s.drop && [s.drop.startTime, s.drop.endTime].some((t) => t !== null && t > s.now && t <= now);
|
|
2177
|
+
const crossed = s.drop && [s.drop.startTime, s.drop.endTime, _nullishCoalesce(s.drop.phaseEndsAt, () => ( null))].some((t) => t !== null && t > s.now && t <= now);
|
|
2820
2178
|
dispatch({ type: "TICK", now });
|
|
2821
2179
|
if (crossed) void refreshNow();
|
|
2822
2180
|
}, TICK_MS);
|
|
2823
2181
|
return () => clearInterval(timer);
|
|
2824
2182
|
}, [boundary, dispatch, refreshNow]);
|
|
2825
|
-
const prevName = (0,
|
|
2826
|
-
(0,
|
|
2183
|
+
const prevName = _react.useRef.call(void 0, null);
|
|
2184
|
+
_react.useEffect.call(void 0, () => {
|
|
2827
2185
|
const name = widgetFail ? isUnsupported(widgetFail.reason) ? "unsupported" : "error" : machine.name;
|
|
2828
2186
|
if (prevName.current === name) return;
|
|
2829
2187
|
prevName.current = name;
|
|
2830
|
-
emit("state", { state: name, reason: widgetFail
|
|
2188
|
+
emit("state", { state: name, reason: _nullishCoalesce(_optionalChain([widgetFail, 'optionalAccess', _89 => _89.reason]), () => ( machine.reason)) });
|
|
2831
2189
|
}, [machine.name, machine.reason, widgetFail, emit]);
|
|
2832
|
-
const setQuantity = (0,
|
|
2190
|
+
const setQuantity = _react.useCallback.call(void 0,
|
|
2833
2191
|
(next) => {
|
|
2834
2192
|
const s = stateRef.current;
|
|
2835
|
-
const max = selectMaxQuantity(s)
|
|
2193
|
+
const max = _nullishCoalesce(_chunkGO4TR3HBcjs.selectMaxQuantity.call(void 0, s), () => ( 65535));
|
|
2836
2194
|
const clamped = Math.max(1, Math.min(Math.floor(Number.isNaN(next) ? 1 : next), max));
|
|
2837
2195
|
const handler = propsRef.current.onQuantityChange;
|
|
2838
2196
|
if (handler) {
|
|
@@ -2854,7 +2212,7 @@ function useMint(options) {
|
|
|
2854
2212
|
const wallet = machine.account && machine.walletRead ? {
|
|
2855
2213
|
address: machine.account.address,
|
|
2856
2214
|
chainId: machine.account.chainId,
|
|
2857
|
-
recipient: recipient
|
|
2215
|
+
recipient: _nullishCoalesce(recipient, () => ( machine.account.address)),
|
|
2858
2216
|
walletMinted: machine.walletRead.walletMinted,
|
|
2859
2217
|
walletMax: machine.walletRead.walletMax,
|
|
2860
2218
|
allowlistRemaining: machine.walletRead.allowlistRemaining
|
|
@@ -2867,46 +2225,46 @@ function useMint(options) {
|
|
|
2867
2225
|
wallet,
|
|
2868
2226
|
quantity: machine.quantity,
|
|
2869
2227
|
setQuantity,
|
|
2870
|
-
maxQuantity: selectMaxQuantity(machine),
|
|
2871
|
-
total: selectTotal(machine),
|
|
2228
|
+
maxQuantity: _chunkGO4TR3HBcjs.selectMaxQuantity.call(void 0, machine),
|
|
2229
|
+
total: _chunkGO4TR3HBcjs.selectTotal.call(void 0, machine),
|
|
2872
2230
|
mint,
|
|
2873
2231
|
result: machine.result,
|
|
2874
2232
|
refresh,
|
|
2875
2233
|
// An attempt claimed by a click is not clickable, even while the reducer still reads 'live'.
|
|
2876
|
-
canAct: canAct({ ...machine, name: effective.name }) && machine.attempt === null,
|
|
2234
|
+
canAct: _chunkGO4TR3HBcjs.canAct.call(void 0, { ...machine, name: effective.name }) && machine.attempt === null,
|
|
2877
2235
|
// Short on the wallet chain is neither route: nothing can be paid until the collector picks another chain.
|
|
2878
|
-
route: machine.route
|
|
2879
|
-
crossChain: machine.crossChain && machine.account && crossChainInfo
|
|
2236
|
+
route: _nullishCoalesce(machine.route, () => ( (machine.walletRead && machine.drop && !machine.routePending && machine.short === null ? { kind: "direct", chainId: machine.drop.chainId } : null))),
|
|
2237
|
+
crossChain: machine.crossChain && machine.account && _optionalChain([crossChainInfo, 'optionalAccess', _90 => _90.gen]) === machine.walletGen ? crossChainInfo.info : null
|
|
2880
2238
|
};
|
|
2881
2239
|
}
|
|
2882
2240
|
|
|
2883
2241
|
// src/react/PayWithPicker.ts
|
|
2884
|
-
|
|
2885
|
-
|
|
2242
|
+
|
|
2243
|
+
|
|
2886
2244
|
var PICKER_REFRESH_MS = 2e4;
|
|
2887
2245
|
var PICKER_DEBOUNCE_MS = 500;
|
|
2888
2246
|
var RELAY_REASONS = /* @__PURE__ */ new Set(["BRIDGE_UNAVAILABLE", "BRIDGE_TIMEOUT", "BRIDGE_REFUNDED", "BRIDGE_FAILED"]);
|
|
2889
|
-
var
|
|
2890
|
-
const c = getChain(chainId).nativeCurrency;
|
|
2891
|
-
return { value, decimals: c.decimals, symbol: c.symbol, formatted: (0,
|
|
2247
|
+
var money3 = (value, chainId) => {
|
|
2248
|
+
const c = _chunkGO4TR3HBcjs.getChain.call(void 0, chainId).nativeCurrency;
|
|
2249
|
+
return { value, decimals: c.decimals, symbol: c.symbol, formatted: _viem.formatUnits.call(void 0, value, c.decimals) };
|
|
2892
2250
|
};
|
|
2893
2251
|
function usePayOptions(mint, onSelect) {
|
|
2894
2252
|
const info = mint.crossChain;
|
|
2895
|
-
const current = mint.wallet
|
|
2896
|
-
const [quotes, setQuotes] = (0,
|
|
2897
|
-
const [balance, setBalance] = (0,
|
|
2898
|
-
const [tick, setTick] = (0,
|
|
2899
|
-
(0,
|
|
2253
|
+
const current = _nullishCoalesce(_optionalChain([mint, 'access', _91 => _91.wallet, 'optionalAccess', _92 => _92.chainId]), () => ( null));
|
|
2254
|
+
const [quotes, setQuotes] = _react.useState.call(void 0, {});
|
|
2255
|
+
const [balance, setBalance] = _react.useState.call(void 0, null);
|
|
2256
|
+
const [tick, setTick] = _react.useState.call(void 0, 0);
|
|
2257
|
+
_react.useEffect.call(void 0, () => {
|
|
2900
2258
|
const t = setInterval(() => setTick((n) => n + 1), PICKER_REFRESH_MS);
|
|
2901
2259
|
return () => clearInterval(t);
|
|
2902
2260
|
}, []);
|
|
2903
2261
|
const key = info ? `${info.tx.to}:${info.tx.value}:${info.tx.data}:${info.payer}:${info.recipient}:${info.payChains.join()}` : "";
|
|
2904
|
-
const [quotedKey, setQuotedKey] = (0,
|
|
2262
|
+
const [quotedKey, setQuotedKey] = _react.useState.call(void 0, key);
|
|
2905
2263
|
if (quotedKey !== key) {
|
|
2906
2264
|
setQuotedKey(key);
|
|
2907
2265
|
setQuotes({});
|
|
2908
2266
|
}
|
|
2909
|
-
(0,
|
|
2267
|
+
_react.useEffect.call(void 0, () => {
|
|
2910
2268
|
if (!info) return;
|
|
2911
2269
|
const controller = new AbortController();
|
|
2912
2270
|
const timer = setTimeout(() => {
|
|
@@ -2917,7 +2275,7 @@ function usePayOptions(mint, onSelect) {
|
|
|
2917
2275
|
if (!controller.signal.aborted) setQuotes((prev) => ({ ...prev, [chainId]: { relayFee: q.relayFee, amountIn: q.amountIn } }));
|
|
2918
2276
|
},
|
|
2919
2277
|
(e) => {
|
|
2920
|
-
if (controller.signal.aborted || e
|
|
2278
|
+
if (controller.signal.aborted || _optionalChain([e, 'optionalAccess', _93 => _93.reason]) === "RATE_LIMITED") return;
|
|
2921
2279
|
setQuotes((prev) => ({ ...prev, [chainId]: "failed" }));
|
|
2922
2280
|
}
|
|
2923
2281
|
);
|
|
@@ -2928,10 +2286,10 @@ function usePayOptions(mint, onSelect) {
|
|
|
2928
2286
|
controller.abort();
|
|
2929
2287
|
};
|
|
2930
2288
|
}, [key, tick]);
|
|
2931
|
-
(0,
|
|
2289
|
+
_react.useEffect.call(void 0, () => {
|
|
2932
2290
|
if (!info || current === null || !mint.wallet) return;
|
|
2933
2291
|
let alive = true;
|
|
2934
|
-
getConnectedBalance(mint.wallet.address, current).then(
|
|
2292
|
+
_chunkGO4TR3HBcjs.getConnectedBalance.call(void 0, mint.wallet.address, current).then(
|
|
2935
2293
|
(value) => {
|
|
2936
2294
|
if (alive) setBalance({ chainId: current, value });
|
|
2937
2295
|
},
|
|
@@ -2942,12 +2300,12 @@ function usePayOptions(mint, onSelect) {
|
|
|
2942
2300
|
return () => {
|
|
2943
2301
|
alive = false;
|
|
2944
2302
|
};
|
|
2945
|
-
}, [current, mint.wallet
|
|
2946
|
-
const select = (0,
|
|
2303
|
+
}, [current, _optionalChain([mint, 'access', _94 => _94.wallet, 'optionalAccess', _95 => _95.address]), key, tick]);
|
|
2304
|
+
const select = _react.useCallback.call(void 0,
|
|
2947
2305
|
(chainId) => {
|
|
2948
|
-
switchToChain(chainId).then(
|
|
2949
|
-
() => onSelect
|
|
2950
|
-
(e) => onSelect
|
|
2306
|
+
_chunkGO4TR3HBcjs.switchToChain.call(void 0, chainId).then(
|
|
2307
|
+
() => _optionalChain([onSelect, 'optionalCall', _96 => _96(chainId, null)]),
|
|
2308
|
+
(e) => _optionalChain([onSelect, 'optionalCall', _97 => _97(chainId, e)])
|
|
2951
2309
|
);
|
|
2952
2310
|
},
|
|
2953
2311
|
[onSelect]
|
|
@@ -2959,12 +2317,12 @@ function usePayOptions(mint, onSelect) {
|
|
|
2959
2317
|
const quoted = q && q !== "failed" ? q : null;
|
|
2960
2318
|
return {
|
|
2961
2319
|
chainId,
|
|
2962
|
-
name: chainName(chainId),
|
|
2320
|
+
name: _chunkGO4TR3HBcjs.chainName.call(void 0, chainId),
|
|
2963
2321
|
selected: chainId === current,
|
|
2964
2322
|
isDropChain,
|
|
2965
|
-
relayFee: isDropChain ? null : quoted
|
|
2966
|
-
amountIn: isDropChain ? null : quoted
|
|
2967
|
-
balance: balance && balance.chainId === chainId && chainId === current ?
|
|
2323
|
+
relayFee: isDropChain ? null : _nullishCoalesce(_optionalChain([quoted, 'optionalAccess', _98 => _98.relayFee]), () => ( null)),
|
|
2324
|
+
amountIn: isDropChain ? null : _nullishCoalesce(_optionalChain([quoted, 'optionalAccess', _99 => _99.amountIn]), () => ( null)),
|
|
2325
|
+
balance: balance && balance.chainId === chainId && chainId === current ? money3(balance.value, chainId) : null,
|
|
2968
2326
|
loading: !isDropChain && q === void 0,
|
|
2969
2327
|
select: () => select(chainId)
|
|
2970
2328
|
};
|
|
@@ -2979,11 +2337,11 @@ function PayWithPicker(props) {
|
|
|
2979
2337
|
const rows = usePayOptions(props.mint, props.onSelect);
|
|
2980
2338
|
if (rows.length === 0) return null;
|
|
2981
2339
|
const open = props.mint.state === "insufficient-funds" || props.mint.reason !== null && RELAY_REASONS.has(props.mint.reason);
|
|
2982
|
-
return (0,
|
|
2340
|
+
return _react.createElement.call(void 0,
|
|
2983
2341
|
"div",
|
|
2984
2342
|
{ className: props.className, role: "group", "aria-label": "Pay with", "data-open": open ? "true" : "false" },
|
|
2985
2343
|
rows.map(
|
|
2986
|
-
(row) => (0,
|
|
2344
|
+
(row) => _react.createElement.call(void 0,
|
|
2987
2345
|
"button",
|
|
2988
2346
|
{
|
|
2989
2347
|
key: row.chainId,
|
|
@@ -3003,16 +2361,16 @@ function PayWithPicker(props) {
|
|
|
3003
2361
|
}
|
|
3004
2362
|
|
|
3005
2363
|
// src/react/MintButton.ts
|
|
3006
|
-
|
|
2364
|
+
|
|
3007
2365
|
function defaultLabel(m) {
|
|
3008
|
-
const symbol = m.total
|
|
2366
|
+
const symbol = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([m, 'access', _100 => _100.total, 'optionalAccess', _101 => _101.erc20, 'optionalAccess', _102 => _102.symbol]), () => ( _optionalChain([m, 'access', _103 => _103.total, 'optionalAccess', _104 => _104.native, 'access', _105 => _105.symbol]))), () => ( _optionalChain([m, 'access', _106 => _106.drop, 'optionalAccess', _107 => _107.unitPrice, 'access', _108 => _108.symbol]))), () => ( ""));
|
|
3009
2367
|
switch (m.state) {
|
|
3010
2368
|
case "loading":
|
|
3011
2369
|
return "Loading\u2026";
|
|
3012
2370
|
case "unsupported":
|
|
3013
2371
|
return "Unavailable";
|
|
3014
2372
|
case "upcoming": {
|
|
3015
|
-
const t = m.drop
|
|
2373
|
+
const t = _optionalChain([m, 'access', _109 => _109.drop, 'optionalAccess', _110 => _110.startTime]);
|
|
3016
2374
|
return `Starts ${t ? new Date(t * 1e3).toLocaleString() : "soon"}`;
|
|
3017
2375
|
}
|
|
3018
2376
|
case "ended":
|
|
@@ -3025,8 +2383,8 @@ function defaultLabel(m) {
|
|
|
3025
2383
|
return "Connecting\u2026";
|
|
3026
2384
|
case "live": {
|
|
3027
2385
|
const route = m.route;
|
|
3028
|
-
if (route
|
|
3029
|
-
return `Mint \xB7 ${route.amountIn.formatted} ${route.amountIn.symbol} on ${chainName(route.originChainId)}`;
|
|
2386
|
+
if (_optionalChain([route, 'optionalAccess', _111 => _111.kind]) === "relay") {
|
|
2387
|
+
return `Mint \xB7 ${route.amountIn.formatted} ${route.amountIn.symbol} on ${_chunkGO4TR3HBcjs.chainName.call(void 0, route.originChainId)}`;
|
|
3030
2388
|
}
|
|
3031
2389
|
const total = m.total;
|
|
3032
2390
|
if (!total) return "Mint";
|
|
@@ -3036,8 +2394,8 @@ function defaultLabel(m) {
|
|
|
3036
2394
|
case "ineligible":
|
|
3037
2395
|
return "Not eligible";
|
|
3038
2396
|
case "insufficient-funds": {
|
|
3039
|
-
const erc20 = m.total
|
|
3040
|
-
const shortage = erc20 && m.message === `Not enough ${erc20.symbol} to cover the mint.` ? erc20.symbol : m.total
|
|
2397
|
+
const erc20 = _optionalChain([m, 'access', _112 => _112.total, 'optionalAccess', _113 => _113.erc20]);
|
|
2398
|
+
const shortage = erc20 && m.message === `Not enough ${erc20.symbol} to cover the mint.` ? erc20.symbol : _nullishCoalesce(_optionalChain([m, 'access', _114 => _114.total, 'optionalAccess', _115 => _115.native, 'access', _116 => _116.symbol]), () => ( symbol));
|
|
3041
2399
|
return `Insufficient ${shortage}`.trimEnd();
|
|
3042
2400
|
}
|
|
3043
2401
|
case "switching-chain":
|
|
@@ -3058,8 +2416,8 @@ function MintButton(props) {
|
|
|
3058
2416
|
const { className, labels, children, ...options } = props;
|
|
3059
2417
|
const m = useMint(options);
|
|
3060
2418
|
if (typeof children === "function") return children(m);
|
|
3061
|
-
const label = labels
|
|
3062
|
-
return (0,
|
|
2419
|
+
const label = _nullishCoalesce(_optionalChain([labels, 'optionalAccess', _117 => _117[m.state]]), () => ( defaultLabel(m)));
|
|
2420
|
+
return _react.createElement.call(void 0,
|
|
3063
2421
|
"button",
|
|
3064
2422
|
{
|
|
3065
2423
|
type: "button",
|
|
@@ -3070,24 +2428,23 @@ function MintButton(props) {
|
|
|
3070
2428
|
disabled: !m.canAct,
|
|
3071
2429
|
onClick: m.mint
|
|
3072
2430
|
},
|
|
3073
|
-
children
|
|
2431
|
+
_nullishCoalesce(children, () => ( label))
|
|
3074
2432
|
);
|
|
3075
2433
|
}
|
|
3076
2434
|
|
|
3077
2435
|
// src/index.ts
|
|
3078
|
-
var VERSION = "0.
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
});
|
|
2436
|
+
var VERSION = "0.4.0";
|
|
2437
|
+
|
|
2438
|
+
|
|
2439
|
+
|
|
2440
|
+
|
|
2441
|
+
|
|
2442
|
+
|
|
2443
|
+
|
|
2444
|
+
|
|
2445
|
+
|
|
2446
|
+
|
|
2447
|
+
|
|
2448
|
+
|
|
2449
|
+
exports.CLICKABLE_STATES = _chunkGO4TR3HBcjs.CLICKABLE_STATES; exports.MAX_QUANTITY = _chunkGO4TR3HBcjs.MAX_QUANTITY; exports.MINT_STATES = _chunkGO4TR3HBcjs.MINT_STATES; exports.MintButton = MintButton; exports.MintError = _chunkGO4TR3HBcjs.MintError; exports.PayWithPicker = PayWithPicker; exports.REASON_CODES = _chunkGO4TR3HBcjs.REASON_CODES; exports.VERSION = VERSION; exports.isMintError = _chunkGO4TR3HBcjs.isMintError; exports.useMint = useMint; exports.usePayOptions = usePayOptions;
|
|
3093
2450
|
//# sourceMappingURL=index.cjs.map
|