@zoralabs/protocol-sdk 0.5.4-exports.0 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.turbo/turbo-build.log +16 -0
  2. package/CHANGELOG.md +2 -3
  3. package/dist/anvil.d.ts +36 -0
  4. package/dist/anvil.d.ts.map +1 -0
  5. package/dist/apis/chain-constants.d.ts +13 -0
  6. package/dist/apis/chain-constants.d.ts.map +1 -0
  7. package/dist/apis/client-base.d.ts +15 -0
  8. package/dist/apis/client-base.d.ts.map +1 -0
  9. package/dist/apis/generated/premint-api-types.d.ts +460 -0
  10. package/dist/apis/generated/premint-api-types.d.ts.map +1 -0
  11. package/dist/apis/http-api-base.d.ts +32 -0
  12. package/dist/apis/http-api-base.d.ts.map +1 -0
  13. package/dist/constants.d.ts +36 -0
  14. package/dist/constants.d.ts.map +1 -0
  15. package/dist/create/1155-create-helper.d.ts +62 -0
  16. package/dist/create/1155-create-helper.d.ts.map +1 -0
  17. package/dist/index.cjs +1694 -0
  18. package/dist/index.cjs.map +1 -0
  19. package/dist/index.d.ts +9 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +1664 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/mint/mint-api-client.d.ts +27 -0
  24. package/dist/mint/mint-api-client.d.ts.map +1 -0
  25. package/dist/mint/mint-client.d.ts +61 -0
  26. package/dist/mint/mint-client.d.ts.map +1 -0
  27. package/dist/premint/contract-types.d.ts +125 -0
  28. package/dist/premint/contract-types.d.ts.map +1 -0
  29. package/dist/premint/conversions.d.ts +78 -0
  30. package/dist/premint/conversions.d.ts.map +1 -0
  31. package/dist/premint/premint-api-client.d.ts +32 -0
  32. package/dist/premint/premint-api-client.d.ts.map +1 -0
  33. package/dist/premint/premint-client.d.ts +203 -0
  34. package/dist/premint/premint-client.d.ts.map +1 -0
  35. package/dist/premint/preminter.d.ts +121 -0
  36. package/dist/premint/preminter.d.ts.map +1 -0
  37. package/dist/preminter.d.ts +36 -0
  38. package/dist/preminter.d.ts.map +1 -0
  39. package/dist/types.d.ts +2 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/package.json +1 -1
