@zoralabs/protocol-sdk 0.5.16 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +24 -0
  3. package/README.md +1 -416
  4. package/dist/apis/generated/premint-api-types.d.ts +9 -2
  5. package/dist/apis/generated/premint-api-types.d.ts.map +1 -1
  6. package/dist/create/1155-create-helper.d.ts +16 -55
  7. package/dist/create/1155-create-helper.d.ts.map +1 -1
  8. package/dist/create/contract-setup.d.ts +14 -0
  9. package/dist/create/contract-setup.d.ts.map +1 -0
  10. package/dist/create/token-setup.d.ts +27 -0
  11. package/dist/create/token-setup.d.ts.map +1 -0
  12. package/dist/create/types.d.ts +45 -0
  13. package/dist/create/types.d.ts.map +1 -0
  14. package/dist/index.cjs +1392 -931
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.ts +4 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1356 -907
  19. package/dist/index.js.map +1 -1
  20. package/dist/mint/mint-client.d.ts +4083 -43
  21. package/dist/mint/mint-client.d.ts.map +1 -1
  22. package/dist/mint/subgraph-mint-getter.d.ts +17 -0
  23. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -0
  24. package/dist/mint/types.d.ts +79 -0
  25. package/dist/mint/types.d.ts.map +1 -0
  26. package/dist/mints/mints-contracts.d.ts +24 -24
  27. package/dist/premint/contract-types.d.ts +21 -0
  28. package/dist/premint/contract-types.d.ts.map +1 -1
  29. package/dist/premint/conversions.d.ts +12 -22
  30. package/dist/premint/conversions.d.ts.map +1 -1
  31. package/dist/premint/premint-api-client.d.ts +28 -14
  32. package/dist/premint/premint-api-client.d.ts.map +1 -1
  33. package/dist/premint/premint-client.d.ts +83 -67
  34. package/dist/premint/premint-client.d.ts.map +1 -1
  35. package/dist/premint/preminter.d.ts +42 -18
  36. package/dist/premint/preminter.d.ts.map +1 -1
  37. package/dist/sdk.d.ts +43 -0
  38. package/dist/sdk.d.ts.map +1 -0
  39. package/dist/utils.d.ts +17 -6870
  40. package/dist/utils.d.ts.map +1 -1
  41. package/package.json +3 -2
  42. package/src/apis/generated/premint-api-types.ts +9 -2
  43. package/src/create/1155-create-helper.test.ts +235 -56
  44. package/src/create/1155-create-helper.ts +141 -309
  45. package/src/create/contract-setup.ts +88 -0
  46. package/src/create/token-setup.ts +379 -0
  47. package/src/create/types.ts +57 -0
  48. package/src/index.ts +11 -1
  49. package/src/mint/mint-client.test.ts +50 -61
  50. package/src/mint/mint-client.ts +321 -157
  51. package/src/mint/{mint-api-client.ts → subgraph-mint-getter.ts} +2 -25
  52. package/src/mint/types.ts +122 -0
  53. package/src/mints/mints-contracts.test.ts +3 -3
  54. package/src/mints/mints-contracts.ts +4 -4
  55. package/src/premint/contract-types.ts +32 -1
  56. package/src/premint/conversions.ts +31 -9
  57. package/src/premint/premint-api-client.ts +58 -46
  58. package/src/premint/premint-client.test.ts +153 -125
  59. package/src/premint/premint-client.ts +316 -330
  60. package/src/premint/preminter.test.ts +156 -5
  61. package/src/premint/preminter.ts +145 -44
  62. package/src/sdk.ts +98 -0
  63. package/src/utils.ts +30 -23
  64. package/test-integration/premint-client.test.ts +8 -8
  65. package/dist/mint/mint-api-client.d.ts +0 -35
  66. package/dist/mint/mint-api-client.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,6 +1,9 @@
1
1
  // src/premint/premint-client.ts
2
2
  import { decodeEventLog, zeroAddress as zeroAddress2 } from "viem";
3
- import { zoraCreator1155PremintExecutorImplABI as zoraCreator1155PremintExecutorImplABI2 } from "@zoralabs/protocol-deployments";
3
+ import {
4
+ encodePremintConfig,
5
+ zoraCreator1155PremintExecutorImplABI as zoraCreator1155PremintExecutorImplABI2
6
+ } from "@zoralabs/protocol-deployments";
4
7
 
5
8
  // src/premint/preminter.ts
