@zoralabs/protocol-sdk 0.3.3 → 0.3.5

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 (37) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +28 -0
  3. package/README.md +7 -26
  4. package/dist/anvil.d.ts +4 -2
  5. package/dist/anvil.d.ts.map +1 -1
  6. package/dist/constants.d.ts +32 -0
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/index.cjs +476 -323
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.js +447 -298
  11. package/dist/index.js.map +1 -1
  12. package/dist/mint/mint-api-client.d.ts +16 -213
  13. package/dist/mint/mint-api-client.d.ts.map +1 -1
  14. package/dist/mint/mint-client.d.ts +7 -226
  15. package/dist/mint/mint-client.d.ts.map +1 -1
  16. package/dist/premint/premint-client.d.ts +63 -17
  17. package/dist/premint/premint-client.d.ts.map +1 -1
  18. package/dist/premint/preminter.d.ts +106 -19
  19. package/dist/premint/preminter.d.ts.map +1 -1
  20. package/dist/types.d.ts +2 -0
  21. package/dist/types.d.ts.map +1 -0
  22. package/package.json +2 -1
  23. package/src/anvil.ts +7 -4
  24. package/src/constants.ts +7 -0
  25. package/src/create/1155-create-helper.ts +1 -1
  26. package/src/mint/mint-api-client.ts +79 -53
  27. package/src/mint/mint-client.test.ts +9 -11
  28. package/src/mint/mint-client.ts +50 -215
  29. package/src/premint/premint-client.test.ts +9 -8
  30. package/src/premint/premint-client.ts +113 -61
  31. package/src/premint/preminter.test.ts +207 -130
  32. package/src/premint/preminter.ts +388 -51
  33. package/src/types.ts +1 -0
  34. package/tsconfig.json +2 -17
  35. package/dist/apis/generated/discover-api-types.d.ts +0 -2131
  36. package/dist/apis/generated/discover-api-types.d.ts.map +0 -1
  37. package/src/apis/generated/discover-api-types.ts +0 -2180
package/dist/index.js CHANGED
@@ -1,60 +1,259 @@
1
1
  // src/premint/premint-client.ts
2
2
  import { createPublicClient, decodeEventLog, http } from "viem";
3
3
  import {
4
- zoraCreator1155PremintExecutorImplABI,
5
- zoraCreator1155PremintExecutorImplAddress,
4
+ zoraCreator1155PremintExecutorImplABI as zoraCreator1155PremintExecutorImplABI2,
6
5
  zoraCreatorFixedPriceSaleStrategyAddress
7
6
  } from "@zoralabs/protocol-deployments";
8
7
 
9
8
  // src/premint/preminter.ts