package/dist/index.cjs ADDED
@@ -0,0 +1,1694 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ DEFAULT_SALE_SETTINGS: () => DEFAULT_SALE_SETTINGS,
24
+ Errors: () => Errors,
25
+ MintAPIClient: () => MintAPIClient,
26
+ PremintAPIClient: () => PremintAPIClient,
27
+ PremintConfigVersion: () => PremintConfigVersion,
28
+ PreminterDomain: () => PreminterDomain,
29
+ ZORA_API_BASE: () => ZORA_API_BASE,
30
+ applyUpdateToPremint: () => applyUpdateToPremint,
31
+ convertCollectionFromApi: () => convertCollectionFromApi,
32
+ convertGetPremintApiResponse: () => convertGetPremintApiResponse,
33
+ convertPremintFromApi: () => convertPremintFromApi,
34
+ create1155CreatorClient: () => create1155CreatorClient,
35
+ create1155TokenSetupArgs: () => create1155TokenSetupArgs,
36
+ createMintClient: () => createMintClient,
37
+ createPremintClient: () => createPremintClient,
38
+ defaultTokenConfigV1MintArguments: () => defaultTokenConfigV1MintArguments,
39
+ defaultTokenConfigV2MintArguments: () => defaultTokenConfigV2MintArguments,
40
+ encodePostSignatureInput: () => encodePostSignatureInput,
41
+ encodePremintForAPI: () => encodePremintForAPI,
42
+ getApiNetworkConfigForChain: () => getApiNetworkConfigForChain,
43
+ getDefaultFixedPriceMinterAddress: () => getDefaultFixedPriceMinterAddress,
44
+ getMintCosts: () => getMintCosts,
45
+ getPremintCollectionAddress: () => getPremintCollectionAddress,
46
+ getPremintExecutorAddress: () => getPremintExecutorAddress,
47
+ getPremintMintCosts: () => getPremintMintCosts,
48
+ getPremintMintFee: () => getPremintMintFee,
49
+ getPremintedLogFromReceipt: () => getPremintedLogFromReceipt,
50
+ getTokenIdFromCreateReceipt: () => getTokenIdFromCreateReceipt,
51
+ isAuthorizedToCreatePremint: () => isAuthorizedToCreatePremint,
52
+ isValidSignature: () => isValidSignature,
53
+ makeMintRewardsRecipient: () => makeMintRewardsRecipient,
54
+ makeNewPremint: () => makeNewPremint,
55
+ markPremintDeleted: () => markPremintDeleted,
56
+ migratePremintConfigToV2: () => migratePremintConfigToV2,
57
+ premintTypedDataDefinition: () => premintTypedDataDefinition,
58
+ recoverCreatorFromCreatorAttribution: () => recoverCreatorFromCreatorAttribution,
59
+ recoverPremintSigner: () => recoverPremintSigner,
60
+ supportedPremintVersions: () => supportedPremintVersions,
61
+ supportsPremintVersion: () => supportsPremintVersion,
62
+ tryRecoverPremintSigner: () => tryRecoverPremintSigner,
63
+ v1Types: () => v1Types,
64
+ v2Types: () => v2Types
65
+ });
66
+ module.exports = __toCommonJS(src_exports);
67
+
68
+ // src/premint/premint-client.ts
69
+ var import_viem4 = require("viem");
70
+ var import_protocol_deployments2 = require("@zoralabs/protocol-deployments");
71
+
72
+ // src/premint/preminter.ts
73
+ var import_protocol_deployments = require("@zoralabs/protocol-deployments");
74
+ var import_viem = require("viem");
75
+
76
+ // src/premint/contract-types.ts
77
+ var v1Types = {
78
+ CreatorAttribution: [
79
+ { name: "tokenConfig", type: "TokenCreationConfig" },
80
+ // unique id scoped to the contract and token to create.
81
+ // ensure that a signature can be replaced, as long as the replacement
82
+ // has the same uid, and a newer version.
83
+ { name: "uid", type: "uint32" },
84
+ { name: "version", type: "uint32" },
85
+ // if this update should result in the signature being deleted.
86
+ { name: "deleted", type: "bool" }
87
+ ],
88
+ TokenCreationConfig: [
89
+ { name: "tokenURI", type: "string" },
90
+ { name: "maxSupply", type: "uint256" },
91
+ { name: "maxTokensPerAddress", type: "uint64" },
92
+ { name: "pricePerToken", type: "uint96" },
93
+ { name: "mintStart", type: "uint64" },
94
+ { name: "mintDuration", type: "uint64" },
95
+ { name: "royaltyMintSchedule", type: "uint32" },
96
+ { name: "royaltyBPS", type: "uint32" },
97
+ { name: "royaltyRecipient", type: "address" },
98
+ { name: "fixedPriceMinter", type: "address" }
99
+ ]
100
+ };
101
+ var v2Types = {
102
+ CreatorAttribution: [
103
+ { name: "tokenConfig", type: "TokenCreationConfig" },
104
+ // unique id scoped to the contract and token to create.
105
+ // ensure that a signature can be replaced, as long as the replacement
106
+ // has the same uid, and a newer version.
107
+ { name: "uid", type: "uint32" },
108
+ { name: "version", type: "uint32" },
109
+ // if this update should result in the signature being deleted.
110
+ { name: "deleted", type: "bool" }
111
+ ],
112
+ TokenCreationConfig: [
113
+ { name: "tokenURI", type: "string" },
114
+ { name: "maxSupply", type: "uint256" },
115
+ { name: "maxTokensPerAddress", type: "uint64" },
116
+ { name: "pricePerToken", type: "uint96" },
117
+ { name: "mintStart", type: "uint64" },
118
+ { name: "mintDuration", type: "uint64" },
119
+ { name: "royaltyBPS", type: "uint32" },
120
+ { name: "payoutRecipient", type: "address" },
121
+ { name: "fixedPriceMinter", type: "address" },
122
+ { name: "createReferral", type: "address" }
123
+ ]
124
+ };
125
+ var PreminterDomain = "Preminter";
126
+ var PremintConfigVersion = /* @__PURE__ */ ((PremintConfigVersion2) => {
127
+ PremintConfigVersion2["V1"] = "1";
128
+ PremintConfigVersion2["V2"] = "2";
129
+ return PremintConfigVersion2;
130
+ })(PremintConfigVersion || {});
131
+
132
+ // src/premint/preminter.ts
133
+ var getPremintExecutorAddress = () => import_protocol_deployments.zoraCreator1155PremintExecutorImplAddress[999];
134
+ var premintTypedDataDefinition = ({
135
+ verifyingContract,
136
+ chainId,
137
+ premintConfigVersion: version,
138
+ premintConfig
139
+ }) => {
140
+ const domain = {
141
+ chainId,
142
+ name: PreminterDomain,
143
+ version,
144
+ verifyingContract
145
+ };
146
+ if (version === "1" /* V1 */)
147
+ return {
148
+ domain,
149
+ types: v1Types,
150
+ message: premintConfig,
151
+ primaryType: "CreatorAttribution"
152
+ };
153
+ if (version === "2" /* V2 */) {
154
+ return {
155
+ domain,
156
+ types: v2Types,
157
+ message: premintConfig,
158
+ primaryType: "CreatorAttribution"
159
+ };
160
+ }
161
+ throw new Error(`Invalid version ${version}`);
162
+ };
163
+ async function isAuthorizedToCreatePremint({
164
+ collection,
165
+ collectionAddress,
166
+ publicClient,
167
+ signer
168
+ }) {
169
+ return await publicClient.readContract({
170
+ abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
171
+ address: getPremintExecutorAddress(),
172
+ functionName: "isAuthorizedToCreatePremint",
173
+ args: [signer, collection.contractAdmin, collectionAddress]
174
+ });
175
+ }
176
+ async function recoverPremintSigner({
177
+ signature,
178
+ ...rest
179
+ }) {
180
+ const typedData = premintTypedDataDefinition(rest);
181
+ return await (0, import_viem.recoverTypedDataAddress)({
182
+ ...typedData,
183
+ signature
184
+ });
185
+ }
186
+ async function tryRecoverPremintSigner(params) {
187
+ try {
188
+ return await recoverPremintSigner(params);
189
+ } catch (error) {
190
+ console.error(error);
191
+ return void 0;
192
+ }
193
+ }
194
+ async function isValidSignature({
195
+ signature,
196
+ publicClient,
197
+ collection,
198
+ chainId,
199
+ ...premintConfigAndVersion
200
+ }) {
201
+ const tokenContract = await getPremintCollectionAddress({
202
+ collection,
203
+ publicClient
204
+ });
205
+ const recoveredAddress = await tryRecoverPremintSigner({
206
+ ...premintConfigAndVersion,
207
+ signature,
208
+ verifyingContract: tokenContract,
209
+ chainId
210
+ });
211
+ if (!import_viem.recoverAddress) {
212
+ return {
213
+ isAuthorized: false
214
+ };
215
+ }
216
+ const isAuthorized = await isAuthorizedToCreatePremint({
217
+ signer: recoveredAddress,
218
+ collection,
219
+ collectionAddress: tokenContract,
220
+ publicClient
221
+ });
222
+ return {
223
+ isAuthorized,
224
+ recoveredAddress
225
+ };
226
+ }
227
+ function migratePremintConfigToV2({
228
+ premintConfig,
229
+ createReferral = import_viem.zeroAddress
230
+ }) {
231
+ return {
232
+ ...premintConfig,
233
+ tokenConfig: {
234
+ tokenURI: premintConfig.tokenConfig.tokenURI,
235
+ maxSupply: premintConfig.tokenConfig.maxSupply,
236
+ maxTokensPerAddress: premintConfig.tokenConfig.maxTokensPerAddress,
237
+ pricePerToken: premintConfig.tokenConfig.pricePerToken,
238
+ mintStart: premintConfig.tokenConfig.mintStart,
239
+ mintDuration: premintConfig.tokenConfig.mintDuration,
240
+ payoutRecipient: premintConfig.tokenConfig.royaltyRecipient,
241
+ royaltyBPS: premintConfig.tokenConfig.royaltyBPS,
242
+ fixedPriceMinter: premintConfig.tokenConfig.fixedPriceMinter,
243
+ createReferral
244
+ }
245
+ };
246
+ }
247
+ var recoverCreatorFromCreatorAttribution = async ({
248
+ creatorAttribution: { version, domainName, structHash, signature },
249
+ chainId,
250
+ tokenContract
251
+ }) => {
252
+ const hashedDomain = (0, import_viem.hashDomain)({
253
+ domain: {
254
+ chainId,
255
+ name: domainName,
256
+ verifyingContract: tokenContract,
257
+ version
258
+ },
259
+ types: {
260
+ EIP712Domain: [
261
+ { name: "name", type: "string" },
262
+ { name: "version", type: "string" },
263
+ {
264
+ name: "chainId",
265
+ type: "uint256"
266
+ },
267
+ {
268
+ name: "verifyingContract",
269
+ type: "address"
270
+ }
271
+ ]
272
+ }
273
+ });
274
+ const parts = ["0x1901", hashedDomain, structHash];
275
+ const hashedTypedData = (0, import_viem.keccak256)((0, import_viem.concat)(parts));
276
+ return await (0, import_viem.recoverAddress)({
277
+ hash: hashedTypedData,
278
+ signature
279
+ });
280
+ };
281
+ var supportedPremintVersions = async ({
282
+ tokenContract,
283
+ publicClient
284
+ }) => {
285
+ return await publicClient.readContract({
286
+ abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
287
+ address: getPremintExecutorAddress(),
288
+ functionName: "supportedPremintSignatureVersions",
289
+ args: [tokenContract]
290
+ });
291
+ };
292
+ var supportsPremintVersion = async ({
293
+ version,
294
+ tokenContract,
295
+ publicClient
296
+ }) => {
297
+ return (await supportedPremintVersions({ tokenContract, publicClient })).includes(version);
298
+ };
299
+ async function getPremintCollectionAddress({
300
+ collection,
301
+ publicClient
302
+ }) {
303
+ return publicClient.readContract({
304
+ address: getPremintExecutorAddress(),
305
+ abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
306
+ functionName: "getContractAddress",
307
+ args: [collection]
308
+ });
309
+ }
310
+ function markPremintDeleted(premintConfig) {
311
+ return {
312
+ ...premintConfig,
313
+ version: premintConfig.version + 1,
314
+ deleted: true
315
+ };
316
+ }
317
+ function applyUpdateToPremint({
318
+ uid,
319
+ version,
320
+ tokenConfig,
321
+ tokenConfigUpdates
322
+ }) {
323
+ const updatedTokenConfig = {
324
+ ...tokenConfig,
325
+ ...tokenConfigUpdates
326
+ };
327
+ const result = {
328
+ deleted: false,
329
+ uid,
330
+ version: version + 1,
331
+ tokenConfig: updatedTokenConfig
332
+ };
333
+ return result;
334
+ }
335
+ function makeNewPremint({
336
+ tokenConfig,
337
+ uid
338
+ }) {
339
+ return {
340
+ deleted: false,
341
+ uid,
342
+ version: 0,
343
+ tokenConfig
344
+ };
345
+ }
346
+ async function getPremintMintFee({
347
+ tokenContract,
348
+ publicClient
349
+ }) {
350
+ try {
351
+ return await publicClient.readContract({
352
+ address: getPremintExecutorAddress(),
353
+ abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
354
+ functionName: "mintFee",
355
+ args: [tokenContract]
356
+ });
357
+ } catch (e) {
358
+ console.error(e);
359
+ return (0, import_viem.parseEther)("0.000777");
360
+ }
361
+ }
362
+ async function getPremintMintCosts({
363
+ publicClient,
364
+ tokenContract,
365
+ tokenPrice,
366
+ quantityToMint
367
+ }) {
368
+ const mintFee = await getPremintMintFee({ tokenContract, publicClient });
369
+ return {
370
+ mintFee: mintFee * quantityToMint,
371
+ tokenPurchaseCost: tokenPrice * quantityToMint,
372
+ totalCost: (mintFee + tokenPrice) * quantityToMint
373
+ };
374
+ }
375
+ function makeMintRewardsRecipient({
376
+ mintReferral = import_viem.zeroAddress,
377
+ platformReferral = import_viem.zeroAddress
378
+ }) {
379
+ return [mintReferral, platformReferral];
380
+ }
381
+ function getDefaultFixedPriceMinterAddress(chainId) {
382
+ return import_protocol_deployments.zoraCreatorFixedPriceSaleStrategyAddress[chainId];
383
+ }
384
+
385
+ // src/apis/http-api-base.ts
386
+ var BadResponseError = class extends Error {
387
+ constructor(message, status, json) {
388
+ super(message);
389
+ this.name = "BadResponseError";
390
+ this.status = status;
391
+ this.json = json;
392
+ }
393
+ };
394
+ async function wait(delayMs) {
395
+ return new Promise((resolve) => {
396
+ setTimeout(resolve, delayMs);
397
+ });
398
+ }
399
+ var get = async (url) => {
400
+ const response = await fetch(url, { method: "GET" });
401
+ if (response.status !== 200) {
402
+ let json;
403
+ try {
404
+ json = await response.json();
405
+ } catch (e) {
406
+ }
407
+ throw new BadResponseError(
408
+ `Invalid response, status ${response.status}`,
409
+ response.status,
410
+ json
411
+ );
412
+ }
413
+ return await response.json();
414
+ };
415
+ var post = async (url, data) => {
416
+ const response = await fetch(url, {
417
+ method: "POST",
418
+ headers: {
419
+ "content-type": "application/json",
420
+ accept: "application/json"
421
+ },
422
+ body: JSON.stringify(data)
423
+ });
424
+ if (response.status !== 200) {
425
+ let json;
426
+ try {
427
+ json = await response.json();
428
+ } catch (e) {
429
+ }
430
+ throw new BadResponseError(
431
+ `Bad response: ${response.status}`,
432
+ response.status,
433
+ json
434
+ );
435
+ }
436
+ return await response.json();
437
+ };
438
+ var retries = async (tryFn, maxTries = 3, atTry = 1, linearBackoffMS = 200) => {
439
+ try {
440
+ return await tryFn();
441
+ } catch (err) {
442
+ if (err instanceof BadResponseError) {
443
+ if (err.status >= 500) {
444
+ if (atTry <= maxTries) {
445
+ await wait(atTry * linearBackoffMS);
446
+ return await retries(tryFn, maxTries, atTry + 1);
447
+ }
448
+ }
449
+ }
450
+ throw err;
451
+ }
452
+ };
453
+ var httpClient = {
454
+ get,
455
+ post,
456
+ retries
457
+ };
458
+
459
+ // src/constants.ts
460
+ var import_viem2 = require("viem");
461
+ var ZORA_API_BASE = "https://api.zora.co/";
462
+ var OPEN_EDITION_MINT_SIZE = BigInt("18446744073709551615");
463
+ var SUBGRAPH_CONFIG_BASE = "https://api.goldsky.com/api/public/project_clhk16b61ay9t49vm6ntn4mkz/subgraphs";
464
+ function getSubgraph(name, version) {
465
+ return `${SUBGRAPH_CONFIG_BASE}/${name}/${version}/gn`;
466
+ }
467
+ var zora721Abi = (0, import_viem2.parseAbi)([
468
+ "function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
469
+ "function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
470
+ ]);
471
+
472
+ // src/apis/chain-constants.ts
473
+ var import_chains = require("viem/chains");
474
+ var import_viem3 = require("viem");
475
+ var REWARD_PER_TOKEN = (0, import_viem3.parseEther)("0.000777");
476
+ var networkConfigByChain = {
477
+ [import_chains.mainnet.id]: {
478
+ chainId: import_chains.mainnet.id,
479
+ isTestnet: false,
480
+ zoraCollectPathChainName: "eth",
481
+ zoraBackendChainName: "ETHEREUM-MAINNET",
482
+ subgraphUrl: getSubgraph("zora-create-mainnet", "stable")
483
+ },
484
+ [import_chains.goerli.id]: {
485
+ chainId: import_chains.goerli.id,
486
+ isTestnet: true,
487
+ zoraCollectPathChainName: "gor",
488
+ zoraBackendChainName: "ETHEREUM-GOERLI",
489
+ subgraphUrl: getSubgraph("zora-create-goerli", "stable")
490
+ },
491
+ [import_chains.zora.id]: {
492
+ chainId: import_chains.zora.id,
493
+ isTestnet: false,
494
+ zoraCollectPathChainName: "zora",
495
+ zoraBackendChainName: "ZORA-MAINNET",
496
+ subgraphUrl: getSubgraph("zora-create-zora-mainnet", "stable")
497
+ },
498
+ [import_chains.zoraTestnet.id]: {
499
+ chainId: import_chains.zoraTestnet.id,
500
+ isTestnet: true,
501
+ zoraCollectPathChainName: "zgor",
502
+ zoraBackendChainName: "ZORA-GOERLI",
503
+ subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
504
+ },
505
+ [import_chains.zoraSepolia.id]: {
506
+ chainId: import_chains.zoraSepolia.id,
507
+ isTestnet: true,
508
+ zoraCollectPathChainName: "zsep",
509
+ zoraBackendChainName: "ZORA-SEPOLIA",
510
+ subgraphUrl: getSubgraph("zora-create-zora-sepolia", "stable")
511
+ },
512
+ [import_chains.optimism.id]: {
513
+ chainId: import_chains.optimism.id,
514
+ isTestnet: false,
515
+ zoraCollectPathChainName: "oeth",
516
+ zoraBackendChainName: "OPTIMISM-MAINNET",
517
+ subgraphUrl: getSubgraph("zora-create-optimism", "stable")
518
+ },
519
+ [import_chains.optimismGoerli.id]: {
520
+ chainId: import_chains.optimismGoerli.id,
521
+ isTestnet: true,
522
+ zoraCollectPathChainName: "ogor",
523
+ zoraBackendChainName: "OPTIMISM-GOERLI",
524
+ subgraphUrl: getSubgraph("zora-create-optimism-goerli", "stable")
525
+ },
526
+ [import_chains.base.id]: {
527
+ chainId: import_chains.base.id,
528
+ isTestnet: false,
529
+ zoraCollectPathChainName: "base",
530
+ zoraBackendChainName: "BASE-MAINNET",
531
+ subgraphUrl: getSubgraph("zora-create-base-mainnet", "stable")
532
+ },
533
+ [import_chains.baseGoerli.id]: {
534
+ chainId: import_chains.baseGoerli.id,
535
+ isTestnet: true,
536
+ zoraCollectPathChainName: "bgor",
537
+ zoraBackendChainName: "BASE-GOERLI",
538
+ subgraphUrl: getSubgraph("zora-create-base-goerli", "stable")
539
+ },
540
+ [import_chains.foundry.id]: {
541
+ chainId: import_chains.foundry.id,
542
+ isTestnet: true,
543
+ zoraCollectPathChainName: "zgor",
544
+ zoraBackendChainName: "ZORA-GOERLI",
545
+ subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
546
+ }
547
+ };
548
+
549
+ // src/mint/mint-api-client.ts
550
+ var getApiNetworkConfigForChain = (chainId) => {
551
+ if (!networkConfigByChain[chainId]) {
552
+ throw new Error(`chain id ${chainId} network not configured `);
553
+ }
554
+ return networkConfigByChain[chainId];
555
+ };
556
+ var MintAPIClient = class {
557
+ constructor(chainId, httpClient2) {
558
+ this.httpClient = httpClient2 || httpClient;
559
+ this.networkConfig = getApiNetworkConfigForChain(chainId);
560
+ }
561
+ async getSalesConfigAndTokenInfo({
562
+ tokenAddress,
563
+ tokenId
564
+ }) {
565
+ const { retries: retries2, post: post2 } = this.httpClient;
566
+ return retries2(async () => {
567
+ const response = await post2(this.networkConfig.subgraphUrl, {
568
+ query: `
569
+ fragment SaleStrategy on SalesStrategyConfig {
570
+ type
571
+ fixedPrice {
572
+ address
573
+ pricePerToken
574
+ saleEnd
575
+ saleStart
576
+ maxTokensPerAddress
577
+ }
578
+ }
579
+
580
+ query ($id: ID!) {
581
+ zoraCreateToken(id: $id) {
582
+ id
583
+ contract {
584
+ mintFeePerQuantity
585
+ salesStrategies(where: {type: "FIXED_PRICE"}) {
586
+ ...SaleStrategy
587
+ }
588
+ }
589
+ salesStrategies(where: {type: "FIXED_PRICE"}) {
590
+ ...SaleStrategy
591
+ }
592
+ }
593
+ }
594
+ `,
595
+ variables: {
596
+ id: tokenId !== void 0 ? (
597
+ // Generic Token ID types all stringify down to the base numeric equivalent.
598
+ `${tokenAddress.toLowerCase()}-${tokenId}`
599
+ ) : `${tokenAddress.toLowerCase()}-0`
600
+ }
601
+ });
602
+ const token = response.data?.zoraCreateToken;
603
+ if (!token) {
604
+ throw new Error("Cannot find a token to mint");
605
+ }
606
+ const saleStrategies = tokenId !== void 0 ? token.salesStrategies : token.contract.salesStrategies;
607
+ const fixedPrice = saleStrategies?.sort(
608
+ (a, b) => BigInt(a.fixedPrice.saleEnd) > BigInt(b.fixedPrice.saleEnd) ? 1 : -1
609
+ )?.find(() => true)?.fixedPrice;
610
+ if (!fixedPrice) {
611
+ throw new Error("Cannot find fixed price sale strategy");
612
+ }
613
+ return {
614
+ fixedPrice,
615
+ mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
616
+ };
617
+ });
618
+ }
619
+ };
620
+
621
+ // src/premint/conversions.ts
622
+ var convertCollectionFromApi = (collection) => ({
623
+ ...collection,
624
+ contractAdmin: collection.contractAdmin
625
+ });
626
+ var convertPremintFromApi = (premint) => {
627
+ if (premint.config_version === "1" /* V1 */ || !premint.config_version) {
628
+ const tokenConfig = premint.tokenConfig;
629
+ return {
630
+ premintConfigVersion: "1" /* V1 */,
631
+ premintConfig: {
632
+ deleted: premint.deleted,
633
+ uid: premint.uid,
634
+ version: premint.version,
635
+ tokenConfig: {
636
+ ...tokenConfig,
637
+ fixedPriceMinter: tokenConfig.fixedPriceMinter,
638
+ royaltyRecipient: tokenConfig.royaltyRecipient,
639
+ maxSupply: BigInt(tokenConfig.maxSupply),
640
+ pricePerToken: BigInt(tokenConfig.pricePerToken),
641
+ mintStart: BigInt(tokenConfig.mintStart),
642
+ mintDuration: BigInt(tokenConfig.mintDuration),
643
+ maxTokensPerAddress: BigInt(tokenConfig.maxTokensPerAddress)
644
+ }
645
+ }
646
+ };
647
+ } else {
648
+ const tokenConfig = premint.tokenConfig;
649
+ return {
650
+ premintConfigVersion: "2" /* V2 */,
651
+ premintConfig: {
652
+ deleted: premint.deleted,
653
+ uid: premint.uid,
654
+ version: premint.version,
655
+ tokenConfig: {
656
+ ...tokenConfig,
657
+ fixedPriceMinter: tokenConfig.fixedPriceMinter,
658
+ payoutRecipient: tokenConfig.payoutRecipient,
659
+ createReferral: tokenConfig.createReferral,
660
+ maxSupply: BigInt(tokenConfig.maxSupply),
661
+ pricePerToken: BigInt(tokenConfig.pricePerToken),
662
+ mintStart: BigInt(tokenConfig.mintStart),
663
+ mintDuration: BigInt(tokenConfig.mintDuration),
664
+ maxTokensPerAddress: BigInt(tokenConfig.maxTokensPerAddress)
665
+ }
666
+ }
667
+ };
668
+ }
669
+ };
670
+ var convertGetPremintApiResponse = (response) => ({
671
+ ...convertPremintFromApi(response.premint),
672
+ collection: convertCollectionFromApi(response.collection),
673
+ signature: response.signature
674
+ });
675
+ var encodePremintV1ForAPI = ({
676
+ tokenConfig,
677
+ ...premint
678
+ }) => ({
679
+ ...premint,
680
+ config_version: "1",
681
+ tokenConfig: {
682
+ ...tokenConfig,
683
+ maxSupply: tokenConfig.maxSupply.toString(),
684
+ pricePerToken: tokenConfig.pricePerToken.toString(),
685
+ mintStart: tokenConfig.mintStart.toString(),
686
+ mintDuration: tokenConfig.mintDuration.toString(),
687
+ maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
688
+ }
689
+ });
690
+ var encodePremintV2ForAPI = ({
691
+ tokenConfig,
692
+ ...premint
693
+ }) => ({
694
+ ...premint,
695
+ config_version: "2",
696
+ tokenConfig: {
697
+ ...tokenConfig,
698
+ maxSupply: tokenConfig.maxSupply.toString(),
699
+ pricePerToken: tokenConfig.pricePerToken.toString(),
700
+ mintStart: tokenConfig.mintStart.toString(),
701
+ mintDuration: tokenConfig.mintDuration.toString(),
702
+ maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
703
+ }
704
+ });
705
+ var encodePremintForAPI = ({
706
+ premintConfig,
707
+ premintConfigVersion
708
+ }) => {
709
+ if (premintConfigVersion === "1" /* V1 */) {
710
+ return encodePremintV1ForAPI(premintConfig);
711
+ }
712
+ if (premintConfigVersion === "2" /* V2 */) {
713
+ return encodePremintV2ForAPI(premintConfig);
714
+ }
715
+ throw new Error(`Invalid premint config version ${premintConfigVersion}`);
716
+ };
717
+ var encodePostSignatureInput = ({
718
+ collection,
719
+ premintConfigVersion,
720
+ premintConfig,
721
+ signature,
722
+ chainId
723
+ }) => ({
724
+ premint: encodePremintForAPI({
725
+ premintConfig,
726
+ premintConfigVersion
727
+ }),
728
+ signature,
729
+ collection,
730
+ chain_name: networkConfigByChain[chainId].zoraBackendChainName
731
+ });
732
+
733
+ // src/premint/premint-api-client.ts
734
+ var postSignature = async ({
735
+ httpClient: { post: post2, retries: retries2 } = httpClient,
736
+ ...data
737
+ }) => retries2(
738
+ () => post2(`${ZORA_API_BASE}premint/signature`, data)
739
+ );
740
+ var getNextUID = async ({
741
+ chain_name,
742
+ collection_address,
743
+ httpClient: { retries: retries2, get: get2 } = httpClient
744
+ }) => retries2(
745
+ () => get2(
746
+ `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/next_uid`
747
+ )
748
+ );
749
+ var getSignature = async ({
750
+ collection_address,
751
+ uid,
752
+ chain_name,
753
+ httpClient: { retries: retries2, get: get2 } = httpClient
754
+ }) => {
755
+ const result = await retries2(
756
+ () => get2(
757
+ `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
758
+ )
759
+ );
760
+ return result;
761
+ };
762
+ var PremintAPIClient = class {
763
+ constructor(chainId, httpClient2) {
764
+ this.postSignature = async ({
765
+ collection,
766
+ signature,
767
+ ...premintConfigAndVersion
768
+ }) => {
769
+ const data = encodePostSignatureInput({
770
+ collection,
771
+ ...premintConfigAndVersion,
772
+ chainId: this.networkConfig.chainId,
773
+ signature
774
+ });
775
+ return postSignature({
776
+ ...data,
777
+ httpClient: this.httpClient
778
+ });
779
+ };
780
+ this.getNextUID = async (collectionAddress) => (await getNextUID({
781
+ collection_address: collectionAddress.toLowerCase(),
782
+ chain_name: this.networkConfig.zoraBackendChainName,
783
+ httpClient: this.httpClient
784
+ })).next_uid;
785
+ this.getSignature = async ({
786
+ collectionAddress,
787
+ uid
788
+ }) => {
789
+ const response = await getSignature({
790
+ collection_address: collectionAddress.toLowerCase(),
791
+ uid,
792
+ chain_name: this.networkConfig.zoraBackendChainName,
793
+ httpClient: this.httpClient
794
+ });
795
+ return convertGetPremintApiResponse(response);
796
+ };
797
+ this.httpClient = httpClient2 || httpClient;
798
+ this.networkConfig = getApiNetworkConfigForChain(chainId);
799
+ }
800
+ };
801
+
802
+ // src/premint/premint-client.ts
803
+ var defaultTokenConfigV1MintArguments = () => ({
804
+ maxSupply: OPEN_EDITION_MINT_SIZE,
805
+ maxTokensPerAddress: 0n,
806
+ pricePerToken: 0n,
807
+ mintDuration: BigInt(60 * 60 * 24 * 7),
808
+ // 1 week
809
+ mintStart: 0n,
810
+ royaltyMintSchedule: 0,
811
+ royaltyBPS: 1e3
812
+ // 10%,
813
+ });
814
+ var defaultTokenConfigV2MintArguments = () => ({
815
+ maxSupply: OPEN_EDITION_MINT_SIZE,
816
+ maxTokensPerAddress: 0n,
817
+ pricePerToken: 0n,
818
+ mintDuration: BigInt(60 * 60 * 24 * 7),
819
+ // 1 week
820
+ mintStart: 0n,
821
+ royaltyBPS: 1e3
822
+ // 10%,
823
+ });
824
+ var makeTokenConfigWithDefaults = ({
825
+ chainId,
826
+ premintConfigVersion,
827
+ tokenCreationConfig,
828
+ creatorAccount
829
+ }) => {
830
+ const fixedPriceMinter = tokenCreationConfig.fixedPriceMinter || getDefaultFixedPriceMinterAddress(chainId);
831
+ if (premintConfigVersion === "1" /* V1 */) {
832
+ return {
833
+ fixedPriceMinter,
834
+ ...defaultTokenConfigV1MintArguments(),
835
+ royaltyRecipient: creatorAccount,
836
+ ...tokenCreationConfig
837
+ };
838
+ } else if (premintConfigVersion === "2" /* V2 */) {
839
+ return {
840
+ fixedPriceMinter,
841
+ ...defaultTokenConfigV2MintArguments(),
842
+ payoutRecipient: creatorAccount,
843
+ createReferral: import_viem4.zeroAddress,
844
+ ...tokenCreationConfig
845
+ };
846
+ } else {
847
+ throw new Error(`Invalid premint config version ${premintConfigVersion}`);
848
+ }
849
+ };
850
+ function getPremintedLogFromReceipt(receipt) {
851
+ for (const data of receipt.logs) {
852
+ try {
853
+ const decodedLog = (0, import_viem4.decodeEventLog)({
854
+ abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
855
+ eventName: "PremintedV2",
856
+ ...data
857
+ });
858
+ if (decodedLog.eventName === "PremintedV2") {
859
+ return decodedLog.args;
860
+ }
861
+ } catch (err) {
862
+ }
863
+ }
864
+ }
865
+ var PremintClient = class {
866
+ constructor(chain, publicClient, httpClient2) {
867
+ this.chain = chain;
868
+ this.apiClient = new PremintAPIClient(chain.id, httpClient2);
869
+ this.publicClient = publicClient || (0, import_viem4.createPublicClient)({ chain, transport: (0, import_viem4.http)() });
870
+ }
871
+ getDataFromPremintReceipt(receipt) {
872
+ const premintedLog = getPremintedLogFromReceipt(receipt);
873
+ return {
874
+ premintedLog,
875
+ urls: this.makeUrls({
876
+ address: premintedLog?.contractAddress,
877
+ tokenId: premintedLog?.tokenId
878
+ })
879
+ };
880
+ }
881
+ /**
882
+ * Update existing premint given collection address and UID of existing premint.
883
+ *
884
+ * 1. Loads existing premint token
885
+ * 2. Updates with settings passed into function
886
+ * 3. Increments the version field
887
+ * 4. Re-signs the premint
888
+ * 5. Uploads the premint to the ZORA API
889
+ *
890
+ * Updates existing premint
891
+ * @param settings Settings for the new premint
892
+ * @param settings.account Account to sign the premint update from. Taken from walletClient if none passed in.
893
+ * @param settings.collection Collection information for the mint
894
+ * @param settings.walletClient viem wallet client to use to sign
895
+ * @param settings.uid UID
896
+ * @param settings.token Mint argument settings, optional settings are overridden with sensible defaults.
897
+ *
898
+ */
899
+ async updatePremint({
900
+ walletClient,
901
+ uid,
902
+ collection,
903
+ account,
904
+ tokenConfigUpdates
905
+ }) {
906
+ const {
907
+ premintConfig,
908
+ collection: collectionCreationConfig,
909
+ premintConfigVersion
910
+ } = await this.apiClient.getSignature({
911
+ collectionAddress: collection,
912
+ uid
913
+ });
914
+ const updatedPremint = applyUpdateToPremint({
915
+ uid: premintConfig.uid,
916
+ version: premintConfig.version,
917
+ tokenConfig: premintConfig.tokenConfig,
918
+ tokenConfigUpdates
919
+ });
920
+ return await this.signAndSubmitPremint({
921
+ walletClient,
922
+ account,
923
+ checkSignature: true,
924
+ verifyingContract: collection,
925
+ collection: collectionCreationConfig,
926
+ premintConfig: updatedPremint,
927
+ premintConfigVersion
928
+ });
929
+ }
930
+ /**
931
+ * Delete premint.
932
+ *
933
+ * 1. Loads current premint from collection address with UID
934
+ * 2. Increments version and marks as deleted
935
+ * 3. Signs new premint version
936
+ * 4. Sends to ZORA Premint API
937
+ *
938
+ * Deletes existing premint
939
+ * @param settings.collection collection address
940
+ * @param settings.uid UID
941
+ * @param settings.walletClient viem wallet client to use to sign
942
+ *
943
+ */
944
+ async deletePremint({
945
+ walletClient,
946
+ uid,
947
+ account,
948
+ collection
949
+ }) {
950
+ const {
951
+ premintConfig,
952
+ premintConfigVersion,
953
+ collection: collectionCreationConfig
954
+ } = await this.apiClient.getSignature({
955
+ collectionAddress: collection,
956
+ uid
957
+ });
958
+ const deletedPremint = markPremintDeleted(premintConfig);
959
+ return await this.signAndSubmitPremint({
960
+ walletClient,
961
+ account,
962
+ checkSignature: false,
963
+ verifyingContract: collection,
964
+ collection: collectionCreationConfig,
965
+ premintConfig: deletedPremint,
966
+ premintConfigVersion
967
+ });
968
+ }
969
+ /**
970
+ * Internal function to sign and submit a premint request.
971
+ *
972
+ * @param premintArguments Arguments to premint
973
+ * @returns
974
+ */
975
+ async signAndSubmitPremint(params) {
976
+ const { verifyingContract } = await signAndSubmitPremint({
977
+ ...params,
978
+ chainId: this.chain.id,
979
+ apiClient: this.apiClient,
980
+ publicClient: this.publicClient
981
+ });
982
+ const uid = params.premintConfig.uid;
983
+ return {
984
+ urls: this.makeUrls({ address: verifyingContract, uid }),
985
+ uid,
986
+ verifyingContract
987
+ };
988
+ }
989
+ /**
990
+ * Create premint
991
+ *
992
+ * @param settings Settings for the new premint
993
+ * @param settings.account Account to sign the premint with. Taken from walletClient if none passed in.
994
+ * @param settings.collection Collection information for the mint
995
+ * @param settings.tokenCreationConfig Mint argument settings, optional settings are overridden with sensible defaults.
996
+ * @param setings.premintConfigVersion Premint config version to use, defaults to V2
997
+ * @param settings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
998
+ * @param settings.checkSignature if the signature should have a pre-flight check. Not required but helpful for debugging.
999
+ * @returns premint url, uid, newContractAddress, and premint object
1000
+ */
1001
+ async createPremint({
1002
+ creatorAccount,
1003
+ collection,
1004
+ tokenCreationConfig,
1005
+ premintConfigVersion,
1006
+ walletClient,
1007
+ uid,
1008
+ checkSignature = false
1009
+ }) {
1010
+ const newContractAddress = await getPremintCollectionAddress({
1011
+ publicClient: this.publicClient,
1012
+ collection
1013
+ });
1014
+ let uidToUse = uid;
1015
+ if (typeof uidToUse !== "number") {
1016
+ uidToUse = await this.apiClient.getNextUID(newContractAddress);
1017
+ }
1018
+ const actualVersion = premintConfigVersion || "1" /* V1 */;
1019
+ if (!await supportsPremintVersion({
1020
+ version: actualVersion,
1021
+ publicClient: this.publicClient,
1022
+ tokenContract: newContractAddress
1023
+ })) {
1024
+ throw new Error(
1025
+ `Premint version ${actualVersion} not supported by contract`
1026
+ );
1027
+ }
1028
+ const premintConfig = makeNewPremint({
1029
+ tokenConfig: makeTokenConfigWithDefaults({
1030
+ premintConfigVersion: actualVersion,
1031
+ tokenCreationConfig,
1032
+ creatorAccount: typeof creatorAccount === "string" ? creatorAccount : creatorAccount.address,
1033
+ chainId: this.chain.id
1034
+ }),
1035
+ uid: uidToUse
1036
+ });
1037
+ return await this.signAndSubmitPremint({
1038
+ verifyingContract: newContractAddress,
1039
+ premintConfig,
1040
+ premintConfigVersion: actualVersion,
1041
+ checkSignature,
1042
+ account: creatorAccount,
1043
+ walletClient,
1044
+ collection
1045
+ });
1046
+ }
1047
+ /**
1048
+ * Fetches given premint data from the ZORA API.
1049
+ *
1050
+ * @param address Address for the premint contract
1051
+ * @param uid UID for the desired premint
1052
+ * @returns PremintSignatureGetResponse of premint data from the API
1053
+ */
1054
+ async getPremintSignature({
1055
+ address,
1056
+ uid
1057
+ }) {
1058
+ return await this.apiClient.getSignature({
1059
+ collectionAddress: address,
1060
+ uid
1061
+ });
1062
+ }
1063
+ /**
1064
+ * Gets the deterministic contract address for a premint collection
1065
+ * @param collection Collection to get the address for
1066
+ * @returns deterministic contract address
1067
+ */
1068
+ async getCollectionAddress(collection) {
1069
+ return await getPremintCollectionAddress({
1070
+ collection,
1071
+ publicClient: this.publicClient
1072
+ });
1073
+ }
1074
+ /**
1075
+ * Check user signature for v1
1076
+ *
1077
+ * @param data Signature data from the API
1078
+ * @returns isValid = signature is valid or not, recoveredSigner = signer from contract
1079
+ */
1080
+ async isValidSignature({
1081
+ signature,
1082
+ collection,
1083
+ premintConfig,
1084
+ premintConfigVersion
1085
+ }) {
1086
+ const { isAuthorized, recoveredAddress } = await isValidSignature({
1087
+ chainId: this.chain.id,
1088
+ signature,
1089
+ collection,
1090
+ publicClient: this.publicClient,
1091
+ premintConfig,
1092
+ premintConfigVersion: premintConfigVersion || "1" /* V1 */
1093
+ });
1094
+ return { isValid: isAuthorized, recoveredSigner: recoveredAddress };
1095
+ }
1096
+ makeUrls({
1097
+ uid,
1098
+ address,
1099
+ tokenId
1100
+ }) {
1101
+ return makeUrls({
1102
+ uid,
1103
+ address,
1104
+ tokenId,
1105
+ chain: this.chain
1106
+ });
1107
+ }
1108
+ async getMintCosts({
1109
+ tokenContract,
1110
+ quantityToMint,
1111
+ pricePerToken
1112
+ }) {
1113
+ return await getPremintMintCosts({
1114
+ publicClient: this.publicClient,
1115
+ quantityToMint,
1116
+ tokenContract,
1117
+ tokenPrice: pricePerToken
1118
+ });
1119
+ }
1120
+ /**
1121
+ * Execute premint on-chain
1122
+ *
1123
+ * @param settings.data Data from the API for the mint
1124
+ * @param settings.account Optional account (if omitted taken from wallet client) for the account executing the premint.
1125
+ * @param settings.walletClient WalletClient to send execution from.
1126
+ * @param settings.mintArguments User minting arguments.
1127
+ * @param settings.mintArguments.quantityToMint Quantity to mint, optional, defaults to 1.
1128
+ * @param settings.mintArguments.mintComment Optional mint comment, optional, omits when not included.
1129
+ * @param settings.publicClient Optional public client for preflight checks.
1130
+ * @returns receipt, log, zoraURL
1131
+ */
1132
+ async makeMintParameters({
1133
+ uid,
1134
+ tokenContract,
1135
+ minterAccount,
1136
+ mintArguments
1137
+ }) {
1138
+ if (mintArguments && mintArguments?.quantityToMint < 1) {
1139
+ throw new Error("Quantity to mint cannot be below 1");
1140
+ }
1141
+ if (!minterAccount) {
1142
+ throw new Error("Wallet not passed in");
1143
+ }
1144
+ const { premintConfig, premintConfigVersion, collection, signature } = await this.getPremintSignature({
1145
+ address: tokenContract,
1146
+ uid
1147
+ });
1148
+ const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
1149
+ const value = (await getPremintMintCosts({
1150
+ tokenContract,
1151
+ quantityToMint: numberToMint,
1152
+ publicClient: this.publicClient,
1153
+ tokenPrice: premintConfig.tokenConfig.pricePerToken
1154
+ })).totalCost;
1155
+ const mintArgumentsContract = {
1156
+ mintComment: mintArguments?.mintComment || "",
1157
+ mintRecipient: mintArguments?.mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address),
1158
+ mintRewardsRecipients: makeMintRewardsRecipient({
1159
+ mintReferral: mintArguments?.mintReferral,
1160
+ platformReferral: mintArguments?.platformReferral
1161
+ })
1162
+ };
1163
+ if (premintConfigVersion === "1" /* V1 */) {
1164
+ return {
1165
+ account: minterAccount,
1166
+ abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
1167
+ functionName: "premintV1",
1168
+ value,
1169
+ address: getPremintExecutorAddress(),
1170
+ args: [
1171
+ collection,
1172
+ premintConfig,
1173
+ signature,
1174
+ numberToMint,
1175
+ mintArgumentsContract
1176
+ ]
1177
+ };
1178
+ } else if (premintConfigVersion === "2" /* V2 */) {
1179
+ return {
1180
+ account: minterAccount,
1181
+ abi: import_protocol_deployments2.zoraCreator1155PremintExecutorImplABI,
1182
+ functionName: "premintV2",
1183
+ value,
1184
+ address: getPremintExecutorAddress(),
1185
+ args: [
1186
+ collection,
1187
+ premintConfig,
1188
+ signature,
1189
+ numberToMint,
1190
+ mintArgumentsContract
1191
+ ]
1192
+ };
1193
+ }
1194
+ throw new Error(`Invalid premint config version ${premintConfigVersion}`);
1195
+ }
1196
+ };
1197
+ function createPremintClient({
1198
+ chain,
1199
+ httpClient: httpClient2,
1200
+ publicClient
1201
+ }) {
1202
+ return new PremintClient(chain, publicClient, httpClient2);
1203
+ }
1204
+ function makeUrls({
1205
+ uid,
1206
+ address,
1207
+ tokenId,
1208
+ chain
1209
+ }) {
1210
+ if ((!uid || !tokenId) && !address) {
1211
+ return { explorer: null, zoraCollect: null, zoraManage: null };
1212
+ }
1213
+ const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
1214
+ const network = getApiNetworkConfigForChain(chain.id);
1215
+ return {
1216
+ explorer: tokenId ? `https://${chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
1217
+ zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`,
1218
+ zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`
1219
+ };
1220
+ }
1221
+ async function signAndSubmitPremint({
1222
+ walletClient,
1223
+ verifyingContract,
1224
+ account,
1225
+ checkSignature,
1226
+ collection,
1227
+ chainId,
1228
+ publicClient,
1229
+ apiClient,
1230
+ ...premintConfigAndVersion
1231
+ }) {
1232
+ if (!account) {
1233
+ account = walletClient.account;
1234
+ }
1235
+ if (!account) {
1236
+ throw new Error("No account provided");
1237
+ }
1238
+ const signature = await walletClient.signTypedData({
1239
+ account,
1240
+ ...premintTypedDataDefinition({
1241
+ verifyingContract,
1242
+ ...premintConfigAndVersion,
1243
+ chainId
1244
+ })
1245
+ });
1246
+ if (checkSignature) {
1247
+ const isAuthorized = await isAuthorizedToCreatePremint({
1248
+ collection,
1249
+ publicClient,
1250
+ signer: typeof account === "string" ? account : account.address,
1251
+ collectionAddress: await getPremintCollectionAddress({
1252
+ collection,
1253
+ publicClient
1254
+ })
1255
+ });
1256
+ if (!isAuthorized) {
1257
+ throw new Error("Not authorized to create premint");
1258
+ }
1259
+ }
1260
+ const premint = await apiClient.postSignature({
1261
+ collection,
1262
+ signature,
1263
+ ...premintConfigAndVersion
1264
+ });
1265
+ return { premint, verifyingContract };
1266
+ }
1267
+
1268
+ // src/mint/mint-client.ts
1269
+ var import_viem5 = require("viem");
1270
+ var import_protocol_deployments3 = require("@zoralabs/protocol-deployments");
1271
+ var MintError = class extends Error {
1272
+ };
1273
+ var MintInactiveError = class extends Error {
1274
+ };
1275
+ var Errors = {
1276
+ MintError,
1277
+ MintInactiveError
1278
+ };
1279
+ var MintClient = class {
1280
+ constructor(chain, publicClient, httpClient2) {
1281
+ this.apiClient = new MintAPIClient(chain.id, httpClient2);
1282
+ this.publicClient = publicClient || (0, import_viem5.createPublicClient)({ chain, transport: (0, import_viem5.http)() });
1283
+ }
1284
+ /**
1285
+ * Returns the parameters needed to prepare a transaction mint a token.
1286
+ * @param param0.minterAccount The account that will mint the token.
1287
+ * @param param0.mintable The mintable token to mint.
1288
+ * @param param0.mintArguments The arguments for the mint (mint recipient, comment, mint referral, quantity to mint)
1289
+ * @returns
1290
+ */
1291
+ async makePrepareMintTokenParams({
1292
+ ...rest
1293
+ }) {
1294
+ return makePrepareMintTokenParams({
1295
+ ...rest,
1296
+ apiClient: this.apiClient,
1297
+ publicClient: this.publicClient
1298
+ });
1299
+ }
1300
+ };
1301
+ function createMintClient({
1302
+ chain,
1303
+ publicClient,
1304
+ httpClient: httpClient2
1305
+ }) {
1306
+ return new MintClient(chain, publicClient, httpClient2);
1307
+ }
1308
+ async function makePrepareMintTokenParams({
1309
+ publicClient,
1310
+ apiClient,
1311
+ tokenId,
1312
+ tokenAddress,
1313
+ ...rest
1314
+ }) {
1315
+ const salesConfigAndTokenInfo = await apiClient.getSalesConfigAndTokenInfo({
1316
+ tokenId,
1317
+ tokenAddress
1318
+ });
1319
+ if (tokenId === void 0) {
1320
+ return makePrepareMint721TokenParams({
1321
+ salesConfigAndTokenInfo,
1322
+ tokenAddress,
1323
+ ...rest
1324
+ });
1325
+ }
1326
+ return makePrepareMint1155TokenParams({
1327
+ salesConfigAndTokenInfo,
1328
+ tokenAddress,
1329
+ tokenId,
1330
+ ...rest
1331
+ });
1332
+ }
1333
+ async function makePrepareMint721TokenParams({
1334
+ tokenAddress,
1335
+ salesConfigAndTokenInfo,
1336
+ minterAccount,
1337
+ mintArguments
1338
+ }) {
1339
+ const mintValue = getMintCosts({
1340
+ salesConfigAndTokenInfo,
1341
+ quantityToMint: BigInt(mintArguments.quantityToMint)
1342
+ }).totalCost;
1343
+ const result = {
1344
+ abi: zora721Abi,
1345
+ address: tokenAddress,
1346
+ account: minterAccount,
1347
+ functionName: "mintWithRewards",
1348
+ value: mintValue,
1349
+ args: [
1350
+ mintArguments.mintToAddress,
1351
+ BigInt(mintArguments.quantityToMint),
1352
+ mintArguments.mintComment || "",
1353
+ mintArguments.mintReferral || import_viem5.zeroAddress
1354
+ ]
1355
+ };
1356
+ return result;
1357
+ }
1358
+ function getMintCosts({
1359
+ salesConfigAndTokenInfo,
1360
+ quantityToMint
1361
+ }) {
1362
+ const mintFeeForTokens = salesConfigAndTokenInfo.mintFeePerQuantity * quantityToMint;
1363
+ const tokenPurchaseCost = BigInt(salesConfigAndTokenInfo.fixedPrice.pricePerToken) * quantityToMint;
1364
+ return {
1365
+ mintFee: mintFeeForTokens,
1366
+ tokenPurchaseCost,
1367
+ totalCost: mintFeeForTokens + tokenPurchaseCost
1368
+ };
1369
+ }
1370
+ async function makePrepareMint1155TokenParams({
1371
+ tokenId,
1372
+ salesConfigAndTokenInfo,
1373
+ minterAccount,
1374
+ tokenAddress,
1375
+ mintArguments
1376
+ }) {
1377
+ const mintQuantity = BigInt(mintArguments.quantityToMint);
1378
+ const mintValue = getMintCosts({
1379
+ salesConfigAndTokenInfo,
1380
+ quantityToMint: mintQuantity
1381
+ }).totalCost;
1382
+ const result = {
1383
+ abi: import_protocol_deployments3.zoraCreator1155ImplABI,
1384
+ functionName: "mintWithRewards",
1385
+ account: minterAccount,
1386
+ value: mintValue,
1387
+ address: tokenAddress,
1388
+ /* args: minter, tokenId, quantity, minterArguments, mintReferral */
1389
+ args: [
1390
+ salesConfigAndTokenInfo?.fixedPrice.address || import_protocol_deployments3.zoraCreatorFixedPriceSaleStrategyAddress[999],
1391
+ BigInt(tokenId),
1392
+ mintQuantity,
1393
+ (0, import_viem5.encodeAbiParameters)((0, import_viem5.parseAbiParameters)("address, string"), [
1394
+ mintArguments.mintToAddress,
1395
+ mintArguments.mintComment || ""
1396
+ ]),
1397
+ mintArguments.mintReferral || import_viem5.zeroAddress
1398
+ ]
1399
+ };
1400
+ return result;
1401
+ }
1402
+
1403
+ // src/create/1155-create-helper.ts
1404
+ var import_protocol_deployments4 = require("@zoralabs/protocol-deployments");
1405
+ var import_viem6 = require("viem");
1406
+ var SALE_END_FOREVER = 18446744073709551615n;
1407
+ var ROYALTY_BPS_DEFAULT = 1e3;
1408
+ var DEFAULT_SALE_SETTINGS = {
1409
+ fundsRecipient: import_viem6.zeroAddress,
1410
+ // Free Mint
1411
+ pricePerToken: 0n,
1412
+ // Sale start time – defaults to beginning of unix time
1413
+ saleStart: 0n,
1414
+ // This is the end of uint64, plenty of time
1415
+ saleEnd: SALE_END_FOREVER,
1416
+ // 0 Here means no limit
1417
+ maxTokensPerAddress: 0n
1418
+ };
1419
+ var PERMISSION_BIT_MINTER = 4n;
1420
+ function create1155TokenSetupArgs({
1421
+ nextTokenId,
1422
+ // How many NFTs upon initialization to mint to the creator
1423
+ mintToCreatorCount,
1424
+ tokenMetadataURI,
1425
+ // Fixed price minter address – required minter
1426
+ fixedPriceMinterAddress,
1427
+ // Address to use as the create referral, optional.
1428
+ createReferral,
1429
+ // Optional max supply of the token. Default unlimited
1430
+ maxSupply,
1431
+ // wallet sending the transaction
1432
+ account,
1433
+ salesConfig,
1434
+ royaltySettings
1435
+ }) {
1436
+ if (!maxSupply) {
1437
+ maxSupply = OPEN_EDITION_MINT_SIZE;
1438
+ }
1439
+ maxSupply = BigInt(maxSupply);
1440
+ mintToCreatorCount = BigInt(mintToCreatorCount);
1441
+ const salesConfigWithDefaults = {
1442
+ // Set static sales default.
1443
+ ...DEFAULT_SALE_SETTINGS,
1444
+ // Override with user settings.
1445
+ ...salesConfig
1446
+ };
1447
+ const setupActions = [
1448
+ (0, import_viem6.encodeFunctionData)({
1449
+ abi: import_protocol_deployments4.zoraCreator1155ImplABI,
1450
+ functionName: "assumeLastTokenIdMatches",
1451
+ args: [nextTokenId - 1n]
1452
+ }),
1453
+ createReferral ? (0, import_viem6.encodeFunctionData)({
1454
+ abi: import_protocol_deployments4.zoraCreator1155ImplABI,
1455
+ functionName: "setupNewTokenWithCreateReferral",
1456
+ args: [tokenMetadataURI, maxSupply, createReferral]
1457
+ }) : (0, import_viem6.encodeFunctionData)({
1458
+ abi: import_protocol_deployments4.zoraCreator1155ImplABI,
1459
+ functionName: "setupNewToken",
1460
+ args: [tokenMetadataURI, maxSupply]
1461
+ }),
1462
+ (0, import_viem6.encodeFunctionData)({
1463
+ abi: import_protocol_deployments4.zoraCreator1155ImplABI,
1464
+ functionName: "addPermission",
1465
+ args: [0n, fixedPriceMinterAddress, PERMISSION_BIT_MINTER]
1466
+ }),
1467
+ (0, import_viem6.encodeFunctionData)({
1468
+ abi: import_protocol_deployments4.zoraCreator1155ImplABI,
1469
+ functionName: "callSale",
1470
+ args: [
1471
+ nextTokenId,
1472
+ fixedPriceMinterAddress,
1473
+ (0, import_viem6.encodeFunctionData)({
1474
+ abi: import_protocol_deployments4.zoraCreatorFixedPriceSaleStrategyABI,
1475
+ functionName: "setSale",
1476
+ args: [nextTokenId, salesConfigWithDefaults]
1477
+ })
1478
+ ]
1479
+ })
1480
+ ];
1481
+ if (mintToCreatorCount) {
1482
+ setupActions.push(
1483
+ (0, import_viem6.encodeFunctionData)({
1484
+ abi: import_protocol_deployments4.zoraCreator1155ImplABI,
1485
+ functionName: "adminMint",
1486
+ args: [account, nextTokenId, mintToCreatorCount, "0x"]
1487
+ })
1488
+ );
1489
+ }
1490
+ if (royaltySettings) {
1491
+ setupActions.push(
1492
+ (0, import_viem6.encodeFunctionData)({
1493
+ abi: import_protocol_deployments4.zoraCreator1155ImplABI,
1494
+ functionName: "updateRoyaltiesForToken",
1495
+ args: [
1496
+ nextTokenId,
1497
+ {
1498
+ royaltyMintSchedule: 0,
1499
+ royaltyBPS: royaltySettings?.royaltyBPS || ROYALTY_BPS_DEFAULT,
1500
+ royaltyRecipient: royaltySettings?.royaltyRecipient || account
1501
+ }
1502
+ ]
1503
+ })
1504
+ );
1505
+ }
1506
+ return setupActions;
1507
+ }
1508
+ var getTokenIdFromCreateReceipt = (receipt) => {
1509
+ for (const data of receipt.logs) {
1510
+ try {
1511
+ const decodedLog = (0, import_viem6.decodeEventLog)({
1512
+ abi: import_protocol_deployments4.zoraCreator1155ImplABI,
1513
+ eventName: "SetupNewToken",
1514
+ ...data
1515
+ });
1516
+ if (decodedLog && decodedLog.eventName === "SetupNewToken") {
1517
+ return decodedLog.args.tokenId;
1518
+ }
1519
+ } catch (err) {
1520
+ }
1521
+ }
1522
+ };
1523
+ async function getContractExists(publicClient, contract, account) {
1524
+ let contractAddress;
1525
+ let contractExists = false;
1526
+ if (typeof contract !== "string") {
1527
+ contractAddress = await publicClient.readContract({
1528
+ abi: import_protocol_deployments4.zoraCreator1155FactoryImplABI,
1529
+ // Since this address is deterministic we can hardcode a chain id safely here.
1530
+ address: import_protocol_deployments4.zoraCreator1155FactoryImplAddress[999],
1531
+ functionName: "deterministicContractAddress",
1532
+ args: [
1533
+ account,
1534
+ contract.uri,
1535
+ contract.name,
1536
+ contract.defaultAdmin || account
1537
+ ]
1538
+ });
1539
+ try {
1540
+ await publicClient.readContract({
1541
+ abi: import_protocol_deployments4.zoraCreator1155ImplABI,
1542
+ address: contractAddress,
1543
+ functionName: "contractVersion"
1544
+ });
1545
+ contractExists = true;
1546
+ } catch (e) {
1547
+ }
1548
+ return { contractAddress, contractExists };
1549
+ }
1550
+ return {
1551
+ contractExists: true,
1552
+ contractAddress: contract
1553
+ };
1554
+ }
1555
+ function create1155CreatorClient({
1556
+ publicClient
1557
+ }) {
1558
+ async function createNew1155Token({
1559
+ contract,
1560
+ tokenMetadataURI,
1561
+ mintToCreatorCount = 1,
1562
+ salesConfig = {},
1563
+ maxSupply,
1564
+ account,
1565
+ royaltySettings,
1566
+ getAdditionalSetupActions
1567
+ }) {
1568
+ const { contractExists, contractAddress } = await getContractExists(
1569
+ publicClient,
1570
+ contract,
1571
+ account
1572
+ );
1573
+ let nextTokenId = 1n;
1574
+ if (contractExists) {
1575
+ nextTokenId = await publicClient.readContract({
1576
+ abi: import_protocol_deployments4.zoraCreator1155ImplABI,
1577
+ functionName: "nextTokenId",
1578
+ address: contractAddress
1579
+ });
1580
+ }
1581
+ const fixedPriceMinterAddress = await publicClient.readContract({
1582
+ abi: import_protocol_deployments4.zoraCreator1155FactoryImplABI,
1583
+ address: import_protocol_deployments4.zoraCreator1155FactoryImplAddress[999],
1584
+ functionName: "fixedPriceMinter"
1585
+ });
1586
+ let tokenSetupActions = create1155TokenSetupArgs({
1587
+ tokenMetadataURI,
1588
+ nextTokenId,
1589
+ salesConfig,
1590
+ maxSupply,
1591
+ fixedPriceMinterAddress,
1592
+ account,
1593
+ mintToCreatorCount,
1594
+ royaltySettings
1595
+ });
1596
+ if (getAdditionalSetupActions) {
1597
+ tokenSetupActions = [
1598
+ ...getAdditionalSetupActions({ tokenId: nextTokenId, contractAddress }),
1599
+ ...tokenSetupActions
1600
+ ];
1601
+ }
1602
+ if (!contractAddress && typeof contract === "string") {
1603
+ throw new Error("Invariant: contract cannot be missing and an address");
1604
+ }
1605
+ if (!contractExists && typeof contract !== "string") {
1606
+ const request = {
1607
+ abi: import_protocol_deployments4.zoraCreator1155FactoryImplABI,
1608
+ functionName: "createContractDeterministic",
1609
+ account,
1610
+ address: import_protocol_deployments4.zoraCreator1155FactoryImplAddress[999],
1611
+ args: [
1612
+ contract.uri,
1613
+ contract.name,
1614
+ {
1615
+ // deprecated
1616
+ royaltyMintSchedule: 0,
1617
+ royaltyBPS: royaltySettings?.royaltyBPS || ROYALTY_BPS_DEFAULT,
1618
+ royaltyRecipient: royaltySettings?.royaltyRecipient || account
1619
+ },
1620
+ contract.defaultAdmin || account,
1621
+ tokenSetupActions
1622
+ ]
1623
+ };
1624
+ return {
1625
+ request,
1626
+ tokenSetupActions,
1627
+ contractAddress,
1628
+ contractExists
1629
+ };
1630
+ } else if (contractExists) {
1631
+ const request = {
1632
+ abi: import_protocol_deployments4.zoraCreator1155ImplABI,
1633
+ functionName: "multicall",
1634
+ account,
1635
+ address: contractAddress,
1636
+ args: [tokenSetupActions]
1637
+ };
1638
+ return {
1639
+ request,
1640
+ tokenSetupActions,
1641
+ contractAddress,
1642
+ contractExists
1643
+ };
1644
+ }
1645
+ throw new Error("Unsupported contract argument type");
1646
+ }
1647
+ return { createNew1155Token };
1648
+ }
1649
+ // Annotate the CommonJS export names for ESM import in node:
1650
+ 0 && (module.exports = {
1651
+ DEFAULT_SALE_SETTINGS,
1652
+ Errors,
1653
+ MintAPIClient,
1654
+ PremintAPIClient,
1655
+ PremintConfigVersion,
1656
+ PreminterDomain,
1657
+ ZORA_API_BASE,
1658
+ applyUpdateToPremint,
1659
+ convertCollectionFromApi,
1660
+ convertGetPremintApiResponse,
1661
+ convertPremintFromApi,
1662
+ create1155CreatorClient,
1663
+ create1155TokenSetupArgs,
1664
+ createMintClient,
1665
+ createPremintClient,
1666
+ defaultTokenConfigV1MintArguments,
1667
+ defaultTokenConfigV2MintArguments,
1668
+ encodePostSignatureInput,
1669
+ encodePremintForAPI,
1670
+ getApiNetworkConfigForChain,
1671
+ getDefaultFixedPriceMinterAddress,
1672
+ getMintCosts,
1673
+ getPremintCollectionAddress,
1674
+ getPremintExecutorAddress,
1675
+ getPremintMintCosts,
1676
+ getPremintMintFee,
1677
+ getPremintedLogFromReceipt,
1678
+ getTokenIdFromCreateReceipt,
1679
+ isAuthorizedToCreatePremint,
1680
+ isValidSignature,
1681
+ makeMintRewardsRecipient,
1682
+ makeNewPremint,
1683
+ markPremintDeleted,
1684
+ migratePremintConfigToV2,
1685
+ premintTypedDataDefinition,
1686
+ recoverCreatorFromCreatorAttribution,
1687
+ recoverPremintSigner,
1688
+ supportedPremintVersions,
1689
+ supportsPremintVersion,
1690
+ tryRecoverPremintSigner,
1691
+ v1Types,
1692
+ v2Types
1693
+ });
1694
+ //# sourceMappingURL=index.cjs.map