6
9
  import {
@@ -17,26 +20,283 @@ import {
17
20
  keccak256,
18
21
  concat,
19
22
  recoverAddress,
20
- parseEther
23
+ parseEther as parseEther2
21
24
  } from "viem";
25
+
26
+ // src/apis/chain-constants.ts
27
+ import {
28
+ arbitrum,
29
+ base,
30
+ baseSepolia,
31
+ foundry,
32
+ mainnet,
33
+ optimism,
34
+ sepolia,
35
+ zora,
36
+ zoraSepolia
37
+ } from "viem/chains";
38
+ import { parseEther } from "viem";
39
+
40
+ // src/constants.ts
41
+ import { parseAbi } from "viem";
42
+ var ZORA_API_BASE = "https://api.zora.co/";
43
+ var OPEN_EDITION_MINT_SIZE = BigInt("18446744073709551615");
44
+ var SUBGRAPH_CONFIG_BASE = "https://api.goldsky.com/api/public/project_clhk16b61ay9t49vm6ntn4mkz/subgraphs";
45
+ function getSubgraph(name, version) {
46
+ return `${SUBGRAPH_CONFIG_BASE}/${name}/${version}/gn`;
47
+ }
48
+ var zora721Abi = parseAbi([
49
+ "function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
50
+ "function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
51
+ ]);
52
+ var NFT_SALE_QUERY = `
53
+ fragment SaleStrategy on SalesStrategyConfig {
54
+ type
55
+ fixedPrice {
56
+ address
57
+ pricePerToken
58
+ saleEnd
59
+ saleStart
60
+ maxTokensPerAddress
61
+ }
62
+ erc20Minter {
63
+ address
64
+ pricePerToken
65
+ currency
66
+ saleEnd
67
+ saleStart
68
+ maxTokensPerAddress
69
+ }
70
+ }
71
+
72
+ query ($id: ID!) {
73
+ zoraCreateToken(id: $id) {
74
+ id
75
+ contract {
76
+ mintFeePerQuantity
77
+ salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
78
+ ...SaleStrategy
79
+ }
80
+ }
81
+ salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
82
+ ...SaleStrategy
83
+ }
84
+ }
85
+ }
86
+ `;
87
+
88
+ // src/apis/chain-constants.ts
89
+ var REWARD_PER_TOKEN = parseEther("0.000777");
90
+ var networkConfigByChain = {
91
+ [mainnet.id]: {
92
+ chainId: mainnet.id,
93
+ isTestnet: false,
94
+ zoraCollectPathChainName: "eth",
95
+ zoraBackendChainName: "ETHEREUM-MAINNET",
96
+ subgraphUrl: getSubgraph("zora-create-mainnet", "stable")
97
+ },
98
+ [sepolia.id]: {
99
+ chainId: sepolia.id,
100
+ isTestnet: true,
101
+ zoraCollectPathChainName: "sep",
102
+ zoraBackendChainName: "ETHEREUM-SEPOLIA",
103
+ subgraphUrl: getSubgraph("zora-create-sepolia", "stable")
104
+ },
105
+ [zora.id]: {
106
+ chainId: zora.id,
107
+ isTestnet: false,
108
+ zoraCollectPathChainName: "zora",
109
+ zoraBackendChainName: "ZORA-MAINNET",
110
+ subgraphUrl: getSubgraph("zora-create-zora-mainnet", "stable")
111
+ },
112
+ [zoraSepolia.id]: {
113
+ chainId: zoraSepolia.id,
114
+ isTestnet: true,
115
+ zoraCollectPathChainName: "zsep",
116
+ zoraBackendChainName: "ZORA-SEPOLIA",
117
+ subgraphUrl: getSubgraph("zora-create-zora-sepolia", "stable")
118
+ },
119
+ [optimism.id]: {
120
+ chainId: optimism.id,
121
+ isTestnet: false,
122
+ zoraCollectPathChainName: "oeth",
123
+ zoraBackendChainName: "OPTIMISM-MAINNET",
124
+ subgraphUrl: getSubgraph("zora-create-optimism", "stable")
125
+ },
126
+ [arbitrum.id]: {
127
+ chainId: arbitrum.id,
128
+ isTestnet: true,
129
+ zoraCollectPathChainName: "arb",
130
+ zoraBackendChainName: "ARBITRUM-MAINNET",
131
+ subgraphUrl: getSubgraph("zora-create-arbitrum-one", "stable")
132
+ },
133
+ [base.id]: {
134
+ chainId: base.id,
135
+ isTestnet: false,
136
+ zoraCollectPathChainName: "base",
137
+ zoraBackendChainName: "BASE-MAINNET",
138
+ subgraphUrl: getSubgraph("zora-create-base-mainnet", "stable")
139
+ },
140
+ [baseSepolia.id]: {
141
+ chainId: baseSepolia.id,
142
+ isTestnet: true,
143
+ zoraCollectPathChainName: "bsep",
144
+ zoraBackendChainName: "BASE-SEPOLIA",
145
+ subgraphUrl: getSubgraph("zora-create-base-sepolia", "stable")
146
+ },
147
+ [foundry.id]: {
148
+ chainId: foundry.id,
149
+ isTestnet: true,
150
+ zoraCollectPathChainName: "zgor",
151
+ zoraBackendChainName: "ZORA-GOERLI",
152
+ subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
153
+ }
154
+ };
155
+
156
+ // src/premint/conversions.ts
157
+ import {
158
+ PremintConfigVersion
159
+ } from "@zoralabs/protocol-deployments";
160
+ var convertCollectionFromApi = (collection) => {
161
+ if (!collection)
162
+ return void 0;
163
+ return {
164
+ additionalAdmins: collection.additionalAdmins || [],
165
+ contractAdmin: collection.contractAdmin,
166
+ contractName: collection.contractName,
167
+ contractURI: collection.contractURI
168
+ };
169
+ };
170
+ var convertPremintFromApi = (premint) => {
171
+ if (premint.config_version === PremintConfigVersion.V1 || !premint.config_version) {
172
+ const tokenConfig = premint.tokenConfig;
173
+ return {
174
+ premintConfigVersion: PremintConfigVersion.V1,
175
+ premintConfig: {
176
+ deleted: premint.deleted,
177
+ uid: premint.uid,
178
+ version: premint.version,
179
+ tokenConfig: {
180
+ ...tokenConfig,
181
+ fixedPriceMinter: tokenConfig.fixedPriceMinter,
182
+ royaltyRecipient: tokenConfig.royaltyRecipient,
183
+ maxSupply: BigInt(tokenConfig.maxSupply),
184
+ pricePerToken: BigInt(tokenConfig.pricePerToken),
185
+ mintStart: BigInt(tokenConfig.mintStart),
186
+ mintDuration: BigInt(tokenConfig.mintDuration),
187
+ maxTokensPerAddress: BigInt(tokenConfig.maxTokensPerAddress)
188
+ }
189
+ }
190
+ };
191
+ } else {
192
+ const tokenConfig = premint.tokenConfig;
193
+ return {
194
+ premintConfigVersion: PremintConfigVersion.V2,
195
+ premintConfig: {
196
+ deleted: premint.deleted,
197
+ uid: premint.uid,
198
+ version: premint.version,
199
+ tokenConfig: {
200
+ ...tokenConfig,
201
+ fixedPriceMinter: tokenConfig.fixedPriceMinter,
202
+ payoutRecipient: tokenConfig.payoutRecipient,
203
+ createReferral: tokenConfig.createReferral,
204
+ maxSupply: BigInt(tokenConfig.maxSupply),
205
+ pricePerToken: BigInt(tokenConfig.pricePerToken),
206
+ mintStart: BigInt(tokenConfig.mintStart),
207
+ mintDuration: BigInt(tokenConfig.mintDuration),
208
+ maxTokensPerAddress: BigInt(tokenConfig.maxTokensPerAddress)
209
+ }
210
+ }
211
+ };
212
+ }
213
+ };
214
+ var convertGetPremintApiResponse = (response) => ({
215
+ ...convertPremintFromApi(response.premint),
216
+ collection: convertCollectionFromApi(response.collection),
217
+ collectionAddress: response.collection_address,
218
+ signature: response.signature
219
+ });
220
+ var encodePremintV1ForAPI = ({
221
+ tokenConfig,
222
+ ...premint
223
+ }) => ({
224
+ ...premint,
225
+ config_version: "1",
226
+ tokenConfig: {
227
+ ...tokenConfig,
228
+ maxSupply: tokenConfig.maxSupply.toString(),
229
+ pricePerToken: tokenConfig.pricePerToken.toString(),
230
+ mintStart: tokenConfig.mintStart.toString(),
231
+ mintDuration: tokenConfig.mintDuration.toString(),
232
+ maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
233
+ }
234
+ });
235
+ var encodePremintV2ForAPI = ({
236
+ tokenConfig,
237
+ ...premint
238
+ }) => ({
239
+ ...premint,
240
+ config_version: "2",
241
+ tokenConfig: {
242
+ ...tokenConfig,
243
+ maxSupply: tokenConfig.maxSupply.toString(),
244
+ pricePerToken: tokenConfig.pricePerToken.toString(),
245
+ mintStart: tokenConfig.mintStart.toString(),
246
+ mintDuration: tokenConfig.mintDuration.toString(),
247
+ maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
248
+ }
249
+ });
250
+ var encodePremintForAPI = ({
251
+ premintConfig,
252
+ premintConfigVersion
253
+ }) => {
254
+ if (premintConfigVersion === PremintConfigVersion.V1) {
255
+ return encodePremintV1ForAPI(premintConfig);
256
+ }
257
+ if (premintConfigVersion === PremintConfigVersion.V2) {
258
+ return encodePremintV2ForAPI(premintConfig);
259
+ }
260
+ throw new Error(`Invalid premint config version ${premintConfigVersion}`);
261
+ };
262
+ var encodePostSignatureInput = ({
263
+ contract: collection,
264
+ contractAddress: collectionAddress,
265
+ premintConfigVersion,
266
+ premintConfig,
267
+ signature,
268
+ chainId
269
+ }) => ({
270
+ premint: encodePremintForAPI({
271
+ premintConfig,
272
+ premintConfigVersion
273
+ }),
274
+ signature,
275
+ collection,
276
+ collection_address: collectionAddress,
277
+ chain_name: networkConfigByChain[chainId].zoraBackendChainName
278
+ });
279
+ var isPremintConfigV1 = (premintConfigAndVersion) => premintConfigAndVersion.premintConfigVersion === PremintConfigVersion.V1;
280
+ var isPremintConfigV2 = (premintConfigAndVersion) => premintConfigAndVersion.premintConfigVersion === PremintConfigVersion.V2;
281
+
282
+ // src/premint/preminter.ts
22
283
  var getPremintExecutorAddress = () => zoraCreator1155PremintExecutorImplAddress[999];
23
284
  async function isAuthorizedToCreatePremint({
24
- collection,
285
+ contractAdmin = zeroAddress,
286
+ additionalAdmins = [],
25
287
  collectionAddress,
26
288
  publicClient,
27
289
  signer
28
290
  }) {
29
- if (collection.additionalAdmins.length > 0)
30
- throw new Error("additionalAdmins not supported yet.");
31
291
  return await publicClient.readContract({
32
292
  abi: preminterAbi,
33
293
  address: getPremintExecutorAddress(),
34
294
  functionName: "isAuthorizedToCreatePremintWithAdditionalAdmins",
35
295
  args: [
36
- signer,
37
- collection.contractAdmin,
296
+ typeof signer === "string" ? signer : signer.address,
297
+ contractAdmin,
38
298
  collectionAddress,
39
- collection.additionalAdmins
299
+ additionalAdmins
40
300
  ]
41
301
  });
42
302
  }
@@ -61,17 +321,14 @@ async function isValidSignature({
61
321
  signature,
62
322
  publicClient,
63
323
  collection,
324
+ collectionAddress,
64
325
  chainId,
65
326
  ...premintConfigAndVersion
66
327
  }) {
67
- const tokenContract = await getPremintCollectionAddress({
68
- collection,
69
- publicClient
70
- });
71
328
  const recoveredAddress = await tryRecoverPremintSigner({
72
329
  ...premintConfigAndVersion,
73
330
  signature,
74
- verifyingContract: tokenContract,
331
+ verifyingContract: collectionAddress,
75
332
  chainId
76
333
  });
77
334
  if (!recoverAddress) {
@@ -81,8 +338,9 @@ async function isValidSignature({
81
338
  }
82
339
  const isAuthorized = await isAuthorizedToCreatePremint({
83
340
  signer: recoveredAddress,
84
- collection,
85
- collectionAddress: tokenContract,
341
+ additionalAdmins: collection?.additionalAdmins,
342
+ contractAdmin: collection?.contractAdmin,
343
+ collectionAddress,
86
344
  publicClient
87
345
  });
88
346
  return {
@@ -163,15 +421,24 @@ var supportsPremintVersion = async ({
163
421
  return (await supportedPremintVersions({ tokenContract, publicClient })).includes(version);
164
422
  };
165
423
  async function getPremintCollectionAddress({
166
- collection,
167
- publicClient
424
+ publicClient,
425
+ contract: collection,
426
+ contractAddress: collectionAddress
168
427
  }) {
169
- return publicClient.readContract({
170
- address: getPremintExecutorAddress(),
171
- abi: zoraCreator1155PremintExecutorImplABI,
172
- functionName: "getContractAddress",
173
- args: [collection]
174
- });
428
+ if (typeof collection !== "undefined") {
429
+ return publicClient.readContract({
430
+ address: getPremintExecutorAddress(),
431
+ abi: zoraCreator1155PremintExecutorImplABI,
432
+ functionName: "getContractWithAdditionalAdminsAddress",
433
+ args: [
434
+ {
435
+ ...collection,
436
+ additionalAdmins: collection.additionalAdmins || []
437
+ }
438
+ ]
439
+ });
440
+ }
441
+ return collectionAddress;
175
442
  }
176
443
  function applyUpdateToPremint({
177
444
  uid,
@@ -215,7 +482,7 @@ async function getPremintMintFee({
215
482
  });
216
483
  } catch (e) {
217
484
  console.error(e);
218
- return parseEther("0.000777");
485
+ return parseEther2("0.000777");
219
486
  }
220
487
  }
221
488
  async function getPremintMintCosts({
@@ -225,12 +492,42 @@ async function getPremintMintCosts({
225
492
  quantityToMint
226
493
  }) {
227
494
  const mintFee = await getPremintMintFee({ tokenContract, publicClient });
495
+ const quantityToMintBigInt = BigInt(quantityToMint);
228
496
  return {
229
- mintFee: mintFee * quantityToMint,
230
- tokenPurchaseCost: tokenPrice * quantityToMint,
231
- totalCost: (mintFee + tokenPrice) * quantityToMint
497
+ mintFee: mintFee * quantityToMintBigInt,
498
+ totalPurchaseCost: tokenPrice * quantityToMintBigInt,
499
+ totalCostEth: (mintFee + tokenPrice) * quantityToMintBigInt
232
500
  };
233
501
  }
502
+ async function getPremintPricePerToken({
503
+ collection,
504
+ uid,
505
+ premintGetter
506
+ }) {
507
+ const premintConfigWithVersion = await premintGetter.getSignature({
508
+ collectionAddress: collection,
509
+ uid
510
+ });
511
+ if (isPremintConfigV1(premintConfigWithVersion) || isPremintConfigV2(premintConfigWithVersion)) {
512
+ return premintConfigWithVersion.premintConfig.tokenConfig.pricePerToken;
513
+ }
514
+ throw new Error("Premint version not supported to get price");
515
+ }
516
+ async function getPremintMintCostsWithUnknownTokenPrice({
517
+ premintGetter,
518
+ uid,
519
+ ...rest
520
+ }) {
521
+ const pricePerToken = await getPremintPricePerToken({
522
+ uid,
523
+ premintGetter,
524
+ collection: rest.tokenContract
525
+ });
526
+ return await getPremintMintCosts({
527
+ ...rest,
528
+ tokenPrice: pricePerToken
529
+ });
530
+ }
234
531
  function makeMintRewardsRecipient({
235
532
  mintReferral = zeroAddress,
236
533
  platformReferral = zeroAddress
@@ -240,6 +537,34 @@ function makeMintRewardsRecipient({
240
537
  function getDefaultFixedPriceMinterAddress(chainId) {
241
538
  return zoraCreatorFixedPriceSaleStrategyAddress[chainId];
242
539
  }
540
+ var emptyContractCreationConfig = () => ({
541
+ contractAdmin: zeroAddress,
542
+ contractURI: "",
543
+ contractName: "",
544
+ additionalAdmins: []
545
+ });
546
+ function defaultAdditionalAdmins(collection) {
547
+ return {
548
+ ...collection,
549
+ additionalAdmins: collection.additionalAdmins || []
550
+ };
551
+ }
552
+ var toContractCreationConfigOrAddress = ({
553
+ collection,
554
+ collectionAddress
555
+ }) => {
556
+ if (typeof collection !== "undefined") {
557
+ return {
558
+ contract: collection
559
+ };
560
+ }
561
+ if (typeof collectionAddress !== "undefined") {
562
+ return {
563
+ contractAddress: collectionAddress
564
+ };
565
+ }
566
+ throw new Error("Must provide either a collection or a collection address");
567
+ };
243
568
 
244
569
  // src/premint/premint-client.ts
245
570
  import {
@@ -321,142 +646,14 @@ var httpClient = {
321
646
  retries
322
647
  };
323
648
 
324
- // src/constants.ts
325
- import { parseAbi } from "viem";
326
- var ZORA_API_BASE = "https://api.zora.co/";
327
- var OPEN_EDITION_MINT_SIZE = BigInt("18446744073709551615");
328
- var SUBGRAPH_CONFIG_BASE = "https://api.goldsky.com/api/public/project_clhk16b61ay9t49vm6ntn4mkz/subgraphs";
329
- function getSubgraph(name, version) {
330
- return `${SUBGRAPH_CONFIG_BASE}/${name}/${version}/gn`;
331
- }
332
- var zora721Abi = parseAbi([
333
- "function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
334
- "function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)"
335
- ]);
336
- var NFT_SALE_QUERY = `
337
- fragment SaleStrategy on SalesStrategyConfig {
338
- type
339
- fixedPrice {
340
- address
341
- pricePerToken
342
- saleEnd
343
- saleStart
344
- maxTokensPerAddress
345
- }
346
- erc20Minter {
347
- address
348
- pricePerToken
349
- currency
350
- saleEnd
351
- saleStart
352
- maxTokensPerAddress
353
- }
354
- }
355
-
356
- query ($id: ID!) {
357
- zoraCreateToken(id: $id) {
358
- id
359
- contract {
360
- mintFeePerQuantity
361
- salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
362
- ...SaleStrategy
363
- }
364
- }
365
- salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
366
- ...SaleStrategy
367
- }
368
- }
369
- }
370
- `;
371
-
372
- // src/apis/chain-constants.ts
373
- import {
374
- arbitrum,
375
- base,
376
- baseSepolia,
377
- foundry,
378
- mainnet,
379
- optimism,
380
- sepolia,
381
- zora,
382
- zoraSepolia
383
- } from "viem/chains";
384
- import { parseEther as parseEther2 } from "viem";
385
- var REWARD_PER_TOKEN = parseEther2("0.000777");
386
- var networkConfigByChain = {
387
- [mainnet.id]: {
388
- chainId: mainnet.id,
389
- isTestnet: false,
390
- zoraCollectPathChainName: "eth",
391
- zoraBackendChainName: "ETHEREUM-MAINNET",
392
- subgraphUrl: getSubgraph("zora-create-mainnet", "stable")
393
- },
394
- [sepolia.id]: {
395
- chainId: sepolia.id,
396
- isTestnet: true,
397
- zoraCollectPathChainName: "sep",
398
- zoraBackendChainName: "ETHEREUM-SEPOLIA",
399
- subgraphUrl: getSubgraph("zora-create-sepolia", "stable")
400
- },
401
- [zora.id]: {
402
- chainId: zora.id,
403
- isTestnet: false,
404
- zoraCollectPathChainName: "zora",
405
- zoraBackendChainName: "ZORA-MAINNET",
406
- subgraphUrl: getSubgraph("zora-create-zora-mainnet", "stable")
407
- },
408
- [zoraSepolia.id]: {
409
- chainId: zoraSepolia.id,
410
- isTestnet: true,
411
- zoraCollectPathChainName: "zsep",
412
- zoraBackendChainName: "ZORA-SEPOLIA",
413
- subgraphUrl: getSubgraph("zora-create-zora-sepolia", "stable")
414
- },
415
- [optimism.id]: {
416
- chainId: optimism.id,
417
- isTestnet: false,
418
- zoraCollectPathChainName: "oeth",
419
- zoraBackendChainName: "OPTIMISM-MAINNET",
420
- subgraphUrl: getSubgraph("zora-create-optimism", "stable")
421
- },
422
- [arbitrum.id]: {
423
- chainId: arbitrum.id,
424
- isTestnet: true,
425
- zoraCollectPathChainName: "arb",
426
- zoraBackendChainName: "ARBITRUM-MAINNET",
427
- subgraphUrl: getSubgraph("zora-create-arbitrum-one", "stable")
428
- },
429
- [base.id]: {
430
- chainId: base.id,
431
- isTestnet: false,
432
- zoraCollectPathChainName: "base",
433
- zoraBackendChainName: "BASE-MAINNET",
434
- subgraphUrl: getSubgraph("zora-create-base-mainnet", "stable")
435
- },
436
- [baseSepolia.id]: {
437
- chainId: baseSepolia.id,
438
- isTestnet: true,
439
- zoraCollectPathChainName: "bsep",
440
- zoraBackendChainName: "BASE-SEPOLIA",
441
- subgraphUrl: getSubgraph("zora-create-base-sepolia", "stable")
442
- },
443
- [foundry.id]: {
444
- chainId: foundry.id,
445
- isTestnet: true,
446
- zoraCollectPathChainName: "zgor",
447
- zoraBackendChainName: "ZORA-GOERLI",
448
- subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
449
- }
450
- };
451
-
452
- // src/mint/mint-api-client.ts
649
+ // src/mint/subgraph-mint-getter.ts
453
650
  var getApiNetworkConfigForChain = (chainId) => {
454
651
  if (!networkConfigByChain[chainId]) {
455
652
  throw new Error(`chain id ${chainId} network not configured `);
456
653
  }
457
654
  return networkConfigByChain[chainId];
458
655
  };
459
- var MintAPIClient = class {
656
+ var SubgraphMintGetter = class {
460
657
  constructor(chainId, httpClient2) {
461
658
  this.httpClient = httpClient2 || httpClient;
462
659
  this.networkConfig = getApiNetworkConfigForChain(chainId);
@@ -502,236 +699,46 @@ var MintAPIClient = class {
502
699
  );
503
700
  if (!targetStrategy) {
504
701
  throw new Error(`Cannot find sale strategy for ${mappedSaleType}`);
505
- }
506
- }
507
- if (targetStrategy.type === "FIXED_PRICE") {
508
- return {
509
- salesConfig: {
510
- saleType: "fixedPrice",
511
- ...targetStrategy.fixedPrice,
512
- maxTokensPerAddress: BigInt(
513
- targetStrategy.fixedPrice.maxTokensPerAddress
514
- ),
515
- pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken)
516
- },
517
- mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
518
- };
519
- }
520
- if (targetStrategy.type === "ERC_20_MINTER") {
521
- return {
522
- salesConfig: {
523
- saleType: "erc20",
524
- ...targetStrategy.erc20Minter,
525
- maxTokensPerAddress: BigInt(
526
- targetStrategy.erc20Minter.maxTokensPerAddress
527
- ),
528
- pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken)
529
- },
530
- mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
531
- };
532
- }
533
- throw new Error("Invalid saleType");
534
- });
535
- }
536
- };
537
-
538
- // src/premint/conversions.ts
539
- import {
540
- PremintConfigVersion
541
- } from "@zoralabs/protocol-deployments";
542
- var convertCollectionFromApi = (collection) => ({
543
- ...collection,
544
- contractAdmin: collection.contractAdmin,
545
- additionalAdmins: []
546
- });
547
- var convertPremintFromApi = (premint) => {
548
- if (premint.config_version === PremintConfigVersion.V1 || !premint.config_version) {
549
- const tokenConfig = premint.tokenConfig;
550
- return {
551
- premintConfigVersion: PremintConfigVersion.V1,
552
- premintConfig: {
553
- deleted: premint.deleted,
554
- uid: premint.uid,
555
- version: premint.version,
556
- tokenConfig: {
557
- ...tokenConfig,
558
- fixedPriceMinter: tokenConfig.fixedPriceMinter,
559
- royaltyRecipient: tokenConfig.royaltyRecipient,
560
- maxSupply: BigInt(tokenConfig.maxSupply),
561
- pricePerToken: BigInt(tokenConfig.pricePerToken),
562
- mintStart: BigInt(tokenConfig.mintStart),
563
- mintDuration: BigInt(tokenConfig.mintDuration),
564
- maxTokensPerAddress: BigInt(tokenConfig.maxTokensPerAddress)
565
- }
566
- }
567
- };
568
- } else {
569
- const tokenConfig = premint.tokenConfig;
570
- return {
571
- premintConfigVersion: PremintConfigVersion.V2,
572
- premintConfig: {
573
- deleted: premint.deleted,
574
- uid: premint.uid,
575
- version: premint.version,
576
- tokenConfig: {
577
- ...tokenConfig,
578
- fixedPriceMinter: tokenConfig.fixedPriceMinter,
579
- payoutRecipient: tokenConfig.payoutRecipient,
580
- createReferral: tokenConfig.createReferral,
581
- maxSupply: BigInt(tokenConfig.maxSupply),
582
- pricePerToken: BigInt(tokenConfig.pricePerToken),
583
- mintStart: BigInt(tokenConfig.mintStart),
584
- mintDuration: BigInt(tokenConfig.mintDuration),
585
- maxTokensPerAddress: BigInt(tokenConfig.maxTokensPerAddress)
586
- }
587
- }
588
- };
589
- }
590
- };
591
- var convertGetPremintApiResponse = (response) => ({
592
- ...convertPremintFromApi(response.premint),
593
- collection: convertCollectionFromApi(response.collection),
594
- signature: response.signature
595
- });
596
- var encodePremintV1ForAPI = ({
597
- tokenConfig,
598
- ...premint
599
- }) => ({
600
- ...premint,
601
- config_version: "1",
602
- tokenConfig: {
603
- ...tokenConfig,
604
- maxSupply: tokenConfig.maxSupply.toString(),
605
- pricePerToken: tokenConfig.pricePerToken.toString(),
606
- mintStart: tokenConfig.mintStart.toString(),
607
- mintDuration: tokenConfig.mintDuration.toString(),
608
- maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
609
- }
610
- });
611
- var encodePremintV2ForAPI = ({
612
- tokenConfig,
613
- ...premint
614
- }) => ({
615
- ...premint,
616
- config_version: "2",
617
- tokenConfig: {
618
- ...tokenConfig,
619
- maxSupply: tokenConfig.maxSupply.toString(),
620
- pricePerToken: tokenConfig.pricePerToken.toString(),
621
- mintStart: tokenConfig.mintStart.toString(),
622
- mintDuration: tokenConfig.mintDuration.toString(),
623
- maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
624
- }
625
- });
626
- var encodePremintForAPI = ({
627
- premintConfig,
628
- premintConfigVersion
629
- }) => {
630
- if (premintConfigVersion === PremintConfigVersion.V1) {
631
- return encodePremintV1ForAPI(premintConfig);
632
- }
633
- if (premintConfigVersion === PremintConfigVersion.V2) {
634
- return encodePremintV2ForAPI(premintConfig);
635
- }
636
- throw new Error(`Invalid premint config version ${premintConfigVersion}`);
637
- };
638
- var encodePostSignatureInput = ({
639
- collection,
640
- premintConfigVersion,
641
- premintConfig,
642
- signature,
643
- chainId
644
- }) => ({
645
- premint: encodePremintForAPI({
646
- premintConfig,
647
- premintConfigVersion
648
- }),
649
- signature,
650
- collection,
651
- chain_name: networkConfigByChain[chainId].zoraBackendChainName
652
- });
653
-
654
- // src/premint/premint-api-client.ts
655
- var postSignature = async ({
656
- httpClient: { post: post2, retries: retries2 } = httpClient,
657
- ...data
658
- }) => retries2(
659
- () => post2(`${ZORA_API_BASE}premint/signature`, data)
660
- );
661
- var getNextUID = async ({
662
- chain_name,
663
- collection_address,
664
- httpClient: { retries: retries2, get: get2 } = httpClient
665
- }) => retries2(
666
- () => get2(
667
- `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/next_uid`
668
- )
669
- );
670
- var getSignature = async ({
671
- collection_address,
672
- uid,
673
- chain_name,
674
- httpClient: { retries: retries2, get: get2 } = httpClient
675
- }) => {
676
- const result = await retries2(
677
- () => get2(
678
- `${ZORA_API_BASE}premint/signature/${chain_name}/${collection_address}/${uid}`
679
- )
680
- );
681
- return result;
682
- };
683
- var PremintAPIClient = class {
684
- constructor(chainId, httpClient2) {
685
- this.postSignature = async ({
686
- collection,
687
- signature,
688
- ...premintConfigAndVersion
689
- }) => {
690
- const data = encodePostSignatureInput({
691
- collection,
692
- ...premintConfigAndVersion,
693
- chainId: this.networkConfig.chainId,
694
- signature
695
- });
696
- return postSignature({
697
- ...data,
698
- httpClient: this.httpClient
699
- });
700
- };
701
- this.getNextUID = async (collectionAddress) => (await getNextUID({
702
- collection_address: collectionAddress.toLowerCase(),
703
- chain_name: this.networkConfig.zoraBackendChainName,
704
- httpClient: this.httpClient
705
- })).next_uid;
706
- this.getSignature = async ({
707
- collectionAddress,
708
- uid
709
- }) => {
710
- const response = await getSignature({
711
- collection_address: collectionAddress.toLowerCase(),
712
- uid,
713
- chain_name: this.networkConfig.zoraBackendChainName,
714
- httpClient: this.httpClient
715
- });
716
- return convertGetPremintApiResponse(response);
717
- };
718
- this.httpClient = httpClient2 || httpClient;
719
- this.networkConfig = getApiNetworkConfigForChain(chainId);
702
+ }
703
+ }
704
+ if (targetStrategy.type === "FIXED_PRICE") {
705
+ return {
706
+ salesConfig: {
707
+ saleType: "fixedPrice",
708
+ ...targetStrategy.fixedPrice,
709
+ maxTokensPerAddress: BigInt(
710
+ targetStrategy.fixedPrice.maxTokensPerAddress
711
+ ),
712
+ pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken)
713
+ },
714
+ mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
715
+ };
716
+ }
717
+ if (targetStrategy.type === "ERC_20_MINTER") {
718
+ return {
719
+ salesConfig: {
720
+ saleType: "erc20",
721
+ ...targetStrategy.erc20Minter,
722
+ maxTokensPerAddress: BigInt(
723
+ targetStrategy.erc20Minter.maxTokensPerAddress
724
+ ),
725
+ pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken)
726
+ },
727
+ mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity)
728
+ };
729
+ }
730
+ throw new Error("Invalid saleType");
731
+ });
720
732
  }
721
733
  };
722
734
 
723
735
  // src/utils.ts
724
- import {
725
- createPublicClient,
726
- http
727
- } from "viem";
728
- var makeSimulateContractParamaters = (args) => args;
729
- function setupClient({ chain, httpClient: httpClient2, publicClient }) {
730
- return {
731
- chain,
732
- httpClient: httpClient2 || httpClient,
733
- publicClient: publicClient || createPublicClient({ chain, transport: http() })
734
- };
736
+ var makeContractParameters = (args) => args;
737
+ function mintRecipientOrAccount({
738
+ mintRecipient,
739
+ minterAccount
740
+ }) {
741
+ return mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
735
742
  }
736
743
 
737
744
  // src/premint/premint-client.ts
@@ -739,51 +746,77 @@ var defaultTokenConfigV1MintArguments = () => ({
739
746
  maxSupply: OPEN_EDITION_MINT_SIZE,
740
747
  maxTokensPerAddress: 0n,
741
748
  pricePerToken: 0n,
742
- mintDuration: BigInt(60 * 60 * 24 * 7),
743
- // 1 week
749
+ mintDuration: 0n,
744
750
  mintStart: 0n,
745
751
  royaltyMintSchedule: 0,
746
752
  royaltyBPS: 1e3
747
753
  // 10%,
748
754
  });
755
+ var pickTokenConfigV1 = (tokenConfig) => ({
756
+ maxSupply: tokenConfig.maxSupply,
757
+ maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
758
+ pricePerToken: tokenConfig.pricePerToken,
759
+ mintDuration: tokenConfig.mintDuration,
760
+ mintStart: tokenConfig.mintStart,
761
+ royaltyBPS: tokenConfig.royaltyBPS,
762
+ tokenURI: tokenConfig.tokenURI,
763
+ royaltyRecipient: tokenConfig.payoutRecipient
764
+ });
765
+ var pickTokenConfigV2 = (tokenConfig) => ({
766
+ maxSupply: tokenConfig.maxSupply,
767
+ maxTokensPerAddress: tokenConfig.maxTokensPerAddress,
768
+ pricePerToken: tokenConfig.pricePerToken,
769
+ mintDuration: tokenConfig.mintDuration,
770
+ mintStart: tokenConfig.mintStart,
771
+ royaltyBPS: tokenConfig.royaltyBPS,
772
+ tokenURI: tokenConfig.tokenURI,
773
+ payoutRecipient: tokenConfig.payoutRecipient,
774
+ createReferral: tokenConfig.createReferral || zeroAddress2
775
+ });
776
+ var tokenConfigV1WithDefault = (tokenConfig, fixedPriceMinter) => ({
777
+ ...pickTokenConfigV1(tokenConfig),
778
+ ...defaultTokenConfigV1MintArguments(),
779
+ fixedPriceMinter
780
+ });
781
+ var tokenConfigV2WithDefault = (tokenConfig, fixedPriceMinter) => ({
782
+ ...pickTokenConfigV2(tokenConfig),
783
+ ...defaultTokenConfigV2MintArguments(),
784
+ fixedPriceMinter
785
+ });
749
786
  var defaultTokenConfigV2MintArguments = () => ({
750
787
  maxSupply: OPEN_EDITION_MINT_SIZE,
751
788
  maxTokensPerAddress: 0n,
752
789
  pricePerToken: 0n,
753
- mintDuration: BigInt(60 * 60 * 24 * 7),
754
- // 1 week
790
+ mintDuration: 0n,
755
791
  mintStart: 0n,
756
792
  royaltyBPS: 1e3
757
793
  // 10%,
758
794
  });
759
795
  var makeTokenConfigWithDefaults = ({
760
796
  chainId,
761
- premintConfigVersion,
762
797
  tokenCreationConfig,
763
- payoutRecipient
798
+ supportedPremintVersions: supportedPremintVersions2
764
799
  }) => {
765
- if (premintConfigVersion === PremintConfigVersion2.V3) {
766
- throw new Error("PremintV3 not supported in SDK");
767
- }
768
- const fixedPriceMinter = tokenCreationConfig.fixedPriceMinter || getDefaultFixedPriceMinterAddress(chainId);
769
- if (premintConfigVersion === PremintConfigVersion2.V1) {
770
- return {
771
- fixedPriceMinter,
772
- ...defaultTokenConfigV1MintArguments(),
773
- royaltyRecipient: payoutRecipient,
774
- ...tokenCreationConfig
775
- };
776
- } else if (premintConfigVersion === PremintConfigVersion2.V2) {
800
+ const fixedPriceMinter = getDefaultFixedPriceMinterAddress(chainId);
801
+ if (!supportedPremintVersions2.includes(PremintConfigVersion2.V2)) {
802
+ if (tokenCreationConfig.createReferral) {
803
+ throw new Error("Contract does not support create referral");
804
+ }
777
805
  return {
778
- fixedPriceMinter,
779
- ...defaultTokenConfigV2MintArguments(),
780
- payoutRecipient,
781
- createReferral: zeroAddress2,
782
- ...tokenCreationConfig
806
+ premintConfigVersion: PremintConfigVersion2.V1,
807
+ tokenConfig: tokenConfigV1WithDefault(
808
+ tokenCreationConfig,
809
+ fixedPriceMinter
810
+ )
783
811
  };
784
- } else {
785
- throw new Error(`Invalid premint config version ${premintConfigVersion}`);
786
812
  }
813
+ return {
814
+ premintConfigVersion: PremintConfigVersion2.V2,
815
+ tokenConfig: tokenConfigV2WithDefault(
816
+ tokenCreationConfig,
817
+ fixedPriceMinter
818
+ )
819
+ };
787
820
  };
788
821
  function getPremintedLogFromReceipt(receipt) {
789
822
  for (const data of receipt.logs) {
@@ -801,20 +834,17 @@ function getPremintedLogFromReceipt(receipt) {
801
834
  }
802
835
  }
803
836
  var PremintClient = class {
804
- constructor(chain, publicClient, httpClient2) {
805
- this.chain = chain;
806
- this.apiClient = new PremintAPIClient(chain.id, httpClient2);
837
+ constructor({
838
+ chainId,
839
+ publicClient,
840
+ premintApi
841
+ }) {
842
+ this.chainId = chainId;
843
+ this.apiClient = premintApi;
807
844
  this.publicClient = publicClient;
808
845
  }
809
- getDataFromPremintReceipt(receipt) {
810
- const premintedLog = getPremintedLogFromReceipt(receipt);
811
- return {
812
- premintedLog,
813
- urls: this.makeUrls({
814
- address: premintedLog?.contractAddress,
815
- tokenId: premintedLog?.tokenId
816
- })
817
- };
846
+ getDataFromPremintReceipt(receipt, blockExplorerUrl) {
847
+ return getDataFromPremintReceipt(receipt, this.chainId, blockExplorerUrl);
818
848
  }
819
849
  /**
820
850
  * Prepares data for updating a premint
@@ -827,7 +857,7 @@ var PremintClient = class {
827
857
  ...args,
828
858
  apiClient: this.apiClient,
829
859
  publicClient: this.publicClient,
830
- chainId: this.chain.id
860
+ chainId: this.chainId
831
861
  });
832
862
  }
833
863
  /**
@@ -841,7 +871,7 @@ var PremintClient = class {
841
871
  ...params,
842
872
  apiClient: this.apiClient,
843
873
  publicClient: this.publicClient,
844
- chainId: this.chain.id
874
+ chainId: this.chainId
845
875
  });
846
876
  }
847
877
  /**
@@ -855,7 +885,7 @@ var PremintClient = class {
855
885
  ...parameters,
856
886
  publicClient: this.publicClient,
857
887
  apiClient: this.apiClient,
858
- chainId: this.chain.id
888
+ chainId: this.chainId
859
889
  });
860
890
  }
861
891
  /**
@@ -865,10 +895,7 @@ var PremintClient = class {
865
895
  * @param uid UID for the desired premint
866
896
  * @returns PremintSignatureGetResponse of premint data from the API
867
897
  */
868
- async getPremintSignature({
869
- address,
870
- uid
871
- }) {
898
+ async getPremint({ address, uid }) {
872
899
  return await this.apiClient.getSignature({
873
900
  collectionAddress: address,
874
901
  uid
@@ -881,44 +908,10 @@ var PremintClient = class {
881
908
  */
882
909
  async getCollectionAddress(collection) {
883
910
  return await getPremintCollectionAddress({
884
- collection,
911
+ contract: collection,
885
912
  publicClient: this.publicClient
886
913
  });
887
914
  }
888
- /**
889
- * Check user signature for v1
890
- *
891
- * @param data Signature data from the API
892
- * @returns isValid = signature is valid or not, recoveredSigner = signer from contract
893
- */
894
- async isValidSignature({
895
- signature,
896
- collection,
897
- premintConfig,
898
- premintConfigVersion
899
- }) {
900
- const { isAuthorized, recoveredAddress } = await isValidSignature({
901
- chainId: this.chain.id,
902
- signature,
903
- collection,
904
- publicClient: this.publicClient,
905
- premintConfig,
906
- premintConfigVersion: premintConfigVersion || PremintConfigVersion2.V1
907
- });
908
- return { isValid: isAuthorized, recoveredSigner: recoveredAddress };
909
- }
910
- makeUrls({
911
- uid,
912
- address,
913
- tokenId
914
- }) {
915
- return makeUrls({
916
- uid,
917
- address,
918
- tokenId,
919
- chain: this.chain
920
- });
921
- }
922
915
  async getMintCosts({
923
916
  tokenContract,
924
917
  quantityToMint,
@@ -938,27 +931,50 @@ var PremintClient = class {
938
931
  * @param parameters - Parameters for collecting the Premint {@link MakeMintParametersArguments}
939
932
  * @returns receipt, log, zoraURL
940
933
  */
941
- async makeMintParameters(parameters) {
942
- return await makeMintParameters({
943
- ...parameters,
944
- apiClient: this.apiClient,
934
+ async makeMintParameters({
935
+ minterAccount,
936
+ tokenContract,
937
+ uid,
938
+ mintArguments,
939
+ firstMinter
940
+ }) {
941
+ return await collectPremint({
942
+ uid,
943
+ tokenContract,
944
+ minterAccount,
945
+ quantityToMint: mintArguments?.quantityToMint || 1n,
946
+ mintComment: mintArguments?.mintComment,
947
+ mintReferral: mintArguments?.mintReferral,
948
+ mintRecipient: mintArguments?.mintRecipient,
949
+ firstMinter,
950
+ premintGetter: this.apiClient,
945
951
  publicClient: this.publicClient
946
952
  });
947
953
  }
948
954
  };
949
- function createPremintClient(clientConfig) {
950
- const { chain, httpClient: httpClient2, publicClient } = setupClient(clientConfig);
951
- return new PremintClient(chain, publicClient, httpClient2);
955
+ function getDataFromPremintReceipt(receipt, chainId, blockExplorerUrl) {
956
+ const premintedLog = getPremintedLogFromReceipt(receipt);
957
+ return {
958
+ tokenId: premintedLog?.tokenId,
959
+ collectionAddres: premintedLog?.contractAddress,
960
+ premintedLog,
961
+ urls: makeUrls({
962
+ address: premintedLog?.contractAddress,
963
+ tokenId: premintedLog?.tokenId,
964
+ chainId,
965
+ blockExplorerUrl
966
+ })
967
+ };
952
968
  }
953
969
  function makePremintReturn({
954
970
  premintConfig,
955
971
  premintConfigVersion,
956
- collectionAddress,
957
- collection,
958
972
  publicClient,
959
973
  apiClient,
960
- chainId
974
+ chainId,
975
+ ...collectionAndAddress
961
976
  }) {
977
+ const { collection, collectionAddress } = collectionAndAddress;
962
978
  const typedDataDefinition = premintTypedDataDefinition2({
963
979
  verifyingContract: collectionAddress,
964
980
  premintConfig,
@@ -978,7 +994,7 @@ function makePremintReturn({
978
994
  await submit({
979
995
  signature,
980
996
  checkSignature,
981
- signerAccount
997
+ account: signerAccount
982
998
  });
983
999
  return {
984
1000
  signature,
@@ -988,23 +1004,22 @@ function makePremintReturn({
988
1004
  const submit = async ({
989
1005
  signature,
990
1006
  checkSignature,
991
- signerAccount
1007
+ account
992
1008
  }) => {
993
1009
  if (checkSignature) {
994
- await validateSignature({
995
- collection: {
996
- ...collection,
997
- additionalAdmins: []
998
- },
1010
+ const isAuthorized = await isAuthorizedToCreatePremint({
1011
+ collectionAddress,
1012
+ additionalAdmins: collection?.additionalAdmins,
1013
+ contractAdmin: collection?.contractAdmin,
999
1014
  publicClient,
1000
- signerAccount
1015
+ signer: account
1001
1016
  });
1017
+ if (!isAuthorized) {
1018
+ throw new Error("Not authorized to create premint");
1019
+ }
1002
1020
  }
1003
1021
  await apiClient.postSignature({
1004
- collection: {
1005
- ...collection,
1006
- additionalAdmins: []
1007
- },
1022
+ ...toContractCreationConfigOrAddress(collectionAndAddress),
1008
1023
  signature,
1009
1024
  premintConfig,
1010
1025
  premintConfigVersion
@@ -1039,43 +1054,21 @@ async function signPremint({
1039
1054
  signerAccount: account
1040
1055
  };
1041
1056
  }
1042
- var validateSignature = async ({
1043
- collection,
1044
- publicClient,
1045
- signerAccount
1046
- }) => {
1047
- const isAuthorized = await isAuthorizedToCreatePremint({
1048
- collection,
1049
- publicClient,
1050
- signer: typeof signerAccount === "string" ? signerAccount : signerAccount.address,
1051
- collectionAddress: await getPremintCollectionAddress({
1052
- collection,
1053
- publicClient
1054
- })
1055
- });
1056
- if (!isAuthorized) {
1057
- throw new Error("Not authorized to create premint");
1058
- }
1059
- };
1060
1057
  async function createPremint({
1061
- payoutRecipient: creatorAccount,
1062
- collection,
1063
- tokenCreationConfig,
1064
- premintConfigVersion,
1058
+ token: tokenCreationConfig,
1065
1059
  uid,
1066
1060
  publicClient,
1067
1061
  apiClient,
1068
- chainId
1062
+ chainId,
1063
+ ...collectionOrAddress
1069
1064
  }) {
1070
1065
  const {
1071
1066
  premintConfig,
1072
- premintConfigVersion: actualVersion,
1073
- collectionAddress
1067
+ premintConfigVersion,
1068
+ collectionAddress: collectionAddressToUse
1074
1069
  } = await prepareCreatePremintConfig({
1075
- payoutRecipient: creatorAccount,
1076
- collection,
1070
+ ...collectionOrAddress,
1077
1071
  tokenCreationConfig,
1078
- premintConfigVersion,
1079
1072
  uid,
1080
1073
  publicClient,
1081
1074
  apiClient,
@@ -1083,59 +1076,49 @@ async function createPremint({
1083
1076
  });
1084
1077
  return makePremintReturn({
1085
1078
  premintConfig,
1086
- premintConfigVersion: actualVersion,
1087
- collectionAddress,
1088
- collection,
1079
+ premintConfigVersion,
1080
+ collectionAddress: collectionAddressToUse,
1081
+ collection: collectionOrAddress.contract,
1089
1082
  publicClient,
1090
1083
  apiClient,
1091
1084
  chainId
1092
1085
  });
1093
1086
  }
1094
1087
  async function prepareCreatePremintConfig({
1095
- payoutRecipient,
1096
- collection,
1097
1088
  tokenCreationConfig,
1098
- premintConfigVersion,
1099
1089
  uid,
1100
1090
  publicClient,
1101
1091
  apiClient,
1102
- chainId
1092
+ chainId,
1093
+ ...collectionOrAddress
1103
1094
  }) {
1104
- const collectionWithAdditionalAdmins = {
1105
- ...collection,
1106
- additionalAdmins: collection.additionalAdmins || []
1107
- };
1108
1095
  const newContractAddress = await getPremintCollectionAddress({
1109
1096
  publicClient,
1110
- collection: collectionWithAdditionalAdmins
1097
+ ...collectionOrAddress
1111
1098
  });
1112
1099
  let uidToUse = uid;
1113
1100
  if (typeof uidToUse !== "number") {
1114
1101
  uidToUse = await apiClient.getNextUID(newContractAddress);
1115
1102
  }
1116
- const actualVersion = premintConfigVersion || PremintConfigVersion2.V1;
1117
- if (!await supportsPremintVersion({
1118
- version: actualVersion,
1119
- publicClient,
1120
- tokenContract: newContractAddress
1121
- })) {
1122
- throw new Error(
1123
- `Premint version ${actualVersion} not supported by contract`
1124
- );
1125
- }
1103
+ const supportedVersions = await supportedPremintVersions({
1104
+ tokenContract: newContractAddress,
1105
+ publicClient
1106
+ });
1107
+ const tokenConfigAndVersion = makeTokenConfigWithDefaults({
1108
+ tokenCreationConfig,
1109
+ chainId,
1110
+ supportedPremintVersions: supportedVersions
1111
+ });
1126
1112
  const premintConfig = makeNewPremint({
1127
- tokenConfig: makeTokenConfigWithDefaults({
1128
- // @ts-ignore
1129
- premintConfigVersion: actualVersion,
1130
- tokenCreationConfig,
1131
- payoutRecipient: typeof payoutRecipient === "string" ? payoutRecipient : payoutRecipient.address,
1132
- chainId
1133
- }),
1113
+ ...tokenConfigAndVersion,
1134
1114
  uid: uidToUse
1135
1115
  });
1136
- return {
1116
+ const premintConfigAndVersion = {
1137
1117
  premintConfig,
1138
- premintConfigVersion: actualVersion,
1118
+ premintConfigVersion: tokenConfigAndVersion.premintConfigVersion
1119
+ };
1120
+ return {
1121
+ ...premintConfigAndVersion,
1139
1122
  collectionAddress: newContractAddress
1140
1123
  };
1141
1124
  }
@@ -1181,7 +1164,8 @@ async function deletePremint({
1181
1164
  const {
1182
1165
  premintConfig,
1183
1166
  premintConfigVersion,
1184
- collection: collectionCreationConfig
1167
+ collection: collectionCreationConfig,
1168
+ collectionAddress
1185
1169
  } = await apiClient.getSignature({
1186
1170
  collectionAddress: collection,
1187
1171
  uid
@@ -1194,32 +1178,39 @@ async function deletePremint({
1194
1178
  return makePremintReturn({
1195
1179
  premintConfig: deletedPremint,
1196
1180
  premintConfigVersion,
1197
- collectionAddress: collection,
1181
+ collectionAddress,
1198
1182
  collection: collectionCreationConfig,
1199
1183
  publicClient,
1200
1184
  apiClient,
1201
1185
  chainId
1202
1186
  });
1203
1187
  }
1204
- async function makeMintParameters({
1188
+ async function collectPremint({
1205
1189
  uid,
1206
1190
  tokenContract,
1207
1191
  minterAccount,
1208
- mintArguments,
1209
- apiClient,
1192
+ quantityToMint,
1193
+ mintComment = "",
1194
+ mintReferral,
1195
+ mintRecipient,
1196
+ firstMinter,
1197
+ premintGetter,
1210
1198
  publicClient
1211
1199
  }) {
1212
- if (mintArguments && mintArguments?.quantityToMint < 1) {
1200
+ if (typeof quantityToMint !== "undefined" && quantityToMint < 1) {
1213
1201
  throw new Error("Quantity to mint cannot be below 1");
1214
1202
  }
1215
- if (!minterAccount) {
1216
- throw new Error("Wallet not passed in");
1217
- }
1218
- const { premintConfig, premintConfigVersion, collection, signature } = await apiClient.getSignature({
1203
+ const {
1204
+ premintConfig,
1205
+ premintConfigVersion,
1206
+ collection,
1207
+ collectionAddress,
1208
+ signature
1209
+ } = await premintGetter.getSignature({
1219
1210
  collectionAddress: tokenContract,
1220
1211
  uid
1221
1212
  });
1222
- const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
1213
+ const numberToMint = BigInt(quantityToMint || 1);
1223
1214
  if (premintConfigVersion === PremintConfigVersion2.V3) {
1224
1215
  throw new Error("PremintV3 not supported in premint SDK");
1225
1216
  }
@@ -1228,67 +1219,64 @@ async function makeMintParameters({
1228
1219
  quantityToMint: numberToMint,
1229
1220
  publicClient,
1230
1221
  tokenPrice: premintConfig.tokenConfig.pricePerToken
1231
- })).totalCost;
1222
+ })).totalCostEth;
1232
1223
  const mintArgumentsContract = {
1233
- mintComment: mintArguments?.mintComment || "",
1234
- mintRecipient: mintArguments?.mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address),
1224
+ mintComment,
1225
+ mintRecipient: mintRecipientOrAccount({
1226
+ mintRecipient,
1227
+ minterAccount
1228
+ }),
1235
1229
  mintRewardsRecipients: makeMintRewardsRecipient({
1236
- mintReferral: mintArguments?.mintReferral
1230
+ mintReferral
1237
1231
  })
1238
1232
  };
1239
- if (premintConfigVersion === PremintConfigVersion2.V1) {
1240
- return makeSimulateContractParamaters({
1241
- account: minterAccount,
1242
- abi: zoraCreator1155PremintExecutorImplABI2,
1243
- functionName: "premintV1",
1244
- value,
1245
- address: getPremintExecutorAddress(),
1246
- args: [
1247
- collection,
1248
- premintConfig,
1249
- signature,
1250
- numberToMint,
1251
- mintArgumentsContract
1252
- ]
1253
- });
1254
- } else if (premintConfigVersion === PremintConfigVersion2.V2) {
1255
- return makeSimulateContractParamaters({
1256
- account: minterAccount,
1257
- abi: zoraCreator1155PremintExecutorImplABI2,
1258
- functionName: "premintV2",
1259
- value,
1260
- address: getPremintExecutorAddress(),
1261
- args: [
1262
- collection,
1233
+ const collectionOrEmpty = collection ? defaultAdditionalAdmins(collection) : emptyContractCreationConfig();
1234
+ const collectionAddressToSubmit = collection ? zeroAddress2 : collectionAddress;
1235
+ const firstMinterToSubmit = firstMinter || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
1236
+ return makeContractParameters({
1237
+ account: minterAccount,
1238
+ abi: zoraCreator1155PremintExecutorImplABI2,
1239
+ functionName: "premint",
1240
+ value,
1241
+ address: getPremintExecutorAddress(),
1242
+ args: [
1243
+ collectionOrEmpty,
1244
+ collectionAddressToSubmit,
1245
+ encodePremintConfig({
1263
1246
  premintConfig,
1264
- signature,
1265
- numberToMint,
1266
- mintArgumentsContract
1267
- ]
1268
- });
1269
- }
1270
- throw new Error(`Invalid premint config version ${premintConfigVersion}`);
1247
+ premintConfigVersion
1248
+ }),
1249
+ signature,
1250
+ numberToMint,
1251
+ mintArgumentsContract,
1252
+ firstMinterToSubmit,
1253
+ zeroAddress2
1254
+ ]
1255
+ });
1271
1256
  }
1272
1257
  function makeUrls({
1273
1258
  uid,
1274
1259
  address,
1275
1260
  tokenId,
1276
- chain
1261
+ chainId,
1262
+ blockExplorerUrl
1277
1263
  }) {
1278
1264
  if ((!uid || !tokenId) && !address) {
1279
1265
  return { explorer: null, zoraCollect: null, zoraManage: null };
1280
1266
  }
1281
1267
  const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
1282
- const network = getApiNetworkConfigForChain(chain.id);
1268
+ const network = getApiNetworkConfigForChain(chainId);
1283
1269
  return {
1284
- explorer: tokenId ? `https://${chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
1270
+ explorer: tokenId ? `https://${blockExplorerUrl}/token/${address}/instance/${tokenId}` : null,
1285
1271
  zoraCollect: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`,
1286
1272
  zoraManage: `https://${network.isTestnet ? "testnet." : ""}zora.co/collect/${network.zoraCollectPathChainName}:${address}/${zoraTokenPath}`
1287
1273
  };
1288
1274
  }
1289
1275
 
1290
1276
  // src/premint/contract-types.ts
1291
- import { PremintConfigVersion as PremintConfigVersionOrig } from "@zoralabs/protocol-deployments";
1277
+ import {
1278
+ PremintConfigVersion as PremintConfigVersionOrig
1279
+ } from "@zoralabs/protocol-deployments";
1292
1280
  var PremintConfigVersion3 = ((PremintConfigVersion4) => {
1293
1281
  PremintConfigVersion4[PremintConfigVersion4["V1"] = PremintConfigVersionOrig.V1] = "V1";
1294
1282
  PremintConfigVersion4[PremintConfigVersion4["V2"] = PremintConfigVersionOrig.V2] = "V2";
@@ -1296,11 +1284,79 @@ var PremintConfigVersion3 = ((PremintConfigVersion4) => {
1296
1284
  return PremintConfigVersion4;
1297
1285
  })(PremintConfigVersion3 || {});
1298
1286
 
1287
+ // src/premint/premint-api-client.ts
1288
+ var postSignature = async ({
1289
+ httpClient: { post: post2, retries: retries2 } = httpClient,
1290
+ ...data
1291
+ }) => retries2(
1292
+ () => post2(`${ZORA_API_BASE}premint/signature`, data)
1293
+ );
1294
+ var getNextUID = async ({
1295
+ chainId,
1296
+ collection_address,
1297
+ httpClient: { retries: retries2, get: get2 } = httpClient
1298
+ }) => retries2(
1299
+ () => get2(
1300
+ `${ZORA_API_BASE}premint/signature/${getApiNetworkConfigForChain(chainId).zoraBackendChainName}/${collection_address}/next_uid`
1301
+ )
1302
+ );
1303
+ var getSignature = async ({
1304
+ collectionAddress,
1305
+ uid,
1306
+ chainId,
1307
+ httpClient: { retries: retries2, get: get2 } = httpClient
1308
+ }) => {
1309
+ const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
1310
+ const result = await retries2(
1311
+ () => get2(
1312
+ `${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}/${uid}`
1313
+ )
1314
+ );
1315
+ return convertGetPremintApiResponse(result);
1316
+ };
1317
+ var PremintAPIClient = class {
1318
+ constructor(chainId, httpClient2) {
1319
+ this.postSignature = ({
1320
+ signature,
1321
+ ...rest
1322
+ }) => {
1323
+ const data = encodePostSignatureInput({
1324
+ ...rest,
1325
+ chainId: this.chainId,
1326
+ signature
1327
+ });
1328
+ return postSignature({
1329
+ ...data,
1330
+ httpClient: this.httpClient
1331
+ });
1332
+ };
1333
+ this.getNextUID = async (collectionAddress) => (await getNextUID({
1334
+ collection_address: collectionAddress.toLowerCase(),
1335
+ chainId: this.chainId,
1336
+ httpClient: this.httpClient
1337
+ })).next_uid;
1338
+ this.getSignature = async ({
1339
+ collectionAddress,
1340
+ uid
1341
+ }) => {
1342
+ return getSignature({
1343
+ collectionAddress,
1344
+ uid,
1345
+ chainId: this.chainId,
1346
+ httpClient: this.httpClient
1347
+ });
1348
+ };
1349
+ this.chainId = chainId;
1350
+ this.httpClient = httpClient2 || httpClient;
1351
+ }
1352
+ };
1353
+
1299
1354
  // src/mint/mint-client.ts
1300
1355
  import {
1301
1356
  encodeAbiParameters,
1302
1357
  parseAbiParameters,
1303
- zeroAddress as zeroAddress3
1358
+ zeroAddress as zeroAddress3,
1359
+ erc20Abi
1304
1360
  } from "viem";
1305
1361
  import {
1306
1362
  erc20MinterABI,
@@ -1308,6 +1364,15 @@ import {
1308
1364
  zoraCreator1155ImplABI as zoraCreator1155ImplABI2,
1309
1365
  zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress2
1310
1366
  } from "@zoralabs/protocol-deployments";
1367
+
1368
+ // src/mint/types.ts
1369
+ var isOnChainMint = (mint2) => mint2.mintType !== "premint";
1370
+ var is1155Mint = (mint2) => mint2.mintType === "1155";
1371
+ function isErc20SaleStrategy(salesConfig) {
1372
+ return salesConfig.saleType === "erc20";
1373
+ }
1374
+
1375
+ // src/mint/mint-client.ts
1311
1376
  var MintError = class extends Error {
1312
1377
  };
1313
1378
  var MintInactiveError = class extends Error {
@@ -1317,265 +1382,612 @@ var Errors = {
1317
1382
  MintInactiveError
1318
1383
  };
1319
1384
  var MintClient = class {
1320
- constructor(chain, publicClient, httpClient2) {
1321
- this.apiClient = new MintAPIClient(chain.id, httpClient2);
1385
+ constructor({
1386
+ chainId,
1387
+ publicClient,
1388
+ premintGetter,
1389
+ mintGetter
1390
+ }) {
1391
+ this.chainId = chainId;
1322
1392
  this.publicClient = publicClient;
1393
+ this.mintGetter = mintGetter;
1394
+ this.premintGetter = premintGetter;
1323
1395
  }
1324
1396
  /**
1325
1397
  * Returns the parameters needed to prepare a transaction mint a token.
1398
+ * Works with premint, onchain 1155, and onchain 721.
1326
1399
  *
1327
- * @param parameters - Parameters for collecting the token {@link MintTokenParams}
1400
+ * @param parameters - Parameters for collecting the token {@link MakeMintParametersArguments}
1328
1401
  * @returns Parameters for simulating/executing the mint transaction
1329
1402
  */
1330
- async makePrepareMintTokenParams(parameters) {
1331
- return makePrepareMintTokenParams({
1403
+ async mint(parameters) {
1404
+ return mint({
1405
+ parameters,
1406
+ chainId: this.chainId,
1407
+ publicClient: this.publicClient,
1408
+ mintGetter: this.mintGetter,
1409
+ premintGetter: this.premintGetter
1410
+ });
1411
+ }
1412
+ /**
1413
+ * Gets the costs to mint the quantity of tokens specified for a mint.
1414
+ * @param parameters - Parameters for the mint {@link GetMintCostsParameters}
1415
+ * @returns Costs to mint the quantity of tokens specified
1416
+ */
1417
+ async getMintCosts(parameters) {
1418
+ return getMintCosts({
1419
+ ...parameters,
1420
+ mintGetter: this.mintGetter,
1421
+ premintGetter: this.premintGetter,
1422
+ publicClient: this.publicClient
1423
+ });
1424
+ }
1425
+ };
1426
+ function isPremintCollect(parameters) {
1427
+ return parameters.mintType === "premint";
1428
+ }
1429
+ function is721Collect(parameters) {
1430
+ return parameters.mintType === "721";
1431
+ }
1432
+ async function mint({
1433
+ parameters,
1434
+ chainId,
1435
+ publicClient,
1436
+ mintGetter,
1437
+ premintGetter
1438
+ }) {
1439
+ if (isPremintCollect(parameters)) {
1440
+ return {
1441
+ parameters: await collectPremint({
1442
+ ...parameters,
1443
+ premintGetter,
1444
+ publicClient
1445
+ })
1446
+ };
1447
+ }
1448
+ return {
1449
+ parameters: await collectOnchain({
1332
1450
  ...parameters,
1333
- apiClient: this.apiClient,
1334
- publicClient: this.publicClient
1451
+ mintGetter,
1452
+ chainId
1453
+ })
1454
+ };
1455
+ }
1456
+ function requestErc20ApprovalForMint({
1457
+ account,
1458
+ tokenAddress,
1459
+ quantityErc20,
1460
+ erc20MinterAddress: erc20MinterAddress2
1461
+ }) {
1462
+ return makeContractParameters({
1463
+ abi: erc20Abi,
1464
+ address: tokenAddress,
1465
+ account,
1466
+ functionName: "approve",
1467
+ args: [erc20MinterAddress2, quantityErc20]
1468
+ });
1469
+ }
1470
+ async function getNecessaryErc20Approval({
1471
+ chainId,
1472
+ account,
1473
+ tokenAddress,
1474
+ quantityErc20,
1475
+ publicClient
1476
+ }) {
1477
+ const destination = erc20MinterAddress[chainId];
1478
+ const allowance = await publicClient.readContract({
1479
+ abi: erc20Abi,
1480
+ address: tokenAddress,
1481
+ functionName: "allowance",
1482
+ account,
1483
+ args: [
1484
+ destination,
1485
+ erc20MinterAddress[chainId]
1486
+ ]
1487
+ });
1488
+ if (allowance < quantityErc20) {
1489
+ return requestErc20ApprovalForMint({
1490
+ erc20MinterAddress: destination,
1491
+ account,
1492
+ tokenAddress,
1493
+ quantityErc20: quantityErc20 - allowance
1335
1494
  });
1336
1495
  }
1337
- };
1338
- function createMintClient(clientConfig) {
1339
- const { chain, publicClient, httpClient: httpClient2 } = setupClient(clientConfig);
1340
- return new MintClient(chain, publicClient, httpClient2);
1496
+ return void 0;
1341
1497
  }
1342
- async function makePrepareMintTokenParams({
1343
- publicClient,
1344
- apiClient,
1345
- tokenId,
1346
- tokenAddress,
1347
- mintArguments,
1348
- ...rest
1498
+ async function collectOnchain({
1499
+ chainId,
1500
+ mintGetter,
1501
+ ...parameters
1349
1502
  }) {
1350
- const salesConfigAndTokenInfo = await apiClient.getSalesConfigAndTokenInfo({
1503
+ const { tokenContract, saleType } = parameters;
1504
+ const tokenId = is1155Mint(parameters) ? parameters.tokenId : void 0;
1505
+ const salesConfigAndTokenInfo = await mintGetter.getSalesConfigAndTokenInfo({
1351
1506
  tokenId,
1352
- tokenAddress,
1353
- saleType: mintArguments.saleType
1507
+ tokenAddress: tokenContract,
1508
+ saleType
1354
1509
  });
1355
- if (tokenId === void 0) {
1510
+ if (is721Collect(parameters)) {
1356
1511
  return makePrepareMint721TokenParams({
1357
1512
  salesConfigAndTokenInfo,
1358
- tokenAddress,
1359
- mintArguments,
1360
- ...rest
1513
+ ...parameters
1361
1514
  });
1362
1515
  }
1363
1516
  return makePrepareMint1155TokenParams({
1364
1517
  salesConfigAndTokenInfo,
1365
- tokenAddress,
1366
- tokenId,
1367
- mintArguments,
1368
- ...rest
1518
+ chainId,
1519
+ ...parameters
1369
1520
  });
1370
1521
  }
1371
1522
  async function makePrepareMint721TokenParams({
1372
- tokenAddress,
1373
1523
  salesConfigAndTokenInfo,
1374
1524
  minterAccount,
1375
- mintArguments
1525
+ tokenContract,
1526
+ mintComment,
1527
+ mintReferral,
1528
+ mintRecipient,
1529
+ quantityToMint
1376
1530
  }) {
1377
- const mintValue = getMintCosts({
1531
+ const actualQuantityToMint = BigInt(quantityToMint || 1);
1532
+ const mintValue = parseMintCosts({
1378
1533
  salesConfigAndTokenInfo,
1379
- quantityToMint: BigInt(mintArguments.quantityToMint)
1380
- }).totalCost;
1381
- return makeSimulateContractParamaters({
1534
+ quantityToMint: actualQuantityToMint
1535
+ }).totalCostEth;
1536
+ return makeContractParameters({
1382
1537
  abi: zora721Abi,
1383
- address: tokenAddress,
1538
+ address: tokenContract,
1384
1539
  account: minterAccount,
1385
1540
  functionName: "mintWithRewards",
1386
1541
  value: mintValue,
1387
1542
  args: [
1388
- mintArguments.mintToAddress,
1389
- BigInt(mintArguments.quantityToMint),
1390
- mintArguments.mintComment || "",
1391
- mintArguments.mintReferral || zeroAddress3
1543
+ mintRecipientOrAccount({ mintRecipient, minterAccount }),
1544
+ actualQuantityToMint,
1545
+ mintComment || "",
1546
+ mintReferral || zeroAddress3
1392
1547
  ]
1393
1548
  });
1394
1549
  }
1395
- function getMintCosts({
1550
+ function parseMintCosts({
1396
1551
  salesConfigAndTokenInfo,
1397
1552
  quantityToMint
1398
1553
  }) {
1399
1554
  const mintFeeForTokens = salesConfigAndTokenInfo.mintFeePerQuantity * quantityToMint;
1400
1555
  const tokenPurchaseCost = BigInt(salesConfigAndTokenInfo.salesConfig.pricePerToken) * quantityToMint;
1556
+ const totalPurchaseCostCurrency = isErc20SaleStrategy(
1557
+ salesConfigAndTokenInfo.salesConfig
1558
+ ) ? salesConfigAndTokenInfo.salesConfig.currency : void 0;
1559
+ const totalPurchaseCostEth = totalPurchaseCostCurrency ? 0n : tokenPurchaseCost;
1401
1560
  return {
1402
1561
  mintFee: mintFeeForTokens,
1403
- tokenPurchaseCost,
1404
- totalCost: mintFeeForTokens + tokenPurchaseCost
1562
+ totalPurchaseCost: tokenPurchaseCost,
1563
+ totalPurchaseCostCurrency,
1564
+ totalCostEth: mintFeeForTokens + totalPurchaseCostEth
1405
1565
  };
1406
1566
  }
1407
- async function makePrepareMint1155TokenParams({
1567
+ async function getMintCosts(params) {
1568
+ const { quantityMinted: quantityToMint, collection, publicClient } = params;
1569
+ if (isOnChainMint(params)) {
1570
+ const tokenId = is1155Mint(params) ? params.tokenId : void 0;
1571
+ const salesConfigAndTokenInfo = await params.mintGetter.getSalesConfigAndTokenInfo({
1572
+ tokenId,
1573
+ tokenAddress: collection
1574
+ });
1575
+ return parseMintCosts({
1576
+ salesConfigAndTokenInfo,
1577
+ quantityToMint: BigInt(quantityToMint)
1578
+ });
1579
+ }
1580
+ return getPremintMintCostsWithUnknownTokenPrice({
1581
+ premintGetter: params.premintGetter,
1582
+ publicClient,
1583
+ quantityToMint: BigInt(quantityToMint),
1584
+ uid: params.uid,
1585
+ tokenContract: collection
1586
+ });
1587
+ }
1588
+ function makePrepareMint1155TokenParams({
1589
+ tokenContract,
1408
1590
  tokenId,
1409
1591
  salesConfigAndTokenInfo,
1410
1592
  minterAccount,
1411
- tokenAddress,
1412
- mintArguments
1593
+ mintComment,
1594
+ mintReferral,
1595
+ mintRecipient,
1596
+ quantityToMint,
1597
+ chainId
1413
1598
  }) {
1414
- const mintQuantity = BigInt(mintArguments.quantityToMint);
1415
- const mintValue = getMintCosts({
1416
- salesConfigAndTokenInfo,
1417
- quantityToMint: mintQuantity
1418
- }).totalCost;
1419
- switch (salesConfigAndTokenInfo.salesConfig.saleType) {
1420
- case "fixedPrice":
1421
- const fixedPriceArgs = mintArguments;
1422
- return makeSimulateContractParamaters({
1423
- abi: zoraCreator1155ImplABI2,
1424
- functionName: "mintWithRewards",
1425
- account: minterAccount,
1426
- value: mintValue,
1427
- address: tokenAddress,
1428
- /* args: minter, tokenId, quantity, minterArguments, mintReferral */
1429
- args: [
1430
- salesConfigAndTokenInfo.salesConfig.address || zoraCreatorFixedPriceSaleStrategyAddress2[999999999],
1431
- BigInt(tokenId),
1432
- mintQuantity,
1433
- encodeAbiParameters(parseAbiParameters("address, string"), [
1434
- fixedPriceArgs.mintToAddress,
1435
- fixedPriceArgs.mintComment || ""
1436
- ]),
1437
- fixedPriceArgs.mintReferral || zeroAddress3
1438
- ]
1439
- });
1440
- case "erc20":
1441
- const erc20Args = mintArguments;
1442
- return makeSimulateContractParamaters({
1443
- abi: erc20MinterABI,
1444
- functionName: "mint",
1445
- account: minterAccount,
1446
- address: salesConfigAndTokenInfo?.salesConfig.address || erc20MinterAddress[999999999],
1447
- /* args: mintTo, quantity, tokenAddress, tokenId, totalValue, currency, mintReferral, comment */
1448
- args: [
1449
- mintArguments.mintToAddress,
1450
- mintQuantity,
1451
- tokenAddress,
1452
- BigInt(tokenId),
1453
- salesConfigAndTokenInfo.salesConfig.pricePerToken,
1454
- salesConfigAndTokenInfo.salesConfig.currency,
1455
- erc20Args.mintReferral || zeroAddress3,
1456
- erc20Args.mintComment || ""
1457
- ]
1458
- });
1459
- default:
1460
- throw new MintError("Unsupported sale type");
1599
+ const mintQuantity = BigInt(quantityToMint || 1);
1600
+ const mintTo = mintRecipientOrAccount({ mintRecipient, minterAccount });
1601
+ const saleType = salesConfigAndTokenInfo.salesConfig.saleType;
1602
+ if (saleType === "fixedPrice") {
1603
+ const mintValue = parseMintCosts({
1604
+ salesConfigAndTokenInfo,
1605
+ quantityToMint: mintQuantity
1606
+ }).totalCostEth;
1607
+ return makeContractParameters({
1608
+ abi: zoraCreator1155ImplABI2,
1609
+ functionName: "mintWithRewards",
1610
+ account: minterAccount,
1611
+ value: mintValue,
1612
+ address: tokenContract,
1613
+ /* args: minter, tokenId, quantity, minterArguments, mintReferral */
1614
+ args: [
1615
+ salesConfigAndTokenInfo.salesConfig.address || zoraCreatorFixedPriceSaleStrategyAddress2[chainId],
1616
+ BigInt(tokenId),
1617
+ mintQuantity,
1618
+ encodeAbiParameters(parseAbiParameters("address, string"), [
1619
+ mintTo,
1620
+ mintComment || ""
1621
+ ]),
1622
+ mintReferral || zeroAddress3
1623
+ ]
1624
+ });
1461
1625
  }
1626
+ if (saleType === "erc20") {
1627
+ return makeContractParameters({
1628
+ abi: erc20MinterABI,
1629
+ functionName: "mint",
1630
+ account: minterAccount,
1631
+ address: salesConfigAndTokenInfo?.salesConfig.address || erc20MinterAddress[chainId],
1632
+ /* args: mintTo, quantity, tokenAddress, tokenId, totalValue, currency, mintReferral, comment */
1633
+ args: [
1634
+ mintTo,
1635
+ mintQuantity,
1636
+ tokenContract,
1637
+ BigInt(tokenId),
1638
+ salesConfigAndTokenInfo.salesConfig.pricePerToken * mintQuantity,
1639
+ salesConfigAndTokenInfo.salesConfig.currency,
1640
+ mintReferral || zeroAddress3,
1641
+ mintComment || ""
1642
+ ]
1643
+ });
1644
+ }
1645
+ throw new MintError("Unsupported sale type");
1462
1646
  }
1463
1647
 
1464
1648
  // src/create/1155-create-helper.ts
1465
1649
  import {
1650
+ zoraCreator1155FactoryImplABI as zoraCreator1155FactoryImplABI2,
1651
+ zoraCreator1155FactoryImplAddress as zoraCreator1155FactoryImplAddress2,
1652
+ zoraCreator1155ImplABI as zoraCreator1155ImplABI5
1653
+ } from "@zoralabs/protocol-deployments";
1654
+ import { decodeEventLog as decodeEventLog2 } from "viem";
1655
+
1656
+ // src/create/contract-setup.ts
1657
+ import {
1658
+ contracts1155,
1466
1659
  zoraCreator1155FactoryImplABI,
1467
1660
  zoraCreator1155FactoryImplAddress,
1468
- zoraCreator1155ImplABI as zoraCreator1155ImplABI3,
1469
- zoraCreatorFixedPriceSaleStrategyABI
1661
+ zoraCreator1155ImplABI as zoraCreator1155ImplABI3
1470
1662
  } from "@zoralabs/protocol-deployments";
1471
- import { decodeEventLog as decodeEventLog2, encodeFunctionData, zeroAddress as zeroAddress4 } from "viem";
1472
- var SALE_END_FOREVER = 18446744073709551615n;
1473
- var ROYALTY_BPS_DEFAULT = 1e3;
1474
- var DEFAULT_SALE_SETTINGS = {
1475
- fundsRecipient: zeroAddress4,
1476
- // Free Mint
1477
- pricePerToken: 0n,
1478
- // Sale start time – defaults to beginning of unix time
1479
- saleStart: 0n,
1480
- // This is the end of uint64, plenty of time
1481
- saleEnd: SALE_END_FOREVER,
1482
- // 0 Here means no limit
1483
- maxTokensPerAddress: 0n
1484
- };
1485
- var PERMISSION_BIT_MINTER = 4n;
1486
- function create1155TokenSetupArgs({
1487
- nextTokenId,
1488
- // How many NFTs upon initialization to mint to the creator
1489
- mintToCreatorCount,
1490
- tokenMetadataURI,
1491
- // Fixed price minter address – required minter
1492
- fixedPriceMinterAddress,
1493
- // Address to use as the create referral, optional.
1494
- createReferral,
1495
- // Optional max supply of the token. Default unlimited
1496
- maxSupply,
1497
- // wallet sending the transaction
1498
- account,
1499
- salesConfig,
1500
- royaltySettings
1663
+ function new1155ContractVersion(chainId) {
1664
+ const address = contracts1155.addresses[chainId];
1665
+ if (!address) {
1666
+ throw new Error(`No contract address for chainId ${chainId}`);
1667
+ }
1668
+ return address.CONTRACT_1155_IMPL_VERSION;
1669
+ }
1670
+ async function getContractInfo({
1671
+ publicClient,
1672
+ chainId,
1673
+ contract,
1674
+ account
1501
1675
  }) {
1502
- if (!maxSupply) {
1503
- maxSupply = OPEN_EDITION_MINT_SIZE;
1676
+ const contractAddress = typeof contract === "string" ? contract : await publicClient.readContract({
1677
+ abi: zoraCreator1155FactoryImplABI,
1678
+ // Since this address is deterministic we can hardcode a chain id safely here.
1679
+ address: zoraCreator1155FactoryImplAddress[chainId],
1680
+ functionName: "deterministicContractAddress",
1681
+ args: [
1682
+ account,
1683
+ contract.uri,
1684
+ contract.name,
1685
+ contract.defaultAdmin || account
1686
+ ]
1687
+ });
1688
+ let contractVersion;
1689
+ let contractExists;
1690
+ try {
1691
+ contractVersion = await publicClient.readContract({
1692
+ abi: zoraCreator1155ImplABI3,
1693
+ address: contractAddress,
1694
+ functionName: "contractVersion"
1695
+ });
1696
+ contractExists = true;
1697
+ } catch (e) {
1698
+ contractVersion = new1155ContractVersion(chainId);
1699
+ contractExists = false;
1504
1700
  }
1505
- maxSupply = BigInt(maxSupply);
1506
- mintToCreatorCount = BigInt(mintToCreatorCount);
1507
- const salesConfigWithDefaults = {
1508
- // Set static sales default.
1701
+ const nextTokenId = contractExists ? await publicClient.readContract({
1702
+ address: contractAddress,
1703
+ abi: zoraCreator1155ImplABI3,
1704
+ functionName: "nextTokenId"
1705
+ }) : 1n;
1706
+ return {
1707
+ contractExists,
1708
+ contractAddress,
1709
+ contractVersion,
1710
+ nextTokenId
1711
+ };
1712
+ }
1713
+
1714
+ // src/create/token-setup.ts
1715
+ import {
1716
+ erc20MinterABI as erc20MinterABI2,
1717
+ erc20MinterAddress as erc20MinterAddresses,
1718
+ zoraCreator1155ImplABI as zoraCreator1155ImplABI4,
1719
+ zoraCreatorFixedPriceSaleStrategyABI,
1720
+ zoraCreatorFixedPriceSaleStrategyAddress as zoraCreatorFixedPriceSaleStrategyAddress3
1721
+ } from "@zoralabs/protocol-deployments";
1722
+ import { encodeFunctionData, zeroAddress as zeroAddress4 } from "viem";
1723
+ import * as semver from "semver";
1724
+ var PERMISSION_BITS = {
1725
+ MINTER: 2n ** 2n
1726
+ };
1727
+ var saleSettingsOrDefault = (saleSettings) => {
1728
+ const SALE_END_FOREVER = 18446744073709551615n;
1729
+ const DEFAULT_SALE_SETTINGS = {
1730
+ currency: zeroAddress4,
1731
+ // Free Mint
1732
+ pricePerToken: 0n,
1733
+ // Sale start time – defaults to beginning of unix time
1734
+ saleStart: 0n,
1735
+ // This is the end of uint64, plenty of time
1736
+ saleEnd: SALE_END_FOREVER,
1737
+ // 0 Here means no limit
1738
+ maxTokensPerAddress: 0n
1739
+ };
1740
+ return {
1509
1741
  ...DEFAULT_SALE_SETTINGS,
1510
- // Override with user settings.
1511
- ...salesConfig
1742
+ ...saleSettings
1512
1743
  };
1513
- const setupActions = [
1514
- encodeFunctionData({
1515
- abi: zoraCreator1155ImplABI3,
1516
- functionName: "assumeLastTokenIdMatches",
1517
- args: [nextTokenId - 1n]
1518
- }),
1519
- createReferral ? encodeFunctionData({
1520
- abi: zoraCreator1155ImplABI3,
1744
+ };
1745
+ function applyNew1155Defaults(props, ownerAddress) {
1746
+ const { payoutRecipient: fundsRecipient } = props;
1747
+ const fundsRecipientOrOwner = fundsRecipient && fundsRecipient !== zeroAddress4 ? fundsRecipient : ownerAddress;
1748
+ return {
1749
+ payoutRecipient: fundsRecipientOrOwner,
1750
+ createReferral: props.createReferral || zeroAddress4,
1751
+ maxSupply: typeof props.maxSupply === "undefined" ? OPEN_EDITION_MINT_SIZE : BigInt(props.maxSupply),
1752
+ royaltyBPS: props.royaltyBPS || 1e3,
1753
+ salesConfig: saleSettingsOrDefault(props.salesConfig),
1754
+ tokenMetadataURI: props.tokenMetadataURI
1755
+ };
1756
+ }
1757
+ function setupErc20Minter({
1758
+ pricePerToken,
1759
+ chainId,
1760
+ tokenId: nextTokenId,
1761
+ currency,
1762
+ saleStart,
1763
+ saleEnd,
1764
+ maxTokensPerAddress: mintLimit,
1765
+ fundsRecipient
1766
+ }) {
1767
+ const erc20MinterAddress2 = erc20MinterAddresses[chainId];
1768
+ if (!erc20MinterAddress2)
1769
+ throw new Error(`ERC20Minter not deployed on chainId ${chainId}`);
1770
+ const erc20MinterApproval = encodeFunctionData({
1771
+ abi: zoraCreator1155ImplABI4,
1772
+ functionName: "addPermission",
1773
+ args: [BigInt(nextTokenId), erc20MinterAddress2, PERMISSION_BITS.MINTER]
1774
+ });
1775
+ const saleData = encodeFunctionData({
1776
+ abi: erc20MinterABI2,
1777
+ functionName: "setSale",
1778
+ args: [
1779
+ BigInt(nextTokenId),
1780
+ {
1781
+ saleStart: saleStart || BigInt(0),
1782
+ saleEnd: saleEnd || BigInt(0),
1783
+ maxTokensPerAddress: BigInt(mintLimit || 0),
1784
+ pricePerToken,
1785
+ fundsRecipient,
1786
+ currency
1787
+ }
1788
+ ]
1789
+ });
1790
+ const callSale = encodeFunctionData({
1791
+ abi: zoraCreator1155ImplABI4,
1792
+ functionName: "callSale",
1793
+ args: [BigInt(nextTokenId), erc20MinterAddress2, saleData]
1794
+ });
1795
+ return {
1796
+ minter: erc20MinterAddress2,
1797
+ setupActions: [erc20MinterApproval, callSale]
1798
+ };
1799
+ }
1800
+ function setupFixedPriceMinter({
1801
+ pricePerToken: price,
1802
+ tokenId: nextTokenId,
1803
+ chainId,
1804
+ saleStart,
1805
+ saleEnd,
1806
+ maxTokensPerAddress: mintLimit,
1807
+ fundsRecipient
1808
+ }) {
1809
+ const fixedPriceStrategyAddress = zoraCreatorFixedPriceSaleStrategyAddress3[chainId];
1810
+ const fixedPriceApproval = encodeFunctionData({
1811
+ abi: zoraCreator1155ImplABI4,
1812
+ functionName: "addPermission",
1813
+ args: [
1814
+ BigInt(nextTokenId),
1815
+ fixedPriceStrategyAddress,
1816
+ PERMISSION_BITS.MINTER
1817
+ ]
1818
+ });
1819
+ const saleData = encodeFunctionData({
1820
+ abi: zoraCreatorFixedPriceSaleStrategyABI,
1821
+ functionName: "setSale",
1822
+ args: [
1823
+ BigInt(nextTokenId),
1824
+ {
1825
+ pricePerToken: price,
1826
+ saleStart: saleStart || BigInt(0),
1827
+ saleEnd: saleEnd || BigInt(0),
1828
+ maxTokensPerAddress: BigInt(mintLimit || 0),
1829
+ fundsRecipient
1830
+ }
1831
+ ]
1832
+ });
1833
+ const callSale = encodeFunctionData({
1834
+ abi: zoraCreator1155ImplABI4,
1835
+ functionName: "callSale",
1836
+ args: [BigInt(nextTokenId), fixedPriceStrategyAddress, saleData]
1837
+ });
1838
+ return {
1839
+ minter: fixedPriceStrategyAddress,
1840
+ setupActions: [fixedPriceApproval, callSale]
1841
+ };
1842
+ }
1843
+ function setupMinters({ salesConfig, ...rest }) {
1844
+ if (!salesConfig)
1845
+ throw new Error("No sales config for token");
1846
+ const { currency: currencyAddress } = salesConfig;
1847
+ if (currencyAddress === zeroAddress4) {
1848
+ return setupFixedPriceMinter({
1849
+ ...salesConfig,
1850
+ ...rest
1851
+ });
1852
+ } else {
1853
+ return setupErc20Minter({
1854
+ ...salesConfig,
1855
+ ...rest
1856
+ });
1857
+ }
1858
+ }
1859
+ function buildSetupNewToken({
1860
+ tokenURI,
1861
+ maxSupply = OPEN_EDITION_MINT_SIZE,
1862
+ createReferral = zeroAddress4,
1863
+ contractVersion
1864
+ }) {
1865
+ if (contractSupportsMintRewards(contractVersion, "ERC1155")) {
1866
+ return encodeFunctionData({
1867
+ abi: zoraCreator1155ImplABI4,
1521
1868
  functionName: "setupNewTokenWithCreateReferral",
1522
- args: [tokenMetadataURI, maxSupply, createReferral]
1523
- }) : encodeFunctionData({
1524
- abi: zoraCreator1155ImplABI3,
1525
- functionName: "setupNewToken",
1526
- args: [tokenMetadataURI, maxSupply]
1527
- }),
1528
- encodeFunctionData({
1529
- abi: zoraCreator1155ImplABI3,
1530
- functionName: "addPermission",
1531
- args: [0n, fixedPriceMinterAddress, PERMISSION_BIT_MINTER]
1532
- }),
1533
- encodeFunctionData({
1534
- abi: zoraCreator1155ImplABI3,
1535
- functionName: "callSale",
1869
+ args: [tokenURI, BigInt(maxSupply), createReferral]
1870
+ });
1871
+ }
1872
+ if (createReferral !== zeroAddress4) {
1873
+ throw new Error(
1874
+ "Contract does not support create referral, but one was provided"
1875
+ );
1876
+ }
1877
+ return encodeFunctionData({
1878
+ abi: zoraCreator1155ImplABI4,
1879
+ functionName: "setupNewToken",
1880
+ args: [tokenURI, BigInt(maxSupply)]
1881
+ });
1882
+ }
1883
+ function setupRoyaltyConfig({
1884
+ royaltyBPS,
1885
+ royaltyRecipient,
1886
+ nextTokenId
1887
+ }) {
1888
+ if (royaltyBPS > 0 && royaltyRecipient != zeroAddress4) {
1889
+ return encodeFunctionData({
1890
+ abi: zoraCreator1155ImplABI4,
1891
+ functionName: "updateRoyaltiesForToken",
1536
1892
  args: [
1537
1893
  nextTokenId,
1538
- fixedPriceMinterAddress,
1539
- encodeFunctionData({
1540
- abi: zoraCreatorFixedPriceSaleStrategyABI,
1541
- functionName: "setSale",
1542
- args: [nextTokenId, salesConfigWithDefaults]
1543
- })
1894
+ {
1895
+ royaltyBPS,
1896
+ royaltyRecipient,
1897
+ royaltyMintSchedule: 0
1898
+ }
1544
1899
  ]
1545
- })
1546
- ];
1547
- if (mintToCreatorCount) {
1548
- setupActions.push(
1549
- encodeFunctionData({
1550
- abi: zoraCreator1155ImplABI3,
1551
- functionName: "adminMint",
1552
- args: [account, nextTokenId, mintToCreatorCount, "0x"]
1553
- })
1554
- );
1900
+ });
1555
1901
  }
1556
- if (royaltySettings) {
1557
- setupActions.push(
1558
- encodeFunctionData({
1559
- abi: zoraCreator1155ImplABI3,
1560
- functionName: "updateRoyaltiesForToken",
1561
- args: [
1562
- nextTokenId,
1563
- {
1564
- royaltyMintSchedule: 0,
1565
- royaltyBPS: royaltySettings?.royaltyBPS || ROYALTY_BPS_DEFAULT,
1566
- royaltyRecipient: royaltySettings?.royaltyRecipient || account
1567
- }
1568
- ]
1569
- })
1570
- );
1902
+ return null;
1903
+ }
1904
+ function makeAdminMintCall({
1905
+ ownerAddress,
1906
+ mintQuantity,
1907
+ nextTokenId
1908
+ }) {
1909
+ if (!mintQuantity || mintQuantity <= 0 || !ownerAddress) {
1910
+ return null;
1571
1911
  }
1572
- return setupActions;
1912
+ return encodeFunctionData({
1913
+ abi: zoraCreator1155ImplABI4,
1914
+ functionName: "adminMint",
1915
+ args: [ownerAddress, nextTokenId, BigInt(mintQuantity), zeroAddress4]
1916
+ });
1917
+ }
1918
+ function constructCreate1155TokenCalls(props) {
1919
+ const {
1920
+ chainId,
1921
+ nextTokenId,
1922
+ mintToCreatorCount,
1923
+ ownerAddress,
1924
+ contractVersion
1925
+ } = props;
1926
+ const new1155TokenPropsWithDefaults = applyNew1155Defaults(
1927
+ props,
1928
+ ownerAddress
1929
+ );
1930
+ const verifyTokenIdExpected = encodeFunctionData({
1931
+ abi: zoraCreator1155ImplABI4,
1932
+ functionName: "assumeLastTokenIdMatches",
1933
+ args: [nextTokenId - 1n]
1934
+ });
1935
+ const setupNewToken = buildSetupNewToken({
1936
+ tokenURI: new1155TokenPropsWithDefaults.tokenMetadataURI,
1937
+ maxSupply: new1155TokenPropsWithDefaults.maxSupply,
1938
+ createReferral: new1155TokenPropsWithDefaults.createReferral,
1939
+ contractVersion
1940
+ });
1941
+ const royaltyConfig = setupRoyaltyConfig({
1942
+ royaltyBPS: new1155TokenPropsWithDefaults.royaltyBPS,
1943
+ royaltyRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
1944
+ nextTokenId
1945
+ });
1946
+ const { minter, setupActions: mintersSetup } = setupMinters({
1947
+ tokenId: nextTokenId,
1948
+ chainId,
1949
+ fundsRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
1950
+ salesConfig: new1155TokenPropsWithDefaults.salesConfig
1951
+ });
1952
+ const adminMintCall = makeAdminMintCall({
1953
+ ownerAddress,
1954
+ mintQuantity: mintToCreatorCount,
1955
+ nextTokenId
1956
+ });
1957
+ const setupActions = [
1958
+ verifyTokenIdExpected,
1959
+ setupNewToken,
1960
+ ...mintersSetup,
1961
+ royaltyConfig,
1962
+ adminMintCall
1963
+ ].filter((item) => item !== null);
1964
+ return {
1965
+ setupActions,
1966
+ minter,
1967
+ newToken: new1155TokenPropsWithDefaults
1968
+ };
1573
1969
  }
1970
+ var contractSupportsMintRewards = (contractVersion, contractStandard) => {
1971
+ if (!contractStandard || !contractVersion) {
1972
+ return false;
1973
+ }
1974
+ const semVerContractVersion = semver.coerce(contractVersion)?.raw;
1975
+ if (!semVerContractVersion)
1976
+ return false;
1977
+ if (contractStandard === "ERC1155") {
1978
+ return semver.gte(semVerContractVersion, "1.3.5");
1979
+ } else {
1980
+ return semver.gte(semVerContractVersion, "14.0.0");
1981
+ }
1982
+ };
1983
+
1984
+ // src/create/1155-create-helper.ts
1985
+ var ROYALTY_BPS_DEFAULT = 1e3;
1574
1986
  var getTokenIdFromCreateReceipt = (receipt) => {
1575
1987
  for (const data of receipt.logs) {
1576
1988
  try {
1577
1989
  const decodedLog = decodeEventLog2({
1578
- abi: zoraCreator1155ImplABI3,
1990
+ abi: zoraCreator1155ImplABI5,
1579
1991
  eventName: "SetupNewToken",
1580
1992
  ...data
1581
1993
  });
@@ -1586,132 +1998,116 @@ var getTokenIdFromCreateReceipt = (receipt) => {
1586
1998
  }
1587
1999
  }
1588
2000
  };
1589
- async function getContractExists(publicClient, contract, account) {
1590
- let contractAddress;
1591
- let contractExists = false;
1592
- if (typeof contract !== "string") {
1593
- contractAddress = await publicClient.readContract({
1594
- abi: zoraCreator1155FactoryImplABI,
1595
- // Since this address is deterministic we can hardcode a chain id safely here.
1596
- address: zoraCreator1155FactoryImplAddress[999],
1597
- functionName: "deterministicContractAddress",
2001
+ function makeCreateContractAndTokenCall({
2002
+ contractExists,
2003
+ contractAddress,
2004
+ contract,
2005
+ account,
2006
+ royaltyBPS,
2007
+ tokenSetupActions,
2008
+ fundsRecipient
2009
+ }) {
2010
+ if (!contractAddress && typeof contract === "string") {
2011
+ throw new Error("Invariant: contract cannot be missing and an address");
2012
+ }
2013
+ if (!contractExists) {
2014
+ if (typeof contract === "string") {
2015
+ throw new Error("Invariant: expected contract object");
2016
+ }
2017
+ const accountAddress = typeof account === "string" ? account : account.address;
2018
+ return makeContractParameters({
2019
+ abi: zoraCreator1155FactoryImplABI2,
2020
+ functionName: "createContractDeterministic",
2021
+ account,
2022
+ address: zoraCreator1155FactoryImplAddress2[999],
1598
2023
  args: [
1599
- account,
1600
2024
  contract.uri,
1601
2025
  contract.name,
1602
- contract.defaultAdmin || account
2026
+ {
2027
+ // deprecated
2028
+ royaltyMintSchedule: 0,
2029
+ royaltyBPS: royaltyBPS || ROYALTY_BPS_DEFAULT,
2030
+ royaltyRecipient: fundsRecipient || accountAddress
2031
+ },
2032
+ contract.defaultAdmin || accountAddress,
2033
+ tokenSetupActions
1603
2034
  ]
1604
2035
  });
1605
- try {
1606
- await publicClient.readContract({
1607
- abi: zoraCreator1155ImplABI3,
1608
- address: contractAddress,
1609
- functionName: "contractVersion"
1610
- });
1611
- contractExists = true;
1612
- } catch (e) {
1613
- }
1614
- return { contractAddress, contractExists };
1615
2036
  }
1616
- return {
1617
- contractExists: true,
1618
- contractAddress: contract
1619
- };
1620
- }
1621
- function create1155CreatorClient(clientConfig) {
1622
- const { publicClient } = setupClient(clientConfig);
1623
- async function createNew1155Token({
1624
- contract,
1625
- tokenMetadataURI,
1626
- mintToCreatorCount = 1,
1627
- salesConfig = {},
1628
- maxSupply,
2037
+ return makeContractParameters({
2038
+ abi: zoraCreator1155ImplABI5,
2039
+ functionName: "multicall",
1629
2040
  account,
1630
- royaltySettings,
1631
- createReferral,
1632
- getAdditionalSetupActions
2041
+ address: contractAddress,
2042
+ args: [tokenSetupActions]
2043
+ });
2044
+ }
2045
+ var Create1155Client = class {
2046
+ constructor({
2047
+ chainId,
2048
+ publicClient
1633
2049
  }) {
1634
- const { contractExists, contractAddress } = await getContractExists(
1635
- publicClient,
1636
- contract,
1637
- account
1638
- );
1639
- let nextTokenId = 1n;
1640
- if (contractExists) {
1641
- nextTokenId = await publicClient.readContract({
1642
- abi: zoraCreator1155ImplABI3,
1643
- functionName: "nextTokenId",
1644
- address: contractAddress
1645
- });
1646
- }
1647
- const fixedPriceMinterAddress = await publicClient.readContract({
1648
- abi: zoraCreator1155FactoryImplABI,
1649
- address: zoraCreator1155FactoryImplAddress[999],
1650
- functionName: "fixedPriceMinter"
1651
- });
1652
- let tokenSetupActions = create1155TokenSetupArgs({
1653
- tokenMetadataURI,
1654
- nextTokenId,
1655
- salesConfig,
1656
- maxSupply,
1657
- fixedPriceMinterAddress,
1658
- account,
1659
- mintToCreatorCount,
1660
- royaltySettings,
1661
- createReferral
2050
+ this.chainId = chainId;
2051
+ this.publicClient = publicClient;
2052
+ }
2053
+ async createNew1155Token(props) {
2054
+ return createNew1155Token({
2055
+ ...props,
2056
+ publicClient: this.publicClient,
2057
+ chainId: this.chainId
1662
2058
  });
1663
- if (getAdditionalSetupActions) {
1664
- tokenSetupActions = [
1665
- ...getAdditionalSetupActions({ tokenId: nextTokenId, contractAddress }),
1666
- ...tokenSetupActions
1667
- ];
1668
- }
1669
- if (!contractAddress && typeof contract === "string") {
1670
- throw new Error("Invariant: contract cannot be missing and an address");
1671
- }
1672
- if (!contractExists && typeof contract !== "string") {
1673
- const request = makeSimulateContractParamaters({
1674
- abi: zoraCreator1155FactoryImplABI,
1675
- functionName: "createContractDeterministic",
1676
- account,
1677
- address: zoraCreator1155FactoryImplAddress[999],
1678
- args: [
1679
- contract.uri,
1680
- contract.name,
1681
- {
1682
- // deprecated
1683
- royaltyMintSchedule: 0,
1684
- royaltyBPS: royaltySettings?.royaltyBPS || ROYALTY_BPS_DEFAULT,
1685
- royaltyRecipient: royaltySettings?.royaltyRecipient || account
1686
- },
1687
- contract.defaultAdmin || account,
1688
- tokenSetupActions
1689
- ]
1690
- });
1691
- return {
1692
- request,
1693
- tokenSetupActions,
1694
- contractAddress,
1695
- contractExists
1696
- };
1697
- } else if (contractExists) {
1698
- const request = makeSimulateContractParamaters({
1699
- abi: zoraCreator1155ImplABI3,
1700
- functionName: "multicall",
1701
- account,
1702
- address: contractAddress,
1703
- args: [tokenSetupActions]
1704
- });
1705
- return {
1706
- request,
1707
- tokenSetupActions,
1708
- contractAddress,
1709
- contractExists
1710
- };
1711
- }
1712
- throw new Error("Unsupported contract argument type");
1713
2059
  }
1714
- return { createNew1155Token };
2060
+ };
2061
+ async function createNew1155Token({
2062
+ contract,
2063
+ account,
2064
+ getAdditionalSetupActions,
2065
+ token: tokenConfig,
2066
+ publicClient,
2067
+ chainId
2068
+ }) {
2069
+ const { contractExists, contractAddress, nextTokenId, contractVersion } = await getContractInfo({
2070
+ publicClient,
2071
+ chainId,
2072
+ contract,
2073
+ account
2074
+ });
2075
+ const {
2076
+ minter,
2077
+ newToken,
2078
+ setupActions: tokenSetupActions
2079
+ } = constructCreate1155TokenCalls({
2080
+ chainId,
2081
+ ownerAddress: account,
2082
+ contractVersion,
2083
+ nextTokenId,
2084
+ ...tokenConfig
2085
+ });
2086
+ const setupActions = getAdditionalSetupActions ? [
2087
+ ...getAdditionalSetupActions({
2088
+ tokenId: nextTokenId,
2089
+ contractAddress
2090
+ }),
2091
+ ...tokenSetupActions
2092
+ ] : tokenSetupActions;
2093
+ const request = makeCreateContractAndTokenCall({
2094
+ contractExists,
2095
+ contractAddress,
2096
+ contract,
2097
+ account,
2098
+ tokenSetupActions: setupActions,
2099
+ royaltyBPS: tokenConfig.royaltyBPS,
2100
+ fundsRecipient: tokenConfig.payoutRecipient
2101
+ });
2102
+ return {
2103
+ parameters: request,
2104
+ tokenSetupActions,
2105
+ collectionAddress: contractAddress,
2106
+ contractExists,
2107
+ newTokenId: nextTokenId,
2108
+ newToken,
2109
+ minter
2110
+ };
1715
2111
  }
1716
2112
 
1717
2113
  // src/mints/mints-queries.ts
@@ -1791,7 +2187,7 @@ var mintWithEthParams = ({
1791
2187
  chainId,
1792
2188
  pricePerMint,
1793
2189
  account
1794
- }) => makeSimulateContractParamaters({
2190
+ }) => makeContractParameters({
1795
2191
  abi: zoraMintsManagerImplConfig.abi,
1796
2192
  address: zoraMintsManagerImplConfig.address[chainId],
1797
2193
  functionName: "mintWithEth",
@@ -1847,7 +2243,7 @@ function collectWithMintsParams({
1847
2243
  minter,
1848
2244
  mintArguments
1849
2245
  });
1850
- return makeSimulateContractParamaters({
2246
+ return makeContractParameters({
1851
2247
  abi: zoraMints1155Config.abi,
1852
2248
  address: zoraMints1155Config.address[chainId],
1853
2249
  functionName: "transferBatchToManagerAndCall",
@@ -1993,7 +2389,7 @@ function collectPremintV2WithMintsParams({
1993
2389
  const call = encodePremintOnManager({
1994
2390
  ...rest
1995
2391
  });
1996
- return makeSimulateContractParamaters({
2392
+ return makeContractParameters({
1997
2393
  abi: zoraMints1155Config.abi,
1998
2394
  address: zoraMints1155Config.address[chainId],
1999
2395
  functionName: "transferBatchToManagerAndCall",
@@ -2046,41 +2442,90 @@ var unwrapAndForwardEthPermitAndTypedDataDefinition = ({
2046
2442
  to: mintsEthUnwrapperAndCallerAddress[chainId],
2047
2443
  nonce
2048
2444
  });
2445
+
2446
+ // src/sdk.ts
2447
+ function createCreatorClient(clientConfig) {
2448
+ const premintClient = new PremintClient({
2449
+ chainId: clientConfig.chainId,
2450
+ publicClient: clientConfig.publicClient,
2451
+ premintApi: clientConfig.premintApi || new PremintAPIClient(clientConfig.chainId)
2452
+ });
2453
+ const create1155CreatorClient = new Create1155Client({
2454
+ chainId: clientConfig.chainId,
2455
+ publicClient: clientConfig.publicClient
2456
+ });
2457
+ return {
2458
+ createPremint: (p) => premintClient.createPremint(p),
2459
+ updatePremint: (p) => premintClient.updatePremint(p),
2460
+ deletePremint: (p) => premintClient.deletePremint(p),
2461
+ create1155: (p) => create1155CreatorClient.createNew1155Token(p)
2462
+ };
2463
+ }
2464
+ function createCollectorClient(params) {
2465
+ const premintGetterToUse = params.premintGetter || new PremintAPIClient(params.chainId);
2466
+ const mintGetterToUse = params.mintGetter || new SubgraphMintGetter(params.chainId);
2467
+ const mintClient = new MintClient({
2468
+ chainId: params.chainId,
2469
+ publicClient: params.publicClient,
2470
+ premintGetter: premintGetterToUse,
2471
+ mintGetter: mintGetterToUse
2472
+ });
2473
+ return {
2474
+ getPremint: (p) => premintGetterToUse.getSignature({
2475
+ collectionAddress: p.address,
2476
+ uid: p.uid
2477
+ }),
2478
+ getCollectDataFromPremintReceipt: (p) => getDataFromPremintReceipt(p, params.chainId),
2479
+ mint: (p) => mintClient.mint(p),
2480
+ getMintCosts: (p) => mintClient.getMintCosts(p)
2481
+ };
2482
+ }
2049
2483
  export {
2050
- DEFAULT_SALE_SETTINGS,
2484
+ Create1155Client,
2051
2485
  Errors,
2052
- MintAPIClient,
2486
+ MintClient,
2053
2487
  PremintAPIClient,
2488
+ PremintClient,
2054
2489
  PremintConfigVersion3 as PremintConfigVersion,
2490
+ SubgraphMintGetter,
2055
2491
  ZORA_API_BASE,
2056
2492
  applyUpdateToPremint,
2493
+ collectOnchain,
2494
+ collectPremint,
2057
2495
  collectPremintV2WithMintsParams,
2058
2496
  collectWithMintsParams,
2059
2497
  convertCollectionFromApi,
2060
2498
  convertGetPremintApiResponse,
2061
2499
  convertPremintFromApi,
2062
- create1155CreatorClient,
2063
- create1155TokenSetupArgs,
2064
- createMintClient,
2065
- createPremintClient,
2500
+ createCollectorClient,
2501
+ createCreatorClient,
2066
2502
  decodeCallFailedError,
2503
+ defaultAdditionalAdmins,
2067
2504
  defaultTokenConfigV1MintArguments,
2068
2505
  defaultTokenConfigV2MintArguments,
2506
+ emptyContractCreationConfig,
2069
2507
  encodeCollectOnManager,
2070
2508
  encodePostSignatureInput,
2071
2509
  encodePremintForAPI,
2072
2510
  getApiNetworkConfigForChain,
2511
+ getDataFromPremintReceipt,
2073
2512
  getDefaultFixedPriceMinterAddress,
2074
2513
  getMintCosts,
2075
2514
  getMintsAccountBalanceWithPriceQuery,
2076
2515
  getMintsEthPrice,
2516
+ getNecessaryErc20Approval,
2077
2517
  getPremintCollectionAddress,
2078
2518
  getPremintExecutorAddress,
2079
2519
  getPremintMintCosts,
2520
+ getPremintMintCostsWithUnknownTokenPrice,
2080
2521
  getPremintMintFee,
2522
+ getPremintPricePerToken,
2081
2523
  getPremintedLogFromReceipt,
2524
+ getSignature,
2082
2525
  getTokenIdFromCreateReceipt,
2083
2526
  isAuthorizedToCreatePremint,
2527
+ isPremintConfigV1,
2528
+ isPremintConfigV2,
2084
2529
  isValidSignature,
2085
2530
  makeCallWithEthSafeTransferData,
2086
2531
  makeMintRewardsRecipient,
@@ -2088,16 +2533,20 @@ export {
2088
2533
  makePermitToCollectPremintOrNonPremint,
2089
2534
  makePermitTransferBatchAndTypeData,
2090
2535
  makePermitTransferTypeData,
2536
+ makePrepareMint1155TokenParams,
2091
2537
  makeUrls,
2092
2538
  migratePremintConfigToV2,
2093
2539
  mintWithEthParams,
2094
2540
  mintsBalanceOfAccountParams,
2541
+ parseMintCosts,
2095
2542
  recoverCreatorFromCreatorAttribution,
2096
2543
  recoverPremintSigner,
2544
+ requestErc20ApprovalForMint,
2097
2545
  selectMintsToCollectWithFromQueryResult,
2098
2546
  sumBalances,
2099
2547
  supportedPremintVersions,
2100
2548
  supportsPremintVersion,
2549
+ toContractCreationConfigOrAddress,
2101
2550
  tryRecoverPremintSigner,
2102
2551
  unwrapAndForwardEthPermitAndTypedDataDefinition
2103
2552
  };