10
- var preminterTypedDataDefinition = ({
9
+ import {
10
+ zoraCreator1155PremintExecutorImplABI as preminterAbi,
11
+ zoraCreator1155PremintExecutorImplABI,
12
+ zoraCreator1155PremintExecutorImplAddress
13
+ } from "@zoralabs/protocol-deployments";
14
+ import {
15
+ recoverTypedDataAddress,
16
+ zeroAddress,
17
+ hashDomain,
18
+ keccak256,
19
+ concat,
20
+ recoverAddress
21
+ } from "viem";
22
+ var v1Types = {
23
+ CreatorAttribution: [
24
+ { name: "tokenConfig", type: "TokenCreationConfig" },
25
+ // unique id scoped to the contract and token to create.
26
+ // ensure that a signature can be replaced, as long as the replacement
27
+ // has the same uid, and a newer version.
28
+ { name: "uid", type: "uint32" },
29
+ { name: "version", type: "uint32" },
30
+ // if this update should result in the signature being deleted.
31
+ { name: "deleted", type: "bool" }
32
+ ],
33
+ TokenCreationConfig: [
34
+ { name: "tokenURI", type: "string" },
35
+ { name: "maxSupply", type: "uint256" },
36
+ { name: "maxTokensPerAddress", type: "uint64" },
37
+ { name: "pricePerToken", type: "uint96" },
38
+ { name: "mintStart", type: "uint64" },
39
+ { name: "mintDuration", type: "uint64" },
40
+ { name: "royaltyMintSchedule", type: "uint32" },
41
+ { name: "royaltyBPS", type: "uint32" },
42
+ { name: "royaltyRecipient", type: "address" },
43
+ { name: "fixedPriceMinter", type: "address" }
44
+ ]
45
+ };
46
+ var v2Types = {
47
+ CreatorAttribution: [
48
+ { name: "tokenConfig", type: "TokenCreationConfig" },
49
+ // unique id scoped to the contract and token to create.
50
+ // ensure that a signature can be replaced, as long as the replacement
51
+ // has the same uid, and a newer version.
52
+ { name: "uid", type: "uint32" },
53
+ { name: "version", type: "uint32" },
54
+ // if this update should result in the signature being deleted.
55
+ { name: "deleted", type: "bool" }
56
+ ],
57
+ TokenCreationConfig: [
58
+ { name: "tokenURI", type: "string" },
59
+ { name: "maxSupply", type: "uint256" },
60
+ { name: "maxTokensPerAddress", type: "uint64" },
61
+ { name: "pricePerToken", type: "uint96" },
62
+ { name: "mintStart", type: "uint64" },
63
+ { name: "mintDuration", type: "uint64" },
64
+ { name: "royaltyBPS", type: "uint32" },
65
+ { name: "payoutRecipient", type: "address" },
66
+ { name: "fixedPriceMinter", type: "address" },
67
+ { name: "createReferral", type: "address" }
68
+ ]
69
+ };
70
+ var PreminterDomain = "Preminter";
71
+ var PremintConfigVersion = {
72
+ V1: "1",
73
+ V2: "2"
74
+ };
75
+ var getPremintExecutorAddress = () => zoraCreator1155PremintExecutorImplAddress[999];
76
+ var premintTypedDataDefinition = ({
11
77
  verifyingContract,
12
- premintConfig,
13
- chainId
78
+ chainId,
79
+ premintConfigVersion: version,
80
+ premintConfig
14
81
  }) => {
15
- const { tokenConfig, uid, version, deleted } = premintConfig;
16
- const types = {
17
- CreatorAttribution: [
18
- { name: "tokenConfig", type: "TokenCreationConfig" },
19
- // unique id scoped to the contract and token to create.
20
- // ensure that a signature can be replaced, as long as the replacement
21
- // has the same uid, and a newer version.
22
- { name: "uid", type: "uint32" },
23
- { name: "version", type: "uint32" },
24
- // if this update should result in the signature being deleted.
25
- { name: "deleted", type: "bool" }
26
- ],
27
- TokenCreationConfig: [
28
- { name: "tokenURI", type: "string" },
29
- { name: "maxSupply", type: "uint256" },
30
- { name: "maxTokensPerAddress", type: "uint64" },
31
- { name: "pricePerToken", type: "uint96" },
32
- { name: "mintStart", type: "uint64" },
33
- { name: "mintDuration", type: "uint64" },
34
- { name: "royaltyMintSchedule", type: "uint32" },
35
- { name: "royaltyBPS", type: "uint32" },
36
- { name: "royaltyRecipient", type: "address" },
37
- { name: "fixedPriceMinter", type: "address" }
38
- ]
82
+ const domain = {
83
+ chainId,
84
+ name: PreminterDomain,
85
+ version,
86
+ verifyingContract
39
87
  };
40
- const result = {
88
+ if (version === PremintConfigVersion.V1)
89
+ return {
90
+ domain,
91
+ types: v1Types,
92
+ message: premintConfig,
93
+ primaryType: "CreatorAttribution"
94
+ };
95
+ if (version === PremintConfigVersion.V2) {
96
+ return {
97
+ domain,
98
+ types: v2Types,
99
+ message: premintConfig,
100
+ primaryType: "CreatorAttribution"
101
+ };
102
+ }
103
+ throw new Error(`Invalid version ${version}`);
104
+ };
105
+ async function isAuthorizedToCreatePremint({
106
+ collection,
107
+ collectionAddress,
108
+ publicClient,
109
+ premintConfig,
110
+ premintConfigVersion,
111
+ signature,
112
+ signer
113
+ }) {
114
+ if (premintConfigVersion === PremintConfigVersion.V1) {
115
+ const [isValidSignature2] = await publicClient.readContract({
116
+ abi: zoraCreator1155PremintExecutorImplABI,
117
+ address: getPremintExecutorAddress(),
118
+ functionName: "isValidSignature",
119
+ args: [collection, premintConfig, signature]
120
+ });
121
+ return isValidSignature2;
122
+ }
123
+ return await publicClient.readContract({
124
+ abi: preminterAbi,
125
+ address: getPremintExecutorAddress(),
126
+ functionName: "isAuthorizedToCreatePremint",
127
+ args: [signer, collection.contractAdmin, collectionAddress]
128
+ });
129
+ }
130
+ async function recoverPremintSigner({
131
+ signature,
132
+ ...rest
133
+ }) {
134
+ const typedData = premintTypedDataDefinition(rest);
135
+ return await recoverTypedDataAddress({
136
+ ...typedData,
137
+ signature
138
+ });
139
+ }
140
+ async function tryRecoverPremintSigner(params) {
141
+ try {
142
+ return await recoverPremintSigner(params);
143
+ } catch (error) {
144
+ console.error(error);
145
+ return void 0;
146
+ }
147
+ }
148
+ async function isValidSignature({
149
+ signature,
150
+ publicClient,
151
+ collection,
152
+ chainId,
153
+ ...premintConfigAndVersion
154
+ }) {
155
+ const tokenContract = await getPremintCollectionAddress({
156
+ collection,
157
+ publicClient
158
+ });
159
+ const recoveredAddress = await tryRecoverPremintSigner({
160
+ ...premintConfigAndVersion,
161
+ signature,
162
+ verifyingContract: tokenContract,
163
+ chainId
164
+ });
165
+ if (!recoverAddress) {
166
+ return {
167
+ isAuthorized: false
168
+ };
169
+ }
170
+ const isAuthorized = await isAuthorizedToCreatePremint({
171
+ signer: recoveredAddress,
172
+ collection,
173
+ collectionAddress: tokenContract,
174
+ publicClient,
175
+ signature,
176
+ ...premintConfigAndVersion
177
+ });
178
+ return {
179
+ isAuthorized,
180
+ recoveredAddress
181
+ };
182
+ }
183
+ function migratePremintConfigToV2({
184
+ premintConfig,
185
+ createReferral = zeroAddress
186
+ }) {
187
+ return {
188
+ ...premintConfig,
189
+ tokenConfig: {
190
+ tokenURI: premintConfig.tokenConfig.tokenURI,
191
+ maxSupply: premintConfig.tokenConfig.maxSupply,
192
+ maxTokensPerAddress: premintConfig.tokenConfig.maxTokensPerAddress,
193
+ pricePerToken: premintConfig.tokenConfig.pricePerToken,
194
+ mintStart: premintConfig.tokenConfig.mintStart,
195
+ mintDuration: premintConfig.tokenConfig.mintDuration,
196
+ payoutRecipient: premintConfig.tokenConfig.royaltyRecipient,
197
+ royaltyBPS: premintConfig.tokenConfig.royaltyBPS,
198
+ fixedPriceMinter: premintConfig.tokenConfig.fixedPriceMinter,
199
+ createReferral
200
+ }
201
+ };
202
+ }
203
+ var recoverCreatorFromCreatorAttribution = async ({
204
+ creatorAttribution: { version, domainName, structHash, signature },
205
+ chainId,
206
+ tokenContract
207
+ }) => {
208
+ const hashedDomain = hashDomain({
41
209
  domain: {
42
210
  chainId,
43
- name: "Preminter",
44
- version: "1",
45
- verifyingContract
46
- },
47
- types,
48
- message: {
49
- tokenConfig,
50
- uid,
51
- version,
52
- deleted
211
+ name: domainName,
212
+ verifyingContract: tokenContract,
213
+ version
53
214
  },
54
- primaryType: "CreatorAttribution"
55
- };
56
- return result;
215
+ types: {
216
+ EIP712Domain: [
217
+ { name: "name", type: "string" },
218
+ { name: "version", type: "string" },
219
+ {
220
+ name: "chainId",
221
+ type: "uint256"
222
+ },
223
+ {
224
+ name: "verifyingContract",
225
+ type: "address"
226
+ }
227
+ ]
228
+ }
229
+ });
230
+ const parts = ["0x1901", hashedDomain, structHash];
231
+ const hashedTypedData = keccak256(concat(parts));
232
+ return await recoverAddress({
233
+ hash: hashedTypedData,
234
+ signature
235
+ });
57
236
  };
237
+ var supportsPremintVersion = async (version, tokenContract, publicClient) => {
238
+ const supportedPremintSignatureVersions = await publicClient.readContract({
239
+ abi: preminterAbi,
240
+ address: getPremintExecutorAddress(),
241
+ functionName: "supportedPremintSignatureVersions",
242
+ args: [tokenContract]
243
+ });
244
+ return supportedPremintSignatureVersions.includes(version);
245
+ };
246
+ async function getPremintCollectionAddress({
247
+ collection,
248
+ publicClient
249
+ }) {
250
+ return publicClient.readContract({
251
+ address: getPremintExecutorAddress(),
252
+ abi: zoraCreator1155PremintExecutorImplABI,
253
+ functionName: "getContractAddress",
254
+ args: [collection]
255
+ });
256
+ }
58
257
 
59
258
  // src/apis/http-api-base.ts
60
259
  var BadResponseError = class extends Error {
@@ -131,12 +330,17 @@ var httpClient = {
131
330
  };
132
331
 
133
332
  // src/constants.ts
333
+ import { parseAbi } from "viem";
134
334
  var ZORA_API_BASE = "https://api.zora.co/";
135
335
  var OPEN_EDITION_MINT_SIZE = BigInt("18446744073709551615");
136
336
  var SUBGRAPH_CONFIG_BASE = "https://api.goldsky.com/api/public/project_clhk16b61ay9t49vm6ntn4mkz/subgraphs";
137
337
  function getSubgraph(name, version) {
138
338
  return `${SUBGRAPH_CONFIG_BASE}/${name}/${version}/gn`;
139
339
  }
340
+ var zora721Abi = parseAbi([
341
+ "function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
342
+ "function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
343
+ ]);
140
344
 
141
345
  // src/apis/chain-constants.ts
142
346
  import {
@@ -229,9 +433,6 @@ var networkConfigByChain = {
229
433
  };
230
434
 
231
435
  // src/mint/mint-api-client.ts
232
- function encodeQueryParameters(params) {
233
- return new URLSearchParams(params).toString();
234
- }
235
436
  var getApiNetworkConfigForChain = (chainId) => {
236
437
  if (!networkConfigByChain[chainId]) {
237
438
  throw new Error(`chain id ${chainId} network not configured `);
@@ -243,41 +444,64 @@ var MintAPIClient = class {
243
444
  this.httpClient = httpClient2 || httpClient;
244
445
  this.networkConfig = getApiNetworkConfigForChain(chainId);
245
446
  }
246
- async getMintable(path, query) {
247
- const httpClient2 = this.httpClient;
248
- return httpClient2.retries(() => {
249
- return httpClient2.get(
250
- `${ZORA_API_BASE}discover/mintables/${path.chain_name}/${path.collection_address}${query?.token_id ? `?${encodeQueryParameters(query)}` : ""}`
251
- );
252
- });
253
- }
254
- async getSalesConfigFixedPrice({
255
- contractAddress,
447
+ async getSalesConfigAndTokenInfo({
448
+ tokenAddress,
256
449
  tokenId
257
450
  }) {
258
451
  const { retries: retries2, post: post2 } = this.httpClient;
259
452
  return retries2(async () => {
260
453
  const response = await post2(this.networkConfig.subgraphUrl, {
261
- query: "query($id: ID!) {\n zoraCreateToken(id: $id) {\n id\n salesStrategies{\n fixedPrice {\n address\n }\n }\n }\n}",
454
+ query: `
455
+ fragment SaleStrategy on SalesStrategyConfig {
456
+ type
457
+ fixedPrice {
458
+ address
459
+ pricePerToken
460
+ saleEnd
461
+ saleStart
462
+ maxTokensPerAddress
463
+ }
464
+ }
465
+
466
+ query ($id: ID!) {
467
+ zoraCreateToken(id: $id) {
468
+ id
469
+ contract {
470
+ mintFeePerQuantity
471
+ salesStrategies(where: {type: "FIXED_PRICE"}) {
472
+ ...SaleStrategy
473
+ }
474
+ }
475
+ salesStrategies(where: {type: "FIXED_PRICE"}) {
476
+ ...SaleStrategy
477
+ }
478
+ }
479
+ }
480
+ `,
262
481
  variables: {
263
- id: `${contractAddress.toLowerCase()}-${tokenId.toString()}`
482
+ id: tokenId !== void 0 ? (
483
+ // Generic Token ID types all stringify down to the base numeric equivalent.
484
+ `${tokenAddress.toLowerCase()}-${tokenId}`
485
+ ) : `${tokenAddress.toLowerCase()}-0`
264
486
  }
265
487
  });
266
- return response.zoraCreateToken?.salesStrategies?.find(() => true)?.fixedPriceMinterAddress;
488
+ const token = response.data?.zoraCreateToken;
489
+ if (!token) {
490
+ throw new Error("Cannot find a token to mint");
491
+ }
492
+ const saleStrategies = tokenId !== void 0 ? token.salesStrategies : token.contract.salesStrategies;
493
+ const fixedPrice = saleStrategies?.sort(
494
+ (a, b) => BigInt(a.fixedPrice.saleEnd) > BigInt(b.fixedPrice.saleEnd) ? 1 : -1
495
+ )?.find(() => true)?.fixedPrice;
496
+ if (!fixedPrice) {
497
+ throw new Error("Cannot find fixed price sale strategy");
498
+ }
499
+ return {
500
+ fixedPrice,
501
+ mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
502
+ };
267
503
  });
268
504
  }
269
- async getMintableForToken({
270
- tokenContract,
271
- tokenId
272
- }) {
273
- return await this.getMintable(
274
- {
275
- chain_name: this.networkConfig.zoraBackendChainName,
276
- collection_address: tokenContract
277
- },
278
- { token_id: tokenId?.toString() }
279
- );
280
- }
281
505
  };
282
506
 
283
507
  // src/premint/premint-api-client.ts
@@ -348,7 +572,7 @@ function getPremintedLogFromReceipt(receipt) {
348
572
  for (const data of receipt.logs) {
349
573
  try {
350
574
  const decodedLog = decodeEventLog({
351
- abi: zoraCreator1155PremintExecutorImplABI,
575
+ abi: zoraCreator1155PremintExecutorImplABI2,
352
576
  eventName: "Preminted",
353
577
  ...data
354
578
  });
@@ -359,7 +583,7 @@ function getPremintedLogFromReceipt(receipt) {
359
583
  }
360
584
  }
361
585
  }
362
- var convertPremint = (premint) => ({
586
+ var convertPremintV1 = (premint) => ({
363
587
  ...premint,
364
588
  tokenConfig: {
365
589
  ...premint.tokenConfig,
@@ -376,7 +600,21 @@ var convertCollection = (collection) => ({
376
600
  ...collection,
377
601
  contractAdmin: collection.contractAdmin
378
602
  });
379
- var encodePremintForAPI = ({
603
+ var encodePremintV1ForAPI = ({
604
+ tokenConfig,
605
+ ...premint
606
+ }) => ({
607
+ ...premint,
608
+ tokenConfig: {
609
+ ...tokenConfig,
610
+ maxSupply: tokenConfig.maxSupply.toString(),
611
+ pricePerToken: tokenConfig.pricePerToken.toString(),
612
+ mintStart: tokenConfig.mintStart.toString(),
613
+ mintDuration: tokenConfig.mintDuration.toString(),
614
+ maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
615
+ }
616
+ });
617
+ var encodePremintV2ForAPI = ({
380
618
  tokenConfig,
381
619
  ...premint
382
620
  }) => ({
@@ -390,21 +628,24 @@ var encodePremintForAPI = ({
390
628
  maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
391
629
  }
392
630
  });
631
+ var encodePremintForAPI = ({
632
+ premintConfig,
633
+ premintConfigVersion
634
+ }) => {
635
+ if (premintConfigVersion === PremintConfigVersion.V1) {
636
+ return encodePremintV1ForAPI(premintConfig);
637
+ }
638
+ if (premintConfigVersion === PremintConfigVersion.V2) {
639
+ return encodePremintV2ForAPI(premintConfig);
640
+ }
641
+ throw new Error(`Invalid premint config version ${premintConfigVersion}`);
642
+ };
393
643
  var PremintClient = class {
394
644
  constructor(chain, publicClient, httpClient2) {
395
645
  this.chain = chain;
396
646
  this.apiClient = new PremintAPIClient(chain.id, httpClient2);
397
647
  this.publicClient = publicClient || createPublicClient({ chain, transport: http() });
398
648
  }
399
- /**
400
- * The premint executor address is deployed to the same address across all chains.
401
- * Can be overridden as needed by making a parent class.
402
- *
403
- * @returns Executor address for premints
404
- */
405
- getExecutorAddress() {
406
- return zoraCreator1155PremintExecutorImplAddress[999];
407
- }
408
649
  /**
409
650
  * The fixed price minter address is the same across all chains for our current
410
651
  * deployer strategy.
@@ -454,7 +695,7 @@ var PremintClient = class {
454
695
  collection_address: collection.toLowerCase(),
455
696
  uid
456
697
  });
457
- const convertedPremint = convertPremint(signatureResponse.premint);
698
+ const convertedPremint = convertPremintV1(signatureResponse.premint);
458
699
  const signerData = {
459
700
  ...signatureResponse,
460
701
  premint: {
@@ -475,7 +716,8 @@ var PremintClient = class {
475
716
  ...signerData.collection,
476
717
  contractAdmin: signerData.collection.contractAdmin
477
718
  },
478
- premintConfig: signerData.premint
719
+ premintConfig: signerData.premint,
720
+ premintConfigVersion: PremintConfigVersion.V1
479
721
  });
480
722
  }
481
723
  /**
@@ -506,7 +748,7 @@ var PremintClient = class {
506
748
  ...signatureResponse,
507
749
  collection: convertCollection(signatureResponse.collection),
508
750
  premint: {
509
- ...convertPremint(signatureResponse.premint),
751
+ ...convertPremintV1(signatureResponse.premint),
510
752
  deleted: true
511
753
  }
512
754
  };
@@ -517,7 +759,8 @@ var PremintClient = class {
517
759
  verifyingContract: collection,
518
760
  uid,
519
761
  collection: signerData.collection,
520
- premintConfig: signerData.premint
762
+ premintConfig: signerData.premint,
763
+ premintConfigVersion: PremintConfigVersion.V1
521
764
  });
522
765
  }
523
766
  /**
@@ -529,11 +772,11 @@ var PremintClient = class {
529
772
  async signAndSubmitPremint({
530
773
  walletClient,
531
774
  verifyingContract,
532
- premintConfig,
533
775
  uid,
534
776
  account,
535
777
  checkSignature,
536
- collection
778
+ collection,
779
+ ...premintConfigAndVersion
537
780
  }) {
538
781
  if (!account) {
539
782
  account = walletClient.account;
@@ -543,26 +786,32 @@ var PremintClient = class {
543
786
  }
544
787
  const signature = await walletClient.signTypedData({
545
788
  account,
546
- ...preminterTypedDataDefinition({
789
+ ...premintTypedDataDefinition({
547
790
  verifyingContract,
548
- premintConfig,
791
+ ...premintConfigAndVersion,
549
792
  chainId: this.chain.id
550
793
  })
551
794
  });
552
795
  if (checkSignature) {
553
- const [isValidSignature] = await this.publicClient.readContract({
554
- abi: zoraCreator1155PremintExecutorImplABI,
555
- address: this.getExecutorAddress(),
556
- functionName: "isValidSignature",
557
- args: [convertCollection(collection), premintConfig, signature]
796
+ const convertedCollection = convertCollection(collection);
797
+ const isAuthorized = await isAuthorizedToCreatePremint({
798
+ collection: convertCollection(collection),
799
+ signature,
800
+ publicClient: this.publicClient,
801
+ signer: typeof account === "string" ? account : account.address,
802
+ collectionAddress: await this.getCollectionAddress(convertedCollection),
803
+ ...premintConfigAndVersion
558
804
  });
559
- if (!isValidSignature) {
560
- throw new Error("Invalid signature");
805
+ if (!isAuthorized) {
806
+ throw new Error("Not authorized to create premint");
561
807
  }
562
808
  }
809
+ if (premintConfigAndVersion.premintConfigVersion === PremintConfigVersion.V2) {
810
+ throw new Error("premint config v2 not supported yet");
811
+ }
563
812
  const apiData = {
564
813
  collection,
565
- premint: encodePremintForAPI(premintConfig),
814
+ premint: encodePremintV1ForAPI(premintConfigAndVersion.premintConfig),
566
815
  signature
567
816
  };
568
817
  const premint = await this.apiClient.postSignature(apiData);
@@ -596,11 +845,9 @@ var PremintClient = class {
596
845
  executionSettings,
597
846
  checkSignature = false
598
847
  }) {
599
- const newContractAddress = await this.publicClient.readContract({
600
- address: this.getExecutorAddress(),
601
- abi: zoraCreator1155PremintExecutorImplABI,
602
- functionName: "getContractAddress",
603
- args: [convertCollection(collection)]
848
+ const newContractAddress = await getPremintCollectionAddress({
849
+ publicClient: this.publicClient,
850
+ collection: convertCollection(collection)
604
851
  });
605
852
  const tokenConfig = {
606
853
  ...DefaultMintArguments,
@@ -629,6 +876,7 @@ var PremintClient = class {
629
876
  uid,
630
877
  verifyingContract: newContractAddress,
631
878
  premintConfig,
879
+ premintConfigVersion: PremintConfigVersion.V1,
632
880
  checkSignature,
633
881
  account,
634
882
  walletClient,
@@ -651,26 +899,37 @@ var PremintClient = class {
651
899
  uid
652
900
  });
653
901
  }
902
+ /**
903
+ * Gets the deterministic contract address for a premint collection
904
+ * @param collection Collection to get the address for
905
+ * @returns deterministic contract address
906
+ */
907
+ async getCollectionAddress(collection) {
908
+ return await getPremintCollectionAddress({
909
+ collection,
910
+ publicClient: this.publicClient
911
+ });
912
+ }
654
913
  /**
655
914
  * Check user signature for v1
656
915
  *
657
916
  * @param data Signature data from the API
658
- * @returns isValid = signature is valid or not, contractAddress = assumed contract address, recoveredSigner = signer from contract
917
+ * @returns isValid = signature is valid or not, recoveredSigner = signer from contract
659
918
  */
660
919
  async isValidSignature({
661
- data
920
+ signature,
921
+ premint,
922
+ collection
662
923
  }) {
663
- const [isValid, contractAddress, recoveredSigner] = await this.publicClient.readContract({
664
- abi: zoraCreator1155PremintExecutorImplABI,
665
- address: this.getExecutorAddress(),
666
- functionName: "isValidSignature",
667
- args: [
668
- convertCollection(data.collection),
669
- convertPremint(data.premint),
670
- data.signature
671
- ]
924
+ const { isAuthorized, recoveredAddress } = await isValidSignature({
925
+ chainId: this.chain.id,
926
+ signature,
927
+ premintConfig: convertPremintV1(premint),
928
+ premintConfigVersion: PremintConfigVersion.V1,
929
+ collection: convertCollection(collection),
930
+ publicClient: this.publicClient
672
931
  });
673
- return { isValid, contractAddress, recoveredSigner };
932
+ return { isValid: isAuthorized, recoveredSigner: recoveredAddress };
674
933
  }
675
934
  makeUrls({
676
935
  uid,
@@ -708,11 +967,10 @@ var PremintClient = class {
708
967
  if (mintArguments && mintArguments?.quantityToMint < 1) {
709
968
  throw new Error("Quantity to mint cannot be below 1");
710
969
  }
711
- const targetAddress = this.getExecutorAddress();
712
970
  const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
713
971
  const args = [
714
972
  convertCollection(data.collection),
715
- convertPremint(data.premint),
973
+ convertPremintV1(data.premint),
716
974
  data.signature,
717
975
  numberToMint,
718
976
  mintArguments?.mintComment || ""
@@ -723,10 +981,10 @@ var PremintClient = class {
723
981
  const value = numberToMint * REWARD_PER_TOKEN;
724
982
  const request = {
725
983
  account,
726
- abi: zoraCreator1155PremintExecutorImplABI,
984
+ abi: zoraCreator1155PremintExecutorImplABI2,
727
985
  functionName: "premint",
728
986
  value,
729
- address: targetAddress,
987
+ address: getPremintExecutorAddress(),
730
988
  args
731
989
  };
732
990
  return request;
@@ -744,13 +1002,12 @@ function createPremintClient({
744
1002
  import {
745
1003
  createPublicClient as createPublicClient2,
746
1004
  encodeAbiParameters,
747
- parseAbi,
748
1005
  parseAbiParameters,
749
- zeroAddress,
1006
+ zeroAddress as zeroAddress2,
750
1007
  http as http2
751
1008
  } from "viem";
752
1009
  import {
753
- zoraCreator1155ImplABI,
1010
+ zoraCreator1155ImplABI as zoraCreator1155ImplABI2,
754
1011
  zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress2
755
1012
  } from "@zoralabs/protocol-deployments";
756
1013
  var MintError = class extends Error {
@@ -761,30 +1018,11 @@ var Errors = {
761
1018
  MintError,
762
1019
  MintInactiveError
763
1020
  };
764
- var zora721Abi = parseAbi([
765
- "function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
766
- "function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
767
- ]);
768
1021
  var MintClient = class {
769
1022
  constructor(chain, publicClient, httpClient2) {
770
1023
  this.apiClient = new MintAPIClient(chain.id, httpClient2);
771
1024
  this.publicClient = publicClient || createPublicClient2({ chain, transport: http2() });
772
1025
  }
773
- /**
774
- * Gets mintable information for a given token
775
- * @param param0.tokenContract The contract address of the token to mint.
776
- * @param param0.tokenId The token id to mint.
777
- * @returns
778
- */
779
- async getMintable({
780
- tokenContract,
781
- tokenId
782
- }) {
783
- return await this.apiClient.getMintableForToken({
784
- tokenContract,
785
- tokenId: tokenId?.toString()
786
- });
787
- }
788
1026
  /**
789
1027
  * Returns the parameters needed to prepare a transaction mint a token.
790
1028
  * @param param0.minterAccount The account that will mint the token.
@@ -801,35 +1039,6 @@ var MintClient = class {
801
1039
  publicClient: this.publicClient
802
1040
  });
803
1041
  }
804
- /**
805
- * Returns the mintFee, sale fee, and total cost of minting x quantities of a token.
806
- * @param param0.mintable The mintable token to mint.
807
- * @param param0.quantityToMint The quantity of tokens to mint.
808
- * @returns
809
- */
810
- async getMintCosts({
811
- mintable,
812
- quantityToMint
813
- }) {
814
- const mintContextType = validateMintableAndGetContextType(mintable);
815
- if (mintContextType === "zora_create_1155") {
816
- return await get1155MintCosts({
817
- mintable,
818
- publicClient: this.publicClient,
819
- quantityToMint: BigInt(quantityToMint)
820
- });
821
- }
822
- if (mintContextType === "zora_create") {
823
- return await get721MintCosts({
824
- mintable,
825
- publicClient: this.publicClient,
826
- quantityToMint: BigInt(quantityToMint)
827
- });
828
- }
829
- throw new MintError(
830
- `Mintable type ${mintContextType} is currently unsupported.`
831
- );
832
- }
833
1042
  };
834
1043
  function createMintClient({
835
1044
  chain,
@@ -838,91 +1047,44 @@ function createMintClient({
838
1047
  }) {
839
1048
  return new MintClient(chain, publicClient, httpClient2);
840
1049
  }
841
- function validateMintableAndGetContextType(mintable) {
842
- if (!mintable) {
843
- throw new MintError("No mintable found");
844
- }
845
- if (!mintable.is_active) {
846
- throw new MintInactiveError("Minting token is inactive");
847
- }
848
- if (!mintable.mint_context) {
849
- throw new MintError("No minting context data from zora API");
850
- }
851
- if (!["zora_create", "zora_create_1155"].includes(
852
- mintable.mint_context?.mint_context_type
853
- )) {
854
- throw new MintError(
855
- `Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`
856
- );
857
- }
858
- return mintable.mint_context.mint_context_type;
859
- }
860
1050
  async function makePrepareMintTokenParams({
861
1051
  publicClient,
862
- mintable,
863
1052
  apiClient,
1053
+ tokenId,
1054
+ tokenAddress,
864
1055
  ...rest
865
1056
  }) {
866
- const mintContextType = validateMintableAndGetContextType(mintable);
867
- const thisPublicClient = publicClient;
868
- if (mintContextType === "zora_create_1155") {
869
- return makePrepareMint1155TokenParams({
870
- apiClient,
871
- publicClient: thisPublicClient,
872
- mintable,
873
- mintContextType,
874
- ...rest
875
- });
876
- }
877
- if (mintContextType === "zora_create") {
1057
+ const salesConfigAndTokenInfo = await apiClient.getSalesConfigAndTokenInfo({
1058
+ tokenId,
1059
+ tokenAddress
1060
+ });
1061
+ if (tokenId === void 0) {
878
1062
  return makePrepareMint721TokenParams({
879
- publicClient: thisPublicClient,
880
- mintable,
881
- mintContextType,
1063
+ salesConfigAndTokenInfo,
1064
+ tokenAddress,
882
1065
  ...rest
883
1066
  });
884
1067
  }
885
- throw new MintError(
886
- `Mintable type ${mintContextType} is currently unsupported.`
887
- );
888
- }
889
- async function get721MintCosts({
890
- mintable,
891
- publicClient,
892
- quantityToMint
893
- }) {
894
- const address = mintable.collection.address;
895
- const [_, mintFee] = await publicClient.readContract({
896
- abi: zora721Abi,
897
- address,
898
- functionName: "zoraFeeForAmount",
899
- args: [BigInt(quantityToMint)]
1068
+ return makePrepareMint1155TokenParams({
1069
+ salesConfigAndTokenInfo,
1070
+ tokenAddress,
1071
+ tokenId,
1072
+ ...rest
900
1073
  });
901
- const tokenPurchaseCost = BigInt(mintable.cost.native_price.raw) * quantityToMint;
902
- return {
903
- mintFee,
904
- tokenPurchaseCost,
905
- totalCost: mintFee + tokenPurchaseCost
906
- };
907
1074
  }
908
1075
  async function makePrepareMint721TokenParams({
909
- publicClient,
1076
+ tokenAddress,
1077
+ salesConfigAndTokenInfo,
910
1078
  minterAccount,
911
- mintable,
912
- mintContextType,
913
1079
  mintArguments
914
1080
  }) {
915
- if (mintContextType !== "zora_create") {
916
- throw new Error("Minted token type must be for 1155");
917
- }
918
- const mintValue = (await get721MintCosts({
919
- mintable,
920
- publicClient,
1081
+ const mintValue = getMintCosts({
1082
+ salesConfigAndTokenInfo,
921
1083
  quantityToMint: BigInt(mintArguments.quantityToMint)
922
- })).totalCost;
1084
+ }).totalCost;
923
1085
  const result = {
924
1086
  abi: zora721Abi,
925
- address: mintable.contract_address,
1087
+ address: tokenAddress,
926
1088
  account: minterAccount,
927
1089
  functionName: "mintWithRewards",
928
1090
  value: mintValue,
@@ -930,33 +1092,17 @@ async function makePrepareMint721TokenParams({
930
1092
  mintArguments.mintToAddress,
931
1093
  BigInt(mintArguments.quantityToMint),
932
1094
  mintArguments.mintComment || "",
933
- mintArguments.mintReferral || zeroAddress
1095
+ mintArguments.mintReferral || zeroAddress2
934
1096
  ]
935
1097
  };
936
1098
  return result;
937
1099
  }
938
- async function get1155MintFee({
939
- collectionAddress,
940
- publicClient
941
- }) {
942
- return await publicClient.readContract({
943
- abi: zoraCreator1155ImplABI,
944
- functionName: "mintFee",
945
- address: collectionAddress
946
- });
947
- }
948
- async function get1155MintCosts({
949
- mintable,
950
- publicClient,
1100
+ function getMintCosts({
1101
+ salesConfigAndTokenInfo,
951
1102
  quantityToMint
952
1103
  }) {
953
- const address = mintable.collection.address;
954
- const mintFee = await get1155MintFee({
955
- collectionAddress: address,
956
- publicClient
957
- });
958
- const mintFeeForTokens = mintFee * quantityToMint;
959
- const tokenPurchaseCost = BigInt(mintable.cost.native_price.raw) * quantityToMint;
1104
+ const mintFeeForTokens = salesConfigAndTokenInfo.mintFeePerQuantity * quantityToMint;
1105
+ const tokenPurchaseCost = BigInt(salesConfigAndTokenInfo.fixedPrice.pricePerToken) * quantityToMint;
960
1106
  return {
961
1107
  mintFee: mintFeeForTokens,
962
1108
  tokenPurchaseCost,
@@ -964,43 +1110,33 @@ async function get1155MintCosts({
964
1110
  };
965
1111
  }
966
1112
  async function makePrepareMint1155TokenParams({
967
- apiClient,
968
- publicClient,
1113
+ tokenId,
1114
+ salesConfigAndTokenInfo,
969
1115
  minterAccount,
970
- mintable,
971
- mintContextType,
1116
+ tokenAddress,
972
1117
  mintArguments
973
1118
  }) {
974
- if (mintContextType !== "zora_create_1155") {
975
- throw new Error("Minted token type must be for 1155");
976
- }
977
1119
  const mintQuantity = BigInt(mintArguments.quantityToMint);
978
- const address = mintable.collection.address;
979
- const mintValue = (await get1155MintCosts({
980
- mintable,
981
- publicClient,
1120
+ const mintValue = getMintCosts({
1121
+ salesConfigAndTokenInfo,
982
1122
  quantityToMint: mintQuantity
983
- })).totalCost;
984
- const tokenFixedPriceMinter = await apiClient.getSalesConfigFixedPrice({
985
- contractAddress: address,
986
- tokenId: BigInt(mintable.token_id)
987
- });
1123
+ }).totalCost;
988
1124
  const result = {
989
- abi: zoraCreator1155ImplABI,
1125
+ abi: zoraCreator1155ImplABI2,
990
1126
  functionName: "mintWithRewards",
991
1127
  account: minterAccount,
992
1128
  value: mintValue,
993
- address,
1129
+ address: tokenAddress,
994
1130
  /* args: minter, tokenId, quantity, minterArguments, mintReferral */
995
1131
  args: [
996
- tokenFixedPriceMinter || zoraCreatorFixedPriceSaleStrategyAddress2[999],
997
- BigInt(mintable.token_id),
1132
+ salesConfigAndTokenInfo?.fixedPrice.address || zoraCreatorFixedPriceSaleStrategyAddress2[999],
1133
+ BigInt(tokenId),
998
1134
  mintQuantity,
999
1135
  encodeAbiParameters(parseAbiParameters("address, string"), [
1000
1136
  mintArguments.mintToAddress,
1001
1137
  mintArguments.mintComment || ""
1002
1138
  ]),
1003
- mintArguments.mintReferral || zeroAddress
1139
+ mintArguments.mintReferral || zeroAddress2
1004
1140
  ]
1005
1141
  };
1006
1142
  return result;
@@ -1010,14 +1146,14 @@ async function makePrepareMint1155TokenParams({
1010
1146
  import {
1011
1147
  zoraCreator1155FactoryImplABI,
1012
1148
  zoraCreator1155FactoryImplAddress,
1013
- zoraCreator1155ImplABI as zoraCreator1155ImplABI2,
1149
+ zoraCreator1155ImplABI as zoraCreator1155ImplABI3,
1014
1150
  zoraCreatorFixedPriceSaleStrategyABI
1015
1151
  } from "@zoralabs/protocol-deployments";
1016
- import { decodeEventLog as decodeEventLog2, encodeFunctionData, zeroAddress as zeroAddress2 } from "viem";
1152
+ import { decodeEventLog as decodeEventLog2, encodeFunctionData, zeroAddress as zeroAddress3 } from "viem";
1017
1153
  var SALE_END_FOREVER = 18446744073709551615n;
1018
1154
  var ROYALTY_BPS_DEFAULT = 1e3;
1019
1155
  var DEFAULT_SALE_SETTINGS = {
1020
- fundsRecipient: zeroAddress2,
1156
+ fundsRecipient: zeroAddress3,
1021
1157
  // Free Mint
1022
1158
  pricePerToken: 0n,
1023
1159
  // Sale start time – defaults to beginning of unix time
@@ -1027,7 +1163,7 @@ var DEFAULT_SALE_SETTINGS = {
1027
1163
  // 0 Here means no limit
1028
1164
  maxTokensPerAddress: 0n
1029
1165
  };
1030
- var PERMISSION_BIT_MINTER = 2n ** 2n;
1166
+ var PERMISSION_BIT_MINTER = 4n;
1031
1167
  function create1155TokenSetupArgs({
1032
1168
  nextTokenId,
1033
1169
  // How many NFTs upon initialization to mint to the creator
@@ -1057,26 +1193,26 @@ function create1155TokenSetupArgs({
1057
1193
  };
1058
1194
  const setupActions = [
1059
1195
  encodeFunctionData({
1060
- abi: zoraCreator1155ImplABI2,
1196
+ abi: zoraCreator1155ImplABI3,
1061
1197
  functionName: "assumeLastTokenIdMatches",
1062
1198
  args: [nextTokenId - 1n]
1063
1199
  }),
1064
1200
  createReferral ? encodeFunctionData({
1065
- abi: zoraCreator1155ImplABI2,
1201
+ abi: zoraCreator1155ImplABI3,
1066
1202
  functionName: "setupNewTokenWithCreateReferral",
1067
1203
  args: [tokenMetadataURI, maxSupply, createReferral]
1068
1204
  }) : encodeFunctionData({
1069
- abi: zoraCreator1155ImplABI2,
1205
+ abi: zoraCreator1155ImplABI3,
1070
1206
  functionName: "setupNewToken",
1071
1207
  args: [tokenMetadataURI, maxSupply]
1072
1208
  }),
1073
1209
  encodeFunctionData({
1074
- abi: zoraCreator1155ImplABI2,
1210
+ abi: zoraCreator1155ImplABI3,
1075
1211
  functionName: "addPermission",
1076
1212
  args: [0n, fixedPriceMinterAddress, PERMISSION_BIT_MINTER]
1077
1213
  }),
1078
1214
  encodeFunctionData({
1079
- abi: zoraCreator1155ImplABI2,
1215
+ abi: zoraCreator1155ImplABI3,
1080
1216
  functionName: "callSale",
1081
1217
  args: [
1082
1218
  nextTokenId,
@@ -1092,7 +1228,7 @@ function create1155TokenSetupArgs({
1092
1228
  if (mintToCreatorCount) {
1093
1229
  setupActions.push(
1094
1230
  encodeFunctionData({
1095
- abi: zoraCreator1155ImplABI2,
1231
+ abi: zoraCreator1155ImplABI3,
1096
1232
  functionName: "adminMint",
1097
1233
  args: [account, nextTokenId, mintToCreatorCount, "0x"]
1098
1234
  })
@@ -1101,7 +1237,7 @@ function create1155TokenSetupArgs({
1101
1237
  if (royaltySettings) {
1102
1238
  setupActions.push(
1103
1239
  encodeFunctionData({
1104
- abi: zoraCreator1155ImplABI2,
1240
+ abi: zoraCreator1155ImplABI3,
1105
1241
  functionName: "updateRoyaltiesForToken",
1106
1242
  args: [
1107
1243
  nextTokenId,
@@ -1120,7 +1256,7 @@ var getTokenIdFromCreateReceipt = (receipt) => {
1120
1256
  for (const data of receipt.logs) {
1121
1257
  try {
1122
1258
  const decodedLog = decodeEventLog2({
1123
- abi: zoraCreator1155ImplABI2,
1259
+ abi: zoraCreator1155ImplABI3,
1124
1260
  eventName: "SetupNewToken",
1125
1261
  ...data
1126
1262
  });
@@ -1149,7 +1285,7 @@ async function getContractExists(publicClient, contract, account) {
1149
1285
  });
1150
1286
  try {
1151
1287
  await publicClient.readContract({
1152
- abi: zoraCreator1155ImplABI2,
1288
+ abi: zoraCreator1155ImplABI3,
1153
1289
  address: contractAddress,
1154
1290
  functionName: "contractVersion"
1155
1291
  });
@@ -1184,7 +1320,7 @@ function create1155CreatorClient({
1184
1320
  let nextTokenId = 1n;
1185
1321
  if (contractExists) {
1186
1322
  nextTokenId = await publicClient.readContract({
1187
- abi: zoraCreator1155ImplABI2,
1323
+ abi: zoraCreator1155ImplABI3,
1188
1324
  functionName: "nextTokenId",
1189
1325
  address: contractAddress
1190
1326
  });
@@ -1240,7 +1376,7 @@ function create1155CreatorClient({
1240
1376
  };
1241
1377
  } else if (contractExists) {
1242
1378
  const request = {
1243
- abi: zoraCreator1155ImplABI2,
1379
+ abi: zoraCreator1155ImplABI3,
1244
1380
  functionName: "multicall",
1245
1381
  account,
1246
1382
  address: contractAddress,
@@ -1263,18 +1399,31 @@ export {
1263
1399
  Errors,
1264
1400
  MintAPIClient,
1265
1401
  PremintAPIClient,
1402
+ PremintConfigVersion,
1403
+ PreminterDomain,
1266
1404
  ZORA_API_BASE,
1267
1405
  convertCollection,
1268
- convertPremint,
1406
+ convertPremintV1,
1269
1407
  create1155CreatorClient,
1270
1408
  create1155TokenSetupArgs,
1271
1409
  createMintClient,
1272
1410
  createPremintClient,
1273
1411
  encodePremintForAPI,
1274
- get1155MintCosts,
1412
+ encodePremintV1ForAPI,
1413
+ encodePremintV2ForAPI,
1275
1414
  getApiNetworkConfigForChain,
1415
+ getMintCosts,
1416
+ getPremintCollectionAddress,
1417
+ getPremintExecutorAddress,
1276
1418
  getPremintedLogFromReceipt,
1277
1419
  getTokenIdFromCreateReceipt,
1278
- preminterTypedDataDefinition
1420
+ isAuthorizedToCreatePremint,
1421
+ isValidSignature,
1422
+ migratePremintConfigToV2,
1423
+ premintTypedDataDefinition,
1424
+ recoverCreatorFromCreatorAttribution,
1425
+ recoverPremintSigner,
1426
+ supportsPremintVersion,
1427
+ tryRecoverPremintSigner
1279
1428
  };
1280
1429
  //# sourceMappingURL=index.js.map